MCPcopy Index your code
hub / github.com/continuedev/continue / getSessionMetadataWithPreview

Function getSessionMetadataWithPreview

extensions/cli/src/session.ts:399–439  ·  view source on GitHub ↗

* Get metadata from a session file with first user message preview

(
  filePath: string,
)

Source from the content-addressed store, hash-verified

397 * Get metadata from a session file with first user message preview
398 */
399function getSessionMetadataWithPreview(
400 filePath: string,
401): ExtendedSessionMetadata | null {
402 try {
403 const sessionData: Session = JSON.parse(fs.readFileSync(filePath, "utf8"));
404 const stats = fs.statSync(filePath);
405
406 // Find the first user message for preview
407 let firstUserMessage: string | undefined;
408 for (const item of sessionData.history || []) {
409 if (item.message.role === "user") {
410 const content = item.message.content;
411 // Handle both string and array content types
412 if (typeof content === "string") {
413 firstUserMessage = content;
414 } else if (Array.isArray(content)) {
415 // For array content, find the first text part
416 const textPart = content.find((part) => part.type === "text");
417 firstUserMessage =
418 textPart && "text" in textPart
419 ? textPart.text
420 : "(multimodal message)";
421 } else {
422 firstUserMessage = "(unknown content type)";
423 }
424 break;
425 }
426 }
427
428 return {
429 sessionId: sessionData.sessionId,
430 title: sessionData.title || DEFAULT_SESSION_TITLE,
431 dateCreated: stats.birthtime.toISOString(),
432 workspaceDirectory: sessionData.workspaceDirectory || "",
433 firstUserMessage,
434 };
435 } catch (error) {
436 logger.error(`Error reading session file ${filePath}:`, error);
437 return null;
438 }
439}
440
441/**
442 * Remote sessions are no longer available (Hub integration removed).

Callers 1

listSessionsFunction · 0.85

Calls 1

errorMethod · 0.80

Tested by

no test coverage detected