@kanonak-protocol/sdk 3.60.0 → 3.61.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.
@@ -82,10 +82,17 @@ export declare class KanonakUrlResolver {
82
82
  *
83
83
  * Default: full URL with `https://` scheme. Pass `pathOnly: true` to
84
84
  * get the path component only — useful for same-publisher links.
85
+ *
86
+ * `publisherFirst: true` emits a PUBLISHER-FIRST path
87
+ * (`/{publisher}/{package}/{version}/{name}`) instead — the form a
88
+ * request-driven consumer (the Kanonak Browser, request-driven `serve`)
89
+ * uses so EVERY resource, same- or cross-publisher, resolves back through
90
+ * one local origin. It takes precedence over `pathOnly`/`scheme`.
85
91
  */
86
92
  static format(address: UrlAddress, opts?: {
87
93
  scheme?: 'https' | 'http';
88
94
  pathOnly?: boolean;
95
+ publisherFirst?: boolean;
89
96
  }): string;
90
97
  /**
91
98
  * Format a pinned resource reference as a URL with a specific
@@ -110,5 +117,6 @@ export declare class KanonakUrlResolver {
110
117
  }, urlForm: UrlForm, opts?: {
111
118
  scheme?: 'https' | 'http';
112
119
  contextPublisher?: string;
120
+ publisherFirst?: boolean;
113
121
  }): string;
114
122
  }
@@ -1 +1 @@
1
- import{a as p,b as x}from"../chunk-PEUTCG3B.js";import{a as s}from"../chunk-NIGFQYVA.js";import{a as k}from"../chunk-SC5M74NM.js";import{a as o,b as q,c as r,d as t,e as u,f as v,g as w}from"../chunk-N224PFBI.js";import"../chunk-Q4DKP5DO.js";import{b as m,c as n}from"../chunk-64TVBQFR.js";import"../chunk-W6T7MOKY.js";import{a as l}from"../chunk-FUUTGGJS.js";import{a,b,c,d,e,f,g,h,i,j}from"../chunk-2ACBWC7K.js";export{l as KanonakUri,p as KanonakUriBuilder,s as KanonakUrlResolver,m as ResourceResolver,o as ResourceTypeClassifier,n as TypeResolver,k as assertPackageIdentity,c as compareVersions,w as contextTypesOf,f as createVersion,x as findInstancesByType,r as formatKanonakAddress,e as formatVersion,h as isCompatibleVersion,i as isMajorCompatible,q as parseKanonakAddress,g as parseVersionString,j as pickHighestDocument,u as propertiesInScope,v as resolvePropertyStep,t as subjectUri,a as versionOperatorFromChar,b as versionOperatorToChar,d as versionsEqual};
1
+ import{a as p,b as x}from"../chunk-PEUTCG3B.js";import{a as s}from"../chunk-PEJALHXK.js";import{a as k}from"../chunk-SC5M74NM.js";import{a as o,b as q,c as r,d as t,e as u,f as v,g as w}from"../chunk-N224PFBI.js";import"../chunk-Q4DKP5DO.js";import{b as m,c as n}from"../chunk-64TVBQFR.js";import"../chunk-W6T7MOKY.js";import{a as l}from"../chunk-FUUTGGJS.js";import{a,b,c,d,e,f,g,h,i,j}from"../chunk-2ACBWC7K.js";export{l as KanonakUri,p as KanonakUriBuilder,s as KanonakUrlResolver,m as ResourceResolver,o as ResourceTypeClassifier,n as TypeResolver,k as assertPackageIdentity,c as compareVersions,w as contextTypesOf,f as createVersion,x as findInstancesByType,r as formatKanonakAddress,e as formatVersion,h as isCompatibleVersion,i as isMajorCompatible,q as parseKanonakAddress,g as parseVersionString,j as pickHighestDocument,u as propertiesInScope,v as resolvePropertyStep,t as subjectUri,a as versionOperatorFromChar,b as versionOperatorToChar,d as versionsEqual};
@@ -1,4 +1,4 @@
1
- import{a as p}from"../chunk-JYUZT2JU.js";import"../chunk-3NEUHF7E.js";import"../chunk-PEUTCG3B.js";import"../chunk-NIGFQYVA.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 p}from"../chunk-IL6VHYRU.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.
2
2
  Install it with:
3
3
  npm install @huggingface/transformers
4
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+`
@@ -2,6 +2,8 @@ export { loadServerModel } from './loadServerModel.js';
2
2
  export { loadResourceModel } from './loadResourceModel.js';
3
3
  export type { LoadResourceModelOptions } from './loadResourceModel.js';
4
4
  export { route } from './route.js';
5
+ export { RequestRouter, landingPage } from './requestRouter.js';
6
+ export type { RequestRouterOptions } from './requestRouter.js';
5
7
  export { deriveImportClosure, ClosureScopedRepository } from './closure.js';
6
8
  export { UNIVERSAL_RENDER_BASE, resolveRenderContract, renderRefKey, } from './renderStack.js';
7
9
  export type { RenderPackageRef } from './renderStack.js';
@@ -1,3 +1,3 @@
1
- import{c as L}from"../chunk-JYUZT2JU.js";import"../chunk-3NEUHF7E.js";import{a as T,d as x,f as q,g as J}from"../chunk-CA2EATJR.js";import{a as W,b as G,c as Y,d as V,e as N}from"../chunk-RSIZQAFL.js";import"../chunk-PEUTCG3B.js";import{a as Q}from"../chunk-NIGFQYVA.js";import"../chunk-SC5M74NM.js";import{c as F}from"../chunk-Q6QTQWR2.js";import"../chunk-H2LEQLVD.js";import{a as M}from"../chunk-ORFSMEMM.js";import{b as I}from"../chunk-N224PFBI.js";import"../chunk-Q4DKP5DO.js";import"../chunk-64TVBQFR.js";import{c as z}from"../chunk-W6T7MOKY.js";import"../chunk-FUUTGGJS.js";import{c as C,g as U}from"../chunk-2ACBWC7K.js";import{readFileSync as te,existsSync as oe,readdirSync as se,writeFileSync as ae,mkdirSync as ie}from"fs";import{join as O}from"path";function X(s){let e=s.metadata?.namespace_;return e?`${e.publisher}/${e.package_}`:void 0}async function A(s,e){let n=new Set,r=[...s];for(;r.length>0;){let o=r.shift(),g=X(o);if(!g||n.has(g))continue;n.add(g);let d=o.metadata?.imports;if(d)for(let[l,v]of Object.entries(d))for(let h of v)try{let p=await e.getHighestCompatibleVersionAsync(l,h);p&&r.push(p)}catch{}}return n}var K=class{constructor(e,n){this.inner=e;this.scope=n}inner;scope;async getAllDocumentsAsync(){return(await this.inner.getAllDocumentsAsync()).filter(n=>{let r=X(n);return r!==void 0&&this.scope.has(r)})}getDocumentAsync(e){return this.inner.getDocumentAsync(e)}getDocumentsByNamespaceAsync(e,n){return this.inner.getDocumentsByNamespaceAsync(e,n)}getHighestCompatibleVersionAsync(e,n){return this.inner.getHighestCompatibleVersionAsync(e,n)}saveDocumentAsync(e,n){return this.inner.saveDocumentAsync(e,n)}deleteDocumentAsync(e){return this.inner.deleteDocumentAsync(e)}clearNamespaceAsync(e,n){return this.inner.clearNamespaceAsync(e,n)}getAllDocumentReferencesAsync(){return this.inner.getAllDocumentReferencesAsync()}getDocumentContentAsync(e){return this.inner.getDocumentContentAsync(e)}getDocumentUriAsync(e){return this.inner.getDocumentUriAsync(e)}};var Z=[{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 j(s){let e=s?.render;if(e&&e.length>0){let n=[];for(let r of e)try{let o=I(r);o.kind==="package"?n.push({publisher:o.publisher,package_:o.package_}):o.kind==="resource"&&n.push({publisher:o.uri.publisher,package_:o.uri.package_})}catch{}if(n.length>0)return n}return Z}function B(s){return`${s.publisher}/${s.package_}`}function E(s){let{publisher:e,availablePublishers:n,catalog:r,lookRenderer:o,localNamespaces:g,rawByNsKey:d}=s,l=new Map,v=new Map,h=new Map,p=new Set;for(let c of r){if(!(c instanceof z))continue;let u=c.namespace||"";if(!g.has(u))continue;l.set(`${u}/${c.name}`,c);let f=u.split("/")[1]??"",[y,D]=f.split("@");if(!y||!D)continue;let a=U(D);a&&(p.has(f)||(p.add(f),v.has(y)||v.set(y,[]),v.get(y).push({verStr:D,version:a})),c.name===y&&h.set(f,c))}for(let c of v.values())c.sort((u,f)=>C(f.version,u.version));return{publisher:e,availablePublishers:n,catalog:r,lookRenderer:o,localNamespaces:g,rawByNsKey:d,bySubject:l,pkgVersions:v,pkgSelfByVer:h}}async function ce(s,e={}){let n=new M,r=new W(n),o=[],g=[];for(let a of J(s)){let w;try{w=te(a,"utf-8")}catch{continue}let b;try{b=n.parse(w).metadata?.namespace_}catch{continue}if(!b?.version)continue;let _=b.version;g.push({publisher:b.publisher,package_:b.package_,verStr:`${_.major}.${_.minor}.${_.patch}`,version:_,source:w})}g.sort((a,w)=>C(w.version,a.version));for(let a of g)await r.saveDocumentAsync(n.parse(a.source),`${a.publisher}/${a.package_}@${a.verStr}`),o.push({publisher:a.publisher,package_:a.package_,verStr:a.verStr,source:a.source});let d=[...new Set(o.map(a=>a.publisher))].sort(),l=e.publisher;if(l){if(!d.includes(l))throw new Error(`Publisher "${l}" not found in workspace. Available: ${d.join(", ")||"(none)"}`)}else if(d.length===1)l=d[0];else throw d.length===0?new Error(`No Kanonak packages found under ${s}`):new Error(`Workspace has multiple publishers (${d.join(", ")}). Pass --publisher <domain> to choose which one to serve.`);let v=new Set,h=new Map;for(let a of o)a.publisher===l&&(v.add(`${a.publisher}/${a.package_}@${a.verStr}`),h.set(`${a.package_}@${a.verStr}`,a.source));let p=new T(x(),!0,n),c=e.repository??new q(r,p,new N(e.httpCache?{getFromCache:e.httpCache.getFromCache,onFetch:e.httpCache.onFetch}:void 0)),u=j(void 0);if(!e.repository){let a=x(),w=t=>{let m=O(a,t);return oe(m)?new Set(se(m).filter(k=>k.endsWith(".kan.yml")).map(k=>k.split("@")[0])):new Set},b=(t,m)=>o.some(k=>k.publisher===t&&k.package_===m),_=new V,i=new Map;for(let t of u)if(i.has(t.publisher)||i.set(t.publisher,w(t.publisher)),!(i.get(t.publisher).has(t.package_)||b(t.publisher,t.package_)))try{let m=await _.getHighestVersion(t.publisher,t.package_);if(!m)continue;let k=await _.getPackageUrl(t.publisher,t.package_,m),$=await fetch(k);if(!$.ok)continue;let ne=await $.text(),H=O(a,t.publisher);ie(H,{recursive:!0}),ae(O(H,`${t.package_}@${m}.kan.yml`),ne,"utf-8")}catch{}}let f=c;if(!e.repository){let a=(await r.getAllDocumentsAsync()).filter(b=>b.metadata.namespace_?.publisher===l),w=await A(a,c);for(let b of u)w.add(B(b));f=new K(c,w)}let y=await new F(n).parseKanonaks(f),D=new L(y);return E({publisher:l,availablePublishers:d,catalog:y,lookRenderer:D,localNamespaces:v,rawByNsKey:h})}import{existsSync as le,readFileSync as pe,writeFileSync as ue,mkdirSync as me}from"fs";import{join as ee}from"path";async function ge(s,e={}){let n=new M,r=I(s),o=r.kind==="resource"?r.uri.publisher:r.publisher,g=e.cacheRoot??x(),d=(i,t,m)=>ee(g,i,`${t}@${m}.kan.yml`),l=new N({getFromCache:(i,t,m)=>{let k=d(i,t,m);return le(k)?pe(k,"utf-8"):null},onFetch:(i,t,m,k)=>{let $=ee(g,i);me($,{recursive:!0}),ue(d(i,t,m),k,"utf-8")},...e.fetchFn?{fetchFn:e.fetchFn}:{}}),v=new V(e.fetchFn?{fetchFn:e.fetchFn}:void 0),h;if(r.kind==="resource"){let i=r.uri.version;h=[i?{package_:r.uri.package_,version:`${i.major}.${i.minor}.${i.patch}`}:{package_:r.uri.package_}]}else if(r.kind==="package"){let i=r.version;h=[i?{package_:r.package_,version:`${i.major}.${i.minor}.${i.patch}`}:{package_:r.package_}]}else h=(await v.listLatestPackages(o)).map(t=>({package_:t.packageName}));let p=async(i,t,m)=>{try{let k=m?n.buildImport(t,"=",m,i):n.buildImport(t,"*","0.0.0",i);return await l.getHighestCompatibleVersionAsync(i,k)}catch{return null}},c=[];for(let i of h){let t=await p(o,i.package_,i.version);t&&c.push(t)}if(c.length===0)throw new Error(`Could not fetch any package for address "${s}" from publisher "${o}".`);let u=await new Y().getConfig(o).catch(()=>{}),f=[];for(let i of j(u)){let t=await p(i.publisher,i.package_,void 0);t&&f.push(t)}let y=await A([...c,...f],l),D=new K(l,y),a=await new F(n).parseKanonaks(D),w=new L(a),b=new Set,_=new Map;for(let i of await l.getAllDocumentsAsync()){let t=i.metadata.namespace_;if(!t||t.publisher!==o)continue;let m=`${t.version.major}.${t.version.minor}.${t.version.patch}`,k=`${t.publisher}/${t.package_}@${m}`;b.add(k);let $=await l.getDocumentContentAsync(k);$!==null&&_.set(`${t.package_}@${m}`,$)}return E({publisher:o,availablePublishers:[o],catalog:a,lookRenderer:w,localNamespaces:b,rawByNsKey:_})}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"},R=(s,e,n,r)=>({status:s,headers:{"Content-Type":e,...r||{}},body:n}),P=s=>R(404,S[".html"],`<!doctype html><meta charset=utf-8><title>404</title><h1>404</h1><p>Not found: ${s}</p>`),de=s=>({status:301,headers:{Location:s},body:""});function re(s,e,n){let r=s.pkgVersions.get(e);if(!r||r.length===0)return null;switch(n.kind){case"any":return r[0].verStr;case"major-pin":return r.find(o=>o.version.major===n.major)?.verStr??null;case"minor-pin":return r.find(o=>o.version.major===n.major&&o.version.minor===n.minor)?.verStr??null;case"exact":return r.find(o=>o.version.major===n.major&&o.version.minor===n.minor&&o.version.patch===n.patch)?.verStr??null;default:return null}}function fe(s,e,n=""){let{lookRenderer:r,publisher:o}=s;if(e==="/.well-known/kanonak.json")return R(200,S[".json"],JSON.stringify(G(o),null,2));if(e==="/index.txt"){let c=[...s.localNamespaces].map(u=>u.split("/")[1].replace("@","/")).sort();return R(200,S[".txt"],c.join(`
1
+ import{c as L}from"../chunk-IL6VHYRU.js";import"../chunk-3NEUHF7E.js";import{a as J,d as K,f as X,g as Z}from"../chunk-CA2EATJR.js";import{a as Y,b as z,c as Q,d as F,e as V}from"../chunk-RSIZQAFL.js";import"../chunk-PEUTCG3B.js";import{a as re}from"../chunk-PEJALHXK.js";import"../chunk-SC5M74NM.js";import{c as N}from"../chunk-Q6QTQWR2.js";import"../chunk-H2LEQLVD.js";import{a as C}from"../chunk-ORFSMEMM.js";import{b as I}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 M,g as G}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 H}from"path";function te(s){let e=s.metadata?.namespace_;return e?`${e.publisher}/${e.package_}`:void 0}async function j(s,e){let n=new Set,r=[...s];for(;r.length>0;){let t=r.shift(),d=te(t);if(!d||n.has(d))continue;n.add(d);let m=t.metadata?.imports;if(m)for(let[l,g]of Object.entries(m))for(let y of g)try{let p=await e.getHighestCompatibleVersionAsync(l,y);p&&r.push(p)}catch{}}return n}var $=class{constructor(e,n){this.inner=e;this.scope=n}inner;scope;async getAllDocumentsAsync(){return(await this.inner.getAllDocumentsAsync()).filter(n=>{let r=te(n);return r!==void 0&&this.scope.has(r)})}getDocumentAsync(e){return this.inner.getDocumentAsync(e)}getDocumentsByNamespaceAsync(e,n){return this.inner.getDocumentsByNamespaceAsync(e,n)}getHighestCompatibleVersionAsync(e,n){return this.inner.getHighestCompatibleVersionAsync(e,n)}saveDocumentAsync(e,n){return this.inner.saveDocumentAsync(e,n)}deleteDocumentAsync(e){return this.inner.deleteDocumentAsync(e)}clearNamespaceAsync(e,n){return this.inner.clearNamespaceAsync(e,n)}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 A(s){let e=s?.render;if(e&&e.length>0){let n=[];for(let r of e)try{let t=I(r);t.kind==="package"?n.push({publisher:t.publisher,package_:t.package_}):t.kind==="resource"&&n.push({publisher:t.uri.publisher,package_:t.uri.package_})}catch{}if(n.length>0)return n}return ne}function B(s){return`${s.publisher}/${s.package_}`}function E(s){let{publisher:e,availablePublishers:n,catalog:r,lookRenderer:t,localNamespaces:d,rawByNsKey:m}=s,l=new Map,g=new Map,y=new Map,p=new Set;for(let c of r){if(!(c instanceof ee))continue;let u=c.namespace||"";if(!d.has(u))continue;l.set(`${u}/${c.name}`,c);let h=u.split("/")[1]??"",[v,x]=h.split("@");if(!v||!x)continue;let a=G(x);a&&(p.has(h)||(p.add(h),g.has(v)||g.set(v,[]),g.get(v).push({verStr:x,version:a})),c.name===v&&y.set(h,c))}for(let c of g.values())c.sort((u,h)=>M(h.version,u.version));return{publisher:e,availablePublishers:n,catalog:r,lookRenderer:t,localNamespaces:d,rawByNsKey:m,bySubject:l,pkgVersions:g,pkgSelfByVer:y}}async function q(s,e={}){let n=new C,r=new Y(n),t=[],d=[];for(let a of Z(s)){let w;try{w=ce(a,"utf-8")}catch{continue}let b;try{b=n.parse(w).metadata?.namespace_}catch{continue}if(!b?.version)continue;let _=b.version;d.push({publisher:b.publisher,package_:b.package_,verStr:`${_.major}.${_.minor}.${_.patch}`,version:_,source:w})}d.sort((a,w)=>M(w.version,a.version));for(let a of d)await r.saveDocumentAsync(n.parse(a.source),`${a.publisher}/${a.package_}@${a.verStr}`),t.push({publisher:a.publisher,package_:a.package_,verStr:a.verStr,source:a.source});let m=[...new Set(t.map(a=>a.publisher))].sort(),l=e.publisher;if(l){if(!m.includes(l))throw new Error(`Publisher "${l}" not found in workspace. Available: ${m.join(", ")||"(none)"}`)}else if(m.length===1)l=m[0];else throw m.length===0?new Error(`No Kanonak packages found under ${s}`):new Error(`Workspace has multiple publishers (${m.join(", ")}). Pass --publisher <domain> to choose which one to serve.`);let g=new Set,y=new Map;for(let a of t)a.publisher===l&&(g.add(`${a.publisher}/${a.package_}@${a.verStr}`),y.set(`${a.package_}@${a.verStr}`,a.source));let p=new J(K(),!0,n),c=e.repository??new X(r,p,new V(e.httpCache?{getFromCache:e.httpCache.getFromCache,onFetch:e.httpCache.onFetch}:void 0)),u=A(void 0);if(!e.repository){let a=K(),w=o=>{let f=H(a,o);return le(f)?new Set(pe(f).filter(k=>k.endsWith(".kan.yml")).map(k=>k.split("@")[0])):new Set},b=(o,f)=>t.some(k=>k.publisher===o&&k.package_===f),_=new F,i=new Map;for(let o of u)if(i.has(o.publisher)||i.set(o.publisher,w(o.publisher)),!(i.get(o.publisher).has(o.package_)||b(o.publisher,o.package_)))try{let f=await _.getHighestVersion(o.publisher,o.package_);if(!f)continue;let k=await _.getPackageUrl(o.publisher,o.package_,f),D=await fetch(k);if(!D.ok)continue;let ie=await D.text(),W=H(a,o.publisher);de(W,{recursive:!0}),ue(H(W,`${o.package_}@${f}.kan.yml`),ie,"utf-8")}catch{}}let h=c;if(!e.repository){let a=(await r.getAllDocumentsAsync()).filter(b=>b.metadata.namespace_?.publisher===l),w=await j(a,c);for(let b of u)w.add(B(b));h=new $(c,w)}let v=await new N(n).parseKanonaks(h),x=new L(v);return E({publisher:l,availablePublishers:m,catalog:v,lookRenderer:x,localNamespaces:g,rawByNsKey:y})}import{existsSync as me,readFileSync as ge,writeFileSync as fe,mkdirSync as he}from"fs";import{join as oe}from"path";async function O(s,e={}){let n=new C,r=I(s),t=r.kind==="resource"?r.uri.publisher:r.publisher,d=e.cacheRoot??K(),m=(i,o,f)=>oe(d,i,`${o}@${f}.kan.yml`),l=new V({getFromCache:(i,o,f)=>{let k=m(i,o,f);return me(k)?ge(k,"utf-8"):null},onFetch:(i,o,f,k)=>{let D=oe(d,i);he(D,{recursive:!0}),fe(m(i,o,f),k,"utf-8")},...e.fetchFn?{fetchFn:e.fetchFn}:{}}),g=new F(e.fetchFn?{fetchFn:e.fetchFn}:void 0),y;if(r.kind==="resource"){let i=r.uri.version;y=[i?{package_:r.uri.package_,version:`${i.major}.${i.minor}.${i.patch}`}:{package_:r.uri.package_}]}else if(r.kind==="package"){let i=r.version;y=[i?{package_:r.package_,version:`${i.major}.${i.minor}.${i.patch}`}:{package_:r.package_}]}else y=(await g.listLatestPackages(t)).map(o=>({package_:o.packageName}));let p=async(i,o,f)=>{try{let k=f?n.buildImport(o,"=",f,i):n.buildImport(o,"*","0.0.0",i);return await l.getHighestCompatibleVersionAsync(i,k)}catch{return null}},c=[];for(let i of y){let o=await p(t,i.package_,i.version);o&&c.push(o)}if(c.length===0)throw new Error(`Could not fetch any package for address "${s}" from publisher "${t}".`);let u=await new Q().getConfig(t).catch(()=>{}),h=[];for(let i of A(u)){let o=await p(i.publisher,i.package_,void 0);o&&h.push(o)}let v=await j([...c,...h],l),x=new $(l,v),a=await new N(n).parseKanonaks(x),w=new L(a),b=new Set,_=new Map;for(let i of await l.getAllDocumentsAsync()){let o=i.metadata.namespace_;if(!o||o.publisher!==t)continue;let f=`${o.version.major}.${o.version.minor}.${o.version.patch}`,k=`${o.publisher}/${o.package_}@${f}`;b.add(k);let D=await l.getDocumentContentAsync(k);D!==null&&_.set(`${o.package_}@${f}`,D)}return E({publisher:t,availablePublishers:[t],catalog:a,lookRenderer:w,localNamespaces:b,rawByNsKey:_})}var R={".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"},S=(s,e,n,r)=>({status:s,headers:{"Content-Type":e,...r||{}},body:n}),P=s=>S(404,R[".html"],`<!doctype html><meta charset=utf-8><title>404</title><h1>404</h1><p>Not found: ${s}</p>`),ke=s=>({status:301,headers:{Location:s},body:""});function se(s,e,n){let r=s.pkgVersions.get(e);if(!r||r.length===0)return null;switch(n.kind){case"any":return r[0].verStr;case"major-pin":return r.find(t=>t.version.major===n.major)?.verStr??null;case"minor-pin":return r.find(t=>t.version.major===n.major&&t.version.minor===n.minor)?.verStr??null;case"exact":return r.find(t=>t.version.major===n.major&&t.version.minor===n.minor&&t.version.patch===n.patch)?.verStr??null;default:return null}}function T(s,e,n=""){let{lookRenderer:r,publisher:t}=s;if(e==="/.well-known/kanonak.json")return S(200,R[".json"],JSON.stringify(z(t),null,2));if(e==="/index.txt"){let c=[...s.localNamespaces].map(u=>u.split("/")[1].replace("@","/")).sort();return S(200,R[".txt"],c.join(`
2
2
  `)+`
3
- `)}if(e==="/"||e==="/index.html"||e==="/index.css"){let c=r.publisherSubject(o);return e==="/index.css"?R(200,S[".css"],r.renderStylesheet(c)):R(200,S[".html"],r.renderDocument(c,{rootIndex:!0}))}let g=".html",d=!1,l=e;for(let c of[".kan.yml",".css",".svg",".md",".html"])if(e.endsWith(c)){g=c,d=!0,l=e.slice(0,-c.length);break}let v=!d&&/application\/yaml|text\/yaml/i.test(n),h=l.endsWith("/");h&&l!=="/"&&(l=l.slice(0,-1));let p=Q.parse(l,o);if(!p)return P(e);if(p.kind==="package"){let c=re(s,p.package_,p.versionSpec);if(!c)return P(e);if(g===".kan.yml"||v){let y=s.rawByNsKey.get(`${p.package_}@${c}`);return y!==void 0?R(200,S[".kan.yml"],y):P(e)}let u=s.pkgSelfByVer.get(`${p.package_}@${c}`);if(!u)return P(e);if(g===".css")return R(200,S[".css"],r.renderStylesheet(u));if(!h)return de(l+"/");let f=p.versionSpec.kind==="any";if(f&&!r.hasDeclaredView(u)){let y=(s.pkgVersions.get(p.package_)||[]).map(D=>D.verStr);return R(200,S[".html"],r.renderPackageVersionList(p.package_,y,u))}return R(200,S[".html"],r.renderDocument(u,f?{bareOverview:!0}:void 0))}if(p.kind==="resource"){let c=re(s,p.package_,p.versionSpec);if(!c)return P(e);let u=s.bySubject.get(`${o}/${p.package_}@${c}/${p.name}`);if(!u)return P(e);switch(g){case".css":return R(200,S[".css"],r.renderStylesheet(u));case".svg":return R(200,S[".svg"],r.renderSvg(u));case".md":{let f=r.renderRawMarkdown(u);return f===void 0?P(e):R(200,S[".md"],f)}default:return R(200,S[".html"],r.renderDocument(u))}}return P(e)}export{K as ClosureScopedRepository,Z as UNIVERSAL_RENDER_BASE,A as deriveImportClosure,ge as loadResourceModel,ce as loadServerModel,B as renderRefKey,j as resolveRenderContract,fe as route};
3
+ `)}if(e==="/"||e==="/index.html"||e==="/index.css"){let c=r.publisherSubject(t);return e==="/index.css"?S(200,R[".css"],r.renderStylesheet(c)):S(200,R[".html"],r.renderDocument(c,{rootIndex:!0}))}let d=".html",m=!1,l=e;for(let c of[".kan.yml",".css",".svg",".md",".html"])if(e.endsWith(c)){d=c,m=!0,l=e.slice(0,-c.length);break}let g=!m&&/application\/yaml|text\/yaml/i.test(n),y=l.endsWith("/");y&&l!=="/"&&(l=l.slice(0,-1));let p=re.parse(l,t);if(!p)return P(e);if(p.kind==="package"){let c=se(s,p.package_,p.versionSpec);if(!c)return P(e);if(d===".kan.yml"||g){let v=s.rawByNsKey.get(`${p.package_}@${c}`);return v!==void 0?S(200,R[".kan.yml"],v):P(e)}let u=s.pkgSelfByVer.get(`${p.package_}@${c}`);if(!u)return P(e);if(d===".css")return S(200,R[".css"],r.renderStylesheet(u));if(!y)return ke(l+"/");let h=p.versionSpec.kind==="any";if(h&&!r.hasDeclaredView(u)){let v=(s.pkgVersions.get(p.package_)||[]).map(x=>x.verStr);return S(200,R[".html"],r.renderPackageVersionList(p.package_,v,u))}return S(200,R[".html"],r.renderDocument(u,h?{bareOverview:!0}:void 0))}if(p.kind==="resource"){let c=se(s,p.package_,p.versionSpec);if(!c)return P(e);let u=s.bySubject.get(`${t}/${p.package_}@${c}/${p.name}`);if(!u)return P(e);switch(d){case".css":return S(200,R[".css"],r.renderStylesheet(u));case".svg":return S(200,R[".svg"],r.renderSvg(u));case".md":{let h=r.renderRawMarkdown(u);return h===void 0?P(e):S(200,R[".md"],h)}default:return S(200,R[".html"],r.renderDocument(u))}}return P(e)}var U=class{constructor(e={}){this.options=e}options;models=new Map;clearCache(){this.models.clear()}async modelFor(e){let n=this.models.get(e);if(n)return n;let r=this.options.fetchFn?{fetchFn:this.options.fetchFn}:{},t;if(this.options.root!==void 0)try{t=await q(this.options.root,{publisher:e})}catch(d){if(!/not found in workspace/i.test(d.message))throw d;t=await O(e,r)}else t=await O(e,r);return t.lookRenderer.setLinkMode("open-world"),this.models.set(e,t),t}async handle(e,n=""){let r=e.split("/").filter(Boolean);if(r.length===0)return{status:200,headers:{"Content-Type":"text/html; charset=utf-8"},body:ae()};let t=r[0];if(!t.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 d=await this.modelFor(t),m=e.endsWith("/")&&r.length>1?"/":"",l="/"+r.slice(1).join("/")+m,g=T(d,l,n);return g.headers.Location?{...g,headers:{...g.headers,Location:`/${t}${g.headers.Location}`}}:g}};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{$ as ClosureScopedRepository,U as RequestRouter,ne as UNIVERSAL_RENDER_BASE,j as deriveImportClosure,ae as landingPage,O as loadResourceModel,q as loadServerModel,B as renderRefKey,A as resolveRenderContract,T as route};
@@ -0,0 +1,53 @@
1
+ import type { ServerModel, RouteResponse } from './types.js';
2
+ import type { AuthenticatedFetchFn } from '../auth/index.js';
3
+ export interface RequestRouterOptions {
4
+ /**
5
+ * Workspace root, for publishers that are LOCAL (served from disk with live
6
+ * edits). Omit for a pure remote router that fetches every publisher over
7
+ * HTTP.
8
+ */
9
+ root?: string;
10
+ /** Authenticated fetch for remote publisher fetches (auth / testing). */
11
+ fetchFn?: AuthenticatedFetchFn;
12
+ }
13
+ /**
14
+ * The request-driven routing engine: maps a publisher-FIRST path
15
+ * (`/{publisher}/{package}/{version}/{resource}`) to a response by deriving the
16
+ * publisher from the first path segment and building a per-publisher
17
+ * {@link ServerModel} on demand — from the workspace if that publisher is local
18
+ * (when `root` is set), else fetched over HTTP via {@link loadResourceModel}.
19
+ * One model is cached per publisher.
20
+ *
21
+ * This is the canonical request-driven engine shared by `kanonak serve`
22
+ * (request-driven mode) and the VS Code extension's `EmbeddedServer`: both are
23
+ * thin HTTP listeners over it, exactly as they already share `route` and
24
+ * `loadServerModel`. It is pure of transport concerns — CORS, logging, the
25
+ * choice of status code for an upstream failure — which belong to the listener.
26
+ */
27
+ export declare class RequestRouter {
28
+ private readonly options;
29
+ private readonly models;
30
+ constructor(options?: RequestRouterOptions);
31
+ /** Drop cached models — e.g. after a workspace `.kan.yml` change. */
32
+ clearCache(): void;
33
+ /**
34
+ * The model for one publisher, built on first use and cached. A local
35
+ * workspace publisher is served from disk; any other publisher is fetched
36
+ * over HTTP (its latest catalogue). Throws if neither resolves.
37
+ */
38
+ modelFor(publisher: string): Promise<ServerModel>;
39
+ /**
40
+ * Route one publisher-first path:
41
+ * - `/` → a landing page (no single publisher to show);
42
+ * - a first segment that isn't a domain → 404;
43
+ * - otherwise → the resource rendered via {@link route} against the
44
+ * publisher's model, with any redirect `Location` re-prefixed with the
45
+ * publisher so navigation stays under `/{publisher}/…`.
46
+ *
47
+ * Throws only when a publisher's model can't be built (unreachable / no such
48
+ * publisher); the listener decides how to surface that (e.g. a 502).
49
+ */
50
+ handle(pathname: string, accept?: string): Promise<RouteResponse>;
51
+ }
52
+ /** Minimal landing for the request-driven root, which has no single publisher. */
53
+ export declare function landingPage(): string;
@@ -1,4 +1,4 @@
1
- import{b as X,c as ye}from"../chunk-JYUZT2JU.js";import{a as Ne}from"../chunk-IUCHSPLQ.js";import"../chunk-3NEUHF7E.js";import"../chunk-7JZUJ2K4.js";import"../chunk-NIGFQYVA.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-IL6VHYRU.js";import{a as Ne}from"../chunk-IUCHSPLQ.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,7 +1,7 @@
1
1
  {
2
2
  "name": "@kanonak-protocol/sdk",
3
- "version": "3.60.0",
4
- "description": "Kanonak Protocol SDK - Document repository and parsing implementations for TypeScript",
3
+ "version": "3.61.0",
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",
7
7
  "types": "./dist/index.d.ts",
@@ -106,8 +106,10 @@
106
106
  },
107
107
  "repository": {
108
108
  "type": "git",
109
- "url": "https://github.com/kanonak-protocol"
109
+ "url": "https://github.com/kanonak-protocol/typescript.git",
110
+ "directory": "sdk"
110
111
  },
112
+ "homepage": "https://kanonak.org",
111
113
  "publishConfig": {
112
114
  "registry": "https://npm.pkg.github.com"
113
115
  },
@@ -121,7 +123,7 @@
121
123
  "yaml-parser"
122
124
  ],
123
125
  "dependencies": {
124
- "@kanonak-protocol/types": "^3.60.0",
126
+ "@kanonak-protocol/types": "^3.61.0",
125
127
  "ignore": "^7.0.5",
126
128
  "js-yaml": "^4.1.0",
127
129
  "yaml": "^2.7.0"