Skip to content

Commit 376e0ee

Browse files
committed
fix: json extractor code
1 parent 68f09b4 commit 376e0ee

3 files changed

Lines changed: 14 additions & 11 deletions

File tree

src/analysisWorker.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,10 @@ class AnalysisWorker {
200200
});
201201
}
202202

203-
extractJsonFromMessage(message) {
203+
extractJsonFromMessage(data) {
204+
const message = data.message;
204205
if (!message) return null;
205206

206-
// 1. Extract code-fenced JSON inside ```json ... ```
207207
const fenceRegex = /```json\s*([\s\S]*?)```/i;
208208
const fencedMatch = message.match(fenceRegex);
209209

@@ -212,7 +212,6 @@ class AnalysisWorker {
212212
if (fencedMatch && fencedMatch[1]) {
213213
jsonString = fencedMatch[1];
214214
} else {
215-
// fallback: try to extract first JSON-like structure from message
216215
const looseJsonRegex = /\{[\s\S]*\}/;
217216
const looseMatch = message.match(looseJsonRegex);
218217
if (looseMatch) jsonString = looseMatch[0];
@@ -223,15 +222,19 @@ class AnalysisWorker {
223222
return null;
224223
}
225224

226-
try {
227-
// Clean invisible characters
228-
jsonString = jsonString.trim();
225+
let cleaned = jsonString
226+
.split("\n")
227+
.filter((line) => !line.trim().startsWith("//"))
228+
.join("\n");
229+
230+
cleaned = cleaned.replace(/,\s*([}\]])/g, "$1");
231+
cleaned = cleaned.trim();
229232

230-
// Parse JSON safely
231-
return JSON.parse(jsonString);
233+
try {
234+
return JSON.parse(cleaned);
232235
} catch (err) {
233236
console.error("❌ Failed to parse JSON:", err);
234-
console.error("Raw JSON string:", jsonString);
237+
console.error("Cleaned JSON was:\n", cleaned);
235238
return null;
236239
}
237240
}

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ app.post('/analyze', async (req, res) => {
162162

163163
const repoName = repo;
164164
const branchName = branch || 'main';
165-
const analysisQuestion = question || 'Analyze and explain the repository architecture, return the full set of snippet for the full project architecture knowledge, analyze every node and provide a rich "analysis_response" result';
165+
const analysisQuestion = question || 'Analyze and explain the repository architecture, return the full set of snippet for the full project architecture knowledge, analyze every node and provide a rich and complete "analysis_response" result';
166166

167167
console.log(`Starting analysis for repository: ${repoName}, branch: ${branchName}`);
168168

src/potpieClient.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class PotpieClient {
5252
async getParsingStatus(projectId) {
5353
try {
5454
const response = await this.client.get(`/api/v2/parsing-status/${projectId}`);
55-
console.log(response);
55+
5656
return {
5757
success: true,
5858
data: response.data

0 commit comments

Comments
 (0)