Download apps/vis/server/src/routes/wire.ts from SaylorTwift/kimi-code: direct link, hf CLI and curl.
- Browser
- Download file 1.69 kB
-
https://huggingface.co/SaylorTwift/kimi-code/resolve/main/apps/vis/server/src/routes/wire.ts
- Command line
-
hf download hf://SaylorTwift/kimi-code/apps/vis/server/src/routes/wire.ts
-
curl -L -o wire.ts https://huggingface.co/SaylorTwift/kimi-code/resolve/main/apps/vis/server/src/routes/wire.ts
1.69 kB
| import { Hono } from 'hono'; | |
| import { join } from 'node:path'; | |
| import { KIMI_CODE_HOME } from '../config'; | |
| import { isSafeAgentId, readSessionDetail } from '../lib/session-store'; | |
| import { rehydrateWireEntries } from '../lib/blob-resolver'; | |
| import { readAgentWire } from '../lib/wire-reader'; | |
| export function wireRoute(home: string = KIMI_CODE_HOME): Hono { | |
| const r = new Hono(); | |
| r.get('/:id/wire', async (c) => { | |
| const id = c.req.param('id'); | |
| const agentId = c.req.query('agent') ?? 'main'; | |
| if (!isSafeAgentId(agentId)) { | |
| return c.json({ error: 'invalid agent id', code: 'BAD_REQUEST' }, 400); | |
| } | |
| const detail = await readSessionDetail(home, id); | |
| if (!detail) { | |
| return c.json({ error: 'session not found', code: 'NOT_FOUND' }, 404); | |
| } | |
| const agent = detail.agents.find((a) => a.agentId === agentId); | |
| if (!agent) { | |
| return c.json({ error: `agent "${agentId}" not found`, code: 'NOT_FOUND' }, 404); | |
| } | |
| if (!agent.wireExists) { | |
| return c.json({ error: 'wire missing', code: 'NOT_FOUND' }, 404); | |
| } | |
| try { | |
| const result = await readAgentWire( | |
| join(detail.sessionDir, 'agents', agentId, 'wire.jsonl'), | |
| ); | |
| const baseUrl = new URL(c.req.url).origin; | |
| rehydrateWireEntries(result.records, id, agentId, baseUrl); | |
| return c.json({ | |
| sessionId: id, | |
| agentId, | |
| protocolVersion: result.metadata.protocolVersion, | |
| metadata: result.metadata, | |
| records: result.records, | |
| warnings: result.warnings, | |
| }); | |
| } catch (err) { | |
| const msg = (err as Error).message; | |
| return c.json({ error: msg, code: 'READ_ERROR' }, 500); | |
| } | |
| }); | |
| return r; | |
| } | |