From 97f86e564f7cad21820931e01def1bfd4091ca89 Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Mon, 27 Jan 2025 21:32:50 -0500 Subject: [PATCH] dev: oh my Claude Sometimes tool use requests are streamed as JSON, but sometimes they're streamed as an empty string (causing the JSON parser to error). Had they not streamed anything we actually would've responded correctly, but what they stream implies "this empty string is the JSON input" which is incorrect. Oh well. --- src/backend/src/modules/puterai/ClaudeService.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/backend/src/modules/puterai/ClaudeService.js b/src/backend/src/modules/puterai/ClaudeService.js index 363c9efae..55ce2d4ae 100644 --- a/src/backend/src/modules/puterai/ClaudeService.js +++ b/src/backend/src/modules/puterai/ClaudeService.js @@ -209,6 +209,13 @@ class ClaudeService extends BaseService { on_event: (event) => { if ( event.type === 'content_block_stop' ) { state = STATES.ready; + + // Yeah... claude will send an empty string instead of + // an empty object when there's no input. So we have to + // check for that. Good job, Anthropic. + if ( buffer === '' ) { + buffer = '{}'; + } const str = JSON.stringify({ tool_use: { ...content_block,