MCPcopy
hub / github.com/continuedev/continue / shareSession

Function shareSession

core/util/historyUtils.ts:67–105  ·  view source on GitHub ↗
(
  ide: IDE,
  history: ChatMessage[],
  outputDir?: string,
)

Source from the content-addressed store, hash-verified

65}
66
67export 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}

Callers 2

share.tsFile · 0.50

Calls 8

toMarkDownFunction · 0.85
getContinueGlobalPathFunction · 0.85
asBasicISOStringFunction · 0.85
getOffsetDatetimeFunction · 0.85
getWorkspaceDirsMethod · 0.65
writeFileMethod · 0.65
openFileMethod · 0.65
replaceMethod · 0.45

Tested by

no test coverage detected