MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / importSessionZip

Function importSessionZip

apps/vis/server/src/lib/import-store.ts:49–84  ·  view source on GitHub ↗
(
  home: string,
  zipBuffer: Buffer,
  originalName: string | null,
  now: Date,
)

Source from the content-addressed store, hash-verified

47 * `import-meta.json` contents.
48 */
49export async function importSessionZip(
50 home: string,
51 zipBuffer: Buffer,
52 originalName: string | null,
53 now: Date,
54): Promise<ImportInfo> {
55 const importId = newImportId();
56 const dir = importedDirOf(home, importId);
57 await mkdir(dir, { recursive: true });
58
59 try {
60 await extractZip(zipBuffer, dir);
61
62 // A debug bundle must contain a main wire; without it there is nothing to
63 // visualize. `state.json` / `manifest.json` are best-effort.
64 const hasMainWire = await pathExists(join(dir, 'agents', 'main', 'wire.jsonl'));
65 if (!hasMainWire) {
66 throw new ZipImportError(
67 'zip does not look like a kimi-code session bundle (missing agents/main/wire.jsonl)',
68 );
69 }
70
71 const manifest = await readManifest(dir);
72 const meta: ImportInfo = {
73 importId,
74 importedAt: now.toISOString(),
75 originalName: originalName !== null && originalName.length > 0 ? originalName : null,
76 manifest,
77 };
78 await writeFile(join(dir, META_FILE), JSON.stringify(meta, null, 2), 'utf8');
79 return meta;
80 } catch (error) {
81 await rm(dir, { recursive: true, force: true }).catch(() => {});
82 throw error instanceof ZipImportError ? error : new ZipImportError((error as Error).message);
83 }
84}
85
86/** Enumerate imported bundle ids (newest-first by directory mtime). */
87export async function listImportedIds(home: string): Promise<string[]> {

Callers 2

importsRouteFunction · 0.90

Calls 7

extractZipFunction · 0.90
newImportIdFunction · 0.85
importedDirOfFunction · 0.85
readManifestFunction · 0.85
pathExistsFunction · 0.70
mkdirFunction · 0.50
writeFileFunction · 0.50

Tested by

no test coverage detected