@@ -12,6 +12,7 @@ import type {
1212 ProviderReplaySessionState ,
1313} from "../../plugins/types.js" ;
1414import {
15+ annotateInterSessionPromptText ,
1516 hasInterSessionUserProvenance ,
1617 normalizeInputProvenance ,
1718} from "../../sessions/input-provenance.js" ;
@@ -49,7 +50,6 @@ import {
4950 stripInvalidThinkingSignatures ,
5051} from "./thinking.js" ;
5152
52- const INTER_SESSION_PREFIX_BASE = "[Inter-session message]" ;
5353const MODEL_SNAPSHOT_CUSTOM_TYPE = "model-snapshot" ;
5454type CustomEntryLike = { type ?: unknown ; customType ?: unknown ; data ?: unknown } ;
5555type ModelSnapshotEntry = {
@@ -90,22 +90,6 @@ function createProviderReplayPluginParams(params: ProviderReplayHookParams) {
9090 } ;
9191}
9292
93- function buildInterSessionPrefix ( message : AgentMessage ) : string {
94- const provenance = normalizeInputProvenance ( ( message as { provenance ?: unknown } ) . provenance ) ;
95- if ( ! provenance ) {
96- return INTER_SESSION_PREFIX_BASE ;
97- }
98- const details = [
99- provenance . sourceSessionKey ? `sourceSession=${ provenance . sourceSessionKey } ` : undefined ,
100- provenance . sourceChannel ? `sourceChannel=${ provenance . sourceChannel } ` : undefined ,
101- provenance . sourceTool ? `sourceTool=${ provenance . sourceTool } ` : undefined ,
102- ] . filter ( Boolean ) ;
103- if ( details . length === 0 ) {
104- return INTER_SESSION_PREFIX_BASE ;
105- }
106- return `${ INTER_SESSION_PREFIX_BASE } ${ details . join ( " " ) } ` ;
107- }
108-
10993function annotateInterSessionUserMessages ( messages : AgentMessage [ ] ) : AgentMessage [ ] {
11094 let touched = false ;
11195 const out : AgentMessage [ ] = [ ] ;
@@ -114,17 +98,18 @@ function annotateInterSessionUserMessages(messages: AgentMessage[]): AgentMessag
11498 out . push ( msg ) ;
11599 continue ;
116100 }
117- const prefix = buildInterSessionPrefix ( msg ) ;
101+ const provenance = normalizeInputProvenance ( ( msg as { provenance ?: unknown } ) . provenance ) ;
118102 const user = msg as Extract < AgentMessage , { role : "user" } > ;
119103 if ( typeof user . content === "string" ) {
120- if ( user . content . startsWith ( prefix ) ) {
104+ const annotated = annotateInterSessionPromptText ( user . content , provenance ) ;
105+ if ( annotated === user . content ) {
121106 out . push ( msg ) ;
122107 continue ;
123108 }
124109 touched = true ;
125110 out . push ( {
126111 ...( msg as unknown as Record < string , unknown > ) ,
127- content : ` ${ prefix } \n ${ user . content } ` ,
112+ content : annotated ,
128113 } as AgentMessage ) ;
129114 continue ;
130115 }
@@ -143,14 +128,15 @@ function annotateInterSessionUserMessages(messages: AgentMessage[]): AgentMessag
143128
144129 if ( textIndex >= 0 ) {
145130 const existing = user . content [ textIndex ] as { type : "text" ; text : string } ;
146- if ( existing . text . startsWith ( prefix ) ) {
131+ const annotated = annotateInterSessionPromptText ( existing . text , provenance ) ;
132+ if ( annotated === existing . text ) {
147133 out . push ( msg ) ;
148134 continue ;
149135 }
150136 const nextContent = [ ...user . content ] ;
151137 nextContent [ textIndex ] = {
152138 ...existing ,
153- text : ` ${ prefix } \n ${ existing . text } ` ,
139+ text : annotated ,
154140 } ;
155141 touched = true ;
156142 out . push ( {
@@ -163,7 +149,13 @@ function annotateInterSessionUserMessages(messages: AgentMessage[]): AgentMessag
163149 touched = true ;
164150 out . push ( {
165151 ...( msg as unknown as Record < string , unknown > ) ,
166- content : [ { type : "text" , text : prefix } , ...user . content ] ,
152+ content : [
153+ {
154+ type : "text" ,
155+ text : annotateInterSessionPromptText ( "Inter-session content follows." , provenance ) ,
156+ } ,
157+ ...user . content ,
158+ ] ,
167159 } as AgentMessage ) ;
168160 }
169161 return touched ? out : messages ;
0 commit comments