1/* Code snippets reference the SDK as @miso.ai/client-sdk@latest â a valid URL 2 (jsdelivr resolves it), so it is also the graceful fallback. This script 3 swaps "@latest" for the real version number so readers see (and copy) a 4 pinned URL. The version comes from the npm registry's dist-tags, the same 5 endpoint npm-version-element uses. Docs pages render as a SPA, so newly 6 rendered content is patched via a MutationObserver, not just on load. */ 7(() => { 8 const PKG = '@miso.ai/client-sdk'; 9 const NEEDLE = PKG + '@latest'; 10 11 let version = null; 12 let fetching = null; 13 const fetchVersion = () => 14 (fetching ||= fetch('https://registry.npmjs.org/' + PKG) 15 .then((res) => res.json()) 16 .then((data) => (version = data['dist-tags'].latest)) 17 .catch(() => null)); 18 19 /* The needle always sits inside a single text node (a highlighted string 20 token), so a text-node walk is enough. */ 21 const patch = () => { 22 if (!version || !document.body) return; 23 const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT); 24 for (let node; (node = walker.nextNode()); ) { 25 if (node.nodeValue.includes(NEEDLE)) { 26 node.nodeValue = node.nodeValue.replaceAll(NEEDLE, PKG + '@' + version); 27 } 28 } 29 }; 30 31 let queued = false; 32 const run = () => { 33 queued = false; 34 if (!document.body || !document.body.textContent.includes(NEEDLE)) return; 35 version ? patch() : fetchVersion().then(patch); 36 }; 37 const schedule = () => { 38 if (queued) return; 39 queued = true; 40 requestAnimationFrame(run); 41 }; 42 43 const start = () => { 44 schedule(); 45 new MutationObserver(schedule).observe(document.body, { 46 childList: true, 47 subtree: true, 48 }); 49 }; 50 document.body 51 ? start() 52 : document.addEventListener('DOMContentLoaded', start); 53})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.