@@ -10,6 +10,10 @@ interface FromConsoleView {
10
10
uuid : string ;
11
11
}
12
12
13
+ // Maximum interactions we retain; when we exceed this, we drop the
14
+ // oldest and also send a message to the view to do the same.
15
+ const MAX_INTERACTIONS = 50 ;
16
+
13
17
export class ContinueConsoleWebviewViewProvider
14
18
implements vscode . WebviewViewProvider
15
19
{
@@ -36,7 +40,7 @@ export class ContinueConsoleWebviewViewProvider
36
40
this . _webview ?. postMessage ( {
37
41
type : "init" ,
38
42
uuid : this . _currentUuid ,
39
- items : this . _items ,
43
+ items : this . getAllItems ( ) ,
40
44
} ) ;
41
45
}
42
46
} ) ;
@@ -50,7 +54,8 @@ export class ContinueConsoleWebviewViewProvider
50
54
private _webview ?: vscode . Webview ;
51
55
private _webviewView ?: vscode . WebviewView ;
52
56
private _currentUuid ?: string ;
53
- private _items : LLMInteractionItem [ ] = [ ] ;
57
+ private _currentInteractions = new Map < string , LLMInteractionItem [ ] > ( ) ;
58
+ private _completedInteractions : LLMInteractionItem [ ] [ ] = [ ] ;
54
59
private _saveLog ;
55
60
56
61
constructor (
@@ -71,24 +76,68 @@ export class ContinueConsoleWebviewViewProvider
71
76
}
72
77
} ) ;
73
78
74
- llmLogger . onLogItem ( ( item ) => {
75
- if ( ! this . _saveLog ) {
76
- return ;
77
- }
79
+ llmLogger . onLogItem ( ( item ) => this . addItem ( item ) ) ;
80
+ }
78
81
79
- this . _items . push ( item ) ;
80
- if ( this . _currentUuid ) {
81
- this . _webview ?. postMessage ( {
82
- type : "item" ,
83
- uuid : this . _currentUuid ,
84
- item,
85
- } ) ;
86
- }
87
- } ) ;
82
+ private addItem ( item : LLMInteractionItem ) {
83
+ if ( ! this . _saveLog ) {
84
+ return ;
85
+ }
86
+
87
+ let iteractionItems = this . _currentInteractions . get ( item . interactionId ) ;
88
+ if ( iteractionItems === undefined ) {
89
+ iteractionItems = [ ] ;
90
+ this . _currentInteractions . set ( item . interactionId , iteractionItems ) ;
91
+ }
92
+
93
+ iteractionItems . push ( item ) ;
94
+ switch ( item . kind ) {
95
+ case "success" :
96
+ case "cancel" :
97
+ case "error" :
98
+ this . _completedInteractions . push ( iteractionItems ) ;
99
+ this . _currentInteractions . delete ( item . interactionId ) ;
100
+ break ;
101
+ default :
102
+ break ;
103
+ }
104
+
105
+ if ( this . _currentUuid ) {
106
+ this . _webview ?. postMessage ( {
107
+ type : "item" ,
108
+ uuid : this . _currentUuid ,
109
+ item,
110
+ } ) ;
111
+ }
112
+
113
+ while (
114
+ this . _completedInteractions . length > 0 &&
115
+ this . _completedInteractions . length + this . _currentInteractions . size >
116
+ MAX_INTERACTIONS
117
+ ) {
118
+ let toRemove = this . _completedInteractions . shift ( ) ;
119
+ this . _webview ?. postMessage ( {
120
+ type : "remove" ,
121
+ uuid : this . _currentUuid ,
122
+ interactionId : toRemove ! [ 0 ] . interactionId ,
123
+ } ) ;
124
+ }
125
+ }
126
+
127
+ private getAllItems ( ) {
128
+ let items = this . _completedInteractions . flat ( ) ;
129
+
130
+ for ( const interactionItems of this . _currentInteractions . values ( ) ) {
131
+ items . push ( ...interactionItems ) ;
132
+ }
133
+
134
+ return items ;
88
135
}
89
136
90
137
clearLog ( ) {
91
- this . _items = [ ] ;
138
+ this . _completedInteractions = [ ] ;
139
+ this . _currentInteractions = new Map ( ) ;
140
+
92
141
if ( this . _currentUuid ) {
93
142
this . _webview ?. postMessage ( {
94
143
type : "clear" ,
0 commit comments