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

Function handleVis

apps/kimi-code/src/cli/sub/vis.ts:51–101  ·  view source on GitHub ↗
(deps: VisDeps, opts: VisOptions)

Source from the content-addressed store, hash-verified

49}
50
51export async function handleVis(deps: VisDeps, opts: VisOptions): Promise<void> {
52 const homeDir = deps.getHomeDir();
53
54 // Lazily load the embedded single-file SPA so normal `kimi` startup never
55 // pays for it. The module is generated at build time (prebuild). When running
56 // from source without a build — e.g. tests — the generated value module is
57 // absent and the dynamic import throws; in that case the server falls back to
58 // its own static `public/` directory.
59 let webAsset: { gzipped: Uint8Array } | undefined;
60 try {
61 const { VIS_WEB_GZIP_B64 } = await import('#/generated/vis-web-asset');
62 if (VIS_WEB_GZIP_B64.length > 0) {
63 webAsset = { gzipped: new Uint8Array(Buffer.from(VIS_WEB_GZIP_B64, 'base64')) };
64 }
65 } catch {
66 // Embedded asset not generated in this context — fall back to filesystem.
67 }
68
69 let server: StartedVisServer;
70 try {
71 server = await deps.startVisServer({
72 homeDir,
73 port: opts.port ?? 0,
74 ...(opts.host === undefined ? {} : { host: opts.host }),
75 ...(webAsset === undefined ? {} : { webAsset }),
76 });
77 } catch (error) {
78 const msg = error instanceof Error ? error.message : String(error);
79 deps.stderr.write(`Failed to start kimi vis: ${msg}\n`);
80 return deps.exit(1);
81 }
82
83 const target =
84 opts.sessionId === undefined
85 ? server.url
86 : `${server.url}sessions/${encodeURIComponent(opts.sessionId)}`;
87
88 deps.stdout.write(`kimi vis is running at ${server.url}\n`);
89 deps.stdout.write('Press Ctrl-C to stop.\n');
90
91 if (opts.open) {
92 try {
93 await deps.openUrl(target);
94 } catch {
95 deps.stderr.write(`Could not open a browser; visit ${target} manually.\n`);
96 }
97 }
98
99 await deps.waitForShutdown();
100 await server.close();
101}
102
103export function registerVisCommand(parent: Command, overrides?: Partial<VisDeps>): void {
104 parent

Callers 2

vis.test.tsFile · 0.90
registerVisCommandFunction · 0.85

Calls 4

writeMethod · 0.65
exitMethod · 0.65
openUrlMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected