@yunuseon/kayra 0.17.0 → 0.17.1
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.
- package/ansible/roles/platform/tasks/main.yml +31 -0
- package/cli/dist/browser/assets/index-hcyM6f6T.js +7 -0
- package/cli/dist/browser/index.html +1 -1
- package/cli/dist/clients/api/api.js +138 -218
- package/cli/dist/clients/api/auth.js +8 -7
- package/cli/dist/clients/api/commands.js +50 -14
- package/cli/dist/clients/api/contract.js +8 -6
- package/cli/dist/clients/api/discovery.js +7 -2
- package/cli/dist/clients/api/live.js +40 -0
- package/cli/dist/clients/api/protocol.js +17 -10
- package/cli/dist/clients/api/queries.js +3 -3
- package/cli/dist/clients/api/runs.js +10 -9
- package/cli/dist/clients/api/start.js +97 -0
- package/cli/dist/clients/api/status.js +29 -0
- package/cli/dist/clients/api/validate.js +13 -0
- package/cli/dist/clients/cli/explain.js +12 -10
- package/cli/dist/clients/cli/framed.js +12 -9
- package/cli/dist/clients/cli/invocation.js +4 -3
- package/cli/dist/clients/cli/paint.js +1 -1
- package/cli/dist/clients/cli/parser.js +8 -8
- package/cli/dist/clients/cli/questions.js +11 -10
- package/cli/dist/clients/cli/status.js +75 -0
- package/cli/dist/clients/cli/terminal.js +4 -2
- package/cli/dist/{core/present → clients/cli}/text.js +15 -24
- package/cli/dist/clients/cli/validate.js +32 -0
- package/cli/dist/clients/cli/values.js +19 -0
- package/cli/dist/{core/present → clients/cli}/views.js +28 -60
- package/cli/dist/core/adapters/fs.js +18 -0
- package/cli/dist/core/{net.js → adapters/network.js} +20 -5
- package/cli/dist/core/adapters/opentofu.js +24 -0
- package/cli/dist/core/ctl/answers.js +32 -0
- package/cli/dist/core/fleet/brand.js +45 -0
- package/cli/dist/core/{schemas.js → fleet/docs.js} +4 -3
- package/cli/dist/core/fleet/load.js +44 -0
- package/cli/dist/core/fleet/model.js +1 -0
- package/cli/dist/core/{fleet.js → fleet/parse.js} +61 -41
- package/cli/dist/core/{settings.js → fleet/settings.js} +10 -3
- package/cli/dist/core/{validate.js → fleet/shape.js} +6 -5
- package/cli/dist/core/{present/progress.js → interpreter/events.js} +27 -31
- package/cli/dist/core/interpreter/io.js +18 -0
- package/cli/dist/core/interpreter/loop.js +101 -0
- package/cli/dist/core/interpreter/needs.js +47 -0
- package/cli/dist/core/interpreter/process.js +107 -0
- package/cli/dist/core/interpreter/progress.js +15 -0
- package/cli/dist/core/interpreter/pty.js +8 -0
- package/cli/dist/core/operations/catalog.js +35 -18
- package/cli/dist/core/operations/{run.js → dispatch.js} +49 -46
- package/cli/dist/core/{plan.js → plan/describe.js} +4 -14
- package/cli/dist/core/plan/model.js +14 -0
- package/cli/dist/core/{commands → recipes}/app-check.js +11 -16
- package/cli/dist/core/recipes/apps.js +63 -0
- package/cli/dist/core/recipes/backup.js +34 -0
- package/cli/dist/core/recipes/certs.js +4 -0
- package/cli/dist/core/{commands → recipes}/doctor.js +20 -35
- package/cli/dist/core/recipes/host.js +104 -0
- package/cli/dist/core/recipes/ssh.js +20 -0
- package/cli/dist/core/recipes/steps.js +82 -0
- package/cli/dist/core/status/look.js +55 -0
- package/cli/dist/core/status/model.js +6 -0
- package/cli/dist/core/status/ports.js +1 -0
- package/cli/dist/core/text/plural.js +2 -0
- package/cli/dist/core/text/spans.js +22 -0
- package/cli/dist/core/text/time.js +12 -0
- package/cli/dist/core/validation/facts.js +49 -0
- package/cli/dist/core/{commands/validate.js → validation/findings.js} +31 -66
- package/cli/dist/deployer/app.js +2 -1
- package/cli/dist/deployer/{builder.js → build/builder.js} +14 -13
- package/cli/dist/deployer/{bundle.js → build/bundle.js} +8 -7
- package/cli/dist/deployer/{compose.js → build/compose.js} +8 -7
- package/cli/dist/deployer/cron.js +2 -2
- package/cli/dist/deployer/{answers.js → ctl/answers.js} +5 -4
- package/cli/dist/deployer/{ctl.js → ctl/ctl.js} +3 -3
- package/cli/dist/deployer/deployer.js +23 -22
- package/cli/dist/deployer/{forge.js → forges/forge.js} +2 -1
- package/cli/dist/deployer/{forgejo.js → forges/forgejo.js} +2 -2
- package/cli/dist/deployer/{github.js → forges/github.js} +2 -2
- package/cli/dist/deployer/{gitlab.js → forges/gitlab.js} +2 -2
- package/cli/dist/deployer/{github-issues.js → forges/issues.js} +5 -4
- package/cli/dist/deployer/{notify.js → forges/notify.js} +9 -8
- package/cli/dist/deployer/{http.js → http/http.js} +1 -0
- package/cli/dist/deployer/{page.js → http/page.js} +1 -1
- package/cli/dist/deployer/{webhook.js → http/webhook.js} +2 -1
- package/cli/dist/deployer/main.js +2 -2
- package/cli/dist/deployer/{queue.js → runs/queue.js} +4 -3
- package/cli/dist/deployer/{records.js → runs/records.js} +9 -8
- package/cli/dist/deployer/{run.js → runs/run.js} +10 -9
- package/cli/dist/deployer/{store.js → runs/store.js} +9 -8
- package/cli/dist/main.js +89 -89
- package/cli/dist/result.js +11 -1
- package/cli/dist/serve.js +2 -2
- package/cli/dist/typed.js +2 -0
- package/package.json +3 -2
- package/cli/dist/browser/assets/index-9a-SE2rU.js +0 -7
- package/cli/dist/core/brand.js +0 -39
- package/cli/dist/core/commands/server.js +0 -298
- package/cli/dist/core/commands/status.js +0 -194
- package/cli/dist/core/gather.js +0 -61
- package/cli/dist/core/interpret.js +0 -276
- package/cli/dist/core/load.js +0 -64
- package/cli/dist/core/present/line.js +0 -17
- /package/cli/dist/core/{updates.js → status/updates.js} +0 -0
|
@@ -124,10 +124,41 @@
|
|
|
124
124
|
loop:
|
|
125
125
|
- deployer/
|
|
126
126
|
- "result.{{ 'ts' if deployer_source.stat.exists else 'js' }}"
|
|
127
|
+
- "typed.{{ 'ts' if deployer_source.stat.exists else 'js' }}"
|
|
127
128
|
vars:
|
|
128
129
|
code: "{{ 'src' if deployer_source.stat.exists else 'dist' }}"
|
|
129
130
|
become: true
|
|
130
131
|
|
|
132
|
+
# The deployer's files used to sit flat in deployer/; those now in folders
|
|
133
|
+
# are removed here, since a copy adds and never removes. Idempotent; drop it
|
|
134
|
+
# once every fleet's servers have deployed the folders.
|
|
135
|
+
- name: Remove the deployer's flat files of earlier versions
|
|
136
|
+
ansible.builtin.file:
|
|
137
|
+
path: "{{ platform_dir }}/deployer/app/deployer/{{ item.0 }}.{{ item.1 }}"
|
|
138
|
+
state: absent
|
|
139
|
+
loop: "{{ moved | product(['ts', 'js']) | list }}"
|
|
140
|
+
vars:
|
|
141
|
+
moved:
|
|
142
|
+
- answers
|
|
143
|
+
- builder
|
|
144
|
+
- bundle
|
|
145
|
+
- compose
|
|
146
|
+
- ctl
|
|
147
|
+
- forge
|
|
148
|
+
- forgejo
|
|
149
|
+
- github
|
|
150
|
+
- github-issues
|
|
151
|
+
- gitlab
|
|
152
|
+
- http
|
|
153
|
+
- notify
|
|
154
|
+
- page
|
|
155
|
+
- queue
|
|
156
|
+
- records
|
|
157
|
+
- run
|
|
158
|
+
- store
|
|
159
|
+
- webhook
|
|
160
|
+
become: true
|
|
161
|
+
|
|
131
162
|
- name: Copy the platform scripts
|
|
132
163
|
ansible.builtin.copy:
|
|
133
164
|
src: "{{ kayra_root }}/scripts/platform/"
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h={},g=[],_=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,v=Array.isArray;function y(e,t){for(var n in t)e[n]=t[n];return e}function ee(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function b(t,n,r){var i,a,o,s={};for(o in n)o==`key`?i=n[o]:o==`ref`?a=n[o]:s[o]=n[o];if(arguments.length>2&&(s.children=arguments.length>3?e.call(arguments,2):r),typeof t==`function`&&t.defaultProps!=null)for(o in t.defaultProps)s[o]===void 0&&(s[o]=t.defaultProps[o]);return x(t,s,i,a,null)}function x(e,r,i,a,o){var s={type:e,props:r,key:i,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:o??++n,__i:-1,__u:0};return o==null&&t.vnode!=null&&t.vnode(s),s}function S(e){return e.children}function te(e,t){this.props=e,this.context=t}function C(e,t){if(t==null)return e.__?C(e.__,e.__i+1):null;for(var n;t<e.__k.length;t++)if((n=e.__k[t])!=null&&n.__e!=null)return n.__e;return typeof e.type==`function`?C(e):null}function w(e){if(e.__P&&e.__d){var n=e.__v,r=n.__e,i=[],a=[],o=y({},n);o.__v=n.__v+1,t.vnode&&t.vnode(o),se(e.__P,o,n,e.__n,e.__P.namespaceURI,32&n.__u?[r]:null,i,r??C(n),!!(32&n.__u),a),o.__v=n.__v,o.__.__k[o.__i]=o,le(i,o,a),n.__e=n.__=null,o.__e!=r&&T(o)}}function T(e){if((e=e.__)!=null&&e.__c!=null)return e.__e=e.__c.base=null,e.__k.some(function(t){if(t!=null&&t.__e!=null)return e.__e=e.__c.base=t.__e}),T(e)}function E(e){(!e.__d&&(e.__d=!0)&&i.push(e)&&!D.__r++||a!=t.debounceRendering)&&((a=t.debounceRendering)||o)(D)}function D(){try{for(var e,t=1;i.length;)i.length>t&&i.sort(s),e=i.shift(),t=i.length,w(e)}finally{i.length=D.__r=0}}function ne(e,t,n,r,i,a,o,s,c,l,u){var d,f,p,m,_,v,y=r&&r.__k||g,ee=t.length;for(c=O(n,t,y,c,ee),d=0;d<ee;d++)(p=n.__k[d])!=null&&(f=p.__i!=-1&&y[p.__i]||h,p.__i=d,v=se(e,p,f,i,a,o,s,c,l,u),m=p.__e,p.ref&&f.ref!=p.ref&&(f.ref&&fe(f.ref,null,p),u.push(p.ref,p.__c||m,p)),_==null&&m!=null&&(_=m),4&p.__u?(c=re(p,c,e),f.__e&&(f.__e=null)):typeof p.type==`function`&&v!==void 0?c=v:m&&(c=m.nextSibling),p.__u&=-7);return n.__e=_,c}function O(e,t,n,r,i){var a,o,s,c,l,u=n.length,d=u,f=0;for(e.__k=Array(i),a=0;a<i;a++)(o=t[a])!=null&&typeof o!=`boolean`&&typeof o!=`function`?(typeof o==`string`||typeof o==`number`||typeof o==`bigint`||o.constructor==String?o=e.__k[a]=x(null,o,null,null,null):v(o)?o=e.__k[a]=x(S,{children:o},null,null,null):o.constructor===void 0&&o.__b>0?o=e.__k[a]=x(o.type,o.props,o.key,o.ref?o.ref:null,o.__v):e.__k[a]=o,c=a+f,o.__=e,o.__b=e.__b+1,s=null,(l=o.__i=ie(o,n,c,d))!=-1&&(d--,(s=n[l])&&(s.__u|=2)),s==null||s.__v==null?(l==-1&&(i>u?f--:i<u&&f++),typeof o.type!=`function`&&(o.__u|=4)):l!=c&&(l==c-1?f--:l==c+1?f++:(l>c?f--:f++,o.__u|=4))):e.__k[a]=null;if(d)for(a=0;a<u;a++)(s=n[a])!=null&&!(2&s.__u)&&(s.__e==r&&(r=C(s)),pe(s,s));return r}function re(e,t,n){var r,i;if(typeof e.type==`function`){for(r=e.__k,i=0;r&&i<r.length;i++)r[i]&&(r[i].__=e,t=re(r[i],t,n));return t}e.__e!=t&&(t&&e.type&&!t.parentNode&&(t=C(e)),t=n.insertBefore(e.__e,t||null));do t&&=t.nextSibling;while(t!=null&&t.nodeType==8);return t}function ie(e,t,n,r){var i,a,o,s=e.key,c=e.type,l=t[n],u=l!=null&&!(2&l.__u);if(l===null&&s==null||u&&s==l.key&&c==l.type)return n;if(r>+!!u){for(i=n-1,a=n+1;i>=0||a<t.length;)if((l=t[o=i>=0?i--:a++])!=null&&!(2&l.__u)&&s==l.key&&c==l.type)return o}return-1}function ae(e,t,n){t[0]==`-`?e.setProperty(t,n??``):e[t]=n==null?``:typeof n!=`number`||_.test(t)?n:n+`px`}function k(e,t,n,r,i){var a,o;n:if(t==`style`){if(typeof n==`string`)e.style.cssText=n;else{if(typeof r==`string`&&(e.style.cssText=r=``),r)for(t in r)n&&t in n||ae(e.style,t,``);if(n)for(t in n)r&&n[t]==r[t]||ae(e.style,t,n[t])}}else if(t[0]==`o`&&t[1]==`n`)a=t!=(t=t.replace(d,`$1`)),o=t.toLowerCase(),t=o in e||t==`onFocusOut`||t==`onFocusIn`?o.slice(2):t.slice(2),e.l||={},e.l[t+a]=n,n?r?n[u]=r[u]:(n[u]=f,e.addEventListener(t,a?m:p,a)):e.removeEventListener(t,a?m:p,a);else{if(i==`http://www.w3.org/2000/svg`)t=t.replace(/xlink(H|:h)/,`h`).replace(/sName$/,`s`);else if(t!=`width`&&t!=`height`&&t!=`href`&&t!=`list`&&t!=`form`&&t!=`tabIndex`&&t!=`download`&&t!=`rowSpan`&&t!=`colSpan`&&t!=`role`&&t!=`popover`&&t in e)try{e[t]=n??``;break n}catch{}typeof n==`function`||(n==null||!1===n&&t[4]!=`-`?e.removeAttribute(t):e.setAttribute(t,t==`popover`&&n==1?``:n))}}function oe(e){return function(n){if(this.l){var r=this.l[n.type+e];if(n[l]==null)n[l]=f++;else if(n[l]<r[u])return;return r(t.event?t.event(n):n)}}}function se(e,n,r,i,a,o,s,c,l,u){var d,f,p,m,h,_,b,x,w,T,E,D,O,re,ie,ae,k=n.type;if(n.constructor!==void 0)return null;128&r.__u&&(l=!!(32&r.__u),o=[c=n.__e=r.__e]),(d=t.__b)&&d(n);n:if(typeof k==`function`){f=s.length;try{if(w=n.props,T=k.prototype&&k.prototype.render,E=(d=k.contextType)&&i[d.__c],D=d?E?E.props.value:d.__:i,r.__c?x=(p=n.__c=r.__c).__=p.__E:(T?n.__c=p=new k(w,D):(n.__c=p=new te(w,D),p.constructor=k,p.render=me),E&&E.sub(p),p.state||(p.state={}),p.__n=i,m=p.__d=!0,p.__h=[],p._sb=[]),T&&p.__s==null&&(p.__s=p.state),T&&k.getDerivedStateFromProps!=null&&(p.__s==p.state&&(p.__s=y({},p.__s)),y(p.__s,k.getDerivedStateFromProps(w,p.__s))),h=p.props,_=p.state,p.__v=n,m)T&&k.getDerivedStateFromProps==null&&p.componentWillMount!=null&&p.componentWillMount(),T&&p.componentDidMount!=null&&p.__h.push(p.componentDidMount);else{if(T&&k.getDerivedStateFromProps==null&&w!==h&&p.componentWillReceiveProps!=null&&p.componentWillReceiveProps(w,D),n.__v==r.__v||!p.__e&&p.shouldComponentUpdate!=null&&!1===p.shouldComponentUpdate(w,p.__s,D)){n.__v!=r.__v&&(p.props=w,p.state=p.__s,p.__d=!1),n.__e=r.__e,n.__k=r.__k,n.__k.some(function(e){e&&(e.__=n)}),g.push.apply(p.__h,p._sb),p._sb=[],p.__h.length&&s.push(p),c=C(r);break n}p.componentWillUpdate!=null&&p.componentWillUpdate(w,p.__s,D),T&&p.componentDidUpdate!=null&&p.__h.push(function(){p.componentDidUpdate(h,_,b)})}if(p.context=D,p.props=w,p.__P=e,p.__e=!1,O=t.__r,re=0,T)p.state=p.__s,p.__d=!1,O&&O(n),d=p.render(p.props,p.state,p.context),g.push.apply(p.__h,p._sb),p._sb=[];else do p.__d=!1,O&&O(n),d=p.render(p.props,p.state,p.context),p.state=p.__s;while(p.__d&&++re<25);p.state=p.__s,p.getChildContext!=null&&(i=y(y({},i),p.getChildContext())),T&&!m&&p.getSnapshotBeforeUpdate!=null&&(b=p.getSnapshotBeforeUpdate(h,_)),ie=d!=null&&d.type===S&&d.key==null?ue(d.props.children):d,c=ne(e,v(ie)?ie:[ie],n,r,i,a,o,s,c,l,u),p.base=n.__e,n.__u&=-161,p.__h.length&&s.push(p),x&&(p.__E=p.__=null)}catch(e){if(s.length=f,n.__v=null,l||o!=null){if(e.then){for(n.__u|=l?160:128;c&&c.nodeType==8&&c.nextSibling;)c=c.nextSibling;o!=null&&(o[o.indexOf(c)]=null),n.__e=c}else if(o!=null)for(ae=o.length;ae--;)ee(o[ae])}else n.__e=r.__e;n.__k??=r.__k||[],e.then||ce(n),t.__e(e,n,r)}}else o==null&&n.__v==r.__v?(n.__k=r.__k,n.__e=r.__e):c=n.__e=de(r.__e,n,r,i,a,o,s,l,u);return(d=t.diffed)&&d(n),128&n.__u?void 0:c}function ce(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(ce))}function le(e,n,r){for(var i=0;i<r.length;i++)fe(r[i],r[++i],r[++i]);t.__c&&t.__c(n,e),e.some(function(n){try{e=n.__h,n.__h=[],e.some(function(e){e.call(n)})}catch(e){t.__e(e,n.__v)}})}function ue(e){return typeof e!=`object`||!e||e.__b>0?e:v(e)?e.map(ue):e.constructor===void 0?y({},e):null}function de(n,r,i,a,o,s,c,l,u){var d,f,p,m,g,_,y,b=i.props||h,x=r.props,S=r.type;if(S==`svg`?o=`http://www.w3.org/2000/svg`:S==`math`?o=`http://www.w3.org/1998/Math/MathML`:o||=`http://www.w3.org/1999/xhtml`,s!=null){for(d=0;d<s.length;d++)if((g=s[d])&&`setAttribute`in g==!!S&&(S?g.localName==S:g.nodeType==3)){n=g,s[d]=null;break}}if(n==null){if(S==null)return document.createTextNode(x);n=document.createElementNS(o,S,x.is&&x),l&&=(t.__m&&t.__m(r,s),!1),s=null}if(S==null)b===x||l&&n.data==x||(n.data=x);else{if(s=S==`textarea`&&x.defaultValue!=null?null:s&&e.call(n.childNodes),!l&&s!=null)for(b={},d=0;d<n.attributes.length;d++)b[(g=n.attributes[d]).name]=g.value;for(d in b)g=b[d],d==`dangerouslySetInnerHTML`?p=g:d==`children`||d in x||d==`value`&&`defaultValue`in x||d==`checked`&&`defaultChecked`in x||k(n,d,null,g,o);for(d in x)g=x[d],d==`children`?m=g:d==`dangerouslySetInnerHTML`?f=g:d==`value`?_=g:d==`checked`?y=g:l&&typeof g!=`function`||b[d]===g||k(n,d,g,b[d],o);if(f)l||p&&(f.__html==p.__html||f.__html==n.innerHTML)||(n.innerHTML=f.__html),r.__k=[];else if(p&&(n.innerHTML=``),ne(r.type==`template`?n.content:n,v(m)?m:[m],r,i,a,S==`foreignObject`?`http://www.w3.org/1999/xhtml`:o,s,c,s?s[0]:i.__k&&C(i,0),l,u),s!=null)for(d=s.length;d--;)ee(s[d]);l&&S!=`textarea`||(d=`value`,S==`progress`&&_==null?n.removeAttribute(`value`):_!=null&&(_!==n[d]||S==`progress`&&!_||S==`option`&&_!=b[d])&&k(n,d,_,b[d],o),d=`checked`,y!=null&&y!=n[d]&&k(n,d,y,b[d],o))}return n}function fe(e,n,r){try{if(typeof e==`function`){var i=typeof e.__u==`function`;i&&e.__u(),i&&n==null||(e.__u=e(n))}else e.current=n}catch(e){t.__e(e,r)}}function pe(e,n,r){var i,a;if(t.unmount&&t.unmount(e),(i=e.ref)&&(i.current&&i.current!=e.__e||fe(i,null,n)),(i=e.__c)!=null){if(i.componentWillUnmount)try{i.componentWillUnmount()}catch(e){t.__e(e,n)}i.base=i.__P=i.__n=null}if(i=e.__k)for(a=0;a<i.length;a++)i[a]&&pe(i[a],n,r||typeof e.type!=`function`);r||ee(e.__e),e.__c=e.__=e.__e=void 0}function me(e,t,n){return this.constructor(e,n)}function he(n,r,i){var a,o,s,c;r==document&&(r=document.documentElement),t.__&&t.__(n,r),o=(a=typeof i==`function`)?null:i&&i.__k||r.__k,s=[],c=[],se(r,n=(!a&&i||r).__k=b(S,null,[n]),o||h,h,r.namespaceURI,!a&&i?[i]:o?null:r.firstChild?e.call(r.childNodes):null,s,!a&&i?i:o?o.__e:r.firstChild,a,c),le(s,n,c),n.props.children=null}e=g.slice,t={__e:function(e,t,n,r){for(var i,a,o;t=t.__;)if((i=t.__c)&&!i.__)try{if((a=i.constructor)&&a.getDerivedStateFromError!=null&&(i.setState(a.getDerivedStateFromError(e)),o=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(e,r||{}),o=i.__d),o)return i.__E=i}catch(t){e=t}throw e}},n=0,r=function(e){return e!=null&&e.constructor===void 0},te.prototype.setState=function(e,t){var n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=y({},this.state);typeof e==`function`&&(e=e(y({},n),this.props)),e&&y(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),E(this))},te.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),E(this))},te.prototype.render=S,i=[],o=typeof Promise==`function`?Promise.prototype.then.bind(Promise.resolve()):setTimeout,s=function(e,t){return e.__v.__b-t.__v.__b},D.__r=0,c=Math.random().toString(8),l=`__d`+c,u=`__a`+c,d=/(PointerCapture)$|Capture$/i,f=0,p=oe(!1),m=oe(!0);var ge,A,_e,ve,ye=0,be=[],j=t,xe=j.__b,Se=j.__r,Ce=j.diffed,we=j.__c,Te=j.unmount,Ee=j.__;function De(e,t){j.__h&&j.__h(A,e,ye||t),ye=0;var n=A.__H||(A.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function M(e){return ye=1,Oe(Le,e)}function Oe(e,t,n){var r=De(ge++,2);if(r.t=e,!r.__c&&(r.__=[n?n(t):Le(void 0,t),function(e){var t=r.__N?r.__N[0]:r.__[0],n=r.t(t,e);t!==n&&(r.__N=[n,r.__[1]],r.__c.setState({}))}],r.__c=A,!A.__f)){var i=function(e,t,n){if(!r.__c.__H)return!0;var i=!1,o=r.__c.props!==e;if(r.__c.__H.__.some(function(e){if(e.__N){i=!0;var t=e.__[0];e.__=e.__N,e.__N=void 0,t!==e.__[0]&&(o=!0)}}),a){var s=a.call(this,e,t,n);return i?s||o:s}return!i||o};A.__f=!0;var a=A.shouldComponentUpdate,o=A.componentWillUpdate;A.componentWillUpdate=function(e,t,n){if(this.__e){var r=a;a=void 0,i(e,t,n),a=r}o&&o.call(this,e,t,n)},A.shouldComponentUpdate=i}return r.__N||r.__}function N(e,t){var n=De(ge++,3);!j.__s&&Ie(n.__H,t)&&(n.__=e,n.u=t,A.__H.__h.push(n))}function ke(e){return ye=5,Ae(function(){return{current:e}},[])}function Ae(e,t){var n=De(ge++,7);return Ie(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function je(){for(var e;e=be.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(Pe),t.__h.some(Fe),t.__h=[]}catch(n){t.__h=[],j.__e(n,e.__v)}}}j.__b=function(e){A=null,xe&&xe(e)},j.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),Ee&&Ee(e,t)},j.__r=function(e){Se&&Se(e),ge=0;var t=(A=e.__c).__H;t&&(_e===A?(t.__h=[],A.__h=[],t.__.some(function(e){e.__N&&(e.__=e.__N),e.u=e.__N=void 0})):(t.__h.some(Pe),t.__h.some(Fe),t.__h=[],ge=0)),_e=A},j.diffed=function(e){Ce&&Ce(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(be.push(t)!==1&&ve===j.requestAnimationFrame||((ve=j.requestAnimationFrame)||Ne)(je)),t.__H.__.some(function(e){e.u&&=(e.__H=e.u,void 0)})),_e=A=null},j.__c=function(e,t){t.some(function(e){try{e.__h.some(Pe),e.__h=e.__h.filter(function(e){return!e.__||Fe(e)})}catch(n){t.some(function(e){e.__h&&=[]}),t=[],j.__e(n,e.__v)}}),we&&we(e,t)},j.unmount=function(e){Te&&Te(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(e){try{Pe(e)}catch(e){t=e}}),n.__H=void 0,t&&j.__e(t,n.__v))};var Me=typeof requestAnimationFrame==`function`;function Ne(e){var t,n=function(){clearTimeout(r),Me&&cancelAnimationFrame(t),setTimeout(e)},r=setTimeout(n,35);Me&&(t=requestAnimationFrame(n))}function Pe(e){var t=A,n=e.__c;typeof n==`function`&&(e.__c=void 0,n()),A=t}function Fe(e){var t=A;e.__c=e.__(),A=t}function Ie(e,t){return!e||e.length!==t.length||t.some(function(t,n){return t!==e[n]})}function Le(e,t){return typeof t==`function`?t(e):t}var Re=Symbol.for(`preact-signals`);function ze(){if(F>1)F--;else{var e,t=!1;for((function(){var e=qe;for(qe=void 0;e!==void 0;){var t=e.S;if(t.v===e.v)for(var n=t.t;n!==void 0;n=n.x)n.i===e.i&&(n.i=t.i);e=e.o}})();Ue!==void 0;){var n=Ue;for(Ue=void 0,We++;n!==void 0;){var r=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&Xe(n))try{n.c()}catch(n){t||=(e=n,!0)}n=r}}if(We=0,F--,t)throw e}}function Be(e){if(F>0)return e();Ke=++Ge,F++;try{return e()}finally{ze()}}var Ve,P=void 0;function He(e){var t=P,n=Ve;P=void 0,Ve=void 0;try{return e()}finally{P=t,Ve=n}}var Ue=void 0,F=0,We=0,Ge=0,Ke=0,qe=void 0,Je=0;function Ye(e){if(P!==void 0){var t=e.n;if(t===void 0||t.t!==P)return t={i:0,S:e,p:P.s,n:void 0,t:P,e:void 0,x:void 0,r:t},P.s!==void 0&&(P.s.n=t),P.s=t,e.n=t,32&P.f&&e.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=P.s,t.n=void 0,P.s.n=t,P.s=t),t}}function I(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}I.prototype.brand=Re,I.prototype.h=function(){return!0},I.prototype.S=function(e){var t=this,n=this.t;n!==e&&e.e===void 0&&(e.x=n,this.t=e,n===void 0?He(function(){var e;(e=t.W)==null||e.call(t)}):n.e=e)},I.prototype.U=function(e){var t=this;if(this.t!==void 0){var n=e.e,r=e.x;n!==void 0&&(n.x=r,e.e=void 0),r!==void 0&&(r.e=n,e.x=void 0),e===this.t&&(this.t=r,r===void 0&&He(function(){var e;(e=t.Z)==null||e.call(t)}))}},I.prototype.subscribe=function(e){var t=this;return rt(function(){var n=t.value;He(function(){return e(n)})},{name:`sub`})},I.prototype.valueOf=function(){return this.value},I.prototype.toString=function(){return this.value+``},I.prototype.toJSON=function(){return this.value},I.prototype.peek=function(){var e=this;return He(function(){return e.value})},Object.defineProperty(I.prototype,"value",{get:function(){var e=Ye(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(We>100)throw Error(`Cycle detected`);(function(e){F!==0&&We===0&&e.l!==Ke&&(e.l=Ke,qe={S:e,v:e.v,i:e.i,o:qe})})(this),this.v=e,this.i++,Je++,F++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{ze()}}}});function L(e,t){return new I(e,t)}function Xe(e){for(var t=e.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function Ze(e){for(var t=e.s;t!==void 0;t=t.n){var n=t.S.n;if(n!==void 0&&(t.r=n),t.S.n=t,t.i=-1,t.n===void 0){e.s=t;break}}}function Qe(e){for(var t=e.s,n=void 0;t!==void 0;){var r=t.p;t.i===-1?(t.S.U(t),r!==void 0&&(r.n=t.n),t.n!==void 0&&(t.n.p=r)):n=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=r}e.s=n}function R(e,t){I.call(this,void 0,t),this.x=e,this.s=void 0,this.g=Je-1,this.f=4}R.prototype=new I,R.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===Je))return!0;if(this.g=Je,this.f|=1,this.i>0&&!Xe(this))return this.f&=-2,!0;var e=P;try{Ze(this),P=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(e){this.v=e,this.f|=16,this.i++}return P=e,Qe(this),this.f&=-2,!0},R.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}I.prototype.S.call(this,e)},R.prototype.U=function(e){if(this.t!==void 0&&(I.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}},R.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}},Object.defineProperty(R.prototype,"value",{get:function(){if(1&this.f)throw Error(`Cycle detected`);var e=Ye(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function $e(e,t){return new R(e,t)}function et(e){var t=e.m;if(e.m=void 0,typeof t==`function`){F++;var n=P;P=void 0;try{t()}catch(t){throw e.f&=-2,e.f|=8,tt(e),t}finally{P=n,ze()}}}function tt(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,et(e)}function nt(e){if(P!==this)throw Error(`Out-of-order effect`);Qe(this),P=e,this.f&=-2,8&this.f&&tt(this),ze()}function z(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name,Ve&&Ve.push(this)}z.prototype.c=function(){var e=this.S();try{if(8&this.f||this.x===void 0)return;var t=this.x();typeof t==`function`&&(this.m=t)}finally{e()}},z.prototype.S=function(){if(1&this.f)throw Error(`Cycle detected`);this.f|=1,this.f&=-9,et(this),Ze(this),F++;var e=P;return P=this,nt.bind(this,e)},z.prototype.N=function(){2&this.f||(this.f|=2,this.u=Ue,Ue=this)},z.prototype.d=function(){this.f|=8,1&this.f||tt(this)},z.prototype.dispose=function(){this.d()};function rt(e,t){var n=new z(e,t);try{n.c()}catch(e){throw n.d(),e}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var it,at,ot=typeof window<`u`&&!!window.__PREACT_SIGNALS_DEVTOOLS__,st=[];rt(function(){it=this.N})();function B(e,n){t[e]=n.bind(null,t[e]||function(){})}function ct(e){if(at){var t=at;at=void 0,t()}at=e&&e.S()}function lt(e){var t=this,n=e.data,i=dt(n);i.name=`ReactiveDom`,i.value=n;var a=Ae(function(){for(var e=t,n=t.__v;n=n.__;)if(n.__c){n.__c.__$f|=4;break}var a=$e(function(){var e=i.value.value;return e===0?0:!0===e?``:e||``}),o=$e(function(){return!Array.isArray(a.value)&&!r(a.value)}),s=rt(function(){if(this.N=mt,o.value){var t=a.value;e.__v&&e.__v.__e&&e.__v.__e.nodeType===3&&(e.__v.__e.data=t)}}),c=t.__$u.d;return t.__$u.d=function(){s(),c.call(this)},[o,a]},[]),o=a[0],s=a[1];return o.value?s.peek():s.value}lt.displayName=`ReactiveTextNode`,Object.defineProperties(I.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:lt},props:{configurable:!0,get:function(){var e=this;return{data:{get value(){return e.value}}}}},__b:{configurable:!0,value:1}}),B(`__b`,function(e,t){if(ct(),typeof t.type==`string`){var n,r=t.props;for(var i in r)if(i!==`children`){var a=r[i];a instanceof I&&(n||(t.__np=n={}),n[i]=a,r[i]=a.peek())}}e(t)}),B(`__r`,function(e,t){if(e(t),t.type!==S){ct();var n,r=t.__c;r&&(r.__$f&=-2,(n=r.__$u)===void 0&&(r.__$u=n=function(e,t){var n;return rt(function(){n=this},{name:t}),n.c=e,n}(function(e){return function(){var t;ot&&((t=this.y)==null||t.call(this)),e.__$f|=1,e.setState({})}}(r),typeof t.type==`function`?t.type.displayName||t.type.name:``))),ct(n)}}),B(`__e`,function(e,t,n,r){ct(),e(t,n,r)}),B(`diffed`,function(e,t){ct();var n;if(typeof t.type==`string`&&(n=t.__e)){var r=t.__np,i=t.props,a=n.U;if(a)for(var o in a){var s=a[o];s===void 0||r&&o in r||(s.d(),a[o]=void 0)}if(r)for(var c in a||(a={},n.U=a),r){var l=a[c],u=r[c];l===void 0?(l=ut(n,c,u,i),a[c]=l):l.o(u,i)}}e(t)});function ut(e,t,n,r){var i=t in e&&e.ownerSVGElement===void 0,a=L(n);return{o:function(e,t){a.value=e,r=t},d:rt(function(){this.N=mt;var n=a.value.value;r[t]!==n&&(r[t]=n,i?e[t]=n:n!=null&&(!1!==n||t[4]===`-`)?e.setAttribute(t,n):e.removeAttribute(t))})}}B(`unmount`,function(e,t){if(typeof t.type==`string`){var n=t.__e;if(n){var r=n.U;if(r)for(var i in n.U=void 0,r){var a=r[i];a&&a.d()}}var o=t.__np;if(o){var s=t.props;for(var c in o)s[c]=o[c]}t.__np=void 0}else{var l=t.__c;if(l){l.__$f|=8;var u=l.__$u;u&&(l.__$u=void 0,u.d())}}e(t)}),B(`__h`,function(e,t,n,r){r<3&&(t.__$f|=2),e(t,n,r)}),te.prototype.shouldComponentUpdate=function(e,t){if(this.__R)return!0;var n=this.__$u,r=n&&n.s!==void 0;for(var i in t)return!0;if(this.__f||typeof this.u==`boolean`&&!0===this.u){var a=2&this.__$f;if(!(r||a||4&this.__$f)||1&this.__$f)return!0}else if(!(r||4&this.__$f)||3&this.__$f)return!0;for(var o in e)if(o!==`__source`&&e[o]!==this.props[o])return!0;for(var s in this.props)if(!(s in e))return!0;return!1};function dt(e,t){return Ae(function(){return L(e,t)},[])}var ft=function(e){queueMicrotask(function(){queueMicrotask(e)})};function pt(){Be(function(){for(var e;e=st.shift();)it.call(e)})}function mt(){st.push(this)===1&&(t.requestAnimationFrame||ft)(pt)}var V=e=>e,ht={up:{label:`Up`,icon:`↑`},provision:{label:`Provision`,icon:`+`},deploy:{label:`Deploy`,icon:`↑`},setup:{label:`Setup`,icon:`⚙`},plan:{label:`Plan`,icon:`≡`},verify:{label:`Verify`,icon:`✓`},apps:{label:`Register apps`,icon:`▦`},hosts:{label:`Local hosts`,icon:`⌂`},ssh:{label:`SSH terminal`,icon:`>_`},"ssh.exec":{label:`SSH command`,icon:`>`},down:{label:`Destroy`,icon:`×`},adopt:{label:`Adopt`,icon:`+`},"backup.test":{label:`Test backup`,icon:`✓`},"app.check":{label:`Check app repository`,icon:`✓`},"app.purge":{label:`Purge app data`,icon:`×`},"app.runs":{label:`App runs`,icon:`≡`},"app.log":{label:`App log`,icon:`≡`},"app.deploy":{label:`Deploy app`,icon:`↑`},"app.releases":{label:`App releases`,icon:`≡`},"app.rollback":{label:`Roll back app`,icon:`↶`},job:{label:`Run job`,icon:`▶`},status:{label:`Status`,icon:`●`},validate:{label:`Validate`,icon:`✓`},doctor:{label:`Doctor`,icon:`✓`},certs:{label:`Local certificates`,icon:`◇`},version:{label:`Version`,icon:`i`}},gt=e=>typeof e==`object`&&!!e&&!Array.isArray(e),_t=e=>gt(e)?e:V({}),vt=e=>Array.isArray(e)?e.filter(e=>typeof e==`string`):V([]),yt=e=>Object.freeze(Object.entries(_t(e.properties)).map(([t,n])=>{let r=_t(n);return{name:t,type:r.type,required:vt(e.required).includes(t),description:typeof r.description==`string`?r.description:``,choices:vt(r.enum),default:r.default,minLength:typeof r.minLength==`number`?r.minLength:void 0,pattern:typeof r.pattern==`string`?r.pattern:void 0,supported:r.type===`string`||r.type===`boolean`||r.type===`array`&&_t(r.items).type===`string`}})),bt=e=>typeof e==`boolean`||typeof e==`string`?e:Array.isArray(e)?vt(e).join(`
|
|
2
|
+
`):V(``),xt=(e,t)=>Object.freeze(Object.fromEntries(yt(e).map(e=>[e.name,bt(t[e.name]??e.default)]))),St=(e,t)=>Object.freeze(Object.fromEntries(yt(e).flatMap(e=>{let n=t[e.name];return e.type===`boolean`?V([[e.name,n===!0]]):V(typeof n!=`string`||n===``?[]:[[e.name,e.type===`array`?n.split(/\r?\n/):n]])}))),Ct=(e,t)=>Object.freeze(e.filter(e=>e.scope===`app`&&t.kind===`platform`||e.scope===`server`&&(t.commands.some(t=>t===e.name)||e.name===`ssh`||e.name===`ssh.exec`||e.name===`hosts`&&t.target===`multipass`))),wt=(e,t)=>{let n=t.toLowerCase().replace(/\s+/g,``);if(n===``)return V(0);let r=e.toLowerCase(),i=Array.from(n).reduce((e,t)=>{if(e===void 0)return;let n=r.indexOf(t,e.at);return n===-1?void 0:{at:n+1,gaps:e.gaps+(e.first===-1?0:n-e.at),first:e.first===-1?n:e.first}},{at:0,gaps:0,first:-1});return i===void 0?void 0:i.gaps*2+i.first+(r.startsWith(n)?-10:0)},Tt=(e,t)=>Object.freeze(e.flatMap(e=>{let n=wt(`${e.label} ${e.hint}`,t);return Object.freeze(n===void 0?[]:[{choice:e,scored:n}])}).toSorted((e,t)=>e.scored-t.scored).map(e=>e.choice)),Et=e=>e,Dt=async(e,t)=>e.ok?V({ok:!0,value:Et(await t(e))}):V({ok:!1,failure:{status:e.status,message:(await e.text()).trim()}}),Ot=async e=>{try{return await e()}catch{return V({ok:!1,failure:{status:0,message:`Cannot reach kayra. Check that kayra serve is still running.`}})}},kt=e=>Ot(()=>fetch(e).then(e=>Dt(e,e=>e.json()))),H=(e,t)=>Ot(async()=>Dt(await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)}),async e=>e.status===204?void 0:e.json())),At=(e,t)=>H(`/api/operations/${e.name}/preview`,{input:e.input,options:t}),jt=(e,t,n)=>H(`/api/operations/${e.name}`,{input:e.input,options:t,...n===void 0?{}:{confirm:n}}),Mt=(e,t={})=>H(`/api/operations/${e}`,{input:t}),Nt=(e,t)=>H(`/api/runs/${encodeURIComponent(e)}/answers`,{text:t}),Pt=e=>H(`/api/runs/${encodeURIComponent(e)}/cancel`,{}),Ft=(e,t)=>H(`/api/sessions/${encodeURIComponent(e)}/input`,{text:t}),It=e=>Ot(async()=>Dt(await fetch(`/api/sessions/${encodeURIComponent(e)}`,{method:`DELETE`}),()=>Promise.resolve(void 0))),Lt=()=>kt(`/api/runs`),Rt=(e,t,n,r,i)=>{let a=new AbortController;return(async()=>{let n=await fetch(e,{signal:a.signal,...r===void 0?{}:{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(r)}});if(!n.ok){i?.({status:n.status,message:(await n.text()).trim()});return}if(n.body===null)throw Error(`No stream`);let o=n.body.getReader(),s=new TextDecoder,c={text:``},l=async()=>{let e=await o.read();if(e.done)return;let n=(c.text+s.decode(e.value,{stream:!0})).split(`
|
|
3
|
+
|
|
4
|
+
`);c.text=n.pop()??``,n.forEach(e=>{e.startsWith(`data: `)&&t(Et(JSON.parse(e.slice(6))))}),await l()};await l()})().catch(()=>{a.signal.aborted||i?.({status:0,message:`The connection to kayra was interrupted.`})}).finally(n),()=>{a.abort()}},zt=/^[A-Za-z0-9._-]+$/,Bt=e=>{let t=e.split(`/`).filter(e=>e!==``).map(decodeURIComponent);if(!t.every(e=>zt.test(e)))return V({page:`missing`,path:e});let[n,r,i,a]=t;return n===void 0?V({page:`fleet`}):n===`runs`&&r===void 0?V({page:`runs`}):n===`runs`&&r!==void 0&&i===void 0?V({page:`run`,id:r}):n===`sessions`&&r!==void 0&&i===void 0?V({page:`session`,id:r}):n===`validate`&&r===void 0?V({page:`validate`}):n===`servers`&&r!==void 0&&i===void 0?V({page:`server`,server:r}):n===`servers`&&r!==void 0&&i===`apps`&&a!==void 0&&t.length===4?V({page:`app`,server:r,app:a}):V({page:`missing`,path:e})},Vt=e=>{switch(e.page){case`fleet`:return`/`;case`server`:return`/servers/${encodeURIComponent(e.server)}`;case`app`:return`/servers/${encodeURIComponent(e.server)}/apps/${encodeURIComponent(e.app)}`;case`runs`:return`/runs`;case`run`:return`/runs/${encodeURIComponent(e.id)}`;case`session`:return`/sessions/${encodeURIComponent(e.id)}`;case`validate`:return`/validate`;case`missing`:return e.path}},Ht=L(Bt(location.pathname)),Ut=e=>{history.pushState(null,``,Vt(e)),Ht.value=e,scrollTo({top:0})};addEventListener(`popstate`,()=>{Ht.value=Bt(location.pathname)});var U=L({state:`loading`}),Wt=L({state:`loading`}),Gt=async()=>{let e=await kt(`/api/operations`);Wt.value=e.ok?{state:`ready`,value:e.value}:{state:`failed`,failure:e.failure}},W=L({value:void 0,live:!1}),Kt=L({state:`loading`}),qt=async()=>{let e=await kt(`/api/fleet`);U.value=e.ok?{state:`ready`,value:e.value}:{state:`failed`,failure:e.failure}},Jt=()=>{W.value={value:W.value.value,live:!0},Rt(`/api/operations/status`,e=>{W.value={value:e,live:!0}},()=>{W.value={value:W.value.value,live:!1}},{input:{}})},Yt=async()=>{Kt.value={state:`loading`};let e=await Mt(`validate`);Kt.value=e.ok?{state:`ready`,value:e.value}:{state:`failed`,failure:e.failure}},Xt=0;Array.isArray;function G(e,n,r,i,a,o){n||={};var s,c,l=n;if(`ref`in l)for(c in l={},n)c==`ref`?s=n[c]:l[c]=n[c];var u={type:e,props:l,key:r,ref:s,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Xt,__i:-1,__u:0,__source:a,__self:o};if(typeof e==`function`&&(s=e.defaultProps))for(c in s)l[c]===void 0&&(l[c]=s[c]);return t.vnode&&t.vnode(u),u}var Zt=(e,t)=>{if(typeof e==`string`)return e;let n=e.tone===void 0?void 0:`tone-${e.tone}`;return e.href===void 0?G(`span`,{class:n,children:e.text},t):G(`a`,{class:n,href:e.href,target:`_blank`,rel:`noreferrer`,children:e.text},t)},Qt=({text:e})=>G(S,{children:(typeof e==`string`?[e]:e).map(Zt)}),$t=({lines:e})=>G(`div`,{class:`lines`,children:e.map((e,t)=>G(`div`,{children:G(Qt,{text:e})},t))}),K=({tone:e,label:t})=>G(`span`,{class:`dot dot-${e}`,title:t,"aria-label":t,role:t===void 0?void 0:`img`}),q=({children:e,tone:t})=>G(`span`,{class:`pill${t===void 0?``:` pill-${t}`}`,children:e}),J=({label:e,cell:t})=>t===void 0?null:G(`div`,{class:`fact`,children:[G(`dt`,{children:e}),G(`dd`,{title:t.title,children:[G(K,{tone:t.tone}),G(`span`,{class:t.tone===`waiting`?`tone-muted`:`tone-${t.tone}`,children:t.text})]})]}),Y=({failure:e})=>G(`div`,{class:`problem`,role:`alert`,children:[G(`strong`,{children:e.status===0?`Connection problem`:`kayra answered ${String(e.status)}`}),G(`pre`,{children:e.message})]}),X=({what:e})=>G(`div`,{class:`waiting`,children:[G(`span`,{class:`spinner`,"aria-hidden":`true`}),` `,e]}),Z=({title:e,sub:t,children:n})=>G(`header`,{class:`page-header`,children:[G(`div`,{children:[G(`h1`,{children:e}),t===void 0?null:G(`div`,{class:`sub`,children:t})]}),n===void 0?null:G(`div`,{class:`actions`,children:n})]}),en=({initial:e,choose:t,close:n})=>{let[r,i]=M(e===``?`.`:e),[a,o]=M(void 0);return N(()=>{let e={current:!1};return o(void 0),kt(`/api/directories?path=${encodeURIComponent(r)}`).then(t=>{e.current||o(t)}),()=>{e.current=!0}},[r]),G(`section`,{class:`directory-picker`,"aria-label":`Choose a local directory`,children:[G(`div`,{class:`buttons`,children:[G(`strong`,{children:`Choose a local directory`}),G(`button`,{type:`button`,class:`button small`,onClick:n,children:`Close picker`})]}),a===void 0?G(X,{what:`Reading directories`}):a.ok?G(S,{children:[G(`code`,{class:`directory-path`,children:a.value.path}),G(`ul`,{class:`directory-list`,children:[a.value.parent===a.value.path?null:G(`li`,{children:G(`button`,{type:`button`,onClick:()=>{i(a.value.parent)},children:`↑ Parent directory`})}),a.value.directories.map(e=>G(`li`,{children:G(`button`,{type:`button`,onClick:()=>{i(e.path)},children:[`▸ `,e.name]})},e.path))]}),G(`button`,{type:`button`,class:`button`,onClick:()=>{t(a.value.path)},children:`Use this directory`})]}):G(Y,{failure:a.failure})]})},tn=L(void 0),nn=(e,t={})=>{tn.value={name:e,input:t}},rn=e=>{nn(e.name,Object.fromEntries(Object.entries(e).filter(([e])=>e!==`name`)))},Q=()=>{tn.value=void 0},an=({step:e})=>G(`li`,{class:`plan-step`,children:[G(`span`,{class:`plan-index`,children:e.index+1}),G(`div`,{children:[G(`div`,{class:`plan-title`,children:[G(q,{tone:e.kind===`guard`?`warn`:e.kind===`confirm`?`bad`:`active`,children:e.kind}),` `,e.title]}),e.command===void 0?null:G(`code`,{class:`plan-command`,children:e.command})]})]}),on=({field:e,value:t,change:n,server:r})=>{let[i,a]=M(!1),o=U.value,s=o.state===`ready`?o.value.servers:[],c=typeof t==`string`?t:``,l=`operation-${e.name}`;return e.type===`boolean`?G(`label`,{class:`toggle`,children:[G(`input`,{type:`checkbox`,checked:t===!0,onChange:e=>{n(e.currentTarget.checked)}}),e.description||e.name]}):G(`div`,{class:`operation-field`,children:[G(`label`,{for:l,children:[e.name,e.required?``:` (optional)`]}),e.name===`server`||e.choices.length>0?G(`select`,{id:l,required:e.required,value:c,onChange:e=>{n(e.currentTarget.value)},children:[G(`option`,{value:``,children:e.required?`Choose…`:`All servers`}),(e.name===`server`?s.map(e=>e.name):e.choices).map(e=>G(`option`,{value:e,children:e},e))]}):e.type===`array`?G(`textarea`,{id:l,rows:3,value:c,required:e.required,placeholder:`One item per line`,onInput:e=>{n(e.currentTarget.value)}}):G(`div`,{class:`inline`,children:[G(`input`,{id:l,value:c,required:e.required,minLength:e.minLength,pattern:e.pattern,list:e.name===`app`?`operation-apps`:void 0,spellcheck:!1,onInput:e=>{n(e.currentTarget.value)}}),e.name===`dir`?G(`button`,{type:`button`,class:`button`,onClick:()=>{a(!i)},children:`Browse…`}):null]}),e.name===`app`?G(`datalist`,{id:`operation-apps`,children:s.find(e=>e.name===r)?.apps.map(e=>G(`option`,{value:e},e))}):null,e.description===``?null:G(`span`,{class:`hint`,children:e.description}),e.type===`array`?G(`span`,{class:`hint`,children:[`One `,e.name===`command`?`argument`:`item`,` per line. Spaces within a line are preserved.`]}):null,i?G(en,{initial:c,close:()=>{a(!1)},choose:e=>{n(e),a(!1)}}):null]})},sn=({info:e,seed:t,options:n,submit:r})=>{let[i,a]=M(()=>xt(e.input,t.input)),[o,s]=M(n.verbose??!1),[c,l]=M(n.dryRun??!1),u=e.kind===`plan`||e.kind===`session`,d=yt(e.input),f=d.some(e=>!e.supported);return G(`form`,{onSubmit:t=>{t.preventDefault(),r({draft:{name:e.name,input:St(e.input,i)},options:{verbose:o,dryRun:c}})},children:[G(`div`,{class:`sheet-body operation-fields`,children:[d.map(e=>G(on,{field:e,value:i[e.name]??``,server:i.server,change:t=>{a({...i,[e.name]:t})}},e.name)),f?G(`p`,{role:`alert`,children:`This operation has an unsupported input. Update the UI before running it.`}):null,u?G(`fieldset`,{class:`run-options`,children:[G(`legend`,{children:`Run options`}),G(`label`,{class:`toggle`,children:[G(`input`,{type:`checkbox`,checked:o,onChange:e=>{s(e.currentTarget.checked)}}),`Verbose output`]}),G(`label`,{class:`toggle`,children:[G(`input`,{type:`checkbox`,checked:c,onChange:e=>{l(e.currentTarget.checked)}}),`Dry run — preview only`]})]}):null]}),G(`div`,{class:`sheet-foot buttons`,children:[G(`button`,{type:`button`,class:`button`,onClick:Q,children:`Cancel`}),G(`button`,{type:`submit`,class:`button primary`,disabled:f,children:u?`Preview plan`:`Run query`})]})]})},cn=e=>{let t=U.value,n=t.state===`ready`?t.value.servers.find(t=>t.name===e.input.server):void 0;return n?.target===`multipass`?void 0:n?.name},ln=({prepared:e,back:t})=>{let{draft:n,options:r}=e,[i,a]=M(void 0),[o,s]=M(``),[c,l]=M(void 0);if(N(()=>{At(n,r).then(a)},[e]),i===void 0)return G(`div`,{class:`sheet-body`,children:G(X,{what:`Planning`})});if(!i.ok)return G(`div`,{class:`sheet-body`,children:[G(Y,{failure:i.failure}),G(`button`,{class:`button`,onClick:t,children:`Edit inputs`})]});let{invocation:u,steps:d,changes:f}=i.value,p=f&&!r.dryRun?cn(n):void 0,m=p===void 0||o===p,h=async()=>{l(`starting`);let e=await jt(n,r,p===void 0?void 0:o);e.ok?(Q(),Ut(`session`in e.value?{page:`session`,id:e.value.session}:{page:`run`,id:e.value.run})):l(e.failure)};return G(S,{children:[G(`div`,{class:`sheet-body`,children:[G(`code`,{class:`command`,children:u.command}),G(`p`,{class:`sub`,children:[d.length,` steps · `,f?`changes things`:`reads only`,r.verbose?` · verbose`:``,r.dryRun?` · preview only`:``]}),G(`ol`,{class:`plan`,children:d.map(e=>G(an,{step:e},e.index))})]}),G(`form`,{class:`sheet-foot`,onSubmit:e=>{e.preventDefault(),m&&!r.dryRun&&h()},children:[p===void 0?null:G(`label`,{class:`confirm`,children:[G(`span`,{children:[`This changes `,G(`strong`,{children:p}),`, a real server. Type its name to go on:`]}),G(`input`,{value:o,onInput:e=>{s(e.currentTarget.value)},placeholder:p,autoComplete:`off`,spellcheck:!1})]}),c===void 0||c===`starting`?null:G(Y,{failure:c}),G(`div`,{class:`buttons`,children:[G(`button`,{type:`button`,class:`button`,onClick:t,disabled:c===`starting`,children:`Edit inputs`}),r.dryRun?G(`button`,{type:`button`,class:`button primary`,onClick:Q,children:`Done`}):G(`button`,{type:`submit`,class:p===void 0?`button primary`:`button danger`,disabled:!m||c===`starting`,children:c===`starting`?`Starting…`:n.name===`ssh`?`Open terminal`:`Run`})]})]})]})},un=({prepared:e,info:t,back:n})=>{let[r,i]=M(void 0),[a,o]=M(t.kind===`stream`);return N(()=>{let n={current:!0};return t.kind===`stream`?Rt(`/api/operations/${t.name}`,e=>{i({ok:!0,value:e})},()=>{o(!1)},{input:e.draft.input},e=>{i({ok:!1,failure:e})}):(Mt(t.name,e.draft.input).then(e=>{n.current&&i(e)}),()=>{n.current=!1})},[e]),G(S,{children:[G(`div`,{class:`sheet-body`,children:[r===void 0?G(X,{what:`Asking kayra`}):r.ok?G(`pre`,{class:`query-result`,children:typeof r.value==`string`?r.value:JSON.stringify(r.value,null,2)}):G(Y,{failure:r.failure}),a?G(X,{what:`Receiving updates`}):null]}),G(`div`,{class:`sheet-foot buttons`,children:[G(`button`,{class:`button`,onClick:n,children:`Edit inputs`}),G(`button`,{class:`button`,onClick:Q,children:`Close`})]})]})},dn=({draft:e,info:t})=>{let[n,r]=M(void 0),[i,a]=M({draft:e,options:{}}),o=()=>{n!==void 0&&a(n),r(void 0)};return G(S,{children:[G(`div`,{class:`sheet-head`,children:[G(`h2`,{id:`operation-title`,children:[ht[t.name].icon,` `,ht[t.name].label]}),G(`p`,{class:`sub`,children:t.summary})]}),n===void 0?G(sn,{info:t,seed:i.draft,options:i.options,submit:r}):t.kind===`plan`||t.kind===`session`?G(ln,{prepared:n,back:o}):G(un,{prepared:n,info:t,back:o})]})},fn=()=>{let e=tn.value,t=ke(null),n=e!==void 0;if(N(()=>{if(!n)return;let e=document.activeElement;t.current?.focus();let r=e=>{if(e.key===`Escape`&&Q(),e.key===`Tab`){let n=t.current?.querySelectorAll(`button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled)`),r=n?.[0],i=n?.[n.length-1];r===void 0?e.preventDefault():e.shiftKey&&(document.activeElement===r||document.activeElement===t.current)?(e.preventDefault(),i?.focus()):!e.shiftKey&&document.activeElement===i&&(e.preventDefault(),r.focus())}};return addEventListener(`keydown`,r),()=>{removeEventListener(`keydown`,r),e instanceof HTMLElement&&e.focus()}},[n]),e===void 0)return null;let r=Wt.value,i=r.state===`ready`?r.value.find(t=>t.name===e.name):void 0;return G(`div`,{class:`overlay`,onClick:Q,children:G(`div`,{ref:t,tabIndex:-1,class:`sheet`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`operation-title`,onClick:e=>{e.stopPropagation()},children:r.state===`loading`?G(X,{what:`Reading operations`}):r.state===`failed`?G(Y,{failure:r.failure}):i===void 0?G(`p`,{role:`alert`,children:`Operation unavailable.`}):G(dn,{draft:e,info:i},JSON.stringify(e))})})},$=L(!1),pn=()=>{let e=U.value,t=e.state===`ready`?e.value.servers:[],n=Wt.value.state===`ready`?Wt.value.value:[];return V([{label:`Fleet`,hint:`every server`,go:{page:`fleet`}},{label:`Runs`,hint:`what ran from here`,go:{page:`runs`}},{label:`Validate`,hint:`the fleet beyond its schemas`,go:{page:`validate`}},...n.map(e=>V({label:`${e.name} · ${ht[e.name].label}`,hint:e.summary,run:{name:e.name,input:{}}})),...t.flatMap(e=>V([{label:e.name,hint:`${e.kind} on ${e.target}`,go:{page:`server`,server:e.name}},...e.apps.map(t=>V({label:`${e.name}/${t}`,hint:`app`,go:{page:`app`,server:e.name,app:t}})),...Ct(n,e).map(t=>V({label:`${t.name} ${e.name}`,hint:t.summary,run:{name:t.name,input:{server:e.name}}}))]))])},mn=e=>{$.value=!1,`go`in e?Ut(e.go):nn(e.run.name,e.run.input)},hn=()=>{let[e,t]=M(``),[n,r]=M(0),i=ke(null),a=$.value;if(N(()=>{a&&i.current?.focus()},[a]),N(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`k`?(e.preventDefault(),$.value=!$.value,t(``),r(0)):e.key===`Escape`&&($.value=!1)};return addEventListener(`keydown`,e),()=>{removeEventListener(`keydown`,e)}},[]),!$.value)return null;let o=Tt(pn(),e).slice(0,12);return G(`div`,{class:`overlay`,onClick:()=>{$.value=!1},children:G(`div`,{class:`palette`,role:`dialog`,"aria-modal":`true`,onClick:e=>{e.stopPropagation()},children:[G(`input`,{ref:i,value:e,placeholder:`Go to, or run…`,spellcheck:!1,onInput:e=>{t(e.currentTarget.value),r(0)},onKeyDown:e=>{if(e.key===`ArrowDown`)r(Math.min(n+1,o.length-1));else if(e.key===`ArrowUp`)r(Math.max(n-1,0));else if(e.key===`Enter`){let e=o[n];e!==void 0&&mn(e)}else return;e.preventDefault()}}),G(`ul`,{children:o.map((e,t)=>G(`li`,{class:t===n?`selected`:void 0,onMouseEnter:()=>{r(t)},onClick:()=>{mn(e)},children:[G(`span`,{children:e.label}),G(`span`,{class:`hint`,children:e.hint})]},e.label))})]})})},gn=()=>{$.value=!0},_n=e=>e===null?``:` · ${String(e)} ms`,vn={pending:`asking`,open:`open`,answered:`answered`,refused:`refused`,"no-answer":`no answer`,unreachable:`unreachable`,"unknown-host":`unknown host`,"bad-certificate":`bad certificate`,failed:`failed`,skipped:`not asked`},yn=e=>{let{state:t,address:n,reason:r}=e.machine;switch(t){case`pending`:return V({text:`asking OpenTofu`,tone:`waiting`});case`found`:return V({text:n??`an address OpenTofu does not give`,tone:n===null?`warn`:`strong`});case`not-provisioned`:return V({text:`not provisioned`,tone:`muted`});case`no-machine`:return V({text:`no machine in its state`,tone:`muted`});case`unreadable`:return V({text:`state unreadable`,tone:`bad`,...r===null?{}:{title:r}})}},bn=e=>{let{state:t,error:n}=e.ssh;switch(t){case`pending`:return V({text:`connecting`,tone:`waiting`});case`open`:return V({text:`port ${String(e.ssh.port)} open${_n(e.ssh.ms)}`,tone:`ok`});case`refused`:return V({text:`off (refused)`,tone:`warn`,title:`Nothing listens: SSH may be on only on demand.`});case`skipped`:return V({text:`not asked`,tone:`muted`});case`answered`:case`no-answer`:case`unreachable`:case`unknown-host`:case`bad-certificate`:case`failed`:return V({text:vn[t],tone:`bad`,...n===null?{}:{title:n}})}},xn=e=>{let{https:t}=e;if(t!==null)switch(t.state){case`pending`:return V({text:`asking`,tone:`waiting`});case`answered`:return V({text:`HTTP ${String(t.status??`?`)}${_n(t.ms)}`,tone:t.status!==null&&t.status<400?`ok`:`bad`});case`skipped`:return V({text:`not asked`,tone:`muted`});case`open`:case`refused`:case`no-answer`:case`unreachable`:case`unknown-host`:case`bad-certificate`:case`failed`:return V({text:vn[t.state],tone:`bad`,...t.error===null?{}:{title:t.error}})}},Sn=e=>{if(e===void 0)return V(`waiting`);let t=[yn(e),bn(e),xn(e)].flatMap(e=>Object.freeze(e===void 0?[]:[e.tone]));return t.includes(`waiting`)?V(`waiting`):t.includes(`bad`)?V(`bad`):t.includes(`warn`)?V(`warn`):t.includes(`ok`)?V(`ok`):V(`muted`)},Cn=({to:e,children:t,class:n})=>G(`a`,{href:Vt(e),class:n,onClick:t=>{t.metaKey||t.ctrlKey||t.shiftKey||t.button!==0||(t.preventDefault(),Ut(e))},children:t}),wn=(e,t)=>Vt(e)===Vt(t),Tn=({to:e,label:t})=>G(Cn,{to:e,class:wn(Ht.value,e)?`nav-item current`:`nav-item`,children:t}),En=()=>{let e=U.value;if(e.state!==`ready`)return null;let t=Ht.value;return G(`nav`,{class:`servers`,"aria-label":`Servers`,children:[G(`div`,{class:`nav-title`,children:`Servers`}),e.value.servers.map(e=>G(Cn,{to:{page:`server`,server:e.name},class:`server`in t&&t.server===e.name?`nav-item current`:`nav-item`,children:[G(K,{tone:Sn(W.value.value?.servers.find(t=>t.name===e.name))}),G(`span`,{children:e.name}),G(`span`,{class:`nav-meta`,children:e.kind})]},e.name))]})},Dn=({children:e})=>{let t=U.value;return G(`div`,{class:`shell`,children:[G(`aside`,{class:`sidebar`,children:[G(Cn,{to:{page:`fleet`},class:`brand`,children:[G(`span`,{class:`logo`,"aria-hidden":`true`,children:`k`}),G(`span`,{children:[G(`strong`,{children:`kayra`}),G(`span`,{class:`brand-sub`,children:t.state===`ready`?t.value.fleet:`…`})]})]}),G(`nav`,{"aria-label":`Pages`,children:[G(Tn,{to:{page:`fleet`},label:`Fleet`}),G(Tn,{to:{page:`runs`},label:`Runs`}),G(Tn,{to:{page:`validate`},label:`Validate`})]}),G(En,{}),G(`div`,{class:`sidebar-foot`,children:t.state===`ready`?`kayra ${t.value.version}`:``})]}),G(`main`,{class:`main`,children:e})]})},On=e=>{let t=Math.max(0,e)/1e3;if(t<10)return`${(Math.floor(t*10)/10).toFixed(1)}s`;if(t<60)return`${String(Math.floor(t))}s`;let n=Math.floor(t/60);return n<60?`${String(n)}m${String(Math.floor(t%60)).padStart(2,`0`)}s`:`${String(Math.floor(n/60))}h${String(n%60).padStart(2,`0`)}m`},kn=e=>{let t=Math.floor(Math.max(0,e)/1e3);if(t<10)return`just now`;if(t<60)return`${String(t)}s ago`;let n=Math.floor(t/60);if(n<60)return`${String(n)}m ago`;let r=Math.floor(n/60);return r<48?`${String(r)}h ago`:`${String(Math.floor(r/24))}d ago`},An=e=>Date.parse(e),jn=(e,t)=>{let[n,r]=M(void 0),i=()=>{r(void 0),e().then(r)};return N(i,[t]),V([n,i])},Mn=e=>e===`success`?`ok`:e===`failure`?`bad`:`waiting`,Nn=({server:e,app:t,open:n})=>{let[r]=jn(()=>Mt(`app.runs`,{server:e,app:t}),`${e}/${t}`);if(r===void 0)return G(X,{what:`Asking the deployer`});if(!r.ok)return G(Y,{failure:r.failure});let i=Date.now(),{live:a,runs:o}=r.value;return G(S,{children:[G(`p`,{class:`sub`,children:a===void 0?`Not deployed yet.`:`Live: ${a.sha.slice(0,7)} since ${kn(i-Date.parse(a.time))}`}),G(`table`,{class:`table`,children:[G(`thead`,{children:G(`tr`,{children:[G(`th`,{}),G(`th`,{children:`Commit`}),G(`th`,{children:`Why`}),G(`th`,{children:`What`}),G(`th`,{class:`right`,children:`When`}),G(`th`,{class:`right`,children:`Took`})]})}),G(`tbody`,{children:o.map(e=>G(`tr`,{class:`clickable`,onClick:()=>{n(e.id)},children:[G(`td`,{class:`narrow`,children:G(K,{tone:Mn(e.state),label:e.state})}),G(`td`,{children:G(`code`,{children:e.sha?.slice(0,7)??``})}),G(`td`,{children:e.why}),G(`td`,{children:e.what}),G(`td`,{class:`right tone-muted`,children:kn(i-Date.parse(e.started))}),G(`td`,{class:`right tone-muted`,children:e.finished===void 0?``:On(Date.parse(e.finished)-Date.parse(e.started))})]},e.id))})]})]})},Pn=({server:e,app:t})=>{let[n]=jn(()=>Mt(`app.releases`,{server:e,app:t}),`${e}/${t}`);if(n===void 0)return G(X,{what:`Asking the deployer`});if(!n.ok)return G(Y,{failure:n.failure});let r=Date.now();return G(`ul`,{class:`releases`,children:n.value.releases.map(n=>G(`li`,{children:[G(`code`,{children:n.sha.slice(0,12)}),G(`span`,{class:`tone-muted`,children:kn(r-Date.parse(n.time))}),n.live?G(q,{tone:`ok`,children:`live`}):G(`button`,{class:`button small`,onClick:()=>{rn({name:`app.rollback`,server:e,app:t,sha:n.sha})},children:`Roll back to it`})]},n.sha))})},Fn=e=>{if(/\b(error|failed|fatal|refused)\b/i.test(e))return V(`tone-bad`);if(/\bwarn(ing)?\b/i.test(e))return V(`tone-warn`)},In=({server:e,app:t,run:n})=>{let[r]=jn(()=>Mt(`app.log`,{server:e,app:t,...n===void 0?{}:{run:n}}),`${e}/${t}/${n??``}`);return r===void 0?G(X,{what:`Fetching the log`}):r.ok?G(`pre`,{class:`log`,children:r.value.split(`
|
|
5
|
+
`).map((e,t)=>G(`div`,{class:Fn(e),children:e===``?` `:e},t))}):G(Y,{failure:r.failure})},Ln=({server:e,app:t})=>{let[n,r]=M(`runs`),[i,a]=M(void 0),[o,s]=M(``);return G(S,{children:[G(Z,{title:t,sub:`on ${e}`,children:G(`form`,{class:`inline`,onSubmit:n=>{n.preventDefault(),rn({name:`app.deploy`,server:e,app:t,...o.trim()===``?{}:{ref:o.trim()}})},children:[G(`input`,{value:o,onInput:e=>{s(e.currentTarget.value)},placeholder:`its ref`,spellcheck:!1,"aria-label":`Branch, tag or commit`}),G(`button`,{type:`submit`,class:`button primary`,children:`Deploy`})]})}),G(`nav`,{class:`tabs`,role:`tablist`,children:[`runs`,`releases`,`log`].map(e=>G(`button`,{role:`tab`,"aria-selected":n===e,class:n===e?`tab current`:`tab`,onClick:()=>{r(e)},children:[e,e===`log`&&i!==void 0?` · ${i}`:``]},e))}),G(`section`,{class:`card`,children:n===`runs`?G(Nn,{server:e,app:t,open:e=>{a(e),r(`log`)}}):n===`releases`?G(Pn,{server:e,app:t}):G(In,{server:e,app:t,run:i})}),G(`p`,{class:`tone-muted small`,children:[`Purging an app's data is irreversible:`,` `,G(`button`,{class:`link danger-link`,onClick:()=>{rn({name:`app.purge`,server:e,app:t})},children:[`purge `,t,`'s volumes`]})]})]})},Rn=({server:e})=>{let t=Wt.value;return t.state===`loading`?G(X,{what:`Reading operations`}):t.state===`failed`?G(Y,{failure:t.failure}):G(`div`,{class:`action-grid`,children:(e===void 0?t.value.filter(e=>e.scope===`fleet`||e.scope===`repo`):Ct(t.value,e)).map(t=>G(`button`,{class:`action${t.effect===`destroys`?` danger`:``}`,onClick:()=>{nn(t.name,e===void 0?{}:{server:e.name})},children:[G(`strong`,{children:[G(`span`,{"aria-hidden":`true`,children:ht[t.name].icon}),` `,ht[t.name].label]}),G(`span`,{children:t.summary})]},t.name))})},zn=({facts:e,seen:t})=>G(Cn,{to:{page:`server`,server:e.name},class:`card server-card`,children:[G(`div`,{class:`card-head`,children:[G(K,{tone:Sn(t)}),G(`h2`,{children:e.name}),G(q,{children:e.kind}),G(q,{tone:e.target===`multipass`?`muted`:e.target===`hetzner`?`accent`:`active`,children:e.target})]}),G(`div`,{class:`domain`,children:e.domain}),t===void 0?G(X,{what:`asking`}):G(`dl`,{class:`facts`,children:[G(J,{label:`Address`,cell:yn(t)}),G(J,{label:`SSH`,cell:bn(t)}),G(J,{label:`Login`,cell:xn(t)})]}),e.apps.length===0?null:G(`div`,{class:`chips`,children:e.apps.map(e=>G(q,{children:e},e))})]}),Bn=()=>{let e=U.value;if(e.state===`loading`)return G(X,{what:`Reading the fleet`});if(e.state===`failed`)return G(Y,{failure:e.failure});let{value:t,live:n}=W.value,{servers:r}=e.value,i=r.filter(e=>Sn(t?.servers.find(t=>t.name===e.name))===`ok`).length;return G(S,{children:[G(Z,{title:`Fleet`,sub:G(S,{children:[r.length,` servers · `,t===void 0?`asking each`:`${String(i)} answering everything they were asked`]}),children:G(`button`,{class:`button`,onClick:()=>{Jt()},disabled:n,children:n?`Asking…`:`Ask again`})}),G(`div`,{class:`cards`,children:r.map(e=>G(zn,{facts:e,seen:t?.servers.find(t=>t.name===e.name)},e.name))}),G(`section`,{class:`card`,children:[G(`h2`,{children:`Fleet and local commands`}),G(Rn,{})]})]})},Vn=({id:e,question:t})=>{let[n,r]=M(``),[i,a]=M(!1),[o,s]=M(void 0),c=ke(null);N(()=>{c.current?.focus()},[]);let l=async t=>{a(!0),r(``);let n=await Nt(e,t);n.ok||(s(n.failure),a(!1))};return G(`form`,{class:`ask`,onSubmit:e=>{e.preventDefault(),i||l(n)},children:[G(`label`,{for:`run-answer`,children:G(Qt,{text:t.prompt})}),G(`input`,{id:`run-answer`,ref:c,type:t.secret?`password`:`text`,autoComplete:`off`,value:n,disabled:i,onInput:e=>{r(e.currentTarget.value)},spellcheck:!1}),G(`button`,{type:`submit`,class:`button primary`,disabled:i,children:i?`Sending…`:`Answer`}),G(`button`,{type:`button`,class:`button`,disabled:i,onClick:()=>{l(``)},children:`Decline`}),o===void 0?null:G(Y,{failure:o})]})},Hn={invocation:void 0,steps:[],current:void 0,asking:void 0,ended:void 0},Un=(e,t,n)=>t===void 0?e:V({...e,steps:e.steps.map((e,r)=>r===t?n(e):e)}),Wn=(e,t)=>Un(e,e.current,e=>({...e,said:[...e.said,t]})),Gn=(e,t,n)=>{switch(t.kind){case`plan`:return V({...e,invocation:t.invocation,steps:t.steps.map(e=>({listed:e,state:`waiting`,said:[]}))});case`started`:return Un({...e,current:t.index},t.index,e=>({...e,state:`running`,started:n}));case`done`:return Un(e,t.index,e=>({...e,state:t.failed?`failed`:t.stopped?`stopped`:`passed`,ms:t.ms,...t.why===void 0?{}:{why:t.why}}));case`ended`:{let n={failures:t.failures,ms:t.ms,footer:t.footer,...t.stop===void 0?{}:{stop:t.stop}};return V({...e,asking:void 0,ended:n,steps:e.steps.map((e,n)=>e.state===`running`||t.stop?.why===`interrupted`&&t.stop.index===n?{...e,state:`stopped`}:e.state===`waiting`?{...e,state:`skipped`}:e)})}case`output`:return Wn(e,{kind:`output`,stream:t.stream,chunk:t.chunk});case`said`:return Wn(e,{kind:`said`,stream:t.stream,text:t.text});case`ask`:return V({...e,asking:t});case`answered`:return V({...e,asking:void 0})}},Kn=e=>{let{ended:t}=e;return t===void 0?V(`running`):t.stop?.why===`interrupted`?V(`interrupted`):t.stop?.why===`declined`?V(`declined`):t.failures===0?V(`passed`):V(`failed`)},qn={fg:void 0,bold:!1,dim:!1},Jn=[`black`,`red`,`green`,`yellow`,`blue`,`magenta`,`cyan`,`white`],Yn=(e,t)=>{let n=t===``?[0]:t.split(`;`).map(Number),r=(e,t)=>{let[n,...i]=t;return n===void 0?e:n===38||n===48?r(e,i[0]===5?i.slice(2):i[0]===2?i.slice(4):i):r(n===0?qn:n===1?{...e,bold:!0}:n===2?{...e,dim:!0}:n===22?{...e,bold:!1,dim:!1}:n===39?{...e,fg:void 0}:n>=30&&n<=37?{...e,fg:Jn[n-30]}:n>=90&&n<=97?{...e,fg:`bright-${Jn[n-90]??`white`}`}:e,i)};return r(e,n)},Xn=e=>[e.fg===void 0?``:`sgr-${e.fg}`,e.bold?`sgr-bold`:``,e.dim?`sgr-dim`:``].filter(e=>e!==``).join(` `),Zn=/\u001b\[([0-9;]*)m|\u001b\[[0-9;?]*[A-Za-z]|\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)/g,Qn=e=>{let t=[...e.matchAll(Zn)].reduce((t,n)=>{let r=e.slice(t.at,n.index),i=r===``?t.out:[...t.out,{text:r,classes:Xn(t.look)}],a=n[1];return{out:i,look:a===void 0?t.look:Yn(t.look,a),at:n.index+n[0].length}},{out:[],look:qn,at:0}),n=e.slice(t.at);return n===``?t.out:V([...t.out,{text:n,classes:Xn(t.look)}])},$n={running:`active`,passed:`ok`,failed:`bad`,interrupted:`warn`,declined:`warn`},er={waiting:`○`,running:``,passed:`✓`,failed:`✗`,stopped:`■`,skipped:`–`},tr=({step:e})=>G(`div`,{class:`output`,children:e.said.map((e,t)=>e.kind===`output`?G(`span`,{class:e.stream===`stderr`?`stderr`:void 0,children:Qn(e.chunk).map((e,t)=>G(`span`,{class:e.classes===``?void 0:e.classes,children:e.text},t))},t):G(`div`,{class:e.stream===`err`?`said said-err`:`said`,children:G(Qt,{text:e.text})},t))}),nr=({step:e,now:t})=>{let n=e.state===`running`||e.state===`failed`,r=e.ms??(e.started===void 0?void 0:t-e.started),i=e.said.length===0?null:G(tr,{step:e});return G(`details`,{class:`step step-${e.state}`,open:n,children:[G(`summary`,{children:[G(`span`,{class:`step-icon`,children:e.state===`running`?G(`span`,{class:`spinner`}):er[e.state]}),G(`span`,{class:`step-title`,children:e.listed.title}),G(`span`,{class:`step-kind`,children:e.listed.kind}),G(`span`,{class:`step-time`,children:[e.why===void 0?``:`${e.why} · `,r===void 0?``:On(r)]})]}),i]})},rr=({id:e})=>{let[t,n]=Oe((e,t)=>Gn(e,t,Date.now()),Hn),[r,i]=M(Date.now()),[a,o]=M(void 0);N(()=>Rt(`/api/runs/${encodeURIComponent(e)}/events`,n,()=>void 0,void 0,o),[e]);let s=Kn(t)===`running`;N(()=>{if(!s)return;let e=setInterval(()=>{i(Date.now())},250);return()=>{clearInterval(e)}},[s]);let{invocation:c,steps:l,ended:u,asking:d}=t;if(c===void 0)return a===void 0?G(X,{what:`Starting`}):G(Y,{failure:a});let f=Kn(t);return G(S,{children:[G(Z,{title:G(`code`,{class:`command`,children:c.command}),sub:`${c.about.join(` · `)} · ${String(l.length)} steps`,children:[G(q,{tone:$n[f],children:f}),s?G(`button`,{class:`button danger`,onClick:()=>{Pt(e).then(e=>{e.ok||o(e.failure)})},children:`Stop`}):null]}),a===void 0?null:G(Y,{failure:a}),d===void 0?null:G(Vn,{id:e,question:d},JSON.stringify(d)),G(`div`,{class:`timeline`,children:l.map(e=>G(`div`,{children:[e.listed.opens===void 0?null:G(`h3`,{class:`part`,children:e.listed.opens}),G(nr,{step:e,now:r})]},e.listed.index))}),u===void 0?null:G(`footer`,{class:`run-footer tone-border-${$n[f]}`,children:G($t,{lines:u.footer})})]})},ir={running:`waiting`,passed:`ok`,failed:`bad`,interrupted:`warn`,declined:`warn`},ar=({server:e})=>{let[t,n]=M(void 0);if(N(()=>{let e=()=>{Lt().then(n)};e();let t=setInterval(e,3e3);return()=>{clearInterval(t)}},[]),t===void 0)return G(X,{what:`Reading the runs`});if(!t.ok)return G(Y,{failure:t.failure});let r=t.value.filter(t=>e===void 0||t.server===e);if(r.length===0)return G(`p`,{class:`empty`,children:`Nothing run from here yet.`});let i=Date.now();return G(`table`,{class:`table`,children:G(`tbody`,{children:r.map(e=>G(`tr`,{children:[G(`td`,{class:`narrow`,children:G(K,{tone:ir[e.state],label:e.state})}),G(`td`,{children:G(Cn,{to:{page:e.session?`session`:`run`,id:e.id},children:G(`code`,{children:e.command})})}),G(`td`,{class:`tone-${ir[e.state]===`waiting`?`active`:ir[e.state]}`,children:e.state}),G(`td`,{class:`tone-muted right`,children:kn(i-An(e.started))})]},e.id))})})},or=()=>G(S,{children:[G(Z,{title:`Runs`,sub:`Every command run from here, recorded in the fleet's .cache/ui/runs`}),G(`section`,{class:`card`,children:G(ar,{})})]}),sr=({name:e})=>{let t=U.value;if(t.state!==`ready`)return G(X,{what:`Reading the fleet`});let n=t.value.servers.find(t=>t.name===e);if(n===void 0)return G(`p`,{class:`empty`,children:[`No server `,e,` in this fleet.`]});let r=W.value.value?.servers.find(t=>t.name===e);return G(S,{children:[G(Z,{title:G(S,{children:[G(K,{tone:Sn(r)}),` `,n.name]}),sub:G(S,{children:[G(q,{children:n.kind}),` `,G(q,{children:n.target}),` `,G(`a`,{href:`https://${n.domain}`,target:`_blank`,rel:`noreferrer`,children:n.domain})]})}),G(`div`,{class:`columns`,children:[G(`section`,{class:`card`,children:[G(`h2`,{children:`Now`}),r===void 0?G(X,{what:`asking`}):G(`dl`,{class:`facts`,children:[G(J,{label:`Address`,cell:yn(r)}),G(J,{label:`SSH`,cell:bn(r)}),G(J,{label:`Login`,cell:xn(r)})]})]}),G(`section`,{class:`card`,children:[G(`h2`,{children:`Apps`}),n.apps.length===0?G(`p`,{class:`empty`,children:n.kind===`platform`?`None in server.yml.`:`A ${n.kind} server runs no apps.`}):G(`ul`,{class:`links`,children:n.apps.map(e=>G(`li`,{children:G(Cn,{to:{page:`app`,server:n.name,app:e},children:e})},e))})]})]}),G(`section`,{class:`card`,children:[G(`h2`,{children:`Commands`}),G(Rn,{server:n})]}),G(`section`,{class:`card`,children:[G(`h2`,{children:`Runs from here`}),G(ar,{server:n.name})]})]})},cr=e=>e===`problem`?`bad`:e===`unchecked`?`warn`:`ok`,lr=e=>e===`problem`?`✗`:e===`unchecked`?`·`:`✓`,ur={problem:`problems`,unchecked:`partly checked`,passed:`holds`},dr=()=>{N(()=>{Yt()},[]);let e=Kt.value;if(e.state===`loading`)return G(X,{what:`Checking the fleet beyond its schemas`});if(e.state===`failed`)return G(Y,{failure:e.failure});let{result:t,servers:n}=e.value,r=e=>n.flatMap(e=>e.findings).filter(t=>t.result===e).length;return G(S,{children:[G(Z,{title:`Validate`,sub:`Secrets, apps against their contract, stacks, routes · ${String(r(`problem`))} problems · ${String(r(`unchecked`))} not checked`,children:[G(q,{tone:cr(t),children:ur[t]}),G(`button`,{class:`button`,onClick:()=>void Yt(),children:`Check again`})]}),n.map(e=>G(`section`,{class:`card`,children:[G(`div`,{class:`card-head`,children:[G(K,{tone:cr(e.result)}),G(`h2`,{children:e.name}),G(q,{children:e.kind}),G(q,{children:e.target}),G(`span`,{class:`grow`}),G(q,{tone:cr(e.result),children:ur[e.result]})]}),G(`ul`,{class:`findings`,children:e.findings.map((e,t)=>G(`li`,{class:`finding finding-${e.result}`,children:[G(`span`,{class:`glyph tone-${cr(e.result)}`,children:lr(e.result)}),G(`span`,{children:[e.text,e.hint===null?null:G(`span`,{class:`hint`,children:[`→ `,e.hint]})]})]},t))})]},e.name))]})},fr=e=>typeof e==`string`?e:e.map(e=>typeof e==`string`?e:e.text).join(``),pr=e=>e.kind===`output`?e.chunk:e.kind===`said`?`${fr(e.text)}\r\n`:``,mr=(e,t)=>{let n={current:Promise.resolve(!0)};return r=>{n.current=n.current.then(async n=>{if(!n)return!1;let i=await e(r);return i.ok||t(i.failure),i.ok})}},hr=`modulepreload`,gr=function(e){return`/`+e},_r={},vr=function(e){return e.pathname.endsWith(`.css`)},yr=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=gr(t,n);let r=s(t);if(r.href in _r)return;_r[r.href]=!0;let i=vr(r);if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let o=document.createElement(`link`);if(o.rel=i?`stylesheet`:hr,i||(o.as=`script`),o.crossOrigin=``,o.href=r.href,a&&o.setAttribute(`nonce`,a),document.head.appendChild(o),i)return new Promise((e,t)=>{o.addEventListener(`load`,e),o.addEventListener(`error`,()=>t(Error(`Unable to preload CSS for ${r}`)))})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},br=({id:e})=>{let t=ke(null),[n,r]=M(void 0),[i,a]=M(void 0),[o,s]=M(`running`),[c,l]=M(void 0),[u,d]=M(!1);N(()=>{let n={current:!0},i={current:()=>void 0};return(async()=>{let{Terminal:o}=await yr(async()=>{let{Terminal:e}=await import(`./xterm-CerOhKYV.js`);return{Terminal:e}},[]);if(!n.current||t.current===null)return;let c=new o({cols:120,rows:32,fontSize:13,cursorBlink:!0,disableStdin:!0,theme:{background:`#0a0a0c`,foreground:`#e4e4e8`}});c.open(t.current),c.focus();let u={current:[]},d={current:!1},f={current:!1},p={current:!1},m=e=>{f.current=!e,c.options.disableStdin=e},h=e=>{p.current=!0,m(!0),l(e)},g=mr(t=>Ft(e,t),h),_=c.onData(e=>{f.current&&g(e)}),v=Rt(`/api/sessions/${encodeURIComponent(e)}/output`,e=>{e.kind===`plan`&&(r(e.invocation),u.current=e.steps),e.kind===`started`&&u.current.find(t=>t.index===e.index)?.kind===`session`&&m(!1),e.kind===`ask`&&(m(!0),a(e)),e.kind===`answered`&&a(void 0);let t=pr(e);t!==``&&c.write(t),e.kind===`ended`&&(d.current=!0,m(!0),s(e.stop?.why===`interrupted`?`interrupted`:e.stop?.why===`declined`?`declined`:e.failures>0||e.stop!==void 0?`failed`:`passed`),c.write(`\r
|
|
6
|
+
[Session ended]\r
|
|
7
|
+
`))},()=>{m(!0),n.current&&!d.current&&!p.current&&l({status:0,message:`Session output disconnected. Reload this page to reconnect.`})},void 0,h);i.current=()=>{v(),_.dispose(),c.dispose()}})().catch(()=>{n.current&&l({status:0,message:`The terminal could not start. Reload this page to reconnect.`})}),()=>{n.current=!1,i.current()}},[e]);let f=async()=>{d(!0);let t=await It(e);t.ok||(l(t.failure),d(!1))};return G(S,{children:[G(Z,{title:n?.command??`SSH terminal`,sub:`120 columns × 32 rows`,children:[G(q,{tone:o===`running`?`active`:o===`passed`?`ok`:`warn`,children:o}),o===`running`?G(`button`,{class:`button danger`,disabled:u,onClick:()=>{f()},children:u?`Closing…`:`Close session`}):null]}),c===void 0?null:G(Y,{failure:c}),i===void 0?null:G(Vn,{id:e,question:i},JSON.stringify(i)),G(`div`,{class:`terminal-scroll`,children:G(`div`,{ref:t,class:`terminal`})}),G(`p`,{class:`hint`,children:`Leaving this page keeps the session open. Use Close session to disconnect.`})]})},xr=()=>{let e=Ht.value;switch(e.page){case`fleet`:return G(Bn,{});case`server`:return G(sr,{name:e.server});case`app`:return G(Ln,{server:e.server,app:e.app});case`runs`:return G(or,{});case`run`:return G(rr,{id:e.id},e.id);case`session`:return G(br,{id:e.id},e.id);case`validate`:return G(dr,{});case`missing`:return G(`p`,{class:`empty`,children:[`Nothing at `,e.path,`.`]})}},Sr=()=>(N(()=>{qt(),Gt(),Jt()},[]),G(S,{children:[G(Dn,{children:[G(`div`,{class:`topbar`,children:[G(`button`,{class:`search`,onClick:gn,children:[G(`span`,{children:`Go to, or run…`}),G(`kbd`,{children:`⌘K`})]}),G(`button`,{class:`button`,onClick:()=>{rn({name:`doctor`})},children:`Doctor`})]}),G(xr,{})]}),G(fn,{}),G(hn,{})]})),Cr=document.getElementById(`app`);Cr!==null&&he(G(Sr,{}),Cr);
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<meta name="color-scheme" content="light dark" />
|
|
7
7
|
<title>kayra</title>
|
|
8
8
|
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' rx='8' fill='%235b5bd6'/%3E%3Cpath d='M11 8v16M11 16l9-8M14 13l7 11' stroke='white' stroke-width='3' stroke-linecap='round' fill='none'/%3E%3C/svg%3E" />
|
|
9
|
-
<script type="module" crossorigin src="/assets/index-
|
|
9
|
+
<script type="module" crossorigin src="/assets/index-hcyM6f6T.js"></script>
|
|
10
10
|
<link rel="stylesheet" crossorigin href="/assets/index-Ct0Eudk4.css">
|
|
11
11
|
</head>
|
|
12
12
|
<body>
|
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync } from "node:fs";
|
|
3
|
-
import { join, sep } from "node:path";
|
|
1
|
+
import { sep } from "node:path";
|
|
4
2
|
import { z } from "zod";
|
|
5
|
-
import { within } from "../../core/brand.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { follow } from "../../core/updates.js";
|
|
13
|
-
import { err, ok } from "../../result.js";
|
|
14
|
-
import { json, send } from "../../deployer/http.js";
|
|
3
|
+
import { within } from "../../core/fleet/brand.js";
|
|
4
|
+
import { opentofu } from "../../core/adapters/opentofu.js";
|
|
5
|
+
import { isOperation, operation } from "../../core/operations/catalog.js";
|
|
6
|
+
import { contextFor, invocation, isQuery, isStream, stream } from "../../core/operations/dispatch.js";
|
|
7
|
+
import { follow } from "../../core/status/updates.js";
|
|
8
|
+
import { json, send } from "../../deployer/http/http.js";
|
|
9
|
+
import { facts } from "./commands.js";
|
|
15
10
|
import { catalog, openapi } from "./contract.js";
|
|
16
11
|
import { directories } from "./directories.js";
|
|
17
|
-
import {
|
|
18
|
-
import { answer as queryAnswer } from "./queries.js";
|
|
12
|
+
import { inFlight, liveRuns } from "./live.js";
|
|
19
13
|
import { options, requestBody } from "./protocol.js";
|
|
20
|
-
import {
|
|
14
|
+
import { answer as queryAnswer } from "./queries.js";
|
|
15
|
+
import { stateOf, summary } from "./runs.js";
|
|
16
|
+
import { allRuns, preview, start } from "./start.js";
|
|
17
|
+
import { statusJson } from "./status.js";
|
|
21
18
|
const answerJson = (response, status, value) => {
|
|
22
19
|
send(response, status, JSON.stringify(value), "application/json; charset=utf-8");
|
|
23
20
|
};
|
|
@@ -29,115 +26,124 @@ const events = (response, ndjson = false) => {
|
|
|
29
26
|
end: () => { response.end(ndjson ? "" : "event: end\ndata: {}\n\n"); },
|
|
30
27
|
};
|
|
31
28
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const done = interpret(coloured, io, reporting(emit, about(call), api.short)).catch(() => {
|
|
116
|
-
emit({ kind: "said", stream: "err", text: "The run could not finish; check the local kayra process." });
|
|
117
|
-
emit({ kind: "ended", failures: 1, ms: Date.now() - Date.parse(started), footer: [] });
|
|
118
|
-
}).finally(() => { swap(id, (live) => ({ ...live, answer: undefined, input: undefined })); });
|
|
119
|
-
swap(id, (live) => ({ ...live, done }));
|
|
120
|
-
return ok(id);
|
|
121
|
-
};
|
|
122
|
-
const watch = (id, response, ndjson, session = false) => {
|
|
123
|
-
const live = cell.live[id];
|
|
124
|
-
const run = live?.run ?? allRuns().find((each) => each.id === id);
|
|
125
|
-
if (run === undefined || (session && !run.session)) {
|
|
126
|
-
send(response, 404, "no run or session\n");
|
|
127
|
-
return;
|
|
29
|
+
/** A run's events as they come, after those it has had: until it ends, or the client goes. */
|
|
30
|
+
const watch = (served, id, response, ndjson, session = false) => {
|
|
31
|
+
const live = served.runs.get(id);
|
|
32
|
+
const run = live?.run ?? allRuns(served).find((each) => each.id === id);
|
|
33
|
+
if (run === undefined || (session && !run.session)) {
|
|
34
|
+
send(response, 404, "no run or session\n");
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const { say, end } = events(response, ndjson);
|
|
38
|
+
run.events.forEach(say);
|
|
39
|
+
if (live === undefined || stateOf(run.events) !== "running") {
|
|
40
|
+
end();
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const listener = (event) => { say(event); if (event.kind === "ended")
|
|
44
|
+
end(); };
|
|
45
|
+
served.runs.swap(id, (current) => ({ ...current, listeners: [...current.listeners, listener] }));
|
|
46
|
+
response.on("close", () => { served.runs.swap(id, (current) => ({ ...current, listeners: current.listeners.filter((each) => each !== listener) })); });
|
|
47
|
+
};
|
|
48
|
+
/** POST /api/operations/<name>[/preview]: a plan previewed or started, a session started, a query answered, a stream followed. */
|
|
49
|
+
const operate = async (served, request, response, named, previewing, ndjson) => {
|
|
50
|
+
const name = decodeURIComponent(named);
|
|
51
|
+
if (!isOperation(name)) {
|
|
52
|
+
send(response, 404, "no such operation\n");
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const body = requestBody.safeParse(await json(request));
|
|
56
|
+
if (!body.success) {
|
|
57
|
+
send(response, 400, "expected {input, options?, confirm?}\n");
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const call = invocation(name, body.data.input);
|
|
61
|
+
const settings = options.parse(body.data.options ?? {});
|
|
62
|
+
if (!call.ok) {
|
|
63
|
+
send(response, 400, `${call.error}\n`);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const kind = operation(call.value.name).kind;
|
|
67
|
+
if (previewing || settings.dryRun) {
|
|
68
|
+
const shown = preview(served, call.value, settings);
|
|
69
|
+
if (shown.ok)
|
|
70
|
+
answerJson(response, 200, shown.value);
|
|
71
|
+
else
|
|
72
|
+
send(response, 400, `${shown.error}\n`);
|
|
73
|
+
}
|
|
74
|
+
else if (kind === "plan" || kind === "session") {
|
|
75
|
+
const started = start(served, call.value, settings, body.data.confirm);
|
|
76
|
+
if (!started.ok)
|
|
77
|
+
send(response, started.error[0], `${started.error[1]}\n`);
|
|
78
|
+
else
|
|
79
|
+
answerJson(response, kind === "session" ? 201 : 202, { [kind === "session" ? "session" : "run"]: started.value });
|
|
80
|
+
}
|
|
81
|
+
else if (isStream(call.value)) {
|
|
82
|
+
const { initial, updates } = stream(served.context, call.value.name, call.value.input);
|
|
83
|
+
const sink = events(response, ndjson);
|
|
84
|
+
await follow(initial, updates, (looks) => { const value = statusJson(looks); sink.say(value); });
|
|
85
|
+
sink.end();
|
|
86
|
+
}
|
|
87
|
+
else if (isQuery(call.value)) {
|
|
88
|
+
const result = await queryAnswer(served.context, call.value.name, call.value.input);
|
|
89
|
+
if (result.ok)
|
|
90
|
+
answerJson(response, 200, result.value);
|
|
91
|
+
else
|
|
92
|
+
send(response, call.value.name === "validate" ? 400 : 502, `${result.error}\n`);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
/** /api/runs/<id>[/events|answers|cancel] and /api/sessions/<id>[/output|input]: follow, answer, stop. */
|
|
96
|
+
const steer = async (served, request, response, id, action, session, ndjson) => {
|
|
97
|
+
const method = request.method ?? "GET";
|
|
98
|
+
const live = served.runs.get(id);
|
|
99
|
+
if (session && live?.run.session !== true && !allRuns(served).some((each) => each.id === id && each.session)) {
|
|
100
|
+
send(response, 404, "no session\n");
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (method === "GET" && (action === "events" || action === "output"))
|
|
104
|
+
watch(served, id, response, ndjson, session);
|
|
105
|
+
else if (method === "GET" && action === undefined && !session) {
|
|
106
|
+
const run = allRuns(served).find((each) => each.id === id);
|
|
107
|
+
if (run === undefined)
|
|
108
|
+
send(response, 404, "no run\n");
|
|
109
|
+
else {
|
|
110
|
+
const value = { ...summary(run), events: run.events };
|
|
111
|
+
answerJson(response, 200, value);
|
|
128
112
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
113
|
+
}
|
|
114
|
+
else if (((method === "POST" && action === "cancel") || (session && method === "DELETE" && action === undefined)) && live !== undefined && stateOf(live.run.events) === "running") {
|
|
115
|
+
live.stop.abort();
|
|
116
|
+
send(response, 204, "");
|
|
117
|
+
}
|
|
118
|
+
else if (method === "POST" && (action === "answers" || action === "input")) {
|
|
119
|
+
const deliver = action === "answers" ? live?.answer : session ? live?.input : undefined;
|
|
120
|
+
if (deliver === undefined || live?.stop.signal.aborted === true) {
|
|
121
|
+
send(response, 404, "nothing waiting for input\n");
|
|
133
122
|
return;
|
|
134
123
|
}
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
124
|
+
const body = z.strictObject({ text: z.string() }).safeParse(await json(request));
|
|
125
|
+
if (!body.success)
|
|
126
|
+
send(response, 400, "expected {text: string}\n");
|
|
127
|
+
else {
|
|
128
|
+
deliver(body.data.text);
|
|
129
|
+
send(response, 204, "");
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else
|
|
133
|
+
send(response, 404, "no active resource\n");
|
|
134
|
+
};
|
|
135
|
+
/** The API of one listener: its requests routed, and a stop that waits for runs and requests to end. */
|
|
136
|
+
export const createApi = (api) => {
|
|
137
|
+
const shutdown = new AbortController();
|
|
138
|
+
const served = {
|
|
139
|
+
api,
|
|
140
|
+
context: contextFor({ kayra: api.kayra, fleet: api.fleet, version: api.version, here: api.fleet.root, network: api.network, tofu: api.tofu ?? opentofu, signal: shutdown.signal }),
|
|
141
|
+
runs: liveRuns(),
|
|
142
|
+
dir: within(api.fleet.root, ".cache", "ui", "runs"),
|
|
143
|
+
shutdown,
|
|
139
144
|
};
|
|
140
|
-
const
|
|
145
|
+
const requests = inFlight();
|
|
146
|
+
const route = async (request, response, url) => {
|
|
141
147
|
const method = request.method ?? "GET";
|
|
142
148
|
const path = url.pathname;
|
|
143
149
|
const named = /^\/api\/operations\/([^/]+)(\/preview)?$/.exec(path);
|
|
@@ -159,111 +165,25 @@ export const createApi = (api) => {
|
|
|
159
165
|
const factsOfFleet = { fleet: api.fleet.root.split(sep).at(-1) ?? "", version: api.version, servers: api.fleet.servers.map(facts) };
|
|
160
166
|
answerJson(response, 200, factsOfFleet);
|
|
161
167
|
}
|
|
162
|
-
else if (method === "POST" && named !== null)
|
|
163
|
-
|
|
164
|
-
if (!isOperation(name)) {
|
|
165
|
-
send(response, 404, "no such operation\n");
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
const body = requestBody.safeParse(await json(request));
|
|
169
|
-
if (!body.success) {
|
|
170
|
-
send(response, 400, "expected {input, options?, confirm?}\n");
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
const call = invocation(name, body.data.input);
|
|
174
|
-
const settings = options.parse(body.data.options ?? {});
|
|
175
|
-
if (!call.ok) {
|
|
176
|
-
send(response, 400, `${call.error}\n`);
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
const kind = operation(call.value.name).kind;
|
|
180
|
-
if (named[2] !== undefined || settings.dryRun) {
|
|
181
|
-
const shown = preview(call.value, settings);
|
|
182
|
-
if (shown.ok)
|
|
183
|
-
answerJson(response, 200, shown.value);
|
|
184
|
-
else
|
|
185
|
-
send(response, 400, `${shown.error}\n`);
|
|
186
|
-
}
|
|
187
|
-
else if (kind === "plan" || kind === "session") {
|
|
188
|
-
const started = start(call.value, settings, body.data.confirm);
|
|
189
|
-
if (!started.ok)
|
|
190
|
-
send(response, started.error[0], `${started.error[1]}\n`);
|
|
191
|
-
else
|
|
192
|
-
answerJson(response, kind === "session" ? 201 : 202, { [kind === "session" ? "session" : "run"]: started.value });
|
|
193
|
-
}
|
|
194
|
-
else if (isStream(call.value)) {
|
|
195
|
-
const { initial, updates } = stream(context, call.value.name, call.value.input);
|
|
196
|
-
const sink = events(response, ndjson);
|
|
197
|
-
await follow(initial, updates, (looks) => { const value = statusJson(looks); sink.say(value); });
|
|
198
|
-
sink.end();
|
|
199
|
-
}
|
|
200
|
-
else if (isQuery(call.value)) {
|
|
201
|
-
const result = await queryAnswer(context, call.value.name, call.value.input);
|
|
202
|
-
if (result.ok)
|
|
203
|
-
answerJson(response, 200, result.value);
|
|
204
|
-
else
|
|
205
|
-
send(response, call.value.name === "validate" ? 400 : 502, `${result.error}\n`);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
168
|
+
else if (method === "POST" && named !== null)
|
|
169
|
+
await operate(served, request, response, named[1] ?? "", named[2] !== undefined, ndjson);
|
|
208
170
|
else if (method === "GET" && path === "/api/runs") {
|
|
209
|
-
const runs = allRuns().map(summary);
|
|
171
|
+
const runs = allRuns(served).map(summary);
|
|
210
172
|
answerJson(response, 200, runs);
|
|
211
173
|
}
|
|
212
174
|
else if (runPath !== null || sessionPath !== null) {
|
|
213
175
|
const [, id = "", action] = runPath ?? sessionPath ?? [];
|
|
214
|
-
|
|
215
|
-
const session = sessionPath !== null;
|
|
216
|
-
if (session && live?.run.session !== true && !allRuns().some((each) => each.id === id && each.session)) {
|
|
217
|
-
send(response, 404, "no session\n");
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
if (method === "GET" && (action === "events" || action === "output"))
|
|
221
|
-
watch(id, response, ndjson, session);
|
|
222
|
-
else if (method === "GET" && action === undefined && !session) {
|
|
223
|
-
const run = allRuns().find((each) => each.id === id);
|
|
224
|
-
if (run === undefined)
|
|
225
|
-
send(response, 404, "no run\n");
|
|
226
|
-
else {
|
|
227
|
-
const value = { ...summary(run), events: run.events };
|
|
228
|
-
answerJson(response, 200, value);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
else if (((method === "POST" && action === "cancel") || (session && method === "DELETE" && action === undefined)) && live !== undefined && stateOf(live.run.events) === "running") {
|
|
232
|
-
live.stop.abort();
|
|
233
|
-
send(response, 204, "");
|
|
234
|
-
}
|
|
235
|
-
else if (method === "POST" && (action === "answers" || action === "input")) {
|
|
236
|
-
const deliver = action === "answers" ? live?.answer : session ? live?.input : undefined;
|
|
237
|
-
if (deliver === undefined || live?.stop.signal.aborted === true) {
|
|
238
|
-
send(response, 404, "nothing waiting for input\n");
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
const body = z.strictObject({ text: z.string() }).safeParse(await json(request));
|
|
242
|
-
if (!body.success)
|
|
243
|
-
send(response, 400, "expected {text: string}\n");
|
|
244
|
-
else {
|
|
245
|
-
deliver(body.data.text);
|
|
246
|
-
send(response, 204, "");
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
else
|
|
250
|
-
send(response, 404, "no active resource\n");
|
|
176
|
+
await steer(served, request, response, id, action, sessionPath !== null, ndjson);
|
|
251
177
|
}
|
|
252
178
|
else
|
|
253
179
|
send(response, 404, "not found\n");
|
|
254
180
|
};
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
cell.pending = cell.pending.filter((pending) => pending !== work);
|
|
259
|
-
});
|
|
260
|
-
// eslint-disable-next-line functional/immutable-data -- shutdown waits for in-flight requests as well as runs
|
|
261
|
-
cell.pending = [...cell.pending, work];
|
|
262
|
-
return work;
|
|
263
|
-
};
|
|
264
|
-
return { handle, stop: async () => {
|
|
181
|
+
return {
|
|
182
|
+
handle: (request, response, url) => requests.track(route(request, response, url)),
|
|
183
|
+
stop: async () => {
|
|
265
184
|
shutdown.abort();
|
|
266
|
-
|
|
267
|
-
await Promise.allSettled([
|
|
268
|
-
}
|
|
185
|
+
served.runs.all().forEach((live) => { live.stop.abort(); });
|
|
186
|
+
await Promise.allSettled([requests.settled(), ...served.runs.all().map((live) => live.done)]);
|
|
187
|
+
},
|
|
188
|
+
};
|
|
269
189
|
};
|