@kanonak-protocol/sdk 3.67.0 → 3.68.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -62,7 +62,7 @@ var b=document.createElement('button');b.type='button';b.className='kan-dgm-btn'
62
62
  b.style.cssText='position:absolute;top:6px;right:6px;z-index:3;border:1px solid var(--kan-border,#333);background:var(--kan-bg-card,#111);color:var(--kan-text,#ccc);border-radius:6px;width:28px;height:28px;cursor:pointer;font-size:15px;line-height:1;padding:0';
63
63
  b.addEventListener('click',function(ev){ev.preventDefault();ev.stopPropagation();open(c);});c.appendChild(b);})(cs[i]);}}
64
64
  if(document.readyState!=='loading')enhance();else document.addEventListener('DOMContentLoaded',enhance);
65
- })();`,Oe={chip:56,icon:120,card:240,full:420},Rt=["chip","icon","card","full"],yt={56:"chip",120:"icon",240:"card",420:"full"},fe=11,Kt={publisher:"kanonak.org",package_:"look",name:"placement"},xt={publisher:"kanonak.org",package_:"look",name:"width"},Lt=4,wt={publisher:"kanonak.org",package_:"look",name:"StatRow"},Ot={publisher:"kanonak.org",package_:"look",name:"Horizon"},Et={publisher:"kanonak.org",package_:"look",name:"PackageContents"},We={publisher:"kanonak.org",package_:"core-kanonak",name:"Package"},It={publisher:"kanonak.org",package_:"core-kanonak",name:"Publisher"},Ut={publisher:"kanonak.org",package_:"look",name:"FeaturedResource"},Ft={publisher:"kanonak.org",package_:"look",name:"PublisherPackages"},Tt={publisher:"kanonak.org",package_:"look",name:"packages"},Ct={publisher:"kanonak.org",package_:"code-grammars",name:"CodeGrammar"},At={publisher:"kanonak.org",package_:"code-grammars",name:"language"},Mt={publisher:"kanonak.org",package_:"code-grammars",name:"rule"},Dt={publisher:"kanonak.org",package_:"code-grammars",name:"tokenClass"},Nt={publisher:"kanonak.org",package_:"code-grammars",name:"pattern"},Pt={publisher:"kanonak.org",package_:"look",name:"Links"},Vt={publisher:"kanonak.org",package_:"link",name:"url"},Ht={publisher:"kanonak.org",package_:"link",name:"links"};var Bt={publisher:"kanonak.org",package_:"look",name:"Distribution"},Gt={publisher:"kanonak.org",package_:"look",name:"alphaPath"},zt={publisher:"kanonak.org",package_:"look",name:"betaPath"},Ye={publisher:"kanonak.org",package_:"look",name:"SectionHeading"},Wt={publisher:"kanonak.org",package_:"look",name:"SectionNav"},mn={publisher:"kanonak.org",package_:"look",name:"heading"},Yt={publisher:"kanonak.org",package_:"look",name:"note"},qt={publisher:"kanonak.org",package_:"look",name:"VersionDelta"},Xt={publisher:"kanonak.org",package_:"look",name:"TimePlot"},Zt={publisher:"kanonak.org",package_:"look",name:"Details"},Jt={publisher:"kanonak.org",package_:"look",name:"EmbeddedViews"},Qt={publisher:"kanonak.org",package_:"look",name:"skip"},ea={publisher:"kanonak.org",package_:"derivation",name:"derivations"},na={publisher:"kanonak.org",package_:"look",name:"laneBy"},ta={publisher:"kanonak.org",package_:"look",name:"stats"},aa={publisher:"kanonak.org",package_:"look",name:"statPath"},sa={publisher:"kanonak.org",package_:"look",name:"statLabel"},hn={publisher:"kanonak.org",package_:"look",name:"labelPath"},oa={publisher:"kanonak.org",package_:"look",name:"badgePath"},qe={publisher:"kanonak.org",package_:"look",name:"orderBy"},bn={publisher:"kanonak.org",package_:"look",name:"track"},Fe={publisher:"kanonak.org",package_:"look",name:"metricPath"},Xe={publisher:"kanonak.org",package_:"look",name:"hueBy"},vn={publisher:"kanonak.org",package_:"look",name:"lowerPath"},$n={publisher:"kanonak.org",package_:"look",name:"upperPath"},ra={publisher:"kanonak.org",package_:"look",name:"axisMin"},ia={publisher:"kanonak.org",package_:"look",name:"axisMax"},ca={publisher:"kanonak.org",package_:"look",name:"valueLabel"};var _n={publisher:"kanonak.org",package_:"look",name:"semanticSvg"},la={publisher:"kanonak.org",package_:"look",name:"tierChip"},ua={publisher:"kanonak.org",package_:"look",name:"tierIcon"},da={publisher:"kanonak.org",package_:"look",name:"tierCard"},pa={publisher:"kanonak.org",package_:"look",name:"tierFull"},fa={publisher:"kanonak.org",package_:"core-rdf",name:"type"},jn=6,Ze={publisher:"kanonak.org",package_:"look",name:"bands"},ga={publisher:"kanonak.org",package_:"look",name:"title"},ka={publisher:"kanonak.org",package_:"look",name:"eyebrow"},ma={publisher:"kanonak.org",package_:"look",name:"subtitle"},Sn={publisher:"kanonak.org",package_:"look",name:"badges"},ae={publisher:"kanonak.org",package_:"look",name:"source"},ha={publisher:"kanonak.org",package_:"look",name:"via"},ba={publisher:"kanonak.org",package_:"look",name:"size"},va={publisher:"kanonak.org",package_:"look",name:"icon"},$a={publisher:"kanonak.org",package_:"look",name:"avatar"},_a={publisher:"kanonak.org",package_:"look",name:"contents"},ja={publisher:"kanonak.org",package_:"look",name:"transitive"},Sa={publisher:"kanonak.org",package_:"look",name:"chips"},Rn={publisher:"kanonak.org",package_:"look",name:"entries"},Ra={publisher:"kanonak.org",package_:"look",name:"urlForm"},tn=class{constructor(e){this.catalog=e}catalog;linkMode="single-publisher";setLinkMode(e){return this.linkMode=e,this}get publisherFirst(){return this.linkMode==="open-world"}linkBase(e){return this.publisherFirst?`/${e}`:""}resourceHref(e,n,a="="){return sn.formatResourceUrl(e,a,{contextPublisher:n,...this.publisherFirst?{publisherFirst:!0}:{}})}packageHref(e,n,a){return`${this.linkBase(e)}/${n}${a?`/${a}`:""}`}publisherHref(e){return`${this.linkBase(e)}/`}_codeHighlighter;findCascadedLook(e){let n=Ka(e)?void 0:Te(e);return n?{declaration:n,sourceClass:{publisher:B(e),package_:(e.namespace||"").split("/")[1]?.split("@")[0]??"",name:e.name}}:this.lookFromTypeRefs(ce(e))}lookFromTypeRefs(e){let n=new Set,a=[...e];for(;a.length>0;){let o=a.shift().subject,s=z(o);if(n.has(s))continue;n.add(s);let r=de(this.catalog,o);for(let i of r){let c=Te(i);if(c)return{declaration:c,sourceClass:{publisher:o.publisher,package_:o.package_,name:o.name}}}for(let i of r)for(let c of Ee(i))a.push(c)}if(!n.has(z(ke)))for(let t of de(this.catalog,ke)){let o=Te(t);if(o)return{declaration:o,sourceClass:{...ke}}}}findCascadedTokens(e){let n=new Map;for(let[o,s]of Je(e))n.has(o)||n.set(o,s);let a=new Set,t=ce(e);for(;t.length>0;){let o=t.shift(),s=z(o.subject);if(a.has(s))continue;a.add(s);let r=de(this.catalog,o.subject);if(r.length!==0)for(let i of r){for(let[c,l]of Je(i))n.has(c)||n.set(c,l);for(let c of Ee(i))t.push(c)}}if(!a.has(z(ke))){let o=de(this.catalog,ke);for(let s of o)for(let[r,i]of Je(s))n.has(r)||n.set(r,i)}return n}renderSvg(e){let n=A(this.catalog,e).label,a=(n.trim().charAt(0)||"?").toUpperCase(),t=`${e.namespace??""}/${e.name}`,o={label:n,firstLetter:a,uri:t},s=this.collectCascadedSvgTiers(e),r=k=>this.applyPlaceholders(k,e,o),i=r(s.tierChip??""),c=r(s.tierIcon??""),l=r(s.tierCard??""),d=r(s.tierFull??""),g=[...this.findCascadedTokens(e)].map(([k,f])=>`--kan-${k}: ${f};`).join(" ");return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 400" style="${me(g)}">
65
+ })();`,Oe={chip:56,icon:120,card:240,full:420},Rt=["chip","icon","card","full"],yt={56:"chip",120:"icon",240:"card",420:"full"},fe=11,Kt={publisher:"kanonak.org",package_:"look",name:"placement"},xt={publisher:"kanonak.org",package_:"look",name:"width"},Lt=4,wt={publisher:"kanonak.org",package_:"look",name:"StatRow"},Ot={publisher:"kanonak.org",package_:"look",name:"Horizon"},Et={publisher:"kanonak.org",package_:"look",name:"PackageContents"},We={publisher:"kanonak.org",package_:"core-kanonak",name:"Package"},It={publisher:"kanonak.org",package_:"core-kanonak",name:"Publisher"},Ut={publisher:"kanonak.org",package_:"look",name:"FeaturedResource"},Ft={publisher:"kanonak.org",package_:"look",name:"PublisherPackages"},Tt={publisher:"kanonak.org",package_:"look",name:"packages"},Ct={publisher:"kanonak.org",package_:"code-grammars",name:"CodeGrammar"},At={publisher:"kanonak.org",package_:"code-grammars",name:"language"},Mt={publisher:"kanonak.org",package_:"code-grammars",name:"rule"},Dt={publisher:"kanonak.org",package_:"code-grammars",name:"tokenClass"},Nt={publisher:"kanonak.org",package_:"code-grammars",name:"pattern"},Pt={publisher:"kanonak.org",package_:"look",name:"Links"},Vt={publisher:"kanonak.org",package_:"link",name:"url"},Ht={publisher:"kanonak.org",package_:"link",name:"links"};var Bt={publisher:"kanonak.org",package_:"look",name:"Distribution"},Gt={publisher:"kanonak.org",package_:"look",name:"alphaPath"},zt={publisher:"kanonak.org",package_:"look",name:"betaPath"},Ye={publisher:"kanonak.org",package_:"look",name:"SectionHeading"},Wt={publisher:"kanonak.org",package_:"look",name:"SectionNav"},mn={publisher:"kanonak.org",package_:"look",name:"heading"},Yt={publisher:"kanonak.org",package_:"look",name:"note"},qt={publisher:"kanonak.org",package_:"look",name:"VersionDelta"},Xt={publisher:"kanonak.org",package_:"look",name:"TimePlot"},Zt={publisher:"kanonak.org",package_:"look",name:"Details"},Jt={publisher:"kanonak.org",package_:"look",name:"EmbeddedViews"},Qt={publisher:"kanonak.org",package_:"look",name:"skip"},ea={publisher:"kanonak.org",package_:"derivation",name:"derivations"},na={publisher:"kanonak.org",package_:"look",name:"laneBy"},ta={publisher:"kanonak.org",package_:"look",name:"stats"},aa={publisher:"kanonak.org",package_:"look",name:"statPath"},sa={publisher:"kanonak.org",package_:"look",name:"statLabel"},hn={publisher:"kanonak.org",package_:"look",name:"labelPath"},oa={publisher:"kanonak.org",package_:"look",name:"badgePath"},qe={publisher:"kanonak.org",package_:"look",name:"orderBy"},bn={publisher:"kanonak.org",package_:"look",name:"track"},Fe={publisher:"kanonak.org",package_:"look",name:"metricPath"},Xe={publisher:"kanonak.org",package_:"look",name:"hueBy"},vn={publisher:"kanonak.org",package_:"look",name:"lowerPath"},$n={publisher:"kanonak.org",package_:"look",name:"upperPath"},ra={publisher:"kanonak.org",package_:"look",name:"axisMin"},ia={publisher:"kanonak.org",package_:"look",name:"axisMax"},ca={publisher:"kanonak.org",package_:"look",name:"valueLabel"};var _n={publisher:"kanonak.org",package_:"look",name:"semanticSvg"},la={publisher:"kanonak.org",package_:"look",name:"tierChip"},ua={publisher:"kanonak.org",package_:"look",name:"tierIcon"},da={publisher:"kanonak.org",package_:"look",name:"tierCard"},pa={publisher:"kanonak.org",package_:"look",name:"tierFull"},fa={publisher:"kanonak.org",package_:"core-rdf",name:"type"},jn=6,Ze={publisher:"kanonak.org",package_:"look",name:"bands"},ga={publisher:"kanonak.org",package_:"look",name:"title"},ka={publisher:"kanonak.org",package_:"look",name:"eyebrow"},ma={publisher:"kanonak.org",package_:"look",name:"subtitle"},Sn={publisher:"kanonak.org",package_:"look",name:"badges"},ae={publisher:"kanonak.org",package_:"look",name:"source"},ha={publisher:"kanonak.org",package_:"look",name:"via"},ba={publisher:"kanonak.org",package_:"look",name:"size"},va={publisher:"kanonak.org",package_:"look",name:"icon"},$a={publisher:"kanonak.org",package_:"look",name:"avatar"},_a={publisher:"kanonak.org",package_:"look",name:"contents"},ja={publisher:"kanonak.org",package_:"look",name:"transitive"},Sa={publisher:"kanonak.org",package_:"look",name:"chips"},Rn={publisher:"kanonak.org",package_:"look",name:"entries"},Ra={publisher:"kanonak.org",package_:"look",name:"urlForm"},tn=class{constructor(e){this.catalog=e}catalog;linkMode="single-publisher";setLinkMode(e){return this.linkMode=e,this}get publisherFirst(){return this.linkMode==="open-world"}linkBase(e){return this.publisherFirst?`/${e}`:""}resourceHref(e,n,a="="){return sn.formatResourceUrl(e,a,{contextPublisher:n,...this.publisherFirst?{publisherFirst:!0}:{}})}packageHref(e,n,a){return`${this.linkBase(e)}/${n}${a?`/${a}`:""}`}publisherHref(e){return`${this.linkBase(e)}/`}_codeHighlighter;findCascadedLook(e){let n=Ka(e)?void 0:Te(e);return n?{declaration:n,sourceClass:{publisher:B(e),package_:(e.namespace||"").split("/")[1]?.split("@")[0]??"",name:e.name}}:this.lookFromTypeRefs(ce(e))}lookFromTypeRefs(e){let n=new Set,a=[...e];for(;a.length>0;){let o=a.shift().subject,s=z(o);if(n.has(s))continue;n.add(s);let r=de(this.catalog,o);for(let i of r){let c=Te(i);if(c)return{declaration:c,sourceClass:{publisher:o.publisher,package_:o.package_,name:o.name}}}for(let i of r)for(let c of Ee(i))a.push(c)}if(!n.has(z(ke)))for(let t of de(this.catalog,ke)){let o=Te(t);if(o)return{declaration:o,sourceClass:{...ke}}}}findCascadedTokens(e){let n=new Map;for(let[o,s]of Je(e))n.has(o)||n.set(o,s);let a=new Set,t=ce(e);for(;t.length>0;){let o=t.shift(),s=z(o.subject);if(a.has(s))continue;a.add(s);let r=de(this.catalog,o.subject);if(r.length!==0)for(let i of r){for(let[c,l]of Je(i))n.has(c)||n.set(c,l);for(let c of Ee(i))t.push(c)}}if(!a.has(z(ke))){let o=de(this.catalog,ke);for(let s of o)for(let[r,i]of Je(s))n.has(r)||n.set(r,i)}return n}renderSvg(e){let n=A(this.catalog,e).label,a=(n.trim().charAt(0)||"?").toUpperCase(),t=`${e.namespace??""}/${e.name}`,o={label:n,firstLetter:a,uri:t,resourceKey:e.name},s=this.collectCascadedSvgTiers(e),r=k=>this.applyPlaceholders(k,e,o),i=r(s.tierChip??""),c=r(s.tierIcon??""),l=r(s.tierCard??""),d=r(s.tierFull??""),g=[...this.findCascadedTokens(e)].map(([k,f])=>`--kan-${k}: ${f};`).join(" ");return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 400" style="${me(g)}">
66
66
  <style>
67
67
  .tier-chip,.tier-icon,.tier-card{display:none}
68
68
  .tier-full{display:block}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import{a as ut,b as pt,c as mt,d as ft,e as yt}from"./chunk-QHJ6EY3Y.js";import{a as sr,c as cr}from"./chunk-6HRLK46T.js";import{a as ct,b as lt,c as dt,d as b,e as S,f as i}from"./chunk-KSTGTV35.js";import{a as ir}from"./chunk-767XYRNU.js";import"./chunk-3NEUHF7E.js";import{a as Le,b as Fe,c as De,d as Ne,e as Oe,f as Me,g as _e,h as ze}from"./chunk-CA2EATJR.js";import{a as Te,c as Ae,d as Ue,e as He}from"./chunk-RSIZQAFL.js";import{a as ht,b as kt,c as bt,d as St}from"./chunk-7JZUJ2K4.js";import{a as Ct,b as Kt}from"./chunk-PEUTCG3B.js";import{a as wt}from"./chunk-PEJALHXK.js";import{a as Ve}from"./chunk-SC5M74NM.js";import{A as rr,B as nr,C as or,E as ar,a as It,b as Bt,c as Tt,d as jt,e as Lt,f as Ft,g as Dt,h as Nt,i as Ot,j as At,k as Ut,l as Vt,m as Ht,n as Mt,o as _t,p as zt,q as Gt,r as Wt,s as Jt,t as qt,u as Yt,v as Xt,w as Zt,x as Qt,y as er,z as tr}from"./chunk-OIVACCMQ.js";import{a as ot,b as at,c as it}from"./chunk-Q6QTQWR2.js";import{a as F,b as N,c as Ye}from"./chunk-H2LEQLVD.js";import{a as je}from"./chunk-ORFSMEMM.js";import{a as st,b as Pt,c as Rt,d as xt,e as vt,f as $t,g as Et}from"./chunk-N224PFBI.js";import"./chunk-Q4DKP5DO.js";import{b as Xe,c as Ze,d as Qe,e as et,f as tt,h as rt,j as nt}from"./chunk-64TVBQFR.js";import{a as Ge,b as j,c as L,d as D,e as Je,f as qe,g as O,h as A,i as U,j as V,k as H,l as M}from"./chunk-W6T7MOKY.js";import{a as We}from"./chunk-FUUTGGJS.js";import{a as Pe,b as Re,c as we,d as xe,e as ve,f as $e,g as Ee,h as Ke,i as Ie,j as Be}from"./chunk-2ACBWC7K.js";import{a as gt}from"./chunk-ODIECDN7.js";import{VersionOperator as ko}from"@kanonak-protocol/types/document/models/enums";import{existsSync as vr,readFileSync as $r}from"fs";import{homedir as Er}from"os";import{join as Kr}from"path";import{execFile as lr}from"child_process";import{promisify as dr}from"util";var C=dr(lr),P="kanonak",R="/usr/bin/security",p=class{async get(e){let r=i(e);try{let{stdout:n}=await C(R,["find-generic-password","-s",P,"-a",r,"-w"],{timeout:1e4});try{return JSON.parse(n.trim())}catch{throw new Error(`Stored credential for '${r}' is corrupted (not valid JSON).
1
+ import{a as ut,b as pt,c as mt,d as ft,e as yt}from"./chunk-QHJ6EY3Y.js";import{a as sr,c as cr}from"./chunk-FXKT6OI4.js";import{a as ct,b as lt,c as dt,d as b,e as S,f as i}from"./chunk-KSTGTV35.js";import{a as ir}from"./chunk-767XYRNU.js";import"./chunk-3NEUHF7E.js";import{a as Le,b as Fe,c as De,d as Ne,e as Oe,f as Me,g as _e,h as ze}from"./chunk-CA2EATJR.js";import{a as Te,c as Ae,d as Ue,e as He}from"./chunk-RSIZQAFL.js";import{a as ht,b as kt,c as bt,d as St}from"./chunk-7JZUJ2K4.js";import{a as Ct,b as Kt}from"./chunk-PEUTCG3B.js";import{a as wt}from"./chunk-PEJALHXK.js";import{a as Ve}from"./chunk-SC5M74NM.js";import{A as rr,B as nr,C as or,E as ar,a as It,b as Bt,c as Tt,d as jt,e as Lt,f as Ft,g as Dt,h as Nt,i as Ot,j as At,k as Ut,l as Vt,m as Ht,n as Mt,o as _t,p as zt,q as Gt,r as Wt,s as Jt,t as qt,u as Yt,v as Xt,w as Zt,x as Qt,y as er,z as tr}from"./chunk-OIVACCMQ.js";import{a as ot,b as at,c as it}from"./chunk-Q6QTQWR2.js";import{a as F,b as N,c as Ye}from"./chunk-H2LEQLVD.js";import{a as je}from"./chunk-ORFSMEMM.js";import{a as st,b as Pt,c as Rt,d as xt,e as vt,f as $t,g as Et}from"./chunk-N224PFBI.js";import"./chunk-Q4DKP5DO.js";import{b as Xe,c as Ze,d as Qe,e as et,f as tt,h as rt,j as nt}from"./chunk-64TVBQFR.js";import{a as Ge,b as j,c as L,d as D,e as Je,f as qe,g as O,h as A,i as U,j as V,k as H,l as M}from"./chunk-W6T7MOKY.js";import{a as We}from"./chunk-FUUTGGJS.js";import{a as Pe,b as Re,c as we,d as xe,e as ve,f as $e,g as Ee,h as Ke,i as Ie,j as Be}from"./chunk-2ACBWC7K.js";import{a as gt}from"./chunk-ODIECDN7.js";import{VersionOperator as ko}from"@kanonak-protocol/types/document/models/enums";import{existsSync as vr,readFileSync as $r}from"fs";import{homedir as Er}from"os";import{join as Kr}from"path";import{execFile as lr}from"child_process";import{promisify as dr}from"util";var C=dr(lr),P="kanonak",R="/usr/bin/security",p=class{async get(e){let r=i(e);try{let{stdout:n}=await C(R,["find-generic-password","-s",P,"-a",r,"-w"],{timeout:1e4});try{return JSON.parse(n.trim())}catch{throw new Error(`Stored credential for '${r}' is corrupted (not valid JSON).
2
2
  Run 'kanonak logout ${r}' then 'kanonak login ${r}' to fix.`)}}catch(n){if(X(n,44))return null;throw new Error(`macOS Keychain read failed for '${r}': ${w(n)}
3
3
  The Keychain may be locked or inaccessible.
4
4
  Try unlocking it via Keychain Access.app or running 'security unlock-keychain'.`)}}async store(e,r){let n=i(e),o=JSON.stringify(r);try{await C(R,["add-generic-password","-s",P,"-a",n,"-U","-w",o],{timeout:1e4})}catch(a){throw new Error(`macOS Keychain write failed for '${n}': ${w(a)}
@@ -28,14 +28,85 @@ export interface BuildResult {
28
28
  /** Whether vectors were loaded from cache (true) or freshly embedded. */
29
29
  cached: boolean;
30
30
  }
31
+ /**
32
+ * Embeds a batch of texts into vectors. This is the unit of pluggability:
33
+ * each host supplies one. The default loads `@huggingface/transformers`; a
34
+ * bundled host (the VS Code extension, a browser build) injects its own —
35
+ * a runtime it provisioned outside its bundle, or a different backend
36
+ * (onnxruntime-web) entirely.
37
+ */
38
+ export type EmbedFn = (texts: string[]) => Promise<number[][]>;
39
+ /**
40
+ * The slice of the `@huggingface/transformers` module API the embedder uses,
41
+ * declared structurally so the SDK carries no type-level dependency on the
42
+ * optional runtime.
43
+ */
44
+ export interface TransformersModule {
45
+ pipeline: (task: 'feature-extraction', model: string, options?: {
46
+ dtype?: string;
47
+ }) => Promise<(texts: string[], options?: {
48
+ pooling?: string;
49
+ normalize?: boolean;
50
+ }) => Promise<{
51
+ tolist(): number[][];
52
+ }>>;
53
+ env: {
54
+ cacheDir?: string;
55
+ };
56
+ }
57
+ /**
58
+ * Build an {@link EmbedFn} from an already-loaded transformers module. This is
59
+ * the ONE place the model id, quantization, pooling, and normalization live,
60
+ * so every host produces identical, comparable embeddings — both the CLI's
61
+ * default loader below and any host that resolves the runtime itself (e.g. the
62
+ * VS Code extension provisioning it outside its bundle) go through here.
63
+ */
64
+ export declare function createTransformersEmbedder(options: {
65
+ transformers: TransformersModule;
66
+ /** Where transformers caches model weights. Default: `~/.kanonak/models`. */
67
+ modelCacheDir?: string;
68
+ }): Promise<EmbedFn>;
69
+ /**
70
+ * Resolve and import `@huggingface/transformers` from a specific install
71
+ * directory's `node_modules`, rather than relying on it being importable by
72
+ * bare specifier. For hosts that provision the runtime into a known shared
73
+ * location (e.g. the VS Code extension installing it into `~/.kanonak/runtime`,
74
+ * the same place a future provisioning CLI would use). Throws if the package
75
+ * is not installed under `runtimeDir` — callers provision then retry.
76
+ *
77
+ * We deliberately load the package's ESM entry (its `exports.node.import`
78
+ * build), NOT what `require.resolve` would pick (the `require`/CJS build): a
79
+ * CJS bundle imported from ESM collapses its exports under `.default`, so
80
+ * `env`/`pipeline` come back undefined. The ESM build exposes them as named
81
+ * exports — and is the exact build the SDK's default loader resolves, so every
82
+ * host embeds identically. The trailing `.default` unwrap is a belt-and-braces
83
+ * guard for packages that only ship CJS.
84
+ */
85
+ export declare function loadTransformersFrom(runtimeDir: string): Promise<TransformersModule>;
31
86
  /**
32
87
  * The natural-language document indexed for a resource: its display label,
33
88
  * its type's label ("a City", "a Framework"), and its summary — all via the
34
89
  * object model, so search reads what a human reads, not raw YAML.
35
90
  */
36
91
  export declare function embedTextFor(catalog: Kanonak[], subject: SubjectKanonak): string;
92
+ export interface SearchIndexOptions {
93
+ /**
94
+ * The embedding backend. When omitted, the optional
95
+ * `@huggingface/transformers` runtime is lazily imported (the CLI default,
96
+ * failing visibly if absent). A host that bundles itself and can't rely on
97
+ * that import — the VS Code extension, a browser build — supplies its own,
98
+ * e.g. via {@link createTransformersEmbedder} over a runtime it resolved, or
99
+ * a different backend entirely. `build` and `query` share it, so the query
100
+ * vector is always comparable to the indexed vectors.
101
+ */
102
+ embedder?: EmbedFn;
103
+ }
37
104
  export declare class SearchIndex {
38
105
  private entries;
106
+ private readonly embedder;
107
+ constructor(options?: SearchIndexOptions);
108
+ /** The injected embedder, or the lazily-loaded default if none was given. */
109
+ private resolveEmbedder;
39
110
  /** Number of indexed resources. */
40
111
  get size(): number;
41
112
  /**
@@ -1,2 +1,2 @@
1
- export { SearchIndex, embedTextFor } from './SearchIndex.js';
2
- export type { SearchHit, BuildOptions, BuildResult } from './SearchIndex.js';
1
+ export { SearchIndex, embedTextFor, createTransformersEmbedder, loadTransformersFrom } from './SearchIndex.js';
2
+ export type { SearchHit, BuildOptions, BuildResult, SearchIndexOptions, EmbedFn, TransformersModule, } from './SearchIndex.js';
@@ -1,6 +1,6 @@
1
- import{a as p}from"../chunk-6HRLK46T.js";import"../chunk-3NEUHF7E.js";import"../chunk-PEUTCG3B.js";import"../chunk-PEJALHXK.js";import"../chunk-SC5M74NM.js";import"../chunk-H2LEQLVD.js";import{d as m,g as x}from"../chunk-N224PFBI.js";import{a as d,f as S}from"../chunk-Q4DKP5DO.js";import"../chunk-64TVBQFR.js";import{c as j}from"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";import{c as v}from"../chunk-2ACBWC7K.js";import{homedir as P}from"os";import{join as k}from"path";import{existsSync as B,mkdirSync as C,readFileSync as D,writeFileSync as O}from"fs";import{createHash as z}from"crypto";var f="Xenova/all-MiniLM-L6-v2",w="q8",b=32,g=null;async function K(){return g||(g=(async()=>{let t;try{t=await import("@huggingface/transformers")}catch(i){throw new Error(`Semantic search requires the embedding runtime, which is an optional dependency.
1
+ import{a as g}from"../chunk-FXKT6OI4.js";import"../chunk-3NEUHF7E.js";import"../chunk-PEUTCG3B.js";import"../chunk-PEJALHXK.js";import"../chunk-SC5M74NM.js";import"../chunk-H2LEQLVD.js";import{d as m,g as S}from"../chunk-N224PFBI.js";import{a as p,f as E}from"../chunk-Q4DKP5DO.js";import"../chunk-64TVBQFR.js";import{c as v}from"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";import{c as x}from"../chunk-2ACBWC7K.js";import{homedir as P}from"os";import{join as d}from"path";import{existsSync as M,mkdirSync as D,readFileSync as j,writeFileSync as O}from"fs";import{createHash as C}from"crypto";import{pathToFileURL as B}from"url";var h="Xenova/all-MiniLM-L6-v2",w="q8",b=32;async function F(r){let{pipeline:e,env:t}=r.transformers;t.cacheDir=r.modelCacheDir??d(P(),".kanonak","models");let n=await e("feature-extraction",h,{dtype:w});return async s=>(await n(s,{pooling:"mean",normalize:!0})).tolist()}async function z(r){let e=d(r,"node_modules","@huggingface","transformers"),t=JSON.parse(j(d(e,"package.json"),"utf-8")),n=I(t);if(!n)throw new Error(`@huggingface/transformers at ${e} exposes no resolvable ESM entry.`);let s=await import(B(d(e,n)).href);return typeof s.pipeline=="function"?s:s.default}function I(r){let e=r.exports,t=n=>typeof n=="string"?n:n?.default;return typeof e=="string"?e:t(e?.node?.import)??t(e?.import)??t(e?.default)??r.module??r.main}var y=null;async function U(){return y||(y=(async()=>{let r;try{r=await import("@huggingface/transformers")}catch(e){throw new Error(`Semantic search requires the embedding runtime, which is an optional dependency.
2
2
  Install it with:
3
3
  npm install @huggingface/transformers
4
- (underlying import error: ${i.message})`)}let{pipeline:r,env:n}=t;n.cacheDir=k(P(),".kanonak","models");let e=await r("feature-extraction",f,{dtype:w});return async i=>(await e(i,{pooling:"mean",normalize:!0})).tolist()})()),g}function H(t,r){let n=0;for(let e=0;e<t.length;e++)n+=t[e]*r[e];return n}function U(t,r){return r?t.version?r.version?v(t.version,r.version)>0:!0:!1:!0}function F(t,r){let n=p(t,r),e=[n.label],i=x(r);if(i.length>0){let s=S(t,i[0]),c=s?p(t,s).label:i[0].name;c&&e.push(`\u2014 a ${c}.`)}return n.summary&&e.push(n.summary),e.join(" ")}function M(t){let r=new Map;for(let n of t){if(!(n instanceof j))continue;let e=m(n);if(!e)continue;let i=d(e),s=r.get(i);(!s||U(e,m(s)))&&r.set(i,n)}return[...r.values()].sort((n,e)=>{let i=m(n)?d(m(n)):n.name,s=m(e)?d(m(e)):e.name;return i.localeCompare(s)})}var y=class{entries=[];get size(){return this.entries.length}async build(r,n={}){let e=M(r);if(n.include&&(e=e.filter(n.include)),e.length===0)return this.entries=[],{size:0,cached:!1};let i=e.map(o=>F(r,o)),s=n.cacheDir,c;if(s){let o=z("sha256").update(f+"|"+w+`
5
- `+i.join(`
6
- `)).digest("hex").slice(0,32);c=k(s,`index-${o}.json`);let u=T(c);if(u&&u.model===f&&u.vectors.length===e.length)return this.entries=e.map((h,E)=>({subject:h,namespace:h.namespace||"",vector:u.vectors[E]})),{size:this.entries.length,cached:!0}}let a=await K(),l=[];for(let o=0;o<i.length;o+=b){let u=await a(i.slice(o,o+b));for(let h of u)l.push(h);n.onProgress?.(Math.min(o+b,i.length),i.length)}return this.entries=e.map((o,u)=>({subject:o,namespace:o.namespace||"",vector:l[u]})),c&&q(c,{model:f,vectors:l}),{size:this.entries.length,cached:!1}}async query(r,n){if(this.entries.length===0)return[];let e=await K(),[i]=await e([r]),s=n?.scope;return this.entries.filter(a=>!s||a.namespace.startsWith(s)).map(a=>({subject:a.subject,score:H(i,a.vector)})).sort((a,l)=>l.score-a.score).slice(0,n?.limit??20)}};function T(t){try{return B(t)?JSON.parse(D(t,"utf-8")):null}catch{return null}}function q(t,r){try{C(k(t,".."),{recursive:!0}),O(t,JSON.stringify(r))}catch{}}export{y as SearchIndex,F as embedTextFor};
4
+ (underlying import error: ${e.message})`)}return F({transformers:r})})()),y}function H(r,e){let t=0;for(let n=0;n<r.length;n++)t+=r[n]*e[n];return t}function R(r,e){return e?r.version?e.version?x(r.version,e.version)>0:!0:!1:!0}function K(r,e){let t=g(r,e),n=[t.label],s=S(e);if(s.length>0){let i=E(r,s[0]),a=i?g(r,i).label:s[0].name;a&&n.push(`\u2014 a ${a}.`)}return t.summary&&n.push(t.summary),n.join(" ")}function q(r){let e=new Map;for(let t of r){if(!(t instanceof v))continue;let n=m(t);if(!n)continue;let s=p(n),i=e.get(s);(!i||R(n,m(i)))&&e.set(s,t)}return[...e.values()].sort((t,n)=>{let s=m(t)?p(m(t)):t.name,i=m(n)?p(m(n)):n.name;return s.localeCompare(i)})}var k=class{entries=[];embedder;constructor(e={}){this.embedder=e.embedder}resolveEmbedder(){return this.embedder?Promise.resolve(this.embedder):U()}get size(){return this.entries.length}async build(e,t={}){let n=q(e);if(t.include&&(n=n.filter(t.include)),n.length===0)return this.entries=[],{size:0,cached:!1};let s=n.map(o=>K(e,o)),i=t.cacheDir,a;if(i){let o=C("sha256").update(h+"|"+w+`
5
+ `+s.join(`
6
+ `)).digest("hex").slice(0,32);a=d(i,`index-${o}.json`);let u=L(a);if(u&&u.model===h&&u.vectors.length===n.length)return this.entries=n.map((f,T)=>({subject:f,namespace:f.namespace||"",vector:u.vectors[T]})),{size:this.entries.length,cached:!0}}let c=await this.resolveEmbedder(),l=[];for(let o=0;o<s.length;o+=b){let u=await c(s.slice(o,o+b));for(let f of u)l.push(f);t.onProgress?.(Math.min(o+b,s.length),s.length)}return this.entries=n.map((o,u)=>({subject:o,namespace:o.namespace||"",vector:l[u]})),a&&$(a,{model:h,vectors:l}),{size:this.entries.length,cached:!1}}async query(e,t){if(this.entries.length===0)return[];let n=await this.resolveEmbedder(),[s]=await n([e]),i=t?.scope;return this.entries.filter(c=>!i||c.namespace.startsWith(i)).map(c=>({subject:c.subject,score:H(s,c.vector)})).sort((c,l)=>l.score-c.score).slice(0,t?.limit??20)}};function L(r){try{return M(r)?JSON.parse(j(r,"utf-8")):null}catch{return null}}function $(r,e){try{D(d(r,".."),{recursive:!0}),O(r,JSON.stringify(e))}catch{}}export{k as SearchIndex,F as createTransformersEmbedder,K as embedTextFor,z as loadTransformersFrom};
@@ -1,3 +1,3 @@
1
- import{c as O}from"../chunk-6HRLK46T.js";import"../chunk-3NEUHF7E.js";import{a as z,d as j,f as Z,g as V}from"../chunk-CA2EATJR.js";import{a as J,b as Q,c as X,d as F,e as I}from"../chunk-RSIZQAFL.js";import"../chunk-PEUTCG3B.js";import{a as te}from"../chunk-PEJALHXK.js";import"../chunk-SC5M74NM.js";import{c as N}from"../chunk-Q6QTQWR2.js";import"../chunk-H2LEQLVD.js";import{a as K}from"../chunk-ORFSMEMM.js";import{b as L}from"../chunk-N224PFBI.js";import"../chunk-Q4DKP5DO.js";import"../chunk-64TVBQFR.js";import{c as ee}from"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";import{c as C,g as Y}from"../chunk-2ACBWC7K.js";import{readFileSync as ce,existsSync as le,readdirSync as pe,writeFileSync as ue,mkdirSync as de}from"fs";import{join as W}from"path";function re(a){let e=a.metadata?.namespace_;return e?`${e.publisher}/${e.package_}`:void 0}async function A(a,e){let r=new Set,t=[...a];for(;t.length>0;){let n=t.shift(),u=re(n);if(!u||r.has(u))continue;r.add(u);let d=n.metadata?.imports;if(d)for(let[i,g]of Object.entries(d))for(let f of g)try{let p=await e.getHighestCompatibleVersionAsync(i,f);p&&t.push(p)}catch{}}return r}var D=class{constructor(e,r){this.inner=e;this.scope=r}inner;scope;async getAllDocumentsAsync(){return(await this.inner.getAllDocumentsAsync()).filter(r=>{let t=re(r);return t!==void 0&&this.scope.has(t)})}getDocumentAsync(e){return this.inner.getDocumentAsync(e)}getDocumentsByNamespaceAsync(e,r){return this.inner.getDocumentsByNamespaceAsync(e,r)}getHighestCompatibleVersionAsync(e,r){return this.inner.getHighestCompatibleVersionAsync(e,r)}saveDocumentAsync(e,r){return this.inner.saveDocumentAsync(e,r)}deleteDocumentAsync(e){return this.inner.deleteDocumentAsync(e)}clearNamespaceAsync(e,r){return this.inner.clearNamespaceAsync(e,r)}getAllDocumentReferencesAsync(){return this.inner.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.inner.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.inner.getDocumentUriAsync(e)}};var ne=[{publisher:"kanonak.org",package_:"core-kanonak"},{publisher:"kanonak.org",package_:"site"},{publisher:"kanonak.org",package_:"link"},{publisher:"kanonak.org",package_:"look-tokens"},{publisher:"kanonak.org",package_:"look-styles"},{publisher:"kanonak.org",package_:"look"},{publisher:"kanonak.org",package_:"universal-look"}];function M(a){let e=a?.render;if(e&&e.length>0){let r=[];for(let t of e)try{let n=L(t);n.kind==="package"?r.push({publisher:n.publisher,package_:n.package_}):n.kind==="resource"&&r.push({publisher:n.uri.publisher,package_:n.uri.package_})}catch{}if(r.length>0)return r}return ne}function B(a){return`${a.publisher}/${a.package_}`}function E(a){let{publisher:e,availablePublishers:r,catalog:t,lookRenderer:n,localNamespaces:u,rawByNsKey:d}=a,i=new Map,g=new Map,f=new Map,p=new Set;for(let o of t){if(!(o instanceof ee))continue;let m=o.namespace||"";if(!u.has(m))continue;i.set(`${m}/${o.name}`,o);let k=m.split("/")[1]??"",[v,$]=k.split("@");if(!v||!$)continue;let c=Y($);c&&(p.has(k)||(p.add(k),g.has(v)||g.set(v,[]),g.get(v).push({verStr:$,version:c})),o.name===v&&f.set(k,o))}for(let o of g.values())o.sort((m,k)=>C(k.version,m.version));return{publisher:e,availablePublishers:r,catalog:t,lookRenderer:n,localNamespaces:u,rawByNsKey:d,bySubject:i,pkgVersions:g,pkgSelfByVer:f}}async function H(a,e={}){let r=new K,t=new J(r),n=[],u=[];for(let c of V(a)){let R;try{R=ce(c,"utf-8")}catch{continue}let b;try{b=r.parse(R).metadata?.namespace_}catch{continue}if(!b?.version)continue;let x=b.version;u.push({publisher:b.publisher,package_:b.package_,verStr:`${x.major}.${x.minor}.${x.patch}`,version:x,source:R})}u.sort((c,R)=>C(R.version,c.version));for(let c of u)await t.saveDocumentAsync(r.parse(c.source),`${c.publisher}/${c.package_}@${c.verStr}`),n.push({publisher:c.publisher,package_:c.package_,verStr:c.verStr,source:c.source});let d=[...new Set(n.map(c=>c.publisher))].sort(),i=e.publisher;if(i){if(!d.includes(i))throw new Error(`Publisher "${i}" not found in workspace. Available: ${d.join(", ")||"(none)"}`)}else if(d.length===1)i=d[0];else throw d.length===0?new Error(`No Kanonak packages found under ${a}`):new Error(`Workspace has multiple publishers (${d.join(", ")}). Pass --publisher <domain> to choose which one to serve.`);let g=new Set,f=new Map;for(let c of n)c.publisher===i&&(g.add(`${c.publisher}/${c.package_}@${c.verStr}`),f.set(`${c.package_}@${c.verStr}`,c.source));let p=new z(j(),!0,r),o=e.repository??new Z(t,p,new I(e.httpCache?{getFromCache:e.httpCache.getFromCache,onFetch:e.httpCache.onFetch}:void 0)),m=M(void 0);if(!e.repository){let c=j(),R=s=>{let h=W(c,s);return le(h)?new Set(pe(h).filter(y=>y.endsWith(".kan.yml")).map(y=>y.split("@")[0])):new Set},b=(s,h)=>n.some(y=>y.publisher===s&&y.package_===h),x=new F,l=new Map;for(let s of m)if(l.has(s.publisher)||l.set(s.publisher,R(s.publisher)),!(l.get(s.publisher).has(s.package_)||b(s.publisher,s.package_)))try{let h=await x.getHighestVersion(s.publisher,s.package_);if(!h)continue;let y=await x.getPackageUrl(s.publisher,s.package_,h),P=await fetch(y);if(!P.ok)continue;let ie=await P.text(),G=W(c,s.publisher);de(G,{recursive:!0}),ue(W(G,`${s.package_}@${h}.kan.yml`),ie,"utf-8")}catch{}}let k=o;if(!e.repository){let c=(await t.getAllDocumentsAsync()).filter(b=>b.metadata.namespace_?.publisher===i),R=await A(c,o);for(let b of m)R.add(B(b));k=new D(o,R)}let v=await new N(r).parseKanonaks(k),$=new O(v);return E({publisher:i,availablePublishers:d,catalog:v,lookRenderer:$,localNamespaces:g,rawByNsKey:f})}import{existsSync as me,readFileSync as ge,writeFileSync as fe,mkdirSync as he}from"fs";import{join as oe}from"path";async function q(a,e={}){let r=new K,t=L(a),n=t.kind==="resource"?t.uri.publisher:t.publisher,u=e.cacheRoot??j(),d=(l,s,h)=>oe(u,l,`${s}@${h}.kan.yml`),i=new I({getFromCache:(l,s,h)=>{let y=d(l,s,h);return me(y)?ge(y,"utf-8"):null},onFetch:(l,s,h,y)=>{let P=oe(u,l);he(P,{recursive:!0}),fe(d(l,s,h),y,"utf-8")},...e.fetchFn?{fetchFn:e.fetchFn}:{}}),g=new F(e.fetchFn?{fetchFn:e.fetchFn}:void 0),f;if(t.kind==="resource"){let l=t.uri.version;f=[l?{package_:t.uri.package_,version:`${l.major}.${l.minor}.${l.patch}`}:{package_:t.uri.package_}]}else if(t.kind==="package"){let l=t.version;f=[l?{package_:t.package_,version:`${l.major}.${l.minor}.${l.patch}`}:{package_:t.package_}]}else f=(await g.listLatestPackages(n)).map(s=>({package_:s.packageName}));let p=async(l,s,h)=>{try{let y=h?r.buildImport(s,"=",h,l):r.buildImport(s,"*","0.0.0",l);return await i.getHighestCompatibleVersionAsync(l,y)}catch{return null}},o=[];for(let l of f){let s=await p(n,l.package_,l.version);s&&o.push(s)}if(o.length===0)throw new Error(`Could not fetch any package for address "${a}" from publisher "${n}".`);let m=await new X().getConfig(n).catch(()=>{}),k=[];for(let l of M(m)){let s=await p(l.publisher,l.package_,void 0);s&&k.push(s)}let v=await A([...o,...k],i),$=new D(i,v),c=await new N(r).parseKanonaks($),R=new O(c),b=new Set,x=new Map;for(let l of await i.getAllDocumentsAsync()){let s=l.metadata.namespace_;if(!s||s.publisher!==n)continue;let h=`${s.version.major}.${s.version.minor}.${s.version.patch}`,y=`${s.publisher}/${s.package_}@${h}`;b.add(y);let P=await i.getDocumentContentAsync(y);P!==null&&x.set(`${s.package_}@${h}`,P)}return E({publisher:n,availablePublishers:[n],catalog:c,lookRenderer:R,localNamespaces:b,rawByNsKey:x})}var S={".html":"text/html; charset=utf-8",".css":"text/css; charset=utf-8",".svg":"image/svg+xml",".md":"text/markdown; charset=utf-8",".kan.yml":"application/yaml; charset=utf-8",".txt":"text/plain; charset=utf-8",".json":"application/json; charset=utf-8"},w=(a,e,r,t)=>({status:a,headers:{"Content-Type":e,...t||{}},body:r}),_=a=>w(404,S[".html"],`<!doctype html><meta charset=utf-8><title>404</title><h1>404</h1><p>Not found: ${a}</p>`),ke=a=>({status:301,headers:{Location:a},body:""});function se(a,e,r){let t=a.pkgVersions.get(e);if(!t||t.length===0)return null;switch(r.kind){case"any":return t[0].verStr;case"major-pin":return t.find(n=>n.version.major===r.major)?.verStr??null;case"minor-pin":return t.find(n=>n.version.major===r.major&&n.version.minor===r.minor)?.verStr??null;case"exact":return t.find(n=>n.version.major===r.major&&n.version.minor===r.minor&&n.version.patch===r.patch)?.verStr??null;default:return null}}function T(a,e,r=""){let{lookRenderer:t,publisher:n}=a;if(e==="/.well-known/kanonak.json")return w(200,S[".json"],JSON.stringify(Q(n),null,2));if(e==="/index.txt"){let o=[...a.localNamespaces].map(m=>m.split("/")[1].replace("@","/")).sort();return w(200,S[".txt"],o.join(`
1
+ import{c as O}from"../chunk-FXKT6OI4.js";import"../chunk-3NEUHF7E.js";import{a as z,d as j,f as Z,g as V}from"../chunk-CA2EATJR.js";import{a as J,b as Q,c as X,d as F,e as I}from"../chunk-RSIZQAFL.js";import"../chunk-PEUTCG3B.js";import{a as te}from"../chunk-PEJALHXK.js";import"../chunk-SC5M74NM.js";import{c as N}from"../chunk-Q6QTQWR2.js";import"../chunk-H2LEQLVD.js";import{a as K}from"../chunk-ORFSMEMM.js";import{b as L}from"../chunk-N224PFBI.js";import"../chunk-Q4DKP5DO.js";import"../chunk-64TVBQFR.js";import{c as ee}from"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";import{c as C,g as Y}from"../chunk-2ACBWC7K.js";import{readFileSync as ce,existsSync as le,readdirSync as pe,writeFileSync as ue,mkdirSync as de}from"fs";import{join as W}from"path";function re(a){let e=a.metadata?.namespace_;return e?`${e.publisher}/${e.package_}`:void 0}async function A(a,e){let r=new Set,t=[...a];for(;t.length>0;){let n=t.shift(),u=re(n);if(!u||r.has(u))continue;r.add(u);let d=n.metadata?.imports;if(d)for(let[i,g]of Object.entries(d))for(let f of g)try{let p=await e.getHighestCompatibleVersionAsync(i,f);p&&t.push(p)}catch{}}return r}var D=class{constructor(e,r){this.inner=e;this.scope=r}inner;scope;async getAllDocumentsAsync(){return(await this.inner.getAllDocumentsAsync()).filter(r=>{let t=re(r);return t!==void 0&&this.scope.has(t)})}getDocumentAsync(e){return this.inner.getDocumentAsync(e)}getDocumentsByNamespaceAsync(e,r){return this.inner.getDocumentsByNamespaceAsync(e,r)}getHighestCompatibleVersionAsync(e,r){return this.inner.getHighestCompatibleVersionAsync(e,r)}saveDocumentAsync(e,r){return this.inner.saveDocumentAsync(e,r)}deleteDocumentAsync(e){return this.inner.deleteDocumentAsync(e)}clearNamespaceAsync(e,r){return this.inner.clearNamespaceAsync(e,r)}getAllDocumentReferencesAsync(){return this.inner.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.inner.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.inner.getDocumentUriAsync(e)}};var ne=[{publisher:"kanonak.org",package_:"core-kanonak"},{publisher:"kanonak.org",package_:"site"},{publisher:"kanonak.org",package_:"link"},{publisher:"kanonak.org",package_:"look-tokens"},{publisher:"kanonak.org",package_:"look-styles"},{publisher:"kanonak.org",package_:"look"},{publisher:"kanonak.org",package_:"universal-look"}];function M(a){let e=a?.render;if(e&&e.length>0){let r=[];for(let t of e)try{let n=L(t);n.kind==="package"?r.push({publisher:n.publisher,package_:n.package_}):n.kind==="resource"&&r.push({publisher:n.uri.publisher,package_:n.uri.package_})}catch{}if(r.length>0)return r}return ne}function B(a){return`${a.publisher}/${a.package_}`}function E(a){let{publisher:e,availablePublishers:r,catalog:t,lookRenderer:n,localNamespaces:u,rawByNsKey:d}=a,i=new Map,g=new Map,f=new Map,p=new Set;for(let o of t){if(!(o instanceof ee))continue;let m=o.namespace||"";if(!u.has(m))continue;i.set(`${m}/${o.name}`,o);let k=m.split("/")[1]??"",[v,$]=k.split("@");if(!v||!$)continue;let c=Y($);c&&(p.has(k)||(p.add(k),g.has(v)||g.set(v,[]),g.get(v).push({verStr:$,version:c})),o.name===v&&f.set(k,o))}for(let o of g.values())o.sort((m,k)=>C(k.version,m.version));return{publisher:e,availablePublishers:r,catalog:t,lookRenderer:n,localNamespaces:u,rawByNsKey:d,bySubject:i,pkgVersions:g,pkgSelfByVer:f}}async function H(a,e={}){let r=new K,t=new J(r),n=[],u=[];for(let c of V(a)){let R;try{R=ce(c,"utf-8")}catch{continue}let b;try{b=r.parse(R).metadata?.namespace_}catch{continue}if(!b?.version)continue;let x=b.version;u.push({publisher:b.publisher,package_:b.package_,verStr:`${x.major}.${x.minor}.${x.patch}`,version:x,source:R})}u.sort((c,R)=>C(R.version,c.version));for(let c of u)await t.saveDocumentAsync(r.parse(c.source),`${c.publisher}/${c.package_}@${c.verStr}`),n.push({publisher:c.publisher,package_:c.package_,verStr:c.verStr,source:c.source});let d=[...new Set(n.map(c=>c.publisher))].sort(),i=e.publisher;if(i){if(!d.includes(i))throw new Error(`Publisher "${i}" not found in workspace. Available: ${d.join(", ")||"(none)"}`)}else if(d.length===1)i=d[0];else throw d.length===0?new Error(`No Kanonak packages found under ${a}`):new Error(`Workspace has multiple publishers (${d.join(", ")}). Pass --publisher <domain> to choose which one to serve.`);let g=new Set,f=new Map;for(let c of n)c.publisher===i&&(g.add(`${c.publisher}/${c.package_}@${c.verStr}`),f.set(`${c.package_}@${c.verStr}`,c.source));let p=new z(j(),!0,r),o=e.repository??new Z(t,p,new I(e.httpCache?{getFromCache:e.httpCache.getFromCache,onFetch:e.httpCache.onFetch}:void 0)),m=M(void 0);if(!e.repository){let c=j(),R=s=>{let h=W(c,s);return le(h)?new Set(pe(h).filter(y=>y.endsWith(".kan.yml")).map(y=>y.split("@")[0])):new Set},b=(s,h)=>n.some(y=>y.publisher===s&&y.package_===h),x=new F,l=new Map;for(let s of m)if(l.has(s.publisher)||l.set(s.publisher,R(s.publisher)),!(l.get(s.publisher).has(s.package_)||b(s.publisher,s.package_)))try{let h=await x.getHighestVersion(s.publisher,s.package_);if(!h)continue;let y=await x.getPackageUrl(s.publisher,s.package_,h),P=await fetch(y);if(!P.ok)continue;let ie=await P.text(),G=W(c,s.publisher);de(G,{recursive:!0}),ue(W(G,`${s.package_}@${h}.kan.yml`),ie,"utf-8")}catch{}}let k=o;if(!e.repository){let c=(await t.getAllDocumentsAsync()).filter(b=>b.metadata.namespace_?.publisher===i),R=await A(c,o);for(let b of m)R.add(B(b));k=new D(o,R)}let v=await new N(r).parseKanonaks(k),$=new O(v);return E({publisher:i,availablePublishers:d,catalog:v,lookRenderer:$,localNamespaces:g,rawByNsKey:f})}import{existsSync as me,readFileSync as ge,writeFileSync as fe,mkdirSync as he}from"fs";import{join as oe}from"path";async function q(a,e={}){let r=new K,t=L(a),n=t.kind==="resource"?t.uri.publisher:t.publisher,u=e.cacheRoot??j(),d=(l,s,h)=>oe(u,l,`${s}@${h}.kan.yml`),i=new I({getFromCache:(l,s,h)=>{let y=d(l,s,h);return me(y)?ge(y,"utf-8"):null},onFetch:(l,s,h,y)=>{let P=oe(u,l);he(P,{recursive:!0}),fe(d(l,s,h),y,"utf-8")},...e.fetchFn?{fetchFn:e.fetchFn}:{}}),g=new F(e.fetchFn?{fetchFn:e.fetchFn}:void 0),f;if(t.kind==="resource"){let l=t.uri.version;f=[l?{package_:t.uri.package_,version:`${l.major}.${l.minor}.${l.patch}`}:{package_:t.uri.package_}]}else if(t.kind==="package"){let l=t.version;f=[l?{package_:t.package_,version:`${l.major}.${l.minor}.${l.patch}`}:{package_:t.package_}]}else f=(await g.listLatestPackages(n)).map(s=>({package_:s.packageName}));let p=async(l,s,h)=>{try{let y=h?r.buildImport(s,"=",h,l):r.buildImport(s,"*","0.0.0",l);return await i.getHighestCompatibleVersionAsync(l,y)}catch{return null}},o=[];for(let l of f){let s=await p(n,l.package_,l.version);s&&o.push(s)}if(o.length===0)throw new Error(`Could not fetch any package for address "${a}" from publisher "${n}".`);let m=await new X().getConfig(n).catch(()=>{}),k=[];for(let l of M(m)){let s=await p(l.publisher,l.package_,void 0);s&&k.push(s)}let v=await A([...o,...k],i),$=new D(i,v),c=await new N(r).parseKanonaks($),R=new O(c),b=new Set,x=new Map;for(let l of await i.getAllDocumentsAsync()){let s=l.metadata.namespace_;if(!s||s.publisher!==n)continue;let h=`${s.version.major}.${s.version.minor}.${s.version.patch}`,y=`${s.publisher}/${s.package_}@${h}`;b.add(y);let P=await i.getDocumentContentAsync(y);P!==null&&x.set(`${s.package_}@${h}`,P)}return E({publisher:n,availablePublishers:[n],catalog:c,lookRenderer:R,localNamespaces:b,rawByNsKey:x})}var S={".html":"text/html; charset=utf-8",".css":"text/css; charset=utf-8",".svg":"image/svg+xml",".md":"text/markdown; charset=utf-8",".kan.yml":"application/yaml; charset=utf-8",".txt":"text/plain; charset=utf-8",".json":"application/json; charset=utf-8"},w=(a,e,r,t)=>({status:a,headers:{"Content-Type":e,...t||{}},body:r}),_=a=>w(404,S[".html"],`<!doctype html><meta charset=utf-8><title>404</title><h1>404</h1><p>Not found: ${a}</p>`),ke=a=>({status:301,headers:{Location:a},body:""});function se(a,e,r){let t=a.pkgVersions.get(e);if(!t||t.length===0)return null;switch(r.kind){case"any":return t[0].verStr;case"major-pin":return t.find(n=>n.version.major===r.major)?.verStr??null;case"minor-pin":return t.find(n=>n.version.major===r.major&&n.version.minor===r.minor)?.verStr??null;case"exact":return t.find(n=>n.version.major===r.major&&n.version.minor===r.minor&&n.version.patch===r.patch)?.verStr??null;default:return null}}function T(a,e,r=""){let{lookRenderer:t,publisher:n}=a;if(e==="/.well-known/kanonak.json")return w(200,S[".json"],JSON.stringify(Q(n),null,2));if(e==="/index.txt"){let o=[...a.localNamespaces].map(m=>m.split("/")[1].replace("@","/")).sort();return w(200,S[".txt"],o.join(`
2
2
  `)+`
3
3
  `)}if(e==="/"||e==="/index.html"||e==="/index.css"){let o=t.publisherSubject(n);return e==="/index.css"?w(200,S[".css"],t.renderStylesheet(o)):w(200,S[".html"],t.renderDocument(o,{rootIndex:!0}))}let u=".html",d=!1,i=e;for(let o of[".kan.yml",".css",".svg",".md",".html"])if(e.endsWith(o)){u=o,d=!0,i=e.slice(0,-o.length);break}let g=!d&&/application\/yaml|text\/yaml/i.test(r),f=i.endsWith("/");f&&i!=="/"&&(i=i.slice(0,-1));let p=te.parse(i,n);if(!p)return _(e);if(p.kind==="package"){let o=se(a,p.package_,p.versionSpec);if(!o)return _(e);if(u===".kan.yml"||g){let v=a.rawByNsKey.get(`${p.package_}@${o}`);return v!==void 0?w(200,S[".kan.yml"],v):_(e)}let m=a.pkgSelfByVer.get(`${p.package_}@${o}`);if(!m)return _(e);if(u===".css")return w(200,S[".css"],t.renderStylesheet(m));if(!f)return ke(i+"/");let k=p.versionSpec.kind==="any";if(k&&!t.hasDeclaredView(m)){let v=(a.pkgVersions.get(p.package_)||[]).map($=>$.verStr);return w(200,S[".html"],t.renderPackageVersionList(p.package_,v,m))}return w(200,S[".html"],t.renderDocument(m,k?{bareOverview:!0}:void 0))}if(p.kind==="resource"){let o=se(a,p.package_,p.versionSpec);if(!o)return _(e);let m=a.bySubject.get(`${n}/${p.package_}@${o}/${p.name}`);if(!m)return _(e);switch(u){case".css":return w(200,S[".css"],t.renderStylesheet(m));case".svg":return w(200,S[".svg"],t.renderSvg(m));case".md":{let k=t.renderRawMarkdown(m);return k===void 0?_(e):w(200,S[".md"],k)}default:return w(200,S[".html"],t.renderDocument(m))}}return _(e)}import{readFileSync as ye}from"fs";var U=class{constructor(e={}){this.options=e}options;models=new Map;workspaceIndex;clearCache(){this.models.clear(),this.workspaceIndex=void 0}getWorkspaceIndex(){if(this.workspaceIndex)return this.workspaceIndex;let e=new Set,r=new Set;if(this.options.root!==void 0){let t=new K;for(let n of V(this.options.root))try{let u=t.parse(ye(n,"utf-8")).metadata?.namespace_;if(!u?.version)continue;let d=u.version;e.add(`${u.publisher}/${u.package_}@${d.major}.${d.minor}.${d.patch}`),r.add(`${u.publisher}/${u.package_}`)}catch{}}return this.workspaceIndex={exact:e,pkgs:r},this.workspaceIndex}async modelFor(e,r,t){let n=this.getWorkspaceIndex(),u=this.options.fetchFn?{fetchFn:this.options.fetchFn}:{},d=r?t?n.exact.has(`${e}/${r}@${t}`):n.pkgs.has(`${e}/${r}`):[...n.pkgs].some(o=>o.startsWith(`${e}/`)),i,g;if(d&&this.options.root!==void 0){let o=this.options.root;i=`ws:${e}`,g=()=>H(o,{publisher:e})}else{let o=r?t?`${e}/${r}@${t}`:`${e}/${r}`:e;i=`rm:${o}`,g=()=>q(o,u)}let f=this.models.get(i);if(f)return f;let p=await g();return p.lookRenderer.setLinkMode("open-world"),this.models.set(i,p),p}async handle(e,r=""){let t=e.split("/").filter(Boolean);if(t.length===0)return{status:200,headers:{"Content-Type":"text/html; charset=utf-8"},body:ae()};let n=t[0];if(!n.includes("."))return{status:404,headers:{"Content-Type":"text/html; charset=utf-8"},body:"<!doctype html><meta charset=utf-8><title>404</title><h1>404</h1><p>Expected a publisher domain as the first path segment: <code>/{publisher}/{package}/{version}/{resource}</code></p>"};let u=t.length>=2&&(t[1]==="index.html"||t[1]==="index.css"||t[1]==="index.txt"||t[1]===".well-known"),d=!u&&t.length>=2?t[1]:void 0,i=!u&&t.length>=3&&/^\d+\.\d+\.\d+$/.test(t[2])?t[2]:void 0,g=await this.modelFor(n,d,i),f=e.endsWith("/")&&t.length>1?"/":"",p="/"+t.slice(1).join("/")+f,o=T(g,p,r);return o.headers.Location?{...o,headers:{...o.headers,Location:`/${n}${o.headers.Location}`}}:o}};function ae(){return'<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Kanonak origin</title></head><body style="font-family:system-ui;max-width:40rem;margin:4rem auto;padding:0 1rem"><h1>Kanonak request-driven origin</h1><p>Open a resource by its address:</p><p><code>/{publisher}/{package}/{version}/{resource}</code></p><p>e.g. <code>/kanonak.org/capabilities/2.0.0/Capability</code></p></body></html>'}export{D as ClosureScopedRepository,U as RequestRouter,ne as UNIVERSAL_RENDER_BASE,A as deriveImportClosure,ae as landingPage,q as loadResourceModel,H as loadServerModel,B as renderRefKey,M as resolveRenderContract,T as route};
@@ -1,4 +1,4 @@
1
- import{b as X,c as ye}from"../chunk-6HRLK46T.js";import{a as Ne}from"../chunk-767XYRNU.js";import"../chunk-3NEUHF7E.js";import"../chunk-7JZUJ2K4.js";import"../chunk-PEJALHXK.js";import{c as Ue}from"../chunk-Q6QTQWR2.js";import{a as C,c as Ce}from"../chunk-H2LEQLVD.js";import{a as Re}from"../chunk-ORFSMEMM.js";import{b as E,c as F,d as f,f as M,l as Oe}from"../chunk-Q4DKP5DO.js";import"../chunk-64TVBQFR.js";import{b as K,c as w,d as b,g as L,h as U,i as O,j,k as T,l as S}from"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";import{g as Le}from"../chunk-2ACBWC7K.js";var yt="kanonak.org",kt="document-ast",m=t=>({publisher:yt,package_:kt,name:t}),k={Document:m("Document"),Block:m("Block"),Inline:m("Inline"),StructuredValue:m("StructuredValue"),Heading:m("Heading"),Paragraph:m("Paragraph"),RawBlock:m("RawBlock"),Text:m("Text"),StructuredMap:m("StructuredMap"),StructuredEntry:m("StructuredEntry"),StructuredList:m("StructuredList"),StringScalar:m("StringScalar"),IntegerScalar:m("IntegerScalar"),EscapeHint:m("EscapeHint"),MediaType:m("MediaType"),metadata:m("metadata"),children:m("children"),level:m("level"),inlines:m("inlines"),text:m("text"),entries:m("entries"),key:m("key"),value:m("value"),escapeHint:m("escapeHint"),items:m("items"),stringValue:m("stringValue"),integerValue:m("integerValue"),rawContent:m("rawContent"),mediaType:m("mediaType"),mimeType:m("mimeType"),ESC_RAW:m("esc-raw"),ESC_YAML_SAFE:m("esc-yaml-safe"),ESC_TOML_STRING:m("esc-toml-string"),ESC_TOML_MULTILINE:m("esc-toml-multiline"),ESC_JSON:m("esc-json"),ESC_DYNAMODB_BOOL:m("esc-dynamodb-bool"),ESC_DYNAMODB_NUMBER:m("esc-dynamodb-number"),ESC_DYNAMODB_NULL:m("esc-dynamodb-null"),TEXT_PLAIN:m("text-plain"),TEXT_MARKDOWN:m("text-markdown"),TEXT_HTML:m("text-html"),TEXT_CSS:m("text-css"),APPLICATION_JSON:m("application-json"),TEXT_YAML:m("text-yaml"),IMAGE_SVG_XML:m("image-svg-xml"),ResourceLink:m("ResourceLink"),target:m("target"),linkLabel:m("linkLabel"),PropertyList:m("PropertyList"),propertyEntries:m("propertyEntries"),PropertyEntry:m("PropertyEntry"),propertyKey:m("propertyKey"),propertyValue:m("propertyValue"),Table:m("Table"),tableColumnLabels:m("tableColumnLabels"),tableRows:m("tableRows"),TableRow:m("TableRow"),tableCells:m("tableCells")};function Ie(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var Y=class{backendUri="kanonak.org/transformations/markdown-with-frontmatter";render(e,n){let r=ht(e.metadata,n),a=St(e.children),u=["---",...r,"---","",a].join(`
1
+ import{b as X,c as ye}from"../chunk-FXKT6OI4.js";import{a as Ne}from"../chunk-767XYRNU.js";import"../chunk-3NEUHF7E.js";import"../chunk-7JZUJ2K4.js";import"../chunk-PEJALHXK.js";import{c as Ue}from"../chunk-Q6QTQWR2.js";import{a as C,c as Ce}from"../chunk-H2LEQLVD.js";import{a as Re}from"../chunk-ORFSMEMM.js";import{b as E,c as F,d as f,f as M,l as Oe}from"../chunk-Q4DKP5DO.js";import"../chunk-64TVBQFR.js";import{b as K,c as w,d as b,g as L,h as U,i as O,j,k as T,l as S}from"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";import{g as Le}from"../chunk-2ACBWC7K.js";var yt="kanonak.org",kt="document-ast",m=t=>({publisher:yt,package_:kt,name:t}),k={Document:m("Document"),Block:m("Block"),Inline:m("Inline"),StructuredValue:m("StructuredValue"),Heading:m("Heading"),Paragraph:m("Paragraph"),RawBlock:m("RawBlock"),Text:m("Text"),StructuredMap:m("StructuredMap"),StructuredEntry:m("StructuredEntry"),StructuredList:m("StructuredList"),StringScalar:m("StringScalar"),IntegerScalar:m("IntegerScalar"),EscapeHint:m("EscapeHint"),MediaType:m("MediaType"),metadata:m("metadata"),children:m("children"),level:m("level"),inlines:m("inlines"),text:m("text"),entries:m("entries"),key:m("key"),value:m("value"),escapeHint:m("escapeHint"),items:m("items"),stringValue:m("stringValue"),integerValue:m("integerValue"),rawContent:m("rawContent"),mediaType:m("mediaType"),mimeType:m("mimeType"),ESC_RAW:m("esc-raw"),ESC_YAML_SAFE:m("esc-yaml-safe"),ESC_TOML_STRING:m("esc-toml-string"),ESC_TOML_MULTILINE:m("esc-toml-multiline"),ESC_JSON:m("esc-json"),ESC_DYNAMODB_BOOL:m("esc-dynamodb-bool"),ESC_DYNAMODB_NUMBER:m("esc-dynamodb-number"),ESC_DYNAMODB_NULL:m("esc-dynamodb-null"),TEXT_PLAIN:m("text-plain"),TEXT_MARKDOWN:m("text-markdown"),TEXT_HTML:m("text-html"),TEXT_CSS:m("text-css"),APPLICATION_JSON:m("application-json"),TEXT_YAML:m("text-yaml"),IMAGE_SVG_XML:m("image-svg-xml"),ResourceLink:m("ResourceLink"),target:m("target"),linkLabel:m("linkLabel"),PropertyList:m("PropertyList"),propertyEntries:m("propertyEntries"),PropertyEntry:m("PropertyEntry"),propertyKey:m("propertyKey"),propertyValue:m("propertyValue"),Table:m("Table"),tableColumnLabels:m("tableColumnLabels"),tableRows:m("tableRows"),TableRow:m("TableRow"),tableCells:m("tableCells")};function Ie(t,e){return t.publisher===e.publisher&&t.package_===e.package_&&t.name===e.name}var Y=class{backendUri="kanonak.org/transformations/markdown-with-frontmatter";render(e,n){let r=ht(e.metadata,n),a=St(e.children),u=["---",...r,"---","",a].join(`
2
2
  `);return n?.trailingNewline&&(u.endsWith(`
3
3
  `)||(u+=`
4
4
  `)),u}};function ht(t,e){if(!t)return[];let n=new Map;for(let c of t.entries)n.set(ue(c.key),c);let r=new Map;if(e?.metadataRenames)for(let[c,l]of e.metadataRenames)r.set(ue(c),l);let i=(e?.metadataKeys??t.entries.map(c=>c.key)).map(ue),u=[];for(let c of i){let l=n.get(c);if(!l)continue;let p=r.get(c),y=ue(p??c),h=Me(l.value,l.escapeHint);h!==void 0&&u.push(`${y}: ${h}`)}return u}function ue(t){let e=t.lastIndexOf(".");return e===-1?t:t.substring(e+1)||t}function Me(t,e){switch(t.kind){case"StringScalar":return bt(t.stringValue,e);case"IntegerScalar":return String(t.integerValue);case"StructuredList":{let n=[];for(let r of t.items){let a=Me(r,e);a!==void 0&&n.push(a)}return n.join(", ")}case"StructuredMap":return;default:return}}function bt(t,e){return!e||Ie(e,k.ESC_RAW)?t:Ie(e,k.ESC_YAML_SAFE)?wt(t):t}function wt(t){return t.includes(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kanonak-protocol/sdk",
3
- "version": "3.67.0",
3
+ "version": "3.68.0",
4
4
  "description": "TypeScript SDK for the Kanonak Protocol — parse, resolve, validate, reason over, and render .kan.yml packages.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -122,7 +122,7 @@
122
122
  "yaml-parser"
123
123
  ],
124
124
  "dependencies": {
125
- "@kanonak-protocol/types": "^3.67.0",
125
+ "@kanonak-protocol/types": "^3.68.0",
126
126
  "ignore": "^7.0.5",
127
127
  "js-yaml": "^4.1.0",
128
128
  "yaml": "^2.7.0"