Skip to content

Commit 52d39f3

Browse files
committed
do not overload context
1 parent 2342d95 commit 52d39f3

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

client/agents/compliai/utils.js

+14-12
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,14 @@ export async function ecfr({ path, params = {} }) {
130130
const errorText = await response.text();
131131
throw new Error(`eCFR API error (${response.status}): ${errorText}`);
132132
}
133-
134-
// For .json paths, parse as JSON; for .xml paths, return as text
135-
if (path.endsWith('.json')) {
136-
return response.json();
137-
} else {
138-
return response.text();
133+
134+
let results = path.endsWith('.json') ? await response.json() : await response.text();
135+
const stringifiedResults = JSON.stringify(results, null, 2);
136+
const limit = 10_000;
137+
if (stringifiedResults.length > limit) {
138+
results = stringifiedResults.slice(0, limit) + "\n... (truncated)";
139139
}
140+
return results;
140141
} catch (error) {
141142
console.error("eCFR API error:", error);
142143
throw error;
@@ -170,13 +171,14 @@ export async function federalRegister({ path, params = {} }) {
170171
const errorText = await response.text();
171172
throw new Error(`Federal Register API error (${response.status}): ${errorText}`);
172173
}
173-
174-
// For .json paths, parse as JSON; for .csv paths, return as text
175-
if (path.endsWith('.json')) {
176-
return response.json();
177-
} else {
178-
return response.text();
174+
175+
let results = path.endsWith('.json') ? await response.json() : await response.text();
176+
const stringifiedResults = JSON.stringify(results, null, 2);
177+
const limit = 10_000;
178+
if (stringifiedResults.length > limit) {
179+
results = stringifiedResults.slice(0, limit) + "\n... (truncated)";
179180
}
181+
return results;
180182
} catch (error) {
181183
console.error("Federal Register API error:", error);
182184
throw error;

0 commit comments

Comments
 (0)