@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.
Files changed (82) hide show
  1. package/dist/conversion/codecs/gemini-openai-codec.js +33 -4
  2. package/dist/conversion/codecs/openai-openai-codec.js +2 -1
  3. package/dist/conversion/codecs/responses-openai-codec.js +3 -2
  4. package/dist/conversion/compat/actions/claude-thinking-tools.d.ts +15 -0
  5. package/dist/conversion/compat/actions/claude-thinking-tools.js +72 -0
  6. package/dist/conversion/compat/actions/glm-history-image-trim.d.ts +2 -0
  7. package/dist/conversion/compat/actions/glm-history-image-trim.js +88 -0
  8. package/dist/conversion/compat/profiles/chat-gemini.json +15 -14
  9. package/dist/conversion/compat/profiles/chat-glm.json +194 -194
  10. package/dist/conversion/compat/profiles/chat-iflow.json +199 -199
  11. package/dist/conversion/compat/profiles/chat-lmstudio.json +43 -43
  12. package/dist/conversion/compat/profiles/chat-qwen.json +20 -20
  13. package/dist/conversion/compat/profiles/responses-c4m.json +42 -42
  14. package/dist/conversion/compat/profiles/responses-output2choices-test.json +12 -0
  15. package/dist/conversion/hub/pipeline/compat/compat-pipeline-executor.js +6 -0
  16. package/dist/conversion/hub/pipeline/compat/compat-types.d.ts +2 -0
  17. package/dist/conversion/hub/pipeline/hub-pipeline.d.ts +6 -1
  18. package/dist/conversion/hub/pipeline/hub-pipeline.js +40 -13
  19. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/index.js +15 -0
  20. package/dist/conversion/hub/process/chat-process.js +107 -26
  21. package/dist/conversion/hub/semantic-mappers/anthropic-mapper.js +8 -0
  22. package/dist/conversion/hub/semantic-mappers/gemini-mapper.js +28 -10
  23. package/dist/conversion/hub/semantic-mappers/responses-mapper.js +51 -2
  24. package/dist/conversion/hub/tool-session-compat.d.ts +26 -0
  25. package/dist/conversion/hub/tool-session-compat.js +299 -0
  26. package/dist/conversion/hub/types/chat-envelope.d.ts +1 -0
  27. package/dist/conversion/responses/responses-openai-bridge.d.ts +0 -1
  28. package/dist/conversion/responses/responses-openai-bridge.js +0 -71
  29. package/dist/conversion/shared/anthropic-message-utils.js +54 -0
  30. package/dist/conversion/shared/args-mapping.js +11 -3
  31. package/dist/conversion/shared/gemini-tool-utils.js +8 -0
  32. package/dist/conversion/shared/responses-output-builder.js +47 -88
  33. package/dist/conversion/shared/streaming-text-extractor.d.ts +25 -0
  34. package/dist/conversion/shared/streaming-text-extractor.js +31 -38
  35. package/dist/conversion/shared/text-markup-normalizer.js +42 -27
  36. package/dist/conversion/shared/tool-filter-pipeline.js +2 -1
  37. package/dist/conversion/shared/tool-governor.js +75 -4
  38. package/dist/conversion/shared/tool-harvester.js +43 -12
  39. package/dist/conversion/shared/tool-mapping.d.ts +1 -0
  40. package/dist/conversion/shared/tool-mapping.js +33 -13
  41. package/dist/filters/index.d.ts +1 -0
  42. package/dist/filters/index.js +1 -0
  43. package/dist/filters/special/request-toolcalls-stringify.js +5 -55
  44. package/dist/filters/special/request-tools-normalize.js +14 -23
  45. package/dist/filters/special/response-apply-patch-toon-decode.d.ts +23 -0
  46. package/dist/filters/special/response-apply-patch-toon-decode.js +109 -0
  47. package/dist/filters/special/response-tool-arguments-toon-decode.d.ts +10 -0
  48. package/dist/filters/special/response-tool-arguments-toon-decode.js +55 -13
  49. package/dist/guidance/index.js +70 -27
  50. package/dist/router/virtual-router/bootstrap.js +10 -5
  51. package/dist/router/virtual-router/classifier.js +9 -4
  52. package/dist/router/virtual-router/engine-health.d.ts +22 -0
  53. package/dist/router/virtual-router/engine-health.js +423 -0
  54. package/dist/router/virtual-router/engine-logging.d.ts +20 -0
  55. package/dist/router/virtual-router/engine-logging.js +197 -0
  56. package/dist/router/virtual-router/engine-selection.d.ts +32 -0
  57. package/dist/router/virtual-router/engine-selection.js +649 -0
  58. package/dist/router/virtual-router/engine.d.ts +21 -14
  59. package/dist/router/virtual-router/engine.js +200 -523
  60. package/dist/router/virtual-router/message-utils.js +22 -0
  61. package/dist/router/virtual-router/routing-instructions.d.ts +8 -1
  62. package/dist/router/virtual-router/routing-instructions.js +137 -3
  63. package/dist/router/virtual-router/tool-signals.js +57 -11
  64. package/dist/router/virtual-router/types.d.ts +30 -0
  65. package/dist/router/virtual-router/types.js +1 -1
  66. package/dist/servertool/engine.js +3 -0
  67. package/dist/servertool/handlers/gemini-empty-reply-continue.d.ts +1 -0
  68. package/dist/servertool/handlers/gemini-empty-reply-continue.js +120 -0
  69. package/dist/servertool/handlers/iflow-model-error-retry.d.ts +1 -0
  70. package/dist/servertool/handlers/iflow-model-error-retry.js +93 -0
  71. package/dist/servertool/handlers/stop-message-auto.d.ts +1 -0
  72. package/dist/servertool/handlers/stop-message-auto.js +204 -0
  73. package/dist/servertool/handlers/vision.js +105 -7
  74. package/dist/servertool/server-side-tools.d.ts +3 -0
  75. package/dist/servertool/server-side-tools.js +29 -0
  76. package/dist/sse/sse-to-json/builders/anthropic-response-builder.js +16 -0
  77. package/dist/tools/apply-patch-structured.d.ts +20 -0
  78. package/dist/tools/apply-patch-structured.js +239 -0
  79. package/dist/tools/tool-description-utils.d.ts +5 -0
  80. package/dist/tools/tool-description-utils.js +50 -0
  81. package/dist/tools/tool-registry.js +14 -5
  82. 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 input = asString(rawArgs.input);
99
- const patch = asString(rawArgs.patch) ?? input;
100
- if (!patch) {
101
- return { ok: false, reason: 'missing_input' };
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsonstudio/llms",
3
- "version": "0.6.473",
3
+ "version": "0.6.568",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -62,4 +62,4 @@
62
62
  "dist",
63
63
  "README.md"
64
64
  ]
65
- }
65
+ }