Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c00e9bc

Browse files
minor tweaking
1 parent cd08459 commit c00e9bc

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

‎packages/core/src/utils/anthropic-ai/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function addResponseAttributes(span: Span, response: AnthropicAiResponse, record
103103
span.setAttributes({
104104
[GEN_AI_RESPONSE_TEXT_ATTRIBUTE]: response.content
105105
.map((item: ContentBlock) => item.text)
106-
.filter((text): text is string=> text!==undefined)
106+
.filter(text=> !!text)
107107
.join(''),
108108
});
109109

‎packages/core/src/utils/anthropic-ai/streaming.ts‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function handleMessageMetadata(event: AnthropicAiStreamingEvent, state: Streamin
117117
*/
118118
function handleContentBlockStart(event: AnthropicAiStreamingEvent, state: StreamingState): void {
119119
if (event.type !== 'content_block_start' || typeof event.index !== 'number' || !event.content_block) return;
120-
if (event.content_block.type === 'tool_use') {
120+
if (event.content_block.type === 'tool_use'||event.content_block.type==='server_tool_use') {
121121
state.activeToolBlocks[event.index] = {
122122
id: event.content_block.id,
123123
name: event.content_block.name,
@@ -164,7 +164,13 @@ function handleContentBlockStop(event: AnthropicAiStreamingEvent, state: Streami
164164
if (!active) return;
165165

166166
const raw = active.inputJsonParts.join('');
167-
const parsedInput = raw ? JSON.parse(raw) : {};
167+
let parsedInput: unknown;
168+
169+
try {
170+
parsedInput = raw ? JSON.parse(raw) : {};
171+
} catch (error) {
172+
parsedInput = { __unparsed: raw };
173+
}
168174

169175
state.toolCalls.push({
170176
type: 'tool_use',
@@ -173,9 +179,8 @@ function handleContentBlockStop(event: AnthropicAiStreamingEvent, state: Streami
173179
input: parsedInput,
174180
});
175181

176-
// Avoid deleting a dynamic key; rebuild the map without this index
177-
const remainingEntries = Object.entries(state.activeToolBlocks).filter(([key]) => key !== String(event.index));
178-
state.activeToolBlocks = Object.fromEntries(remainingEntries);
182+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
183+
delete state.activeToolBlocks[event.index];
179184
}
180185

181186
/**

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /