@jupyterlite/pyodide-kernel 0.8.0-beta.0 → 0.8.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,12 @@
1
- var Qo=Object.create;var $n=Object.defineProperty;var Zo=Object.getOwnPropertyDescriptor;var ea=Object.getOwnPropertyNames;var ta=Object.getPrototypeOf,na=Object.prototype.hasOwnProperty;var or=(r,e)=>()=>(r&&(e=r(r=0)),e);var O=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),sa=(r,e)=>{for(var t in e)$n(r,t,{get:e[t],enumerable:!0})},ra=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of ea(e))!na.call(r,s)&&s!==t&&$n(r,s,{get:()=>e[s],enumerable:!(n=Zo(e,s))||n.enumerable});return r};var Wn=(r,e,t)=>(t=r!=null?Qo(ta(r)):{},ra(e||!r||!r.__esModule?$n(t,"default",{value:r,enumerable:!0}):t,r));var Gn=O((xt,_r)=>{(function(r,e){typeof xt=="object"&&typeof _r!="undefined"?e(xt):typeof define=="function"&&define.amd?define(["exports"],e):(r=typeof globalThis!="undefined"?globalThis:r||self,e(r.lumino_algorithm={}))})(xt,function(r){"use strict";r.ArrayExt=void 0,function(f){function y(S,M,g=0,_=-1){let p=S.length;if(p===0)return-1;g<0?g=Math.max(0,g+p):g=Math.min(g,p-1),_<0?_=Math.max(0,_+p):_=Math.min(_,p-1);let I;_<g?I=_+1+(p-g):I=_-g+1;for(let D=0;D<I;++D){let z=(g+D)%p;if(S[z]===M)return z}return-1}f.firstIndexOf=y;function b(S,M,g=-1,_=0){let p=S.length;if(p===0)return-1;g<0?g=Math.max(0,g+p):g=Math.min(g,p-1),_<0?_=Math.max(0,_+p):_=Math.min(_,p-1);let I;g<_?I=g+1+(p-_):I=g-_+1;for(let D=0;D<I;++D){let z=(g-D+p)%p;if(S[z]===M)return z}return-1}f.lastIndexOf=b;function P(S,M,g=0,_=-1){let p=S.length;if(p===0)return-1;g<0?g=Math.max(0,g+p):g=Math.min(g,p-1),_<0?_=Math.max(0,_+p):_=Math.min(_,p-1);let I;_<g?I=_+1+(p-g):I=_-g+1;for(let D=0;D<I;++D){let z=(g+D)%p;if(M(S[z],z))return z}return-1}f.findFirstIndex=P;function x(S,M,g=-1,_=0){let p=S.length;if(p===0)return-1;g<0?g=Math.max(0,g+p):g=Math.min(g,p-1),_<0?_=Math.max(0,_+p):_=Math.min(_,p-1);let I;g<_?I=g+1+(p-_):I=g-_+1;for(let D=0;D<I;++D){let z=(g-D+p)%p;if(M(S[z],z))return z}return-1}f.findLastIndex=x;function J(S,M,g=0,_=-1){let p=P(S,M,g,_);return p!==-1?S[p]:void 0}f.findFirstValue=J;function F(S,M,g=-1,_=0){let p=x(S,M,g,_);return p!==-1?S[p]:void 0}f.findLastValue=F;function K(S,M,g,_=0,p=-1){let I=S.length;if(I===0)return 0;_<0?_=Math.max(0,_+I):_=Math.min(_,I-1),p<0?p=Math.max(0,p+I):p=Math.min(p,I-1);let D=_,z=p-_+1;for(;z>0;){let Se=z>>1,at=D+Se;g(S[at],M)<0?(D=at+1,z-=Se+1):z=Se}return D}f.lowerBound=K;function Y(S,M,g,_=0,p=-1){let I=S.length;if(I===0)return 0;_<0?_=Math.max(0,_+I):_=Math.min(_,I-1),p<0?p=Math.max(0,p+I):p=Math.min(p,I-1);let D=_,z=p-_+1;for(;z>0;){let Se=z>>1,at=D+Se;g(S[at],M)>0?z=Se:(D=at+1,z-=Se+1)}return D}f.upperBound=Y;function B(S,M,g){if(S===M)return!0;if(S.length!==M.length)return!1;for(let _=0,p=S.length;_<p;++_)if(g?!g(S[_],M[_]):S[_]!==M[_])return!1;return!0}f.shallowEqual=B;function Z(S,M={}){let{start:g,stop:_,step:p}=M;if(p===void 0&&(p=1),p===0)throw new Error("Slice `step` cannot be zero.");let I=S.length;g===void 0?g=p<0?I-1:0:g<0?g=Math.max(g+I,p<0?-1:0):g>=I&&(g=p<0?I-1:I),_===void 0?_=p<0?-1:I:_<0?_=Math.max(_+I,p<0?-1:0):_>=I&&(_=p<0?I-1:I);let D;p<0&&_>=g||p>0&&g>=_?D=0:p<0?D=Math.floor((_-g+1)/p+1):D=Math.floor((_-g-1)/p+1);let z=[];for(let Se=0;Se<D;++Se)z[Se]=S[g+Se*p];return z}f.slice=Z;function G(S,M,g){let _=S.length;if(_<=1||(M<0?M=Math.max(0,M+_):M=Math.min(M,_-1),g<0?g=Math.max(0,g+_):g=Math.min(g,_-1),M===g))return;let p=S[M],I=M<g?1:-1;for(let D=M;D!==g;D+=I)S[D]=S[D+I];S[g]=p}f.move=G;function ue(S,M=0,g=-1){let _=S.length;if(!(_<=1))for(M<0?M=Math.max(0,M+_):M=Math.min(M,_-1),g<0?g=Math.max(0,g+_):g=Math.min(g,_-1);M<g;){let p=S[M],I=S[g];S[M++]=I,S[g--]=p}}f.reverse=ue;function Pe(S,M,g=0,_=-1){let p=S.length;if(p<=1||(g<0?g=Math.max(0,g+p):g=Math.min(g,p-1),_<0?_=Math.max(0,_+p):_=Math.min(_,p-1),g>=_))return;let I=_-g+1;if(M>0?M=M%I:M<0&&(M=(M%I+I)%I),M===0)return;let D=g+M;ue(S,g,D-1),ue(S,D,_),ue(S,g,_)}f.rotate=Pe;function Ie(S,M,g=0,_=-1){let p=S.length;if(p===0)return;g<0?g=Math.max(0,g+p):g=Math.min(g,p-1),_<0?_=Math.max(0,_+p):_=Math.min(_,p-1);let I;_<g?I=_+1+(p-g):I=_-g+1;for(let D=0;D<I;++D)S[(g+D)%p]=M}f.fill=Ie;function $o(S,M,g){let _=S.length;M<0?M=Math.max(0,M+_):M=Math.min(M,_);for(let p=_;p>M;--p)S[p]=S[p-1];S[M]=g}f.insert=$o;function ot(S,M){let g=S.length;if(M<0&&(M+=g),M<0||M>=g)return;let _=S[M];for(let p=M+1;p<g;++p)S[p-1]=S[p];return S.length=g-1,_}f.removeAt=ot;function Wo(S,M,g=0,_=-1){let p=y(S,M,g,_);return p!==-1&&ot(S,p),p}f.removeFirstOf=Wo;function Ho(S,M,g=-1,_=0){let p=b(S,M,g,_);return p!==-1&&ot(S,p),p}f.removeLastOf=Ho;function Jo(S,M,g=0,_=-1){let p=S.length;if(p===0)return 0;g<0?g=Math.max(0,g+p):g=Math.min(g,p-1),_<0?_=Math.max(0,_+p):_=Math.min(_,p-1);let I=0;for(let D=0;D<p;++D)g<=_&&D>=g&&D<=_&&S[D]===M||_<g&&(D<=_||D>=g)&&S[D]===M?I++:I>0&&(S[D-I]=S[D]);return I>0&&(S.length=p-I),I}f.removeAllOf=Jo;function Go(S,M,g=0,_=-1){let p,I=P(S,M,g,_);return I!==-1&&(p=ot(S,I)),{index:I,value:p}}f.removeFirstWhere=Go;function Xo(S,M,g=-1,_=0){let p,I=x(S,M,g,_);return I!==-1&&(p=ot(S,I)),{index:I,value:p}}f.removeLastWhere=Xo;function Yo(S,M,g=0,_=-1){let p=S.length;if(p===0)return 0;g<0?g=Math.max(0,g+p):g=Math.min(g,p-1),_<0?_=Math.max(0,_+p):_=Math.min(_,p-1);let I=0;for(let D=0;D<p;++D)g<=_&&D>=g&&D<=_&&M(S[D],D)||_<g&&(D<=_||D>=g)&&M(S[D],D)?I++:I>0&&(S[D-I]=S[D]);return I>0&&(S.length=p-I),I}f.removeAllWhere=Yo}(r.ArrayExt||(r.ArrayExt={}));function*e(...f){for(let y of f)yield*y}function*t(){}function*n(f,y=0){for(let b of f)yield[y++,b]}function*s(f,y){let b=0;for(let P of f)y(P,b++)&&(yield P)}function i(f,y){let b=0;for(let P of f)if(y(P,b++))return P}function o(f,y){let b=0;for(let P of f)if(y(P,b++))return b-1;return-1}function a(f,y){let b;for(let P of f){if(b===void 0){b=P;continue}y(P,b)<0&&(b=P)}return b}function h(f,y){let b;for(let P of f){if(b===void 0){b=P;continue}y(P,b)>0&&(b=P)}return b}function c(f,y){let b=!0,P,x;for(let J of f)b?(P=J,x=J,b=!1):y(J,P)<0?P=J:y(J,x)>0&&(x=J);return b?void 0:[P,x]}function u(f){return Array.from(f)}function l(f){let y={};for(let[b,P]of f)y[b]=P;return y}function d(f,y){let b=0;for(let P of f)if(y(P,b++)===!1)return}function m(f,y){let b=0;for(let P of f)if(y(P,b++)===!1)return!1;return!0}function v(f,y){let b=0;for(let P of f)if(y(P,b++))return!0;return!1}function*T(f,y){let b=0;for(let P of f)yield y(P,b++)}function*E(f,y,b){y===void 0?(y=f,f=0,b=1):b===void 0&&(b=1);let P=q.rangeLength(f,y,b);for(let x=0;x<P;x++)yield f+b*x}var q;(function(f){function y(b,P,x){return x===0?1/0:b>P&&x>0||b<P&&x<0?0:Math.ceil((P-b)/x)}f.rangeLength=y})(q||(q={}));function A(f,y,b){let P=f[Symbol.iterator](),x=0,J=P.next();if(J.done&&b===void 0)throw new TypeError("Reduce of empty iterable with no initial value.");if(J.done)return b;let F=P.next();if(F.done&&b===void 0)return J.value;if(F.done)return y(b,J.value,x++);let K;b===void 0?K=y(J.value,F.value,x++):K=y(y(b,J.value,x++),F.value,x++);let Y;for(;!(Y=P.next()).done;)K=y(K,Y.value,x++);return K}function*C(f,y){for(;0<y--;)yield f}function*w(f){yield f}function*k(f){if(typeof f.retro=="function")yield*f.retro();else for(let y=f.length-1;y>-1;y--)yield f[y]}function N(f){let y=[],b=new Set,P=new Map;for(let F of f)x(F);for(let[F]of P)J(F);return y;function x(F){let[K,Y]=F,B=P.get(Y);B?B.push(K):P.set(Y,[K])}function J(F){if(b.has(F))return;b.add(F);let K=P.get(F);if(K)for(let Y of K)J(Y);y.push(F)}}function*j(f,y){let b=0;for(let P of f)b++%y===0&&(yield P)}r.StringExt=void 0,function(f){function y(F,K,Y=0){let B=new Array(K.length);for(let Z=0,G=Y,ue=K.length;Z<ue;++Z,++G){if(G=F.indexOf(K[Z],G),G===-1)return null;B[Z]=G}return B}f.findIndices=y;function b(F,K,Y=0){let B=y(F,K,Y);if(!B)return null;let Z=0;for(let G=0,ue=B.length;G<ue;++G){let Pe=B[G]-Y;Z+=Pe*Pe}return{score:Z,indices:B}}f.matchSumOfSquares=b;function P(F,K,Y=0){let B=y(F,K,Y);if(!B)return null;let Z=0,G=Y-1;for(let ue=0,Pe=B.length;ue<Pe;++ue){let Ie=B[ue];Z+=Ie-G-1,G=Ie}return{score:Z,indices:B}}f.matchSumOfDeltas=P;function x(F,K,Y){let B=[],Z=0,G=0,ue=K.length;for(;Z<ue;){let Pe=K[Z],Ie=K[Z];for(;++Z<ue&&K[Z]===Ie+1;)Ie++;G<Pe&&B.push(F.slice(G,Pe)),Pe<Ie+1&&B.push(Y(F.slice(Pe,Ie+1))),G=Ie+1}return G<F.length&&B.push(F.slice(G)),B}f.highlight=x;function J(F,K){return F<K?-1:F>K?1:0}f.cmp=J}(r.StringExt||(r.StringExt={}));function*R(f,y){if(y<1)return;let b=f[Symbol.iterator](),P;for(;0<y--&&!(P=b.next()).done;)yield P.value}function*U(...f){let y=f.map(P=>P[Symbol.iterator]()),b=y.map(P=>P.next());for(;m(b,P=>!P.done);b=y.map(P=>P.next()))yield b.map(P=>P.value)}r.chain=e,r.each=d,r.empty=t,r.enumerate=n,r.every=m,r.filter=s,r.find=i,r.findIndex=o,r.map=T,r.max=h,r.min=a,r.minmax=c,r.once=w,r.range=E,r.reduce=A,r.repeat=C,r.retro=k,r.some=v,r.stride=j,r.take=R,r.toArray=u,r.toObject=l,r.topologicSort=N,r.zip=U})});var X=O((Ft,gr)=>{(function(r,e){typeof Ft=="object"&&typeof gr!="undefined"?e(Ft,Gn()):typeof define=="function"&&define.amd?define(["exports","@lumino/algorithm"],e):(r=typeof globalThis!="undefined"?globalThis:r||self,e(r.lumino_coreutils={},r.lumino_algorithm))})(Ft,function(r,e){"use strict";r.JSONExt=void 0,function(c){c.emptyObject=Object.freeze({}),c.emptyArray=Object.freeze([]);function u(C){return C===null||typeof C=="boolean"||typeof C=="number"||typeof C=="string"}c.isPrimitive=u;function l(C){return Array.isArray(C)}c.isArray=l;function d(C){return!u(C)&&!l(C)}c.isObject=d;function m(C,w){if(C===w)return!0;if(u(C)||u(w))return!1;let k=l(C),N=l(w);return k!==N?!1:k&&N?T(C,w):E(C,w)}c.deepEqual=m;function v(C){return u(C)?C:l(C)?q(C):A(C)}c.deepCopy=v;function T(C,w){if(C===w)return!0;if(C.length!==w.length)return!1;for(let k=0,N=C.length;k<N;++k)if(!m(C[k],w[k]))return!1;return!0}function E(C,w){if(C===w)return!0;for(let k in C)if(C[k]!==void 0&&!(k in w))return!1;for(let k in w)if(w[k]!==void 0&&!(k in C))return!1;for(let k in C){let N=C[k],j=w[k];if(!(N===void 0&&j===void 0)&&(N===void 0||j===void 0||!m(N,j)))return!1}return!0}function q(C){let w=new Array(C.length);for(let k=0,N=C.length;k<N;++k)w[k]=v(C[k]);return w}function A(C){let w={};for(let k in C){let N=C[k];N!==void 0&&(w[k]=v(N))}return w}}(r.JSONExt||(r.JSONExt={}));class t{constructor(){this._types=[],this._values=[]}types(){return this._types.slice()}hasData(u){return this._types.indexOf(u)!==-1}getData(u){let l=this._types.indexOf(u);return l!==-1?this._values[l]:void 0}setData(u,l){this.clearData(u),this._types.push(u),this._values.push(l)}clearData(u){let l=this._types.indexOf(u);l!==-1&&(this._types.splice(l,1),this._values.splice(l,1))}clear(){this._types.length=0,this._values.length=0}}class n{constructor(u={}){this._application=null,this._validatePlugin=()=>!0,this._plugins=new Map,this._services=new Map,u.validatePlugin&&(console.info("Plugins may be rejected by the custom validation plugin method."),this._validatePlugin=u.validatePlugin)}get application(){return this._application}set application(u){if(this._application!==null)throw Error("PluginRegistry.application is already set. It cannot be overridden.");this._application=u}get deferredPlugins(){return Array.from(this._plugins).filter(([u,l])=>l.autoStart==="defer").map(([u,l])=>u)}getPluginDescription(u){var l,d;return(d=(l=this._plugins.get(u))===null||l===void 0?void 0:l.description)!==null&&d!==void 0?d:""}hasPlugin(u){return this._plugins.has(u)}isPluginActivated(u){var l,d;return(d=(l=this._plugins.get(u))===null||l===void 0?void 0:l.activated)!==null&&d!==void 0?d:!1}listPlugins(){return Array.from(this._plugins.keys())}registerPlugin(u){if(this._plugins.has(u.id))throw new TypeError(`Plugin '${u.id}' is already registered.`);if(!this._validatePlugin(u))throw new Error(`Plugin '${u.id}' is not valid.`);let l=s.createPluginData(u);s.ensureNoCycle(l,this._plugins,this._services),l.provides&&this._services.set(l.provides,l.id),this._plugins.set(l.id,l)}registerPlugins(u){for(let l of u)this.registerPlugin(l)}deregisterPlugin(u,l){let d=this._plugins.get(u);if(d){if(d.activated&&!l)throw new Error(`Plugin '${u}' is still active.`);this._plugins.delete(u)}}async activatePlugin(u){let l=this._plugins.get(u);if(!l)throw new ReferenceError(`Plugin '${u}' is not registered.`);if(l.activated)return;if(l.promise)return l.promise;let d=l.requires.map(v=>this.resolveRequiredService(v)),m=l.optional.map(v=>this.resolveOptionalService(v));return l.promise=Promise.all([...d,...m]).then(v=>l.activate.apply(void 0,[this.application,...v])).then(v=>{l.service=v,l.activated=!0,l.promise=null}).catch(v=>{throw l.promise=null,v}),l.promise}async activatePlugins(u,l={}){switch(u){case"defer":{let d=this.deferredPlugins.filter(m=>this._plugins.get(m).autoStart).map(m=>this.activatePlugin(m));await Promise.all(d);break}case"startUp":{let m=s.collectStartupPlugins(this._plugins,l).map(async v=>{try{return await this.activatePlugin(v)}catch(T){console.error(`Plugin '${v}' failed to activate.`,T)}});await Promise.all(m);break}}}async deactivatePlugin(u){let l=this._plugins.get(u);if(!l)throw new ReferenceError(`Plugin '${u}' is not registered.`);if(!l.activated)return[];if(!l.deactivate)throw new TypeError(`Plugin '${u}'#deactivate() method missing`);let d=s.findDependents(u,this._plugins,this._services),m=d.map(v=>this._plugins.get(v));for(let v of m)if(!v.deactivate)throw new TypeError(`Plugin ${v.id}#deactivate() method missing (depends on ${u})`);for(let v of m){let T=[...v.requires,...v.optional].map(E=>{let q=this._services.get(E);return q?this._plugins.get(q).service:null});await v.deactivate(this.application,...T),v.service=null,v.activated=!1}return d.pop(),d}async resolveRequiredService(u){let l=this._services.get(u);if(!l)throw new TypeError(`No provider for: ${u.name}.`);let d=this._plugins.get(l);return d.activated||await this.activatePlugin(l),d.service}async resolveOptionalService(u){let l=this._services.get(u);if(!l)return null;let d=this._plugins.get(l);if(!d.activated)try{await this.activatePlugin(l)}catch(m){return console.error(m),null}return d.service}}var s;(function(c){class u{constructor(E){var q,A,C,w;this._activated=!1,this._promise=null,this._service=null,this.id=E.id,this.description=(q=E.description)!==null&&q!==void 0?q:"",this.activate=E.activate,this.deactivate=(A=E.deactivate)!==null&&A!==void 0?A:null,this.provides=(C=E.provides)!==null&&C!==void 0?C:null,this.autoStart=(w=E.autoStart)!==null&&w!==void 0?w:!1,this.requires=E.requires?E.requires.slice():[],this.optional=E.optional?E.optional.slice():[]}get activated(){return this._activated}set activated(E){this._activated=E}get service(){return this._service}set service(E){this._service=E}get promise(){return this._promise}set promise(E){this._promise=E}}function l(T){return new u(T)}c.createPluginData=l;function d(T,E,q){let A=[...T.requires,...T.optional],C=k=>{if(k===T.provides)return!0;let N=q.get(k);if(!N)return!1;let j=E.get(N),R=[...j.requires,...j.optional];return R.length===0?!1:(w.push(N),R.some(C)?!0:(w.pop(),!1))};if(!T.provides||A.length===0)return;let w=[T.id];if(A.some(C))throw new ReferenceError(`Cycle detected: ${w.join(" -> ")}.`)}c.ensureNoCycle=d;function m(T,E,q){let A=new Array,C=R=>{let U=E.get(R),f=[...U.requires,...U.optional];A.push(...f.reduce((y,b)=>{let P=q.get(b);return P&&y.push([R,P]),y},[]))};for(let R of E.keys())C(R);let w=A.filter(R=>R[1]===T),k=0;for(;w.length>k;){let R=w.length,U=new Set(w.map(f=>f[0]));for(let f of U)A.filter(y=>y[1]===f).forEach(y=>{w.includes(y)||w.push(y)});k=R}let N=e.topologicSort(w),j=N.findIndex(R=>R===T);return j===-1?[T]:N.slice(0,j+1)}c.findDependents=m;function v(T,E){let q=new Set;for(let A of T.keys())T.get(A).autoStart===!0&&q.add(A);if(E.startPlugins)for(let A of E.startPlugins)q.add(A);if(E.ignorePlugins)for(let A of E.ignorePlugins)q.delete(A);return Array.from(q)}c.collectStartupPlugins=v})(s||(s={}));class i{constructor(){this.promise=new Promise((u,l)=>{this._resolve=u,this._reject=l})}resolve(u){let l=this._resolve;l(u)}reject(u){let l=this._reject;l(u)}}class o{constructor(u,l){this.name=u,this.description=l!=null?l:"",this._tokenStructuralPropertyT=null}}function a(c){let u=0;for(let l=0,d=c.length;l<d;++l)l%4===0&&(u=Math.random()*4294967295>>>0),c[l]=u&255,u>>>=8}r.Random=void 0,function(c){c.getRandomValues=(()=>{let u=typeof window!="undefined"&&(window.crypto||window.msCrypto)||null;return u&&typeof u.getRandomValues=="function"?function(d){return u.getRandomValues(d)}:a})()}(r.Random||(r.Random={}));function h(c){let u=new Uint8Array(16),l=new Array(256);for(let d=0;d<16;++d)l[d]="0"+d.toString(16);for(let d=16;d<256;++d)l[d]=d.toString(16);return function(){return c(u),u[6]=64|u[6]&15,u[8]=128|u[8]&63,l[u[0]]+l[u[1]]+l[u[2]]+l[u[3]]+"-"+l[u[4]]+l[u[5]]+"-"+l[u[6]]+l[u[7]]+"-"+l[u[8]]+l[u[9]]+"-"+l[u[10]]+l[u[11]]+l[u[12]]+l[u[13]]+l[u[14]]+l[u[15]]}}r.UUID=void 0,function(c){c.uuid4=h(r.Random.getRandomValues)}(r.UUID||(r.UUID={})),r.MimeData=t,r.PluginRegistry=n,r.PromiseDelegate=i,r.Token=o})});var ee=O((Kt,pr)=>{(function(r,e){typeof Kt=="object"&&typeof pr!="undefined"?e(Kt,Gn(),X()):typeof define=="function"&&define.amd?define(["exports","@lumino/algorithm","@lumino/coreutils"],e):(r=typeof globalThis!="undefined"?globalThis:r||self,e(r.lumino_signaling={},r.lumino_algorithm,r.lumino_coreutils))})(Kt,function(r,e,t){"use strict";class n{constructor(a){this.sender=a}connect(a,h){return i.connect(this,a,h)}disconnect(a,h){return i.disconnect(this,a,h)}emit(a){i.emit(this,a)}}(function(o){function a(v,T){i.disconnectBetween(v,T)}o.disconnectBetween=a;function h(v){i.disconnectSender(v)}o.disconnectSender=h;function c(v){i.disconnectReceiver(v)}o.disconnectReceiver=c;function u(v){i.disconnectAll(v)}o.disconnectAll=u;function l(v){i.disconnectAll(v)}o.clearData=l;function d(){return i.exceptionHandler}o.getExceptionHandler=d;function m(v){let T=i.exceptionHandler;return i.exceptionHandler=v,T}o.setExceptionHandler=m})(n||(n={}));class s extends n{constructor(){super(...arguments),this._pending=new t.PromiseDelegate}async*[Symbol.asyncIterator](){let a=this._pending;for(;;)try{let{args:h,next:c}=await a.promise;a=c,yield h}catch{return}}emit(a){let h=this._pending,c=this._pending=new t.PromiseDelegate;h.resolve({args:a,next:c}),super.emit(a)}stop(){this._pending.promise.catch(()=>{}),this._pending.reject("stop"),this._pending=new t.PromiseDelegate}}var i;(function(o){o.exceptionHandler=R=>{console.error(R)};function a(R,U,f){f=f||void 0;let y=v.get(R.sender);if(y||(y=[],v.set(R.sender,y)),A(y,R,U,f))return!1;let b=f||U,P=T.get(b);P||(P=[],T.set(b,P));let x={signal:R,slot:U,thisArg:f};return y.push(x),P.push(x),!0}o.connect=a;function h(R,U,f){f=f||void 0;let y=v.get(R.sender);if(!y||y.length===0)return!1;let b=A(y,R,U,f);if(!b)return!1;let P=f||U,x=T.get(P);return b.signal=null,w(y),w(x),!0}o.disconnect=h;function c(R,U){let f=v.get(R);if(!f||f.length===0)return;let y=T.get(U);if(!(!y||y.length===0)){for(let b of y)b.signal&&b.signal.sender===R&&(b.signal=null);w(f),w(y)}}o.disconnectBetween=c;function u(R){let U=v.get(R);if(!(!U||U.length===0)){for(let f of U){if(!f.signal)continue;let y=f.thisArg||f.slot;f.signal=null,w(T.get(y))}w(U)}}o.disconnectSender=u;function l(R){let U=T.get(R);if(!(!U||U.length===0)){for(let f of U){if(!f.signal)continue;let y=f.signal.sender;f.signal=null,w(v.get(y))}w(U)}}o.disconnectReceiver=l;function d(R){u(R),l(R)}o.disconnectAll=d;function m(R,U){let f=v.get(R.sender);if(!(!f||f.length===0))for(let y=0,b=f.length;y<b;++y){let P=f[y];P.signal===R&&C(P,U)}}o.emit=m;let v=new WeakMap,T=new WeakMap,E=new Set,q=typeof requestAnimationFrame=="function"?requestAnimationFrame:setImmediate;function A(R,U,f,y){return e.find(R,b=>b.signal===U&&b.slot===f&&b.thisArg===y)}function C(R,U){let{signal:f,slot:y,thisArg:b}=R;try{y.call(b,f.sender,U)}catch(P){o.exceptionHandler(P)}}function w(R){E.size===0&&q(k),E.add(R)}function k(){E.forEach(N),E.clear()}function N(R){e.ArrayExt.removeAllWhere(R,j)}function j(R){return R.signal===null}})(i||(i={})),r.Signal=n,r.Stream=s})});var vr=O(zt=>{"use strict";Object.defineProperty(zt,"__esModule",{value:!0});zt.ActivityMonitor=void 0;var mr=ee(),Xn=class{constructor(e){this._timer=-1,this._timeout=-1,this._isDisposed=!1,this._activityStopped=new mr.Signal(this),e.signal.connect(this._onSignalFired,this),this._timeout=e.timeout||1e3}get activityStopped(){return this._activityStopped}get timeout(){return this._timeout}set timeout(e){this._timeout=e}get isDisposed(){return this._isDisposed}dispose(){this._isDisposed||(this._isDisposed=!0,mr.Signal.clearData(this))}_onSignalFired(e,t){clearTimeout(this._timer),this._sender=e,this._args=t,this._timer=setTimeout(()=>{this._activityStopped.emit({sender:this._sender,args:this._args})},this._timeout)}};zt.ActivityMonitor=Xn});var wr=O(yr=>{"use strict";Object.defineProperty(yr,"__esModule",{value:!0})});var Sr=O(Vt=>{"use strict";Object.defineProperty(Vt,"__esModule",{value:!0});Vt.LruCache=void 0;var va=128,Yn=class{constructor(e={}){if(this._map=new Map,this._maxSize=(e==null?void 0:e.maxSize)||va,this._maxSize<1)throw new Error("maxSize must be at least 1")}get size(){return this._map.size}clear(){this._map.clear()}get(e){let t=this._map.get(e)||null;return t!=null&&(this._map.delete(e),this._map.set(e,t)),t}set(e,t){this._map.size>=this._maxSize&&this._map.delete(this._map.keys().next().value),this._map.set(e,t)}};Vt.LruCache=Yn});var Cr=O(Bt=>{"use strict";Object.defineProperty(Bt,"__esModule",{value:!0});Bt.MarkdownCodeBlocks=void 0;var br;(function(r){r.CODE_BLOCK_MARKER="```";let e=[".markdown",".mdown",".mkdn",".md",".mkd",".mdwn",".mdtxt",".mdtext",".text",".txt",".Rmd"];class t{constructor(o){this.startLine=o,this.code="",this.endLine=-1}}r.MarkdownCodeBlock=t;function n(i){return e.indexOf(i)>-1}r.isMarkdown=n;function s(i){if(!i||i==="")return[];let o=i.split(`
1
+ var Zo=Object.create;var $n=Object.defineProperty;var ea=Object.getOwnPropertyDescriptor;var ta=Object.getOwnPropertyNames;var na=Object.getPrototypeOf,sa=Object.prototype.hasOwnProperty;var or=(r,e)=>()=>(r&&(e=r(r=0)),e);var O=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),ra=(r,e)=>{for(var t in e)$n(r,t,{get:e[t],enumerable:!0})},ia=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of ta(e))!sa.call(r,s)&&s!==t&&$n(r,s,{get:()=>e[s],enumerable:!(n=ea(e,s))||n.enumerable});return r};var Wn=(r,e,t)=>(t=r!=null?Zo(na(r)):{},ia(e||!r||!r.__esModule?$n(t,"default",{value:r,enumerable:!0}):t,r));var Gn=O((xt,_r)=>{(function(r,e){typeof xt=="object"&&typeof _r!="undefined"?e(xt):typeof define=="function"&&define.amd?define(["exports"],e):(r=typeof globalThis!="undefined"?globalThis:r||self,e(r.lumino_algorithm={}))})(xt,function(r){"use strict";r.ArrayExt=void 0,function(f){function y(S,M,g=0,_=-1){let p=S.length;if(p===0)return-1;g<0?g=Math.max(0,g+p):g=Math.min(g,p-1),_<0?_=Math.max(0,_+p):_=Math.min(_,p-1);let I;_<g?I=_+1+(p-g):I=_-g+1;for(let D=0;D<I;++D){let z=(g+D)%p;if(S[z]===M)return z}return-1}f.firstIndexOf=y;function b(S,M,g=-1,_=0){let p=S.length;if(p===0)return-1;g<0?g=Math.max(0,g+p):g=Math.min(g,p-1),_<0?_=Math.max(0,_+p):_=Math.min(_,p-1);let I;g<_?I=g+1+(p-_):I=g-_+1;for(let D=0;D<I;++D){let z=(g-D+p)%p;if(S[z]===M)return z}return-1}f.lastIndexOf=b;function P(S,M,g=0,_=-1){let p=S.length;if(p===0)return-1;g<0?g=Math.max(0,g+p):g=Math.min(g,p-1),_<0?_=Math.max(0,_+p):_=Math.min(_,p-1);let I;_<g?I=_+1+(p-g):I=_-g+1;for(let D=0;D<I;++D){let z=(g+D)%p;if(M(S[z],z))return z}return-1}f.findFirstIndex=P;function x(S,M,g=-1,_=0){let p=S.length;if(p===0)return-1;g<0?g=Math.max(0,g+p):g=Math.min(g,p-1),_<0?_=Math.max(0,_+p):_=Math.min(_,p-1);let I;g<_?I=g+1+(p-_):I=g-_+1;for(let D=0;D<I;++D){let z=(g-D+p)%p;if(M(S[z],z))return z}return-1}f.findLastIndex=x;function J(S,M,g=0,_=-1){let p=P(S,M,g,_);return p!==-1?S[p]:void 0}f.findFirstValue=J;function F(S,M,g=-1,_=0){let p=x(S,M,g,_);return p!==-1?S[p]:void 0}f.findLastValue=F;function K(S,M,g,_=0,p=-1){let I=S.length;if(I===0)return 0;_<0?_=Math.max(0,_+I):_=Math.min(_,I-1),p<0?p=Math.max(0,p+I):p=Math.min(p,I-1);let D=_,z=p-_+1;for(;z>0;){let Se=z>>1,at=D+Se;g(S[at],M)<0?(D=at+1,z-=Se+1):z=Se}return D}f.lowerBound=K;function Y(S,M,g,_=0,p=-1){let I=S.length;if(I===0)return 0;_<0?_=Math.max(0,_+I):_=Math.min(_,I-1),p<0?p=Math.max(0,p+I):p=Math.min(p,I-1);let D=_,z=p-_+1;for(;z>0;){let Se=z>>1,at=D+Se;g(S[at],M)>0?z=Se:(D=at+1,z-=Se+1)}return D}f.upperBound=Y;function B(S,M,g){if(S===M)return!0;if(S.length!==M.length)return!1;for(let _=0,p=S.length;_<p;++_)if(g?!g(S[_],M[_]):S[_]!==M[_])return!1;return!0}f.shallowEqual=B;function Z(S,M={}){let{start:g,stop:_,step:p}=M;if(p===void 0&&(p=1),p===0)throw new Error("Slice `step` cannot be zero.");let I=S.length;g===void 0?g=p<0?I-1:0:g<0?g=Math.max(g+I,p<0?-1:0):g>=I&&(g=p<0?I-1:I),_===void 0?_=p<0?-1:I:_<0?_=Math.max(_+I,p<0?-1:0):_>=I&&(_=p<0?I-1:I);let D;p<0&&_>=g||p>0&&g>=_?D=0:p<0?D=Math.floor((_-g+1)/p+1):D=Math.floor((_-g-1)/p+1);let z=[];for(let Se=0;Se<D;++Se)z[Se]=S[g+Se*p];return z}f.slice=Z;function G(S,M,g){let _=S.length;if(_<=1||(M<0?M=Math.max(0,M+_):M=Math.min(M,_-1),g<0?g=Math.max(0,g+_):g=Math.min(g,_-1),M===g))return;let p=S[M],I=M<g?1:-1;for(let D=M;D!==g;D+=I)S[D]=S[D+I];S[g]=p}f.move=G;function ue(S,M=0,g=-1){let _=S.length;if(!(_<=1))for(M<0?M=Math.max(0,M+_):M=Math.min(M,_-1),g<0?g=Math.max(0,g+_):g=Math.min(g,_-1);M<g;){let p=S[M],I=S[g];S[M++]=I,S[g--]=p}}f.reverse=ue;function Pe(S,M,g=0,_=-1){let p=S.length;if(p<=1||(g<0?g=Math.max(0,g+p):g=Math.min(g,p-1),_<0?_=Math.max(0,_+p):_=Math.min(_,p-1),g>=_))return;let I=_-g+1;if(M>0?M=M%I:M<0&&(M=(M%I+I)%I),M===0)return;let D=g+M;ue(S,g,D-1),ue(S,D,_),ue(S,g,_)}f.rotate=Pe;function Ie(S,M,g=0,_=-1){let p=S.length;if(p===0)return;g<0?g=Math.max(0,g+p):g=Math.min(g,p-1),_<0?_=Math.max(0,_+p):_=Math.min(_,p-1);let I;_<g?I=_+1+(p-g):I=_-g+1;for(let D=0;D<I;++D)S[(g+D)%p]=M}f.fill=Ie;function Wo(S,M,g){let _=S.length;M<0?M=Math.max(0,M+_):M=Math.min(M,_);for(let p=_;p>M;--p)S[p]=S[p-1];S[M]=g}f.insert=Wo;function ot(S,M){let g=S.length;if(M<0&&(M+=g),M<0||M>=g)return;let _=S[M];for(let p=M+1;p<g;++p)S[p-1]=S[p];return S.length=g-1,_}f.removeAt=ot;function Ho(S,M,g=0,_=-1){let p=y(S,M,g,_);return p!==-1&&ot(S,p),p}f.removeFirstOf=Ho;function Jo(S,M,g=-1,_=0){let p=b(S,M,g,_);return p!==-1&&ot(S,p),p}f.removeLastOf=Jo;function Go(S,M,g=0,_=-1){let p=S.length;if(p===0)return 0;g<0?g=Math.max(0,g+p):g=Math.min(g,p-1),_<0?_=Math.max(0,_+p):_=Math.min(_,p-1);let I=0;for(let D=0;D<p;++D)g<=_&&D>=g&&D<=_&&S[D]===M||_<g&&(D<=_||D>=g)&&S[D]===M?I++:I>0&&(S[D-I]=S[D]);return I>0&&(S.length=p-I),I}f.removeAllOf=Go;function Xo(S,M,g=0,_=-1){let p,I=P(S,M,g,_);return I!==-1&&(p=ot(S,I)),{index:I,value:p}}f.removeFirstWhere=Xo;function Yo(S,M,g=-1,_=0){let p,I=x(S,M,g,_);return I!==-1&&(p=ot(S,I)),{index:I,value:p}}f.removeLastWhere=Yo;function Qo(S,M,g=0,_=-1){let p=S.length;if(p===0)return 0;g<0?g=Math.max(0,g+p):g=Math.min(g,p-1),_<0?_=Math.max(0,_+p):_=Math.min(_,p-1);let I=0;for(let D=0;D<p;++D)g<=_&&D>=g&&D<=_&&M(S[D],D)||_<g&&(D<=_||D>=g)&&M(S[D],D)?I++:I>0&&(S[D-I]=S[D]);return I>0&&(S.length=p-I),I}f.removeAllWhere=Qo}(r.ArrayExt||(r.ArrayExt={}));function*e(...f){for(let y of f)yield*y}function*t(){}function*n(f,y=0){for(let b of f)yield[y++,b]}function*s(f,y){let b=0;for(let P of f)y(P,b++)&&(yield P)}function i(f,y){let b=0;for(let P of f)if(y(P,b++))return P}function o(f,y){let b=0;for(let P of f)if(y(P,b++))return b-1;return-1}function a(f,y){let b;for(let P of f){if(b===void 0){b=P;continue}y(P,b)<0&&(b=P)}return b}function h(f,y){let b;for(let P of f){if(b===void 0){b=P;continue}y(P,b)>0&&(b=P)}return b}function c(f,y){let b=!0,P,x;for(let J of f)b?(P=J,x=J,b=!1):y(J,P)<0?P=J:y(J,x)>0&&(x=J);return b?void 0:[P,x]}function u(f){return Array.from(f)}function l(f){let y={};for(let[b,P]of f)y[b]=P;return y}function d(f,y){let b=0;for(let P of f)if(y(P,b++)===!1)return}function m(f,y){let b=0;for(let P of f)if(y(P,b++)===!1)return!1;return!0}function v(f,y){let b=0;for(let P of f)if(y(P,b++))return!0;return!1}function*T(f,y){let b=0;for(let P of f)yield y(P,b++)}function*E(f,y,b){y===void 0?(y=f,f=0,b=1):b===void 0&&(b=1);let P=q.rangeLength(f,y,b);for(let x=0;x<P;x++)yield f+b*x}var q;(function(f){function y(b,P,x){return x===0?1/0:b>P&&x>0||b<P&&x<0?0:Math.ceil((P-b)/x)}f.rangeLength=y})(q||(q={}));function A(f,y,b){let P=f[Symbol.iterator](),x=0,J=P.next();if(J.done&&b===void 0)throw new TypeError("Reduce of empty iterable with no initial value.");if(J.done)return b;let F=P.next();if(F.done&&b===void 0)return J.value;if(F.done)return y(b,J.value,x++);let K;b===void 0?K=y(J.value,F.value,x++):K=y(y(b,J.value,x++),F.value,x++);let Y;for(;!(Y=P.next()).done;)K=y(K,Y.value,x++);return K}function*C(f,y){for(;0<y--;)yield f}function*w(f){yield f}function*k(f){if(typeof f.retro=="function")yield*f.retro();else for(let y=f.length-1;y>-1;y--)yield f[y]}function N(f){let y=[],b=new Set,P=new Map;for(let F of f)x(F);for(let[F]of P)J(F);return y;function x(F){let[K,Y]=F,B=P.get(Y);B?B.push(K):P.set(Y,[K])}function J(F){if(b.has(F))return;b.add(F);let K=P.get(F);if(K)for(let Y of K)J(Y);y.push(F)}}function*j(f,y){let b=0;for(let P of f)b++%y===0&&(yield P)}r.StringExt=void 0,function(f){function y(F,K,Y=0){let B=new Array(K.length);for(let Z=0,G=Y,ue=K.length;Z<ue;++Z,++G){if(G=F.indexOf(K[Z],G),G===-1)return null;B[Z]=G}return B}f.findIndices=y;function b(F,K,Y=0){let B=y(F,K,Y);if(!B)return null;let Z=0;for(let G=0,ue=B.length;G<ue;++G){let Pe=B[G]-Y;Z+=Pe*Pe}return{score:Z,indices:B}}f.matchSumOfSquares=b;function P(F,K,Y=0){let B=y(F,K,Y);if(!B)return null;let Z=0,G=Y-1;for(let ue=0,Pe=B.length;ue<Pe;++ue){let Ie=B[ue];Z+=Ie-G-1,G=Ie}return{score:Z,indices:B}}f.matchSumOfDeltas=P;function x(F,K,Y){let B=[],Z=0,G=0,ue=K.length;for(;Z<ue;){let Pe=K[Z],Ie=K[Z];for(;++Z<ue&&K[Z]===Ie+1;)Ie++;G<Pe&&B.push(F.slice(G,Pe)),Pe<Ie+1&&B.push(Y(F.slice(Pe,Ie+1))),G=Ie+1}return G<F.length&&B.push(F.slice(G)),B}f.highlight=x;function J(F,K){return F<K?-1:F>K?1:0}f.cmp=J}(r.StringExt||(r.StringExt={}));function*R(f,y){if(y<1)return;let b=f[Symbol.iterator](),P;for(;0<y--&&!(P=b.next()).done;)yield P.value}function*U(...f){let y=f.map(P=>P[Symbol.iterator]()),b=y.map(P=>P.next());for(;m(b,P=>!P.done);b=y.map(P=>P.next()))yield b.map(P=>P.value)}r.chain=e,r.each=d,r.empty=t,r.enumerate=n,r.every=m,r.filter=s,r.find=i,r.findIndex=o,r.map=T,r.max=h,r.min=a,r.minmax=c,r.once=w,r.range=E,r.reduce=A,r.repeat=C,r.retro=k,r.some=v,r.stride=j,r.take=R,r.toArray=u,r.toObject=l,r.topologicSort=N,r.zip=U})});var X=O((Ft,gr)=>{(function(r,e){typeof Ft=="object"&&typeof gr!="undefined"?e(Ft,Gn()):typeof define=="function"&&define.amd?define(["exports","@lumino/algorithm"],e):(r=typeof globalThis!="undefined"?globalThis:r||self,e(r.lumino_coreutils={},r.lumino_algorithm))})(Ft,function(r,e){"use strict";r.JSONExt=void 0,function(c){c.emptyObject=Object.freeze({}),c.emptyArray=Object.freeze([]);function u(C){return C===null||typeof C=="boolean"||typeof C=="number"||typeof C=="string"}c.isPrimitive=u;function l(C){return Array.isArray(C)}c.isArray=l;function d(C){return!u(C)&&!l(C)}c.isObject=d;function m(C,w){if(C===w)return!0;if(u(C)||u(w))return!1;let k=l(C),N=l(w);return k!==N?!1:k&&N?T(C,w):E(C,w)}c.deepEqual=m;function v(C){return u(C)?C:l(C)?q(C):A(C)}c.deepCopy=v;function T(C,w){if(C===w)return!0;if(C.length!==w.length)return!1;for(let k=0,N=C.length;k<N;++k)if(!m(C[k],w[k]))return!1;return!0}function E(C,w){if(C===w)return!0;for(let k in C)if(C[k]!==void 0&&!(k in w))return!1;for(let k in w)if(w[k]!==void 0&&!(k in C))return!1;for(let k in C){let N=C[k],j=w[k];if(!(N===void 0&&j===void 0)&&(N===void 0||j===void 0||!m(N,j)))return!1}return!0}function q(C){let w=new Array(C.length);for(let k=0,N=C.length;k<N;++k)w[k]=v(C[k]);return w}function A(C){let w={};for(let k in C){let N=C[k];N!==void 0&&(w[k]=v(N))}return w}}(r.JSONExt||(r.JSONExt={}));class t{constructor(){this._types=[],this._values=[]}types(){return this._types.slice()}hasData(u){return this._types.indexOf(u)!==-1}getData(u){let l=this._types.indexOf(u);return l!==-1?this._values[l]:void 0}setData(u,l){this.clearData(u),this._types.push(u),this._values.push(l)}clearData(u){let l=this._types.indexOf(u);l!==-1&&(this._types.splice(l,1),this._values.splice(l,1))}clear(){this._types.length=0,this._values.length=0}}class n{constructor(u={}){this._application=null,this._validatePlugin=()=>!0,this._plugins=new Map,this._services=new Map,u.validatePlugin&&(console.info("Plugins may be rejected by the custom validation plugin method."),this._validatePlugin=u.validatePlugin)}get application(){return this._application}set application(u){if(this._application!==null)throw Error("PluginRegistry.application is already set. It cannot be overridden.");this._application=u}get deferredPlugins(){return Array.from(this._plugins).filter(([u,l])=>l.autoStart==="defer").map(([u,l])=>u)}getPluginDescription(u){var l,d;return(d=(l=this._plugins.get(u))===null||l===void 0?void 0:l.description)!==null&&d!==void 0?d:""}hasPlugin(u){return this._plugins.has(u)}isPluginActivated(u){var l,d;return(d=(l=this._plugins.get(u))===null||l===void 0?void 0:l.activated)!==null&&d!==void 0?d:!1}listPlugins(){return Array.from(this._plugins.keys())}registerPlugin(u){if(this._plugins.has(u.id))throw new TypeError(`Plugin '${u.id}' is already registered.`);if(!this._validatePlugin(u))throw new Error(`Plugin '${u.id}' is not valid.`);let l=s.createPluginData(u);s.ensureNoCycle(l,this._plugins,this._services),l.provides&&this._services.set(l.provides,l.id),this._plugins.set(l.id,l)}registerPlugins(u){for(let l of u)this.registerPlugin(l)}deregisterPlugin(u,l){let d=this._plugins.get(u);if(d){if(d.activated&&!l)throw new Error(`Plugin '${u}' is still active.`);this._plugins.delete(u)}}async activatePlugin(u){let l=this._plugins.get(u);if(!l)throw new ReferenceError(`Plugin '${u}' is not registered.`);if(l.activated)return;if(l.promise)return l.promise;let d=l.requires.map(v=>this.resolveRequiredService(v)),m=l.optional.map(v=>this.resolveOptionalService(v));return l.promise=Promise.all([...d,...m]).then(v=>l.activate.apply(void 0,[this.application,...v])).then(v=>{l.service=v,l.activated=!0,l.promise=null}).catch(v=>{throw l.promise=null,v}),l.promise}async activatePlugins(u,l={}){switch(u){case"defer":{let d=this.deferredPlugins.filter(m=>this._plugins.get(m).autoStart).map(m=>this.activatePlugin(m));await Promise.all(d);break}case"startUp":{let m=s.collectStartupPlugins(this._plugins,l).map(async v=>{try{return await this.activatePlugin(v)}catch(T){console.error(`Plugin '${v}' failed to activate.`,T)}});await Promise.all(m);break}}}async deactivatePlugin(u){let l=this._plugins.get(u);if(!l)throw new ReferenceError(`Plugin '${u}' is not registered.`);if(!l.activated)return[];if(!l.deactivate)throw new TypeError(`Plugin '${u}'#deactivate() method missing`);let d=s.findDependents(u,this._plugins,this._services),m=d.map(v=>this._plugins.get(v));for(let v of m)if(!v.deactivate)throw new TypeError(`Plugin ${v.id}#deactivate() method missing (depends on ${u})`);for(let v of m){let T=[...v.requires,...v.optional].map(E=>{let q=this._services.get(E);return q?this._plugins.get(q).service:null});await v.deactivate(this.application,...T),v.service=null,v.activated=!1}return d.pop(),d}async resolveRequiredService(u){let l=this._services.get(u);if(!l)throw new TypeError(`No provider for: ${u.name}.`);let d=this._plugins.get(l);return d.activated||await this.activatePlugin(l),d.service}async resolveOptionalService(u){let l=this._services.get(u);if(!l)return null;let d=this._plugins.get(l);if(!d.activated)try{await this.activatePlugin(l)}catch(m){return console.error(m),null}return d.service}}var s;(function(c){class u{constructor(E){var q,A,C,w;this._activated=!1,this._promise=null,this._service=null,this.id=E.id,this.description=(q=E.description)!==null&&q!==void 0?q:"",this.activate=E.activate,this.deactivate=(A=E.deactivate)!==null&&A!==void 0?A:null,this.provides=(C=E.provides)!==null&&C!==void 0?C:null,this.autoStart=(w=E.autoStart)!==null&&w!==void 0?w:!1,this.requires=E.requires?E.requires.slice():[],this.optional=E.optional?E.optional.slice():[]}get activated(){return this._activated}set activated(E){this._activated=E}get service(){return this._service}set service(E){this._service=E}get promise(){return this._promise}set promise(E){this._promise=E}}function l(T){return new u(T)}c.createPluginData=l;function d(T,E,q){let A=[...T.requires,...T.optional],C=k=>{if(k===T.provides)return!0;let N=q.get(k);if(!N)return!1;let j=E.get(N),R=[...j.requires,...j.optional];return R.length===0?!1:(w.push(N),R.some(C)?!0:(w.pop(),!1))};if(!T.provides||A.length===0)return;let w=[T.id];if(A.some(C))throw new ReferenceError(`Cycle detected: ${w.join(" -> ")}.`)}c.ensureNoCycle=d;function m(T,E,q){let A=new Array,C=R=>{let U=E.get(R),f=[...U.requires,...U.optional];A.push(...f.reduce((y,b)=>{let P=q.get(b);return P&&y.push([R,P]),y},[]))};for(let R of E.keys())C(R);let w=A.filter(R=>R[1]===T),k=0;for(;w.length>k;){let R=w.length,U=new Set(w.map(f=>f[0]));for(let f of U)A.filter(y=>y[1]===f).forEach(y=>{w.includes(y)||w.push(y)});k=R}let N=e.topologicSort(w),j=N.findIndex(R=>R===T);return j===-1?[T]:N.slice(0,j+1)}c.findDependents=m;function v(T,E){let q=new Set;for(let A of T.keys())T.get(A).autoStart===!0&&q.add(A);if(E.startPlugins)for(let A of E.startPlugins)q.add(A);if(E.ignorePlugins)for(let A of E.ignorePlugins)q.delete(A);return Array.from(q)}c.collectStartupPlugins=v})(s||(s={}));class i{constructor(){this.promise=new Promise((u,l)=>{this._resolve=u,this._reject=l})}resolve(u){let l=this._resolve;l(u)}reject(u){let l=this._reject;l(u)}}class o{constructor(u,l){this.name=u,this.description=l!=null?l:"",this._tokenStructuralPropertyT=null}}function a(c){let u=0;for(let l=0,d=c.length;l<d;++l)l%4===0&&(u=Math.random()*4294967295>>>0),c[l]=u&255,u>>>=8}r.Random=void 0,function(c){c.getRandomValues=(()=>{let u=typeof window!="undefined"&&(window.crypto||window.msCrypto)||null;return u&&typeof u.getRandomValues=="function"?function(d){return u.getRandomValues(d)}:a})()}(r.Random||(r.Random={}));function h(c){let u=new Uint8Array(16),l=new Array(256);for(let d=0;d<16;++d)l[d]="0"+d.toString(16);for(let d=16;d<256;++d)l[d]=d.toString(16);return function(){return c(u),u[6]=64|u[6]&15,u[8]=128|u[8]&63,l[u[0]]+l[u[1]]+l[u[2]]+l[u[3]]+"-"+l[u[4]]+l[u[5]]+"-"+l[u[6]]+l[u[7]]+"-"+l[u[8]]+l[u[9]]+"-"+l[u[10]]+l[u[11]]+l[u[12]]+l[u[13]]+l[u[14]]+l[u[15]]}}r.UUID=void 0,function(c){c.uuid4=h(r.Random.getRandomValues)}(r.UUID||(r.UUID={})),r.MimeData=t,r.PluginRegistry=n,r.PromiseDelegate=i,r.Token=o})});var ee=O((Kt,pr)=>{(function(r,e){typeof Kt=="object"&&typeof pr!="undefined"?e(Kt,Gn(),X()):typeof define=="function"&&define.amd?define(["exports","@lumino/algorithm","@lumino/coreutils"],e):(r=typeof globalThis!="undefined"?globalThis:r||self,e(r.lumino_signaling={},r.lumino_algorithm,r.lumino_coreutils))})(Kt,function(r,e,t){"use strict";class n{constructor(a){this.sender=a}connect(a,h){return i.connect(this,a,h)}disconnect(a,h){return i.disconnect(this,a,h)}emit(a){i.emit(this,a)}}(function(o){function a(v,T){i.disconnectBetween(v,T)}o.disconnectBetween=a;function h(v){i.disconnectSender(v)}o.disconnectSender=h;function c(v){i.disconnectReceiver(v)}o.disconnectReceiver=c;function u(v){i.disconnectAll(v)}o.disconnectAll=u;function l(v){i.disconnectAll(v)}o.clearData=l;function d(){return i.exceptionHandler}o.getExceptionHandler=d;function m(v){let T=i.exceptionHandler;return i.exceptionHandler=v,T}o.setExceptionHandler=m})(n||(n={}));class s extends n{constructor(){super(...arguments),this._pending=new t.PromiseDelegate}async*[Symbol.asyncIterator](){let a=this._pending;for(;;)try{let{args:h,next:c}=await a.promise;a=c,yield h}catch{return}}emit(a){let h=this._pending,c=this._pending=new t.PromiseDelegate;h.resolve({args:a,next:c}),super.emit(a)}stop(){this._pending.promise.catch(()=>{}),this._pending.reject("stop"),this._pending=new t.PromiseDelegate}}var i;(function(o){o.exceptionHandler=R=>{console.error(R)};function a(R,U,f){f=f||void 0;let y=v.get(R.sender);if(y||(y=[],v.set(R.sender,y)),A(y,R,U,f))return!1;let b=f||U,P=T.get(b);P||(P=[],T.set(b,P));let x={signal:R,slot:U,thisArg:f};return y.push(x),P.push(x),!0}o.connect=a;function h(R,U,f){f=f||void 0;let y=v.get(R.sender);if(!y||y.length===0)return!1;let b=A(y,R,U,f);if(!b)return!1;let P=f||U,x=T.get(P);return b.signal=null,w(y),w(x),!0}o.disconnect=h;function c(R,U){let f=v.get(R);if(!f||f.length===0)return;let y=T.get(U);if(!(!y||y.length===0)){for(let b of y)b.signal&&b.signal.sender===R&&(b.signal=null);w(f),w(y)}}o.disconnectBetween=c;function u(R){let U=v.get(R);if(!(!U||U.length===0)){for(let f of U){if(!f.signal)continue;let y=f.thisArg||f.slot;f.signal=null,w(T.get(y))}w(U)}}o.disconnectSender=u;function l(R){let U=T.get(R);if(!(!U||U.length===0)){for(let f of U){if(!f.signal)continue;let y=f.signal.sender;f.signal=null,w(v.get(y))}w(U)}}o.disconnectReceiver=l;function d(R){u(R),l(R)}o.disconnectAll=d;function m(R,U){let f=v.get(R.sender);if(!(!f||f.length===0))for(let y=0,b=f.length;y<b;++y){let P=f[y];P.signal===R&&C(P,U)}}o.emit=m;let v=new WeakMap,T=new WeakMap,E=new Set,q=typeof requestAnimationFrame=="function"?requestAnimationFrame:setImmediate;function A(R,U,f,y){return e.find(R,b=>b.signal===U&&b.slot===f&&b.thisArg===y)}function C(R,U){let{signal:f,slot:y,thisArg:b}=R;try{y.call(b,f.sender,U)}catch(P){o.exceptionHandler(P)}}function w(R){E.size===0&&q(k),E.add(R)}function k(){E.forEach(N),E.clear()}function N(R){e.ArrayExt.removeAllWhere(R,j)}function j(R){return R.signal===null}})(i||(i={})),r.Signal=n,r.Stream=s})});var vr=O(zt=>{"use strict";Object.defineProperty(zt,"__esModule",{value:!0});zt.ActivityMonitor=void 0;var mr=ee(),Xn=class{constructor(e){this._timer=-1,this._timeout=-1,this._isDisposed=!1,this._activityStopped=new mr.Signal(this),e.signal.connect(this._onSignalFired,this),this._timeout=e.timeout||1e3}get activityStopped(){return this._activityStopped}get timeout(){return this._timeout}set timeout(e){this._timeout=e}get isDisposed(){return this._isDisposed}dispose(){this._isDisposed||(this._isDisposed=!0,mr.Signal.clearData(this))}_onSignalFired(e,t){clearTimeout(this._timer),this._sender=e,this._args=t,this._timer=setTimeout(()=>{this._activityStopped.emit({sender:this._sender,args:this._args})},this._timeout)}};zt.ActivityMonitor=Xn});var wr=O(yr=>{"use strict";Object.defineProperty(yr,"__esModule",{value:!0})});var Sr=O(Vt=>{"use strict";Object.defineProperty(Vt,"__esModule",{value:!0});Vt.LruCache=void 0;var ya=128,Yn=class{constructor(e={}){if(this._map=new Map,this._maxSize=(e==null?void 0:e.maxSize)||ya,this._maxSize<1)throw new Error("maxSize must be at least 1")}get size(){return this._map.size}clear(){this._map.clear()}get(e){let t=this._map.get(e)||null;return t!=null&&(this._map.delete(e),this._map.set(e,t)),t}set(e,t){this._map.size>=this._maxSize&&this._map.delete(this._map.keys().next().value),this._map.set(e,t)}};Vt.LruCache=Yn});var Cr=O(Bt=>{"use strict";Object.defineProperty(Bt,"__esModule",{value:!0});Bt.MarkdownCodeBlocks=void 0;var br;(function(r){r.CODE_BLOCK_MARKER="```";let e=[".markdown",".mdown",".mkdn",".md",".mkd",".mdwn",".mdtxt",".mdtext",".text",".txt",".Rmd"];class t{constructor(o){this.startLine=o,this.code="",this.endLine=-1}}r.MarkdownCodeBlock=t;function n(i){return e.indexOf(i)>-1}r.isMarkdown=n;function s(i){if(!i||i==="")return[];let o=i.split(`
2
2
  `),a=[],h=null;for(let c=0;c<o.length;c++){let u=o[c],l=u.indexOf(r.CODE_BLOCK_MARKER)===0,d=h!=null;if(!(!l&&!d))if(d)h&&(l?(h.endLine=c-1,a.push(h),h=null):h.code+=u+`
3
- `);else{h=new t(c);let m=u.indexOf(r.CODE_BLOCK_MARKER),v=u.lastIndexOf(r.CODE_BLOCK_MARKER);m!==v&&(h.code=u.substring(m+r.CODE_BLOCK_MARKER.length,v),h.endLine=c,a.push(h),h=null)}}return a}r.findMarkdownCodeBlocks=s})(br||(Bt.MarkdownCodeBlocks=br={}))});var Ir=O((Nu,Er)=>{"use strict";function ya(r,e){var t=r;e.slice(0,-1).forEach(function(s){t=t[s]||{}});var n=e[e.length-1];return n in t}function Pr(r){return typeof r=="number"||/^0x[0-9a-f]+$/i.test(r)?!0:/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(r)}function Mr(r,e){return e==="constructor"&&typeof r[e]=="function"||e==="__proto__"}Er.exports=function(r,e){e||(e={});var t={bools:{},strings:{},unknownFn:null};typeof e.unknown=="function"&&(t.unknownFn=e.unknown),typeof e.boolean=="boolean"&&e.boolean?t.allBools=!0:[].concat(e.boolean).filter(Boolean).forEach(function(w){t.bools[w]=!0});var n={};function s(w){return n[w].some(function(k){return t.bools[k]})}Object.keys(e.alias||{}).forEach(function(w){n[w]=[].concat(e.alias[w]),n[w].forEach(function(k){n[k]=[w].concat(n[w].filter(function(N){return k!==N}))})}),[].concat(e.string).filter(Boolean).forEach(function(w){t.strings[w]=!0,n[w]&&[].concat(n[w]).forEach(function(k){t.strings[k]=!0})});var i=e.default||{},o={_:[]};function a(w,k){return t.allBools&&/^--[^=]+$/.test(k)||t.strings[w]||t.bools[w]||n[w]}function h(w,k,N){for(var j=w,R=0;R<k.length-1;R++){var U=k[R];if(Mr(j,U))return;j[U]===void 0&&(j[U]={}),(j[U]===Object.prototype||j[U]===Number.prototype||j[U]===String.prototype)&&(j[U]={}),j[U]===Array.prototype&&(j[U]=[]),j=j[U]}var f=k[k.length-1];Mr(j,f)||((j===Object.prototype||j===Number.prototype||j===String.prototype)&&(j={}),j===Array.prototype&&(j=[]),j[f]===void 0||t.bools[f]||typeof j[f]=="boolean"?j[f]=N:Array.isArray(j[f])?j[f].push(N):j[f]=[j[f],N])}function c(w,k,N){if(!(N&&t.unknownFn&&!a(w,N)&&t.unknownFn(N)===!1)){var j=!t.strings[w]&&Pr(k)?Number(k):k;h(o,w.split("."),j),(n[w]||[]).forEach(function(R){h(o,R.split("."),j)})}}Object.keys(t.bools).forEach(function(w){c(w,i[w]===void 0?!1:i[w])});var u=[];r.indexOf("--")!==-1&&(u=r.slice(r.indexOf("--")+1),r=r.slice(0,r.indexOf("--")));for(var l=0;l<r.length;l++){var d=r[l],m,v;if(/^--.+=/.test(d)){var T=d.match(/^--([^=]+)=([\s\S]*)$/);m=T[1];var E=T[2];t.bools[m]&&(E=E!=="false"),c(m,E,d)}else if(/^--no-.+/.test(d))m=d.match(/^--no-(.+)/)[1],c(m,!1,d);else if(/^--.+/.test(d))m=d.match(/^--(.+)/)[1],v=r[l+1],v!==void 0&&!/^(-|--)[^-]/.test(v)&&!t.bools[m]&&!t.allBools&&(!n[m]||!s(m))?(c(m,v,d),l+=1):/^(true|false)$/.test(v)?(c(m,v==="true",d),l+=1):c(m,t.strings[m]?"":!0,d);else if(/^-[^-]+/.test(d)){for(var q=d.slice(1,-1).split(""),A=!1,C=0;C<q.length;C++){if(v=d.slice(C+2),v==="-"){c(q[C],v,d);continue}if(/[A-Za-z]/.test(q[C])&&v[0]==="="){c(q[C],v.slice(1),d),A=!0;break}if(/[A-Za-z]/.test(q[C])&&/-?\d+(\.\d*)?(e-?\d+)?$/.test(v)){c(q[C],v,d),A=!0;break}if(q[C+1]&&q[C+1].match(/\W/)){c(q[C],d.slice(C+2),d),A=!0;break}else c(q[C],t.strings[q[C]]?"":!0,d)}m=d.slice(-1)[0],!A&&m!=="-"&&(r[l+1]&&!/^(-|--)[^-]/.test(r[l+1])&&!t.bools[m]&&(!n[m]||!s(m))?(c(m,r[l+1],d),l+=1):r[l+1]&&/^(true|false)$/.test(r[l+1])?(c(m,r[l+1]==="true",d),l+=1):c(m,t.strings[m]?"":!0,d))}else if((!t.unknownFn||t.unknownFn(d)!==!1)&&o._.push(t.strings._||!Pr(d)?d:Number(d)),e.stopEarly){o._.push.apply(o._,r.slice(l+1));break}}return Object.keys(i).forEach(function(w){ya(o,w.split("."))||(h(o,w.split("."),i[w]),(n[w]||[]).forEach(function(k){h(o,k.split("."),i[w])}))}),e["--"]?o["--"]=u.slice():u.forEach(function(w){o._.push(w)}),o}});var $t=O((Lu,Rr)=>{"use strict";function Oe(r){if(typeof r!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(r))}function Or(r,e){for(var t="",n=0,s=-1,i=0,o,a=0;a<=r.length;++a){if(a<r.length)o=r.charCodeAt(a);else{if(o===47)break;o=47}if(o===47){if(!(s===a-1||i===1))if(s!==a-1&&i===2){if(t.length<2||n!==2||t.charCodeAt(t.length-1)!==46||t.charCodeAt(t.length-2)!==46){if(t.length>2){var h=t.lastIndexOf("/");if(h!==t.length-1){h===-1?(t="",n=0):(t=t.slice(0,h),n=t.length-1-t.lastIndexOf("/")),s=a,i=0;continue}}else if(t.length===2||t.length===1){t="",n=0,s=a,i=0;continue}}e&&(t.length>0?t+="/..":t="..",n=2)}else t.length>0?t+="/"+r.slice(s+1,a):t=r.slice(s+1,a),n=a-s-1;s=a,i=0}else o===46&&i!==-1?++i:i=-1}return t}function wa(r,e){var t=e.dir||e.root,n=e.base||(e.name||"")+(e.ext||"");return t?t===e.root?t+n:t+r+n:n}var Qe={resolve:function(){for(var e="",t=!1,n,s=arguments.length-1;s>=-1&&!t;s--){var i;s>=0?i=arguments[s]:(n===void 0&&(n=process.cwd()),i=n),Oe(i),i.length!==0&&(e=i+"/"+e,t=i.charCodeAt(0)===47)}return e=Or(e,!t),t?e.length>0?"/"+e:"/":e.length>0?e:"."},normalize:function(e){if(Oe(e),e.length===0)return".";var t=e.charCodeAt(0)===47,n=e.charCodeAt(e.length-1)===47;return e=Or(e,!t),e.length===0&&!t&&(e="."),e.length>0&&n&&(e+="/"),t?"/"+e:e},isAbsolute:function(e){return Oe(e),e.length>0&&e.charCodeAt(0)===47},join:function(){if(arguments.length===0)return".";for(var e,t=0;t<arguments.length;++t){var n=arguments[t];Oe(n),n.length>0&&(e===void 0?e=n:e+="/"+n)}return e===void 0?".":Qe.normalize(e)},relative:function(e,t){if(Oe(e),Oe(t),e===t||(e=Qe.resolve(e),t=Qe.resolve(t),e===t))return"";for(var n=1;n<e.length&&e.charCodeAt(n)===47;++n);for(var s=e.length,i=s-n,o=1;o<t.length&&t.charCodeAt(o)===47;++o);for(var a=t.length,h=a-o,c=i<h?i:h,u=-1,l=0;l<=c;++l){if(l===c){if(h>c){if(t.charCodeAt(o+l)===47)return t.slice(o+l+1);if(l===0)return t.slice(o+l)}else i>c&&(e.charCodeAt(n+l)===47?u=l:l===0&&(u=0));break}var d=e.charCodeAt(n+l),m=t.charCodeAt(o+l);if(d!==m)break;d===47&&(u=l)}var v="";for(l=n+u+1;l<=s;++l)(l===s||e.charCodeAt(l)===47)&&(v.length===0?v+="..":v+="/..");return v.length>0?v+t.slice(o+u):(o+=u,t.charCodeAt(o)===47&&++o,t.slice(o))},_makeLong:function(e){return e},dirname:function(e){if(Oe(e),e.length===0)return".";for(var t=e.charCodeAt(0),n=t===47,s=-1,i=!0,o=e.length-1;o>=1;--o)if(t=e.charCodeAt(o),t===47){if(!i){s=o;break}}else i=!1;return s===-1?n?"/":".":n&&s===1?"//":e.slice(0,s)},basename:function(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');Oe(e);var n=0,s=-1,i=!0,o;if(t!==void 0&&t.length>0&&t.length<=e.length){if(t.length===e.length&&t===e)return"";var a=t.length-1,h=-1;for(o=e.length-1;o>=0;--o){var c=e.charCodeAt(o);if(c===47){if(!i){n=o+1;break}}else h===-1&&(i=!1,h=o+1),a>=0&&(c===t.charCodeAt(a)?--a===-1&&(s=o):(a=-1,s=h))}return n===s?s=h:s===-1&&(s=e.length),e.slice(n,s)}else{for(o=e.length-1;o>=0;--o)if(e.charCodeAt(o)===47){if(!i){n=o+1;break}}else s===-1&&(i=!1,s=o+1);return s===-1?"":e.slice(n,s)}},extname:function(e){Oe(e);for(var t=-1,n=0,s=-1,i=!0,o=0,a=e.length-1;a>=0;--a){var h=e.charCodeAt(a);if(h===47){if(!i){n=a+1;break}continue}s===-1&&(i=!1,s=a+1),h===46?t===-1?t=a:o!==1&&(o=1):t!==-1&&(o=-1)}return t===-1||s===-1||o===0||o===1&&t===s-1&&t===n+1?"":e.slice(t,s)},format:function(e){if(e===null||typeof e!="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof e);return wa("/",e)},parse:function(e){Oe(e);var t={root:"",dir:"",base:"",ext:"",name:""};if(e.length===0)return t;var n=e.charCodeAt(0),s=n===47,i;s?(t.root="/",i=1):i=0;for(var o=-1,a=0,h=-1,c=!0,u=e.length-1,l=0;u>=i;--u){if(n=e.charCodeAt(u),n===47){if(!c){a=u+1;break}continue}h===-1&&(c=!1,h=u+1),n===46?o===-1?o=u:l!==1&&(l=1):o!==-1&&(l=-1)}return o===-1||h===-1||l===0||l===1&&o===h-1&&o===a+1?h!==-1&&(a===0&&s?t.base=t.name=e.slice(1,h):t.base=t.name=e.slice(a,h)):(a===0&&s?(t.name=e.slice(1,o),t.base=e.slice(1,h)):(t.name=e.slice(a,o),t.base=e.slice(a,h)),t.ext=e.slice(o,h)),a>0?t.dir=e.slice(0,a-1):s&&(t.dir="/"),t},sep:"/",delimiter:":",win32:null,posix:null};Qe.posix=Qe;Rr.exports=Qe});var Dr=O((xu,kr)=>{"use strict";kr.exports=function(e,t){if(t=t.split(":")[0],e=+e,!e)return!1;switch(t){case"http":case"ws":return e!==80;case"https":case"wss":return e!==443;case"ftp":return e!==21;case"gopher":return e!==70;case"file":return!1}return e!==0}});var jr=O(Qn=>{"use strict";var Sa=Object.prototype.hasOwnProperty,ba;function Tr(r){try{return decodeURIComponent(r.replace(/\+/g," "))}catch{return null}}function qr(r){try{return encodeURIComponent(r)}catch{return null}}function Ca(r){for(var e=/([^=?#&]+)=?([^&]*)/g,t={},n;n=e.exec(r);){var s=Tr(n[1]),i=Tr(n[2]);s===null||i===null||s in t||(t[s]=i)}return t}function Pa(r,e){e=e||"";var t=[],n,s;typeof e!="string"&&(e="?");for(s in r)if(Sa.call(r,s)){if(n=r[s],!n&&(n===null||n===ba||isNaN(n))&&(n=""),s=qr(s),n=qr(n),s===null||n===null)continue;t.push(s+"="+n)}return t.length?e+t.join("&"):""}Qn.stringify=Pa;Qn.parse=Ca});var zr=O((Ku,Kr)=>{"use strict";var Ar=Dr(),Wt=jr(),Ma=/^[\x00-\x20\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/,Nr=/[\n\r\t]/g,Ea=/^[A-Za-z][A-Za-z0-9+-.]*:\/\//,Lr=/:\d+$/,Ia=/^([a-z][a-z0-9.+-]*:)?(\/\/)?([\\/]+)?([\S\s]*)/i,Oa=/^[a-zA-Z]:/;function es(r){return(r||"").toString().replace(Ma,"")}var Zn=[["#","hash"],["?","query"],function(e,t){return Re(t.protocol)?e.replace(/\\/g,"/"):e},["/","pathname"],["@","auth",1],[NaN,"host",void 0,1,1],[/:(\d*)$/,"port",void 0,1],[NaN,"hostname",void 0,1,1]],Ur={hash:1,query:1};function xr(r){var e;typeof window!="undefined"?e=window:typeof global!="undefined"?e=global:typeof self!="undefined"?e=self:e={};var t=e.location||{};r=r||t;var n={},s=typeof r,i;if(r.protocol==="blob:")n=new ke(unescape(r.pathname),{});else if(s==="string"){n=new ke(r,{});for(i in Ur)delete n[i]}else if(s==="object"){for(i in r)i in Ur||(n[i]=r[i]);n.slashes===void 0&&(n.slashes=Ea.test(r.href))}return n}function Re(r){return r==="file:"||r==="ftp:"||r==="http:"||r==="https:"||r==="ws:"||r==="wss:"}function Fr(r,e){r=es(r),r=r.replace(Nr,""),e=e||{};var t=Ia.exec(r),n=t[1]?t[1].toLowerCase():"",s=!!t[2],i=!!t[3],o=0,a;return s?i?(a=t[2]+t[3]+t[4],o=t[2].length+t[3].length):(a=t[2]+t[4],o=t[2].length):i?(a=t[3]+t[4],o=t[3].length):a=t[4],n==="file:"?o>=2&&(a=a.slice(2)):Re(n)?a=t[4]:n?s&&(a=a.slice(2)):o>=2&&Re(e.protocol)&&(a=t[4]),{protocol:n,slashes:s||Re(n),slashesCount:o,rest:a}}function Ra(r,e){if(r==="")return e;for(var t=(e||"/").split("/").slice(0,-1).concat(r.split("/")),n=t.length,s=t[n-1],i=!1,o=0;n--;)t[n]==="."?t.splice(n,1):t[n]===".."?(t.splice(n,1),o++):o&&(n===0&&(i=!0),t.splice(n,1),o--);return i&&t.unshift(""),(s==="."||s==="..")&&t.push(""),t.join("/")}function ke(r,e,t){if(r=es(r),r=r.replace(Nr,""),!(this instanceof ke))return new ke(r,e,t);var n,s,i,o,a,h,c=Zn.slice(),u=typeof e,l=this,d=0;for(u!=="object"&&u!=="string"&&(t=e,e=null),t&&typeof t!="function"&&(t=Wt.parse),e=xr(e),s=Fr(r||"",e),n=!s.protocol&&!s.slashes,l.slashes=s.slashes||n&&e.slashes,l.protocol=s.protocol||e.protocol||"",r=s.rest,(s.protocol==="file:"&&(s.slashesCount!==2||Oa.test(r))||!s.slashes&&(s.protocol||s.slashesCount<2||!Re(l.protocol)))&&(c[3]=[/(.*)/,"pathname"]);d<c.length;d++){if(o=c[d],typeof o=="function"){r=o(r,l);continue}i=o[0],h=o[1],i!==i?l[h]=r:typeof i=="string"?(a=i==="@"?r.lastIndexOf(i):r.indexOf(i),~a&&(typeof o[2]=="number"?(l[h]=r.slice(0,a),r=r.slice(a+o[2])):(l[h]=r.slice(a),r=r.slice(0,a)))):(a=i.exec(r))&&(l[h]=a[1],r=r.slice(0,a.index)),l[h]=l[h]||n&&o[3]&&e[h]||"",o[4]&&(l[h]=l[h].toLowerCase())}t&&(l.query=t(l.query)),n&&e.slashes&&l.pathname.charAt(0)!=="/"&&(l.pathname!==""||e.pathname!=="")&&(l.pathname=Ra(l.pathname,e.pathname)),l.pathname.charAt(0)!=="/"&&Re(l.protocol)&&(l.pathname="/"+l.pathname),Ar(l.port,l.protocol)||(l.host=l.hostname,l.port=""),l.username=l.password="",l.auth&&(a=l.auth.indexOf(":"),~a?(l.username=l.auth.slice(0,a),l.username=encodeURIComponent(decodeURIComponent(l.username)),l.password=l.auth.slice(a+1),l.password=encodeURIComponent(decodeURIComponent(l.password))):l.username=encodeURIComponent(decodeURIComponent(l.auth)),l.auth=l.password?l.username+":"+l.password:l.username),l.origin=l.protocol!=="file:"&&Re(l.protocol)&&l.host?l.protocol+"//"+l.host:"null",l.href=l.toString()}function ka(r,e,t){var n=this;switch(r){case"query":typeof e=="string"&&e.length&&(e=(t||Wt.parse)(e)),n[r]=e;break;case"port":n[r]=e,Ar(e,n.protocol)?e&&(n.host=n.hostname+":"+e):(n.host=n.hostname,n[r]="");break;case"hostname":n[r]=e,n.port&&(e+=":"+n.port),n.host=e;break;case"host":n[r]=e,Lr.test(e)?(e=e.split(":"),n.port=e.pop(),n.hostname=e.join(":")):(n.hostname=e,n.port="");break;case"protocol":n.protocol=e.toLowerCase(),n.slashes=!t;break;case"pathname":case"hash":if(e){var s=r==="pathname"?"/":"#";n[r]=e.charAt(0)!==s?s+e:e}else n[r]=e;break;case"username":case"password":n[r]=encodeURIComponent(e);break;case"auth":var i=e.indexOf(":");~i?(n.username=e.slice(0,i),n.username=encodeURIComponent(decodeURIComponent(n.username)),n.password=e.slice(i+1),n.password=encodeURIComponent(decodeURIComponent(n.password))):n.username=encodeURIComponent(decodeURIComponent(e))}for(var o=0;o<Zn.length;o++){var a=Zn[o];a[4]&&(n[a[1]]=n[a[1]].toLowerCase())}return n.auth=n.password?n.username+":"+n.password:n.username,n.origin=n.protocol!=="file:"&&Re(n.protocol)&&n.host?n.protocol+"//"+n.host:"null",n.href=n.toString(),n}function Da(r){(!r||typeof r!="function")&&(r=Wt.stringify);var e,t=this,n=t.host,s=t.protocol;s&&s.charAt(s.length-1)!==":"&&(s+=":");var i=s+(t.protocol&&t.slashes||Re(t.protocol)?"//":"");return t.username?(i+=t.username,t.password&&(i+=":"+t.password),i+="@"):t.password?(i+=":"+t.password,i+="@"):t.protocol!=="file:"&&Re(t.protocol)&&!n&&t.pathname!=="/"&&(i+="@"),(n[n.length-1]===":"||Lr.test(t.hostname)&&!t.port)&&(n+=":"),i+=n+t.pathname,e=typeof t.query=="object"?r(t.query):t.query,e&&(i+=e.charAt(0)!=="?"?"?"+e:e),t.hash&&(i+=t.hash),i}ke.prototype={set:ka,toString:Da};ke.extractProtocol=Fr;ke.location=xr;ke.trimLeft=es;ke.qs=Wt;Kr.exports=ke});var ts=O(Ze=>{"use strict";var Ta=Ze&&Ze.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(Ze,"__esModule",{value:!0});Ze.URLExt=void 0;var qa=$t(),Ht=Ta(zr()),Vr;(function(r){function e(c){if(typeof document!="undefined"&&document){let u=document.createElement("a");return u.href=c,u}return(0,Ht.default)(c)}r.parse=e;function t(c){return(0,Ht.default)(c).hostname}r.getHostName=t;function n(c){return c&&e(c).toString()}r.normalize=n;function s(...c){let u=(0,Ht.default)(c[0],{}),l=u.protocol===""&&u.slashes;l&&(u=(0,Ht.default)(c[0],"https:"+c[0]));let d=`${l?"":u.protocol}${u.slashes?"//":""}${u.auth}${u.auth?"@":""}${u.host}`,m=qa.posix.join(`${d&&u.pathname[0]!=="/"?"/":""}${u.pathname}`,...c.slice(1));return`${d}${m==="."?"":m}`}r.join=s;function i(c){return s(...c.split("/").map(encodeURIComponent))}r.encodeParts=i;function o(c){let u=Object.keys(c).filter(l=>l.length>0);return u.length?"?"+u.map(l=>{let d=encodeURIComponent(String(c[l]));return l+(d?"="+d:"")}).join("&"):""}r.objectToQueryString=o;function a(c){return c.replace(/^\?/,"").split("&").reduce((u,l)=>{let[d,m]=l.split("=");return d.length>0&&(u[d]=decodeURIComponent(m||"")),u},{})}r.queryStringToObject=a;function h(c,u=!1){let{protocol:l}=e(c);return(!l||c.toLowerCase().indexOf(l)!==0)&&(u?c.indexOf("//")!==0:c.indexOf("/")!==0)}r.isLocal=h})(Vr||(Ze.URLExt=Vr={}))});var Br=O((exports,module)=>{"use strict";var __importDefault=exports&&exports.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(exports,"__esModule",{value:!0});exports.PageConfig=void 0;exports.compareVersions=compareVersions;var coreutils_1=X(),minimist_1=__importDefault(Ir()),url_1=ts(),PageConfig;(function(PageConfig){function getOption(name){if(configData)return configData[name]||getBodyData(name);configData=Object.create(null);let found=!1;if(typeof document!="undefined"&&document){let r=document.getElementById("jupyter-config-data");r&&(configData=JSON.parse(r.textContent||""),found=!0)}if(!found&&typeof process!="undefined"&&process.argv)try{let cli=(0,minimist_1.default)(process.argv.slice(2)),path=$t(),fullPath="";"jupyter-config-data"in cli?fullPath=path.resolve(cli["jupyter-config-data"]):"JUPYTER_CONFIG_DATA"in process.env&&(fullPath=path.resolve(process.env.JUPYTER_CONFIG_DATA)),fullPath&&(configData=eval("require")(fullPath))}catch(r){console.error(r)}if(!coreutils_1.JSONExt.isObject(configData))configData=Object.create(null);else for(let r in configData)typeof configData[r]!="string"&&(configData[r]=JSON.stringify(configData[r]));return configData[name]||getBodyData(name)}PageConfig.getOption=getOption;function setOption(r,e){let t=getOption(r);return configData[r]=e,t}PageConfig.setOption=setOption;function getBaseUrl(){return url_1.URLExt.normalize(getOption("baseUrl")||"/")}PageConfig.getBaseUrl=getBaseUrl;function getTreeUrl(){return url_1.URLExt.join(getBaseUrl(),getOption("treeUrl"))}PageConfig.getTreeUrl=getTreeUrl;function getShareUrl(){return url_1.URLExt.normalize(getOption("shareUrl")||getBaseUrl())}PageConfig.getShareUrl=getShareUrl;function getTreeShareUrl(){return url_1.URLExt.normalize(url_1.URLExt.join(getShareUrl(),getOption("treeUrl")))}PageConfig.getTreeShareUrl=getTreeShareUrl;function getUrl(r){var e,t,n;let s=r.toShare?getShareUrl():getBaseUrl(),i=(e=r.mode)!==null&&e!==void 0?e:getOption("mode"),o=(t=r.workspace)!==null&&t!==void 0?t:getOption("workspace"),a=i==="single-document"?"doc":"lab";s=url_1.URLExt.join(s,a),o!==PageConfig.defaultWorkspace&&(s=url_1.URLExt.join(s,"workspaces",encodeURIComponent(o)));let h=(n=r.treePath)!==null&&n!==void 0?n:getOption("treePath");return h&&(s=url_1.URLExt.join(s,"tree",url_1.URLExt.encodeParts(h))),s}PageConfig.getUrl=getUrl,PageConfig.defaultWorkspace="default";function getWsUrl(r){let e=getOption("wsUrl");if(!e){if(r=r?url_1.URLExt.normalize(r):getBaseUrl(),r.indexOf("http")!==0)return"";e="ws"+r.slice(4)}return url_1.URLExt.normalize(e)}PageConfig.getWsUrl=getWsUrl;function getNBConvertURL({path:r,format:e,download:t}){let n=url_1.URLExt.encodeParts(r),s=url_1.URLExt.join(getBaseUrl(),"nbconvert",e,n);return t?s+"?download=true":s}PageConfig.getNBConvertURL=getNBConvertURL;function getToken(){return getOption("token")||getBodyData("jupyterApiToken")}PageConfig.getToken=getToken;function getNotebookVersion(){let r=getOption("notebookVersion");return r===""?[0,0,0]:JSON.parse(r)}PageConfig.getNotebookVersion=getNotebookVersion;let configData=null;function getBodyData(r){if(typeof document=="undefined"||!document.body)return"";let e=document.body.dataset[r];return typeof e=="undefined"?"":decodeURIComponent(e)}let Extension;(function(r){function e(s){try{let i=getOption(s);if(i)return JSON.parse(i)}catch(i){console.warn(`Unable to parse ${s}.`,i)}return[]}r.deferred=e("deferredExtensions"),r.disabled=e("disabledExtensions");function t(s){let i=s.indexOf(":"),o="";return i!==-1&&(o=s.slice(0,i)),r.deferred.some(a=>a===s||o&&a===o)}r.isDeferred=t;function n(s){let i=s.indexOf(":"),o="";return i!==-1&&(o=s.slice(0,i)),r.disabled.some(a=>a===s||o&&a===o)}r.isDisabled=n})(Extension=PageConfig.Extension||(PageConfig.Extension={}))})(PageConfig||(exports.PageConfig=PageConfig={}));function compareVersions(r,e){for(let t=0;t<3;t++)if(r[t]!==e[t])return r[t]-e[t];return 0}});var Wr=O(Jt=>{"use strict";Object.defineProperty(Jt,"__esModule",{value:!0});Jt.PathExt=void 0;var Le=$t(),$r;(function(r){function e(...l){let d=Le.posix.join(...l);return d==="."?"":u(d)}r.join=e;function t(...l){let d=Le.posix.join(...l);return d==="."?"":d}r.joinWithLeadingSlash=t;function n(l,d){return Le.posix.basename(l,d)}r.basename=n;function s(l){let d=u(Le.posix.dirname(l));return d==="."?"":d}r.dirname=s;function i(l){return Le.posix.extname(l)}r.extname=i;function o(l){return l===""?"":u(Le.posix.normalize(l))}r.normalize=o;function a(...l){return u(Le.posix.resolve(...l))}r.resolve=a;function h(l,d){return u(Le.posix.relative(l,d))}r.relative=h;function c(l){return l.length>0&&l.indexOf(".")!==0&&(l=`.${l}`),l}r.normalizeExtension=c;function u(l){return l.indexOf("/")===0&&(l=l.slice(1)),l}r.removeSlash=u})($r||(Jt.PathExt=$r={}))});var Hr=O(ns=>{"use strict";Object.defineProperty(ns,"__esModule",{value:!0});ns.signalToPromise=Ua;var ja=X();function Ua(r,e){let t=new ja.PromiseDelegate;function n(){r.disconnect(s)}function s(i,o){n(),t.resolve([i,o])}return r.connect(s),(e!=null?e:0)>0&&setTimeout(()=>{n(),t.reject(`Signal not emitted within ${e} ms.`)},e),t.promise}});var Gr=O(Gt=>{"use strict";Object.defineProperty(Gt,"__esModule",{value:!0});Gt.Text=void 0;var Jr;(function(r){let e=2>1;function t(o,a){if(!e)return o;let h=o;for(let c=0;c+1<a.length&&c<o;c++){let u=a.charCodeAt(c);if(u>=55296&&u<=56319){let l=a.charCodeAt(c+1);l>=56320&&l<=57343&&(h--,c++)}}return h}r.jsIndexToCharIndex=t;function n(o,a){if(!e)return o;let h=o;for(let c=0;c+1<a.length&&c<h;c++){let u=a.charCodeAt(c);if(u>=55296&&u<=56319){let l=a.charCodeAt(c+1);l>=56320&&l<=57343&&(h++,c++)}}return h}r.charIndexToJsIndex=n;function s(o,a=!1){return o.replace(/^(\w)|[\s-_:]+(\w)/g,function(h,c,u){return u?u.toUpperCase():a?c.toUpperCase():c.toLowerCase()})}r.camelCase=s;function i(o){return(o||"").toLowerCase().split(" ").map(a=>a.charAt(0).toUpperCase()+a.slice(1)).join(" ")}r.titleCase=i})(Jr||(Gt.Text=Jr={}))});var Yr=O(Xt=>{"use strict";Object.defineProperty(Xt,"__esModule",{value:!0});Xt.Time=void 0;var Aa=[{name:"years",milliseconds:365*24*60*60*1e3},{name:"months",milliseconds:30*24*60*60*1e3},{name:"days",milliseconds:24*60*60*1e3},{name:"hours",milliseconds:60*60*1e3},{name:"minutes",milliseconds:60*1e3},{name:"seconds",milliseconds:1e3}],Xr;(function(r){function e(n,s="long"){let i=document.documentElement.lang||"en",o=new Intl.RelativeTimeFormat(i,{numeric:"auto",style:s}),a=new Date(n).getTime()-Date.now();for(let h of Aa){let c=Math.ceil(a/h.milliseconds);if(c!==0)return o.format(c,h.name)}return o.format(0,"seconds")}r.formatHuman=e;function t(n){let s=document.documentElement.lang||"en";return new Intl.DateTimeFormat(s,{dateStyle:"short",timeStyle:"short"}).format(new Date(n))}r.format=t})(Xr||(Xt.Time=Xr={}))});var Qr=O(Yt=>{"use strict";Object.defineProperty(Yt,"__esModule",{value:!0});Yt.JupyterPluginRegistry=void 0;var Na=X(),La=5e3,ss=class extends Na.PluginRegistry{constructor(e){var t;super(e),this._pluginData=new Map,this._expectedActivationTime=(t=e==null?void 0:e.expectedActivationTime)!==null&&t!==void 0?t:La}registerPlugin(e){return this._pluginData.set(e.id,e),super.registerPlugin(e)}async activatePlugin(e){let t=performance.now(),n=setTimeout(()=>{console.warn(`Plugin ${e} is taking too long to activate.`)},this._expectedActivationTime);try{let s=await super.activatePlugin(e);clearTimeout(n);let o=performance.now()-t;if(o>=this._expectedActivationTime){let a=this._getDependentCount(e);console.warn(`Plugin ${e} (with ${a} dependants) took ${o.toFixed(2)}ms to activate.`)}return s}catch(s){throw clearTimeout(n),console.error(`Error activating plugin: ${e}`,s),s}}_getDependentCount(e){var t;let n=this._pluginData.get(e);if(!(n!=null&&n.provides))return 0;let s=n.provides.name,i=0;for(let[o,a]of this._pluginData.entries()){if(o===e)continue;((t=a.requires)===null||t===void 0?void 0:t.filter(c=>!!c).some(c=>c.name===s))&&i++}return i}};Yt.JupyterPluginRegistry=ss});var te=O(re=>{"use strict";var xa=re&&re.__createBinding||(Object.create?function(r,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,n,s)}:function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]}),Me=re&&re.__exportStar||function(r,e){for(var t in r)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&xa(e,r,t)};Object.defineProperty(re,"__esModule",{value:!0});Me(vr(),re);Me(wr(),re);Me(Sr(),re);Me(Cr(),re);Me(Br(),re);Me(Wr(),re);Me(Hr(),re);Me(Gr(),re);Me(Yr(),re);Me(ts(),re);Me(Qr(),re)});var et=O(V=>{"use strict";Object.defineProperty(V,"__esModule",{value:!0});V.supportedKernelWebSocketProtocols=void 0;V.createMessage=Ka;V.isStreamMsg=za;V.isDisplayDataMsg=Va;V.isUpdateDisplayDataMsg=Ba;V.isExecuteInputMsg=$a;V.isExecuteResultMsg=Wa;V.isErrorMsg=Ha;V.isStatusMsg=Ja;V.isClearOutputMsg=Ga;V.isDebugEventMsg=Xa;V.isCommOpenMsg=Ya;V.isCommCloseMsg=Qa;V.isCommMsgMsg=Za;V.isInfoRequestMsg=el;V.isExecuteReplyMsg=tl;V.isDebugRequestMsg=nl;V.isDebugReplyMsg=sl;V.isInputRequestMsg=rl;V.isInputReplyMsg=il;var Fa=X();function Ka(r){var e,t,n,s,i,o;return{buffers:(e=r.buffers)!==null&&e!==void 0?e:[],channel:r.channel,content:r.content,header:{date:new Date().toISOString(),msg_id:(t=r.msgId)!==null&&t!==void 0?t:Fa.UUID.uuid4(),msg_type:r.msgType,session:r.session,username:(n=r.username)!==null&&n!==void 0?n:"",subshell_id:(s=r.subshellId)!==null&&s!==void 0?s:null,version:"5.2"},metadata:(i=r.metadata)!==null&&i!==void 0?i:{},parent_header:(o=r.parentHeader)!==null&&o!==void 0?o:{}}}function za(r){return r.header.msg_type==="stream"}function Va(r){return r.header.msg_type==="display_data"}function Ba(r){return r.header.msg_type==="update_display_data"}function $a(r){return r.header.msg_type==="execute_input"}function Wa(r){return r.header.msg_type==="execute_result"}function Ha(r){return r.header.msg_type==="error"}function Ja(r){return r.header.msg_type==="status"}function Ga(r){return r.header.msg_type==="clear_output"}function Xa(r){return r.header.msg_type==="debug_event"}function Ya(r){return r.header.msg_type==="comm_open"}function Qa(r){return r.header.msg_type==="comm_close"}function Za(r){return r.header.msg_type==="comm_msg"}function el(r){return r.header.msg_type==="kernel_info_request"}function tl(r){return r.header.msg_type==="execute_reply"}function nl(r){return r.header.msg_type==="debug_request"}function sl(r){return r.header.msg_type==="debug_reply"}function rl(r){return r.header.msg_type==="input_request"}function il(r){return r.header.msg_type==="input_reply"}var Zr;(function(r){r.v1KernelWebsocketJupyterOrg="v1.kernel.websocket.jupyter.org"})(Zr||(V.supportedKernelWebSocketProtocols=Zr={}))});var ti=O(De=>{"use strict";var ol=De&&De.__createBinding||(Object.create?function(r,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,n,s)}:function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]}),al=De&&De.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),ll=De&&De.__importStar||function(){var r=function(e){return r=Object.getOwnPropertyNames||function(t){var n=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[n.length]=s);return n},r(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n=r(e),s=0;s<n.length;s++)n[s]!=="default"&&ol(t,e,n[s]);return al(t,e),t}}();Object.defineProperty(De,"__esModule",{value:!0});De.serialize=cl;De.deserialize=ul;var ei=ll(et());function cl(r,e=""){switch(e){case ei.supportedKernelWebSocketProtocols.v1KernelWebsocketJupyterOrg:return tt.serializeV1KernelWebsocketJupyterOrg(r);default:return tt.serializeDefault(r)}}function ul(r,e=""){switch(e){case ei.supportedKernelWebSocketProtocols.v1KernelWebsocketJupyterOrg:return tt.deserializeV1KernelWebsocketJupyterOrg(r);default:return tt.deserializeDefault(r)}}var tt;(function(r){function e(a){let h,c=new DataView(a),u=Number(c.getBigUint64(0,!0)),l=[];for(let C=0;C<u;C++)l.push(Number(c.getBigUint64(8*(C+1),!0)));let d=new TextDecoder("utf8"),m=d.decode(a.slice(l[0],l[1])),v=JSON.parse(d.decode(a.slice(l[1],l[2]))),T=JSON.parse(d.decode(a.slice(l[2],l[3]))),E=JSON.parse(d.decode(a.slice(l[3],l[4]))),q=JSON.parse(d.decode(a.slice(l[4],l[5]))),A=[];for(let C=5;C<l.length-1;C++)A.push(new DataView(a.slice(l[C],l[C+1])));return h={channel:m,header:v,parent_header:T,metadata:E,content:q,buffers:A},h}r.deserializeV1KernelWebsocketJupyterOrg=e;function t(a){let h=JSON.stringify(a.header),c=a.parent_header==null?"{}":JSON.stringify(a.parent_header),u=JSON.stringify(a.metadata),l=JSON.stringify(a.content),d=a.buffers!==void 0?a.buffers:[],m=5+d.length+1,v=[];v.push(8*(1+m)),v.push(a.channel.length+v[v.length-1]);let T=new TextEncoder,E=T.encode(a.channel),q=T.encode(h),A=T.encode(c),C=T.encode(u),w=T.encode(l),k=new Uint8Array(E.length+q.length+A.length+C.length+w.length);k.set(E),k.set(q,E.length),k.set(A,E.length+q.length),k.set(C,E.length+q.length+A.length),k.set(w,E.length+q.length+A.length+C.length);for(let f of[q.length,A.length,C.length,w.length])v.push(f+v[v.length-1]);let N=0;for(let f of d){let y=f.byteLength;v.push(y+v[v.length-1]),N+=y}let j=new Uint8Array(8*(1+m)+k.byteLength+N),R=new ArrayBuffer(8),U=new DataView(R);U.setBigUint64(0,BigInt(m),!0),j.set(new Uint8Array(R),0);for(let f=0;f<v.length;f++)U.setBigUint64(0,BigInt(v[f]),!0),j.set(new Uint8Array(R),8*(f+1));j.set(k,v[0]);for(let f=0;f<d.length;f++){let y=d[f];j.set(new Uint8Array(ArrayBuffer.isView(y)?y.buffer:y),v[5+f])}return j.buffer}r.serializeV1KernelWebsocketJupyterOrg=t;function n(a){let h;return typeof a=="string"?h=JSON.parse(a):h=i(a),h}r.deserializeDefault=n;function s(a){var h;let c;return!((h=a.buffers)===null||h===void 0)&&h.length?c=o(a):c=JSON.stringify(a),c}r.serializeDefault=s;function i(a){let h=new DataView(a),c=h.getUint32(0),u=[];if(c<2)throw new Error("Invalid incoming Kernel Message");for(let m=1;m<=c;m++)u.push(h.getUint32(m*4));let l=new Uint8Array(a.slice(u[0],u[1])),d=JSON.parse(new TextDecoder("utf8").decode(l));d.buffers=[];for(let m=1;m<c;m++){let v=u[m],T=u[m+1]||a.byteLength;d.buffers.push(new DataView(a.slice(v,T)))}return d}function o(a){let h=[],c=[],u=new TextEncoder,l=[];a.buffers!==void 0&&(l=a.buffers,delete a.buffers);let d=u.encode(JSON.stringify(a));c.push(d.buffer);for(let E=0;E<l.length;E++){let q=l[E];c.push(ArrayBuffer.isView(q)?q.buffer:q)}let m=c.length;h.push(4*(m+1));for(let E=0;E+1<c.length;E++)h.push(h[h.length-1]+c[E].byteLength);let v=new Uint8Array(h[h.length-1]+c[c.length-1].byteLength),T=new DataView(v.buffer);T.setUint32(0,m);for(let E=0;E<h.length;E++)T.setUint32(4*(E+1),h[E]);for(let E=0;E<c.length;E++)v.set(new Uint8Array(c[E]),h[E]);return v.buffer}})(tt||(tt={}))});var ni=O(rs=>{"use strict";Object.defineProperty(rs,"__esModule",{value:!0});rs.default=WebSocket});var he=O(Zt=>{"use strict";Object.defineProperty(Zt,"__esModule",{value:!0});Zt.ServerConnection=void 0;var xe=te(),si=ti(),is;typeof window=="undefined"?is=ni():is=WebSocket;var os;(function(r){function e(i){return Qt.makeSettings(i)}r.makeSettings=e;function t(i,o,a){return Qt.handleRequest(i,o,a)}r.makeRequest=t;class n extends Error{static async create(o){try{let a=await o.json(),{message:h,traceback:c}=a;return c&&console.error(c),new n(o,h!=null?h:n._defaultMessage(o),c!=null?c:"")}catch(a){return console.debug(a),new n(o)}}constructor(o,a=n._defaultMessage(o),h=""){super(a),this.response=o,this.traceback=h}static _defaultMessage(o){return`Invalid response: ${o.status} ${o.statusText}`}}r.ResponseError=n;class s extends TypeError{constructor(o){super(o.message),this.stack=o.stack}}r.NetworkError=s})(os||(Zt.ServerConnection=os={}));var Qt;(function(r){function e(s={}){var i;let o=xe.PageConfig.getBaseUrl(),a=xe.PageConfig.getWsUrl(),h=xe.URLExt.normalize(s.baseUrl)||o,c=s.wsUrl;!c&&h===o&&(c=a),!c&&h.indexOf("http")===0&&(c="ws"+h.slice(4)),c=c!=null?c:a;let u=xe.PageConfig.getOption("appendToken").toLowerCase(),l;return u===""?l=typeof window=="undefined"||typeof process!="undefined"&&((i=process==null?void 0:process.env)===null||i===void 0?void 0:i.JEST_WORKER_ID)!==void 0||xe.URLExt.getHostName(o)!==xe.URLExt.getHostName(c):l=u==="true",{init:{cache:"no-store",credentials:"same-origin"},fetch,Headers,Request,WebSocket:is,token:xe.PageConfig.getToken(),appUrl:xe.PageConfig.getOption("appUrl"),appendToken:l,serializer:{serialize:si.serialize,deserialize:si.deserialize},...s,baseUrl:h,wsUrl:c}}r.makeSettings=e;function t(s,i,o){var a;if(s.indexOf(o.baseUrl)!==0)throw new Error("Can only be used for notebook server requests");((a=i.cache)!==null&&a!==void 0?a:o.init.cache)==="no-store"&&(s+=(/\?/.test(s)?"&":"?")+new Date().getTime());let c=new o.Request(s,{...o.init,...i}),u=!1;if(o.token&&(u=!0,c.headers.append("Authorization",`token ${o.token}`)),typeof document!="undefined"){let l=n("_xsrf");l!==void 0&&(u=!0,c.headers.append("X-XSRFToken",l))}return!c.headers.has("Content-Type")&&u&&c.headers.set("Content-Type","application/json"),o.fetch.call(null,c).catch(l=>{throw new os.NetworkError(l)})}r.handleRequest=t;function n(s){let i="";try{i=document.cookie}catch{return}let o=s+"=",a;for(let h of i.split(";")){let c=h.trim();c.startsWith(o)&&(a=c.substring(o.length))}return a}})(Qt||(Qt={}))});var Je=O(en=>{"use strict";Object.defineProperty(en,"__esModule",{value:!0});en.BaseManager=void 0;var ri=ee(),hl=he(),as=class{constructor(e){var t;this._isDisposed=!1,this._disposed=new ri.Signal(this),this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:hl.ServerConnection.makeSettings()}get disposed(){return this._disposed}get isDisposed(){return this._isDisposed}get isActive(){return!0}dispose(){this.isDisposed||(this._isDisposed=!0,this._disposed.emit(void 0),ri.Signal.clearData(this))}};en.BaseManager=as});var oi=O(Fe=>{"use strict";Object.defineProperty(Fe,"__esModule",{value:!0});Fe.ConfigWithDefaults=Fe.ConfigSection=Fe.ConfigSectionManager=void 0;var dl=te(),nt=Ae(),fl="api/config",ls=class{constructor(e){var t;this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:nt.ServerConnection.makeSettings()}async create(e){let t=new tn({...e,serverSettings:this.serverSettings});return await t.load(),t}};Fe.ConfigSectionManager=ls;var ii;(function(r){async function e(s){if(!t){let o=new tn(s);return await o.load(),o}return await t.create(s)}r.create=e;let t;function n(s){if(t)throw new Error("ConfigSectionManager already set. If you would like to create a config section, use the `IConfigSectionManager` token in a plugin.");t=s}r._setConfigSectionManager=n})(ii||(Fe.ConfigSection=ii={}));var tn=class{constructor(e){var t;this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:nt.ServerConnection.makeSettings(),this._name=e.name}get data(){return this._data}async load(){let e=await nt.ServerConnection.makeRequest(this._url,{},this.serverSettings);if(e.status!==200)throw await nt.ServerConnection.ResponseError.create(e);this._data=await e.json()}async update(e){this._data={...this._data,...e};let t={method:"PATCH",body:JSON.stringify(e)},n=await nt.ServerConnection.makeRequest(this._url,t,this.serverSettings);if(n.status!==200)throw await nt.ServerConnection.ResponseError.create(n);return this._data=await n.json(),this._data}get _url(){return dl.URLExt.join(this.serverSettings.baseUrl,fl,encodeURIComponent(this._name))}},cs=class{constructor(e){var t,n;this._className="",this._section=e.section,this._defaults=(t=e.defaults)!==null&&t!==void 0?t:{},this._className=(n=e.className)!==null&&n!==void 0?n:""}get(e){let t=this._classData();return e in t?t[e]:this._defaults[e]}set(e,t){let n={};if(n[e]=t,this._className){let s={};return s[this._className]=n,this._section.update(s)}else return this._section.update(n)}_classData(){let e=this._section.data;return this._className&&this._className in e?e[this._className]:e}};Fe.ConfigWithDefaults=cs});var ai=O(nn=>{"use strict";Object.defineProperty(nn,"__esModule",{value:!0});nn.ConnectionStatus=void 0;var us=class{constructor(){this.isConnected=!0}};nn.ConnectionStatus=us});var rn=O((sn,li)=>{(function(r,e){typeof sn=="object"&&typeof li!="undefined"?e(sn,ee()):typeof define=="function"&&define.amd?define(["exports","@lumino/signaling"],e):(r=typeof globalThis!="undefined"?globalThis:r||self,e(r.lumino_disposable={},r.lumino_signaling))})(sn,function(r,e){"use strict";class t{constructor(a){this._fn=a}get isDisposed(){return!this._fn}dispose(){if(!this._fn)return;let a=this._fn;this._fn=null,a()}}class n extends t{constructor(){super(...arguments),this._disposed=new e.Signal(this)}get disposed(){return this._disposed}dispose(){this.isDisposed||(super.dispose(),this._disposed.emit(void 0),e.Signal.clearData(this))}}class s{constructor(){this._isDisposed=!1,this._items=new Set}get isDisposed(){return this._isDisposed}dispose(){this._isDisposed||(this._isDisposed=!0,this._items.forEach(a=>{a.dispose()}),this._items.clear())}contains(a){return this._items.has(a)}add(a){this._items.add(a)}remove(a){this._items.delete(a)}clear(){this._items.clear()}}(function(o){function a(h){let c=new o;for(let u of h)c.add(u);return c}o.from=a})(s||(s={}));class i extends s{constructor(){super(...arguments),this._disposed=new e.Signal(this)}get disposed(){return this._disposed}dispose(){this.isDisposed||(super.dispose(),this._disposed.emit(void 0),e.Signal.clearData(this))}}(function(o){function a(h){let c=new o;for(let u of h)c.add(u);return c}o.from=a})(i||(i={})),r.DisposableDelegate=t,r.DisposableSet=s,r.ObservableDisposableDelegate=n,r.ObservableDisposableSet=i})});var lt=O(hs=>{"use strict";Object.defineProperty(hs,"__esModule",{value:!0});hs.validateProperty=_l;function _l(r,e,t,n=[]){if(!r.hasOwnProperty(e))throw Error(`Missing property '${e}'`);let s=r[e];if(t!==void 0){let i;switch(t){case"array":i=Array.isArray(s);break;case"object":i=typeof s!="undefined";break;default:i=typeof s===t}if(!i)throw new Error(`Property '${e}' is not of type '${t}'`);if(n.length>0){let o;switch(t){case"string":case"number":case"boolean":o=n.includes(s);break;default:o=n.findIndex(a=>a===s)>=0;break}if(!o)throw new Error(`Property '${e}' is not one of the valid values ${JSON.stringify(n)}`)}}}});var ci=O(on=>{"use strict";Object.defineProperty(on,"__esModule",{value:!0});on.validateContentsModel=gl;on.validateCheckpointModel=pl;var Te=lt();function gl(r){(0,Te.validateProperty)(r,"name","string"),(0,Te.validateProperty)(r,"path","string"),(0,Te.validateProperty)(r,"type","string"),(0,Te.validateProperty)(r,"created","string"),(0,Te.validateProperty)(r,"last_modified","string"),(0,Te.validateProperty)(r,"mimetype","object"),(0,Te.validateProperty)(r,"content","object"),(0,Te.validateProperty)(r,"format","object")}function pl(r){(0,Te.validateProperty)(r,"id","string"),(0,Te.validateProperty)(r,"last_modified","string")}});var _s=O(ne=>{"use strict";var ml=ne&&ne.__createBinding||(Object.create?function(r,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,n,s)}:function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]}),vl=ne&&ne.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),yl=ne&&ne.__importStar||function(){var r=function(e){return r=Object.getOwnPropertyNames||function(t){var n=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[n.length]=s);return n},r(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n=r(e),s=0;s<n.length;s++)n[s]!=="default"&&ml(t,e,n[s]);return vl(t,e),t}}();Object.defineProperty(ne,"__esModule",{value:!0});ne.RestContentProvider=ne.ContentProviderRegistry=ne.Drive=ne.ContentsManager=ne.Contents=void 0;var de=te(),wl=X(),Sl=rn(),ct=ee(),$=Ae(),Ne=yl(ci()),bl="api/contents",Cl="files",ui;(function(r){function e(n){Ne.validateContentsModel(n)}r.validateContentsModel=e;function t(n){Ne.validateCheckpointModel(n)}r.validateCheckpointModel=t})(ui||(ne.Contents=ui={}));var ds=class{constructor(e={}){var t,n;this._isDisposed=!1,this._additionalDrives=new Map,this._fileChanged=new ct.Signal(this);let s=this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:$.ServerConnection.makeSettings();this._defaultDrive=(n=e.defaultDrive)!==null&&n!==void 0?n:new an({serverSettings:s}),this._defaultDrive.fileChanged.connect(this._onFileChanged,this)}get defaultDrive(){return this._defaultDrive}get fileChanged(){return this._fileChanged}get isDisposed(){return this._isDisposed}dispose(){this.isDisposed||(this._isDisposed=!0,ct.Signal.clearData(this))}addDrive(e){this._additionalDrives.set(e.name,e),e.fileChanged.connect(this._onFileChanged,this)}getSharedModelFactory(e,t){var n,s;let[i]=this._driveForPath(e),o=(n=i.contentProviderRegistry)===null||n===void 0?void 0:n.getProvider(t==null?void 0:t.contentProviderId);return o!=null&&o.sharedModelFactory?o.sharedModelFactory:(s=i.sharedModelFactory)!==null&&s!==void 0?s:null}localPath(e){let t=e.split("/"),n=t[0].split(":");return n.length===1||!this._additionalDrives.has(n[0])?de.PathExt.removeSlash(e):de.PathExt.join(n.slice(1).join(":"),...t.slice(1))}normalize(e){let t=e.split(":");return t.length===1?de.PathExt.normalize(e):`${t[0]}:${de.PathExt.normalize(t.slice(1).join(":"))}`}resolvePath(e,t){let n=this.driveName(e),s=this.localPath(e),i=de.PathExt.resolve("/",s,t);return n?`${n}:${i}`:i}driveName(e){let n=e.split("/")[0].split(":");return n.length===1?"":this._additionalDrives.has(n[0])?n[0]:""}get(e,t){let[n,s]=this._driveForPath(e);return n.get(s,t).then(i=>{let o=[];if(i.type==="directory"&&i.content){for(let a of i.content)o.push({...a,path:this._toGlobalPath(n,a.path)});return{...i,path:this._toGlobalPath(n,s),content:o,serverPath:i.path}}else return{...i,path:this._toGlobalPath(n,s),serverPath:i.path}})}getDownloadUrl(e){let[t,n]=this._driveForPath(e);return t.getDownloadUrl(n)}newUntitled(e={}){if(e.path){let t=this.normalize(e.path),[n,s]=this._driveForPath(t);return n.newUntitled({...e,path:s}).then(i=>({...i,path:de.PathExt.join(t,i.name),serverPath:i.path}))}else return this._defaultDrive.newUntitled(e)}delete(e){let[t,n]=this._driveForPath(e);return t.delete(n)}rename(e,t){let[n,s]=this._driveForPath(e),[i,o]=this._driveForPath(t);if(n!==i)throw Error("ContentsManager: renaming files must occur within a Drive");return n.rename(s,o).then(a=>({...a,path:this._toGlobalPath(n,o),serverPath:a.path}))}async overwrite(e,t){let n=`${t}.${wl.UUID.uuid4()}`;await this.rename(e,n);try{await this.delete(t)}finally{}return await this.rename(n,t)}save(e,t={}){let n=this.normalize(e),[s,i]=this._driveForPath(e);return s.save(i,{...t,path:i}).then(o=>({...o,path:n,serverPath:o.path}))}copy(e,t){let[n,s]=this._driveForPath(e),[i,o]=this._driveForPath(t);if(n===i)return n.copy(s,o).then(a=>({...a,path:this._toGlobalPath(n,a.path),serverPath:a.path}));throw Error("Copying files between drives is not currently implemented")}createCheckpoint(e){let[t,n]=this._driveForPath(e);return t.createCheckpoint(n)}listCheckpoints(e){let[t,n]=this._driveForPath(e);return t.listCheckpoints(n)}restoreCheckpoint(e,t){let[n,s]=this._driveForPath(e);return n.restoreCheckpoint(s,t)}deleteCheckpoint(e,t){let[n,s]=this._driveForPath(e);return n.deleteCheckpoint(s,t)}_toGlobalPath(e,t){return e===this._defaultDrive?de.PathExt.removeSlash(t):`${e.name}:${de.PathExt.removeSlash(t)}`}_driveForPath(e){let t=this.driveName(e),n=this.localPath(e);return t?[this._additionalDrives.get(t),n]:[this._defaultDrive,n]}_onFileChanged(e,t){var n,s;if(e===this._defaultDrive)this._fileChanged.emit(t);else{let i=null,o=null;!((n=t.newValue)===null||n===void 0)&&n.path&&(i={...t.newValue,path:this._toGlobalPath(e,t.newValue.path)}),!((s=t.oldValue)===null||s===void 0)&&s.path&&(o={...t.oldValue,path:this._toGlobalPath(e,t.oldValue.path)}),this._fileChanged.emit({type:t.type,newValue:i,oldValue:o})}}};ne.ContentsManager=ds;var an=class{constructor(e={}){var t,n,s;this._isDisposed=!1,this._fileChanged=new ct.Signal(this),this.name=(t=e.name)!==null&&t!==void 0?t:"Default",this._apiEndpoint=(n=e.apiEndpoint)!==null&&n!==void 0?n:bl,this.serverSettings=(s=e.serverSettings)!==null&&s!==void 0?s:$.ServerConnection.makeSettings(),this._restContentProvider=new ln({...e,apiEndpoint:this._apiEndpoint,serverSettings:this.serverSettings}),e.defaultContentProvider?this.contentProviderRegistry=new ut({defaultProvider:e.defaultContentProvider}):this.contentProviderRegistry=new ut,this.contentProviderRegistry.fileChanged.connect((i,o)=>{this._fileChanged.emit(o)})}get fileChanged(){return this._fileChanged}get isDisposed(){return this._isDisposed}dispose(){this.isDisposed||(this._isDisposed=!0,ct.Signal.clearData(this))}async get(e,t){let n=this.contentProviderRegistry.getProvider(t==null?void 0:t.contentProviderId);return n?n.get(e,t):await this._restContentProvider.get(e,t)}getDownloadUrl(e){let t=this.serverSettings.baseUrl,n=de.URLExt.join(t,Cl,de.URLExt.encodeParts(e)),s="";try{s=document.cookie}catch{}let i=s.match("\\b_xsrf=([^;]*)\\b");if(i){let o=new URL(n);o.searchParams.append("_xsrf",i[1]),n=o.toString()}return Promise.resolve(n)}async newUntitled(e={}){var t;let n="{}";e&&(e.ext&&(e.ext=fs.normalizeExtension(e.ext)),n=JSON.stringify(e));let s=this.serverSettings,i=this._getUrl((t=e.path)!==null&&t!==void 0?t:""),o={method:"POST",body:n},a=await $.ServerConnection.makeRequest(i,o,s);if(a.status!==201)throw await $.ServerConnection.ResponseError.create(a);let h=await a.json();return Ne.validateContentsModel(h),this._fileChanged.emit({type:"new",oldValue:null,newValue:h}),h}async delete(e){let t=this._getUrl(e),n=this.serverSettings,s={method:"DELETE"},i=await $.ServerConnection.makeRequest(t,s,n);if(i.status!==204)throw await $.ServerConnection.ResponseError.create(i);this._fileChanged.emit({type:"delete",oldValue:{path:e},newValue:null})}async rename(e,t){let n=this.serverSettings,s=this._getUrl(e),i={method:"PATCH",body:JSON.stringify({path:t})},o=await $.ServerConnection.makeRequest(s,i,n);if(o.status!==200)throw await $.ServerConnection.ResponseError.create(o);let a=await o.json();return Ne.validateContentsModel(a),this._fileChanged.emit({type:"rename",oldValue:{path:e},newValue:a}),a}async save(e,t={}){let n=this.contentProviderRegistry.getProvider(t==null?void 0:t.contentProviderId),s;return n?s=await n.save(e,t):s=await this._restContentProvider.save(e,t),this._fileChanged.emit({type:"save",oldValue:null,newValue:s}),s}async copy(e,t){let n=this.serverSettings,s=this._getUrl(t),i={method:"POST",body:JSON.stringify({copy_from:e})},o=await $.ServerConnection.makeRequest(s,i,n);if(o.status!==201)throw await $.ServerConnection.ResponseError.create(o);let a=await o.json();return Ne.validateContentsModel(a),this._fileChanged.emit({type:"new",oldValue:null,newValue:a}),a}async createCheckpoint(e){let t=this._getUrl(e,"checkpoints"),n={method:"POST"},s=await $.ServerConnection.makeRequest(t,n,this.serverSettings);if(s.status!==201)throw await $.ServerConnection.ResponseError.create(s);let i=await s.json();return Ne.validateCheckpointModel(i),i}async listCheckpoints(e){let t=this._getUrl(e,"checkpoints"),n=await $.ServerConnection.makeRequest(t,{},this.serverSettings);if(n.status!==200)throw await $.ServerConnection.ResponseError.create(n);let s=await n.json();if(!Array.isArray(s))throw new Error("Invalid Checkpoint list");for(let i=0;i<s.length;i++)Ne.validateCheckpointModel(s[i]);return s}async restoreCheckpoint(e,t){let n=this._getUrl(e,"checkpoints",t),s={method:"POST"},i=await $.ServerConnection.makeRequest(n,s,this.serverSettings);if(i.status!==204)throw await $.ServerConnection.ResponseError.create(i)}async deleteCheckpoint(e,t){let n=this._getUrl(e,"checkpoints",t),s={method:"DELETE"},i=await $.ServerConnection.makeRequest(n,s,this.serverSettings);if(i.status!==204)throw await $.ServerConnection.ResponseError.create(i)}_getUrl(...e){let t=e.map(s=>de.URLExt.encodeParts(s)),n=this.serverSettings.baseUrl;return de.URLExt.join(n,this._apiEndpoint,...t)}};ne.Drive=an;var fs;(function(r){function e(t){return t.length>0&&t.indexOf(".")!==0&&(t=`.${t}`),t}r.normalizeExtension=e})(fs||(fs={}));var ut=class{constructor(e){this._providers=new Map,this._fileChanged=new ct.Signal(this),e!=null&&e.defaultProvider&&this.register("default",e.defaultProvider)}register(e,t){if(this._providers.has(e))throw Error(`Provider with ${e} identifier was already registered on this drive`);this._providers.set(e,t);let n=(s,i)=>{this._fileChanged.emit(i)};return t.fileChanged&&t.fileChanged.connect(n),new Sl.DisposableDelegate(()=>{t.fileChanged&&t.fileChanged.disconnect(n),this._providers.has(e)&&this._providers.delete(e)})}getProvider(e){if(!e)return null;let t=this._providers.get(e);if(!t)throw Error(`Provider ${e} is not registered`);return t}get fileChanged(){return this._fileChanged}};ne.ContentProviderRegistry=ut;var ln=class{constructor(e){this._options=e}async get(e,t){let n=this._getUrl(e);if(t){t.type==="notebook"&&delete t.format;let a=t.content?"1":"0",h=t.hash?"1":"0",c={...t,content:a,hash:h};n+=de.URLExt.objectToQueryString(c)}let s=this._options.serverSettings,i=await $.ServerConnection.makeRequest(n,{},s);if(i.status!==200)throw await $.ServerConnection.ResponseError.create(i);let o=await i.json();return Ne.validateContentsModel(o),o}async save(e,t={}){let n=this._options.serverSettings,s=this._getUrl(e),o={method:"PUT",body:new File([JSON.stringify(t)],"data.json",{type:"application/json"})},a=await $.ServerConnection.makeRequest(s,o,n);if(a.status!==200&&a.status!==201)throw await $.ServerConnection.ResponseError.create(a);let h=await a.json();return Ne.validateContentsModel(h),h}_getUrl(...e){let t=e.map(s=>de.URLExt.encodeParts(s)),n=this._options.serverSettings.baseUrl;return de.URLExt.join(n,this._options.apiEndpoint,...t)}};ne.RestContentProvider=ln});var Ge=O((cn,hi)=>{(function(r,e){typeof cn=="object"&&typeof hi!="undefined"?e(cn,X(),ee()):typeof define=="function"&&define.amd?define(["exports","@lumino/coreutils","@lumino/signaling"],e):(r=typeof globalThis!="undefined"?globalThis:r||self,e(r.lumino_polling={},r.lumino_coreutils,r.lumino_signaling))})(cn,function(r,e,t){"use strict";class n{constructor(c){var u;this._disposed=new t.Signal(this),this._lingered=0,this._tick=new e.PromiseDelegate,this._ticked=new t.Signal(this),this._factory=c.factory,this._linger=(u=c.linger)!==null&&u!==void 0?u:s.DEFAULT_LINGER,this._standby=c.standby||s.DEFAULT_STANDBY,this._state={...s.DEFAULT_STATE,timestamp:new Date().getTime()};let l=c.frequency||{},d=Math.max(l.interval||0,l.max||0,s.DEFAULT_FREQUENCY.max);this.frequency={...s.DEFAULT_FREQUENCY,...l,max:d},this.name=c.name||s.DEFAULT_NAME,(!("auto"in c)||c.auto)&&setTimeout(()=>this.start())}get disposed(){return this._disposed}get frequency(){return this._frequency}set frequency(c){if(this.isDisposed||e.JSONExt.deepEqual(c,this.frequency||{}))return;let{backoff:u,interval:l,max:d}=c;if(l=Math.round(l),d=Math.round(d),typeof u=="number"&&u<1)throw new Error("Poll backoff growth factor must be at least 1");if((l<0||l>d)&&l!==n.NEVER)throw new Error("Poll interval must be between 0 and max");if(d>n.MAX_INTERVAL&&d!==n.NEVER)throw new Error(`Max interval must be less than ${n.MAX_INTERVAL}`);this._frequency={backoff:u,interval:l,max:d}}get isDisposed(){return this.state.phase==="disposed"}get standby(){return this._standby}set standby(c){this.isDisposed||this.standby===c||(this._standby=c)}get state(){return this._state}get tick(){return this._tick.promise}get ticked(){return this._ticked}async*[Symbol.asyncIterator](){for(;!this.isDisposed;)yield this.state,await this.tick.catch(()=>{})}dispose(){this.isDisposed||(this._state={...s.DISPOSED_STATE,timestamp:new Date().getTime()},this._tick.promise.catch(c=>{}),this._tick.reject(new Error(`Poll (${this.name}) is disposed.`)),this._disposed.emit(void 0),t.Signal.clearData(this))}refresh(){return this.schedule({cancel:({phase:c})=>c==="refreshed",interval:n.IMMEDIATE,phase:"refreshed"})}async schedule(c={}){if(this.isDisposed||c.cancel&&c.cancel(this.state))return;let u=this._tick,l=new e.PromiseDelegate,d={interval:this.frequency.interval,payload:null,phase:"standby",timestamp:new Date().getTime(),...c};if(this._state=d,this._tick=l,clearTimeout(this._timeout),this._ticked.emit(this.state),u.resolve(this),await u.promise,d.interval===n.NEVER){this._timeout=void 0;return}let m=()=>{this.isDisposed||this.tick!==l.promise||this._execute()};this._timeout=setTimeout(m,d.interval)}start(){return this.schedule({cancel:({phase:c})=>c!=="constructed"&&c!=="standby"&&c!=="stopped",interval:n.IMMEDIATE,phase:"started"})}stop(){return this.schedule({cancel:({phase:c})=>c==="stopped",interval:n.NEVER,phase:"stopped"})}get hidden(){return s.hidden}_execute(){let c=typeof this.standby=="function"?this.standby():this.standby;if(c==="never"?c=!1:c==="when-hidden"&&(this.hidden?c=++this._lingered>this._linger:(this._lingered=0,c=!1)),c){this.schedule();return}let u=this.tick;this._factory(this.state).then(l=>{this.isDisposed||this.tick!==u||this.schedule({payload:l,phase:this.state.phase==="rejected"?"reconnected":"resolved"})}).catch(l=>{this.isDisposed||this.tick!==u||this.schedule({interval:s.sleep(this.frequency,this.state),payload:l,phase:"rejected"})})}}(function(h){h.IMMEDIATE=0,h.MAX_INTERVAL=2147483647,h.NEVER=1/0})(n||(n={}));var s;(function(h){h.DEFAULT_BACKOFF=3,h.DEFAULT_FREQUENCY={backoff:!0,interval:1e3,max:30*1e3},h.DEFAULT_LINGER=1,h.DEFAULT_NAME="unknown",h.DEFAULT_STANDBY="when-hidden",h.DEFAULT_STATE={interval:n.NEVER,payload:null,phase:"constructed",timestamp:new Date(0).getTime()},h.DISPOSED_STATE={interval:n.NEVER,payload:null,phase:"disposed",timestamp:new Date(0).getTime()};function c(l,d){let{backoff:m,interval:v,max:T}=l;if(v===n.NEVER)return v;let E=m===!0?h.DEFAULT_BACKOFF:m===!1?1:m,q=u(v,d.interval*E);return Math.min(T,q)}h.sleep=c,h.hidden=typeof document=="undefined"?!1:(document.addEventListener("visibilitychange",()=>{h.hidden=document.visibilityState==="hidden"}),document.addEventListener("pagehide",()=>{h.hidden=document.visibilityState==="hidden"}),document.visibilityState==="hidden");function u(l,d){return l=Math.ceil(l),d=Math.floor(d),Math.floor(Math.random()*(d-l+1))+l}})(s||(s={}));class i{constructor(c,u=500){this.args=void 0,this.payload=null,this.limit=u,this.poll=new n({auto:!1,factory:async()=>{let{args:l}=this;return this.args=void 0,c(...l)},frequency:{backoff:!1,interval:n.NEVER,max:n.NEVER},standby:"never"}),this.payload=new e.PromiseDelegate,this.poll.ticked.connect((l,d)=>{let{payload:m}=this;if(d.phase==="resolved"){this.payload=new e.PromiseDelegate,m.resolve(d.payload);return}if(d.phase==="rejected"||d.phase==="stopped"){this.payload=new e.PromiseDelegate,m.promise.catch(v=>{}),m.reject(d.payload);return}},this)}get isDisposed(){return this.payload===null}dispose(){this.isDisposed||(this.args=void 0,this.payload=null,this.poll.dispose())}async stop(){return this.poll.stop()}}class o extends i{invoke(...c){return this.args=c,this.poll.schedule({interval:this.limit,phase:"invoked"}),this.payload.promise}}class a extends i{constructor(c,u){super(c,typeof u=="number"?u:u&&u.limit),this._trailing=!1,typeof u!="number"&&u&&u.edge==="trailing"&&(this._trailing=!0),this._interval=this._trailing?this.limit:n.IMMEDIATE}invoke(...c){let u=this.poll.state.phase!=="invoked";return(u||this._trailing)&&(this.args=c),u&&this.poll.schedule({interval:this._interval,phase:"invoked"}),this.payload.promise}}r.Debouncer=o,r.Poll=n,r.RateLimiter=i,r.Throttler=a})});var ps=O(un=>{"use strict";Object.defineProperty(un,"__esModule",{value:!0});un.EventManager=void 0;var di=te(),Pl=Ge(),fi=ee(),_i=he(),gi="api/events",gs=class{constructor(e={}){var t,n;this._socket=null,this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:_i.ServerConnection.makeSettings(),this._poll=new Pl.Poll({factory:()=>this._subscribe(),standby:(n=e.standby)!==null&&n!==void 0?n:"when-hidden"}),this._stream=new fi.Stream(this),this._poll.start()}get isDisposed(){return this._poll.isDisposed}get stream(){return this._stream}dispose(){if(this.isDisposed)return;this._poll.dispose();let e=this._socket;e&&(this._socket=null,e.onopen=()=>{},e.onerror=()=>{},e.onmessage=()=>{},e.onclose=()=>{},e.close()),fi.Signal.clearData(this),this._stream.stop()}async emit(e){let{serverSettings:t}=this,{baseUrl:n}=t,{makeRequest:s,ResponseError:i}=_i.ServerConnection,o=di.URLExt.join(n,gi),a={body:JSON.stringify(e),method:"POST"},h=await s(o,a,t);if(h.status!==204)throw new i(h)}_subscribe(){return new Promise((e,t)=>{if(this.isDisposed)return;let{appendToken:n,token:s,WebSocket:i,wsUrl:o}=this.serverSettings,a=di.URLExt.join(o,gi,"subscribe");n&&s!==""&&(a+=`?token=${encodeURIComponent(s)}`);let h=this._socket=new i(a),c=this._stream;h.onclose=()=>t(new Error("EventManager socket closed")),h.onmessage=u=>u.data&&c.emit(JSON.parse(u.data))})}};un.EventManager=gs});var vs=O(be=>{"use strict";var Ml=be&&be.__createBinding||(Object.create?function(r,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,n,s)}:function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]}),El=be&&be.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),Il=be&&be.__importStar||function(){var r=function(e){return r=Object.getOwnPropertyNames||function(t){var n=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[n.length]=s);return n},r(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n=r(e),s=0;s<n.length;s++)n[s]!=="default"&&Ml(t,e,n[s]);return El(t,e),t}}();Object.defineProperty(be,"__esModule",{value:!0});be.CommHandler=be.CommsOverSubshells=void 0;var ms=X(),Ol=rn(),hn=Il(et()),Ke;(function(r){r.Disabled="disabled",r.PerComm="perComm",r.PerCommTarget="perCommTarget"})(Ke||(be.CommsOverSubshells=Ke={}));var dn=class r extends Ol.DisposableDelegate{constructor(e,t,n,s,i){super(s),this._subshellStarted=new ms.PromiseDelegate,this._subshellId=null,this._target="",this._id="",this._id=t,this._target=e,this._kernel=n,this._kernel.statusChanged.connect(()=>{this._kernel.status==="restarting"&&this._cleanSubshells()}),this.commsOverSubshells=i!=null?i:Ke.PerCommTarget}get commId(){return this._id}get targetName(){return this._target}get subshellId(){return this._subshellId}get subshellStarted(){return this._subshellStarted.promise}get commsOverSubshells(){return this._commsOverSubshells}set commsOverSubshells(e){if(e===this._commsOverSubshells)return;let t=this._maybeCloseSubshell(this._commsOverSubshells);this._commsOverSubshells=e,t.then(()=>{this._commsOverSubshells!==Ke.Disabled&&this._maybeStartSubshell()}).catch(console.warn)}get onClose(){return this._onClose}set onClose(e){this._onClose=e}get onMsg(){return this._onMsg}set onMsg(e){this._onMsg=e}open(e,t,n=[]){if(this.isDisposed||this._kernel.isDisposed)throw new Error("Cannot open");let s=hn.createMessage({msgType:"comm_open",channel:"shell",username:this._kernel.username,session:this._kernel.clientId,subshellId:this._subshellId||this._kernel.subshellId,content:{comm_id:this._id,target_name:this._target,data:e!=null?e:{}},metadata:t,buffers:n});return this._kernel.sendShellMessage(s,!1,!0)}send(e,t,n=[],s=!0){if(this.isDisposed||this._kernel.isDisposed)throw new Error("Cannot send");let i=hn.createMessage({msgType:"comm_msg",channel:"shell",username:this._kernel.username,session:this._kernel.clientId,subshellId:this._subshellId||this._kernel.subshellId,content:{comm_id:this._id,data:e},metadata:t,buffers:n});return this._kernel.sendShellMessage(i,!1,s)}close(e,t,n=[]){if(this.isDisposed||this._kernel.isDisposed)throw new Error("Cannot close");let s=hn.createMessage({msgType:"comm_close",channel:"shell",username:this._kernel.username,session:this._kernel.clientId,subshellId:this._subshellId||this._kernel.subshellId,content:{comm_id:this._id,data:e!=null?e:{}},metadata:t,buffers:n}),i=this._kernel.sendShellMessage(s,!1,!0),o=this._onClose;if(o){let a=hn.createMessage({msgType:"comm_close",channel:"iopub",username:this._kernel.username,session:this._kernel.clientId,subshellId:this._subshellId||this._kernel.subshellId,content:{comm_id:this._id,data:e!=null?e:{}},metadata:t,buffers:n});o(a)}return this.dispose(),i}dispose(){this._maybeCloseSubshell(this._commsOverSubshells),super.dispose()}_cleanSubshells(){let e=this._kernel.id;r._commTargetSubShellsId.hasOwnProperty(e)&&delete r._commTargetSubShellsId[e]}async _maybeStartSubshell(){if(await this._kernel.info,!this._kernel.supportsSubshells)return;if(this._commsOverSubshells===Ke.PerComm){let o=await this._kernel.requestCreateSubshell({}).done;this._subshellId=o.content.subshell_id,this._subshellStarted.resolve();return}let e=this._subshellStarted,t=this._kernel.id;r._commTargetSubShellsId.hasOwnProperty(t)||(r._commTargetSubShellsId[t]={});let n=r._commTargetSubShellsId[t],s=n[this._target];if(s){s.referenceCount+=1;try{this._subshellId=await s.subshellId,e.resolve()}catch(o){await this._closePerCommTargetSubshell(!1),e.reject(`Per comm-target subshell creation failed: ${o}`)}return}let i={subshellId:this._kernel.requestCreateSubshell({}).done.then(o=>o.content.subshell_id),referenceCount:1};n[this._target]=i;try{this._subshellId=await i.subshellId,e.resolve()}catch(o){await this._closePerCommTargetSubshell(!1),e.reject(`Per comm-target subshell creation failed: ${o}`)}}async _closePerCommTargetSubshell(e=!0){let t=this._kernel.id,n=this._target;if(r._commTargetSubShellsId.hasOwnProperty(t)){let s=r._commTargetSubShellsId[t],i=s[n];if(i&&(i.referenceCount-=1,i.referenceCount<=0)){if(e){let o=null;try{o=await i.subshellId}catch(a){console.warn(`Subshell identifier not available in the closeout sequence, will not request deletion: ${a}`)}o!==null&&this._kernel.requestDeleteSubshell({subshell_id:o},!0)}delete s[n]}Object.keys(s).length===0&&delete r._commTargetSubShellsId[t],this._subshellId=null}this._subshellStarted=new ms.PromiseDelegate}async _maybeCloseSubshell(e){if(this._kernel.status!=="dead")switch(e){case Ke.PerComm:{this._subshellId&&(this._kernel.requestDeleteSubshell({subshell_id:this._subshellId},!0),this._subshellId=null),this._subshellStarted=new ms.PromiseDelegate;break}case Ke.PerCommTarget:{await this._closePerCommTargetSubshell();break}case Ke.Disabled:break}}};be.CommHandler=dn;dn._commTargetSubShellsId={}});var mi=O(pi=>{"use strict";Object.defineProperty(pi,"__esModule",{value:!0})});var fn=O(ht=>{"use strict";Object.defineProperty(ht,"__esModule",{value:!0});ht.validateMessage=Dl;ht.validateModel=yi;ht.validateModels=ql;var Xe=lt(),vi=["username","version","session","msg_id","msg_type"],Rl={stream:{name:"string",text:"string"},display_data:{data:"object",metadata:"object"},execute_input:{code:"string",execution_count:"number"},execute_result:{execution_count:"number",data:"object",metadata:"object"},error:{ename:"string",evalue:"string",traceback:"object"},status:{execution_state:["string",["starting","idle","busy","restarting","dead"]]},clear_output:{wait:"boolean"},comm_open:{comm_id:"string",target_name:"string",data:"object"},comm_msg:{comm_id:"string",data:"object"},comm_close:{comm_id:"string"},shutdown_reply:{restart:"boolean"}};function kl(r){for(let e=0;e<vi.length;e++)(0,Xe.validateProperty)(r,vi[e],"string")}function Dl(r){(0,Xe.validateProperty)(r,"metadata","object"),(0,Xe.validateProperty)(r,"content","object"),(0,Xe.validateProperty)(r,"channel","string"),kl(r.header),r.channel==="iopub"&&Tl(r)}function Tl(r){if(r.channel==="iopub"){let e=Rl[r.header.msg_type];if(e===void 0)return;let t=Object.keys(e),n=r.content;for(let s=0;s<t.length;s++){let i=e[t[s]];Array.isArray(i)||(i=[i]),(0,Xe.validateProperty)(n,t[s],...i)}}}function yi(r){(0,Xe.validateProperty)(r,"name","string"),(0,Xe.validateProperty)(r,"id","string")}function ql(r){if(!Array.isArray(r))throw new Error("Invalid kernel list");r.forEach(e=>yi(e))}});var gn=O(se=>{"use strict";Object.defineProperty(se,"__esModule",{value:!0});se.KernelAPIClient=se.KERNEL_SERVICE_URL=void 0;se.listRunning=wi;se.startNew=Si;se.restartKernel=bi;se.interruptKernel=Ci;se.shutdownKernel=Pi;se.getKernelModel=Mi;var Q=he(),st=te(),_n=fn();se.KERNEL_SERVICE_URL="api/kernels";async function wi(r=Q.ServerConnection.makeSettings()){let e=st.URLExt.join(r.baseUrl,se.KERNEL_SERVICE_URL),t=await Q.ServerConnection.makeRequest(e,{},r);if(t.status!==200)throw await Q.ServerConnection.ResponseError.create(t);let n=await t.json();return(0,_n.validateModels)(n),n}async function Si(r={},e=Q.ServerConnection.makeSettings()){let t=st.URLExt.join(e.baseUrl,se.KERNEL_SERVICE_URL),n={method:"POST",body:JSON.stringify(r)},s=await Q.ServerConnection.makeRequest(t,n,e);if(s.status!==201)throw await Q.ServerConnection.ResponseError.create(s);let i=await s.json();return(0,_n.validateModel)(i),i}async function bi(r,e=Q.ServerConnection.makeSettings()){let t=st.URLExt.join(e.baseUrl,se.KERNEL_SERVICE_URL,encodeURIComponent(r),"restart"),n={method:"POST"},s=await Q.ServerConnection.makeRequest(t,n,e);if(s.status!==200)throw await Q.ServerConnection.ResponseError.create(s);let i=await s.json();(0,_n.validateModel)(i)}async function Ci(r,e=Q.ServerConnection.makeSettings()){let t=st.URLExt.join(e.baseUrl,se.KERNEL_SERVICE_URL,encodeURIComponent(r),"interrupt"),n={method:"POST"},s=await Q.ServerConnection.makeRequest(t,n,e);if(s.status!==204)throw await Q.ServerConnection.ResponseError.create(s)}async function Pi(r,e=Q.ServerConnection.makeSettings()){let t=st.URLExt.join(e.baseUrl,se.KERNEL_SERVICE_URL,encodeURIComponent(r)),n={method:"DELETE"},s=await Q.ServerConnection.makeRequest(t,n,e);if(s.status===404){let i=`The kernel "${r}" does not exist on the server`;console.warn(i)}else if(s.status!==204)throw await Q.ServerConnection.ResponseError.create(s)}async function Mi(r,e=Q.ServerConnection.makeSettings()){let t=st.URLExt.join(e.baseUrl,se.KERNEL_SERVICE_URL,encodeURIComponent(r)),n=await Q.ServerConnection.makeRequest(t,{},e);if(n.status===404)return;if(n.status!==200)throw await Q.ServerConnection.ResponseError.create(n);let s=await n.json();return(0,_n.validateModel)(s),s}var ys=class{constructor(e={}){var t;this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:Q.ServerConnection.makeSettings()}async listRunning(){return wi(this.serverSettings)}async getModel(e){return Mi(e,this.serverSettings)}async startNew(e={}){return Si(e,this.serverSettings)}async restart(e){return bi(e,this.serverSettings)}async interrupt(e){return Ci(e,this.serverSettings)}async shutdown(e){return Pi(e,this.serverSettings)}};se.KernelAPIClient=ys});var Ii=O(ve=>{"use strict";var jl=ve&&ve.__createBinding||(Object.create?function(r,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,n,s)}:function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]}),Ul=ve&&ve.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),Al=ve&&ve.__importStar||function(){var r=function(e){return r=Object.getOwnPropertyNames||function(t){var n=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[n.length]=s);return n},r(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n=r(e),s=0;s<n.length;s++)n[s]!=="default"&&jl(t,e,n[s]);return Ul(t,e),t}}();Object.defineProperty(ve,"__esModule",{value:!0});ve.KernelShellFutureHandler=ve.KernelControlFutureHandler=ve.KernelFutureHandler=void 0;var Ei=X(),Nl=rn(),Ll=Al(et()),dt=class extends Nl.DisposableDelegate{constructor(e,t,n,s,i){super(e),this._status=0,this._stdin=ie.noOp,this._iopub=ie.noOp,this._reply=ie.noOp,this._done=new Ei.PromiseDelegate,this._hooks=new ie.HookList,this._disposeOnDone=!0,this._msg=t,n||this._setFlag(ie.KernelFutureFlag.GotReply),this._disposeOnDone=s,this._kernel=i}get msg(){return this._msg}get done(){return this._done.promise}get onReply(){return this._reply}set onReply(e){this._reply=e}get onIOPub(){return this._iopub}set onIOPub(e){this._iopub=e}get onStdin(){return this._stdin}set onStdin(e){this._stdin=e}registerMessageHook(e){if(this.isDisposed)throw new Error("Kernel future is disposed");this._hooks.add(e)}removeMessageHook(e){this.isDisposed||this._hooks.remove(e)}sendInputReply(e,t){this._kernel.sendInputReply(e,t)}dispose(){this._stdin=ie.noOp,this._iopub=ie.noOp,this._reply=ie.noOp,this._hooks=null,this._testFlag(ie.KernelFutureFlag.IsDone)||(this._done.promise.catch(()=>{}),this._done.reject(new Error(`Canceled future for ${this.msg.header.msg_type} message before replies were done`))),super.dispose()}async handleMsg(e){switch(e.channel){case"control":case"shell":e.channel===this.msg.channel&&e.parent_header.msg_id===this.msg.header.msg_id&&await this._handleReply(e);break;case"stdin":await this._handleStdin(e);break;case"iopub":await this._handleIOPub(e);break;default:break}}async _handleReply(e){let t=this._reply;t&&await t(e),this._replyMsg=e,this._setFlag(ie.KernelFutureFlag.GotReply),this._testFlag(ie.KernelFutureFlag.GotIdle)&&this._handleDone()}async _handleStdin(e){this._kernel.hasPendingInput=!0;let t=this._stdin;t&&await t(e)}async _handleIOPub(e){let t=await this._hooks.process(e),n=this._iopub;t&&n&&await n(e),Ll.isStatusMsg(e)&&e.content.execution_state==="idle"&&(this._setFlag(ie.KernelFutureFlag.GotIdle),this._testFlag(ie.KernelFutureFlag.GotReply)&&this._handleDone())}_handleDone(){this._testFlag(ie.KernelFutureFlag.IsDone)||(this._setFlag(ie.KernelFutureFlag.IsDone),this._done.resolve(this._replyMsg),this._disposeOnDone&&this.dispose())}_testFlag(e){return(this._status&e)!==0}_setFlag(e){this._status|=e}};ve.KernelFutureHandler=dt;var ws=class extends dt{};ve.KernelControlFutureHandler=ws;var Ss=class extends dt{};ve.KernelShellFutureHandler=Ss;var ie;(function(r){r.noOp=()=>{};let e=typeof requestAnimationFrame=="function"?requestAnimationFrame:setImmediate;class t{constructor(){this._hooks=[]}add(i){this.remove(i),this._hooks.push(i)}remove(i){let o=this._hooks.indexOf(i);o>=0&&(this._hooks[o]=null,this._scheduleCompact())}async process(i){await this._processing;let o=new Ei.PromiseDelegate;this._processing=o.promise;let a;for(let h=this._hooks.length-1;h>=0;h--){let c=this._hooks[h];if(c!==null){try{a=await c(i)}catch(u){a=!0,console.error(u)}if(a===!1)return o.resolve(void 0),!1}}return o.resolve(void 0),!0}_scheduleCompact(){this._compactScheduled||(this._compactScheduled=!0,e(()=>{this._processing=this._processing.then(()=>{this._compactScheduled=!1,this._compact()})}))}_compact(){let i=0;for(let o=0,a=this._hooks.length;o<a;o++){let h=this._hooks[o];this._hooks[o]===null?i++:this._hooks[o-i]=h}this._hooks.length-=i}}r.HookList=t;let n;(function(s){s[s.GotReply=1]="GotReply",s[s.GotIdle=2]="GotIdle",s[s.IsDone=4]="IsDone",s[s.DisposeOnDone=8]="DisposeOnDone"})(n=r.KernelFutureFlag||(r.KernelFutureFlag={}))})(ie||(ie={}))});var Ri=O(pn=>{"use strict";Object.defineProperty(pn,"__esModule",{value:!0});pn.validateSpecModel=Oi;pn.validateSpecModels=xl;var ze=lt();function Oi(r){let e=r.spec;if(!e)throw new Error("Invalid kernel spec");(0,ze.validateProperty)(r,"name","string"),(0,ze.validateProperty)(r,"resources","object"),(0,ze.validateProperty)(e,"language","string"),(0,ze.validateProperty)(e,"display_name","string"),(0,ze.validateProperty)(e,"argv","array");let t=null;e.hasOwnProperty("metadata")&&((0,ze.validateProperty)(e,"metadata","object"),t=e.metadata);let n=null;return e.hasOwnProperty("env")&&((0,ze.validateProperty)(e,"env","object"),n=e.env),e.hasOwnProperty("interrupt_mode")&&((0,ze.validateProperty)(e,"interrupt_mode","string"),n=e.env),{name:r.name,resources:r.resources,language:e.language,display_name:e.display_name,argv:e.argv,metadata:t,env:n}}function xl(r){if(!r.hasOwnProperty("kernelspecs"))throw new Error("No kernelspecs found");let e=Object.keys(r.kernelspecs),t=Object.create(null),n=r.default;for(let s=0;s<e.length;s++){let i=r.kernelspecs[e[s]];try{t[e[s]]=Oi(i)}catch{console.warn(`Removing errant kernel spec: ${e[s]}`)}}if(e=Object.keys(t),!e.length)throw new Error("No valid kernelspecs found");return(!n||typeof n!="string"||!(n in t))&&(n=e[0],console.warn(`Default kernel not found, using '${e[0]}'`)),{default:n,kernelspecs:t}}});var _t=O(ft=>{"use strict";Object.defineProperty(ft,"__esModule",{value:!0});ft.KernelSpecAPIClient=void 0;ft.getSpecs=ki;var mn=he(),Fl=Ri(),Kl=te(),zl="api/kernelspecs";async function ki(r=mn.ServerConnection.makeSettings()){let e=Kl.URLExt.join(r.baseUrl,zl),t=await mn.ServerConnection.makeRequest(e,{},r);if(t.status!==200)throw await mn.ServerConnection.ResponseError.create(t);let n=await t.json();return(0,Fl.validateSpecModels)(n)}var bs=class{constructor(e={}){var t;this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:mn.ServerConnection.makeSettings()}async get(){return ki(this.serverSettings)}};ft.KernelSpecAPIClient=bs});var Ps=O(ye=>{"use strict";var Vl=ye&&ye.__createBinding||(Object.create?function(r,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,n,s)}:function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]}),Bl=ye&&ye.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),Ui=ye&&ye.__importStar||function(){var r=function(e){return r=Object.getOwnPropertyNames||function(t){var n=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[n.length]=s);return n},r(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n=r(e),s=0;s<n.length;s++)n[s]!=="default"&&Vl(t,e,n[s]);return Bl(t,e),t}}();Object.defineProperty(ye,"__esModule",{value:!0});ye.KernelConnection=ye.DEFAULT_KERNEL_INFO_TIMEOUT=void 0;var Di=te(),Ve=X(),Be=ee(),gt=Ae(),Ti=vs(),oe=Ui(et()),qi=Ii(),$l=Ui(fn()),ji=gn(),Wl=_t(),Hl=te();ye.DEFAULT_KERNEL_INFO_TIMEOUT=3e3;var rt="_RESTARTING_",Jl="",Cs=class r{constructor(e){var t,n,s,i,o,a,h,c,u;this._createSocket=(l=!0)=>{this._errorIfDisposed(),this._clearSocket(),this._updateConnectionStatus("connecting");let d=this.serverSettings,m=Di.URLExt.join(d.wsUrl,ji.KERNEL_SERVICE_URL,encodeURIComponent(this._id)),v=m.replace(/^((?:\w+:)?\/\/)[^@/]+@/,"$1");console.debug(`Starting WebSocket: ${v}`);let T=Di.URLExt.join(m,"channels?session_id="+encodeURIComponent(this._clientId)),E=d.token;d.appendToken&&E!==""&&(T=T+`&token=${encodeURIComponent(E)}`);let q=l?this._supportedProtocols:[];this._ws=new d.WebSocket(T,q),this._ws.binaryType="arraybuffer";let A=!1,C=async k=>{var N,j;if(!this._isDisposed){this._reason="",this._model=void 0;try{let R=await this._kernelAPIClient.getModel(this._id);this._model=R,(R==null?void 0:R.execution_state)==="dead"?this._updateStatus("dead"):this._onWSClose(k)}catch(R){if(R instanceof gt.ServerConnection.NetworkError||((N=R.response)===null||N===void 0?void 0:N.status)===503||((j=R.response)===null||j===void 0?void 0:j.status)===424){let U=Ce.getRandomIntInclusive(10,30)*1e3;setTimeout(C,U,k)}else this._reason="Kernel died unexpectedly",this._updateStatus("dead")}}},w=async k=>{A||(A=!0,await C(k))};this._ws.onmessage=this._onWSMessage,this._ws.onopen=this._onWSOpen,this._ws.onclose=w,this._ws.onerror=w},this._onWSOpen=l=>{if(this._ws.protocol!==""&&!this._supportedProtocols.includes(this._ws.protocol))throw console.log("Server selected unknown kernel wire protocol:",this._ws.protocol),this._updateStatus("dead"),new Error(`Unknown kernel wire protocol: ${this._ws.protocol}`);this._selectedProtocol=this._ws.protocol,this._ws.onclose=this._onWSClose,this._ws.onerror=this._onWSClose,this._updateConnectionStatus("connected")},this._onWSMessage=l=>{let d;try{d=this.serverSettings.serializer.deserialize(l.data,this._ws.protocol),$l.validateMessage(d)}catch(m){throw m.message=`Kernel message validation error: ${m.message}`,m}this._kernelSession=d.header.session,this._msgChain=this._msgChain.then(()=>this._handleMessage(d)).catch(m=>{m.message.startsWith("Canceled future for ")&&console.error(m)}),this._anyMessage.emit({msg:d,direction:"recv"})},this._onWSClose=l=>{if(!this.isDisposed){if("code"in l&&(l.code===1e3||l.code===1001)){this._updateConnectionStatus("disconnected");return}this._reconnect()}},this._id="",this._name="",this._status="unknown",this._connectionStatus="connecting",this._kernelSession="",this._isDisposed=!1,this._ws=null,this._username="",this._reconnectLimit=7,this._reconnectAttempt=0,this._reconnectTimeout=null,this._supportedProtocols=Object.values(oe.supportedKernelWebSocketProtocols),this._selectedProtocol="",this._commsOverSubshells=gt.CommsOverSubshells.PerCommTarget,this._futures=new Map,this._comms=new Map,this._targetRegistry=Object.create(null),this._info=new Ve.PromiseDelegate,this._pendingMessages=[],this._statusChanged=new Be.Signal(this),this._connectionStatusChanged=new Be.Signal(this),this._disposed=new Be.Signal(this),this._iopubMessage=new Be.Signal(this),this._anyMessage=new Be.Signal(this),this._pendingInput=new Be.Signal(this),this._unhandledMessage=new Be.Signal(this),this._displayIdToParentIds=new Map,this._msgIdToDisplayIds=new Map,this._msgChain=Promise.resolve(),this._hasPendingInput=!1,this._reason="",this._noOp=()=>{},this._supportsSubshells=!1,this._kernelInfoTimeout=ye.DEFAULT_KERNEL_INFO_TIMEOUT,this._name=e.model.name,this._id=e.model.id,this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:gt.ServerConnection.makeSettings(),this._kernelAPIClient=(n=e.kernelAPIClient)!==null&&n!==void 0?n:new ji.KernelAPIClient({serverSettings:this.serverSettings}),this._kernelSpecAPIClient=(s=e.kernelSpecAPIClient)!==null&&s!==void 0?s:new Wl.KernelSpecAPIClient({serverSettings:this.serverSettings}),this._clientId=(i=e.clientId)!==null&&i!==void 0?i:Ve.UUID.uuid4(),this._username=(o=e.username)!==null&&o!==void 0?o:"",this.handleComms=(a=e.handleComms)!==null&&a!==void 0?a:!0,this._commsOverSubshells=(h=e.commsOverSubshells)!==null&&h!==void 0?h:gt.CommsOverSubshells.PerCommTarget,this._subshellId=(c=e.subshellId)!==null&&c!==void 0?c:null,this._createSocket(),this._kernelInfoTimeout=(u=e==null?void 0:e.kernelInfoTimeout)!==null&&u!==void 0?u:ye.DEFAULT_KERNEL_INFO_TIMEOUT}get disposed(){return this._disposed}get commsOverSubshells(){return this._commsOverSubshells}set commsOverSubshells(e){this._commsOverSubshells=e;for(let[t,n]of this._comms)n.commsOverSubshells=e}get statusChanged(){return this._statusChanged}get connectionStatusChanged(){return this._connectionStatusChanged}get iopubMessage(){return this._iopubMessage}get unhandledMessage(){return this._unhandledMessage}get model(){return this._model||{id:this.id,name:this.name,reason:this._reason}}get anyMessage(){return this._anyMessage}get pendingInput(){return this._pendingInput}get id(){return this._id}get name(){return this._name}get username(){return this._username}get clientId(){return this._clientId}get subshellId(){return this._subshellId}set subshellId(e){this._subshellId=e}get status(){return this._status}get connectionStatus(){return this._connectionStatus}get isDisposed(){return this._isDisposed}get info(){return this._info.promise}get spec(){return this._specPromise?this._specPromise:(this._specPromise=this._kernelSpecAPIClient.get().then(e=>e.kernelspecs[this._name]),this._specPromise)}get supportsSubshells(){return this._supportsSubshells}clone(e={}){return new r({model:this.model,username:this.username,serverSettings:this.serverSettings,handleComms:!1,kernelAPIClient:this._kernelAPIClient,commsOverSubshells:gt.CommsOverSubshells.Disabled,kernelInfoTimeout:this._kernelInfoTimeout,...e})}dispose(){if(this.isDisposed)return;let e=()=>{this._isDisposed=!0,this._disposed.emit(),this._updateConnectionStatus("disconnected"),this._clearKernelState(),this._pendingMessages=[],this._clearSocket(),Be.Signal.clearData(this)};if(this._subshellId!==null){let t=this.requestDeleteSubshell({subshell_id:this._subshellId},!0);t.onReply=n=>{e()}}else e()}sendShellMessage(e,t=!1,n=!0){return this._sendKernelShellControl(qi.KernelShellFutureHandler,e,t,n)}sendControlMessage(e,t=!1,n=!0){return this._sendKernelShellControl(qi.KernelControlFutureHandler,e,t,n)}_sendKernelShellControl(e,t,n=!1,s=!0){this._sendMessage(t),this._anyMessage.emit({msg:t,direction:"send"});let i=new e(()=>{let o=t.header.msg_id;this._futures.delete(o);let a=this._msgIdToDisplayIds.get(o);a&&(a.forEach(h=>{let c=this._displayIdToParentIds.get(h);if(c){let u=c.indexOf(o);if(u===-1)return;c.length===1?this._displayIdToParentIds.delete(h):(c.splice(u,1),this._displayIdToParentIds.set(h,c))}}),this._msgIdToDisplayIds.delete(o))},t,n,s,this);return this._futures.set(t.header.msg_id,i),i}_sendMessage(e,t=!0){if(this.status==="dead")throw new Error("Kernel is dead");if((this._kernelSession===Jl||this._kernelSession===rt)&&oe.isInfoRequestMsg(e))if(this.connectionStatus==="connected"){this._ws.send(this.serverSettings.serializer.serialize(e,this._ws.protocol));return}else throw new Error("Could not send message: status is not connected");if(t&&this._pendingMessages.length>0){this._pendingMessages.push(e);return}if(this.connectionStatus==="connected"&&this._kernelSession!==rt)this._ws.send(this.serverSettings.serializer.serialize(e,this._ws.protocol));else if(t)this._pendingMessages.push(e);else throw new Error("Could not send message")}async interrupt(){if(this.hasPendingInput=!1,this.status==="dead")throw new Error("Kernel is dead");return this._kernelAPIClient.interrupt(this.id)}async restart(){if(this.status==="dead")throw new Error("Kernel is dead");this._updateStatus("restarting"),this._clearKernelState(),this._kernelSession=rt,await this._kernelAPIClient.restart(this.id),await this.reconnect(),this.hasPendingInput=!1}reconnect(){this._errorIfDisposed();let e=new Ve.PromiseDelegate,t=(n,s)=>{s==="connected"?(e.resolve(),this.connectionStatusChanged.disconnect(t,this)):s==="disconnected"&&(e.reject(new Error("Kernel connection disconnected")),this.connectionStatusChanged.disconnect(t,this))};return this.connectionStatusChanged.connect(t,this),this._reconnectAttempt=0,this._reconnect(),e.promise}async shutdown(){this.status!=="dead"&&await this._kernelAPIClient.shutdown(this.id),this.handleShutdown()}handleShutdown(){this._updateStatus("dead"),this.dispose()}async requestKernelInfo(){let e=oe.createMessage({msgType:"kernel_info_request",channel:"shell",username:this._username,session:this._clientId,subshellId:this._subshellId,content:{}}),t;try{t=await Ce.handleShellMessage(this,e)}catch(s){if(this.isDisposed)return;throw s}if(this._errorIfDisposed(),!t)return;if(t.content.status===void 0&&(t.content.status="ok"),t.content.status!=="ok")return this._info.reject("Kernel info reply errored"),t;this._info.resolve(t.content),this._kernelSession=t.header.session;let n=t.content.supported_features;return this._supportsSubshells=n!==void 0&&n.includes("kernel subshells"),t}requestComplete(e){let t=oe.createMessage({msgType:"complete_request",channel:"shell",username:this._username,session:this._clientId,subshellId:this._subshellId,content:e});return Ce.handleShellMessage(this,t)}requestInspect(e){let t=oe.createMessage({msgType:"inspect_request",channel:"shell",username:this._username,session:this._clientId,subshellId:this._subshellId,content:e});return Ce.handleShellMessage(this,t)}requestHistory(e){let t=oe.createMessage({msgType:"history_request",channel:"shell",username:this._username,session:this._clientId,subshellId:this._subshellId,content:e});return Ce.handleShellMessage(this,t)}requestExecute(e,t=!0,n){let s={silent:!1,store_history:!0,user_expressions:{},allow_stdin:!0,stop_on_error:!1},i=oe.createMessage({msgType:"execute_request",channel:"shell",username:this._username,session:this._clientId,subshellId:this._subshellId,content:{...s,...e},metadata:n});return this.sendShellMessage(i,!0,t)}requestDebug(e,t=!0){let n=oe.createMessage({msgType:"debug_request",channel:"control",username:this._username,session:this._clientId,content:e});return this.sendControlMessage(n,!0,t)}requestCreateSubshell(e,t=!0){if(!this.supportsSubshells)throw new Error("Kernel subshells are not supported");let n=oe.createMessage({msgType:"create_subshell_request",channel:"control",username:this._username,session:this._clientId,content:e});return this.sendControlMessage(n,!0,t)}requestDeleteSubshell(e,t=!0){if(!this.supportsSubshells)throw new Error("Kernel subshells are not supported");let n=oe.createMessage({msgType:"delete_subshell_request",channel:"control",username:this._username,session:this._clientId,content:e});return this.sendControlMessage(n,!0,t)}requestListSubshell(e,t=!0){if(!this.supportsSubshells)throw new Error("Kernel subshells are not supported");let n=oe.createMessage({msgType:"list_subshell_request",channel:"control",username:this._username,session:this._clientId,content:e});return this.sendControlMessage(n,!0,t)}requestIsComplete(e){let t=oe.createMessage({msgType:"is_complete_request",channel:"shell",username:this._username,session:this._clientId,subshellId:this._subshellId,content:e});return Ce.handleShellMessage(this,t)}requestCommInfo(e){let t=oe.createMessage({msgType:"comm_info_request",channel:"shell",username:this._username,session:this._clientId,subshellId:this._subshellId,content:e});return Ce.handleShellMessage(this,t)}sendInputReply(e,t){let n=oe.createMessage({msgType:"input_reply",channel:"stdin",username:this._username,session:this._clientId,content:e});n.parent_header=t,this._sendMessage(n),this._anyMessage.emit({msg:n,direction:"send"}),this.hasPendingInput=!1}createComm(e,t=Ve.UUID.uuid4()){if(!this.handleComms)throw new Error("Comms are disabled on this kernel connection");if(this._comms.has(t))throw new Error("Comm is already created");let n=new Ti.CommHandler(e,t,this,()=>{this._unregisterComm(t)},this._commsOverSubshells);return this._comms.set(t,n),n}hasComm(e){return this._comms.has(e)}registerCommTarget(e,t){this.handleComms&&(this._targetRegistry[e]=t)}removeCommTarget(e,t){this.handleComms&&!this.isDisposed&&this._targetRegistry[e]===t&&delete this._targetRegistry[e]}registerMessageHook(e,t){var n;let s=(n=this._futures)===null||n===void 0?void 0:n.get(e);s&&s.registerMessageHook(t)}removeMessageHook(e,t){var n;let s=(n=this._futures)===null||n===void 0?void 0:n.get(e);s&&s.removeMessageHook(t)}removeInputGuard(){this.hasPendingInput=!1}async _handleDisplayId(e,t){var n,s;let i=t.parent_header.msg_id,o=this._displayIdToParentIds.get(e);if(o){let h={header:Ve.JSONExt.deepCopy(t.header),parent_header:Ve.JSONExt.deepCopy(t.parent_header),metadata:Ve.JSONExt.deepCopy(t.metadata),content:Ve.JSONExt.deepCopy(t.content),channel:t.channel,buffers:t.buffers?t.buffers.slice():[]};h.header.msg_type="update_display_data",await Promise.all(o.map(async c=>{let u=this._futures&&this._futures.get(c);u&&await u.handleMsg(h)}))}if(t.header.msg_type==="update_display_data")return!0;o=(n=this._displayIdToParentIds.get(e))!==null&&n!==void 0?n:[],o.indexOf(i)===-1&&o.push(i),this._displayIdToParentIds.set(e,o);let a=(s=this._msgIdToDisplayIds.get(i))!==null&&s!==void 0?s:[];return a.indexOf(i)===-1&&a.push(i),this._msgIdToDisplayIds.set(i,a),!1}_clearSocket(){this._ws!==null&&(this._ws.onopen=this._noOp,this._ws.onclose=this._noOp,this._ws.onerror=this._noOp,this._ws.onmessage=this._noOp,this._ws.close(),this._ws=null)}_updateStatus(e){this._status===e||this._status==="dead"||(this._status=e,Ce.logKernelStatus(this),this._statusChanged.emit(e),e==="dead"&&this.dispose())}_sendPending(){for(;this.connectionStatus==="connected"&&this._kernelSession!==rt&&this._pendingMessages.length>0;)this._sendMessage(this._pendingMessages[0],!1),this._pendingMessages.shift()}_clearKernelState(){this._kernelSession="",this._pendingMessages=[],this._futures.forEach(e=>{e.dispose()}),this._comms.forEach(e=>{e.dispose()}),this._msgChain=Promise.resolve(),this._futures=new Map,this._comms=new Map,this._displayIdToParentIds.clear(),this._msgIdToDisplayIds.clear()}_assertCurrentMessage(e){if(this._errorIfDisposed(),e.header.session!==this._kernelSession)throw new Error(`Canceling handling of old message: ${e.header.msg_type}`)}async _handleCommOpen(e){this._assertCurrentMessage(e);let t=e.content,n=new Ti.CommHandler(t.target_name,t.comm_id,this,()=>{this._unregisterComm(t.comm_id)},this.commsOverSubshells);this._comms.set(t.comm_id,n);try{await(await Ce.loadObject(t.target_name,t.target_module,this._targetRegistry))(n,e)}catch(s){throw n.close(),console.error("Exception opening new comm"),s}}async _handleCommClose(e){this._assertCurrentMessage(e);let t=e.content,n=this._comms.get(t.comm_id);if(!n){console.error("Comm not found for comm id "+t.comm_id);return}this._unregisterComm(n.commId);let s=n.onClose;s&&await s(e),n.dispose()}async _handleCommMsg(e){this._assertCurrentMessage(e);let t=e.content,n=this._comms.get(t.comm_id);if(!n)return;let s=n.onMsg;s&&await s(e)}_unregisterComm(e){this._comms.delete(e)}_updateConnectionStatus(e){if(this._connectionStatus!==e){if(this._connectionStatus=e,e!=="connecting"&&(this._reconnectAttempt=0,clearTimeout(this._reconnectTimeout)),this.status!=="dead")if(e==="connected"){let t=this._kernelSession===rt,n=this.requestKernelInfo(),s=!1,i=()=>{s||(s=!0,t&&this._kernelSession===rt&&(this._kernelSession=""),clearTimeout(o),this._pendingMessages.length>0&&this._sendPending())};n.then(i);let o=setTimeout(i,this._kernelInfoTimeout)}else this._updateStatus("unknown");this._connectionStatusChanged.emit(e)}}async _handleMessage(e){var t,n;let s=!1;if(e.parent_header&&e.channel==="iopub"&&(oe.isDisplayDataMsg(e)||oe.isUpdateDisplayDataMsg(e)||oe.isExecuteResultMsg(e))){let o=((t=e.content.transient)!==null&&t!==void 0?t:{}).display_id;o&&(s=await this._handleDisplayId(o,e),this._assertCurrentMessage(e))}if(!s&&e.parent_header){let i=e.parent_header,o=(n=this._futures)===null||n===void 0?void 0:n.get(i.msg_id);if(o)await o.handleMsg(e),this._assertCurrentMessage(e);else{let a=i.session===this.clientId;e.channel!=="iopub"&&a&&this._unhandledMessage.emit(e)}}if(e.channel==="iopub"){switch(e.header.msg_type){case"status":{let i=Hl.PageConfig.getOption("untracked_message_types");if(JSON.parse(i||"[]").includes(e.parent_header.msg_type))break;let a=e.content.execution_state;a==="restarting"&&Promise.resolve().then(async()=>{this._updateStatus("autorestarting"),this._clearKernelState(),await this.reconnect()}),this._updateStatus(a);break}case"comm_open":this.handleComms&&await this._handleCommOpen(e);break;case"comm_msg":this.handleComms&&await this._handleCommMsg(e);break;case"comm_close":this.handleComms&&await this._handleCommClose(e);break;default:break}this.isDisposed||(this._assertCurrentMessage(e),this._iopubMessage.emit(e))}}_reconnect(){if(this._errorIfDisposed(),clearTimeout(this._reconnectTimeout),this._reconnectAttempt<this._reconnectLimit){this._updateConnectionStatus("connecting");let e=Ce.getRandomIntInclusive(0,1e3*(Math.pow(2,this._reconnectAttempt)-1));console.warn(`Connection lost, reconnecting in ${Math.floor(e/1e3)} seconds.`);let t=this._selectedProtocol!=="";this._reconnectTimeout=setTimeout(this._createSocket,e,t),this._reconnectAttempt+=1}else this._updateConnectionStatus("disconnected");this._clearSocket()}_errorIfDisposed(){if(this.isDisposed)throw new Error("Kernel connection is disposed")}get hasPendingInput(){return this._hasPendingInput}set hasPendingInput(e){this._hasPendingInput=e,this._pendingInput.emit(e)}};ye.KernelConnection=Cs;var Ce;(function(r){function e(i){switch(i.status){case"idle":case"busy":case"unknown":return;default:console.debug(`Kernel: ${i.status} (${i.id})`);break}}r.logKernelStatus=e;async function t(i,o){return i.sendShellMessage(o,!0).done}r.handleShellMessage=t;function n(i,o,a){return new Promise((h,c)=>{if(o){if(typeof requirejs=="undefined")throw new Error("requirejs not found");requirejs([o],u=>{if(u[i]===void 0){let l=`Object '${i}' not found in module '${o}'`;c(new Error(l))}else h(u[i])},c)}else a!=null&&a[i]?h(a[i]):c(new Error(`Object '${i}' not found in registry`))})}r.loadObject=n;function s(i,o){return i=Math.ceil(i),o=Math.floor(o),Math.floor(Math.random()*(o-i+1))+i}r.getRandomIntInclusive=s})(Ce||(Ce={}))});var xi=O(mt=>{"use strict";Object.defineProperty(mt,"__esModule",{value:!0});mt.KernelManager=void 0;var Gl=Ge(),Ai=ee(),Ni=Ae(),Xl=Je(),Yl=gn(),Li=Ps(),Ql=_t(),pt=class extends Xl.BaseManager{constructor(e={}){var t,n,s;super(e),this._commsOverSubshells=Ni.CommsOverSubshells.PerCommTarget,this._isReady=!1,this._kernelConnections=new Set,this._models=new Map,this._runningChanged=new Ai.Signal(this),this._connectionFailure=new Ai.Signal(this),this._kernelInfoTimeout=Li.DEFAULT_KERNEL_INFO_TIMEOUT,this._kernelAPIClient=(t=e.kernelAPIClient)!==null&&t!==void 0?t:new Yl.KernelAPIClient({serverSettings:this.serverSettings}),this._kernelSpecAPIClient=(n=e.kernelSpecAPIClient)!==null&&n!==void 0?n:new Ql.KernelSpecAPIClient({serverSettings:this.serverSettings}),this._pollModels=new Gl.Poll({auto:!1,factory:()=>this.requestRunning(),frequency:{interval:10*1e3,backoff:!0,max:300*1e3},name:"@jupyterlab/services:KernelManager#models",standby:(s=e.standby)!==null&&s!==void 0?s:"when-hidden"}),this._ready=(async()=>{await this._pollModels.start(),await this._pollModels.tick,this._isReady=!0})()}get isReady(){return this._isReady}get ready(){return this._ready}get runningChanged(){return this._runningChanged}get connectionFailure(){return this._connectionFailure}get kernelInfoTimeout(){return this._kernelInfoTimeout}set kernelInfoTimeout(e){this._kernelInfoTimeout=e}dispose(){this.isDisposed||(this._models.clear(),this._kernelConnections.forEach(e=>e.dispose()),this._pollModels.dispose(),super.dispose())}connectTo(e){var t;let{id:n}=e.model,s=(t=e.handleComms)!==null&&t!==void 0?t:!0;if(e.handleComms===void 0){for(let o of this._kernelConnections)if(o.id===n&&o.handleComms){s=!1;break}}e.commsOverSubshells=this._commsOverSubshells;let i=new Li.KernelConnection({handleComms:s,...e,serverSettings:this.serverSettings,kernelAPIClient:this._kernelAPIClient,kernelSpecAPIClient:this._kernelSpecAPIClient,kernelInfoTimeout:this._kernelInfoTimeout});return this._onStarted(i),this._models.has(n)||this.refreshRunning().catch(()=>{}),i}running(){return this._models.values()}get runningCount(){return this._models.size}get commsOverSubshells(){return this._commsOverSubshells}set commsOverSubshells(e){this._commsOverSubshells=e;for(let t of this._kernelConnections)t.commsOverSubshells=e}async refreshRunning(){await this._pollModels.refresh(),await this._pollModels.tick}async startNew(e={},t={}){let n=await this._kernelAPIClient.startNew(e);return this.connectTo({...t,model:n})}async shutdown(e){await this._kernelAPIClient.shutdown(e),await this.refreshRunning()}async shutdownAll(){await this.refreshRunning(),await Promise.all([...this._models.keys()].map(e=>this._kernelAPIClient.shutdown(e))),await this.refreshRunning()}async findById(e){return this._models.has(e)?this._models.get(e):(await this.refreshRunning(),this._models.get(e))}async requestRunning(){var e,t;let n;try{n=await this._kernelAPIClient.listRunning()}catch(s){throw(s instanceof Ni.ServerConnection.NetworkError||((e=s.response)===null||e===void 0?void 0:e.status)===503||((t=s.response)===null||t===void 0?void 0:t.status)===424)&&this._connectionFailure.emit(s),s}this.isDisposed||this._models.size===n.length&&n.every(s=>{let i=this._models.get(s.id);return i?i.connections===s.connections&&i.execution_state===s.execution_state&&i.last_activity===s.last_activity&&i.name===s.name&&i.reason===s.reason&&i.traceback===s.traceback:!1})||(this._models=new Map(n.map(s=>[s.id,s])),this._kernelConnections.forEach(s=>{this._models.has(s.id)||s.handleShutdown()}),this._runningChanged.emit(n))}_onStarted(e){this._kernelConnections.add(e),e.statusChanged.connect(this._onStatusChanged,this),e.disposed.connect(this._onDisposed,this)}_onDisposed(e){this._kernelConnections.delete(e),this.refreshRunning().catch(()=>{})}_onStatusChanged(e,t){t==="dead"&&this.refreshRunning().catch(()=>{})}};mt.KernelManager=pt;(function(r){class e extends r{constructor(){super(...arguments),this._readyPromise=new Promise(()=>{})}get isActive(){return!1}get parentReady(){return super.ready}async startNew(n={},s={}){return Promise.reject(new Error("Not implemented in no-op Kernel Manager"))}connectTo(n){throw new Error("Not implemented in no-op Kernel Manager")}async shutdown(n){return Promise.reject(new Error("Not implemented in no-op Kernel Manager"))}get ready(){return this.parentReady.then(()=>this._readyPromise)}async requestRunning(){return Promise.resolve()}}r.NoopManager=e})(pt||(mt.KernelManager=pt={}))});var Es=O(H=>{"use strict";var Fi=H&&H.__createBinding||(Object.create?function(r,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,n,s)}:function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]}),Zl=H&&H.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),Ms=H&&H.__importStar||function(){var r=function(e){return r=Object.getOwnPropertyNames||function(t){var n=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[n.length]=s);return n},r(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n=r(e),s=0;s<n.length;s++)n[s]!=="default"&&Fi(t,e,n[s]);return Zl(t,e),t}}(),ec=H&&H.__exportStar||function(r,e){for(var t in r)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&Fi(e,r,t)};Object.defineProperty(H,"__esModule",{value:!0});H.CommsOverSubshells=H.KernelConnection=H.KernelAPI=H.KernelMessage=H.Kernel=void 0;var tc=vs();Object.defineProperty(H,"CommsOverSubshells",{enumerable:!0,get:function(){return tc.CommsOverSubshells}});var nc=Ms(mi());H.Kernel=nc;var sc=Ms(et());H.KernelMessage=sc;var rc=Ms(gn());H.KernelAPI=rc;var ic=Ps();Object.defineProperty(H,"KernelConnection",{enumerable:!0,get:function(){return ic.KernelConnection}});ec(xi(),H)});var zi=O(Ki=>{"use strict";Object.defineProperty(Ki,"__esModule",{value:!0})});var Bi=O(vn=>{"use strict";Object.defineProperty(vn,"__esModule",{value:!0});vn.KernelSpecManager=void 0;var oc=X(),ac=Ge(),Vi=ee(),lc=Je(),cc=_t(),Is=class extends lc.BaseManager{constructor(e={}){var t,n;super(e),this._isReady=!1,this._connectionFailure=new Vi.Signal(this),this._specs=null,this._specsChanged=new Vi.Signal(this),this._kernelSpecAPIClient=(t=e.kernelSpecAPIClient)!==null&&t!==void 0?t:new cc.KernelSpecAPIClient({serverSettings:this.serverSettings}),this._ready=Promise.all([this.requestSpecs()]).then(s=>{}).catch(s=>{}).then(()=>{this.isDisposed||(this._isReady=!0)}),this._pollSpecs=new ac.Poll({auto:!1,factory:()=>this.requestSpecs(),frequency:{interval:61*1e3,backoff:!0,max:300*1e3},name:"@jupyterlab/services:KernelSpecManager#specs",standby:(n=e.standby)!==null&&n!==void 0?n:"when-hidden"}),this.ready.then(()=>{this._pollSpecs.start()})}get isReady(){return this._isReady}get ready(){return this._ready}get specs(){return this._specs}get specsChanged(){return this._specsChanged}get connectionFailure(){return this._connectionFailure}dispose(){this._pollSpecs.dispose(),super.dispose()}async refreshSpecs(){await this._pollSpecs.refresh(),await this._pollSpecs.tick}async requestSpecs(){let e=await this._kernelSpecAPIClient.get();this.isDisposed||oc.JSONExt.deepEqual(e,this._specs)||(this._specs=e,this._specsChanged.emit(e))}};vn.KernelSpecManager=Is});var Os=O(fe=>{"use strict";var $i=fe&&fe.__createBinding||(Object.create?function(r,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,n,s)}:function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]}),uc=fe&&fe.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),Wi=fe&&fe.__importStar||function(){var r=function(e){return r=Object.getOwnPropertyNames||function(t){var n=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[n.length]=s);return n},r(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n=r(e),s=0;s<n.length;s++)n[s]!=="default"&&$i(t,e,n[s]);return uc(t,e),t}}(),hc=fe&&fe.__exportStar||function(r,e){for(var t in r)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&$i(e,r,t)};Object.defineProperty(fe,"__esModule",{value:!0});fe.KernelSpecAPI=fe.KernelSpec=void 0;var dc=Wi(zi());fe.KernelSpec=dc;var fc=Wi(_t());fe.KernelSpecAPI=fc;hc(Bi(),fe)});var Hi=O(yn=>{"use strict";Object.defineProperty(yn,"__esModule",{value:!0});yn.BuildManager=void 0;var Rs=te(),$e=he(),_c="api/build",ks=class{constructor(e={}){var t;this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:$e.ServerConnection.makeSettings()}get isAvailable(){return Rs.PageConfig.getOption("buildAvailable").toLowerCase()==="true"}get shouldCheck(){return Rs.PageConfig.getOption("buildCheck").toLowerCase()==="true"}getStatus(){let{_url:e,serverSettings:t}=this;return $e.ServerConnection.makeRequest(e,{},t).then(s=>{if(s.status!==200)throw new $e.ServerConnection.ResponseError(s);return s.json()}).then(s=>{if(typeof s.status!="string")throw new Error("Invalid data");if(typeof s.message!="string")throw new Error("Invalid data");return s})}build(){let{_url:e,serverSettings:t}=this,n={method:"POST"};return $e.ServerConnection.makeRequest(e,n,t).then(i=>{if(i.status===400)throw new $e.ServerConnection.ResponseError(i,"Build aborted");if(i.status!==200){let o=`Build failed with ${i.status}.
3
+ `);else{h=new t(c);let m=u.indexOf(r.CODE_BLOCK_MARKER),v=u.lastIndexOf(r.CODE_BLOCK_MARKER);m!==v&&(h.code=u.substring(m+r.CODE_BLOCK_MARKER.length,v),h.endLine=c,a.push(h),h=null)}}return a}r.findMarkdownCodeBlocks=s})(br||(Bt.MarkdownCodeBlocks=br={}))});var Ir=O((Lu,Er)=>{"use strict";function wa(r,e){var t=r;e.slice(0,-1).forEach(function(s){t=t[s]||{}});var n=e[e.length-1];return n in t}function Pr(r){return typeof r=="number"||/^0x[0-9a-f]+$/i.test(r)?!0:/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(r)}function Mr(r,e){return e==="constructor"&&typeof r[e]=="function"||e==="__proto__"}Er.exports=function(r,e){e||(e={});var t={bools:{},strings:{},unknownFn:null};typeof e.unknown=="function"&&(t.unknownFn=e.unknown),typeof e.boolean=="boolean"&&e.boolean?t.allBools=!0:[].concat(e.boolean).filter(Boolean).forEach(function(w){t.bools[w]=!0});var n={};function s(w){return n[w].some(function(k){return t.bools[k]})}Object.keys(e.alias||{}).forEach(function(w){n[w]=[].concat(e.alias[w]),n[w].forEach(function(k){n[k]=[w].concat(n[w].filter(function(N){return k!==N}))})}),[].concat(e.string).filter(Boolean).forEach(function(w){t.strings[w]=!0,n[w]&&[].concat(n[w]).forEach(function(k){t.strings[k]=!0})});var i=e.default||{},o={_:[]};function a(w,k){return t.allBools&&/^--[^=]+$/.test(k)||t.strings[w]||t.bools[w]||n[w]}function h(w,k,N){for(var j=w,R=0;R<k.length-1;R++){var U=k[R];if(Mr(j,U))return;j[U]===void 0&&(j[U]={}),(j[U]===Object.prototype||j[U]===Number.prototype||j[U]===String.prototype)&&(j[U]={}),j[U]===Array.prototype&&(j[U]=[]),j=j[U]}var f=k[k.length-1];Mr(j,f)||((j===Object.prototype||j===Number.prototype||j===String.prototype)&&(j={}),j===Array.prototype&&(j=[]),j[f]===void 0||t.bools[f]||typeof j[f]=="boolean"?j[f]=N:Array.isArray(j[f])?j[f].push(N):j[f]=[j[f],N])}function c(w,k,N){if(!(N&&t.unknownFn&&!a(w,N)&&t.unknownFn(N)===!1)){var j=!t.strings[w]&&Pr(k)?Number(k):k;h(o,w.split("."),j),(n[w]||[]).forEach(function(R){h(o,R.split("."),j)})}}Object.keys(t.bools).forEach(function(w){c(w,i[w]===void 0?!1:i[w])});var u=[];r.indexOf("--")!==-1&&(u=r.slice(r.indexOf("--")+1),r=r.slice(0,r.indexOf("--")));for(var l=0;l<r.length;l++){var d=r[l],m,v;if(/^--.+=/.test(d)){var T=d.match(/^--([^=]+)=([\s\S]*)$/);m=T[1];var E=T[2];t.bools[m]&&(E=E!=="false"),c(m,E,d)}else if(/^--no-.+/.test(d))m=d.match(/^--no-(.+)/)[1],c(m,!1,d);else if(/^--.+/.test(d))m=d.match(/^--(.+)/)[1],v=r[l+1],v!==void 0&&!/^(-|--)[^-]/.test(v)&&!t.bools[m]&&!t.allBools&&(!n[m]||!s(m))?(c(m,v,d),l+=1):/^(true|false)$/.test(v)?(c(m,v==="true",d),l+=1):c(m,t.strings[m]?"":!0,d);else if(/^-[^-]+/.test(d)){for(var q=d.slice(1,-1).split(""),A=!1,C=0;C<q.length;C++){if(v=d.slice(C+2),v==="-"){c(q[C],v,d);continue}if(/[A-Za-z]/.test(q[C])&&v[0]==="="){c(q[C],v.slice(1),d),A=!0;break}if(/[A-Za-z]/.test(q[C])&&/-?\d+(\.\d*)?(e-?\d+)?$/.test(v)){c(q[C],v,d),A=!0;break}if(q[C+1]&&q[C+1].match(/\W/)){c(q[C],d.slice(C+2),d),A=!0;break}else c(q[C],t.strings[q[C]]?"":!0,d)}m=d.slice(-1)[0],!A&&m!=="-"&&(r[l+1]&&!/^(-|--)[^-]/.test(r[l+1])&&!t.bools[m]&&(!n[m]||!s(m))?(c(m,r[l+1],d),l+=1):r[l+1]&&/^(true|false)$/.test(r[l+1])?(c(m,r[l+1]==="true",d),l+=1):c(m,t.strings[m]?"":!0,d))}else if((!t.unknownFn||t.unknownFn(d)!==!1)&&o._.push(t.strings._||!Pr(d)?d:Number(d)),e.stopEarly){o._.push.apply(o._,r.slice(l+1));break}}return Object.keys(i).forEach(function(w){wa(o,w.split("."))||(h(o,w.split("."),i[w]),(n[w]||[]).forEach(function(k){h(o,k.split("."),i[w])}))}),e["--"]?o["--"]=u.slice():u.forEach(function(w){o._.push(w)}),o}});var $t=O((xu,Rr)=>{"use strict";function Oe(r){if(typeof r!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(r))}function Or(r,e){for(var t="",n=0,s=-1,i=0,o,a=0;a<=r.length;++a){if(a<r.length)o=r.charCodeAt(a);else{if(o===47)break;o=47}if(o===47){if(!(s===a-1||i===1))if(s!==a-1&&i===2){if(t.length<2||n!==2||t.charCodeAt(t.length-1)!==46||t.charCodeAt(t.length-2)!==46){if(t.length>2){var h=t.lastIndexOf("/");if(h!==t.length-1){h===-1?(t="",n=0):(t=t.slice(0,h),n=t.length-1-t.lastIndexOf("/")),s=a,i=0;continue}}else if(t.length===2||t.length===1){t="",n=0,s=a,i=0;continue}}e&&(t.length>0?t+="/..":t="..",n=2)}else t.length>0?t+="/"+r.slice(s+1,a):t=r.slice(s+1,a),n=a-s-1;s=a,i=0}else o===46&&i!==-1?++i:i=-1}return t}function Sa(r,e){var t=e.dir||e.root,n=e.base||(e.name||"")+(e.ext||"");return t?t===e.root?t+n:t+r+n:n}var Qe={resolve:function(){for(var e="",t=!1,n,s=arguments.length-1;s>=-1&&!t;s--){var i;s>=0?i=arguments[s]:(n===void 0&&(n=process.cwd()),i=n),Oe(i),i.length!==0&&(e=i+"/"+e,t=i.charCodeAt(0)===47)}return e=Or(e,!t),t?e.length>0?"/"+e:"/":e.length>0?e:"."},normalize:function(e){if(Oe(e),e.length===0)return".";var t=e.charCodeAt(0)===47,n=e.charCodeAt(e.length-1)===47;return e=Or(e,!t),e.length===0&&!t&&(e="."),e.length>0&&n&&(e+="/"),t?"/"+e:e},isAbsolute:function(e){return Oe(e),e.length>0&&e.charCodeAt(0)===47},join:function(){if(arguments.length===0)return".";for(var e,t=0;t<arguments.length;++t){var n=arguments[t];Oe(n),n.length>0&&(e===void 0?e=n:e+="/"+n)}return e===void 0?".":Qe.normalize(e)},relative:function(e,t){if(Oe(e),Oe(t),e===t||(e=Qe.resolve(e),t=Qe.resolve(t),e===t))return"";for(var n=1;n<e.length&&e.charCodeAt(n)===47;++n);for(var s=e.length,i=s-n,o=1;o<t.length&&t.charCodeAt(o)===47;++o);for(var a=t.length,h=a-o,c=i<h?i:h,u=-1,l=0;l<=c;++l){if(l===c){if(h>c){if(t.charCodeAt(o+l)===47)return t.slice(o+l+1);if(l===0)return t.slice(o+l)}else i>c&&(e.charCodeAt(n+l)===47?u=l:l===0&&(u=0));break}var d=e.charCodeAt(n+l),m=t.charCodeAt(o+l);if(d!==m)break;d===47&&(u=l)}var v="";for(l=n+u+1;l<=s;++l)(l===s||e.charCodeAt(l)===47)&&(v.length===0?v+="..":v+="/..");return v.length>0?v+t.slice(o+u):(o+=u,t.charCodeAt(o)===47&&++o,t.slice(o))},_makeLong:function(e){return e},dirname:function(e){if(Oe(e),e.length===0)return".";for(var t=e.charCodeAt(0),n=t===47,s=-1,i=!0,o=e.length-1;o>=1;--o)if(t=e.charCodeAt(o),t===47){if(!i){s=o;break}}else i=!1;return s===-1?n?"/":".":n&&s===1?"//":e.slice(0,s)},basename:function(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');Oe(e);var n=0,s=-1,i=!0,o;if(t!==void 0&&t.length>0&&t.length<=e.length){if(t.length===e.length&&t===e)return"";var a=t.length-1,h=-1;for(o=e.length-1;o>=0;--o){var c=e.charCodeAt(o);if(c===47){if(!i){n=o+1;break}}else h===-1&&(i=!1,h=o+1),a>=0&&(c===t.charCodeAt(a)?--a===-1&&(s=o):(a=-1,s=h))}return n===s?s=h:s===-1&&(s=e.length),e.slice(n,s)}else{for(o=e.length-1;o>=0;--o)if(e.charCodeAt(o)===47){if(!i){n=o+1;break}}else s===-1&&(i=!1,s=o+1);return s===-1?"":e.slice(n,s)}},extname:function(e){Oe(e);for(var t=-1,n=0,s=-1,i=!0,o=0,a=e.length-1;a>=0;--a){var h=e.charCodeAt(a);if(h===47){if(!i){n=a+1;break}continue}s===-1&&(i=!1,s=a+1),h===46?t===-1?t=a:o!==1&&(o=1):t!==-1&&(o=-1)}return t===-1||s===-1||o===0||o===1&&t===s-1&&t===n+1?"":e.slice(t,s)},format:function(e){if(e===null||typeof e!="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof e);return Sa("/",e)},parse:function(e){Oe(e);var t={root:"",dir:"",base:"",ext:"",name:""};if(e.length===0)return t;var n=e.charCodeAt(0),s=n===47,i;s?(t.root="/",i=1):i=0;for(var o=-1,a=0,h=-1,c=!0,u=e.length-1,l=0;u>=i;--u){if(n=e.charCodeAt(u),n===47){if(!c){a=u+1;break}continue}h===-1&&(c=!1,h=u+1),n===46?o===-1?o=u:l!==1&&(l=1):o!==-1&&(l=-1)}return o===-1||h===-1||l===0||l===1&&o===h-1&&o===a+1?h!==-1&&(a===0&&s?t.base=t.name=e.slice(1,h):t.base=t.name=e.slice(a,h)):(a===0&&s?(t.name=e.slice(1,o),t.base=e.slice(1,h)):(t.name=e.slice(a,o),t.base=e.slice(a,h)),t.ext=e.slice(o,h)),a>0?t.dir=e.slice(0,a-1):s&&(t.dir="/"),t},sep:"/",delimiter:":",win32:null,posix:null};Qe.posix=Qe;Rr.exports=Qe});var Dr=O((Fu,kr)=>{"use strict";kr.exports=function(e,t){if(t=t.split(":")[0],e=+e,!e)return!1;switch(t){case"http":case"ws":return e!==80;case"https":case"wss":return e!==443;case"ftp":return e!==21;case"gopher":return e!==70;case"file":return!1}return e!==0}});var jr=O(Qn=>{"use strict";var ba=Object.prototype.hasOwnProperty,Ca;function Tr(r){try{return decodeURIComponent(r.replace(/\+/g," "))}catch{return null}}function qr(r){try{return encodeURIComponent(r)}catch{return null}}function Pa(r){for(var e=/([^=?#&]+)=?([^&]*)/g,t={},n;n=e.exec(r);){var s=Tr(n[1]),i=Tr(n[2]);s===null||i===null||s in t||(t[s]=i)}return t}function Ma(r,e){e=e||"";var t=[],n,s;typeof e!="string"&&(e="?");for(s in r)if(ba.call(r,s)){if(n=r[s],!n&&(n===null||n===Ca||isNaN(n))&&(n=""),s=qr(s),n=qr(n),s===null||n===null)continue;t.push(s+"="+n)}return t.length?e+t.join("&"):""}Qn.stringify=Ma;Qn.parse=Pa});var zr=O((zu,Kr)=>{"use strict";var Ar=Dr(),Wt=jr(),Ea=/^[\x00-\x20\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/,Nr=/[\n\r\t]/g,Ia=/^[A-Za-z][A-Za-z0-9+-.]*:\/\//,Lr=/:\d+$/,Oa=/^([a-z][a-z0-9.+-]*:)?(\/\/)?([\\/]+)?([\S\s]*)/i,Ra=/^[a-zA-Z]:/;function es(r){return(r||"").toString().replace(Ea,"")}var Zn=[["#","hash"],["?","query"],function(e,t){return Re(t.protocol)?e.replace(/\\/g,"/"):e},["/","pathname"],["@","auth",1],[NaN,"host",void 0,1,1],[/:(\d*)$/,"port",void 0,1],[NaN,"hostname",void 0,1,1]],Ur={hash:1,query:1};function xr(r){var e;typeof window!="undefined"?e=window:typeof global!="undefined"?e=global:typeof self!="undefined"?e=self:e={};var t=e.location||{};r=r||t;var n={},s=typeof r,i;if(r.protocol==="blob:")n=new ke(unescape(r.pathname),{});else if(s==="string"){n=new ke(r,{});for(i in Ur)delete n[i]}else if(s==="object"){for(i in r)i in Ur||(n[i]=r[i]);n.slashes===void 0&&(n.slashes=Ia.test(r.href))}return n}function Re(r){return r==="file:"||r==="ftp:"||r==="http:"||r==="https:"||r==="ws:"||r==="wss:"}function Fr(r,e){r=es(r),r=r.replace(Nr,""),e=e||{};var t=Oa.exec(r),n=t[1]?t[1].toLowerCase():"",s=!!t[2],i=!!t[3],o=0,a;return s?i?(a=t[2]+t[3]+t[4],o=t[2].length+t[3].length):(a=t[2]+t[4],o=t[2].length):i?(a=t[3]+t[4],o=t[3].length):a=t[4],n==="file:"?o>=2&&(a=a.slice(2)):Re(n)?a=t[4]:n?s&&(a=a.slice(2)):o>=2&&Re(e.protocol)&&(a=t[4]),{protocol:n,slashes:s||Re(n),slashesCount:o,rest:a}}function ka(r,e){if(r==="")return e;for(var t=(e||"/").split("/").slice(0,-1).concat(r.split("/")),n=t.length,s=t[n-1],i=!1,o=0;n--;)t[n]==="."?t.splice(n,1):t[n]===".."?(t.splice(n,1),o++):o&&(n===0&&(i=!0),t.splice(n,1),o--);return i&&t.unshift(""),(s==="."||s==="..")&&t.push(""),t.join("/")}function ke(r,e,t){if(r=es(r),r=r.replace(Nr,""),!(this instanceof ke))return new ke(r,e,t);var n,s,i,o,a,h,c=Zn.slice(),u=typeof e,l=this,d=0;for(u!=="object"&&u!=="string"&&(t=e,e=null),t&&typeof t!="function"&&(t=Wt.parse),e=xr(e),s=Fr(r||"",e),n=!s.protocol&&!s.slashes,l.slashes=s.slashes||n&&e.slashes,l.protocol=s.protocol||e.protocol||"",r=s.rest,(s.protocol==="file:"&&(s.slashesCount!==2||Ra.test(r))||!s.slashes&&(s.protocol||s.slashesCount<2||!Re(l.protocol)))&&(c[3]=[/(.*)/,"pathname"]);d<c.length;d++){if(o=c[d],typeof o=="function"){r=o(r,l);continue}i=o[0],h=o[1],i!==i?l[h]=r:typeof i=="string"?(a=i==="@"?r.lastIndexOf(i):r.indexOf(i),~a&&(typeof o[2]=="number"?(l[h]=r.slice(0,a),r=r.slice(a+o[2])):(l[h]=r.slice(a),r=r.slice(0,a)))):(a=i.exec(r))&&(l[h]=a[1],r=r.slice(0,a.index)),l[h]=l[h]||n&&o[3]&&e[h]||"",o[4]&&(l[h]=l[h].toLowerCase())}t&&(l.query=t(l.query)),n&&e.slashes&&l.pathname.charAt(0)!=="/"&&(l.pathname!==""||e.pathname!=="")&&(l.pathname=ka(l.pathname,e.pathname)),l.pathname.charAt(0)!=="/"&&Re(l.protocol)&&(l.pathname="/"+l.pathname),Ar(l.port,l.protocol)||(l.host=l.hostname,l.port=""),l.username=l.password="",l.auth&&(a=l.auth.indexOf(":"),~a?(l.username=l.auth.slice(0,a),l.username=encodeURIComponent(decodeURIComponent(l.username)),l.password=l.auth.slice(a+1),l.password=encodeURIComponent(decodeURIComponent(l.password))):l.username=encodeURIComponent(decodeURIComponent(l.auth)),l.auth=l.password?l.username+":"+l.password:l.username),l.origin=l.protocol!=="file:"&&Re(l.protocol)&&l.host?l.protocol+"//"+l.host:"null",l.href=l.toString()}function Da(r,e,t){var n=this;switch(r){case"query":typeof e=="string"&&e.length&&(e=(t||Wt.parse)(e)),n[r]=e;break;case"port":n[r]=e,Ar(e,n.protocol)?e&&(n.host=n.hostname+":"+e):(n.host=n.hostname,n[r]="");break;case"hostname":n[r]=e,n.port&&(e+=":"+n.port),n.host=e;break;case"host":n[r]=e,Lr.test(e)?(e=e.split(":"),n.port=e.pop(),n.hostname=e.join(":")):(n.hostname=e,n.port="");break;case"protocol":n.protocol=e.toLowerCase(),n.slashes=!t;break;case"pathname":case"hash":if(e){var s=r==="pathname"?"/":"#";n[r]=e.charAt(0)!==s?s+e:e}else n[r]=e;break;case"username":case"password":n[r]=encodeURIComponent(e);break;case"auth":var i=e.indexOf(":");~i?(n.username=e.slice(0,i),n.username=encodeURIComponent(decodeURIComponent(n.username)),n.password=e.slice(i+1),n.password=encodeURIComponent(decodeURIComponent(n.password))):n.username=encodeURIComponent(decodeURIComponent(e))}for(var o=0;o<Zn.length;o++){var a=Zn[o];a[4]&&(n[a[1]]=n[a[1]].toLowerCase())}return n.auth=n.password?n.username+":"+n.password:n.username,n.origin=n.protocol!=="file:"&&Re(n.protocol)&&n.host?n.protocol+"//"+n.host:"null",n.href=n.toString(),n}function Ta(r){(!r||typeof r!="function")&&(r=Wt.stringify);var e,t=this,n=t.host,s=t.protocol;s&&s.charAt(s.length-1)!==":"&&(s+=":");var i=s+(t.protocol&&t.slashes||Re(t.protocol)?"//":"");return t.username?(i+=t.username,t.password&&(i+=":"+t.password),i+="@"):t.password?(i+=":"+t.password,i+="@"):t.protocol!=="file:"&&Re(t.protocol)&&!n&&t.pathname!=="/"&&(i+="@"),(n[n.length-1]===":"||Lr.test(t.hostname)&&!t.port)&&(n+=":"),i+=n+t.pathname,e=typeof t.query=="object"?r(t.query):t.query,e&&(i+=e.charAt(0)!=="?"?"?"+e:e),t.hash&&(i+=t.hash),i}ke.prototype={set:Da,toString:Ta};ke.extractProtocol=Fr;ke.location=xr;ke.trimLeft=es;ke.qs=Wt;Kr.exports=ke});var ts=O(Ze=>{"use strict";var qa=Ze&&Ze.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(Ze,"__esModule",{value:!0});Ze.URLExt=void 0;var ja=$t(),Ht=qa(zr()),Vr;(function(r){function e(c){if(typeof document!="undefined"&&document){let u=document.createElement("a");return u.href=c,u}return(0,Ht.default)(c)}r.parse=e;function t(c){return(0,Ht.default)(c).hostname}r.getHostName=t;function n(c){return c&&e(c).toString()}r.normalize=n;function s(...c){let u=(0,Ht.default)(c[0],{}),l=u.protocol===""&&u.slashes;l&&(u=(0,Ht.default)(c[0],"https:"+c[0]));let d=`${l?"":u.protocol}${u.slashes?"//":""}${u.auth}${u.auth?"@":""}${u.host}`,m=ja.posix.join(`${d&&u.pathname[0]!=="/"?"/":""}${u.pathname}`,...c.slice(1));return`${d}${m==="."?"":m}`}r.join=s;function i(c){return s(...c.split("/").map(encodeURIComponent))}r.encodeParts=i;function o(c){let u=Object.keys(c).filter(l=>l.length>0);return u.length?"?"+u.map(l=>{let d=encodeURIComponent(String(c[l]));return l+(d?"="+d:"")}).join("&"):""}r.objectToQueryString=o;function a(c){return c.replace(/^\?/,"").split("&").reduce((u,l)=>{let[d,m]=l.split("=");return d.length>0&&(u[d]=decodeURIComponent(m||"")),u},{})}r.queryStringToObject=a;function h(c,u=!1){let{protocol:l}=e(c);return(!l||c.toLowerCase().indexOf(l)!==0)&&(u?c.indexOf("//")!==0:c.indexOf("/")!==0)}r.isLocal=h})(Vr||(Ze.URLExt=Vr={}))});var Br=O((exports,module)=>{"use strict";var __importDefault=exports&&exports.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(exports,"__esModule",{value:!0});exports.PageConfig=void 0;exports.compareVersions=compareVersions;var coreutils_1=X(),minimist_1=__importDefault(Ir()),url_1=ts(),PageConfig;(function(PageConfig){function getOption(name){if(configData)return configData[name]||getBodyData(name);configData=Object.create(null);let found=!1;if(typeof document!="undefined"&&document){let r=document.getElementById("jupyter-config-data");r&&(configData=JSON.parse(r.textContent||""),found=!0)}if(!found&&typeof process!="undefined"&&process.argv)try{let cli=(0,minimist_1.default)(process.argv.slice(2)),path=$t(),fullPath="";"jupyter-config-data"in cli?fullPath=path.resolve(cli["jupyter-config-data"]):"JUPYTER_CONFIG_DATA"in process.env&&(fullPath=path.resolve(process.env.JUPYTER_CONFIG_DATA)),fullPath&&(configData=eval("require")(fullPath))}catch(r){console.error(r)}if(!coreutils_1.JSONExt.isObject(configData))configData=Object.create(null);else for(let r in configData)typeof configData[r]!="string"&&(configData[r]=JSON.stringify(configData[r]));return configData[name]||getBodyData(name)}PageConfig.getOption=getOption;function setOption(r,e){let t=getOption(r);return configData[r]=e,t}PageConfig.setOption=setOption;function getBaseUrl(){return url_1.URLExt.normalize(getOption("baseUrl")||"/")}PageConfig.getBaseUrl=getBaseUrl;function getTreeUrl(){return url_1.URLExt.join(getBaseUrl(),getOption("treeUrl"))}PageConfig.getTreeUrl=getTreeUrl;function getShareUrl(){return url_1.URLExt.normalize(getOption("shareUrl")||getBaseUrl())}PageConfig.getShareUrl=getShareUrl;function getTreeShareUrl(){return url_1.URLExt.normalize(url_1.URLExt.join(getShareUrl(),getOption("treeUrl")))}PageConfig.getTreeShareUrl=getTreeShareUrl;function getUrl(r){var e,t,n;let s=r.toShare?getShareUrl():getBaseUrl(),i=(e=r.mode)!==null&&e!==void 0?e:getOption("mode"),o=(t=r.workspace)!==null&&t!==void 0?t:getOption("workspace"),a=i==="single-document"?"doc":"lab";s=url_1.URLExt.join(s,a),o!==PageConfig.defaultWorkspace&&(s=url_1.URLExt.join(s,"workspaces",encodeURIComponent(o)));let h=(n=r.treePath)!==null&&n!==void 0?n:getOption("treePath");return h&&(s=url_1.URLExt.join(s,"tree",url_1.URLExt.encodeParts(h))),s}PageConfig.getUrl=getUrl,PageConfig.defaultWorkspace="default";function getWsUrl(r){let e=getOption("wsUrl");if(!e){if(r=r?url_1.URLExt.normalize(r):getBaseUrl(),r.indexOf("http")!==0)return"";e="ws"+r.slice(4)}return url_1.URLExt.normalize(e)}PageConfig.getWsUrl=getWsUrl;function getNBConvertURL({path:r,format:e,download:t}){let n=url_1.URLExt.encodeParts(r),s=url_1.URLExt.join(getBaseUrl(),"nbconvert",e,n);return t?s+"?download=true":s}PageConfig.getNBConvertURL=getNBConvertURL;function getToken(){return getOption("token")||getBodyData("jupyterApiToken")}PageConfig.getToken=getToken;function getNotebookVersion(){let r=getOption("notebookVersion");return r===""?[0,0,0]:JSON.parse(r)}PageConfig.getNotebookVersion=getNotebookVersion;let configData=null;function getBodyData(r){if(typeof document=="undefined"||!document.body)return"";let e=document.body.dataset[r];return typeof e=="undefined"?"":decodeURIComponent(e)}let Extension;(function(r){function e(s){try{let i=getOption(s);if(i)return JSON.parse(i)}catch(i){console.warn(`Unable to parse ${s}.`,i)}return[]}r.deferred=e("deferredExtensions"),r.disabled=e("disabledExtensions");function t(s){let i=s.indexOf(":"),o="";return i!==-1&&(o=s.slice(0,i)),r.deferred.some(a=>a===s||o&&a===o)}r.isDeferred=t;function n(s){let i=s.indexOf(":"),o="";return i!==-1&&(o=s.slice(0,i)),r.disabled.some(a=>a===s||o&&a===o)}r.isDisabled=n})(Extension=PageConfig.Extension||(PageConfig.Extension={}))})(PageConfig||(exports.PageConfig=PageConfig={}));function compareVersions(r,e){for(let t=0;t<3;t++)if(r[t]!==e[t])return r[t]-e[t];return 0}});var Wr=O(Jt=>{"use strict";Object.defineProperty(Jt,"__esModule",{value:!0});Jt.PathExt=void 0;var Le=$t(),$r;(function(r){function e(...l){let d=Le.posix.join(...l);return d==="."?"":u(d)}r.join=e;function t(...l){let d=Le.posix.join(...l);return d==="."?"":d}r.joinWithLeadingSlash=t;function n(l,d){return Le.posix.basename(l,d)}r.basename=n;function s(l){let d=u(Le.posix.dirname(l));return d==="."?"":d}r.dirname=s;function i(l){return Le.posix.extname(l)}r.extname=i;function o(l){return l===""?"":u(Le.posix.normalize(l))}r.normalize=o;function a(...l){return u(Le.posix.resolve(...l))}r.resolve=a;function h(l,d){return u(Le.posix.relative(l,d))}r.relative=h;function c(l){return l.length>0&&l.indexOf(".")!==0&&(l=`.${l}`),l}r.normalizeExtension=c;function u(l){return l.indexOf("/")===0&&(l=l.slice(1)),l}r.removeSlash=u})($r||(Jt.PathExt=$r={}))});var Hr=O(ns=>{"use strict";Object.defineProperty(ns,"__esModule",{value:!0});ns.signalToPromise=Aa;var Ua=X();function Aa(r,e){let t=new Ua.PromiseDelegate;function n(){r.disconnect(s)}function s(i,o){n(),t.resolve([i,o])}return r.connect(s),(e!=null?e:0)>0&&setTimeout(()=>{n(),t.reject(`Signal not emitted within ${e} ms.`)},e),t.promise}});var Gr=O(Gt=>{"use strict";Object.defineProperty(Gt,"__esModule",{value:!0});Gt.Text=void 0;var Jr;(function(r){let e=2>1;function t(o,a){if(!e)return o;let h=o;for(let c=0;c+1<a.length&&c<o;c++){let u=a.charCodeAt(c);if(u>=55296&&u<=56319){let l=a.charCodeAt(c+1);l>=56320&&l<=57343&&(h--,c++)}}return h}r.jsIndexToCharIndex=t;function n(o,a){if(!e)return o;let h=o;for(let c=0;c+1<a.length&&c<h;c++){let u=a.charCodeAt(c);if(u>=55296&&u<=56319){let l=a.charCodeAt(c+1);l>=56320&&l<=57343&&(h++,c++)}}return h}r.charIndexToJsIndex=n;function s(o,a=!1){return o.replace(/^(\w)|[\s-_:]+(\w)/g,function(h,c,u){return u?u.toUpperCase():a?c.toUpperCase():c.toLowerCase()})}r.camelCase=s;function i(o){return(o||"").toLowerCase().split(" ").map(a=>a.charAt(0).toUpperCase()+a.slice(1)).join(" ")}r.titleCase=i})(Jr||(Gt.Text=Jr={}))});var Yr=O(Xt=>{"use strict";Object.defineProperty(Xt,"__esModule",{value:!0});Xt.Time=void 0;var Na=[{name:"years",milliseconds:365*24*60*60*1e3},{name:"months",milliseconds:30*24*60*60*1e3},{name:"days",milliseconds:24*60*60*1e3},{name:"hours",milliseconds:60*60*1e3},{name:"minutes",milliseconds:60*1e3},{name:"seconds",milliseconds:1e3}],Xr;(function(r){function e(n,s="long"){let i=document.documentElement.lang||"en",o=new Intl.RelativeTimeFormat(i,{numeric:"auto",style:s}),a=new Date(n).getTime()-Date.now();for(let h of Na){let c=Math.ceil(a/h.milliseconds);if(c!==0)return o.format(c,h.name)}return o.format(0,"seconds")}r.formatHuman=e;function t(n){let s=document.documentElement.lang||"en";return new Intl.DateTimeFormat(s,{dateStyle:"short",timeStyle:"short"}).format(new Date(n))}r.format=t})(Xr||(Xt.Time=Xr={}))});var Qr=O(Yt=>{"use strict";Object.defineProperty(Yt,"__esModule",{value:!0});Yt.JupyterPluginRegistry=void 0;var La=X(),xa=5e3,ss=class extends La.PluginRegistry{constructor(e){var t;super(e),this._pluginData=new Map,this._expectedActivationTime=(t=e==null?void 0:e.expectedActivationTime)!==null&&t!==void 0?t:xa}registerPlugin(e){return this._pluginData.set(e.id,e),super.registerPlugin(e)}async activatePlugin(e){let t=performance.now(),n=setTimeout(()=>{console.warn(`Plugin ${e} is taking too long to activate.`)},this._expectedActivationTime);try{let s=await super.activatePlugin(e);clearTimeout(n);let o=performance.now()-t;if(o>=this._expectedActivationTime){let a=this._getDependentCount(e);console.warn(`Plugin ${e} (with ${a} dependants) took ${o.toFixed(2)}ms to activate.`)}return s}catch(s){throw clearTimeout(n),console.error(`Error activating plugin: ${e}`,s),s}}_getDependentCount(e){var t;let n=this._pluginData.get(e);if(!(n!=null&&n.provides))return 0;let s=n.provides.name,i=0;for(let[o,a]of this._pluginData.entries()){if(o===e)continue;((t=a.requires)===null||t===void 0?void 0:t.filter(c=>!!c).some(c=>c.name===s))&&i++}return i}};Yt.JupyterPluginRegistry=ss});var te=O(re=>{"use strict";var Fa=re&&re.__createBinding||(Object.create?function(r,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,n,s)}:function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]}),Me=re&&re.__exportStar||function(r,e){for(var t in r)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&Fa(e,r,t)};Object.defineProperty(re,"__esModule",{value:!0});Me(vr(),re);Me(wr(),re);Me(Sr(),re);Me(Cr(),re);Me(Br(),re);Me(Wr(),re);Me(Hr(),re);Me(Gr(),re);Me(Yr(),re);Me(ts(),re);Me(Qr(),re)});var et=O(V=>{"use strict";Object.defineProperty(V,"__esModule",{value:!0});V.supportedKernelWebSocketProtocols=void 0;V.createMessage=za;V.isStreamMsg=Va;V.isDisplayDataMsg=Ba;V.isUpdateDisplayDataMsg=$a;V.isExecuteInputMsg=Wa;V.isExecuteResultMsg=Ha;V.isErrorMsg=Ja;V.isStatusMsg=Ga;V.isClearOutputMsg=Xa;V.isDebugEventMsg=Ya;V.isCommOpenMsg=Qa;V.isCommCloseMsg=Za;V.isCommMsgMsg=el;V.isInfoRequestMsg=tl;V.isExecuteReplyMsg=nl;V.isDebugRequestMsg=sl;V.isDebugReplyMsg=rl;V.isInputRequestMsg=il;V.isInputReplyMsg=ol;var Ka=X();function za(r){var e,t,n,s,i,o;return{buffers:(e=r.buffers)!==null&&e!==void 0?e:[],channel:r.channel,content:r.content,header:{date:new Date().toISOString(),msg_id:(t=r.msgId)!==null&&t!==void 0?t:Ka.UUID.uuid4(),msg_type:r.msgType,session:r.session,username:(n=r.username)!==null&&n!==void 0?n:"",subshell_id:(s=r.subshellId)!==null&&s!==void 0?s:null,version:"5.2"},metadata:(i=r.metadata)!==null&&i!==void 0?i:{},parent_header:(o=r.parentHeader)!==null&&o!==void 0?o:{}}}function Va(r){return r.header.msg_type==="stream"}function Ba(r){return r.header.msg_type==="display_data"}function $a(r){return r.header.msg_type==="update_display_data"}function Wa(r){return r.header.msg_type==="execute_input"}function Ha(r){return r.header.msg_type==="execute_result"}function Ja(r){return r.header.msg_type==="error"}function Ga(r){return r.header.msg_type==="status"}function Xa(r){return r.header.msg_type==="clear_output"}function Ya(r){return r.header.msg_type==="debug_event"}function Qa(r){return r.header.msg_type==="comm_open"}function Za(r){return r.header.msg_type==="comm_close"}function el(r){return r.header.msg_type==="comm_msg"}function tl(r){return r.header.msg_type==="kernel_info_request"}function nl(r){return r.header.msg_type==="execute_reply"}function sl(r){return r.header.msg_type==="debug_request"}function rl(r){return r.header.msg_type==="debug_reply"}function il(r){return r.header.msg_type==="input_request"}function ol(r){return r.header.msg_type==="input_reply"}var Zr;(function(r){r.v1KernelWebsocketJupyterOrg="v1.kernel.websocket.jupyter.org"})(Zr||(V.supportedKernelWebSocketProtocols=Zr={}))});var ti=O(De=>{"use strict";var al=De&&De.__createBinding||(Object.create?function(r,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,n,s)}:function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]}),ll=De&&De.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),cl=De&&De.__importStar||function(){var r=function(e){return r=Object.getOwnPropertyNames||function(t){var n=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[n.length]=s);return n},r(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n=r(e),s=0;s<n.length;s++)n[s]!=="default"&&al(t,e,n[s]);return ll(t,e),t}}();Object.defineProperty(De,"__esModule",{value:!0});De.serialize=ul;De.deserialize=hl;var ei=cl(et());function ul(r,e=""){switch(e){case ei.supportedKernelWebSocketProtocols.v1KernelWebsocketJupyterOrg:return tt.serializeV1KernelWebsocketJupyterOrg(r);default:return tt.serializeDefault(r)}}function hl(r,e=""){switch(e){case ei.supportedKernelWebSocketProtocols.v1KernelWebsocketJupyterOrg:return tt.deserializeV1KernelWebsocketJupyterOrg(r);default:return tt.deserializeDefault(r)}}var tt;(function(r){function e(a){let h,c=new DataView(a),u=Number(c.getBigUint64(0,!0)),l=[];for(let C=0;C<u;C++)l.push(Number(c.getBigUint64(8*(C+1),!0)));let d=new TextDecoder("utf8"),m=d.decode(a.slice(l[0],l[1])),v=JSON.parse(d.decode(a.slice(l[1],l[2]))),T=JSON.parse(d.decode(a.slice(l[2],l[3]))),E=JSON.parse(d.decode(a.slice(l[3],l[4]))),q=JSON.parse(d.decode(a.slice(l[4],l[5]))),A=[];for(let C=5;C<l.length-1;C++)A.push(new DataView(a.slice(l[C],l[C+1])));return h={channel:m,header:v,parent_header:T,metadata:E,content:q,buffers:A},h}r.deserializeV1KernelWebsocketJupyterOrg=e;function t(a){let h=JSON.stringify(a.header),c=a.parent_header==null?"{}":JSON.stringify(a.parent_header),u=JSON.stringify(a.metadata),l=JSON.stringify(a.content),d=a.buffers!==void 0?a.buffers:[],m=5+d.length+1,v=[];v.push(8*(1+m)),v.push(a.channel.length+v[v.length-1]);let T=new TextEncoder,E=T.encode(a.channel),q=T.encode(h),A=T.encode(c),C=T.encode(u),w=T.encode(l),k=new Uint8Array(E.length+q.length+A.length+C.length+w.length);k.set(E),k.set(q,E.length),k.set(A,E.length+q.length),k.set(C,E.length+q.length+A.length),k.set(w,E.length+q.length+A.length+C.length);for(let f of[q.length,A.length,C.length,w.length])v.push(f+v[v.length-1]);let N=0;for(let f of d){let y=f.byteLength;v.push(y+v[v.length-1]),N+=y}let j=new Uint8Array(8*(1+m)+k.byteLength+N),R=new ArrayBuffer(8),U=new DataView(R);U.setBigUint64(0,BigInt(m),!0),j.set(new Uint8Array(R),0);for(let f=0;f<v.length;f++)U.setBigUint64(0,BigInt(v[f]),!0),j.set(new Uint8Array(R),8*(f+1));j.set(k,v[0]);for(let f=0;f<d.length;f++){let y=d[f];j.set(new Uint8Array(ArrayBuffer.isView(y)?y.buffer:y),v[5+f])}return j.buffer}r.serializeV1KernelWebsocketJupyterOrg=t;function n(a){let h;return typeof a=="string"?h=JSON.parse(a):h=i(a),h}r.deserializeDefault=n;function s(a){var h;let c;return!((h=a.buffers)===null||h===void 0)&&h.length?c=o(a):c=JSON.stringify(a),c}r.serializeDefault=s;function i(a){let h=new DataView(a),c=h.getUint32(0),u=[];if(c<2)throw new Error("Invalid incoming Kernel Message");for(let m=1;m<=c;m++)u.push(h.getUint32(m*4));let l=new Uint8Array(a.slice(u[0],u[1])),d=JSON.parse(new TextDecoder("utf8").decode(l));d.buffers=[];for(let m=1;m<c;m++){let v=u[m],T=u[m+1]||a.byteLength;d.buffers.push(new DataView(a.slice(v,T)))}return d}function o(a){let h=[],c=[],u=new TextEncoder,l=[];a.buffers!==void 0&&(l=a.buffers,delete a.buffers);let d=u.encode(JSON.stringify(a));c.push(d.buffer);for(let E=0;E<l.length;E++){let q=l[E];c.push(ArrayBuffer.isView(q)?q.buffer:q)}let m=c.length;h.push(4*(m+1));for(let E=0;E+1<c.length;E++)h.push(h[h.length-1]+c[E].byteLength);let v=new Uint8Array(h[h.length-1]+c[c.length-1].byteLength),T=new DataView(v.buffer);T.setUint32(0,m);for(let E=0;E<h.length;E++)T.setUint32(4*(E+1),h[E]);for(let E=0;E<c.length;E++)v.set(new Uint8Array(c[E]),h[E]);return v.buffer}})(tt||(tt={}))});var ni=O(rs=>{"use strict";Object.defineProperty(rs,"__esModule",{value:!0});rs.default=WebSocket});var he=O(Zt=>{"use strict";Object.defineProperty(Zt,"__esModule",{value:!0});Zt.ServerConnection=void 0;var xe=te(),si=ti(),is;typeof window=="undefined"?is=ni():is=WebSocket;var os;(function(r){function e(i){return Qt.makeSettings(i)}r.makeSettings=e;function t(i,o,a){return Qt.handleRequest(i,o,a)}r.makeRequest=t;class n extends Error{static async create(o){try{let a=await o.json(),{message:h,traceback:c}=a;return c&&console.error(c),new n(o,h!=null?h:n._defaultMessage(o),c!=null?c:"")}catch(a){return console.debug(a),new n(o)}}constructor(o,a=n._defaultMessage(o),h=""){super(a),this.response=o,this.traceback=h}static _defaultMessage(o){return`Invalid response: ${o.status} ${o.statusText}`}}r.ResponseError=n;class s extends TypeError{constructor(o){super(o.message),this.stack=o.stack}}r.NetworkError=s})(os||(Zt.ServerConnection=os={}));var Qt;(function(r){function e(s={}){var i;let o=xe.PageConfig.getBaseUrl(),a=xe.PageConfig.getWsUrl(),h=xe.URLExt.normalize(s.baseUrl)||o,c=s.wsUrl;!c&&h===o&&(c=a),!c&&h.indexOf("http")===0&&(c="ws"+h.slice(4)),c=c!=null?c:a;let u=xe.PageConfig.getOption("appendToken").toLowerCase(),l;return u===""?l=typeof window=="undefined"||typeof process!="undefined"&&((i=process==null?void 0:process.env)===null||i===void 0?void 0:i.JEST_WORKER_ID)!==void 0||xe.URLExt.getHostName(o)!==xe.URLExt.getHostName(c):l=u==="true",{init:{cache:"no-store",credentials:"same-origin"},fetch,Headers,Request,WebSocket:is,token:xe.PageConfig.getToken(),appUrl:xe.PageConfig.getOption("appUrl"),appendToken:l,serializer:{serialize:si.serialize,deserialize:si.deserialize},...s,baseUrl:h,wsUrl:c}}r.makeSettings=e;function t(s,i,o){var a;if(s.indexOf(o.baseUrl)!==0)throw new Error("Can only be used for notebook server requests");((a=i.cache)!==null&&a!==void 0?a:o.init.cache)==="no-store"&&(s+=(/\?/.test(s)?"&":"?")+new Date().getTime());let c=new o.Request(s,{...o.init,...i}),u=!1;if(o.token&&(u=!0,c.headers.append("Authorization",`token ${o.token}`)),typeof document!="undefined"){let l=n("_xsrf");l!==void 0&&(u=!0,c.headers.append("X-XSRFToken",l))}return!c.headers.has("Content-Type")&&u&&c.headers.set("Content-Type","application/json"),o.fetch.call(null,c).catch(l=>{throw new os.NetworkError(l)})}r.handleRequest=t;function n(s){let i="";try{i=document.cookie}catch{return}let o=s+"=",a;for(let h of i.split(";")){let c=h.trim();c.startsWith(o)&&(a=c.substring(o.length))}return a}})(Qt||(Qt={}))});var Je=O(en=>{"use strict";Object.defineProperty(en,"__esModule",{value:!0});en.BaseManager=void 0;var ri=ee(),dl=he(),as=class{constructor(e){var t;this._isDisposed=!1,this._disposed=new ri.Signal(this),this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:dl.ServerConnection.makeSettings()}get disposed(){return this._disposed}get isDisposed(){return this._isDisposed}get isActive(){return!0}dispose(){this.isDisposed||(this._isDisposed=!0,this._disposed.emit(void 0),ri.Signal.clearData(this))}};en.BaseManager=as});var oi=O(Fe=>{"use strict";Object.defineProperty(Fe,"__esModule",{value:!0});Fe.ConfigWithDefaults=Fe.ConfigSection=Fe.ConfigSectionManager=void 0;var fl=te(),nt=Ae(),_l="api/config",ls=class{constructor(e){var t;this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:nt.ServerConnection.makeSettings()}async create(e){let t=new tn({...e,serverSettings:this.serverSettings});return await t.load(),t}};Fe.ConfigSectionManager=ls;var ii;(function(r){async function e(s){if(!t){let o=new tn(s);return await o.load(),o}return await t.create(s)}r.create=e;let t;function n(s){if(t)throw new Error("ConfigSectionManager already set. If you would like to create a config section, use the `IConfigSectionManager` token in a plugin.");t=s}r._setConfigSectionManager=n})(ii||(Fe.ConfigSection=ii={}));var tn=class{constructor(e){var t;this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:nt.ServerConnection.makeSettings(),this._name=e.name}get data(){return this._data}async load(){let e=await nt.ServerConnection.makeRequest(this._url,{},this.serverSettings);if(e.status!==200)throw await nt.ServerConnection.ResponseError.create(e);this._data=await e.json()}async update(e){this._data={...this._data,...e};let t={method:"PATCH",body:JSON.stringify(e)},n=await nt.ServerConnection.makeRequest(this._url,t,this.serverSettings);if(n.status!==200)throw await nt.ServerConnection.ResponseError.create(n);return this._data=await n.json(),this._data}get _url(){return fl.URLExt.join(this.serverSettings.baseUrl,_l,encodeURIComponent(this._name))}},cs=class{constructor(e){var t,n;this._className="",this._section=e.section,this._defaults=(t=e.defaults)!==null&&t!==void 0?t:{},this._className=(n=e.className)!==null&&n!==void 0?n:""}get(e){let t=this._classData();return e in t?t[e]:this._defaults[e]}set(e,t){let n={};if(n[e]=t,this._className){let s={};return s[this._className]=n,this._section.update(s)}else return this._section.update(n)}_classData(){let e=this._section.data;return this._className&&this._className in e?e[this._className]:e}};Fe.ConfigWithDefaults=cs});var ai=O(nn=>{"use strict";Object.defineProperty(nn,"__esModule",{value:!0});nn.ConnectionStatus=void 0;var us=class{constructor(){this.isConnected=!0}};nn.ConnectionStatus=us});var rn=O((sn,li)=>{(function(r,e){typeof sn=="object"&&typeof li!="undefined"?e(sn,ee()):typeof define=="function"&&define.amd?define(["exports","@lumino/signaling"],e):(r=typeof globalThis!="undefined"?globalThis:r||self,e(r.lumino_disposable={},r.lumino_signaling))})(sn,function(r,e){"use strict";class t{constructor(a){this._fn=a}get isDisposed(){return!this._fn}dispose(){if(!this._fn)return;let a=this._fn;this._fn=null,a()}}class n extends t{constructor(){super(...arguments),this._disposed=new e.Signal(this)}get disposed(){return this._disposed}dispose(){this.isDisposed||(super.dispose(),this._disposed.emit(void 0),e.Signal.clearData(this))}}class s{constructor(){this._isDisposed=!1,this._items=new Set}get isDisposed(){return this._isDisposed}dispose(){this._isDisposed||(this._isDisposed=!0,this._items.forEach(a=>{a.dispose()}),this._items.clear())}contains(a){return this._items.has(a)}add(a){this._items.add(a)}remove(a){this._items.delete(a)}clear(){this._items.clear()}}(function(o){function a(h){let c=new o;for(let u of h)c.add(u);return c}o.from=a})(s||(s={}));class i extends s{constructor(){super(...arguments),this._disposed=new e.Signal(this)}get disposed(){return this._disposed}dispose(){this.isDisposed||(super.dispose(),this._disposed.emit(void 0),e.Signal.clearData(this))}}(function(o){function a(h){let c=new o;for(let u of h)c.add(u);return c}o.from=a})(i||(i={})),r.DisposableDelegate=t,r.DisposableSet=s,r.ObservableDisposableDelegate=n,r.ObservableDisposableSet=i})});var lt=O(hs=>{"use strict";Object.defineProperty(hs,"__esModule",{value:!0});hs.validateProperty=gl;function gl(r,e,t,n=[]){if(!r.hasOwnProperty(e))throw Error(`Missing property '${e}'`);let s=r[e];if(t!==void 0){let i;switch(t){case"array":i=Array.isArray(s);break;case"object":i=typeof s!="undefined";break;default:i=typeof s===t}if(!i)throw new Error(`Property '${e}' is not of type '${t}'`);if(n.length>0){let o;switch(t){case"string":case"number":case"boolean":o=n.includes(s);break;default:o=n.findIndex(a=>a===s)>=0;break}if(!o)throw new Error(`Property '${e}' is not one of the valid values ${JSON.stringify(n)}`)}}}});var ci=O(on=>{"use strict";Object.defineProperty(on,"__esModule",{value:!0});on.validateContentsModel=pl;on.validateCheckpointModel=ml;var Te=lt();function pl(r){(0,Te.validateProperty)(r,"name","string"),(0,Te.validateProperty)(r,"path","string"),(0,Te.validateProperty)(r,"type","string"),(0,Te.validateProperty)(r,"created","string"),(0,Te.validateProperty)(r,"last_modified","string"),(0,Te.validateProperty)(r,"mimetype","object"),(0,Te.validateProperty)(r,"content","object"),(0,Te.validateProperty)(r,"format","object")}function ml(r){(0,Te.validateProperty)(r,"id","string"),(0,Te.validateProperty)(r,"last_modified","string")}});var _s=O(ne=>{"use strict";var vl=ne&&ne.__createBinding||(Object.create?function(r,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,n,s)}:function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]}),yl=ne&&ne.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),wl=ne&&ne.__importStar||function(){var r=function(e){return r=Object.getOwnPropertyNames||function(t){var n=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[n.length]=s);return n},r(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n=r(e),s=0;s<n.length;s++)n[s]!=="default"&&vl(t,e,n[s]);return yl(t,e),t}}();Object.defineProperty(ne,"__esModule",{value:!0});ne.RestContentProvider=ne.ContentProviderRegistry=ne.Drive=ne.ContentsManager=ne.Contents=void 0;var de=te(),Sl=X(),bl=rn(),ct=ee(),$=Ae(),Ne=wl(ci()),Cl="api/contents",Pl="files",ui;(function(r){function e(n){Ne.validateContentsModel(n)}r.validateContentsModel=e;function t(n){Ne.validateCheckpointModel(n)}r.validateCheckpointModel=t})(ui||(ne.Contents=ui={}));var ds=class{constructor(e={}){var t,n;this._isDisposed=!1,this._additionalDrives=new Map,this._fileChanged=new ct.Signal(this);let s=this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:$.ServerConnection.makeSettings();this._defaultDrive=(n=e.defaultDrive)!==null&&n!==void 0?n:new an({serverSettings:s}),this._defaultDrive.fileChanged.connect(this._onFileChanged,this)}get defaultDrive(){return this._defaultDrive}get fileChanged(){return this._fileChanged}get isDisposed(){return this._isDisposed}dispose(){this.isDisposed||(this._isDisposed=!0,ct.Signal.clearData(this))}addDrive(e){this._additionalDrives.set(e.name,e),e.fileChanged.connect(this._onFileChanged,this)}getSharedModelFactory(e,t){var n,s;let[i]=this._driveForPath(e),o=(n=i.contentProviderRegistry)===null||n===void 0?void 0:n.getProvider(t==null?void 0:t.contentProviderId);return o!=null&&o.sharedModelFactory?o.sharedModelFactory:(s=i.sharedModelFactory)!==null&&s!==void 0?s:null}localPath(e){let t=e.split("/"),n=t[0].split(":");return n.length===1||!this._additionalDrives.has(n[0])?de.PathExt.removeSlash(e):de.PathExt.join(n.slice(1).join(":"),...t.slice(1))}normalize(e){let t=e.split(":");return t.length===1?de.PathExt.normalize(e):`${t[0]}:${de.PathExt.normalize(t.slice(1).join(":"))}`}resolvePath(e,t){let n=this.driveName(e),s=this.localPath(e),i=de.PathExt.resolve("/",s,t);return n?`${n}:${i}`:i}driveName(e){let n=e.split("/")[0].split(":");return n.length===1?"":this._additionalDrives.has(n[0])?n[0]:""}get(e,t){let[n,s]=this._driveForPath(e);return n.get(s,t).then(i=>{let o=[];if(i.type==="directory"&&i.content){for(let a of i.content)o.push({...a,path:this._toGlobalPath(n,a.path)});return{...i,path:this._toGlobalPath(n,s),content:o,serverPath:i.path}}else return{...i,path:this._toGlobalPath(n,s),serverPath:i.path}})}getDownloadUrl(e){let[t,n]=this._driveForPath(e);return t.getDownloadUrl(n)}newUntitled(e={}){if(e.path){let t=this.normalize(e.path),[n,s]=this._driveForPath(t);return n.newUntitled({...e,path:s}).then(i=>({...i,path:de.PathExt.join(t,i.name),serverPath:i.path}))}else return this._defaultDrive.newUntitled(e)}delete(e){let[t,n]=this._driveForPath(e);return t.delete(n)}rename(e,t){let[n,s]=this._driveForPath(e),[i,o]=this._driveForPath(t);if(n!==i)throw Error("ContentsManager: renaming files must occur within a Drive");return n.rename(s,o).then(a=>({...a,path:this._toGlobalPath(n,o),serverPath:a.path}))}async overwrite(e,t){let n=`${t}.${Sl.UUID.uuid4()}`;await this.rename(e,n);try{await this.delete(t)}finally{}return await this.rename(n,t)}save(e,t={}){let n=this.normalize(e),[s,i]=this._driveForPath(e);return s.save(i,{...t,path:i}).then(o=>({...o,path:n,serverPath:o.path}))}copy(e,t){let[n,s]=this._driveForPath(e),[i,o]=this._driveForPath(t);if(n===i)return n.copy(s,o).then(a=>({...a,path:this._toGlobalPath(n,a.path),serverPath:a.path}));throw Error("Copying files between drives is not currently implemented")}createCheckpoint(e){let[t,n]=this._driveForPath(e);return t.createCheckpoint(n)}listCheckpoints(e){let[t,n]=this._driveForPath(e);return t.listCheckpoints(n)}restoreCheckpoint(e,t){let[n,s]=this._driveForPath(e);return n.restoreCheckpoint(s,t)}deleteCheckpoint(e,t){let[n,s]=this._driveForPath(e);return n.deleteCheckpoint(s,t)}_toGlobalPath(e,t){return e===this._defaultDrive?de.PathExt.removeSlash(t):`${e.name}:${de.PathExt.removeSlash(t)}`}_driveForPath(e){let t=this.driveName(e),n=this.localPath(e);return t?[this._additionalDrives.get(t),n]:[this._defaultDrive,n]}_onFileChanged(e,t){var n,s;if(e===this._defaultDrive)this._fileChanged.emit(t);else{let i=null,o=null;!((n=t.newValue)===null||n===void 0)&&n.path&&(i={...t.newValue,path:this._toGlobalPath(e,t.newValue.path)}),!((s=t.oldValue)===null||s===void 0)&&s.path&&(o={...t.oldValue,path:this._toGlobalPath(e,t.oldValue.path)}),this._fileChanged.emit({type:t.type,newValue:i,oldValue:o})}}};ne.ContentsManager=ds;var an=class{constructor(e={}){var t,n,s;this._isDisposed=!1,this._fileChanged=new ct.Signal(this),this.name=(t=e.name)!==null&&t!==void 0?t:"Default",this._apiEndpoint=(n=e.apiEndpoint)!==null&&n!==void 0?n:Cl,this.serverSettings=(s=e.serverSettings)!==null&&s!==void 0?s:$.ServerConnection.makeSettings(),this._restContentProvider=new ln({...e,apiEndpoint:this._apiEndpoint,serverSettings:this.serverSettings}),e.defaultContentProvider?this.contentProviderRegistry=new ut({defaultProvider:e.defaultContentProvider}):this.contentProviderRegistry=new ut,this.contentProviderRegistry.fileChanged.connect((i,o)=>{this._fileChanged.emit(o)})}get fileChanged(){return this._fileChanged}get isDisposed(){return this._isDisposed}dispose(){this.isDisposed||(this._isDisposed=!0,ct.Signal.clearData(this))}async get(e,t){let n=this.contentProviderRegistry.getProvider(t==null?void 0:t.contentProviderId);return n?n.get(e,t):await this._restContentProvider.get(e,t)}getDownloadUrl(e){let t=this.serverSettings.baseUrl,n=de.URLExt.join(t,Pl,de.URLExt.encodeParts(e)),s="";try{s=document.cookie}catch{}let i=s.match("\\b_xsrf=([^;]*)\\b");if(i){let o=new URL(n);o.searchParams.append("_xsrf",i[1]),n=o.toString()}return Promise.resolve(n)}async newUntitled(e={}){var t;let n="{}";e&&(e.ext&&(e.ext=fs.normalizeExtension(e.ext)),n=JSON.stringify(e));let s=this.serverSettings,i=this._getUrl((t=e.path)!==null&&t!==void 0?t:""),o={method:"POST",body:n},a=await $.ServerConnection.makeRequest(i,o,s);if(a.status!==201)throw await $.ServerConnection.ResponseError.create(a);let h=await a.json();return Ne.validateContentsModel(h),this._fileChanged.emit({type:"new",oldValue:null,newValue:h}),h}async delete(e){let t=this._getUrl(e),n=this.serverSettings,s={method:"DELETE"},i=await $.ServerConnection.makeRequest(t,s,n);if(i.status!==204)throw await $.ServerConnection.ResponseError.create(i);this._fileChanged.emit({type:"delete",oldValue:{path:e},newValue:null})}async rename(e,t){let n=this.serverSettings,s=this._getUrl(e),i={method:"PATCH",body:JSON.stringify({path:t})},o=await $.ServerConnection.makeRequest(s,i,n);if(o.status!==200)throw await $.ServerConnection.ResponseError.create(o);let a=await o.json();return Ne.validateContentsModel(a),this._fileChanged.emit({type:"rename",oldValue:{path:e},newValue:a}),a}async save(e,t={}){let n=this.contentProviderRegistry.getProvider(t==null?void 0:t.contentProviderId),s;return n?s=await n.save(e,t):s=await this._restContentProvider.save(e,t),this._fileChanged.emit({type:"save",oldValue:null,newValue:s}),s}async copy(e,t){let n=this.serverSettings,s=this._getUrl(t),i={method:"POST",body:JSON.stringify({copy_from:e})},o=await $.ServerConnection.makeRequest(s,i,n);if(o.status!==201)throw await $.ServerConnection.ResponseError.create(o);let a=await o.json();return Ne.validateContentsModel(a),this._fileChanged.emit({type:"new",oldValue:null,newValue:a}),a}async createCheckpoint(e){let t=this._getUrl(e,"checkpoints"),n={method:"POST"},s=await $.ServerConnection.makeRequest(t,n,this.serverSettings);if(s.status!==201)throw await $.ServerConnection.ResponseError.create(s);let i=await s.json();return Ne.validateCheckpointModel(i),i}async listCheckpoints(e){let t=this._getUrl(e,"checkpoints"),n=await $.ServerConnection.makeRequest(t,{},this.serverSettings);if(n.status!==200)throw await $.ServerConnection.ResponseError.create(n);let s=await n.json();if(!Array.isArray(s))throw new Error("Invalid Checkpoint list");for(let i=0;i<s.length;i++)Ne.validateCheckpointModel(s[i]);return s}async restoreCheckpoint(e,t){let n=this._getUrl(e,"checkpoints",t),s={method:"POST"},i=await $.ServerConnection.makeRequest(n,s,this.serverSettings);if(i.status!==204)throw await $.ServerConnection.ResponseError.create(i)}async deleteCheckpoint(e,t){let n=this._getUrl(e,"checkpoints",t),s={method:"DELETE"},i=await $.ServerConnection.makeRequest(n,s,this.serverSettings);if(i.status!==204)throw await $.ServerConnection.ResponseError.create(i)}_getUrl(...e){let t=e.map(s=>de.URLExt.encodeParts(s)),n=this.serverSettings.baseUrl;return de.URLExt.join(n,this._apiEndpoint,...t)}};ne.Drive=an;var fs;(function(r){function e(t){return t.length>0&&t.indexOf(".")!==0&&(t=`.${t}`),t}r.normalizeExtension=e})(fs||(fs={}));var ut=class{constructor(e){this._providers=new Map,this._fileChanged=new ct.Signal(this),e!=null&&e.defaultProvider&&this.register("default",e.defaultProvider)}register(e,t){if(this._providers.has(e))throw Error(`Provider with ${e} identifier was already registered on this drive`);this._providers.set(e,t);let n=(s,i)=>{this._fileChanged.emit(i)};return t.fileChanged&&t.fileChanged.connect(n),new bl.DisposableDelegate(()=>{t.fileChanged&&t.fileChanged.disconnect(n),this._providers.has(e)&&this._providers.delete(e)})}getProvider(e){if(!e)return null;let t=this._providers.get(e);if(!t)throw Error(`Provider ${e} is not registered`);return t}get fileChanged(){return this._fileChanged}};ne.ContentProviderRegistry=ut;var ln=class{constructor(e){this._options=e}async get(e,t){let n=this._getUrl(e);if(t){t.type==="notebook"&&delete t.format;let a=t.content?"1":"0",h=t.hash?"1":"0",c={...t,content:a,hash:h};n+=de.URLExt.objectToQueryString(c)}let s=this._options.serverSettings,i=await $.ServerConnection.makeRequest(n,{},s);if(i.status!==200)throw await $.ServerConnection.ResponseError.create(i);let o=await i.json();return Ne.validateContentsModel(o),o}async save(e,t={}){let n=this._options.serverSettings,s=this._getUrl(e),o={method:"PUT",body:new File([JSON.stringify(t)],"data.json",{type:"application/json"})},a=await $.ServerConnection.makeRequest(s,o,n);if(a.status!==200&&a.status!==201)throw await $.ServerConnection.ResponseError.create(a);let h=await a.json();return Ne.validateContentsModel(h),h}_getUrl(...e){let t=e.map(s=>de.URLExt.encodeParts(s)),n=this._options.serverSettings.baseUrl;return de.URLExt.join(n,this._options.apiEndpoint,...t)}};ne.RestContentProvider=ln});var Ge=O((cn,hi)=>{(function(r,e){typeof cn=="object"&&typeof hi!="undefined"?e(cn,X(),ee()):typeof define=="function"&&define.amd?define(["exports","@lumino/coreutils","@lumino/signaling"],e):(r=typeof globalThis!="undefined"?globalThis:r||self,e(r.lumino_polling={},r.lumino_coreutils,r.lumino_signaling))})(cn,function(r,e,t){"use strict";class n{constructor(c){var u;this._disposed=new t.Signal(this),this._lingered=0,this._tick=new e.PromiseDelegate,this._ticked=new t.Signal(this),this._factory=c.factory,this._linger=(u=c.linger)!==null&&u!==void 0?u:s.DEFAULT_LINGER,this._standby=c.standby||s.DEFAULT_STANDBY,this._state={...s.DEFAULT_STATE,timestamp:new Date().getTime()};let l=c.frequency||{},d=Math.max(l.interval||0,l.max||0,s.DEFAULT_FREQUENCY.max);this.frequency={...s.DEFAULT_FREQUENCY,...l,max:d},this.name=c.name||s.DEFAULT_NAME,(!("auto"in c)||c.auto)&&setTimeout(()=>this.start())}get disposed(){return this._disposed}get frequency(){return this._frequency}set frequency(c){if(this.isDisposed||e.JSONExt.deepEqual(c,this.frequency||{}))return;let{backoff:u,interval:l,max:d}=c;if(l=Math.round(l),d=Math.round(d),typeof u=="number"&&u<1)throw new Error("Poll backoff growth factor must be at least 1");if((l<0||l>d)&&l!==n.NEVER)throw new Error("Poll interval must be between 0 and max");if(d>n.MAX_INTERVAL&&d!==n.NEVER)throw new Error(`Max interval must be less than ${n.MAX_INTERVAL}`);this._frequency={backoff:u,interval:l,max:d}}get isDisposed(){return this.state.phase==="disposed"}get standby(){return this._standby}set standby(c){this.isDisposed||this.standby===c||(this._standby=c)}get state(){return this._state}get tick(){return this._tick.promise}get ticked(){return this._ticked}async*[Symbol.asyncIterator](){for(;!this.isDisposed;)yield this.state,await this.tick.catch(()=>{})}dispose(){this.isDisposed||(this._state={...s.DISPOSED_STATE,timestamp:new Date().getTime()},this._tick.promise.catch(c=>{}),this._tick.reject(new Error(`Poll (${this.name}) is disposed.`)),this._disposed.emit(void 0),t.Signal.clearData(this))}refresh(){return this.schedule({cancel:({phase:c})=>c==="refreshed",interval:n.IMMEDIATE,phase:"refreshed"})}async schedule(c={}){if(this.isDisposed||c.cancel&&c.cancel(this.state))return;let u=this._tick,l=new e.PromiseDelegate,d={interval:this.frequency.interval,payload:null,phase:"standby",timestamp:new Date().getTime(),...c};if(this._state=d,this._tick=l,clearTimeout(this._timeout),this._ticked.emit(this.state),u.resolve(this),await u.promise,d.interval===n.NEVER){this._timeout=void 0;return}let m=()=>{this.isDisposed||this.tick!==l.promise||this._execute()};this._timeout=setTimeout(m,d.interval)}start(){return this.schedule({cancel:({phase:c})=>c!=="constructed"&&c!=="standby"&&c!=="stopped",interval:n.IMMEDIATE,phase:"started"})}stop(){return this.schedule({cancel:({phase:c})=>c==="stopped",interval:n.NEVER,phase:"stopped"})}get hidden(){return s.hidden}_execute(){let c=typeof this.standby=="function"?this.standby():this.standby;if(c==="never"?c=!1:c==="when-hidden"&&(this.hidden?c=++this._lingered>this._linger:(this._lingered=0,c=!1)),c){this.schedule();return}let u=this.tick;this._factory(this.state).then(l=>{this.isDisposed||this.tick!==u||this.schedule({payload:l,phase:this.state.phase==="rejected"?"reconnected":"resolved"})}).catch(l=>{this.isDisposed||this.tick!==u||this.schedule({interval:s.sleep(this.frequency,this.state),payload:l,phase:"rejected"})})}}(function(h){h.IMMEDIATE=0,h.MAX_INTERVAL=2147483647,h.NEVER=1/0})(n||(n={}));var s;(function(h){h.DEFAULT_BACKOFF=3,h.DEFAULT_FREQUENCY={backoff:!0,interval:1e3,max:30*1e3},h.DEFAULT_LINGER=1,h.DEFAULT_NAME="unknown",h.DEFAULT_STANDBY="when-hidden",h.DEFAULT_STATE={interval:n.NEVER,payload:null,phase:"constructed",timestamp:new Date(0).getTime()},h.DISPOSED_STATE={interval:n.NEVER,payload:null,phase:"disposed",timestamp:new Date(0).getTime()};function c(l,d){let{backoff:m,interval:v,max:T}=l;if(v===n.NEVER)return v;let E=m===!0?h.DEFAULT_BACKOFF:m===!1?1:m,q=u(v,d.interval*E);return Math.min(T,q)}h.sleep=c,h.hidden=typeof document=="undefined"?!1:(document.addEventListener("visibilitychange",()=>{h.hidden=document.visibilityState==="hidden"}),document.addEventListener("pagehide",()=>{h.hidden=document.visibilityState==="hidden"}),document.visibilityState==="hidden");function u(l,d){return l=Math.ceil(l),d=Math.floor(d),Math.floor(Math.random()*(d-l+1))+l}})(s||(s={}));class i{constructor(c,u=500){this.args=void 0,this.payload=null,this.limit=u,this.poll=new n({auto:!1,factory:async()=>{let{args:l}=this;return this.args=void 0,c(...l)},frequency:{backoff:!1,interval:n.NEVER,max:n.NEVER},standby:"never"}),this.payload=new e.PromiseDelegate,this.poll.ticked.connect((l,d)=>{let{payload:m}=this;if(d.phase==="resolved"){this.payload=new e.PromiseDelegate,m.resolve(d.payload);return}if(d.phase==="rejected"||d.phase==="stopped"){this.payload=new e.PromiseDelegate,m.promise.catch(v=>{}),m.reject(d.payload);return}},this)}get isDisposed(){return this.payload===null}dispose(){this.isDisposed||(this.args=void 0,this.payload=null,this.poll.dispose())}async stop(){return this.poll.stop()}}class o extends i{invoke(...c){return this.args=c,this.poll.schedule({interval:this.limit,phase:"invoked"}),this.payload.promise}}class a extends i{constructor(c,u){super(c,typeof u=="number"?u:u&&u.limit),this._trailing=!1,typeof u!="number"&&u&&u.edge==="trailing"&&(this._trailing=!0),this._interval=this._trailing?this.limit:n.IMMEDIATE}invoke(...c){let u=this.poll.state.phase!=="invoked";return(u||this._trailing)&&(this.args=c),u&&this.poll.schedule({interval:this._interval,phase:"invoked"}),this.payload.promise}}r.Debouncer=o,r.Poll=n,r.RateLimiter=i,r.Throttler=a})});var ps=O(un=>{"use strict";Object.defineProperty(un,"__esModule",{value:!0});un.EventManager=void 0;var di=te(),Ml=Ge(),fi=ee(),_i=he(),gi="api/events",gs=class{constructor(e={}){var t,n;this._socket=null,this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:_i.ServerConnection.makeSettings(),this._poll=new Ml.Poll({factory:()=>this._subscribe(),standby:(n=e.standby)!==null&&n!==void 0?n:"when-hidden"}),this._stream=new fi.Stream(this),this._poll.start()}get isDisposed(){return this._poll.isDisposed}get stream(){return this._stream}dispose(){if(this.isDisposed)return;this._poll.dispose();let e=this._socket;e&&(this._socket=null,e.onopen=()=>{},e.onerror=()=>{},e.onmessage=()=>{},e.onclose=()=>{},e.close()),fi.Signal.clearData(this),this._stream.stop()}async emit(e){let{serverSettings:t}=this,{baseUrl:n}=t,{makeRequest:s,ResponseError:i}=_i.ServerConnection,o=di.URLExt.join(n,gi),a={body:JSON.stringify(e),method:"POST"},h=await s(o,a,t);if(h.status!==204)throw new i(h)}_subscribe(){return new Promise((e,t)=>{if(this.isDisposed)return;let{appendToken:n,token:s,WebSocket:i,wsUrl:o}=this.serverSettings,a=di.URLExt.join(o,gi,"subscribe");n&&s!==""&&(a+=`?token=${encodeURIComponent(s)}`);let h=this._socket=new i(a),c=this._stream;h.onclose=()=>t(new Error("EventManager socket closed")),h.onmessage=u=>u.data&&c.emit(JSON.parse(u.data))})}};un.EventManager=gs});var vs=O(be=>{"use strict";var El=be&&be.__createBinding||(Object.create?function(r,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,n,s)}:function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]}),Il=be&&be.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),Ol=be&&be.__importStar||function(){var r=function(e){return r=Object.getOwnPropertyNames||function(t){var n=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[n.length]=s);return n},r(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n=r(e),s=0;s<n.length;s++)n[s]!=="default"&&El(t,e,n[s]);return Il(t,e),t}}();Object.defineProperty(be,"__esModule",{value:!0});be.CommHandler=be.CommsOverSubshells=void 0;var ms=X(),Rl=rn(),hn=Ol(et()),Ke;(function(r){r.Disabled="disabled",r.PerComm="perComm",r.PerCommTarget="perCommTarget"})(Ke||(be.CommsOverSubshells=Ke={}));var dn=class r extends Rl.DisposableDelegate{constructor(e,t,n,s,i){super(s),this._subshellStarted=new ms.PromiseDelegate,this._subshellId=null,this._target="",this._id="",this._id=t,this._target=e,this._kernel=n,this._kernel.statusChanged.connect(()=>{this._kernel.status==="restarting"&&this._cleanSubshells()}),this.commsOverSubshells=i!=null?i:Ke.PerCommTarget}get commId(){return this._id}get targetName(){return this._target}get subshellId(){return this._subshellId}get subshellStarted(){return this._subshellStarted.promise}get commsOverSubshells(){return this._commsOverSubshells}set commsOverSubshells(e){if(e===this._commsOverSubshells)return;let t=this._maybeCloseSubshell(this._commsOverSubshells);this._commsOverSubshells=e,t.then(()=>{this._commsOverSubshells!==Ke.Disabled&&this._maybeStartSubshell()}).catch(console.warn)}get onClose(){return this._onClose}set onClose(e){this._onClose=e}get onMsg(){return this._onMsg}set onMsg(e){this._onMsg=e}open(e,t,n=[]){if(this.isDisposed||this._kernel.isDisposed)throw new Error("Cannot open");let s=hn.createMessage({msgType:"comm_open",channel:"shell",username:this._kernel.username,session:this._kernel.clientId,subshellId:this._subshellId||this._kernel.subshellId,content:{comm_id:this._id,target_name:this._target,data:e!=null?e:{}},metadata:t,buffers:n});return this._kernel.sendShellMessage(s,!1,!0)}send(e,t,n=[],s=!0){if(this.isDisposed||this._kernel.isDisposed)throw new Error("Cannot send");let i=hn.createMessage({msgType:"comm_msg",channel:"shell",username:this._kernel.username,session:this._kernel.clientId,subshellId:this._subshellId||this._kernel.subshellId,content:{comm_id:this._id,data:e},metadata:t,buffers:n});return this._kernel.sendShellMessage(i,!1,s)}close(e,t,n=[]){if(this.isDisposed||this._kernel.isDisposed)throw new Error("Cannot close");let s=hn.createMessage({msgType:"comm_close",channel:"shell",username:this._kernel.username,session:this._kernel.clientId,subshellId:this._subshellId||this._kernel.subshellId,content:{comm_id:this._id,data:e!=null?e:{}},metadata:t,buffers:n}),i=this._kernel.sendShellMessage(s,!1,!0),o=this._onClose;if(o){let a=hn.createMessage({msgType:"comm_close",channel:"iopub",username:this._kernel.username,session:this._kernel.clientId,subshellId:this._subshellId||this._kernel.subshellId,content:{comm_id:this._id,data:e!=null?e:{}},metadata:t,buffers:n});o(a)}return this.dispose(),i}dispose(){this._maybeCloseSubshell(this._commsOverSubshells),super.dispose()}_cleanSubshells(){let e=this._kernel.id;r._commTargetSubShellsId.hasOwnProperty(e)&&delete r._commTargetSubShellsId[e]}async _maybeStartSubshell(){if(await this._kernel.info,!this._kernel.supportsSubshells)return;if(this._commsOverSubshells===Ke.PerComm){let o=await this._kernel.requestCreateSubshell({}).done;this._subshellId=o.content.subshell_id,this._subshellStarted.resolve();return}let e=this._subshellStarted,t=this._kernel.id;r._commTargetSubShellsId.hasOwnProperty(t)||(r._commTargetSubShellsId[t]={});let n=r._commTargetSubShellsId[t],s=n[this._target];if(s){s.referenceCount+=1;try{this._subshellId=await s.subshellId,e.resolve()}catch(o){await this._closePerCommTargetSubshell(!1),e.reject(`Per comm-target subshell creation failed: ${o}`)}return}let i={subshellId:this._kernel.requestCreateSubshell({}).done.then(o=>o.content.subshell_id),referenceCount:1};n[this._target]=i;try{this._subshellId=await i.subshellId,e.resolve()}catch(o){await this._closePerCommTargetSubshell(!1),e.reject(`Per comm-target subshell creation failed: ${o}`)}}async _closePerCommTargetSubshell(e=!0){let t=this._kernel.id,n=this._target;if(r._commTargetSubShellsId.hasOwnProperty(t)){let s=r._commTargetSubShellsId[t],i=s[n];if(i&&(i.referenceCount-=1,i.referenceCount<=0)){if(e){let o=null;try{o=await i.subshellId}catch(a){console.warn(`Subshell identifier not available in the closeout sequence, will not request deletion: ${a}`)}o!==null&&this._kernel.requestDeleteSubshell({subshell_id:o},!0)}delete s[n]}Object.keys(s).length===0&&delete r._commTargetSubShellsId[t],this._subshellId=null}this._subshellStarted=new ms.PromiseDelegate}async _maybeCloseSubshell(e){if(this._kernel.status!=="dead")switch(e){case Ke.PerComm:{this._subshellId&&(this._kernel.requestDeleteSubshell({subshell_id:this._subshellId},!0),this._subshellId=null),this._subshellStarted=new ms.PromiseDelegate;break}case Ke.PerCommTarget:{await this._closePerCommTargetSubshell();break}case Ke.Disabled:break}}};be.CommHandler=dn;dn._commTargetSubShellsId={}});var mi=O(pi=>{"use strict";Object.defineProperty(pi,"__esModule",{value:!0})});var fn=O(ht=>{"use strict";Object.defineProperty(ht,"__esModule",{value:!0});ht.validateMessage=Tl;ht.validateModel=yi;ht.validateModels=jl;var Xe=lt(),vi=["username","version","session","msg_id","msg_type"],kl={stream:{name:"string",text:"string"},display_data:{data:"object",metadata:"object"},execute_input:{code:"string",execution_count:"number"},execute_result:{execution_count:"number",data:"object",metadata:"object"},error:{ename:"string",evalue:"string",traceback:"object"},status:{execution_state:["string",["starting","idle","busy","restarting","dead"]]},clear_output:{wait:"boolean"},comm_open:{comm_id:"string",target_name:"string",data:"object"},comm_msg:{comm_id:"string",data:"object"},comm_close:{comm_id:"string"},shutdown_reply:{restart:"boolean"}};function Dl(r){for(let e=0;e<vi.length;e++)(0,Xe.validateProperty)(r,vi[e],"string")}function Tl(r){(0,Xe.validateProperty)(r,"metadata","object"),(0,Xe.validateProperty)(r,"content","object"),(0,Xe.validateProperty)(r,"channel","string"),Dl(r.header),r.channel==="iopub"&&ql(r)}function ql(r){if(r.channel==="iopub"){let e=kl[r.header.msg_type];if(e===void 0)return;let t=Object.keys(e),n=r.content;for(let s=0;s<t.length;s++){let i=e[t[s]];Array.isArray(i)||(i=[i]),(0,Xe.validateProperty)(n,t[s],...i)}}}function yi(r){(0,Xe.validateProperty)(r,"name","string"),(0,Xe.validateProperty)(r,"id","string")}function jl(r){if(!Array.isArray(r))throw new Error("Invalid kernel list");r.forEach(e=>yi(e))}});var gn=O(se=>{"use strict";Object.defineProperty(se,"__esModule",{value:!0});se.KernelAPIClient=se.KERNEL_SERVICE_URL=void 0;se.listRunning=wi;se.startNew=Si;se.restartKernel=bi;se.interruptKernel=Ci;se.shutdownKernel=Pi;se.getKernelModel=Mi;var Q=he(),st=te(),_n=fn();se.KERNEL_SERVICE_URL="api/kernels";async function wi(r=Q.ServerConnection.makeSettings()){let e=st.URLExt.join(r.baseUrl,se.KERNEL_SERVICE_URL),t=await Q.ServerConnection.makeRequest(e,{},r);if(t.status!==200)throw await Q.ServerConnection.ResponseError.create(t);let n=await t.json();return(0,_n.validateModels)(n),n}async function Si(r={},e=Q.ServerConnection.makeSettings()){let t=st.URLExt.join(e.baseUrl,se.KERNEL_SERVICE_URL),n={method:"POST",body:JSON.stringify(r)},s=await Q.ServerConnection.makeRequest(t,n,e);if(s.status!==201)throw await Q.ServerConnection.ResponseError.create(s);let i=await s.json();return(0,_n.validateModel)(i),i}async function bi(r,e=Q.ServerConnection.makeSettings()){let t=st.URLExt.join(e.baseUrl,se.KERNEL_SERVICE_URL,encodeURIComponent(r),"restart"),n={method:"POST"},s=await Q.ServerConnection.makeRequest(t,n,e);if(s.status!==200)throw await Q.ServerConnection.ResponseError.create(s);let i=await s.json();(0,_n.validateModel)(i)}async function Ci(r,e=Q.ServerConnection.makeSettings()){let t=st.URLExt.join(e.baseUrl,se.KERNEL_SERVICE_URL,encodeURIComponent(r),"interrupt"),n={method:"POST"},s=await Q.ServerConnection.makeRequest(t,n,e);if(s.status!==204)throw await Q.ServerConnection.ResponseError.create(s)}async function Pi(r,e=Q.ServerConnection.makeSettings()){let t=st.URLExt.join(e.baseUrl,se.KERNEL_SERVICE_URL,encodeURIComponent(r)),n={method:"DELETE"},s=await Q.ServerConnection.makeRequest(t,n,e);if(s.status===404){let i=`The kernel "${r}" does not exist on the server`;console.warn(i)}else if(s.status!==204)throw await Q.ServerConnection.ResponseError.create(s)}async function Mi(r,e=Q.ServerConnection.makeSettings()){let t=st.URLExt.join(e.baseUrl,se.KERNEL_SERVICE_URL,encodeURIComponent(r)),n=await Q.ServerConnection.makeRequest(t,{},e);if(n.status===404)return;if(n.status!==200)throw await Q.ServerConnection.ResponseError.create(n);let s=await n.json();return(0,_n.validateModel)(s),s}var ys=class{constructor(e={}){var t;this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:Q.ServerConnection.makeSettings()}async listRunning(){return wi(this.serverSettings)}async getModel(e){return Mi(e,this.serverSettings)}async startNew(e={}){return Si(e,this.serverSettings)}async restart(e){return bi(e,this.serverSettings)}async interrupt(e){return Ci(e,this.serverSettings)}async shutdown(e){return Pi(e,this.serverSettings)}};se.KernelAPIClient=ys});var Ii=O(ve=>{"use strict";var Ul=ve&&ve.__createBinding||(Object.create?function(r,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,n,s)}:function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]}),Al=ve&&ve.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),Nl=ve&&ve.__importStar||function(){var r=function(e){return r=Object.getOwnPropertyNames||function(t){var n=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[n.length]=s);return n},r(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n=r(e),s=0;s<n.length;s++)n[s]!=="default"&&Ul(t,e,n[s]);return Al(t,e),t}}();Object.defineProperty(ve,"__esModule",{value:!0});ve.KernelShellFutureHandler=ve.KernelControlFutureHandler=ve.KernelFutureHandler=void 0;var Ei=X(),Ll=rn(),xl=Nl(et()),dt=class extends Ll.DisposableDelegate{constructor(e,t,n,s,i){super(e),this._status=0,this._stdin=ie.noOp,this._iopub=ie.noOp,this._reply=ie.noOp,this._done=new Ei.PromiseDelegate,this._hooks=new ie.HookList,this._disposeOnDone=!0,this._msg=t,n||this._setFlag(ie.KernelFutureFlag.GotReply),this._disposeOnDone=s,this._kernel=i}get msg(){return this._msg}get done(){return this._done.promise}get onReply(){return this._reply}set onReply(e){this._reply=e}get onIOPub(){return this._iopub}set onIOPub(e){this._iopub=e}get onStdin(){return this._stdin}set onStdin(e){this._stdin=e}registerMessageHook(e){if(this.isDisposed)throw new Error("Kernel future is disposed");this._hooks.add(e)}removeMessageHook(e){this.isDisposed||this._hooks.remove(e)}sendInputReply(e,t){this._kernel.sendInputReply(e,t)}dispose(){this._stdin=ie.noOp,this._iopub=ie.noOp,this._reply=ie.noOp,this._hooks=null,this._testFlag(ie.KernelFutureFlag.IsDone)||(this._done.promise.catch(()=>{}),this._done.reject(new Error(`Canceled future for ${this.msg.header.msg_type} message before replies were done`))),super.dispose()}async handleMsg(e){switch(e.channel){case"control":case"shell":e.channel===this.msg.channel&&e.parent_header.msg_id===this.msg.header.msg_id&&await this._handleReply(e);break;case"stdin":await this._handleStdin(e);break;case"iopub":await this._handleIOPub(e);break;default:break}}async _handleReply(e){let t=this._reply;t&&await t(e),this._replyMsg=e,this._setFlag(ie.KernelFutureFlag.GotReply),this._testFlag(ie.KernelFutureFlag.GotIdle)&&this._handleDone()}async _handleStdin(e){this._kernel.hasPendingInput=!0;let t=this._stdin;t&&await t(e)}async _handleIOPub(e){let t=await this._hooks.process(e),n=this._iopub;t&&n&&await n(e),xl.isStatusMsg(e)&&e.content.execution_state==="idle"&&(this._setFlag(ie.KernelFutureFlag.GotIdle),this._testFlag(ie.KernelFutureFlag.GotReply)&&this._handleDone())}_handleDone(){this._testFlag(ie.KernelFutureFlag.IsDone)||(this._setFlag(ie.KernelFutureFlag.IsDone),this._done.resolve(this._replyMsg),this._disposeOnDone&&this.dispose())}_testFlag(e){return(this._status&e)!==0}_setFlag(e){this._status|=e}};ve.KernelFutureHandler=dt;var ws=class extends dt{};ve.KernelControlFutureHandler=ws;var Ss=class extends dt{};ve.KernelShellFutureHandler=Ss;var ie;(function(r){r.noOp=()=>{};let e=typeof requestAnimationFrame=="function"?requestAnimationFrame:setImmediate;class t{constructor(){this._hooks=[]}add(i){this.remove(i),this._hooks.push(i)}remove(i){let o=this._hooks.indexOf(i);o>=0&&(this._hooks[o]=null,this._scheduleCompact())}async process(i){await this._processing;let o=new Ei.PromiseDelegate;this._processing=o.promise;let a;for(let h=this._hooks.length-1;h>=0;h--){let c=this._hooks[h];if(c!==null){try{a=await c(i)}catch(u){a=!0,console.error(u)}if(a===!1)return o.resolve(void 0),!1}}return o.resolve(void 0),!0}_scheduleCompact(){this._compactScheduled||(this._compactScheduled=!0,e(()=>{this._processing=this._processing.then(()=>{this._compactScheduled=!1,this._compact()})}))}_compact(){let i=0;for(let o=0,a=this._hooks.length;o<a;o++){let h=this._hooks[o];this._hooks[o]===null?i++:this._hooks[o-i]=h}this._hooks.length-=i}}r.HookList=t;let n;(function(s){s[s.GotReply=1]="GotReply",s[s.GotIdle=2]="GotIdle",s[s.IsDone=4]="IsDone",s[s.DisposeOnDone=8]="DisposeOnDone"})(n=r.KernelFutureFlag||(r.KernelFutureFlag={}))})(ie||(ie={}))});var Ri=O(pn=>{"use strict";Object.defineProperty(pn,"__esModule",{value:!0});pn.validateSpecModel=Oi;pn.validateSpecModels=Fl;var ze=lt();function Oi(r){let e=r.spec;if(!e)throw new Error("Invalid kernel spec");(0,ze.validateProperty)(r,"name","string"),(0,ze.validateProperty)(r,"resources","object"),(0,ze.validateProperty)(e,"language","string"),(0,ze.validateProperty)(e,"display_name","string"),(0,ze.validateProperty)(e,"argv","array");let t=null;e.hasOwnProperty("metadata")&&((0,ze.validateProperty)(e,"metadata","object"),t=e.metadata);let n=null;return e.hasOwnProperty("env")&&((0,ze.validateProperty)(e,"env","object"),n=e.env),e.hasOwnProperty("interrupt_mode")&&((0,ze.validateProperty)(e,"interrupt_mode","string"),n=e.env),{name:r.name,resources:r.resources,language:e.language,display_name:e.display_name,argv:e.argv,metadata:t,env:n}}function Fl(r){if(!r.hasOwnProperty("kernelspecs"))throw new Error("No kernelspecs found");let e=Object.keys(r.kernelspecs),t=Object.create(null),n=r.default;for(let s=0;s<e.length;s++){let i=r.kernelspecs[e[s]];try{t[e[s]]=Oi(i)}catch{console.warn(`Removing errant kernel spec: ${e[s]}`)}}if(e=Object.keys(t),!e.length)throw new Error("No valid kernelspecs found");return(!n||typeof n!="string"||!(n in t))&&(n=e[0],console.warn(`Default kernel not found, using '${e[0]}'`)),{default:n,kernelspecs:t}}});var _t=O(ft=>{"use strict";Object.defineProperty(ft,"__esModule",{value:!0});ft.KernelSpecAPIClient=void 0;ft.getSpecs=ki;var mn=he(),Kl=Ri(),zl=te(),Vl="api/kernelspecs";async function ki(r=mn.ServerConnection.makeSettings()){let e=zl.URLExt.join(r.baseUrl,Vl),t=await mn.ServerConnection.makeRequest(e,{},r);if(t.status!==200)throw await mn.ServerConnection.ResponseError.create(t);let n=await t.json();return(0,Kl.validateSpecModels)(n)}var bs=class{constructor(e={}){var t;this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:mn.ServerConnection.makeSettings()}async get(){return ki(this.serverSettings)}};ft.KernelSpecAPIClient=bs});var Ps=O(ye=>{"use strict";var Bl=ye&&ye.__createBinding||(Object.create?function(r,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,n,s)}:function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]}),$l=ye&&ye.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),Ui=ye&&ye.__importStar||function(){var r=function(e){return r=Object.getOwnPropertyNames||function(t){var n=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[n.length]=s);return n},r(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n=r(e),s=0;s<n.length;s++)n[s]!=="default"&&Bl(t,e,n[s]);return $l(t,e),t}}();Object.defineProperty(ye,"__esModule",{value:!0});ye.KernelConnection=ye.DEFAULT_KERNEL_INFO_TIMEOUT=void 0;var Di=te(),Ve=X(),Be=ee(),gt=Ae(),Ti=vs(),oe=Ui(et()),qi=Ii(),Wl=Ui(fn()),ji=gn(),Hl=_t(),Jl=te();ye.DEFAULT_KERNEL_INFO_TIMEOUT=3e3;var rt="_RESTARTING_",Gl="",Cs=class r{constructor(e){var t,n,s,i,o,a,h,c,u;this._createSocket=(l=!0)=>{this._errorIfDisposed(),this._clearSocket(),this._updateConnectionStatus("connecting");let d=this.serverSettings,m=Di.URLExt.join(d.wsUrl,ji.KERNEL_SERVICE_URL,encodeURIComponent(this._id)),v=m.replace(/^((?:\w+:)?\/\/)[^@/]+@/,"$1");console.debug(`Starting WebSocket: ${v}`);let T=Di.URLExt.join(m,"channels?session_id="+encodeURIComponent(this._clientId)),E=d.token;d.appendToken&&E!==""&&(T=T+`&token=${encodeURIComponent(E)}`);let q=l?this._supportedProtocols:[];this._ws=new d.WebSocket(T,q),this._ws.binaryType="arraybuffer";let A=!1,C=async k=>{var N,j;if(!this._isDisposed){this._reason="",this._model=void 0;try{let R=await this._kernelAPIClient.getModel(this._id);this._model=R,(R==null?void 0:R.execution_state)==="dead"?this._updateStatus("dead"):this._onWSClose(k)}catch(R){if(R instanceof gt.ServerConnection.NetworkError||((N=R.response)===null||N===void 0?void 0:N.status)===503||((j=R.response)===null||j===void 0?void 0:j.status)===424){let U=Ce.getRandomIntInclusive(10,30)*1e3;setTimeout(C,U,k)}else this._reason="Kernel died unexpectedly",this._updateStatus("dead")}}},w=async k=>{A||(A=!0,await C(k))};this._ws.onmessage=this._onWSMessage,this._ws.onopen=this._onWSOpen,this._ws.onclose=w,this._ws.onerror=w},this._onWSOpen=l=>{if(this._ws.protocol!==""&&!this._supportedProtocols.includes(this._ws.protocol))throw console.log("Server selected unknown kernel wire protocol:",this._ws.protocol),this._updateStatus("dead"),new Error(`Unknown kernel wire protocol: ${this._ws.protocol}`);this._selectedProtocol=this._ws.protocol,this._ws.onclose=this._onWSClose,this._ws.onerror=this._onWSClose,this._updateConnectionStatus("connected")},this._onWSMessage=l=>{let d;try{d=this.serverSettings.serializer.deserialize(l.data,this._ws.protocol),Wl.validateMessage(d)}catch(m){throw m.message=`Kernel message validation error: ${m.message}`,m}this._kernelSession=d.header.session,this._msgChain=this._msgChain.then(()=>this._handleMessage(d)).catch(m=>{m.message.startsWith("Canceled future for ")&&console.error(m)}),this._anyMessage.emit({msg:d,direction:"recv"})},this._onWSClose=l=>{if(!this.isDisposed){if("code"in l&&(l.code===1e3||l.code===1001)){this._updateConnectionStatus("disconnected");return}this._reconnect()}},this._id="",this._name="",this._status="unknown",this._connectionStatus="connecting",this._kernelSession="",this._isDisposed=!1,this._ws=null,this._username="",this._reconnectLimit=7,this._reconnectAttempt=0,this._reconnectTimeout=null,this._supportedProtocols=Object.values(oe.supportedKernelWebSocketProtocols),this._selectedProtocol="",this._commsOverSubshells=gt.CommsOverSubshells.PerCommTarget,this._futures=new Map,this._comms=new Map,this._targetRegistry=Object.create(null),this._info=new Ve.PromiseDelegate,this._pendingMessages=[],this._statusChanged=new Be.Signal(this),this._connectionStatusChanged=new Be.Signal(this),this._disposed=new Be.Signal(this),this._iopubMessage=new Be.Signal(this),this._anyMessage=new Be.Signal(this),this._pendingInput=new Be.Signal(this),this._unhandledMessage=new Be.Signal(this),this._displayIdToParentIds=new Map,this._msgIdToDisplayIds=new Map,this._msgChain=Promise.resolve(),this._hasPendingInput=!1,this._reason="",this._noOp=()=>{},this._supportsSubshells=!1,this._kernelInfoTimeout=ye.DEFAULT_KERNEL_INFO_TIMEOUT,this._name=e.model.name,this._id=e.model.id,this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:gt.ServerConnection.makeSettings(),this._kernelAPIClient=(n=e.kernelAPIClient)!==null&&n!==void 0?n:new ji.KernelAPIClient({serverSettings:this.serverSettings}),this._kernelSpecAPIClient=(s=e.kernelSpecAPIClient)!==null&&s!==void 0?s:new Hl.KernelSpecAPIClient({serverSettings:this.serverSettings}),this._clientId=(i=e.clientId)!==null&&i!==void 0?i:Ve.UUID.uuid4(),this._username=(o=e.username)!==null&&o!==void 0?o:"",this.handleComms=(a=e.handleComms)!==null&&a!==void 0?a:!0,this._commsOverSubshells=(h=e.commsOverSubshells)!==null&&h!==void 0?h:gt.CommsOverSubshells.PerCommTarget,this._subshellId=(c=e.subshellId)!==null&&c!==void 0?c:null,this._createSocket(),this._kernelInfoTimeout=(u=e==null?void 0:e.kernelInfoTimeout)!==null&&u!==void 0?u:ye.DEFAULT_KERNEL_INFO_TIMEOUT}get disposed(){return this._disposed}get commsOverSubshells(){return this._commsOverSubshells}set commsOverSubshells(e){this._commsOverSubshells=e;for(let[t,n]of this._comms)n.commsOverSubshells=e}get statusChanged(){return this._statusChanged}get connectionStatusChanged(){return this._connectionStatusChanged}get iopubMessage(){return this._iopubMessage}get unhandledMessage(){return this._unhandledMessage}get model(){return this._model||{id:this.id,name:this.name,reason:this._reason}}get anyMessage(){return this._anyMessage}get pendingInput(){return this._pendingInput}get id(){return this._id}get name(){return this._name}get username(){return this._username}get clientId(){return this._clientId}get subshellId(){return this._subshellId}set subshellId(e){this._subshellId=e}get status(){return this._status}get connectionStatus(){return this._connectionStatus}get isDisposed(){return this._isDisposed}get info(){return this._info.promise}get spec(){return this._specPromise?this._specPromise:(this._specPromise=this._kernelSpecAPIClient.get().then(e=>e.kernelspecs[this._name]),this._specPromise)}get supportsSubshells(){return this._supportsSubshells}clone(e={}){return new r({model:this.model,username:this.username,serverSettings:this.serverSettings,handleComms:!1,kernelAPIClient:this._kernelAPIClient,commsOverSubshells:gt.CommsOverSubshells.Disabled,kernelInfoTimeout:this._kernelInfoTimeout,...e})}dispose(){if(this.isDisposed)return;let e=()=>{this._isDisposed=!0,this._disposed.emit(),this._updateConnectionStatus("disconnected"),this._clearKernelState(),this._pendingMessages=[],this._clearSocket(),Be.Signal.clearData(this)};if(this._subshellId!==null){let t=this.requestDeleteSubshell({subshell_id:this._subshellId},!0);t.onReply=n=>{e()}}else e()}sendShellMessage(e,t=!1,n=!0){return this._sendKernelShellControl(qi.KernelShellFutureHandler,e,t,n)}sendControlMessage(e,t=!1,n=!0){return this._sendKernelShellControl(qi.KernelControlFutureHandler,e,t,n)}_sendKernelShellControl(e,t,n=!1,s=!0){this._sendMessage(t),this._anyMessage.emit({msg:t,direction:"send"});let i=new e(()=>{let o=t.header.msg_id;this._futures.delete(o);let a=this._msgIdToDisplayIds.get(o);a&&(a.forEach(h=>{let c=this._displayIdToParentIds.get(h);if(c){let u=c.indexOf(o);if(u===-1)return;c.length===1?this._displayIdToParentIds.delete(h):(c.splice(u,1),this._displayIdToParentIds.set(h,c))}}),this._msgIdToDisplayIds.delete(o))},t,n,s,this);return this._futures.set(t.header.msg_id,i),i}_sendMessage(e,t=!0){if(this.status==="dead")throw new Error("Kernel is dead");if((this._kernelSession===Gl||this._kernelSession===rt)&&oe.isInfoRequestMsg(e))if(this.connectionStatus==="connected"){this._ws.send(this.serverSettings.serializer.serialize(e,this._ws.protocol));return}else throw new Error("Could not send message: status is not connected");if(t&&this._pendingMessages.length>0){this._pendingMessages.push(e);return}if(this.connectionStatus==="connected"&&this._kernelSession!==rt)this._ws.send(this.serverSettings.serializer.serialize(e,this._ws.protocol));else if(t)this._pendingMessages.push(e);else throw new Error("Could not send message")}async interrupt(){if(this.hasPendingInput=!1,this.status==="dead")throw new Error("Kernel is dead");return this._kernelAPIClient.interrupt(this.id)}async restart(){if(this.status==="dead")throw new Error("Kernel is dead");this._updateStatus("restarting"),this._clearKernelState(),this._kernelSession=rt,await this._kernelAPIClient.restart(this.id),await this.reconnect(),this.hasPendingInput=!1}reconnect(){this._errorIfDisposed();let e=new Ve.PromiseDelegate,t=(n,s)=>{s==="connected"?(e.resolve(),this.connectionStatusChanged.disconnect(t,this)):s==="disconnected"&&(e.reject(new Error("Kernel connection disconnected")),this.connectionStatusChanged.disconnect(t,this))};return this.connectionStatusChanged.connect(t,this),this._reconnectAttempt=0,this._reconnect(),e.promise}async shutdown(){this.status!=="dead"&&await this._kernelAPIClient.shutdown(this.id),this.handleShutdown()}handleShutdown(){this._updateStatus("dead"),this.dispose()}async requestKernelInfo(){let e=oe.createMessage({msgType:"kernel_info_request",channel:"shell",username:this._username,session:this._clientId,subshellId:this._subshellId,content:{}}),t;try{t=await Ce.handleShellMessage(this,e)}catch(s){if(this.isDisposed)return;throw s}if(this._errorIfDisposed(),!t)return;if(t.content.status===void 0&&(t.content.status="ok"),t.content.status!=="ok")return this._info.reject("Kernel info reply errored"),t;this._info.resolve(t.content),this._kernelSession=t.header.session;let n=t.content.supported_features;return this._supportsSubshells=n!==void 0&&n.includes("kernel subshells"),t}requestComplete(e){let t=oe.createMessage({msgType:"complete_request",channel:"shell",username:this._username,session:this._clientId,subshellId:this._subshellId,content:e});return Ce.handleShellMessage(this,t)}requestInspect(e){let t=oe.createMessage({msgType:"inspect_request",channel:"shell",username:this._username,session:this._clientId,subshellId:this._subshellId,content:e});return Ce.handleShellMessage(this,t)}requestHistory(e){let t=oe.createMessage({msgType:"history_request",channel:"shell",username:this._username,session:this._clientId,subshellId:this._subshellId,content:e});return Ce.handleShellMessage(this,t)}requestExecute(e,t=!0,n){let s={silent:!1,store_history:!0,user_expressions:{},allow_stdin:!0,stop_on_error:!1},i=oe.createMessage({msgType:"execute_request",channel:"shell",username:this._username,session:this._clientId,subshellId:this._subshellId,content:{...s,...e},metadata:n});return this.sendShellMessage(i,!0,t)}requestDebug(e,t=!0){let n=oe.createMessage({msgType:"debug_request",channel:"control",username:this._username,session:this._clientId,content:e});return this.sendControlMessage(n,!0,t)}requestCreateSubshell(e,t=!0){if(!this.supportsSubshells)throw new Error("Kernel subshells are not supported");let n=oe.createMessage({msgType:"create_subshell_request",channel:"control",username:this._username,session:this._clientId,content:e});return this.sendControlMessage(n,!0,t)}requestDeleteSubshell(e,t=!0){if(!this.supportsSubshells)throw new Error("Kernel subshells are not supported");let n=oe.createMessage({msgType:"delete_subshell_request",channel:"control",username:this._username,session:this._clientId,content:e});return this.sendControlMessage(n,!0,t)}requestListSubshell(e,t=!0){if(!this.supportsSubshells)throw new Error("Kernel subshells are not supported");let n=oe.createMessage({msgType:"list_subshell_request",channel:"control",username:this._username,session:this._clientId,content:e});return this.sendControlMessage(n,!0,t)}requestIsComplete(e){let t=oe.createMessage({msgType:"is_complete_request",channel:"shell",username:this._username,session:this._clientId,subshellId:this._subshellId,content:e});return Ce.handleShellMessage(this,t)}requestCommInfo(e){let t=oe.createMessage({msgType:"comm_info_request",channel:"shell",username:this._username,session:this._clientId,subshellId:this._subshellId,content:e});return Ce.handleShellMessage(this,t)}sendInputReply(e,t){let n=oe.createMessage({msgType:"input_reply",channel:"stdin",username:this._username,session:this._clientId,content:e});n.parent_header=t,this._sendMessage(n),this._anyMessage.emit({msg:n,direction:"send"}),this.hasPendingInput=!1}createComm(e,t=Ve.UUID.uuid4()){if(!this.handleComms)throw new Error("Comms are disabled on this kernel connection");if(this._comms.has(t))throw new Error("Comm is already created");let n=new Ti.CommHandler(e,t,this,()=>{this._unregisterComm(t)},this._commsOverSubshells);return this._comms.set(t,n),n}hasComm(e){return this._comms.has(e)}registerCommTarget(e,t){this.handleComms&&(this._targetRegistry[e]=t)}removeCommTarget(e,t){this.handleComms&&!this.isDisposed&&this._targetRegistry[e]===t&&delete this._targetRegistry[e]}registerMessageHook(e,t){var n;let s=(n=this._futures)===null||n===void 0?void 0:n.get(e);s&&s.registerMessageHook(t)}removeMessageHook(e,t){var n;let s=(n=this._futures)===null||n===void 0?void 0:n.get(e);s&&s.removeMessageHook(t)}removeInputGuard(){this.hasPendingInput=!1}async _handleDisplayId(e,t){var n,s;let i=t.parent_header.msg_id,o=this._displayIdToParentIds.get(e);if(o){let h={header:Ve.JSONExt.deepCopy(t.header),parent_header:Ve.JSONExt.deepCopy(t.parent_header),metadata:Ve.JSONExt.deepCopy(t.metadata),content:Ve.JSONExt.deepCopy(t.content),channel:t.channel,buffers:t.buffers?t.buffers.slice():[]};h.header.msg_type="update_display_data",await Promise.all(o.map(async c=>{let u=this._futures&&this._futures.get(c);u&&await u.handleMsg(h)}))}if(t.header.msg_type==="update_display_data")return!0;o=(n=this._displayIdToParentIds.get(e))!==null&&n!==void 0?n:[],o.indexOf(i)===-1&&o.push(i),this._displayIdToParentIds.set(e,o);let a=(s=this._msgIdToDisplayIds.get(i))!==null&&s!==void 0?s:[];return a.indexOf(i)===-1&&a.push(i),this._msgIdToDisplayIds.set(i,a),!1}_clearSocket(){this._ws!==null&&(this._ws.onopen=this._noOp,this._ws.onclose=this._noOp,this._ws.onerror=this._noOp,this._ws.onmessage=this._noOp,this._ws.close(),this._ws=null)}_updateStatus(e){this._status===e||this._status==="dead"||(this._status=e,Ce.logKernelStatus(this),this._statusChanged.emit(e),e==="dead"&&this.dispose())}_sendPending(){for(;this.connectionStatus==="connected"&&this._kernelSession!==rt&&this._pendingMessages.length>0;)this._sendMessage(this._pendingMessages[0],!1),this._pendingMessages.shift()}_clearKernelState(){this._kernelSession="",this._pendingMessages=[],this._futures.forEach(e=>{e.dispose()}),this._comms.forEach(e=>{e.dispose()}),this._msgChain=Promise.resolve(),this._futures=new Map,this._comms=new Map,this._displayIdToParentIds.clear(),this._msgIdToDisplayIds.clear()}_assertCurrentMessage(e){if(this._errorIfDisposed(),e.header.session!==this._kernelSession)throw new Error(`Canceling handling of old message: ${e.header.msg_type}`)}async _handleCommOpen(e){this._assertCurrentMessage(e);let t=e.content,n=new Ti.CommHandler(t.target_name,t.comm_id,this,()=>{this._unregisterComm(t.comm_id)},this.commsOverSubshells);this._comms.set(t.comm_id,n);try{await(await Ce.loadObject(t.target_name,t.target_module,this._targetRegistry))(n,e)}catch(s){throw n.close(),console.error("Exception opening new comm"),s}}async _handleCommClose(e){this._assertCurrentMessage(e);let t=e.content,n=this._comms.get(t.comm_id);if(!n){console.error("Comm not found for comm id "+t.comm_id);return}this._unregisterComm(n.commId);let s=n.onClose;s&&await s(e),n.dispose()}async _handleCommMsg(e){this._assertCurrentMessage(e);let t=e.content,n=this._comms.get(t.comm_id);if(!n)return;let s=n.onMsg;s&&await s(e)}_unregisterComm(e){this._comms.delete(e)}_updateConnectionStatus(e){if(this._connectionStatus!==e){if(this._connectionStatus=e,e!=="connecting"&&(this._reconnectAttempt=0,clearTimeout(this._reconnectTimeout)),this.status!=="dead")if(e==="connected"){let t=this._kernelSession===rt,n=this.requestKernelInfo(),s=!1,i=()=>{s||(s=!0,t&&this._kernelSession===rt&&(this._kernelSession=""),clearTimeout(o),this._pendingMessages.length>0&&this._sendPending())};n.then(i);let o=setTimeout(i,this._kernelInfoTimeout)}else this._updateStatus("unknown");this._connectionStatusChanged.emit(e)}}async _handleMessage(e){var t,n;let s=!1;if(e.parent_header&&e.channel==="iopub"&&(oe.isDisplayDataMsg(e)||oe.isUpdateDisplayDataMsg(e)||oe.isExecuteResultMsg(e))){let o=((t=e.content.transient)!==null&&t!==void 0?t:{}).display_id;o&&(s=await this._handleDisplayId(o,e),this._assertCurrentMessage(e))}if(!s&&e.parent_header){let i=e.parent_header,o=(n=this._futures)===null||n===void 0?void 0:n.get(i.msg_id);if(o)await o.handleMsg(e),this._assertCurrentMessage(e);else{let a=i.session===this.clientId;e.channel!=="iopub"&&a&&this._unhandledMessage.emit(e)}}if(e.channel==="iopub"){switch(e.header.msg_type){case"status":{let i=Jl.PageConfig.getOption("untracked_message_types");if(JSON.parse(i||"[]").includes(e.parent_header.msg_type))break;let a=e.content.execution_state;a==="restarting"&&Promise.resolve().then(async()=>{this._updateStatus("autorestarting"),this._clearKernelState(),await this.reconnect()}),this._updateStatus(a);break}case"comm_open":this.handleComms&&await this._handleCommOpen(e);break;case"comm_msg":this.handleComms&&await this._handleCommMsg(e);break;case"comm_close":this.handleComms&&await this._handleCommClose(e);break;default:break}this.isDisposed||(this._assertCurrentMessage(e),this._iopubMessage.emit(e))}}_reconnect(){if(this._errorIfDisposed(),clearTimeout(this._reconnectTimeout),this._reconnectAttempt<this._reconnectLimit){this._updateConnectionStatus("connecting");let e=Ce.getRandomIntInclusive(0,1e3*(Math.pow(2,this._reconnectAttempt)-1));console.warn(`Connection lost, reconnecting in ${Math.floor(e/1e3)} seconds.`);let t=this._selectedProtocol!=="";this._reconnectTimeout=setTimeout(this._createSocket,e,t),this._reconnectAttempt+=1}else this._updateConnectionStatus("disconnected");this._clearSocket()}_errorIfDisposed(){if(this.isDisposed)throw new Error("Kernel connection is disposed")}get hasPendingInput(){return this._hasPendingInput}set hasPendingInput(e){this._hasPendingInput=e,this._pendingInput.emit(e)}};ye.KernelConnection=Cs;var Ce;(function(r){function e(i){switch(i.status){case"idle":case"busy":case"unknown":return;default:console.debug(`Kernel: ${i.status} (${i.id})`);break}}r.logKernelStatus=e;async function t(i,o){return i.sendShellMessage(o,!0).done}r.handleShellMessage=t;function n(i,o,a){return new Promise((h,c)=>{if(o){if(typeof requirejs=="undefined")throw new Error("requirejs not found");requirejs([o],u=>{if(u[i]===void 0){let l=`Object '${i}' not found in module '${o}'`;c(new Error(l))}else h(u[i])},c)}else a!=null&&a[i]?h(a[i]):c(new Error(`Object '${i}' not found in registry`))})}r.loadObject=n;function s(i,o){return i=Math.ceil(i),o=Math.floor(o),Math.floor(Math.random()*(o-i+1))+i}r.getRandomIntInclusive=s})(Ce||(Ce={}))});var xi=O(mt=>{"use strict";Object.defineProperty(mt,"__esModule",{value:!0});mt.KernelManager=void 0;var Xl=Ge(),Ai=ee(),Ni=Ae(),Yl=Je(),Ql=gn(),Li=Ps(),Zl=_t(),pt=class extends Yl.BaseManager{constructor(e={}){var t,n,s;super(e),this._commsOverSubshells=Ni.CommsOverSubshells.PerCommTarget,this._isReady=!1,this._kernelConnections=new Set,this._models=new Map,this._runningChanged=new Ai.Signal(this),this._connectionFailure=new Ai.Signal(this),this._kernelInfoTimeout=Li.DEFAULT_KERNEL_INFO_TIMEOUT,this._kernelAPIClient=(t=e.kernelAPIClient)!==null&&t!==void 0?t:new Ql.KernelAPIClient({serverSettings:this.serverSettings}),this._kernelSpecAPIClient=(n=e.kernelSpecAPIClient)!==null&&n!==void 0?n:new Zl.KernelSpecAPIClient({serverSettings:this.serverSettings}),this._pollModels=new Xl.Poll({auto:!1,factory:()=>this.requestRunning(),frequency:{interval:10*1e3,backoff:!0,max:300*1e3},name:"@jupyterlab/services:KernelManager#models",standby:(s=e.standby)!==null&&s!==void 0?s:"when-hidden"}),this._ready=(async()=>{await this._pollModels.start(),await this._pollModels.tick,this._isReady=!0})()}get isReady(){return this._isReady}get ready(){return this._ready}get runningChanged(){return this._runningChanged}get connectionFailure(){return this._connectionFailure}get kernelInfoTimeout(){return this._kernelInfoTimeout}set kernelInfoTimeout(e){this._kernelInfoTimeout=e}dispose(){this.isDisposed||(this._models.clear(),this._kernelConnections.forEach(e=>e.dispose()),this._pollModels.dispose(),super.dispose())}connectTo(e){var t;let{id:n}=e.model,s=(t=e.handleComms)!==null&&t!==void 0?t:!0;if(e.handleComms===void 0){for(let o of this._kernelConnections)if(o.id===n&&o.handleComms){s=!1;break}}e.commsOverSubshells=this._commsOverSubshells;let i=new Li.KernelConnection({handleComms:s,...e,serverSettings:this.serverSettings,kernelAPIClient:this._kernelAPIClient,kernelSpecAPIClient:this._kernelSpecAPIClient,kernelInfoTimeout:this._kernelInfoTimeout});return this._onStarted(i),this._models.has(n)||this.refreshRunning().catch(()=>{}),i}running(){return this._models.values()}get runningCount(){return this._models.size}get commsOverSubshells(){return this._commsOverSubshells}set commsOverSubshells(e){this._commsOverSubshells=e;for(let t of this._kernelConnections)t.commsOverSubshells=e}async refreshRunning(){await this._pollModels.refresh(),await this._pollModels.tick}async startNew(e={},t={}){let n=await this._kernelAPIClient.startNew(e);return this.connectTo({...t,model:n})}async shutdown(e){await this._kernelAPIClient.shutdown(e),await this.refreshRunning()}async shutdownAll(){await this.refreshRunning(),await Promise.all([...this._models.keys()].map(e=>this._kernelAPIClient.shutdown(e))),await this.refreshRunning()}async findById(e){return this._models.has(e)?this._models.get(e):(await this.refreshRunning(),this._models.get(e))}async requestRunning(){var e,t;let n;try{n=await this._kernelAPIClient.listRunning()}catch(s){throw(s instanceof Ni.ServerConnection.NetworkError||((e=s.response)===null||e===void 0?void 0:e.status)===503||((t=s.response)===null||t===void 0?void 0:t.status)===424)&&this._connectionFailure.emit(s),s}this.isDisposed||this._models.size===n.length&&n.every(s=>{let i=this._models.get(s.id);return i?i.connections===s.connections&&i.execution_state===s.execution_state&&i.last_activity===s.last_activity&&i.name===s.name&&i.reason===s.reason&&i.traceback===s.traceback:!1})||(this._models=new Map(n.map(s=>[s.id,s])),this._kernelConnections.forEach(s=>{this._models.has(s.id)||s.handleShutdown()}),this._runningChanged.emit(n))}_onStarted(e){this._kernelConnections.add(e),e.statusChanged.connect(this._onStatusChanged,this),e.disposed.connect(this._onDisposed,this)}_onDisposed(e){this._kernelConnections.delete(e),this.refreshRunning().catch(()=>{})}_onStatusChanged(e,t){t==="dead"&&this.refreshRunning().catch(()=>{})}};mt.KernelManager=pt;(function(r){class e extends r{constructor(){super(...arguments),this._readyPromise=new Promise(()=>{})}get isActive(){return!1}get parentReady(){return super.ready}async startNew(n={},s={}){return Promise.reject(new Error("Not implemented in no-op Kernel Manager"))}connectTo(n){throw new Error("Not implemented in no-op Kernel Manager")}async shutdown(n){return Promise.reject(new Error("Not implemented in no-op Kernel Manager"))}get ready(){return this.parentReady.then(()=>this._readyPromise)}async requestRunning(){return Promise.resolve()}}r.NoopManager=e})(pt||(mt.KernelManager=pt={}))});var Es=O(H=>{"use strict";var Fi=H&&H.__createBinding||(Object.create?function(r,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,n,s)}:function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]}),ec=H&&H.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),Ms=H&&H.__importStar||function(){var r=function(e){return r=Object.getOwnPropertyNames||function(t){var n=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[n.length]=s);return n},r(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n=r(e),s=0;s<n.length;s++)n[s]!=="default"&&Fi(t,e,n[s]);return ec(t,e),t}}(),tc=H&&H.__exportStar||function(r,e){for(var t in r)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&Fi(e,r,t)};Object.defineProperty(H,"__esModule",{value:!0});H.CommsOverSubshells=H.KernelConnection=H.KernelAPI=H.KernelMessage=H.Kernel=void 0;var nc=vs();Object.defineProperty(H,"CommsOverSubshells",{enumerable:!0,get:function(){return nc.CommsOverSubshells}});var sc=Ms(mi());H.Kernel=sc;var rc=Ms(et());H.KernelMessage=rc;var ic=Ms(gn());H.KernelAPI=ic;var oc=Ps();Object.defineProperty(H,"KernelConnection",{enumerable:!0,get:function(){return oc.KernelConnection}});tc(xi(),H)});var zi=O(Ki=>{"use strict";Object.defineProperty(Ki,"__esModule",{value:!0})});var Bi=O(vn=>{"use strict";Object.defineProperty(vn,"__esModule",{value:!0});vn.KernelSpecManager=void 0;var ac=X(),lc=Ge(),Vi=ee(),cc=Je(),uc=_t(),Is=class extends cc.BaseManager{constructor(e={}){var t,n;super(e),this._isReady=!1,this._connectionFailure=new Vi.Signal(this),this._specs=null,this._specsChanged=new Vi.Signal(this),this._kernelSpecAPIClient=(t=e.kernelSpecAPIClient)!==null&&t!==void 0?t:new uc.KernelSpecAPIClient({serverSettings:this.serverSettings}),this._ready=Promise.all([this.requestSpecs()]).then(s=>{}).catch(s=>{}).then(()=>{this.isDisposed||(this._isReady=!0)}),this._pollSpecs=new lc.Poll({auto:!1,factory:()=>this.requestSpecs(),frequency:{interval:61*1e3,backoff:!0,max:300*1e3},name:"@jupyterlab/services:KernelSpecManager#specs",standby:(n=e.standby)!==null&&n!==void 0?n:"when-hidden"}),this.ready.then(()=>{this._pollSpecs.start()})}get isReady(){return this._isReady}get ready(){return this._ready}get specs(){return this._specs}get specsChanged(){return this._specsChanged}get connectionFailure(){return this._connectionFailure}dispose(){this._pollSpecs.dispose(),super.dispose()}async refreshSpecs(){await this._pollSpecs.refresh(),await this._pollSpecs.tick}async requestSpecs(){let e=await this._kernelSpecAPIClient.get();this.isDisposed||ac.JSONExt.deepEqual(e,this._specs)||(this._specs=e,this._specsChanged.emit(e))}};vn.KernelSpecManager=Is});var Os=O(fe=>{"use strict";var $i=fe&&fe.__createBinding||(Object.create?function(r,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,n,s)}:function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]}),hc=fe&&fe.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),Wi=fe&&fe.__importStar||function(){var r=function(e){return r=Object.getOwnPropertyNames||function(t){var n=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[n.length]=s);return n},r(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n=r(e),s=0;s<n.length;s++)n[s]!=="default"&&$i(t,e,n[s]);return hc(t,e),t}}(),dc=fe&&fe.__exportStar||function(r,e){for(var t in r)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&$i(e,r,t)};Object.defineProperty(fe,"__esModule",{value:!0});fe.KernelSpecAPI=fe.KernelSpec=void 0;var fc=Wi(zi());fe.KernelSpec=fc;var _c=Wi(_t());fe.KernelSpecAPI=_c;dc(Bi(),fe)});var Hi=O(yn=>{"use strict";Object.defineProperty(yn,"__esModule",{value:!0});yn.BuildManager=void 0;var Rs=te(),$e=he(),gc="api/build",ks=class{constructor(e={}){var t;this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:$e.ServerConnection.makeSettings()}get isAvailable(){return Rs.PageConfig.getOption("buildAvailable").toLowerCase()==="true"}get shouldCheck(){return Rs.PageConfig.getOption("buildCheck").toLowerCase()==="true"}getStatus(){let{_url:e,serverSettings:t}=this;return $e.ServerConnection.makeRequest(e,{},t).then(s=>{if(s.status!==200)throw new $e.ServerConnection.ResponseError(s);return s.json()}).then(s=>{if(typeof s.status!="string")throw new Error("Invalid data");if(typeof s.message!="string")throw new Error("Invalid data");return s})}build(){let{_url:e,serverSettings:t}=this,n={method:"POST"};return $e.ServerConnection.makeRequest(e,n,t).then(i=>{if(i.status===400)throw new $e.ServerConnection.ResponseError(i,"Build aborted");if(i.status!==200){let o=`Build failed with ${i.status}.
4
4
 
5
5
  If you are experiencing the build failure after installing an extension (or trying to include previously installed extension after updating JupyterLab) please check the extension repository for new installation instructions as many extensions migrated to the prebuilt extensions system which no longer requires rebuilding JupyterLab (but uses a different installation procedure, typically involving a package manager such as 'pip' or 'conda').
6
6
 
7
- If you specifically intended to install a source extension, please run 'jupyter lab build' on the server for full output.`;throw new $e.ServerConnection.ResponseError(i,o)}})}cancel(){let{_url:e,serverSettings:t}=this,n={method:"DELETE"};return $e.ServerConnection.makeRequest(e,n,t).then(i=>{if(i.status!==204)throw new $e.ServerConnection.ResponseError(i)})}get _url(){let{baseUrl:e,appUrl:t}=this.serverSettings;return Rs.URLExt.join(e,t,_c)}};yn.BuildManager=ks});var js=O(wn=>{"use strict";Object.defineProperty(wn,"__esModule",{value:!0});wn.NbConvertManager=void 0;var Ds=te(),Ts=he(),gc=X(),pc="api/nbconvert",mc="nbconvert",qs=class{constructor(e={}){var t;this._exportFormats=null,this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:Ts.ServerConnection.makeSettings()}async fetchExportFormats(){this._requestingFormats=new gc.PromiseDelegate,this._exportFormats=null;let e=this.serverSettings.baseUrl,t=Ds.URLExt.join(e,pc),{serverSettings:n}=this,s=await Ts.ServerConnection.makeRequest(t,{},n);if(s.status!==200)throw await Ts.ServerConnection.ResponseError.create(s);let i=await s.json(),o={};return Object.keys(i).forEach(function(h){let c=i[h].output_mimetype;o[h]={output_mimetype:c}}),this._exportFormats=o,this._requestingFormats.resolve(o),o}async getExportFormats(e=!0){return this._requestingFormats?this._requestingFormats.promise:e||!this._exportFormats?await this.fetchExportFormats():this._exportFormats}async exportAs(e){let{format:t,path:n}=e,{download:s=!1,sanitizeHtml:i=!1}=e.exporterOptions||{},o=this.serverSettings.baseUrl,a=Ds.URLExt.encodeParts(n),h=Ds.URLExt.join(o,mc,t,a),c=new URLSearchParams;s&&c.set("download","true"),i&&c.set("sanitize_html","true");let u=c.toString();u&&(h+=`?${u}`),window==null||window.open(h,"_blank","noopener")}};wn.NbConvertManager=qs});var Gi=O(Ji=>{"use strict";Object.defineProperty(Ji,"__esModule",{value:!0})});var Yi=O(yt=>{"use strict";Object.defineProperty(yt,"__esModule",{value:!0});yt.validateModel=Xi;yt.updateLegacySessionModel=yc;yt.validateModels=wc;var vc=fn(),vt=lt();function Xi(r){(0,vt.validateProperty)(r,"id","string"),(0,vt.validateProperty)(r,"type","string"),(0,vt.validateProperty)(r,"name","string"),(0,vt.validateProperty)(r,"path","string"),(0,vt.validateProperty)(r,"kernel","object"),(0,vc.validateModel)(r.kernel)}function yc(r){r.path===void 0&&r.notebook!==void 0&&(r.path=r.notebook.path,r.type="notebook",r.name="")}function wc(r){if(!Array.isArray(r))throw new Error("Invalid session list");r.forEach(e=>Xi(e))}});var Cn=O(_e=>{"use strict";Object.defineProperty(_e,"__esModule",{value:!0});_e.SessionAPIClient=_e.SESSION_SERVICE_URL=void 0;_e.listRunning=Qi;_e.getSessionUrl=bn;_e.shutdownSession=Zi;_e.getSessionModel=eo;_e.startSession=to;_e.updateSession=no;var ae=he(),Sn=te(),We=Yi();_e.SESSION_SERVICE_URL="api/sessions";async function Qi(r=ae.ServerConnection.makeSettings()){let e=Sn.URLExt.join(r.baseUrl,_e.SESSION_SERVICE_URL),t=await ae.ServerConnection.makeRequest(e,{},r);if(t.status!==200)throw await ae.ServerConnection.ResponseError.create(t);let n=await t.json();if(!Array.isArray(n))throw new Error("Invalid Session list");return n.forEach(s=>{(0,We.updateLegacySessionModel)(s),(0,We.validateModel)(s)}),n}function bn(r,e){let t=Sn.URLExt.join(r,_e.SESSION_SERVICE_URL),n=Sn.URLExt.join(t,e);if(!n.startsWith(t))throw new Error("Can only be used for services requests");return n}async function Zi(r,e=ae.ServerConnection.makeSettings()){var t;let n=bn(e.baseUrl,r),s={method:"DELETE"},i=await ae.ServerConnection.makeRequest(n,s,e);if(i.status===404){let a=(t=(await i.json()).message)!==null&&t!==void 0?t:`The session "${r}"" does not exist on the server`;console.warn(a)}else{if(i.status===410)throw new ae.ServerConnection.ResponseError(i,"The kernel was deleted but the session was not");if(i.status!==204)throw await ae.ServerConnection.ResponseError.create(i)}}async function eo(r,e=ae.ServerConnection.makeSettings()){let t=bn(e.baseUrl,r),n=await ae.ServerConnection.makeRequest(t,{},e);if(n.status!==200)throw await ae.ServerConnection.ResponseError.create(n);let s=await n.json();return(0,We.updateLegacySessionModel)(s),(0,We.validateModel)(s),s}async function to(r,e=ae.ServerConnection.makeSettings()){let t=Sn.URLExt.join(e.baseUrl,_e.SESSION_SERVICE_URL),n={method:"POST",body:JSON.stringify(r)},s=await ae.ServerConnection.makeRequest(t,n,e);if(s.status!==201)throw await ae.ServerConnection.ResponseError.create(s);let i=await s.json();return(0,We.updateLegacySessionModel)(i),(0,We.validateModel)(i),i}async function no(r,e=ae.ServerConnection.makeSettings()){let t=bn(e.baseUrl,r.id),n={method:"PATCH",body:JSON.stringify(r)},s=await ae.ServerConnection.makeRequest(t,n,e);if(s.status!==200)throw await ae.ServerConnection.ResponseError.create(s);let i=await s.json();return(0,We.updateLegacySessionModel)(i),(0,We.validateModel)(i),i}var Us=class{constructor(e){var t;this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:ae.ServerConnection.makeSettings()}async listRunning(){return Qi(this.serverSettings)}async getModel(e){return eo(e,this.serverSettings)}async startNew(e){return to(e,this.serverSettings)}async shutdown(e){return Zi(e,this.serverSettings)}async update(e){return no(e,this.serverSettings)}};_e.SessionAPIClient=Us});var so=O(Pn=>{"use strict";Object.defineProperty(Pn,"__esModule",{value:!0});Pn.SessionConnection=void 0;var qe=ee(),Sc=Ae(),bc=X(),Cc=Cn(),As=class{constructor(e){var t,n,s,i,o;this._id="",this._path="",this._name="",this._type="",this._kernel=null,this._isDisposed=!1,this._disposed=new qe.Signal(this),this._kernelChanged=new qe.Signal(this),this._statusChanged=new qe.Signal(this),this._connectionStatusChanged=new qe.Signal(this),this._pendingInput=new qe.Signal(this),this._iopubMessage=new qe.Signal(this),this._unhandledMessage=new qe.Signal(this),this._anyMessage=new qe.Signal(this),this._propertyChanged=new qe.Signal(this),this._id=e.model.id,this._name=e.model.name,this._path=e.model.path,this._type=e.model.type,this._username=(t=e.username)!==null&&t!==void 0?t:"",this._clientId=(n=e.clientId)!==null&&n!==void 0?n:bc.UUID.uuid4(),this._connectToKernel=e.connectToKernel,this._kernelConnectionOptions=(s=e.kernelConnectionOptions)!==null&&s!==void 0?s:{},this.serverSettings=(i=e.serverSettings)!==null&&i!==void 0?i:Sc.ServerConnection.makeSettings(),this._sessionAPIClient=(o=e.sessionAPIClient)!==null&&o!==void 0?o:new Cc.SessionAPIClient({serverSettings:this.serverSettings}),this.setupKernel(e.model.kernel)}get disposed(){return this._disposed}get kernelChanged(){return this._kernelChanged}get statusChanged(){return this._statusChanged}get connectionStatusChanged(){return this._connectionStatusChanged}get pendingInput(){return this._pendingInput}get iopubMessage(){return this._iopubMessage}get unhandledMessage(){return this._unhandledMessage}get anyMessage(){return this._anyMessage}get propertyChanged(){return this._propertyChanged}get id(){return this._id}get kernel(){return this._kernel}get path(){return this._path}get type(){return this._type}get name(){return this._name}get model(){return{id:this.id,kernel:this.kernel&&{id:this.kernel.id,name:this.kernel.name},path:this._path,type:this._type,name:this._name}}get isDisposed(){return this._isDisposed}update(e){let t=this.model;if(this._path=e.path,this._name=e.name,this._type=e.type,this._kernel===null&&e.kernel!==null||this._kernel!==null&&e.kernel===null||this._kernel!==null&&e.kernel!==null&&this._kernel.id!==e.kernel.id){this._kernel!==null&&this._kernel.dispose();let n=this._kernel||null;this.setupKernel(e.kernel);let s=this._kernel||null;this._kernelChanged.emit({name:"kernel",oldValue:n,newValue:s})}this._handleModelChange(t)}dispose(){if(!this.isDisposed){if(this._isDisposed=!0,this._disposed.emit(),this._kernel){this._kernel.dispose();let e=this._kernel;this._kernel=null;let t=this._kernel;this._kernelChanged.emit({name:"kernel",oldValue:e,newValue:t})}qe.Signal.clearData(this)}}async setPath(e){if(this.isDisposed)throw new Error("Session is disposed");await this._patch({path:e})}async setName(e){if(this.isDisposed)throw new Error("Session is disposed");await this._patch({name:e})}async setType(e){if(this.isDisposed)throw new Error("Session is disposed");await this._patch({type:e})}async changeKernel(e){if(this.isDisposed)throw new Error("Session is disposed");return await this._patch({kernel:e}),this.kernel}async shutdown(){if(this.isDisposed)throw new Error("Session is disposed");await this._sessionAPIClient.shutdown(this.id),this.dispose()}setupKernel(e){if(e===null){this._kernel=null;return}let t=this._connectToKernel({...this._kernelConnectionOptions,model:e,username:this._username,clientId:this._clientId,serverSettings:this.serverSettings});this._kernel=t,t.statusChanged.connect(this.onKernelStatus,this),t.connectionStatusChanged.connect(this.onKernelConnectionStatus,this),t.pendingInput.connect(this.onPendingInput,this),t.unhandledMessage.connect(this.onUnhandledMessage,this),t.iopubMessage.connect(this.onIOPubMessage,this),t.anyMessage.connect(this.onAnyMessage,this)}onKernelStatus(e,t){this._statusChanged.emit(t)}onKernelConnectionStatus(e,t){this._connectionStatusChanged.emit(t)}onPendingInput(e,t){this._pendingInput.emit(t)}onIOPubMessage(e,t){this._iopubMessage.emit(t)}onUnhandledMessage(e,t){this._unhandledMessage.emit(t)}onAnyMessage(e,t){this._anyMessage.emit(t)}async _patch(e){let t=await this._sessionAPIClient.update({...e,id:this._id});return this.update(t),t}_handleModelChange(e){e.name!==this._name&&this._propertyChanged.emit("name"),e.type!==this._type&&this._propertyChanged.emit("type"),e.path!==this._path&&this._propertyChanged.emit("path")}};Pn.SessionConnection=As});var io=O(St=>{"use strict";Object.defineProperty(St,"__esModule",{value:!0});St.SessionManager=void 0;var Pc=Ge(),ro=ee(),Mc=he(),Ec=Je(),Ic=so(),Oc=Cn(),wt=class extends Ec.BaseManager{constructor(e){var t,n;super(e),this._isReady=!1,this._sessionConnections=new Set,this._models=new Map,this._runningChanged=new ro.Signal(this),this._connectionFailure=new ro.Signal(this),this._connectToKernel=s=>this._kernelManager.connectTo(s),this._kernelManager=e.kernelManager,this._sessionAPIClient=(t=e.sessionAPIClient)!==null&&t!==void 0?t:new Oc.SessionAPIClient({serverSettings:e.serverSettings}),this._pollModels=new Pc.Poll({auto:!1,factory:()=>this.requestRunning(),frequency:{interval:10*1e3,backoff:!0,max:300*1e3},name:"@jupyterlab/services:SessionManager#models",standby:(n=e.standby)!==null&&n!==void 0?n:"when-hidden"}),this._ready=(async()=>{await this._pollModels.start(),await this._pollModels.tick,this._kernelManager.isActive&&await this._kernelManager.ready,this._isReady=!0})()}get isReady(){return this._isReady}get ready(){return this._ready}get runningChanged(){return this._runningChanged}get connectionFailure(){return this._connectionFailure}dispose(){this.isDisposed||(this._models.clear(),this._sessionConnections.forEach(e=>e.dispose()),this._pollModels.dispose(),super.dispose())}connectTo(e){let t=new Ic.SessionConnection({...e,connectToKernel:this._connectToKernel,serverSettings:this.serverSettings,sessionAPIClient:this._sessionAPIClient});return this._onStarted(t),this._models.has(e.model.id)||this.refreshRunning().catch(()=>{}),t}running(){return this._models.values()}async refreshRunning(){await this._pollModels.refresh(),await this._pollModels.tick}async startNew(e,t={}){let n=await this._sessionAPIClient.startNew(e);return await this.refreshRunning(),this.connectTo({...t,model:n})}async shutdown(e){await this._sessionAPIClient.shutdown(e),await this.refreshRunning()}async shutdownAll(){await this.refreshRunning(),await Promise.all([...this._models.keys()].map(e=>this._sessionAPIClient.shutdown(e))),await this.refreshRunning()}async stopIfNeeded(e){try{let n=(await this._sessionAPIClient.listRunning()).filter(s=>s.path===e);if(n.length===1){let s=n[0].id;await this.shutdown(s)}}catch{}}async findById(e){return this._models.has(e)?this._models.get(e):(await this.refreshRunning(),this._models.get(e))}async findByPath(e){for(let t of this._models.values())if(t.path===e)return t;await this.refreshRunning();for(let t of this._models.values())if(t.path===e)return t}async requestRunning(){var e,t;let n;try{n=await this._sessionAPIClient.listRunning()}catch(s){throw(s instanceof Mc.ServerConnection.NetworkError||((e=s.response)===null||e===void 0?void 0:e.status)===503||((t=s.response)===null||t===void 0?void 0:t.status)===424)&&this._connectionFailure.emit(s),s}this.isDisposed||this._models.size===n.length&&n.every(s=>{var i,o,a,h;let c=this._models.get(s.id);return c?((i=c.kernel)===null||i===void 0?void 0:i.id)===((o=s.kernel)===null||o===void 0?void 0:o.id)&&((a=c.kernel)===null||a===void 0?void 0:a.name)===((h=s.kernel)===null||h===void 0?void 0:h.name)&&c.name===s.name&&c.path===s.path&&c.type===s.type:!1})||(this._models=new Map(n.map(s=>[s.id,s])),this._sessionConnections.forEach(s=>{this._models.has(s.id)?s.update(this._models.get(s.id)):s.dispose()}),this._runningChanged.emit(n))}_onStarted(e){this._sessionConnections.add(e),e.disposed.connect(this._onDisposed,this),e.propertyChanged.connect(this._onChanged,this),e.kernelChanged.connect(this._onChanged,this)}_onDisposed(e){this._sessionConnections.delete(e),this.refreshRunning().catch(()=>{})}_onChanged(){this.refreshRunning().catch(()=>{})}};St.SessionManager=wt;(function(r){class e extends r{constructor(){super(...arguments),this._readyPromise=new Promise(()=>{})}get isActive(){return!1}get parentReady(){return super.ready}async startNew(n,s={}){return Promise.reject(new Error("Not implemented in no-op Session Manager"))}connectTo(n){throw Error("Not implemented in no-op Session Manager")}get ready(){return this.parentReady.then(()=>this._readyPromise)}async shutdown(n){return Promise.reject(new Error("Not implemented in no-op Session Manager"))}async requestRunning(){return Promise.resolve()}}r.NoopManager=e})(wt||(St.SessionManager=wt={}))});var Ns=O(ge=>{"use strict";var oo=ge&&ge.__createBinding||(Object.create?function(r,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,n,s)}:function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]}),Rc=ge&&ge.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),ao=ge&&ge.__importStar||function(){var r=function(e){return r=Object.getOwnPropertyNames||function(t){var n=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[n.length]=s);return n},r(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n=r(e),s=0;s<n.length;s++)n[s]!=="default"&&oo(t,e,n[s]);return Rc(t,e),t}}(),kc=ge&&ge.__exportStar||function(r,e){for(var t in r)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&oo(e,r,t)};Object.defineProperty(ge,"__esModule",{value:!0});ge.SessionAPI=ge.Session=void 0;var Dc=ao(Gi());ge.Session=Dc;var Tc=ao(Cn());ge.SessionAPI=Tc;kc(io(),ge)});var lo=O(Mn=>{"use strict";Object.defineProperty(Mn,"__esModule",{value:!0});Mn.DataConnector=void 0;var Ls=class{async list(e){throw new Error("DataConnector#list method has not been implemented.")}async remove(e){throw new Error("DataConnector#remove method has not been implemented.")}async save(e,t){throw new Error("DataConnector#save method has not been implemented.")}};Mn.DataConnector=Ls});var uo=O(co=>{"use strict";Object.defineProperty(co,"__esModule",{value:!0})});var fo=O((En,ho)=>{(function(r,e){typeof En=="object"&&typeof ho!="undefined"?e(En):typeof define=="function"&&define.amd?define(["exports"],e):(r=typeof globalThis!="undefined"?globalThis:r||self,e(r.lumino_properties={}))})(En,function(r){"use strict";class e{constructor(s){this._pid=t.nextPID(),this.name=s.name,this._create=s.create,this._coerce=s.coerce||null,this._compare=s.compare||null,this._changed=s.changed||null}get(s){let i,o=t.ensureMap(s);return this._pid in o?i=o[this._pid]:i=o[this._pid]=this._createValue(s),i}set(s,i){let o,a=t.ensureMap(s);this._pid in a?o=a[this._pid]:o=a[this._pid]=this._createValue(s);let h=this._coerceValue(s,i);this._maybeNotify(s,o,a[this._pid]=h)}coerce(s){let i,o=t.ensureMap(s);this._pid in o?i=o[this._pid]:i=o[this._pid]=this._createValue(s);let a=this._coerceValue(s,i);this._maybeNotify(s,i,o[this._pid]=a)}_createValue(s){let i=this._create;return i(s)}_coerceValue(s,i){let o=this._coerce;return o?o(s,i):i}_compareValue(s,i){let o=this._compare;return o?o(s,i):s===i}_maybeNotify(s,i,o){let a=this._changed;a&&!this._compareValue(i,o)&&a(s,i,o)}}(function(n){function s(i){t.ownerData.delete(i)}n.clearData=s})(e||(e={}));var t;(function(n){n.ownerData=new WeakMap,n.nextPID=(()=>{let i=0;return()=>`pid-${`${Math.random()}`.slice(2)}-${i++}`})();function s(i){let o=n.ownerData.get(i);return o||(o=Object.create(null),n.ownerData.set(i,o),o)}n.ensureMap=s})(t||(t={})),r.AttachedProperty=e})});var go=O(On=>{"use strict";Object.defineProperty(On,"__esModule",{value:!0});On.RestorablePool=void 0;var qc=X(),_o=fo(),In=ee(),xs=class{constructor(e){this._added=new In.Signal(this),this._current=null,this._currentChanged=new In.Signal(this),this._hasRestored=!1,this._isDisposed=!1,this._objects=new Set,this._restore=null,this._restored=new qc.PromiseDelegate,this._updated=new In.Signal(this),this.namespace=e.namespace}get added(){return this._added}get current(){return this._current}set current(e){this._current!==e&&e!==null&&this._objects.has(e)&&(this._current=e,this._currentChanged.emit(this._current))}get currentChanged(){return this._currentChanged}get isDisposed(){return this._isDisposed}get restored(){return this._restored.promise}get size(){return this._objects.size}get updated(){return this._updated}async add(e){var t,n;if(e.isDisposed){let s="A disposed object cannot be added.";throw console.warn(s,e),new Error(s)}if(this._objects.has(e)){let s="This object already exists in the pool.";throw console.warn(s,e),new Error(s)}if(this._objects.add(e),e.disposed.connect(this._onInstanceDisposed,this),!je.injectedProperty.get(e)){if(this._restore){let{connector:s}=this._restore,i=this._restore.name(e);if(i){let o=`${this.namespace}:${i}`,a=(n=(t=this._restore).args)===null||n===void 0?void 0:n.call(t,e);je.nameProperty.set(e,o),await s.save(o,{data:a})}}this._added.emit(e)}}dispose(){this.isDisposed||(this._current=null,this._isDisposed=!0,this._objects.clear(),In.Signal.clearData(this))}find(e){let t=this._objects.values();for(let n of t)if(e(n))return n}forEach(e){this._objects.forEach(e)}filter(e){let t=[];return this.forEach(n=>{e(n)&&t.push(n)}),t}inject(e){return je.injectedProperty.set(e,!0),this.add(e)}has(e){return this._objects.has(e)}async restore(e){if(this._hasRestored)throw new Error("This pool has already been restored.");this._hasRestored=!0;let{command:t,connector:n,registry:s,when:i}=e,o=this.namespace,a=i?[n.list(o)].concat(i):[n.list(o)];this._restore=e;let[h]=await Promise.all(a),c=await Promise.all(h.ids.map(async(u,l)=>{let d=h.values[l],m=d&&d.data;return m===void 0?n.remove(u):s.execute(t,m).catch(()=>n.remove(u))}));return this._restored.resolve(),c}async save(e){var t,n;let s=je.injectedProperty.get(e);if(!this._restore||!this.has(e)||s)return;let{connector:i}=this._restore,o=this._restore.name(e),a=je.nameProperty.get(e),h=o?`${this.namespace}:${o}`:"";if(a&&a!==h&&await i.remove(a),je.nameProperty.set(e,h),h){let c=(n=(t=this._restore).args)===null||n===void 0?void 0:n.call(t,e);await i.save(h,{data:c})}a!==h&&this._updated.emit(e)}_onInstanceDisposed(e){if(this._objects.delete(e),e===this._current&&(this._current=null,this._currentChanged.emit(this._current)),je.injectedProperty.get(e)||!this._restore)return;let{connector:t}=this._restore,n=je.nameProperty.get(e);n&&t.remove(n)}};On.RestorablePool=xs;var je;(function(r){r.injectedProperty=new _o.AttachedProperty({name:"injected",create:()=>!1}),r.nameProperty=new _o.AttachedProperty({name:"name",create:()=>""})})(je||(je={}))});var po=O(Ct=>{"use strict";Object.defineProperty(Ct,"__esModule",{value:!0});Ct.StateDB=void 0;var jc=ee(),bt=class r{constructor(e={}){this._changed=new jc.Signal(this);let{connector:t,transform:n}=e;this._connector=t||new r.Connector,n?this._ready=n.then(s=>{let{contents:i,type:o}=s;switch(o){case"cancel":return;case"clear":return this._clear();case"merge":return this._merge(i||{});case"overwrite":return this._overwrite(i||{});default:return}}):this._ready=Promise.resolve(void 0)}get changed(){return this._changed}async clear(){await this._ready,await this._clear()}async fetch(e){return await this._ready,this._fetch(e)}async list(e){return await this._ready,this._list(e)}async remove(e){await this._ready,await this._remove(e),this._changed.emit({id:e,type:"remove"})}async save(e,t){await this._ready,await this._save(e,t),this._changed.emit({id:e,type:"save"})}async toJSON(){await this._ready;let{ids:e,values:t}=await this._list();return t.reduce((n,s,i)=>(n[e[i]]=s,n),{})}async _clear(){await Promise.all((await this._list()).ids.map(e=>this._remove(e)))}async _fetch(e){let t=await this._connector.fetch(e);if(t)return JSON.parse(t).v}async _list(e=""){let{ids:t,values:n}=await this._connector.list(e);return{ids:t,values:n.map(s=>JSON.parse(s).v)}}async _merge(e){await Promise.all(Object.keys(e).map(t=>e[t]&&this._save(t,e[t])))}async _overwrite(e){await this._clear(),await this._merge(e)}async _remove(e){return this._connector.remove(e)}async _save(e,t){return this._connector.save(e,JSON.stringify({v:t}))}};Ct.StateDB=bt;(function(r){class e{constructor(){this._storage={}}async fetch(n){return this._storage[n]}async list(n=""){return Object.keys(this._storage).reduce((s,i)=>((n===""||n===i.split(":")[0])&&(s.ids.push(i),s.values.push(this._storage[i])),s),{ids:[],values:[]})}async remove(n){delete this._storage[n]}async save(n,s){this._storage[n]=s}}r.Connector=e})(bt||(Ct.StateDB=bt={}))});var mo=O(Rn=>{"use strict";Object.defineProperty(Rn,"__esModule",{value:!0});Rn.IStateDB=void 0;var Uc=X();Rn.IStateDB=new Uc.Token("@jupyterlab/coreutils:IStateDB",`A service for the JupyterLab state database.
7
+ If you specifically intended to install a source extension, please run 'jupyter lab build' on the server for full output.`;throw new $e.ServerConnection.ResponseError(i,o)}})}cancel(){let{_url:e,serverSettings:t}=this,n={method:"DELETE"};return $e.ServerConnection.makeRequest(e,n,t).then(i=>{if(i.status!==204)throw new $e.ServerConnection.ResponseError(i)})}get _url(){let{baseUrl:e,appUrl:t}=this.serverSettings;return Rs.URLExt.join(e,t,gc)}};yn.BuildManager=ks});var js=O(wn=>{"use strict";Object.defineProperty(wn,"__esModule",{value:!0});wn.NbConvertManager=void 0;var Ds=te(),Ts=he(),pc=X(),mc="api/nbconvert",vc="nbconvert",qs=class{constructor(e={}){var t;this._exportFormats=null,this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:Ts.ServerConnection.makeSettings()}async fetchExportFormats(){this._requestingFormats=new pc.PromiseDelegate,this._exportFormats=null;let e=this.serverSettings.baseUrl,t=Ds.URLExt.join(e,mc),{serverSettings:n}=this,s=await Ts.ServerConnection.makeRequest(t,{},n);if(s.status!==200)throw await Ts.ServerConnection.ResponseError.create(s);let i=await s.json(),o={};return Object.keys(i).forEach(function(h){let c=i[h].output_mimetype;o[h]={output_mimetype:c}}),this._exportFormats=o,this._requestingFormats.resolve(o),o}async getExportFormats(e=!0){return this._requestingFormats?this._requestingFormats.promise:e||!this._exportFormats?await this.fetchExportFormats():this._exportFormats}async exportAs(e){let{format:t,path:n}=e,{download:s=!1,sanitizeHtml:i=!1}=e.exporterOptions||{},o=this.serverSettings.baseUrl,a=Ds.URLExt.encodeParts(n),h=Ds.URLExt.join(o,vc,t,a),c=new URLSearchParams;s&&c.set("download","true"),i&&c.set("sanitize_html","true");let u=c.toString();u&&(h+=`?${u}`),window==null||window.open(h,"_blank","noopener")}};wn.NbConvertManager=qs});var Gi=O(Ji=>{"use strict";Object.defineProperty(Ji,"__esModule",{value:!0})});var Yi=O(yt=>{"use strict";Object.defineProperty(yt,"__esModule",{value:!0});yt.validateModel=Xi;yt.updateLegacySessionModel=wc;yt.validateModels=Sc;var yc=fn(),vt=lt();function Xi(r){(0,vt.validateProperty)(r,"id","string"),(0,vt.validateProperty)(r,"type","string"),(0,vt.validateProperty)(r,"name","string"),(0,vt.validateProperty)(r,"path","string"),(0,vt.validateProperty)(r,"kernel","object"),(0,yc.validateModel)(r.kernel)}function wc(r){r.path===void 0&&r.notebook!==void 0&&(r.path=r.notebook.path,r.type="notebook",r.name="")}function Sc(r){if(!Array.isArray(r))throw new Error("Invalid session list");r.forEach(e=>Xi(e))}});var Cn=O(_e=>{"use strict";Object.defineProperty(_e,"__esModule",{value:!0});_e.SessionAPIClient=_e.SESSION_SERVICE_URL=void 0;_e.listRunning=Qi;_e.getSessionUrl=bn;_e.shutdownSession=Zi;_e.getSessionModel=eo;_e.startSession=to;_e.updateSession=no;var ae=he(),Sn=te(),We=Yi();_e.SESSION_SERVICE_URL="api/sessions";async function Qi(r=ae.ServerConnection.makeSettings()){let e=Sn.URLExt.join(r.baseUrl,_e.SESSION_SERVICE_URL),t=await ae.ServerConnection.makeRequest(e,{},r);if(t.status!==200)throw await ae.ServerConnection.ResponseError.create(t);let n=await t.json();if(!Array.isArray(n))throw new Error("Invalid Session list");return n.forEach(s=>{(0,We.updateLegacySessionModel)(s),(0,We.validateModel)(s)}),n}function bn(r,e){let t=Sn.URLExt.join(r,_e.SESSION_SERVICE_URL),n=Sn.URLExt.join(t,e);if(!n.startsWith(t))throw new Error("Can only be used for services requests");return n}async function Zi(r,e=ae.ServerConnection.makeSettings()){var t;let n=bn(e.baseUrl,r),s={method:"DELETE"},i=await ae.ServerConnection.makeRequest(n,s,e);if(i.status===404){let a=(t=(await i.json()).message)!==null&&t!==void 0?t:`The session "${r}"" does not exist on the server`;console.warn(a)}else{if(i.status===410)throw new ae.ServerConnection.ResponseError(i,"The kernel was deleted but the session was not");if(i.status!==204)throw await ae.ServerConnection.ResponseError.create(i)}}async function eo(r,e=ae.ServerConnection.makeSettings()){let t=bn(e.baseUrl,r),n=await ae.ServerConnection.makeRequest(t,{},e);if(n.status!==200)throw await ae.ServerConnection.ResponseError.create(n);let s=await n.json();return(0,We.updateLegacySessionModel)(s),(0,We.validateModel)(s),s}async function to(r,e=ae.ServerConnection.makeSettings()){let t=Sn.URLExt.join(e.baseUrl,_e.SESSION_SERVICE_URL),n={method:"POST",body:JSON.stringify(r)},s=await ae.ServerConnection.makeRequest(t,n,e);if(s.status!==201)throw await ae.ServerConnection.ResponseError.create(s);let i=await s.json();return(0,We.updateLegacySessionModel)(i),(0,We.validateModel)(i),i}async function no(r,e=ae.ServerConnection.makeSettings()){let t=bn(e.baseUrl,r.id),n={method:"PATCH",body:JSON.stringify(r)},s=await ae.ServerConnection.makeRequest(t,n,e);if(s.status!==200)throw await ae.ServerConnection.ResponseError.create(s);let i=await s.json();return(0,We.updateLegacySessionModel)(i),(0,We.validateModel)(i),i}var Us=class{constructor(e){var t;this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:ae.ServerConnection.makeSettings()}async listRunning(){return Qi(this.serverSettings)}async getModel(e){return eo(e,this.serverSettings)}async startNew(e){return to(e,this.serverSettings)}async shutdown(e){return Zi(e,this.serverSettings)}async update(e){return no(e,this.serverSettings)}};_e.SessionAPIClient=Us});var so=O(Pn=>{"use strict";Object.defineProperty(Pn,"__esModule",{value:!0});Pn.SessionConnection=void 0;var qe=ee(),bc=Ae(),Cc=X(),Pc=Cn(),As=class{constructor(e){var t,n,s,i,o;this._id="",this._path="",this._name="",this._type="",this._kernel=null,this._isDisposed=!1,this._disposed=new qe.Signal(this),this._kernelChanged=new qe.Signal(this),this._statusChanged=new qe.Signal(this),this._connectionStatusChanged=new qe.Signal(this),this._pendingInput=new qe.Signal(this),this._iopubMessage=new qe.Signal(this),this._unhandledMessage=new qe.Signal(this),this._anyMessage=new qe.Signal(this),this._propertyChanged=new qe.Signal(this),this._id=e.model.id,this._name=e.model.name,this._path=e.model.path,this._type=e.model.type,this._username=(t=e.username)!==null&&t!==void 0?t:"",this._clientId=(n=e.clientId)!==null&&n!==void 0?n:Cc.UUID.uuid4(),this._connectToKernel=e.connectToKernel,this._kernelConnectionOptions=(s=e.kernelConnectionOptions)!==null&&s!==void 0?s:{},this.serverSettings=(i=e.serverSettings)!==null&&i!==void 0?i:bc.ServerConnection.makeSettings(),this._sessionAPIClient=(o=e.sessionAPIClient)!==null&&o!==void 0?o:new Pc.SessionAPIClient({serverSettings:this.serverSettings}),this.setupKernel(e.model.kernel)}get disposed(){return this._disposed}get kernelChanged(){return this._kernelChanged}get statusChanged(){return this._statusChanged}get connectionStatusChanged(){return this._connectionStatusChanged}get pendingInput(){return this._pendingInput}get iopubMessage(){return this._iopubMessage}get unhandledMessage(){return this._unhandledMessage}get anyMessage(){return this._anyMessage}get propertyChanged(){return this._propertyChanged}get id(){return this._id}get kernel(){return this._kernel}get path(){return this._path}get type(){return this._type}get name(){return this._name}get model(){return{id:this.id,kernel:this.kernel&&{id:this.kernel.id,name:this.kernel.name},path:this._path,type:this._type,name:this._name}}get isDisposed(){return this._isDisposed}update(e){let t=this.model;if(this._path=e.path,this._name=e.name,this._type=e.type,this._kernel===null&&e.kernel!==null||this._kernel!==null&&e.kernel===null||this._kernel!==null&&e.kernel!==null&&this._kernel.id!==e.kernel.id){this._kernel!==null&&this._kernel.dispose();let n=this._kernel||null;this.setupKernel(e.kernel);let s=this._kernel||null;this._kernelChanged.emit({name:"kernel",oldValue:n,newValue:s})}this._handleModelChange(t)}dispose(){if(!this.isDisposed){if(this._isDisposed=!0,this._disposed.emit(),this._kernel){this._kernel.dispose();let e=this._kernel;this._kernel=null;let t=this._kernel;this._kernelChanged.emit({name:"kernel",oldValue:e,newValue:t})}qe.Signal.clearData(this)}}async setPath(e){if(this.isDisposed)throw new Error("Session is disposed");await this._patch({path:e})}async setName(e){if(this.isDisposed)throw new Error("Session is disposed");await this._patch({name:e})}async setType(e){if(this.isDisposed)throw new Error("Session is disposed");await this._patch({type:e})}async changeKernel(e){if(this.isDisposed)throw new Error("Session is disposed");return await this._patch({kernel:e}),this.kernel}async shutdown(){if(this.isDisposed)throw new Error("Session is disposed");await this._sessionAPIClient.shutdown(this.id),this.dispose()}setupKernel(e){if(e===null){this._kernel=null;return}let t=this._connectToKernel({...this._kernelConnectionOptions,model:e,username:this._username,clientId:this._clientId,serverSettings:this.serverSettings});this._kernel=t,t.statusChanged.connect(this.onKernelStatus,this),t.connectionStatusChanged.connect(this.onKernelConnectionStatus,this),t.pendingInput.connect(this.onPendingInput,this),t.unhandledMessage.connect(this.onUnhandledMessage,this),t.iopubMessage.connect(this.onIOPubMessage,this),t.anyMessage.connect(this.onAnyMessage,this)}onKernelStatus(e,t){this._statusChanged.emit(t)}onKernelConnectionStatus(e,t){this._connectionStatusChanged.emit(t)}onPendingInput(e,t){this._pendingInput.emit(t)}onIOPubMessage(e,t){this._iopubMessage.emit(t)}onUnhandledMessage(e,t){this._unhandledMessage.emit(t)}onAnyMessage(e,t){this._anyMessage.emit(t)}async _patch(e){let t=await this._sessionAPIClient.update({...e,id:this._id});return this.update(t),t}_handleModelChange(e){e.name!==this._name&&this._propertyChanged.emit("name"),e.type!==this._type&&this._propertyChanged.emit("type"),e.path!==this._path&&this._propertyChanged.emit("path")}};Pn.SessionConnection=As});var io=O(St=>{"use strict";Object.defineProperty(St,"__esModule",{value:!0});St.SessionManager=void 0;var Mc=Ge(),ro=ee(),Ec=he(),Ic=Je(),Oc=so(),Rc=Cn(),wt=class extends Ic.BaseManager{constructor(e){var t,n;super(e),this._isReady=!1,this._sessionConnections=new Set,this._models=new Map,this._runningChanged=new ro.Signal(this),this._connectionFailure=new ro.Signal(this),this._connectToKernel=s=>this._kernelManager.connectTo(s),this._kernelManager=e.kernelManager,this._sessionAPIClient=(t=e.sessionAPIClient)!==null&&t!==void 0?t:new Rc.SessionAPIClient({serverSettings:e.serverSettings}),this._pollModels=new Mc.Poll({auto:!1,factory:()=>this.requestRunning(),frequency:{interval:10*1e3,backoff:!0,max:300*1e3},name:"@jupyterlab/services:SessionManager#models",standby:(n=e.standby)!==null&&n!==void 0?n:"when-hidden"}),this._ready=(async()=>{await this._pollModels.start(),await this._pollModels.tick,this._kernelManager.isActive&&await this._kernelManager.ready,this._isReady=!0})()}get isReady(){return this._isReady}get ready(){return this._ready}get runningChanged(){return this._runningChanged}get connectionFailure(){return this._connectionFailure}dispose(){this.isDisposed||(this._models.clear(),this._sessionConnections.forEach(e=>e.dispose()),this._pollModels.dispose(),super.dispose())}connectTo(e){let t=new Oc.SessionConnection({...e,connectToKernel:this._connectToKernel,serverSettings:this.serverSettings,sessionAPIClient:this._sessionAPIClient});return this._onStarted(t),this._models.has(e.model.id)||this.refreshRunning().catch(()=>{}),t}running(){return this._models.values()}async refreshRunning(){await this._pollModels.refresh(),await this._pollModels.tick}async startNew(e,t={}){let n=await this._sessionAPIClient.startNew(e);return await this.refreshRunning(),this.connectTo({...t,model:n})}async shutdown(e){await this._sessionAPIClient.shutdown(e),await this.refreshRunning()}async shutdownAll(){await this.refreshRunning(),await Promise.all([...this._models.keys()].map(e=>this._sessionAPIClient.shutdown(e))),await this.refreshRunning()}async stopIfNeeded(e){try{let n=(await this._sessionAPIClient.listRunning()).filter(s=>s.path===e);if(n.length===1){let s=n[0].id;await this.shutdown(s)}}catch{}}async findById(e){return this._models.has(e)?this._models.get(e):(await this.refreshRunning(),this._models.get(e))}async findByPath(e){for(let t of this._models.values())if(t.path===e)return t;await this.refreshRunning();for(let t of this._models.values())if(t.path===e)return t}async requestRunning(){var e,t;let n;try{n=await this._sessionAPIClient.listRunning()}catch(s){throw(s instanceof Ec.ServerConnection.NetworkError||((e=s.response)===null||e===void 0?void 0:e.status)===503||((t=s.response)===null||t===void 0?void 0:t.status)===424)&&this._connectionFailure.emit(s),s}this.isDisposed||this._models.size===n.length&&n.every(s=>{var i,o,a,h;let c=this._models.get(s.id);return c?((i=c.kernel)===null||i===void 0?void 0:i.id)===((o=s.kernel)===null||o===void 0?void 0:o.id)&&((a=c.kernel)===null||a===void 0?void 0:a.name)===((h=s.kernel)===null||h===void 0?void 0:h.name)&&c.name===s.name&&c.path===s.path&&c.type===s.type:!1})||(this._models=new Map(n.map(s=>[s.id,s])),this._sessionConnections.forEach(s=>{this._models.has(s.id)?s.update(this._models.get(s.id)):s.dispose()}),this._runningChanged.emit(n))}_onStarted(e){this._sessionConnections.add(e),e.disposed.connect(this._onDisposed,this),e.propertyChanged.connect(this._onChanged,this),e.kernelChanged.connect(this._onChanged,this)}_onDisposed(e){this._sessionConnections.delete(e),this.refreshRunning().catch(()=>{})}_onChanged(){this.refreshRunning().catch(()=>{})}};St.SessionManager=wt;(function(r){class e extends r{constructor(){super(...arguments),this._readyPromise=new Promise(()=>{})}get isActive(){return!1}get parentReady(){return super.ready}async startNew(n,s={}){return Promise.reject(new Error("Not implemented in no-op Session Manager"))}connectTo(n){throw Error("Not implemented in no-op Session Manager")}get ready(){return this.parentReady.then(()=>this._readyPromise)}async shutdown(n){return Promise.reject(new Error("Not implemented in no-op Session Manager"))}async requestRunning(){return Promise.resolve()}}r.NoopManager=e})(wt||(St.SessionManager=wt={}))});var Ns=O(ge=>{"use strict";var oo=ge&&ge.__createBinding||(Object.create?function(r,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,n,s)}:function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]}),kc=ge&&ge.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),ao=ge&&ge.__importStar||function(){var r=function(e){return r=Object.getOwnPropertyNames||function(t){var n=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[n.length]=s);return n},r(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n=r(e),s=0;s<n.length;s++)n[s]!=="default"&&oo(t,e,n[s]);return kc(t,e),t}}(),Dc=ge&&ge.__exportStar||function(r,e){for(var t in r)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&oo(e,r,t)};Object.defineProperty(ge,"__esModule",{value:!0});ge.SessionAPI=ge.Session=void 0;var Tc=ao(Gi());ge.Session=Tc;var qc=ao(Cn());ge.SessionAPI=qc;Dc(io(),ge)});var lo=O(Mn=>{"use strict";Object.defineProperty(Mn,"__esModule",{value:!0});Mn.DataConnector=void 0;var Ls=class{async list(e){throw new Error("DataConnector#list method has not been implemented.")}async remove(e){throw new Error("DataConnector#remove method has not been implemented.")}async save(e,t){throw new Error("DataConnector#save method has not been implemented.")}};Mn.DataConnector=Ls});var uo=O(co=>{"use strict";Object.defineProperty(co,"__esModule",{value:!0})});var fo=O((En,ho)=>{(function(r,e){typeof En=="object"&&typeof ho!="undefined"?e(En):typeof define=="function"&&define.amd?define(["exports"],e):(r=typeof globalThis!="undefined"?globalThis:r||self,e(r.lumino_properties={}))})(En,function(r){"use strict";class e{constructor(s){this._pid=t.nextPID(),this.name=s.name,this._create=s.create,this._coerce=s.coerce||null,this._compare=s.compare||null,this._changed=s.changed||null}get(s){let i,o=t.ensureMap(s);return this._pid in o?i=o[this._pid]:i=o[this._pid]=this._createValue(s),i}set(s,i){let o,a=t.ensureMap(s);this._pid in a?o=a[this._pid]:o=a[this._pid]=this._createValue(s);let h=this._coerceValue(s,i);this._maybeNotify(s,o,a[this._pid]=h)}coerce(s){let i,o=t.ensureMap(s);this._pid in o?i=o[this._pid]:i=o[this._pid]=this._createValue(s);let a=this._coerceValue(s,i);this._maybeNotify(s,i,o[this._pid]=a)}_createValue(s){let i=this._create;return i(s)}_coerceValue(s,i){let o=this._coerce;return o?o(s,i):i}_compareValue(s,i){let o=this._compare;return o?o(s,i):s===i}_maybeNotify(s,i,o){let a=this._changed;a&&!this._compareValue(i,o)&&a(s,i,o)}}(function(n){function s(i){t.ownerData.delete(i)}n.clearData=s})(e||(e={}));var t;(function(n){n.ownerData=new WeakMap,n.nextPID=(()=>{let i=0;return()=>`pid-${`${Math.random()}`.slice(2)}-${i++}`})();function s(i){let o=n.ownerData.get(i);return o||(o=Object.create(null),n.ownerData.set(i,o),o)}n.ensureMap=s})(t||(t={})),r.AttachedProperty=e})});var go=O(On=>{"use strict";Object.defineProperty(On,"__esModule",{value:!0});On.RestorablePool=void 0;var jc=X(),_o=fo(),In=ee(),xs=class{constructor(e){this._added=new In.Signal(this),this._current=null,this._currentChanged=new In.Signal(this),this._hasRestored=!1,this._isDisposed=!1,this._objects=new Set,this._restore=null,this._restored=new jc.PromiseDelegate,this._updated=new In.Signal(this),this.namespace=e.namespace}get added(){return this._added}get current(){return this._current}set current(e){this._current!==e&&e!==null&&this._objects.has(e)&&(this._current=e,this._currentChanged.emit(this._current))}get currentChanged(){return this._currentChanged}get isDisposed(){return this._isDisposed}get restored(){return this._restored.promise}get size(){return this._objects.size}get updated(){return this._updated}async add(e){var t,n;if(e.isDisposed){let s="A disposed object cannot be added.";throw console.warn(s,e),new Error(s)}if(this._objects.has(e)){let s="This object already exists in the pool.";throw console.warn(s,e),new Error(s)}if(this._objects.add(e),e.disposed.connect(this._onInstanceDisposed,this),!je.injectedProperty.get(e)){if(this._restore){let{connector:s}=this._restore,i=this._restore.name(e);if(i){let o=`${this.namespace}:${i}`,a=(n=(t=this._restore).args)===null||n===void 0?void 0:n.call(t,e);je.nameProperty.set(e,o),await s.save(o,{data:a})}}this._added.emit(e)}}dispose(){this.isDisposed||(this._current=null,this._isDisposed=!0,this._objects.clear(),In.Signal.clearData(this))}find(e){let t=this._objects.values();for(let n of t)if(e(n))return n}forEach(e){this._objects.forEach(e)}filter(e){let t=[];return this.forEach(n=>{e(n)&&t.push(n)}),t}inject(e){return je.injectedProperty.set(e,!0),this.add(e)}has(e){return this._objects.has(e)}async restore(e){if(this._hasRestored)throw new Error("This pool has already been restored.");this._hasRestored=!0;let{command:t,connector:n,registry:s,when:i}=e,o=this.namespace,a=i?[n.list(o)].concat(i):[n.list(o)];this._restore=e;let[h]=await Promise.all(a),c=await Promise.all(h.ids.map(async(u,l)=>{let d=h.values[l],m=d&&d.data;return m===void 0?n.remove(u):s.execute(t,m).catch(()=>n.remove(u))}));return this._restored.resolve(),c}async save(e){var t,n;let s=je.injectedProperty.get(e);if(!this._restore||!this.has(e)||s)return;let{connector:i}=this._restore,o=this._restore.name(e),a=je.nameProperty.get(e),h=o?`${this.namespace}:${o}`:"";if(a&&a!==h&&await i.remove(a),je.nameProperty.set(e,h),h){let c=(n=(t=this._restore).args)===null||n===void 0?void 0:n.call(t,e);await i.save(h,{data:c})}a!==h&&this._updated.emit(e)}_onInstanceDisposed(e){if(this._objects.delete(e),e===this._current&&(this._current=null,this._currentChanged.emit(this._current)),je.injectedProperty.get(e)||!this._restore)return;let{connector:t}=this._restore,n=je.nameProperty.get(e);n&&t.remove(n)}};On.RestorablePool=xs;var je;(function(r){r.injectedProperty=new _o.AttachedProperty({name:"injected",create:()=>!1}),r.nameProperty=new _o.AttachedProperty({name:"name",create:()=>""})})(je||(je={}))});var po=O(Ct=>{"use strict";Object.defineProperty(Ct,"__esModule",{value:!0});Ct.StateDB=void 0;var Uc=ee(),bt=class r{constructor(e={}){this._changed=new Uc.Signal(this);let{connector:t,transform:n}=e;this._connector=t||new r.Connector,n?this._ready=n.then(s=>{let{contents:i,type:o}=s;switch(o){case"cancel":return;case"clear":return this._clear();case"merge":return this._merge(i||{});case"overwrite":return this._overwrite(i||{});default:return}}):this._ready=Promise.resolve(void 0)}get changed(){return this._changed}async clear(){await this._ready,await this._clear()}async fetch(e){return await this._ready,this._fetch(e)}async list(e){return await this._ready,this._list(e)}async remove(e){await this._ready,await this._remove(e),this._changed.emit({id:e,type:"remove"})}async save(e,t){await this._ready,await this._save(e,t),this._changed.emit({id:e,type:"save"})}async toJSON(){await this._ready;let{ids:e,values:t}=await this._list();return t.reduce((n,s,i)=>(n[e[i]]=s,n),{})}async _clear(){await Promise.all((await this._list()).ids.map(e=>this._remove(e)))}async _fetch(e){let t=await this._connector.fetch(e);if(t)return JSON.parse(t).v}async _list(e=""){let{ids:t,values:n}=await this._connector.list(e);return{ids:t,values:n.map(s=>JSON.parse(s).v)}}async _merge(e){await Promise.all(Object.keys(e).map(t=>e[t]&&this._save(t,e[t])))}async _overwrite(e){await this._clear(),await this._merge(e)}async _remove(e){return this._connector.remove(e)}async _save(e,t){return this._connector.save(e,JSON.stringify({v:t}))}};Ct.StateDB=bt;(function(r){class e{constructor(){this._storage={}}async fetch(n){return this._storage[n]}async list(n=""){return Object.keys(this._storage).reduce((s,i)=>((n===""||n===i.split(":")[0])&&(s.ids.push(i),s.values.push(this._storage[i])),s),{ids:[],values:[]})}async remove(n){delete this._storage[n]}async save(n,s){this._storage[n]=s}}r.Connector=e})(bt||(Ct.StateDB=bt={}))});var mo=O(Rn=>{"use strict";Object.defineProperty(Rn,"__esModule",{value:!0});Rn.IStateDB=void 0;var Ac=X();Rn.IStateDB=new Ac.Token("@jupyterlab/coreutils:IStateDB",`A service for the JupyterLab state database.
8
8
  Use this if you want to store data that will persist across page loads.
9
- See "state database" for more information.`)});var Fs=O(Ee=>{"use strict";var Ac=Ee&&Ee.__createBinding||(Object.create?function(r,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,n,s)}:function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]}),Pt=Ee&&Ee.__exportStar||function(r,e){for(var t in r)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&Ac(e,r,t)};Object.defineProperty(Ee,"__esModule",{value:!0});Pt(lo(),Ee);Pt(uo(),Ee);Pt(go(),Ee);Pt(po(),Ee);Pt(mo(),Ee)});var Vs=O(Dn=>{"use strict";Object.defineProperty(Dn,"__esModule",{value:!0});Dn.SettingManager=void 0;var Ks=te(),Nc=Fs(),kn=he(),Lc="api/settings",zs=class extends Nc.DataConnector{constructor(e={}){var t;super(),this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:kn.ServerConnection.makeSettings()}async fetch(e){if(!e)throw new Error("Plugin `id` parameter is required for settings fetch.");let{serverSettings:t}=this,{baseUrl:n,appUrl:s}=t,{makeRequest:i,ResponseError:o}=kn.ServerConnection,a=n+s,h=Mt.url(a,e),c=await i(h,{},t);if(c.status!==200)throw await o.create(c);return c.json()}async list(e){var t,n,s,i;let{serverSettings:o}=this,{baseUrl:a,appUrl:h}=o,{makeRequest:c,ResponseError:u}=kn.ServerConnection,l=a+h,d=Mt.url(l,"",e==="ids"),m=await c(d,{},o);if(m.status!==200)throw new u(m);let v=await m.json(),T=(n=(t=v==null?void 0:v.settings)===null||t===void 0?void 0:t.map(q=>q.id))!==null&&n!==void 0?n:[],E=[];return e||(E=(i=(s=v==null?void 0:v.settings)===null||s===void 0?void 0:s.map(q=>(q.data={composite:{},user:{}},q)))!==null&&i!==void 0?i:[]),{ids:T,values:E}}async save(e,t){let{serverSettings:n}=this,{baseUrl:s,appUrl:i}=n,{makeRequest:o,ResponseError:a}=kn.ServerConnection,h=s+i,c=Mt.url(h,e),u={body:JSON.stringify({raw:t}),method:"PUT"},l=await o(c,u,n);if(l.status!==204)throw new a(l)}};Dn.SettingManager=zs;var Mt;(function(r){function e(t,n,s){let i=s?Ks.URLExt.objectToQueryString({ids_only:!0}):"",o=Ks.URLExt.join(t,Lc),a=Ks.URLExt.join(o,n);if(!a.startsWith(o))throw new Error("Can only be used for workspaces requests");return`${a}${i}`}r.url=e})(Mt||(Mt={}))});var Ot=O(we=>{"use strict";Object.defineProperty(we,"__esModule",{value:!0});we.TerminalAPIClient=we.TERMINAL_SERVICE_URL=void 0;we.isAvailable=$s;we.startNew=vo;we.listRunning=yo;we.shutdownTerminal=wo;var Et=te(),Ue=he();we.TERMINAL_SERVICE_URL="api/terminals";function $s(){return String(Et.PageConfig.getOption("terminalsAvailable")).toLowerCase()==="true"}async function vo(r=Ue.ServerConnection.makeSettings(),e,t){It.errorIfNotAvailable();let n=Et.URLExt.join(r.baseUrl,we.TERMINAL_SERVICE_URL),s={method:"POST",body:JSON.stringify({name:e,cwd:t})},i=await Ue.ServerConnection.makeRequest(n,s,r);if(i.status!==200)throw await Ue.ServerConnection.ResponseError.create(i);return await i.json()}async function yo(r=Ue.ServerConnection.makeSettings()){It.errorIfNotAvailable();let e=Et.URLExt.join(r.baseUrl,we.TERMINAL_SERVICE_URL),t=await Ue.ServerConnection.makeRequest(e,{},r);if(t.status!==200)throw await Ue.ServerConnection.ResponseError.create(t);let n=await t.json();if(!Array.isArray(n))throw new Error("Invalid terminal list");return n}async function wo(r,e=Ue.ServerConnection.makeSettings()){var t;It.errorIfNotAvailable();let n=Et.URLExt.join(e.baseUrl,we.TERMINAL_SERVICE_URL),s=Et.URLExt.join(n,r);if(!s.startsWith(n))throw new Error("Can only be used for terminal requests");let i={method:"DELETE"},o=await Ue.ServerConnection.makeRequest(s,i,e);if(o.status===404){let h=(t=(await o.json()).message)!==null&&t!==void 0?t:`The terminal session "${r}"" does not exist on the server`;console.warn(h)}else if(o.status!==204)throw await Ue.ServerConnection.ResponseError.create(o)}var Bs=class{constructor(e={}){var t;this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:Ue.ServerConnection.makeSettings()}get isAvailable(){return $s()}async startNew(e={}){let{name:t,cwd:n}=e;return vo(this.serverSettings,t,n)}async listRunning(){return yo(this.serverSettings)}async shutdown(e){return wo(e,this.serverSettings)}};we.TerminalAPIClient=Bs;var It;(function(r){function e(){if(!$s())throw new Error("Terminals Unavailable")}r.errorIfNotAvailable=e})(It||(It={}))});var So=O(Tn=>{"use strict";Object.defineProperty(Tn,"__esModule",{value:!0});Tn.isAvailable=void 0;var xc=Ot();Object.defineProperty(Tn,"isAvailable",{enumerable:!0,get:function(){return xc.isAvailable}})});var bo=O(jn=>{"use strict";Object.defineProperty(jn,"__esModule",{value:!0});jn.TerminalConnection=void 0;var Fc=te(),Kc=X(),qn=ee(),zc=Ae(),Vc=Ot(),Ws=class r{constructor(e){var t,n;this._createSocket=()=>{this._errorIfDisposed(),this._clearSocket(),this._updateConnectionStatus("connecting");let s=this._name,i=this.serverSettings,o=Fc.URLExt.join(i.wsUrl,"terminals","websocket",encodeURIComponent(s)),a=i.token;i.appendToken&&a!==""&&(o=o+`?token=${encodeURIComponent(a)}`),this._ws=new i.WebSocket(o),this._ws.onmessage=this._onWSMessage,this._ws.onclose=this._onWSClose,this._ws.onerror=this._onWSClose},this._onWSMessage=s=>{if(this._isDisposed)return;let i=JSON.parse(s.data);if(i[0]==="disconnect"&&this.dispose(),this._connectionStatus==="connecting"){i[0]==="setup"&&this._updateConnectionStatus("connected");return}this._messageReceived.emit({type:i[0],content:i.slice(1)})},this._onWSClose=s=>{console.warn(`Terminal websocket closed: ${s.code}`),!this.isDisposed&&(s.code===1e3||s.code===1001||this._reconnect())},this._connectionStatus="connecting",this._connectionStatusChanged=new qn.Signal(this),this._isDisposed=!1,this._disposed=new qn.Signal(this),this._messageReceived=new qn.Signal(this),this._reconnectTimeout=null,this._ws=null,this._noOp=()=>{},this._reconnectLimit=7,this._reconnectAttempt=0,this._pendingMessages=[],this._name=e.model.name,this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:zc.ServerConnection.makeSettings(),this._terminalAPIClient=(n=e.terminalAPIClient)!==null&&n!==void 0?n:new Vc.TerminalAPIClient({serverSettings:this.serverSettings}),this._createSocket()}get disposed(){return this._disposed}get messageReceived(){return this._messageReceived}get name(){return this._name}get model(){return{name:this._name}}get isDisposed(){return this._isDisposed}dispose(){this._isDisposed||(this._isDisposed=!0,this._disposed.emit(),this._updateConnectionStatus("disconnected"),this._clearSocket(),qn.Signal.clearData(this))}send(e){this._sendMessage(e)}_sendMessage(e,t=!0){if(!(this._isDisposed||!e.content))if(this.connectionStatus==="connected"&&this._ws){let n=[e.type,...e.content];this._ws.send(JSON.stringify(n))}else if(t)this._pendingMessages.push(e);else throw new Error(`Could not send message: ${JSON.stringify(e)}`)}_sendPending(){for(;this.connectionStatus==="connected"&&this._pendingMessages.length>0;)this._sendMessage(this._pendingMessages[0],!1),this._pendingMessages.shift()}reconnect(){this._errorIfDisposed();let e=new Kc.PromiseDelegate,t=(n,s)=>{s==="connected"?(e.resolve(),this.connectionStatusChanged.disconnect(t,this)):s==="disconnected"&&(e.reject(new Error("Terminal connection disconnected")),this.connectionStatusChanged.disconnect(t,this))};return this.connectionStatusChanged.connect(t,this),this._reconnectAttempt=0,this._reconnect(),e.promise}_reconnect(){if(this._errorIfDisposed(),clearTimeout(this._reconnectTimeout),this._reconnectAttempt<this._reconnectLimit){this._updateConnectionStatus("connecting");let e=Hs.getRandomIntInclusive(0,1e3*(Math.pow(2,this._reconnectAttempt)-1));console.error(`Connection lost, reconnecting in ${Math.floor(e/1e3)} seconds.`),this._reconnectTimeout=setTimeout(this._createSocket,e),this._reconnectAttempt+=1}else this._updateConnectionStatus("disconnected");this._clearSocket()}_clearSocket(){this._ws!==null&&(this._ws.onopen=this._noOp,this._ws.onclose=this._noOp,this._ws.onerror=this._noOp,this._ws.onmessage=this._noOp,this._ws.close(),this._ws=null)}async shutdown(){await this._terminalAPIClient.shutdown(this.name),this.dispose()}clone(){return new r({model:this.model,serverSettings:this.serverSettings,terminalAPIClient:this._terminalAPIClient})}_updateConnectionStatus(e){this._connectionStatus!==e&&(this._connectionStatus=e,e!=="connecting"&&(this._reconnectAttempt=0,clearTimeout(this._reconnectTimeout)),e==="connected"&&this._sendPending(),this._connectionStatusChanged.emit(e))}_errorIfDisposed(){if(this.isDisposed)throw new Error("Terminal connection is disposed")}get connectionStatusChanged(){return this._connectionStatusChanged}get connectionStatus(){return this._connectionStatus}};jn.TerminalConnection=Ws;var Hs;(function(r){function e(t,n){return t=Math.ceil(t),n=Math.floor(n),Math.floor(Math.random()*(n-t+1))+t}r.getRandomIntInclusive=e})(Hs||(Hs={}))});var Po=O(kt=>{"use strict";Object.defineProperty(kt,"__esModule",{value:!0});kt.TerminalManager=void 0;var Bc=Ge(),Co=ee(),$c=Ae(),Wc=Je(),Hc=Ot(),Jc=bo(),Rt=class extends Wc.BaseManager{constructor(e={}){var t,n;if(super(e),this._isReady=!1,this._names=[],this._terminalConnections=new Set,this._runningChanged=new Co.Signal(this),this._connectionFailure=new Co.Signal(this),this._terminalAPIClient=(t=e.terminalAPIClient)!==null&&t!==void 0?t:new Hc.TerminalAPIClient({serverSettings:this.serverSettings}),!this.isAvailable()){this._ready=Promise.reject("Terminals unavailable"),this._ready.catch(i=>{});return}let s=this._pollModels=new Bc.Poll({auto:!1,factory:()=>this.requestRunning(),frequency:{interval:10*1e3,backoff:!0,max:300*1e3},name:"@jupyterlab/services:TerminalManager#models",standby:(n=e.standby)!==null&&n!==void 0?n:"when-hidden"});this._ready=(async()=>{await s.start(),await s.tick,this._isReady=!0})()}get isReady(){return this._isReady}get ready(){return this._ready}get runningChanged(){return this._runningChanged}get connectionFailure(){return this._connectionFailure}dispose(){var e;this.isDisposed||(this._names.length=0,this._terminalConnections.forEach(t=>t.dispose()),(e=this._pollModels)===null||e===void 0||e.dispose(),super.dispose())}isAvailable(){return this._terminalAPIClient.isAvailable}connectTo(e){let t=new Jc.TerminalConnection({...e,serverSettings:this.serverSettings,terminalAPIClient:this._terminalAPIClient});return this._onStarted(t),this._names.includes(e.model.name)||this.refreshRunning().catch(()=>{}),t}running(){return this._models[Symbol.iterator]()}async refreshRunning(){this._pollModels&&(await this._pollModels.refresh(),await this._pollModels.tick)}async startNew(e={}){let{name:t,cwd:n}=e,s=await this._terminalAPIClient.startNew({name:t,cwd:n});return await this.refreshRunning(),this.connectTo({model:s})}async shutdown(e){await this._terminalAPIClient.shutdown(e),await this.refreshRunning()}async shutdownAll(){await this.refreshRunning(),await Promise.all(this._names.map(e=>this._terminalAPIClient.shutdown(e))),await this.refreshRunning()}async requestRunning(){var e,t;let n;try{n=await this._terminalAPIClient.listRunning()}catch(i){throw(i instanceof $c.ServerConnection.NetworkError||((e=i.response)===null||e===void 0?void 0:e.status)===503||((t=i.response)===null||t===void 0?void 0:t.status)===424)&&this._connectionFailure.emit(i),i}if(this.isDisposed)return;let s=n.map(({name:i})=>i).sort();s!==this._names&&(this._names=s,this._terminalConnections.forEach(i=>{s.includes(i.name)||i.dispose()}),this._runningChanged.emit(this._models))}_onStarted(e){this._terminalConnections.add(e),e.disposed.connect(this._onDisposed,this)}_onDisposed(e){this._terminalConnections.delete(e),this.refreshRunning().catch(()=>{})}get _models(){return this._names.map(e=>({name:e}))}};kt.TerminalManager=Rt;(function(r){class e extends r{constructor(){super(...arguments),this._readyPromise=new Promise(()=>{})}get isActive(){return!1}get parentReady(){return super.ready}get ready(){return this.parentReady.then(()=>this._readyPromise)}async startNew(n){return Promise.reject(new Error("Not implemented in no-op Terminal Manager"))}connectTo(n){throw Error("Not implemented in no-op Terminal Manager")}async shutdown(n){return Promise.reject(new Error("Not implemented in no-op Terminal Manager"))}async requestRunning(){return Promise.resolve()}}r.NoopManager=e})(Rt||(kt.TerminalManager=Rt={}))});var Js=O(pe=>{"use strict";var Mo=pe&&pe.__createBinding||(Object.create?function(r,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,n,s)}:function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]}),Gc=pe&&pe.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),Eo=pe&&pe.__importStar||function(){var r=function(e){return r=Object.getOwnPropertyNames||function(t){var n=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[n.length]=s);return n},r(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n=r(e),s=0;s<n.length;s++)n[s]!=="default"&&Mo(t,e,n[s]);return Gc(t,e),t}}(),Xc=pe&&pe.__exportStar||function(r,e){for(var t in r)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&Mo(e,r,t)};Object.defineProperty(pe,"__esModule",{value:!0});pe.TerminalAPI=pe.Terminal=void 0;var Yc=Eo(So());pe.Terminal=Yc;var Qc=Eo(Ot());pe.TerminalAPI=Qc;Xc(Po(),pe)});var Oo=O(Io=>{"use strict";Object.defineProperty(Io,"__esModule",{value:!0})});var Xs=O(Un=>{"use strict";Object.defineProperty(Un,"__esModule",{value:!0});Un.UserAPIClient=void 0;var Ro=he(),Zc=te(),eu="api/me",Gs=class{constructor(e={}){var t;this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:Ro.ServerConnection.makeSettings()}async get(){let{baseUrl:e}=this.serverSettings,{makeRequest:t,ResponseError:n}=Ro.ServerConnection,s=Zc.URLExt.join(e,eu),i=await t(s,{},this.serverSettings);if(i.status!==200)throw await n.create(i);return await i.json()}};Un.UserAPIClient=Gs});var Do=O(An=>{"use strict";Object.defineProperty(An,"__esModule",{value:!0});An.UserManager=void 0;var tu=X(),nu=Ge(),ko=ee(),su=Je(),ru=Xs(),Ys="@jupyterlab/services:UserManager#user",Qs=class extends su.BaseManager{constructor(e={}){var t,n;super(e),this._isReady=!1,this._userChanged=new ko.Signal(this),this._connectionFailure=new ko.Signal(this),this._userApiClient=(t=e.userApiClient)!==null&&t!==void 0?t:new ru.UserAPIClient({serverSettings:this.serverSettings}),this._ready=this.requestUser().then(()=>{this.isDisposed||(this._isReady=!0)}).catch(s=>new Promise(()=>{})),this._pollUser=new nu.Poll({auto:!1,factory:()=>this.requestUser(),frequency:{interval:61*1e3,backoff:!0,max:300*1e3},name:Ys,standby:(n=e.standby)!==null&&n!==void 0?n:"when-hidden"}),this.ready.then(()=>{this._pollUser.start()})}get isReady(){return this._isReady}get ready(){return this._ready}get identity(){return this._identity}get permissions(){return this._permissions}get userChanged(){return this._userChanged}get connectionFailure(){return this._connectionFailure}dispose(){this._pollUser.dispose(),super.dispose()}async refreshUser(){await this._pollUser.refresh(),await this._pollUser.tick}async requestUser(){if(this.isDisposed)return;let e={identity:this._identity,permissions:this._permissions},t=await this._userApiClient.get(),n=t.identity,{localStorage:s}=window,i=s.getItem(Ys);if(i&&(!n.initials||!n.color)){let o=JSON.parse(i);n.initials=n.initials||o.initials||n.name.substring(0,1),n.color=n.color||o.color||Zs.getRandomColor()}tu.JSONExt.deepEqual(t,e)||(this._identity=n,this._permissions=t.permissions,s.setItem(Ys,JSON.stringify(n)),this._userChanged.emit(t))}};An.UserManager=Qs;var Zs;(function(r){let e=["var(--jp-collaborator-color1)","var(--jp-collaborator-color2)","var(--jp-collaborator-color3)","var(--jp-collaborator-color4)","var(--jp-collaborator-color5)","var(--jp-collaborator-color6)","var(--jp-collaborator-color7)"];r.getRandomColor=()=>e[Math.floor(Math.random()*e.length)]})(Zs||(Zs={}))});var er=O(me=>{"use strict";var To=me&&me.__createBinding||(Object.create?function(r,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,n,s)}:function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]}),iu=me&&me.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),qo=me&&me.__importStar||function(){var r=function(e){return r=Object.getOwnPropertyNames||function(t){var n=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[n.length]=s);return n},r(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n=r(e),s=0;s<n.length;s++)n[s]!=="default"&&To(t,e,n[s]);return iu(t,e),t}}(),ou=me&&me.__exportStar||function(r,e){for(var t in r)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&To(e,r,t)};Object.defineProperty(me,"__esModule",{value:!0});me.UserAPI=me.User=void 0;var au=qo(Oo());me.User=au;var lu=qo(Xs());me.UserAPI=lu;ou(Do(),me)});var nr=O(Nn=>{"use strict";Object.defineProperty(Nn,"__esModule",{value:!0});Nn.WorkspaceManager=void 0;var jo=te(),cu=Fs(),Dt=he(),uu="api/workspaces",tr=class extends cu.DataConnector{constructor(e={}){var t;super(),this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:Dt.ServerConnection.makeSettings()}async fetch(e){let{serverSettings:t}=this,{baseUrl:n,appUrl:s}=t,{makeRequest:i,ResponseError:o}=Dt.ServerConnection,a=n+s,h=it.url(a,e),c=await i(h,{},t);if(c.status!==200)throw await o.create(c);return c.json()}async list(){let{serverSettings:e}=this,{baseUrl:t,appUrl:n}=e,{makeRequest:s,ResponseError:i}=Dt.ServerConnection,o=t+n,a=it.url(o,""),h=await s(a,{},e);if(h.status!==200)throw await i.create(h);return(await h.json()).workspaces}async remove(e){let{serverSettings:t}=this,{baseUrl:n,appUrl:s}=t,{makeRequest:i,ResponseError:o}=Dt.ServerConnection,a=n+s,h=it.url(a,e),u=await i(h,{method:"DELETE"},t);if(u.status!==204)throw await o.create(u)}async save(e,t){let{serverSettings:n}=this,{baseUrl:s,appUrl:i}=n,{makeRequest:o,ResponseError:a}=Dt.ServerConnection,h=s+i,c=it.url(h,e),u={body:JSON.stringify(t),method:"PUT"},l=await o(c,u,n);if(l.status!==204)throw await a.create(l)}};Nn.WorkspaceManager=tr;var it;(function(r){function e(t,n){let s=jo.URLExt.join(t,uu),i=jo.URLExt.join(s,n);if(!i.startsWith(s))throw new Error("Can only be used for workspaces requests");return i}r.url=e})(it||(it={}))});var Ao=O(Ln=>{"use strict";Object.defineProperty(Ln,"__esModule",{value:!0});Ln.ServiceManager=void 0;var Uo=ee(),hu=Hi(),du=_s(),fu=ps(),_u=Es(),gu=Os(),pu=js(),mu=he(),vu=Ns(),yu=Vs(),wu=Js(),Su=er(),bu=nr(),sr=class{constructor(e={}){var t,n;this._isDisposed=!1,this._connectionFailure=new Uo.Signal(this),this._isReady=!1;let s=e.defaultDrive,i=(t=e.serverSettings)!==null&&t!==void 0?t:mu.ServerConnection.makeSettings(),o=(n=e.standby)!==null&&n!==void 0?n:"when-hidden",a={defaultDrive:s,serverSettings:i,standby:o};this.serverSettings=i,this.contents=e.contents||new du.ContentsManager(a),this.events=e.events||new fu.EventManager(a),this.kernels=e.kernels||new _u.KernelManager(a),this.sessions=e.sessions||new vu.SessionManager({...a,kernelManager:this.kernels}),this.settings=e.settings||new yu.SettingManager(a),this.terminals=e.terminals||new wu.TerminalManager(a),this.builder=e.builder||new hu.BuildManager(a),this.workspaces=e.workspaces||new bu.WorkspaceManager(a),this.nbconvert=e.nbconvert||new pu.NbConvertManager(a),this.kernelspecs=e.kernelspecs||new gu.KernelSpecManager(a),this.user=e.user||new Su.UserManager(a),this.kernelspecs.connectionFailure.connect(this._onConnectionFailure,this),this.sessions.connectionFailure.connect(this._onConnectionFailure,this),this.terminals.connectionFailure.connect(this._onConnectionFailure,this);let h=[this.sessions.ready,this.kernelspecs.ready];this.terminals.isAvailable()&&h.push(this.terminals.ready),this._readyPromise=Promise.all(h).then(()=>{this._isReady=!0})}get connectionFailure(){return this._connectionFailure}get isDisposed(){return this._isDisposed}dispose(){this.isDisposed||(this._isDisposed=!0,Uo.Signal.clearData(this),this.contents.dispose(),this.events.dispose(),this.sessions.dispose(),this.terminals.dispose())}get isReady(){return this._isReady}get ready(){return this._readyPromise}_onConnectionFailure(e,t){this._connectionFailure.emit(t)}};Ln.ServiceManager=sr});var No=O(L=>{"use strict";Object.defineProperty(L,"__esModule",{value:!0});L.IWorkspaceManager=L.IUserManager=L.ITerminalManager=L.IServiceManager=L.ISettingManager=L.ISessionManager=L.IServerSettings=L.INbConvertManager=L.IKernelSpecManager=L.IKernelManager=L.IEventManager=L.IDefaultDrive=L.IDefaultContentProvider=L.IContentsManager=L.IConfigSectionManager=L.IConnectionStatus=void 0;var le=X();L.IConnectionStatus=new le.Token("@jupyterlab/application:IConnectionStatus","A service providing the application connection status.");L.IConfigSectionManager=new le.Token("@jupyterlab/services:IConfigSectionManager","A service providing the config section manager.");L.IContentsManager=new le.Token("@jupyterlab/services:IContentsManager","The contents manager token.");L.IDefaultContentProvider=new le.Token("@jupyterlab/services:IDefaultContentProvider","The default content provider for the contents manager.");L.IDefaultDrive=new le.Token("@jupyterlab/services:IDefaultDrive","The default drive for the contents manager.");L.IEventManager=new le.Token("@jupyterlab/services:IEventManager","The event manager token.");L.IKernelManager=new le.Token("@jupyterlab/services:IKernelManager","The kernel manager token.");L.IKernelSpecManager=new le.Token("@jupyterlab/services:IKernelSpecManager","The kernel spec manager token.");L.INbConvertManager=new le.Token("@jupyterlab/services:INbConvertManager","The nbconvert manager token.");L.IServerSettings=new le.Token("@jupyterlab/services:IServerSettings","The server settings for the application.");L.ISessionManager=new le.Token("@jupyterlab/services:ISessionManager","The session manager token.");L.ISettingManager=new le.Token("@jupyterlab/services:ISettingManager","The setting manager token.");L.IServiceManager=new le.Token("@jupyterlab/services:IServiceManager","The service manager for the application.");L.ITerminalManager=new le.Token("@jupyterlab/services:ITerminalManager","The terminal manager token.");L.IUserManager=new le.Token("@jupyterlab/services:IUserManager","The user manager token.");L.IWorkspaceManager=new le.Token("@jupyterlab/services:IWorkspaceManager","The workspace manager token.")});var Ae=O(W=>{"use strict";var Cu=W&&W.__createBinding||(Object.create?function(r,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,n,s)}:function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]}),ce=W&&W.__exportStar||function(r,e){for(var t in r)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&Cu(e,r,t)};Object.defineProperty(W,"__esModule",{value:!0});ce(Je(),W);ce(oi(),W);ce(ai(),W);ce(_s(),W);ce(ps(),W);ce(Es(),W);ce(Os(),W);ce(Ao(),W);ce(he(),W);ce(Ns(),W);ce(Vs(),W);ce(Js(),W);ce(No(),W);ce(er(),W);ce(nr(),W);ce(js(),W)});function Lo(r){return"node"in r}var xo=or(()=>{});var zo={};sa(zo,{BLOCK_SIZE:()=>Iu,ContentsAPI:()=>zn,DRIVE_SEPARATOR:()=>Ko,DriveFS:()=>Tt,DriveFSEmscriptenNodeOps:()=>Kn,DriveFSEmscriptenStreamOps:()=>Fn,ServiceWorkerContentsAPI:()=>Vn});var Fo,Ko,Iu,Ou,Ru,xn,Fn,Kn,zn,Vn,Tt,rr=or(()=>{Fo=Wn(X());xo();Ko=":",Iu=4096,Ou=new TextEncoder,Ru=new TextDecoder("utf-8"),xn={0:!1,1:!0,2:!0,64:!0,65:!0,66:!0,129:!0,193:!0,514:!0,577:!0,578:!0,705:!0,706:!0,1024:!0,1025:!0,1026:!0,1089:!0,1090:!0,1153:!0,1154:!0,1217:!0,1218:!0,4096:!0,4098:!0},Fn=class{constructor(e){this.fs=e}open(e){var t;let n=this.fs.realPath(e.node);if(this.fs.FS.isFile(e.node.mode))try{let s=this.fs.API.get(n);e.file=s}catch{let s=(t=e.flags)!==null&&t!==void 0?t:e.shared.flags,i=typeof s=="string"?parseInt(s,10):s;i&=8191;let o=!0;if(i in xn&&(o=xn[i]),o){e.node=this.fs.node_ops.mknod(e.node.parent,e.node.name,e.node.mode,0);let a=this.fs.API.get(n);e.file=a}else throw new this.fs.FS.ErrnoError(this.fs.ERRNO_CODES.ENOENT)}}close(e){var t;if(!this.fs.FS.isFile(e.node.mode)||!e.file)return;let n=this.fs.realPath(e.node),s=(t=e.flags)!==null&&t!==void 0?t:e.shared.flags,i=typeof s=="string"?parseInt(s,10):s;i&=8191;let o=!0;i in xn&&(o=xn[i]),o&&this.fs.API.put(n,e.file),e.file=void 0}read(e,t,n,s,i){if(s<=0||e.file===void 0||i>=(e.file.data.length||0))return 0;let o=Math.min(e.file.data.length-i,s);return t.set(e.file.data.subarray(i,i+o),n),o}write(e,t,n,s,i){var o;if(s<=0||e.file===void 0)return 0;let a=Date.now();if(e.node.timestamp=a,e.node.atime=a,e.node.mtime=a,e.node.ctime=a,i+s>(((o=e.file)===null||o===void 0?void 0:o.data.length)||0)){let h=e.file.data?e.file.data:new Uint8Array;e.file.data=new Uint8Array(i+s),e.file.data.set(h)}return e.file.data.set(t.subarray(n,n+s),i),s}llseek(e,t,n){var s;let i=t;if(n===1)i+=(s=e.position)!==null&&s!==void 0?s:e.shared.position;else if(n===2&&this.fs.FS.isFile(e.node.mode))if(e.file!==void 0)i+=e.file.data.length;else throw new this.fs.FS.ErrnoError(this.fs.ERRNO_CODES.EPERM);if(i<0)throw new this.fs.FS.ErrnoError(this.fs.ERRNO_CODES.EINVAL);return i}},Kn=class{constructor(e){this.node=t=>Lo(t)?t.node:t,this.getattr=t=>{let n=this.node(t);return{...this.fs.API.getattr(this.fs.realPath(n)),mode:n.mode,ino:n.id}},this.setattr=(t,n)=>{let s=this.node(t);for(let[i,o]of Object.entries(n))switch(i){case"mode":s.mode=o;break;case"timestamp":s.timestamp=o;break;case"atime":s.atime=o;break;case"mtime":s.mtime=o;break;case"ctime":s.ctime=o;break;case"size":{let a=o,h=this.fs.realPath(s);if(this.fs.FS.isFile(s.mode)&&a>=0){let c;try{c=this.fs.API.get(h)}catch{break}let u=c.data?c.data:new Uint8Array;a!==u.length&&(a<u.length?c.data=c.data.slice(0,a):(c.data=new Uint8Array(a),c.data.set(u)),this.fs.API.put(h,c))}else console.warn("setattr size of",a,"on",s,"not yet implemented");break}case"dontFollow":break;default:console.warn("setattr",i,"of",o,"on",s,"not yet implemented");break}},this.lookup=(t,n)=>{let s=this.node(t),i=this.fs.PATH.join2(this.fs.realPath(s),n),o=this.fs.API.lookup(i);if(!o.ok)throw new this.fs.FS.ErrnoError(this.fs.ERRNO_CODES.ENOENT);return this.fs.createNode(s,n,o.mode,0)},this.mknod=(t,n,s,i)=>{let o=this.node(t),a=this.fs.PATH.join2(this.fs.realPath(o),n);return this.fs.API.mknod(a,s),this.fs.createNode(o,n,s,i)},this.rename=(t,n,s)=>{let i=this.node(t),o=this.node(n);this.fs.API.rename(i.parent?this.fs.PATH.join2(this.fs.realPath(i.parent),i.name):i.name,this.fs.PATH.join2(this.fs.realPath(o),s)),i.name=s,i.parent=o},this.unlink=(t,n)=>this.fs.API.rmdir(this.fs.PATH.join2(this.fs.realPath(this.node(t)),n)),this.rmdir=(t,n)=>this.fs.API.rmdir(this.fs.PATH.join2(this.fs.realPath(this.node(t)),n)),this.readdir=t=>this.fs.API.readdir(this.fs.realPath(this.node(t))),this.symlink=(t,n,s)=>{throw new this.fs.FS.ErrnoError(this.fs.ERRNO_CODES.EPERM)},this.readlink=t=>{throw new this.fs.FS.ErrnoError(this.fs.ERRNO_CODES.EINVAL)},this.fs=e}},zn=class{constructor(e){this._driveName=e.driveName,this._mountpoint=e.mountpoint,this.FS=e.FS,this.ERRNO_CODES=e.ERRNO_CODES}lookup(e){return this.request({method:"lookup",path:this.normalizePath(e)})}getmode(e){return this.request({method:"getmode",path:this.normalizePath(e)})}mknod(e,t){return this.request({method:"mknod",path:this.normalizePath(e),data:{mode:t}})}rename(e,t){return this.request({method:"rename",path:this.normalizePath(e),data:{newPath:this.normalizePath(t)}})}readdir(e){let t=this.request({method:"readdir",path:this.normalizePath(e)});return t.push("."),t.push(".."),t}rmdir(e){return this.request({method:"rmdir",path:this.normalizePath(e)})}get(e){let t=this.request({method:"get",path:this.normalizePath(e)});if(!t)throw new this.FS.ErrnoError(this.ERRNO_CODES.ENOENT);let n=t.content,s=t.format;switch(s){case"json":case"text":return{data:Ou.encode(n),format:s};case"base64":{let i=atob(n),o=i.length,a=new Uint8Array(o);for(let h=0;h<o;h++)a[h]=i.charCodeAt(h);return{data:a,format:s}}default:throw new this.FS.ErrnoError(this.ERRNO_CODES.ENOENT)}}put(e,t){switch(t.format){case"json":case"text":return this.request({method:"put",path:this.normalizePath(e),data:{format:t.format,data:Ru.decode(t.data)}});case"base64":{let n="";for(let s=0;s<t.data.byteLength;s++)n+=String.fromCharCode(t.data[s]);return this.request({method:"put",path:this.normalizePath(e),data:{format:t.format,data:btoa(n)}})}}}getattr(e){let t=this.request({method:"getattr",path:this.normalizePath(e)}),n=new Date(0);return t.atime=t.atime?new Date(t.atime):n,t.mtime=t.mtime?new Date(t.mtime):n,t.ctime=t.ctime?new Date(t.ctime):n,t.size=t.size||0,t}normalizePath(e){return e.startsWith(this._mountpoint)&&(e=e.slice(this._mountpoint.length)),this._driveName&&(e=`${this._driveName}${Ko}${e}`),e}},Vn=class extends zn{constructor(e){super(e),this._baseUrl=e.baseUrl,this._browsingContextId=e.browsingContextId||""}request(e){let t=new XMLHttpRequest;t.open("POST",encodeURI(this.endpoint),!1);let n=Fo.UUID.uuid4(),s={data:{...e,requestId:n},browsingContextId:this._browsingContextId,requestId:n};try{t.send(JSON.stringify(s))}catch(i){console.error(i)}if(t.status>=400)throw new this.FS.ErrnoError(this.ERRNO_CODES.EINVAL);return JSON.parse(t.responseText)}get endpoint(){return`${this._baseUrl}api/drive`}},Tt=class{constructor(e){this.FS=e.FS,this.PATH=e.PATH,this.ERRNO_CODES=e.ERRNO_CODES,this.API=this.createAPI(e),this.driveName=e.driveName,this.node_ops=new Kn(this),this.stream_ops=new Fn(this)}createAPI(e){if(!e.browsingContextId||!e.baseUrl)throw new Error("Cannot create service-worker API without current browsingContextId");return new Vn(e)}mount(e){return this.createNode(null,e.mountpoint,16895,0)}createNode(e,t,n,s){let i=this.FS;if(!i.isDir(n)&&!i.isFile(n))throw new i.ErrnoError(this.ERRNO_CODES.EINVAL);let o=i.createNode(e,t,n,s);return o.node_ops=this.node_ops,o.stream_ops=this.stream_ops,o}getMode(e){return this.API.getmode(e)}realPath(e){let t=[],n=e;for(t.push(n.name);n.parent!==n;)n=n.parent,t.push(n.name);return t.reverse(),this.PATH.join.apply(null,t)}}});var lr=Symbol("Comlink.proxy"),ia=Symbol("Comlink.endpoint"),oa=Symbol("Comlink.releaseProxy"),Hn=Symbol("Comlink.finalizer"),jt=Symbol("Comlink.thrown"),cr=r=>typeof r=="object"&&r!==null||typeof r=="function",aa={canHandle:r=>cr(r)&&r[lr],serialize(r){let{port1:e,port2:t}=new MessageChannel;return Lt(r,e),[t,[t]]},deserialize(r){return r.start(),ha(r)}},la={canHandle:r=>cr(r)&&jt in r,serialize({value:r}){let e;return r instanceof Error?e={isError:!0,value:{message:r.message,name:r.name,stack:r.stack}}:e={isError:!1,value:r},[e,[]]},deserialize(r){throw r.isError?Object.assign(new Error(r.value.message),r.value):r.value}},ur=new Map([["proxy",aa],["throw",la]]);function ca(r,e){for(let t of r)if(e===t||t==="*"||t instanceof RegExp&&t.test(e))return!0;return!1}function Lt(r,e=globalThis,t=["*"]){e.addEventListener("message",function n(s){if(!s||!s.data)return;if(!ca(t,s.origin)){console.warn(`Invalid origin '${s.origin}' for comlink proxy`);return}let{id:i,type:o,path:a}=Object.assign({path:[]},s.data),h=(s.data.argumentList||[]).map(He),c;try{let u=a.slice(0,-1).reduce((d,m)=>d[m],r),l=a.reduce((d,m)=>d[m],r);switch(o){case"GET":c=l;break;case"SET":u[a.slice(-1)[0]]=He(s.data.value),c=!0;break;case"APPLY":c=l.apply(u,h);break;case"CONSTRUCT":{let d=new l(...h);c=pa(d)}break;case"ENDPOINT":{let{port1:d,port2:m}=new MessageChannel;Lt(r,m),c=ga(d,[d])}break;case"RELEASE":c=void 0;break;default:return}}catch(u){c={value:u,[jt]:0}}Promise.resolve(c).catch(u=>({value:u,[jt]:0})).then(u=>{let[l,d]=Nt(u);e.postMessage(Object.assign(Object.assign({},l),{id:i}),d),o==="RELEASE"&&(e.removeEventListener("message",n),hr(e),Hn in r&&typeof r[Hn]=="function"&&r[Hn]())}).catch(u=>{let[l,d]=Nt({value:new TypeError("Unserializable return value"),[jt]:0});e.postMessage(Object.assign(Object.assign({},l),{id:i}),d)})}),e.start&&e.start()}function ua(r){return r.constructor.name==="MessagePort"}function hr(r){ua(r)&&r.close()}function ha(r,e){let t=new Map;return r.addEventListener("message",function(s){let{data:i}=s;if(!i||!i.id)return;let o=t.get(i.id);if(o)try{o(i)}finally{t.delete(i.id)}}),Jn(r,t,[],e)}function qt(r){if(r)throw new Error("Proxy has been released and is not useable")}function dr(r){return Ye(r,new Map,{type:"RELEASE"}).then(()=>{hr(r)})}var Ut=new WeakMap,At="FinalizationRegistry"in globalThis&&new FinalizationRegistry(r=>{let e=(Ut.get(r)||0)-1;Ut.set(r,e),e===0&&dr(r)});function da(r,e){let t=(Ut.get(e)||0)+1;Ut.set(e,t),At&&At.register(r,e,r)}function fa(r){At&&At.unregister(r)}function Jn(r,e,t=[],n=function(){}){let s=!1,i=new Proxy(n,{get(o,a){if(qt(s),a===oa)return()=>{fa(i),dr(r),e.clear(),s=!0};if(a==="then"){if(t.length===0)return{then:()=>i};let h=Ye(r,e,{type:"GET",path:t.map(c=>c.toString())}).then(He);return h.then.bind(h)}return Jn(r,e,[...t,a])},set(o,a,h){qt(s);let[c,u]=Nt(h);return Ye(r,e,{type:"SET",path:[...t,a].map(l=>l.toString()),value:c},u).then(He)},apply(o,a,h){qt(s);let c=t[t.length-1];if(c===ia)return Ye(r,e,{type:"ENDPOINT"}).then(He);if(c==="bind")return Jn(r,e,t.slice(0,-1));let[u,l]=ar(h);return Ye(r,e,{type:"APPLY",path:t.map(d=>d.toString()),argumentList:u},l).then(He)},construct(o,a){qt(s);let[h,c]=ar(a);return Ye(r,e,{type:"CONSTRUCT",path:t.map(u=>u.toString()),argumentList:h},c).then(He)}});return da(i,r),i}function _a(r){return Array.prototype.concat.apply([],r)}function ar(r){let e=r.map(Nt);return[e.map(t=>t[0]),_a(e.map(t=>t[1]))]}var fr=new WeakMap;function ga(r,e){return fr.set(r,e),r}function pa(r){return Object.assign(r,{[lr]:!0})}function Nt(r){for(let[e,t]of ur)if(t.canHandle(r)){let[n,s]=t.serialize(r);return[{type:"HANDLER",name:e,value:n},s]}return[{type:"RAW",value:r},fr.get(r)||[]]}function He(r){switch(r.type){case"HANDLER":return ur.get(r.name).deserialize(r.value);case"RAW":return r.value}}function Ye(r,e,t,n){return new Promise(s=>{let i=ma();e.set(i,s),r.start&&r.start(),r.postMessage(Object.assign({id:i},t),n)})}function ma(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}var Vo=Wn(te()),Bo=Wn(Ae());rr();var Bn=class{constructor(){this._options=null;this._initializer=null;this._pyodide=null;this._localPath="";this._driveName="";this._driveFS=null;this._sendWorkerMessage=()=>{};this._logMessage=()=>{};this._initialized=new Promise((e,t)=>{this._initializer={resolve:e,reject:t}})}async initialize(e){var t;if(this._options=e,e.location.includes(":")){let n=e.location.split(":");this._driveName=n[0],this._localPath=n[1]}else this._driveName="",this._localPath=e.location;await this.initRuntime(e),await this.initFilesystem(e),await this.initPackageManager(e),await this.initKernel(e),await this.initGlobals(e),(t=this._initializer)==null||t.resolve()}async initRuntime(e){let{pyodideUrl:t,indexUrl:n}=e,s;t.endsWith(".mjs")?s=(await import(t)).loadPyodide:(importScripts(t),s=self.loadPyodide),this._pyodide=await s({indexURL:n,stdout:i=>{console.log(i),this._logMessage({type:"text",level:"info",data:i})},stderr:i=>{console.error(i),this._logMessage({type:"text",level:"critical",data:i})},...e.loadPyodideOptions}),this._pyodide._api.on_fatal=async i=>{let o="";i.name==="Exit"?o="Pyodide has exited and can no longer be used.":o=`Pyodide has suffered a fatal error. Please report this to the Pyodide maintainers.
9
+ See "state database" for more information.`)});var Fs=O(Ee=>{"use strict";var Nc=Ee&&Ee.__createBinding||(Object.create?function(r,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,n,s)}:function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]}),Pt=Ee&&Ee.__exportStar||function(r,e){for(var t in r)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&Nc(e,r,t)};Object.defineProperty(Ee,"__esModule",{value:!0});Pt(lo(),Ee);Pt(uo(),Ee);Pt(go(),Ee);Pt(po(),Ee);Pt(mo(),Ee)});var Vs=O(Dn=>{"use strict";Object.defineProperty(Dn,"__esModule",{value:!0});Dn.SettingManager=void 0;var Ks=te(),Lc=Fs(),kn=he(),xc="api/settings",zs=class extends Lc.DataConnector{constructor(e={}){var t;super(),this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:kn.ServerConnection.makeSettings()}async fetch(e){if(!e)throw new Error("Plugin `id` parameter is required for settings fetch.");let{serverSettings:t}=this,{baseUrl:n,appUrl:s}=t,{makeRequest:i,ResponseError:o}=kn.ServerConnection,a=n+s,h=Mt.url(a,e),c=await i(h,{},t);if(c.status!==200)throw await o.create(c);return c.json()}async list(e){var t,n,s,i;let{serverSettings:o}=this,{baseUrl:a,appUrl:h}=o,{makeRequest:c,ResponseError:u}=kn.ServerConnection,l=a+h,d=Mt.url(l,"",e==="ids"),m=await c(d,{},o);if(m.status!==200)throw new u(m);let v=await m.json(),T=(n=(t=v==null?void 0:v.settings)===null||t===void 0?void 0:t.map(q=>q.id))!==null&&n!==void 0?n:[],E=[];return e||(E=(i=(s=v==null?void 0:v.settings)===null||s===void 0?void 0:s.map(q=>(q.data={composite:{},user:{}},q)))!==null&&i!==void 0?i:[]),{ids:T,values:E}}async save(e,t){let{serverSettings:n}=this,{baseUrl:s,appUrl:i}=n,{makeRequest:o,ResponseError:a}=kn.ServerConnection,h=s+i,c=Mt.url(h,e),u={body:JSON.stringify({raw:t}),method:"PUT"},l=await o(c,u,n);if(l.status!==204)throw new a(l)}};Dn.SettingManager=zs;var Mt;(function(r){function e(t,n,s){let i=s?Ks.URLExt.objectToQueryString({ids_only:!0}):"",o=Ks.URLExt.join(t,xc),a=Ks.URLExt.join(o,n);if(!a.startsWith(o))throw new Error("Can only be used for workspaces requests");return`${a}${i}`}r.url=e})(Mt||(Mt={}))});var Ot=O(we=>{"use strict";Object.defineProperty(we,"__esModule",{value:!0});we.TerminalAPIClient=we.TERMINAL_SERVICE_URL=void 0;we.isAvailable=$s;we.startNew=vo;we.listRunning=yo;we.shutdownTerminal=wo;var Et=te(),Ue=he();we.TERMINAL_SERVICE_URL="api/terminals";function $s(){return String(Et.PageConfig.getOption("terminalsAvailable")).toLowerCase()==="true"}async function vo(r=Ue.ServerConnection.makeSettings(),e,t){It.errorIfNotAvailable();let n=Et.URLExt.join(r.baseUrl,we.TERMINAL_SERVICE_URL),s={method:"POST",body:JSON.stringify({name:e,cwd:t})},i=await Ue.ServerConnection.makeRequest(n,s,r);if(i.status!==200)throw await Ue.ServerConnection.ResponseError.create(i);return await i.json()}async function yo(r=Ue.ServerConnection.makeSettings()){It.errorIfNotAvailable();let e=Et.URLExt.join(r.baseUrl,we.TERMINAL_SERVICE_URL),t=await Ue.ServerConnection.makeRequest(e,{},r);if(t.status!==200)throw await Ue.ServerConnection.ResponseError.create(t);let n=await t.json();if(!Array.isArray(n))throw new Error("Invalid terminal list");return n}async function wo(r,e=Ue.ServerConnection.makeSettings()){var t;It.errorIfNotAvailable();let n=Et.URLExt.join(e.baseUrl,we.TERMINAL_SERVICE_URL),s=Et.URLExt.join(n,r);if(!s.startsWith(n))throw new Error("Can only be used for terminal requests");let i={method:"DELETE"},o=await Ue.ServerConnection.makeRequest(s,i,e);if(o.status===404){let h=(t=(await o.json()).message)!==null&&t!==void 0?t:`The terminal session "${r}"" does not exist on the server`;console.warn(h)}else if(o.status!==204)throw await Ue.ServerConnection.ResponseError.create(o)}var Bs=class{constructor(e={}){var t;this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:Ue.ServerConnection.makeSettings()}get isAvailable(){return $s()}async startNew(e={}){let{name:t,cwd:n}=e;return vo(this.serverSettings,t,n)}async listRunning(){return yo(this.serverSettings)}async shutdown(e){return wo(e,this.serverSettings)}};we.TerminalAPIClient=Bs;var It;(function(r){function e(){if(!$s())throw new Error("Terminals Unavailable")}r.errorIfNotAvailable=e})(It||(It={}))});var So=O(Tn=>{"use strict";Object.defineProperty(Tn,"__esModule",{value:!0});Tn.isAvailable=void 0;var Fc=Ot();Object.defineProperty(Tn,"isAvailable",{enumerable:!0,get:function(){return Fc.isAvailable}})});var bo=O(jn=>{"use strict";Object.defineProperty(jn,"__esModule",{value:!0});jn.TerminalConnection=void 0;var Kc=te(),zc=X(),qn=ee(),Vc=Ae(),Bc=Ot(),Ws=class r{constructor(e){var t,n;this._createSocket=()=>{this._errorIfDisposed(),this._clearSocket(),this._updateConnectionStatus("connecting");let s=this._name,i=this.serverSettings,o=Kc.URLExt.join(i.wsUrl,"terminals","websocket",encodeURIComponent(s)),a=i.token;i.appendToken&&a!==""&&(o=o+`?token=${encodeURIComponent(a)}`),this._ws=new i.WebSocket(o),this._ws.onmessage=this._onWSMessage,this._ws.onclose=this._onWSClose,this._ws.onerror=this._onWSClose},this._onWSMessage=s=>{if(this._isDisposed)return;let i=JSON.parse(s.data);if(i[0]==="disconnect"&&this.dispose(),this._connectionStatus==="connecting"){i[0]==="setup"&&this._updateConnectionStatus("connected");return}this._messageReceived.emit({type:i[0],content:i.slice(1)})},this._onWSClose=s=>{console.warn(`Terminal websocket closed: ${s.code}`),!this.isDisposed&&(s.code===1e3||s.code===1001||this._reconnect())},this._connectionStatus="connecting",this._connectionStatusChanged=new qn.Signal(this),this._isDisposed=!1,this._disposed=new qn.Signal(this),this._messageReceived=new qn.Signal(this),this._reconnectTimeout=null,this._ws=null,this._noOp=()=>{},this._reconnectLimit=7,this._reconnectAttempt=0,this._pendingMessages=[],this._name=e.model.name,this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:Vc.ServerConnection.makeSettings(),this._terminalAPIClient=(n=e.terminalAPIClient)!==null&&n!==void 0?n:new Bc.TerminalAPIClient({serverSettings:this.serverSettings}),this._createSocket()}get disposed(){return this._disposed}get messageReceived(){return this._messageReceived}get name(){return this._name}get model(){return{name:this._name}}get isDisposed(){return this._isDisposed}dispose(){this._isDisposed||(this._isDisposed=!0,this._disposed.emit(),this._updateConnectionStatus("disconnected"),this._clearSocket(),qn.Signal.clearData(this))}send(e){this._sendMessage(e)}_sendMessage(e,t=!0){if(!(this._isDisposed||!e.content))if(this.connectionStatus==="connected"&&this._ws){let n=[e.type,...e.content];this._ws.send(JSON.stringify(n))}else if(t)this._pendingMessages.push(e);else throw new Error(`Could not send message: ${JSON.stringify(e)}`)}_sendPending(){for(;this.connectionStatus==="connected"&&this._pendingMessages.length>0;)this._sendMessage(this._pendingMessages[0],!1),this._pendingMessages.shift()}reconnect(){this._errorIfDisposed();let e=new zc.PromiseDelegate,t=(n,s)=>{s==="connected"?(e.resolve(),this.connectionStatusChanged.disconnect(t,this)):s==="disconnected"&&(e.reject(new Error("Terminal connection disconnected")),this.connectionStatusChanged.disconnect(t,this))};return this.connectionStatusChanged.connect(t,this),this._reconnectAttempt=0,this._reconnect(),e.promise}_reconnect(){if(this._errorIfDisposed(),clearTimeout(this._reconnectTimeout),this._reconnectAttempt<this._reconnectLimit){this._updateConnectionStatus("connecting");let e=Hs.getRandomIntInclusive(0,1e3*(Math.pow(2,this._reconnectAttempt)-1));console.error(`Connection lost, reconnecting in ${Math.floor(e/1e3)} seconds.`),this._reconnectTimeout=setTimeout(this._createSocket,e),this._reconnectAttempt+=1}else this._updateConnectionStatus("disconnected");this._clearSocket()}_clearSocket(){this._ws!==null&&(this._ws.onopen=this._noOp,this._ws.onclose=this._noOp,this._ws.onerror=this._noOp,this._ws.onmessage=this._noOp,this._ws.close(),this._ws=null)}async shutdown(){await this._terminalAPIClient.shutdown(this.name),this.dispose()}clone(){return new r({model:this.model,serverSettings:this.serverSettings,terminalAPIClient:this._terminalAPIClient})}_updateConnectionStatus(e){this._connectionStatus!==e&&(this._connectionStatus=e,e!=="connecting"&&(this._reconnectAttempt=0,clearTimeout(this._reconnectTimeout)),e==="connected"&&this._sendPending(),this._connectionStatusChanged.emit(e))}_errorIfDisposed(){if(this.isDisposed)throw new Error("Terminal connection is disposed")}get connectionStatusChanged(){return this._connectionStatusChanged}get connectionStatus(){return this._connectionStatus}};jn.TerminalConnection=Ws;var Hs;(function(r){function e(t,n){return t=Math.ceil(t),n=Math.floor(n),Math.floor(Math.random()*(n-t+1))+t}r.getRandomIntInclusive=e})(Hs||(Hs={}))});var Po=O(kt=>{"use strict";Object.defineProperty(kt,"__esModule",{value:!0});kt.TerminalManager=void 0;var $c=Ge(),Co=ee(),Wc=Ae(),Hc=Je(),Jc=Ot(),Gc=bo(),Rt=class extends Hc.BaseManager{constructor(e={}){var t,n;if(super(e),this._isReady=!1,this._names=[],this._terminalConnections=new Set,this._runningChanged=new Co.Signal(this),this._connectionFailure=new Co.Signal(this),this._terminalAPIClient=(t=e.terminalAPIClient)!==null&&t!==void 0?t:new Jc.TerminalAPIClient({serverSettings:this.serverSettings}),!this.isAvailable()){this._ready=Promise.reject("Terminals unavailable"),this._ready.catch(i=>{});return}let s=this._pollModels=new $c.Poll({auto:!1,factory:()=>this.requestRunning(),frequency:{interval:10*1e3,backoff:!0,max:300*1e3},name:"@jupyterlab/services:TerminalManager#models",standby:(n=e.standby)!==null&&n!==void 0?n:"when-hidden"});this._ready=(async()=>{await s.start(),await s.tick,this._isReady=!0})()}get isReady(){return this._isReady}get ready(){return this._ready}get runningChanged(){return this._runningChanged}get connectionFailure(){return this._connectionFailure}dispose(){var e;this.isDisposed||(this._names.length=0,this._terminalConnections.forEach(t=>t.dispose()),(e=this._pollModels)===null||e===void 0||e.dispose(),super.dispose())}isAvailable(){return this._terminalAPIClient.isAvailable}connectTo(e){let t=new Gc.TerminalConnection({...e,serverSettings:this.serverSettings,terminalAPIClient:this._terminalAPIClient});return this._onStarted(t),this._names.includes(e.model.name)||this.refreshRunning().catch(()=>{}),t}running(){return this._models[Symbol.iterator]()}async refreshRunning(){this._pollModels&&(await this._pollModels.refresh(),await this._pollModels.tick)}async startNew(e={}){let{name:t,cwd:n}=e,s=await this._terminalAPIClient.startNew({name:t,cwd:n});return await this.refreshRunning(),this.connectTo({model:s})}async shutdown(e){await this._terminalAPIClient.shutdown(e),await this.refreshRunning()}async shutdownAll(){await this.refreshRunning(),await Promise.all(this._names.map(e=>this._terminalAPIClient.shutdown(e))),await this.refreshRunning()}async requestRunning(){var e,t;let n;try{n=await this._terminalAPIClient.listRunning()}catch(i){throw(i instanceof Wc.ServerConnection.NetworkError||((e=i.response)===null||e===void 0?void 0:e.status)===503||((t=i.response)===null||t===void 0?void 0:t.status)===424)&&this._connectionFailure.emit(i),i}if(this.isDisposed)return;let s=n.map(({name:i})=>i).sort();s!==this._names&&(this._names=s,this._terminalConnections.forEach(i=>{s.includes(i.name)||i.dispose()}),this._runningChanged.emit(this._models))}_onStarted(e){this._terminalConnections.add(e),e.disposed.connect(this._onDisposed,this)}_onDisposed(e){this._terminalConnections.delete(e),this.refreshRunning().catch(()=>{})}get _models(){return this._names.map(e=>({name:e}))}};kt.TerminalManager=Rt;(function(r){class e extends r{constructor(){super(...arguments),this._readyPromise=new Promise(()=>{})}get isActive(){return!1}get parentReady(){return super.ready}get ready(){return this.parentReady.then(()=>this._readyPromise)}async startNew(n){return Promise.reject(new Error("Not implemented in no-op Terminal Manager"))}connectTo(n){throw Error("Not implemented in no-op Terminal Manager")}async shutdown(n){return Promise.reject(new Error("Not implemented in no-op Terminal Manager"))}async requestRunning(){return Promise.resolve()}}r.NoopManager=e})(Rt||(kt.TerminalManager=Rt={}))});var Js=O(pe=>{"use strict";var Mo=pe&&pe.__createBinding||(Object.create?function(r,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,n,s)}:function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]}),Xc=pe&&pe.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),Eo=pe&&pe.__importStar||function(){var r=function(e){return r=Object.getOwnPropertyNames||function(t){var n=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[n.length]=s);return n},r(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n=r(e),s=0;s<n.length;s++)n[s]!=="default"&&Mo(t,e,n[s]);return Xc(t,e),t}}(),Yc=pe&&pe.__exportStar||function(r,e){for(var t in r)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&Mo(e,r,t)};Object.defineProperty(pe,"__esModule",{value:!0});pe.TerminalAPI=pe.Terminal=void 0;var Qc=Eo(So());pe.Terminal=Qc;var Zc=Eo(Ot());pe.TerminalAPI=Zc;Yc(Po(),pe)});var Oo=O(Io=>{"use strict";Object.defineProperty(Io,"__esModule",{value:!0})});var Xs=O(Un=>{"use strict";Object.defineProperty(Un,"__esModule",{value:!0});Un.UserAPIClient=void 0;var Ro=he(),eu=te(),tu="api/me",Gs=class{constructor(e={}){var t;this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:Ro.ServerConnection.makeSettings()}async get(){let{baseUrl:e}=this.serverSettings,{makeRequest:t,ResponseError:n}=Ro.ServerConnection,s=eu.URLExt.join(e,tu),i=await t(s,{},this.serverSettings);if(i.status!==200)throw await n.create(i);return await i.json()}};Un.UserAPIClient=Gs});var Do=O(An=>{"use strict";Object.defineProperty(An,"__esModule",{value:!0});An.UserManager=void 0;var nu=X(),su=Ge(),ko=ee(),ru=Je(),iu=Xs(),Ys="@jupyterlab/services:UserManager#user",Qs=class extends ru.BaseManager{constructor(e={}){var t,n;super(e),this._isReady=!1,this._userChanged=new ko.Signal(this),this._connectionFailure=new ko.Signal(this),this._userApiClient=(t=e.userApiClient)!==null&&t!==void 0?t:new iu.UserAPIClient({serverSettings:this.serverSettings}),this._ready=this.requestUser().then(()=>{this.isDisposed||(this._isReady=!0)}).catch(s=>new Promise(()=>{})),this._pollUser=new su.Poll({auto:!1,factory:()=>this.requestUser(),frequency:{interval:61*1e3,backoff:!0,max:300*1e3},name:Ys,standby:(n=e.standby)!==null&&n!==void 0?n:"when-hidden"}),this.ready.then(()=>{this._pollUser.start()})}get isReady(){return this._isReady}get ready(){return this._ready}get identity(){return this._identity}get permissions(){return this._permissions}get userChanged(){return this._userChanged}get connectionFailure(){return this._connectionFailure}dispose(){this._pollUser.dispose(),super.dispose()}async refreshUser(){await this._pollUser.refresh(),await this._pollUser.tick}async requestUser(){if(this.isDisposed)return;let e={identity:this._identity,permissions:this._permissions},t=await this._userApiClient.get(),n=t.identity,{localStorage:s}=window,i=s.getItem(Ys);if(i&&(!n.initials||!n.color)){let o=JSON.parse(i);n.initials=n.initials||o.initials||n.name.substring(0,1),n.color=n.color||o.color||Zs.getRandomColor()}nu.JSONExt.deepEqual(t,e)||(this._identity=n,this._permissions=t.permissions,s.setItem(Ys,JSON.stringify(n)),this._userChanged.emit(t))}};An.UserManager=Qs;var Zs;(function(r){let e=["var(--jp-collaborator-color1)","var(--jp-collaborator-color2)","var(--jp-collaborator-color3)","var(--jp-collaborator-color4)","var(--jp-collaborator-color5)","var(--jp-collaborator-color6)","var(--jp-collaborator-color7)"];r.getRandomColor=()=>e[Math.floor(Math.random()*e.length)]})(Zs||(Zs={}))});var er=O(me=>{"use strict";var To=me&&me.__createBinding||(Object.create?function(r,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,n,s)}:function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]}),ou=me&&me.__setModuleDefault||(Object.create?function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}:function(r,e){r.default=e}),qo=me&&me.__importStar||function(){var r=function(e){return r=Object.getOwnPropertyNames||function(t){var n=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[n.length]=s);return n},r(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n=r(e),s=0;s<n.length;s++)n[s]!=="default"&&To(t,e,n[s]);return ou(t,e),t}}(),au=me&&me.__exportStar||function(r,e){for(var t in r)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&To(e,r,t)};Object.defineProperty(me,"__esModule",{value:!0});me.UserAPI=me.User=void 0;var lu=qo(Oo());me.User=lu;var cu=qo(Xs());me.UserAPI=cu;au(Do(),me)});var nr=O(Nn=>{"use strict";Object.defineProperty(Nn,"__esModule",{value:!0});Nn.WorkspaceManager=void 0;var jo=te(),uu=Fs(),Dt=he(),hu="api/workspaces",tr=class extends uu.DataConnector{constructor(e={}){var t;super(),this.serverSettings=(t=e.serverSettings)!==null&&t!==void 0?t:Dt.ServerConnection.makeSettings()}async fetch(e){let{serverSettings:t}=this,{baseUrl:n,appUrl:s}=t,{makeRequest:i,ResponseError:o}=Dt.ServerConnection,a=n+s,h=it.url(a,e),c=await i(h,{},t);if(c.status!==200)throw await o.create(c);return c.json()}async list(){let{serverSettings:e}=this,{baseUrl:t,appUrl:n}=e,{makeRequest:s,ResponseError:i}=Dt.ServerConnection,o=t+n,a=it.url(o,""),h=await s(a,{},e);if(h.status!==200)throw await i.create(h);return(await h.json()).workspaces}async remove(e){let{serverSettings:t}=this,{baseUrl:n,appUrl:s}=t,{makeRequest:i,ResponseError:o}=Dt.ServerConnection,a=n+s,h=it.url(a,e),u=await i(h,{method:"DELETE"},t);if(u.status!==204)throw await o.create(u)}async save(e,t){let{serverSettings:n}=this,{baseUrl:s,appUrl:i}=n,{makeRequest:o,ResponseError:a}=Dt.ServerConnection,h=s+i,c=it.url(h,e),u={body:JSON.stringify(t),method:"PUT"},l=await o(c,u,n);if(l.status!==204)throw await a.create(l)}};Nn.WorkspaceManager=tr;var it;(function(r){function e(t,n){let s=jo.URLExt.join(t,hu),i=jo.URLExt.join(s,n);if(!i.startsWith(s))throw new Error("Can only be used for workspaces requests");return i}r.url=e})(it||(it={}))});var Ao=O(Ln=>{"use strict";Object.defineProperty(Ln,"__esModule",{value:!0});Ln.ServiceManager=void 0;var Uo=ee(),du=Hi(),fu=_s(),_u=ps(),gu=Es(),pu=Os(),mu=js(),vu=he(),yu=Ns(),wu=Vs(),Su=Js(),bu=er(),Cu=nr(),sr=class{constructor(e={}){var t,n;this._isDisposed=!1,this._connectionFailure=new Uo.Signal(this),this._isReady=!1;let s=e.defaultDrive,i=(t=e.serverSettings)!==null&&t!==void 0?t:vu.ServerConnection.makeSettings(),o=(n=e.standby)!==null&&n!==void 0?n:"when-hidden",a={defaultDrive:s,serverSettings:i,standby:o};this.serverSettings=i,this.contents=e.contents||new fu.ContentsManager(a),this.events=e.events||new _u.EventManager(a),this.kernels=e.kernels||new gu.KernelManager(a),this.sessions=e.sessions||new yu.SessionManager({...a,kernelManager:this.kernels}),this.settings=e.settings||new wu.SettingManager(a),this.terminals=e.terminals||new Su.TerminalManager(a),this.builder=e.builder||new du.BuildManager(a),this.workspaces=e.workspaces||new Cu.WorkspaceManager(a),this.nbconvert=e.nbconvert||new mu.NbConvertManager(a),this.kernelspecs=e.kernelspecs||new pu.KernelSpecManager(a),this.user=e.user||new bu.UserManager(a),this.kernelspecs.connectionFailure.connect(this._onConnectionFailure,this),this.sessions.connectionFailure.connect(this._onConnectionFailure,this),this.terminals.connectionFailure.connect(this._onConnectionFailure,this);let h=[this.sessions.ready,this.kernelspecs.ready];this.terminals.isAvailable()&&h.push(this.terminals.ready),this._readyPromise=Promise.all(h).then(()=>{this._isReady=!0})}get connectionFailure(){return this._connectionFailure}get isDisposed(){return this._isDisposed}dispose(){this.isDisposed||(this._isDisposed=!0,Uo.Signal.clearData(this),this.contents.dispose(),this.events.dispose(),this.sessions.dispose(),this.terminals.dispose())}get isReady(){return this._isReady}get ready(){return this._readyPromise}_onConnectionFailure(e,t){this._connectionFailure.emit(t)}};Ln.ServiceManager=sr});var No=O(L=>{"use strict";Object.defineProperty(L,"__esModule",{value:!0});L.IWorkspaceManager=L.IUserManager=L.ITerminalManager=L.IServiceManager=L.ISettingManager=L.ISessionManager=L.IServerSettings=L.INbConvertManager=L.IKernelSpecManager=L.IKernelManager=L.IEventManager=L.IDefaultDrive=L.IDefaultContentProvider=L.IContentsManager=L.IConfigSectionManager=L.IConnectionStatus=void 0;var le=X();L.IConnectionStatus=new le.Token("@jupyterlab/application:IConnectionStatus","A service providing the application connection status.");L.IConfigSectionManager=new le.Token("@jupyterlab/services:IConfigSectionManager","A service providing the config section manager.");L.IContentsManager=new le.Token("@jupyterlab/services:IContentsManager","The contents manager token.");L.IDefaultContentProvider=new le.Token("@jupyterlab/services:IDefaultContentProvider","The default content provider for the contents manager.");L.IDefaultDrive=new le.Token("@jupyterlab/services:IDefaultDrive","The default drive for the contents manager.");L.IEventManager=new le.Token("@jupyterlab/services:IEventManager","The event manager token.");L.IKernelManager=new le.Token("@jupyterlab/services:IKernelManager","The kernel manager token.");L.IKernelSpecManager=new le.Token("@jupyterlab/services:IKernelSpecManager","The kernel spec manager token.");L.INbConvertManager=new le.Token("@jupyterlab/services:INbConvertManager","The nbconvert manager token.");L.IServerSettings=new le.Token("@jupyterlab/services:IServerSettings","The server settings for the application.");L.ISessionManager=new le.Token("@jupyterlab/services:ISessionManager","The session manager token.");L.ISettingManager=new le.Token("@jupyterlab/services:ISettingManager","The setting manager token.");L.IServiceManager=new le.Token("@jupyterlab/services:IServiceManager","The service manager for the application.");L.ITerminalManager=new le.Token("@jupyterlab/services:ITerminalManager","The terminal manager token.");L.IUserManager=new le.Token("@jupyterlab/services:IUserManager","The user manager token.");L.IWorkspaceManager=new le.Token("@jupyterlab/services:IWorkspaceManager","The workspace manager token.")});var Ae=O(W=>{"use strict";var Pu=W&&W.__createBinding||(Object.create?function(r,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,n,s)}:function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]}),ce=W&&W.__exportStar||function(r,e){for(var t in r)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&Pu(e,r,t)};Object.defineProperty(W,"__esModule",{value:!0});ce(Je(),W);ce(oi(),W);ce(ai(),W);ce(_s(),W);ce(ps(),W);ce(Es(),W);ce(Os(),W);ce(Ao(),W);ce(he(),W);ce(Ns(),W);ce(Vs(),W);ce(Js(),W);ce(No(),W);ce(er(),W);ce(nr(),W);ce(js(),W)});function Lo(r){return"node"in r}var xo=or(()=>{});var zo={};ra(zo,{BLOCK_SIZE:()=>Ou,ContentsAPI:()=>zn,DRIVE_SEPARATOR:()=>Ko,DriveFS:()=>Tt,DriveFSEmscriptenNodeOps:()=>Kn,DriveFSEmscriptenStreamOps:()=>Fn,ServiceWorkerContentsAPI:()=>Vn});var Fo,Ko,Ou,Ru,ku,xn,Fn,Kn,zn,Vn,Tt,rr=or(()=>{Fo=Wn(X());xo();Ko=":",Ou=4096,Ru=new TextEncoder,ku=new TextDecoder("utf-8"),xn={0:!1,1:!0,2:!0,64:!0,65:!0,66:!0,129:!0,193:!0,514:!0,577:!0,578:!0,705:!0,706:!0,1024:!0,1025:!0,1026:!0,1089:!0,1090:!0,1153:!0,1154:!0,1217:!0,1218:!0,4096:!0,4098:!0},Fn=class{constructor(e){this.fs=e}open(e){var t;let n=this.fs.realPath(e.node);if(this.fs.FS.isFile(e.node.mode))try{let s=this.fs.API.get(n);e.file=s}catch{let s=(t=e.flags)!==null&&t!==void 0?t:e.shared.flags,i=typeof s=="string"?parseInt(s,10):s;i&=8191;let o=!0;if(i in xn&&(o=xn[i]),o){e.node=this.fs.node_ops.mknod(e.node.parent,e.node.name,e.node.mode,0);let a=this.fs.API.get(n);e.file=a}else throw new this.fs.FS.ErrnoError(this.fs.ERRNO_CODES.ENOENT)}}close(e){var t;if(!this.fs.FS.isFile(e.node.mode)||!e.file)return;let n=this.fs.realPath(e.node),s=(t=e.flags)!==null&&t!==void 0?t:e.shared.flags,i=typeof s=="string"?parseInt(s,10):s;i&=8191;let o=!0;i in xn&&(o=xn[i]),o&&this.fs.API.put(n,e.file),e.file=void 0}read(e,t,n,s,i){if(s<=0||e.file===void 0||i>=(e.file.data.length||0))return 0;let o=Math.min(e.file.data.length-i,s);return t.set(e.file.data.subarray(i,i+o),n),o}write(e,t,n,s,i){var o;if(s<=0||e.file===void 0)return 0;let a=Date.now();if(e.node.timestamp=a,e.node.atime=a,e.node.mtime=a,e.node.ctime=a,i+s>(((o=e.file)===null||o===void 0?void 0:o.data.length)||0)){let h=e.file.data?e.file.data:new Uint8Array;e.file.data=new Uint8Array(i+s),e.file.data.set(h)}return e.file.data.set(t.subarray(n,n+s),i),s}llseek(e,t,n){var s;let i=t;if(n===1)i+=(s=e.position)!==null&&s!==void 0?s:e.shared.position;else if(n===2&&this.fs.FS.isFile(e.node.mode))if(e.file!==void 0)i+=e.file.data.length;else throw new this.fs.FS.ErrnoError(this.fs.ERRNO_CODES.EPERM);if(i<0)throw new this.fs.FS.ErrnoError(this.fs.ERRNO_CODES.EINVAL);return i}},Kn=class{constructor(e){this.node=t=>Lo(t)?t.node:t,this.getattr=t=>{let n=this.node(t);return{...this.fs.API.getattr(this.fs.realPath(n)),mode:n.mode,ino:n.id}},this.setattr=(t,n)=>{let s=this.node(t);for(let[i,o]of Object.entries(n))switch(i){case"mode":s.mode=o;break;case"timestamp":s.timestamp=o;break;case"atime":s.atime=o;break;case"mtime":s.mtime=o;break;case"ctime":s.ctime=o;break;case"size":{let a=o,h=this.fs.realPath(s);if(this.fs.FS.isFile(s.mode)&&a>=0){let c;try{c=this.fs.API.get(h)}catch{break}let u=c.data?c.data:new Uint8Array;a!==u.length&&(a<u.length?c.data=c.data.slice(0,a):(c.data=new Uint8Array(a),c.data.set(u)),this.fs.API.put(h,c))}else console.warn("setattr size of",a,"on",s,"not yet implemented");break}case"dontFollow":break;default:console.warn("setattr",i,"of",o,"on",s,"not yet implemented");break}},this.lookup=(t,n)=>{let s=this.node(t),i=this.fs.PATH.join2(this.fs.realPath(s),n),o=this.fs.API.lookup(i);if(!o.ok)throw new this.fs.FS.ErrnoError(this.fs.ERRNO_CODES.ENOENT);return this.fs.createNode(s,n,o.mode,0)},this.mknod=(t,n,s,i)=>{let o=this.node(t),a=this.fs.PATH.join2(this.fs.realPath(o),n);return this.fs.API.mknod(a,s),this.fs.createNode(o,n,s,i)},this.rename=(t,n,s)=>{let i=this.node(t),o=this.node(n);this.fs.API.rename(i.parent?this.fs.PATH.join2(this.fs.realPath(i.parent),i.name):i.name,this.fs.PATH.join2(this.fs.realPath(o),s)),i.name=s,i.parent=o},this.unlink=(t,n)=>this.fs.API.rmdir(this.fs.PATH.join2(this.fs.realPath(this.node(t)),n)),this.rmdir=(t,n)=>this.fs.API.rmdir(this.fs.PATH.join2(this.fs.realPath(this.node(t)),n)),this.readdir=t=>this.fs.API.readdir(this.fs.realPath(this.node(t))),this.symlink=(t,n,s)=>{throw new this.fs.FS.ErrnoError(this.fs.ERRNO_CODES.EPERM)},this.readlink=t=>{throw new this.fs.FS.ErrnoError(this.fs.ERRNO_CODES.EINVAL)},this.fs=e}},zn=class{constructor(e){this._driveName=e.driveName,this._mountpoint=e.mountpoint,this.FS=e.FS,this.ERRNO_CODES=e.ERRNO_CODES}lookup(e){return this.request({method:"lookup",path:this.normalizePath(e)})}getmode(e){return this.request({method:"getmode",path:this.normalizePath(e)})}mknod(e,t){return this.request({method:"mknod",path:this.normalizePath(e),data:{mode:t}})}rename(e,t){return this.request({method:"rename",path:this.normalizePath(e),data:{newPath:this.normalizePath(t)}})}readdir(e){let t=this.request({method:"readdir",path:this.normalizePath(e)});return t.push("."),t.push(".."),t}rmdir(e){return this.request({method:"rmdir",path:this.normalizePath(e)})}get(e){let t=this.request({method:"get",path:this.normalizePath(e)});if(!t)throw new this.FS.ErrnoError(this.ERRNO_CODES.ENOENT);let n=t.content,s=t.format;switch(s){case"json":case"text":return{data:Ru.encode(n),format:s};case"base64":{let i=atob(n),o=i.length,a=new Uint8Array(o);for(let h=0;h<o;h++)a[h]=i.charCodeAt(h);return{data:a,format:s}}default:throw new this.FS.ErrnoError(this.ERRNO_CODES.ENOENT)}}put(e,t){switch(t.format){case"json":case"text":return this.request({method:"put",path:this.normalizePath(e),data:{format:t.format,data:ku.decode(t.data)}});case"base64":{let n="";for(let s=0;s<t.data.byteLength;s++)n+=String.fromCharCode(t.data[s]);return this.request({method:"put",path:this.normalizePath(e),data:{format:t.format,data:btoa(n)}})}}}getattr(e){let t=this.request({method:"getattr",path:this.normalizePath(e)}),n=new Date(0);return t.atime=t.atime?new Date(t.atime):n,t.mtime=t.mtime?new Date(t.mtime):n,t.ctime=t.ctime?new Date(t.ctime):n,t.size=t.size||0,t}normalizePath(e){return e.startsWith(this._mountpoint)&&(e=e.slice(this._mountpoint.length)),this._driveName&&(e=`${this._driveName}${Ko}${e}`),e}},Vn=class extends zn{constructor(e){super(e),this._baseUrl=e.baseUrl,this._browsingContextId=e.browsingContextId||""}request(e){let t=new XMLHttpRequest;t.open("POST",encodeURI(this.endpoint),!1);let n=Fo.UUID.uuid4(),s={data:{...e,requestId:n},browsingContextId:this._browsingContextId,requestId:n};try{t.send(JSON.stringify(s))}catch(i){console.error(i)}if(t.status>=400)throw new this.FS.ErrnoError(this.ERRNO_CODES.EINVAL);return JSON.parse(t.responseText)}get endpoint(){return`${this._baseUrl}api/drive`}},Tt=class{constructor(e){this.FS=e.FS,this.PATH=e.PATH,this.ERRNO_CODES=e.ERRNO_CODES,this.API=this.createAPI(e),this.driveName=e.driveName,this.node_ops=new Kn(this),this.stream_ops=new Fn(this)}createAPI(e){if(!e.browsingContextId||!e.baseUrl)throw new Error("Cannot create service-worker API without current browsingContextId");return new Vn(e)}mount(e){return this.createNode(null,e.mountpoint,16895,0)}createNode(e,t,n,s){let i=this.FS;if(!i.isDir(n)&&!i.isFile(n))throw new i.ErrnoError(this.ERRNO_CODES.EINVAL);let o=i.createNode(e,t,n,s);return o.node_ops=this.node_ops,o.stream_ops=this.stream_ops,o}getMode(e){return this.API.getmode(e)}realPath(e){let t=[],n=e;for(t.push(n.name);n.parent!==n;)n=n.parent,t.push(n.name);return t.reverse(),this.PATH.join.apply(null,t)}}});var lr=Symbol("Comlink.proxy"),oa=Symbol("Comlink.endpoint"),aa=Symbol("Comlink.releaseProxy"),Hn=Symbol("Comlink.finalizer"),jt=Symbol("Comlink.thrown"),cr=r=>typeof r=="object"&&r!==null||typeof r=="function",la={canHandle:r=>cr(r)&&r[lr],serialize(r){let{port1:e,port2:t}=new MessageChannel;return Lt(r,e),[t,[t]]},deserialize(r){return r.start(),da(r)}},ca={canHandle:r=>cr(r)&&jt in r,serialize({value:r}){let e;return r instanceof Error?e={isError:!0,value:{message:r.message,name:r.name,stack:r.stack}}:e={isError:!1,value:r},[e,[]]},deserialize(r){throw r.isError?Object.assign(new Error(r.value.message),r.value):r.value}},ur=new Map([["proxy",la],["throw",ca]]);function ua(r,e){for(let t of r)if(e===t||t==="*"||t instanceof RegExp&&t.test(e))return!0;return!1}function Lt(r,e=globalThis,t=["*"]){e.addEventListener("message",function n(s){if(!s||!s.data)return;if(!ua(t,s.origin)){console.warn(`Invalid origin '${s.origin}' for comlink proxy`);return}let{id:i,type:o,path:a}=Object.assign({path:[]},s.data),h=(s.data.argumentList||[]).map(He),c;try{let u=a.slice(0,-1).reduce((d,m)=>d[m],r),l=a.reduce((d,m)=>d[m],r);switch(o){case"GET":c=l;break;case"SET":u[a.slice(-1)[0]]=He(s.data.value),c=!0;break;case"APPLY":c=l.apply(u,h);break;case"CONSTRUCT":{let d=new l(...h);c=ma(d)}break;case"ENDPOINT":{let{port1:d,port2:m}=new MessageChannel;Lt(r,m),c=pa(d,[d])}break;case"RELEASE":c=void 0;break;default:return}}catch(u){c={value:u,[jt]:0}}Promise.resolve(c).catch(u=>({value:u,[jt]:0})).then(u=>{let[l,d]=Nt(u);e.postMessage(Object.assign(Object.assign({},l),{id:i}),d),o==="RELEASE"&&(e.removeEventListener("message",n),hr(e),Hn in r&&typeof r[Hn]=="function"&&r[Hn]())}).catch(u=>{let[l,d]=Nt({value:new TypeError("Unserializable return value"),[jt]:0});e.postMessage(Object.assign(Object.assign({},l),{id:i}),d)})}),e.start&&e.start()}function ha(r){return r.constructor.name==="MessagePort"}function hr(r){ha(r)&&r.close()}function da(r,e){let t=new Map;return r.addEventListener("message",function(s){let{data:i}=s;if(!i||!i.id)return;let o=t.get(i.id);if(o)try{o(i)}finally{t.delete(i.id)}}),Jn(r,t,[],e)}function qt(r){if(r)throw new Error("Proxy has been released and is not useable")}function dr(r){return Ye(r,new Map,{type:"RELEASE"}).then(()=>{hr(r)})}var Ut=new WeakMap,At="FinalizationRegistry"in globalThis&&new FinalizationRegistry(r=>{let e=(Ut.get(r)||0)-1;Ut.set(r,e),e===0&&dr(r)});function fa(r,e){let t=(Ut.get(e)||0)+1;Ut.set(e,t),At&&At.register(r,e,r)}function _a(r){At&&At.unregister(r)}function Jn(r,e,t=[],n=function(){}){let s=!1,i=new Proxy(n,{get(o,a){if(qt(s),a===aa)return()=>{_a(i),dr(r),e.clear(),s=!0};if(a==="then"){if(t.length===0)return{then:()=>i};let h=Ye(r,e,{type:"GET",path:t.map(c=>c.toString())}).then(He);return h.then.bind(h)}return Jn(r,e,[...t,a])},set(o,a,h){qt(s);let[c,u]=Nt(h);return Ye(r,e,{type:"SET",path:[...t,a].map(l=>l.toString()),value:c},u).then(He)},apply(o,a,h){qt(s);let c=t[t.length-1];if(c===oa)return Ye(r,e,{type:"ENDPOINT"}).then(He);if(c==="bind")return Jn(r,e,t.slice(0,-1));let[u,l]=ar(h);return Ye(r,e,{type:"APPLY",path:t.map(d=>d.toString()),argumentList:u},l).then(He)},construct(o,a){qt(s);let[h,c]=ar(a);return Ye(r,e,{type:"CONSTRUCT",path:t.map(u=>u.toString()),argumentList:h},c).then(He)}});return fa(i,r),i}function ga(r){return Array.prototype.concat.apply([],r)}function ar(r){let e=r.map(Nt);return[e.map(t=>t[0]),ga(e.map(t=>t[1]))]}var fr=new WeakMap;function pa(r,e){return fr.set(r,e),r}function ma(r){return Object.assign(r,{[lr]:!0})}function Nt(r){for(let[e,t]of ur)if(t.canHandle(r)){let[n,s]=t.serialize(r);return[{type:"HANDLER",name:e,value:n},s]}return[{type:"RAW",value:r},fr.get(r)||[]]}function He(r){switch(r.type){case"HANDLER":return ur.get(r.name).deserialize(r.value);case"RAW":return r.value}}function Ye(r,e,t,n){return new Promise(s=>{let i=va();e.set(i,s),r.start&&r.start(),r.postMessage(Object.assign({id:i},t),n)})}function va(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}var Bo=Wn(te()),$o=Wn(Ae());rr();async function Vo(r){return new Function("url","return import(url)")(r)}var Bn=class{constructor(){this._options=null;this._initializer=null;this._pyodide=null;this._localPath="";this._driveName="";this._driveFS=null;this._sendWorkerMessage=()=>{};this._logMessage=()=>{};this._initialized=new Promise((e,t)=>{this._initializer={resolve:e,reject:t}})}async initialize(e){var t;if(this._options=e,e.location.includes(":")){let n=e.location.split(":");this._driveName=n[0],this._localPath=n[1]}else this._driveName="",this._localPath=e.location;await this.initRuntime(e),await this.initFilesystem(e),await this.initPackageManager(e),await this.initKernel(e),await this.initGlobals(e),(t=this._initializer)==null||t.resolve()}async initRuntime(e){let{pyodideUrl:t,indexUrl:n}=e,{loadPyodide:s}=await Vo(t);this._pyodide=await s({indexURL:n,stdout:i=>{console.log(i),this._logMessage({type:"text",level:"info",data:i})},stderr:i=>{console.error(i),this._logMessage({type:"text",level:"critical",data:i})},...e.loadPyodideOptions}),this._pyodide._api.on_fatal=async i=>{let o="";i.name==="Exit"?o="Pyodide has exited and can no longer be used.":o=`Pyodide has suffered a fatal error. Please report this to the Pyodide maintainers.
10
10
  The cause of the error was: ${i.name}
11
11
  ${i.message}
12
12
  Stack trace:
@@ -17,8 +17,8 @@ ${i.stack}`,this._logMessage({type:"text",level:"critical",data:o})}}async initP
17
17
  import piplite.piplite
18
18
  piplite.piplite._PIPLITE_DISABLE_PYPI = ${n?"True":"False"}
19
19
  piplite.piplite._PIPLITE_URLS = ${JSON.stringify(s)}
20
- `)}async initKernel(e){let t=(e.loadPyodideOptions||{}).packages||[],n=["sqlite3","ipykernel","comm","pyodide_kernel","jedi","ipython"],s=[];for(let i of n)t.includes(i)||s.push(`await piplite.install('${i}', keep_going=True)`);s.push("import pyodide_kernel"),e.mountDrive&&this._localPath&&s.push("import os",`os.chdir("${this._localPath}")`),await this._pyodide.runPythonAsync(s.join(`
21
- `))}async initGlobals(e){let{globals:t}=this._pyodide;this._kernel=t.get("pyodide_kernel").kernel_instance.copy(),this._stdout_stream=t.get("pyodide_kernel").stdout_stream.copy(),this._stderr_stream=t.get("pyodide_kernel").stderr_stream.copy(),this._interpreter=this._kernel.interpreter.copy(),this._interpreter.send_comm=this.sendComm.bind(this)}async initFilesystem(e){if(e.mountDrive){let t="/drive",{FS:n,PATH:s,ERRNO_CODES:i}=this._pyodide,{baseUrl:o}=e,{DriveFS:a}=await Promise.resolve().then(()=>(rr(),zo)),h=new a({FS:n,PATH:s,ERRNO_CODES:i,baseUrl:o,driveName:this._driveName,mountpoint:t,browsingContextId:this._browsingContextId});n.mkdirTree(t),n.mount(h,{},t),n.chdir(t),this._driveFS=h}}mapToObject(e){let t=e instanceof Array?[]:{},n=e instanceof Map?e.entries():Object.entries(e);for(let[s,i]of n)t[s]=i instanceof Map||i instanceof Array?this.mapToObject(i):i;return t}formatResult(e){if(!(e instanceof this._pyodide.ffi.PyProxy))return e;let t=e.toJs();return this.mapToObject(t)}registerWorkerMessageCallback(e){this._sendWorkerMessage=e}registerLogMessageCallback(e){this._logMessage=e}async setup(e){await this._initialized,this._kernel._parent_header=this._pyodide.toPy(e)}async execute(e,t){await this.setup(t);let n=(l,d,m)=>{let v={execution_count:l,data:this.formatResult(d),metadata:this.formatResult(m)};this._sendWorkerMessage({parentHeader:this.formatResult(this._kernel._parent_header).header,bundle:v,type:"execute_result"})},s=(l,d,m)=>{let v={ename:l,evalue:d,traceback:m};this._sendWorkerMessage({parentHeader:this.formatResult(this._kernel._parent_header).header,bundle:v,type:"execute_error"})},i=l=>{let d={wait:this.formatResult(l)};this._sendWorkerMessage({parentHeader:this.formatResult(this._kernel._parent_header).header,bundle:d,type:"clear_output"})},o=(l,d,m)=>{let v={data:this.formatResult(l),metadata:this.formatResult(d),transient:this.formatResult(m)};this._sendWorkerMessage({parentHeader:this.formatResult(this._kernel._parent_header).header,bundle:v,type:"display_data"})},a=(l,d,m)=>{let v={data:this.formatResult(l),metadata:this.formatResult(d),transient:this.formatResult(m)};this._sendWorkerMessage({parentHeader:this.formatResult(this._kernel._parent_header).header,bundle:v,type:"update_display_data"})},h=(l,d)=>{let m={name:this.formatResult(l),text:this.formatResult(d)};this._sendWorkerMessage({parentHeader:this.formatResult(this._kernel._parent_header).header,bundle:m,type:"stream"})};this._stdout_stream.publish_stream_callback=h,this._stderr_stream.publish_stream_callback=h,this._interpreter.display_pub.clear_output_callback=i,this._interpreter.display_pub.display_data_callback=o,this._interpreter.display_pub.update_display_data_callback=a,this._interpreter.displayhook.publish_execution_result=n,this._interpreter.input=this.input.bind(this),this._interpreter.getpass=this.getpass.bind(this);let c=await this._kernel.run(e.code),u=this.formatResult(c);return u.status==="error"&&s(u.ename,u.evalue,u.traceback),u}async complete(e,t){await this.setup(t);let n=this._kernel.complete(e.code,e.cursor_pos);return this.formatResult(n)}async inspect(e,t){await this.setup(t);let n=this._kernel.inspect(e.code,e.cursor_pos,e.detail_level);return this.formatResult(n)}async isComplete(e,t){await this.setup(t);let n=this._kernel.is_complete(e.code);return this.formatResult(n)}async commInfo(e,t){await this.setup(t);let n=this._kernel.comm_info(e.target_name);return{comms:this.formatResult(n),status:"ok"}}async commOpen(e,t){await this.setup(t);let n=this._kernel.comm_manager.comm_open(this._pyodide.toPy(null),this._pyodide.toPy(null),this._pyodide.toPy(e));return this.formatResult(n)}async commMsg(e,t){await this.setup(t);let n=this._kernel.comm_manager.comm_msg(this._pyodide.toPy(null),this._pyodide.toPy(null),this._pyodide.toPy(e));return this.formatResult(n)}async commClose(e,t){await this.setup(t);let n=this._kernel.comm_manager.comm_close(this._pyodide.toPy(null),this._pyodide.toPy(null),this._pyodide.toPy(e));return this.formatResult(n)}async inputReply(e,t){}getpass(e){return e=typeof e=="undefined"?"":e,this.sendInputRequest(e,!0)}input(e){return e=typeof e=="undefined"?"":e,this.sendInputRequest(e,!1)}async sendComm(e,t,n,s,i){this._sendWorkerMessage({type:e,content:this.formatResult(t),metadata:this.formatResult(n),ident:this.formatResult(s),buffers:this.formatResult(i),parentHeader:this.formatResult(this._kernel._parent_header).header})}};var ir=class extends Bn{constructor(){super(),this._sendWorkerMessage=e=>{postMessage({_kernelMessage:e})},this._logMessage=e=>{postMessage({_logMessage:e})}}async initFilesystem(e){if(e.mountDrive){let t="/drive",{FS:n,PATH:s,ERRNO_CODES:i}=this._pyodide,{baseUrl:o,browsingContextId:a}=e,h=new Tt({FS:n,PATH:s,ERRNO_CODES:i,baseUrl:o,driveName:this._driveName,mountpoint:t,browsingContextId:a});n.mkdirTree(t),n.mount(h,{},t),n.chdir(t),this._driveFS=h}}sendInputRequest(e,t){var i,o;let n=this.formatResult(this._kernel._parent_header).header,s=Bo.KernelMessage.createMessage({channel:"stdin",msgType:"input_request",session:(i=n==null?void 0:n.session)!=null?i:"",parentHeader:n,content:{prompt:e,password:t}});try{if(!this._options)throw new Error("Kernel options not set");let{baseUrl:a,browsingContextId:h}=this._options;if(!h)throw new Error("Kernel browsingContextId not set");let c=new XMLHttpRequest,u=Vo.URLExt.join(a,"/api/stdin/kernel");c.open("POST",u,!1);let l=JSON.stringify({browsingContextId:h,data:s});c.send(l);let d=JSON.parse(c.response);if("error"in d)throw new Error(d.error);return(o=d.content)==null?void 0:o.value}catch(a){console.warn(`Failed to request stdin via service worker: ${a}`);return}}},ku=new ir;Lt(ku);export{ir as PyodideComlinkKernel};
20
+ `)}async initKernel(e){let t=(e.loadPyodideOptions||{}).packages||[],n=["ipykernel","comm","pyodide-kernel","jedi","ipython"],s=[];for(let i of n)t.includes(i)||s.push(`await piplite.install('${i}', keep_going=True)`);s.push("import pyodide_kernel"),e.mountDrive&&this._localPath&&s.push("import os",`os.chdir("${this._localPath}")`),await this._pyodide.runPythonAsync(s.join(`
21
+ `))}async initGlobals(e){let{globals:t}=this._pyodide;this._kernel=t.get("pyodide_kernel").kernel_instance.copy(),this._stdout_stream=t.get("pyodide_kernel").stdout_stream.copy(),this._stderr_stream=t.get("pyodide_kernel").stderr_stream.copy(),this._interpreter=this._kernel.interpreter.copy(),this._interpreter.send_comm=this.sendComm.bind(this)}async initFilesystem(e){if(e.mountDrive){let t="/drive",{FS:n,PATH:s,ERRNO_CODES:i}=this._pyodide,{baseUrl:o}=e,{DriveFS:a}=await Promise.resolve().then(()=>(rr(),zo)),h=new a({FS:n,PATH:s,ERRNO_CODES:i,baseUrl:o,driveName:this._driveName,mountpoint:t,browsingContextId:this._browsingContextId});n.mkdirTree(t),n.mount(h,{},t),n.chdir(t),this._driveFS=h}}mapToObject(e){let t=e instanceof Array?[]:{},n=e instanceof Map?e.entries():Object.entries(e);for(let[s,i]of n)t[s]=i instanceof Map||i instanceof Array?this.mapToObject(i):i;return t}formatResult(e){if(!(e instanceof this._pyodide.ffi.PyProxy))return e;let t=e.toJs();return this.mapToObject(t)}registerWorkerMessageCallback(e){this._sendWorkerMessage=e}registerLogMessageCallback(e){this._logMessage=e}async setup(e){await this._initialized,this._kernel._parent_header=this._pyodide.toPy(e)}async execute(e,t){await this.setup(t);let n=(l,d,m)=>{let v={execution_count:l,data:this.formatResult(d),metadata:this.formatResult(m)};this._sendWorkerMessage({parentHeader:this.formatResult(this._kernel._parent_header).header,bundle:v,type:"execute_result"})},s=(l,d,m)=>{let v={ename:l,evalue:d,traceback:m};this._sendWorkerMessage({parentHeader:this.formatResult(this._kernel._parent_header).header,bundle:v,type:"execute_error"})},i=l=>{let d={wait:this.formatResult(l)};this._sendWorkerMessage({parentHeader:this.formatResult(this._kernel._parent_header).header,bundle:d,type:"clear_output"})},o=(l,d,m)=>{let v={data:this.formatResult(l),metadata:this.formatResult(d),transient:this.formatResult(m)};this._sendWorkerMessage({parentHeader:this.formatResult(this._kernel._parent_header).header,bundle:v,type:"display_data"})},a=(l,d,m)=>{let v={data:this.formatResult(l),metadata:this.formatResult(d),transient:this.formatResult(m)};this._sendWorkerMessage({parentHeader:this.formatResult(this._kernel._parent_header).header,bundle:v,type:"update_display_data"})},h=(l,d)=>{let m={name:this.formatResult(l),text:this.formatResult(d)};this._sendWorkerMessage({parentHeader:this.formatResult(this._kernel._parent_header).header,bundle:m,type:"stream"})};this._stdout_stream.publish_stream_callback=h,this._stderr_stream.publish_stream_callback=h,this._interpreter.display_pub.clear_output_callback=i,this._interpreter.display_pub.display_data_callback=o,this._interpreter.display_pub.update_display_data_callback=a,this._interpreter.displayhook.publish_execution_result=n,this._interpreter.input=this.input.bind(this),this._interpreter.getpass=this.getpass.bind(this);let c=await this._kernel.run(e.code),u=this.formatResult(c);return u.status==="error"&&s(u.ename,u.evalue,u.traceback),u}async complete(e,t){await this.setup(t);let n=this._kernel.complete(e.code,e.cursor_pos);return this.formatResult(n)}async inspect(e,t){await this.setup(t);let n=this._kernel.inspect(e.code,e.cursor_pos,e.detail_level);return this.formatResult(n)}async isComplete(e,t){await this.setup(t);let n=this._kernel.is_complete(e.code);return this.formatResult(n)}async commInfo(e,t){await this.setup(t);let n=this._kernel.comm_info(e.target_name);return{comms:this.formatResult(n),status:"ok"}}async commOpen(e,t){await this.setup(t);let n=this._kernel.comm_manager.comm_open(this._pyodide.toPy(null),this._pyodide.toPy(null),this._pyodide.toPy(e));return this.formatResult(n)}async commMsg(e,t){await this.setup(t);let n=this._kernel.comm_manager.comm_msg(this._pyodide.toPy(null),this._pyodide.toPy(null),this._pyodide.toPy(e));return this.formatResult(n)}async commClose(e,t){await this.setup(t);let n=this._kernel.comm_manager.comm_close(this._pyodide.toPy(null),this._pyodide.toPy(null),this._pyodide.toPy(e));return this.formatResult(n)}async inputReply(e,t){}getpass(e){return e=typeof e=="undefined"?"":e,this.sendInputRequest(e,!0)}input(e){return e=typeof e=="undefined"?"":e,this.sendInputRequest(e,!1)}async sendComm(e,t,n,s,i){this._sendWorkerMessage({type:e,content:this.formatResult(t),metadata:this.formatResult(n),ident:this.formatResult(s),buffers:this.formatResult(i),parentHeader:this.formatResult(this._kernel._parent_header).header})}};var ir=class extends Bn{constructor(){super(),this._sendWorkerMessage=e=>{postMessage({_kernelMessage:e})},this._logMessage=e=>{postMessage({_logMessage:e})}}async initFilesystem(e){if(e.mountDrive){let t="/drive",{FS:n,PATH:s,ERRNO_CODES:i}=this._pyodide,{baseUrl:o,browsingContextId:a}=e,h=new Tt({FS:n,PATH:s,ERRNO_CODES:i,baseUrl:o,driveName:this._driveName,mountpoint:t,browsingContextId:a});n.mkdirTree(t),n.mount(h,{},t),n.chdir(t),this._driveFS=h}}sendInputRequest(e,t){var i,o;let n=this.formatResult(this._kernel._parent_header).header,s=$o.KernelMessage.createMessage({channel:"stdin",msgType:"input_request",session:(i=n==null?void 0:n.session)!=null?i:"",parentHeader:n,content:{prompt:e,password:t}});try{if(!this._options)throw new Error("Kernel options not set");let{baseUrl:a,browsingContextId:h}=this._options;if(!h)throw new Error("Kernel browsingContextId not set");let c=new XMLHttpRequest,u=Bo.URLExt.join(a,"/api/stdin/kernel");c.open("POST",u,!1);let l=JSON.stringify({browsingContextId:h,data:s});c.send(l);let d=JSON.parse(c.response);if("error"in d)throw new Error(d.error);return(o=d.content)==null?void 0:o.value}catch(a){console.warn(`Failed to request stdin via service worker: ${a}`);return}}},Du=new ir;Lt(Du);export{ir as PyodideComlinkKernel};
22
22
  /*! Bundled license information:
23
23
 
24
24
  comlink/dist/esm/comlink.mjs: