@probelabs/probe 0.6.0-rc132 → 0.6.0-rc133

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.
@@ -46498,19 +46498,16 @@ function cleanSchemaResponse(response) {
46498
46498
  return trimmed.substring(startIndex, endIndex);
46499
46499
  }
46500
46500
  }
46501
- const firstBracket = Math.min(
46502
- trimmed.indexOf("{") >= 0 ? trimmed.indexOf("{") : Infinity,
46503
- trimmed.indexOf("[") >= 0 ? trimmed.indexOf("[") : Infinity
46504
- );
46505
- const lastBracket = Math.max(
46506
- trimmed.lastIndexOf("}"),
46507
- trimmed.lastIndexOf("]")
46508
- );
46509
- if (firstBracket < Infinity && lastBracket >= 0 && firstBracket < lastBracket) {
46510
- const beforeFirstBracket = trimmed.substring(0, firstBracket).trim();
46511
- if (beforeFirstBracket === "" || beforeFirstBracket.match(/^```\w*$/) || beforeFirstBracket.split("\n").length <= 2) {
46512
- return trimmed.substring(firstBracket, lastBracket + 1);
46513
- }
46501
+ let cleaned = trimmed;
46502
+ cleaned = cleaned.replace(/^```(?:json)?\s*\n?/i, "");
46503
+ cleaned = cleaned.replace(/\n?```\s*$/, "");
46504
+ cleaned = cleaned.trim();
46505
+ const firstChar = cleaned[0];
46506
+ const lastChar = cleaned[cleaned.length - 1];
46507
+ const isJsonObject = firstChar === "{" && lastChar === "}";
46508
+ const isJsonArray = firstChar === "[" && lastChar === "]";
46509
+ if (isJsonObject || isJsonArray) {
46510
+ return cleaned;
46514
46511
  }
46515
46512
  return response;
46516
46513
  }
@@ -106,28 +106,28 @@ export function cleanSchemaResponse(response) {
106
106
  }
107
107
  }
108
108
 
109
- // Fallback: Find JSON boundaries anywhere in the text
110
- const firstBracket = Math.min(
111
- trimmed.indexOf('{') >= 0 ? trimmed.indexOf('{') : Infinity,
112
- trimmed.indexOf('[') >= 0 ? trimmed.indexOf('[') : Infinity
113
- );
114
-
115
- const lastBracket = Math.max(
116
- trimmed.lastIndexOf('}'),
117
- trimmed.lastIndexOf(']')
118
- );
119
-
120
- // Only extract if we found valid JSON boundaries
121
- if (firstBracket < Infinity && lastBracket >= 0 && firstBracket < lastBracket) {
122
- // Check if the response likely starts with JSON (directly or after minimal content)
123
- const beforeFirstBracket = trimmed.substring(0, firstBracket).trim();
124
-
125
- // If there's minimal content before the first bracket, extract the JSON
126
- if (beforeFirstBracket === '' ||
127
- beforeFirstBracket.match(/^```\w*$/) ||
128
- beforeFirstBracket.split('\n').length <= 2) {
129
- return trimmed.substring(firstBracket, lastBracket + 1);
130
- }
109
+ // Fallback: Check if response is JSON after removing code block markers and whitespace
110
+ // First, remove common code block markers from top and bottom
111
+ let cleaned = trimmed;
112
+
113
+ // Remove opening code block markers (```json, ```, etc.)
114
+ cleaned = cleaned.replace(/^```(?:json)?\s*\n?/i, '');
115
+
116
+ // Remove closing code block markers
117
+ cleaned = cleaned.replace(/\n?```\s*$/, '');
118
+
119
+ // Trim whitespace and newlines
120
+ cleaned = cleaned.trim();
121
+
122
+ // Now check if first and last characters are valid JSON boundaries
123
+ const firstChar = cleaned[0];
124
+ const lastChar = cleaned[cleaned.length - 1];
125
+
126
+ const isJsonObject = firstChar === '{' && lastChar === '}';
127
+ const isJsonArray = firstChar === '[' && lastChar === ']';
128
+
129
+ if (isJsonObject || isJsonArray) {
130
+ return cleaned;
131
131
  }
132
132
 
133
133
  return response; // Return original if no extractable JSON found
@@ -71893,19 +71893,16 @@ function cleanSchemaResponse(response) {
71893
71893
  return trimmed.substring(startIndex, endIndex);
71894
71894
  }
71895
71895
  }
71896
- const firstBracket = Math.min(
71897
- trimmed.indexOf("{") >= 0 ? trimmed.indexOf("{") : Infinity,
71898
- trimmed.indexOf("[") >= 0 ? trimmed.indexOf("[") : Infinity
71899
- );
71900
- const lastBracket = Math.max(
71901
- trimmed.lastIndexOf("}"),
71902
- trimmed.lastIndexOf("]")
71903
- );
71904
- if (firstBracket < Infinity && lastBracket >= 0 && firstBracket < lastBracket) {
71905
- const beforeFirstBracket = trimmed.substring(0, firstBracket).trim();
71906
- if (beforeFirstBracket === "" || beforeFirstBracket.match(/^```\w*$/) || beforeFirstBracket.split("\n").length <= 2) {
71907
- return trimmed.substring(firstBracket, lastBracket + 1);
71908
- }
71896
+ let cleaned = trimmed;
71897
+ cleaned = cleaned.replace(/^```(?:json)?\s*\n?/i, "");
71898
+ cleaned = cleaned.replace(/\n?```\s*$/, "");
71899
+ cleaned = cleaned.trim();
71900
+ const firstChar = cleaned[0];
71901
+ const lastChar = cleaned[cleaned.length - 1];
71902
+ const isJsonObject = firstChar === "{" && lastChar === "}";
71903
+ const isJsonArray = firstChar === "[" && lastChar === "]";
71904
+ if (isJsonObject || isJsonArray) {
71905
+ return cleaned;
71909
71906
  }
71910
71907
  return response;
71911
71908
  }
package/cjs/index.cjs CHANGED
@@ -72073,19 +72073,16 @@ function cleanSchemaResponse(response) {
72073
72073
  return trimmed.substring(startIndex, endIndex);
72074
72074
  }
72075
72075
  }
72076
- const firstBracket = Math.min(
72077
- trimmed.indexOf("{") >= 0 ? trimmed.indexOf("{") : Infinity,
72078
- trimmed.indexOf("[") >= 0 ? trimmed.indexOf("[") : Infinity
72079
- );
72080
- const lastBracket = Math.max(
72081
- trimmed.lastIndexOf("}"),
72082
- trimmed.lastIndexOf("]")
72083
- );
72084
- if (firstBracket < Infinity && lastBracket >= 0 && firstBracket < lastBracket) {
72085
- const beforeFirstBracket = trimmed.substring(0, firstBracket).trim();
72086
- if (beforeFirstBracket === "" || beforeFirstBracket.match(/^```\w*$/) || beforeFirstBracket.split("\n").length <= 2) {
72087
- return trimmed.substring(firstBracket, lastBracket + 1);
72088
- }
72076
+ let cleaned = trimmed;
72077
+ cleaned = cleaned.replace(/^```(?:json)?\s*\n?/i, "");
72078
+ cleaned = cleaned.replace(/\n?```\s*$/, "");
72079
+ cleaned = cleaned.trim();
72080
+ const firstChar = cleaned[0];
72081
+ const lastChar = cleaned[cleaned.length - 1];
72082
+ const isJsonObject = firstChar === "{" && lastChar === "}";
72083
+ const isJsonArray = firstChar === "[" && lastChar === "]";
72084
+ if (isJsonObject || isJsonArray) {
72085
+ return cleaned;
72089
72086
  }
72090
72087
  return response;
72091
72088
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@probelabs/probe",
3
- "version": "0.6.0-rc132",
3
+ "version": "0.6.0-rc133",
4
4
  "description": "Node.js wrapper for the probe code search tool",
5
5
  "main": "src/index.js",
6
6
  "module": "src/index.js",
@@ -106,28 +106,28 @@ export function cleanSchemaResponse(response) {
106
106
  }
107
107
  }
108
108
 
109
- // Fallback: Find JSON boundaries anywhere in the text
110
- const firstBracket = Math.min(
111
- trimmed.indexOf('{') >= 0 ? trimmed.indexOf('{') : Infinity,
112
- trimmed.indexOf('[') >= 0 ? trimmed.indexOf('[') : Infinity
113
- );
114
-
115
- const lastBracket = Math.max(
116
- trimmed.lastIndexOf('}'),
117
- trimmed.lastIndexOf(']')
118
- );
119
-
120
- // Only extract if we found valid JSON boundaries
121
- if (firstBracket < Infinity && lastBracket >= 0 && firstBracket < lastBracket) {
122
- // Check if the response likely starts with JSON (directly or after minimal content)
123
- const beforeFirstBracket = trimmed.substring(0, firstBracket).trim();
124
-
125
- // If there's minimal content before the first bracket, extract the JSON
126
- if (beforeFirstBracket === '' ||
127
- beforeFirstBracket.match(/^```\w*$/) ||
128
- beforeFirstBracket.split('\n').length <= 2) {
129
- return trimmed.substring(firstBracket, lastBracket + 1);
130
- }
109
+ // Fallback: Check if response is JSON after removing code block markers and whitespace
110
+ // First, remove common code block markers from top and bottom
111
+ let cleaned = trimmed;
112
+
113
+ // Remove opening code block markers (```json, ```, etc.)
114
+ cleaned = cleaned.replace(/^```(?:json)?\s*\n?/i, '');
115
+
116
+ // Remove closing code block markers
117
+ cleaned = cleaned.replace(/\n?```\s*$/, '');
118
+
119
+ // Trim whitespace and newlines
120
+ cleaned = cleaned.trim();
121
+
122
+ // Now check if first and last characters are valid JSON boundaries
123
+ const firstChar = cleaned[0];
124
+ const lastChar = cleaned[cleaned.length - 1];
125
+
126
+ const isJsonObject = firstChar === '{' && lastChar === '}';
127
+ const isJsonArray = firstChar === '[' && lastChar === ']';
128
+
129
+ if (isJsonObject || isJsonArray) {
130
+ return cleaned;
131
131
  }
132
132
 
133
133
  return response; // Return original if no extractable JSON found