@jsonstudio/llms 0.6.1643 → 0.6.1739

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 (96) hide show
  1. package/dist/conversion/compat/actions/harvest-tool-calls-from-text.d.ts +10 -0
  2. package/dist/conversion/compat/actions/harvest-tool-calls-from-text.js +121 -0
  3. package/dist/conversion/compat/actions/iflow-kimi-cli-defaults.d.ts +10 -0
  4. package/dist/conversion/compat/actions/iflow-kimi-cli-defaults.js +80 -0
  5. package/dist/conversion/compat/actions/iflow-kimi-history-media-placeholder.d.ts +7 -0
  6. package/dist/conversion/compat/actions/iflow-kimi-history-media-placeholder.js +161 -0
  7. package/dist/conversion/compat/actions/iflow-kimi-thinking-reasoning-fill.d.ts +12 -0
  8. package/dist/conversion/compat/actions/iflow-kimi-thinking-reasoning-fill.js +67 -0
  9. package/dist/conversion/compat/actions/iflow-response-body-unwrap.d.ts +9 -0
  10. package/dist/conversion/compat/actions/iflow-response-body-unwrap.js +140 -0
  11. package/dist/conversion/compat/actions/lmstudio-responses-fc-ids.d.ts +10 -0
  12. package/dist/conversion/compat/actions/lmstudio-responses-fc-ids.js +59 -0
  13. package/dist/conversion/compat/actions/lmstudio-responses-input-stringify.d.ts +14 -0
  14. package/dist/conversion/compat/actions/lmstudio-responses-input-stringify.js +125 -0
  15. package/dist/conversion/compat/actions/normalize-tool-call-ids.d.ts +11 -0
  16. package/dist/conversion/compat/actions/normalize-tool-call-ids.js +140 -0
  17. package/dist/conversion/compat/actions/strip-orphan-function-calls-tag.d.ts +2 -0
  18. package/dist/conversion/compat/actions/strip-orphan-function-calls-tag.js +152 -0
  19. package/dist/conversion/compat/antigravity-session-signature.d.ts +1 -1
  20. package/dist/conversion/compat/antigravity-session-signature.js +5 -4
  21. package/dist/conversion/compat/profiles/chat-iflow.json +6 -0
  22. package/dist/conversion/compat/profiles/chat-lmstudio.json +7 -1
  23. package/dist/conversion/hub/operation-table/operation-table-runner.js +1 -1
  24. package/dist/conversion/hub/operation-table/semantic-mappers/gemini-mapper.js +19 -2
  25. package/dist/conversion/hub/pipeline/compat/compat-pipeline-executor.js +101 -5
  26. package/dist/conversion/hub/pipeline/compat/compat-profile-resolver.d.ts +2 -0
  27. package/dist/conversion/hub/pipeline/compat/compat-profile-resolver.js +63 -0
  28. package/dist/conversion/hub/pipeline/compat/compat-types.d.ts +18 -0
  29. package/dist/conversion/hub/pipeline/hub-pipeline.js +1 -1
  30. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage1_semantic_map/index.js +8 -5
  31. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage3_compat/index.js +5 -1
  32. package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage1_sse_decode/index.js +113 -0
  33. package/dist/conversion/hub/pipeline/target-utils.js +3 -0
  34. package/dist/conversion/hub/response/provider-response.js +27 -1
  35. package/dist/conversion/responses/responses-openai-bridge.js +32 -6
  36. package/dist/conversion/shared/anthropic-message-utils.js +20 -5
  37. package/dist/conversion/shared/bridge-id-utils.d.ts +2 -0
  38. package/dist/conversion/shared/bridge-id-utils.js +52 -15
  39. package/dist/conversion/shared/responses-conversation-store.js +40 -5
  40. package/dist/conversion/shared/responses-output-builder.js +23 -7
  41. package/dist/conversion/shared/responses-tool-utils.d.ts +1 -0
  42. package/dist/conversion/shared/responses-tool-utils.js +30 -13
  43. package/dist/conversion/shared/text-markup-normalizer.d.ts +1 -0
  44. package/dist/conversion/shared/text-markup-normalizer.js +269 -1
  45. package/dist/router/virtual-router/bootstrap.js +31 -7
  46. package/dist/router/virtual-router/classifier.js +1 -1
  47. package/dist/router/virtual-router/engine/antigravity/alias-lease.d.ts +33 -0
  48. package/dist/router/virtual-router/engine/antigravity/alias-lease.js +247 -0
  49. package/dist/router/virtual-router/engine/health/index.d.ts +23 -0
  50. package/dist/router/virtual-router/engine/health/index.js +720 -0
  51. package/dist/router/virtual-router/engine/provider-key/parse.d.ts +6 -0
  52. package/dist/router/virtual-router/engine/provider-key/parse.js +43 -0
  53. package/dist/router/virtual-router/engine/routing-pools/index.d.ts +13 -0
  54. package/dist/router/virtual-router/engine/routing-pools/index.js +225 -0
  55. package/dist/router/virtual-router/engine/routing-state/keys.d.ts +3 -0
  56. package/dist/router/virtual-router/engine/routing-state/keys.js +30 -0
  57. package/dist/router/virtual-router/engine/routing-state/metadata.d.ts +6 -0
  58. package/dist/router/virtual-router/engine/routing-state/metadata.js +132 -0
  59. package/dist/router/virtual-router/engine/routing-state/store.d.ts +11 -0
  60. package/dist/router/virtual-router/engine/routing-state/store.js +107 -0
  61. package/dist/router/virtual-router/engine-health.d.ts +1 -23
  62. package/dist/router/virtual-router/engine-health.js +1 -720
  63. package/dist/router/virtual-router/engine-selection/route-utils.js +57 -0
  64. package/dist/router/virtual-router/engine-selection/tier-selection-select.js +8 -48
  65. package/dist/router/virtual-router/engine-selection/tier-selection.js +34 -17
  66. package/dist/router/virtual-router/engine-selection.d.ts +1 -13
  67. package/dist/router/virtual-router/engine-selection.js +1 -225
  68. package/dist/router/virtual-router/engine.d.ts +2 -23
  69. package/dist/router/virtual-router/engine.js +130 -603
  70. package/dist/router/virtual-router/message-utils.js +15 -5
  71. package/dist/servertool/engine.js +4 -4
  72. package/dist/servertool/handlers/followup-request-builder.js +46 -0
  73. package/dist/servertool/handlers/gemini-empty-reply-continue.js +48 -47
  74. package/dist/servertool/handlers/stop-message-auto.js +64 -7
  75. package/dist/servertool/handlers/vision.js +10 -0
  76. package/dist/servertool/types.d.ts +3 -0
  77. package/dist/sse/sse-to-json/builders/response-builder.js +6 -0
  78. package/dist/sse/sse-to-json/chat-sse-to-json-converter.js +32 -2
  79. package/dist/sse/sse-to-json/parsers/sse-parser.js +34 -0
  80. package/dist/sse/sse-to-json/responses-sse-to-json-converter.d.ts +1 -0
  81. package/dist/sse/sse-to-json/responses-sse-to-json-converter.js +33 -1
  82. package/dist/tools/apply-patch/args-normalizer/default-actions.d.ts +2 -0
  83. package/dist/tools/apply-patch/args-normalizer/default-actions.js +12 -0
  84. package/dist/tools/apply-patch/args-normalizer/extract-patch.d.ts +2 -0
  85. package/dist/tools/apply-patch/args-normalizer/extract-patch.js +15 -0
  86. package/dist/tools/apply-patch/args-normalizer/index.d.ts +2 -0
  87. package/dist/tools/apply-patch/args-normalizer/index.js +164 -0
  88. package/dist/tools/apply-patch/args-normalizer/structured-builders.d.ts +7 -0
  89. package/dist/tools/apply-patch/args-normalizer/structured-builders.js +85 -0
  90. package/dist/tools/apply-patch/args-normalizer/types.d.ts +54 -0
  91. package/dist/tools/apply-patch/args-normalizer/types.js +1 -0
  92. package/dist/tools/apply-patch/patch-text/looks-like-patch.js +1 -0
  93. package/dist/tools/apply-patch/patch-text/normalize.js +104 -5
  94. package/dist/tools/apply-patch/structured/coercion.js +28 -4
  95. package/dist/tools/apply-patch/validator.js +7 -146
  96. package/package.json +1 -1
@@ -1,8 +1,5 @@
1
- import { buildStructuredPatch, StructuredApplyPatchError } from './structured.js';
2
- import { coerceStructuredPayload } from './structured/coercion.js';
3
- import { tryParseJsonLoose } from './json/parse-loose.js';
1
+ import { normalizeApplyPatchArgs } from './args-normalizer/index.js';
4
2
  import { normalizeApplyPatchText, looksLikePatch } from './patch-text/normalize.js';
5
- import { asString, isRecord } from './validation/shared.js';
6
3
  export { looksLikePatch, normalizeApplyPatchText };
7
4
  const toJson = (value) => {
8
5
  try {
@@ -13,148 +10,12 @@ const toJson = (value) => {
13
10
  }
14
11
  };
15
12
  export function validateApplyPatchArgs(argsString, rawArgs) {
16
- const rawTrimmed = typeof argsString === 'string' ? argsString.trim() : '';
17
- const looksJsonContainer = rawTrimmed.startsWith('{') || rawTrimmed.startsWith('[');
18
- // Raw patch text without JSON wrapper
19
- if (!looksJsonContainer && looksLikePatch(rawTrimmed)) {
20
- const patchText = normalizeApplyPatchText(rawTrimmed);
21
- if (!patchText.includes('*** Begin Patch')) {
22
- return { ok: false, reason: 'unsupported_patch_format' };
23
- }
24
- return { ok: true, normalizedArgs: toJson({ patch: patchText, input: patchText }) };
13
+ const normalized = normalizeApplyPatchArgs(argsString, rawArgs);
14
+ if (normalized.ok === false) {
15
+ return { ok: false, reason: normalized.reason };
25
16
  }
26
- const extractFromRecord = (rec) => {
27
- // Special case: argsString claims to be JSON but isn't parseable and raw text looks like a patch.
28
- if (looksJsonContainer && Object.keys(rec).length === 0 && looksLikePatch(rawTrimmed)) {
29
- const patchText = normalizeApplyPatchText(rawTrimmed);
30
- if (!patchText.includes('*** Begin Patch'))
31
- return { failureReason: 'unsupported_patch_format' };
32
- return { patchText };
33
- }
34
- const patchField = asString(rec.patch);
35
- if (patchField && looksLikePatch(patchField)) {
36
- const patchText = normalizeApplyPatchText(patchField);
37
- if (!patchText.includes('*** Begin Patch'))
38
- return { failureReason: 'unsupported_patch_format' };
39
- return { patchText };
40
- }
41
- const diffField = asString(rec.diff) ?? asString(rec.patchText) ?? asString(rec.body);
42
- if (diffField && looksLikePatch(diffField)) {
43
- const patchText = normalizeApplyPatchText(diffField);
44
- if (!patchText.includes('*** Begin Patch'))
45
- return { failureReason: 'unsupported_patch_format' };
46
- return { patchText };
47
- }
48
- const inputField = asString(rec.input);
49
- if (inputField && looksLikePatch(inputField)) {
50
- const patchText = normalizeApplyPatchText(inputField);
51
- if (!patchText.includes('*** Begin Patch'))
52
- return { failureReason: 'unsupported_patch_format' };
53
- return { patchText };
54
- }
55
- // Common shape: patch text stored under `instructions` (e.g. "*** Update File: ...").
56
- const instructionsField = asString(rec.instructions);
57
- if (instructionsField && looksLikePatch(instructionsField)) {
58
- const patchText = normalizeApplyPatchText(instructionsField);
59
- if (!patchText.includes('*** Begin Patch'))
60
- return { failureReason: 'unsupported_patch_format' };
61
- return { patchText };
62
- }
63
- // Common wrapper shape (seen in codex samples): { _raw: "{...json...}" }.
64
- // `_raw` may contain either patch text or a JSON-encoded structured payload.
65
- const rawEnvelope = asString(rec._raw);
66
- if (rawEnvelope) {
67
- const trimmed = rawEnvelope.trim();
68
- if (looksLikePatch(trimmed)) {
69
- const patchText = normalizeApplyPatchText(trimmed);
70
- if (!patchText.includes('*** Begin Patch'))
71
- return { failureReason: 'unsupported_patch_format' };
72
- return { patchText };
73
- }
74
- const parsed = tryParseJsonLoose(trimmed);
75
- if (parsed && isRecord(parsed)) {
76
- return extractFromRecord(parsed);
77
- }
78
- if (Array.isArray(parsed) && parsed.length > 0) {
79
- const changesArray = parsed.filter((entry) => isRecord(entry));
80
- if (changesArray.length && changesArray.some((c) => typeof c.kind === 'string')) {
81
- const payload = { changes: changesArray };
82
- try {
83
- return { patchText: buildStructuredPatch(payload) };
84
- }
85
- catch (error) {
86
- if (!(error instanceof StructuredApplyPatchError))
87
- throw error;
88
- return { failureReason: error.reason || 'structured_apply_patch_error' };
89
- }
90
- }
91
- }
92
- }
93
- const payload = coerceStructuredPayload(rec);
94
- if (payload) {
95
- try {
96
- return { patchText: buildStructuredPatch(payload) };
97
- }
98
- catch (error) {
99
- if (!(error instanceof StructuredApplyPatchError))
100
- throw error;
101
- return { failureReason: error.reason || 'structured_apply_patch_error' };
102
- }
103
- }
104
- return {};
17
+ return {
18
+ ok: true,
19
+ normalizedArgs: toJson({ patch: normalized.patchText, input: normalized.patchText })
105
20
  };
106
- let patchText;
107
- let failureReason;
108
- if (isRecord(rawArgs)) {
109
- const res = extractFromRecord(rawArgs);
110
- patchText = res.patchText;
111
- failureReason = res.failureReason;
112
- }
113
- else if (Array.isArray(rawArgs) && rawArgs.length > 0) {
114
- // compatibility: arguments may be either:
115
- // - a single-element array [{ file, changes: [...] }]
116
- // - a raw changes array [{ kind, ... }, ...]
117
- const first = rawArgs.find((entry) => isRecord(entry));
118
- if (first && Array.isArray(first.changes)) {
119
- const res = extractFromRecord(first);
120
- patchText = res.patchText;
121
- failureReason = res.failureReason;
122
- }
123
- else {
124
- const changesArray = rawArgs.filter((entry) => isRecord(entry));
125
- if (changesArray.length && changesArray.some((c) => typeof c.kind === 'string')) {
126
- const payload = { changes: changesArray };
127
- try {
128
- patchText = buildStructuredPatch(payload);
129
- }
130
- catch (error) {
131
- if (!(error instanceof StructuredApplyPatchError))
132
- throw error;
133
- failureReason = error.reason || 'structured_apply_patch_error';
134
- }
135
- }
136
- }
137
- }
138
- else if (typeof rawArgs === 'string' && looksLikePatch(rawArgs)) {
139
- const normalized = normalizeApplyPatchText(rawArgs);
140
- if (normalized.includes('*** Begin Patch')) {
141
- patchText = normalized;
142
- }
143
- else {
144
- failureReason = 'unsupported_patch_format';
145
- }
146
- }
147
- if (!patchText) {
148
- if (failureReason)
149
- return { ok: false, reason: failureReason };
150
- if (looksJsonContainer &&
151
- isRecord(rawArgs) &&
152
- Object.keys(rawArgs).length === 0 &&
153
- rawTrimmed.length > 0 &&
154
- !looksLikePatch(rawTrimmed)) {
155
- return { ok: false, reason: 'invalid_json' };
156
- }
157
- return { ok: false, reason: 'missing_changes' };
158
- }
159
- return { ok: true, normalizedArgs: toJson({ patch: patchText, input: patchText }) };
160
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsonstudio/llms",
3
- "version": "0.6.1643",
3
+ "version": "0.6.1739",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",