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

Function blobsRoute

apps/vis/server/src/routes/blobs.ts:9–45  ·  view source on GitHub ↗
(home: string = KIMI_CODE_HOME)

Source from the content-addressed store, hash-verified

7import { isSafeBlobHash } from '../lib/blob-resolver';
8
9export function blobsRoute(home: string = KIMI_CODE_HOME): Hono {
10 const r = new Hono();
11 r.get('/:id/blobs/:hash', async (c) => {
12 const id = c.req.param('id');
13 const agentId = c.req.query('agent') ?? 'main';
14 const hash = c.req.param('hash');
15 if (!isSafeAgentId(agentId)) {
16 return c.json({ error: 'invalid agent id', code: 'BAD_REQUEST' }, 400);
17 }
18 if (!isSafeBlobHash(hash)) {
19 return c.json({ error: 'invalid blob hash', code: 'BAD_REQUEST' }, 400);
20 }
21 const detail = await readSessionDetail(home, id);
22 if (!detail) {
23 return c.json({ error: 'session not found', code: 'NOT_FOUND' }, 404);
24 }
25 const agent = detail.agents.find((a) => a.agentId === agentId);
26 if (!agent) {
27 return c.json(
28 { error: `agent "${agentId}" not found`, code: 'NOT_FOUND' },
29 404,
30 );
31 }
32 const blobPath = join(agent.homedir, 'blobs', hash);
33 let content: Buffer;
34 try {
35 content = await readFile(blobPath);
36 } catch {
37 return c.json({ error: 'blob not found', code: 'NOT_FOUND' }, 404);
38 }
39 const mimeType = c.req.query('mime') ?? 'application/octet-stream';
40 return new Response(content, {
41 headers: { 'content-type': mimeType },
42 });
43 });
44 return r;
45}

Callers 2

blobs.test.tsFile · 0.90
createAppFunction · 0.90

Calls 6

isSafeAgentIdFunction · 0.90
isSafeBlobHashFunction · 0.90
readSessionDetailFunction · 0.90
jsonMethod · 0.80
getMethod · 0.65
readFileFunction · 0.50

Tested by

no test coverage detected