fix: preserve structured attachment outputs (#17)
This commit is contained in:
@@ -356,7 +356,7 @@ async function runQuery(
|
||||
writeOutput({
|
||||
status: 'success',
|
||||
phase: 'intermediate',
|
||||
result: pendingProgressText,
|
||||
...normalizeStructuredOutput(pendingProgressText),
|
||||
newSessionId,
|
||||
});
|
||||
pendingProgressText = null;
|
||||
|
||||
@@ -18,6 +18,7 @@ export type RunnerOutputVerdict =
|
||||
| 'done'
|
||||
| 'done_with_concerns'
|
||||
| 'blocked'
|
||||
| 'in_progress'
|
||||
| 'silent';
|
||||
|
||||
export type RunnerOutputVisibility = 'public' | 'silent';
|
||||
@@ -93,10 +94,20 @@ function isVisibleVerdict(
|
||||
value: unknown,
|
||||
): value is Exclude<RunnerOutputVerdict, 'silent'> {
|
||||
return (
|
||||
value === 'done' || value === 'done_with_concerns' || value === 'blocked'
|
||||
value === 'done' ||
|
||||
value === 'done_with_concerns' ||
|
||||
value === 'blocked' ||
|
||||
value === 'in_progress'
|
||||
);
|
||||
}
|
||||
|
||||
const LEADING_STRUCTURED_OUTPUT_CONTROL_RE =
|
||||
/^[\u0000-\u001F\u007F\u200B-\u200F\u202A-\u202E\u2060-\u206F\uFEFF]+/u;
|
||||
|
||||
function stripLeadingStructuredOutputControls(value: string): string {
|
||||
return value.replace(LEADING_STRUCTURED_OUTPUT_CONTROL_RE, '').trimStart();
|
||||
}
|
||||
|
||||
function normalizeAttachments(value: unknown): RunnerOutputAttachment[] {
|
||||
if (!Array.isArray(value)) return [];
|
||||
|
||||
@@ -138,7 +149,7 @@ export function normalizeEjclawStructuredOutput(
|
||||
return { result };
|
||||
}
|
||||
|
||||
const trimmed = result.trim();
|
||||
const trimmed = stripLeadingStructuredOutputControls(result.trim());
|
||||
const jsonCandidate = extractStructuredJsonCandidate(trimmed);
|
||||
try {
|
||||
const parsed = JSON.parse(jsonCandidate) as {
|
||||
|
||||
@@ -121,6 +121,77 @@ describe('shared agent protocol helpers', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('parses fenced ejclaw envelopes with leading invisible control characters', () => {
|
||||
expect(
|
||||
normalizeEjclawStructuredOutput(`\u2063\u2063\u2063\`\`\`json
|
||||
{
|
||||
"ejclaw": {
|
||||
"visibility": "public",
|
||||
"text": "최종 이미지를 첨부했습니다.",
|
||||
"verdict": "done",
|
||||
"attachments": [
|
||||
{
|
||||
"path": "/tmp/ejclaw-discord-image-final.png",
|
||||
"name": "final.png",
|
||||
"mime": "image/png"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
\`\`\``),
|
||||
).toEqual({
|
||||
result: '최종 이미지를 첨부했습니다.',
|
||||
output: {
|
||||
visibility: 'public',
|
||||
text: '최종 이미지를 첨부했습니다.',
|
||||
verdict: 'done',
|
||||
attachments: [
|
||||
{
|
||||
path: '/tmp/ejclaw-discord-image-final.png',
|
||||
name: 'final.png',
|
||||
mime: 'image/png',
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('parses in_progress public envelopes instead of leaking raw structured JSON', () => {
|
||||
const raw = JSON.stringify({
|
||||
ejclaw: {
|
||||
visibility: 'public',
|
||||
text: '이미지를 생성하는 중입니다.',
|
||||
verdict: 'in_progress',
|
||||
attachments: [
|
||||
{
|
||||
path: '/tmp/ejclaw-discord-image-draft.png',
|
||||
name: 'draft.png',
|
||||
mime: 'image/png',
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
const normalized = normalizeEjclawStructuredOutput(raw);
|
||||
|
||||
expect(normalized).toEqual({
|
||||
result: '이미지를 생성하는 중입니다.',
|
||||
output: {
|
||||
visibility: 'public',
|
||||
text: '이미지를 생성하는 중입니다.',
|
||||
verdict: 'in_progress',
|
||||
attachments: [
|
||||
{
|
||||
path: '/tmp/ejclaw-discord-image-draft.png',
|
||||
name: 'draft.png',
|
||||
mime: 'image/png',
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(normalized.result).not.toContain('"ejclaw"');
|
||||
});
|
||||
|
||||
it('parses unlabeled fenced ejclaw envelopes', () => {
|
||||
expect(
|
||||
normalizeEjclawStructuredOutput(`\`\`\`
|
||||
|
||||
Reference in New Issue
Block a user