MiniCPM5-2B-WebGPU-Pi-HTTP / app /src /pi /capabilities.mjs
Mike0021's picture
Enable browser HTTP commands with CORS-aware errors and bounded requests
39371ea verified
Raw History Blame Contribute Delete
1.39 kB
// xterm.js renders text/ANSI; this app does not install Kitty/iTerm image addons.
// Pi's native image module also probes tmux via child_process. Keep that host
// dependency out of the browser and advertise only capabilities we implement.
let capabilities = { images: null, trueColor: true, hyperlinks: true };
let dimensions = { widthPx: 8, heightPx: 16 };
export const getCapabilities = () => capabilities;
export const setCapabilities = value => { capabilities = { ...value, images: null }; };
export const getCellDimensions = () => dimensions;
export const setCellDimensions = value => { dimensions = value; };
export const isImageLine = () => false;
export const getKittyImagePlacement = () => undefined;
export const getKittyImageMetadata = () => undefined;
export const cropKittyImageLine = line => line;
export const deleteKittyImage = () => '';
export const deleteAllKittyImages = () => '';
export const deleteAllKittyPlacements = () => '';
export function hyperlink(text, url) {
// Generated text may contain arbitrary URLs. Only explicit user clicks open
// HTTP(S) links, and no terminal control bytes may enter their OSC envelope.
try {
const parsed = new URL(url);
if (!['https:', 'http:'].includes(parsed.protocol) || /[\x00-\x20\x7f-\x9f]/.test(url)) return text;
return `\x1b]8;;${parsed.href}\x07${text}\x1b]8;;\x07`;
} catch { return text; }
}