@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.js CHANGED
@@ -4120,19 +4120,44 @@ var LLM = class {
4120
4120
  }
4121
4121
  const firstBrace = jsonText.indexOf("{");
4122
4122
  const firstBracket = jsonText.indexOf("[");
4123
- const lastBrace = jsonText.lastIndexOf("}");
4124
- const lastBracket = jsonText.lastIndexOf("]");
4125
4123
  let startIdx = -1;
4126
- let endIdx = -1;
4124
+ let openChar = "";
4125
+ let closeChar = "";
4127
4126
  if (firstBrace !== -1 && (firstBracket === -1 || firstBrace < firstBracket)) {
4128
4127
  startIdx = firstBrace;
4129
- endIdx = lastBrace;
4128
+ openChar = "{";
4129
+ closeChar = "}";
4130
4130
  } else if (firstBracket !== -1) {
4131
4131
  startIdx = firstBracket;
4132
- endIdx = lastBracket;
4133
- }
4134
- if (startIdx !== -1 && endIdx !== -1 && startIdx < endIdx) {
4135
- jsonText = jsonText.substring(startIdx, endIdx + 1);
4132
+ openChar = "[";
4133
+ closeChar = "]";
4134
+ }
4135
+ if (startIdx !== -1) {
4136
+ let depth = 0;
4137
+ let inString = false;
4138
+ let endIdx = -1;
4139
+ for (let i = startIdx; i < jsonText.length; i++) {
4140
+ const char = jsonText[i];
4141
+ const prevChar = i > 0 ? jsonText[i - 1] : "";
4142
+ if (char === '"' && prevChar !== "\\") {
4143
+ inString = !inString;
4144
+ continue;
4145
+ }
4146
+ if (!inString) {
4147
+ if (char === openChar) {
4148
+ depth++;
4149
+ } else if (char === closeChar) {
4150
+ depth--;
4151
+ if (depth === 0) {
4152
+ endIdx = i;
4153
+ break;
4154
+ }
4155
+ }
4156
+ }
4157
+ }
4158
+ if (endIdx !== -1) {
4159
+ jsonText = jsonText.substring(startIdx, endIdx + 1);
4160
+ }
4136
4161
  }
4137
4162
  try {
4138
4163
  const repairedJson = (0, import_jsonrepair.jsonrepair)(jsonText);