Skip to content

Commit 7eb643c

Browse files
committed
fix: match Fast widget persisted serialization limit
1 parent 3f72b82 commit 7eb643c

2 files changed

Lines changed: 43 additions & 11 deletions

File tree

‎packages/cloud-agents/src/server/fast-agent/__tests__/fast-agent-service.test.ts‎

Lines changed: 28 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/cloud-agents/src/server/fast-agent/fast-agent-service.ts‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,7 @@ function serializeFastAgentToolOutput(result: unknown): {
163163
output: string;
164164
truncated: boolean;
165165
} {
166-
let output: string;
167-
try {
168-
output = JSON.stringify(result, null, 2) ?? String(result);
169-
} catch {
170-
output = String(result);
171-
}
166+
const output = stringifyFastAgentToolOutput(result);
172167

173168
const { text, truncation } = truncateAcpOutputText(
174169
output,
@@ -177,6 +172,16 @@ function serializeFastAgentToolOutput(result: unknown): {
177172
return { output: text, truncated: truncation !== null };
178173
}
179174

175+
function stringifyFastAgentToolOutput(result: unknown): string {
176+
let output: string;
177+
try {
178+
output = JSON.stringify(result, null, 2) ?? String(result);
179+
} catch {
180+
output = String(result);
181+
}
182+
return output;
183+
}
184+
180185
function getFastAgentDefaultSlackHistoryOldest(latest?: string): string {
181186
const numericLatest =
182187
latest && /^\d+(?:\.\d+)?$/.test(latest) ? Number(latest) : Number.NaN;
@@ -1426,7 +1431,10 @@ export async function answerFastAgentQuestion({
14261431
return result;
14271432
}
14281433

1429-
if (JSON.stringify(result).length > ACP_UI_TOOL_OUTPUT_MAX_CHARS) {
1434+
if (
1435+
stringifyFastAgentToolOutput(result).length >
1436+
ACP_UI_TOOL_OUTPUT_MAX_CHARS
1437+
) {
14301438
return {
14311439
success: false,
14321440
error: `The sanitized widget exceeds the Fast transcript limit of ${ACP_UI_TOOL_OUTPUT_MAX_CHARS} characters.`,

0 commit comments

Comments
 (0)