@@ -3,6 +3,14 @@ import os from "os"
33import * as path from "path"
44import * as vscode from "vscode"
55
6+ // Extended content block types to support new Anthropic API features
7+ interface ReasoningBlock {
8+ type : "reasoning"
9+ text : string
10+ }
11+
12+ type ExtendedContentBlock = Anthropic . Messages . ContentBlockParam | ReasoningBlock
13+
614export async function downloadTask ( dateTs : number , conversationHistory : Anthropic . MessageParam [ ] ) {
715 // File name
816 const date = new Date ( dateTs )
@@ -22,7 +30,7 @@ export async function downloadTask(dateTs: number, conversationHistory: Anthropi
2230 . map ( ( message ) => {
2331 const role = message . role === "user" ? "**User:**" : "**Assistant:**"
2432 const content = Array . isArray ( message . content )
25- ? message . content . map ( ( block ) => formatContentBlockToMarkdown ( block ) ) . join ( "\n" )
33+ ? message . content . map ( ( block ) => formatContentBlockToMarkdown ( block as ExtendedContentBlock ) ) . join ( "\n" )
2634 : message . content
2735 return `${ role } \n\n${ content } \n\n`
2836 } )
@@ -41,7 +49,7 @@ export async function downloadTask(dateTs: number, conversationHistory: Anthropi
4149 }
4250}
4351
44- export function formatContentBlockToMarkdown ( block : Anthropic . Messages . ContentBlockParam ) : string {
52+ export function formatContentBlockToMarkdown ( block : ExtendedContentBlock ) : string {
4553 switch ( block . type ) {
4654 case "text" :
4755 return block . text
@@ -51,7 +59,13 @@ export function formatContentBlockToMarkdown(block: Anthropic.Messages.ContentBl
5159 let input : string
5260 if ( typeof block . input === "object" && block . input !== null ) {
5361 input = Object . entries ( block . input )
54- . map ( ( [ key , value ] ) => `${ key . charAt ( 0 ) . toUpperCase ( ) + key . slice ( 1 ) } : ${ value } ` )
62+ . map ( ( [ key , value ] ) => {
63+ const formattedKey = key . charAt ( 0 ) . toUpperCase ( ) + key . slice ( 1 )
64+ // Handle nested objects/arrays by JSON stringifying them
65+ const formattedValue =
66+ typeof value === "object" && value !== null ? JSON . stringify ( value , null , 2 ) : String ( value )
67+ return `${ formattedKey } : ${ formattedValue } `
68+ } )
5569 . join ( "\n" )
5670 } else {
5771 input = String ( block . input )
@@ -72,8 +86,10 @@ export function formatContentBlockToMarkdown(block: Anthropic.Messages.ContentBl
7286 return `[${ toolName } ${ block . is_error ? " (Error)" : "" } ]`
7387 }
7488 }
89+ case "reasoning" :
90+ return `[Reasoning]\n${ block . text } `
7591 default :
76- return " [Unexpected content type]"
92+ return ` [Unexpected content type: ${ block . type } ]`
7793 }
7894}
7995
0 commit comments