tryassay 0.33.0 → 0.33.1
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.
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
export declare function stripCodeFences(text: string): string;
|
|
2
|
+
/**
|
|
3
|
+
* Extract JSON from text that may contain code fences and trailing prose.
|
|
4
|
+
* Handles the common LLM pattern of returning:
|
|
5
|
+
* ```json\n{...}\n```\n\n**Reasoning:**\n...
|
|
6
|
+
*/
|
|
7
|
+
export declare function extractJSON(text: string): string;
|
|
2
8
|
export declare function safeParseJSON(text: string): any | null;
|
package/dist/hunt/parse-utils.js
CHANGED
|
@@ -6,9 +6,36 @@ export function stripCodeFences(text) {
|
|
|
6
6
|
lines.pop();
|
|
7
7
|
return lines.join('\n').trim();
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Extract JSON from text that may contain code fences and trailing prose.
|
|
11
|
+
* Handles the common LLM pattern of returning:
|
|
12
|
+
* ```json\n{...}\n```\n\n**Reasoning:**\n...
|
|
13
|
+
*/
|
|
14
|
+
export function extractJSON(text) {
|
|
15
|
+
// First try: extract content between code fences
|
|
16
|
+
const fenceMatch = text.match(/```(?:json)?\s*\n([\s\S]*?)\n```/);
|
|
17
|
+
if (fenceMatch)
|
|
18
|
+
return fenceMatch[1].trim();
|
|
19
|
+
// Second try: find the first { and its matching closing }
|
|
20
|
+
const start = text.indexOf('{');
|
|
21
|
+
if (start === -1)
|
|
22
|
+
return text.trim();
|
|
23
|
+
let depth = 0;
|
|
24
|
+
for (let i = start; i < text.length; i++) {
|
|
25
|
+
if (text[i] === '{')
|
|
26
|
+
depth++;
|
|
27
|
+
else if (text[i] === '}') {
|
|
28
|
+
depth--;
|
|
29
|
+
if (depth === 0)
|
|
30
|
+
return text.slice(start, i + 1);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Fallback: return from first { to end (old behavior via stripCodeFences)
|
|
34
|
+
return stripCodeFences(text);
|
|
35
|
+
}
|
|
9
36
|
export function safeParseJSON(text) {
|
|
10
37
|
try {
|
|
11
|
-
return JSON.parse(
|
|
38
|
+
return JSON.parse(extractJSON(text));
|
|
12
39
|
}
|
|
13
40
|
catch {
|
|
14
41
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-utils.js","sourceRoot":"","sources":["../../src/hunt/parse-utils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACtC,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC;QAAE,KAAK,CAAC,KAAK,EAAE,CAAC;IAC/C,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC;QAAE,KAAK,CAAC,GAAG,EAAE,CAAC;IAC5D,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"parse-utils.js","sourceRoot":"","sources":["../../src/hunt/parse-utils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACtC,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC;QAAE,KAAK,CAAC,KAAK,EAAE,CAAC;IAC/C,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC;QAAE,KAAK,CAAC,GAAG,EAAE,CAAC;I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