@feltdb/feltkit 0.3.7 → 0.3.8

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.
@@ -9,7 +9,7 @@ Error generating stack: `+n.message+`
9
9
  `).replace(Ay,"")}function th(e,t){return t=eh(t),eh(e)===t}function Me(e,t,a,n,s,c){switch(a){case"children":typeof n=="string"?t==="body"||t==="textarea"&&n===""||kl(e,n):(typeof n=="number"||typeof n=="bigint")&&t!=="body"&&kl(e,""+n);break;case"className":yi(e,"class",n);break;case"tabIndex":yi(e,"tabindex",n);break;case"dir":case"role":case"viewBox":case"width":case"height":yi(e,a,n);break;case"style":Pr(e,n,c);break;case"data":if(t!=="object"){yi(e,"data",n);break}case"src":case"href":if(n===""&&(t!=="a"||a!=="href")){e.removeAttribute(a);break}if(n==null||typeof n=="function"||typeof n=="symbol"||typeof n=="boolean"){e.removeAttribute(a);break}n=bi(""+n),e.setAttribute(a,n);break;case"action":case"formAction":if(typeof n=="function"){e.setAttribute(a,"javascript:throw new Error('A React form was unexpectedly submitted. If you called form.submit() manually, consider using form.requestSubmit() instead. If you\\'re trying to use event.stopPropagation() in a submit event handler, consider also calling event.preventDefault().')");break}else typeof c=="function"&&(a==="formAction"?(t!=="input"&&Me(e,t,"name",s.name,s,null),Me(e,t,"formEncType",s.formEncType,s,null),Me(e,t,"formMethod",s.formMethod,s,null),Me(e,t,"formTarget",s.formTarget,s,null)):(Me(e,t,"encType",s.encType,s,null),Me(e,t,"method",s.method,s,null),Me(e,t,"target",s.target,s,null)));if(n==null||typeof n=="symbol"||typeof n=="boolean"){e.removeAttribute(a);break}n=bi(""+n),e.setAttribute(a,n);break;case"onClick":n!=null&&(e.onclick=ra);break;case"onScroll":n!=null&&ge("scroll",e);break;case"onScrollEnd":n!=null&&ge("scrollend",e);break;case"dangerouslySetInnerHTML":if(n!=null){if(typeof n!="object"||!("__html"in n))throw Error(r(61));if(a=n.__html,a!=null){if(s.children!=null)throw Error(r(60));e.innerHTML=a}}break;case"multiple":e.multiple=n&&typeof n!="function"&&typeof n!="symbol";break;case"muted":e.muted=n&&typeof n!="function"&&typeof n!="symbol";break;case"suppressContentEditableWarning":case"suppressHydrationWarning":case"defaultValue":case"defaultChecked":case"innerHTML":case"ref":break;case"autoFocus":break;case"xlinkHref":if(n==null||typeof n=="function"||typeof n=="boolean"||typeof n=="symbol"){e.removeAttribute("xlink:href");break}a=bi(""+n),e.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",a);break;case"contentEditable":case"spellCheck":case"draggable":case"value":case"autoReverse":case"externalResourcesRequired":case"focusable":case"preserveAlpha":n!=null&&typeof n!="function"&&typeof n!="symbol"?e.setAttribute(a,""+n):e.removeAttribute(a);break;case"inert":case"allowFullScreen":case"async":case"autoPlay":case"controls":case"default":case"defer":case"disabled":case"disablePictureInPicture":case"disableRemotePlayback":case"formNoValidate":case"hidden":case"loop":case"noModule":case"noValidate":case"open":case"playsInline":case"readOnly":case"required":case"reversed":case"scoped":case"seamless":case"itemScope":n&&typeof n!="function"&&typeof n!="symbol"?e.setAttribute(a,""):e.removeAttribute(a);break;case"capture":case"download":n===!0?e.setAttribute(a,""):n!==!1&&n!=null&&typeof n!="function"&&typeof n!="symbol"?e.setAttribute(a,n):e.removeAttribute(a);break;case"cols":case"rows":case"size":case"span":n!=null&&typeof n!="function"&&typeof n!="symbol"&&!isNaN(n)&&1<=n?e.setAttribute(a,n):e.removeAttribute(a);break;case"rowSpan":case"start":n==null||typeof n=="function"||typeof n=="symbol"||isNaN(n)?e.removeAttribute(a):e.setAttribute(a,n);break;case"popover":ge("beforetoggle",e),ge("toggle",e),vi(e,"popover",n);break;case"xlinkActuate":ua(e,"http://www.w3.org/1999/xlink","xlink:actuate",n);break;case"xlinkArcrole":ua(e,"http://www.w3.org/1999/xlink","xlink:arcrole",n);break;case"xlinkRole":ua(e,"http://www.w3.org/1999/xlink","xlink:role",n);break;case"xlinkShow":ua(e,"http://www.w3.org/1999/xlink","xlink:show",n);break;case"xlinkTitle":ua(e,"http://www.w3.org/1999/xlink","xlink:title",n);break;case"xlinkType":ua(e,"http://www.w3.org/1999/xlink","xlink:type",n);break;case"xmlBase":ua(e,"http://www.w3.org/XML/1998/namespace","xml:base",n);break;case"xmlLang":ua(e,"http://www.w3.org/XML/1998/namespace","xml:lang",n);break;case"xmlSpace":ua(e,"http://www.w3.org/XML/1998/namespace","xml:space",n);break;case"is":vi(e,"is",n);break;case"innerText":case"textContent":break;default:(!(2<a.length)||a[0]!=="o"&&a[0]!=="O"||a[1]!=="n"&&a[1]!=="N")&&(a=tv.get(a)||a,vi(e,a,n))}}function Bu(e,t,a,n,s,c){switch(a){case"style":Pr(e,n,c);break;case"dangerouslySetInnerHTML":if(n!=null){if(typeof n!="object"||!("__html"in n))throw Error(r(61));if(a=n.__html,a!=null){if(s.children!=null)throw Error(r(60));e.innerHTML=a}}break;case"children":typeof n=="string"?kl(e,n):(typeof n=="number"||typeof n=="bigint")&&kl(e,""+n);break;case"onScroll":n!=null&&ge("scroll",e);break;case"onScrollEnd":n!=null&&ge("scrollend",e);break;case"onClick":n!=null&&(e.onclick=ra);break;case"suppressContentEditableWarning":case"suppressHydrationWarning":case"innerHTML":case"ref":break;case"innerText":case"textContent":break;default:if(!Qr.hasOwnProperty(a))e:{if(a[0]==="o"&&a[1]==="n"&&(s=a.endsWith("Capture"),t=a.slice(2,s?a.length-7:void 0),c=e[bt]||null,c=c!=null?c[a]:null,typeof c=="function"&&e.removeEventListener(t,c,s),typeof n=="function")){typeof c!="function"&&c!==null&&(a in e?e[a]=null:e.hasAttribute(a)&&e.removeAttribute(a)),e.addEventListener(t,n,s);break e}a in e?e[a]=n:n===!0?e.setAttribute(a,""):vi(e,a,n)}}}function ft(e,t,a){switch(t){case"div":case"span":case"svg":case"path":case"a":case"g":case"p":case"li":break;case"img":ge("error",e),ge("load",e);var n=!1,s=!1,c;for(c in a)if(a.hasOwnProperty(c)){var o=a[c];if(o!=null)switch(c){case"src":n=!0;break;case"srcSet":s=!0;break;case"children":case"dangerouslySetInnerHTML":throw Error(r(137,t));default:Me(e,t,c,o,a,null)}}s&&Me(e,t,"srcSet",a.srcSet,a,null),n&&Me(e,t,"src",a.src,a,null);return;case"input":ge("invalid",e);var m=c=o=s=null,S=null,O=null;for(n in a)if(a.hasOwnProperty(n)){var U=a[n];if(U!=null)switch(n){case"name":s=U;break;case"type":o=U;break;case"checked":S=U;break;case"defaultChecked":O=U;break;case"value":c=U;break;case"defaultValue":m=U;break;case"children":case"dangerouslySetInnerHTML":if(U!=null)throw Error(r(137,t));break;default:Me(e,t,n,U,a,null)}}Jr(e,c,m,S,O,o,s,!1);return;case"select":ge("invalid",e),n=o=c=null;for(s in a)if(a.hasOwnProperty(s)&&(m=a[s],m!=null))switch(s){case"value":c=m;break;case"defaultValue":o=m;break;case"multiple":n=m;default:Me(e,t,s,m,a,null)}t=c,a=o,e.multiple=!!n,t!=null?Al(e,!!n,t,!1):a!=null&&Al(e,!!n,a,!0);return;case"textarea":ge("invalid",e),c=s=n=null;for(o in a)if(a.hasOwnProperty(o)&&(m=a[o],m!=null))switch(o){case"value":n=m;break;case"defaultValue":s=m;break;case"children":c=m;break;case"dangerouslySetInnerHTML":if(m!=null)throw Error(r(91));break;default:Me(e,t,o,m,a,null)}Wr(e,n,s,c);return;case"option":for(S in a)a.hasOwnProperty(S)&&(n=a[S],n!=null)&&(S==="selected"?e.selected=n&&typeof n!="function"&&typeof n!="symbol":Me(e,t,S,n,a,null));return;case"dialog":ge("beforetoggle",e),ge("toggle",e),ge("cancel",e),ge("close",e);break;case"iframe":case"object":ge("load",e);break;case"video":case"audio":for(n=0;n<Kn.length;n++)ge(Kn[n],e);break;case"image":ge("error",e),ge("load",e);break;case"details":ge("toggle",e);break;case"embed":case"source":case"link":ge("error",e),ge("load",e);case"area":case"base":case"br":case"col":case"hr":case"keygen":case"meta":case"param":case"track":case"wbr":case"menuitem":for(O in a)if(a.hasOwnProperty(O)&&(n=a[O],n!=null))switch(O){case"children":case"dangerouslySetInnerHTML":throw Error(r(137,t));default:Me(e,t,O,n,a,null)}return;default:if(Ps(t)){for(U in a)a.hasOwnProperty(U)&&(n=a[U],n!==void 0&&Bu(e,t,U,n,a,void 0));return}}for(m in a)a.hasOwnProperty(m)&&(n=a[m],n!=null&&Me(e,t,m,n,a,null))}function ky(e,t,a,n){switch(t){case"div":case"span":case"svg":case"path":case"a":case"g":case"p":case"li":break;case"input":var s=null,c=null,o=null,m=null,S=null,O=null,U=null;for(M in a){var L=a[M];if(a.hasOwnProperty(M)&&L!=null)switch(M){case"checked":break;case"value":break;case"defaultValue":S=L;default:n.hasOwnProperty(M)||Me(e,t,M,null,n,L)}}for(var D in n){var M=n[D];if(L=a[D],n.hasOwnProperty(D)&&(M!=null||L!=null))switch(D){case"type":c=M;break;case"name":s=M;break;case"checked":O=M;break;case"defaultChecked":U=M;break;case"value":o=M;break;case"defaultValue":m=M;break;case"children":case"dangerouslySetInnerHTML":if(M!=null)throw Error(r(137,t));break;default:M!==L&&Me(e,t,D,M,n,L)}}Ws(e,o,m,S,O,U,c,s);return;case"select":M=o=m=D=null;for(c in a)if(S=a[c],a.hasOwnProperty(c)&&S!=null)switch(c){case"value":break;case"multiple":M=S;default:n.hasOwnProperty(c)||Me(e,t,c,null,n,S)}for(s in n)if(c=n[s],S=a[s],n.hasOwnProperty(s)&&(c!=null||S!=null))switch(s){case"value":D=c;break;case"defaultValue":m=c;break;case"multiple":o=c;default:c!==S&&Me(e,t,s,c,n,S)}t=m,a=o,n=M,D!=null?Al(e,!!a,D,!1):!!n!=!!a&&(t!=null?Al(e,!!a,t,!0):Al(e,!!a,a?[]:"",!1));return;case"textarea":M=D=null;for(m in a)if(s=a[m],a.hasOwnProperty(m)&&s!=null&&!n.hasOwnProperty(m))switch(m){case"value":break;case"children":break;default:Me(e,t,m,null,n,s)}for(o in n)if(s=n[o],c=a[o],n.hasOwnProperty(o)&&(s!=null||c!=null))switch(o){case"value":D=s;break;case"defaultValue":M=s;break;case"children":break;case"dangerouslySetInnerHTML":if(s!=null)throw Error(r(91));break;default:s!==c&&Me(e,t,o,s,n,c)}Fr(e,D,M);return;case"option":for(var F in a)D=a[F],a.hasOwnProperty(F)&&D!=null&&!n.hasOwnProperty(F)&&(F==="selected"?e.selected=!1:Me(e,t,F,null,n,D));for(S in n)D=n[S],M=a[S],n.hasOwnProperty(S)&&D!==M&&(D!=null||M!=null)&&(S==="selected"?e.selected=D&&typeof D!="function"&&typeof D!="symbol":Me(e,t,S,D,n,M));return;case"img":case"link":case"area":case"base":case"br":case"col":case"embed":case"hr":case"keygen":case"meta":case"param":case"source":case"track":case"wbr":case"menuitem":for(var ie in a)D=a[ie],a.hasOwnProperty(ie)&&D!=null&&!n.hasOwnProperty(ie)&&Me(e,t,ie,null,n,D);for(O in n)if(D=n[O],M=a[O],n.hasOwnProperty(O)&&D!==M&&(D!=null||M!=null))switch(O){case"children":case"dangerouslySetInnerHTML":if(D!=null)throw Error(r(137,t));break;default:Me(e,t,O,D,n,M)}return;default:if(Ps(t)){for(var Ue in a)D=a[Ue],a.hasOwnProperty(Ue)&&D!==void 0&&!n.hasOwnProperty(Ue)&&Bu(e,t,Ue,void 0,n,D);for(U in n)D=n[U],M=a[U],!n.hasOwnProperty(U)||D===M||D===void 0&&M===void 0||Bu(e,t,U,D,n,M);return}}for(var T in a)D=a[T],a.hasOwnProperty(T)&&D!=null&&!n.hasOwnProperty(T)&&Me(e,t,T,null,n,D);for(L in n)D=n[L],M=a[L],!n.hasOwnProperty(L)||D===M||D==null&&M==null||Me(e,t,L,D,n,M)}function ah(e){switch(e){case"css":case"script":case"font":case"img":case"image":case"input":case"link":return!0;default:return!1}}function Cy(){if(typeof performance.getEntriesByType=="function"){for(var e=0,t=0,a=performance.getEntriesByType("resource"),n=0;n<a.length;n++){var s=a[n],c=s.transferSize,o=s.initiatorType,m=s.duration;if(c&&m&&ah(o)){for(o=0,m=s.responseEnd,n+=1;n<a.length;n++){var S=a[n],O=S.startTime;if(O>m)break;var U=S.transferSize,L=S.initiatorType;U&&ah(L)&&(S=S.responseEnd,o+=U*(S<m?1:(m-O)/(S-O)))}if(--n,t+=8*(c+o)/(s.duration/1e3),e++,10<e)break}}if(0<e)return t/e/1e6}return navigator.connection&&(e=navigator.connection.downlink,typeof e=="number")?e:5}var Lu=null,Yu=null;function hs(e){return e.nodeType===9?e:e.ownerDocument}function lh(e){switch(e){case"http://www.w3.org/2000/svg":return 1;case"http://www.w3.org/1998/Math/MathML":return 2;default:return 0}}function nh(e,t){if(e===0)switch(t){case"svg":return 1;case"math":return 2;default:return 0}return e===1&&t==="foreignObject"?0:e}function Gu(e,t){return e==="textarea"||e==="noscript"||typeof t.children=="string"||typeof t.children=="number"||typeof t.children=="bigint"||typeof t.dangerouslySetInnerHTML=="object"&&t.dangerouslySetInnerHTML!==null&&t.dangerouslySetInnerHTML.__html!=null}var Vu=null;function Oy(){var e=window.event;return e&&e.type==="popstate"?e===Vu?!1:(Vu=e,!0):(Vu=null,!1)}var ih=typeof setTimeout=="function"?setTimeout:void 0,zy=typeof clearTimeout=="function"?clearTimeout:void 0,sh=typeof Promise=="function"?Promise:void 0,Dy=typeof queueMicrotask=="function"?queueMicrotask:typeof sh<"u"?function(e){return sh.resolve(null).then(e).catch(wy)}:ih;function wy(e){setTimeout(function(){throw e})}function Za(e){return e==="head"}function ch(e,t){var a=t,n=0;do{var s=a.nextSibling;if(e.removeChild(a),s&&s.nodeType===8)if(a=s.data,a==="/$"||a==="/&"){if(n===0){e.removeChild(s),sn(t);return}n--}else if(a==="$"||a==="$?"||a==="$~"||a==="$!"||a==="&")n++;else if(a==="html")Fn(e.ownerDocument.documentElement);else if(a==="head"){a=e.ownerDocument.head,Fn(a);for(var c=a.firstChild;c;){var o=c.nextSibling,m=c.nodeName;c[mn]||m==="SCRIPT"||m==="STYLE"||m==="LINK"&&c.rel.toLowerCase()==="stylesheet"||a.removeChild(c),c=o}}else a==="body"&&Fn(e.ownerDocument.body);a=s}while(a);sn(t)}function uh(e,t){var a=e;e=0;do{var n=a.nextSibling;if(a.nodeType===1?t?(a._stashedDisplay=a.style.display,a.style.display="none"):(a.style.display=a._stashedDisplay||"",a.getAttribute("style")===""&&a.removeAttribute("style")):a.nodeType===3&&(t?(a._stashedText=a.nodeValue,a.nodeValue=""):a.nodeValue=a._stashedText||""),n&&n.nodeType===8)if(a=n.data,a==="/$"){if(e===0)break;e--}else a!=="$"&&a!=="$?"&&a!=="$~"&&a!=="$!"||e++;a=n}while(a)}function Qu(e){var t=e.firstChild;for(t&&t.nodeType===10&&(t=t.nextSibling);t;){var a=t;switch(t=t.nextSibling,a.nodeName){case"HTML":case"HEAD":case"BODY":Qu(a),Js(a);continue;case"SCRIPT":case"STYLE":continue;case"LINK":if(a.rel.toLowerCase()==="stylesheet")continue}e.removeChild(a)}}function Ry(e,t,a,n){for(;e.nodeType===1;){var s=a;if(e.nodeName.toLowerCase()!==t.toLowerCase()){if(!n&&(e.nodeName!=="INPUT"||e.type!=="hidden"))break}else if(n){if(!e[mn])switch(t){case"meta":if(!e.hasAttribute("itemprop"))break;return e;case"link":if(c=e.getAttribute("rel"),c==="stylesheet"&&e.hasAttribute("data-precedence"))break;if(c!==s.rel||e.getAttribute("href")!==(s.href==null||s.href===""?null:s.href)||e.getAttribute("crossorigin")!==(s.crossOrigin==null?null:s.crossOrigin)||e.getAttribute("title")!==(s.title==null?null:s.title))break;return e;case"style":if(e.hasAttribute("data-precedence"))break;return e;case"script":if(c=e.getAttribute("src"),(c!==(s.src==null?null:s.src)||e.getAttribute("type")!==(s.type==null?null:s.type)||e.getAttribute("crossorigin")!==(s.crossOrigin==null?null:s.crossOrigin))&&c&&e.hasAttribute("async")&&!e.hasAttribute("itemprop"))break;return e;default:return e}}else if(t==="input"&&e.type==="hidden"){var c=s.name==null?null:""+s.name;if(s.type==="hidden"&&e.getAttribute("name")===c)return e}else return e;if(e=Kt(e.nextSibling),e===null)break}return null}function My(e,t,a){if(t==="")return null;for(;e.nodeType!==3;)if((e.nodeType!==1||e.nodeName!=="INPUT"||e.type!=="hidden")&&!a||(e=Kt(e.nextSibling),e===null))return null;return e}function rh(e,t){for(;e.nodeType!==8;)if((e.nodeType!==1||e.nodeName!=="INPUT"||e.type!=="hidden")&&!t||(e=Kt(e.nextSibling),e===null))return null;return e}function Xu(e){return e.data==="$?"||e.data==="$~"}function $u(e){return e.data==="$!"||e.data==="$?"&&e.ownerDocument.readyState!=="loading"}function Uy(e,t){var a=e.ownerDocument;if(e.data==="$~")e._reactRetry=t;else if(e.data!=="$?"||a.readyState!=="loading")t();else{var n=function(){t(),a.removeEventListener("DOMContentLoaded",n)};a.addEventListener("DOMContentLoaded",n),e._reactRetry=n}}function Kt(e){for(;e!=null;e=e.nextSibling){var t=e.nodeType;if(t===1||t===3)break;if(t===8){if(t=e.data,t==="$"||t==="$!"||t==="$?"||t==="$~"||t==="&"||t==="F!"||t==="F")break;if(t==="/$"||t==="/&")return null}}return e}var Zu=null;function oh(e){e=e.nextSibling;for(var t=0;e;){if(e.nodeType===8){var a=e.data;if(a==="/$"||a==="/&"){if(t===0)return Kt(e.nextSibling);t--}else a!=="$"&&a!=="$!"&&a!=="$?"&&a!=="$~"&&a!=="&"||t++}e=e.nextSibling}return null}function dh(e){e=e.previousSibling;for(var t=0;e;){if(e.nodeType===8){var a=e.data;if(a==="$"||a==="$!"||a==="$?"||a==="$~"||a==="&"){if(t===0)return e;t--}else a!=="/$"&&a!=="/&"||t++}e=e.previousSibling}return null}function fh(e,t,a){switch(t=hs(a),e){case"html":if(e=t.documentElement,!e)throw Error(r(452));return e;case"head":if(e=t.head,!e)throw Error(r(453));return e;case"body":if(e=t.body,!e)throw Error(r(454));return e;default:throw Error(r(451))}}function Fn(e){for(var t=e.attributes;t.length;)e.removeAttributeNode(t[0]);Js(e)}var Jt=new Map,hh=new Set;function ms(e){return typeof e.getRootNode=="function"?e.getRootNode():e.nodeType===9?e:e.ownerDocument}var Ea=$.d;$.d={f:qy,r:Hy,D:By,C:Ly,L:Yy,m:Gy,X:Qy,S:Vy,M:Xy};function qy(){var e=Ea.f(),t=is();return e||t}function Hy(e){var t=_l(e);t!==null&&t.tag===5&&t.type==="form"?Cd(t):Ea.r(e)}var an=typeof document>"u"?null:document;function mh(e,t,a){var n=an;if(n&&typeof t=="string"&&t){var s=Yt(t);s='link[rel="'+e+'"][href="'+s+'"]',typeof a=="string"&&(s+='[crossorigin="'+a+'"]'),hh.has(s)||(hh.add(s),e={rel:e,crossOrigin:a,href:t},n.querySelector(s)===null&&(t=n.createElement("link"),ft(t,"link",e),st(t),n.head.appendChild(t)))}}function By(e){Ea.D(e),mh("dns-prefetch",e,null)}function Ly(e,t){Ea.C(e,t),mh("preconnect",e,t)}function Yy(e,t,a){Ea.L(e,t,a);var n=an;if(n&&e&&t){var s='link[rel="preload"][as="'+Yt(t)+'"]';t==="image"&&a&&a.imageSrcSet?(s+='[imagesrcset="'+Yt(a.imageSrcSet)+'"]',typeof a.imageSizes=="string"&&(s+='[imagesizes="'+Yt(a.imageSizes)+'"]')):s+='[href="'+Yt(e)+'"]';var c=s;switch(t){case"style":c=ln(e);break;case"script":c=nn(e)}Jt.has(c)||(e=g({rel:"preload",href:t==="image"&&a&&a.imageSrcSet?void 0:e,as:t},a),Jt.set(c,e),n.querySelector(s)!==null||t==="style"&&n.querySelector(Wn(c))||t==="script"&&n.querySelector(In(c))||(t=n.createElement("link"),ft(t,"link",e),st(t),n.head.appendChild(t)))}}function Gy(e,t){Ea.m(e,t);var a=an;if(a&&e){var n=t&&typeof t.as=="string"?t.as:"script",s='link[rel="modulepreload"][as="'+Yt(n)+'"][href="'+Yt(e)+'"]',c=s;switch(n){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":c=nn(e)}if(!Jt.has(c)&&(e=g({rel:"modulepreload",href:e},t),Jt.set(c,e),a.querySelector(s)===null)){switch(n){case"audioworklet":case"paintworklet":case"serviceworker":case"sharedworker":case"worker":case"script":if(a.querySelector(In(c)))return}n=a.createElement("link"),ft(n,"link",e),st(n),a.head.appendChild(n)}}}function Vy(e,t,a){Ea.S(e,t,a);var n=an;if(n&&e){var s=El(n).hoistableStyles,c=ln(e);t=t||"default";var o=s.get(c);if(!o){var m={loading:0,preload:null};if(o=n.querySelector(Wn(c)))m.loading=5;else{e=g({rel:"stylesheet",href:e,"data-precedence":t},a),(a=Jt.get(c))&&Ku(e,a);var S=o=n.createElement("link");st(S),ft(S,"link",e),S._p=new Promise(function(O,U){S.onload=O,S.onerror=U}),S.addEventListener("load",function(){m.loading|=1}),S.addEventListener("error",function(){m.loading|=2}),m.loading|=4,vs(o,t,n)}o={type:"stylesheet",instance:o,count:1,state:m},s.set(c,o)}}}function Qy(e,t){Ea.X(e,t);var a=an;if(a&&e){var n=El(a).hoistableScripts,s=nn(e),c=n.get(s);c||(c=a.querySelector(In(s)),c||(e=g({src:e,async:!0},t),(t=Jt.get(s))&&Ju(e,t),c=a.createElement("script"),st(c),ft(c,"link",e),a.head.appendChild(c)),c={type:"script",instance:c,count:1,state:null},n.set(s,c))}}function Xy(e,t){Ea.M(e,t);var a=an;if(a&&e){var n=El(a).hoistableScripts,s=nn(e),c=n.get(s);c||(c=a.querySelector(In(s)),c||(e=g({src:e,async:!0,type:"module"},t),(t=Jt.get(s))&&Ju(e,t),c=a.createElement("script"),st(c),ft(c,"link",e),a.head.appendChild(c)),c={type:"script",instance:c,count:1,state:null},n.set(s,c))}}function vh(e,t,a,n){var s=(s=Q.current)?ms(s):null;if(!s)throw Error(r(446));switch(e){case"meta":case"title":return null;case"style":return typeof a.precedence=="string"&&typeof a.href=="string"?(t=ln(a.href),a=El(s).hoistableStyles,n=a.get(t),n||(n={type:"style",instance:null,count:0,state:null},a.set(t,n)),n):{type:"void",instance:null,count:0,state:null};case"link":if(a.rel==="stylesheet"&&typeof a.href=="string"&&typeof a.precedence=="string"){e=ln(a.href);var c=El(s).hoistableStyles,o=c.get(e);if(o||(s=s.ownerDocument||s,o={type:"stylesheet",instance:null,count:0,state:{loading:0,preload:null}},c.set(e,o),(c=s.querySelector(Wn(e)))&&!c._p&&(o.instance=c,o.state.loading=5),Jt.has(e)||(a={rel:"preload",as:"style",href:a.href,crossOrigin:a.crossOrigin,integrity:a.integrity,media:a.media,hrefLang:a.hrefLang,referrerPolicy:a.referrerPolicy},Jt.set(e,a),c||$y(s,e,a,o.state))),t&&n===null)throw Error(r(528,""));return o}if(t&&n!==null)throw Error(r(529,""));return null;case"script":return t=a.async,a=a.src,typeof a=="string"&&t&&typeof t!="function"&&typeof t!="symbol"?(t=nn(a),a=El(s).hoistableScripts,n=a.get(t),n||(n={type:"script",instance:null,count:0,state:null},a.set(t,n)),n):{type:"void",instance:null,count:0,state:null};default:throw Error(r(444,e))}}function ln(e){return'href="'+Yt(e)+'"'}function Wn(e){return'link[rel="stylesheet"]['+e+"]"}function yh(e){return g({},e,{"data-precedence":e.precedence,precedence:null})}function $y(e,t,a,n){e.querySelector('link[rel="preload"][as="style"]['+t+"]")?n.loading=1:(t=e.createElement("link"),n.preload=t,t.addEventListener("load",function(){return n.loading|=1}),t.addEventListener("error",function(){return n.loading|=2}),ft(t,"link",a),st(t),e.head.appendChild(t))}function nn(e){return'[src="'+Yt(e)+'"]'}function In(e){return"script[async]"+e}function gh(e,t,a){if(t.count++,t.instance===null)switch(t.type){case"style":var n=e.querySelector('style[data-href~="'+Yt(a.href)+'"]');if(n)return t.instance=n,st(n),n;var s=g({},a,{"data-href":a.href,"data-precedence":a.precedence,href:null,precedence:null});return n=(e.ownerDocument||e).createElement("style"),st(n),ft(n,"style",s),vs(n,a.precedence,e),t.instance=n;case"stylesheet":s=ln(a.href);var c=e.querySelector(Wn(s));if(c)return t.state.loading|=4,t.instance=c,st(c),c;n=yh(a),(s=Jt.get(s))&&Ku(n,s),c=(e.ownerDocument||e).createElement("link"),st(c);var o=c;return o._p=new Promise(function(m,S){o.onload=m,o.onerror=S}),ft(c,"link",n),t.state.loading|=4,vs(c,a.precedence,e),t.instance=c;case"script":return c=nn(a.src),(s=e.querySelector(In(c)))?(t.instance=s,st(s),s):(n=a,(s=Jt.get(c))&&(n=g({},a),Ju(n,s)),e=e.ownerDocument||e,s=e.createElement("script"),st(s),ft(s,"link",n),e.head.appendChild(s),t.instance=s);case"void":return null;default:throw Error(r(443,t.type))}else t.type==="stylesheet"&&(t.state.loading&4)===0&&(n=t.instance,t.state.loading|=4,vs(n,a.precedence,e));return t.instance}function vs(e,t,a){for(var n=a.querySelectorAll('link[rel="stylesheet"][data-precedence],style[data-precedence]'),s=n.length?n[n.length-1]:null,c=s,o=0;o<n.length;o++){var m=n[o];if(m.dataset.precedence===t)c=m;else if(c!==s)break}c?c.parentNode.insertBefore(e,c.nextSibling):(t=a.nodeType===9?a.head:a,t.insertBefore(e,t.firstChild))}function Ku(e,t){e.crossOrigin==null&&(e.crossOrigin=t.crossOrigin),e.referrerPolicy==null&&(e.referrerPolicy=t.referrerPolicy),e.title==null&&(e.title=t.title)}function Ju(e,t){e.crossOrigin==null&&(e.crossOrigin=t.crossOrigin),e.referrerPolicy==null&&(e.referrerPolicy=t.referrerPolicy),e.integrity==null&&(e.integrity=t.integrity)}var ys=null;function bh(e,t,a){if(ys===null){var n=new Map,s=ys=new Map;s.set(a,n)}else s=ys,n=s.get(a),n||(n=new Map,s.set(a,n));if(n.has(e))return n;for(n.set(e,null),a=a.getElementsByTagName(e),s=0;s<a.length;s++){var c=a[s];if(!(c[mn]||c[ut]||e==="link"&&c.getAttribute("rel")==="stylesheet")&&c.namespaceURI!=="http://www.w3.org/2000/svg"){var o=c.getAttribute(t)||"";o=e+o;var m=n.get(o);m?m.push(c):n.set(o,[c])}}return n}function xh(e,t,a){e=e.ownerDocument||e,e.head.insertBefore(a,t==="title"?e.querySelector("head > title"):null)}function Zy(e,t,a){if(a===1||t.itemProp!=null)return!1;switch(e){case"meta":case"title":return!0;case"style":if(typeof t.precedence!="string"||typeof t.href!="string"||t.href==="")break;return!0;case"link":if(typeof t.rel!="string"||typeof t.href!="string"||t.href===""||t.onLoad||t.onError)break;return t.rel==="stylesheet"?(e=t.disabled,typeof t.precedence=="string"&&e==null):!0;case"script":if(t.async&&typeof t.async!="function"&&typeof t.async!="symbol"&&!t.onLoad&&!t.onError&&t.src&&typeof t.src=="string")return!0}return!1}function jh(e){return!(e.type==="stylesheet"&&(e.state.loading&3)===0)}function Ky(e,t,a,n){if(a.type==="stylesheet"&&(typeof n.media!="string"||matchMedia(n.media).matches!==!1)&&(a.state.loading&4)===0){if(a.instance===null){var s=ln(n.href),c=t.querySelector(Wn(s));if(c){t=c._p,t!==null&&typeof t=="object"&&typeof t.then=="function"&&(e.count++,e=gs.bind(e),t.then(e,e)),a.state.loading|=4,a.instance=c,st(c);return}c=t.ownerDocument||t,n=yh(n),(s=Jt.get(s))&&Ku(n,s),c=c.createElement("link"),st(c);var o=c;o._p=new Promise(function(m,S){o.onload=m,o.onerror=S}),ft(c,"link",n),a.instance=c}e.stylesheets===null&&(e.stylesheets=new Map),e.stylesheets.set(a,t),(t=a.state.preload)&&(a.state.loading&3)===0&&(e.count++,a=gs.bind(e),t.addEventListener("load",a),t.addEventListener("error",a))}}var Fu=0;function Jy(e,t){return e.stylesheets&&e.count===0&&xs(e,e.stylesheets),0<e.count||0<e.imgCount?function(a){var n=setTimeout(function(){if(e.stylesheets&&xs(e,e.stylesheets),e.unsuspend){var c=e.unsuspend;e.unsuspend=null,c()}},6e4+t);0<e.imgBytes&&Fu===0&&(Fu=62500*Cy());var s=setTimeout(function(){if(e.waitingForImages=!1,e.count===0&&(e.stylesheets&&xs(e,e.stylesheets),e.unsuspend)){var c=e.unsuspend;e.unsuspend=null,c()}},(e.imgBytes>Fu?50:800)+t);return e.unsuspend=a,function(){e.unsuspend=null,clearTimeout(n),clearTimeout(s)}}:null}function gs(){if(this.count--,this.count===0&&(this.imgCount===0||!this.waitingForImages)){if(this.stylesheets)xs(this,this.stylesheets);else if(this.unsuspend){var e=this.unsuspend;this.unsuspend=null,e()}}}var bs=null;function xs(e,t){e.stylesheets=null,e.unsuspend!==null&&(e.count++,bs=new Map,t.forEach(Fy,e),bs=null,gs.call(e))}function Fy(e,t){if(!(t.state.loading&4)){var a=bs.get(e);if(a)var n=a.get(null);else{a=new Map,bs.set(e,a);for(var s=e.querySelectorAll("link[data-precedence],style[data-precedence]"),c=0;c<s.length;c++){var o=s[c];(o.nodeName==="LINK"||o.getAttribute("media")!=="not all")&&(a.set(o.dataset.precedence,o),n=o)}n&&a.set(null,n)}s=t.instance,o=s.getAttribute("data-precedence"),c=a.get(o)||n,c===n&&a.set(null,s),a.set(o,s),this.count++,n=gs.bind(this),s.addEventListener("load",n),s.addEventListener("error",n),c?c.parentNode.insertBefore(s,c.nextSibling):(e=e.nodeType===9?e.head:e,e.insertBefore(s,e.firstChild)),t.state.loading|=4}}var Pn={$$typeof:w,Provider:null,Consumer:null,_currentValue:W,_currentValue2:W,_threadCount:0};function Wy(e,t,a,n,s,c,o,m,S){this.tag=1,this.containerInfo=e,this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.next=this.pendingContext=this.context=this.cancelPendingCommit=null,this.callbackPriority=0,this.expirationTimes=Xs(-1),this.entangledLanes=this.shellSuspendCounter=this.errorRecoveryDisabledLanes=this.expiredLanes=this.warmLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Xs(0),this.hiddenUpdates=Xs(null),this.identifierPrefix=n,this.onUncaughtError=s,this.onCaughtError=c,this.onRecoverableError=o,this.pooledCache=null,this.pooledCacheLanes=0,this.formState=S,this.incompleteTransitions=new Map}function ph(e,t,a,n,s,c,o,m,S,O,U,L){return e=new Wy(e,t,a,o,S,O,U,L,m),t=1,c===!0&&(t|=24),c=zt(3,null,null,t),e.current=c,c.stateNode=e,t=Cc(),t.refCount++,e.pooledCache=t,t.refCount++,c.memoizedState={element:n,isDehydrated:a,cache:t},wc(c),e}function Sh(e){return e?(e=Ml,e):Ml}function Nh(e,t,a,n,s,c){s=Sh(s),n.context===null?n.context=s:n.pendingContext=s,n=Ua(t),n.payload={element:a},c=c===void 0?null:c,c!==null&&(n.callback=c),a=qa(e,n,t),a!==null&&(_t(a,e,t),zn(a,e,t))}function _h(e,t){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var a=e.retryLane;e.retryLane=a!==0&&a<t?a:t}}function Wu(e,t){_h(e,t),(e=e.alternate)&&_h(e,t)}function Eh(e){if(e.tag===13||e.tag===31){var t=cl(e,67108864);t!==null&&_t(t,e,67108864),Wu(e,67108864)}}function Th(e){if(e.tag===13||e.tag===31){var t=Ut();t=$s(t);var a=cl(e,t);a!==null&&_t(a,e,t),Wu(e,t)}}var js=!0;function Iy(e,t,a,n){var s=z.T;z.T=null;var c=$.p;try{$.p=2,Iu(e,t,a,n)}finally{$.p=c,z.T=s}}function Py(e,t,a,n){var s=z.T;z.T=null;var c=$.p;try{$.p=8,Iu(e,t,a,n)}finally{$.p=c,z.T=s}}function Iu(e,t,a,n){if(js){var s=Pu(n);if(s===null)Hu(e,t,n,ps,a),kh(e,n);else if(tg(s,e,t,a,n))n.stopPropagation();else if(kh(e,n),t&4&&-1<eg.indexOf(e)){for(;s!==null;){var c=_l(s);if(c!==null)switch(c.tag){case 3:if(c=c.stateNode,c.current.memoizedState.isDehydrated){var o=al(c.pendingLanes);if(o!==0){var m=c;for(m.pendingLanes|=2,m.entangledLanes|=2;o;){var S=1<<31-Ct(o);m.entanglements[1]|=S,o&=~S}ia(c),(Ae&6)===0&&(ls=At()+500,Zn(0))}}break;case 31:case 13:m=cl(c,2),m!==null&&_t(m,c,2),is(),Wu(c,2)}if(c=Pu(n),c===null&&Hu(e,t,n,ps,a),c===s)break;s=c}s!==null&&n.stopPropagation()}else Hu(e,t,n,null,a)}}function Pu(e){return e=tc(e),er(e)}var ps=null;function er(e){if(ps=null,e=Nl(e),e!==null){var t=v(e);if(t===null)e=null;else{var a=t.tag;if(a===13){if(e=x(t),e!==null)return e;e=null}else if(a===31){if(e=b(t),e!==null)return e;e=null}else if(a===3){if(t.stateNode.current.memoizedState.isDehydrated)return t.tag===3?t.stateNode.containerInfo:null;e=null}else t!==e&&(e=null)}}return ps=e,null}function Ah(e){switch(e){case"beforetoggle":case"cancel":case"click":case"close":case"contextmenu":case"copy":case"cut":case"auxclick":case"dblclick":case"dragend":case"dragstart":case"drop":case"focusin":case"focusout":case"input":case"invalid":case"keydown":case"keypress":case"keyup":case"mousedown":case"mouseup":case"paste":case"pause":case"play":case"pointercancel":case"pointerdown":case"pointerup":case"ratechange":case"reset":case"resize":case"seeked":case"submit":case"toggle":case"touchcancel":case"touchend":case"touchstart":case"volumechange":case"change":case"selectionchange":case"textInput":case"compositionstart":case"compositionend":case"compositionupdate":case"beforeblur":case"afterblur":case"beforeinput":case"blur":case"fullscreenchange":case"focus":case"hashchange":case"popstate":case"select":case"selectstart":return 2;case"drag":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"mousemove":case"mouseout":case"mouseover":case"pointermove":case"pointerout":case"pointerover":case"scroll":case"touchmove":case"wheel":case"mouseenter":case"mouseleave":case"pointerenter":case"pointerleave":return 8;case"message":switch(Bm()){case wr:return 2;case Rr:return 8;case oi:case Lm:return 32;case Mr:return 268435456;default:return 32}default:return 32}}var tr=!1,Ka=null,Ja=null,Fa=null,ei=new Map,ti=new Map,Wa=[],eg="mousedown mouseup touchcancel touchend touchstart auxclick dblclick pointercancel pointerdown pointerup dragend dragstart drop compositionend compositionstart keydown keypress keyup input textInput copy cut paste click change contextmenu reset".split(" ");function kh(e,t){switch(e){case"focusin":case"focusout":Ka=null;break;case"dragenter":case"dragleave":Ja=null;break;case"mouseover":case"mouseout":Fa=null;break;case"pointerover":case"pointerout":ei.delete(t.pointerId);break;case"gotpointercapture":case"lostpointercapture":ti.delete(t.pointerId)}}function ai(e,t,a,n,s,c){return e===null||e.nativeEvent!==c?(e={blockedOn:t,domEventName:a,eventSystemFlags:n,nativeEvent:c,targetContainers:[s]},t!==null&&(t=_l(t),t!==null&&Eh(t)),e):(e.eventSystemFlags|=n,t=e.targetContainers,s!==null&&t.indexOf(s)===-1&&t.push(s),e)}function tg(e,t,a,n,s){switch(t){case"focusin":return Ka=ai(Ka,e,t,a,n,s),!0;case"dragenter":return Ja=ai(Ja,e,t,a,n,s),!0;case"mouseover":return Fa=ai(Fa,e,t,a,n,s),!0;case"pointerover":var c=s.pointerId;return ei.set(c,ai(ei.get(c)||null,e,t,a,n,s)),!0;case"gotpointercapture":return c=s.pointerId,ti.set(c,ai(ti.get(c)||null,e,t,a,n,s)),!0}return!1}function Ch(e){var t=Nl(e.target);if(t!==null){var a=v(t);if(a!==null){if(t=a.tag,t===13){if(t=x(a),t!==null){e.blockedOn=t,Yr(e.priority,function(){Th(a)});return}}else if(t===31){if(t=b(a),t!==null){e.blockedOn=t,Yr(e.priority,function(){Th(a)});return}}else if(t===3&&a.stateNode.current.memoizedState.isDehydrated){e.blockedOn=a.tag===3?a.stateNode.containerInfo:null;return}}}e.blockedOn=null}function Ss(e){if(e.blockedOn!==null)return!1;for(var t=e.targetContainers;0<t.length;){var a=Pu(e.nativeEvent);if(a===null){a=e.nativeEvent;var n=new a.constructor(a.type,a);ec=n,a.target.dispatchEvent(n),ec=null}else return t=_l(a),t!==null&&Eh(t),e.blockedOn=a,!1;t.shift()}return!0}function Oh(e,t,a){Ss(e)&&a.delete(t)}function ag(){tr=!1,Ka!==null&&Ss(Ka)&&(Ka=null),Ja!==null&&Ss(Ja)&&(Ja=null),Fa!==null&&Ss(Fa)&&(Fa=null),ei.forEach(Oh),ti.forEach(Oh)}function Ns(e,t){e.blockedOn===t&&(e.blockedOn=null,tr||(tr=!0,i.unstable_scheduleCallback(i.unstable_NormalPriority,ag)))}var _s=null;function zh(e){_s!==e&&(_s=e,i.unstable_scheduleCallback(i.unstable_NormalPriority,function(){_s===e&&(_s=null);for(var t=0;t<e.length;t+=3){var a=e[t],n=e[t+1],s=e[t+2];if(typeof n!="function"){if(er(n||a)===null)continue;break}var c=_l(a);c!==null&&(e.splice(t,3),t-=3,Pc(c,{pending:!0,data:s,method:a.method,action:n},n,s))}}))}function sn(e){function t(S){return Ns(S,e)}Ka!==null&&Ns(Ka,e),Ja!==null&&Ns(Ja,e),Fa!==null&&Ns(Fa,e),ei.forEach(t),ti.forEach(t);for(var a=0;a<Wa.length;a++){var n=Wa[a];n.blockedOn===e&&(n.blockedOn=null)}for(;0<Wa.length&&(a=Wa[0],a.blockedOn===null);)Ch(a),a.blockedOn===null&&Wa.shift();if(a=(e.ownerDocument||e).$$reactFormReplay,a!=null)for(n=0;n<a.length;n+=3){var s=a[n],c=a[n+1],o=s[bt]||null;if(typeof c=="function")o||zh(a);else if(o){var m=null;if(c&&c.hasAttribute("formAction")){if(s=c,o=c[bt]||null)m=o.formAction;else if(er(s)!==null)continue}else m=o.action;typeof m=="function"?a[n+1]=m:(a.splice(n,3),n-=3),zh(a)}}}function Dh(){function e(c){c.canIntercept&&c.info==="react-transition"&&c.intercept({handler:function(){return new Promise(function(o){return s=o})},focusReset:"manual",scroll:"manual"})}function t(){s!==null&&(s(),s=null),n||setTimeout(a,20)}function a(){if(!n&&!navigation.transition){var c=navigation.currentEntry;c&&c.url!=null&&navigation.navigate(c.url,{state:c.getState(),info:"react-transition",history:"replace"})}}if(typeof navigation=="object"){var n=!1,s=null;return navigation.addEventListener("navigate",e),navigation.addEventListener("navigatesuccess",t),navigation.addEventListener("navigateerror",t),setTimeout(a,100),function(){n=!0,navigation.removeEventListener("navigate",e),navigation.removeEventListener("navigatesuccess",t),navigation.removeEventListener("navigateerror",t),s!==null&&(s(),s=null)}}}function ar(e){this._internalRoot=e}Es.prototype.render=ar.prototype.render=function(e){var t=this._internalRoot;if(t===null)throw Error(r(409));var a=t.current,n=Ut();Nh(a,n,e,t,null,null)},Es.prototype.unmount=ar.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var t=e.containerInfo;Nh(e.current,2,null,e,null,null),is(),t[Sl]=null}};function Es(e){this._internalRoot=e}Es.prototype.unstable_scheduleHydration=function(e){if(e){var t=Lr();e={blockedOn:null,target:e,priority:t};for(var a=0;a<Wa.length&&t!==0&&t<Wa[a].priority;a++);Wa.splice(a,0,e),a===0&&Ch(e)}};var wh=u.version;if(wh!=="19.2.0")throw Error(r(527,wh,"19.2.0"));$.findDOMNode=function(e){var t=e._reactInternals;if(t===void 0)throw typeof e.render=="function"?Error(r(188)):(e=Object.keys(e).join(","),Error(r(268,e)));return e=y(t),e=e!==null?j(e):null,e=e===null?null:e.stateNode,e};var lg={bundleType:0,version:"19.2.0",rendererPackageName:"react-dom",currentDispatcherRef:z,reconcilerVersion:"19.2.0"};if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"){var Ts=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!Ts.isDisabled&&Ts.supportsFiber)try{dn=Ts.inject(lg),kt=Ts}catch{}}return ni.createRoot=function(e,t){if(!h(e))throw Error(r(299));var a=!1,n="",s=Bd,c=Ld,o=Yd;return t!=null&&(t.unstable_strictMode===!0&&(a=!0),t.identifierPrefix!==void 0&&(n=t.identifierPrefix),t.onUncaughtError!==void 0&&(s=t.onUncaughtError),t.onCaughtError!==void 0&&(c=t.onCaughtError),t.onRecoverableError!==void 0&&(o=t.onRecoverableError)),t=ph(e,1,!1,null,null,a,n,null,s,c,o,Dh),e[Sl]=t.current,qu(e),new ar(t)},ni.hydrateRoot=function(e,t,a){if(!h(e))throw Error(r(299));var n=!1,s="",c=Bd,o=Ld,m=Yd,S=null;return a!=null&&(a.unstable_strictMode===!0&&(n=!0),a.identifierPrefix!==void 0&&(s=a.identifierPrefix),a.onUncaughtError!==void 0&&(c=a.onUncaughtError),a.onCaughtError!==void 0&&(o=a.onCaughtError),a.onRecoverableError!==void 0&&(m=a.onRecoverableError),a.formState!==void 0&&(S=a.formState)),t=ph(e,1,!0,t,a??null,n,s,S,c,o,m,Dh),t.context=Sh(null),a=t.current,n=Ut(),n=$s(n),s=Ua(n),s.callback=null,qa(a,s,n),a=n,t.current.lanes=a,hn(t,a),ia(t),e[Sl]=t.current,qu(e),new Es(t)},ni.version="19.2.0",ni}var Vh;function hg(){if(Vh)return ir.exports;Vh=1;function i(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(i)}catch(u){console.error(u)}}return i(),ir.exports=fg(),ir.exports}var mg=hg();const Cs="feltkit.admin-token";function vg(){const i=/(?:^|[#&])token=([^&]+)/.exec(location.hash);if(i){try{sessionStorage.setItem(Cs,decodeURIComponent(i[1]))}catch{}return history.replaceState(null,"",`${location.pathname}#/overview`),decodeURIComponent(i[1])}try{return sessionStorage.getItem(Cs)}catch{return null}}function Qh(i){try{i?sessionStorage.setItem(Cs,i):sessionStorage.removeItem(Cs)}catch{}}class Xh extends Error{constructor(u,d,r){super(d),this.code=u,this.status=r}code;status}let rm=null;const rr=i=>rm=i;let ks=null;const or=i=>ks=i;function om(i){return ks?i?{"x-feltkit-csrf":ks.csrf,"x-feltkit-environment":ks.environment}:{}:{"x-feltkit-admin":rm??""}}async function ne(i,u={}){const d=await fetch(`/_feltkit/api${i}`,{...u,credentials:"same-origin",headers:{...om(!!(u.method&&u.method!=="GET")),...u.body?{"Content-Type":"application/json"}:{},...u.headers??{}}});let r;try{r=await d.json()}catch{throw new Xh("UNAVAILABLE",`The server answered ${d.status}.`,d.status)}if(!d.ok)throw new Xh(r?.error?.code??"INTERNAL",r?.error?.message??`Request failed (${d.status})`,d.status);return r}function yg(i,u){const d=new AbortController;return(async()=>{let r=500;for(;!d.signal.aborted;){try{const h=await fetch("/_feltkit/api/events",{credentials:"same-origin",headers:om(!1),signal:d.signal});if(!h.ok||!h.body)throw new Error(String(h.status));u(!0),r=500;const v=h.body.getReader(),x=new TextDecoder;let b="";for(;;){const{value:f,done:y}=await v.read();if(y)break;b+=x.decode(f,{stream:!0});let j;for(;(j=b.indexOf(`
10
10
 
11
11
  `))>=0;){const g=b.slice(0,j);b=b.slice(j+2);const R=/^event: (.+)$/m.exec(g)?.[1],q=/^data: (.+)$/m.exec(g)?.[1];R&&q&&i(R,JSON.parse(q))}}}catch{}if(u(!1),d.signal.aborted)break;await new Promise(h=>setTimeout(h,r)),r=Math.min(r*2,8e3)}})(),()=>d.abort()}function Rs(i){const u=!!i?.environment?.development,r=(i?.operator?.permissions??[]).some(h=>h==="*"||h==="feltkit.*"||h==="feltkit.operations.*"||h==="feltkit.operations.write");return{development:u,canAct:u||r,actor:i?.operator?.principal?.id??null}}const vr=Object.freeze({positive:"●",progress:"◐",attention:"▲",critical:"✕",neutral:"○",unknown:"?"}),gg=Object.freeze(["verified","verification_failed","not_verified","not_evaluated"]);function dm(i){const u=String(i).replace(/_/g," ");return u&&u[0].toUpperCase()+u.slice(1)}const Se="positive",se="progress",Ft="attention",we="critical",Be="neutral",Pa="unknown",bg={"compute.environment.actual_state":{running:Se,completed:Se,pending:se,starting:se,stopping:se,degraded:Ft,failed:we,denied:we,stopped:Be},"compute.health":{healthy:Se,unhealthy:we,unknown:Pa},"compute.environment.readiness":{ready:Se,created:se,starting:se,degraded:Ft,failed:we,unavailable:we},"compute.process.readiness":{ready:Se,starting:se,unready:Ft},"compute.process.state":{ready:Se,running:Se,pending:se,starting:se,stopping:se,unready:Ft,failed:we,lost:we,stopped:Be,exited:Be,destroyed:Be,expired:Be,unverified:Pa,unreachable:Pa},"compute.deployment.status":{active:Se,complete:Se,pending:se,starting:se,ready:se,network_ready:se,switching:se,draining:se,failed:we,rolled_back:we},"compute.version.status":{published:Se,publishing:se,failed:we},"compute.rollout.status":{active:Se,applying:se,failed:we,superseded:Be},"compute.job.status":{succeeded:Se,created:se,accepted:se,queued:se,waiting_for_capacity:se,reserved:se,admitted:se,preparing:se,running:se,failed:we,rejected:we,timed_out:we,cancelled:Be},"compute.computer.observed":{running:Se,starting:se,reconciling:se,stopping:se,failed:we,lost:we,stopped:Be,destroyed:Be,expired:Be,unverified:Pa,unreachable:Pa},"compute.computer.status":{running:Se,pending:se,provisioning:se,resuming:se,stopping:se,destroying:se,failed:we,lost:we,stopped:Be,destroyed:Be,expired:Be,unreachable:Pa},"feltdb.health.ready_state":{healthy:Se,recovering:se,degraded:Ft,unavailable:we},"feltdb.authority.availability":{available:Se,recovering:se,degraded:Ft,closed:Be,unknown:Pa},"feltdb.authority.lease_clock_healthy":{true:[Se,"Healthy"],false:[Ft,"Degraded"]},"authboundry.decision.live":{allow:[Se,"Allow"],deny:[we,"Deny"]},"authboundry.decision.recorded":{allow:[Se,"Allow"],deny:[Be,"Deny"]},"authboundry.delegation.status":{active:Se,pending:se,revoked:we,expired:Be},"authboundry.application.status":{active:Se,awaiting_contract:se,disabled:Be},"appport.job.status":{completed:Se,scheduled:se,pending:se,running:se,retrying:se,failed:we},"appport.notification.status":{delivered:Se,pending:se,failed:we,read:Be,acknowledged:Be,expired:Be},"appport.api_key.revoked":{false:[Se,"Active"],true:[Be,"Revoked"]},"appport.webhook.disabled":{false:[Se,"Enabled"],true:[Be,"Disabled"]},"appport.schedule.enabled":{true:[Se,"Enabled"],false:[Be,"Disabled"]},"appport.configuration.secret.configured":{true:[Se,"Configured"]},"appboundry.lifecycle.phase":{ACTIVE:[Se,"Active"],DRAFT:[se,"Draft"],VALIDATED:[se,"Validated"],REGISTERED:[se,"Registered"],CHANGE_PROPOSED:[Ft,"Change proposed"],RETIRED:[Be,"Retired"]},"appboundry.provider.compatible":{true:[Se,"Compatible"],false:[Ft,"Incompatible"]},"appboundry.execution.status":{succeeded:Se,running:se,failed:we,timed_out:[we,"Timed out"],cancelled:Be},"appboundry.source.status":{connected:Se,stale:Ft,failed:we,disconnected:Be},"appboundry.implementation.status":{verified:[Se,"Current"],stale:Ft,revoked:we},"appboundry.provider.eligibility":{ELIGIBLE:[Se,"Eligible"],INELIGIBLE:[Be,"Ineligible"]},"appboundry.health.ready":{true:[Se,"Ready"],false:[we,"Not ready"]},"appboundry.health.check":{available:Se,degraded:Ft,unavailable:we}},xg={"feltdb.revision.integrity_verified":{true:"verified",false:"verification_failed"},"appboundry.implementation.verification":{verified:"verified",stale:"not_verified"},"appboundry.attestation.status":{verified:"verified",CONTRACT_MISMATCH:"verification_failed",IDENTITY_MISMATCH:"verification_failed"},"appboundry.conformance.status":{CONFORMING:"verified",NON_CONFORMING:"verification_failed"}},jg={"compute.response.state":{live:"live",cached:"cached",stale:"stale"},"feltdb.snapshot.staleness":{current:"live",stale:"stale",unknown:"unknown"}},Nr=i=>Object.freeze(Object.fromEntries(Object.entries(i).map(([u,d])=>[u,Object.freeze({...d})]))),pg=Nr(bg);Nr(xg);Nr(jg);const Sg=(i,u)=>Object.prototype.hasOwnProperty.call(i,u);function Ng(i,u,d){const r=pg[i];if(!r)throw new Error(`unknown field: ${i}`);const h=String(u),v=Sg(r,h)?r[h]:null,[x,b]=v===null?[Pa,null]:Array.isArray(v)?v:[v,null],f=d&&d.label||b||(v===null?h:dm(h));return{field:i,value:h,tone:x,label:f,glyph:vr[x],mapped:v!==null}}function yr(i,u){const d=_g(u);let r=gg.includes(i)?i:"not_evaluated";return r==="verified"&&d.length===0&&(r="not_evaluated"),r==="verified"&&d.some(h=>h.status==="failed")&&(r="verification_failed"),{state:r,checks:d}}function _g(i){return i?i.map(u=>typeof u=="string"?{label:u}:{label:String(u.label),...u.status?{status:u.status}:{}}):[]}const Ta=Object.freeze({company:Object.freeze({name:"Boundry",href:"https://boundry.company",tagline:"Infrastructure for applications and agents.",family:"Part of the Boundry family of products"}),products:Object.freeze([{id:"feltdb",name:"FeltDB",mark:"FD",category:"Durable state",href:"https://feltdb.com"},{id:"feltkit",name:"FeltKit",mark:"FK",category:"Developer platform",href:"https://getfeltkit.com"},{id:"appboundry",name:"AppBoundry",mark:"AB",category:"Application boundaries",href:"https://appboundry.com"},{id:"authboundry",name:"AuthBoundry",mark:"AU",category:"Authority and delegation",href:"https://authboundry.com"},{id:"appport",name:"AppPort",mark:"AP",category:"Application capabilities",href:"https://boundry.company/ecosystem/#appport"}].map(i=>Object.freeze(i)))});function gr(i){return Ta.products.find(u=>u.id===i)||null}const p=(i,u,d,r,h)=>({t:i,a:u||{},c:d===void 0?[]:[].concat(d),...r?{on:r}:{},...h==null?{}:{k:String(h)}}),dr=i=>!!(i&&typeof i=="object"&&typeof i.t=="string"&&i.a&&Array.isArray(i.c)),he=(...i)=>i.filter(Boolean).join(" "),G=i=>i!=null&&i!=="",me=i=>{const u={};for(const[d,r]of Object.entries(i||{}))(/^(data-|aria-)/.test(d)||d==="id"||d==="title")&&(u[d]=r);return u};function Eg(i){const u=new Date(i);return Number.isNaN(u.getTime())?String(i):`${u.toISOString().slice(0,19).replace("T"," ")} UTC`}const Ms=(i,u)=>{const d=new Date(i);return Number.isNaN(d.getTime())?p("span",{class:u},String(i)):p("time",{class:u,datetime:d.toISOString()},Eg(i))};function Tg(i){const{field:u,value:d,detail:r,className:h,attrs:v}=i,x=u?Ng(u,d,{label:i.label}):null,b=x?x.tone:i.tone||"unknown",f=x?x.label:G(i.label)?i.label:dm(b),y=i.glyph||vr[b]||vr.unknown;return p("span",{class:he("stack-status",`stack-status--${b}`,h),"data-tone":b,...x?{"data-field":x.field,"data-value":x.value}:{},...me(v)},[p("span",{class:"stack-status__glyph","aria-hidden":"true"},y),p("span",{class:"stack-status__label"},f),G(r)?p("span",{class:"stack-status__detail"},r):null])}const Ag={verified:"✓",verification_failed:"✕",not_verified:"!",not_evaluated:"–"};function fm(i){const{state:u,checks:d}=yr(i.state,i.checks),r=d.filter(v=>v.status==="failed");let h;if(u==="verified")h=d.length===1?`Verified · ${d[0].label}`:`Verified · ${d.length} checks`;else if(u==="verification_failed"){const v=r.length?r:d;h=v.length===1?`Verification failed · ${v[0].label}`:v.length?`Verification failed · ${v.length} checks`:"Verification failed"}else h=u==="not_verified"?"Not verified":"Not evaluated";return p("div",{class:he("stack-verification",`stack-verification--${u}`,i.className),"data-verification":u,...me(i.attrs)},[p("span",{class:"stack-verification__glyph","aria-hidden":"true"},Ag[u]),p("span",{class:"stack-verification__label"},h),G(i.at)?[" · ",Ms(i.at,"stack-verification__at")]:null,G(i.evidenceHref)?p("a",{class:"stack-verification__evidence",href:i.evidenceHref},"Evidence"):null,d.length>1?p("ul",{class:"stack-verification__checks"},d.map(v=>p("li",{class:"stack-verification__check",...v.status?{"data-check-status":v.status}:{}},v.status?`${v.label} — ${v.status}`:v.label))):null])}const $h={live:"Live",cached:"Cached",stale:"Stale",unknown:"Freshness unknown"},kg={live:"●",cached:"◷",stale:"▲",unknown:"?"};function Cg(i){const u=$h[i.freshness]?i.freshness:"unknown",d=G(i.asOf)&&u!=="live";return p("span",{class:he("stack-freshness",`stack-freshness--${u}`,i.className),"data-freshness":u,...me(i.attrs)},[p("span",{class:"stack-freshness__glyph","aria-hidden":"true"},kg[u]),p("span",{class:"stack-freshness__label"},[$h[u],d?[" · as of ",Ms(i.asOf,"stack-freshness__as-of")]:null,G(i.source)?` · ${i.source}`:null])])}function Og(i){const u=i.status==="partial"?"partial":"unsupported",d=G(i.title)?i.title:u==="partial"?"Partly available":"Not available";return p("div",{class:he("stack-unavailable",`stack-unavailable--${u}`,i.className),role:"note","data-capability-status":u,...G(i.capability)?{"data-capability":i.capability}:{},...me(i.attrs)},[p(i.headingLevel?Us(i.headingLevel):"p",{class:"stack-unavailable__title"},d),G(i.reason)?p("p",{class:"stack-unavailable__reason"},i.reason):null,i.children||null])}function _r(i){const u=G(i.what)?i.what:"",d=i.long?`Still loading${u?` ${u}`:""}…`:`Loading${u?` ${u}`:""}…`;return p("div",{class:he("stack-loading",i.long?"stack-loading--long":null,i.className),role:"status","aria-live":"polite",...me(i.attrs)},[p("span",{class:"stack-loading__indicator","aria-hidden":"true"}),p("span",{class:"stack-loading__label"},d)])}const Us=i=>`h${Math.min(6,Math.max(1,Number(i)||2))}`;function Er(i){const u=i.variant==="no-match"?"no-match":"empty",d=G(i.title)?i.title:u==="no-match"?"Nothing matches":"Nothing here yet";return p("div",{class:he("stack-empty",`stack-empty--${u}`,i.className),...me(i.attrs)},[p(Us(i.headingLevel),{class:"stack-empty__title"},d),G(i.body)?p("p",{class:"stack-empty__body"},i.body):null,i.action?p("div",{class:"stack-empty__action"},i.action):null])}function qs(i){const u=[G(i.code)?["Code ",p("code",{},i.code)]:null,G(i.requestId)?[G(i.code)?" · ":"","Request ",p("code",{},i.requestId)]:null].filter(Boolean);return p("div",{class:he("stack-error",i.className),role:"alert",...me(i.attrs)},[p("p",{class:"stack-error__title"},G(i.title)?i.title:"Something went wrong"),G(i.message)?p("p",{class:"stack-error__message"},i.message):null,u.length?p("p",{class:"stack-error__meta"},u):null,i.onRetry||i.actions?p("div",{class:"stack-error__actions"},[i.onRetry?sa({label:i.retryLabel||"Retry",onClick:i.onRetry}):null,i.actions||null]):null])}function zg(i){return p("dl",{class:he("stack-meta",i.className),...me(i.attrs)},(i.items||[]).map(u=>{const d=!G(u.value)&&u.value!==0&&u.value!==!1;return p("div",{class:"stack-meta__item",...me(u.attrs)},[p("dt",{class:"stack-meta__label"},u.label),p("dd",{class:he("stack-meta__value",u.mono?"stack-meta__value--mono":null),...d?{"data-missing":"true"}:{}},d?"—":typeof u.value=="boolean"?String(u.value):u.value),G(u.hint)?p("dd",{class:"stack-meta__hint"},u.hint):null])}))}function Dg(i){const u=Number(i.length)||12,d=G(i.id)?String(i.id):null,r=d&&d.length>u?`${d.slice(0,u)}…`:d,h=G(i.name)?p(i.href?"a":"span",{class:"stack-identity__name",...i.href?{href:i.href}:{}},i.name):null;return p("span",{class:he("stack-identity",i.className),...me(i.attrs)},[G(i.kind)?p("span",{class:"stack-identity__kind"},i.kind):null,h,d?p("code",{class:"stack-identity__id",title:d},r===d?d:[p("span",{"aria-hidden":"true"},r),p("span",{class:"stack-visually-hidden"},d)]):null])}function wg(i){return p("header",{class:he("stack-page-header",i.className),...me(i.attrs)},[G(i.eyebrow)?p("p",{class:"stack-page-header__eyebrow"},i.eyebrow):null,p("div",{class:"stack-page-header__title-row"},[p(Us(i.headingLevel||1),{class:"stack-page-header__title"},i.title),i.status?p("span",{class:"stack-page-header__status"},i.status):null,i.actions?p("div",{class:"stack-page-header__actions"},i.actions):null]),G(i.description)?p("p",{class:"stack-page-header__description"},i.description):null,i.meta?p("div",{class:"stack-page-header__meta"},i.meta):null])}const Rg=["primary","secondary","danger","ghost"],Mg=["sm","md","lg"];function sa(i){const u=Rg.includes(i.variant)?i.variant:"secondary",d=Mg.includes(i.size)?i.size:"md",r=!!(i.disabled||i.busy);return p("button",{class:he("stack-button",`stack-button--${u}`,`stack-button--${d}`,i.className),type:i.type==="submit"?"submit":"button",...r?{disabled:!0}:{},...i.busy?{"aria-busy":"true"}:{},...me(i.attrs)},[i.busy?p("span",{class:"stack-button__busy","aria-hidden":"true"}):null,p("span",{class:"stack-button__label"},i.label)],i.onClick&&!r?{click:i.onClick}:void 0)}function Ug(i){const u=(i.items||[]).filter(d=>d&&G(d.label));return p("nav",{class:he("stack-breadcrumbs",i.className),"aria-label":i.label||"Breadcrumb",...me(i.attrs)},p("ol",{class:"stack-breadcrumbs__list"},u.map((d,r)=>{const h=r===u.length-1;return p("li",{class:"stack-breadcrumbs__item"},[r>0?p("span",{class:"stack-breadcrumbs__separator","aria-hidden":"true"},"/"):null,h||!G(d.href)?p("span",{class:"stack-breadcrumbs__current",...h?{"aria-current":"page"}:{}},d.label):p("a",{class:"stack-breadcrumbs__link",href:d.href},d.label)])})))}function qg(i){if(!["ArrowRight","ArrowLeft","ArrowDown","ArrowUp","Home","End"].includes(i.key))return;const d=i.currentTarget,r=Array.from(d.querySelectorAll('[role="tab"]:not([disabled])'));if(!r.length)return;const h=r.indexOf(d.ownerDocument.activeElement),v=d.getAttribute("aria-orientation")==="vertical",x=v?"ArrowDown":"ArrowRight",b=v?"ArrowUp":"ArrowLeft";let f;if(i.key==="Home")f=0;else if(i.key==="End")f=r.length-1;else if(i.key===x)f=h<0?0:(h+1)%r.length;else if(i.key===b)f=h<0?r.length-1:(h-1+r.length)%r.length;else return;i.preventDefault(),r[f].focus()}const nt=i=>String(i).replace(/[^A-Za-z0-9_-]/g,"-"),Hg=i=>u=>{const d=u.currentTarget.ownerDocument.getElementById(i);d&&(u.preventDefault(),d.focus(),typeof d.scrollIntoView=="function"&&d.scrollIntoView())};function Bg(i){const u=nt(i.idPrefix||"stack-tabs"),d=i.tabs||[],r=d.some(h=>h.id===i.active&&!h.disabled)?i.active:null;return p("div",{class:he("stack-tabs",i.className),role:"tablist",...G(i.label)?{"aria-label":i.label}:{},...me(i.attrs)},d.map((h,v)=>{const x=h.id===r,b=x||r===null&&v===0;return p("button",{class:he("stack-tabs__tab",x?"stack-tabs__tab--selected":null,h.className),type:"button",role:"tab",id:`${u}-tab-${nt(h.id)}`,"aria-selected":x?"true":"false",...G(i.panelId)?{"aria-controls":i.panelId}:{},tabindex:b?"0":"-1",...h.disabled?{disabled:!0,...G(h.reason)?{title:h.reason}:{}}:{},...me(h.attrs)},[h.label,G(h.badge)?p("span",{class:"stack-tabs__badge"},h.badge):null],i.onSelect&&!h.disabled?{click:()=>i.onSelect(h.id)}:void 0)}),{keydown:qg})}function Lg(i){const u=nt(i.idPrefix||"stack-tabs");return p("div",{class:he("stack-tabpanel",i.className),role:"tabpanel",id:i.id,...G(i.active)?{"aria-labelledby":`${u}-tab-${nt(i.active)}`}:{},tabindex:"0",...me(i.attrs)},i.children||null)}const Zh={ascending:"▲",descending:"▼"},Yg=i=>u=>{u.target===u.currentTarget&&(u.key!=="Enter"&&u.key!==" "||(u.preventDefault(),i()))};function Gg(i){const u=i.columns||[],d=i.rows||[],r=G(i.label)?i.label:"Table";if(i.error)return qs({title:i.error.title||`${r} could not be read`,message:i.error.message,code:i.error.code,requestId:i.error.requestId,onRetry:i.error.onRetry,className:he("stack-table-state",i.className),attrs:i.attrs});if(i.loading&&!d.length)return _r({what:i.loadingWhat||r.toLowerCase(),className:he("stack-table-state",i.className),attrs:i.attrs});if(!d.length){const b=!!i.noMatch;return Er({variant:b?"no-match":"empty",title:b?i.noMatchTitle||"Nothing matches":i.emptyTitle||"Nothing here yet",body:b?i.noMatchBody:i.emptyBody,action:b?null:i.emptyAction,headingLevel:i.emptyHeadingLevel||3,className:he("stack-table-state",i.className),attrs:i.attrs})}const h=i.sort||{},v=p("thead",{},p("tr",{},u.map(b=>{const f=h.column===b.id&&Zh[h.direction]?h.direction:null,y=b.sortable&&i.onSort?p("button",{class:"stack-table__sort",type:"button"},[b.header,p("span",{class:"stack-table__sort-indicator","aria-hidden":"true"},f?Zh[f]:"↕")],{click:()=>i.onSort(b.id)}):b.header;return p("th",{class:he("stack-table__header",b.align==="end"?"stack-table__cell--end":null),scope:"col",...b.sortable&&i.onSort?{"aria-sort":f||"none"}:{}},y)}))),x=p("tbody",{},d.map(b=>{const f=typeof b.onSelect=="function";return p("tr",{class:he("stack-table__row",f?"stack-table__row--selectable":null,b.selected?"stack-table__row--selected":null,b.className),...f?{tabindex:"0"}:{},...b.selected?{"aria-current":"true"}:{},...me(b.attrs)},u.map(y=>{const j=b.cells?b.cells[y.id]:void 0,g=j==null;return p("td",{class:he("stack-table__cell",y.align==="end"?"stack-table__cell--end":null),...g?{"data-missing":"true"}:{}},g?"—":j)}),f?{click:b.onSelect,keydown:Yg(b.onSelect)}:void 0,b.key)}));return p("div",{class:he("stack-table",i.className),role:"region","aria-label":r,tabindex:"0",...i.loading?{"aria-busy":"true"}:{},...me(i.attrs)},p("table",{class:"stack-table__table"},[p("caption",{class:i.captionVisible?"stack-table__caption":"stack-visually-hidden"},r),v,x]))}function Vg(i,u,d){const r=`${u}-${nt(i.id)}`,h=G(i.value)?String(i.value):"",v=d?b=>d(i.id,b.target.value):null,x=i.type==="select"?p("select",{class:"stack-filter__control",id:r,name:i.id},(i.options||[]).map(b=>{const f=String(typeof b=="object"?b.value:b);return p("option",{value:f,...f===h?{selected:!0}:{}},typeof b=="object"?b.label:b)}),v?{change:v}:void 0):p("input",{class:"stack-filter__control",id:r,name:i.id,type:"search",value:h,...G(i.placeholder)?{placeholder:i.placeholder}:{}},[],v?{input:v}:void 0);return p("div",{class:"stack-filter__field"},[p("label",{class:"stack-filter__label",for:r},i.label),x])}function Qg(i){const u=nt(i.idPrefix||"stack-filter"),d=Number(i.applied)||0;return p("form",{class:he("stack-filter",i.className),role:"search","aria-label":i.label||"Filters",...me(i.attrs)},[p("div",{class:"stack-filter__controls"},[(i.filters||[]).map(r=>Vg(r,u,i.onChange)),p("div",{class:"stack-filter__actions"},[i.live?null:sa({label:i.applyLabel||"Apply",type:"submit",variant:"secondary"}),d&&i.onClear?sa({label:i.clearLabel||"Clear",variant:"ghost",onClick:i.onClear}):null])]),p("p",{class:"stack-filter__result",role:"status","aria-live":"polite"},G(i.result)?i.result:"")],i.onSubmit||i.live?{submit:r=>{r.preventDefault(),i.onSubmit&&i.onSubmit()}}:void 0)}function Xg(i){return p("nav",{class:he("stack-pagination",i.className),"aria-label":i.label||"Pagination",...me(i.attrs)},[G(i.summary)?p("p",{class:"stack-pagination__summary"},i.summary):null,p("div",{class:"stack-pagination__actions"},[sa({label:i.previousLabel||"← Previous",variant:"ghost",disabled:!i.hasPrevious,onClick:i.onPrevious,attrs:{"data-page":"previous"}}),sa({label:i.nextLabel||"Next →",variant:"ghost",disabled:!i.hasNext,onClick:i.onNext,attrs:{"data-page":"next"}})])])}const hm=Object.freeze([{value:"system",label:"System theme"},{value:"light",label:"Light theme"},{value:"dark",label:"Dark theme"}]);function $g(i){const u=i.product||{},d=j=>i.onNavigate?{click:g=>{g.defaultPrevented||g.button!==0||g.metaKey||g.ctrlKey||g.shiftKey||g.altKey||(g.preventDefault(),i.onNavigate(j))}}:void 0,r=nt(i.mainId||"stack-main"),h=[];for(const j of i.navigation||[]){const g=j.group||"";let R=h.find(q=>q.name===g);R||h.push(R={name:g,items:[]}),R.items.push(j)}for(const j of h)j.items.sort((g,R)=>(g.order??0)-(R.order??0));const v=j=>p("li",{class:"stack-shell__nav-entry"},p("a",{class:he("stack-shell__nav-item",j.className),href:j.href,...j.current?{"aria-current":"page"}:{},...me(j.attrs)},j.label,d(j.href))),x=i.theme,b=`${r}-theme`,f=i.otherProducts||(G(u.id)&&gr(u.id)?Ta.products.filter(j=>j.id!==u.id).map(j=>({name:j.name,href:j.href})):[]),y=G(u.id)&&gr(u.id)&&i.family!==!1;return p("div",{class:he("stack-shell",i.className),...G(u.id)?{"data-stack-product":u.id}:{},...me(i.attrs)},[p("a",{class:"stack-shell__skip",href:`#${r}`},i.skipLabel||"Skip to content",{click:Hg(r)}),p("header",{class:"stack-shell__bar"},[p("a",{class:"stack-shell__product",href:u.homeHref||"#"},[G(u.mark)?p("span",{class:"stack-shell__mark","aria-hidden":"true"},u.mark):null,p("span",{class:"stack-shell__product-name"},u.name||"")],d(u.homeHref||"#")),i.context?p("div",{class:"stack-shell__context"},i.context):null,i.search?p("div",{class:"stack-shell__search"},i.search):null,p("div",{class:"stack-shell__end"},[x?p("div",{class:"stack-shell__prefs"},[p("label",{class:"stack-visually-hidden",for:b},"Theme"),p("select",{class:"stack-shell__theme",id:b},hm.map(j=>p("option",{value:j.value,...j.value===(x.preference||"system")?{selected:!0}:{}},j.label)),x.onChange?{change:j=>x.onChange(j.target.value)}:void 0)]):null,i.account?p("div",{class:"stack-shell__account"},i.account):null,y?p("a",{class:"stack-shell__family",href:Ta.company.href},[Hs({idPrefix:`${r}-family-mark`}),p("span",{},["A ",Ta.company.name," product"])]):null])]),p("div",{class:"stack-shell__body"},[p("nav",{class:"stack-shell__nav","aria-label":`${u.name||"Product"} navigation`},[h.map(j=>p("div",{class:"stack-shell__nav-group"},[G(j.name)?p("p",{class:"stack-shell__nav-heading"},j.name):null,p("ul",{class:"stack-shell__nav-list"},j.items.map(v))])),G(i.activityHref)?p("div",{class:"stack-shell__nav-group stack-shell__activity"},p("ul",{class:"stack-shell__nav-list"},v({label:i.activityLabel||"Activity",href:i.activityHref,current:i.activityCurrent}))):null,f.length||y?p("div",{class:"stack-shell__nav-group stack-shell__switcher"},[p("p",{class:"stack-shell__nav-heading"},i.otherProductsLabel||"Other Boundry products"),p("ul",{class:"stack-shell__nav-list"},[f.map(j=>p("li",{class:"stack-shell__nav-entry"},p("a",{class:"stack-shell__nav-item",href:j.href},j.name))),y?p("li",{class:"stack-shell__nav-entry"},p("a",{class:"stack-shell__nav-item stack-shell__nav-item--company",href:Ta.company.href},["About ",Ta.company.name])):null])]):null]),p("main",{class:"stack-shell__main",id:r,tabindex:"-1",...me(i.mainAttrs)},i.children||null)])])}const Zg=["pattern","min","max","step","minlength","maxlength","autocomplete","inputmode","list","spellcheck"],Tr=i=>nt(G(i.id)?i.id:`stack-field-${i.name||"field"}`);function mm(i,u,d,r){return p("div",{class:he("stack-field",`stack-field--${r}`,i.error?"stack-field--invalid":null,i.className),...me(i.attrs)},[p("label",{class:"stack-field__label",for:u},[i.label,i.required?p("span",{class:"stack-field__required","aria-hidden":"true"}," *"):null]),d,G(i.hint)?p("p",{class:"stack-field__hint",id:`${u}-hint`},i.hint):null,G(i.error)?p("p",{class:"stack-field__error",id:`${u}-error`},i.error):null])}const Kg=(i,u)=>{const d=[G(i.hint)?`${u}-hint`:null,G(i.error)?`${u}-error`:null].filter(Boolean);return d.length?{"aria-describedby":d.join(" ")}:{}},Ar=(i,u)=>({...i.required?{required:!0}:{},...i.readOnly?{readonly:!0}:{},...i.disabled?{disabled:!0}:{},...G(i.error)?{"aria-invalid":"true"}:{},...Kg(i,u)});function vm(i){const u=Tr(i),d=i.value!==void 0&&i.value!==null,r=d?String(i.value):null,h=i.onChange?{input:f=>i.onChange(f.target.value)}:void 0,v={};for(const f of Zg)G(i[f])&&(v[f]=String(i[f]));const x={class:"stack-field__control",id:u,...G(i.name)?{name:i.name}:{},...G(i.placeholder)?{placeholder:i.placeholder}:{},...v,...Ar(i,u)},b=i.multiline?p("textarea",{...x,rows:String(Number(i.rows)||4)},d?r:[],h):p("input",{...x,type:i.type||"text",...d?{value:r}:{}},[],h);return mm(i,u,b,i.multiline?"multiline":"text")}function Jg(i){const u=Tr(i),d=G(i.value)?String(i.value):null,r=i.onChange?{change:v=>i.onChange(v.target.value)}:void 0,h=p("select",{class:"stack-field__control",id:u,...G(i.name)?{name:i.name}:{},...Ar(i,u)},(i.options||[]).map(v=>{const x=String(typeof v=="object"?v.value:v);return p("option",{value:x,...x===d?{selected:!0}:{},...typeof v=="object"&&v.disabled?{disabled:!0}:{}},typeof v=="object"?v.label:v)}),r);return mm(i,u,h,"select")}function Fg(i){return p("form",{class:he("stack-form",i.layout==="inline"?"stack-form--inline":null,i.className),...G(i.label)?{"aria-label":i.label}:{},...G(i.id)?{id:nt(i.id)}:{},...i.busy?{"aria-busy":"true"}:{},...me(i.attrs)},[p("div",{class:"stack-form__fields"},i.children||null),p("div",{class:"stack-form__actions"},[sa({label:i.submitLabel||"Save",type:"submit",variant:i.submitVariant||"primary",busy:i.busy}),i.actions||null])],{submit:u=>{u.preventDefault(),i.onSubmit&&i.onSubmit(u)}})}function ym(i){const u=nt(i.id||"stack-dialog"),d=[G(i.description)?`${u}-description`:null,...i.describedBy||[]].filter(Boolean);return p("dialog",{class:he("stack-dialog",i.className),id:u,...i.role==="alertdialog"?{role:"alertdialog"}:{},"aria-labelledby":`${u}-title`,...d.length?{"aria-describedby":d.join(" ")}:{},...me(i.attrs)},p("div",{class:"stack-dialog__surface"},[p("h2",{class:"stack-dialog__title",id:`${u}-title`},i.title),G(i.description)?p("p",{class:"stack-dialog__description",id:`${u}-description`},i.description):null,i.children?p("div",{class:"stack-dialog__body"},i.children):null,i.actions?p("div",{class:"stack-dialog__actions"},i.actions):null]),{cancel:r=>{r.preventDefault(),i.onClose&&i.onClose()}})}function Wg(i){const u=nt(i.id||"stack-confirm"),d=(i.consequences||[]).filter(G),r=!G(i.requireText)||i.typed===i.requireText;return ym({id:u,role:"alertdialog",title:i.title,description:i.description,describedBy:d.length?[`${u}-consequences`]:[],className:he("stack-confirm",i.className),attrs:i.attrs,onClose:i.busy?null:i.onCancel,children:[d.length?p("ul",{class:"stack-confirm__consequences",id:`${u}-consequences`},d.map(h=>p("li",{},h))):null,G(i.requireText)?vm({id:`${u}-typed`,name:"confirm",label:i.requireTextLabel||`Type ${i.requireText} to confirm`,value:i.typed===void 0||i.typed===null?"":i.typed,autocomplete:"off",spellcheck:"false",disabled:i.busy,onChange:i.onTypedChange}):null,i.error?qs({title:i.error.title||"Not done",message:i.error.message,code:i.error.code,requestId:i.error.requestId}):null],actions:[sa({label:i.cancelLabel||"Cancel",variant:"ghost",disabled:i.busy,onClick:i.onCancel,attrs:{"data-dialog-cancel":"true"}}),sa({label:i.confirmLabel,variant:"danger",busy:i.busy,disabled:!r,onClick:i.onConfirm,attrs:{"data-dialog-confirm":"true"}})]})}function Ig(i){const u=nt(i.id||"stack-evidence"),d=(i.claims||[]).filter(g=>g&&G(g.label)),r=d.map(g=>G(g.verification)?yr(g.verification,g.checks).state:"not_evaluated"),h=r.filter(g=>g!=="not_evaluated"),v=h.filter(g=>g==="verified").length,x=h.filter(g=>g==="verification_failed").length,b=r.length-h.length,f=h.length===0?"recorded":v===h.length&&b===0?"verified":"partial",y=b?` · ${b} recorded, not checked`:"",j=f==="recorded"?"Recorded facts · not independently verified":f==="verified"?h.length===1?"Verified":`All ${h.length} claims verified`:`${v} of ${h.length} checked claims verified${x?` · ${x} failed`:""}${y}`;return p("section",{class:he("stack-evidence",`stack-evidence--${f}`,i.className),"aria-labelledby":`${u}-title`,"data-evidence":f,...me(i.attrs)},[p("div",{class:"stack-evidence__header"},[p(Us(i.headingLevel||2),{class:"stack-evidence__title",id:`${u}-title`},G(i.title)?i.title:"Evidence"),i.outcome?p("div",{class:"stack-evidence__outcome"},i.outcome):null]),p("p",{class:"stack-evidence__summary"},j),d.length?p("dl",{class:"stack-evidence__claims"},d.map(g=>{const R=!G(g.value)&&g.value!==0&&g.value!==!1;return p("div",{class:"stack-evidence__claim",...G(g.verification)?{"data-verification":yr(g.verification,g.checks).state}:{},...me(g.attrs)},[p("dt",{class:"stack-evidence__label"},g.label),p("dd",{class:he("stack-evidence__value",g.mono?"stack-evidence__value--mono":null),...R?{"data-missing":"true"}:{}},R?"—":typeof g.value=="boolean"?String(g.value):g.value),G(g.verification)?p("dd",{class:"stack-evidence__check"},fm({state:g.verification,checks:g.checks,evidenceHref:g.evidenceHref})):null])})):null,G(i.source)||G(i.recordedAt)?p("p",{class:"stack-evidence__source"},[G(i.source)?i.source:"Recorded",G(i.recordedAt)?[" · ",Ms(i.recordedAt,"stack-evidence__at")]:null]):null])}const Pg=["info","attention","critical"],eb={info:"i",attention:"▲",critical:"✕"};function tb(i){const u=Pg.includes(i.tone)?i.tone:"info";return p("div",{class:he("stack-alert",`stack-alert--${u}`,i.className),role:u==="critical"?"alert":"status","data-tone":u,...me(i.attrs)},[p("span",{class:"stack-alert__glyph","aria-hidden":"true"},eb[u]),p("div",{class:"stack-alert__content"},[G(i.title)?p("p",{class:"stack-alert__title"},i.title):null,i.children?p("div",{class:"stack-alert__body"},i.children):null,i.actions?p("div",{class:"stack-alert__actions"},i.actions):null])])}function ab(i){const u=Tr(i),d=i.checked!==void 0&&i.checked!==null,r=p("input",{class:"stack-checkbox__control",type:"checkbox",id:u,...G(i.name)?{name:i.name}:{},...G(i.value)?{value:String(i.value)}:{},...d&&i.checked?{checked:!0}:{},...Ar(i,u)},[],i.onChange?{change:h=>i.onChange(!!h.target.checked)}:void 0);return p("div",{class:he("stack-checkbox",i.error?"stack-checkbox--invalid":null,i.className),...me(i.attrs)},[p("div",{class:"stack-checkbox__row"},[r,p("label",{class:"stack-checkbox__label",for:u},[i.label,i.required?p("span",{class:"stack-field__required","aria-hidden":"true"}," *"):null])]),G(i.hint)?p("p",{class:"stack-field__hint",id:`${u}-hint`},i.hint):null,G(i.error)?p("p",{class:"stack-field__error",id:`${u}-error`},i.error):null])}function lb(i){const u=nt(i.id||"stack-group"),d=[G(i.hint)?`${u}-hint`:null,G(i.error)?`${u}-error`:null].filter(Boolean);return p("fieldset",{class:he("stack-fieldgroup",i.error?"stack-fieldgroup--invalid":null,i.className),id:u,...d.length?{"aria-describedby":d.join(" ")}:{},...i.disabled?{disabled:!0}:{},...me(i.attrs)},[p("legend",{class:"stack-fieldgroup__legend"},[i.legend,i.required?p("span",{class:"stack-field__required","aria-hidden":"true"}," *"):null]),G(i.hint)?p("p",{class:"stack-field__hint",id:`${u}-hint`},i.hint):null,p("div",{class:"stack-fieldgroup__controls"},i.children||null),G(i.error)?p("p",{class:"stack-field__error",id:`${u}-error`},i.error):null])}function nb(i){const u=(i.items||[]).filter(h=>h&&G(h.summary)),d=G(i.label)?i.label:"Activity";let r;return i.error?r=qs(typeof i.error=="string"?{message:i.error}:i.error):i.loading&&!u.length?r=_r({what:G(i.what)?i.what:"activity"}):u.length?r=p("ol",{class:"stack-timeline__list","aria-label":d},u.map((h,v)=>p("li",{class:"stack-timeline__item",...me(h.attrs)},[p("span",{class:"stack-timeline__marker","aria-hidden":"true"}),p("div",{class:"stack-timeline__content"},[p("p",{class:"stack-timeline__summary"},G(h.href)?p("a",{class:"stack-timeline__link",href:h.href},h.summary):h.summary),p("p",{class:"stack-timeline__meta"},[G(h.at)?Ms(h.at,"stack-timeline__at"):p("span",{class:"stack-timeline__at","data-missing":"true"},"Time not recorded"),G(h.actor)?[" · ",p("span",{class:"stack-timeline__actor"},h.actor)]:null,h.status?[" ",p("span",{class:"stack-timeline__status"},h.status)]:null]),h.detail?p("div",{class:"stack-timeline__detail"},h.detail):null])],void 0,G(h.id)?h.id:v))):r=Er({title:G(i.emptyTitle)?i.emptyTitle:"No activity recorded",headingLevel:i.headingLevel||3}),p("section",{class:he("stack-timeline",i.className),...i.loading?{"aria-busy":"true"}:{},...me(i.attrs)},[r,i.hasMore&&u.length?p("p",{class:"stack-timeline__more"},[G(i.moreHref)?p("a",{href:i.moreHref,class:"stack-timeline__link"},i.moreLabel||"Older activity exists"):i.onMore?sa({label:i.moreLabel||"Load older activity",onClick:i.onMore,busy:!!i.loading}):i.moreLabel||"Older activity exists"]):null])}function Hs(i){const u=nt(i.idPrefix||"stack-brand-mark"),d=G(i.title);return p("svg",{class:he("stack-brand-mark",i.className),xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 340 315",focusable:"false",...d?{role:"img","aria-labelledby":`${u}-title`}:{"aria-hidden":"true"},...me(i.attrs)},[d?p("title",{id:`${u}-title`},i.title):null,p("defs",{},p("linearGradient",{id:`${u}-fill`,x1:"0",y1:"0",x2:"340",y2:"0",gradientUnits:"userSpaceOnUse"},[p("stop",{class:"stack-brand-mark__start",offset:"0.2"}),p("stop",{class:"stack-brand-mark__end",offset:"0.85"})])),p("path",{fill:`url(#${u}-fill)`,d:"M0 0H250C298 0 330 38 329 84C328 114 309 135 281 143L0 269V182L225 80H0Z"}),p("path",{fill:`url(#${u}-fill)`,d:"M0 315L290 182C318 172 341 202 340 246C339 288 306 315 268 315Z"})])}function gm(i){const u=nt(i.id||"stack-theme");return p("div",{class:he("stack-theme-switch",i.className),...me(i.attrs)},[p("label",{class:"stack-visually-hidden",for:u},i.label||"Theme"),p("select",{class:"stack-theme-switch__control",id:u,"data-stack-theme-control":""},hm.map(d=>p("option",{value:d.value,...d.value===(i.preference||"system")?{selected:!0}:{}},d.label)),i.onChange?{change:d=>i.onChange(d.target.value)}:void 0)])}const bm=i=>i.product?{...gr(i.product.id)||{},...i.product}:null;function ib(i){const u=Ta.company,d=bm(i),r=d?d.name:u.name,h=G(i.homeHref)?i.homeHref:"/";return p("header",{class:he("stack-site-header",i.className),...d&&G(d.id)?{"data-stack-product":d.id}:{},...me(i.attrs)},[p("a",{class:"stack-site-header__skip",href:`#${nt(i.mainId||"main")}`},i.skipLabel||"Skip to content"),p("div",{class:"stack-site-header__inner"},[p("div",{class:"stack-site-header__identity"},[p("a",{class:"stack-site-header__home",href:h,"aria-label":`${r} home`},[i.logo?p("span",{class:"stack-site-header__logo"},i.logo):d?p("span",{class:"stack-site-header__product-mark","aria-hidden":"true"},d.mark||r.slice(0,2)):Hs({className:"stack-site-header__logo",idPrefix:`${nt(i.mainId||"main")}-mark`}),p("span",{class:"stack-site-header__name"},r)]),d?p("a",{class:"stack-site-header__family",href:u.href},["A ",u.name," product"]):null]),(i.navigation||[]).length?p("nav",{class:"stack-site-header__nav","aria-label":i.navigationLabel||"Main"},p("ul",{class:"stack-site-header__nav-list"},i.navigation.map(v=>p("li",{},p("a",{class:"stack-site-header__nav-item",href:v.href,...v.current?{"aria-current":"page"}:{},...me(v.attrs)},v.label))))):null,p("div",{class:"stack-site-header__end"},[i.theme?gm({id:`${nt(i.mainId||"main")}-theme`,preference:i.theme.preference,onChange:i.theme.onChange}):null,i.actions||null])])])}function sb(i){const u=Ta.company,d=bm(i),r=i.columns||[],h=G(i.year)?i.year:null,v=G(i.owner)?i.owner:u.name;return p("footer",{class:he("stack-site-footer",i.className),...d&&G(d.id)?{"data-stack-product":d.id}:{},...me(i.attrs)},p("div",{class:"stack-site-footer__inner"},[p("div",{class:"stack-site-footer__top"},[p("div",{class:"stack-site-footer__about"},[p("p",{class:"stack-site-footer__name"},d?d.name:u.name),G(i.tagline)?p("p",{class:"stack-site-footer__tagline"},i.tagline):null]),r.map(x=>p("nav",{class:"stack-site-footer__column","aria-label":x.title},[p("p",{class:"stack-site-footer__heading"},x.title),p("ul",{class:"stack-site-footer__list"},(x.links||[]).map(b=>p("li",{},p("a",{class:"stack-site-footer__link",href:b.href,...me(b.attrs)},b.label))))]))]),p("nav",{class:"stack-site-footer__family","aria-label":`${u.name} products`},[p("a",{class:"stack-site-footer__company",href:u.href},[Hs({className:"stack-site-footer__mark",idPrefix:`${nt(i.id||"stack-footer")}-mark`}),p("span",{},d?u.family:`${u.name} — ${u.tagline}`)]),p("ul",{class:"stack-site-footer__products"},Ta.products.map(x=>p("li",{"data-stack-product":x.id},p("a",{class:"stack-site-footer__product",href:x.href,...d&&d.id===x.id?{"aria-current":"true"}:{}},[p("span",{class:"stack-site-footer__product-name"},x.name),p("span",{class:"stack-site-footer__product-category"},x.category)]))))]),p("p",{class:"stack-site-footer__legal"},[`© ${h?`${h} `:""}${v}`,d?[" · ",d.name," is a ",p("a",{href:u.href},`${u.name} product`)]:null,i.legal?[" · ",i.legal]:null])]))}const cb=Object.freeze({Breadcrumbs:Ug,Tabs:Bg,TabPanel:Lg,DataTable:Gg,FilterBar:Qg,Pagination:Xg,Shell:$g,StatusIndicator:Tg,VerificationBadge:fm,FreshnessLabel:Cg,Unavailable:Og,Loading:_r,EmptyState:Er,ErrorPanel:qs,MetadataList:zg,ResourceIdentity:Dg,PageHeader:wg,Button:sa,TextField:vm,Select:Jg,Form:Fg,Dialog:ym,ConfirmAction:Wg,EvidenceSummary:Ig,Alert:tb,Checkbox:ab,FieldGroup:lb,ActivityTimeline:nb,BrandMark:Hs,ThemeSwitch:gm,SiteHeader:ib,SiteFooter:sb}),ii="stack-ui.theme",kr=Object.freeze(["system","light","dark"]),xm=i=>{try{return i&&i.localStorage?i.localStorage:null}catch{return null}};function ub(i){const u=xm(globalThis);if(!u)return"system";try{const d=u.getItem(ii);return kr.includes(d)?d:"system"}catch{return"system"}}function rb(i,u){const d=xm(globalThis);if(!d||!kr.includes(i))return!1;try{return i==="system"?d.removeItem(ii):d.setItem(ii,i),!0}catch{return!1}}function ob(i,u){const d=typeof document<"u"?document.documentElement:null;d&&(i==="light"||i==="dark"?d.setAttribute("data-stack-theme",i):d.removeAttribute("data-stack-theme"))}function db(i,u,d){const r=kr.includes(i)?i:"system";return rb(r),ob(r),r}`${JSON.stringify(ii)}`;const fb={class:"className",for:"htmlFor",datetime:"dateTime",tabindex:"tabIndex",readonly:"readOnly",autocomplete:"autoComplete",inputmode:"inputMode",maxlength:"maxLength",minlength:"minLength",spellcheck:"spellCheck"},Kh={click:"onClick",change:"onChange",input:"onInput",submit:"onSubmit",keydown:"onKeyDown",cancel:"onCancel",close:"onClose"};function br(i,u){if(i==null||i===!1||i===!0)return null;if(typeof i=="string"||typeof i=="number")return i;if(Array.isArray(i))return k.createElement(k.Fragment,u===void 0?null:{key:u},...i.map((d,r)=>br(d,r)));if(k.isValidElement(i))return u===void 0?i:k.createElement(k.Fragment,{key:u},i);if(dr(i)){const d=i.k===void 0?u:i.k,r=d===void 0?{}:{key:d};for(const[b,f]of Object.entries(i.a))f==null||f===!1||(r[fb[b]||b]=f);const h=i.t==="input"||i.t==="select"||i.t==="textarea";for(const[b,f]of Object.entries(i.on||{})){if(!Kh[b])throw new Error(`toReact: unsupported event ${b}`);r[h&&(b==="input"||b==="change")?"onChange":Kh[b]]=f}let v=i.c;if(i.t==="textarea"&&(r.value=v.filter(b=>typeof b=="string"||typeof b=="number").join(""),v=[]),i.t==="select"){const b=v.find(f=>dr(f)&&f.t==="option"&&f.a.selected);v=v.map(f=>dr(f)&&f.t==="option"&&f.a.selected?{...f,a:{...f.a,selected:!1}}:f),b&&(r.value=b.a.value)}h&&"checked"in r&&!r.onChange&&(r.defaultChecked=r.checked,delete r.checked),h&&"value"in r&&!r.onChange&&(r.defaultValue=r.value,delete r.value);const x=v.map((b,f)=>br(b,f));return k.createElement(i.t,r,...x)}throw new TypeError("toReact: unsupported child")}const ke=i=>{const u=cb[i],d=r=>br(u(r||{}));return d.displayName=`Stack${i}`,d},hb=ke("StatusIndicator");ke("VerificationBadge");ke("FreshnessLabel");ke("Unavailable");const mb=ke("Loading"),vb=ke("EmptyState"),yb=ke("ErrorPanel");ke("MetadataList");ke("ResourceIdentity");ke("PageHeader");ke("Button");ke("Breadcrumbs");ke("Tabs");ke("TabPanel");ke("DataTable");ke("FilterBar");ke("Pagination");ke("Shell");ke("TextField");ke("Select");ke("Form");ke("EvidenceSummary");ke("Alert");ke("Checkbox");ke("FieldGroup");ke("ActivityTimeline");const gb=ke("BrandMark");ke("ThemeSwitch");ke("SiteHeader");ke("SiteFooter");const bb=["system","light","dark"];function Jh(){return ub()}function xb(i){const u=db(i);u==="system"?delete document.documentElement.dataset.theme:document.documentElement.dataset.theme=u}function jb(){const[i,u]=k.useState(Jh);return k.useEffect(()=>xb(i),[i]),k.useEffect(()=>{const d=r=>{r.key===ii&&u(Jh())};return window.addEventListener("storage",d),()=>window.removeEventListener("storage",d)},[]),[i,u]}function tt(i){if(!i)return"—";const u=Math.max(0,Math.round((Date.now()-Date.parse(i))/1e3));return u<5?"just now":u<60?`${u}s ago`:u<3600?`${Math.floor(u/60)}m ago`:u<86400?`${Math.floor(u/3600)}h ago`:new Date(i).toLocaleDateString()}function jm(i=15e3){const[,u]=k.useState(0);k.useEffect(()=>{const d=setInterval(()=>u(r=>r+1),i);return()=>clearInterval(d)},[i])}function I({tone:i="neutral",children:u,title:d}){return l.jsx("span",{className:`badge badge-${i}`,title:d,children:u})}function cn({outcome:i}){const u=i==="success"?"positive":i==="denied"?"neutral":"critical";return l.jsx(hb,{tone:u,label:i,attrs:{"data-outcome":i}})}function te({title:i,action:u,children:d,className:r=""}){return l.jsxs("section",{className:`card ${r}`,children:[(i||u)&&l.jsxs("header",{className:"card-header",children:[i&&l.jsx("h2",{children:i}),u]}),d]})}function qt({title:i,children:u}){return l.jsx(vb,{title:i,body:u,headingLevel:3})}function Ze({label:i="Loading"}){return l.jsx(mb,{what:i==="Loading"?void 0:i.replace(/^Loading\s+/i,"")})}function ve({error:i,retry:u}){const d=i;return l.jsx(yb,{title:d?.code??"Error",message:d?.message??String(i),requestId:d?.requestId,onRetry:u})}function ci({value:i,max:u=4e3}){let d=JSON.stringify(i,null,2)??"undefined";return d.length>u&&(d=`${d.slice(0,u)}
12
- … (${d.length-u} more characters)`),l.jsx("pre",{className:"json",children:d})}function rn({text:i,label:u="Copy"}){const[d,r]=k.useState(!1);return l.jsx("button",{className:"btn btn-small btn-ghost",onClick:()=>{navigator.clipboard?.writeText(i).then(()=>{r(!0),setTimeout(()=>r(!1),1200)})},children:d?"Copied":u})}function xr({rows:i}){return l.jsx("dl",{className:"kv",children:i.map(([u,d],r)=>l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:u}),l.jsx("dd",{children:d})]},r))})}function si({schema:i}){if(!i)return l.jsx("span",{className:"muted",children:"—"});if(i.type!=="object"||!i.properties)return l.jsx("code",{className:"type",children:Os(i)});const u=new Set(i.required??[]),d=Object.entries(i.properties);return d.length?l.jsx("table",{className:"fields",children:l.jsx("tbody",{children:d.map(([r,h])=>l.jsxs("tr",{children:[l.jsxs("td",{className:"mono",children:[r,!u.has(r)&&l.jsx("span",{className:"muted",children:"?"})]}),l.jsxs("td",{children:[l.jsx("code",{className:"type",children:Os(h)}),Fh(h)&&l.jsxs("span",{className:"muted small",children:[" ",Fh(h)]})]})]},r))})}):l.jsx("span",{className:"muted",children:"no fields"})}function Os(i){return i?i.enum?i.enum.map(u=>JSON.stringify(u)).join(" | "):i.anyOf?i.anyOf.map(Os).join(" | "):i.type==="array"?`${Os(i.items)}[]`:i.type==="object"?i.properties?`{ ${Object.keys(i.properties).join(", ")} }`:"object":Array.isArray(i.type)?i.type.join(" | "):i.type??"unknown":"unknown"}function Fh(i){const u=[];return i.minLength!==void 0&&u.push(`min ${i.minLength}`),i.maxLength!==void 0&&u.push(`max ${i.maxLength}`),i.minimum!==void 0&&u.push(`≥ ${i.minimum}`),i.maximum!==void 0&&u.push(`≤ ${i.maximum}`),u.join(", ")}function pm({title:i,onClose:u,children:d}){return k.useEffect(()=>{const r=h=>h.key==="Escape"&&u();return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[u]),l.jsx("div",{className:"drawer-backdrop",onClick:u,children:l.jsxs("aside",{className:"drawer",role:"dialog","aria-modal":"true","aria-label":typeof i=="string"?i:"Details",onClick:r=>r.stopPropagation(),children:[l.jsxs("header",{className:"drawer-header",children:[l.jsx("h2",{children:i}),l.jsx("button",{className:"btn btn-ghost",onClick:u,"aria-label":"Close",children:"Esc"})]}),l.jsx("div",{className:"drawer-body",children:d})]})})}function Le(i,u){const[d,r]=k.useState({loading:!0}),[h,v]=k.useState(0);return k.useEffect(()=>{let x=!0;return r(b=>({...b,loading:!0})),i().then(b=>x&&r({data:b,loading:!1}),b=>x&&r(f=>({data:f.data,error:b,loading:!1}))),()=>{x=!1}},[...u,h]),{...d,reload:()=>v(x=>x+1)}}const pb={system:l.jsxs(l.Fragment,{children:[l.jsx("rect",{x:"3",y:"4",width:"14",height:"10",rx:"1.5"}),l.jsx("path",{d:"M7.5 17h5M10 14v3"})]}),light:l.jsxs(l.Fragment,{children:[l.jsx("circle",{cx:"10",cy:"10",r:"3.2"}),l.jsx("path",{d:"M10 2.5v2M10 15.5v2M2.5 10h2M15.5 10h2M4.7 4.7l1.4 1.4M13.9 13.9l1.4 1.4M4.7 15.3l1.4-1.4M13.9 6.1l1.4-1.4"})]}),dark:l.jsx("path",{d:"M15.5 12.2A6 6 0 0 1 7.8 4.5a6 6 0 1 0 7.7 7.7Z"})},Wh={system:"System",light:"Light",dark:"Dark"};function Sb(){const[i,u]=jb();return l.jsx("div",{className:"theme-toggle",role:"radiogroup","aria-label":"Theme",children:bb.map(d=>l.jsxs("button",{type:"button",role:"radio","aria-checked":i===d,className:i===d?"on":"",onClick:()=>u(d),title:`${Wh[d]} theme`,children:[l.jsx("svg",{viewBox:"0 0 20 20",width:"15",height:"15",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:pb[d]}),l.jsx("span",{className:"sr-only",children:Wh[d]})]},d))})}const Nb="/_feltkit/assets/feltkit-mark-BygpVIiS.png";function ui(i){const u=i.trim();if(!u||u.startsWith("credential-ref:"))return!1;if(/^(sk-|sk-ant-|sk_live_|sk_test_|rk_live_|xai-|AIza|ghp_|gho_|github_pat_|gsk_|glpat-|xox[abpr]-|hf_|pk_live_)/.test(u))return!0;if(u.length<32||/\s/.test(u)||!/[0-9]/.test(u)||!/[A-Za-z]/.test(u))return!1;const d=new Map;for(const h of u)d.set(h,(d.get(h)??0)+1);let r=0;for(const h of d.values())r-=h/u.length*Math.log2(h/u.length);return r>=4}function Bs({credential:i}){return i?i.present?l.jsxs(I,{tone:"ok",title:i.updatedAt?`updated ${i.updatedAt}`:void 0,children:["set · ",i.location??i.variable,i.version&&i.source==="vault"?`, version ${i.version}`:""]}):l.jsx(I,{tone:"bad",children:i.state==="revoked"?"removed":"not set"}):null}function Cr(i){const u=i?.devUsers??[],[d,r]=k.useState("");return k.useEffect(()=>{!d&&u[0]&&r(u[0].id)},[u,d]),[d,r,u]}function Or({as:i,setAs:u,devUsers:d,label:r="Save as"}){return d.length?l.jsxs("label",{children:[r,l.jsx("select",{className:"input",value:i,onChange:h=>u(h.target.value),"aria-label":"Identity",children:d.map(h=>l.jsxs("option",{value:h.id,children:[h.name??h.id," (",h.roles.join(", "),")"]},h.id))})]}):null}function zs({credentialRef:i,provider:u,as:d,label:r="Set key",onSaved:h}){const[v,x]=k.useState(!1),[b,f]=k.useState(""),[y,j]=k.useState(!1),[g,R]=k.useState(null),[q,V]=k.useState(null),E=async()=>{j(!0),R(null);const A=b;f("");try{const X=await ne("/credentials",{method:"POST",body:JSON.stringify({ref:i,value:A,...u?{provider:u}:{},...d?{as:d}:{}})});V(X.stored),x(!1),h?.(X.stored)}catch(X){R(X)}finally{j(!1)}};return v?l.jsxs("span",{className:"row small",style:{flexWrap:"wrap"},children:[g?l.jsx(ve,{error:g}):null,l.jsx("input",{className:"input",type:"password",autoComplete:"off",spellCheck:!1,value:b,onChange:A=>f(A.target.value),placeholder:`Value for ${i}`,"aria-label":`Value for ${i}`}),l.jsx("button",{className:"btn btn-small btn-primary",onClick:E,disabled:y||!b.trim(),children:y?"Saving…":"Save"}),l.jsx("button",{className:"btn btn-small",onClick:()=>(f(""),x(!1)),children:"Cancel"}),l.jsx("span",{className:"muted",children:"Stored securely on the server; it is never shown again."})]}):l.jsxs("span",{className:"row small",children:[l.jsx("button",{className:"btn btn-small",onClick:()=>x(!0),children:r}),q&&l.jsxs("span",{className:"muted",children:["Stored (",q.location??"custody",", version ",q.version,")."]})]})}function _b(i){return(u,d="GET",r)=>ne(`/services/manage${u}`,{method:d,headers:{"x-feltkit-as":i},...r!==void 0?{body:JSON.stringify(r)}:d!=="GET"&&d!=="DELETE"?{body:"{}"}:{}})}function un(i,u){if(i==null)throw new Error(`${u} was not found or changed meanwhile. Nothing was done.`);return i}const Eb="A credential reference, like credential-ref:stripe. Set its value under Services → Credentials; the value is never stored here.",Tb={files:{title:"Files",description:"File records with ownership and audit. Bytes are stored in this environment's FeltDB instance.",render:i=>l.jsx(wb,{...i})},notifications:{title:"Notifications",description:"Durable in-app notifications. A principal reads only the notifications addressed to it.",render:i=>l.jsx(Mb,{...i})},configuration:{title:"Configuration",description:"Variables and secret references for this environment. Secret values stay in FeltKit's custody.",render:i=>l.jsx(Ub,{...i})},apiKeys:{title:"API keys",description:"Durable machine identities. A secret is shown once, when a key is created or rotated. FeltKit accepts a key as an identity holding services.apiKeys.roles.",render:i=>l.jsx(qb,{...i})},webhooks:{title:"Webhooks",description:"Endpoints for signed outbound delivery, with retries and history.",render:i=>l.jsx(Bb,{...i})},jobs:{title:"Jobs",description:"Durable background work. Each job type runs the FeltKit function declared in services.jobs.handlers, as the principal that queued it.",render:i=>l.jsx(Lb,{...i})},schedules:{title:"Schedules",description:"Recurring jobs. Each run queues a job of the schedule's type.",render:i=>l.jsx(Vb,{...i})},intelligence:{title:"Intelligence",description:"The provider, model, endpoint and credential reference for this environment. Configuration only: AppPort Services never runs a model.",render:i=>l.jsx(Qb,{...i})}};function Ab({id:i,service:u,as:d,picker:r,development:h,summary:v,operations:x}){const{version:b}=Bt(),f=Tb[i],y=l.jsx(Ht,{title:f?.title??i,subtitle:l.jsxs(l.Fragment,{children:[l.jsx("a",{href:"#/services",className:"link",children:"Services"})," ","· ",f?.description]}),actions:r});return f?u?u.state==="available"||u.state==="unavailable"?l.jsxs(l.Fragment,{children:[y,l.jsx(kb,{service:u})]}):l.jsxs(l.Fragment,{children:[y,v,h?d?l.jsxs(l.Fragment,{children:[l.jsxs("p",{className:"muted small",children:["Acting as ",l.jsx("strong",{children:d}),". Every operation is authorized by AppPort Services' gateway with this identity's roles, and recorded in Activity."]}),f.render({as:d,manage:_b(d),version:b})]}):l.jsx(te,{children:l.jsxs("p",{className:"muted small",children:["Declare a development identity in ",l.jsxs("code",{children:["feltkit(","{"," dev: ","{"," users ","}"," ","}",")"]}),": service operations are authorized as that identity."]})}):l.jsxs(l.Fragment,{children:[x,l.jsx(te,{children:l.jsxs("p",{className:"muted small",children:["Configuring ",f.title," is a development tool: change it in development, or with the service's own API from your application."]})})]})]}):l.jsxs(l.Fragment,{children:[y,l.jsx(Ze,{})]}):l.jsxs(l.Fragment,{children:[y,l.jsx(qt,{title:"No such service"})]})}function kb({service:i}){const u=Cb[i.id]??`${i.id}: true`;return l.jsx(te,{title:`Enable ${i.name}`,children:i.state==="unavailable"?l.jsx("p",{className:"error-text",children:i.detail}):l.jsxs(l.Fragment,{children:[l.jsxs("p",{className:"small",children:["Add it to ",l.jsx("code",{children:"services"})," in ",l.jsx("code",{children:"feltkit/app.ts"}),". The backend reloads in place and keeps its state; this screen then manages it."]}),l.jsx("pre",{className:"json",children:`services: { …, ${u} },`}),l.jsxs("span",{className:"row",children:[l.jsx(rn,{text:u,label:"Copy"}),l.jsxs("span",{className:"muted small",children:["Its permissions (",i.capabilities.join(", "),") are granted through your roles."]})]})]})})}const Cb={apiKeys:'apiKeys: { roles: ["member"] }',jobs:'jobs: { handlers: { "report.build": "reports:build" } }'};function jl({title:i,fields:u,submitLabel:d,send:r,done:h}){const v=()=>Object.fromEntries(u.map(E=>[E.name,E.value??(E.options?Aa(E.options[0]):E.choices?.length&&!E.multi?Aa(E.choices[0]):"")])),[x,b]=k.useState(v),[f,y]=k.useState(!1),[j,g]=k.useState(null),[R,q]=k.useState(null),V=async E=>{E.preventDefault(),y(!0),g(null),q(null);try{const A=await r(x);q(h?h(A):"Done."),b(v())}catch(A){g(A)}finally{y(!1)}};return l.jsxs(te,{title:i,children:[l.jsxs("form",{onSubmit:V,children:[l.jsx("div",{className:"form-grid",children:u.map(E=>l.jsxs("label",{children:[l.jsxs("span",{children:[E.label,E.required?" *":""]}),E.choices&&E.multi?l.jsx(zb,{field:E,value:x[E.name]??"",onChange:A=>b({...x,[E.name]:A})}):E.choices?l.jsx(Ob,{field:E,value:x[E.name]??"",onChange:A=>b({...x,[E.name]:A})}):E.options?l.jsx("select",{className:"input",value:x[E.name],onChange:A=>b({...x,[E.name]:A.target.value}),children:E.options.map(A=>l.jsx("option",{value:Aa(A),children:typeof A=="string"?A:A.label},Aa(A)))}):E.multiline?l.jsx("textarea",{className:"input code-input",rows:3,value:x[E.name],placeholder:E.placeholder,required:E.required,onChange:A=>b({...x,[E.name]:A.target.value})}):l.jsx("input",{className:"input",type:E.type??"text",value:x[E.name],placeholder:E.placeholder,required:E.required,pattern:E.pattern,autoComplete:"off",spellCheck:!1,onChange:A=>b({...x,[E.name]:A.target.value})}),E.hint&&l.jsx("span",{className:"muted small",children:E.hint})]},E.name))}),l.jsx("button",{className:"btn btn-primary",type:"submit",disabled:f,children:f?"Working…":d})]}),j?l.jsx(ve,{error:j}):null,R?l.jsx("div",{className:"ok-box small",children:R}):null]})}const Aa=i=>typeof i=="string"?i:i.value,Sm=i=>typeof i=="string"?i:i.label,fr="\0other";function Ob({field:i,value:u,onChange:d}){const r=(i.choices??[]).some(b=>Aa(b)===u),[h,v]=k.useState(!r&&u!==""),x=h||!i.choices?.length&&!i.strict;return l.jsxs(l.Fragment,{children:[(i.choices?.length??0)>0&&l.jsxs("select",{className:"input",value:x?fr:u,required:i.required,onChange:b=>{const f=b.target.value===fr;v(f),d(f?"":b.target.value)},children:[i.choices.map(b=>l.jsx("option",{value:Aa(b),children:Sm(b)},Aa(b))),!i.strict&&l.jsx("option",{value:fr,children:"Other…"})]}),x&&l.jsx("input",{className:"input",value:u,placeholder:i.placeholder,required:i.required,pattern:i.pattern,autoComplete:"off",spellCheck:!1,autoFocus:h,onChange:b=>d(b.target.value)})]})}function zb({field:i,value:u,onChange:d}){const r=(i.choices??[]).map(Aa),h=Ds(u),v=h.filter(j=>r.includes(j)),x=h.filter(j=>!r.includes(j)),[b,f]=k.useState(x.join(", ")),y=(j,g)=>d([...j,...Ds(g)].join(", "));return l.jsxs("span",{className:"choices",children:[(i.choices??[]).map(j=>{const g=Aa(j);return l.jsxs("label",{className:"check",children:[l.jsx("input",{type:"checkbox",checked:v.includes(g),onChange:R=>y(R.target.checked?[...v,g]:v.filter(q=>q!==g),b)}),l.jsx("code",{children:Sm(j)})]},g)}),!i.strict&&l.jsx("input",{className:"input",value:b,placeholder:r.length?"Others, comma separated":i.placeholder,autoComplete:"off",spellCheck:!1,required:i.required&&v.length===0,onChange:j=>(f(j.target.value),y(v,j.target.value))})]})}function on(i,u=0){return Le(()=>ne("/services/catalog"),[i,u]).data}function el({title:i,read:u,deps:d,empty:r,columns:h,actions:v,after:x,tools:b}){const f=Le(u,d),y=f.data??[];return l.jsxs(te,{title:i,action:l.jsxs("span",{className:"row",children:[b?.(f.reload),l.jsx("button",{className:"btn btn-small btn-ghost",onClick:f.reload,children:"Refresh"})]}),children:[f.error?l.jsx(ve,{error:f.error,retry:f.reload}):f.data?y.length===0?l.jsx("p",{className:"muted small",children:r}):l.jsx("div",{className:"table-wrap",children:l.jsxs("table",{className:"table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[h.map(([j])=>l.jsx("th",{children:j},j)),v&&l.jsx("th",{})]})}),l.jsx("tbody",{children:y.map((j,g)=>l.jsxs("tr",{children:[h.map(([R,q])=>l.jsx("td",{children:q(j)},R)),v&&l.jsx("td",{className:"row",children:v(j,f.reload)})]},j.id??g))})]})}):l.jsx(Ze,{}),x]})}function gt({label:i,confirm:u,danger:d,action:r,done:h}){const[v,x]=k.useState(!1),[b,f]=k.useState(!1),[y,j]=k.useState(null),g=async()=>{f(!0),j(null);try{await r(),x(!1),h?.()}catch(R){j(R)}finally{f(!1)}};return l.jsxs("span",{className:"row small",children:[v?l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"muted",children:u}),l.jsx("button",{className:`btn btn-small ${d?"btn-danger":"btn-primary"}`,onClick:g,disabled:b,children:b?"Working…":`Yes, ${i.toLowerCase()}`}),l.jsx("button",{className:"btn btn-small",onClick:()=>x(!1),children:"Cancel"})]}):l.jsx("button",{className:`btn btn-small ${d?"btn-danger":""}`,onClick:()=>u?x(!0):void g(),disabled:b,children:i}),y?l.jsx(ve,{error:y}):null]})}const ea=i=>i?l.jsx("span",{className:"muted small",title:i,children:tt(i)}):l.jsx("span",{className:"muted",children:"—"}),Et=i=>i?l.jsx("code",{children:i}):l.jsx("span",{className:"muted",children:"—"});function Db(i,u){let d;try{d=JSON.parse(i||"{}")}catch{throw new Error(`The ${u} is not valid JSON.`)}if(!d||typeof d!="object"||Array.isArray(d))throw new Error(`The ${u} must be a JSON object, like {"invoice": 7}.`);return d}const Ds=i=>i.split(",").map(u=>u.trim()).filter(Boolean),Nm=({done:i})=>l.jsx(gt,{label:"Run due work now",action:()=>ne("/services/run",{method:"POST",body:"{}"}),done:i});function wb({as:i,manage:u,version:d}){const[r,h]=k.useState(0),[v,x]=k.useState(null),[b,f]=k.useState(!1),[y,j]=k.useState(null),[g,R]=k.useState(null),q=async E=>{if(E.preventDefault(),!!v){f(!0),j(null),R(null);try{const A=await Rb(v),{file:X}=await ne("/services/files",{method:"POST",body:JSON.stringify({as:i,name:v.name,contentType:v.type||void 0,contentBase64:A})});R(`Uploaded ${X.name} (${X.size.toLocaleString()} bytes).`),x(null),E.target.reset(),h(ee=>ee+1)}catch(A){j(A)}finally{f(!1)}}},V=async E=>{const{file:A,contentBase64:X}=await ne(`/services/files/${encodeURIComponent(E.id)}/content?as=${encodeURIComponent(i)}`),ee=Uint8Array.from(atob(X),be=>be.charCodeAt(0)),w=URL.createObjectURL(new Blob([ee],{type:A.contentType??"application/octet-stream"}));Object.assign(document.createElement("a"),{href:w,download:A.name}).click(),setTimeout(()=>URL.revokeObjectURL(w),1e3)};return l.jsxs(l.Fragment,{children:[l.jsxs(te,{title:"Upload a file",children:[l.jsxs("form",{onSubmit:q,className:"row",children:[l.jsx("input",{className:"input",type:"file",onChange:E=>x(E.target.files?.[0]??null),"aria-label":"File"}),l.jsx("button",{className:"btn btn-primary",type:"submit",disabled:!v||b,children:b?"Uploading…":"Upload"})]}),l.jsxs("p",{className:"muted small",children:["Stored in this environment's FeltDB instance as ",i,", through the same Files service your functions use (ctx.services.files)."]}),y?l.jsx(ve,{error:y}):null,g?l.jsx("div",{className:"ok-box small",children:g}):null]}),l.jsx(el,{title:"Files",read:()=>u("/_appport/files"),deps:[i,d,r],empty:"No files yet.",columns:[["Name",E=>l.jsx("strong",{children:E.name})],["Owner",E=>Et(E.owner)],["Type",E=>l.jsx("span",{className:"small",children:E.contentType??"—"})],["Size",E=>l.jsx("span",{className:"num",children:typeof E.size=="number"?E.size.toLocaleString():"—"})],["Updated",E=>ea(E.updatedAt??E.createdAt)]],actions:(E,A)=>l.jsxs(l.Fragment,{children:[l.jsx(gt,{label:"Download",action:()=>V(E)}),l.jsx(_m,{current:E.name,onSave:X=>u(`/_appport/files/${encodeURIComponent(E.id)}`,"PATCH",{name:X}),done:A}),l.jsx(gt,{label:"Delete",danger:!0,confirm:`Delete ${E.name} and its bytes?`,action:()=>ne(`/services/files/${encodeURIComponent(E.id)}?as=${encodeURIComponent(i)}`,{method:"DELETE"}),done:A})]})})]})}function Rb(i){return new Promise((u,d)=>{const r=new FileReader;r.onload=()=>u(String(r.result).replace(/^data:[^,]*,/,"")),r.onerror=()=>d(r.error),r.readAsDataURL(i)})}function _m({current:i,onSave:u,done:d}){const[r,h]=k.useState(!1),[v,x]=k.useState(i),[b,f]=k.useState(null);if(!r)return l.jsx("button",{className:"btn btn-small",onClick:()=>(x(i),h(!0)),children:"Rename"});const y=async()=>{f(null);try{un(await u(v.trim()),"The record"),h(!1),d()}catch(j){f(j)}};return l.jsxs("span",{className:"row small",children:[l.jsx("input",{className:"input",value:v,onChange:j=>x(j.target.value),"aria-label":"New name"}),l.jsx("button",{className:"btn btn-small btn-primary",onClick:y,disabled:!v.trim(),children:"Save"}),l.jsx("button",{className:"btn btn-small",onClick:()=>h(!1),children:"Cancel"}),b?l.jsx(ve,{error:b}):null]})}function Mb({as:i,manage:u,version:d}){const[r,h]=k.useState(0),v=()=>h(f=>f+1),x=on(d,r),b=Bt().overview?.devUsers??[];return l.jsxs(l.Fragment,{children:[l.jsx(jl,{title:"Send a notification",submitLabel:"Send",fields:[{name:"recipient",label:"Recipient",required:!0,value:i,choices:b.map(f=>({value:f.id,label:`${f.name??f.id} (${f.id})`})),hint:"A principal id. Only the recipient can read it."},{name:"type",label:"Type",required:!0,placeholder:"task.assigned",choices:x?.notificationTypes.all??[],hint:x?.notificationTypes.declared.length?"Declared in services.notifications.types, plus types already sent.":"Declare your types in services: { notifications: { types: [...] } } to list them here."},{name:"title",label:"Title",required:!0},{name:"priority",label:"Priority",options:["normal","low","high","urgent"]}],send:async f=>{await u("/_appport/notifications","POST",f),v()},done:()=>"Notification sent."},x?"ready":"loading"),l.jsx(el,{title:`Notifications for ${i}`,read:()=>u(`/_appport/notifications?limit=50&recipient=${encodeURIComponent(i)}`).then(f=>f.items),deps:[i,d,r],empty:"No notifications for this identity.",columns:[["Title",f=>l.jsx("strong",{children:f.title??f.type})],["Type",f=>Et(f.type)],["Priority",f=>f.priority],["State",f=>l.jsx(I,{tone:f.dismissedAt?"neutral":f.readAt?"ok":"info",children:f.dismissedAt?"dismissed":f.status})],["Created",f=>ea(f.createdAt)]],actions:(f,y)=>{const j=`/_appport/notifications/${encodeURIComponent(f.id)}`;return l.jsxs(l.Fragment,{children:[!f.readAt&&l.jsx(gt,{label:"Mark read",action:async()=>un(await u(`${j}/read`,"POST"),"The notification"),done:y}),!f.dismissedAt&&l.jsx(gt,{label:"Dismiss",action:async()=>un(await u(`${j}/dismiss`,"POST"),"The notification"),done:y}),l.jsx(gt,{label:"Delete",danger:!0,confirm:"Delete this notification and its deliveries?",action:()=>u(j,"DELETE"),done:y})]})}})]})}const Ih={pattern:"[A-Z][A-Z0-9_]*",placeholder:"STRIPE_ACCOUNT",hint:"Uppercase letters, digits and underscores, starting with a letter."};function Ub({as:i,manage:u,version:d}){const[r,h]=k.useState(0),v=()=>h(E=>E+1),x=on(d,r),b=Le(()=>u("/v1/configuration"),[i,d,r]),f=[...new Set((b.data?.secrets??[]).map(E=>E.credentialRef))],y=Le(()=>f.length?u(`/v1/configuration/credentials/status?${f.map(E=>`ref=${encodeURIComponent(E)}`).join("&")}`):Promise.resolve([]),[f.join(","),r]),j=new Map((y.data??[]).map(E=>[E.ref,E]));if(b.error)return l.jsx(ve,{error:b.error,retry:b.reload});if(!b.data)return l.jsx(Ze,{});const{variables:g,secrets:R,declarations:q}=b.data,V=q.filter(E=>E.required&&!g.some(A=>A.name===E.name)&&!R.some(A=>A.name===E.name)).length;return l.jsxs(l.Fragment,{children:[l.jsx("p",{className:"small",children:V===0?"Every required value is set.":`${V} required value(s) missing.`}),l.jsx(te,{title:"Variables",children:g.length===0?l.jsx("p",{className:"muted small",children:"No variables yet."}):l.jsx("div",{className:"table-wrap",children:l.jsxs("table",{className:"table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:"Name"}),l.jsx("th",{children:"Value"}),l.jsx("th",{children:"Updated"}),l.jsx("th",{})]})}),l.jsx("tbody",{children:g.map(E=>l.jsxs("tr",{children:[l.jsx("td",{children:Et(E.name)}),l.jsx("td",{className:"mono small",children:E.value}),l.jsx("td",{children:ea(E.updatedAt)}),l.jsxs("td",{className:"row",children:[l.jsx(_m,{current:E.value,onSave:A=>u(`/v1/configuration/variables/${encodeURIComponent(E.name)}`,"PATCH",{value:A,required:!1}),done:v}),l.jsx(gt,{label:"Delete",danger:!0,confirm:`Delete ${E.name}?`,action:()=>u(`/v1/configuration/variables/${encodeURIComponent(E.name)}`,"DELETE"),done:v})]})]},E.name))})]})})}),l.jsx(jl,{title:"Add a variable",submitLabel:"Add variable",fields:[{name:"name",label:"Name",required:!0,...Ih},{name:"value",label:"Value",required:!0,hint:"Not for secrets: add a secret reference below instead."}],send:async E=>{if(ui(E.value))throw new Error("This looks like a secret. Add it as a secret reference instead, and set its value; a variable is stored in FeltDB.");await u("/v1/configuration/variables","POST",{...E,required:!1}),v()},done:()=>"Variable added."}),l.jsx(te,{title:"Secrets",children:R.length===0?l.jsx("p",{className:"muted small",children:"No secrets yet."}):l.jsx("div",{className:"table-wrap",children:l.jsxs("table",{className:"table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:"Name"}),l.jsx("th",{children:"Reference"}),l.jsx("th",{children:"Value"}),l.jsx("th",{children:"Updated"}),l.jsx("th",{})]})}),l.jsx("tbody",{children:R.map(E=>{const A=j.get(E.credentialRef);return l.jsxs("tr",{children:[l.jsx("td",{children:Et(E.name)}),l.jsx("td",{children:Et(E.credentialRef)}),l.jsx("td",{children:A?A.state==="set"?l.jsxs(I,{tone:"ok",children:["set",A.version?` · v${A.version}`:""]}):l.jsx(I,{tone:"warn",children:A.state}):l.jsx(I,{children:"unknown"})}),l.jsx("td",{children:ea(E.updatedAt)}),l.jsxs("td",{className:"row",children:[l.jsx(zs,{credentialRef:E.credentialRef,label:A?.state==="set"?"Replace value":"Set value",as:i,onSaved:v}),l.jsx(gt,{label:"Delete",danger:!0,confirm:`Delete the binding ${E.name}? The stored value is kept.`,action:()=>u(`/v1/configuration/secrets/${encodeURIComponent(E.name)}`,"DELETE"),done:v})]})]},E.name)})})]})})}),l.jsx(jl,{title:"Add a secret reference",submitLabel:"Add secret",fields:[{name:"name",label:"Name",required:!0,...Ih},{name:"credentialRef",label:"Credential reference",required:!0,pattern:"credential-ref:.+",placeholder:"credential-ref:stripe",choices:(x?.credentials??[]).map(E=>({value:E.ref,label:`${E.ref}${E.present?"":" (not set)"}`})),hint:Eb}],send:async E=>{await u("/v1/configuration/secrets","POST",{...E,required:!1}),v()},done:()=>"Secret reference added. Set its value in the table above."},x?"ready":"loading")]})}function qb({manage:i,version:u}){const[d,r]=k.useState(0),h=on(u),[v,x]=k.useState(null),[b,f]=k.useState(null),y=()=>r(g=>g+1),j="/_appport/api/keys";return l.jsxs(l.Fragment,{children:[v&&l.jsxs("div",{className:"ok-box small",children:[v.lead," Copy this secret now; it is not shown again: ",l.jsx("code",{className:"token",children:v.value})," ",l.jsx(rn,{text:v.value})," ",l.jsx("button",{className:"btn btn-small btn-ghost",onClick:()=>x(null),children:"Done"})]}),l.jsx(jl,{title:"Create an API key",submitLabel:"Create API key",fields:[{name:"name",label:"Key name",required:!0},{name:"capabilities",label:"Only these capabilities (optional)",multi:!0,choices:h?.capabilities??[],placeholder:"files.read, jobs.create",hint:"A ceiling: the key's roles still decide. None chosen: no ceiling."},{name:"expiresAt",label:"Expires at (optional)",type:"datetime-local"}],send:async g=>{const R=Ds(g.capabilities??""),q=await i(j,"POST",{name:g.name,...R.length?{restrictions:{capabilities:R}}:{},...g.expiresAt?{expiresAt:new Date(g.expiresAt).toISOString()}:{}});return q?.secret&&x({lead:`Created ${g.name}.`,value:q.secret}),y(),q},done:()=>"API key created."},h?"ready":"loading"),l.jsx(el,{title:"API keys",read:()=>i(j),deps:[u,d],empty:"No API keys yet.",columns:[["Name",g=>l.jsx("strong",{children:g.name})],["Prefix",g=>Et(g.keyPrefix)],["Ceiling",g=>l.jsx("span",{className:"small",children:g.restrictions?g.restrictions.capabilities.length?g.restrictions.capabilities.join(", "):"denies everything":"none"})],["Expires",g=>ea(g.expiresAt)],["Last used",g=>ea(g.lastUsedAt)],["State",g=>l.jsx(I,{tone:g.status==="active"?"ok":"neutral",children:g.rotatedTo?"replaced":g.status})]],actions:(g,R)=>l.jsxs(l.Fragment,{children:[g.status==="active"&&!g.rotatedTo&&l.jsx(gt,{label:"Rotate",confirm:"Issue a new secret and revoke this one now?",action:async()=>{const q=un(await i(`${j}/${encodeURIComponent(g.id)}/rotate`,"POST",{overlapSeconds:0}),`The API key ${g.name}`);x({lead:`Rotated ${g.name}.`,value:q.secret})},done:R}),l.jsx("button",{className:"btn btn-small",onClick:()=>f(g),children:"Audit"}),l.jsx(gt,{label:"Revoke",danger:!0,confirm:`Revoke ${g.name}? Requests with it are refused from then on.`,action:()=>i(`${j}/${encodeURIComponent(g.id)}`,"DELETE"),done:R})]})}),b&&l.jsx(el,{title:`Audit for ${b.name}`,read:()=>i(`${j}/${encodeURIComponent(b.id)}/audit`).then(g=>Array.isArray(g)?g:g.items??[]),deps:[b.id,d],empty:"No events.",columns:[["Time",g=>ea(g.timestamp)],["Event",g=>Et(g.type)],["Result",g=>g.result],["Principal",g=>Et(g.principalId)]]})]})}const Ph="generate";function Hb(){const i=crypto.getRandomValues(new Uint8Array(32));return btoa(String.fromCharCode(...i)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function Bb({as:i,manage:u,version:d}){const[r,h]=k.useState(0),v=()=>h(f=>f+1),x=on(d,r),b=x?.credentials??[];return l.jsxs(l.Fragment,{children:[l.jsx(jl,{title:"Register an endpoint",submitLabel:"Register endpoint",fields:[{name:"url",label:"Endpoint URL",type:"url",required:!0,placeholder:"https://example.com/webhook"},{name:"events",label:"Events",required:!0,multi:!0,placeholder:"invoice.created, invoice.paid",choices:x?.webhookEvents.all??[],hint:x?.webhookEvents.declared.length?"Declared in services.webhooks.events; your functions emit them with ctx.services.webhooks.emit().":"Declare your events in services: { webhooks: { events: [...] } } to list them here."},{name:"signingCredentialRef",label:"Signing secret",required:!0,pattern:"credential-ref:.+",placeholder:"credential-ref:webhook-signing",choices:[{value:Ph,label:"Generate a new signing secret"},...b.map(f=>({value:f.ref,label:`${f.ref}${f.present?"":" (not set)"}`}))],hint:"A new secret is stored in FeltKit's custody and shown to you once, to configure the receiver."}],send:async f=>{const y=Ds(f.events??"");if(!y.length)throw new Error("Choose at least one event.");let j=f.signingCredentialRef,g=null;return j===Ph&&(j=`credential-ref:webhook-${new URL(f.url).hostname.replace(/[^A-Za-z0-9]+/g,"-").replace(/^-|-$/g,"")}-${Date.now().toString(36)}`,g=Hb(),await ne("/credentials",{method:"POST",body:JSON.stringify({ref:j,value:g,as:i})})),await u("/_appport/webhooks","POST",{url:f.url,events:y,signingCredentialRef:j}),v(),{ref:j,secret:g}},done:f=>f.secret?l.jsxs(l.Fragment,{children:["Endpoint registered, signing with ",l.jsx("code",{children:f.ref}),". Give the receiver this secret now; it is not shown again: ",l.jsx("code",{className:"token",children:f.secret})," ",l.jsx(rn,{text:f.secret})]}):l.jsxs(l.Fragment,{children:["Endpoint registered, signing with ",l.jsx("code",{children:f.ref}),"."]})},x?"ready":"loading"),l.jsx(el,{title:"Endpoints",read:()=>u("/_appport/webhooks"),deps:[i,d,r],empty:"No endpoints yet.",columns:[["URL",f=>Et(f.url)],["Events",f=>l.jsx("span",{className:"small",children:(f.events??[]).join(", ")})],["Signing secret",f=>Et(f.signingCredentialRef)],["Created",f=>ea(f.createdAt)],["Status",f=>l.jsx(I,{tone:f.disabledAt?"neutral":"ok",children:f.disabledAt?"disabled":"active"})]],actions:(f,y)=>f.disabledAt?null:l.jsx(gt,{label:"Disable",danger:!0,confirm:"Stop delivering to this endpoint? It cannot be enabled again.",action:()=>u(`/_appport/webhooks/${encodeURIComponent(f.id)}`,"DELETE"),done:y})}),l.jsx(el,{title:"Recent deliveries",read:()=>u("/_appport/webhooks/deliveries?limit=50").then(f=>Array.isArray(f)?f:f.items??[]),deps:[i,d,r],empty:"No deliveries yet.",columns:[["Event",f=>Et(f.eventType)],["Status",f=>l.jsx(I,{tone:f.status==="delivered"?"ok":f.status==="failed"?"bad":"warn",children:f.status})],["Attempts",f=>f.attemptCount],["HTTP",f=>f.lastStatusCode??""],["Last error",f=>l.jsx("span",{className:"error-text small",children:f.lastError??""})],["Created",f=>ea(f.createdAt)]],tools:f=>l.jsx(Nm,{done:f}),actions:(f,y)=>f.status==="failed"?l.jsxs(l.Fragment,{children:[l.jsx(gt,{label:"Replay",action:()=>ne(`/services/deliveries/${encodeURIComponent(f.id)}/replay`,{method:"POST",body:JSON.stringify({as:i})}),done:y}),l.jsx("button",{className:"btn btn-small",onClick:()=>yt(`agent/new/diagnose-delivery/${encodeURIComponent(f.id)}`),children:"Diagnose"})]}):null})]})}function Em({handlers:i,mutations:u}){const[d,r]=k.useState(u[0]??"");if(Object.keys(i).length)return null;const v=`jobs: { handlers: { "${d.replace(":",".")}": "${d}" } },`;return l.jsxs(te,{title:"Declare a job type",children:[l.jsxs("p",{className:"small",children:["A job type runs one of your mutations, as the person who queued it, with retries. None is declared yet. Choose the mutation it runs, then add the line to ",l.jsx("code",{children:"services"})," in ",l.jsx("code",{children:"feltkit/app.ts"}),"; the backend reloads and the type appears below."]}),u.length?l.jsxs(l.Fragment,{children:[l.jsxs("span",{className:"row",children:[l.jsx("select",{className:"input",value:d,onChange:x=>r(x.target.value),"aria-label":"Mutation",children:u.map(x=>l.jsx("option",{value:x,children:x},x))}),l.jsx(rn,{text:v})]}),l.jsx("pre",{className:"json",children:v})]}):l.jsx("p",{className:"muted small",children:"Write a mutation in feltkit/ first."})]})}function Lb({as:i,manage:u,version:d}){const[r,h]=k.useState(0),v=()=>h(y=>y+1),x=on(d),b=x?.jobHandlers??{},f=Object.keys(b);return l.jsxs(l.Fragment,{children:[x&&l.jsx(Em,{handlers:b,mutations:x.mutations}),l.jsx(jl,{title:"Queue a job",submitLabel:"Queue job",fields:[{name:"type",label:"Job type",required:!0,strict:!0,choices:f.map(y=>({value:y,label:`${y} → ${b[y]}`})),placeholder:"Declare a handler first"},{name:"payload",label:"Payload (JSON object)",multiline:!0,value:"{}"}],send:async y=>{if(!f.includes(y.type))throw new Error(`No handler is declared for "${y.type}", so the job would fail. Declare it in services.jobs.handlers first.`);await u("/_appport/jobs","POST",{type:y.type,payload:Db(y.payload??"{}","payload")}),v()},done:()=>l.jsxs(l.Fragment,{children:["Job queued as ",i,"."," ",l.jsx("button",{className:"btn btn-small",onClick:()=>{ne("/services/run",{method:"POST",body:"{}"}).then(v)},children:"Run due work now"})]})},f.join(",")),l.jsx(el,{title:"Jobs",read:()=>u("/_appport/jobs").then(y=>[...y].sort((j,g)=>String(g.createdAt).localeCompare(String(j.createdAt)))),deps:[i,d,r],empty:"No jobs yet.",tools:y=>l.jsx(Nm,{done:y}),columns:[["Type",y=>Et(y.type)],["Status",y=>l.jsx(I,{tone:y.status==="completed"?"ok":y.status==="failed"?"bad":"warn",children:y.status})],["Attempts",y=>`${y.attemptCount}/${y.maxAttempts}`],["Run at",y=>ea(y.runAt)],["Last error",y=>l.jsx("span",{className:"error-text small",children:y.lastError??""})]],actions:(y,j)=>l.jsxs(l.Fragment,{children:[(y.status==="failed"||y.status==="completed")&&l.jsx(gt,{label:"Retry",action:async()=>un(await u(`/_appport/jobs/${encodeURIComponent(y.id)}/retry`,"POST"),`The ${y.type} job`),done:j}),y.status==="failed"&&l.jsx("button",{className:"btn btn-small",onClick:()=>yt(`agent/new/diagnose-job/${encodeURIComponent(y.id)}`),children:"Diagnose"})]})})]})}const Yb={s:"second",m:"minute",h:"hour",d:"day"},Gb=i=>{const u=/^(\d+)([smhd])$/.exec(String(i));return u?`Every ${u[1]} ${Yb[u[2]]}${u[1]==="1"?"":"s"}`:String(i)};function Vb({manage:i,version:u}){const[d,r]=k.useState(0),h=()=>r(f=>f+1),v=on(u),x=v?.jobHandlers??{},b=Object.keys(x);return l.jsxs(l.Fragment,{children:[v&&b.length===0&&l.jsx(Em,{handlers:x,mutations:v.mutations}),l.jsx(jl,{title:"Create a schedule",submitLabel:"Create schedule",fields:[{name:"type",label:"Job type",required:!0,strict:!0,choices:b.map(f=>({value:f,label:`${f} → ${x[f]}`})),placeholder:"Declare a handler first"},{name:"interval",label:"Frequency",options:[{value:"15m",label:"Every 15 minutes"},{value:"30m",label:"Every 30 minutes"},{value:"1h",label:"Every hour"},{value:"6h",label:"Every 6 hours"},{value:"1d",label:"Every day"},{value:"7d",label:"Every week"}]}],send:async f=>{if(!b.includes(f.type))throw new Error(`No handler is declared for "${f.type}", so every scheduled job would fail. Declare it in services.jobs.handlers first.`);await i("/_appport/schedules","POST",{type:f.type,interval:f.interval}),h()},done:()=>"Schedule created."},b.join(",")),l.jsx(el,{title:"Schedules",read:()=>i("/_appport/schedules"),deps:[u,d],empty:"No schedules yet.",columns:[["Type",f=>Et(f.type)],["Frequency",f=>Gb(f.interval)],["Next run",f=>ea(f.nextRunAt)],["Created by",f=>Et(f.createdBy)],["Status",f=>l.jsx(I,{tone:f.enabled?"ok":"neutral",children:f.enabled?"enabled":"disabled"})]],actions:(f,y)=>f.enabled?l.jsx(gt,{label:"Disable",danger:!0,confirm:"Stop queueing jobs from this schedule? It cannot be enabled again.",action:async()=>un(await i(`/_appport/schedules/${encodeURIComponent(f.id)}`,"DELETE"),"The schedule"),done:y}):null})]})}function Qb({manage:i,version:u}){const[d,r]=k.useState(0),h=Le(()=>Promise.all([i("/v1/intelligence/catalog"),i("/v1/intelligence")]),[u,d]),[v,x]=k.useState(null),[b,f]=k.useState(null),[y,j]=k.useState(!1);if(h.error)return l.jsx(ve,{error:h.error,retry:h.reload});if(!h.data)return l.jsx(Ze,{});const[g,R]=h.data,q=v??{provider:R.configured?R.provider:g[0]?.id??"",model:R.configured?R.model:"",endpoint:R.configured&&R.endpoint?.kind==="custom"?R.endpoint.url:"",credentialRef:""},V=g.find(X=>X.id===q.provider),E=X=>(j(!1),x({...q,...X})),A=async X=>{X.preventDefault(),f(null);try{if(ui(q.credentialRef))throw new Error("That looks like an API key. Enter the key in Studio → Models; here, give a credential reference.");await i("/v1/intelligence","PUT",{provider:q.provider,model:q.model,endpoint:q.endpoint&&V?.customEndpoint?q.endpoint:"default",...q.credentialRef?{credentialRef:q.credentialRef}:{}}),x(null),j(!0),r(ee=>ee+1)}catch(ee){f(ee)}};return l.jsxs(l.Fragment,{children:[l.jsxs(te,{title:"Current",children:[l.jsx("p",{className:"small",children:R.configured?l.jsxs(l.Fragment,{children:[l.jsx("strong",{children:R.provider})," / ",l.jsx("code",{children:R.model})," · credential ",R.credentialConfigured?"attached":"not attached"]}):"Not configured. The platform works without it; the agent then has no model to decide with."}),l.jsxs("p",{className:"muted small",children:["To enter an API key and test the model, use"," ",l.jsx("a",{href:"#/models",className:"link",children:"Models"}),"."]})]}),l.jsxs(te,{title:"Configure",children:[l.jsxs("form",{onSubmit:A,children:[l.jsxs("div",{className:"form-grid",children:[l.jsxs("label",{children:[l.jsx("span",{children:"Provider *"}),l.jsx("select",{className:"input",value:q.provider,onChange:X=>E({provider:X.target.value,model:""}),children:g.map(X=>l.jsx("option",{value:X.id,children:X.displayName},X.id))})]}),l.jsxs("label",{children:[l.jsx("span",{children:"Model *"}),l.jsx("input",{className:"input",list:"intelligence-models",value:q.model,required:!0,onChange:X=>E({model:X.target.value})}),l.jsx("datalist",{id:"intelligence-models",children:(V?.models??[]).map(X=>l.jsx("option",{value:X.id,children:X.displayName},X.id))})]}),V?.customEndpoint&&l.jsxs("label",{children:[l.jsx("span",{children:"Custom endpoint (optional)"}),l.jsx("input",{className:"input",type:"url",value:q.endpoint,placeholder:V.endpoints?.[0]?.url??"http://localhost:11434/v1",onChange:X=>E({endpoint:X.target.value})})]}),l.jsxs("label",{children:[l.jsxs("span",{children:["Credential reference",V?.credential==="required"&&!R.credentialConfigured?" *":""]}),l.jsx("input",{className:"input",value:q.credentialRef,pattern:"credential-ref:.+",placeholder:`credential-ref:${q.provider}`,required:V?.credential==="required"&&!R.credentialConfigured,onChange:X=>E({credentialRef:X.target.value})}),l.jsx("span",{className:"muted small",children:"Leave empty to keep the current one."})]})]}),l.jsx("button",{className:"btn btn-primary",type:"submit",children:"Save"}),R.credentialConfigured&&V?.credential!=="required"&&l.jsx(gt,{label:"Remove credential",danger:!0,confirm:"Detach the credential reference?",action:()=>i("/v1/intelligence/credential","DELETE"),done:()=>r(X=>X+1)})]}),b?l.jsx(ve,{error:b}):null,y?l.jsx("div",{className:"ok-box small",children:"Saved."}):null]})]})}const em={configured:{tone:"ok",help:"Enabled, set up, and its records read cleanly."},unconfigured:{tone:"warn",help:"Enabled, but nothing is set up yet."},unhealthy:{tone:"bad",help:"Enabled, but its store failed a check or recent work failed."},available:{tone:"neutral",help:"Can run here; not enabled in feltkit({ services })."},unavailable:{tone:"bad",help:"Cannot run in this installation."}};function ws({service:i}){const u=em[i.state]??em.unavailable;return l.jsx(I,{tone:u.tone,title:u.help,children:i.state})}const Tm="feltkit.services.as",Xb=()=>{try{return sessionStorage.getItem(Tm)}catch{return null}};function $b(i){const[u,d]=k.useState(()=>Xb()??i[0]?.id??""),r=v=>{d(v);try{sessionStorage.setItem(Tm,v)}catch{}};k.useEffect(()=>{i.length&&!i.some(v=>v.id===u)&&d(i[0].id)},[i,u]);const h=l.jsxs("label",{className:"row small",children:[l.jsx("span",{className:"muted",children:"Act as"}),l.jsx("select",{value:u,onChange:v=>r(v.target.value),"aria-label":"Identity for service operations",children:i.map(v=>l.jsxs("option",{value:v.id,children:[v.name??v.id," (",v.roles.join(", "),")"]},v.id))})]});return{as:u,picker:h}}const hr=i=>i.state!=="available"&&i.state!=="unavailable";function Zb({page:i}){const{version:u}=Bt(),d=Le(()=>ne("/services"),[u]),r=Le(()=>ne("/overview"),[u]),h=r.data?.devUsers??[],v=!!r.data?.environment?.development,{canAct:x}=Rs(r.data),{as:b,picker:f}=$b(h),y=d.data?.services??[],j=v&&h.length?f:null;if(i==="credentials")return l.jsxs(l.Fragment,{children:[l.jsx(Ht,{title:"Credentials",subtitle:l.jsx(Kb,{children:"Credential references the services and configuration use, and where each value is kept."}),actions:j}),l.jsx(Fb,{as:b,canAct:x,development:v,version:u})]});if(i){const q=y.find(V=>V.id===i);return l.jsx(Ab,{id:i,service:q,as:b,picker:j,development:v,summary:q&&hr(q)?l.jsx(Jb,{service:q}):null,operations:!v&&i==="jobs"?l.jsx(Wb,{as:b,development:!1,canAct:x,version:u}):!v&&i==="webhooks"?l.jsx(Ib,{as:b,development:!1,canAct:!1,version:u}):null})}const g=y.filter(hr),R=y.filter(q=>!hr(q));return l.jsxs(l.Fragment,{children:[l.jsx(Ht,{title:"Services",subtitle:v?"AppPort Services on this environment’s FeltDB instance. Each service has its own screen; every operation there is authorized by your roles, as the identity you choose.":"AppPort Services on this environment’s FeltDB instance. Configuration is a development tool; job retries here are authorized as you and recorded as yours.",actions:j}),d.error&&!d.data?l.jsx(ve,{error:d.error,retry:d.reload}):d.data?l.jsxs(l.Fragment,{children:[v&&h.length===0&&l.jsx(te,{children:l.jsxs("p",{className:"muted small",children:["Declare a development identity in ",l.jsxs("code",{children:["feltkit(","{"," dev: ","{"," users ","}"," ","}",")"]})," to manage services: their operations are authorized as that identity."]})}),g.length===0&&l.jsxs(qt,{title:"No services enabled",children:["Enable services with feltkit(","{"," services: ","{"," … ","}"," ","}","). Each one gets its own screen here."]}),l.jsxs("div",{className:"grid grid-3",children:[g.map(q=>l.jsxs("a",{href:`#/services/${q.id}`,className:"card service-tile",children:[l.jsxs("span",{className:"row",children:[l.jsx("strong",{children:q.name})," ",l.jsx(ws,{service:q})]}),l.jsx("span",{className:"small",children:q.detail}),q.summary&&l.jsx("span",{className:"muted small",children:Object.entries(q.summary).slice(0,3).map(([V,E])=>`${V} ${E}`).join(" · ")})]},q.id)),l.jsxs("a",{href:"#/services/credentials",className:"card service-tile",children:[l.jsx("strong",{children:"Credentials"}),l.jsx("span",{className:"small",children:"References the services use, and whether each value is set. Values are never shown."})]})]}),R.length>0&&l.jsx(te,{title:"Not enabled",children:l.jsx("ul",{className:"list",children:R.map(q=>l.jsxs("li",{className:"list-row",children:[l.jsxs("span",{children:[l.jsx("strong",{children:q.name})," ",l.jsx("span",{className:"muted small",children:q.state==="unavailable"?q.detail:q.description})]}),l.jsxs("span",{className:"row",children:[l.jsx(ws,{service:q}),q.state==="available"&&l.jsx("button",{className:"btn btn-small",onClick:()=>yt(`services/${q.id}`),children:"Enable"})]})]},q.id))})})]}):l.jsx(Ze,{})]})}const Kb=({children:i})=>l.jsxs(l.Fragment,{children:[l.jsx("a",{href:"#/services",className:"link",children:"Services"})," ","· ",i]});function Jb({service:i}){return l.jsxs(te,{title:l.jsxs("span",{className:"row",children:["Status ",l.jsx(ws,{service:i})]}),action:l.jsxs("span",{className:"muted small",children:[i.package,"@",i.version]}),children:[l.jsxs("dl",{className:"kv",children:[l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Status"}),l.jsxs("dd",{children:[i.detail," ",i.lastCheckedAt&&l.jsxs("span",{className:"muted",children:["· checked ",tt(i.lastCheckedAt)]})]})]}),i.summary&&l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Records"}),l.jsx("dd",{children:Object.entries(i.summary).map(([u,d])=>l.jsxs("span",{className:"chip",children:[u," ",l.jsx("strong",{children:String(d)})]},u))})]}),i.lastError&&l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Last error"}),l.jsxs("dd",{className:"error-text",children:[i.lastError.message," ",l.jsxs("span",{className:"muted",children:["· ",tt(i.lastError.at)]})]})]})]}),l.jsxs("details",{className:"small",children:[l.jsx("summary",{className:"muted",children:"Permissions and stored state"}),l.jsxs("dl",{className:"kv",children:[l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Permissions"}),l.jsx("dd",{children:i.capabilities.map(u=>l.jsx("code",{className:"chip",children:u},u))})]}),l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"State"}),l.jsx("dd",{children:i.collections.map(u=>l.jsx("a",{href:`#/data/${u}`,className:"chip mono",children:u},u))})]})]})]})]})}function Fb({as:i,canAct:u,development:d,version:r}){const[h,v]=k.useState(0),x=Le(()=>ne("/credentials"),[r,h]),[b,f]=k.useState(null),[y,j]=k.useState("");if(x.error)return l.jsx(ve,{error:x.error,retry:x.reload});if(!x.data)return null;const{custody:g,credentials:R}=x.data,q=async E=>{f(null);try{await ne(`/credentials/${encodeURIComponent(E)}${d&&i?`?as=${encodeURIComponent(i)}`:""}`,{method:"DELETE"}),v(A=>A+1)}catch(A){f(A)}},V=y.trim()?y.trim().startsWith("credential-ref:")?y.trim():`credential-ref:${y.trim()}`:"";return l.jsxs(te,{title:"Credentials",children:[l.jsxs("p",{className:"muted small",children:["Services and configuration hold credential references only. Values are kept by FeltKit’s custody (",g.location,") and used inside the effect that needs them; they are never stored in FeltDB, logged, or shown. ",g.note]}),b?l.jsx(ve,{error:b}):null,l.jsx("div",{className:"table-wrap",children:l.jsxs("table",{className:"table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:"Reference"}),l.jsx("th",{children:"Used by"}),l.jsx("th",{children:"Value"}),l.jsx("th",{children:"Override variable"}),l.jsx("th",{})]})}),l.jsx("tbody",{children:R.map(E=>l.jsxs("tr",{children:[l.jsx("td",{className:"mono",children:E.ref}),l.jsx("td",{className:"small",children:E.usedBy.length?E.usedBy.join(", "):l.jsx("span",{className:"muted",children:"stored, not used yet"})}),l.jsx("td",{children:l.jsx(Bs,{credential:E})}),l.jsx("td",{className:"mono small",children:E.variable??"invalid reference"}),l.jsx("td",{children:u&&E.writable&&l.jsxs("span",{className:"row",children:[l.jsx(zs,{credentialRef:E.ref,label:E.present?"Replace":"Set",...d&&i?{as:i}:{},onSaved:()=>v(A=>A+1)}),E.source==="vault"&&E.present&&l.jsx("button",{className:"btn btn-small",onClick:()=>q(E.ref),children:"Remove"})]})})]},E.ref))})]})}),u&&g.writable&&l.jsxs("div",{className:"row small",children:[l.jsx("input",{className:"input",value:y,onChange:E=>j(ui(E.target.value)?"":E.target.value),placeholder:"credential-ref:stripe","aria-label":"New credential reference"}),V&&l.jsx(zs,{credentialRef:V,label:"Set value",...d&&i?{as:i}:{},onSaved:()=>(j(""),v(E=>E+1))})]})]})}function Am({title:i,path:u,as:d,development:r,canAct:h,version:v,retry:x,columns:b}){const[f,y]=k.useState(0),j=Le(()=>ne(`/services/${u}`),[v,f]),[g,R]=k.useState(null),q=async A=>{R(null);try{await ne(`/services/${u}/${encodeURIComponent(A)}/${x.action}`,{method:"POST",body:JSON.stringify(r?{as:d}:{})}),y(X=>X+1)}catch(X){R(X)}},V=async()=>{R(null);try{await ne("/services/run",{method:"POST",body:"{}"}),y(A=>A+1)}catch(A){R(A)}},E=j.data?.items??[];return l.jsxs(te,{title:i,action:r?l.jsx("button",{className:"btn",onClick:V,children:"Run due work now"}):null,children:[g?l.jsx(ve,{error:g}):null,j.data?.replay&&!j.data.replay.enabled?l.jsx("p",{className:"muted small",children:j.data.replay.reason}):null,j.error?l.jsx(ve,{error:j.error,retry:j.reload}):j.data?E.length===0?l.jsx("p",{className:"muted small",children:"Nothing yet."}):l.jsx("div",{className:"table-wrap",children:l.jsxs("table",{className:"table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[b.map(([A])=>l.jsx("th",{children:A},A)),l.jsx("th",{})]})}),l.jsx("tbody",{children:E.slice(0,50).map(A=>l.jsxs("tr",{children:[b.map(([X,ee])=>l.jsx("td",{children:ee(A)},X)),l.jsxs("td",{className:"row",children:[r&&A.status==="failed"&&l.jsx("button",{className:"btn btn-small",onClick:()=>yt(`agent/new/${u==="jobs"?"diagnose-job":"diagnose-delivery"}/${encodeURIComponent(A.id)}`),children:"Diagnose"}),h&&x.when(A)&&(A.retryable??!0)&&l.jsx("button",{className:"btn btn-small",onClick:()=>q(A.id),disabled:r&&!d,children:x.label})]})]},A.id))})]})}):l.jsx(Ze,{})]})}const km=i=>i==="completed"||i==="delivered"?"ok":i==="failed"?"bad":"warn";function Wb(i){return l.jsx(Am,{...i,title:"Job runs",path:"jobs",retry:{label:"Retry",action:"retry",when:u=>u.status==="failed"},columns:[["Type",u=>l.jsx("code",{children:u.type})],["Status",u=>l.jsx(I,{tone:km(u.status),children:u.status})],["Attempts",u=>`${u.attemptCount}/${u.maxAttempts}`],["As",u=>l.jsx("span",{className:"mono small",children:u.principal??"—"})],["Last error",u=>l.jsx("span",{className:"error-text small",children:u.lastError??""})],["Created",u=>l.jsx("span",{className:"muted small",children:tt(u.createdAt)})]]})}function Ib(i){return l.jsx(Am,{...i,title:"Webhook deliveries",path:"deliveries",retry:{label:"Replay",action:"replay",when:u=>u.status==="failed"},columns:[["Event",u=>l.jsx("code",{children:u.eventType})],["To",u=>l.jsx("span",{className:"mono small",children:u.destination??u.endpointId})],["Status",u=>l.jsx(I,{tone:km(u.status),children:u.status})],["Attempts",u=>u.attemptCount],["HTTP",u=>u.lastStatusCode??""],["Last error",u=>l.jsx("span",{className:"error-text small",children:u.lastError??""})],["Created",u=>l.jsx("span",{className:"muted small",children:tt(u.createdAt)})]]})}function Pb(){jm();const{overview:i,activity:u}=Bt();if(!i)return null;const d=i.capabilities??[],r=Cm(u,i.recentActivity??[]).slice(0,8),h=[...i.recentErrors??[],...i.recentDenials??[]].sort((f,y)=>y.at.localeCompare(f.at)).slice(0,6),v=Object.values(i.counts??{}).reduce((f,y)=>f+Number(y),0),x=(i.services??[]).filter(f=>f.state!=="available"&&f.state!=="unavailable"),b=i.agent??{tasks:[],waiting:0,handoffs:0};return l.jsxs(l.Fragment,{children:[l.jsx(Ht,{title:i.application.name,subtitle:i.application.description??"Your application at a glance: where its state lives, what it can do, and what it has done.",actions:l.jsxs(l.Fragment,{children:[l.jsx(I,{tone:i.state==="ready"?"ok":"warn",children:i.state}),i.url&&l.jsx("a",{className:"btn",href:i.url,target:"_blank",rel:"noreferrer",children:"Open app ↗"})]})}),l.jsxs("div",{className:"grid grid-4 stats",children:[l.jsx(As,{label:"Records",value:v,detail:`${i.collections.length} collection${i.collections.length===1?"":"s"}`,onClick:()=>yt("data")}),l.jsx(As,{label:"Functions",value:i.functions.length,detail:`${i.functions.filter(f=>f.kind==="query").length} queries · ${i.functions.filter(f=>f.kind==="mutation").length} mutations`,onClick:()=>yt("capabilities")}),l.jsx(As,{label:"Capabilities",value:d.length,detail:"published through AppPort",onClick:()=>yt("capabilities")}),l.jsx(As,{label:"Errors",value:(i.recentErrors??[]).length,detail:`${(i.recentDenials??[]).length} recent denials`,tone:(i.recentErrors??[]).length?"bad":void 0,onClick:()=>yt("activity")})]}),l.jsxs("div",{className:"grid grid-2",children:[l.jsxs(te,{title:"Where state lives",children:[l.jsx("p",{className:"lede",children:"One FeltDB instance serves this environment. Application functions, AppPort capabilities, AppPort Services, sessions, and this activity log all read and write it."}),l.jsxs("dl",{className:"kv",children:[l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Environment"}),l.jsxs("dd",{children:[i.environment.name," ",i.environment.production&&l.jsx(I,{tone:"warn",children:"production"})]})]}),l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Storage"}),l.jsxs("dd",{children:["FeltDB ",i.instance.feltdbVersion," · ",i.instance.mode," · ",i.instance.durable?"durable":"ephemeral"]})]}),l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Location"}),l.jsx("dd",{children:l.jsx("code",{className:"path",children:i.instance.location})})]}),l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Journal"}),l.jsxs("dd",{children:["position ",i.instance.sequence]})]}),l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Opened"}),l.jsxs("dd",{children:[tt(i.instance.openedAt)," by pid ",i.instance.pid]})]})]}),l.jsxs("div",{className:"components",children:[l.jsx("div",{className:"components-title",children:"Components using this instance"}),Object.entries(i.components??{}).map(([f,y])=>l.jsxs("div",{className:"component",children:[l.jsx("span",{className:"mono",children:f}),l.jsx("span",{className:"muted small",children:y.join(", ")})]},f))]})]}),l.jsx(te,{title:"Recent activity",action:l.jsx("a",{href:"#/activity",className:"link",children:"All activity →"}),children:r.length===0?l.jsx(qt,{title:"Nothing has happened yet",children:"Open the app and make a change. Every query, mutation, capability call, and sign-in appears here."}):l.jsx("ul",{className:"feed",children:r.map(f=>l.jsx("li",{children:l.jsxs("a",{href:`#/activity/${f.id}`,className:"feed-row",children:[l.jsx(cn,{outcome:f.outcome}),l.jsx("span",{className:"mono feed-name",children:f.name}),l.jsx("span",{className:"muted small",children:f.principal?.id??(f.kind==="system"?"system":"anonymous")}),l.jsxs("span",{className:"muted small",children:["via ",f.via]}),f.writes?.length?l.jsxs(I,{tone:"accent",children:[f.writes.length," write",f.writes.length===1?"":"s"]}):null,l.jsx("span",{className:"muted small right",children:tt(f.at)})]})},f.id))})})]}),i.path&&l.jsx(te,{title:"Path to production",children:l.jsx("ol",{className:"journey",children:i.path.map(f=>l.jsxs("li",{children:[l.jsx(I,{tone:f.state==="done"?"ok":f.state==="todo"?"warn":"neutral",children:f.state==="done"?"done":f.state==="todo"?"to do":f.state==="not-tracked"?"not tracked":"review"}),l.jsx("strong",{children:f.step}),l.jsx("span",{className:"small",children:f.detail}),f.link&&l.jsx("a",{className:"link small",href:`#/${f.link}`,"aria-label":`Open ${f.step}`,children:"Open →"})]},f.step))})}),l.jsxs("div",{className:"grid grid-3",children:[l.jsx(te,{title:"Data",action:i.environment.production?null:l.jsx("a",{href:"#/data",className:"link",children:"Explore →"}),children:i.collections.length===0?l.jsxs(qt,{title:"No collections",children:['Declare one with app.collection("name", ',"{ … }",")."]}):l.jsx("ul",{className:"list",children:i.collections.map(f=>l.jsx("li",{children:l.jsxs("a",{href:`#/data/${f.name}`,className:"list-row",children:[l.jsx("span",{className:"mono",children:f.name}),l.jsx("span",{className:"muted",children:i.counts?.[f.name]??0})]})},f.name))})}),l.jsx(te,{title:"Capabilities",action:l.jsx("a",{href:"#/capabilities",className:"link",children:"Inspect →"}),children:d.length===0?l.jsx(qt,{title:"No capabilities published",children:'Add capability: "name.verb" to a query or mutation to publish it through AppPort.'}):l.jsx("ul",{className:"list",children:d.map(f=>l.jsx("li",{children:l.jsxs("a",{href:`#/capabilities/${f.name}`,className:"list-row",children:[l.jsx("span",{className:"mono",children:f.name}),l.jsx(I,{tone:f.effect==="consequential"?"accent":"neutral",children:f.effect})]})},f.name))})}),l.jsx(te,{title:"Services",action:l.jsx("a",{href:"#/services",className:"link",children:"Manage →"}),children:x.length===0?l.jsxs(qt,{title:"No services enabled",children:["Enable AppPort Services with feltkit(","{"," services: ","{"," files: true, jobs: … ","}"," ","}",")."]}):l.jsx("ul",{className:"list",children:x.map(f=>l.jsxs("li",{className:"list-row",children:[l.jsx("span",{children:f.name}),l.jsx(ws,{service:f,compact:!0})]},f.id))})})]}),l.jsxs(te,{title:"Agent",action:l.jsx("a",{href:"#/agent",className:"link",children:"Open →"}),children:[b.waiting>0&&l.jsxs("p",{children:[l.jsxs(I,{tone:"warn",children:[b.waiting," waiting for approval"]})," ",l.jsx("a",{href:"#/agent",children:"Review"})]}),b.handoffs>0&&l.jsxs("p",{className:"muted small",children:[b.handoffs," task(s) waiting for a coding agent to claim over MCP."]}),b.tasks.length===0?l.jsx("p",{className:"muted small",children:"No agent tasks yet. Diagnose a failed job from Services, or start one on the Agent screen."}):l.jsx("ul",{className:"list",children:b.tasks.map(f=>l.jsx("li",{children:l.jsxs("a",{href:`#/agent/${f.id}`,className:"list-row",children:[l.jsx("span",{children:f.objective}),l.jsx(I,{tone:f.status==="completed"?"ok":f.status==="blocked"?"warn":"neutral",children:f.status})]})},f.id))})]}),h.length>0&&l.jsx(te,{title:"Recent errors and denials",action:l.jsx("a",{href:"#/activity",className:"link",children:"Investigate →"}),children:l.jsx("ul",{className:"feed",children:h.map(f=>l.jsx("li",{children:l.jsxs("a",{href:`#/activity/${f.id}`,className:"feed-row",children:[l.jsx(cn,{outcome:f.outcome}),l.jsx("span",{className:"mono feed-name",children:f.name}),l.jsx("span",{className:"error-text small",children:f.error?.code}),l.jsx("span",{className:"small ellipsis",children:f.error?.message}),l.jsx("span",{className:"muted small right",children:tt(f.at)})]})},f.id))})}),!i.environment.production&&l.jsx(te,{title:"Development",children:l.jsxs("dl",{className:"kv",children:[l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Runtime"}),l.jsxs("dd",{children:["started ",tt(i.startedAt)," · functions loaded ",tt(i.loadedAt)," · generation ",i.generation]})]}),l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Project"}),l.jsx("dd",{children:l.jsx("code",{className:"path",children:i.projectDir})})]}),l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Endpoints"}),l.jsxs("dd",{className:"mono small",children:[i.url,"/api · ",i.url,"/appport · ",i.url,"/mcp"]})]}),l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Deploy"}),l.jsxs("dd",{children:[l.jsx("code",{children:"npx feltkit deploy"})," ",l.jsx("span",{className:"muted",children:"builds, verifies the production build boots, and writes a Node/Docker artifact."})]})]})]})})]})}function As({label:i,value:u,detail:d,tone:r,onClick:h}){return l.jsxs("button",{className:`stat ${r==="bad"&&u>0?"stat-bad":""}`,onClick:h,children:[l.jsx("span",{className:"stat-label",children:i}),l.jsx("span",{className:"stat-value",children:u}),l.jsx("span",{className:"stat-detail",children:d})]})}function Cm(i,u){const d=new Set;return[...i,...u].filter(r=>d.has(r.id)?!1:(d.add(r.id),!0)).sort((r,h)=>h.id.localeCompare(r.id))}function ex({collection:i}){const{version:u,overview:d}=Bt(),r=Le(()=>ne("/collections"),[u]),h=r.data?.collections??[],v=h.find(b=>b.name===i)??h.find(b=>b.owner==="application")??h[0],x=!!v?.editable&&!d?.environment?.production;return l.jsxs(l.Fragment,{children:[l.jsx(Ht,{title:"Data",subtitle:l.jsx(l.Fragment,{children:"Records in this environment’s FeltDB instance. Application collections are validated by their schemas; platform collections belong to FeltKit and AppPort Services and are read-only here."})}),r.error&&!r.data?l.jsx(ve,{error:r.error,retry:r.reload}):r.data?l.jsxs("div",{className:"split",children:[l.jsx("aside",{className:"split-nav","aria-label":"Collections",children:["application","platform"].map(b=>{const f=h.filter(y=>b==="application"?y.owner==="application":y.owner!=="application");return f.length?l.jsxs("div",{className:"split-group",children:[l.jsx("div",{className:"split-title",children:b==="application"?"Application":"Platform"}),f.map(y=>l.jsxs("a",{href:`#/data/${y.name}`,className:`split-item ${v?.name===y.name?"active":""}`,children:[l.jsx("span",{className:"mono ellipsis",children:y.name}),l.jsx("span",{className:"muted small",children:y.count})]},y.name))]},b):null})}),l.jsx("section",{className:"split-main",children:v?l.jsx(tx,{collection:v,editable:x},v.name):l.jsx(qt,{title:"No collections"})})]}):l.jsx(Ze,{})]})}function tx({collection:i,editable:u}){const{version:d}=Bt(),[r,h]=k.useState(""),[v,x]=k.useState(""),[b,f]=k.useState(null),[y,j]=k.useState([]),[g,R]=k.useState(null),[q,V]=k.useState(null),E=b?`&field=${encodeURIComponent(b.field)}&eq=${encodeURIComponent(b.value)}`:"",A=Le(()=>ne(`/collections/${encodeURIComponent(i.name)}?limit=50${E}`),[i.name,E,d]);k.useEffect(()=>{A.data&&(j(A.data.records),R(A.data.nextCursor))},[A.data]);const X=k.useMemo(()=>{const w=i.schema?.properties?Object.keys(i.schema.properties):[],K=[...new Set(y.flatMap(be=>Object.keys(be)))].filter(be=>be!=="id"&&be!=="__version");return["id",...(w.length?w:K).slice(0,6),"__version"]},[i.schema,y]),ee=async()=>{if(!g)return;const w=await ne(`/collections/${encodeURIComponent(i.name)}?limit=50&cursor=${encodeURIComponent(g)}${E}`);j(K=>[...K,...w.records]),R(w.nextCursor)};return l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"collection-head",children:[l.jsxs("div",{children:[l.jsx("h2",{className:"mono",children:i.name}),l.jsxs("div",{className:"muted small",children:[i.owner==="application"?"Application collection":`Owned by ${i.owner}`," · ",i.count," record",i.count===1?"":"s",i.description?` · ${i.description}`:""]})]}),l.jsxs("div",{className:"row",children:[!i.editable&&l.jsx(I,{children:"read-only"}),u&&l.jsx("button",{className:"btn btn-primary",onClick:()=>V("new"),children:"New record"})]})]}),i.schema&&l.jsxs("details",{className:"schema",children:[l.jsx("summary",{children:"Schema"}),l.jsx(si,{schema:i.schema}),l.jsx("p",{className:"muted small",children:"Enforced by FeltKit on every write through ctx.db. FeltDB stores JSON documents and adds id and __version."})]}),l.jsxs("form",{className:"filter",onSubmit:w=>{w.preventDefault(),f(r&&v!==""?{field:r,value:v}:null)},children:[l.jsxs("select",{className:"input",value:r,onChange:w=>h(w.target.value),"aria-label":"Filter field",children:[l.jsx("option",{value:"",children:"Filter by field…"}),X.map(w=>l.jsx("option",{value:w,children:w},w))]}),l.jsx("input",{className:"input",value:v,onChange:w=>x(w.target.value),placeholder:"equals…","aria-label":"Filter value"}),l.jsx("button",{className:"btn",type:"submit",children:"Apply"}),b&&l.jsx("button",{className:"btn btn-ghost",type:"button",onClick:()=>{f(null),h(""),x("")},children:"Clear"})]}),A.error?l.jsx(ve,{error:A.error,retry:A.reload}):A.loading&&!A.data?l.jsx(Ze,{}):y.length===0?l.jsx(qt,{title:b?"No records match":"No records yet",children:b?"Try another value.":i.owner==="application"?"Records appear here as soon as a mutation writes them.":""}):l.jsxs("div",{className:"table-wrap",children:[l.jsxs("table",{className:"table",children:[l.jsx("thead",{children:l.jsx("tr",{children:X.map(w=>l.jsx("th",{children:w},w))})}),l.jsx("tbody",{children:y.map(w=>l.jsx("tr",{onClick:()=>V(w),tabIndex:0,onKeyDown:K=>K.key==="Enter"&&V(w),children:X.map(K=>l.jsx("td",{className:K==="id"||K==="__version"?"mono muted":"",children:l.jsx(ax,{value:w[K]})},K))},w.id))})]}),g&&l.jsx("button",{className:"btn more",onClick:ee,children:"Load more"})]}),q&&l.jsx(nx,{collection:i,record:q==="new"?null:q,editable:u,onClose:()=>V(null),onSaved:()=>(V(null),A.reload())})]})}function ax({value:i}){if(i===void 0)return l.jsx("span",{className:"muted",children:"—"});if(typeof i=="boolean")return l.jsx(I,{tone:i?"ok":"neutral",children:String(i)});if(typeof i=="number"&&i>1e12&&i<1e13)return l.jsx("span",{title:String(i),children:new Date(i).toLocaleString()});if(typeof i=="object")return l.jsx("span",{className:"mono small",children:JSON.stringify(i).slice(0,80)});const u=String(i);return l.jsx("span",{title:u.length>60?u:void 0,children:u.length>60?`${u.slice(0,60)}…`:u})}function lx(i){const u={};for(const[d,r]of Object.entries(i?.properties??{}))(i.required??[]).includes(d)&&(u[d]=r.type==="number"||r.type==="integer"?/At$/.test(d)?Date.now():0:r.type==="boolean"?!1:"");return u}function nx({collection:i,record:u,editable:d,onClose:r,onSaved:h}){const v=u?Object.fromEntries(Object.entries(u).filter(([A])=>A!=="id"&&A!=="__version")):lx(i.schema),[x,b]=k.useState(JSON.stringify(v,null,2)),[f,y]=k.useState(null),[j,g]=k.useState(!1),[R,q]=k.useState(!1),V=async()=>{y(null);let A;try{A=JSON.parse(x)}catch{y({code:"INVALID_JSON",message:"That is not valid JSON."});return}g(!0);try{await ne(u?`/collections/${i.name}/${encodeURIComponent(u.id)}`:`/collections/${i.name}`,{method:u?"PATCH":"POST",body:JSON.stringify({record:A})}),h()}catch(X){y(X)}finally{g(!1)}},E=async()=>{g(!0);try{await ne(`/collections/${i.name}/${encodeURIComponent(u.id)}`,{method:"DELETE"}),h()}catch(A){y(A),g(!1)}};return l.jsxs(pm,{title:u?`${i.name} / ${u.id}`:`New ${i.name} record`,onClose:r,children:[u&&l.jsxs("p",{className:"muted small",children:["Version ",u.__version,". Find what wrote it in ",l.jsx("a",{href:"#/activity",children:"Activity"}),"."]}),d?l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"callout",children:["Development edit: validated against the schema and committed atomically, recorded in Activity as ",l.jsx("code",{children:"admin"})," by ",l.jsx("code",{children:"dashboard"}),". Function access rules do not apply to these edits; this tool is not available in production."]}),l.jsx("textarea",{className:"code-input",value:x,onChange:A=>b(A.target.value),rows:14,spellCheck:!1,"aria-label":"Record JSON"}),f?l.jsx(ve,{error:f}):null,l.jsxs("div",{className:"row between",children:[u?R?l.jsxs("span",{className:"row",children:[l.jsx("button",{className:"btn btn-danger",onClick:E,disabled:j,children:"Delete permanently"}),l.jsx("button",{className:"btn btn-ghost",onClick:()=>q(!1),children:"Cancel"})]}):l.jsx("button",{className:"btn btn-ghost danger",onClick:()=>q(!0),children:"Delete…"}):l.jsx("span",{}),l.jsx("button",{className:"btn btn-primary",onClick:V,disabled:j,children:u?"Save changes":"Create record"})]})]}):l.jsx(ci,{value:u,max:2e4}),u&&i.owner!=="application"&&l.jsxs("p",{className:"muted small",children:[i.owner," owns this collection. Change it through its service or capability, so its authorization and audit trail apply."," ",l.jsx("a",{href:"#/services",onClick:()=>yt("services"),children:"Services →"})]})]})}const ix=(i,u)=>i==="*"||i===u||i.endsWith(".*")&&u.startsWith(i.slice(0,-1));function sx(i,u){return Object.entries(i??{}).filter(([,d])=>d.some(r=>ix(r,u))).map(([d])=>d)}function Om(i){if(!i||i.type!=="object")return{};const u={};for(const d of i.required??[]){const r=i.properties?.[d]??{};u[d]=r.type==="boolean"?!0:r.type==="number"||r.type==="integer"?0:""}return u}function cx({selected:i}){const{version:u,overview:d}=Bt(),r=Le(()=>ne("/capabilities"),[u]),[h,v]=k.useState(i?.includes(":")?"functions":"capabilities"),x=r.data?.capabilities??[],b=d?.functions??[],f=h==="capabilities"?x.find(y=>y.name===i)??x[0]:b.find(y=>y.name===i)??b[0];return l.jsxs(l.Fragment,{children:[l.jsx(Ht,{title:"Capabilities",subtitle:"What this application can do. Capabilities are published through AppPort — discoverable by other applications and agents (MCP) — and every invocation passes the same authorization as any other caller."}),l.jsxs("div",{className:"tabs",role:"tablist",children:[l.jsxs("button",{role:"tab","aria-selected":h==="capabilities",className:h==="capabilities"?"active":"",onClick:()=>v("capabilities"),children:["AppPort capabilities ",l.jsx("span",{className:"muted",children:x.length})]}),l.jsxs("button",{role:"tab","aria-selected":h==="functions",className:h==="functions"?"active":"",onClick:()=>v("functions"),children:["All functions ",l.jsx("span",{className:"muted",children:b.length})]})]}),r.error&&!r.data?l.jsx(ve,{error:r.error,retry:r.reload}):r.data?l.jsxs("div",{className:"split",children:[l.jsxs("aside",{className:"split-nav",children:[(h==="capabilities"?x:b).map(y=>l.jsxs("a",{href:`#/capabilities/${y.name}`,className:`split-item ${f?.name===y.name?"active":""}`,children:[l.jsx("span",{className:"mono ellipsis",children:y.name}),h==="functions"?l.jsx(I,{tone:y.kind==="query"?"info":"accent",children:y.kind}):l.jsxs("span",{className:"muted small",children:["v",y.version]})]},y.name)),h==="capabilities"&&x.length===0&&l.jsx("p",{className:"muted small pad",children:"None published yet."})]}),l.jsx("section",{className:"split-main",children:f?h==="capabilities"?l.jsx(ux,{capability:f,roles:d?.roles??{},mcpTools:r.data.mcp?.tools??[],devUsers:d?.devUsers??[],development:d?.environment?.development},f.name):l.jsx(rx,{fn:f,roles:d?.roles??{},devUsers:d?.devUsers??[],development:d?.environment?.development},f.name):l.jsx(qt,{title:h==="capabilities"?"No capabilities":"No functions",children:h==="capabilities"?'Publish a query or mutation with capability: { name: "tasks.complete", description: "…" } and a returns schema.':"Export app.query() or app.mutation() from a module in feltkit/."})})]}):l.jsx(Ze,{})]})}function zm({required:i,roles:u}){return i.length?l.jsx("span",{children:i.map(d=>l.jsxs("span",{children:[l.jsx("code",{children:d})," ",l.jsxs("span",{className:"muted",children:["— granted to ",sx(u,d).join(", ")||"no role"]})]},d))}):l.jsx("span",{children:"any signed-in principal"})}function ux({capability:i,roles:u,mcpTools:d,devUsers:r,development:h}){const v=d.find(x=>x.replace(/_/g,".").includes(i.name))??null;return l.jsxs("div",{className:"stack-lg",children:[l.jsxs("div",{children:[l.jsxs("div",{className:"row",children:[l.jsx("h2",{className:"mono",children:i.name}),l.jsxs(I,{children:["v",i.version]}),l.jsx(I,{tone:i.effect==="consequential"?"accent":"info",children:i.effect})]}),l.jsx("p",{children:i.description??l.jsx("span",{className:"muted",children:"No description. Add one so agents and other applications know what this does."})})]}),l.jsxs(te,{title:"Contract",children:[l.jsxs("dl",{className:"kv",children:[l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Requires"}),l.jsx("dd",{children:l.jsx(zm,{required:i.authorization,roles:u})})]}),l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Implemented by"}),l.jsx("dd",{children:i.function?l.jsx("a",{href:`#/capabilities/${i.function.name}`,className:"mono",children:i.function.name}):"—"})]}),l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Services used"}),l.jsx("dd",{children:i.services?.length?i.services.map(x=>l.jsx(I,{children:x},x)):l.jsx("span",{className:"muted",children:"none observed"})})]}),l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Idempotency"}),l.jsx("dd",{children:i.idempotency??"—"})]}),l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Reachable at"}),l.jsxs("dd",{className:"small",children:[l.jsx("code",{children:"POST /appport"}),v&&l.jsxs(l.Fragment,{children:[" ","· MCP tool ",l.jsx("code",{children:v})]})]})]})]}),l.jsxs("div",{className:"grid grid-2",children:[l.jsxs("div",{children:[l.jsx("div",{className:"label",children:"Input"}),l.jsx(si,{schema:i.input})]}),l.jsxs("div",{children:[l.jsx("div",{className:"label",children:"Output"}),l.jsx(si,{schema:i.output})]})]})]}),l.jsx(te,{title:"Recent invocations",children:i.recent?.length?l.jsx("ul",{className:"feed",children:i.recent.map(x=>l.jsx("li",{children:l.jsxs("a",{href:`#/activity/${x.id}`,className:"feed-row",children:[l.jsx(cn,{outcome:x.outcome}),l.jsx("span",{className:"small",children:x.principal??"anonymous"}),l.jsxs("span",{className:"muted small",children:["via ",x.via]}),x.error&&l.jsx("span",{className:"error-text small",children:x.error.code}),l.jsxs("span",{className:"muted small right",children:[x.durationMs,"ms · ",tt(x.at)]})]})},x.id))}):l.jsx("p",{className:"muted",children:"Not invoked through AppPort yet."})}),h&&l.jsx(Dm,{title:"Invoke through AppPort",note:"Runs through AppPort’s dispatch pipeline with a short-lived session for the identity you choose. The same authorization applies as for any agent or application.",example:Om(i.input),devUsers:r,run:(x,b)=>ne("/capabilities/invoke",{method:"POST",body:JSON.stringify({capability:i.name,version:i.version,input:x,as:b})})})]})}function rx({fn:i,roles:u,devUsers:d,development:r}){const h=i.access==="public"||i.access==="authenticated"?[]:[i.access];return l.jsxs("div",{className:"stack-lg",children:[l.jsxs("div",{children:[l.jsxs("div",{className:"row",children:[l.jsx("h2",{className:"mono",children:i.name}),l.jsx(I,{tone:i.kind==="query"?"info":"accent",children:i.kind}),i.capability&&l.jsxs(I,{tone:"ok",children:["→ ",i.capability.name]})]}),l.jsx("p",{className:"muted",children:i.description??(i.kind==="query"?"Read-only: its database handle cannot write.":"All writes commit in one FeltDB transaction, or none do.")})]}),l.jsxs(te,{title:"Contract",children:[l.jsxs("dl",{className:"kv",children:[l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Access"}),l.jsx("dd",{children:i.access==="public"?"anyone, including anonymous callers":l.jsx(zm,{required:h,roles:u})})]}),l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Endpoint"}),l.jsx("dd",{children:l.jsxs("code",{children:["POST /api/",i.kind,"/",i.name]})})]})]}),l.jsxs("div",{className:"grid grid-2",children:[l.jsxs("div",{children:[l.jsx("div",{className:"label",children:"Arguments"}),l.jsx(si,{schema:i.args})]}),l.jsxs("div",{children:[l.jsx("div",{className:"label",children:"Returns"}),i.returns?l.jsx(si,{schema:i.returns}):l.jsx("span",{className:"muted",children:"not declared"})]})]})]}),r&&l.jsx(Dm,{title:`Run ${i.kind}`,note:"Runs as the identity you choose, through the same validation and authorization as a request from the app.",example:Om(i.args),devUsers:d,run:(v,x)=>ne("/functions/run",{method:"POST",body:JSON.stringify({name:i.name,args:v,as:x})})})]})}function Dm({title:i,note:u,example:d,devUsers:r,run:h}){const[v,x]=k.useState(JSON.stringify(d,null,2)),[b,f]=k.useState(r[0]?.id??"anonymous"),[y,j]=k.useState(null),[g,R]=k.useState(null),[q,V]=k.useState(!1),E=k.useMemo(()=>y&&y.ok===!0,[y]);return l.jsxs(te,{title:i,children:[l.jsx("p",{className:"muted small",children:u}),l.jsx("div",{className:"row",children:l.jsxs("label",{className:"field-inline",children:[l.jsx("span",{children:"Act as"}),l.jsxs("select",{className:"input",value:b,onChange:A=>f(A.target.value),children:[r.map(A=>l.jsxs("option",{value:A.id,children:[A.name??A.id," · ",A.roles.join(", ")]},A.id)),l.jsx("option",{value:"anonymous",children:"anonymous"})]})]})}),l.jsx("textarea",{className:"code-input",rows:6,value:v,onChange:A=>x(A.target.value),spellCheck:!1,"aria-label":"Input JSON"}),l.jsxs("div",{className:"row between",children:[l.jsx("span",{className:"muted small",children:"Input is validated against the contract before authorization runs."}),l.jsx("button",{className:"btn btn-primary",disabled:q,onClick:async()=>{R(null),j(null);let A;try{A=JSON.parse(v||"{}")}catch{R({code:"INVALID_JSON",message:"That is not valid JSON."});return}V(!0);try{j(await h(A,b))}catch(X){R(X)}finally{V(!1)}},children:q?"Running…":"Run"})]}),g?l.jsx(ve,{error:g}):null,y&&l.jsxs("div",{className:`result ${E?"result-ok":"result-bad"}`,children:[l.jsxs("div",{className:"row",children:[l.jsx(cn,{outcome:E?"success":y.error?.code==="FORBIDDEN"||y.error?.code==="UNAUTHORIZED"?"denied":"error"}),y.requestId&&l.jsx("span",{className:"muted small mono",children:y.requestId})]}),l.jsx(ci,{value:E?y.output??y.value:y.error})]})]})}const ox=["","query","mutation","capability","integration","agent","service","auth","admin","system"],dx=["","success","error","denied"];function fx({selected:i}){jm(1e4);const{activity:u}=Bt(),[d,r]=k.useState(""),[h,v]=k.useState(""),[x,b]=k.useState(!1),f=Le(()=>ne(`/activity?limit=200${d?`&kind=${d}`:""}${h?`&outcome=${h}`:""}`),[d,h]),y=k.useMemo(()=>{const j=Cm(u.filter(g=>(!d||g.kind===d)&&(!h||g.outcome===h)),f.data?.entries??[]);return x?j.filter(g=>g.kind!=="query"):j},[u,f.data,d,h,x]);return l.jsxs(l.Fragment,{children:[l.jsx(Ht,{title:"Activity",subtitle:"What actually happened, from the runtime’s own records: who called what, through which interface, the authority decision, and the writes FeltDB committed."}),l.jsxs("div",{className:"filter",children:[l.jsx("select",{className:"input",value:d,onChange:j=>r(j.target.value),"aria-label":"Kind",children:ox.map(j=>l.jsx("option",{value:j,children:j||"All kinds"},j))}),l.jsx("select",{className:"input",value:h,onChange:j=>v(j.target.value),"aria-label":"Outcome",children:dx.map(j=>l.jsx("option",{value:j,children:j||"All outcomes"},j))}),l.jsxs("label",{className:"check",children:[l.jsx("input",{type:"checkbox",checked:x,onChange:j=>b(j.target.checked)})," Hide queries"]}),l.jsx("span",{className:"muted small right",children:"Live · newest first"})]}),f.error&&!f.data?l.jsx(ve,{error:f.error,retry:f.reload}):f.data?y.length===0?l.jsx(qt,{title:"No activity matches",children:"Use the app, invoke a capability, or run a function from Capabilities."}):l.jsx("div",{className:"table-wrap",children:l.jsxs("table",{className:"table activity",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:"When"}),l.jsx("th",{children:"Outcome"}),l.jsx("th",{children:"Kind"}),l.jsx("th",{children:"Name"}),l.jsx("th",{children:"Principal"}),l.jsx("th",{children:"Via"}),l.jsx("th",{children:"Writes"}),l.jsx("th",{className:"num",children:"ms"})]})}),l.jsx("tbody",{children:y.map(j=>l.jsxs("tr",{onClick:()=>yt(`activity/${j.id}`),tabIndex:0,onKeyDown:g=>g.key==="Enter"&&yt(`activity/${j.id}`),className:i===j.id?"selected":"",children:[l.jsx("td",{className:"muted small nowrap",title:j.at,children:tt(j.at)}),l.jsx("td",{children:l.jsx(cn,{outcome:j.outcome})}),l.jsx("td",{className:"small",children:j.kind}),l.jsxs("td",{className:"mono",children:[j.name,j.error&&l.jsxs("span",{className:"error-text small",children:[" ",j.error.code]})]}),l.jsx("td",{className:"small",children:j.principal?`${j.principal.id}`:l.jsx("span",{className:"muted",children:j.kind==="system"?"—":"anonymous"})}),l.jsx("td",{className:"small",children:j.via}),l.jsx("td",{className:"small",children:j.writes?.length?j.writes.length:l.jsx("span",{className:"muted",children:"—"})}),l.jsx("td",{className:"num small muted",children:j.durationMs})]},j.id))})]})}):l.jsx(Ze,{}),i&&l.jsx(hx,{id:i,onClose:()=>yt("activity")})]})}function hx({id:i,onClose:u}){const d=Le(()=>ne(`/activity/${encodeURIComponent(i)}`),[i]),r=d.data?.entry,h=d.data?.serviceEvidence??[];return l.jsx(pm,{title:r?r.name:"Activity",onClose:u,children:d.error?l.jsx(ve,{error:d.error}):r?l.jsxs("div",{className:"stack-lg",children:[l.jsx(xr,{rows:[["Outcome",l.jsx(cn,{outcome:r.outcome},"o")],["When",`${new Date(r.at).toLocaleString()} (${tt(r.at)})`],["Kind",r.kind],["Via",r.via],["Principal",r.principal?`${r.principal.id} (${r.principal.type}; roles: ${r.principal.roles.join(", ")||"none"})`:"anonymous"],...r.capability?[["AppPort capability",`${r.capability.name}@${r.capability.version}`]]:[],["Request",l.jsx("code",{children:r.requestId},"r")],["Duration",`${r.durationMs} ms`],...r.argKeys?[["Arguments",r.argKeys.length?r.argKeys.join(", "):"none"]]:[]]}),r.error&&l.jsxs("section",{children:[l.jsx("h3",{children:"Error"}),l.jsxs("div",{className:"error-box",children:[l.jsx("strong",{children:r.error.code})," ",r.error.message]})]}),r.authority&&l.jsxs("section",{children:[l.jsx("h3",{children:"Authority"}),l.jsx(xr,{rows:[["Decision",r.authority.allowed?l.jsx(I,{tone:"ok",children:"allowed"},"a"):l.jsx(I,{tone:"warn",children:"denied"},"d")],["Required",r.authority.required?l.jsx("code",{children:r.authority.required},"q"):"an authenticated principal"],...r.authority.reason?[["Reason",r.authority.reason]]:[],["Decision id",l.jsx("code",{children:r.authority.decisionId},"i")],...r.authority.appportDecisionId?[["AppPort decision",l.jsx("code",{children:r.authority.appportDecisionId},"ap")]]:[],["Policy version",l.jsx("code",{children:r.authority.policyVersion},"p")]]})]}),l.jsxs("section",{children:[l.jsx("h3",{children:"State changes"}),r.writes?.length?l.jsxs(l.Fragment,{children:[l.jsxs("p",{className:"muted small",children:["Committed by FeltDB in one transaction ",l.jsx("code",{children:r.transactionId}),r.commitRevision!==void 0?` at revision ${r.commitRevision}`:"","."]}),l.jsxs("table",{className:"table compact",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:"Op"}),l.jsx("th",{children:"Collection"}),l.jsx("th",{children:"Record"}),l.jsx("th",{children:"Expected version"})]})}),l.jsx("tbody",{children:r.writes.map((v,x)=>l.jsxs("tr",{children:[l.jsx("td",{children:l.jsx(I,{tone:v.op==="delete"?"bad":v.op==="insert"?"ok":"accent",children:v.op})}),l.jsx("td",{className:"mono",children:v.collection}),l.jsx("td",{className:"mono small",children:v.op==="delete"?v.id:l.jsx("a",{href:`#/data/${v.collection}`,children:v.id})}),l.jsx("td",{className:"small",children:v.expectedVersion??"— (create)"})]},x))})]})]}):l.jsx("p",{className:"muted",children:r.kind==="query"?"Queries cannot write.":r.outcome!=="success"?"Nothing was written through ctx.db: a failed mutation commits nothing.":r.services?.length?"No application records changed through ctx.db. Service effects commit separately; see the evidence below.":"No application records changed."}),r.reads?.length?l.jsxs("p",{className:"muted small",children:["Read: ",r.reads.join(", ")]}):null]}),(h.length>0||r.services?.length)&&l.jsxs("section",{children:[l.jsx("h3",{children:"Service evidence"}),l.jsxs("p",{className:"muted small",children:["Recorded by AppPort Services’ gateway in the same FeltDB instance.",d.data?.serviceEvidenceState==="started"?" An effect has no recorded completion: its outcome is unknown, not failed.":"",d.data?.serviceEvidenceTruncated?" More records exist than are shown.":""]}),h.map(v=>l.jsxs("div",{className:"evidence",children:[l.jsxs("div",{className:"row",children:[l.jsx(I,{tone:v.outcome==="succeeded"?"ok":v.outcome==="denied"?"warn":v.outcome==="started"?"neutral":"bad",children:v.outcome}),l.jsx("span",{className:"mono",children:v.capability}),l.jsx("span",{className:"muted small",children:v.service})]}),l.jsxs("div",{className:"muted small",children:["decision ",v.decision,v.decisionId?` · ${v.decisionId}`:""," · ",v.resource]})]},v.id))]}),r.detail&&l.jsxs("section",{children:[l.jsx("h3",{children:"Detail"}),l.jsx(ci,{value:r.detail})]})]}):l.jsx(Ze,{})})}function wm(){const[i,u]=k.useState(null),[d,r]=k.useState(!1);return{open:async()=>{u(null),r(!0);const v=window.open("about:blank","_blank");try{const x=await ne("/production/studio-link",{method:"POST",body:"{}"});if(!x.url)throw new Error("No deployment is recorded for this project. Run `npx feltkit vercel deploy` first.");v?(v.opener=null,v.location.href=x.url):window.location.assign(x.url)}catch(x){v?.close(),u(x)}finally{r(!1)}},error:i,busy:d}}function mx({production:i}){const u=wm(),d=i?.deployment??null;return i?l.jsxs(te,{title:"Production",action:d?l.jsx(I,{tone:"ok",children:"live"}):i.target?l.jsx(I,{children:"not deployed"}):l.jsx(I,{children:"not set up"}),children:[d?l.jsxs(l.Fragment,{children:[l.jsxs("p",{children:[l.jsx("a",{href:d.url,target:"_blank",rel:"noreferrer",children:d.url})," ",l.jsxs("span",{className:"muted small",children:["· ",i.target??d.target," · deployed ",tt(d.deployedAt)]})]}),l.jsxs("p",{className:"muted small",children:["Data: ",i.storage==="remote"?l.jsx("code",{children:i.location}):i.location]}),l.jsxs("div",{className:"row",children:[l.jsx("a",{className:"btn btn-small",href:d.url,target:"_blank",rel:"noreferrer",children:"Open app ↗"}),d.studio?l.jsx("button",{className:"btn btn-small btn-primary",onClick:()=>{u.open()},disabled:u.busy,children:u.busy?"Signing you in…":"Manage in production Studio ↗"}):l.jsxs("span",{className:"muted small",children:["Production Studio is off. Turn it on with ",l.jsx("code",{children:"npx feltkit vercel deploy --studio"}),"."]})]}),u.error!=null&&l.jsx(ve,{error:u.error}),l.jsxs("p",{className:"muted small",children:["Sign someone in to the app: ",l.jsx("code",{children:"npx feltkit session create --env production --type user --id <id> --role <role>"})," in this project's folder. It uses the deployment's FeltDB settings from ",l.jsx("code",{children:".env.local"}),"."]})]}):i.target?l.jsxs("p",{className:"muted",children:["Built for ",i.target,", not deployed from here yet. Run ",l.jsx("code",{children:"npx feltkit vercel deploy"}),": it uploads the settings, deploys, and signs you in."]}):l.jsxs("p",{className:"muted",children:["Not deployed. ",l.jsx("code",{children:"npx feltkit deploy"})," builds it for where it will run (one container, Vercel, or a FeltDB server), and says what to do next."]}),i.storage==="unconfigured"&&l.jsx("p",{className:"error-text small",children:i.location})]}):null}function vx(){const{version:i,overview:u}=Bt(),d=Le(()=>ne("/environments"),[]),r=Le(()=>ne("/sessions"),[i]),h=u?.environment?.development;return l.jsxs(l.Fragment,{children:[l.jsx(Ht,{title:"Settings",subtitle:"Environments, access policy, and sessions. Configuration lives in feltkit/app.ts; this page shows what the runtime is actually using."}),h&&d.data&&l.jsx(mx,{production:d.data.environments.find(v=>v.name==="production"&&!v.active)}),l.jsxs(te,{title:"Environments",children:[l.jsx("p",{className:"muted small",children:"Each environment has its own FeltDB instance. They never share state; FeltKit refuses to open two environments on the same location."}),d.error?l.jsx(ve,{error:d.error}):d.data?l.jsxs("table",{className:"table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:"Environment"}),l.jsx("th",{children:"Storage"}),l.jsx("th",{children:"Location"}),l.jsx("th",{children:"Instance"})]})}),l.jsx("tbody",{children:d.data.environments.map(v=>l.jsxs("tr",{className:v.active?"selected":"",children:[l.jsxs("td",{children:[l.jsx("strong",{children:v.name})," ",v.active&&l.jsx(I,{tone:"ok",children:"active"})]}),l.jsx("td",{children:v.storage}),l.jsxs("td",{className:"mono small",children:[v.target&&l.jsx("div",{className:"muted",children:v.target}),v.location,v.deployment&&l.jsx("div",{children:l.jsx("a",{href:v.deployment.url,target:"_blank",rel:"noreferrer",children:v.deployment.url})})]}),l.jsx("td",{className:"mono small muted",children:v.instanceId??"not open here"})]},v.name))})]}):l.jsx(Ze,{}),l.jsxs("p",{className:"muted small",children:["Production is what your deployment uses. Built with ",l.jsx("code",{children:"npx feltkit deploy"})," for Vercel or a FeltDB server, that is its FeltDB, reached with the settings in"," ",l.jsx("code",{children:".env.local"}),"; otherwise ",l.jsx("code",{children:"FELTDB_URL"})," + ",l.jsx("code",{children:"FELTDB_TOKEN"})," when set, else ",l.jsx("code",{children:"FELTKIT_STATE_DIR"})," or ",l.jsx("code",{children:".feltkit/production/state"}),"."]})]}),l.jsxs("div",{className:"grid grid-2",children:[l.jsxs(te,{title:"Access policy",action:l.jsxs("code",{className:"muted small",children:["policy ",u?.policyVersion]}),children:[l.jsxs("table",{className:"table compact",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:"Role"}),l.jsx("th",{children:"Permissions"})]})}),l.jsx("tbody",{children:Object.entries(u?.roles??{}).map(([v,x])=>l.jsxs("tr",{children:[l.jsx("td",{children:l.jsx("strong",{children:v})}),l.jsx("td",{children:x.map(b=>l.jsx("code",{className:"chip",children:b},b))})]},v))})]}),l.jsx("p",{className:"muted small",children:"Enforced through AppPort’s authorizer on functions, capabilities, and services alike. Edit roles in feltkit/app.ts."})]}),l.jsx(te,{title:"Development identities",children:h?(u?.devUsers??[]).length?l.jsx("ul",{className:"list",children:u.devUsers.map(v=>l.jsxs("li",{className:"list-row",children:[l.jsxs("span",{children:[l.jsx("strong",{children:v.name??v.id})," ",l.jsx("span",{className:"muted mono small",children:v.id})]}),l.jsx("span",{children:v.roles.map(x=>l.jsx(I,{children:x},x))})]},v.id))}):l.jsxs("p",{className:"muted",children:["None declared. Add dev: ","{ users: [...] }"," to feltkit(","{ … }",")."]}):l.jsx("p",{className:"muted",children:"Development sign-in is disabled in this environment."})})]}),l.jsxs(te,{title:"Sessions",action:l.jsx("span",{className:"muted small",children:"tokens are stored only as SHA-256 digests"}),children:[h&&l.jsx(yx,{roles:Object.keys(u?.roles??{}),onIssued:r.reload}),r.error?l.jsx(ve,{error:r.error}):r.data?r.data.sessions.length===0?l.jsx("p",{className:"muted",children:"No active sessions."}):l.jsxs("table",{className:"table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:"Ref"}),l.jsx("th",{children:"Principal"}),l.jsx("th",{children:"Roles"}),l.jsx("th",{children:"Kind"}),l.jsx("th",{children:"Created"}),l.jsx("th",{children:"Expires"}),l.jsx("th",{})]})}),l.jsx("tbody",{children:r.data.sessions.map(v=>l.jsxs("tr",{children:[l.jsx("td",{className:"mono small muted",children:v.ref}),l.jsxs("td",{children:[v.principal?.id," ",l.jsx("span",{className:"muted small",children:v.principal?.type})]}),l.jsx("td",{className:"small",children:v.principal?.roles?.join(", ")}),l.jsx("td",{className:"small",children:v.kind}),l.jsx("td",{className:"small muted",children:tt(v.createdAt)}),l.jsx("td",{className:"small muted",children:v.expiresAt?new Date(v.expiresAt).toLocaleString():"never"}),l.jsx("td",{children:l.jsx("button",{className:"btn btn-small btn-ghost danger",onClick:()=>ne(`/sessions/${v.ref}`,{method:"DELETE"}).then(r.reload,r.reload),children:"Revoke"})})]},v.ref))})]}):l.jsx(Ze,{})]})]})}function yx({roles:i,onIssued:u}){const[d,r]=k.useState("triage-agent"),[h,v]=k.useState(i.includes("agent")?"agent":i[0]??""),[x,b]=k.useState("agent"),[f,y]=k.useState(null),[j,g]=k.useState(null);return l.jsxs("div",{className:"issue",children:[l.jsxs("form",{className:"row wrap",onSubmit:async R=>{R.preventDefault(),g(null);try{const q=await ne("/sessions",{method:"POST",body:JSON.stringify({principal:{id:d,type:x,roles:[h]},label:"issued from the dashboard",ttlMs:864e5})});y(q.token),u()}catch(q){g(q)}},children:[l.jsx("input",{className:"input",value:d,onChange:R=>r(R.target.value),"aria-label":"Principal id",placeholder:"principal id"}),l.jsxs("select",{className:"input",value:x,onChange:R=>b(R.target.value),"aria-label":"Principal type",children:[l.jsx("option",{value:"agent",children:"agent"}),l.jsx("option",{value:"service",children:"service"}),l.jsx("option",{value:"user",children:"user"})]}),l.jsx("select",{className:"input",value:h,onChange:R=>v(R.target.value),"aria-label":"Role",children:i.map(R=>l.jsx("option",{value:R,children:R},R))}),l.jsx("button",{className:"btn btn-primary",type:"submit",disabled:!d||!h,children:"Issue 24-hour session"})]}),j?l.jsx(ve,{error:j}):null,f&&l.jsxs("div",{className:"callout",children:[l.jsxs("div",{className:"row between",children:[l.jsx("strong",{children:"Shown once."})," ",l.jsx(rn,{text:f})]}),l.jsx("code",{className:"token",children:f}),l.jsxs("div",{className:"muted small",children:["Agents: connect an MCP client to ",l.jsxs("code",{children:[location.origin,"/mcp"]})," with ",l.jsx("code",{children:"Authorization: Bearer <token>"}),". It sees only what this role allows."]})]})]})}function gx(){const i=Le(()=>ne("/projects"),[]),u=i.data?.projects??[],d=wm();return l.jsxs(l.Fragment,{children:[l.jsx(Ht,{title:"Projects",subtitle:"FeltKit applications this machine has run. Each has its own environments and FeltDB instances."}),i.error?l.jsx(ve,{error:i.error,retry:i.reload}):i.data?u.length===0?l.jsx(te,{children:l.jsxs(qt,{title:"Only this project so far",children:["Create another with ",l.jsx("code",{children:"npm create feltkit@latest my-app"}),"."]})}):l.jsx("div",{className:"grid grid-2",children:u.map(r=>l.jsxs(te,{className:r.path===i.data.current?"card-current":"",children:[l.jsxs("div",{className:"row between",children:[l.jsx("h2",{children:r.name}),r.path===i.data.current?l.jsx(I,{tone:"ok",children:"this dashboard"}):r.running?l.jsx(I,{tone:"ok",children:"running"}):r.exists?l.jsx(I,{children:"stopped"}):l.jsx(I,{tone:"bad",children:"missing"})]}),l.jsx("code",{className:"path",children:r.path}),l.jsxs("div",{className:"muted small",children:["last run ",tt(r.lastRunAt)," · ",r.lastEnvironment]}),r.deployment&&l.jsxs("div",{className:"small",children:["Live:"," ",l.jsx("a",{href:r.deployment.url,target:"_blank",rel:"noreferrer",children:r.deployment.url})," ",l.jsxs("span",{className:"muted",children:["(",r.deployment.target,", deployed ",tt(r.deployment.deployedAt),")"]})]}),l.jsxs("div",{className:"row",children:[r.running&&r.url&&r.path!==i.data.current&&l.jsx("a",{className:"btn btn-small",href:r.url,target:"_blank",rel:"noreferrer",children:"Open app ↗"}),r.deployment&&l.jsx("a",{className:"btn btn-small",href:r.deployment.url,target:"_blank",rel:"noreferrer",children:"Open live app ↗"}),r.deployment?.studio&&r.path===i.data.current&&l.jsx("button",{className:"btn btn-small btn-primary",onClick:()=>{d.open()},disabled:d.busy,children:d.busy?"Signing you in…":"Manage production ↗"}),r.deployment?.studio&&r.path!==i.data.current&&l.jsxs("span",{className:"muted small",children:["Manage it: ",l.jsx("code",{children:"npx feltkit manage"})," in its directory."]}),!r.running&&r.exists&&!r.deployment&&l.jsxs("span",{className:"muted small",children:["Start it with ",l.jsx("code",{children:"npm run dev"})," in its directory."]})]})]},r.path))}):l.jsx(Ze,{}),d.error!=null&&l.jsx(ve,{error:d.error}),l.jsx(te,{title:"Start a new application",children:l.jsx("pre",{className:"json",children:`npm create feltkit@latest my-app
12
+ … (${d.length-u} more characters)`),l.jsx("pre",{className:"json",children:d})}function rn({text:i,label:u="Copy"}){const[d,r]=k.useState(!1);return l.jsx("button",{className:"btn btn-small btn-ghost",onClick:()=>{navigator.clipboard?.writeText(i).then(()=>{r(!0),setTimeout(()=>r(!1),1200)})},children:d?"Copied":u})}function xr({rows:i}){return l.jsx("dl",{className:"kv",children:i.map(([u,d],r)=>l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:u}),l.jsx("dd",{children:d})]},r))})}function si({schema:i}){if(!i)return l.jsx("span",{className:"muted",children:"—"});if(i.type!=="object"||!i.properties)return l.jsx("code",{className:"type",children:Os(i)});const u=new Set(i.required??[]),d=Object.entries(i.properties);return d.length?l.jsx("table",{className:"fields",children:l.jsx("tbody",{children:d.map(([r,h])=>l.jsxs("tr",{children:[l.jsxs("td",{className:"mono",children:[r,!u.has(r)&&l.jsx("span",{className:"muted",children:"?"})]}),l.jsxs("td",{children:[l.jsx("code",{className:"type",children:Os(h)}),Fh(h)&&l.jsxs("span",{className:"muted small",children:[" ",Fh(h)]})]})]},r))})}):l.jsx("span",{className:"muted",children:"no fields"})}function Os(i){return i?i.enum?i.enum.map(u=>JSON.stringify(u)).join(" | "):i.anyOf?i.anyOf.map(Os).join(" | "):i.type==="array"?`${Os(i.items)}[]`:i.type==="object"?i.properties?`{ ${Object.keys(i.properties).join(", ")} }`:"object":Array.isArray(i.type)?i.type.join(" | "):i.type??"unknown":"unknown"}function Fh(i){const u=[];return i.minLength!==void 0&&u.push(`min ${i.minLength}`),i.maxLength!==void 0&&u.push(`max ${i.maxLength}`),i.minimum!==void 0&&u.push(`≥ ${i.minimum}`),i.maximum!==void 0&&u.push(`≤ ${i.maximum}`),u.join(", ")}function pm({title:i,onClose:u,children:d}){return k.useEffect(()=>{const r=h=>h.key==="Escape"&&u();return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[u]),l.jsx("div",{className:"drawer-backdrop",onClick:u,children:l.jsxs("aside",{className:"drawer",role:"dialog","aria-modal":"true","aria-label":typeof i=="string"?i:"Details",onClick:r=>r.stopPropagation(),children:[l.jsxs("header",{className:"drawer-header",children:[l.jsx("h2",{children:i}),l.jsx("button",{className:"btn btn-ghost",onClick:u,"aria-label":"Close",children:"Esc"})]}),l.jsx("div",{className:"drawer-body",children:d})]})})}function Le(i,u){const[d,r]=k.useState({loading:!0}),[h,v]=k.useState(0);return k.useEffect(()=>{let x=!0;return r(b=>({...b,loading:!0})),i().then(b=>x&&r({data:b,loading:!1}),b=>x&&r(f=>({data:f.data,error:b,loading:!1}))),()=>{x=!1}},[...u,h]),{...d,reload:()=>v(x=>x+1)}}const pb={system:l.jsxs(l.Fragment,{children:[l.jsx("rect",{x:"3",y:"4",width:"14",height:"10",rx:"1.5"}),l.jsx("path",{d:"M7.5 17h5M10 14v3"})]}),light:l.jsxs(l.Fragment,{children:[l.jsx("circle",{cx:"10",cy:"10",r:"3.2"}),l.jsx("path",{d:"M10 2.5v2M10 15.5v2M2.5 10h2M15.5 10h2M4.7 4.7l1.4 1.4M13.9 13.9l1.4 1.4M4.7 15.3l1.4-1.4M13.9 6.1l1.4-1.4"})]}),dark:l.jsx("path",{d:"M15.5 12.2A6 6 0 0 1 7.8 4.5a6 6 0 1 0 7.7 7.7Z"})},Wh={system:"System",light:"Light",dark:"Dark"};function Sb(){const[i,u]=jb();return l.jsx("div",{className:"theme-toggle",role:"radiogroup","aria-label":"Theme",children:bb.map(d=>l.jsxs("button",{type:"button",role:"radio","aria-checked":i===d,className:i===d?"on":"",onClick:()=>u(d),title:`${Wh[d]} theme`,children:[l.jsx("svg",{viewBox:"0 0 20 20",width:"15",height:"15",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:pb[d]}),l.jsx("span",{className:"sr-only",children:Wh[d]})]},d))})}const Nb="/_feltkit/assets/feltkit-mark-BygpVIiS.png";function ui(i){const u=i.trim();if(!u||u.startsWith("credential-ref:"))return!1;if(/^(sk-|sk-ant-|sk_live_|sk_test_|rk_live_|xai-|AIza|ghp_|gho_|github_pat_|gsk_|glpat-|xox[abpr]-|hf_|pk_live_)/.test(u))return!0;if(u.length<32||/\s/.test(u)||!/[0-9]/.test(u)||!/[A-Za-z]/.test(u))return!1;const d=new Map;for(const h of u)d.set(h,(d.get(h)??0)+1);let r=0;for(const h of d.values())r-=h/u.length*Math.log2(h/u.length);return r>=4}function Bs({credential:i}){return i?i.present?l.jsxs(I,{tone:"ok",title:i.updatedAt?`updated ${i.updatedAt}`:void 0,children:["set · ",i.location??i.variable,i.version&&i.source==="vault"?`, version ${i.version}`:""]}):l.jsx(I,{tone:"bad",children:i.state==="revoked"?"removed":"not set"}):null}function Cr(i){const u=i?.devUsers??[],[d,r]=k.useState("");return k.useEffect(()=>{!d&&u[0]&&r(u[0].id)},[u,d]),[d,r,u]}function Or({as:i,setAs:u,devUsers:d,label:r="Save as"}){return d.length?l.jsxs("label",{children:[r,l.jsx("select",{className:"input",value:i,onChange:h=>u(h.target.value),"aria-label":"Identity",children:d.map(h=>l.jsxs("option",{value:h.id,children:[h.name??h.id," (",h.roles.join(", "),")"]},h.id))})]}):null}function zs({credentialRef:i,provider:u,as:d,label:r="Set key",onSaved:h}){const[v,x]=k.useState(!1),[b,f]=k.useState(""),[y,j]=k.useState(!1),[g,R]=k.useState(null),[q,V]=k.useState(null),E=async()=>{j(!0),R(null);const A=b;f("");try{const X=await ne("/credentials",{method:"POST",body:JSON.stringify({ref:i,value:A,...u?{provider:u}:{},...d?{as:d}:{}})});V(X.stored),x(!1),h?.(X.stored)}catch(X){R(X)}finally{j(!1)}};return v?l.jsxs("span",{className:"row small",style:{flexWrap:"wrap"},children:[g?l.jsx(ve,{error:g}):null,l.jsx("input",{className:"input",type:"password",autoComplete:"off",spellCheck:!1,value:b,onChange:A=>f(A.target.value),placeholder:`Value for ${i}`,"aria-label":`Value for ${i}`}),l.jsx("button",{className:"btn btn-small btn-primary",onClick:E,disabled:y||!b.trim(),children:y?"Saving…":"Save"}),l.jsx("button",{className:"btn btn-small",onClick:()=>(f(""),x(!1)),children:"Cancel"}),l.jsx("span",{className:"muted",children:"Stored securely on the server; it is never shown again."})]}):l.jsxs("span",{className:"row small",children:[l.jsx("button",{className:"btn btn-small",onClick:()=>x(!0),children:r}),q&&l.jsxs("span",{className:"muted",children:["Stored (",q.location??"custody",", version ",q.version,")."]})]})}function _b(i){return(u,d="GET",r)=>ne(`/services/manage${u}`,{method:d,headers:{"x-feltkit-as":i},...r!==void 0?{body:JSON.stringify(r)}:d!=="GET"&&d!=="DELETE"?{body:"{}"}:{}})}function un(i,u){if(i==null)throw new Error(`${u} was not found or changed meanwhile. Nothing was done.`);return i}const Eb="A credential reference, like credential-ref:stripe. Set its value under Services → Credentials; the value is never stored here.",Tb={files:{title:"Files",description:"File records with ownership and audit. Bytes are stored in this environment's FeltDB instance.",render:i=>l.jsx(wb,{...i})},notifications:{title:"Notifications",description:"Durable in-app notifications. A principal reads only the notifications addressed to it.",render:i=>l.jsx(Mb,{...i})},configuration:{title:"Configuration",description:"Variables and secret references for this environment. Secret values stay in FeltKit's custody.",render:i=>l.jsx(Ub,{...i})},apiKeys:{title:"API keys",description:"Durable machine identities. A secret is shown once, when a key is created or rotated. FeltKit accepts a key as an identity holding services.apiKeys.roles.",render:i=>l.jsx(qb,{...i})},webhooks:{title:"Webhooks",description:"Endpoints for signed outbound delivery, with retries and history.",render:i=>l.jsx(Bb,{...i})},jobs:{title:"Jobs",description:"Durable background work. Each job type runs the FeltKit function declared in services.jobs.handlers, as the principal that queued it.",render:i=>l.jsx(Lb,{...i})},schedules:{title:"Schedules",description:"Recurring jobs. Each run queues a job of the schedule's type.",render:i=>l.jsx(Vb,{...i})},intelligence:{title:"Intelligence",description:"The provider, model, endpoint and credential reference for this environment. Configuration only: AppPort Services never runs a model.",render:i=>l.jsx(Qb,{...i})}};function Ab({id:i,service:u,as:d,picker:r,development:h,summary:v,operations:x}){const{version:b}=Bt(),f=Tb[i],y=l.jsx(Ht,{title:f?.title??i,subtitle:l.jsxs(l.Fragment,{children:[l.jsx("a",{href:"#/services",className:"link",children:"Services"})," ","· ",f?.description]}),actions:r});return f?u?u.state==="available"||u.state==="unavailable"?l.jsxs(l.Fragment,{children:[y,l.jsx(kb,{service:u})]}):l.jsxs(l.Fragment,{children:[y,v,h?d?l.jsxs(l.Fragment,{children:[l.jsxs("p",{className:"muted small",children:["Acting as ",l.jsx("strong",{children:d}),". Every operation is authorized by AppPort Services' gateway with this identity's roles, and recorded in Activity."]}),f.render({as:d,manage:_b(d),version:b})]}):l.jsx(te,{children:l.jsxs("p",{className:"muted small",children:["Declare a development identity in ",l.jsxs("code",{children:["feltkit(","{"," dev: ","{"," users ","}"," ","}",")"]}),": service operations are authorized as that identity."]})}):l.jsxs(l.Fragment,{children:[x,l.jsx(te,{children:l.jsxs("p",{className:"muted small",children:["Configuring ",f.title," is a development tool: change it in development, or with the service's own API from your application."]})})]})]}):l.jsxs(l.Fragment,{children:[y,l.jsx(Ze,{})]}):l.jsxs(l.Fragment,{children:[y,l.jsx(qt,{title:"No such service"})]})}function kb({service:i}){const u=Cb[i.id]??`${i.id}: true`;return l.jsx(te,{title:`Enable ${i.name}`,children:i.state==="unavailable"?l.jsx("p",{className:"error-text",children:i.detail}):l.jsxs(l.Fragment,{children:[l.jsxs("p",{className:"small",children:["Add it to ",l.jsx("code",{children:"services"})," in ",l.jsx("code",{children:"feltkit/app.ts"}),". The backend reloads in place and keeps its state; this screen then manages it."]}),l.jsx("pre",{className:"json",children:`services: { …, ${u} },`}),l.jsxs("span",{className:"row",children:[l.jsx(rn,{text:u,label:"Copy"}),l.jsxs("span",{className:"muted small",children:["Its permissions (",i.capabilities.join(", "),") are granted through your roles."]})]})]})})}const Cb={apiKeys:'apiKeys: { roles: ["member"] }',jobs:'jobs: { handlers: { "report.build": "reports:build" } }'};function jl({title:i,fields:u,submitLabel:d,send:r,done:h}){const v=()=>Object.fromEntries(u.map(E=>[E.name,E.value??(E.options?Aa(E.options[0]):E.choices?.length&&!E.multi?Aa(E.choices[0]):"")])),[x,b]=k.useState(v),[f,y]=k.useState(!1),[j,g]=k.useState(null),[R,q]=k.useState(null),V=async E=>{E.preventDefault(),y(!0),g(null),q(null);try{const A=await r(x);q(h?h(A):"Done."),b(v())}catch(A){g(A)}finally{y(!1)}};return l.jsxs(te,{title:i,children:[l.jsxs("form",{onSubmit:V,children:[l.jsx("div",{className:"form-grid",children:u.map(E=>l.jsxs("label",{children:[l.jsxs("span",{children:[E.label,E.required?" *":""]}),E.choices&&E.multi?l.jsx(zb,{field:E,value:x[E.name]??"",onChange:A=>b({...x,[E.name]:A})}):E.choices?l.jsx(Ob,{field:E,value:x[E.name]??"",onChange:A=>b({...x,[E.name]:A})}):E.options?l.jsx("select",{className:"input",value:x[E.name],onChange:A=>b({...x,[E.name]:A.target.value}),children:E.options.map(A=>l.jsx("option",{value:Aa(A),children:typeof A=="string"?A:A.label},Aa(A)))}):E.multiline?l.jsx("textarea",{className:"input code-input",rows:3,value:x[E.name],placeholder:E.placeholder,required:E.required,onChange:A=>b({...x,[E.name]:A.target.value})}):l.jsx("input",{className:"input",type:E.type??"text",value:x[E.name],placeholder:E.placeholder,required:E.required,pattern:E.pattern,autoComplete:"off",spellCheck:!1,onChange:A=>b({...x,[E.name]:A.target.value})}),E.hint&&l.jsx("span",{className:"muted small",children:E.hint})]},E.name))}),l.jsx("button",{className:"btn btn-primary",type:"submit",disabled:f,children:f?"Working…":d})]}),j?l.jsx(ve,{error:j}):null,R?l.jsx("div",{className:"ok-box small",children:R}):null]})}const Aa=i=>typeof i=="string"?i:i.value,Sm=i=>typeof i=="string"?i:i.label,fr="\0other";function Ob({field:i,value:u,onChange:d}){const r=(i.choices??[]).some(b=>Aa(b)===u),[h,v]=k.useState(!r&&u!==""),x=h||!i.choices?.length&&!i.strict;return l.jsxs(l.Fragment,{children:[(i.choices?.length??0)>0&&l.jsxs("select",{className:"input",value:x?fr:u,required:i.required,onChange:b=>{const f=b.target.value===fr;v(f),d(f?"":b.target.value)},children:[i.choices.map(b=>l.jsx("option",{value:Aa(b),children:Sm(b)},Aa(b))),!i.strict&&l.jsx("option",{value:fr,children:"Other…"})]}),x&&l.jsx("input",{className:"input",value:u,placeholder:i.placeholder,required:i.required,pattern:i.pattern,autoComplete:"off",spellCheck:!1,autoFocus:h,onChange:b=>d(b.target.value)})]})}function zb({field:i,value:u,onChange:d}){const r=(i.choices??[]).map(Aa),h=Ds(u),v=h.filter(j=>r.includes(j)),x=h.filter(j=>!r.includes(j)),[b,f]=k.useState(x.join(", ")),y=(j,g)=>d([...j,...Ds(g)].join(", "));return l.jsxs("span",{className:"choices",children:[(i.choices??[]).map(j=>{const g=Aa(j);return l.jsxs("label",{className:"check",children:[l.jsx("input",{type:"checkbox",checked:v.includes(g),onChange:R=>y(R.target.checked?[...v,g]:v.filter(q=>q!==g),b)}),l.jsx("code",{children:Sm(j)})]},g)}),!i.strict&&l.jsx("input",{className:"input",value:b,placeholder:r.length?"Others, comma separated":i.placeholder,autoComplete:"off",spellCheck:!1,required:i.required&&v.length===0,onChange:j=>(f(j.target.value),y(v,j.target.value))})]})}function on(i,u=0){return Le(()=>ne("/services/catalog"),[i,u]).data}function el({title:i,read:u,deps:d,empty:r,columns:h,actions:v,after:x,tools:b}){const f=Le(u,d),y=f.data??[];return l.jsxs(te,{title:i,action:l.jsxs("span",{className:"row",children:[b?.(f.reload),l.jsx("button",{className:"btn btn-small btn-ghost",onClick:f.reload,children:"Refresh"})]}),children:[f.error?l.jsx(ve,{error:f.error,retry:f.reload}):f.data?y.length===0?l.jsx("p",{className:"muted small",children:r}):l.jsx("div",{className:"table-wrap",children:l.jsxs("table",{className:"table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[h.map(([j])=>l.jsx("th",{children:j},j)),v&&l.jsx("th",{})]})}),l.jsx("tbody",{children:y.map((j,g)=>l.jsxs("tr",{children:[h.map(([R,q])=>l.jsx("td",{children:q(j)},R)),v&&l.jsx("td",{className:"row",children:v(j,f.reload)})]},j.id??g))})]})}):l.jsx(Ze,{}),x]})}function gt({label:i,confirm:u,danger:d,action:r,done:h}){const[v,x]=k.useState(!1),[b,f]=k.useState(!1),[y,j]=k.useState(null),g=async()=>{f(!0),j(null);try{await r(),x(!1),h?.()}catch(R){j(R)}finally{f(!1)}};return l.jsxs("span",{className:"row small",children:[v?l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"muted",children:u}),l.jsx("button",{className:`btn btn-small ${d?"btn-danger":"btn-primary"}`,onClick:g,disabled:b,children:b?"Working…":`Yes, ${i.toLowerCase()}`}),l.jsx("button",{className:"btn btn-small",onClick:()=>x(!1),children:"Cancel"})]}):l.jsx("button",{className:`btn btn-small ${d?"btn-danger":""}`,onClick:()=>u?x(!0):void g(),disabled:b,children:i}),y?l.jsx(ve,{error:y}):null]})}const ea=i=>i?l.jsx("span",{className:"muted small",title:i,children:tt(i)}):l.jsx("span",{className:"muted",children:"—"}),Et=i=>i?l.jsx("code",{children:i}):l.jsx("span",{className:"muted",children:"—"});function Db(i,u){let d;try{d=JSON.parse(i||"{}")}catch{throw new Error(`The ${u} is not valid JSON.`)}if(!d||typeof d!="object"||Array.isArray(d))throw new Error(`The ${u} must be a JSON object, like {"invoice": 7}.`);return d}const Ds=i=>i.split(",").map(u=>u.trim()).filter(Boolean),Nm=({done:i})=>l.jsx(gt,{label:"Run due work now",action:()=>ne("/services/run",{method:"POST",body:"{}"}),done:i});function wb({as:i,manage:u,version:d}){const[r,h]=k.useState(0),[v,x]=k.useState(null),[b,f]=k.useState(!1),[y,j]=k.useState(null),[g,R]=k.useState(null),q=async E=>{if(E.preventDefault(),!!v){f(!0),j(null),R(null);try{const A=await Rb(v),{file:X}=await ne("/services/files",{method:"POST",body:JSON.stringify({as:i,name:v.name,contentType:v.type||void 0,contentBase64:A})});R(`Uploaded ${X.name} (${X.size.toLocaleString()} bytes).`),x(null),E.target.reset(),h(ee=>ee+1)}catch(A){j(A)}finally{f(!1)}}},V=async E=>{const{file:A,contentBase64:X}=await ne(`/services/files/${encodeURIComponent(E.id)}/content?as=${encodeURIComponent(i)}`),ee=Uint8Array.from(atob(X),be=>be.charCodeAt(0)),w=URL.createObjectURL(new Blob([ee],{type:A.contentType??"application/octet-stream"}));Object.assign(document.createElement("a"),{href:w,download:A.name}).click(),setTimeout(()=>URL.revokeObjectURL(w),1e3)};return l.jsxs(l.Fragment,{children:[l.jsxs(te,{title:"Upload a file",children:[l.jsxs("form",{onSubmit:q,className:"row",children:[l.jsx("input",{className:"input",type:"file",onChange:E=>x(E.target.files?.[0]??null),"aria-label":"File"}),l.jsx("button",{className:"btn btn-primary",type:"submit",disabled:!v||b,children:b?"Uploading…":"Upload"})]}),l.jsxs("p",{className:"muted small",children:["Stored in this environment's FeltDB instance as ",i,", through the same Files service your functions use (ctx.services.files)."]}),y?l.jsx(ve,{error:y}):null,g?l.jsx("div",{className:"ok-box small",children:g}):null]}),l.jsx(el,{title:"Files",read:()=>u("/_appport/files"),deps:[i,d,r],empty:"No files yet.",columns:[["Name",E=>l.jsx("strong",{children:E.name})],["Owner",E=>Et(E.owner)],["Type",E=>l.jsx("span",{className:"small",children:E.contentType??"—"})],["Size",E=>l.jsx("span",{className:"num",children:typeof E.size=="number"?E.size.toLocaleString():"—"})],["Updated",E=>ea(E.updatedAt??E.createdAt)]],actions:(E,A)=>l.jsxs(l.Fragment,{children:[l.jsx(gt,{label:"Download",action:()=>V(E)}),l.jsx(_m,{current:E.name,onSave:X=>u(`/_appport/files/${encodeURIComponent(E.id)}`,"PATCH",{name:X}),done:A}),l.jsx(gt,{label:"Delete",danger:!0,confirm:`Delete ${E.name} and its bytes?`,action:()=>ne(`/services/files/${encodeURIComponent(E.id)}?as=${encodeURIComponent(i)}`,{method:"DELETE"}),done:A})]})})]})}function Rb(i){return new Promise((u,d)=>{const r=new FileReader;r.onload=()=>u(String(r.result).replace(/^data:[^,]*,/,"")),r.onerror=()=>d(r.error),r.readAsDataURL(i)})}function _m({current:i,onSave:u,done:d}){const[r,h]=k.useState(!1),[v,x]=k.useState(i),[b,f]=k.useState(null);if(!r)return l.jsx("button",{className:"btn btn-small",onClick:()=>(x(i),h(!0)),children:"Rename"});const y=async()=>{f(null);try{un(await u(v.trim()),"The record"),h(!1),d()}catch(j){f(j)}};return l.jsxs("span",{className:"row small",children:[l.jsx("input",{className:"input",value:v,onChange:j=>x(j.target.value),"aria-label":"New name"}),l.jsx("button",{className:"btn btn-small btn-primary",onClick:y,disabled:!v.trim(),children:"Save"}),l.jsx("button",{className:"btn btn-small",onClick:()=>h(!1),children:"Cancel"}),b?l.jsx(ve,{error:b}):null]})}function Mb({as:i,manage:u,version:d}){const[r,h]=k.useState(0),v=()=>h(f=>f+1),x=on(d,r),b=Bt().overview?.devUsers??[];return l.jsxs(l.Fragment,{children:[l.jsx(jl,{title:"Send a notification",submitLabel:"Send",fields:[{name:"recipient",label:"Recipient",required:!0,value:i,choices:b.map(f=>({value:f.id,label:`${f.name??f.id} (${f.id})`})),hint:"A principal id. Only the recipient can read it."},{name:"type",label:"Type",required:!0,placeholder:"task.assigned",choices:x?.notificationTypes.all??[],hint:x?.notificationTypes.declared.length?"Declared in services.notifications.types, plus types already sent.":"Declare your types in services: { notifications: { types: [...] } } to list them here."},{name:"title",label:"Title",required:!0},{name:"priority",label:"Priority",options:["normal","low","high","urgent"]}],send:async f=>{await u("/_appport/notifications","POST",f),v()},done:()=>"Notification sent."},x?"ready":"loading"),l.jsx(el,{title:`Notifications for ${i}`,read:()=>u(`/_appport/notifications?limit=50&recipient=${encodeURIComponent(i)}`).then(f=>f.items),deps:[i,d,r],empty:"No notifications for this identity.",columns:[["Title",f=>l.jsx("strong",{children:f.title??f.type})],["Type",f=>Et(f.type)],["Priority",f=>f.priority],["State",f=>l.jsx(I,{tone:f.dismissedAt?"neutral":f.readAt?"ok":"info",children:f.dismissedAt?"dismissed":f.status})],["Created",f=>ea(f.createdAt)]],actions:(f,y)=>{const j=`/_appport/notifications/${encodeURIComponent(f.id)}`;return l.jsxs(l.Fragment,{children:[!f.readAt&&l.jsx(gt,{label:"Mark read",action:async()=>un(await u(`${j}/read`,"POST"),"The notification"),done:y}),!f.dismissedAt&&l.jsx(gt,{label:"Dismiss",action:async()=>un(await u(`${j}/dismiss`,"POST"),"The notification"),done:y}),l.jsx(gt,{label:"Delete",danger:!0,confirm:"Delete this notification and its deliveries?",action:()=>u(j,"DELETE"),done:y})]})}})]})}const Ih={pattern:"[A-Z][A-Z0-9_]*",placeholder:"STRIPE_ACCOUNT",hint:"Uppercase letters, digits and underscores, starting with a letter."};function Ub({as:i,manage:u,version:d}){const[r,h]=k.useState(0),v=()=>h(E=>E+1),x=on(d,r),b=Le(()=>u("/v1/configuration"),[i,d,r]),f=[...new Set((b.data?.secrets??[]).map(E=>E.credentialRef))],y=Le(()=>f.length?u(`/v1/configuration/credentials/status?${f.map(E=>`ref=${encodeURIComponent(E)}`).join("&")}`):Promise.resolve([]),[f.join(","),r]),j=new Map((y.data??[]).map(E=>[E.ref,E]));if(b.error)return l.jsx(ve,{error:b.error,retry:b.reload});if(!b.data)return l.jsx(Ze,{});const{variables:g,secrets:R,declarations:q}=b.data,V=q.filter(E=>E.required&&!g.some(A=>A.name===E.name)&&!R.some(A=>A.name===E.name)).length;return l.jsxs(l.Fragment,{children:[l.jsx("p",{className:"small",children:V===0?"Every required value is set.":`${V} required value(s) missing.`}),l.jsx(te,{title:"Variables",children:g.length===0?l.jsx("p",{className:"muted small",children:"No variables yet."}):l.jsx("div",{className:"table-wrap",children:l.jsxs("table",{className:"table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:"Name"}),l.jsx("th",{children:"Value"}),l.jsx("th",{children:"Updated"}),l.jsx("th",{})]})}),l.jsx("tbody",{children:g.map(E=>l.jsxs("tr",{children:[l.jsx("td",{children:Et(E.name)}),l.jsx("td",{className:"mono small",children:E.value}),l.jsx("td",{children:ea(E.updatedAt)}),l.jsxs("td",{className:"row",children:[l.jsx(_m,{current:E.value,onSave:A=>u(`/v1/configuration/variables/${encodeURIComponent(E.name)}`,"PATCH",{value:A,required:!1}),done:v}),l.jsx(gt,{label:"Delete",danger:!0,confirm:`Delete ${E.name}?`,action:()=>u(`/v1/configuration/variables/${encodeURIComponent(E.name)}`,"DELETE"),done:v})]})]},E.name))})]})})}),l.jsx(jl,{title:"Add a variable",submitLabel:"Add variable",fields:[{name:"name",label:"Name",required:!0,...Ih},{name:"value",label:"Value",required:!0,hint:"Not for secrets: add a secret reference below instead."}],send:async E=>{if(ui(E.value))throw new Error("This looks like a secret. Add it as a secret reference instead, and set its value; a variable is stored in FeltDB.");await u("/v1/configuration/variables","POST",{...E,required:!1}),v()},done:()=>"Variable added."}),l.jsx(te,{title:"Secrets",children:R.length===0?l.jsx("p",{className:"muted small",children:"No secrets yet."}):l.jsx("div",{className:"table-wrap",children:l.jsxs("table",{className:"table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:"Name"}),l.jsx("th",{children:"Reference"}),l.jsx("th",{children:"Value"}),l.jsx("th",{children:"Updated"}),l.jsx("th",{})]})}),l.jsx("tbody",{children:R.map(E=>{const A=j.get(E.credentialRef);return l.jsxs("tr",{children:[l.jsx("td",{children:Et(E.name)}),l.jsx("td",{children:Et(E.credentialRef)}),l.jsx("td",{children:A?A.state==="set"?l.jsxs(I,{tone:"ok",children:["set",A.version?` · v${A.version}`:""]}):l.jsx(I,{tone:"warn",children:A.state}):l.jsx(I,{children:"unknown"})}),l.jsx("td",{children:ea(E.updatedAt)}),l.jsxs("td",{className:"row",children:[l.jsx(zs,{credentialRef:E.credentialRef,label:A?.state==="set"?"Replace value":"Set value",as:i,onSaved:v}),l.jsx(gt,{label:"Delete",danger:!0,confirm:`Delete the binding ${E.name}? The stored value is kept.`,action:()=>u(`/v1/configuration/secrets/${encodeURIComponent(E.name)}`,"DELETE"),done:v})]})]},E.name)})})]})})}),l.jsx(jl,{title:"Add a secret reference",submitLabel:"Add secret",fields:[{name:"name",label:"Name",required:!0,...Ih},{name:"credentialRef",label:"Credential reference",required:!0,pattern:"credential-ref:.+",placeholder:"credential-ref:stripe",choices:(x?.credentials??[]).map(E=>({value:E.ref,label:`${E.ref}${E.present?"":" (not set)"}`})),hint:Eb}],send:async E=>{await u("/v1/configuration/secrets","POST",{...E,required:!1}),v()},done:()=>"Secret reference added. Set its value in the table above."},x?"ready":"loading")]})}function qb({manage:i,version:u}){const[d,r]=k.useState(0),h=on(u),[v,x]=k.useState(null),[b,f]=k.useState(null),y=()=>r(g=>g+1),j="/_appport/api/keys";return l.jsxs(l.Fragment,{children:[v&&l.jsxs("div",{className:"ok-box small",children:[v.lead," Copy this secret now; it is not shown again: ",l.jsx("code",{className:"token",children:v.value})," ",l.jsx(rn,{text:v.value})," ",l.jsx("button",{className:"btn btn-small btn-ghost",onClick:()=>x(null),children:"Done"})]}),l.jsx(jl,{title:"Create an API key",submitLabel:"Create API key",fields:[{name:"name",label:"Key name",required:!0},{name:"capabilities",label:"Only these capabilities (optional)",multi:!0,choices:h?.capabilities??[],placeholder:"files.read, jobs.create",hint:"A ceiling: the key's roles still decide. None chosen: no ceiling."},{name:"expiresAt",label:"Expires at (optional)",type:"datetime-local"}],send:async g=>{const R=Ds(g.capabilities??""),q=await i(j,"POST",{name:g.name,...R.length?{restrictions:{capabilities:R}}:{},...g.expiresAt?{expiresAt:new Date(g.expiresAt).toISOString()}:{}});return q?.secret&&x({lead:`Created ${g.name}.`,value:q.secret}),y(),q},done:()=>"API key created."},h?"ready":"loading"),l.jsx(el,{title:"API keys",read:()=>i(j),deps:[u,d],empty:"No API keys yet.",columns:[["Name",g=>l.jsx("strong",{children:g.name})],["Prefix",g=>Et(g.keyPrefix)],["Ceiling",g=>l.jsx("span",{className:"small",children:g.restrictions?g.restrictions.capabilities.length?g.restrictions.capabilities.join(", "):"denies everything":"none"})],["Expires",g=>ea(g.expiresAt)],["Last used",g=>ea(g.lastUsedAt)],["State",g=>l.jsx(I,{tone:g.status==="active"?"ok":"neutral",children:g.rotatedTo?"replaced":g.status})]],actions:(g,R)=>l.jsxs(l.Fragment,{children:[g.status==="active"&&!g.rotatedTo&&l.jsx(gt,{label:"Rotate",confirm:"Issue a new secret and revoke this one now?",action:async()=>{const q=un(await i(`${j}/${encodeURIComponent(g.id)}/rotate`,"POST",{overlapSeconds:0}),`The API key ${g.name}`);x({lead:`Rotated ${g.name}.`,value:q.secret})},done:R}),l.jsx("button",{className:"btn btn-small",onClick:()=>f(g),children:"Audit"}),l.jsx(gt,{label:"Revoke",danger:!0,confirm:`Revoke ${g.name}? Requests with it are refused from then on.`,action:()=>i(`${j}/${encodeURIComponent(g.id)}`,"DELETE"),done:R})]})}),b&&l.jsx(el,{title:`Audit for ${b.name}`,read:()=>i(`${j}/${encodeURIComponent(b.id)}/audit`).then(g=>Array.isArray(g)?g:g.items??[]),deps:[b.id,d],empty:"No events.",columns:[["Time",g=>ea(g.timestamp)],["Event",g=>Et(g.type)],["Result",g=>g.result],["Principal",g=>Et(g.principalId)]]})]})}const Ph="generate";function Hb(){const i=crypto.getRandomValues(new Uint8Array(32));return btoa(String.fromCharCode(...i)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function Bb({as:i,manage:u,version:d}){const[r,h]=k.useState(0),v=()=>h(f=>f+1),x=on(d,r),b=x?.credentials??[];return l.jsxs(l.Fragment,{children:[l.jsx(jl,{title:"Register an endpoint",submitLabel:"Register endpoint",fields:[{name:"url",label:"Endpoint URL",type:"url",required:!0,placeholder:"https://example.com/webhook"},{name:"events",label:"Events",required:!0,multi:!0,placeholder:"invoice.created, invoice.paid",choices:x?.webhookEvents.all??[],hint:x?.webhookEvents.declared.length?"Declared in services.webhooks.events; your functions emit them with ctx.services.webhooks.emit().":"Declare your events in services: { webhooks: { events: [...] } } to list them here."},{name:"signingCredentialRef",label:"Signing secret",required:!0,pattern:"credential-ref:.+",placeholder:"credential-ref:webhook-signing",choices:[{value:Ph,label:"Generate a new signing secret"},...b.map(f=>({value:f.ref,label:`${f.ref}${f.present?"":" (not set)"}`}))],hint:"A new secret is stored in FeltKit's custody and shown to you once, to configure the receiver."}],send:async f=>{const y=Ds(f.events??"");if(!y.length)throw new Error("Choose at least one event.");let j=f.signingCredentialRef,g=null;return j===Ph&&(j=`credential-ref:webhook-${new URL(f.url).hostname.replace(/[^A-Za-z0-9]+/g,"-").replace(/^-|-$/g,"")}-${Date.now().toString(36)}`,g=Hb(),await ne("/credentials",{method:"POST",body:JSON.stringify({ref:j,value:g,as:i})})),await u("/_appport/webhooks","POST",{url:f.url,events:y,signingCredentialRef:j}),v(),{ref:j,secret:g}},done:f=>f.secret?l.jsxs(l.Fragment,{children:["Endpoint registered, signing with ",l.jsx("code",{children:f.ref}),". Give the receiver this secret now; it is not shown again: ",l.jsx("code",{className:"token",children:f.secret})," ",l.jsx(rn,{text:f.secret})]}):l.jsxs(l.Fragment,{children:["Endpoint registered, signing with ",l.jsx("code",{children:f.ref}),"."]})},x?"ready":"loading"),l.jsx(el,{title:"Endpoints",read:()=>u("/_appport/webhooks"),deps:[i,d,r],empty:"No endpoints yet.",columns:[["URL",f=>Et(f.url)],["Events",f=>l.jsx("span",{className:"small",children:(f.events??[]).join(", ")})],["Signing secret",f=>Et(f.signingCredentialRef)],["Created",f=>ea(f.createdAt)],["Status",f=>l.jsx(I,{tone:f.disabledAt?"neutral":"ok",children:f.disabledAt?"disabled":"active"})]],actions:(f,y)=>f.disabledAt?null:l.jsx(gt,{label:"Disable",danger:!0,confirm:"Stop delivering to this endpoint? It cannot be enabled again.",action:()=>u(`/_appport/webhooks/${encodeURIComponent(f.id)}`,"DELETE"),done:y})}),l.jsx(el,{title:"Recent deliveries",read:()=>u("/_appport/webhooks/deliveries?limit=50").then(f=>Array.isArray(f)?f:f.items??[]),deps:[i,d,r],empty:"No deliveries yet.",columns:[["Event",f=>Et(f.eventType)],["Status",f=>l.jsx(I,{tone:f.status==="delivered"?"ok":f.status==="failed"?"bad":"warn",children:f.status})],["Attempts",f=>f.attemptCount],["HTTP",f=>f.lastStatusCode??""],["Last error",f=>l.jsx("span",{className:"error-text small",children:f.lastError??""})],["Created",f=>ea(f.createdAt)]],tools:f=>l.jsx(Nm,{done:f}),actions:(f,y)=>f.status==="failed"?l.jsxs(l.Fragment,{children:[l.jsx(gt,{label:"Replay",action:()=>ne(`/services/deliveries/${encodeURIComponent(f.id)}/replay`,{method:"POST",body:JSON.stringify({as:i})}),done:y}),l.jsx("button",{className:"btn btn-small",onClick:()=>yt(`agent/new/diagnose-delivery/${encodeURIComponent(f.id)}`),children:"Diagnose"})]}):null})]})}function Em({handlers:i,mutations:u}){const[d,r]=k.useState(u[0]??"");if(Object.keys(i).length)return null;const v=`jobs: { handlers: { "${d.replace(":",".")}": "${d}" } },`;return l.jsxs(te,{title:"Declare a job type",children:[l.jsxs("p",{className:"small",children:["A job type runs one of your mutations, as the person who queued it, with retries. None is declared yet. Choose the mutation it runs, then add the line to ",l.jsx("code",{children:"services"})," in ",l.jsx("code",{children:"feltkit/app.ts"}),"; the backend reloads and the type appears below."]}),u.length?l.jsxs(l.Fragment,{children:[l.jsxs("span",{className:"row",children:[l.jsx("select",{className:"input",value:d,onChange:x=>r(x.target.value),"aria-label":"Mutation",children:u.map(x=>l.jsx("option",{value:x,children:x},x))}),l.jsx(rn,{text:v})]}),l.jsx("pre",{className:"json",children:v})]}):l.jsx("p",{className:"muted small",children:"Write a mutation in feltkit/ first."})]})}function Lb({as:i,manage:u,version:d}){const[r,h]=k.useState(0),v=()=>h(y=>y+1),x=on(d),b=x?.jobHandlers??{},f=Object.keys(b);return l.jsxs(l.Fragment,{children:[x&&l.jsx(Em,{handlers:b,mutations:x.mutations}),l.jsx(jl,{title:"Queue a job",submitLabel:"Queue job",fields:[{name:"type",label:"Job type",required:!0,strict:!0,choices:f.map(y=>({value:y,label:`${y} → ${b[y]}`})),placeholder:"Declare a handler first"},{name:"payload",label:"Payload (JSON object)",multiline:!0,value:"{}"}],send:async y=>{if(!f.includes(y.type))throw new Error(`No handler is declared for "${y.type}", so the job would fail. Declare it in services.jobs.handlers first.`);await u("/_appport/jobs","POST",{type:y.type,payload:Db(y.payload??"{}","payload")}),v()},done:()=>l.jsxs(l.Fragment,{children:["Job queued as ",i,"."," ",l.jsx("button",{className:"btn btn-small",onClick:()=>{ne("/services/run",{method:"POST",body:"{}"}).then(v)},children:"Run due work now"})]})},f.join(",")),l.jsx(el,{title:"Jobs",read:()=>u("/_appport/jobs").then(y=>[...y].sort((j,g)=>String(g.createdAt).localeCompare(String(j.createdAt)))),deps:[i,d,r],empty:"No jobs yet.",tools:y=>l.jsx(Nm,{done:y}),columns:[["Type",y=>Et(y.type)],["Status",y=>l.jsx(I,{tone:y.status==="completed"?"ok":y.status==="failed"?"bad":"warn",children:y.status})],["Attempts",y=>`${y.attemptCount}/${y.maxAttempts}`],["Run at",y=>ea(y.runAt)],["Last error",y=>l.jsx("span",{className:"error-text small",children:y.lastError??""})]],actions:(y,j)=>l.jsxs(l.Fragment,{children:[(y.status==="failed"||y.status==="completed")&&l.jsx(gt,{label:"Retry",action:async()=>un(await u(`/_appport/jobs/${encodeURIComponent(y.id)}/retry`,"POST"),`The ${y.type} job`),done:j}),y.status==="failed"&&l.jsx("button",{className:"btn btn-small",onClick:()=>yt(`agent/new/diagnose-job/${encodeURIComponent(y.id)}`),children:"Diagnose"})]})})]})}const Yb={s:"second",m:"minute",h:"hour",d:"day"},Gb=i=>{const u=/^(\d+)([smhd])$/.exec(String(i));return u?`Every ${u[1]} ${Yb[u[2]]}${u[1]==="1"?"":"s"}`:String(i)};function Vb({manage:i,version:u}){const[d,r]=k.useState(0),h=()=>r(f=>f+1),v=on(u),x=v?.jobHandlers??{},b=Object.keys(x);return l.jsxs(l.Fragment,{children:[v&&b.length===0&&l.jsx(Em,{handlers:x,mutations:v.mutations}),l.jsx(jl,{title:"Create a schedule",submitLabel:"Create schedule",fields:[{name:"type",label:"Job type",required:!0,strict:!0,choices:b.map(f=>({value:f,label:`${f} → ${x[f]}`})),placeholder:"Declare a handler first"},{name:"interval",label:"Frequency",options:[{value:"15m",label:"Every 15 minutes"},{value:"30m",label:"Every 30 minutes"},{value:"1h",label:"Every hour"},{value:"6h",label:"Every 6 hours"},{value:"1d",label:"Every day"},{value:"7d",label:"Every week"}]}],send:async f=>{if(!b.includes(f.type))throw new Error(`No handler is declared for "${f.type}", so every scheduled job would fail. Declare it in services.jobs.handlers first.`);await i("/_appport/schedules","POST",{type:f.type,interval:f.interval}),h()},done:()=>"Schedule created."},b.join(",")),l.jsx(el,{title:"Schedules",read:()=>i("/_appport/schedules"),deps:[u,d],empty:"No schedules yet.",columns:[["Type",f=>Et(f.type)],["Frequency",f=>Gb(f.interval)],["Next run",f=>ea(f.nextRunAt)],["Created by",f=>Et(f.createdBy)],["Status",f=>l.jsx(I,{tone:f.enabled?"ok":"neutral",children:f.enabled?"enabled":"disabled"})]],actions:(f,y)=>f.enabled?l.jsx(gt,{label:"Disable",danger:!0,confirm:"Stop queueing jobs from this schedule? It cannot be enabled again.",action:async()=>un(await i(`/_appport/schedules/${encodeURIComponent(f.id)}`,"DELETE"),"The schedule"),done:y}):null})]})}function Qb({manage:i,version:u}){const[d,r]=k.useState(0),h=Le(()=>Promise.all([i("/v1/intelligence/catalog"),i("/v1/intelligence")]),[u,d]),[v,x]=k.useState(null),[b,f]=k.useState(null),[y,j]=k.useState(!1);if(h.error)return l.jsx(ve,{error:h.error,retry:h.reload});if(!h.data)return l.jsx(Ze,{});const[g,R]=h.data,q=v??{provider:R.configured?R.provider:g[0]?.id??"",model:R.configured?R.model:"",endpoint:R.configured&&R.endpoint?.kind==="custom"?R.endpoint.url:"",credentialRef:""},V=g.find(X=>X.id===q.provider),E=X=>(j(!1),x({...q,...X})),A=async X=>{X.preventDefault(),f(null);try{if(ui(q.credentialRef))throw new Error("That looks like an API key. Enter the key in Studio → Models; here, give a credential reference.");await i("/v1/intelligence","PUT",{provider:q.provider,model:q.model,endpoint:q.endpoint&&V?.customEndpoint?q.endpoint:"default",...q.credentialRef?{credentialRef:q.credentialRef}:{}}),x(null),j(!0),r(ee=>ee+1)}catch(ee){f(ee)}};return l.jsxs(l.Fragment,{children:[l.jsxs(te,{title:"Current",children:[l.jsx("p",{className:"small",children:R.configured?l.jsxs(l.Fragment,{children:[l.jsx("strong",{children:R.provider})," / ",l.jsx("code",{children:R.model})," · credential ",R.credentialConfigured?"attached":"not attached"]}):"Not configured. The platform works without it; the agent then has no model to decide with."}),l.jsxs("p",{className:"muted small",children:["To enter an API key and test the model, use"," ",l.jsx("a",{href:"#/models",className:"link",children:"Models"}),"."]})]}),l.jsxs(te,{title:"Configure",children:[l.jsxs("form",{onSubmit:A,children:[l.jsxs("div",{className:"form-grid",children:[l.jsxs("label",{children:[l.jsx("span",{children:"Provider *"}),l.jsx("select",{className:"input",value:q.provider,onChange:X=>E({provider:X.target.value,model:""}),children:g.map(X=>l.jsx("option",{value:X.id,children:X.displayName},X.id))})]}),l.jsxs("label",{children:[l.jsx("span",{children:"Model *"}),l.jsx("input",{className:"input",list:"intelligence-models",value:q.model,required:!0,onChange:X=>E({model:X.target.value})}),l.jsx("datalist",{id:"intelligence-models",children:(V?.models??[]).map(X=>l.jsx("option",{value:X.id,children:X.displayName},X.id))})]}),V?.customEndpoint&&l.jsxs("label",{children:[l.jsx("span",{children:"Custom endpoint (optional)"}),l.jsx("input",{className:"input",type:"url",value:q.endpoint,placeholder:V.endpoints?.[0]?.url??"http://localhost:11434/v1",onChange:X=>E({endpoint:X.target.value})})]}),l.jsxs("label",{children:[l.jsxs("span",{children:["Credential reference",V?.credential==="required"&&!R.credentialConfigured?" *":""]}),l.jsx("input",{className:"input",value:q.credentialRef,pattern:"credential-ref:.+",placeholder:`credential-ref:${q.provider}`,required:V?.credential==="required"&&!R.credentialConfigured,onChange:X=>E({credentialRef:X.target.value})}),l.jsx("span",{className:"muted small",children:"Leave empty to keep the current one."})]})]}),l.jsx("button",{className:"btn btn-primary",type:"submit",children:"Save"}),R.credentialConfigured&&V?.credential!=="required"&&l.jsx(gt,{label:"Remove credential",danger:!0,confirm:"Detach the credential reference?",action:()=>i("/v1/intelligence/credential","DELETE"),done:()=>r(X=>X+1)})]}),b?l.jsx(ve,{error:b}):null,y?l.jsx("div",{className:"ok-box small",children:"Saved."}):null]})]})}const em={configured:{tone:"ok",help:"Enabled, set up, and its records read cleanly."},unconfigured:{tone:"warn",help:"Enabled, but nothing is set up yet."},unhealthy:{tone:"bad",help:"Enabled, but its store failed a check or recent work failed."},available:{tone:"neutral",help:"Can run here; not enabled in feltkit({ services })."},unavailable:{tone:"bad",help:"Cannot run in this installation."}};function ws({service:i}){const u=em[i.state]??em.unavailable;return l.jsx(I,{tone:u.tone,title:u.help,children:i.state})}const Tm="feltkit.services.as",Xb=()=>{try{return sessionStorage.getItem(Tm)}catch{return null}};function $b(i){const[u,d]=k.useState(()=>Xb()??i[0]?.id??""),r=v=>{d(v);try{sessionStorage.setItem(Tm,v)}catch{}};k.useEffect(()=>{i.length&&!i.some(v=>v.id===u)&&d(i[0].id)},[i,u]);const h=l.jsxs("label",{className:"row small",children:[l.jsx("span",{className:"muted",children:"Act as"}),l.jsx("select",{value:u,onChange:v=>r(v.target.value),"aria-label":"Identity for service operations",children:i.map(v=>l.jsxs("option",{value:v.id,children:[v.name??v.id," (",v.roles.join(", "),")"]},v.id))})]});return{as:u,picker:h}}const hr=i=>i.state!=="available"&&i.state!=="unavailable";function Zb({page:i}){const{version:u}=Bt(),d=Le(()=>ne("/services"),[u]),r=Le(()=>ne("/overview"),[u]),h=r.data?.devUsers??[],v=!!r.data?.environment?.development,{canAct:x}=Rs(r.data),{as:b,picker:f}=$b(h),y=d.data?.services??[],j=v&&h.length?f:null;if(i==="credentials")return l.jsxs(l.Fragment,{children:[l.jsx(Ht,{title:"Credentials",subtitle:l.jsx(Kb,{children:"Credential references the services and configuration use, and where each value is kept."}),actions:j}),l.jsx(Fb,{as:b,canAct:x,development:v,version:u})]});if(i){const q=y.find(V=>V.id===i);return l.jsx(Ab,{id:i,service:q,as:b,picker:j,development:v,summary:q&&hr(q)?l.jsx(Jb,{service:q}):null,operations:!v&&i==="jobs"?l.jsx(Wb,{as:b,development:!1,canAct:x,version:u}):!v&&i==="webhooks"?l.jsx(Ib,{as:b,development:!1,canAct:!1,version:u}):null})}const g=y.filter(hr),R=y.filter(q=>!hr(q));return l.jsxs(l.Fragment,{children:[l.jsx(Ht,{title:"Services",subtitle:v?"AppPort Services on this environment’s FeltDB instance. Each service has its own screen; every operation there is authorized by your roles, as the identity you choose.":"AppPort Services on this environment’s FeltDB instance. Configuration is a development tool; job retries here are authorized as you and recorded as yours.",actions:j}),d.error&&!d.data?l.jsx(ve,{error:d.error,retry:d.reload}):d.data?l.jsxs(l.Fragment,{children:[v&&h.length===0&&l.jsx(te,{children:l.jsxs("p",{className:"muted small",children:["Declare a development identity in ",l.jsxs("code",{children:["feltkit(","{"," dev: ","{"," users ","}"," ","}",")"]})," to manage services: their operations are authorized as that identity."]})}),g.length===0&&l.jsxs(qt,{title:"No services enabled",children:["Enable services with feltkit(","{"," services: ","{"," … ","}"," ","}","). Each one gets its own screen here."]}),l.jsxs("div",{className:"grid grid-3",children:[g.map(q=>l.jsxs("a",{href:`#/services/${q.id}`,className:"card service-tile",children:[l.jsxs("span",{className:"row",children:[l.jsx("strong",{children:q.name})," ",l.jsx(ws,{service:q})]}),l.jsx("span",{className:"small",children:q.detail}),q.summary&&l.jsx("span",{className:"muted small",children:Object.entries(q.summary).slice(0,3).map(([V,E])=>`${V} ${E}`).join(" · ")})]},q.id)),l.jsxs("a",{href:"#/services/credentials",className:"card service-tile",children:[l.jsx("strong",{children:"Credentials"}),l.jsx("span",{className:"small",children:"References the services use, and whether each value is set. Values are never shown."})]})]}),R.length>0&&l.jsx(te,{title:"Not enabled",children:l.jsx("ul",{className:"list",children:R.map(q=>l.jsxs("li",{className:"list-row",children:[l.jsxs("span",{children:[l.jsx("strong",{children:q.name})," ",l.jsx("span",{className:"muted small",children:q.state==="unavailable"?q.detail:q.description})]}),l.jsxs("span",{className:"row",children:[l.jsx(ws,{service:q}),q.state==="available"&&l.jsx("button",{className:"btn btn-small",onClick:()=>yt(`services/${q.id}`),children:"Enable"})]})]},q.id))})})]}):l.jsx(Ze,{})]})}const Kb=({children:i})=>l.jsxs(l.Fragment,{children:[l.jsx("a",{href:"#/services",className:"link",children:"Services"})," ","· ",i]});function Jb({service:i}){return l.jsxs(te,{title:l.jsxs("span",{className:"row",children:["Status ",l.jsx(ws,{service:i})]}),action:l.jsxs("span",{className:"muted small",children:[i.package,"@",i.version]}),children:[l.jsxs("dl",{className:"kv",children:[l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Status"}),l.jsxs("dd",{children:[i.detail," ",i.lastCheckedAt&&l.jsxs("span",{className:"muted",children:["· checked ",tt(i.lastCheckedAt)]})]})]}),i.summary&&l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Records"}),l.jsx("dd",{children:Object.entries(i.summary).map(([u,d])=>l.jsxs("span",{className:"chip",children:[u," ",l.jsx("strong",{children:String(d)})]},u))})]}),i.lastError&&l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Last error"}),l.jsxs("dd",{className:"error-text",children:[i.lastError.message," ",l.jsxs("span",{className:"muted",children:["· ",tt(i.lastError.at)]})]})]})]}),l.jsxs("details",{className:"small",children:[l.jsx("summary",{className:"muted",children:"Permissions and stored state"}),l.jsxs("dl",{className:"kv",children:[l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Permissions"}),l.jsx("dd",{children:i.capabilities.map(u=>l.jsx("code",{className:"chip",children:u},u))})]}),l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"State"}),l.jsx("dd",{children:i.collections.map(u=>l.jsx("a",{href:`#/data/${u}`,className:"chip mono",children:u},u))})]})]})]})]})}function Fb({as:i,canAct:u,development:d,version:r}){const[h,v]=k.useState(0),x=Le(()=>ne("/credentials"),[r,h]),[b,f]=k.useState(null),[y,j]=k.useState("");if(x.error)return l.jsx(ve,{error:x.error,retry:x.reload});if(!x.data)return null;const{custody:g,credentials:R}=x.data,q=async E=>{f(null);try{await ne(`/credentials/${encodeURIComponent(E)}${d&&i?`?as=${encodeURIComponent(i)}`:""}`,{method:"DELETE"}),v(A=>A+1)}catch(A){f(A)}},V=y.trim()?y.trim().startsWith("credential-ref:")?y.trim():`credential-ref:${y.trim()}`:"";return l.jsxs(te,{title:"Credentials",children:[l.jsxs("p",{className:"muted small",children:["Services and configuration hold credential references only. Values are kept by FeltKit’s custody (",g.location,") and used inside the effect that needs them; they are never stored in FeltDB, logged, or shown. ",g.note]}),b?l.jsx(ve,{error:b}):null,l.jsx("div",{className:"table-wrap",children:l.jsxs("table",{className:"table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:"Reference"}),l.jsx("th",{children:"Used by"}),l.jsx("th",{children:"Value"}),l.jsx("th",{children:"Override variable"}),l.jsx("th",{})]})}),l.jsx("tbody",{children:R.map(E=>l.jsxs("tr",{children:[l.jsx("td",{className:"mono",children:E.ref}),l.jsx("td",{className:"small",children:E.usedBy.length?E.usedBy.join(", "):l.jsx("span",{className:"muted",children:"stored, not used yet"})}),l.jsx("td",{children:l.jsx(Bs,{credential:E})}),l.jsx("td",{className:"mono small",children:E.variable??"invalid reference"}),l.jsx("td",{children:u&&E.writable&&l.jsxs("span",{className:"row",children:[l.jsx(zs,{credentialRef:E.ref,label:E.present?"Replace":"Set",...d&&i?{as:i}:{},onSaved:()=>v(A=>A+1)}),E.source==="vault"&&E.present&&l.jsx("button",{className:"btn btn-small",onClick:()=>q(E.ref),children:"Remove"})]})})]},E.ref))})]})}),u&&g.writable&&l.jsxs("div",{className:"row small",children:[l.jsx("input",{className:"input",value:y,onChange:E=>j(ui(E.target.value)?"":E.target.value),placeholder:"credential-ref:stripe","aria-label":"New credential reference"}),V&&l.jsx(zs,{credentialRef:V,label:"Set value",...d&&i?{as:i}:{},onSaved:()=>(j(""),v(E=>E+1))})]})]})}function Am({title:i,path:u,as:d,development:r,canAct:h,version:v,retry:x,columns:b}){const[f,y]=k.useState(0),j=Le(()=>ne(`/services/${u}`),[v,f]),[g,R]=k.useState(null),q=async A=>{R(null);try{await ne(`/services/${u}/${encodeURIComponent(A)}/${x.action}`,{method:"POST",body:JSON.stringify(r?{as:d}:{})}),y(X=>X+1)}catch(X){R(X)}},V=async()=>{R(null);try{await ne("/services/run",{method:"POST",body:"{}"}),y(A=>A+1)}catch(A){R(A)}},E=j.data?.items??[];return l.jsxs(te,{title:i,action:r?l.jsx("button",{className:"btn",onClick:V,children:"Run due work now"}):null,children:[g?l.jsx(ve,{error:g}):null,j.data?.replay&&!j.data.replay.enabled?l.jsx("p",{className:"muted small",children:j.data.replay.reason}):null,j.error?l.jsx(ve,{error:j.error,retry:j.reload}):j.data?E.length===0?l.jsx("p",{className:"muted small",children:"Nothing yet."}):l.jsx("div",{className:"table-wrap",children:l.jsxs("table",{className:"table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[b.map(([A])=>l.jsx("th",{children:A},A)),l.jsx("th",{})]})}),l.jsx("tbody",{children:E.slice(0,50).map(A=>l.jsxs("tr",{children:[b.map(([X,ee])=>l.jsx("td",{children:ee(A)},X)),l.jsxs("td",{className:"row",children:[r&&A.status==="failed"&&l.jsx("button",{className:"btn btn-small",onClick:()=>yt(`agent/new/${u==="jobs"?"diagnose-job":"diagnose-delivery"}/${encodeURIComponent(A.id)}`),children:"Diagnose"}),h&&x.when(A)&&(A.retryable??!0)&&l.jsx("button",{className:"btn btn-small",onClick:()=>q(A.id),disabled:r&&!d,children:x.label})]})]},A.id))})]})}):l.jsx(Ze,{})]})}const km=i=>i==="completed"||i==="delivered"?"ok":i==="failed"?"bad":"warn";function Wb(i){return l.jsx(Am,{...i,title:"Job runs",path:"jobs",retry:{label:"Retry",action:"retry",when:u=>u.status==="failed"},columns:[["Type",u=>l.jsx("code",{children:u.type})],["Status",u=>l.jsx(I,{tone:km(u.status),children:u.status})],["Attempts",u=>`${u.attemptCount}/${u.maxAttempts}`],["As",u=>l.jsx("span",{className:"mono small",children:u.principal??"—"})],["Last error",u=>l.jsx("span",{className:"error-text small",children:u.lastError??""})],["Created",u=>l.jsx("span",{className:"muted small",children:tt(u.createdAt)})]]})}function Ib(i){return l.jsx(Am,{...i,title:"Webhook deliveries",path:"deliveries",retry:{label:"Replay",action:"replay",when:u=>u.status==="failed"},columns:[["Event",u=>l.jsx("code",{children:u.eventType})],["To",u=>l.jsx("span",{className:"mono small",children:u.destination??u.endpointId})],["Status",u=>l.jsx(I,{tone:km(u.status),children:u.status})],["Attempts",u=>u.attemptCount],["HTTP",u=>u.lastStatusCode??""],["Last error",u=>l.jsx("span",{className:"error-text small",children:u.lastError??""})],["Created",u=>l.jsx("span",{className:"muted small",children:tt(u.createdAt)})]]})}function Pb(){jm();const{overview:i,activity:u}=Bt();if(!i)return null;const d=i.capabilities??[],r=Cm(u,i.recentActivity??[]).slice(0,8),h=[...i.recentErrors??[],...i.recentDenials??[]].sort((f,y)=>y.at.localeCompare(f.at)).slice(0,6),v=Object.values(i.counts??{}).reduce((f,y)=>f+Number(y),0),x=(i.services??[]).filter(f=>f.state!=="available"&&f.state!=="unavailable"),b=i.agent??{tasks:[],waiting:0,handoffs:0};return l.jsxs(l.Fragment,{children:[l.jsx(Ht,{title:i.application.name,subtitle:i.application.description??"Your application at a glance: where its state lives, what it can do, and what it has done.",actions:l.jsxs(l.Fragment,{children:[l.jsx(I,{tone:i.state==="ready"?"ok":"warn",children:i.state}),i.url&&l.jsx("a",{className:"btn",href:i.url,target:"_blank",rel:"noreferrer",children:"Open app ↗"})]})}),l.jsxs("div",{className:"grid grid-4 stats",children:[l.jsx(As,{label:"Records",value:v,detail:`${i.collections.length} collection${i.collections.length===1?"":"s"}`,onClick:()=>yt("data")}),l.jsx(As,{label:"Functions",value:i.functions.length,detail:`${i.functions.filter(f=>f.kind==="query").length} queries · ${i.functions.filter(f=>f.kind==="mutation").length} mutations`,onClick:()=>yt("capabilities")}),l.jsx(As,{label:"Capabilities",value:d.length,detail:"published through AppPort",onClick:()=>yt("capabilities")}),l.jsx(As,{label:"Errors",value:(i.recentErrors??[]).length,detail:`${(i.recentDenials??[]).length} recent denials`,tone:(i.recentErrors??[]).length?"bad":void 0,onClick:()=>yt("activity")})]}),l.jsxs("div",{className:"grid grid-2",children:[l.jsxs(te,{title:"Where state lives",children:[l.jsx("p",{className:"lede",children:"One FeltDB instance serves this environment. Application functions, AppPort capabilities, AppPort Services, sessions, and this activity log all read and write it."}),l.jsxs("dl",{className:"kv",children:[l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Environment"}),l.jsxs("dd",{children:[i.environment.name," ",i.environment.production&&l.jsx(I,{tone:"warn",children:"production"})]})]}),l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Storage"}),l.jsxs("dd",{children:["FeltDB ",i.instance.feltdbVersion," · ",i.instance.mode," · ",i.instance.durable?"durable":"ephemeral"]})]}),l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Location"}),l.jsx("dd",{children:l.jsx("code",{className:"path",children:i.instance.location})})]}),l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Journal"}),l.jsxs("dd",{children:["position ",i.instance.sequence]})]}),l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Opened"}),l.jsxs("dd",{children:[tt(i.instance.openedAt)," by pid ",i.instance.pid]})]})]}),l.jsxs("div",{className:"components",children:[l.jsx("div",{className:"components-title",children:"Components using this instance"}),Object.entries(i.components??{}).map(([f,y])=>l.jsxs("div",{className:"component",children:[l.jsx("span",{className:"mono",children:f}),l.jsx("span",{className:"muted small",children:y.join(", ")})]},f))]})]}),l.jsx(te,{title:"Recent activity",action:l.jsx("a",{href:"#/activity",className:"link",children:"All activity →"}),children:r.length===0?l.jsx(qt,{title:"Nothing has happened yet",children:"Open the app and make a change. Every query, mutation, capability call, and sign-in appears here."}):l.jsx("ul",{className:"feed",children:r.map(f=>l.jsx("li",{children:l.jsxs("a",{href:`#/activity/${f.id}`,className:"feed-row",children:[l.jsx(cn,{outcome:f.outcome}),l.jsx("span",{className:"mono feed-name",children:f.name}),l.jsx("span",{className:"muted small",children:f.principal?.id??(f.kind==="system"?"system":"anonymous")}),l.jsxs("span",{className:"muted small",children:["via ",f.via]}),f.writes?.length?l.jsxs(I,{tone:"accent",children:[f.writes.length," write",f.writes.length===1?"":"s"]}):null,l.jsx("span",{className:"muted small right",children:tt(f.at)})]})},f.id))})})]}),i.path&&l.jsx(te,{title:"Path to production",children:l.jsx("ol",{className:"journey",children:i.path.map(f=>l.jsxs("li",{children:[l.jsx(I,{tone:f.state==="done"?"ok":f.state==="todo"?"warn":"neutral",children:f.state==="done"?"done":f.state==="todo"?"to do":f.state==="not-tracked"?"not tracked":"review"}),l.jsx("strong",{children:f.step}),l.jsx("span",{className:"small",children:f.detail}),f.link&&l.jsx("a",{className:"link small",href:`#/${f.link}`,"aria-label":`Open ${f.step}`,children:"Open →"})]},f.step))})}),l.jsxs("div",{className:"grid grid-3",children:[l.jsx(te,{title:"Data",action:i.environment.production?null:l.jsx("a",{href:"#/data",className:"link",children:"Explore →"}),children:i.collections.length===0?l.jsxs(qt,{title:"No collections",children:['Declare one with app.collection("name", ',"{ … }",")."]}):l.jsx("ul",{className:"list",children:i.collections.map(f=>l.jsx("li",{children:l.jsxs("a",{href:`#/data/${f.name}`,className:"list-row",children:[l.jsx("span",{className:"mono",children:f.name}),l.jsx("span",{className:"muted",children:i.counts?.[f.name]??0})]})},f.name))})}),l.jsx(te,{title:"Capabilities",action:l.jsx("a",{href:"#/capabilities",className:"link",children:"Inspect →"}),children:d.length===0?l.jsx(qt,{title:"No capabilities published",children:'Add capability: "name.verb" to a query or mutation to publish it through AppPort.'}):l.jsx("ul",{className:"list",children:d.map(f=>l.jsx("li",{children:l.jsxs("a",{href:`#/capabilities/${f.name}`,className:"list-row",children:[l.jsx("span",{className:"mono",children:f.name}),l.jsx(I,{tone:f.effect==="consequential"?"accent":"neutral",children:f.effect})]})},f.name))})}),l.jsx(te,{title:"Services",action:l.jsx("a",{href:"#/services",className:"link",children:"Manage →"}),children:x.length===0?l.jsxs(qt,{title:"No services enabled",children:["Enable AppPort Services with feltkit(","{"," services: ","{"," files: true, jobs: … ","}"," ","}",")."]}):l.jsx("ul",{className:"list",children:x.map(f=>l.jsxs("li",{className:"list-row",children:[l.jsx("span",{children:f.name}),l.jsx(ws,{service:f,compact:!0})]},f.id))})})]}),l.jsxs(te,{title:"Agent",action:l.jsx("a",{href:"#/agent",className:"link",children:"Open →"}),children:[b.waiting>0&&l.jsxs("p",{children:[l.jsxs(I,{tone:"warn",children:[b.waiting," waiting for approval"]})," ",l.jsx("a",{href:"#/agent",children:"Review"})]}),b.handoffs>0&&l.jsxs("p",{className:"muted small",children:[b.handoffs," task(s) waiting for a coding agent to claim over MCP."]}),b.tasks.length===0?l.jsx("p",{className:"muted small",children:"No agent tasks yet. Diagnose a failed job from Services, or start one on the Agent screen."}):l.jsx("ul",{className:"list",children:b.tasks.map(f=>l.jsx("li",{children:l.jsxs("a",{href:`#/agent/${f.id}`,className:"list-row",children:[l.jsx("span",{children:f.objective}),l.jsx(I,{tone:f.status==="completed"?"ok":f.status==="blocked"?"warn":"neutral",children:f.status})]})},f.id))})]}),h.length>0&&l.jsx(te,{title:"Recent errors and denials",action:l.jsx("a",{href:"#/activity",className:"link",children:"Investigate →"}),children:l.jsx("ul",{className:"feed",children:h.map(f=>l.jsx("li",{children:l.jsxs("a",{href:`#/activity/${f.id}`,className:"feed-row",children:[l.jsx(cn,{outcome:f.outcome}),l.jsx("span",{className:"mono feed-name",children:f.name}),l.jsx("span",{className:"error-text small",children:f.error?.code}),l.jsx("span",{className:"small ellipsis",children:f.error?.message}),l.jsx("span",{className:"muted small right",children:tt(f.at)})]})},f.id))})}),!i.environment.production&&l.jsx(te,{title:"Development",children:l.jsxs("dl",{className:"kv",children:[l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Runtime"}),l.jsxs("dd",{children:["started ",tt(i.startedAt)," · functions loaded ",tt(i.loadedAt)," · generation ",i.generation]})]}),l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Project"}),l.jsx("dd",{children:l.jsx("code",{className:"path",children:i.projectDir})})]}),l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Endpoints"}),l.jsxs("dd",{className:"mono small",children:[i.url,"/api · ",i.url,"/appport · ",i.url,"/mcp"]})]}),l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Deploy"}),l.jsxs("dd",{children:[l.jsx("code",{children:"npx feltkit deploy"})," ",l.jsx("span",{className:"muted",children:"builds, verifies the production build boots, and writes a Node/Docker artifact."})]})]})]})})]})}function As({label:i,value:u,detail:d,tone:r,onClick:h}){return l.jsxs("button",{className:`stat ${r==="bad"&&u>0?"stat-bad":""}`,onClick:h,children:[l.jsx("span",{className:"stat-label",children:i}),l.jsx("span",{className:"stat-value",children:u}),l.jsx("span",{className:"stat-detail",children:d})]})}function Cm(i,u){const d=new Set;return[...i,...u].filter(r=>d.has(r.id)?!1:(d.add(r.id),!0)).sort((r,h)=>h.id.localeCompare(r.id))}function ex({collection:i}){const{version:u,overview:d}=Bt(),r=Le(()=>ne("/collections"),[u]),h=r.data?.collections??[],v=h.find(b=>b.name===i)??h.find(b=>b.owner==="application")??h[0],x=!!v?.editable&&!d?.environment?.production;return l.jsxs(l.Fragment,{children:[l.jsx(Ht,{title:"Data",subtitle:l.jsx(l.Fragment,{children:"Records in this environment’s FeltDB instance. Application collections are validated by their schemas; platform collections belong to FeltKit and AppPort Services and are read-only here."})}),r.error&&!r.data?l.jsx(ve,{error:r.error,retry:r.reload}):r.data?l.jsxs("div",{className:"split",children:[l.jsx("aside",{className:"split-nav","aria-label":"Collections",children:["application","platform"].map(b=>{const f=h.filter(y=>b==="application"?y.owner==="application":y.owner!=="application");return f.length?l.jsxs("div",{className:"split-group",children:[l.jsx("div",{className:"split-title",children:b==="application"?"Application":"Platform"}),f.map(y=>l.jsxs("a",{href:`#/data/${y.name}`,className:`split-item ${v?.name===y.name?"active":""}`,children:[l.jsx("span",{className:"mono ellipsis",children:y.name}),l.jsx("span",{className:"muted small",children:y.count})]},y.name))]},b):null})}),l.jsx("section",{className:"split-main",children:v?l.jsx(tx,{collection:v,editable:x},v.name):l.jsx(qt,{title:"No collections"})})]}):l.jsx(Ze,{})]})}function tx({collection:i,editable:u}){const{version:d}=Bt(),[r,h]=k.useState(""),[v,x]=k.useState(""),[b,f]=k.useState(null),[y,j]=k.useState([]),[g,R]=k.useState(null),[q,V]=k.useState(null),E=b?`&field=${encodeURIComponent(b.field)}&eq=${encodeURIComponent(b.value)}`:"",A=Le(()=>ne(`/collections/${encodeURIComponent(i.name)}?limit=50${E}`),[i.name,E,d]);k.useEffect(()=>{A.data&&(j(A.data.records),R(A.data.nextCursor))},[A.data]);const X=k.useMemo(()=>{const w=i.schema?.properties?Object.keys(i.schema.properties):[],K=[...new Set(y.flatMap(be=>Object.keys(be)))].filter(be=>be!=="id"&&be!=="__version");return["id",...(w.length?w:K).slice(0,6),"__version"]},[i.schema,y]),ee=async()=>{if(!g)return;const w=await ne(`/collections/${encodeURIComponent(i.name)}?limit=50&cursor=${encodeURIComponent(g)}${E}`);j(K=>[...K,...w.records]),R(w.nextCursor)};return l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"collection-head",children:[l.jsxs("div",{children:[l.jsx("h2",{className:"mono",children:i.name}),l.jsxs("div",{className:"muted small",children:[i.owner==="application"?"Application collection":`Owned by ${i.owner}`," · ",i.count," record",i.count===1?"":"s",i.description?` · ${i.description}`:""]})]}),l.jsxs("div",{className:"row",children:[!i.editable&&l.jsx(I,{children:"read-only"}),u&&l.jsx("button",{className:"btn btn-primary",onClick:()=>V("new"),children:"New record"})]})]}),i.schema&&l.jsxs("details",{className:"schema",children:[l.jsx("summary",{children:"Schema"}),l.jsx(si,{schema:i.schema}),l.jsx("p",{className:"muted small",children:"Enforced by FeltKit on every write through ctx.db. FeltDB stores JSON documents and adds id and __version."})]}),l.jsxs("form",{className:"filter",onSubmit:w=>{w.preventDefault(),f(r&&v!==""?{field:r,value:v}:null)},children:[l.jsxs("select",{className:"input",value:r,onChange:w=>h(w.target.value),"aria-label":"Filter field",children:[l.jsx("option",{value:"",children:"Filter by field…"}),X.map(w=>l.jsx("option",{value:w,children:w},w))]}),l.jsx("input",{className:"input",value:v,onChange:w=>x(w.target.value),placeholder:"equals…","aria-label":"Filter value"}),l.jsx("button",{className:"btn",type:"submit",children:"Apply"}),b&&l.jsx("button",{className:"btn btn-ghost",type:"button",onClick:()=>{f(null),h(""),x("")},children:"Clear"})]}),A.error?l.jsx(ve,{error:A.error,retry:A.reload}):A.loading&&!A.data?l.jsx(Ze,{}):y.length===0?l.jsx(qt,{title:b?"No records match":"No records yet",children:b?"Try another value.":i.owner==="application"?"Records appear here as soon as a mutation writes them.":""}):l.jsxs("div",{className:"table-wrap",children:[l.jsxs("table",{className:"table",children:[l.jsx("thead",{children:l.jsx("tr",{children:X.map(w=>l.jsx("th",{children:w},w))})}),l.jsx("tbody",{children:y.map(w=>l.jsx("tr",{onClick:()=>V(w),tabIndex:0,onKeyDown:K=>K.key==="Enter"&&V(w),children:X.map(K=>l.jsx("td",{className:K==="id"||K==="__version"?"mono muted":"",children:l.jsx(ax,{value:w[K]})},K))},w.id))})]}),g&&l.jsx("button",{className:"btn more",onClick:ee,children:"Load more"})]}),q&&l.jsx(nx,{collection:i,record:q==="new"?null:q,editable:u,onClose:()=>V(null),onSaved:()=>(V(null),A.reload())})]})}function ax({value:i}){if(i===void 0)return l.jsx("span",{className:"muted",children:"—"});if(typeof i=="boolean")return l.jsx(I,{tone:i?"ok":"neutral",children:String(i)});if(typeof i=="number"&&i>1e12&&i<1e13)return l.jsx("span",{title:String(i),children:new Date(i).toLocaleString()});if(typeof i=="object")return l.jsx("span",{className:"mono small",children:JSON.stringify(i).slice(0,80)});const u=String(i);return l.jsx("span",{title:u.length>60?u:void 0,children:u.length>60?`${u.slice(0,60)}…`:u})}function lx(i){const u={};for(const[d,r]of Object.entries(i?.properties??{}))(i.required??[]).includes(d)&&(u[d]=r.type==="number"||r.type==="integer"?/At$/.test(d)?Date.now():0:r.type==="boolean"?!1:"");return u}function nx({collection:i,record:u,editable:d,onClose:r,onSaved:h}){const v=u?Object.fromEntries(Object.entries(u).filter(([A])=>A!=="id"&&A!=="__version")):lx(i.schema),[x,b]=k.useState(JSON.stringify(v,null,2)),[f,y]=k.useState(null),[j,g]=k.useState(!1),[R,q]=k.useState(!1),V=async()=>{y(null);let A;try{A=JSON.parse(x)}catch{y({code:"INVALID_JSON",message:"That is not valid JSON."});return}g(!0);try{await ne(u?`/collections/${i.name}/${encodeURIComponent(u.id)}`:`/collections/${i.name}`,{method:u?"PATCH":"POST",body:JSON.stringify({record:A})}),h()}catch(X){y(X)}finally{g(!1)}},E=async()=>{g(!0);try{await ne(`/collections/${i.name}/${encodeURIComponent(u.id)}`,{method:"DELETE"}),h()}catch(A){y(A),g(!1)}};return l.jsxs(pm,{title:u?`${i.name} / ${u.id}`:`New ${i.name} record`,onClose:r,children:[u&&l.jsxs("p",{className:"muted small",children:["Version ",u.__version,". Find what wrote it in ",l.jsx("a",{href:"#/activity",children:"Activity"}),"."]}),d?l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"callout",children:["Development edit: validated against the schema and committed atomically, recorded in Activity as ",l.jsx("code",{children:"admin"})," by ",l.jsx("code",{children:"dashboard"}),". Function access rules do not apply to these edits; this tool is not available in production."]}),l.jsx("textarea",{className:"code-input",value:x,onChange:A=>b(A.target.value),rows:14,spellCheck:!1,"aria-label":"Record JSON"}),f?l.jsx(ve,{error:f}):null,l.jsxs("div",{className:"row between",children:[u?R?l.jsxs("span",{className:"row",children:[l.jsx("button",{className:"btn btn-danger",onClick:E,disabled:j,children:"Delete permanently"}),l.jsx("button",{className:"btn btn-ghost",onClick:()=>q(!1),children:"Cancel"})]}):l.jsx("button",{className:"btn btn-ghost danger",onClick:()=>q(!0),children:"Delete…"}):l.jsx("span",{}),l.jsx("button",{className:"btn btn-primary",onClick:V,disabled:j,children:u?"Save changes":"Create record"})]})]}):l.jsx(ci,{value:u,max:2e4}),u&&i.owner!=="application"&&l.jsxs("p",{className:"muted small",children:[i.owner," owns this collection. Change it through its service or capability, so its authorization and audit trail apply."," ",l.jsx("a",{href:"#/services",onClick:()=>yt("services"),children:"Services →"})]})]})}const ix=(i,u)=>i==="*"||i===u||i.endsWith(".*")&&u.startsWith(i.slice(0,-1));function sx(i,u){return Object.entries(i??{}).filter(([,d])=>d.some(r=>ix(r,u))).map(([d])=>d)}function Om(i){if(!i||i.type!=="object")return{};const u={};for(const d of i.required??[]){const r=i.properties?.[d]??{};u[d]=r.type==="boolean"?!0:r.type==="number"||r.type==="integer"?0:""}return u}function cx({selected:i}){const{version:u,overview:d}=Bt(),r=Le(()=>ne("/capabilities"),[u]),[h,v]=k.useState(i?.includes(":")?"functions":"capabilities"),x=r.data?.capabilities??[],b=d?.functions??[],f=h==="capabilities"?x.find(y=>y.name===i)??x[0]:b.find(y=>y.name===i)??b[0];return l.jsxs(l.Fragment,{children:[l.jsx(Ht,{title:"Capabilities",subtitle:"What this application can do. Capabilities are published through AppPort — discoverable by other applications and agents (MCP) — and every invocation passes the same authorization as any other caller."}),l.jsxs("div",{className:"tabs",role:"tablist",children:[l.jsxs("button",{role:"tab","aria-selected":h==="capabilities",className:h==="capabilities"?"active":"",onClick:()=>v("capabilities"),children:["AppPort capabilities ",l.jsx("span",{className:"muted",children:x.length})]}),l.jsxs("button",{role:"tab","aria-selected":h==="functions",className:h==="functions"?"active":"",onClick:()=>v("functions"),children:["All functions ",l.jsx("span",{className:"muted",children:b.length})]})]}),r.error&&!r.data?l.jsx(ve,{error:r.error,retry:r.reload}):r.data?l.jsxs("div",{className:"split",children:[l.jsxs("aside",{className:"split-nav",children:[(h==="capabilities"?x:b).map(y=>l.jsxs("a",{href:`#/capabilities/${y.name}`,className:`split-item ${f?.name===y.name?"active":""}`,children:[l.jsx("span",{className:"mono ellipsis",children:y.name}),h==="functions"?l.jsx(I,{tone:y.kind==="query"?"info":"accent",children:y.kind}):l.jsxs("span",{className:"muted small",children:["v",y.version]})]},y.name)),h==="capabilities"&&x.length===0&&l.jsx("p",{className:"muted small pad",children:"None published yet."})]}),l.jsx("section",{className:"split-main",children:f?h==="capabilities"?l.jsx(ux,{capability:f,roles:d?.roles??{},mcpTools:r.data.mcp?.tools??[],devUsers:d?.devUsers??[],development:d?.environment?.development},f.name):l.jsx(rx,{fn:f,roles:d?.roles??{},devUsers:d?.devUsers??[],development:d?.environment?.development},f.name):l.jsx(qt,{title:h==="capabilities"?"No capabilities":"No functions",children:h==="capabilities"?'Publish a query or mutation with capability: { name: "tasks.complete", description: "…" } and a returns schema.':"Export app.query() or app.mutation() from a module in feltkit/."})})]}):l.jsx(Ze,{})]})}function zm({required:i,roles:u}){return i.length?l.jsx("span",{children:i.map(d=>l.jsxs("span",{children:[l.jsx("code",{children:d})," ",l.jsxs("span",{className:"muted",children:["— granted to ",sx(u,d).join(", ")||"no role"]})]},d))}):l.jsx("span",{children:"any signed-in principal"})}function ux({capability:i,roles:u,mcpTools:d,devUsers:r,development:h}){const v=d.find(x=>x.replace(/_/g,".").includes(i.name))??null;return l.jsxs("div",{className:"stack-lg",children:[l.jsxs("div",{children:[l.jsxs("div",{className:"row",children:[l.jsx("h2",{className:"mono",children:i.name}),l.jsxs(I,{children:["v",i.version]}),l.jsx(I,{tone:i.effect==="consequential"?"accent":"info",children:i.effect})]}),l.jsx("p",{children:i.description??l.jsx("span",{className:"muted",children:"No description. Add one so agents and other applications know what this does."})})]}),l.jsxs(te,{title:"Contract",children:[l.jsxs("dl",{className:"kv",children:[l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Requires"}),l.jsx("dd",{children:l.jsx(zm,{required:i.authorization,roles:u})})]}),l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Implemented by"}),l.jsx("dd",{children:i.function?l.jsx("a",{href:`#/capabilities/${i.function.name}`,className:"mono",children:i.function.name}):"—"})]}),l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Services used"}),l.jsx("dd",{children:i.services?.length?i.services.map(x=>l.jsx(I,{children:x},x)):l.jsx("span",{className:"muted",children:"none observed"})})]}),l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Idempotency"}),l.jsx("dd",{children:i.idempotency??"—"})]}),l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Reachable at"}),l.jsxs("dd",{className:"small",children:[l.jsx("code",{children:"POST /appport"}),v&&l.jsxs(l.Fragment,{children:[" ","· MCP tool ",l.jsx("code",{children:v})]})]})]})]}),l.jsxs("div",{className:"grid grid-2",children:[l.jsxs("div",{children:[l.jsx("div",{className:"label",children:"Input"}),l.jsx(si,{schema:i.input})]}),l.jsxs("div",{children:[l.jsx("div",{className:"label",children:"Output"}),l.jsx(si,{schema:i.output})]})]})]}),l.jsx(te,{title:"Recent invocations",children:i.recent?.length?l.jsx("ul",{className:"feed",children:i.recent.map(x=>l.jsx("li",{children:l.jsxs("a",{href:`#/activity/${x.id}`,className:"feed-row",children:[l.jsx(cn,{outcome:x.outcome}),l.jsx("span",{className:"small",children:x.principal??"anonymous"}),l.jsxs("span",{className:"muted small",children:["via ",x.via]}),x.error&&l.jsx("span",{className:"error-text small",children:x.error.code}),l.jsxs("span",{className:"muted small right",children:[x.durationMs,"ms · ",tt(x.at)]})]})},x.id))}):l.jsx("p",{className:"muted",children:"Not invoked through AppPort yet."})}),h&&l.jsx(Dm,{title:"Invoke through AppPort",note:"Runs through AppPort’s dispatch pipeline with a short-lived session for the identity you choose. The same authorization applies as for any agent or application.",example:Om(i.input),devUsers:r,run:(x,b)=>ne("/capabilities/invoke",{method:"POST",body:JSON.stringify({capability:i.name,version:i.version,input:x,as:b})})})]})}function rx({fn:i,roles:u,devUsers:d,development:r}){const h=i.access==="public"||i.access==="authenticated"?[]:[i.access];return l.jsxs("div",{className:"stack-lg",children:[l.jsxs("div",{children:[l.jsxs("div",{className:"row",children:[l.jsx("h2",{className:"mono",children:i.name}),l.jsx(I,{tone:i.kind==="query"?"info":"accent",children:i.kind}),i.capability&&l.jsxs(I,{tone:"ok",children:["→ ",i.capability.name]})]}),l.jsx("p",{className:"muted",children:i.description??(i.kind==="query"?"Read-only: its database handle cannot write.":"All writes commit in one FeltDB transaction, or none do.")})]}),l.jsxs(te,{title:"Contract",children:[l.jsxs("dl",{className:"kv",children:[l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Access"}),l.jsx("dd",{children:i.access==="public"?"anyone, including anonymous callers":l.jsx(zm,{required:h,roles:u})})]}),l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Endpoint"}),l.jsx("dd",{children:l.jsxs("code",{children:["POST /api/",i.kind,"/",i.name]})})]})]}),l.jsxs("div",{className:"grid grid-2",children:[l.jsxs("div",{children:[l.jsx("div",{className:"label",children:"Arguments"}),l.jsx(si,{schema:i.args})]}),l.jsxs("div",{children:[l.jsx("div",{className:"label",children:"Returns"}),i.returns?l.jsx(si,{schema:i.returns}):l.jsx("span",{className:"muted",children:"not declared"})]})]})]}),r&&l.jsx(Dm,{title:`Run ${i.kind}`,note:"Runs as the identity you choose, through the same validation and authorization as a request from the app.",example:Om(i.args),devUsers:d,run:(v,x)=>ne("/functions/run",{method:"POST",body:JSON.stringify({name:i.name,args:v,as:x})})})]})}function Dm({title:i,note:u,example:d,devUsers:r,run:h}){const[v,x]=k.useState(JSON.stringify(d,null,2)),[b,f]=k.useState(r[0]?.id??"anonymous"),[y,j]=k.useState(null),[g,R]=k.useState(null),[q,V]=k.useState(!1),E=k.useMemo(()=>y&&y.ok===!0,[y]);return l.jsxs(te,{title:i,children:[l.jsx("p",{className:"muted small",children:u}),l.jsx("div",{className:"row",children:l.jsxs("label",{className:"field-inline",children:[l.jsx("span",{children:"Act as"}),l.jsxs("select",{className:"input",value:b,onChange:A=>f(A.target.value),children:[r.map(A=>l.jsxs("option",{value:A.id,children:[A.name??A.id," · ",A.roles.join(", ")]},A.id)),l.jsx("option",{value:"anonymous",children:"anonymous"})]})]})}),l.jsx("textarea",{className:"code-input",rows:6,value:v,onChange:A=>x(A.target.value),spellCheck:!1,"aria-label":"Input JSON"}),l.jsxs("div",{className:"row between",children:[l.jsx("span",{className:"muted small",children:"Input is validated against the contract before authorization runs."}),l.jsx("button",{className:"btn btn-primary",disabled:q,onClick:async()=>{R(null),j(null);let A;try{A=JSON.parse(v||"{}")}catch{R({code:"INVALID_JSON",message:"That is not valid JSON."});return}V(!0);try{j(await h(A,b))}catch(X){R(X)}finally{V(!1)}},children:q?"Running…":"Run"})]}),g?l.jsx(ve,{error:g}):null,y&&l.jsxs("div",{className:`result ${E?"result-ok":"result-bad"}`,children:[l.jsxs("div",{className:"row",children:[l.jsx(cn,{outcome:E?"success":y.error?.code==="FORBIDDEN"||y.error?.code==="UNAUTHORIZED"?"denied":"error"}),y.requestId&&l.jsx("span",{className:"muted small mono",children:y.requestId})]}),l.jsx(ci,{value:E?y.output??y.value:y.error})]})]})}const ox=["","query","mutation","capability","integration","agent","service","auth","admin","system"],dx=["","success","error","denied"];function fx({selected:i}){jm(1e4);const{activity:u}=Bt(),[d,r]=k.useState(""),[h,v]=k.useState(""),[x,b]=k.useState(!1),f=Le(()=>ne(`/activity?limit=200${d?`&kind=${d}`:""}${h?`&outcome=${h}`:""}`),[d,h]),y=k.useMemo(()=>{const j=Cm(u.filter(g=>(!d||g.kind===d)&&(!h||g.outcome===h)),f.data?.entries??[]);return x?j.filter(g=>g.kind!=="query"):j},[u,f.data,d,h,x]);return l.jsxs(l.Fragment,{children:[l.jsx(Ht,{title:"Activity",subtitle:"What actually happened, from the runtime’s own records: who called what, through which interface, the authority decision, and the writes FeltDB committed."}),l.jsxs("div",{className:"filter",children:[l.jsx("select",{className:"input",value:d,onChange:j=>r(j.target.value),"aria-label":"Kind",children:ox.map(j=>l.jsx("option",{value:j,children:j||"All kinds"},j))}),l.jsx("select",{className:"input",value:h,onChange:j=>v(j.target.value),"aria-label":"Outcome",children:dx.map(j=>l.jsx("option",{value:j,children:j||"All outcomes"},j))}),l.jsxs("label",{className:"check",children:[l.jsx("input",{type:"checkbox",checked:x,onChange:j=>b(j.target.checked)})," Hide queries"]}),l.jsx("span",{className:"muted small right",children:"Live · newest first"})]}),f.error&&!f.data?l.jsx(ve,{error:f.error,retry:f.reload}):f.data?y.length===0?l.jsx(qt,{title:"No activity matches",children:"Use the app, invoke a capability, or run a function from Capabilities."}):l.jsx("div",{className:"table-wrap",children:l.jsxs("table",{className:"table activity",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:"When"}),l.jsx("th",{children:"Outcome"}),l.jsx("th",{children:"Kind"}),l.jsx("th",{children:"Name"}),l.jsx("th",{children:"Principal"}),l.jsx("th",{children:"Via"}),l.jsx("th",{children:"Writes"}),l.jsx("th",{className:"num",children:"ms"})]})}),l.jsx("tbody",{children:y.map(j=>l.jsxs("tr",{onClick:()=>yt(`activity/${j.id}`),tabIndex:0,onKeyDown:g=>g.key==="Enter"&&yt(`activity/${j.id}`),className:i===j.id?"selected":"",children:[l.jsx("td",{className:"muted small nowrap",title:j.at,children:tt(j.at)}),l.jsx("td",{children:l.jsx(cn,{outcome:j.outcome})}),l.jsx("td",{className:"small",children:j.kind}),l.jsxs("td",{className:"mono",children:[j.name,j.error&&l.jsxs("span",{className:"error-text small",children:[" ",j.error.code]})]}),l.jsx("td",{className:"small",children:j.principal?`${j.principal.id}`:l.jsx("span",{className:"muted",children:j.kind==="system"?"—":"anonymous"})}),l.jsx("td",{className:"small",children:j.via}),l.jsx("td",{className:"small",children:j.writes?.length?j.writes.length:l.jsx("span",{className:"muted",children:"—"})}),l.jsx("td",{className:"num small muted",children:j.durationMs})]},j.id))})]})}):l.jsx(Ze,{}),i&&l.jsx(hx,{id:i,onClose:()=>yt("activity")})]})}function hx({id:i,onClose:u}){const d=Le(()=>ne(`/activity/${encodeURIComponent(i)}`),[i]),r=d.data?.entry,h=d.data?.serviceEvidence??[];return l.jsx(pm,{title:r?r.name:"Activity",onClose:u,children:d.error?l.jsx(ve,{error:d.error}):r?l.jsxs("div",{className:"stack-lg",children:[l.jsx(xr,{rows:[["Outcome",l.jsx(cn,{outcome:r.outcome},"o")],["When",`${new Date(r.at).toLocaleString()} (${tt(r.at)})`],["Kind",r.kind],["Via",r.via],["Principal",r.principal?`${r.principal.id} (${r.principal.type}; roles: ${r.principal.roles.join(", ")||"none"})`:"anonymous"],...r.capability?[["AppPort capability",`${r.capability.name}@${r.capability.version}`]]:[],["Request",l.jsx("code",{children:r.requestId},"r")],["Duration",`${r.durationMs} ms`],...r.argKeys?[["Arguments",r.argKeys.length?r.argKeys.join(", "):"none"]]:[]]}),r.error&&l.jsxs("section",{children:[l.jsx("h3",{children:"Error"}),l.jsxs("div",{className:"error-box",children:[l.jsx("strong",{children:r.error.code})," ",r.error.message]})]}),r.authority&&l.jsxs("section",{children:[l.jsx("h3",{children:"Authority"}),l.jsx(xr,{rows:[["Decision",r.authority.allowed?l.jsx(I,{tone:"ok",children:"allowed"},"a"):l.jsx(I,{tone:"warn",children:"denied"},"d")],["Required",r.authority.required?l.jsx("code",{children:r.authority.required},"q"):"an authenticated principal"],...r.authority.reason?[["Reason",r.authority.reason]]:[],["Decision id",l.jsx("code",{children:r.authority.decisionId},"i")],...r.authority.appportDecisionId?[["AppPort decision",l.jsx("code",{children:r.authority.appportDecisionId},"ap")]]:[],["Policy version",l.jsx("code",{children:r.authority.policyVersion},"p")]]})]}),l.jsxs("section",{children:[l.jsx("h3",{children:"State changes"}),r.writes?.length?l.jsxs(l.Fragment,{children:[l.jsxs("p",{className:"muted small",children:["Committed by FeltDB in one transaction ",l.jsx("code",{children:r.transactionId}),r.commitRevision!==void 0?` at revision ${r.commitRevision}`:"","."]}),l.jsxs("table",{className:"table compact",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:"Op"}),l.jsx("th",{children:"Collection"}),l.jsx("th",{children:"Record"}),l.jsx("th",{children:"Expected version"})]})}),l.jsx("tbody",{children:r.writes.map((v,x)=>l.jsxs("tr",{children:[l.jsx("td",{children:l.jsx(I,{tone:v.op==="delete"?"bad":v.op==="insert"?"ok":"accent",children:v.op})}),l.jsx("td",{className:"mono",children:v.collection}),l.jsx("td",{className:"mono small",children:v.op==="delete"?v.id:l.jsx("a",{href:`#/data/${v.collection}`,children:v.id})}),l.jsx("td",{className:"small",children:v.expectedVersion??"— (create)"})]},x))})]})]}):l.jsx("p",{className:"muted",children:r.kind==="query"?"Queries cannot write.":r.outcome!=="success"?"Nothing was written through ctx.db: a failed mutation commits nothing.":r.services?.length?"No application records changed through ctx.db. Service effects commit separately; see the evidence below.":"No application records changed."}),r.reads?.length?l.jsxs("p",{className:"muted small",children:["Read: ",r.reads.join(", ")]}):null]}),(h.length>0||r.services?.length)&&l.jsxs("section",{children:[l.jsx("h3",{children:"Service evidence"}),l.jsxs("p",{className:"muted small",children:["Recorded by AppPort Services’ gateway in the same FeltDB instance.",d.data?.serviceEvidenceState==="started"?" An effect has no recorded completion: its outcome is unknown, not failed.":"",d.data?.serviceEvidenceTruncated?" More records exist than are shown.":""]}),h.map(v=>l.jsxs("div",{className:"evidence",children:[l.jsxs("div",{className:"row",children:[l.jsx(I,{tone:v.outcome==="succeeded"?"ok":v.outcome==="denied"?"warn":v.outcome==="started"?"neutral":"bad",children:v.outcome}),l.jsx("span",{className:"mono",children:v.capability}),l.jsx("span",{className:"muted small",children:v.service})]}),l.jsxs("div",{className:"muted small",children:["decision ",v.decision,v.decisionId?` · ${v.decisionId}`:""," · ",v.resource]})]},v.id))]}),r.detail&&l.jsxs("section",{children:[l.jsx("h3",{children:"Detail"}),l.jsx(ci,{value:r.detail})]})]}):l.jsx(Ze,{})})}function wm(){const[i,u]=k.useState(null),[d,r]=k.useState(!1);return{open:async()=>{u(null),r(!0);const v=window.open("about:blank","_blank");try{const x=await ne("/production/studio-link",{method:"POST",body:"{}"});if(!x.url)throw new Error("No deployment is recorded for this project. Run `npx feltkit vercel deploy` or `npx feltkit cloudflare deploy` first.");v?(v.opener=null,v.location.href=x.url):window.location.assign(x.url)}catch(x){v?.close(),u(x)}finally{r(!1)}},error:i,busy:d}}const mx=i=>i==="vercel"||i==="cloudflare"?`npx feltkit ${i} deploy`:"npx feltkit deploy";function vx({production:i}){const u=wm(),d=mx(i?.targetId??i?.deployment?.target),r=i?.deployment??null;return i?l.jsxs(te,{title:"Production",action:r?l.jsx(I,{tone:"ok",children:"live"}):i.target?l.jsx(I,{children:"not deployed"}):l.jsx(I,{children:"not set up"}),children:[r?l.jsxs(l.Fragment,{children:[l.jsxs("p",{children:[l.jsx("a",{href:r.url,target:"_blank",rel:"noreferrer",children:r.url})," ",l.jsxs("span",{className:"muted small",children:["· ",i.target??r.target," · deployed ",tt(r.deployedAt)]})]}),l.jsxs("p",{className:"muted small",children:["Data: ",i.storage==="remote"?l.jsx("code",{children:i.location}):i.location]}),l.jsxs("div",{className:"row",children:[l.jsx("a",{className:"btn btn-small",href:r.url,target:"_blank",rel:"noreferrer",children:"Open app ↗"}),r.studio?l.jsx("button",{className:"btn btn-small btn-primary",onClick:()=>{u.open()},disabled:u.busy,children:u.busy?"Signing you in…":"Manage in production Studio ↗"}):l.jsxs("span",{className:"muted small",children:["Production Studio is off. Turn it on with ",l.jsxs("code",{children:[d," --studio"]}),"."]})]}),u.error!=null&&l.jsx(ve,{error:u.error}),l.jsxs("p",{className:"muted small",children:["Sign someone in to the app: ",l.jsx("code",{children:"npx feltkit session create --env production --type user --id <id> --role <role>"})," in this project's folder. It uses the deployment's FeltDB settings from ",l.jsx("code",{children:".env.local"}),"."]})]}):i.target?l.jsxs("p",{className:"muted",children:["Built for ",i.target,", not deployed from here yet. Run ",l.jsx("code",{children:d}),": it uploads the settings, deploys, and signs you in."]}):l.jsxs("p",{className:"muted",children:["Not deployed. ",l.jsx("code",{children:"npx feltkit deploy"})," builds it for where it will run (one container, Vercel, or a FeltDB server), and says what to do next."]}),i.storage==="unconfigured"&&l.jsx("p",{className:"error-text small",children:i.location})]}):null}function yx(){const{version:i,overview:u}=Bt(),d=Le(()=>ne("/environments"),[]),r=Le(()=>ne("/sessions"),[i]),h=u?.environment?.development;return l.jsxs(l.Fragment,{children:[l.jsx(Ht,{title:"Settings",subtitle:"Environments, access policy, and sessions. Configuration lives in feltkit/app.ts; this page shows what the runtime is actually using."}),h&&d.data&&l.jsx(vx,{production:d.data.environments.find(v=>v.name==="production"&&!v.active)}),l.jsxs(te,{title:"Environments",children:[l.jsx("p",{className:"muted small",children:"Each environment has its own FeltDB instance. They never share state; FeltKit refuses to open two environments on the same location."}),d.error?l.jsx(ve,{error:d.error}):d.data?l.jsxs("table",{className:"table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:"Environment"}),l.jsx("th",{children:"Storage"}),l.jsx("th",{children:"Location"}),l.jsx("th",{children:"Instance"})]})}),l.jsx("tbody",{children:d.data.environments.map(v=>l.jsxs("tr",{className:v.active?"selected":"",children:[l.jsxs("td",{children:[l.jsx("strong",{children:v.name})," ",v.active&&l.jsx(I,{tone:"ok",children:"active"})]}),l.jsx("td",{children:v.storage}),l.jsxs("td",{className:"mono small",children:[v.target&&l.jsx("div",{className:"muted",children:v.target}),v.location,v.deployment&&l.jsx("div",{children:l.jsx("a",{href:v.deployment.url,target:"_blank",rel:"noreferrer",children:v.deployment.url})})]}),l.jsx("td",{className:"mono small muted",children:v.instanceId??"not open here"})]},v.name))})]}):l.jsx(Ze,{}),l.jsxs("p",{className:"muted small",children:["Production is what your deployment uses. Built with ",l.jsx("code",{children:"npx feltkit deploy"})," for Vercel or a FeltDB server, that is its FeltDB, reached with the settings in"," ",l.jsx("code",{children:".env.local"}),"; otherwise ",l.jsx("code",{children:"FELTDB_URL"})," + ",l.jsx("code",{children:"FELTDB_TOKEN"})," when set, else ",l.jsx("code",{children:"FELTKIT_STATE_DIR"})," or ",l.jsx("code",{children:".feltkit/production/state"}),"."]})]}),l.jsxs("div",{className:"grid grid-2",children:[l.jsxs(te,{title:"Access policy",action:l.jsxs("code",{className:"muted small",children:["policy ",u?.policyVersion]}),children:[l.jsxs("table",{className:"table compact",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:"Role"}),l.jsx("th",{children:"Permissions"})]})}),l.jsx("tbody",{children:Object.entries(u?.roles??{}).map(([v,x])=>l.jsxs("tr",{children:[l.jsx("td",{children:l.jsx("strong",{children:v})}),l.jsx("td",{children:x.map(b=>l.jsx("code",{className:"chip",children:b},b))})]},v))})]}),l.jsx("p",{className:"muted small",children:"Enforced through AppPort’s authorizer on functions, capabilities, and services alike. Edit roles in feltkit/app.ts."})]}),l.jsx(te,{title:"Development identities",children:h?(u?.devUsers??[]).length?l.jsx("ul",{className:"list",children:u.devUsers.map(v=>l.jsxs("li",{className:"list-row",children:[l.jsxs("span",{children:[l.jsx("strong",{children:v.name??v.id})," ",l.jsx("span",{className:"muted mono small",children:v.id})]}),l.jsx("span",{children:v.roles.map(x=>l.jsx(I,{children:x},x))})]},v.id))}):l.jsxs("p",{className:"muted",children:["None declared. Add dev: ","{ users: [...] }"," to feltkit(","{ … }",")."]}):l.jsx("p",{className:"muted",children:"Development sign-in is disabled in this environment."})})]}),l.jsxs(te,{title:"Sessions",action:l.jsx("span",{className:"muted small",children:"tokens are stored only as SHA-256 digests"}),children:[h&&l.jsx(gx,{roles:Object.keys(u?.roles??{}),onIssued:r.reload}),r.error?l.jsx(ve,{error:r.error}):r.data?r.data.sessions.length===0?l.jsx("p",{className:"muted",children:"No active sessions."}):l.jsxs("table",{className:"table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:"Ref"}),l.jsx("th",{children:"Principal"}),l.jsx("th",{children:"Roles"}),l.jsx("th",{children:"Kind"}),l.jsx("th",{children:"Created"}),l.jsx("th",{children:"Expires"}),l.jsx("th",{})]})}),l.jsx("tbody",{children:r.data.sessions.map(v=>l.jsxs("tr",{children:[l.jsx("td",{className:"mono small muted",children:v.ref}),l.jsxs("td",{children:[v.principal?.id," ",l.jsx("span",{className:"muted small",children:v.principal?.type})]}),l.jsx("td",{className:"small",children:v.principal?.roles?.join(", ")}),l.jsx("td",{className:"small",children:v.kind}),l.jsx("td",{className:"small muted",children:tt(v.createdAt)}),l.jsx("td",{className:"small muted",children:v.expiresAt?new Date(v.expiresAt).toLocaleString():"never"}),l.jsx("td",{children:l.jsx("button",{className:"btn btn-small btn-ghost danger",onClick:()=>ne(`/sessions/${v.ref}`,{method:"DELETE"}).then(r.reload,r.reload),children:"Revoke"})})]},v.ref))})]}):l.jsx(Ze,{})]})]})}function gx({roles:i,onIssued:u}){const[d,r]=k.useState("triage-agent"),[h,v]=k.useState(i.includes("agent")?"agent":i[0]??""),[x,b]=k.useState("agent"),[f,y]=k.useState(null),[j,g]=k.useState(null);return l.jsxs("div",{className:"issue",children:[l.jsxs("form",{className:"row wrap",onSubmit:async R=>{R.preventDefault(),g(null);try{const q=await ne("/sessions",{method:"POST",body:JSON.stringify({principal:{id:d,type:x,roles:[h]},label:"issued from the dashboard",ttlMs:864e5})});y(q.token),u()}catch(q){g(q)}},children:[l.jsx("input",{className:"input",value:d,onChange:R=>r(R.target.value),"aria-label":"Principal id",placeholder:"principal id"}),l.jsxs("select",{className:"input",value:x,onChange:R=>b(R.target.value),"aria-label":"Principal type",children:[l.jsx("option",{value:"agent",children:"agent"}),l.jsx("option",{value:"service",children:"service"}),l.jsx("option",{value:"user",children:"user"})]}),l.jsx("select",{className:"input",value:h,onChange:R=>v(R.target.value),"aria-label":"Role",children:i.map(R=>l.jsx("option",{value:R,children:R},R))}),l.jsx("button",{className:"btn btn-primary",type:"submit",disabled:!d||!h,children:"Issue 24-hour session"})]}),j?l.jsx(ve,{error:j}):null,f&&l.jsxs("div",{className:"callout",children:[l.jsxs("div",{className:"row between",children:[l.jsx("strong",{children:"Shown once."})," ",l.jsx(rn,{text:f})]}),l.jsx("code",{className:"token",children:f}),l.jsxs("div",{className:"muted small",children:["Agents: connect an MCP client to ",l.jsxs("code",{children:[location.origin,"/mcp"]})," with ",l.jsx("code",{children:"Authorization: Bearer <token>"}),". It sees only what this role allows."]})]})]})}function bx(){const i=Le(()=>ne("/projects"),[]),u=i.data?.projects??[],d=wm();return l.jsxs(l.Fragment,{children:[l.jsx(Ht,{title:"Projects",subtitle:"FeltKit applications this machine has run. Each has its own environments and FeltDB instances."}),i.error?l.jsx(ve,{error:i.error,retry:i.reload}):i.data?u.length===0?l.jsx(te,{children:l.jsxs(qt,{title:"Only this project so far",children:["Create another with ",l.jsx("code",{children:"npm create feltkit@latest my-app"}),"."]})}):l.jsx("div",{className:"grid grid-2",children:u.map(r=>l.jsxs(te,{className:r.path===i.data.current?"card-current":"",children:[l.jsxs("div",{className:"row between",children:[l.jsx("h2",{children:r.name}),r.path===i.data.current?l.jsx(I,{tone:"ok",children:"this dashboard"}):r.running?l.jsx(I,{tone:"ok",children:"running"}):r.exists?l.jsx(I,{children:"stopped"}):l.jsx(I,{tone:"bad",children:"missing"})]}),l.jsx("code",{className:"path",children:r.path}),l.jsxs("div",{className:"muted small",children:["last run ",tt(r.lastRunAt)," · ",r.lastEnvironment]}),r.deployment&&l.jsxs("div",{className:"small",children:["Live:"," ",l.jsx("a",{href:r.deployment.url,target:"_blank",rel:"noreferrer",children:r.deployment.url})," ",l.jsxs("span",{className:"muted",children:["(",r.deployment.target,", deployed ",tt(r.deployment.deployedAt),")"]})]}),l.jsxs("div",{className:"row",children:[r.running&&r.url&&r.path!==i.data.current&&l.jsx("a",{className:"btn btn-small",href:r.url,target:"_blank",rel:"noreferrer",children:"Open app ↗"}),r.deployment&&l.jsx("a",{className:"btn btn-small",href:r.deployment.url,target:"_blank",rel:"noreferrer",children:"Open live app ↗"}),r.deployment?.studio&&r.path===i.data.current&&l.jsx("button",{className:"btn btn-small btn-primary",onClick:()=>{d.open()},disabled:d.busy,children:d.busy?"Signing you in…":"Manage production ↗"}),r.deployment?.studio&&r.path!==i.data.current&&l.jsxs("span",{className:"muted small",children:["Manage it: ",l.jsx("code",{children:"npx feltkit manage"})," in its directory."]}),!r.running&&r.exists&&!r.deployment&&l.jsxs("span",{className:"muted small",children:["Start it with ",l.jsx("code",{children:"npm run dev"})," in its directory."]})]})]},r.path))}):l.jsx(Ze,{}),d.error!=null&&l.jsx(ve,{error:d.error}),l.jsx(te,{title:"Start a new application",children:l.jsx("pre",{className:"json",children:`npm create feltkit@latest my-app
13
13
  cd my-app
14
14
  npm install
15
- npm run dev`})})]})}const mr=[{id:"inspect-app",label:"Inspect the application",help:"Capabilities you may use, unhealthy services, recent errors and denials."},{id:"diagnose-job",label:"Diagnose a job",help:"Read the job, its runs and error; propose a retry when it can help.",target:"Job id"},{id:"diagnose-delivery",label:"Diagnose a webhook delivery",help:"Read the delivery, endpoint, and signing credential; propose a replay when it can help.",target:"Delivery id"},{id:"invoke",label:"Run a capability",help:"One capability: observations run now, consequential ones wait for approval."},{id:"handoff",label:"Hand off to a coding agent",help:"Open-ended work. A coding agent claims it over MCP (feltkit_agent_claim) and proposes actions; you approve them here."}],jr=i=>i==="completed"?"ok":i==="cancelled"?"neutral":i==="blocked"?"warn":"info";function bx({rest:i}){const{version:u}=Bt(),d=Le(()=>ne("/overview"),[u]),r=d.data?.devUsers??[],h=!!d.data?.environment?.development,{canAct:v,actor:x}=Rs(d.data),[b,f]=k.useState("");k.useEffect(()=>{!b&&r[0]&&f(r[0].id)},[r,b]);const y=Le(()=>ne(`/agent${b?`?as=${encodeURIComponent(b)}`:""}`),[u,b]),j=i[0]&&i[0]!=="new"?i[0]:null;return l.jsxs(l.Fragment,{children:[l.jsx(Ht,{title:"Agent",subtitle:"FeltDB’s agent runtime operating this application through its AppPort capabilities and AppPort Services. Every action runs as the task owner; consequential ones wait for a person who may perform them.",actions:r.length?l.jsxs("label",{className:"row small",children:[l.jsx("span",{className:"muted",children:"Act as"}),l.jsx("select",{value:b,onChange:g=>f(g.target.value),"aria-label":"Identity for agent actions",children:r.map(g=>l.jsxs("option",{value:g.id,children:[g.name??g.id," (",g.roles.join(", "),")"]},g.id))})]}):null}),y.error&&!y.data?l.jsx(ve,{error:y.error,retry:y.reload}):y.data?j?l.jsx(px,{taskId:j,as:b,development:h,canAct:v,actor:h?b:x??"",version:u}):l.jsxs(l.Fragment,{children:[h&&r.length>0&&l.jsx(xx,{as:b,tools:y.data.tools,initial:i[0]==="new"?{playbook:i[1],target:i[2]}:void 0}),!h&&l.jsx(te,{children:l.jsxs("p",{className:"muted small",children:["Production: tasks come from agents (over MCP) and playbooks. ",v?"You can approve, reject, retry, and settle their actions; each runs as the task owner and is recorded as yours.":"You can inspect them; acting needs feltkit.operations.write."]})}),y.data.handoffs.length>0&&l.jsxs(te,{title:"Waiting for a coding agent",children:[l.jsx("ul",{className:"list",children:y.data.handoffs.map(g=>l.jsxs("li",{className:"list-row",children:[l.jsx("a",{href:`#/agent/${g.taskId}`,children:g.objective}),l.jsxs("span",{className:"muted small mono",children:[g.handoffId," · from ",g.from]})]},g.handoffId))}),l.jsxs("p",{className:"muted small",children:["A coding agent with an agent session claims these with the MCP tool ",l.jsx("code",{children:"feltkit_agent_claim"}),"."]})]}),l.jsx(te,{title:"Tasks",children:y.data.tasks.length===0?l.jsx(qt,{title:"No tasks yet",children:"Start one above, or from a failed job or delivery on the Services screen."}):l.jsx("div",{className:"table-wrap",children:l.jsxs("table",{className:"table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:"Objective"}),l.jsx("th",{children:"Status"}),l.jsx("th",{children:"FeltDB execution"}),l.jsx("th",{children:"Owner"}),l.jsx("th",{children:"Waiting"}),l.jsx("th",{children:"Updated"})]})}),l.jsx("tbody",{children:y.data.tasks.map(g=>l.jsxs("tr",{onClick:()=>yt(`agent/${g.task.task_id}`),children:[l.jsx("td",{children:g.task.objective}),l.jsx("td",{children:l.jsx(I,{tone:jr(g.task.status),children:g.task.status})}),l.jsx("td",{className:"mono small",children:g.execution?.status??"—"}),l.jsx("td",{className:"mono small",children:g.task.owner}),l.jsx("td",{children:g.pending?l.jsxs(I,{tone:"warn",children:[g.pending," approval",g.pending>1?"s":""]}):""}),l.jsx("td",{className:"muted small",children:tt(g.task.updated_at)})]},g.task.task_id))})]})})})]}):l.jsx(Ze,{})]})}function xx({as:i,tools:u,initial:d}){const[r,h]=k.useState(d?.playbook&&mr.some(w=>w.id===d.playbook)?d.playbook:"inspect-app"),[v,x]=k.useState(d?.target??""),[b,f]=k.useState(""),[y,j]=k.useState(""),[g,R]=k.useState("{}"),[q,V]=k.useState(!1),[E,A]=k.useState(null),X=mr.find(w=>w.id===r),ee=async()=>{A(null),V(!0);try{let w={};if(r==="invoke")try{w=JSON.parse(g||"{}")}catch{throw new Error("Input is not valid JSON.")}const K=await ne("/agent/tasks",{method:"POST",body:JSON.stringify({as:i,playbook:r,objective:b||(X.target?`${X.label}: ${v}`:r==="invoke"?`Run ${y}`:X.label),...X.target?{target:v}:{},...r==="invoke"?{capability:y,args:w}:{}})});yt(`agent/${K.task.task_id}`)}catch(w){A(w)}finally{V(!1)}};return l.jsxs(te,{title:"New task",children:[E?l.jsx(ve,{error:E}):null,l.jsxs("div",{className:"form",children:[l.jsxs("label",{children:[l.jsx("span",{children:"What"}),l.jsx("select",{value:r,onChange:w=>h(w.target.value),children:mr.map(w=>l.jsx("option",{value:w.id,children:w.label},w.id))})]}),l.jsx("p",{className:"muted small",children:X.help}),X.target&&l.jsxs("label",{children:[l.jsx("span",{children:X.target}),l.jsx("input",{className:"input mono",value:v,onChange:w=>x(w.target.value)})]}),r==="invoke"&&l.jsxs(l.Fragment,{children:[l.jsxs("label",{children:[l.jsx("span",{children:"Capability"}),l.jsxs("select",{value:y,onChange:w=>j(w.target.value),children:[l.jsx("option",{value:"",children:"Choose…"}),u.map(w=>l.jsxs("option",{value:w.name,disabled:!w.allowed,children:[w.name," — ",w.effect==="consequential"?"needs approval":"observation",w.allowed?"":" (not permitted for this identity)"]},w.name))]})]}),l.jsxs("label",{children:[l.jsx("span",{children:"Input (JSON)"}),l.jsx("textarea",{className:"input mono",rows:3,value:g,onChange:w=>R(w.target.value)})]})]}),l.jsxs("label",{children:[l.jsx("span",{children:"Objective"}),l.jsx("input",{className:"input",value:b,placeholder:r==="handoff"?"Describe the work for the coding agent":"Optional",onChange:w=>f(w.target.value)})]}),l.jsx("div",{children:l.jsx("button",{className:"btn btn-primary",onClick:ee,disabled:q||!i||!!X.target&&!v||r==="invoke"&&!y||r==="handoff"&&!b,children:q?"Working…":"Start"})})]})]})}const jx=i=>({failed:"Failed",interrupted:"Outcome unknown",executing:"Running",approved:"Approved, starting"})[i]??i;function px({taskId:i,as:u,development:d,canAct:r,actor:h,version:v}){const[x,b]=k.useState({}),[f,y]=k.useState(0),j=Le(()=>ne(`/agent/tasks/${encodeURIComponent(i)}`),[i,v,f]),[g,R]=k.useState(null),[q,V]=k.useState(""),E=async(Y,de={})=>{R(null);try{await ne(`/agent/tasks/${encodeURIComponent(i)}/${Y}`,{method:"POST",body:JSON.stringify(d?{as:u,...de}:de)}),y(qe=>qe+1)}catch(qe){R(qe)}};if(j.error)return l.jsx(ve,{error:j.error,retry:j.reload});if(!j.data)return l.jsx(Ze,{});const{task:A,checkpoints:X,execution:ee,pending:w,actions:K=[]}=j.data,be=K.filter(Y=>Y.state==="failed"||Y.state==="interrupted"||Y.state==="executing"||Y.state==="approved"),Ce=A.status!=="completed"&&A.status!=="cancelled";return l.jsxs(l.Fragment,{children:[l.jsx("p",{children:l.jsx("a",{href:"#/agent",children:"← Tasks"})}),g?l.jsx(ve,{error:g}):null,l.jsxs(te,{title:l.jsxs("span",{className:"row",children:[A.objective," ",l.jsx(I,{tone:jr(A.status),children:A.status})]}),action:l.jsx("span",{className:"muted small mono",children:A.owner}),children:[l.jsxs("dl",{className:"kv",children:[l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"FeltDB execution"}),l.jsx("dd",{className:"mono small",children:ee?`${ee.agentRef} · ${ee.status}${ee.error?` · ${ee.error}`:""}`:"—"})]}),l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Task"}),l.jsxs("dd",{className:"mono small",children:[A.task_id," · checkpoint v",A.checkpoint_version]})]})]}),r&&Ce&&j.data.playbook==="decide"&&K.every(Y=>!["proposed","approved","executing","interrupted"].includes(Y.state))&&l.jsxs("div",{className:"row",children:[l.jsx("button",{className:"btn",onClick:()=>E("decide"),children:"Ask the model again"}),l.jsx("span",{className:"muted small",children:"Uses this environment’s model (Models). The answer is a new proposal."})]}),d&&Ce&&l.jsxs("div",{className:"row",children:[l.jsx("input",{className:"input grow",placeholder:"Summary of what was done",value:q,onChange:Y=>V(Y.target.value)}),l.jsx("button",{className:"btn",onClick:()=>E("complete",{summary:q}),disabled:w.length>0,children:"Complete"}),l.jsx("button",{className:"btn btn-ghost",onClick:()=>E("cancel",{reason:"cancelled from Studio"}),children:"Cancel"})]})]}),w.map(Y=>l.jsxs(te,{title:l.jsxs("span",{className:"row",children:["Waiting for approval ",l.jsx(I,{tone:"warn",children:Y.capability})]}),action:l.jsxs("span",{className:"muted small",children:["proposed by ",Y.proposedBy]}),children:[l.jsx("p",{children:Y.reason}),Y.decision&&l.jsxs("p",{className:"small",children:["Chosen by the model ",l.jsxs("span",{className:"mono",children:[Y.decision.provider,Y.decision.model?` / ${Y.decision.model}`:""]})," (",Y.decision.runtime,") among the options the owner may take. A choice is a proposal, not evidence."]}),l.jsx(ci,{value:Y.input}),l.jsxs("p",{className:"muted small",children:["Runs as ",l.jsx("span",{className:"mono",children:A.owner}),", through ",Y.source==="application"?"the application’s AppPort dispatch":"AppPort Services",". You must be permitted to perform it yourself to approve it."]}),r&&l.jsxs("div",{className:"row",children:[l.jsxs("button",{className:"btn btn-primary",onClick:()=>E("approve",{actionId:Y.actionId}),children:["Approve as ",h]}),l.jsx("button",{className:"btn",onClick:()=>E("reject",{actionId:Y.actionId,reason:"rejected in Studio"}),children:"Reject"})]})]},Y.actionId)),be.map(Y=>l.jsxs(te,{title:l.jsxs("span",{className:"row",children:[jx(Y.state)," ",l.jsx(I,{tone:Y.state==="failed"?"bad":"warn",children:Y.capability})]}),action:l.jsxs("span",{className:"muted small",children:["attempt ",Y.attempt," · approved by ",Y.decidedBy??"—"]}),children:[l.jsx("p",{children:Y.reason}),Y.outcome?.error?l.jsxs("p",{className:"small mono",children:[Y.outcome.error.code,": ",Y.outcome.error.message]}):null,Y.interruption?l.jsxs("p",{className:"small",children:[String(Y.interruption).replace(/\.?$/,".")," Check the effect before settling it; it is never replayed automatically."]}):null,r&&Y.state==="failed"&&Ce&&l.jsx("div",{className:"row",children:l.jsx("button",{className:"btn",onClick:()=>E("retry",{actionId:Y.actionId}),children:"Retry (needs approval again)"})}),r&&Y.state==="interrupted"&&l.jsxs("div",{className:"row",children:[l.jsx("input",{className:"input grow",placeholder:"What you checked (recorded with your name)","aria-label":`What you checked for ${Y.actionId}`,value:x[Y.actionId]??"",onChange:de=>b(qe=>({...qe,[Y.actionId]:de.target.value}))}),l.jsx("button",{className:"btn",disabled:(x[Y.actionId]??"").trim().length<3,onClick:()=>E("resolve",{actionId:Y.actionId,outcome:"succeeded",note:x[Y.actionId]}),children:"It succeeded"}),l.jsx("button",{className:"btn",disabled:(x[Y.actionId]??"").trim().length<3,onClick:()=>E("resolve",{actionId:Y.actionId,outcome:"failed",note:x[Y.actionId]}),children:"It did not take effect"})]})]},Y.actionId)),l.jsx(te,{title:"Checkpoints",children:l.jsx("ol",{className:"timeline",children:X.slice().reverse().map(Y=>l.jsxs("li",{className:"timeline-item",children:[l.jsxs("div",{className:"row",children:[l.jsxs("strong",{children:["v",Y.version]})," ",l.jsx(I,{tone:jr(Y.status),children:Y.status})," ",l.jsxs("span",{className:"muted small",children:[Y.actor," · ",tt(Y.created_at)]})]}),l.jsx("p",{children:Y.summary}),Y.completed.length>0&&l.jsx("ul",{className:"small",children:Y.completed.map((de,qe)=>l.jsx("li",{className:"mono",children:de},qe))}),Y.decisions.length>0&&Y.version===X.length&&l.jsxs("details",{children:[l.jsxs("summary",{className:"small",children:["Decisions (",Y.decisions.length,")"]}),l.jsx("ul",{className:"small",children:Y.decisions.map((de,qe)=>l.jsx("li",{children:de},qe))})]}),Y.evidence.filter(de=>de.checkpoint_version===Y.version).map((de,qe)=>l.jsxs("div",{className:"small",children:["Evidence: ",de.kind==="record"?l.jsxs("a",{href:`#/activity/${de.id}`,className:"mono",children:[de.collection,"/",de.id]}):l.jsx("span",{className:"mono",children:de.uri})," ",de.verified?l.jsx(I,{tone:"ok",children:"verified at commit"}):l.jsx(I,{tone:"neutral",children:"unverified"})]},qe))]},Y.version))})})]})}function Sx(){const{version:i}=Bt(),[u,d]=k.useState(0),r=Le(()=>ne("/models"),[i,u]),h=Le(()=>ne("/overview"),[i]),{development:v,canAct:x}=Rs(h.data),[b,f]=k.useState(null),[y,j]=k.useState(!1);if(r.error)return l.jsx(ve,{error:r.error,retry:r.reload});if(!r.data)return l.jsx(Ze,{});const{status:g,catalog:R,intelligence:q,saved:V}=r.data,E=async()=>{j(!0),f(null);try{f(await ne("/models/test",{method:"POST",body:"{}"}))}catch(A){f({ok:!1,error:{message:A.message}})}finally{j(!1)}};return l.jsxs(l.Fragment,{children:[l.jsx(Ht,{title:"Models",subtitle:"The model that makes agent decisions in this environment. It chooses among the options your application offers and the task owner may take; its choice becomes a proposal, never an execution."}),l.jsxs(te,{title:l.jsxs("span",{className:"row",children:["Decision model ",g.ready?l.jsx(I,{tone:"ok",children:"ready"}):l.jsx(I,{tone:"bad",children:"not ready"})]}),action:x?l.jsx("button",{className:"btn",onClick:E,disabled:y||!g.ready,children:y?"Calling…":"Test"}):null,children:[l.jsx(xr,{rows:[["Source",g.source==="application"?"Application code (agent.decisions)":g.source==="intelligence"?"AppPort Services Intelligence (this environment)":"None"],["Provider",g.provider?l.jsxs("span",{className:"mono",children:[g.provider,g.protocol?` · ${g.protocol}`:""]}):"—"],["Model",g.model?l.jsx("span",{className:"mono",children:g.model}):"—"],["Endpoint",g.endpoint?l.jsx("span",{className:"mono",children:g.endpoint}):"—"],["API key",g.credential.ref?l.jsxs("span",{children:[l.jsx("span",{className:"mono",children:g.credential.ref})," ",l.jsx(Bs,{credential:g.credential})]}):g.credential.required?l.jsx(I,{tone:"bad",children:"required, none entered"}):"none needed"],["Runtime",g.runtime?l.jsxs("span",{className:"mono",children:[g.runtime.metadata.runtime," (",g.runtime.metadata.execution_method,")"]}):"—"],["Can decide",g.runtime?["binary","choice","score","batch","probability_distribution"].map(A=>l.jsxs(I,{tone:g.runtime.capabilities[A]?"ok":"neutral",children:[A.replace("_"," "),g.runtime.capabilities[A]?"":": no"]},A)):"—"]]}),g.problems.map(A=>l.jsxs("div",{className:"error-box",children:[l.jsx("strong",{children:A.message}),l.jsx("div",{className:"small",children:A.fix})]},A.problem)),b&&l.jsx("div",{className:b.ok?"ok-box":"error-box",children:b.ok?l.jsxs(l.Fragment,{children:[l.jsx("strong",{children:"The model answered"})," in ",b.durationMs," ms (",b.provider,", ",b.runtime.runtime,"): ",l.jsx(ci,{value:b.result})]}):l.jsxs(l.Fragment,{children:[l.jsx("strong",{children:b.error.message}),b.error.hint&&l.jsx("div",{className:"small",children:b.error.hint})]})})]}),q&&V.length>0&&l.jsx(Nx,{saved:V,development:v,overview:h.data,onChanged:()=>(f(null),d(A=>A+1))}),v&&q&&l.jsx(_x,{catalog:R,current:g,overview:h.data,onSaved:()=>d(A=>A+1)}),!v&&l.jsx(te,{children:l.jsxs("p",{className:"muted small",children:["Production: the model is selected on the host with ",l.jsx("code",{children:"feltkit model set --env production"}),"; keys live in the host’s environment as ",l.jsx("code",{children:"FELTKIT_CREDENTIAL_<ID>"})," (or in a vault the operator opted in to with ",l.jsx("code",{children:"FELTKIT_CREDENTIAL_VAULT=1"}),")."]})}),!q&&l.jsx(te,{children:l.jsxs("p",{className:"muted small",children:["The Intelligence service is not enabled for this application. Add ",l.jsx("code",{children:"intelligence: true"})," to ",l.jsx("code",{children:"services"})," in ",l.jsx("code",{children:"feltkit/app.ts"})," (new apps have it on); Studio reloads and you can choose a provider and enter its API key here. Alternatively pass ",l.jsx("code",{children:"agent.decisions"}),"."]})})]})}function Nx({saved:i,development:u,overview:d,onChanged:r}){const[h,v,x]=Cr(d),[b,f]=k.useState(null),[y,j]=k.useState(null),g=async(R,q,V)=>{f(null),j(R);try{await ne(q,V),r()}catch(E){f(E)}finally{j(null)}};return l.jsxs(te,{title:"Saved models",action:u?l.jsx(Or,{as:h,setAs:v,devUsers:x,label:"Switch as"}):null,children:[l.jsx("p",{className:"muted small",children:"The agent decides with the model in use. Keep others here to switch between providers and models; each keeps its own API key reference."}),b?l.jsx(ve,{error:b}):null,l.jsx("div",{className:"table-wrap",children:l.jsxs("table",{className:"table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:"Provider"}),l.jsx("th",{children:"Model"}),l.jsx("th",{children:"Endpoint"}),l.jsx("th",{children:"API key"}),l.jsx("th",{})]})}),l.jsx("tbody",{children:i.map(R=>l.jsxs("tr",{children:[l.jsx("td",{className:"mono",children:R.provider}),l.jsxs("td",{className:"mono",children:[R.model," ",R.active&&l.jsx(I,{tone:"ok",children:"in use"})]}),l.jsx("td",{className:"mono small",children:R.endpoint??l.jsx("span",{className:"muted",children:"default"})}),l.jsx("td",{className:"mono small",children:R.credentialRef??l.jsx("span",{className:"muted",children:"none"})}),l.jsx("td",{className:"row",children:u&&!R.active&&l.jsxs(l.Fragment,{children:[l.jsx("button",{className:"btn btn-small btn-primary",disabled:y!==null,onClick:()=>g(R.id,`/models/saved/${R.id}/use`,{method:"POST",body:JSON.stringify({as:h})}),children:y===R.id?"Switching…":"Use"}),l.jsx("button",{className:"btn btn-small",disabled:y!==null,onClick:()=>g(R.id,`/models/saved/${R.id}`,{method:"DELETE"}),children:"Forget"})]})})]},R.id))})]})})]})}function _x({catalog:i,current:u,overview:d,onSaved:r}){const[h,v]=k.useState(u.provider??i[0]?.id??""),x=i.find(z=>z.id===h),[b,f]=k.useState(u.model??""),[y,j]=k.useState(u.endpoint??""),[g,R]=k.useState(u.credential?.ref??""),[q,V]=k.useState(""),[E,A]=k.useState(!1),[X,ee]=k.useState(null),[w,K]=k.useState(null),[be,Ce]=k.useState(!1),[Y,de,qe]=Cr(d),it=x?x.credential!=="none":!1,Fe=`credential-ref:${h}`,Qe=g.trim()||Fe,Tt=u.credential?.ref===Qe?u.credential:null;k.useEffect(()=>{x&&x.modelSelection==="catalog"&&!x.models.includes(b)&&f(x.models[0]??"")},[h]);const ht=z=>{if(ui(z)){V(z.trim()),R(""),A(!0);return}R(z)},at=async z=>{ee(null),K(null),Ce(!0);const $=q;V(""),A(!1);try{const W=it?Qe:g.trim(),Ne={provider:h,model:b,...x?.customEndpoint&&y?{endpoint:y}:{},...W&&($||x?.credential==="required"||g.trim())?{credentialRef:W}:{},...$?{apiKey:$}:{},...Y?{as:Y}:{},...z?{}:{activate:!1}},Te=await ne("/models",{method:"POST",body:JSON.stringify(Ne)});K({...Te.stored??{},activate:z}),r()}catch(W){ee(W)}finally{Ce(!1)}};return l.jsxs(te,{title:"Add a model (development)",children:[X?l.jsx(ve,{error:X}):null,l.jsxs("div",{className:"form-grid",children:[l.jsxs("label",{children:["Provider",l.jsx("select",{className:"input",value:h,onChange:z=>v(z.target.value),"aria-label":"Provider",children:i.map(z=>l.jsxs("option",{value:z.id,children:[z.displayName," (",z.protocol,z.credential==="required"?", needs an API key":z.credential==="optional"?", API key optional":"",")"]},z.id))})]}),l.jsxs("label",{children:["Model",x?.modelSelection==="catalog"?l.jsx("select",{className:"input",value:b,onChange:z=>f(z.target.value),"aria-label":"Model",children:x.models.map(z=>l.jsx("option",{children:z},z))}):l.jsx("input",{className:"input",value:b,onChange:z=>f(z.target.value),placeholder:x?.models[0]??"model id","aria-label":"Model"})]}),x?.customEndpoint&&l.jsxs("label",{children:["Endpoint",l.jsx("input",{className:"input",value:y,onChange:z=>j(z.target.value),placeholder:x.endpoints[0]??"http://localhost:11434/v1","aria-label":"Endpoint"})]}),it&&l.jsxs("label",{children:["API key",x?.credential==="optional"?" (optional)":"",l.jsx("input",{className:"input",type:"password",autoComplete:"off",spellCheck:!1,value:q,onChange:z=>V(z.target.value),placeholder:Tt?.present?"Set — leave empty to keep it, or type a new key to replace it":"Paste your API key","aria-label":"API key"})]}),l.jsx(Or,{as:Y,setAs:de,devUsers:qe})]}),E&&l.jsx("div",{className:"ok-box small",children:"This looks like an API key — it will be stored securely, not in configuration."}),it&&l.jsxs("p",{className:"muted small",children:["The key is stored on the server in this environment’s custody (",u.credential?.location&&u.credential.source!=="environment"?u.credential.location:"the local encrypted vault","), outside FeltDB, and never shown again. An environment variable ",l.jsx("code",{children:Ex(Qe)})," overrides it.",Tt?.present?l.jsxs(l.Fragment,{children:[" ","Currently: ",l.jsx(Bs,{credential:Tt})]}):null]}),l.jsxs("details",{className:"schema",children:[l.jsx("summary",{children:"Advanced: credential reference"}),l.jsxs("label",{className:"small",children:["Reference (default ",l.jsx("code",{children:Fe}),")",l.jsx("input",{className:"input",value:g,onChange:z=>ht(z.target.value),placeholder:Fe,"aria-label":"Credential reference"})]}),l.jsxs("p",{className:"muted small",children:["A name for where the key is kept, such as ",l.jsx("code",{children:"credential-ref:openai"})," — not the key itself. Configuration stores only this name."]})]}),l.jsxs("div",{className:"row",children:[l.jsx("button",{className:"btn btn-primary",onClick:()=>at(!0),disabled:be||!h||!b,children:be?"Saving…":"Save and use"}),l.jsx("button",{className:"btn",onClick:()=>at(!1),disabled:be||!h||!b,children:"Save for later"}),w&&l.jsxs("span",{className:"muted small",children:["Saved",w.activate?" and in use":"; switch to it under Saved models",".",w.version?` API key: set (${w.location??"custody"}, version ${w.version}).`:"",w.activate?" Use “Test” above to call the model.":""]})]})]})}function Ex(i){return`FELTKIT_CREDENTIAL_${i.replace(/^credential-ref:/,"").replace(/[^A-Za-z0-9]/g,"_").toUpperCase()}`}const Tx=["GET","POST","PUT","PATCH","DELETE"],Ax=["string","number","integer","boolean","unknown"],tm=i=>i.map(u=>`${u.name}${u.required?"":"?"}${u.type==="string"?"":`:${u.type}`}`).join(", ");function kx(i){return i.split(",").map(u=>u.trim()).filter(Boolean).map(u=>{const[d="",r="string"]=u.split(":").map(v=>v.trim()),h=Ax.includes(r)?r:"string";return{name:d.replace(/\?$/,""),type:h,required:!d.endsWith("?")}})}const Cx=i=>{const d=[...i.path.matchAll(/\{([^}]+)\}/g)].map(r=>r[1]).filter(r=>!i.input.some(h=>h.name===r));return d.length?{...i,input:[...d.map(r=>({name:r,type:"string",required:!0})),...i.input]}:i},am=i=>i.toLowerCase().replace(/[^a-z0-9]+/g,"").replace(/^[0-9]+/,"")||"op";function Ox({overview:i,existing:u,onConnected:d,onClose:r}){const h=Object.keys(i?.roles??{}),[v,x,b]=Cr(i),[f,y]=k.useState("openapi"),[j,g]=k.useState(""),[R,q]=k.useState(""),[V,E]=k.useState(""),[A,X]=k.useState(""),[ee,w]=k.useState(""),[K,be]=k.useState("bearer"),[Ce,Y]=k.useState("X-API-Key"),[de,qe]=k.useState(""),[it,Fe]=k.useState([]),[Qe,Tt]=k.useState(h.filter(Q=>Q==="member"||Q==="admin")),[ht,at]=k.useState(null),[z,$]=k.useState(null),[W,Ne]=k.useState(null),Te=async()=>{$(null),at("read");try{const Q=await ne("/integrations/openapi",{method:"POST",body:JSON.stringify(j.trim()?{url:j.trim()}:{document:R})});E(Q.name),X(Q.description??Q.title??""),w(Q.baseUrl??""),Fe(Q.operations.map(le=>({...le,include:!0})))}catch(Q){$(Q)}finally{at(null)}},_=()=>Fe([...it,{include:!0,name:"",method:"GET",path:"/",access:`${V||"api"}.read`,input:[]}]),B=(Q,le)=>Fe(it.map((re,Oe)=>{if(Oe!==Q)return re;const ta={...re,...le},ca=V||"api";return le.method&&re.access===`${ca}.${re.method==="GET"?"read":"write"}`&&(ta.access=`${ca}.${le.method==="GET"?"read":"write"}`),ta})),Z=Q=>{const le=Q.toLowerCase().replace(/[^a-z0-9]/g,""),re=`${V||"api"}.`;Fe(it.map(Oe=>Oe.access.startsWith(re)?{...Oe,access:`${le||"api"}.${Oe.access.slice(re.length)}`}:Oe)),E(le)},J=it.filter(Q=>Q.include),ce=async()=>{$(null),at("connect");const Q=de;qe("");try{const le={name:V,...A.trim()?{description:A.trim()}:{},baseUrl:ee.trim(),auth:K==="header"?{kind:"header",header:Ce}:{kind:K},operations:J.map(({include:Oe,...ta})=>{const ca=Cx({...ta,include:!0}),{include:ri,...pl}=ca;return{...pl,name:am(pl.name),effect:pl.method==="GET"?"observation":"consequential"}})},re=await ne("/integrations/connect",{method:"POST",body:JSON.stringify({integration:le,roles:Qe,...Q?{apiKey:Q,as:v}:{}})});Ne(re),d()}catch(le){$(le)}finally{at(null)}};return W?l.jsxs(te,{title:`Connected ${V}`,children:[l.jsxs("div",{className:"ok-box small",children:["Wrote ",l.jsx("code",{children:W.file}),W.granted.length?l.jsxs(l.Fragment,{children:[" ","and granted ",l.jsxs("code",{children:[V,".*"]})," to ",W.granted.join(", ")," in ",l.jsx("code",{children:"feltkit/app.ts"})]}):null,". The server reloads and publishes its operations below as capabilities.",W.stored?` The API key is stored (version ${W.stored.version}) and is never shown again.`:""]}),W.skipped.length>0&&l.jsxs("p",{className:"small",children:["Not granted to ",W.skipped.join(", "),": add ",l.jsxs("code",{children:['"',V,'.*"']})," to their permissions in ",l.jsx("code",{children:"feltkit/app.ts"}),"."]}),l.jsxs("ul",{className:"small",children:[l.jsxs("li",{children:["Narrow each operation's ",l.jsx("code",{children:"output"})," in ",l.jsx("code",{children:W.file})," to what the API returns: AppPort checks every response against it."]}),l.jsxs("li",{children:["For consequential operations, add ",l.jsx("code",{children:"idempotencyHeader"})," if the API deduplicates, and ",l.jsx("code",{children:"verify"})," so an unknown outcome can be settled without resending."]}),l.jsxs("li",{children:["In production set ",l.jsxs("code",{children:[V.toUpperCase(),"_URL"]}),W.credential?l.jsxs(l.Fragment,{children:[" ","and ",l.jsxs("code",{children:["FELTKIT_CREDENTIAL_",V.toUpperCase()]})]}):null," ","on the host."]})]}),l.jsxs("span",{className:"row",children:[l.jsx("button",{className:"btn btn-primary",onClick:r,children:"Done"}),l.jsx("button",{className:"btn",onClick:()=>(Ne(null),Fe([]),E(""),g(""),q("")),children:"Connect another"})]})]}):l.jsxs(te,{title:"Connect an API",children:[l.jsxs("p",{className:"small",children:["Connect a service your app calls: each operation becomes an AppPort capability your functions, agents, and other apps can use, with its permission, effect, and every call recorded. This writes ",l.jsx("code",{children:"feltkit/<name>.ts"}),", which you own and can edit."]}),l.jsxs("div",{className:"tabs",role:"tablist",children:[l.jsx("button",{className:f==="openapi"?"active":"",onClick:()=>y("openapi"),role:"tab","aria-selected":f==="openapi",children:"From an OpenAPI document"}),l.jsx("button",{className:f==="manual"?"active":"",onClick:()=>(y("manual"),it.length===0&&_()),role:"tab","aria-selected":f==="manual",children:"Describe it yourself"})]}),f==="openapi"&&l.jsxs("div",{className:"form",style:{maxWidth:"none",marginTop:12},children:[l.jsxs("label",{children:[l.jsx("span",{children:"Document URL"}),l.jsx("input",{className:"input",type:"url",value:j,onChange:Q=>g(Q.target.value),placeholder:"https://api.example.com/openapi.json"})]}),l.jsxs("label",{children:[l.jsx("span",{children:"…or paste it (JSON)"}),l.jsx("textarea",{className:"input code-input",rows:4,value:R,onChange:Q=>q(Q.target.value),placeholder:'{"openapi": "3.0.0", "paths": { … }}'})]}),l.jsx("div",{children:l.jsx("button",{className:"btn btn-primary",onClick:Te,disabled:ht!==null||!j.trim()&&!R.trim(),children:ht==="read"?"Reading…":"Read operations"})})]}),z?l.jsx(ve,{error:z}):null,(it.length>0||f==="manual")&&l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"form-grid",style:{marginTop:12},children:[l.jsxs("label",{children:[l.jsx("span",{children:"Name *"}),l.jsx("input",{className:"input",value:V,onChange:Q=>Z(Q.target.value),placeholder:"crm"}),l.jsx("span",{className:"muted small",children:u.includes(V)?"Already connected: choose another name.":`Capabilities are ${V||"<name>"}.<operation>.`})]}),l.jsxs("label",{children:[l.jsx("span",{children:"Base URL *"}),l.jsx("input",{className:"input",type:"url",value:ee,onChange:Q=>w(Q.target.value),placeholder:"https://api.example.com"}),l.jsxs("span",{className:"muted small",children:["Used in development; production reads ",V?`${V.toUpperCase()}_URL`:"<NAME>_URL","."]})]}),l.jsxs("label",{children:[l.jsx("span",{children:"Description"}),l.jsx("input",{className:"input",value:A,onChange:Q=>X(Q.target.value)})]}),l.jsxs("label",{children:[l.jsx("span",{children:"API key"}),l.jsxs("select",{className:"input",value:K,onChange:Q=>be(Q.target.value),children:[l.jsx("option",{value:"bearer",children:"Sent as Authorization: Bearer"}),l.jsx("option",{value:"header",children:"Sent in a header"}),l.jsx("option",{value:"none",children:"No key"})]})]}),K==="header"&&l.jsxs("label",{children:[l.jsx("span",{children:"Header"}),l.jsx("input",{className:"input",value:Ce,onChange:Q=>Y(Q.target.value)})]}),K!=="none"&&l.jsxs("label",{children:[l.jsx("span",{children:"Key value (optional now)"}),l.jsx("input",{className:"input",type:"password",autoComplete:"off",spellCheck:!1,value:de,onChange:Q=>qe(Q.target.value),placeholder:"Stored securely; never shown again"}),de&&!ui(de)&&de.length<8?l.jsx("span",{className:"muted small",children:"That looks short for a key."}):null]}),K!=="none"&&de&&l.jsx(Or,{as:v,setAs:x,devUsers:b,label:"Store as"})]}),l.jsx("div",{className:"table-wrap",style:{marginTop:8},children:l.jsxs("table",{className:"table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{}),l.jsx("th",{children:"Operation"}),l.jsx("th",{children:"Method"}),l.jsx("th",{children:"Path"}),l.jsx("th",{children:"Input (name?:type)"}),l.jsx("th",{children:"Permission"}),l.jsx("th",{children:"Effect"})]})}),l.jsx("tbody",{children:it.map((Q,le)=>l.jsxs("tr",{children:[l.jsx("td",{children:l.jsx("input",{type:"checkbox",checked:Q.include,onChange:re=>B(le,{include:re.target.checked}),"aria-label":`Include ${Q.name}`})}),l.jsx("td",{children:l.jsx("input",{className:"input",value:Q.name,onChange:re=>B(le,{name:am(re.target.value)}),placeholder:"listcontacts","aria-label":"Operation name",title:Q.description})}),l.jsx("td",{children:l.jsx("select",{className:"input",value:Q.method,onChange:re=>B(le,{method:re.target.value}),"aria-label":"Method",children:Tx.map(re=>l.jsx("option",{children:re},re))})}),l.jsx("td",{children:l.jsx("input",{className:"input mono",value:Q.path,onChange:re=>B(le,{path:re.target.value}),"aria-label":"Path"})}),l.jsx("td",{children:l.jsx("input",{className:"input mono",defaultValue:tm(Q.input),onBlur:re=>B(le,{input:kx(re.target.value)}),placeholder:"id, amount:number, note?","aria-label":"Input fields"},tm(Q.input))}),l.jsx("td",{children:l.jsx("input",{className:"input mono",value:Q.access,onChange:re=>B(le,{access:re.target.value}),"aria-label":"Permission"})}),l.jsx("td",{className:"small",children:Q.method==="GET"?"observation":"consequential"})]},le))})]})}),l.jsxs("div",{className:"row",style:{marginTop:8},children:[l.jsx("button",{className:"btn btn-small",onClick:_,children:"Add operation"}),l.jsx("span",{className:"muted small",children:"GET reads (observation); other methods may change the API (consequential). An unknown outcome is never re-sent."})]}),h.length>0&&l.jsxs("div",{className:"choices",style:{marginTop:12},children:[l.jsxs("span",{className:"small",children:["Grant ",l.jsxs("code",{children:[V||"<name>",".*"]})," to:"]}),h.map(Q=>l.jsxs("label",{className:"check",children:[l.jsx("input",{type:"checkbox",checked:Qe.includes(Q),onChange:le=>Tt(le.target.checked?[...Qe,Q]:Qe.filter(re=>re!==Q))}),Q]},Q))]}),l.jsxs("div",{className:"row",style:{marginTop:12},children:[l.jsx("button",{className:"btn btn-primary",onClick:ce,disabled:ht!==null||!V||!ee.trim()||J.length===0||u.includes(V),children:ht==="connect"?"Connecting…":`Connect ${J.length} operation${J.length===1?"":"s"}`}),V&&l.jsx(rn,{text:`feltkit/${V}.ts`,label:"Copy file path"})]})]})]})}const zx=i=>i==="succeeded"?"ok":i==="failed"?"bad":"warn";function Dx(){const{version:i}=Bt(),[u,d]=k.useState(0),r=Le(()=>ne("/integrations"),[i,u]),h=Le(()=>ne("/overview"),[i]),{development:v,canAct:x}=Rs(h.data),f=(h.data?.devUsers??[])[0]?.id??"",[y,j]=k.useState({}),[g,R]=k.useState(!1),[q,V]=k.useState(null);if(r.error)return l.jsx(ve,{error:r.error,retry:r.reload});if(!r.data)return l.jsx(Ze,{});const{integrations:E,calls:A}=r.data,X=async w=>{V(null);try{const K=await ne(`/integrations/${encodeURIComponent(w)}/check`,{method:"POST",body:"{}"});j(be=>({...be,[w]:K}))}catch(K){V(K)}},ee=async w=>{V(null);try{await ne(`/integrations/calls/${encodeURIComponent(w)}/verify`,{method:"POST",body:JSON.stringify(v?{as:f}:{})}),d(K=>K+1)}catch(K){V(K)}};return l.jsxs(l.Fragment,{children:[l.jsx(Ht,{title:"Integrations",subtitle:"Existing APIs, published as AppPort capabilities: what each operation does, who may invoke it, whether repeating it is safe, and how its outcome is verified. Seeing an operation grants nothing.",actions:v&&E.length>0&&!g?l.jsx("button",{className:"btn btn-primary",onClick:()=>R(!0),children:"Connect an API"}):null}),q?l.jsx(ve,{error:q}):null,v&&(g||E.length===0)&&l.jsx(Ox,{overview:h.data,existing:E.map(w=>w.name),onConnected:()=>(R(!0),d(w=>w+1)),onClose:()=>R(!1)}),E.length===0?!v&&l.jsxs(qt,{title:"No integrations yet",children:["Connect an API in development (Studio → Integrations), or with ",l.jsxs("code",{children:['app.integration("payments", ',"{"," baseUrl, credential, operations ","}",")"]})," in ",l.jsx("code",{children:"feltkit/"}),"."]}):E.map(w=>l.jsxs(te,{title:l.jsxs("span",{className:"row",children:[w.name," ",w.problems.length?l.jsx(I,{tone:"bad",children:"not configured"}):l.jsx(I,{tone:"ok",children:"configured"})]}),action:x&&w.health?l.jsx("button",{className:"btn",onClick:()=>X(w.name),children:"Check"}):null,children:[w.description&&l.jsx("p",{children:w.description}),l.jsxs("p",{className:"small",children:[l.jsx("span",{className:"mono",children:w.baseUrl.value??"—"})," ",l.jsxs("span",{className:"muted",children:["(",w.baseUrl.source,w.baseUrl.variable?` ${w.baseUrl.variable}`:"",")"]}),w.credential&&l.jsxs(l.Fragment,{children:[" · ",l.jsx("span",{className:"mono",children:w.credential.ref})," ",l.jsx(Bs,{credential:w.credential})," ",x&&w.credential.writable&&l.jsx(zs,{credentialRef:w.credential.ref,label:w.credential.present?"Replace key":"Set key",...v&&f?{as:f}:{},onSaved:()=>d(K=>K+1)}),!w.credential.writable&&!w.credential.present&&l.jsxs("span",{className:"muted small",children:[" set ",w.credential.variable," on the host"]})]})]}),w.problems.map((K,be)=>l.jsxs("div",{className:"error-box",children:[l.jsx("strong",{children:K.message}),l.jsx("div",{className:"small",children:K.fix})]},be)),y[w.name]&&l.jsx("div",{className:y[w.name].ok?"ok-box":"error-box",children:y[w.name].message}),l.jsx("div",{className:"table-wrap",children:l.jsxs("table",{className:"table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:"Capability"}),l.jsx("th",{children:"Request"}),l.jsx("th",{children:"Effect"}),l.jsx("th",{children:"Who may invoke"}),l.jsx("th",{children:"Repeat"}),l.jsx("th",{children:"Outcome unknown →"})]})}),l.jsx("tbody",{children:w.operations.map(K=>l.jsxs("tr",{children:[l.jsx("td",{className:"mono",children:K.capability}),l.jsxs("td",{className:"mono small",children:[K.method," ",K.path]}),l.jsx("td",{children:K.effect==="consequential"?l.jsx(I,{tone:"warn",children:"consequential"}):l.jsx(I,{children:"observation"})}),l.jsx("td",{className:"mono small",children:K.access}),l.jsx("td",{className:"small",children:K.effect==="observation"?"safe":K.idempotent?"deduplicated by the API":"may duplicate"}),l.jsx("td",{className:"small",children:K.effect==="observation"?"—":K.verifiable?"verify, never re-send":"a person settles it"})]},K.capability))})]})})]},w.name)),l.jsxs(te,{title:"Calls",children:[A.length===0?l.jsx("p",{className:"muted small",children:"No calls yet."}):l.jsx("div",{className:"table-wrap",children:l.jsxs("table",{className:"table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:"Capability"}),l.jsx("th",{children:"State"}),l.jsx("th",{children:"How known"}),l.jsx("th",{children:"As"}),l.jsx("th",{children:"HTTP"}),l.jsx("th",{children:"Detail"}),l.jsx("th",{children:"When"}),l.jsx("th",{})]})}),l.jsx("tbody",{children:A.map(w=>l.jsxs("tr",{children:[l.jsx("td",{className:"mono small",children:w.capability}),l.jsx("td",{children:l.jsx(I,{tone:zx(w.state),children:w.state==="started"?"unknown (no outcome recorded)":w.state})}),l.jsxs("td",{className:"small",children:[w.determinedBy??"—",w.verification?` (${w.verification.outcome})`:""]}),l.jsx("td",{className:"mono small",children:w.principal.id}),l.jsx("td",{children:w.status??""}),l.jsx("td",{className:"small error-text",children:w.error?.message??""}),l.jsx("td",{className:"muted small",children:tt(w.startedAt)}),l.jsx("td",{children:x&&(w.state==="unknown"||w.state==="started")&&l.jsx("button",{className:"btn btn-small",onClick:()=>ee(w.id),disabled:v&&!f,children:"Verify"})})]},w.id))})]})}),l.jsx("p",{className:"muted small",children:"A call is recorded before it is sent. “Verify” reads the API’s own state through the declared probe; it never sends the request again."})]})]})}const lm={pass:"ok",fail:"bad",warn:"warn",external:"neutral"},nm={pass:"verified",fail:"fails",warn:"review",external:"outside FeltKit"};function wx(){const{version:i}=Bt(),u=Le(()=>ne("/readiness"),[i]);if(u.error)return l.jsx(ve,{error:u.error,retry:u.reload});if(!u.data)return l.jsx(Ze,{label:"Checking this environment"});const d=u.data,r=[...new Set(d.checks.map(h=>h.area))];return l.jsxs(l.Fragment,{children:[l.jsx(Ht,{title:"Readiness",subtitle:"Real checks of this environment, not a status anyone sets. Passing checks mean the checked things are in place; the operational requirements at the end are yours to meet.",actions:l.jsx("button",{className:"btn",onClick:u.reload,children:"Check again"})}),l.jsxs(te,{children:[l.jsx("p",{children:l.jsx("strong",{children:d.summary})}),l.jsx("div",{className:"row",children:["fail","warn","pass","external"].map(h=>l.jsxs(I,{tone:lm[h],children:[d.counts[h]," ",nm[h]]},h))}),l.jsxs("p",{className:"muted small",children:["The same report: ",l.jsxs("code",{children:["npx feltkit readiness --env ",d.environment.name]}),"."]})]}),r.map(h=>l.jsx(te,{title:h,children:l.jsx("ul",{className:"checks",children:d.checks.filter(v=>v.area===h).map(v=>l.jsxs("li",{className:"check",children:[l.jsx(I,{tone:lm[v.status],children:nm[v.status]})," ",l.jsx("strong",{children:v.title}),l.jsx("div",{className:"small",children:v.detail}),v.fix&&v.status!=="pass"&&l.jsxs("div",{className:"small muted",children:["→ ",v.fix]})]},v.id))})},h))]})}const Rx=new Set(["service_effect_evidence"]),Rm=k.createContext({live:!1,version:0,changed:{},activity:[],overview:void 0,reloadOverview(){}}),Bt=()=>k.useContext(Rm),pr=[{id:"overview",label:"Overview",key:"1"},{id:"data",label:"Data",key:"2"},{id:"capabilities",label:"Capabilities",key:"3"},{id:"services",label:"Services",key:"4"},{id:"agent",label:"Agent",key:"5"},{id:"models",label:"Models",key:"m"},{id:"integrations",label:"Integrations",key:"i"},{id:"readiness",label:"Readiness",key:"r"},{id:"activity",label:"Activity",key:"6"},{id:"settings",label:"Settings",key:"7"},{id:"projects",label:"Projects",key:"8"}],im=["data","settings","projects"];function sm(){const i=location.hash.replace(/^#\/?/,"").split("/").filter(Boolean).map(decodeURIComponent);return{route:pr.find(d=>d.id===i[0])?.id??"overview",rest:i.slice(1)}}function yt(i){location.hash=`#/${i}`}const Mx={overview:l.jsx("path",{d:"M3 10.5 10 4l7 6.5V17a1 1 0 0 1-1 1h-4v-5H8v5H4a1 1 0 0 1-1-1z"}),data:l.jsxs(l.Fragment,{children:[l.jsx("ellipse",{cx:"10",cy:"5",rx:"6.5",ry:"2.5"}),l.jsx("path",{d:"M3.5 5v10c0 1.4 2.9 2.5 6.5 2.5s6.5-1.1 6.5-2.5V5M3.5 10c0 1.4 2.9 2.5 6.5 2.5s6.5-1.1 6.5-2.5"})]}),capabilities:l.jsx("path",{d:"M7 3h6v4l3 3-3 3v4H7v-4l-3-3 3-3z"}),models:l.jsx("path",{d:"M10 3a4 4 0 0 1 4 4v1a3 3 0 0 1 0 6v1a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2v-1a3 3 0 0 1 0-6V7a4 4 0 0 1 4-4zM8 10h.01M12 10h.01"}),integrations:l.jsx("path",{d:"M7 7h-2a3 3 0 0 0 0 6h2M13 7h2a3 3 0 0 1 0 6h-2M7 10h6"}),readiness:l.jsx("path",{d:"M4 10.5 8 14.5 16 5.5"}),services:l.jsxs(l.Fragment,{children:[l.jsx("rect",{x:"3",y:"3",width:"6",height:"6",rx:"1.5"}),l.jsx("rect",{x:"11",y:"3",width:"6",height:"6",rx:"1.5"}),l.jsx("rect",{x:"3",y:"11",width:"6",height:"6",rx:"1.5"}),l.jsx("rect",{x:"11",y:"11",width:"6",height:"6",rx:"1.5"})]}),agent:l.jsx("path",{d:"M10 3a3 3 0 0 1 3 3v1h1.5A1.5 1.5 0 0 1 16 8.5v6a1.5 1.5 0 0 1-1.5 1.5h-9A1.5 1.5 0 0 1 4 14.5v-6A1.5 1.5 0 0 1 5.5 7H7V6a3 3 0 0 1 3-3zM8 11h.01M12 11h.01M8 14h4"}),activity:l.jsx("path",{d:"M2 10h4l2-5 4 10 2-5h4"}),settings:l.jsxs(l.Fragment,{children:[l.jsx("circle",{cx:"10",cy:"10",r:"2.5"}),l.jsx("path",{d:"M10 2.5v2M10 15.5v2M2.5 10h2M15.5 10h2M4.7 4.7l1.4 1.4M13.9 13.9l1.4 1.4M4.7 15.3l1.4-1.4M13.9 6.1l1.4-1.4"})]}),projects:l.jsx(l.Fragment,{children:l.jsx("path",{d:"M3 6.5A1.5 1.5 0 0 1 4.5 5H8l1.5 2h6A1.5 1.5 0 0 1 17 8.5v6A1.5 1.5 0 0 1 15.5 16h-11A1.5 1.5 0 0 1 3 14.5z"})})};function Ux({route:i}){return l.jsx("svg",{viewBox:"0 0 20 20",width:"18",height:"18",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:Mx[i]})}function qx(){const[i,u]=k.useState("loading"),[d,r]=k.useState("");return k.useEffect(()=>{fetch("/api/session",{credentials:"same-origin"}).then(h=>h.json()).then(h=>{r(h?.environment?.name??""),u(h?.environment?.production?"production":"development")}).catch(()=>u("development"))},[]),i==="loading"?l.jsx(Ze,{label:"Connecting"}):i==="production"?l.jsx(Bx,{environment:d}):l.jsx(Yx,{})}function Hx(){const i=/(?:^|[#&])grant=([^&]+)/.exec(location.hash);if(!i)return null;history.replaceState(null,"",`${location.pathname}#/overview`);try{return decodeURIComponent(i[1])}catch{return null}}function Bx({environment:i}){const[u,d]=k.useState("checking"),[r,h]=k.useState(null),[v]=k.useState(Hx),x=f=>{f?.operator&&f?.csrf?(or({csrf:f.csrf,environment:i}),d("signed-in")):(or(null),d("signed-out"))},b=async f=>{h(null);try{const y=await fetch("/_feltkit/api/operator/signin",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json","x-feltkit-environment":i},body:JSON.stringify({grant:f})}),j=await y.json();if(!y.ok)throw new Error(j?.error?.message??`Sign-in failed (${y.status})`);x(j)}catch(y){h(`${y.message}${v===f?" The link works once and expires after 10 minutes: run `npx feltkit manage` for a new one.":""}`),d("signed-out")}};return k.useEffect(()=>{v?b(v):ne("/operator/session").then(x,()=>d("signed-out"))},[]),u==="checking"?l.jsx(Ze,{label:v?"Signing you in":"Checking your operator session"}):u==="signed-in"?l.jsx(Mm,{onSignOut:()=>{ne("/operator/signout",{method:"POST",body:"{}"}).catch(()=>{}).finally(()=>(or(null),d("signed-out")))}}):l.jsx(Lx,{environment:i,...r?{error:r}:{},onGrant:f=>{b(f)}})}function Lx({environment:i,onGrant:u,error:d}){const[r,h]=k.useState("");return l.jsx("div",{className:"gate",children:l.jsxs("div",{className:"gate-card",children:[l.jsx(zr,{}),l.jsxs("h1",{children:["Sign in to ",i," Studio"]}),l.jsxs("p",{className:"muted",children:["Production Studio is for operators. In your project folder, run ",l.jsx("code",{children:"npx feltkit manage"})," and open the one-time link it prints (or paste the grant from"," ",l.jsx("code",{children:"npx feltkit operator grant --id <you> --role <role>"})," here). Everything you do is authorized and recorded as you."]}),d&&l.jsx("p",{className:"error-text",children:d}),l.jsxs("form",{onSubmit:v=>{v.preventDefault(),r.trim()&&u(r.trim())},className:"row",children:[l.jsx("input",{className:"input grow",value:r,onChange:v=>h(v.target.value),placeholder:"fkg1.…","aria-label":"Operator grant",autoFocus:!0}),l.jsx("button",{className:"btn btn-primary",type:"submit",children:"Sign in"})]})]})})}function Yx(){const[i,u]=k.useState(()=>{const h=vg();return rr(h),h}),[d,r]=k.useState(!1);return i?l.jsx(Mm,{onSignOut:h=>(rr(null),Qh(null),r(!!h),u(null))}):l.jsx(Gx,{...d?{error:"That admin token was not accepted. A new one is generated if .feltkit/<env>/admin-token is deleted."}:{},onToken:h=>(rr(h),Qh(h),r(!1),u(h))})}function Gx({onToken:i,error:u}){const[d,r]=k.useState("");return l.jsx("div",{className:"gate",children:l.jsxs("div",{className:"gate-card",children:[l.jsx(zr,{}),l.jsx("h1",{children:"Open the FeltKit dashboard"}),l.jsxs("p",{className:"muted",children:["The dashboard needs this environment’s admin token. Use the ",l.jsx("strong",{children:"Dashboard"})," link that ",l.jsx("code",{children:"feltkit dev"})," prints — it contains the token — or paste the token from ",l.jsx("code",{children:".feltkit/development/admin-token"}),"."]}),u&&l.jsx("p",{className:"error-text",children:u}),l.jsxs("form",{onSubmit:h=>{h.preventDefault(),d.trim()&&i(d.trim())},className:"row",children:[l.jsx("input",{className:"input grow",value:d,onChange:h=>r(h.target.value),placeholder:"fka_…","aria-label":"Admin token",autoFocus:!0}),l.jsx("button",{className:"btn btn-primary",type:"submit",children:"Continue"})]})]})})}function zr(){return l.jsx("span",{className:"logo",children:l.jsx("img",{src:Nb,width:"28",height:"28",alt:"FeltKit"})})}function Mm({onSignOut:i}){const[{route:u,rest:d},r]=k.useState(sm),[h,v]=k.useState(!1),[x,b]=k.useState(0),[f,y]=k.useState({}),[j,g]=k.useState([]),R=Le(()=>ne("/overview"),[x]),q=k.useRef(null);k.useEffect(()=>{const ee=()=>r(sm());return window.addEventListener("hashchange",ee),()=>window.removeEventListener("hashchange",ee)},[]),k.useEffect(()=>yg((ee,w)=>{ee==="activity"&&g(K=>[w,...K].slice(0,200)),!(ee==="change"&&(y(K=>{const be={...K};for(const Ce of w.collections)be[Ce]=(be[Ce]??0)+1;return be}),w.collections.every(K=>Rx.has(K))))&&q.current===null&&(q.current=window.setTimeout(()=>{q.current=null,b(K=>K+1)},250))},v),[]),k.useEffect(()=>{const ee=w=>{const K=w.target;if(w.metaKey||w.ctrlKey||w.altKey||["INPUT","TEXTAREA","SELECT"].includes(K.tagName)||K.isContentEditable)return;const be=pr.find(Ce=>Ce.key===w.key);be&&yt(be.id)};return window.addEventListener("keydown",ee),()=>window.removeEventListener("keydown",ee)},[]);const V=k.useMemo(()=>({live:h,version:x,changed:f,activity:j,overview:R.data,reloadOverview:R.reload}),[h,x,f,j,R.data,R.reload]),E=R.error?.status===401;k.useEffect(()=>{E&&i(!0)},[E,i]);const A=R.data,X=A?.environment?.production;return l.jsx(Rm.Provider,{value:V,children:l.jsxs("div",{className:"app",children:[l.jsxs("nav",{className:"nav","aria-label":"Dashboard",children:[l.jsxs("div",{className:"nav-brand",children:[l.jsx(zr,{}),l.jsxs("div",{children:[l.jsx("div",{className:"nav-app",children:A?.application?.name??"…"}),l.jsx("div",{className:"nav-sub",children:"FeltKit"})]})]}),l.jsx("ul",{children:pr.filter(ee=>!X||!im.includes(ee.id)).map(ee=>{const w=u===ee.id&&!(ee.id==="services"&&d[0]);return l.jsxs("li",{children:[l.jsxs("a",{href:`#/${ee.id}`,className:w?"active":u===ee.id?"within":"","aria-current":w?"page":void 0,children:[l.jsx(Ux,{route:ee.id}),l.jsx("span",{children:ee.label}),l.jsx("kbd",{children:ee.key})]}),ee.id==="services"&&l.jsx(Vx,{services:A?.services??[],current:u==="services"?d[0]:void 0})]},ee.id)})}),l.jsxs("div",{className:"nav-foot",children:[l.jsxs("div",{className:`live ${h?"on":""}`,children:[l.jsx("span",{className:"dot"})," ",h?"Live":"Reconnecting"]}),l.jsx(Sb,{}),l.jsxs("a",{className:"nav-family",href:"https://boundry.company",target:"_blank",rel:"noreferrer",children:[l.jsx(gb,{idPrefix:"nav-family-mark"})," A Boundry product"]}),l.jsx("button",{className:"btn btn-ghost btn-small",onClick:()=>i(),title:A?.operator?"Sign out of production Studio":"Forget the admin token in this tab",children:A?.operator?"Sign out":"Lock"})]})]}),l.jsxs("div",{className:"content",children:[A&&l.jsxs("div",{className:`envbar ${X?"envbar-prod":""}`,children:[l.jsx("span",{className:"envname",children:A.environment.name}),l.jsxs("span",{className:"muted",children:["FeltDB ",A.instance.feltdbVersion," · ",A.instance.mode," · "]}),l.jsx("code",{className:"path",title:A.instance.location,children:A.instance.location}),X?l.jsxs("span",{className:"envwarn",children:["Production · signed in as ",l.jsx("strong",{children:A.operator?.principal?.id})," (",(A.operator?.principal?.roles??[]).join(", "),") · actions run on this environment only"]}):l.jsx("span",{className:"muted",children:"Development tools enabled"})]}),l.jsx("main",{className:"page",children:R.loading&&!A?l.jsx(Ze,{label:"Connecting to the runtime"}):A?l.jsx(Qx,{route:X&&im.includes(u)?"overview":u,rest:d}):l.jsxs("div",{className:"error-box",children:["The runtime did not answer: ",R.error?.message]})})]})]})})}const cm={configured:"ok",unconfigured:"warn",unhealthy:"bad",unavailable:"bad",available:"off"},um="feltkit.nav.services";function Vx({services:i,current:u}){const[d,r]=k.useState(()=>{try{return localStorage.getItem(um)!=="closed"}catch{return!0}}),h=()=>{r(!d);try{localStorage.setItem(um,d?"closed":"open")}catch{}};if(!i.length)return null;const v=i.filter(f=>f.state!=="available"&&f.state!=="unavailable"),x=i.filter(f=>f.state==="available"||f.state==="unavailable"),b=(f,y,j)=>l.jsx("li",{children:l.jsxs("a",{href:`#/services/${f}`,className:u===f?"active":"","aria-current":u===f?"page":void 0,children:[l.jsx("span",{className:`nav-dot nav-dot-${j??"none"}`,"aria-hidden":!0}),l.jsx("span",{children:y})]})},f);return l.jsxs(l.Fragment,{children:[l.jsx("button",{className:"nav-toggle",onClick:h,"aria-expanded":d||!!u,"aria-label":d?"Hide services":"Show services",children:d||u?"▾":"▸"}),(d||u)&&l.jsxs("ul",{className:"nav-children","aria-label":"Services",children:[v.map(f=>b(f.id,f.name,cm[f.state])),b("credentials","Credentials"),x.length>0&&l.jsx("li",{className:"nav-group",children:"Not enabled"}),x.map(f=>b(f.id,f.name,cm[f.state]))]})]})}function Qx({route:i,rest:u}){switch(i){case"data":return l.jsx(ex,{collection:u[0]});case"capabilities":return l.jsx(cx,{selected:u[0]});case"services":return l.jsx(Zb,{page:u[0]});case"agent":return l.jsx(bx,{rest:u});case"models":return l.jsx(Sx,{});case"integrations":return l.jsx(Dx,{});case"readiness":return l.jsx(wx,{});case"activity":return l.jsx(fx,{selected:u[0]});case"settings":return l.jsx(vx,{});case"projects":return l.jsx(gx,{});default:return l.jsx(Pb,{})}}function Ht({title:i,subtitle:u,actions:d}){return l.jsxs("header",{className:"page-header",children:[l.jsxs("div",{children:[l.jsx("h1",{children:i}),u&&l.jsx("p",{className:"muted",children:u})]}),d&&l.jsx("div",{className:"actions",children:d})]})}mg.createRoot(document.getElementById("root")).render(l.jsx(k.StrictMode,{children:l.jsx(qx,{})}));
15
+ npm run dev`})})]})}const mr=[{id:"inspect-app",label:"Inspect the application",help:"Capabilities you may use, unhealthy services, recent errors and denials."},{id:"diagnose-job",label:"Diagnose a job",help:"Read the job, its runs and error; propose a retry when it can help.",target:"Job id"},{id:"diagnose-delivery",label:"Diagnose a webhook delivery",help:"Read the delivery, endpoint, and signing credential; propose a replay when it can help.",target:"Delivery id"},{id:"invoke",label:"Run a capability",help:"One capability: observations run now, consequential ones wait for approval."},{id:"handoff",label:"Hand off to a coding agent",help:"Open-ended work. A coding agent claims it over MCP (feltkit_agent_claim) and proposes actions; you approve them here."}],jr=i=>i==="completed"?"ok":i==="cancelled"?"neutral":i==="blocked"?"warn":"info";function xx({rest:i}){const{version:u}=Bt(),d=Le(()=>ne("/overview"),[u]),r=d.data?.devUsers??[],h=!!d.data?.environment?.development,{canAct:v,actor:x}=Rs(d.data),[b,f]=k.useState("");k.useEffect(()=>{!b&&r[0]&&f(r[0].id)},[r,b]);const y=Le(()=>ne(`/agent${b?`?as=${encodeURIComponent(b)}`:""}`),[u,b]),j=i[0]&&i[0]!=="new"?i[0]:null;return l.jsxs(l.Fragment,{children:[l.jsx(Ht,{title:"Agent",subtitle:"FeltDB’s agent runtime operating this application through its AppPort capabilities and AppPort Services. Every action runs as the task owner; consequential ones wait for a person who may perform them.",actions:r.length?l.jsxs("label",{className:"row small",children:[l.jsx("span",{className:"muted",children:"Act as"}),l.jsx("select",{value:b,onChange:g=>f(g.target.value),"aria-label":"Identity for agent actions",children:r.map(g=>l.jsxs("option",{value:g.id,children:[g.name??g.id," (",g.roles.join(", "),")"]},g.id))})]}):null}),y.error&&!y.data?l.jsx(ve,{error:y.error,retry:y.reload}):y.data?j?l.jsx(Sx,{taskId:j,as:b,development:h,canAct:v,actor:h?b:x??"",version:u}):l.jsxs(l.Fragment,{children:[h&&r.length>0&&l.jsx(jx,{as:b,tools:y.data.tools,initial:i[0]==="new"?{playbook:i[1],target:i[2]}:void 0}),!h&&l.jsx(te,{children:l.jsxs("p",{className:"muted small",children:["Production: tasks come from agents (over MCP) and playbooks. ",v?"You can approve, reject, retry, and settle their actions; each runs as the task owner and is recorded as yours.":"You can inspect them; acting needs feltkit.operations.write."]})}),y.data.handoffs.length>0&&l.jsxs(te,{title:"Waiting for a coding agent",children:[l.jsx("ul",{className:"list",children:y.data.handoffs.map(g=>l.jsxs("li",{className:"list-row",children:[l.jsx("a",{href:`#/agent/${g.taskId}`,children:g.objective}),l.jsxs("span",{className:"muted small mono",children:[g.handoffId," · from ",g.from]})]},g.handoffId))}),l.jsxs("p",{className:"muted small",children:["A coding agent with an agent session claims these with the MCP tool ",l.jsx("code",{children:"feltkit_agent_claim"}),"."]})]}),l.jsx(te,{title:"Tasks",children:y.data.tasks.length===0?l.jsx(qt,{title:"No tasks yet",children:"Start one above, or from a failed job or delivery on the Services screen."}):l.jsx("div",{className:"table-wrap",children:l.jsxs("table",{className:"table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:"Objective"}),l.jsx("th",{children:"Status"}),l.jsx("th",{children:"FeltDB execution"}),l.jsx("th",{children:"Owner"}),l.jsx("th",{children:"Waiting"}),l.jsx("th",{children:"Updated"})]})}),l.jsx("tbody",{children:y.data.tasks.map(g=>l.jsxs("tr",{onClick:()=>yt(`agent/${g.task.task_id}`),children:[l.jsx("td",{children:g.task.objective}),l.jsx("td",{children:l.jsx(I,{tone:jr(g.task.status),children:g.task.status})}),l.jsx("td",{className:"mono small",children:g.execution?.status??"—"}),l.jsx("td",{className:"mono small",children:g.task.owner}),l.jsx("td",{children:g.pending?l.jsxs(I,{tone:"warn",children:[g.pending," approval",g.pending>1?"s":""]}):""}),l.jsx("td",{className:"muted small",children:tt(g.task.updated_at)})]},g.task.task_id))})]})})})]}):l.jsx(Ze,{})]})}function jx({as:i,tools:u,initial:d}){const[r,h]=k.useState(d?.playbook&&mr.some(w=>w.id===d.playbook)?d.playbook:"inspect-app"),[v,x]=k.useState(d?.target??""),[b,f]=k.useState(""),[y,j]=k.useState(""),[g,R]=k.useState("{}"),[q,V]=k.useState(!1),[E,A]=k.useState(null),X=mr.find(w=>w.id===r),ee=async()=>{A(null),V(!0);try{let w={};if(r==="invoke")try{w=JSON.parse(g||"{}")}catch{throw new Error("Input is not valid JSON.")}const K=await ne("/agent/tasks",{method:"POST",body:JSON.stringify({as:i,playbook:r,objective:b||(X.target?`${X.label}: ${v}`:r==="invoke"?`Run ${y}`:X.label),...X.target?{target:v}:{},...r==="invoke"?{capability:y,args:w}:{}})});yt(`agent/${K.task.task_id}`)}catch(w){A(w)}finally{V(!1)}};return l.jsxs(te,{title:"New task",children:[E?l.jsx(ve,{error:E}):null,l.jsxs("div",{className:"form",children:[l.jsxs("label",{children:[l.jsx("span",{children:"What"}),l.jsx("select",{value:r,onChange:w=>h(w.target.value),children:mr.map(w=>l.jsx("option",{value:w.id,children:w.label},w.id))})]}),l.jsx("p",{className:"muted small",children:X.help}),X.target&&l.jsxs("label",{children:[l.jsx("span",{children:X.target}),l.jsx("input",{className:"input mono",value:v,onChange:w=>x(w.target.value)})]}),r==="invoke"&&l.jsxs(l.Fragment,{children:[l.jsxs("label",{children:[l.jsx("span",{children:"Capability"}),l.jsxs("select",{value:y,onChange:w=>j(w.target.value),children:[l.jsx("option",{value:"",children:"Choose…"}),u.map(w=>l.jsxs("option",{value:w.name,disabled:!w.allowed,children:[w.name," — ",w.effect==="consequential"?"needs approval":"observation",w.allowed?"":" (not permitted for this identity)"]},w.name))]})]}),l.jsxs("label",{children:[l.jsx("span",{children:"Input (JSON)"}),l.jsx("textarea",{className:"input mono",rows:3,value:g,onChange:w=>R(w.target.value)})]})]}),l.jsxs("label",{children:[l.jsx("span",{children:"Objective"}),l.jsx("input",{className:"input",value:b,placeholder:r==="handoff"?"Describe the work for the coding agent":"Optional",onChange:w=>f(w.target.value)})]}),l.jsx("div",{children:l.jsx("button",{className:"btn btn-primary",onClick:ee,disabled:q||!i||!!X.target&&!v||r==="invoke"&&!y||r==="handoff"&&!b,children:q?"Working…":"Start"})})]})]})}const px=i=>({failed:"Failed",interrupted:"Outcome unknown",executing:"Running",approved:"Approved, starting"})[i]??i;function Sx({taskId:i,as:u,development:d,canAct:r,actor:h,version:v}){const[x,b]=k.useState({}),[f,y]=k.useState(0),j=Le(()=>ne(`/agent/tasks/${encodeURIComponent(i)}`),[i,v,f]),[g,R]=k.useState(null),[q,V]=k.useState(""),E=async(Y,de={})=>{R(null);try{await ne(`/agent/tasks/${encodeURIComponent(i)}/${Y}`,{method:"POST",body:JSON.stringify(d?{as:u,...de}:de)}),y(qe=>qe+1)}catch(qe){R(qe)}};if(j.error)return l.jsx(ve,{error:j.error,retry:j.reload});if(!j.data)return l.jsx(Ze,{});const{task:A,checkpoints:X,execution:ee,pending:w,actions:K=[]}=j.data,be=K.filter(Y=>Y.state==="failed"||Y.state==="interrupted"||Y.state==="executing"||Y.state==="approved"),Ce=A.status!=="completed"&&A.status!=="cancelled";return l.jsxs(l.Fragment,{children:[l.jsx("p",{children:l.jsx("a",{href:"#/agent",children:"← Tasks"})}),g?l.jsx(ve,{error:g}):null,l.jsxs(te,{title:l.jsxs("span",{className:"row",children:[A.objective," ",l.jsx(I,{tone:jr(A.status),children:A.status})]}),action:l.jsx("span",{className:"muted small mono",children:A.owner}),children:[l.jsxs("dl",{className:"kv",children:[l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"FeltDB execution"}),l.jsx("dd",{className:"mono small",children:ee?`${ee.agentRef} · ${ee.status}${ee.error?` · ${ee.error}`:""}`:"—"})]}),l.jsxs("div",{className:"kv-row",children:[l.jsx("dt",{children:"Task"}),l.jsxs("dd",{className:"mono small",children:[A.task_id," · checkpoint v",A.checkpoint_version]})]})]}),r&&Ce&&j.data.playbook==="decide"&&K.every(Y=>!["proposed","approved","executing","interrupted"].includes(Y.state))&&l.jsxs("div",{className:"row",children:[l.jsx("button",{className:"btn",onClick:()=>E("decide"),children:"Ask the model again"}),l.jsx("span",{className:"muted small",children:"Uses this environment’s model (Models). The answer is a new proposal."})]}),d&&Ce&&l.jsxs("div",{className:"row",children:[l.jsx("input",{className:"input grow",placeholder:"Summary of what was done",value:q,onChange:Y=>V(Y.target.value)}),l.jsx("button",{className:"btn",onClick:()=>E("complete",{summary:q}),disabled:w.length>0,children:"Complete"}),l.jsx("button",{className:"btn btn-ghost",onClick:()=>E("cancel",{reason:"cancelled from Studio"}),children:"Cancel"})]})]}),w.map(Y=>l.jsxs(te,{title:l.jsxs("span",{className:"row",children:["Waiting for approval ",l.jsx(I,{tone:"warn",children:Y.capability})]}),action:l.jsxs("span",{className:"muted small",children:["proposed by ",Y.proposedBy]}),children:[l.jsx("p",{children:Y.reason}),Y.decision&&l.jsxs("p",{className:"small",children:["Chosen by the model ",l.jsxs("span",{className:"mono",children:[Y.decision.provider,Y.decision.model?` / ${Y.decision.model}`:""]})," (",Y.decision.runtime,") among the options the owner may take. A choice is a proposal, not evidence."]}),l.jsx(ci,{value:Y.input}),l.jsxs("p",{className:"muted small",children:["Runs as ",l.jsx("span",{className:"mono",children:A.owner}),", through ",Y.source==="application"?"the application’s AppPort dispatch":"AppPort Services",". You must be permitted to perform it yourself to approve it."]}),r&&l.jsxs("div",{className:"row",children:[l.jsxs("button",{className:"btn btn-primary",onClick:()=>E("approve",{actionId:Y.actionId}),children:["Approve as ",h]}),l.jsx("button",{className:"btn",onClick:()=>E("reject",{actionId:Y.actionId,reason:"rejected in Studio"}),children:"Reject"})]})]},Y.actionId)),be.map(Y=>l.jsxs(te,{title:l.jsxs("span",{className:"row",children:[px(Y.state)," ",l.jsx(I,{tone:Y.state==="failed"?"bad":"warn",children:Y.capability})]}),action:l.jsxs("span",{className:"muted small",children:["attempt ",Y.attempt," · approved by ",Y.decidedBy??"—"]}),children:[l.jsx("p",{children:Y.reason}),Y.outcome?.error?l.jsxs("p",{className:"small mono",children:[Y.outcome.error.code,": ",Y.outcome.error.message]}):null,Y.interruption?l.jsxs("p",{className:"small",children:[String(Y.interruption).replace(/\.?$/,".")," Check the effect before settling it; it is never replayed automatically."]}):null,r&&Y.state==="failed"&&Ce&&l.jsx("div",{className:"row",children:l.jsx("button",{className:"btn",onClick:()=>E("retry",{actionId:Y.actionId}),children:"Retry (needs approval again)"})}),r&&Y.state==="interrupted"&&l.jsxs("div",{className:"row",children:[l.jsx("input",{className:"input grow",placeholder:"What you checked (recorded with your name)","aria-label":`What you checked for ${Y.actionId}`,value:x[Y.actionId]??"",onChange:de=>b(qe=>({...qe,[Y.actionId]:de.target.value}))}),l.jsx("button",{className:"btn",disabled:(x[Y.actionId]??"").trim().length<3,onClick:()=>E("resolve",{actionId:Y.actionId,outcome:"succeeded",note:x[Y.actionId]}),children:"It succeeded"}),l.jsx("button",{className:"btn",disabled:(x[Y.actionId]??"").trim().length<3,onClick:()=>E("resolve",{actionId:Y.actionId,outcome:"failed",note:x[Y.actionId]}),children:"It did not take effect"})]})]},Y.actionId)),l.jsx(te,{title:"Checkpoints",children:l.jsx("ol",{className:"timeline",children:X.slice().reverse().map(Y=>l.jsxs("li",{className:"timeline-item",children:[l.jsxs("div",{className:"row",children:[l.jsxs("strong",{children:["v",Y.version]})," ",l.jsx(I,{tone:jr(Y.status),children:Y.status})," ",l.jsxs("span",{className:"muted small",children:[Y.actor," · ",tt(Y.created_at)]})]}),l.jsx("p",{children:Y.summary}),Y.completed.length>0&&l.jsx("ul",{className:"small",children:Y.completed.map((de,qe)=>l.jsx("li",{className:"mono",children:de},qe))}),Y.decisions.length>0&&Y.version===X.length&&l.jsxs("details",{children:[l.jsxs("summary",{className:"small",children:["Decisions (",Y.decisions.length,")"]}),l.jsx("ul",{className:"small",children:Y.decisions.map((de,qe)=>l.jsx("li",{children:de},qe))})]}),Y.evidence.filter(de=>de.checkpoint_version===Y.version).map((de,qe)=>l.jsxs("div",{className:"small",children:["Evidence: ",de.kind==="record"?l.jsxs("a",{href:`#/activity/${de.id}`,className:"mono",children:[de.collection,"/",de.id]}):l.jsx("span",{className:"mono",children:de.uri})," ",de.verified?l.jsx(I,{tone:"ok",children:"verified at commit"}):l.jsx(I,{tone:"neutral",children:"unverified"})]},qe))]},Y.version))})})]})}function Nx(){const{version:i}=Bt(),[u,d]=k.useState(0),r=Le(()=>ne("/models"),[i,u]),h=Le(()=>ne("/overview"),[i]),{development:v,canAct:x}=Rs(h.data),[b,f]=k.useState(null),[y,j]=k.useState(!1);if(r.error)return l.jsx(ve,{error:r.error,retry:r.reload});if(!r.data)return l.jsx(Ze,{});const{status:g,catalog:R,intelligence:q,saved:V}=r.data,E=async()=>{j(!0),f(null);try{f(await ne("/models/test",{method:"POST",body:"{}"}))}catch(A){f({ok:!1,error:{message:A.message}})}finally{j(!1)}};return l.jsxs(l.Fragment,{children:[l.jsx(Ht,{title:"Models",subtitle:"The model that makes agent decisions in this environment. It chooses among the options your application offers and the task owner may take; its choice becomes a proposal, never an execution."}),l.jsxs(te,{title:l.jsxs("span",{className:"row",children:["Decision model ",g.ready?l.jsx(I,{tone:"ok",children:"ready"}):l.jsx(I,{tone:"bad",children:"not ready"})]}),action:x?l.jsx("button",{className:"btn",onClick:E,disabled:y||!g.ready,children:y?"Calling…":"Test"}):null,children:[l.jsx(xr,{rows:[["Source",g.source==="application"?"Application code (agent.decisions)":g.source==="intelligence"?"AppPort Services Intelligence (this environment)":"None"],["Provider",g.provider?l.jsxs("span",{className:"mono",children:[g.provider,g.protocol?` · ${g.protocol}`:""]}):"—"],["Model",g.model?l.jsx("span",{className:"mono",children:g.model}):"—"],["Endpoint",g.endpoint?l.jsx("span",{className:"mono",children:g.endpoint}):"—"],["API key",g.credential.ref?l.jsxs("span",{children:[l.jsx("span",{className:"mono",children:g.credential.ref})," ",l.jsx(Bs,{credential:g.credential})]}):g.credential.required?l.jsx(I,{tone:"bad",children:"required, none entered"}):"none needed"],["Runtime",g.runtime?l.jsxs("span",{className:"mono",children:[g.runtime.metadata.runtime," (",g.runtime.metadata.execution_method,")"]}):"—"],["Can decide",g.runtime?["binary","choice","score","batch","probability_distribution"].map(A=>l.jsxs(I,{tone:g.runtime.capabilities[A]?"ok":"neutral",children:[A.replace("_"," "),g.runtime.capabilities[A]?"":": no"]},A)):"—"]]}),g.problems.map(A=>l.jsxs("div",{className:"error-box",children:[l.jsx("strong",{children:A.message}),l.jsx("div",{className:"small",children:A.fix})]},A.problem)),b&&l.jsx("div",{className:b.ok?"ok-box":"error-box",children:b.ok?l.jsxs(l.Fragment,{children:[l.jsx("strong",{children:"The model answered"})," in ",b.durationMs," ms (",b.provider,", ",b.runtime.runtime,"): ",l.jsx(ci,{value:b.result})]}):l.jsxs(l.Fragment,{children:[l.jsx("strong",{children:b.error.message}),b.error.hint&&l.jsx("div",{className:"small",children:b.error.hint})]})})]}),q&&V.length>0&&l.jsx(_x,{saved:V,development:v,overview:h.data,onChanged:()=>(f(null),d(A=>A+1))}),v&&q&&l.jsx(Ex,{catalog:R,current:g,overview:h.data,onSaved:()=>d(A=>A+1)}),!v&&l.jsx(te,{children:l.jsxs("p",{className:"muted small",children:["Production: the model is selected on the host with ",l.jsx("code",{children:"feltkit model set --env production"}),"; keys live in the host’s environment as ",l.jsx("code",{children:"FELTKIT_CREDENTIAL_<ID>"})," (or in a vault the operator opted in to with ",l.jsx("code",{children:"FELTKIT_CREDENTIAL_VAULT=1"}),")."]})}),!q&&l.jsx(te,{children:l.jsxs("p",{className:"muted small",children:["The Intelligence service is not enabled for this application. Add ",l.jsx("code",{children:"intelligence: true"})," to ",l.jsx("code",{children:"services"})," in ",l.jsx("code",{children:"feltkit/app.ts"})," (new apps have it on); Studio reloads and you can choose a provider and enter its API key here. Alternatively pass ",l.jsx("code",{children:"agent.decisions"}),"."]})})]})}function _x({saved:i,development:u,overview:d,onChanged:r}){const[h,v,x]=Cr(d),[b,f]=k.useState(null),[y,j]=k.useState(null),g=async(R,q,V)=>{f(null),j(R);try{await ne(q,V),r()}catch(E){f(E)}finally{j(null)}};return l.jsxs(te,{title:"Saved models",action:u?l.jsx(Or,{as:h,setAs:v,devUsers:x,label:"Switch as"}):null,children:[l.jsx("p",{className:"muted small",children:"The agent decides with the model in use. Keep others here to switch between providers and models; each keeps its own API key reference."}),b?l.jsx(ve,{error:b}):null,l.jsx("div",{className:"table-wrap",children:l.jsxs("table",{className:"table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:"Provider"}),l.jsx("th",{children:"Model"}),l.jsx("th",{children:"Endpoint"}),l.jsx("th",{children:"API key"}),l.jsx("th",{})]})}),l.jsx("tbody",{children:i.map(R=>l.jsxs("tr",{children:[l.jsx("td",{className:"mono",children:R.provider}),l.jsxs("td",{className:"mono",children:[R.model," ",R.active&&l.jsx(I,{tone:"ok",children:"in use"})]}),l.jsx("td",{className:"mono small",children:R.endpoint??l.jsx("span",{className:"muted",children:"default"})}),l.jsx("td",{className:"mono small",children:R.credentialRef??l.jsx("span",{className:"muted",children:"none"})}),l.jsx("td",{className:"row",children:u&&!R.active&&l.jsxs(l.Fragment,{children:[l.jsx("button",{className:"btn btn-small btn-primary",disabled:y!==null,onClick:()=>g(R.id,`/models/saved/${R.id}/use`,{method:"POST",body:JSON.stringify({as:h})}),children:y===R.id?"Switching…":"Use"}),l.jsx("button",{className:"btn btn-small",disabled:y!==null,onClick:()=>g(R.id,`/models/saved/${R.id}`,{method:"DELETE"}),children:"Forget"})]})})]},R.id))})]})})]})}function Ex({catalog:i,current:u,overview:d,onSaved:r}){const[h,v]=k.useState(u.provider??i[0]?.id??""),x=i.find(z=>z.id===h),[b,f]=k.useState(u.model??""),[y,j]=k.useState(u.endpoint??""),[g,R]=k.useState(u.credential?.ref??""),[q,V]=k.useState(""),[E,A]=k.useState(!1),[X,ee]=k.useState(null),[w,K]=k.useState(null),[be,Ce]=k.useState(!1),[Y,de,qe]=Cr(d),it=x?x.credential!=="none":!1,Fe=`credential-ref:${h}`,Qe=g.trim()||Fe,Tt=u.credential?.ref===Qe?u.credential:null;k.useEffect(()=>{x&&x.modelSelection==="catalog"&&!x.models.includes(b)&&f(x.models[0]??"")},[h]);const ht=z=>{if(ui(z)){V(z.trim()),R(""),A(!0);return}R(z)},at=async z=>{ee(null),K(null),Ce(!0);const $=q;V(""),A(!1);try{const W=it?Qe:g.trim(),Ne={provider:h,model:b,...x?.customEndpoint&&y?{endpoint:y}:{},...W&&($||x?.credential==="required"||g.trim())?{credentialRef:W}:{},...$?{apiKey:$}:{},...Y?{as:Y}:{},...z?{}:{activate:!1}},Te=await ne("/models",{method:"POST",body:JSON.stringify(Ne)});K({...Te.stored??{},activate:z}),r()}catch(W){ee(W)}finally{Ce(!1)}};return l.jsxs(te,{title:"Add a model (development)",children:[X?l.jsx(ve,{error:X}):null,l.jsxs("div",{className:"form-grid",children:[l.jsxs("label",{children:["Provider",l.jsx("select",{className:"input",value:h,onChange:z=>v(z.target.value),"aria-label":"Provider",children:i.map(z=>l.jsxs("option",{value:z.id,children:[z.displayName," (",z.protocol,z.credential==="required"?", needs an API key":z.credential==="optional"?", API key optional":"",")"]},z.id))})]}),l.jsxs("label",{children:["Model",x?.modelSelection==="catalog"?l.jsx("select",{className:"input",value:b,onChange:z=>f(z.target.value),"aria-label":"Model",children:x.models.map(z=>l.jsx("option",{children:z},z))}):l.jsx("input",{className:"input",value:b,onChange:z=>f(z.target.value),placeholder:x?.models[0]??"model id","aria-label":"Model"})]}),x?.customEndpoint&&l.jsxs("label",{children:["Endpoint",l.jsx("input",{className:"input",value:y,onChange:z=>j(z.target.value),placeholder:x.endpoints[0]??"http://localhost:11434/v1","aria-label":"Endpoint"})]}),it&&l.jsxs("label",{children:["API key",x?.credential==="optional"?" (optional)":"",l.jsx("input",{className:"input",type:"password",autoComplete:"off",spellCheck:!1,value:q,onChange:z=>V(z.target.value),placeholder:Tt?.present?"Set — leave empty to keep it, or type a new key to replace it":"Paste your API key","aria-label":"API key"})]}),l.jsx(Or,{as:Y,setAs:de,devUsers:qe})]}),E&&l.jsx("div",{className:"ok-box small",children:"This looks like an API key — it will be stored securely, not in configuration."}),it&&l.jsxs("p",{className:"muted small",children:["The key is stored on the server in this environment’s custody (",u.credential?.location&&u.credential.source!=="environment"?u.credential.location:"the local encrypted vault","), outside FeltDB, and never shown again. An environment variable ",l.jsx("code",{children:Tx(Qe)})," overrides it.",Tt?.present?l.jsxs(l.Fragment,{children:[" ","Currently: ",l.jsx(Bs,{credential:Tt})]}):null]}),l.jsxs("details",{className:"schema",children:[l.jsx("summary",{children:"Advanced: credential reference"}),l.jsxs("label",{className:"small",children:["Reference (default ",l.jsx("code",{children:Fe}),")",l.jsx("input",{className:"input",value:g,onChange:z=>ht(z.target.value),placeholder:Fe,"aria-label":"Credential reference"})]}),l.jsxs("p",{className:"muted small",children:["A name for where the key is kept, such as ",l.jsx("code",{children:"credential-ref:openai"})," — not the key itself. Configuration stores only this name."]})]}),l.jsxs("div",{className:"row",children:[l.jsx("button",{className:"btn btn-primary",onClick:()=>at(!0),disabled:be||!h||!b,children:be?"Saving…":"Save and use"}),l.jsx("button",{className:"btn",onClick:()=>at(!1),disabled:be||!h||!b,children:"Save for later"}),w&&l.jsxs("span",{className:"muted small",children:["Saved",w.activate?" and in use":"; switch to it under Saved models",".",w.version?` API key: set (${w.location??"custody"}, version ${w.version}).`:"",w.activate?" Use “Test” above to call the model.":""]})]})]})}function Tx(i){return`FELTKIT_CREDENTIAL_${i.replace(/^credential-ref:/,"").replace(/[^A-Za-z0-9]/g,"_").toUpperCase()}`}const Ax=["GET","POST","PUT","PATCH","DELETE"],kx=["string","number","integer","boolean","unknown"],tm=i=>i.map(u=>`${u.name}${u.required?"":"?"}${u.type==="string"?"":`:${u.type}`}`).join(", ");function Cx(i){return i.split(",").map(u=>u.trim()).filter(Boolean).map(u=>{const[d="",r="string"]=u.split(":").map(v=>v.trim()),h=kx.includes(r)?r:"string";return{name:d.replace(/\?$/,""),type:h,required:!d.endsWith("?")}})}const Ox=i=>{const d=[...i.path.matchAll(/\{([^}]+)\}/g)].map(r=>r[1]).filter(r=>!i.input.some(h=>h.name===r));return d.length?{...i,input:[...d.map(r=>({name:r,type:"string",required:!0})),...i.input]}:i},am=i=>i.toLowerCase().replace(/[^a-z0-9]+/g,"").replace(/^[0-9]+/,"")||"op";function zx({overview:i,existing:u,onConnected:d,onClose:r}){const h=Object.keys(i?.roles??{}),[v,x,b]=Cr(i),[f,y]=k.useState("openapi"),[j,g]=k.useState(""),[R,q]=k.useState(""),[V,E]=k.useState(""),[A,X]=k.useState(""),[ee,w]=k.useState(""),[K,be]=k.useState("bearer"),[Ce,Y]=k.useState("X-API-Key"),[de,qe]=k.useState(""),[it,Fe]=k.useState([]),[Qe,Tt]=k.useState(h.filter(Q=>Q==="member"||Q==="admin")),[ht,at]=k.useState(null),[z,$]=k.useState(null),[W,Ne]=k.useState(null),Te=async()=>{$(null),at("read");try{const Q=await ne("/integrations/openapi",{method:"POST",body:JSON.stringify(j.trim()?{url:j.trim()}:{document:R})});E(Q.name),X(Q.description??Q.title??""),w(Q.baseUrl??""),Fe(Q.operations.map(le=>({...le,include:!0})))}catch(Q){$(Q)}finally{at(null)}},_=()=>Fe([...it,{include:!0,name:"",method:"GET",path:"/",access:`${V||"api"}.read`,input:[]}]),B=(Q,le)=>Fe(it.map((re,Oe)=>{if(Oe!==Q)return re;const ta={...re,...le},ca=V||"api";return le.method&&re.access===`${ca}.${re.method==="GET"?"read":"write"}`&&(ta.access=`${ca}.${le.method==="GET"?"read":"write"}`),ta})),Z=Q=>{const le=Q.toLowerCase().replace(/[^a-z0-9]/g,""),re=`${V||"api"}.`;Fe(it.map(Oe=>Oe.access.startsWith(re)?{...Oe,access:`${le||"api"}.${Oe.access.slice(re.length)}`}:Oe)),E(le)},J=it.filter(Q=>Q.include),ce=async()=>{$(null),at("connect");const Q=de;qe("");try{const le={name:V,...A.trim()?{description:A.trim()}:{},baseUrl:ee.trim(),auth:K==="header"?{kind:"header",header:Ce}:{kind:K},operations:J.map(({include:Oe,...ta})=>{const ca=Ox({...ta,include:!0}),{include:ri,...pl}=ca;return{...pl,name:am(pl.name),effect:pl.method==="GET"?"observation":"consequential"}})},re=await ne("/integrations/connect",{method:"POST",body:JSON.stringify({integration:le,roles:Qe,...Q?{apiKey:Q,as:v}:{}})});Ne(re),d()}catch(le){$(le)}finally{at(null)}};return W?l.jsxs(te,{title:`Connected ${V}`,children:[l.jsxs("div",{className:"ok-box small",children:["Wrote ",l.jsx("code",{children:W.file}),W.granted.length?l.jsxs(l.Fragment,{children:[" ","and granted ",l.jsxs("code",{children:[V,".*"]})," to ",W.granted.join(", ")," in ",l.jsx("code",{children:"feltkit/app.ts"})]}):null,". The server reloads and publishes its operations below as capabilities.",W.stored?` The API key is stored (version ${W.stored.version}) and is never shown again.`:""]}),W.skipped.length>0&&l.jsxs("p",{className:"small",children:["Not granted to ",W.skipped.join(", "),": add ",l.jsxs("code",{children:['"',V,'.*"']})," to their permissions in ",l.jsx("code",{children:"feltkit/app.ts"}),"."]}),l.jsxs("ul",{className:"small",children:[l.jsxs("li",{children:["Narrow each operation's ",l.jsx("code",{children:"output"})," in ",l.jsx("code",{children:W.file})," to what the API returns: AppPort checks every response against it."]}),l.jsxs("li",{children:["For consequential operations, add ",l.jsx("code",{children:"idempotencyHeader"})," if the API deduplicates, and ",l.jsx("code",{children:"verify"})," so an unknown outcome can be settled without resending."]}),l.jsxs("li",{children:["In production set ",l.jsxs("code",{children:[V.toUpperCase(),"_URL"]}),W.credential?l.jsxs(l.Fragment,{children:[" ","and ",l.jsxs("code",{children:["FELTKIT_CREDENTIAL_",V.toUpperCase()]})]}):null," ","on the host."]})]}),l.jsxs("span",{className:"row",children:[l.jsx("button",{className:"btn btn-primary",onClick:r,children:"Done"}),l.jsx("button",{className:"btn",onClick:()=>(Ne(null),Fe([]),E(""),g(""),q("")),children:"Connect another"})]})]}):l.jsxs(te,{title:"Connect an API",children:[l.jsxs("p",{className:"small",children:["Connect a service your app calls: each operation becomes an AppPort capability your functions, agents, and other apps can use, with its permission, effect, and every call recorded. This writes ",l.jsx("code",{children:"feltkit/<name>.ts"}),", which you own and can edit."]}),l.jsxs("div",{className:"tabs",role:"tablist",children:[l.jsx("button",{className:f==="openapi"?"active":"",onClick:()=>y("openapi"),role:"tab","aria-selected":f==="openapi",children:"From an OpenAPI document"}),l.jsx("button",{className:f==="manual"?"active":"",onClick:()=>(y("manual"),it.length===0&&_()),role:"tab","aria-selected":f==="manual",children:"Describe it yourself"})]}),f==="openapi"&&l.jsxs("div",{className:"form",style:{maxWidth:"none",marginTop:12},children:[l.jsxs("label",{children:[l.jsx("span",{children:"Document URL"}),l.jsx("input",{className:"input",type:"url",value:j,onChange:Q=>g(Q.target.value),placeholder:"https://api.example.com/openapi.json"})]}),l.jsxs("label",{children:[l.jsx("span",{children:"…or paste it (JSON)"}),l.jsx("textarea",{className:"input code-input",rows:4,value:R,onChange:Q=>q(Q.target.value),placeholder:'{"openapi": "3.0.0", "paths": { … }}'})]}),l.jsx("div",{children:l.jsx("button",{className:"btn btn-primary",onClick:Te,disabled:ht!==null||!j.trim()&&!R.trim(),children:ht==="read"?"Reading…":"Read operations"})})]}),z?l.jsx(ve,{error:z}):null,(it.length>0||f==="manual")&&l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"form-grid",style:{marginTop:12},children:[l.jsxs("label",{children:[l.jsx("span",{children:"Name *"}),l.jsx("input",{className:"input",value:V,onChange:Q=>Z(Q.target.value),placeholder:"crm"}),l.jsx("span",{className:"muted small",children:u.includes(V)?"Already connected: choose another name.":`Capabilities are ${V||"<name>"}.<operation>.`})]}),l.jsxs("label",{children:[l.jsx("span",{children:"Base URL *"}),l.jsx("input",{className:"input",type:"url",value:ee,onChange:Q=>w(Q.target.value),placeholder:"https://api.example.com"}),l.jsxs("span",{className:"muted small",children:["Used in development; production reads ",V?`${V.toUpperCase()}_URL`:"<NAME>_URL","."]})]}),l.jsxs("label",{children:[l.jsx("span",{children:"Description"}),l.jsx("input",{className:"input",value:A,onChange:Q=>X(Q.target.value)})]}),l.jsxs("label",{children:[l.jsx("span",{children:"API key"}),l.jsxs("select",{className:"input",value:K,onChange:Q=>be(Q.target.value),children:[l.jsx("option",{value:"bearer",children:"Sent as Authorization: Bearer"}),l.jsx("option",{value:"header",children:"Sent in a header"}),l.jsx("option",{value:"none",children:"No key"})]})]}),K==="header"&&l.jsxs("label",{children:[l.jsx("span",{children:"Header"}),l.jsx("input",{className:"input",value:Ce,onChange:Q=>Y(Q.target.value)})]}),K!=="none"&&l.jsxs("label",{children:[l.jsx("span",{children:"Key value (optional now)"}),l.jsx("input",{className:"input",type:"password",autoComplete:"off",spellCheck:!1,value:de,onChange:Q=>qe(Q.target.value),placeholder:"Stored securely; never shown again"}),de&&!ui(de)&&de.length<8?l.jsx("span",{className:"muted small",children:"That looks short for a key."}):null]}),K!=="none"&&de&&l.jsx(Or,{as:v,setAs:x,devUsers:b,label:"Store as"})]}),l.jsx("div",{className:"table-wrap",style:{marginTop:8},children:l.jsxs("table",{className:"table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{}),l.jsx("th",{children:"Operation"}),l.jsx("th",{children:"Method"}),l.jsx("th",{children:"Path"}),l.jsx("th",{children:"Input (name?:type)"}),l.jsx("th",{children:"Permission"}),l.jsx("th",{children:"Effect"})]})}),l.jsx("tbody",{children:it.map((Q,le)=>l.jsxs("tr",{children:[l.jsx("td",{children:l.jsx("input",{type:"checkbox",checked:Q.include,onChange:re=>B(le,{include:re.target.checked}),"aria-label":`Include ${Q.name}`})}),l.jsx("td",{children:l.jsx("input",{className:"input",value:Q.name,onChange:re=>B(le,{name:am(re.target.value)}),placeholder:"listcontacts","aria-label":"Operation name",title:Q.description})}),l.jsx("td",{children:l.jsx("select",{className:"input",value:Q.method,onChange:re=>B(le,{method:re.target.value}),"aria-label":"Method",children:Ax.map(re=>l.jsx("option",{children:re},re))})}),l.jsx("td",{children:l.jsx("input",{className:"input mono",value:Q.path,onChange:re=>B(le,{path:re.target.value}),"aria-label":"Path"})}),l.jsx("td",{children:l.jsx("input",{className:"input mono",defaultValue:tm(Q.input),onBlur:re=>B(le,{input:Cx(re.target.value)}),placeholder:"id, amount:number, note?","aria-label":"Input fields"},tm(Q.input))}),l.jsx("td",{children:l.jsx("input",{className:"input mono",value:Q.access,onChange:re=>B(le,{access:re.target.value}),"aria-label":"Permission"})}),l.jsx("td",{className:"small",children:Q.method==="GET"?"observation":"consequential"})]},le))})]})}),l.jsxs("div",{className:"row",style:{marginTop:8},children:[l.jsx("button",{className:"btn btn-small",onClick:_,children:"Add operation"}),l.jsx("span",{className:"muted small",children:"GET reads (observation); other methods may change the API (consequential). An unknown outcome is never re-sent."})]}),h.length>0&&l.jsxs("div",{className:"choices",style:{marginTop:12},children:[l.jsxs("span",{className:"small",children:["Grant ",l.jsxs("code",{children:[V||"<name>",".*"]})," to:"]}),h.map(Q=>l.jsxs("label",{className:"check",children:[l.jsx("input",{type:"checkbox",checked:Qe.includes(Q),onChange:le=>Tt(le.target.checked?[...Qe,Q]:Qe.filter(re=>re!==Q))}),Q]},Q))]}),l.jsxs("div",{className:"row",style:{marginTop:12},children:[l.jsx("button",{className:"btn btn-primary",onClick:ce,disabled:ht!==null||!V||!ee.trim()||J.length===0||u.includes(V),children:ht==="connect"?"Connecting…":`Connect ${J.length} operation${J.length===1?"":"s"}`}),V&&l.jsx(rn,{text:`feltkit/${V}.ts`,label:"Copy file path"})]})]})]})}const Dx=i=>i==="succeeded"?"ok":i==="failed"?"bad":"warn";function wx(){const{version:i}=Bt(),[u,d]=k.useState(0),r=Le(()=>ne("/integrations"),[i,u]),h=Le(()=>ne("/overview"),[i]),{development:v,canAct:x}=Rs(h.data),f=(h.data?.devUsers??[])[0]?.id??"",[y,j]=k.useState({}),[g,R]=k.useState(!1),[q,V]=k.useState(null);if(r.error)return l.jsx(ve,{error:r.error,retry:r.reload});if(!r.data)return l.jsx(Ze,{});const{integrations:E,calls:A}=r.data,X=async w=>{V(null);try{const K=await ne(`/integrations/${encodeURIComponent(w)}/check`,{method:"POST",body:"{}"});j(be=>({...be,[w]:K}))}catch(K){V(K)}},ee=async w=>{V(null);try{await ne(`/integrations/calls/${encodeURIComponent(w)}/verify`,{method:"POST",body:JSON.stringify(v?{as:f}:{})}),d(K=>K+1)}catch(K){V(K)}};return l.jsxs(l.Fragment,{children:[l.jsx(Ht,{title:"Integrations",subtitle:"Existing APIs, published as AppPort capabilities: what each operation does, who may invoke it, whether repeating it is safe, and how its outcome is verified. Seeing an operation grants nothing.",actions:v&&E.length>0&&!g?l.jsx("button",{className:"btn btn-primary",onClick:()=>R(!0),children:"Connect an API"}):null}),q?l.jsx(ve,{error:q}):null,v&&(g||E.length===0)&&l.jsx(zx,{overview:h.data,existing:E.map(w=>w.name),onConnected:()=>(R(!0),d(w=>w+1)),onClose:()=>R(!1)}),E.length===0?!v&&l.jsxs(qt,{title:"No integrations yet",children:["Connect an API in development (Studio → Integrations), or with ",l.jsxs("code",{children:['app.integration("payments", ',"{"," baseUrl, credential, operations ","}",")"]})," in ",l.jsx("code",{children:"feltkit/"}),"."]}):E.map(w=>l.jsxs(te,{title:l.jsxs("span",{className:"row",children:[w.name," ",w.problems.length?l.jsx(I,{tone:"bad",children:"not configured"}):l.jsx(I,{tone:"ok",children:"configured"})]}),action:x&&w.health?l.jsx("button",{className:"btn",onClick:()=>X(w.name),children:"Check"}):null,children:[w.description&&l.jsx("p",{children:w.description}),l.jsxs("p",{className:"small",children:[l.jsx("span",{className:"mono",children:w.baseUrl.value??"—"})," ",l.jsxs("span",{className:"muted",children:["(",w.baseUrl.source,w.baseUrl.variable?` ${w.baseUrl.variable}`:"",")"]}),w.credential&&l.jsxs(l.Fragment,{children:[" · ",l.jsx("span",{className:"mono",children:w.credential.ref})," ",l.jsx(Bs,{credential:w.credential})," ",x&&w.credential.writable&&l.jsx(zs,{credentialRef:w.credential.ref,label:w.credential.present?"Replace key":"Set key",...v&&f?{as:f}:{},onSaved:()=>d(K=>K+1)}),!w.credential.writable&&!w.credential.present&&l.jsxs("span",{className:"muted small",children:[" set ",w.credential.variable," on the host"]})]})]}),w.problems.map((K,be)=>l.jsxs("div",{className:"error-box",children:[l.jsx("strong",{children:K.message}),l.jsx("div",{className:"small",children:K.fix})]},be)),y[w.name]&&l.jsx("div",{className:y[w.name].ok?"ok-box":"error-box",children:y[w.name].message}),l.jsx("div",{className:"table-wrap",children:l.jsxs("table",{className:"table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:"Capability"}),l.jsx("th",{children:"Request"}),l.jsx("th",{children:"Effect"}),l.jsx("th",{children:"Who may invoke"}),l.jsx("th",{children:"Repeat"}),l.jsx("th",{children:"Outcome unknown →"})]})}),l.jsx("tbody",{children:w.operations.map(K=>l.jsxs("tr",{children:[l.jsx("td",{className:"mono",children:K.capability}),l.jsxs("td",{className:"mono small",children:[K.method," ",K.path]}),l.jsx("td",{children:K.effect==="consequential"?l.jsx(I,{tone:"warn",children:"consequential"}):l.jsx(I,{children:"observation"})}),l.jsx("td",{className:"mono small",children:K.access}),l.jsx("td",{className:"small",children:K.effect==="observation"?"safe":K.idempotent?"deduplicated by the API":"may duplicate"}),l.jsx("td",{className:"small",children:K.effect==="observation"?"—":K.verifiable?"verify, never re-send":"a person settles it"})]},K.capability))})]})})]},w.name)),l.jsxs(te,{title:"Calls",children:[A.length===0?l.jsx("p",{className:"muted small",children:"No calls yet."}):l.jsx("div",{className:"table-wrap",children:l.jsxs("table",{className:"table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{children:"Capability"}),l.jsx("th",{children:"State"}),l.jsx("th",{children:"How known"}),l.jsx("th",{children:"As"}),l.jsx("th",{children:"HTTP"}),l.jsx("th",{children:"Detail"}),l.jsx("th",{children:"When"}),l.jsx("th",{})]})}),l.jsx("tbody",{children:A.map(w=>l.jsxs("tr",{children:[l.jsx("td",{className:"mono small",children:w.capability}),l.jsx("td",{children:l.jsx(I,{tone:Dx(w.state),children:w.state==="started"?"unknown (no outcome recorded)":w.state})}),l.jsxs("td",{className:"small",children:[w.determinedBy??"—",w.verification?` (${w.verification.outcome})`:""]}),l.jsx("td",{className:"mono small",children:w.principal.id}),l.jsx("td",{children:w.status??""}),l.jsx("td",{className:"small error-text",children:w.error?.message??""}),l.jsx("td",{className:"muted small",children:tt(w.startedAt)}),l.jsx("td",{children:x&&(w.state==="unknown"||w.state==="started")&&l.jsx("button",{className:"btn btn-small",onClick:()=>ee(w.id),disabled:v&&!f,children:"Verify"})})]},w.id))})]})}),l.jsx("p",{className:"muted small",children:"A call is recorded before it is sent. “Verify” reads the API’s own state through the declared probe; it never sends the request again."})]})]})}const lm={pass:"ok",fail:"bad",warn:"warn",external:"neutral"},nm={pass:"verified",fail:"fails",warn:"review",external:"outside FeltKit"};function Rx(){const{version:i}=Bt(),u=Le(()=>ne("/readiness"),[i]);if(u.error)return l.jsx(ve,{error:u.error,retry:u.reload});if(!u.data)return l.jsx(Ze,{label:"Checking this environment"});const d=u.data,r=[...new Set(d.checks.map(h=>h.area))];return l.jsxs(l.Fragment,{children:[l.jsx(Ht,{title:"Readiness",subtitle:"Real checks of this environment, not a status anyone sets. Passing checks mean the checked things are in place; the operational requirements at the end are yours to meet.",actions:l.jsx("button",{className:"btn",onClick:u.reload,children:"Check again"})}),l.jsxs(te,{children:[l.jsx("p",{children:l.jsx("strong",{children:d.summary})}),l.jsx("div",{className:"row",children:["fail","warn","pass","external"].map(h=>l.jsxs(I,{tone:lm[h],children:[d.counts[h]," ",nm[h]]},h))}),l.jsxs("p",{className:"muted small",children:["The same report: ",l.jsxs("code",{children:["npx feltkit readiness --env ",d.environment.name]}),"."]})]}),r.map(h=>l.jsx(te,{title:h,children:l.jsx("ul",{className:"checks",children:d.checks.filter(v=>v.area===h).map(v=>l.jsxs("li",{className:"check",children:[l.jsx(I,{tone:lm[v.status],children:nm[v.status]})," ",l.jsx("strong",{children:v.title}),l.jsx("div",{className:"small",children:v.detail}),v.fix&&v.status!=="pass"&&l.jsxs("div",{className:"small muted",children:["→ ",v.fix]})]},v.id))})},h))]})}const Mx=new Set(["service_effect_evidence"]),Rm=k.createContext({live:!1,version:0,changed:{},activity:[],overview:void 0,reloadOverview(){}}),Bt=()=>k.useContext(Rm),pr=[{id:"overview",label:"Overview",key:"1"},{id:"data",label:"Data",key:"2"},{id:"capabilities",label:"Capabilities",key:"3"},{id:"services",label:"Services",key:"4"},{id:"agent",label:"Agent",key:"5"},{id:"models",label:"Models",key:"m"},{id:"integrations",label:"Integrations",key:"i"},{id:"readiness",label:"Readiness",key:"r"},{id:"activity",label:"Activity",key:"6"},{id:"settings",label:"Settings",key:"7"},{id:"projects",label:"Projects",key:"8"}],im=["data","settings","projects"];function sm(){const i=location.hash.replace(/^#\/?/,"").split("/").filter(Boolean).map(decodeURIComponent);return{route:pr.find(d=>d.id===i[0])?.id??"overview",rest:i.slice(1)}}function yt(i){location.hash=`#/${i}`}const Ux={overview:l.jsx("path",{d:"M3 10.5 10 4l7 6.5V17a1 1 0 0 1-1 1h-4v-5H8v5H4a1 1 0 0 1-1-1z"}),data:l.jsxs(l.Fragment,{children:[l.jsx("ellipse",{cx:"10",cy:"5",rx:"6.5",ry:"2.5"}),l.jsx("path",{d:"M3.5 5v10c0 1.4 2.9 2.5 6.5 2.5s6.5-1.1 6.5-2.5V5M3.5 10c0 1.4 2.9 2.5 6.5 2.5s6.5-1.1 6.5-2.5"})]}),capabilities:l.jsx("path",{d:"M7 3h6v4l3 3-3 3v4H7v-4l-3-3 3-3z"}),models:l.jsx("path",{d:"M10 3a4 4 0 0 1 4 4v1a3 3 0 0 1 0 6v1a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2v-1a3 3 0 0 1 0-6V7a4 4 0 0 1 4-4zM8 10h.01M12 10h.01"}),integrations:l.jsx("path",{d:"M7 7h-2a3 3 0 0 0 0 6h2M13 7h2a3 3 0 0 1 0 6h-2M7 10h6"}),readiness:l.jsx("path",{d:"M4 10.5 8 14.5 16 5.5"}),services:l.jsxs(l.Fragment,{children:[l.jsx("rect",{x:"3",y:"3",width:"6",height:"6",rx:"1.5"}),l.jsx("rect",{x:"11",y:"3",width:"6",height:"6",rx:"1.5"}),l.jsx("rect",{x:"3",y:"11",width:"6",height:"6",rx:"1.5"}),l.jsx("rect",{x:"11",y:"11",width:"6",height:"6",rx:"1.5"})]}),agent:l.jsx("path",{d:"M10 3a3 3 0 0 1 3 3v1h1.5A1.5 1.5 0 0 1 16 8.5v6a1.5 1.5 0 0 1-1.5 1.5h-9A1.5 1.5 0 0 1 4 14.5v-6A1.5 1.5 0 0 1 5.5 7H7V6a3 3 0 0 1 3-3zM8 11h.01M12 11h.01M8 14h4"}),activity:l.jsx("path",{d:"M2 10h4l2-5 4 10 2-5h4"}),settings:l.jsxs(l.Fragment,{children:[l.jsx("circle",{cx:"10",cy:"10",r:"2.5"}),l.jsx("path",{d:"M10 2.5v2M10 15.5v2M2.5 10h2M15.5 10h2M4.7 4.7l1.4 1.4M13.9 13.9l1.4 1.4M4.7 15.3l1.4-1.4M13.9 6.1l1.4-1.4"})]}),projects:l.jsx(l.Fragment,{children:l.jsx("path",{d:"M3 6.5A1.5 1.5 0 0 1 4.5 5H8l1.5 2h6A1.5 1.5 0 0 1 17 8.5v6A1.5 1.5 0 0 1 15.5 16h-11A1.5 1.5 0 0 1 3 14.5z"})})};function qx({route:i}){return l.jsx("svg",{viewBox:"0 0 20 20",width:"18",height:"18",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:Ux[i]})}function Hx(){const[i,u]=k.useState("loading"),[d,r]=k.useState("");return k.useEffect(()=>{fetch("/api/session",{credentials:"same-origin"}).then(h=>h.json()).then(h=>{r(h?.environment?.name??""),u(h?.environment?.production?"production":"development")}).catch(()=>u("development"))},[]),i==="loading"?l.jsx(Ze,{label:"Connecting"}):i==="production"?l.jsx(Lx,{environment:d}):l.jsx(Gx,{})}function Bx(){const i=/(?:^|[#&])grant=([^&]+)/.exec(location.hash);if(!i)return null;history.replaceState(null,"",`${location.pathname}#/overview`);try{return decodeURIComponent(i[1])}catch{return null}}function Lx({environment:i}){const[u,d]=k.useState("checking"),[r,h]=k.useState(null),[v]=k.useState(Bx),x=f=>{f?.operator&&f?.csrf?(or({csrf:f.csrf,environment:i}),d("signed-in")):(or(null),d("signed-out"))},b=async f=>{h(null);try{const y=await fetch("/_feltkit/api/operator/signin",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json","x-feltkit-environment":i},body:JSON.stringify({grant:f})}),j=await y.json();if(!y.ok)throw new Error(j?.error?.message??`Sign-in failed (${y.status})`);x(j)}catch(y){h(`${y.message}${v===f?" The link works once and expires after 10 minutes: run `npx feltkit manage` for a new one.":""}`),d("signed-out")}};return k.useEffect(()=>{v?b(v):ne("/operator/session").then(x,()=>d("signed-out"))},[]),u==="checking"?l.jsx(Ze,{label:v?"Signing you in":"Checking your operator session"}):u==="signed-in"?l.jsx(Mm,{onSignOut:()=>{ne("/operator/signout",{method:"POST",body:"{}"}).catch(()=>{}).finally(()=>(or(null),d("signed-out")))}}):l.jsx(Yx,{environment:i,...r?{error:r}:{},onGrant:f=>{b(f)}})}function Yx({environment:i,onGrant:u,error:d}){const[r,h]=k.useState("");return l.jsx("div",{className:"gate",children:l.jsxs("div",{className:"gate-card",children:[l.jsx(zr,{}),l.jsxs("h1",{children:["Sign in to ",i," Studio"]}),l.jsxs("p",{className:"muted",children:["Production Studio is for operators. In your project folder, run ",l.jsx("code",{children:"npx feltkit manage"})," and open the one-time link it prints (or paste the grant from"," ",l.jsx("code",{children:"npx feltkit operator grant --id <you> --role <role>"})," here). Everything you do is authorized and recorded as you."]}),d&&l.jsx("p",{className:"error-text",children:d}),l.jsxs("form",{onSubmit:v=>{v.preventDefault(),r.trim()&&u(r.trim())},className:"row",children:[l.jsx("input",{className:"input grow",value:r,onChange:v=>h(v.target.value),placeholder:"fkg1.…","aria-label":"Operator grant",autoFocus:!0}),l.jsx("button",{className:"btn btn-primary",type:"submit",children:"Sign in"})]})]})})}function Gx(){const[i,u]=k.useState(()=>{const h=vg();return rr(h),h}),[d,r]=k.useState(!1);return i?l.jsx(Mm,{onSignOut:h=>(rr(null),Qh(null),r(!!h),u(null))}):l.jsx(Vx,{...d?{error:"That admin token was not accepted. A new one is generated if .feltkit/<env>/admin-token is deleted."}:{},onToken:h=>(rr(h),Qh(h),r(!1),u(h))})}function Vx({onToken:i,error:u}){const[d,r]=k.useState("");return l.jsx("div",{className:"gate",children:l.jsxs("div",{className:"gate-card",children:[l.jsx(zr,{}),l.jsx("h1",{children:"Open the FeltKit dashboard"}),l.jsxs("p",{className:"muted",children:["The dashboard needs this environment’s admin token. Use the ",l.jsx("strong",{children:"Dashboard"})," link that ",l.jsx("code",{children:"feltkit dev"})," prints — it contains the token — or paste the token from ",l.jsx("code",{children:".feltkit/development/admin-token"}),"."]}),u&&l.jsx("p",{className:"error-text",children:u}),l.jsxs("form",{onSubmit:h=>{h.preventDefault(),d.trim()&&i(d.trim())},className:"row",children:[l.jsx("input",{className:"input grow",value:d,onChange:h=>r(h.target.value),placeholder:"fka_…","aria-label":"Admin token",autoFocus:!0}),l.jsx("button",{className:"btn btn-primary",type:"submit",children:"Continue"})]})]})})}function zr(){return l.jsx("span",{className:"logo",children:l.jsx("img",{src:Nb,width:"28",height:"28",alt:"FeltKit"})})}function Mm({onSignOut:i}){const[{route:u,rest:d},r]=k.useState(sm),[h,v]=k.useState(!1),[x,b]=k.useState(0),[f,y]=k.useState({}),[j,g]=k.useState([]),R=Le(()=>ne("/overview"),[x]),q=k.useRef(null);k.useEffect(()=>{const ee=()=>r(sm());return window.addEventListener("hashchange",ee),()=>window.removeEventListener("hashchange",ee)},[]),k.useEffect(()=>yg((ee,w)=>{ee==="activity"&&g(K=>[w,...K].slice(0,200)),!(ee==="change"&&(y(K=>{const be={...K};for(const Ce of w.collections)be[Ce]=(be[Ce]??0)+1;return be}),w.collections.every(K=>Mx.has(K))))&&q.current===null&&(q.current=window.setTimeout(()=>{q.current=null,b(K=>K+1)},250))},v),[]),k.useEffect(()=>{const ee=w=>{const K=w.target;if(w.metaKey||w.ctrlKey||w.altKey||["INPUT","TEXTAREA","SELECT"].includes(K.tagName)||K.isContentEditable)return;const be=pr.find(Ce=>Ce.key===w.key);be&&yt(be.id)};return window.addEventListener("keydown",ee),()=>window.removeEventListener("keydown",ee)},[]);const V=k.useMemo(()=>({live:h,version:x,changed:f,activity:j,overview:R.data,reloadOverview:R.reload}),[h,x,f,j,R.data,R.reload]),E=R.error?.status===401;k.useEffect(()=>{E&&i(!0)},[E,i]);const A=R.data,X=A?.environment?.production;return l.jsx(Rm.Provider,{value:V,children:l.jsxs("div",{className:"app",children:[l.jsxs("nav",{className:"nav","aria-label":"Dashboard",children:[l.jsxs("div",{className:"nav-brand",children:[l.jsx(zr,{}),l.jsxs("div",{children:[l.jsx("div",{className:"nav-app",children:A?.application?.name??"…"}),l.jsx("div",{className:"nav-sub",children:"FeltKit"})]})]}),l.jsx("ul",{children:pr.filter(ee=>!X||!im.includes(ee.id)).map(ee=>{const w=u===ee.id&&!(ee.id==="services"&&d[0]);return l.jsxs("li",{children:[l.jsxs("a",{href:`#/${ee.id}`,className:w?"active":u===ee.id?"within":"","aria-current":w?"page":void 0,children:[l.jsx(qx,{route:ee.id}),l.jsx("span",{children:ee.label}),l.jsx("kbd",{children:ee.key})]}),ee.id==="services"&&l.jsx(Qx,{services:A?.services??[],current:u==="services"?d[0]:void 0})]},ee.id)})}),l.jsxs("div",{className:"nav-foot",children:[l.jsxs("div",{className:`live ${h?"on":""}`,children:[l.jsx("span",{className:"dot"})," ",h?"Live":"Reconnecting"]}),l.jsx(Sb,{}),l.jsxs("a",{className:"nav-family",href:"https://boundry.company",target:"_blank",rel:"noreferrer",children:[l.jsx(gb,{idPrefix:"nav-family-mark"})," A Boundry product"]}),l.jsx("button",{className:"btn btn-ghost btn-small",onClick:()=>i(),title:A?.operator?"Sign out of production Studio":"Forget the admin token in this tab",children:A?.operator?"Sign out":"Lock"})]})]}),l.jsxs("div",{className:"content",children:[A&&l.jsxs("div",{className:`envbar ${X?"envbar-prod":""}`,children:[l.jsx("span",{className:"envname",children:A.environment.name}),l.jsxs("span",{className:"muted",children:["FeltDB ",A.instance.feltdbVersion," · ",A.instance.mode," · "]}),l.jsx("code",{className:"path",title:A.instance.location,children:A.instance.location}),X?l.jsxs("span",{className:"envwarn",children:["Production · signed in as ",l.jsx("strong",{children:A.operator?.principal?.id})," (",(A.operator?.principal?.roles??[]).join(", "),") · actions run on this environment only"]}):l.jsx("span",{className:"muted",children:"Development tools enabled"})]}),l.jsx("main",{className:"page",children:R.loading&&!A?l.jsx(Ze,{label:"Connecting to the runtime"}):A?l.jsx(Xx,{route:X&&im.includes(u)?"overview":u,rest:d}):l.jsxs("div",{className:"error-box",children:["The runtime did not answer: ",R.error?.message]})})]})]})})}const cm={configured:"ok",unconfigured:"warn",unhealthy:"bad",unavailable:"bad",available:"off"},um="feltkit.nav.services";function Qx({services:i,current:u}){const[d,r]=k.useState(()=>{try{return localStorage.getItem(um)!=="closed"}catch{return!0}}),h=()=>{r(!d);try{localStorage.setItem(um,d?"closed":"open")}catch{}};if(!i.length)return null;const v=i.filter(f=>f.state!=="available"&&f.state!=="unavailable"),x=i.filter(f=>f.state==="available"||f.state==="unavailable"),b=(f,y,j)=>l.jsx("li",{children:l.jsxs("a",{href:`#/services/${f}`,className:u===f?"active":"","aria-current":u===f?"page":void 0,children:[l.jsx("span",{className:`nav-dot nav-dot-${j??"none"}`,"aria-hidden":!0}),l.jsx("span",{children:y})]})},f);return l.jsxs(l.Fragment,{children:[l.jsx("button",{className:"nav-toggle",onClick:h,"aria-expanded":d||!!u,"aria-label":d?"Hide services":"Show services",children:d||u?"▾":"▸"}),(d||u)&&l.jsxs("ul",{className:"nav-children","aria-label":"Services",children:[v.map(f=>b(f.id,f.name,cm[f.state])),b("credentials","Credentials"),x.length>0&&l.jsx("li",{className:"nav-group",children:"Not enabled"}),x.map(f=>b(f.id,f.name,cm[f.state]))]})]})}function Xx({route:i,rest:u}){switch(i){case"data":return l.jsx(ex,{collection:u[0]});case"capabilities":return l.jsx(cx,{selected:u[0]});case"services":return l.jsx(Zb,{page:u[0]});case"agent":return l.jsx(xx,{rest:u});case"models":return l.jsx(Nx,{});case"integrations":return l.jsx(wx,{});case"readiness":return l.jsx(Rx,{});case"activity":return l.jsx(fx,{selected:u[0]});case"settings":return l.jsx(yx,{});case"projects":return l.jsx(bx,{});default:return l.jsx(Pb,{})}}function Ht({title:i,subtitle:u,actions:d}){return l.jsxs("header",{className:"page-header",children:[l.jsxs("div",{children:[l.jsx("h1",{children:i}),u&&l.jsx("p",{className:"muted",children:u})]}),d&&l.jsx("div",{className:"actions",children:d})]})}mg.createRoot(document.getElementById("root")).render(l.jsx(k.StrictMode,{children:l.jsx(Hx,{})}));