@superatomai/sdk-node 0.0.34 → 0.0.35

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/index.mjs CHANGED
@@ -4076,19 +4076,44 @@ var LLM = class {
4076
4076
  }
4077
4077
  const firstBrace = jsonText.indexOf("{");
4078
4078
  const firstBracket = jsonText.indexOf("[");
4079
- const lastBrace = jsonText.lastIndexOf("}");
4080
- const lastBracket = jsonText.lastIndexOf("]");
4081
4079
  let startIdx = -1;
4082
- let endIdx = -1;
4080
+ let openChar = "";
4081
+ let closeChar = "";
4083
4082
  if (firstBrace !== -1 && (firstBracket === -1 || firstBrace < firstBracket)) {
4084
4083
  startIdx = firstBrace;
4085
- endIdx = lastBrace;
4084
+ openChar = "{";
4085
+ closeChar = "}";
4086
4086
  } else if (firstBracket !== -1) {
4087
4087
  startIdx = firstBracket;
4088
- endIdx = lastBracket;
4089
- }
4090
- if (startIdx !== -1 && endIdx !== -1 && startIdx < endIdx) {
4091
- jsonText = jsonText.substring(startIdx, endIdx + 1);
4088
+ openChar = "[";
4089
+ closeChar = "]";
4090
+ }
4091
+ if (startIdx !== -1) {
4092
+ let depth = 0;
4093
+ let inString = false;
4094
+ let endIdx = -1;
4095
+ for (let i = startIdx; i < jsonText.length; i++) {
4096
+ const char = jsonText[i];
4097
+ const prevChar = i > 0 ? jsonText[i - 1] : "";
4098
+ if (char === '"' && prevChar !== "\\") {
4099
+ inString = !inString;
4100
+ continue;
4101
+ }
4102
+ if (!inString) {
4103
+ if (char === openChar) {
4104
+ depth++;
4105
+ } else if (char === closeChar) {
4106
+ depth--;
4107
+ if (depth === 0) {
4108
+ endIdx = i;
4109
+ break;
4110
+ }
4111
+ }
4112
+ }
4113
+ }
4114
+ if (endIdx !== -1) {
4115
+ jsonText = jsonText.substring(startIdx, endIdx + 1);
4116
+ }
4092
4117
  }
4093
4118
  try {
4094
4119
  const repairedJson = jsonrepair(jsonText);