Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/daemon/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,15 @@ export async function handleResponse(
format: 'json' | 'md',
): Promise<string> {
if (response.isError) {
if (format === 'md') {
const chunks = [];
for (const content of response.content) {
if (content.type === 'text') {
chunks.push(content.text);
}
}
return chunks.join(' ');
}
return JSON.stringify(response.content);
}
const chunks = [];
Expand Down
13 changes: 12 additions & 1 deletion tests/daemon/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,24 @@ describe('daemon client', () => {
);
});

it('handles error response when isError is true', async () => {
it('handles error response when isError is true with md format', async () => {
const errorResponse = {
isError: true,
content: [{type: 'text' as const, text: 'Something went wrong'}],
};
assert.strictEqual(
await handleResponse(errorResponse, 'md'),
'Something went wrong',
);
});

it('handles error response when isError is true with json format', async () => {
const errorResponse = {
isError: true,
content: [{type: 'text' as const, text: 'Something went wrong'}],
};
assert.strictEqual(
await handleResponse(errorResponse, 'json'),
JSON.stringify(errorResponse.content),
);
});
Expand Down
Loading