@@ -13,6 +13,7 @@ import path from "path"
1313import { Instance } from "@/project/instance"
1414import { Storage } from "@/storage/storage"
1515import { Bus } from "@/bus"
16+ import { mergeDeep , pipe } from "remeda"
1617
1718export namespace SessionSummary {
1819 const log = Log . create ( { service : "session.summary" } )
@@ -73,13 +74,18 @@ export namespace SessionSummary {
7374
7475 const assistantMsg = messages . find ( ( m ) => m . info . role === "assistant" ) ! . info as MessageV2 . Assistant
7576 const small = await Provider . getSmallModel ( assistantMsg . providerID )
76- if ( ! small ) return
77+ const options = pipe (
78+ { } ,
79+ mergeDeep ( ProviderTransform . options ( small . providerID , small . modelID , small . npm ?? "" , assistantMsg . sessionID ) ) ,
80+ mergeDeep ( ProviderTransform . smallOptions ( { providerID : small . providerID , modelID : small . modelID } ) ) ,
81+ mergeDeep ( small . info . options ) ,
82+ )
7783
7884 const textPart = msgWithParts . parts . find ( ( p ) => p . type === "text" && ! p . synthetic ) as MessageV2 . TextPart
7985 if ( textPart && ! userMsg . summary ?. title ) {
8086 const result = await generateText ( {
8187 maxOutputTokens : small . info . reasoning ? 1500 : 20 ,
82- providerOptions : ProviderTransform . providerOptions ( small . npm , small . providerID , { } ) ,
88+ providerOptions : ProviderTransform . providerOptions ( small . npm , small . providerID , options ) ,
8389 messages : [
8490 ...SystemPrompt . title ( small . providerID ) . map (
8591 ( x ) : ModelMessage => ( {
@@ -115,18 +121,28 @@ export namespace SessionSummary {
115121 . findLast ( ( m ) => m . info . role === "assistant" )
116122 ?. parts . findLast ( ( p ) => p . type === "text" ) ?. text
117123 if ( ! summary || diffs . length > 0 ) {
124+ for ( const msg of messages ) {
125+ for ( const part of msg . parts ) {
126+ if ( part . type === "tool" && part . state . status === "completed" ) {
127+ part . state . output = "[TOOL OUTPUT PRUNED]"
128+ }
129+ }
130+ }
118131 const result = await generateText ( {
119132 model : small . language ,
120133 maxOutputTokens : 100 ,
134+ providerOptions : ProviderTransform . providerOptions ( small . npm , small . providerID , options ) ,
121135 messages : [
136+ ...SystemPrompt . summarize ( small . providerID ) . map (
137+ ( x ) : ModelMessage => ( {
138+ role : "system" ,
139+ content : x ,
140+ } ) ,
141+ ) ,
142+ ...MessageV2 . toModelMessage ( messages ) ,
122143 {
123144 role : "user" ,
124- content : `
125- Summarize the following conversation into 2 sentences MAX explaining what the assistant did and why. Do not explain the user's input. Do not speak in the third person about the assistant.
126- <conversation>
127- ${ JSON . stringify ( MessageV2 . toModelMessage ( messages ) ) }
128- </conversation>
129- ` ,
145+ content : `Summarize the above conversation according to your system prompts.` ,
130146 } ,
131147 ] ,
132148 headers : small . info . headers ,
0 commit comments