mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-09-24 15:49:09 +00:00
b02d52516c
messageResponse pulled @streamdown/code on first markdown import, so opening a chat with history paid for the full highlighter even when the reply was just prose. Render with CJK only first. When a fence exists and the composer is idle, lazily import the isolated Shiki plugin.
25 lines
806 B
TypeScript
25 lines
806 B
TypeScript
import type { CodeHighlighterPlugin } from 'streamdown';
|
|
|
|
let cachedCodePlugin: CodeHighlighterPlugin | null = null;
|
|
let codePluginPromise: Promise<CodeHighlighterPlugin> | null = null;
|
|
|
|
export function getCachedStreamdownCodePlugin(): CodeHighlighterPlugin | null {
|
|
return cachedCodePlugin;
|
|
}
|
|
|
|
export function isAiCodeHighlighterReady(): boolean {
|
|
return cachedCodePlugin != null;
|
|
}
|
|
|
|
/** Prefetch Shiki only when a message actually contains a code fence. */
|
|
export function warmAiCodeHighlighter(): Promise<CodeHighlighterPlugin> {
|
|
codePluginPromise ??= import('./streamdownCodePlugin').then((module) => {
|
|
cachedCodePlugin = module.streamdownCodePlugin;
|
|
return module.streamdownCodePlugin;
|
|
}, (error) => {
|
|
codePluginPromise = null;
|
|
throw error;
|
|
});
|
|
return codePluginPromise;
|
|
}
|