( ide: IDE, history: ChatMessage[], outputDir?: string, )
| 65 | } |
| 66 | |
| 67 | export async function shareSession( |
| 68 | ide: IDE, |
| 69 | history: ChatMessage[], |
| 70 | outputDir?: string, |
| 71 | ) { |
| 72 | const now = new Date(); |
| 73 | const content = toMarkDown(history, now); |
| 74 | |
| 75 | outputDir = outputDir ?? getContinueGlobalPath(); |
| 76 | |
| 77 | if (outputDir.startsWith("~")) { |
| 78 | outputDir = outputDir.replace(/^~/, homedir); |
| 79 | } else if ( |
| 80 | outputDir.startsWith("./") || |
| 81 | outputDir.startsWith(".\\") || |
| 82 | outputDir === "." |
| 83 | ) { |
| 84 | const workspaceDirs = await ide.getWorkspaceDirs(); |
| 85 | // Although the most common situation is to have one directory open in a |
| 86 | // workspace it's also possible to have just a file open without an |
| 87 | // associated directory or to use multi-root workspaces in which multiple |
| 88 | // folders are included. We default to using the first item in the list, if |
| 89 | // it exists. |
| 90 | const workspaceDirectory = workspaceDirs?.[0] || ""; |
| 91 | outputDir = outputDir.replace(/^./, fileURLToPath(workspaceDirectory)); |
| 92 | } |
| 93 | |
| 94 | if (!fs.existsSync(outputDir)) { |
| 95 | fs.mkdirSync(outputDir, { recursive: true }); |
| 96 | } |
| 97 | |
| 98 | const dtString = asBasicISOString(getOffsetDatetime(now)); |
| 99 | const outPath = path.join(outputDir, `${dtString}_session.md`); //TODO: more flexible naming? |
| 100 | |
| 101 | const fileUrl = pathToFileURL(outPath).toString(); // TODO switch from path to URI above ^ |
| 102 | await ide.writeFile(fileUrl, content); |
| 103 | await ide.openFile(fileUrl); |
| 104 | return fileUrl; |
| 105 | } |
no test coverage detected