Jinal-Sarvaiya commented on code in PR #150:
URL: https://github.com/apache/camel-kit/pull/150#discussion_r4452986934
##########
kit/camel-kit-core/src/main/java/org/apache/camel/kit/ship/controller/ShipStageResult.java:
##########
@@ -77,8 +80,9 @@ static ShipStageResult parse(Stage stage, String
assistantText) throws IOExcepti
WireResult wire;
boolean legacy = false;
try {
+ String normalized = extractJsonObject(assistantText);
JsonNode document
- = JSON.readValue(utf8(assistantText, MAX_ASSISTANT_BYTES,
"assistant response"), JsonNode.class);
+ = JSON.readValue(utf8(normalized, MAX_ASSISTANT_BYTES,
"assistant response"), JsonNode.class);
Review Comment:
Fixed — \`utf8()\` now runs on the raw \`assistantText\` before
\`extractJsonObject()\`, so oversized prose or lone surrogates outside a fence
are caught before extraction. Covered by
\`rejectsOversizedProseAroundValidFence\`,
\`rejectsInvalidUnicodeOutsideFence\`."
##########
kit/camel-kit-core/src/main/java/org/apache/camel/kit/ship/controller/ShipStageResult.java:
##########
@@ -280,6 +284,26 @@ private static void requireReport(String report) throws
IOException {
utf8(report, MAX_REPORT_BYTES, "stage report");
}
+ private static String extractJsonObject(String text) {
+ if (text == null) {
+ return text;
+ }
+ String stripped = text.strip();
+ if (stripped.startsWith("{")) {
+ return stripped;
+ }
+ Matcher m = JSON_FENCE.matcher(text);
+ if (m.find()) {
+ return m.group(1).strip();
Review Comment:
Fixed — \`extractJsonObject()\` now returns the raw stripped text
(triggering downstream rejection) when it detects a second fenced block or an
array \`[\` prefix before the first brace. Covered by
\`rejectsConflictingFencedEnvelopes\`, \`rejectsArrayWrappedEnvelope\`."
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]