@@ -56,10 +56,8 @@ export interface Miss extends Change {
5656
5757const INLINE_DATA_MIN = 1024
5858
59- // Cache hints only steer breakpoints and metadata never reaches the provider, so neither affects the cached prefix.
6059// Inline media is summarized by type and size so hashing stays fast; replacing or cutting it still changes the hash.
6160const replacer = ( key : string , value : unknown ) => {
62- if ( key === "cache" || key === "metadata" ) return undefined
6361 if ( key === "source" && value && typeof value === "object" && "data" in value ) {
6462 const source = value as { type : string ; mediaType ?: string ; data : string | Uint8Array }
6563 const size = typeof source . data === "string" ? source . data . length : source . data . byteLength
@@ -85,10 +83,19 @@ const isCheckpoint = (message: Message) =>
8583 ( part ) => part . type === "compaction" || ( part . type === "text" && part . text . startsWith ( "<conversation-checkpoint>" ) ) ,
8684 )
8785
86+ // Message and part cache hints only steer breakpoints and their metadata never reaches the provider, so neither affects
87+ // the cached prefix. Same-named keys inside schemas, tool inputs and results do, so only these levels are stripped.
88+ const prefixOf = ( message : Message ) => ( {
89+ ...message ,
90+ cache : undefined ,
91+ metadata : undefined ,
92+ content : message . content . map ( ( part ) => ( { ...part , cache : undefined , metadata : undefined } ) ) ,
93+ } )
94+
8895const printMessage = ( message : Message ) : MessagePrint => ( {
8996 key : messageKey ( message ) ,
9097 role : message . role ,
91- hash : hash ( message ) ,
98+ hash : hash ( prefixOf ( message ) ) ,
9299 media : message . content . reduce ( ( total , part ) => total + mediaCount ( part ) , 0 ) ,
93100 checkpoint : isCheckpoint ( message ) ,
94101} )
0 commit comments