@@ -19,11 +19,12 @@ import {
19
19
WebviewProtocol ,
20
20
} from "core/web/webviewProtocol" ;
21
21
import fs from "fs" ;
22
- import path from "path" ;
22
+ import * as path from "path" ;
23
23
import { v4 as uuidv4 } from "uuid" ;
24
24
import * as vscode from "vscode" ;
25
25
import { VerticalPerLineDiffManager } from "./diff/verticalPerLine/manager" ;
26
26
import { getExtensionUri } from "./util/vscode" ;
27
+ import { stripImages } from "../../../core/llm/countTokens" ;
27
28
28
29
async function showTutorial ( ) {
29
30
const tutorialPath = path . join (
@@ -248,6 +249,36 @@ export class VsCodeWebviewProtocol {
248
249
this . on ( "saveFile" , async ( msg ) => {
249
250
return await ide . saveFile ( msg . data . filepath ) ;
250
251
} ) ;
252
+ this . on ( "saveSessionChatHistory" , async ( msg ) => {
253
+ const datetime = new Date ( ) ;
254
+ const year = datetime . getFullYear ( ) ;
255
+ const month = String ( datetime . getMonth ( ) + 1 ) . padStart ( 2 , '0' ) ;
256
+ const day = String ( datetime . getDate ( ) ) . padStart ( 2 , '0' ) ;
257
+ const hours = String ( datetime . getHours ( ) ) . padStart ( 2 , '0' ) ;
258
+ const minutes = String ( datetime . getMinutes ( ) ) . padStart ( 2 , '0' ) ;
259
+ const seconds = String ( datetime . getSeconds ( ) ) . padStart ( 2 , '0' ) ;
260
+
261
+ const datetime_filename = `${ year } ${ month } ${ day } _${ hours } ${ minutes } ${ seconds } ` ;
262
+
263
+ let content = `This is a session transcript from Ahrefs-Continue on ${ datetime . toLocaleString ( ) } .` ;
264
+
265
+ for ( const m of msg . data . chatHistory ) {
266
+ content += `\n\n## ${
267
+ m . message . role === "user" ? "User" : `Ahrefs-Continue: ${ msg . data . defaultTitle } `
268
+ } \n\n${ stripImages ( m . message . content ) } `;
269
+ }
270
+
271
+ const continueDir = await ide . getContinueDir ( ) ;
272
+ const savedSessionsPath = `${ continueDir } /saved_sessions`
273
+ if ( ! fs . existsSync ( savedSessionsPath ) ) {
274
+ fs . mkdirSync ( savedSessionsPath ) ;
275
+ }
276
+ const path = `${ savedSessionsPath } /${ datetime_filename } _session.md` ;
277
+ await ide . writeFile ( path , content ) ;
278
+ await ide . openFile ( path ) ;
279
+
280
+ vscode . window . showInformationMessage ( `Chat session saved to ${ path } ` ) ;
281
+ } )
251
282
this . on ( "readFile" , async ( msg ) => {
252
283
return await ide . readFile ( msg . data . filepath ) ;
253
284
} ) ;
0 commit comments