@tangle-network/agent-eval 0.14.1 → 0.14.2

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
@@ -11214,17 +11214,34 @@ function quote(s) {
11214
11214
  function parseReflectionResponse(raw, maxProposals) {
11215
11215
  let text = raw.trim();
11216
11216
  if (text.startsWith("```")) text = text.replace(/^```(?:json)?\n?/, "").replace(/\n?```$/, "");
11217
- const start = text.indexOf("{");
11218
- const end = text.lastIndexOf("}");
11219
- if (start < 0 || end <= start) return [];
11220
- let parsed;
11221
- try {
11222
- parsed = JSON.parse(text.slice(start, end + 1));
11223
- } catch {
11224
- return [];
11217
+ let parsed = null;
11218
+ const objectStart = text.indexOf("{");
11219
+ const objectEnd = text.lastIndexOf("}");
11220
+ const arrayStart = text.indexOf("[");
11221
+ const arrayEnd = text.lastIndexOf("]");
11222
+ const tryObjectFirst = objectStart >= 0 && (arrayStart < 0 || objectStart < arrayStart);
11223
+ const candidates = [];
11224
+ if (tryObjectFirst) {
11225
+ if (objectStart >= 0 && objectEnd > objectStart) candidates.push(text.slice(objectStart, objectEnd + 1));
11226
+ if (arrayStart >= 0 && arrayEnd > arrayStart) candidates.push(text.slice(arrayStart, arrayEnd + 1));
11227
+ } else {
11228
+ if (arrayStart >= 0 && arrayEnd > arrayStart) candidates.push(text.slice(arrayStart, arrayEnd + 1));
11229
+ if (objectStart >= 0 && objectEnd > objectStart) candidates.push(text.slice(objectStart, objectEnd + 1));
11230
+ }
11231
+ for (const slice of candidates) {
11232
+ try {
11233
+ parsed = JSON.parse(slice);
11234
+ break;
11235
+ } catch {
11236
+ }
11237
+ }
11238
+ if (parsed == null) return [];
11239
+ let proposalsRaw;
11240
+ if (Array.isArray(parsed)) {
11241
+ proposalsRaw = parsed;
11242
+ } else if (parsed && typeof parsed === "object") {
11243
+ proposalsRaw = parsed.proposals;
11225
11244
  }
11226
- if (!parsed || typeof parsed !== "object") return [];
11227
- const proposalsRaw = parsed.proposals;
11228
11245
  if (!Array.isArray(proposalsRaw)) return [];
11229
11246
  const out = [];
11230
11247
  for (const p of proposalsRaw) {