@sudobility/shapeshyft_engine 1.0.5 → 1.0.8

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 (37) hide show
  1. package/CLAUDE.md +4 -0
  2. package/dist/config/providers.d.ts +27 -0
  3. package/dist/config/providers.d.ts.map +1 -1
  4. package/dist/config/providers.js +70 -0
  5. package/dist/config/providers.js.map +1 -1
  6. package/dist/index.d.ts +1 -0
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +1 -0
  9. package/dist/index.js.map +1 -1
  10. package/dist/lib/api-helper.d.ts.map +1 -1
  11. package/dist/lib/api-helper.js +2 -0
  12. package/dist/lib/api-helper.js.map +1 -1
  13. package/dist/services/llm/gemini.d.ts.map +1 -1
  14. package/dist/services/llm/gemini.js +2 -1
  15. package/dist/services/llm/gemini.js.map +1 -1
  16. package/dist/services/llm/groq.d.ts.map +1 -1
  17. package/dist/services/llm/groq.js +2 -1
  18. package/dist/services/llm/groq.js.map +1 -1
  19. package/dist/services/llm/index.d.ts.map +1 -1
  20. package/dist/services/llm/index.js +4 -0
  21. package/dist/services/llm/index.js.map +1 -1
  22. package/dist/services/llm/jev.d.ts +83 -0
  23. package/dist/services/llm/jev.d.ts.map +1 -0
  24. package/dist/services/llm/jev.js +224 -0
  25. package/dist/services/llm/jev.js.map +1 -0
  26. package/dist/services/llm/json-repair.d.ts +70 -0
  27. package/dist/services/llm/json-repair.d.ts.map +1 -0
  28. package/dist/services/llm/json-repair.js +522 -0
  29. package/dist/services/llm/json-repair.js.map +1 -0
  30. package/dist/services/llm/openai.d.ts.map +1 -1
  31. package/dist/services/llm/openai.js +4 -3
  32. package/dist/services/llm/openai.js.map +1 -1
  33. package/dist/types/index.d.ts +13 -2
  34. package/dist/types/index.d.ts.map +1 -1
  35. package/dist/types/index.js +2 -0
  36. package/dist/types/index.js.map +1 -1
  37. package/package.json +1 -1
@@ -0,0 +1,522 @@
1
+ /**
2
+ * @fileoverview Read model JSON that is nearly, but not quite, JSON.
3
+ * @description A model writing a long answer slips now and then: a trailing
4
+ * comma, a missing one, a bracket left open, a number like `0480`, an unescaped
5
+ * quote inside a lyric. Function calling guarantees the SHAPE of the payload,
6
+ * not that the text is valid — and a strict `JSON.parse` turns any of those
7
+ * into a failed, billed call that then has to be asked for again.
8
+ *
9
+ * Measured on one product's history through this server: 1,045 of 1,205 failed
10
+ * calls were parse failures, every one starting with a well-formed `{` and
11
+ * breaking somewhere after it, at 500-1,700 tokens against a ceiling ten times
12
+ * that. Most were "Unable to parse JSON string", "Expected ']'", "Invalid
13
+ * number" and "Property name must be a string literal". At temperature 0 the
14
+ * same prompt gives the same slip, so asking again does not help; reading the
15
+ * answer tolerantly does, and costs nothing.
16
+ *
17
+ * What a real DeepSeek answer actually got wrong, from the first patched run
18
+ * (6 repairs): five were TRAILING TEXT — a complete document, then the model
19
+ * closed the outer object one brace early and carried on writing its notes,
20
+ * which is what "Unable to parse JSON string" (55% of the history) was — and one
21
+ * was arithmetic in a number, `[1920 - 480, 480, "F3", 106]`. Failed calls in
22
+ * that run's styles fell from 6, 3 and 2 per song to one across three.
23
+ *
24
+ * The rule that keeps this safe: **strict parsing is tried first and is what
25
+ * valid input gets**, byte for byte. The tolerant reader only runs on text
26
+ * `JSON.parse` has already refused, and it reports every repair it made, so the
27
+ * caller can log it. It never guesses at meaning — it closes what is open,
28
+ * inserts what is missing between two values, and drops what is stray. A repaired
29
+ * answer is still only as good as the shape the caller validates it against.
30
+ */
31
+ const MISSING = Symbol("missing");
32
+ /** More repairs than this is not a slip, it is not JSON. */
33
+ const MAX_REPAIRS = 40;
34
+ /** The longest unquoted key or value it will accept. */
35
+ const MAX_BAREWORD = 64;
36
+ /** Deeper than any real answer; a guard against runaway recursion. */
37
+ const MAX_DEPTH = 300;
38
+ const STRICT_NUMBER = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][-+]?\d+)?$/;
39
+ const NUMBER_TOKEN = /^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/;
40
+ const WHITESPACE = /\s/;
41
+ class Reader {
42
+ s;
43
+ i = 0;
44
+ repairs = [];
45
+ constructor(s) {
46
+ this.s = s;
47
+ }
48
+ note(kind, at = this.i) {
49
+ if (this.repairs.length > MAX_REPAIRS)
50
+ throw new TooBroken();
51
+ this.repairs.push({ kind, at });
52
+ }
53
+ skipSpace() {
54
+ for (;;) {
55
+ const c = this.s[this.i];
56
+ if (c === undefined)
57
+ return;
58
+ if (WHITESPACE.test(c) || c === "\uFEFF") {
59
+ this.i += 1;
60
+ }
61
+ else if (c === "/" && this.s[this.i + 1] === "/") {
62
+ this.note("comment");
63
+ while (this.i < this.s.length && this.s[this.i] !== "\n")
64
+ this.i += 1;
65
+ }
66
+ else if (c === "/" && this.s[this.i + 1] === "*") {
67
+ this.note("comment");
68
+ const end = this.s.indexOf("*/", this.i + 2);
69
+ this.i = end === -1 ? this.s.length : end + 2;
70
+ }
71
+ else {
72
+ return;
73
+ }
74
+ }
75
+ }
76
+ /** The whole document: one object or array, anything after it ignored. */
77
+ document() {
78
+ this.skipSpace();
79
+ const first = this.s[this.i];
80
+ if (first !== "{" && first !== "[")
81
+ throw new TooBroken();
82
+ const value = this.value(0);
83
+ if (value === MISSING)
84
+ throw new TooBroken();
85
+ this.skipSpace();
86
+ if (this.i < this.s.length)
87
+ this.note("trailing text");
88
+ return value;
89
+ }
90
+ value(depth) {
91
+ if (depth > MAX_DEPTH)
92
+ throw new TooBroken();
93
+ this.skipSpace();
94
+ const c = this.s[this.i];
95
+ if (c === undefined)
96
+ return MISSING;
97
+ if (c === "{")
98
+ return this.object(depth);
99
+ if (c === "[")
100
+ return this.array(depth);
101
+ if (c === '"' || c === "'")
102
+ return this.string(c);
103
+ if ((c >= "0" && c <= "9") || c === "-" || c === "+" || c === ".") {
104
+ return this.number();
105
+ }
106
+ return this.word();
107
+ }
108
+ object(depth) {
109
+ this.i += 1; // {
110
+ const out = {};
111
+ let sawComma = false;
112
+ for (;;) {
113
+ this.skipSpace();
114
+ const c = this.s[this.i];
115
+ if (c === undefined) {
116
+ this.note("unclosed object");
117
+ return out;
118
+ }
119
+ if (c === "}") {
120
+ if (sawComma)
121
+ this.note("trailing comma");
122
+ this.i += 1;
123
+ return out;
124
+ }
125
+ if (c === "]") {
126
+ // The array this object sits in is closing; this object lost its `}`.
127
+ this.note("missing }");
128
+ return out;
129
+ }
130
+ if (c === ",") {
131
+ if (sawComma || Object.keys(out).length === 0)
132
+ this.note("extra comma");
133
+ sawComma = true;
134
+ this.i += 1;
135
+ continue;
136
+ }
137
+ sawComma = false;
138
+ let key;
139
+ if (c === '"' || c === "'") {
140
+ key = this.string(c);
141
+ }
142
+ else {
143
+ const start = this.i;
144
+ while (this.i < this.s.length) {
145
+ const k = this.s[this.i];
146
+ if (k === ":" || k === "}" || k === "," || WHITESPACE.test(k))
147
+ break;
148
+ this.i += 1;
149
+ }
150
+ key = this.s.slice(start, this.i);
151
+ if (key.length > MAX_BAREWORD)
152
+ throw new TooBroken();
153
+ if (key === "") {
154
+ // Something that cannot begin a key: drop it and carry on.
155
+ this.note("stray character");
156
+ this.i += 1;
157
+ continue;
158
+ }
159
+ this.note("unquoted key", start);
160
+ }
161
+ this.skipSpace();
162
+ if (this.s[this.i] === ":")
163
+ this.i += 1;
164
+ else
165
+ this.note("missing colon");
166
+ const v = this.value(depth + 1);
167
+ if (v === MISSING) {
168
+ this.note("unclosed object");
169
+ return out;
170
+ }
171
+ out[key] = v;
172
+ this.skipSpace();
173
+ const next = this.s[this.i];
174
+ if (next === ",") {
175
+ sawComma = true;
176
+ this.i += 1;
177
+ }
178
+ else if (next !== "}" && next !== "]" && next !== undefined) {
179
+ this.note("missing comma");
180
+ }
181
+ }
182
+ }
183
+ array(depth) {
184
+ this.i += 1; // [
185
+ const out = [];
186
+ let sawComma = false;
187
+ for (;;) {
188
+ this.skipSpace();
189
+ const c = this.s[this.i];
190
+ if (c === undefined) {
191
+ this.note("unclosed array");
192
+ return out;
193
+ }
194
+ if (c === "]") {
195
+ if (sawComma)
196
+ this.note("trailing comma");
197
+ this.i += 1;
198
+ return out;
199
+ }
200
+ if (c === "}") {
201
+ // The object this array sits in is closing; this array lost its `]`.
202
+ this.note("missing ]");
203
+ return out;
204
+ }
205
+ if (c === ",") {
206
+ if (sawComma || out.length === 0)
207
+ this.note("extra comma");
208
+ sawComma = true;
209
+ this.i += 1;
210
+ continue;
211
+ }
212
+ sawComma = false;
213
+ const v = this.value(depth + 1);
214
+ if (v === MISSING) {
215
+ this.note("unclosed array");
216
+ return out;
217
+ }
218
+ out.push(v);
219
+ this.skipSpace();
220
+ const next = this.s[this.i];
221
+ if (next === ",") {
222
+ sawComma = true;
223
+ this.i += 1;
224
+ }
225
+ else if (next !== "]" && next !== "}" && next !== undefined) {
226
+ this.note("missing comma");
227
+ }
228
+ }
229
+ }
230
+ string(quote) {
231
+ const start = this.i;
232
+ if (quote === "'")
233
+ this.note("single-quoted string");
234
+ this.i += 1;
235
+ let out = "";
236
+ let flaggedControl = false;
237
+ for (;;) {
238
+ const c = this.s[this.i];
239
+ if (c === undefined) {
240
+ this.note("unterminated string", start);
241
+ return out;
242
+ }
243
+ if (c === "\\") {
244
+ const e = this.s[this.i + 1];
245
+ if (e === undefined) {
246
+ this.i += 1;
247
+ continue;
248
+ }
249
+ const simple = {
250
+ n: "\n",
251
+ t: "\t",
252
+ r: "\r",
253
+ b: "\b",
254
+ f: "\f",
255
+ "/": "/",
256
+ '"': '"',
257
+ "'": "'",
258
+ "\\": "\\",
259
+ };
260
+ if (e in simple) {
261
+ if (e === "'")
262
+ this.note("bad escape");
263
+ out += simple[e];
264
+ this.i += 2;
265
+ }
266
+ else if (e === "u" &&
267
+ /^[0-9a-fA-F]{4}$/.test(this.s.slice(this.i + 2, this.i + 6))) {
268
+ out += String.fromCharCode(parseInt(this.s.slice(this.i + 2, this.i + 6), 16));
269
+ this.i += 6;
270
+ }
271
+ else if (e === " " &&
272
+ this.s[this.i + 2] !== undefined &&
273
+ this.s[this.i + 2] in simple) {
274
+ // `\ n`: a space slipped between the backslash and the escape letter.
275
+ this.note("bad escape");
276
+ out += simple[this.s[this.i + 2]];
277
+ this.i += 3;
278
+ }
279
+ else {
280
+ // `\x`, `\d`: the backslash is the mistake; keep the character.
281
+ this.note("bad escape");
282
+ out += e;
283
+ this.i += 2;
284
+ }
285
+ continue;
286
+ }
287
+ if (c === quote) {
288
+ // A quote ends the string only if what follows could follow a string.
289
+ let j = this.i + 1;
290
+ while (j < this.s.length && WHITESPACE.test(this.s[j]))
291
+ j += 1;
292
+ const after = this.s[j];
293
+ if (after === undefined ||
294
+ after === "," ||
295
+ after === "]" ||
296
+ after === "}" ||
297
+ after === ":") {
298
+ this.i += 1;
299
+ return out;
300
+ }
301
+ this.note("unescaped quote");
302
+ out += c;
303
+ this.i += 1;
304
+ continue;
305
+ }
306
+ if (c < " ") {
307
+ if (!flaggedControl)
308
+ this.note("raw control character");
309
+ flaggedControl = true;
310
+ }
311
+ out += c;
312
+ this.i += 1;
313
+ }
314
+ }
315
+ number() {
316
+ const at = this.i;
317
+ const rest = this.s.slice(this.i, this.i + 64);
318
+ const match = NUMBER_TOKEN.exec(rest);
319
+ if (!match) {
320
+ this.note("invalid number", at);
321
+ this.i += 1;
322
+ return null;
323
+ }
324
+ const token = match[0];
325
+ this.i += token.length;
326
+ if (!STRICT_NUMBER.test(token))
327
+ this.note("malformed number", at);
328
+ const folded = this.arithmetic(Number(token), at);
329
+ if (folded !== undefined)
330
+ return folded;
331
+ // `480ms`, `1.2.3`: letters or dots stuck to a number are junk, not part of it.
332
+ let junk = false;
333
+ while (this.i < this.s.length) {
334
+ const k = this.s[this.i];
335
+ if (k === "," || k === "]" || k === "}" || WHITESPACE.test(k))
336
+ break;
337
+ junk = true;
338
+ this.i += 1;
339
+ }
340
+ if (junk)
341
+ this.note("junk after number", at);
342
+ return Number(token);
343
+ }
344
+ /**
345
+ * A number the model computed instead of writing: `1920 - 480`.
346
+ *
347
+ * Seen in a real answer — `[1920 - 480, 480, "F3", 106]` — where a model
348
+ * working out a tick offset put the working in the payload. Read as separate
349
+ * tokens it shifts every slot of the tuple after it, so it is evaluated:
350
+ * `*` and `/` before `+` and `-`, left to right, numbers only.
351
+ *
352
+ * Only where the operator is spaced the same way on both sides (`1920 - 480`
353
+ * or `1920-480`), never `1920 -480`, which is a missing comma before a
354
+ * negative number and is read that way. Returns undefined when the text is
355
+ * not an expression, and leaves the position where it was.
356
+ */
357
+ arithmetic(first, at) {
358
+ const terms = [first];
359
+ const ops = [];
360
+ let j = this.i;
361
+ for (;;) {
362
+ let k = j;
363
+ while (this.s[k] === " " || this.s[k] === "\t")
364
+ k += 1;
365
+ const op = this.s[k];
366
+ if (op === undefined || !"+-*/".includes(op))
367
+ break;
368
+ const spacedBefore = k > j;
369
+ let m = k + 1;
370
+ while (this.s[m] === " " || this.s[m] === "\t")
371
+ m += 1;
372
+ const spacedAfter = m > k + 1;
373
+ if (spacedBefore !== spacedAfter)
374
+ break;
375
+ const operand = /^(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/.exec(this.s.slice(m, m + 64));
376
+ if (!operand)
377
+ break;
378
+ terms.push(Number(operand[0]));
379
+ ops.push(op);
380
+ j = m + operand[0].length;
381
+ }
382
+ if (ops.length === 0)
383
+ return undefined;
384
+ // * and / first, then + and -, each left to right.
385
+ const values = [terms[0]];
386
+ const adds = [];
387
+ ops.forEach((op, index) => {
388
+ const next = terms[index + 1];
389
+ if (op === "*")
390
+ values[values.length - 1] *= next;
391
+ else if (op === "/")
392
+ values[values.length - 1] /= next;
393
+ else {
394
+ adds.push(op);
395
+ values.push(next);
396
+ }
397
+ });
398
+ let result = values[0];
399
+ adds.forEach((op, index) => {
400
+ result =
401
+ op === "+" ? result + values[index + 1] : result - values[index + 1];
402
+ });
403
+ this.note("arithmetic expression", at);
404
+ this.i = j;
405
+ return Number.isFinite(result) ? result : null;
406
+ }
407
+ word() {
408
+ const start = this.i;
409
+ while (this.i < this.s.length) {
410
+ const k = this.s[this.i];
411
+ if (k === "," || k === "]" || k === "}" || k === "\n")
412
+ break;
413
+ this.i += 1;
414
+ }
415
+ const raw = this.s.slice(start, this.i).trim();
416
+ if (raw === "") {
417
+ // A closer where a value belonged (`{"a": }`): an empty value, and the
418
+ // closer is left for the caller, so no position is skipped.
419
+ this.note("missing value", start);
420
+ return null;
421
+ }
422
+ // A pitch or a keyword is a few characters; a long unquoted run is prose
423
+ // or noise, and reading it as a value would make garbage look like data.
424
+ if (raw.length > MAX_BAREWORD)
425
+ throw new TooBroken();
426
+ const lower = raw.toLowerCase();
427
+ if (raw === "true" || raw === "false" || raw === "null") {
428
+ return raw === "true" ? true : raw === "false" ? false : null;
429
+ }
430
+ if (lower === "true" ||
431
+ lower === "false" ||
432
+ lower === "none" ||
433
+ lower === "null") {
434
+ this.note("non-JSON literal", start);
435
+ return lower === "true" ? true : lower === "false" ? false : null;
436
+ }
437
+ if (raw === "NaN" ||
438
+ raw === "Infinity" ||
439
+ raw === "-Infinity" ||
440
+ raw === "undefined") {
441
+ this.note("non-JSON literal", start);
442
+ return null;
443
+ }
444
+ this.note("unquoted string", start);
445
+ return raw;
446
+ }
447
+ }
448
+ class TooBroken extends Error {
449
+ }
450
+ /**
451
+ * Read `text` tolerantly, or return null when it is not recoverable JSON.
452
+ *
453
+ * Exported for tests. Callers want `parseModelJson`, which is strict first.
454
+ */
455
+ export function lenientParse(text) {
456
+ const reader = new Reader(text);
457
+ try {
458
+ const value = reader.document();
459
+ return { value, repairs: reader.repairs };
460
+ }
461
+ catch (error) {
462
+ if (error instanceof TooBroken)
463
+ return null;
464
+ throw error;
465
+ }
466
+ }
467
+ /**
468
+ * `JSON.parse`, then — only if that refuses — the tolerant reader.
469
+ *
470
+ * Valid JSON is returned exactly as `JSON.parse` returns it, with no repairs,
471
+ * so putting this where `JSON.parse` was cannot change what a good answer
472
+ * means. Throws the strict parser's own error when the text cannot be repaired,
473
+ * so a caller's failure handling is unchanged.
474
+ */
475
+ export function parseModelJson(text) {
476
+ try {
477
+ return { value: JSON.parse(text), repairs: [] };
478
+ }
479
+ catch (strict) {
480
+ const lenient = lenientParse(text);
481
+ if (lenient)
482
+ return lenient;
483
+ throw strict;
484
+ }
485
+ }
486
+ /** A short window of `text` around the first repair, for a log line. */
487
+ export function windowAroundFirstRepair(text, repairs, radius = 60) {
488
+ const first = repairs[0];
489
+ if (!first)
490
+ return "";
491
+ const from = Math.max(0, first.at - radius);
492
+ const to = Math.min(text.length, first.at + radius);
493
+ return `${from > 0 ? "…" : ""}${text.slice(from, to).replace(/\n/g, "\\n")}${to < text.length ? "…" : ""}`;
494
+ }
495
+ /** "trailing comma x2, missing comma" — what was repaired, once each. */
496
+ export function summarizeRepairs(repairs) {
497
+ const counts = new Map();
498
+ for (const { kind } of repairs)
499
+ counts.set(kind, (counts.get(kind) ?? 0) + 1);
500
+ return [...counts.entries()]
501
+ .map(([kind, n]) => (n > 1 ? `${kind} x${n}` : kind))
502
+ .join(", ");
503
+ }
504
+ /**
505
+ * `parseModelJson` for an adapter: same result, and a log line when a repair
506
+ * was needed.
507
+ *
508
+ * The line names what was fixed and shows the text around the first fix, which
509
+ * is the only record there will be of what a model actually got wrong — the
510
+ * failed answers were never kept, and a repair that works leaves no error to
511
+ * read. `source` says which provider produced it.
512
+ */
513
+ export function readModelJson(text, source) {
514
+ const { value, repairs } = parseModelJson(text);
515
+ if (repairs.length > 0) {
516
+ console.warn(`[llm] ${source}: repaired ${repairs.length} JSON fault(s) in the model's answer ` +
517
+ `(${summarizeRepairs(repairs)}); first at char ${repairs[0].at} of ${text.length}: ` +
518
+ windowAroundFirstRepair(text, repairs));
519
+ }
520
+ return value;
521
+ }
522
+ //# sourceMappingURL=json-repair.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-repair.js","sourceRoot":"","sources":["../../../src/services/llm/json-repair.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAQ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@@ import { normalizeFinishReason } from "./finish-reason.js";
16
16
  import { addUsage, compatibleUsage } from "./compatible-usage.js";
17
17
  import { attachUsage, getFailedInvocationUsage } from "./usage-error.js";
18
18
  import { cohereResponseFormat } from "./cohere-schema.js";
19
+ import { readModelJson } from "./json-repair.js";
19
20
  /** Usage from a Responses API response, which names its fields differently. */
20
21
  function responsesUsage(response) {
21
22
  const inputTokens = response.usage?.input_tokens ?? 0;
@@ -258,10 +259,10 @@ export class OpenAIProvider {
258
259
  }
259
260
  let content;
260
261
  try {
261
- content = JSON.parse(rawResponse);
262
+ content = readModelJson(rawResponse, `${this.providerName}/${model}`);
262
263
  }
263
264
  catch (error) {
264
- // Not truncated, so genuinely malformed. Carry a head of the payload:
265
+ // Not truncated, and not repairable either: genuinely malformed. Carry a head of the payload:
265
266
  // "Unable to parse JSON string" alone leaves nothing to diagnose from.
266
267
  throw attachUsage(new Error(`Model returned unparseable JSON (${error instanceof Error ? error.message : String(error)}). First 300 chars: ${rawResponse.slice(0, 300)}`), usage, response.model);
267
268
  }
@@ -373,7 +374,7 @@ export class OpenAIProvider {
373
374
  }
374
375
  let content;
375
376
  try {
376
- content = JSON.parse(functionCall.arguments);
377
+ content = readModelJson(functionCall.arguments, this.providerName);
377
378
  }
378
379
  catch (error) {
379
380
  throw attachUsage(error, usage, response.model);