@omniviewdev/runtime 0.4.2 → 0.6.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.
- package/dist/api.cjs +1 -1
- package/dist/api.js +246 -113
- package/dist/bindings/events/index.d.ts +140 -0
- package/dist/bindings/github.com/omniviewdev/omniview/appservice.d.ts +5 -0
- package/dist/bindings/github.com/omniviewdev/omniview/backend/pkg/apperror/index.d.ts +1 -0
- package/dist/bindings/github.com/omniviewdev/omniview/backend/pkg/apperror/models.d.ts +58 -0
- package/dist/bindings/github.com/omniviewdev/omniview/backend/pkg/plugin/devserver/index.d.ts +1 -1
- package/dist/bindings/github.com/omniviewdev/omniview/backend/pkg/plugin/devserver/models.d.ts +24 -26
- package/dist/bindings/github.com/omniviewdev/omniview/backend/pkg/plugin/devserver/servicewrapper.d.ts +0 -1
- package/dist/bindings/github.com/omniviewdev/omniview/backend/pkg/plugin/resource/index.d.ts +1 -1
- package/dist/bindings/github.com/omniviewdev/omniview/backend/pkg/plugin/resource/models.d.ts +25 -0
- package/dist/bindings/github.com/omniviewdev/omniview/backend/pkg/plugin/resource/servicewrapper.d.ts +2 -0
- package/dist/bindings/github.com/omniviewdev/omniview/backend/pkg/plugin/servicewrapper.d.ts +2 -0
- package/dist/bindings/github.com/omniviewdev/omniview/internal/devcontract/index.d.ts +1 -0
- package/dist/bindings/github.com/omniviewdev/omniview/internal/devcontract/models.d.ts +101 -0
- package/dist/bindings/github.com/omniviewdev/plugin-sdk/pkg/config/index.d.ts +1 -1
- package/dist/bindings/github.com/omniviewdev/plugin-sdk/pkg/config/models.d.ts +31 -0
- package/dist/{calls-BmUnjINC.js → calls-C1yoW06C.js} +60 -60
- package/dist/{calls-DZctVyoQ.cjs → calls-DUhq86Ki.cjs} +1 -1
- package/dist/context/operations/OperationsContext.d.ts +1 -1
- package/dist/errors/parseAppError.d.ts +1 -14
- package/dist/errors/types.d.ts +15 -2
- package/dist/{events-DDTGFACO.js → events-Bcx6NsMp.js} +1 -2
- package/dist/{events-BTiuwc-0.cjs → events-CtgYnKmS.cjs} +1 -1
- package/dist/graphservice-BKFw5MxQ.js +844 -0
- package/dist/graphservice-CWIVejHl.cjs +1 -0
- package/dist/hooks/resource/useEventBatcher.d.ts +4 -3
- package/dist/hooks/resource/useStreamAction.d.ts +3 -6
- package/dist/index.cjs +2 -2
- package/dist/index.js +985 -946
- package/dist/models-8-4Ny_ft.cjs +1 -0
- package/dist/{models-3V1aa9YT.js → models-BlTzZkmp.js} +46 -60
- package/dist/models-CGYstu7u.cjs +1 -0
- package/dist/{models-B97zjrHu.js → models-D-vu7j83.js} +442 -411
- package/dist/models.cjs +1 -1
- package/dist/models.d.ts +1 -1
- package/dist/models.js +39 -38
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.js +3 -3
- package/package.json +5 -5
- package/dist/graphservice-2kgAuCnt.cjs +0 -1
- package/dist/graphservice-5kuEPkCT.js +0 -731
- package/dist/models-BPmIMpct.cjs +0 -1
- package/dist/models-sJV1iQbd.cjs +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var Je=Object.defineProperty;var Qe=(e,t,r)=>t in e?Je(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var s=(e,t,r)=>Qe(e,typeof t!="symbol"?t+"":t,r);const o=require("./index-D_aIcqH0.cjs"),u=require("./models-CGYstu7u.cjs"),n=require("./calls-DUhq86Ki.cjs");function xe(e,t){return n.ByID(3867104420,e,t).then(r=>v(r))}function ke(e){return n.ByID(3795411887,e)}function Ke(){return n.ByID(1053995964).then(e=>tt(e))}function Xe(e){return n.ByID(3231741321,e).then(t=>nt(t))}function R(e){return n.ByID(2597562645,e).then(t=>_(t))}function Ye(e,t,r){return n.ByID(1481837168,e,t,r)}function Ze(e,t){return n.ByID(230212281,e,t)}function et(){return n.ByID(2408440370).then(e=>_(e))}const v=u.Setting.createFrom,tt=o.Array(o.Any),nt=o.Map(o.Any,v),_=o.Map(o.Any,o.Any),rt=Object.freeze(Object.defineProperty({__proto__:null,GetSetting:xe,HasPlugin:ke,ListPlugins:Ke,ListSettings:Xe,PluginValues:R,SetSetting:Ye,SetSettings:Ze,Values:et},Symbol.toStringTag,{value:"Module"}));function ot(e){return n.ByID(3150413499,e).then(t=>l(t))}function ct(e){return n.ByID(1152913314,e).then(t=>Ft(t))}function w(e){return n.ByID(111194374,e).then(t=>S(t))}function it(e){return n.ByID(3945933305,e)}function ut(e){return n.ByID(2859775056,e).then(t=>L(t))}function st(e,t){return n.ByID(2209599792,e,t).then(r=>Gt(r))}function at(e){return n.ByID(3963363730,e).then(t=>L(t))}function yt(e){return n.ByID(1357029266,e).then(t=>l(t))}function lt(){return n.ByID(2477486666).then(e=>h(e))}function $t(){return n.ByID(976517756).then(e=>h(e))}function pt(e){return n.ByID(1020548995,e).then(t=>h(t))}function ft(e,t){return n.ByID(2004740384,e,t).then(r=>h(r))}function ht(){return n.ByID(873697101).then(e=>M(e))}function Dt(){return n.ByID(637134283).then(e=>Ct(e))}function It(){return n.ByID(550607756).then(e=>Rt(e))}function Bt(e,t){return n.ByID(288660195,e,t).then(r=>l(r))}function Tt(e){return n.ByID(1771013494,e).then(t=>l(t))}function O(e){return n.ByID(2433379724,e).then(t=>l(t))}function St(e,t,r){return n.ByID(2783597264,e,t,r).then(c=>M(c))}function dt(e){return n.ByID(1369550929,e).then(t=>l(t))}function gt(e){return n.ByID(3828800061,e).then(t=>l(t))}const l=u.PluginInfo.createFrom,mt=u.DownloadStats.createFrom,Ft=o.Nullable(mt),S=u.PluginMeta.createFrom,At=u.VersionInfo.createFrom,L=o.Array(At),bt=u.Review.createFrom,Gt=o.Array(bt),h=o.Nullable(S),Pt=u.AvailablePlugin.createFrom,M=o.Array(Pt),Ct=o.Array(S),Rt=o.Array(l),vt=Object.freeze(Object.defineProperty({__proto__:null,GetPlugin:ot,GetPluginDownloadStats:ct,GetPluginMeta:w,GetPluginReadme:it,GetPluginReleaseHistory:ut,GetPluginReviews:st,GetPluginVersions:at,InstallDevPluginFromPath:yt,InstallFromPathPrompt:lt,InstallInDevMode:$t,InstallPluginFromPath:pt,InstallPluginVersion:ft,ListAvailablePlugins:ht,ListPluginMetas:Dt,ListPlugins:It,LoadPlugin:Bt,ReloadPlugin:Tt,RetryFailedPlugin:O,SearchPlugins:St,UninstallPlugin:dt,UnlinkDevPlugin:gt},Symbol.toStringTag,{value:"Module"}));function _t(e){return n.ByID(122243240,e)}function wt(){return n.ByID(269082212).then(e=>xt(e))}function Ot(e){return n.ByID(1421156656,e).then(t=>d(t))}function Lt(e){return n.ByID(3143996982,e).then(t=>j(t))}function Mt(e){return n.ByID(1695819138,e)}function Nt(e){return n.ByID(1827194808,e).then(t=>kt(t))}function jt(e){return n.ByID(72059321,e)}function Ht(e){return n.ByID(62418781,e).then(t=>Kt(t))}function zt(e){return n.ByID(2222012564,e).then(t=>Xt(t))}function Ut(e){return n.ByID(2753368941,e)}function Wt(e){return n.ByID(3825211425,e)}function Vt(e){return n.ByID(2121298005,e).then(t=>Yt(t))}function Et(){return n.ByID(3038957305).then(e=>f(e))}function qt(){return n.ByID(3369612893)}function Jt(e,t){return n.ByID(252556992,e,t)}function Qt(e){return n.ByID(1704369097,e)}function N(){return n.ByID(2936263106).then(e=>j(e))}const d=u.Category.createFrom,xt=o.Array(d),j=o.Map(o.Any,o.Any),kt=o.Array(o.Any),Kt=o.Array(o.Any),Xt=u.Setting.createFrom,Yt=o.Array(o.Any);var f=function e(...t){return f===e&&(f=Zt),f(...t)};const Zt=o.Map(o.Any,d),en=Object.freeze(Object.defineProperty({__proto__:null,GetBool:_t,GetCategories:wt,GetCategory:Ot,GetCategoryValues:Lt,GetFloat:Mt,GetFloatSlice:Nt,GetInt:jt,GetIntSlice:Ht,GetSetting:zt,GetSettingValue:Ut,GetString:Wt,GetStringSlice:Vt,ListSettings:Et,LoadSettings:qt,SetSetting:Jt,SetSettings:Qt,Values:N},Symbol.toStringTag,{value:"Module"}));class g{constructor(t={}){s(this,"type");s(this,"label");s(this,"target");"type"in t||(this.type=""),"label"in t||(this.label=""),Object.assign(this,t)}static createFrom(t={}){let r=typeof t=="string"?JSON.parse(t):t;return new g(r)}}class m{constructor(t={}){s(this,"type");s(this,"title");s(this,"status");s(this,"detail");s(this,"instance");s(this,"suggestions");s(this,"actions");s(this,"code");s(this,"requestId");s(this,"recovery");s(this,"location");"type"in t||(this.type=""),"title"in t||(this.title=""),"status"in t||(this.status=0),"detail"in t||(this.detail=""),Object.assign(this,t)}static createFrom(t={}){const r=tn,c=rn,i=cn;let a=typeof t=="string"?JSON.parse(t):t;return"suggestions"in a&&(a.suggestions=r(a.suggestions)),"actions"in a&&(a.actions=c(a.actions)),"location"in a&&(a.location=i(a.location)),new m(a)}}class F{constructor(t={}){s(this,"start");s(this,"end");s(this,"unit");"start"in t||(this.start=0),"end"in t||(this.end=0),"unit"in t||(this.unit=""),Object.assign(this,t)}static createFrom(t={}){let r=typeof t=="string"?JSON.parse(t):t;return new F(r)}}const tn=o.Array(o.Any),nn=g.createFrom,rn=o.Array(nn),on=F.createFrom,cn=o.Nullable(on);class D{constructor(t={}){s(this,"type");s(this,"data");s(this,"error");"type"in t||(this.type=""),Object.assign(this,t)}static createFrom(t={}){const r=un,c=an;let i=typeof t=="string"?JSON.parse(t):t;return"data"in i&&(i.data=r(i.data)),"error"in i&&(i.error=c(i.error)),new D(i)}}class A{constructor(t={}){s(this,"sequence");s(this,"event");s(this,"terminal");"sequence"in t||(this.sequence=0),"event"in t||(this.event=new D),"terminal"in t||(this.terminal=!1),Object.assign(this,t)}static createFrom(t={}){const r=yn;let c=typeof t=="string"?JSON.parse(t):t;return"event"in c&&(c.event=r(c.event)),new A(c)}}class b{constructor(t={}){s(this,"connection");s(this,"started");s(this,"resources");s(this,"resourceCounts");s(this,"totalResources");s(this,"syncedCount");s(this,"errorCount");s(this,"lastSyncTime");"connection"in t||(this.connection=new u.Connection),"started"in t||(this.started=!1),"resources"in t||(this.resources={}),"resourceCounts"in t||(this.resourceCounts={}),"totalResources"in t||(this.totalResources=0),"syncedCount"in t||(this.syncedCount=0),"errorCount"in t||(this.errorCount=0),Object.assign(this,t)}static createFrom(t={}){const r=ln,c=$n,i=pn;let a=typeof t=="string"?JSON.parse(t):t;return"connection"in a&&(a.connection=r(a.connection)),"resources"in a&&(a.resources=c(a.resources)),"resourceCounts"in a&&(a.resourceCounts=i(a.resourceCounts)),new b(a)}}const un=o.Map(o.Any,o.Any),sn=m.createFrom,an=o.Nullable(sn),yn=D.createFrom,ln=u.Connection.createFrom,$n=o.Map(o.Any,o.Any),pn=o.Map(o.Any,o.Any);function fn(e,t){return n.ByID(4065522324,e,t)}function H(e){return n.ByID(2393377246,e).then(t=>On(t))}function z(e){return n.ByID(1090099505,e)}function hn(e,t){return n.ByID(1688967279,e,t).then(r=>pe(r))}function U(e,t,r,c){return n.ByID(1613386605,e,t,r,c).then(i=>Mn(i))}function W(e,t,r,c){return n.ByID(1477526970,e,t,r,c).then(i=>jn(i))}function Dn(e,t,r){return n.ByID(1338477906,e,t,r)}function V(e,t,r,c,i){return n.ByID(1844283666,e,t,r,c,i).then(a=>zn(a))}function In(e,t,r,c){return n.ByID(4148812394,e,t,r,c).then(i=>Wn(i))}function E(e,t,r,c){return n.ByID(194970279,e,t,r,c).then(i=>En(i))}function q(e,t,r){return n.ByID(419011114,e,t,r).then(c=>Jn(c))}function J(){return n.ByID(4153677080).then(e=>kn(e))}function Q(e,t){return n.ByID(950535743,e,t).then(r=>I(r))}function x(e,t){return n.ByID(537508515,e,t).then(r=>fe(r))}function k(e,t){return n.ByID(1394342402,e,t).then(r=>Xn(r))}function Bn(e,t,r){return n.ByID(1947262600,e,t,r).then(c=>Zn(c))}function Tn(e,t,r,c){return n.ByID(1644192689,e,t,r,c).then(i=>tr(i))}function Sn(e,t){return n.ByID(2699561690,e,t).then(r=>rr(r))}function dn(e,t){return n.ByID(1474609809,e,t).then(r=>cr(r))}function gn(e,t){return n.ByID(4077050094,e,t).then(r=>ir(r))}function mn(e,t,r,c,i,a){return n.ByID(3171791798,e,t,r,c,i,a).then(y=>sr(y))}function Fn(e,t){return n.ByID(114848330,e,t).then(r=>he(r))}function K(e,t){return n.ByID(4290498491,e,t).then(r=>ar(r))}function An(e,t,r){return n.ByID(137675652,e,t,r)}function X(e,t){return n.ByID(2078766795,e,t).then(r=>yr(r))}function Y(e,t){return n.ByID(3311395752,e,t).then(r=>lr(r))}function Z(e,t){return n.ByID(42345827,e,t).then(r=>pr(r))}function bn(e){return n.ByID(854008408,e)}function Gn(e,t){return n.ByID(3547410887,e,t)}function Pn(e,t,r){return n.ByID(3516169863,e,t,r)}function ee(e,t,r,c){return n.ByID(3093409425,e,t,r,c).then(i=>hr(i))}function te(){return n.ByID(1598984489).then(e=>Dr(e))}function ne(e){return n.ByID(1775572154,e).then(t=>G(t))}function Cn(){return n.ByID(3217612415).then(e=>fe(e))}function Rn(e){return n.ByID(2037329938,e).then(t=>G(t))}function re(e,t){return n.ByID(421198049,e,t)}function vn(e,t,r,c,i){return n.ByID(3987850310,e,t,r,c,i).then(a=>Br(a))}function _n(e,t,r){return n.ByID(555702059,e,t,r)}function oe(e,t){return n.ByID(3276991559,e,t).then(r=>pe(r))}function ce(e,t){return n.ByID(3389223006,e,t)}function ie(e,t){return n.ByID(794258089,e,t).then(r=>I(r))}function ue(e,t){return n.ByID(1661153284,e,t)}function wn(e,t,r){return n.ByID(3981374696,e,t,r)}function se(e,t,r,c,i){return n.ByID(2990116431,e,t,r,c,i)}function ae(e,t,r){return n.ByID(2856546527,e,t,r)}function ye(e,t,r){return n.ByID(3710015102,e,t,r)}function le(e,t,r,c){return n.ByID(2408192164,e,t,r,c).then(i=>Sr(i))}function $e(e,t){return n.ByID(2131988692,e,t).then(r=>I(r))}const On=A.createFrom,pe=u.ConnectionStatus.createFrom,Ln=u.CreateResult.createFrom,Mn=o.Nullable(Ln),Nn=u.DeleteResult.createFrom,jn=o.Nullable(Nn),Hn=u.ActionResult.createFrom,zn=o.Nullable(Hn),Un=u.FindResult.createFrom,Wn=o.Nullable(Un),Vn=u.GetResult.createFrom,En=o.Nullable(Vn),qn=u.ActionDescriptor.createFrom,Jn=o.Array(qn),Qn=b.createFrom,xn=o.Array(Qn),kn=o.Map(o.Any,xn),I=u.Connection.createFrom,fe=o.Array(o.Any),Kn=u.EditorSchema.createFrom,Xn=o.Array(Kn),Yn=u.FilterField.createFrom,Zn=o.Array(Yn),er=u.ResourceHealth.createFrom,tr=o.Nullable(er),nr=u.RelationshipDescriptor.createFrom,rr=o.Array(nr),or=u.ResourceCapabilities.createFrom,cr=o.Nullable(or),ir=u.ResourceDefinition.createFrom,ur=u.ResourceEvent.createFrom,sr=o.Array(ur),he=u.ResourceGroup.createFrom,ar=o.Map(o.Any,he),De=u.ResourceMeta.createFrom,yr=o.Nullable(De),lr=o.Map(o.Any,De),$r=u.WatchConnectionSummary.createFrom,pr=o.Nullable($r),fr=u.ListResult.createFrom,hr=o.Nullable(fr),G=o.Array(I),Dr=o.Map(o.Any,G),Ir=u.ResolvedRelationship.createFrom,Br=o.Array(Ir),Tr=u.UpdateResult.createFrom,Sr=o.Nullable(Tr),dr=Object.freeze(Object.defineProperty({__proto__:null,AddConnection:fn,AttachStreamAction:H,CancelStreamAction:z,CheckConnection:hn,Create:U,Delete:W,EnsureResourceWatch:Dn,ExecuteAction:V,Find:In,Get:E,GetActions:q,GetAllConnectionStates:J,GetConnection:Q,GetConnectionNamespaces:x,GetEditorSchemas:k,GetFilterFields:Bn,GetHealth:Tn,GetRelationships:Sn,GetResourceCapabilities:dn,GetResourceDefinition:gn,GetResourceEvents:mn,GetResourceGroup:Fn,GetResourceGroups:K,GetResourceSchema:An,GetResourceType:X,GetResourceTypes:Y,GetWatchState:Z,HasPlugin:bn,HasResourceType:Gn,IsResourceWatchRunning:Pn,List:ee,ListAllConnections:te,ListConnections:ne,ListPlugins:Cn,LoadConnections:Rn,RemoveConnection:re,ResolveRelationships:vn,RestartResourceWatch:_n,StartConnection:oe,StartConnectionWatch:ce,StopConnection:ie,StopConnectionWatch:ue,StopResourceWatch:wn,StreamAction:se,SubscribeResource:ae,UnsubscribeResource:ye,Update:le,UpdateConnection:$e},Symbol.toStringTag,{value:"Module"}));function gr(e,t){return n.ByID(3653639550,e,t)}function Ie(e,t){return n.ByID(851823419,e,t)}function mr(e){return n.ByID(2991415449,e).then(t=>Fr(t))}function Be(e,t,r){return n.ByID(2695679023,e,t,r)}const Fr=o.Array(o.Any),Ar=Object.freeze(Object.defineProperty({__proto__:null,Delete:gr,Get:Ie,Keys:mr,Set:Be},Symbol.toStringTag,{value:"Module"}));function br(e){return n.ByID(93318075,e).then(t=>(t[0]=p(t[0]),t[1]=o.ByteSlice(t[1]),t))}function Gr(e){return n.ByID(1353297556,e)}function Te(e,t,r){return n.ByID(608251756,e,t,r).then(c=>p(c))}function Pr(e){return n.ByID(4182196712,e).then(t=>p(t))}function Cr(e){return n.ByID(3993344525,e).then(t=>p(t))}function Rr(e,t){return n.ByID(1779192716,e,t).then(r=>zr(r))}function vr(){return n.ByID(4033362541).then(e=>Ur(e))}function _r(e){return n.ByID(2619212338,e).then(t=>de(t))}function wr(e){return n.ByID(1371268636,e).then(t=>p(t))}function Or(e){return n.ByID(3881019319,e)}function Lr(){return n.ByID(3006426324).then(e=>Wr(e))}function Mr(){return n.ByID(265791345).then(e=>Vr(e))}function Nr(e,t,r){return n.ByID(1492965384,e,t,r)}function jr(e,t){return n.ByID(486465741,e,t)}const Hr=u.Session.createFrom,p=o.Nullable(Hr),Se=u.Handler.createFrom,zr=o.Nullable(Se),de=o.Map(o.Any,Se),Ur=o.Map(o.Any,de),Wr=o.Array(o.Any),Vr=o.Array(p),Er=Object.freeze(Object.defineProperty({__proto__:null,AttachSession:br,CloseSession:Gr,CreateSession:Te,CreateTerminal:Pr,DetachSession:Cr,GetHandler:Rr,GetHandlers:vr,GetPluginHandlers:_r,GetSession:wr,HasPlugin:Or,ListPlugins:Lr,ListSessions:Mr,ResizeSession:Nr,WriteSession:jr},Symbol.toStringTag,{value:"Module"}));function ge(e){return n.ByID(2776241946,e)}function me(e,t,r){return n.ByID(1762441314,e,t,r).then(c=>B(c))}function qr(e){return n.ByID(1474987050,e).then(t=>B(t))}function Jr(e){return n.ByID(3156347865,e).then(t=>eo(t))}function Qr(e){return n.ByID(1444002509,e)}function xr(){return n.ByID(3104582886).then(e=>to(e))}function kr(){return n.ByID(2249742267).then(e=>no(e))}function Kr(e,t){return n.ByID(1212190993,e,t)}function Xr(e,t){return n.ByID(2177127885,e,t).then(r=>B(r))}const Yr=u.LogSession.createFrom,B=o.Nullable(Yr),Zr=u.Handler$1.createFrom,eo=o.Array(Zr),to=o.Array(o.Any),no=o.Array(B),ro=Object.freeze(Object.defineProperty({__proto__:null,CloseSession:ge,CreateSession:me,GetSession:qr,GetSupportedResources:Jr,HasPlugin:Qr,ListPlugins:xr,ListSessions:kr,SendCommand:Kr,UpdateSessionOptions:Xr},Symbol.toStringTag,{value:"Module"}));class P{constructor(t={}){s(this,"plugin_id");s(this,"provider_id");s(this,"name");s(this,"icon");s(this,"description");s(this,"handlers");"plugin_id"in t||(this.plugin_id=""),"provider_id"in t||(this.provider_id=""),"name"in t||(this.name=""),"icon"in t||(this.icon=""),"description"in t||(this.description=""),"handlers"in t||(this.handlers=[]),Object.assign(this,t)}static createFrom(t={}){const r=co;let c=typeof t=="string"?JSON.parse(t):t;return"handlers"in c&&(c.handlers=r(c.handlers)),new P(c)}}const oo=u.Handler$2.createFrom,co=o.Array(oo);function Fe(){return n.ByID(3919346639).then(e=>Ce(e))}function Ae(e){return n.ByID(3953821778,e).then(t=>Ce(t))}function io(e){return n.ByID(1815388456,e)}function uo(){return n.ByID(2730149903).then(e=>yo(e))}function so(e,t,r){return n.ByID(3947209283,e,t,r).then(c=>Re(c))}function be(e,t,r,c,i,a,y,$,Ve,Ee){return n.ByID(2480040278,e,t,r,c,i,a,y,$,Ve,Ee).then(qe=>$o(qe))}function Ge(e,t,r){return n.ByID(3738888803,e,t,r)}function Pe(e){return n.ByID(3994236150,e)}const ao=P.createFrom,Ce=o.Array(ao),yo=o.Array(o.Any),lo=u.QueryResponse.createFrom,Re=o.Nullable(lo),$o=o.Map(o.Any,Re),po=Object.freeze(Object.defineProperty({__proto__:null,GetProviders:Fe,GetProvidersForResource:Ae,HasPlugin:io,ListPlugins:uo,Query:so,QueryAll:be,Subscribe:Ge,Unsubscribe:Pe},Symbol.toStringTag,{value:"Module"}));function ve(e){return n.ByID(182596922,e).then(t=>T(t))}function _e(e,t,r){return n.ByID(981100722,e,t,r).then(c=>C(c))}function fo(e){return n.ByID(2157304970,e).then(t=>T(t))}function ho(e){return n.ByID(650882,e).then(t=>Le(t))}function Do(e){return n.ByID(3624690437,e)}function we(){return n.ByID(2195697754).then(e=>C(e))}function Io(){return n.ByID(167463150).then(e=>Le(e))}function Bo(e,t){return n.ByID(2090415403,e,t).then(r=>C(r))}function Oe(e,t,r){return n.ByID(780445954,e,t,r).then(c=>T(c))}const To=u.PortForwardSession.createFrom,T=o.Nullable(To),C=o.Array(T),Le=o.Array(o.Any),So=Object.freeze(Object.defineProperty({__proto__:null,ClosePortForwardSession:ve,FindPortForwardSessions:_e,GetPortForwardSession:fo,GetSupportedPortForwardTargets:ho,HasPlugin:Do,ListAllPortForwardSessions:we,ListPlugins:Io,ListPortForwardSessions:Bo,StartResourcePortForwardingSession:Oe},Symbol.toStringTag,{value:"Module"}));function go(e){return n.ByID(2106300110,e).then(t=>Fo(t))}function Me(e){return n.ByID(765209827,e).then(t=>Ao(t))}function mo(e){return n.ByID(2355436169,e).then(t=>je(t))}const Ne=u.ResourceComponent.createFrom,je=o.Array(Ne),Fo=o.Map(o.Any,je),Ao=o.Nullable(Ne),bo=Object.freeze(Object.defineProperty({__proto__:null,GetPluginComponents:go,GetResourceAreaComponent:Me,GetResourceComponents:mo},Symbol.toStringTag,{value:"Module"}));function He(e,t,r,c,i,a){return n.ByID(3749557463,e,t,r,c,i,a).then(y=>Co(y))}function ze(e,t,r,c,i,a,y){return n.ByID(3912521777,e,t,r,c,i,a,y).then($=>We($))}function Go(e,t,r,c,i,a,y){return n.ByID(1916045973,e,t,r,c,i,a,y).then($=>vo($))}function Ue(e,t,r,c,i,a,y){return n.ByID(210990208,e,t,r,c,i,a,y).then($=>wo($))}const Po=u.DependencyTree.createFrom,Co=o.Nullable(Po),Ro=u.GraphEdge.createFrom,We=o.Array(Ro),vo=o.Array(We),_o=u.Subgraph.createFrom,wo=o.Nullable(_o),Oo=Object.freeze(Object.defineProperty({__proto__:null,GetDependencyTree:He,GetRelated:ze,GetRelationshipChain:Go,GetSubgraph:Ue},Symbol.toStringTag,{value:"Module"}));exports.AttachStreamAction=H;exports.CancelStreamAction=z;exports.ClosePortForwardSession=ve;exports.CloseSession=ge;exports.Create=U;exports.CreateSession=Te;exports.CreateSession$1=me;exports.Delete=W;exports.ExecuteAction=V;exports.FindPortForwardSessions=_e;exports.Get=Ie;exports.Get$1=E;exports.GetActions=q;exports.GetAllConnectionStates=J;exports.GetConnection=Q;exports.GetConnectionNamespaces=x;exports.GetDependencyTree=He;exports.GetEditorSchemas=k;exports.GetPluginMeta=w;exports.GetProviders=Fe;exports.GetProvidersForResource=Ae;exports.GetRelated=ze;exports.GetResourceAreaComponent=Me;exports.GetResourceGroups=K;exports.GetResourceType=X;exports.GetResourceTypes=Y;exports.GetSubgraph=Ue;exports.GetWatchState=Z;exports.List=ee;exports.ListAllConnections=te;exports.ListAllPortForwardSessions=we;exports.ListConnections=ne;exports.PluginValues=R;exports.QueryAll=be;exports.RemoveConnection=re;exports.RetryFailedPlugin=O;exports.Set=Be;exports.StartConnection=oe;exports.StartConnectionWatch=ce;exports.StartResourcePortForwardingSession=Oe;exports.StopConnection=ie;exports.StopConnectionWatch=ue;exports.StreamAction=se;exports.Subscribe=Ge;exports.SubscribeResource=ae;exports.Unsubscribe=Pe;exports.UnsubscribeResource=ye;exports.Update=le;exports.UpdateConnection=$e;exports.Values=N;exports.graphservice=Oo;exports.servicewrapper=Er;exports.servicewrapper$1=So;exports.servicewrapper$2=vt;exports.servicewrapper$3=dr;exports.servicewrapper$4=rt;exports.servicewrapper$5=en;exports.servicewrapper$6=bo;exports.servicewrapper$7=ro;exports.servicewrapper$8=po;exports.servicewrapper$9=Ar;
|
|
@@ -46,9 +46,10 @@ export declare function applyBatch(oldData: any, events: ResourceEvent[], idAcce
|
|
|
46
46
|
* window (default 500ms) to batch the initial ADD flood into 1-2 flushes.
|
|
47
47
|
* Satisfies REQ-BATCH-2.
|
|
48
48
|
*
|
|
49
|
-
* **Mode 2 — Live Updates (all other states):**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
49
|
+
* **Mode 2 — Live Updates (all other states):** Races `requestAnimationFrame`
|
|
50
|
+
* against the same bounded window, retaining next-frame batching while allowing
|
|
51
|
+
* already-delivered data to progress when painting is withheld but timers run.
|
|
52
|
+
* This does not promise progress while the entire event loop is frozen.
|
|
52
53
|
*
|
|
53
54
|
* Mode transitions happen automatically when `watchState` changes.
|
|
54
55
|
* Pending timers flush normally; subsequent events use the new scheduling.
|
|
@@ -10,12 +10,9 @@ type StartStreamActionParams = {
|
|
|
10
10
|
label: string;
|
|
11
11
|
params?: Record<string, unknown>;
|
|
12
12
|
};
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
* automatically subscribing to Wails events and tracking the operation
|
|
16
|
-
* in the OperationsContext.
|
|
17
|
-
*/
|
|
18
|
-
export declare const useStreamAction: ({ pluginID: explicitPluginID, connectionID, resourceKey, }: UseStreamActionOptions) => {
|
|
13
|
+
/** Host-ready open, listener-first attachment and owning cleanup of current actions. */
|
|
14
|
+
export declare const useStreamAction: ({ pluginID: explicitPluginID, connectionID, resourceKey }: UseStreamActionOptions) => {
|
|
19
15
|
startStreamAction: ({ actionID, id, namespace, label, params }: StartStreamActionParams) => Promise<string>;
|
|
16
|
+
cancelStreamAction: (handle: string) => void;
|
|
20
17
|
};
|
|
21
18
|
export {};
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`);return{message:e||(t.title!=="Error"?t.title:"Operation failed"),status:"error",details:n,actions:(i=t.actions)==null?void 0:i.map(ve)}}function j(t,e,n){if(le(e))return;const r=$(e);t(Re(r,n))}function N(t,e){return n=>{if(le(n))return;const r=$(n);t(Re(r,r.title!=="Error"?r.title:e))}}function ot(t){const{children:e,pluginId:n}=t,[r,s]=d.useState({}),[i,o]=d.useState(new D.PluginMeta),[a,c]=d.useState(!1),[l,u]=d.useState(null);console.debug("[PluginContextProvider] render",{pluginId:n,metaLoaded:a,metaError:!!l});const y=()=>{n===void 0||n===""||(console.debug(`[PluginContextProvider] fetching settings for "${n}"`),h.PluginValues(n).then(f=>{console.debug(`[PluginContextProvider] settings loaded for "${n}"`,Object.keys(f)),s(f)}).catch(f=>{const g=$(f);console.error(`[PluginContextProvider] error fetching settings for "${n}":`,g.detail)}))},p=()=>{if(n===void 0||n===""){console.debug("[PluginContextProvider] skipping meta fetch — empty pluginId");return}console.debug(`[PluginContextProvider] fetching meta for "${n}"`),u(null),h.GetPluginMeta(n).then(f=>{console.debug(`[PluginContextProvider] meta loaded for "${n}"`,{name:f==null?void 0:f.name,version:f==null?void 0:f.version}),o(f),c(!0)}).catch(f=>{const g=$(f);console.error(`[PluginContextProvider] error fetching meta for "${n}":`,g.detail),u(g.detail),c(!1)})};return d.useEffect(()=>{console.debug(`[PluginContextProvider] useEffect — pluginId changed to "${n}"`),y(),p()},[n]),l?A.jsx("div",{style:{display:"flex",flex:1,alignItems:"center",justifyContent:"center",padding:24},children:A.jsxs("div",{style:{maxWidth:480,width:"100%",border:"1px solid #7F1D1D",borderRadius:8,backgroundColor:"#1C1917",padding:20,fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'},children:[A.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:12},children:[A.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"#EF4444",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[A.jsx("circle",{cx:"12",cy:"12",r:"10"}),A.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),A.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),A.jsx("span",{style:{fontSize:14,fontWeight:600,color:"#FECACA"},children:"Plugin failed to load"})]}),A.jsx("p",{style:{fontSize:13,color:"#A1A1AA",margin:"0 0 16px"},children:l}),A.jsx("button",{onClick:()=>p(),style:{background:"transparent",color:"#F87171",border:"1px solid #7F1D1D",borderRadius:6,padding:"6px 14px",fontSize:13,fontWeight:500,cursor:"pointer"},children:"Retry"})]})}):a?A.jsx(X.Provider,{value:{pluginId:n,settings:r,meta:i},children:e}):A.jsxs("div",{style:{display:"flex",flex:1,alignItems:"center",justifyContent:"center"},children:[A.jsx("div",{style:{width:24,height:24,border:"2px solid #3F3F46",borderTopColor:"#A1A1AA",borderRadius:"50%",animation:"plugin-spin 0.8s linear infinite"}}),A.jsx("style",{children:"@keyframes plugin-spin { to { transform: rotate(360deg); } }"})]})}function V(){const t=d.useContext(X);if(!t)throw new Error("usePluginContext must be used within a PluginContextProvider");return t}function it(){return V().settings}const de=d.createContext(void 0),at=({children:t})=>{const[e,n]=d.useState({}),r=()=>{h.Values().then(i=>{console.log("Fetched settings:",i),n(i)}).catch(i=>{console.error("Error fetching settings:",i)})};d.useEffect(()=>{r()},[]);const s=()=>{r()};return A.jsx(de.Provider,{value:{settings:e,reload:s},children:t})},xe={height:32,focused:0,tabs:[],createTab:()=>{},createTabs:()=>{},updateTab:()=>{},focusTab:()=>{},reorderTab:()=>{},closeTab:()=>{},closeTabs:()=>{},resizeDrawer:()=>{},closeDrawer:()=>{},fullscreenDrawer:()=>{}},Fe=d.createContext(xe),Pe=d.createContext(void 0),Oe=d.createContext(void 0),fe=d.createContext(void 0),ct=3e4,ut=({children:t})=>{const[e,n]=d.useState([]),r=d.useCallback(a=>{n(c=>[a,...c])},[]),s=d.useCallback((a,c)=>{n(l=>l.map(u=>u.id===a?{...u,...c}:u))},[]),i=d.useCallback(a=>{n(c=>c.filter(l=>l.id!==a))},[]);d.useEffect(()=>{const a=[];for(const c of e)if(c.status==="completed"||c.status==="error"){const l=Date.now()-(c.completedAt??c.startedAt),u=Math.max(0,ct-l);a.push(setTimeout(()=>i(c.id),u))}return()=>a.forEach(clearTimeout)},[e,i]);const o=d.useMemo(()=>({operations:e,addOperation:r,updateOperation:s,removeOperation:i}),[e,r,s,i]);return A.jsx(fe.Provider,{value:o,children:t})};var ae=function(t,e){return ae=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(n[s]=r[s])},ae(t,e)};function lt(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");ae(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}var se="Invariant Violation",Ce=Object.setPrototypeOf,dt=Ce===void 0?function(t,e){return t.__proto__=e,t}:Ce,ft=function(t){lt(e,t);function e(n){n===void 0&&(n=se);var r=t.call(this,typeof n=="number"?se+": "+n+" (see https://github.com/apollographql/invariant-packages)":n)||this;return r.framesToPop=1,r.name=se,dt(r,e.prototype),r}return e}(Error);function ce(t,e){if(!t)throw new ft(e)}var Ie=["debug","log","warn","error","silent"],pt=Ie.indexOf("log");function z(t){return function(){if(Ie.indexOf(t)>=pt){var e=console[t]||console.log;return e.apply(console,arguments)}}}(function(t){t.debug=z("debug"),t.log=z("log"),t.warn=z("warn"),t.error=z("error")})(ce||(ce={}));const Te=d.createContext(void 0),Ae=()=>d.useContext(Te);function yt(t){const e=Ae(),n=d.useRef(null),r=e==null?void 0:e.getExtensionPoint(t),s=d.useCallback(o=>{const a=[];return e&&a.push(e.subscribe(o)),r&&a.push(r.subscribe(o)),()=>{for(const c of a)c()}},[e,t,r]),i=d.useCallback(()=>{const o=e==null?void 0:e.getExtensionPoint(t);if(!o){if(n.current&&n.current.store===void 0)return n.current.sentinel;const l={};return n.current={store:void 0,version:-1,sentinel:l},l}const a=n.current;if(a&&a.store===o&&a.version===o.version)return a.sentinel;const c={};return n.current={store:o,version:o.version,sentinel:c},c},[e,t]);return d.useSyncExternalStore(s,i),e==null?void 0:e.getExtensionPoint(t)}const gt=({registry:t,children:e})=>{const n=d.useRef(t);return ce(n.current===t,"You can't change the extension registry after it has been rendered"),A.jsx(Te.Provider,{value:n.current,children:e})},oe=t=>{if(!t||typeof t!="string")throw new TypeError(`extensionName is required to be a string and can't be: "${t}" (${typeof t})`);return t.trim()};class De{constructor(e){M(this,"id");M(this,"mode");M(this,"_pluginId");M(this,"_version",0);M(this,"_contributions",new Map);M(this,"_lookupCache",new Map);M(this,"_matcher");M(this,"_select");M(this,"_listeners",new Set);this.id=e.id,this.mode=e.mode??"multiple",this._pluginId=e.pluginId,this._matcher=e.matcher,this._select=e.select}get pluginId(){return this._pluginId}get version(){return this._version}register(e){if(this._contributions.has(e.id))throw new Error(`Contribution with id "${e.id}" already exists in extension point "${this.id}"`);this._contributions.set(e.id,e),this._invalidateCache(),this._notify()}unregister(e){this._contributions.delete(e)&&(this._invalidateCache(),this._notify())}provide(e){return this._getMatched(e).map(r=>r.value)}list(e){return this._getMatched(e)}listAll(){return Array.from(this._contributions.values())}subscribe(e){return this._listeners.add(e),()=>{this._listeners.delete(e)}}removeContributionsByPlugin(e){let n=!1;for(const[r,s]of this._contributions)s.plugin===e&&(this._contributions.delete(r),n=!0);n&&(this._invalidateCache(),this._notify())}_getMatched(e){const n=this._getCacheKey(e);if(n!=null){const s=this._lookupCache.get(n);if(s){const i=s.map(o=>this._contributions.get(o)).filter(o=>o!=null);return this._applyMode(i,e)}}let r=this._sortDeterministic(Array.from(this._contributions.values()));return this._matcher&&e!==void 0&&(r=r.filter(s=>this._matcher(s,e))),n!=null&&this._lookupCache.set(n,r.map(s=>s.id)),this._applyMode(r,e)}_applyMode(e,n){if(this.mode==="single"){if(this._select){const r=this._select(e,n);return r?[r]:[]}return e.length>0?[e[0]]:[]}return e}_sortDeterministic(e){return[...e].sort((n,r)=>{const s=n.plugin.localeCompare(r.plugin);return s!==0?s:n.id.localeCompare(r.id)})}_getCacheKey(e){if(e!=null&&typeof e=="object"&&"getCacheKey"in e){const n=e.getCacheKey;if(typeof n=="function")return n()}}_invalidateCache(){this._lookupCache.clear()}_notify(){this._version++;for(const e of this._listeners)e()}}class ht{constructor(e){M(this,"_stores",new Map);M(this,"_storeUnsubs",new Map);M(this,"_listeners",new Set);if(e!=null&&e.initialStores)for(const n of e.initialStores)this.addExtensionPoint(n)}addExtensionPoint(e){const n=oe(e.id);if(this._stores.has(n)){const s=this._stores.get(n);throw new Error(`Extension point "${n}" already exists (owned by "${s.pluginId??"unknown"}")`)}const r=new De({...e,id:n});this._stores.set(n,r),this._storeUnsubs.set(n,r.subscribe(()=>this._notify())),this._notify()}getExtensionPoint(e){const n=oe(e);return this._stores.get(n)}hasExtensionPoint(e){const n=oe(e);return this._stores.has(n)}listExtensionPoints(){return Array.from(this._stores.keys())}removeExtensionPoints(e){var r;let n=!1;for(const[s,i]of this._stores)i.pluginId===e&&((r=this._storeUnsubs.get(s))==null||r(),this._storeUnsubs.delete(s),this._stores.delete(s),n=!0);n&&this._notify()}removeContributions(e){for(const n of this._stores.values())n.removeContributionsByPlugin(e);this._notify()}subscribe(e){return this._listeners.add(e),()=>{this._listeners.delete(e)}}_notify(){for(const e of this._listeners)e()}}const Me=d.createContext(void 0),mt={default:"info",info:"info",success:"success",warning:"warning",error:"danger"},St=({children:t})=>{const{toast:e}=nt.useToast(),[n,r]=d.useState([]),s=o=>{r(a=>[...a,o])},i=(o,a,c)=>{const l=typeof o=="object";let u="",y="info",p,f=5e3,g;if(l){if(u=o.message,o.showOnce){if(n.includes(u))return;s(u)}y=o.status,p=o.details,f=o.autoHideDuration??5e3,g=o.actions}else u=o,y=a,p=c;e(p??u,{severity:mt[y]??"info",title:p?u:void 0,duration:f,action:g==null?void 0:g[0]})};return A.jsx(Me.Provider,{value:{showSnackbar:i},children:t})},U=()=>{const t=d.useContext(Me);if(t===void 0)throw new Error("useCustomSnackbar must be used within a CustomSnackbarProvider");return t};function I(t){const e=d.useContext(X),n=(e==null?void 0:e.pluginId)??t;if(!n)throw new Error("pluginID must be provided either via PluginContext or as an explicit parameter");return n}const Ct=({pluginID:t,connectionID:e})=>{const n=I(t),r=m.useQueryClient(),{showSnackbar:s}=U(),i=[n,"connection","detail",e],{mutateAsync:o}=m.useMutation({mutationFn:async()=>h.StartConnection(n,e),onSuccess(y){r.setQueryData(i,y),r.invalidateQueries({queryKey:["EDITOR_SCHEMAS",n,e]})},onError:N(s,"Failed to start connection")}),{mutateAsync:a}=m.useMutation({mutationFn:async()=>h.StopConnection(n,e),onSuccess(y){r.setQueryData(i,y)},onError:N(s,"Failed to stop connection")}),{mutateAsync:c}=m.useMutation({mutationFn:async y=>h.UpdateConnection(n,y),onSuccess(y,{name:p}){s({message:`Connection ${p} successfully updated`,status:"success"}),r.setQueryData(i,y),r.setQueriesData({queryKey:[n,"connection","list"]},f=>f==null?void 0:f.map(g=>g.id===e?y:g))},onError:N(s,"Failed to update connection")}),{mutateAsync:l}=m.useMutation({mutationFn:async()=>h.RemoveConnection(n,e),onSuccess(){s({message:"Connection successfully removed",status:"success"}),r.setQueryData(i,void 0),r.setQueriesData({queryKey:[n,"connection","list"]},y=>y==null?void 0:y.filter(p=>p.id!==e))},onError:N(s,"Failed to remove connection")});return{connection:m.useQuery({queryKey:i,queryFn:async()=>h.GetConnection(n,e)}),startConnection:o,stopConnection:a,updateConnection:c,deleteConnection:l}},Ne=t=>[t,"connection","list"],Et=({plugin:t})=>{const e=I(t),n=m.useQueryClient(),{showSnackbar:r}=U(),s=Ne(e),{mutateAsync:i}=m.useMutation({mutationFn:async l=>h.StartConnectionWatch(e,l.id),onError:N(r,"Failed to start connection watch")}),{mutateAsync:o}=m.useMutation({mutationFn:async l=>h.StopConnectionWatch(e,l.id),onError:N(r,"Failed to stop connection watch")}),a=d.useCallback(l=>{const u=l.data;console.log("got update to connections",u),n.setQueryData(s,u)},[n,s]);return d.useEffect(()=>{const l=T.On(`${e}/connection/sync`,a);return()=>{l()}},[e,a]),{connections:m.useQuery({queryKey:s,queryFn:async()=>{try{return await h.ListConnections(e)}catch(l){console.log(l),N(r,"Failed to load connections")(l)}return[]},staleTime:3e4,placeholderData:m.keepPreviousData}),startWatch:i,stopWatch:o}},_t=({pluginID:t,connectionID:e})=>{const n=I(t),r=[n,"connection","namespaces",e];return{namespaces:m.useQuery({queryKey:r,queryFn:async()=>h.GetConnectionNamespaces(n,e)})}},P=rt.withLegacyNames(D.WatchState,"WatchState");function ue(t){const e=Object.values(t.states),n=e.length;let r=0,s=0,i=0,o=0;for(const u of e)u===P.WatchStateSynced&&r++,(u===P.WatchStateError||u===P.WatchStateFailed)&&s++,u===P.WatchStateForbidden&&i++,u===P.WatchStateSkipped&&o++;const a=n-o,c=e.filter(u=>u===P.WatchStateSynced||u===P.WatchStateError||u===P.WatchStateStopped||u===P.WatchStateFailed||u===P.WatchStateForbidden).length,l=a>0?c/a:0;return{pluginID:t.pluginID,connectionID:t.connectionID,totalResources:n,watchedTotal:a,syncedCount:r,errorCount:s,forbiddenCount:i,skippedCount:o,doneCount:c,progress:l}}function Z(t){return t.watchedTotal>0&&t.doneCount>=t.watchedTotal}function ke(t){return t.some(e=>!Z(e))}function Le(t){const e=t.reduce((r,s)=>r+s.watchedTotal,0);return e===0?0:t.reduce((r,s)=>r+s.doneCount,0)/e}function pe(t){return`${t.pluginId}/${t.connection}`}function qe(t,e){const n=pe(e);t.has(n)||t.set(n,{states:{},pluginID:e.pluginId,connectionID:e.connection});const r=t.get(n);return r.states[e.resourceKey]=e.state,r}function wt(){const[t,e]=d.useState(new Set),[n,r]=d.useState({}),[s,i]=d.useState(new Map),o=d.useRef(new Map),[a,c]=d.useState(new Map);d.useEffect(()=>{const S=T.On("plugin/crash_recovery_failed",F=>{const b=F.data,_=b==null?void 0:b.pluginID;_&&c(v=>{const O=new Map(v);return O.set(_,b.error??"Crash recovery failed"),O})}),x=T.On("plugin/recovered",F=>{const b=F.data,_=b==null?void 0:b.pluginID;_&&c(v=>{if(!v.has(_))return v;const O=new Map(v);return O.delete(_),O})});return()=>{S(),x()}},[]),d.useEffect(()=>{h.GetAllConnectionStates().then(S=>{if(!S)return;const x={},F=new Set,b=new Map;for(const[_,v]of Object.entries(S))if(v){x[_]=v.map(O=>O.connection);for(const O of v){if(!O.started)continue;const L=`${_}/${O.connection.id}`;F.add(L);const k={pluginID:_,connectionID:O.connection.id,states:{}};if(O.resources)for(const[re,Ve]of Object.entries(O.resources))k.states[re]=Ve;o.current.set(L,k),b.set(L,ue(k))}}r(x),e(F),i(b)}).catch(()=>{})},[]),d.useEffect(()=>T.On("connection/status",x=>{const F=x.data,b=`${F.pluginID}/${F.connectionID}`;F.status==="DISCONNECTED"?(e(_=>{const v=new Set(_);return v.delete(b),v}),i(_=>{const v=new Map(_);return v.delete(b),v}),o.current.delete(b)):e(_=>{const v=new Set(_);return v.add(b),v}),h.ListAllConnections().then(_=>{if(!_)return;const v={};for(const[O,L]of Object.entries(_))L!=null&&(v[O]=L);r(v)}).catch(()=>{})}),[]);const l=d.useCallback(S=>{const x=S.data,F=pe(x);e(v=>{if(v.has(F))return v;const O=new Set(v);return O.add(F),O});const b=qe(o.current,x),_=ue(b);i(v=>{const O=new Map(v);return O.set(F,_),O})},[]);d.useEffect(()=>T.On("watch/STATE",l),[l]);const u=d.useCallback(async(S,x)=>{await h.StopConnection(S,x)},[]),y=d.useCallback(async(S,x)=>{await h.StartConnectionWatch(S,x)},[]),p=d.useCallback(async S=>{const x=a.get(S);c(F=>{if(!F.has(S))return F;const b=new Map(F);return b.delete(S),b});try{await h.RetryFailedPlugin(S)}catch(F){throw c(b=>{const _=new Map(b);return _.set(S,x??"Reload failed"),_}),F}},[a]),f=[];for(const S of t){const[x,F]=S.split("/",2),_=(n[x]??[]).find(re=>re.id===F),v=s.get(S),O=v!=null&&!Z(v),L=v!=null&&v.errorCount>0,k=a.get(x);f.push({pluginID:x,connectionID:F,name:(_==null?void 0:_.name)??F,avatar:(_==null?void 0:_.avatar)??"",isStarted:!0,sync:v,isSyncing:O,hasErrors:L||k!=null,pluginFailed:k!=null,pluginError:k})}const g=new Map;for(const S of f){const x=g.get(S.pluginID)??[];x.push(S),g.set(S.pluginID,x)}const w=Array.from(s.values()),R=f.filter(S=>S.isSyncing),C=f.filter(S=>S.hasErrors),E=f.filter(S=>S.pluginFailed);return{entries:f,grouped:g,connectedCount:f.length,syncingCount:R.length,errorCount:C.length,failedCount:E.length,hasSyncing:ke(w),aggregateProgress:Le(w),disconnect:u,retryWatch:y,retryPlugin:p}}function bt(t,e){return e===null?t===null:Array.isArray(e)?Array.isArray(t):typeof e=="object"?typeof t=="object"&&t!==null&&!Array.isArray(t):typeof t==typeof e}function vt(t,e,n){const r=I(t),s=m.useQueryClient(),i=[r,"data",e],o=m.useQuery({queryKey:i,queryFn:async()=>{const c=await h.Get(r,e);return c==null?n:bt(c,n)?c:(console.warn(`[usePluginData] stored value for "${e}" has unexpected type (expected ${Array.isArray(n)?"array":typeof n}, got ${Array.isArray(c)?"array":typeof c}). Using default.`),n)}}),a=m.useMutation({mutationFn:async c=>{await h.Set(r,e,c)},onMutate:async c=>{await s.cancelQueries({queryKey:i});const l=s.getQueryData(i);return s.setQueryData(i,c),{previous:l}},onError:(c,l,u)=>{(u==null?void 0:u.previous)!==void 0&&s.setQueryData(i,u.previous)},onSettled:()=>{s.invalidateQueries({queryKey:i})}});return{data:o.data??n,update:async c=>{await a.mutateAsync(c)},isLoading:o.isLoading}}const Rt=()=>{const t=d.useContext(Pe);if(!t)throw new Error("useRightDrawer must be used within a RightDrawerProvider");return t},ye=()=>{const t=d.useContext(Fe);if(t===void 0)throw new Error("useBottomDrawer must be used within a BottomDrawerProvider");return t},xt=({pluginID:t})=>{const e=I(t),{showSnackbar:n}=U(),{createTab:r,updateTab:s}=ye();return{createSession:m.useMutation({mutationFn:async({connectionID:o,icon:a,label:c,opts:l})=>{const u=`pending-${crypto.randomUUID()}`;r({id:u,title:c??"Connecting...",variant:"terminal",icon:a??"LuSquareTerminal",properties:{status:"connecting",pluginID:e,connectionID:o,opts:{...l}}});const y=D.SessionOptions.createFrom({command:["/bin/bash"],tty:!0,...l});try{const p=await h.CreateSession(e,o,y);if(!p)throw new Error("Failed to create session: null response");s({id:u},{id:p.id,title:c??`Session ${p.id.substring(0,8)}`,properties:{status:"connected",pluginID:e,connectionID:o,opts:{...l}}})}catch(p){const f=$(p);s({id:u},{properties:{status:"error",error:f.detail,pluginID:e,connectionID:o,opts:{...l}}}),j(n,p,"Failed to start session")}}}).mutateAsync}},Ft=({pluginID:t})=>{const e=I(t),{showSnackbar:n}=U(),{createTab:r}=ye(),s=m.useMutation({mutationFn:async({connectionID:o,resourceKey:a,resourceID:c,resourceData:l,icon:u,label:y,target:p,follow:f=!0,tailLines:g=1e3,params:w})=>{const R=D.CreateSessionOptions.createFrom({resource_key:a,resource_id:c,resource_data:l,options:D.LogSessionOptions.createFrom({target:p??"",follow:f,include_previous:!1,include_timestamps:!0,tail_lines:g,since_seconds:0,limit_bytes:0,include_source_events:!0,params:w??{}})}),C=await h.CreateSession$1(e,o,R);if(!C)throw new Error("Failed to create log session: null response");return r({id:C.id,title:y??`Logs ${C.id.substring(0,8)}`,variant:"logs",icon:u??"LuLogs"}),C},onError:N(n,"Failed to start log session")}),i=m.useMutation({mutationFn:async o=>{await h.CloseSession(o)},onError:N(n,"Failed to close log session")});return{createLogSession:s.mutateAsync,closeLogSession:i.mutateAsync}},Pt=()=>m.useQuery({queryKey:["metric","providers"],queryFn:h.GetProviders,staleTime:3e4}),Ue=t=>m.useQuery({queryKey:["metric","providers",t],queryFn:()=>h.GetProvidersForResource(t),enabled:!!t,staleTime:3e4}),Ot=t=>{var R,C;const{connectionID:e,resourceKey:n,resourceID:r,resourceNamespace:s="",resourceData:i={},metricIDs:o=[],shape:a=0,timeRange:c,refreshInterval:l=0,enabled:u=!0}=t,{data:y,isLoading:p}=Ue(n),f=y??[],g=c?Math.max(Math.floor((c.end.getTime()-c.start.getTime())/250),15e3)*1e6:0,w=m.useQuery({queryKey:["metric","query",e,n,r,s,o,a,(R=c==null?void 0:c.start)==null?void 0:R.getTime(),(C=c==null?void 0:c.end)==null?void 0:C.getTime()],queryFn:async()=>{const E=await h.QueryAll(e,n,r,s,i,o,a,((c==null?void 0:c.start)??new Date(0)).toISOString(),((c==null?void 0:c.end)??new Date(0)).toISOString(),g),S={};for(const[x,F]of Object.entries(E))F!=null&&(S[x]=F);return S},enabled:u&&!!e&&!!n&&(n.startsWith("cluster::")||!!r)&&f.length>0,refetchInterval:l>0?l:void 0,staleTime:5e3,placeholderData:m.keepPreviousData});return{data:w.data??void 0,providers:f,isLoading:p||w.isLoading,error:w.error,refetch:w.refetch}},It=t=>{const{pluginID:e,connectionID:n,resourceKey:r,resourceID:s,resourceNamespace:i="",resourceData:o={},metricIDs:a=[],interval:c=1e4,enabled:l=!0}=t,u=I(e),[y,p]=d.useState(null),[f,g]=d.useState(null),[w,R]=d.useState(!1),[C,E]=d.useState(null),S=d.useRef(null),x=d.useCallback(async()=>{if(!(!l||!u||!n||!r||!s))try{const b=await h.Subscribe(u,n,{resource_key:r,resource_id:s,resource_namespace:i,resource_data:o,metric_ids:a,interval:c*1e6});g(b),R(!0),E(null);const _=T.On(`core/metrics/data/${b}`,O=>{const L=O.data;try{const k=JSON.parse(L);k.results&&p(k.results)}catch(k){console.error("Failed to parse metric stream data:",k)}}),v=T.On(`core/metrics/error/${b}`,O=>{const L=O.data;try{const k=JSON.parse(L);E(k.error||"Unknown error")}catch{E("Failed to parse metric stream error")}});S.current=()=>{_(),v()}}catch(b){E(b instanceof Error?b.message:String(b))}},[u,n,r,s,i,a,c,l]),F=d.useCallback(async()=>{if(f)try{await h.Unsubscribe(f)}catch(b){console.error("Failed to unsubscribe:",b)}S.current&&(S.current(),S.current=null),g(null),R(!1)},[f]);return d.useEffect(()=>()=>{f&&h.Unsubscribe(f).catch(console.error),S.current&&S.current()},[f]),{data:y,subscriptionID:f,isStreaming:w,error:C,start:x,stop:F}},Q=["networker","portforward","all-sessions"];function Tt(){const{showSnackbar:t}=U(),e=m.useQueryClient(),n=m.useQuery({queryKey:[...Q],queryFn:async()=>h.ListAllPortForwardSessions().catch(i=>{if($(i).detail.includes("not found"))return[];throw i}),retry:!1});d.useEffect(()=>{const i=T.On("core/networker/portforward/created",()=>{e.invalidateQueries({queryKey:[...Q]})}),o=T.On("core/networker/portforward/closed",()=>{e.invalidateQueries({queryKey:[...Q]})});return()=>{i(),o()}},[e]);const r=n.data??[],s=m.useMutation({mutationFn:async i=>h.ClosePortForwardSession(i),onError:N(t,"Failed to close port forwarding session"),onSuccess:async()=>{await e.invalidateQueries({queryKey:[...Q]})}});return{sessions:n,activeSessions:r,closeSession:s.mutateAsync,openInBrowser:i=>T.OpenURL(`http://localhost:${i}`)}}function At({pluginID:t,connectionID:e,resourceID:n}){const r=I(t),s=["networker","portforward","sessions",r,e,n],{showSnackbar:i}=U(),o=m.useQueryClient(),a=m.useQuery({queryKey:s,queryFn:async()=>h.FindPortForwardSessions(r,e,D.FindPortForwardSessionRequest.createFrom({resource_id:n,connection_id:e})).catch(u=>{const y=$(u);return y.detail.includes("not found")?[]:(i({message:"Failed to fetch port forward sessions",status:"error",details:y.detail}),[])}),retry:!1}),c=m.useMutation({mutationFn:async({opts:u})=>{const y=D.PortForwardSessionOptions.createFrom({local_port:u.localPort||0,remote_port:u.remotePort,protocol:u.protocol||"TCP",connection_type:"RESOURCE",connection:{resource_data:u.resource,connection_id:e,plugin_id:r,resource_id:u.resourceId,resource_key:u.resourceKey},labels:u.labels??{},params:u.parameters??{}}),p=await h.StartResourcePortForwardingSession(r,e,y);if(!p)throw new Error("Failed to start port forwarding: null response");return u.openInBrowser&&T.OpenURL(`http://localhost:${p.local_port}`),p},onError:N(i,"Failed to start port forwarding session"),onSuccess:async()=>{await Promise.all([o.invalidateQueries({queryKey:s}),o.invalidateQueries({queryKey:[...Q]})])}}),l=m.useMutation({mutationFn:async({opts:u})=>h.ClosePortForwardSession(u.sessionID),onError:N(i,"Failed to close port forwarding session"),onSuccess:async()=>{await Promise.all([o.invalidateQueries({queryKey:s}),o.invalidateQueries({queryKey:[...Q]})])}});return{sessions:a,forward:c.mutateAsync,close:l.mutateAsync}}const Dt=()=>{const t=d.useContext(Oe);if(!t)throw new Error("useConfirmationModal must be used within a ConfirmationModalProvider");return t},Mt=({pluginID:t,connectionID:e,resourceKey:n,resourceID:r,namespace:s=""})=>{const i=I(t),o=m.useQueryClient(),{showSnackbar:a}=U(),c=["RESOURCE",i,e,n,r,s],{mutateAsync:l}=m.useMutation({mutationFn:async p=>h.Update(i,e,n,D.UpdateInput.createFrom({input:p.input,id:r,namespace:s})),onSuccess:async()=>{a(`Resource ${r} updated`,"success"),await o.invalidateQueries({queryKey:c})},onError:N(a,`Failed to update resource ${r}`)}),{mutateAsync:u}=m.useMutation({mutationFn:async(p={})=>h.Delete(i,e,n,D.DeleteInput.createFrom({id:r,namespace:s,gracePeriodSeconds:p.gracePeriodSeconds})),onSuccess:async()=>{a(`Resource ${r} deleted`,"success"),await o.invalidateQueries({queryKey:c})},onError:N(a,`Failed to delete resource ${r}`)});return{resource:m.useQuery({queryKey:c,queryFn:async()=>h.Get$1(i,e,n,D.GetInput.createFrom({id:r,namespace:s})),retry:!1}),update:l,remove:u}},Nt=t=>{const e=["component",t.plugin,t.resource,t.area];return{component:m.useQuery({queryKey:e,queryFn:async()=>h.GetResourceAreaComponent(t)})}},kt=({pluginID:t,connectionID:e})=>{const n=I(t),r=[n,"resource_groups","list"];return{groups:m.useQuery({queryKey:r,queryFn:async()=>h.GetResourceGroups(n,e),retry:!1})}},Lt=({pluginID:t,connectionID:e,searches:n})=>{const r=I(t),s=o=>[r,e,o.key,o.namespaces,"list"];return m.useQueries({queries:n.map(o=>({queryKey:s(o),queryFn:async()=>h.List(r,e,o.key,D.ListInput.createFrom({order:[{field:"name",descending:!1}],pagination:{page:1,pageSize:200},namespaces:o.namespaces})).then(a=>a?(console.log(a.result),a.result&&o.postFilter?Object.values(a.result).filter(o.postFilter):Object.values(a.result||{})):[]),retry:!1}))})},qt=({pluginID:t,resourceKey:e})=>{const n=I(t),r=[n,"resources",e];return{resourceType:m.useQuery({queryKey:r,queryFn:async()=>h.GetResourceType(n,e),retry:!1})}},Ut=({pluginID:t,connectionID:e})=>{const n=I(t),r=[n,"resources","list",e];return{types:m.useQuery({queryKey:r,queryFn:async()=>h.GetResourceTypes(n,e),retry:!1})}};var Y=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function $t(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Qt="Expected a function",$e="__lodash_hash_undefined__",jt="[object Function]",Wt="[object GeneratorFunction]",Gt="[object Symbol]",Kt=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Bt=/^\w*$/,Ht=/^\./,zt=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Yt=/[\\^$.*+?()[\]{}|]/g,Jt=/\\(\\)?/g,Zt=/^\[object .+?Constructor\]$/,Xt=typeof Y=="object"&&Y&&Y.Object===Object&&Y,Vt=typeof self=="object"&&self&&self.Object===Object&&self,ge=Xt||Vt||Function("return this")();function en(t,e){return t==null?void 0:t[e]}function tn(t){var e=!1;if(t!=null&&typeof t.toString!="function")try{e=!!(t+"")}catch{}return e}var nn=Array.prototype,rn=Function.prototype,Qe=Object.prototype,ie=ge["__core-js_shared__"],Ee=function(){var t=/[^.]+$/.exec(ie&&ie.keys&&ie.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(),je=rn.toString,he=Qe.hasOwnProperty,We=Qe.toString,sn=RegExp("^"+je.call(he).replace(Yt,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),_e=ge.Symbol,on=nn.splice,an=Ge(ge,"Map"),H=Ge(Object,"create"),we=_e?_e.prototype:void 0,be=we?we.toString:void 0;function W(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function cn(){this.__data__=H?H(null):{}}function un(t){return this.has(t)&&delete this.__data__[t]}function ln(t){var e=this.__data__;if(H){var n=e[t];return n===$e?void 0:n}return he.call(e,t)?e[t]:void 0}function dn(t){var e=this.__data__;return H?e[t]!==void 0:he.call(e,t)}function fn(t,e){var n=this.__data__;return n[t]=H&&e===void 0?$e:e,this}W.prototype.clear=cn;W.prototype.delete=un;W.prototype.get=ln;W.prototype.has=dn;W.prototype.set=fn;function K(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function pn(){this.__data__=[]}function yn(t){var e=this.__data__,n=ee(e,t);if(n<0)return!1;var r=e.length-1;return n==r?e.pop():on.call(e,n,1),!0}function gn(t){var e=this.__data__,n=ee(e,t);return n<0?void 0:e[n][1]}function hn(t){return ee(this.__data__,t)>-1}function mn(t,e){var n=this.__data__,r=ee(n,t);return r<0?n.push([t,e]):n[r][1]=e,this}K.prototype.clear=pn;K.prototype.delete=yn;K.prototype.get=gn;K.prototype.has=hn;K.prototype.set=mn;function G(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function Sn(){this.__data__={hash:new W,map:new(an||K),string:new W}}function Cn(t){return te(this,t).delete(t)}function En(t){return te(this,t).get(t)}function _n(t){return te(this,t).has(t)}function wn(t,e){return te(this,t).set(t,e),this}G.prototype.clear=Sn;G.prototype.delete=Cn;G.prototype.get=En;G.prototype.has=_n;G.prototype.set=wn;function ee(t,e){for(var n=t.length;n--;)if(Dn(t[n][0],e))return n;return-1}function bn(t,e){e=Fn(e,t)?[e]:xn(e);for(var n=0,r=e.length;t!=null&&n<r;)t=t[Tn(e[n++])];return n&&n==r?t:void 0}function vn(t){if(!Be(t)||On(t))return!1;var e=Mn(t)||tn(t)?sn:Zt;return e.test(An(t))}function Rn(t){if(typeof t=="string")return t;if(Se(t))return be?be.call(t):"";var e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function xn(t){return Ke(t)?t:In(t)}function te(t,e){var n=t.__data__;return Pn(e)?n[typeof e=="string"?"string":"hash"]:n.map}function Ge(t,e){var n=en(t,e);return vn(n)?n:void 0}function Fn(t,e){if(Ke(t))return!1;var n=typeof t;return n=="number"||n=="symbol"||n=="boolean"||t==null||Se(t)?!0:Bt.test(t)||!Kt.test(t)||e!=null&&t in Object(e)}function Pn(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}function On(t){return!!Ee&&Ee in t}var In=me(function(t){t=kn(t);var e=[];return Ht.test(t)&&e.push(""),t.replace(zt,function(n,r,s,i){e.push(s?i.replace(Jt,"$1"):r||n)}),e});function Tn(t){if(typeof t=="string"||Se(t))return t;var e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function An(t){if(t!=null){try{return je.call(t)}catch{}try{return t+""}catch{}}return""}function me(t,e){if(typeof t!="function"||e&&typeof e!="function")throw new TypeError(Qt);var n=function(){var r=arguments,s=e?e.apply(this,r):r[0],i=n.cache;if(i.has(s))return i.get(s);var o=t.apply(this,r);return n.cache=i.set(s,o),o};return n.cache=new(me.Cache||G),n}me.Cache=G;function Dn(t,e){return t===e||t!==t&&e!==e}var Ke=Array.isArray;function Mn(t){var e=Be(t)?We.call(t):"";return e==jt||e==Wt}function Be(t){var e=typeof t;return!!t&&(e=="object"||e=="function")}function Nn(t){return!!t&&typeof t=="object"}function Se(t){return typeof t=="symbol"||Nn(t)&&We.call(t)==Gt}function kn(t){return t==null?"":Rn(t)}function Ln(t,e,n){var r=t==null?void 0:bn(t,e);return r===void 0?n:r}var qn=Ln;const J=$t(qn);function He(t,e,n){const r=t??{result:[],success:!0,totalCount:0},s=[...r.result??[]];for(const i of e){const o=J(i.payload.data,n);switch(i.type){case"ADD":{s.findIndex(c=>J(c,n)===o)===-1&&s.push(i.payload.data);break}case"UPDATE":{const a=s.findIndex(c=>J(c,n)===o);a!==-1&&(s[a]=i.payload.data);break}case"DELETE":{const a=s.findIndex(c=>J(c,n)===o);a!==-1&&s.splice(a,1);break}}}return{...r,result:s}}function ze(t,e,n,r,s,i){const o=(i==null?void 0:i.syncWindowMs)??500,a=d.useRef([]),c=d.useRef(null),l=d.useRef(null),u=d.useRef(s);u.current=s;const y=d.useCallback(()=>{const f=a.current;if(a.current=[],c.current=null,l.current=null,!(f.length===0||!r)){t.setQueryData(e,g=>He(g,f,r));for(const g of f)(g.type==="ADD"||g.type==="UPDATE")&&t.setQueryData(n(g.payload.id,g.payload.namespace),{result:g.payload.data})}},[t,e,n,r]),p=d.useCallback(f=>{a.current.push(f),!(c.current!==null||l.current!==null)&&(u.current===1?c.current=setTimeout(y,o):l.current=requestAnimationFrame(y))},[y,o]);return d.useEffect(()=>()=>{c.current!==null&&(clearTimeout(c.current),c.current=null),l.current!==null&&(cancelAnimationFrame(l.current),l.current=null)},[]),p}const Un=({pluginID:t,connectionID:e,resourceKey:n,idAccessor:r,namespaces:s})=>{const i=I(t),o=m.useQueryClient(),{showSnackbar:a}=U(),c=d.useMemo(()=>s??[],[s]),l=d.useMemo(()=>[i,e,n,c,"list"],[i,e,n,c]),u=d.useCallback((R,C)=>[i,e,n,C,R],[i,e,n]),{mutateAsync:y}=m.useMutation({mutationFn:async R=>h.Create(i,e,n,D.CreateInput.createFrom({input:R.input,namespace:R.namespace??(c.length===1?c[0]:"")})),onSuccess:async R=>{var x;const C=R==null?void 0:R.result;let E="";(x=C==null?void 0:C.metadata)!=null&&x.name?E=C.metadata.name:C!=null&&C.id?E=C.id:C!=null&&C.name?E=C.name:C!=null&&C.ID?E=C.ID:C!=null&&C.Name&&(E=C.Name);const S=E?`Resource ${E} created`:"Resource created";a(S,"success"),await o.invalidateQueries({queryKey:l})},onError:N(a,"Failed to create resource")}),p=m.useQuery({queryKey:l,queryFn:async()=>h.List(i,e,n,D.ListInput.createFrom({order:[{field:"name",descending:!1}],pagination:{page:1,pageSize:200},namespaces:c})),placeholderData:(R,C)=>R,retry:!1}),[f,g]=d.useState(P.WatchStateIdle);d.useEffect(()=>T.On(`${i}/${e}/watch/STATE`,C=>{const E=C.data;E.resourceKey===n&&g(E.state)}),[i,e,n]);const w=ze(o,l,u,r,f);return d.useEffect(()=>{if(!r)return;h.SubscribeResource(i,e,n);const R=T.On(`${i}/${e}/${n}/ADD`,S=>w({type:"ADD",payload:S.data})),C=T.On(`${i}/${e}/${n}/UPDATE`,S=>w({type:"UPDATE",payload:S.data})),E=T.On(`${i}/${e}/${n}/DELETE`,S=>w({type:"DELETE",payload:S.data}));return()=>{R(),C(),E(),h.UnsubscribeResource(i,e,n)}},[i,e,n,w]),{resources:p,create:y,watchState:f,isSyncing:f===P.WatchStateSyncing,isSynced:f===P.WatchStateSynced,watchError:f===P.WatchStateError}},$n=({pluginID:t})=>{const e=I(t),{showSnackbar:n}=U(),r=m.useMutation({mutationFn:async({opts:o,input:a})=>h.Create(e,o.connectionID,o.resourceKey,D.CreateInput.createFrom({input:a.input,namespace:a.namespace??o.namespace??""})),onSuccess:(o,{opts:a})=>{n(`Resource ${a.resourceID} created`,"success")},onError(o,{opts:a}){j(n,o,`Failed to create resource ${a.resourceID}`)}}),s=m.useMutation({mutationFn:async({opts:o,input:a})=>h.Update(e,o.connectionID,o.resourceKey,D.UpdateInput.createFrom({input:a.input,id:o.resourceID,namespace:o.namespace??""})),onSuccess:(o,{opts:a})=>{n(`Resource ${a.resourceID} updated`,"success")},onError(o,{opts:a}){j(n,o,`Failed to update resource ${a.resourceID}`)}}),i=m.useMutation({mutationFn:async({opts:o,input:a})=>h.Delete(e,o.connectionID,o.resourceKey,D.DeleteInput.createFrom({id:o.resourceID,namespace:o.namespace??"",gracePeriodSeconds:a.gracePeriodSeconds})),onSuccess:(o,{opts:a})=>{n(`Resource ${a.resourceID} deleted`,"success")},onError(o,{opts:a}){j(n,o,`Failed to delete resource ${a.resourceID}`)}});return{create:r.mutateAsync,update:s.mutateAsync,remove:i.mutateAsync}},Qn=({pluginID:t,connectionID:e,resourceKey:n,enabled:r=!0})=>{const s=I(t),i=m.useQuery({queryKey:["RESOURCE_ACTIONS",s,e,n],queryFn:()=>h.GetActions(s,e,n),enabled:r&&!!s&&!!e&&!!n,staleTime:5*60*1e3});return{actions:i.data??[],isLoading:i.isLoading,error:i.error}},jn=({pluginID:t,connectionID:e,resourceKey:n})=>{const r=I(t),s=m.useQueryClient(),{showSnackbar:i}=U(),o=m.useMutation({mutationFn:async({actionID:a,id:c="",namespace:l="",params:u={}})=>h.ExecuteAction(r,e,n,a,D.ActionInput.createFrom({id:c,namespace:l,params:u})),onSuccess:a=>{a!=null&&a.message&&i(a.message,"success"),s.invalidateQueries({queryKey:["RESOURCES",r,e,n]})},onError:(a,c)=>{j(i,a,`Failed to execute action "${c.actionID}"`)}});return{executeAction:o.mutateAsync,isExecuting:o.isPending,error:o.error}},Wn=({pluginID:t,connectionID:e,enabled:n=!0})=>{const r=I(t),s=m.useQuery({queryKey:["EDITOR_SCHEMAS",r,e],queryFn:()=>h.GetEditorSchemas(r,e),enabled:n&&!!r&&!!e,staleTime:10*60*1e3,retry:1});return{schemas:s.data??[],isLoading:s.isLoading,error:s.error,refetch:s.refetch}},Gn=({pluginID:t,connectionID:e,enabled:n=!0})=>{const r=I(t),s=m.useQueryClient(),i=[r,e,"watch-state"],o=d.useRef([]),a=d.useRef(!1),c=d.useCallback(p=>{s.setQueryData(i,f=>{if(!f)return f;const g={...f.resources,[p.resourceKey]:p.state},w={...f.resourceCounts,[p.resourceKey]:p.resourceCount};let R=0,C=0;for(const E of Object.values(g))E===P.WatchStateSynced&&R++,(E===P.WatchStateError||E===P.WatchStateFailed)&&C++;return{...f,resources:g,resourceCounts:w,totalResources:Object.keys(g).length,syncedCount:R,errorCount:C}})},[s,r,e]),l=m.useQuery({queryKey:i,queryFn:async()=>{const p=await h.GetWatchState(r,e);if(!p)throw new Error("Failed to get watch state: null response");const f={};let g=0,w=0;for(const[C,E]of Object.entries(p.resources??{}))E!=null&&(f[C]=E,E===P.WatchStateSynced&&g++,E===P.WatchStateError&&w++);const R={};for(const[C,E]of Object.entries(p.resourceCounts??{}))E!=null&&(R[C]=E);return{connection:p.connectionId,resources:f,resourceCounts:R,totalResources:Object.keys(f).length,syncedCount:g,errorCount:w}},enabled:n&&!!r&&!!e,refetchInterval:p=>{const f=p.state.data;if(!f||f.totalResources===0)return 3e3;let g=0;for(const w of Object.values(f.resources))(w===P.WatchStateSynced||w===P.WatchStateError||w===P.WatchStateStopped||w===P.WatchStateFailed||w===P.WatchStateForbidden||w===P.WatchStateSkipped)&&g++;return g>=f.totalResources?!1:3e3}});d.useEffect(()=>{if(!l.data||a.current)return;a.current=!0;const p=o.current;o.current=[];for(const f of p)c(f)},[l.data,c]),d.useEffect(()=>{if(!n||!r||!e)return;a.current=!1,o.current=[];const p=T.On(`${r}/${e}/watch/STATE`,f=>{const g=f.data;a.current?c(g):o.current.push(g)});return()=>{p(),a.current=!1,o.current=[]}},[r,e,n,c]);const u=l.data;let y=0;if(u!=null&&u.resources)for(const p of Object.values(u.resources))(p===P.WatchStateSynced||p===P.WatchStateError||p===P.WatchStateStopped||p===P.WatchStateFailed||p===P.WatchStateForbidden||p===P.WatchStateSkipped)&&y++;return{summary:l,getResourceState:p=>u==null?void 0:u.resources[p],isFullySynced:u?u.totalResources>0&&y===u.totalResources:!1,syncProgress:u&&u.totalResources>0?y/u.totalResources:0,errorCount:(u==null?void 0:u.errorCount)??0}},Kn=()=>{const[t,e]=d.useState(new Map),n=d.useRef(new Map),r=d.useRef(new Map),s=d.useCallback(l=>{const u=l.data,y=pe(u),p=qe(n.current,u),f=ue(p);if(e(g=>{const w=new Map(g);return w.set(y,f),w}),r.current.has(y)&&(clearTimeout(r.current.get(y)),r.current.delete(y)),Z(f)){const g=setTimeout(()=>{e(w=>{const R=new Map(w);return R.delete(y),R}),n.current.delete(y),r.current.delete(y)},5e3);r.current.set(y,g)}},[]);d.useEffect(()=>{const l=T.On("watch/STATE",s);return()=>{l();for(const u of r.current.values())clearTimeout(u)}},[s]);const i=Array.from(t.values()),o=ke(i),a=i.find(l=>!Z(l))??i[0]??null,c=Le(i);return{syncs:i,hasSyncing:o,primarySync:a,aggregateProgress:c}},Ye=()=>{const t=d.useContext(fe);if(!t)throw new Error("useOperations must be used within an OperationsProvider");return t},Bn=({pluginID:t,connectionID:e,resourceKey:n})=>{const r=I(t),{showSnackbar:s}=U(),{addOperation:i,updateOperation:o}=Ye(),a=d.useRef([]);return d.useEffect(()=>()=>{a.current.forEach(l=>l())},[]),{startStreamAction:d.useCallback(async({actionID:l,id:u,namespace:y,label:p,params:f={}})=>{try{const g=await h.StreamAction(r,e,n,l,D.ActionInput.createFrom({id:u,namespace:y,params:f}));i({id:g,label:p,resourceKey:n,resourceName:u,namespace:y,connectionID:e,status:"running",startedAt:Date.now()});const w=`action/stream/${g}`,R=T.On(w,C=>{var S,x,F,b;const E=C.data;switch(E.type){case"progress":{const _=E.data??{};o(g,{message:_.message,progress:_.ready!==void 0&&_.desired!==void 0?{ready:_.ready,desired:_.desired}:void 0});break}case"complete":o(g,{status:"completed",message:((S=E.data)==null?void 0:S.message)??"Completed",completedAt:Date.now()}),s(((x=E.data)==null?void 0:x.message)??p+" completed","success"),T.Off(w);break;case"error":o(g,{status:"error",message:((F=E.data)==null?void 0:F.message)??"Failed",completedAt:Date.now()}),s(((b=E.data)==null?void 0:b.message)??p+" failed","error"),T.Off(w);break}});return a.current.push(()=>{R(),T.Off(w)}),g}catch(g){throw j(s,g,`Failed to start "${l}"`),g}},[r,e,n,i,o,s])}};function Je(t,e){return`${t}/${e}/graph/CHANGED`}function ne(t,e,n,r){const s=m.useQueryClient(),i=d.useRef(n);i.current=n;const o=JSON.stringify(n);d.useEffect(()=>{if(!r||!t||!e)return;const a=T.On(Je(t,e),()=>{s.invalidateQueries({queryKey:i.current,exact:!0})});return()=>{a()}},[s,t,e,o,r])}const Hn={owns:{outgoing:"Owns",incoming:"Owned by"},runs_on:{outgoing:"Runs on",incoming:"Running here"},uses:{outgoing:"Uses",incoming:"Used by"},exposes:{outgoing:"Exposes",incoming:"Exposed by"},manages:{outgoing:"Manages",incoming:"Managed by"},member_of:{outgoing:"Member of",incoming:"Members"},selects:{outgoing:"Selects",incoming:"Selected by"}};function zn(t,e){const n=Hn[t];if(n)return n[e];const r=t.replace(/_/g," ");return e==="outgoing"?r:`${r} (incoming)`}function Yn(t,e){return t.pluginId===e.pluginId&&t.connectionId===e.connectionId&&t.resourceKey===e.resourceKey&&t.id===e.id&&(t.namespace??"")===(e.namespace??"")}function Ze(t,e){return e.map(n=>{const r=Yn(n.source,t);return{resource:r?n.target:n.source,type:n.type,direction:r?"outgoing":"incoming",label:n.label}})}const Jn=({pluginID:t,connectionID:e,resourceKey:n,resourceID:r,namespace:s="",direction:i="both",relationshipType:o,enabled:a=!0,refetchInterval:c=!1})=>{const l=I(t),u=["RESOURCE_RELATED",l,e,n,s,r,i,o??null],y=a&&!!l&&!!e&&!!n&&!!r;ne(l,e,u,y);const p=m.useQuery({queryKey:u,queryFn:async()=>h.GetRelated(l,e,n,s,r,i,o??null),enabled:y,refetchInterval:c}),f={pluginId:l,connectionId:e,resourceKey:n,id:r,namespace:s},g=p.data??[];return{related:Ze(f,g),edges:g,isLoading:p.isLoading,isFetching:p.isFetching,error:p.error,refetch:p.refetch}},Zn=({pluginID:t,connectionID:e,resourceKey:n,resourceID:r,namespace:s="",maxDepth:i=3,enabled:o=!0,refetchInterval:a=!1})=>{const c=I(t),l=["RESOURCE_DEPENDENCY_TREE",c,e,n,s,r,i],u=o&&!!c&&!!e&&!!n&&!!r;ne(c,e,l,u);const y=m.useQuery({queryKey:l,queryFn:async()=>h.GetDependencyTree(c,e,n,s,r,i),enabled:u,refetchInterval:a});return{tree:y.data??null,isLoading:y.isLoading,isFetching:y.isFetching,error:y.error,refetch:y.refetch}},Xn=({pluginID:t,connectionID:e,resourceKey:n,resourceID:r,namespace:s="",upDepth:i=2,downDepth:o=3,enabled:a=!0})=>{const c=I(t),l=["RESOURCE_GRAPH",c,e,n,s,r,i,o],u=a&&!!c&&!!e&&!!n&&!!r;ne(c,e,l,u);const y=m.useQuery({queryKey:l,queryFn:async()=>h.GetSubgraph(c,e,n,s,r,i,o),enabled:u});return{graph:y.data??null,isLoading:y.isLoading,isFetching:y.isFetching,error:y.error,refetch:y.refetch}},Vn=()=>{const t=d.useContext(de);if(!t)throw new Error("useSettings must be used within a SettingsProvider");return t},er=({to:t,withinContext:e,...n})=>{const{pluginId:r}=V();r||console.error("Link used outside of a plugin context");const s=`/_plugin/${r}${t.startsWith("/")?"":"/"}${t}`;return d.useMemo(()=>A.jsx(B.Link,{style:{textDecoration:"none",color:"inherit"},...n,to:s}),[n,s])};function tr(){const t=B.useNavigate(),e=B.useLocation(),{pluginId:n}=V();n||console.error("usePluginRouter used outside of a plugin context");const r=`/_plugin/${n}`,s=e.pathname.startsWith(r)?e.pathname.slice(r.length)||"/":e.pathname,i=d.useCallback((o,a)=>{const{...c}=a??{};o.startsWith("/")?t(`${r}${o}`,c):t(o,c)},[t,r]);return d.useMemo(()=>({location:e,navigate:i,pluginPath:s}),[e,i,s])}class nr{}class rr{constructor(){M(this,"_extensions");M(this,"root");M(this,"pages");M(this,"_routes")}get extensions(){return this._extensions||[]}get Routes(){var e;if(!this._routes&&this.root)return[{path:"",index:!0,Component:this.root}];if(!((e=this._routes)!=null&&e.length))throw new Error("cannot use plugin without a root page or router");return this._routes}get Window(){if(!this._routes&&this.root)return A.jsx(this.root,{});const e=B.createMemoryRouter(this._routes||[]);return A.jsx(B.RouterProvider,{router:e})}registerExtensionPoints(e){return this._extensions=e||[],this}setRootPage(e){return this.root=e,this}withPage(e,n){return this.pages||(this.pages={}),this.pages[e]?(console.warn("Cannot register page with the same name. Please use a different name."),this):(this.pages[e]=n,this)}withRoutes(e){return this._routes=e,this}}var Xe=(t=>(t.MISSING_MANIFEST="MISSING_MANIFEST",t.MISSING_PLUGIN="MISSING_PLUGIN",t.MISSING_ENTRYPOINT="MISSING_ENTRYPOINT",t))(Xe||{});const sr=t=>{const e=t.split("::");return e.length===1?{group:"core",version:"",kind:e[0]}:{group:e[0]||"core",version:e[1]||"",kind:e[2]||e[0]}},or=t=>!t||t==="core"?"Core":t.charAt(0).toUpperCase()+t.slice(1);exports.ALL_SESSIONS_KEY=Q;exports.BottomDrawerContext=Fe;exports.ConfirmationModalContext=Oe;exports.ErrorTypes=q;exports.ExtensionPointRegistry=ht;exports.ExtensionPointStore=De;exports.ExtensionProvider=gt;exports.Link=er;exports.OperationsContext=fe;exports.OperationsProvider=ut;exports.PluginContext=X;exports.PluginContextProvider=ot;exports.PluginErrorCode=Xe;exports.PluginWindow=rr;exports.PluginWindowRootProps=nr;exports.RightDrawerContext=Pe;exports.SettingsContext=de;exports.SettingsProvider=at;exports.SnackbarProvider=St;exports.WatchState=P;exports.actionToSnackbar=ve;exports.applyBatch=He;exports.connectionListQueryKey=Ne;exports.createErrorHandler=N;exports.defaultState=xe;exports.formatGroup=or;exports.graphChangedEvent=Je;exports.isCancelledError=le;exports.parseAppError=$;exports.parseResourceKey=sr;exports.relationshipLabel=zn;exports.showAppError=j;exports.toRelatedResources=Ze;exports.useActiveSyncs=Kn;exports.useBottomDrawer=ye;exports.useConfirmationModal=Dt;exports.useConnection=Ct;exports.useConnectionNamespaces=_t;exports.useConnectionStatus=wt;exports.useConnections=Et;exports.useDependencyTree=Zn;exports.useEditorSchemas=Wn;exports.useEventBatcher=ze;exports.useExec=xt;exports.useExecuteAction=jn;exports.useExtensionPoint=yt;exports.useExtensionRegistry=Ae;exports.useLogs=Ft;exports.useMetricProviders=Pt;exports.useMetricProvidersForResource=Ue;exports.useMetricStream=It;exports.useOperations=Ye;exports.usePluginContext=V;exports.usePluginData=vt;exports.usePluginRouter=tr;exports.usePluginSettings=it;exports.usePortForwardSessions=Tt;exports.useRefetchOnGraphChange=ne;exports.useRelatedResources=Jn;exports.useResolvedPluginId=I;exports.useResource=Mt;exports.useResourceActions=Qn;exports.useResourceAreaComponent=Nt;exports.useResourceGraph=Xn;exports.useResourceGroups=kt;exports.useResourceMetrics=Ot;exports.useResourceMutations=$n;exports.useResourcePortForwarder=At;exports.useResourceSearch=Lt;exports.useResourceType=qt;exports.useResourceTypes=Ut;exports.useResources=Un;exports.useRightDrawer=Rt;exports.useSettings=Vn;exports.useSnackbar=U;exports.useStreamAction=Bn;exports.useWatchState=Gn;
|
|
1
|
+
"use strict";var ot=Object.defineProperty;var it=(t,e,n)=>e in t?ot(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var L=(t,e,n)=>it(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=require("react/jsx-runtime"),l=require("react"),H=require("react-router-dom");require("./index-D_aIcqH0.cjs");const E=require("./graphservice-CWIVejHl.cjs"),N=require("./models-CGYstu7u.cjs"),D=require("./events-CtgYnKmS.cjs"),S=require("@tanstack/react-query"),at=require("@omniviewdev/base-ui"),ct=require("./legacyEnum-DkV5yRdA.cjs"),te=l.createContext(void 0),F={PLUGIN_NOT_FOUND:"omniview:plugin/not-found",PLUGIN_NOT_LOADED:"omniview:plugin/not-loaded",PLUGIN_ALREADY_LOADED:"omniview:plugin/already-loaded",PLUGIN_INSTALL_FAILED:"omniview:plugin/install-failed",PLUGIN_LOAD_FAILED:"omniview:plugin/load-failed",PLUGIN_BUILD_FAILED:"omniview:plugin/build-failed",PLUGIN_COMMITTED_CLEANUP_PENDING:"omniview:plugin/committed-cleanup-pending",PLUGIN_COMMIT_UNCERTAIN:"omniview:plugin/commit-uncertain",SETTINGS_MISSING_CONFIG:"omniview:settings/missing-config",SETTINGS_INVALID_CONFIG:"omniview:settings/invalid-config",RESOURCE_NOT_FOUND:"omniview:resource/not-found",RESOURCE_FORBIDDEN:"omniview:resource/forbidden",RESOURCE_UNAUTHORIZED:"omniview:resource/unauthorized",RESOURCE_CONFLICT:"omniview:resource/conflict",RESOURCE_TIMEOUT:"omniview:resource/timeout",RESOURCE_LIMIT:"omniview:resource/limit",RESOURCE_CONTINUATION_EXPIRED:"omniview:resource/continuation-expired",RESOURCE_RESET_REQUIRED:"omniview:resource/reset-required",RESOURCE_PARTIAL:"omniview:resource/partial",RESOURCE_PROVIDER_ERROR:"omniview:resource/provider-error",CONNECTION_NOT_FOUND:"omniview:connection/not-found",CONNECTION_FAILED:"omniview:connection/failed",SESSION_NOT_FOUND:"omniview:session/not-found",SESSION_FAILED:"omniview:session/failed",CANCELLED:"omniview:cancelled",INTERNAL:"omniview:internal",VALIDATION:"omniview:validation",NOT_IMPLEMENTED:"omniview:not-implemented"},Re={INVALID_REQUEST:[F.VALIDATION,400,"correctRequest"],UNSUPPORTED:[F.NOT_IMPLEMENTED,501,"refreshContract"],FORBIDDEN:[F.RESOURCE_FORBIDDEN,403,"none"],UNAUTHORIZED:[F.RESOURCE_UNAUTHORIZED,401,"none"],NOT_FOUND:[F.RESOURCE_NOT_FOUND,404,"none"],CONFLICT:[F.RESOURCE_CONFLICT,409,"refreshContract"],ALREADY_EXISTS:[F.RESOURCE_CONFLICT,409,"refreshContract"],CANCELLED:[F.CANCELLED,499,"none"],TIMEOUT:[F.RESOURCE_TIMEOUT,408,"none"],UNAVAILABLE:[F.CONNECTION_FAILED,503,"reconnect"],CONNECTION_ERROR:[F.CONNECTION_FAILED,503,"reconnect"],CERTIFICATE_ERROR:[F.CONNECTION_FAILED,502,"reconnect"],RESOURCE_LIMIT:[F.RESOURCE_LIMIT,429,"correctRequest"],CONTINUATION_EXPIRED:[F.RESOURCE_CONTINUATION_EXPIRED,410,"restartQuery"],RESET_REQUIRED:[F.RESOURCE_RESET_REQUIRED,409,"restartQuery"],PARTIAL_RESULT:[F.RESOURCE_PARTIAL,422,"none"],PROVIDER_ERROR:[F.RESOURCE_PROVIDER_ERROR,502,"none"],INTERNAL:[F.INTERNAL,500,"none"]};function ae(t){return typeof t=="object"&&t!==null?t:void 0}function $(t,e){return typeof t=="string"&&t.length>0&&t.length<=e}function ce(){return{type:F.CANCELLED,code:"CANCELLED",title:"Cancelled",status:499,detail:"The operation was cancelled.",recovery:"none"}}function Z(t,e){if(e>4)return;if(t==="cancelled")return ce();if(typeof t=="string"){const r=t.trim();if(!r.startsWith("{"))return;try{return Z(JSON.parse(r),e+1)}catch{return}}const n=ae(t);if(n){if(n.name==="AbortError"||n.name==="CancelError")return ce();if($(n.type,256)&&$(n.title,256)&&typeof n.status=="number"&&Number.isInteger(n.status)&&n.status>=100&&n.status<=599&&typeof n.detail=="string"&&n.detail.length<=4096){const r={type:n.type,title:n.title,status:n.status,detail:n.detail};$(n.code,64)&&(r.code=n.code),$(n.requestId,256)&&(r.requestId=n.requestId),$(n.instance,512)&&(r.instance=n.instance),Array.isArray(n.suggestions)&&(r.suggestions=n.suggestions.filter(i=>$(i,512)).slice(0,8)),Array.isArray(n.actions)&&(r.actions=n.actions.filter(i=>{const o=ae(i);return!!o&&["navigate","retry","open-url","copy"].includes(String(o.type))&&$(o.label,256)&&(o.target===void 0||$(o.target,4096))}).slice(0,8)),["correctRequest","refreshContract","restartQuery","reconnect","none"].includes(String(n.recovery))&&(r.recovery=n.recovery);const s=ae(n.location);return(s==null?void 0:s.unit)==="utf8-byte"&&typeof s.start=="number"&&typeof s.end=="number"&&Number.isSafeInteger(s.start)&&Number.isSafeInteger(s.end)&&s.start>=0&&s.end>=s.start&&(r.location={start:s.start,end:s.end,unit:"utf8-byte"}),r}if(typeof n.code=="string"&&typeof n.title=="string"&&typeof n.message=="string"){let r=n.code;if(r==="PERMISSION_DENIED"&&(r="FORBIDDEN"),["INVALID_INPUT","FILTER_UNKNOWN_FIELD","FILTER_INVALID_OPERATOR"].includes(r)&&(r="INVALID_REQUEST"),Object.prototype.hasOwnProperty.call(Re,r)||(r="INTERNAL"),r==="CANCELLED")return ce();const[s,i,o]=Re[r],a=r==="FORBIDDEN"||r==="UNAUTHORIZED"||r==="INTERNAL"||r==="PROVIDER_ERROR";return{type:s,status:i,code:r,recovery:o,title:a?r==="FORBIDDEN"?"Access denied":r==="UNAUTHORIZED"?"Authentication required":"Operation failed":$(n.title,256)?n.title:"Operation failed",detail:a?"The operation could not be completed.":$(n.message,4096)?n.message:"The operation could not be completed.",...!a&&Array.isArray(n.suggestions)?{suggestions:n.suggestions.filter(c=>$(c,512)).slice(0,8)}:{}}}return Z(n.message,e+1)??Z(n.cause,e+1)}}function Q(t){return Z(t,0)??{type:F.INTERNAL,title:t==null?"Unknown error":"Error",status:500,detail:t==null?"An unknown error occurred.":"The operation could not be completed."}}function z(t){return Q(t).type===F.CANCELLED}function Ae(t){switch(t.type){case"navigate":return{label:t.label,onClick:()=>{window.location.hash=t.target??""}};case"open-url":return{label:t.label,onClick:()=>{window.open(t.target,"_blank")}};case"copy":return{label:t.label,onClick:()=>{navigator.clipboard.writeText(t.target??"")}};case"retry":return{label:t.label,onClick:()=>{}};default:return{label:t.label,onClick:()=>{}}}}function Te(t,e){var s,i;const n=[t.detail,...((s=t.suggestions)==null?void 0:s.map(o=>`• ${o}`))??[]].join(`
|
|
2
|
+
`);return{message:e||(t.title!=="Error"?t.title:"Operation failed"),status:"error",details:n,actions:(i=t.actions)==null?void 0:i.map(Ae)}}function j(t,e,n){if(z(e))return;const r=Q(e);t(Te(r,n))}function M(t,e){return n=>{if(z(n))return;const r=Q(n);t(Te(r,r.title!=="Error"?r.title:e))}}function ut(t){const{children:e,pluginId:n}=t,[r,s]=l.useState({}),[i,o]=l.useState(new N.PluginMeta),[a,c]=l.useState(!1),[d,u]=l.useState(null),f=l.useRef(0),p=l.useRef(0);console.debug("[PluginContextProvider] render",{pluginId:n,metaLoaded:a,metaError:!!d});const y=l.useCallback(()=>{if(n===void 0||n==="")return;const _=++f.current;console.debug(`[PluginContextProvider] fetching settings for "${n}"`),E.PluginValues(n).then(g=>{_===f.current&&(console.debug(`[PluginContextProvider] settings loaded for "${n}"`,Object.keys(g)),s(g))}).catch(g=>{if(_!==f.current)return;const h=Q(g);console.error(`[PluginContextProvider] error fetching settings for "${n}":`,h.detail)})},[n]),m=l.useCallback(()=>{if(n===void 0||n===""){console.debug("[PluginContextProvider] skipping meta fetch — empty pluginId");return}const _=++p.current;console.debug(`[PluginContextProvider] fetching meta for "${n}"`),u(null),E.GetPluginMeta(n).then(g=>{_===p.current&&(console.debug(`[PluginContextProvider] meta loaded for "${n}"`,{name:g==null?void 0:g.name,version:g==null?void 0:g.version}),o(g),c(!0))}).catch(g=>{if(_!==p.current)return;const h=Q(g);console.error(`[PluginContextProvider] error fetching meta for "${n}":`,h.detail),u(h.detail),c(!1)})},[n]);return l.useEffect(()=>{if(a)return;const _=()=>{y(),m()},g=[D.On("plugin/init_complete",_),D.On("plugin/dev_install_complete",h=>{var b;((b=h.data)==null?void 0:b.id)===n&&_()}),D.On("plugin/inventory_changed",_)];return()=>{for(const h of g)h()}},[n,a,y,m]),l.useEffect(()=>(console.debug(`[PluginContextProvider] useEffect — pluginId changed to "${n}"`),c(!1),u(null),s({}),y(),m(),()=>{++f.current,++p.current}),[n,y,m]),d?x.jsx("div",{style:{display:"flex",flex:1,alignItems:"center",justifyContent:"center",padding:24},children:x.jsxs("div",{style:{maxWidth:480,width:"100%",border:"1px solid #7F1D1D",borderRadius:8,backgroundColor:"#1C1917",padding:20,fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'},children:[x.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:12},children:[x.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"#EF4444",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[x.jsx("circle",{cx:"12",cy:"12",r:"10"}),x.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),x.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),x.jsx("span",{style:{fontSize:14,fontWeight:600,color:"#FECACA"},children:"Plugin failed to load"})]}),x.jsx("p",{style:{fontSize:13,color:"#A1A1AA",margin:"0 0 16px"},children:d}),x.jsx("button",{onClick:()=>m(),style:{background:"transparent",color:"#F87171",border:"1px solid #7F1D1D",borderRadius:6,padding:"6px 14px",fontSize:13,fontWeight:500,cursor:"pointer"},children:"Retry"})]})}):a?x.jsx(te.Provider,{value:{pluginId:n,settings:r,meta:i},children:e}):x.jsxs("div",{style:{display:"flex",flex:1,alignItems:"center",justifyContent:"center"},children:[x.jsx("div",{style:{width:24,height:24,border:"2px solid #3F3F46",borderTopColor:"#A1A1AA",borderRadius:"50%",animation:"plugin-spin 0.8s linear infinite"}}),x.jsx("style",{children:"@keyframes plugin-spin { to { transform: rotate(360deg); } }"})]})}function ne(){const t=l.useContext(te);if(!t)throw new Error("usePluginContext must be used within a PluginContextProvider");return t}function lt(){return ne().settings}const ge=l.createContext(void 0),dt=({children:t})=>{const[e,n]=l.useState({}),r=l.useRef(0),s=l.useCallback(()=>{const o=r.current+1;r.current=o,E.Values().then(a=>{o===r.current&&n(a)}).catch(a=>{o===r.current&&console.error("Error fetching settings:",a)})},[]);l.useEffect(()=>{const o=D.On("settings/changed",()=>s());return s(),()=>{r.current+=1,o()}},[s]);const i=l.useCallback(()=>{s()},[s]);return x.jsx(ge.Provider,{value:{settings:e,reload:i},children:t})},De={height:32,focused:0,tabs:[],createTab:()=>{},createTabs:()=>{},updateTab:()=>{},focusTab:()=>{},reorderTab:()=>{},closeTab:()=>{},closeTabs:()=>{},resizeDrawer:()=>{},closeDrawer:()=>{},fullscreenDrawer:()=>{}},Fe=l.createContext(De),xe=l.createContext(void 0),Ne=l.createContext(void 0),he=l.createContext(void 0),ft=3e4,pt=({children:t})=>{const[e,n]=l.useState([]),r=l.useCallback(a=>{n(c=>[a,...c])},[]),s=l.useCallback((a,c)=>{n(d=>d.map(u=>u.id===a?{...u,...c}:u))},[]),i=l.useCallback(a=>{n(c=>c.filter(d=>d.id!==a))},[]);l.useEffect(()=>{const a=[];for(const c of e)if(c.status!=="running"){const d=Date.now()-(c.completedAt??c.startedAt),u=Math.max(0,ft-d);a.push(setTimeout(()=>i(c.id),u))}return()=>a.forEach(clearTimeout)},[e,i]);const o=l.useMemo(()=>({operations:e,addOperation:r,updateOperation:s,removeOperation:i}),[e,r,s,i]);return x.jsx(he.Provider,{value:o,children:t})};var fe=function(t,e){return fe=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(n[s]=r[s])},fe(t,e)};function yt(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");fe(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}var ue="Invariant Violation",be=Object.setPrototypeOf,gt=be===void 0?function(t,e){return t.__proto__=e,t}:be,ht=function(t){yt(e,t);function e(n){n===void 0&&(n=ue);var r=t.call(this,typeof n=="number"?ue+": "+n+" (see https://github.com/apollographql/invariant-packages)":n)||this;return r.framesToPop=1,r.name=ue,gt(r,e.prototype),r}return e}(Error);function pe(t,e){if(!t)throw new ht(e)}var Le=["debug","log","warn","error","silent"],mt=Le.indexOf("log");function Y(t){return function(){if(Le.indexOf(t)>=mt){var e=console[t]||console.log;return e.apply(console,arguments)}}}(function(t){t.debug=Y("debug"),t.log=Y("log"),t.warn=Y("warn"),t.error=Y("error")})(pe||(pe={}));const Me=l.createContext(void 0),ke=()=>l.useContext(Me);function Et(t){const e=ke(),n=l.useRef(null),r=e==null?void 0:e.getExtensionPoint(t),s=l.useCallback(o=>{const a=[];return e&&a.push(e.subscribe(o)),r&&a.push(r.subscribe(o)),()=>{for(const c of a)c()}},[e,t,r]),i=l.useCallback(()=>{const o=e==null?void 0:e.getExtensionPoint(t);if(!o){if(n.current&&n.current.store===void 0)return n.current.sentinel;const d={};return n.current={store:void 0,version:-1,sentinel:d},d}const a=n.current;if(a&&a.store===o&&a.version===o.version)return a.sentinel;const c={};return n.current={store:o,version:o.version,sentinel:c},c},[e,t]);return l.useSyncExternalStore(s,i),e==null?void 0:e.getExtensionPoint(t)}const St=({registry:t,children:e})=>{const n=l.useRef(t);return pe(n.current===t,"You can't change the extension registry after it has been rendered"),x.jsx(Me.Provider,{value:n.current,children:e})},le=t=>{if(!t||typeof t!="string")throw new TypeError(`extensionName is required to be a string and can't be: "${t}" (${typeof t})`);return t.trim()};class qe{constructor(e){L(this,"id");L(this,"mode");L(this,"_pluginId");L(this,"_version",0);L(this,"_contributions",new Map);L(this,"_lookupCache",new Map);L(this,"_matcher");L(this,"_select");L(this,"_listeners",new Set);this.id=e.id,this.mode=e.mode??"multiple",this._pluginId=e.pluginId,this._matcher=e.matcher,this._select=e.select}get pluginId(){return this._pluginId}get version(){return this._version}register(e){if(this._contributions.has(e.id))throw new Error(`Contribution with id "${e.id}" already exists in extension point "${this.id}"`);this._contributions.set(e.id,e),this._invalidateCache(),this._notify()}unregister(e){this._contributions.delete(e)&&(this._invalidateCache(),this._notify())}provide(e){return this._getMatched(e).map(r=>r.value)}list(e){return this._getMatched(e)}listAll(){return Array.from(this._contributions.values())}subscribe(e){return this._listeners.add(e),()=>{this._listeners.delete(e)}}removeContributionsByPlugin(e){let n=!1;for(const[r,s]of this._contributions)s.plugin===e&&(this._contributions.delete(r),n=!0);n&&(this._invalidateCache(),this._notify())}_getMatched(e){const n=this._getCacheKey(e);if(n!=null){const s=this._lookupCache.get(n);if(s){const i=s.map(o=>this._contributions.get(o)).filter(o=>o!=null);return this._applyMode(i,e)}}let r=this._sortDeterministic(Array.from(this._contributions.values()));return this._matcher&&e!==void 0&&(r=r.filter(s=>this._matcher(s,e))),n!=null&&this._lookupCache.set(n,r.map(s=>s.id)),this._applyMode(r,e)}_applyMode(e,n){if(this.mode==="single"){if(this._select){const r=this._select(e,n);return r?[r]:[]}return e.length>0?[e[0]]:[]}return e}_sortDeterministic(e){return[...e].sort((n,r)=>{const s=n.plugin.localeCompare(r.plugin);return s!==0?s:n.id.localeCompare(r.id)})}_getCacheKey(e){if(e!=null&&typeof e=="object"&&"getCacheKey"in e){const n=e.getCacheKey;if(typeof n=="function")return n()}}_invalidateCache(){this._lookupCache.clear()}_notify(){this._version++;for(const e of this._listeners)e()}}class Ct{constructor(e){L(this,"_stores",new Map);L(this,"_storeUnsubs",new Map);L(this,"_listeners",new Set);if(e!=null&&e.initialStores)for(const n of e.initialStores)this.addExtensionPoint(n)}addExtensionPoint(e){const n=le(e.id);if(this._stores.has(n)){const s=this._stores.get(n);throw new Error(`Extension point "${n}" already exists (owned by "${s.pluginId??"unknown"}")`)}const r=new qe({...e,id:n});this._stores.set(n,r),this._storeUnsubs.set(n,r.subscribe(()=>this._notify())),this._notify()}getExtensionPoint(e){const n=le(e);return this._stores.get(n)}hasExtensionPoint(e){const n=le(e);return this._stores.has(n)}listExtensionPoints(){return Array.from(this._stores.keys())}removeExtensionPoints(e){var r;let n=!1;for(const[s,i]of this._stores)i.pluginId===e&&((r=this._storeUnsubs.get(s))==null||r(),this._storeUnsubs.delete(s),this._stores.delete(s),n=!0);n&&this._notify()}removeContributions(e){for(const n of this._stores.values())n.removeContributionsByPlugin(e);this._notify()}subscribe(e){return this._listeners.add(e),()=>{this._listeners.delete(e)}}_notify(){for(const e of this._listeners)e()}}const Ue=l.createContext(void 0),_t={default:"info",info:"info",success:"success",warning:"warning",error:"danger"},wt=({children:t})=>{const{toast:e}=at.useToast(),[n,r]=l.useState([]),s=o=>{r(a=>[...a,o])},i=(o,a,c)=>{const d=typeof o=="object";let u="",f="info",p,y=5e3,m;if(d){if(u=o.message,o.showOnce){if(n.includes(u))return;s(u)}f=o.status,p=o.details,y=o.autoHideDuration??5e3,m=o.actions}else u=o,f=a,p=c;e(p??u,{severity:_t[f]??"info",title:p?u:void 0,duration:y,action:m==null?void 0:m[0]})};return x.jsx(Ue.Provider,{value:{showSnackbar:i},children:t})},U=()=>{const t=l.useContext(Ue);if(t===void 0)throw new Error("useCustomSnackbar must be used within a CustomSnackbarProvider");return t};function T(t){const e=l.useContext(te),n=(e==null?void 0:e.pluginId)??t;if(!n)throw new Error("pluginID must be provided either via PluginContext or as an explicit parameter");return n}const Rt=({pluginID:t,connectionID:e})=>{const n=T(t),r=S.useQueryClient(),{showSnackbar:s}=U(),i=[n,"connection","detail",e],{mutateAsync:o}=S.useMutation({mutationFn:async()=>E.StartConnection(n,e),onSuccess(f){r.setQueryData(i,f),r.invalidateQueries({queryKey:["EDITOR_SCHEMAS",n,e]})},onError:M(s,"Failed to start connection")}),{mutateAsync:a}=S.useMutation({mutationFn:async()=>E.StopConnection(n,e),onSuccess(f){r.setQueryData(i,f)},onError:M(s,"Failed to stop connection")}),{mutateAsync:c}=S.useMutation({mutationFn:async f=>E.UpdateConnection(n,f),onSuccess(f,{name:p}){s({message:`Connection ${p} successfully updated`,status:"success"}),r.setQueryData(i,f),r.setQueriesData({queryKey:[n,"connection","list"]},y=>y==null?void 0:y.map(m=>m.id===e?f:m))},onError:M(s,"Failed to update connection")}),{mutateAsync:d}=S.useMutation({mutationFn:async()=>E.RemoveConnection(n,e),onSuccess(){s({message:"Connection successfully removed",status:"success"}),r.setQueryData(i,void 0),r.setQueriesData({queryKey:[n,"connection","list"]},f=>f==null?void 0:f.filter(p=>p.id!==e))},onError:M(s,"Failed to remove connection")});return{connection:S.useQuery({queryKey:i,queryFn:async()=>E.GetConnection(n,e)}),startConnection:o,stopConnection:a,updateConnection:c,deleteConnection:d}},$e=t=>[t,"connection","list"],bt=({plugin:t})=>{const e=T(t),n=S.useQueryClient(),{showSnackbar:r}=U(),s=$e(e),{mutateAsync:i}=S.useMutation({mutationFn:async d=>E.StartConnectionWatch(e,d.id),onError:M(r,"Failed to start connection watch")}),{mutateAsync:o}=S.useMutation({mutationFn:async d=>E.StopConnectionWatch(e,d.id),onError:M(r,"Failed to stop connection watch")}),a=l.useCallback(d=>{const u=d.data;console.log("got update to connections",u),n.setQueryData(s,u)},[n,s]);return l.useEffect(()=>{const d=D.On(`${e}/connection/sync`,a);return()=>{d()}},[e,a]),{connections:S.useQuery({queryKey:s,queryFn:async()=>{try{return await E.ListConnections(e)}catch(d){console.log(d),M(r,"Failed to load connections")(d)}return[]},staleTime:3e4,placeholderData:S.keepPreviousData}),startWatch:i,stopWatch:o}},vt=({pluginID:t,connectionID:e})=>{const n=T(t),r=[n,"connection","namespaces",e];return{namespaces:S.useQuery({queryKey:r,queryFn:async()=>E.GetConnectionNamespaces(n,e)})}},P=ct.withLegacyNames(N.WatchState,"WatchState");function ye(t){const e=Object.values(t.states),n=e.length;let r=0,s=0,i=0,o=0;for(const u of e)u===P.WatchStateSynced&&r++,(u===P.WatchStateError||u===P.WatchStateFailed)&&s++,u===P.WatchStateForbidden&&i++,u===P.WatchStateSkipped&&o++;const a=n-o,c=e.filter(u=>u===P.WatchStateSynced||u===P.WatchStateError||u===P.WatchStateStopped||u===P.WatchStateFailed||u===P.WatchStateForbidden).length,d=a>0?c/a:0;return{pluginID:t.pluginID,connectionID:t.connectionID,totalResources:n,watchedTotal:a,syncedCount:r,errorCount:s,forbiddenCount:i,skippedCount:o,doneCount:c,progress:d}}function ee(t){return t.watchedTotal>0&&t.doneCount>=t.watchedTotal}function Qe(t){return t.some(e=>!ee(e))}function je(t){const e=t.reduce((r,s)=>r+s.watchedTotal,0);return e===0?0:t.reduce((r,s)=>r+s.doneCount,0)/e}function me(t){return`${t.pluginId}/${t.connection}`}function We(t,e){const n=me(e);t.has(n)||t.set(n,{states:{},pluginID:e.pluginId,connectionID:e.connection});const r=t.get(n);return r.states[e.resourceKey]=e.state,r}function It(){const[t,e]=l.useState(new Set),[n,r]=l.useState({}),[s,i]=l.useState(new Map),o=l.useRef(new Map),[a,c]=l.useState(new Map);l.useEffect(()=>{const C=D.On("plugin/crash_recovery_failed",O=>{const w=O.data,R=w==null?void 0:w.pluginID;R&&c(I=>{const A=new Map(I);return A.set(R,w.error??"Crash recovery failed"),A})}),v=D.On("plugin/recovered",O=>{const w=O.data,R=w==null?void 0:w.pluginID;R&&c(I=>{if(!I.has(R))return I;const A=new Map(I);return A.delete(R),A})});return()=>{C(),v()}},[]),l.useEffect(()=>{E.GetAllConnectionStates().then(C=>{if(!C)return;const v={},O=new Set,w=new Map;for(const[R,I]of Object.entries(C))if(I){v[R]=I.map(A=>A.connection);for(const A of I){if(!A.started)continue;const q=`${R}/${A.connection.id}`;O.add(q);const k={pluginID:R,connectionID:A.connection.id,states:{}};if(A.resources)for(const[ie,st]of Object.entries(A.resources))k.states[ie]=st;o.current.set(q,k),w.set(q,ye(k))}}r(v),e(O),i(w)}).catch(()=>{})},[]),l.useEffect(()=>D.On("connection/status",v=>{const O=v.data,w=`${O.pluginID}/${O.connectionID}`;O.status==="DISCONNECTED"?(e(R=>{const I=new Set(R);return I.delete(w),I}),i(R=>{const I=new Map(R);return I.delete(w),I}),o.current.delete(w)):e(R=>{const I=new Set(R);return I.add(w),I}),E.ListAllConnections().then(R=>{if(!R)return;const I={};for(const[A,q]of Object.entries(R))q!=null&&(I[A]=q);r(I)}).catch(()=>{})}),[]);const d=l.useCallback(C=>{const v=C.data,O=me(v);e(I=>{if(I.has(O))return I;const A=new Set(I);return A.add(O),A});const w=We(o.current,v),R=ye(w);i(I=>{const A=new Map(I);return A.set(O,R),A})},[]);l.useEffect(()=>D.On("watch/STATE",d),[d]);const u=l.useCallback(async(C,v)=>{await E.StopConnection(C,v)},[]),f=l.useCallback(async(C,v)=>{await E.StartConnectionWatch(C,v)},[]),p=l.useCallback(async C=>{const v=a.get(C);c(O=>{if(!O.has(C))return O;const w=new Map(O);return w.delete(C),w});try{await E.RetryFailedPlugin(C)}catch(O){throw c(w=>{const R=new Map(w);return R.set(C,v??"Reload failed"),R}),O}},[a]),y=[];for(const C of t){const[v,O]=C.split("/",2),R=(n[v]??[]).find(ie=>ie.id===O),I=s.get(C),A=I!=null&&!ee(I),q=I!=null&&I.errorCount>0,k=a.get(v);y.push({pluginID:v,connectionID:O,name:(R==null?void 0:R.name)??O,avatar:(R==null?void 0:R.avatar)??"",isStarted:!0,sync:I,isSyncing:A,hasErrors:q||k!=null,pluginFailed:k!=null,pluginError:k})}const m=new Map;for(const C of y){const v=m.get(C.pluginID)??[];v.push(C),m.set(C.pluginID,v)}const _=Array.from(s.values()),g=y.filter(C=>C.isSyncing),h=y.filter(C=>C.hasErrors),b=y.filter(C=>C.pluginFailed);return{entries:y,grouped:m,connectedCount:y.length,syncingCount:g.length,errorCount:h.length,failedCount:b.length,hasSyncing:Qe(_),aggregateProgress:je(_),disconnect:u,retryWatch:f,retryPlugin:p}}function Ot(t,e){return e===null?t===null:Array.isArray(e)?Array.isArray(t):typeof e=="object"?typeof t=="object"&&t!==null&&!Array.isArray(t):typeof t==typeof e}function Pt(t,e,n){const r=T(t),s=S.useQueryClient(),i=[r,"data",e],o=S.useQuery({queryKey:i,queryFn:async()=>{const c=await E.Get(r,e);return c==null?n:Ot(c,n)?c:(console.warn(`[usePluginData] stored value for "${e}" has unexpected type (expected ${Array.isArray(n)?"array":typeof n}, got ${Array.isArray(c)?"array":typeof c}). Using default.`),n)}}),a=S.useMutation({mutationFn:async c=>{await E.Set(r,e,c)},onMutate:async c=>{await s.cancelQueries({queryKey:i});const d=s.getQueryData(i);return s.setQueryData(i,c),{previous:d}},onError:(c,d,u)=>{(u==null?void 0:u.previous)!==void 0&&s.setQueryData(i,u.previous)},onSettled:()=>{s.invalidateQueries({queryKey:i})}});return{data:o.data??n,update:async c=>{await a.mutateAsync(c)},isLoading:o.isLoading}}const At=()=>{const t=l.useContext(xe);if(!t)throw new Error("useRightDrawer must be used within a RightDrawerProvider");return t},Ee=()=>{const t=l.useContext(Fe);if(t===void 0)throw new Error("useBottomDrawer must be used within a BottomDrawerProvider");return t},Tt=({pluginID:t})=>{const e=T(t),{showSnackbar:n}=U(),{createTab:r,updateTab:s}=Ee();return{createSession:S.useMutation({mutationFn:async({connectionID:o,icon:a,label:c,opts:d})=>{const u=`pending-${crypto.randomUUID()}`;r({id:u,title:c??"Connecting...",variant:"terminal",icon:a??"LuSquareTerminal",properties:{status:"connecting",pluginID:e,connectionID:o,opts:{...d}}});const f=N.SessionOptions.createFrom({command:["/bin/bash"],tty:!0,...d});try{const p=await E.CreateSession(e,o,f);if(!p)throw new Error("Failed to create session: null response");s({id:u},{id:p.id,title:c??`Session ${p.id.substring(0,8)}`,properties:{status:"connected",pluginID:e,connectionID:o,opts:{...d}}})}catch(p){const y=Q(p);s({id:u},{properties:{status:"error",error:y.detail,pluginID:e,connectionID:o,opts:{...d}}}),j(n,p,"Failed to start session")}}}).mutateAsync}},Dt=({pluginID:t})=>{const e=T(t),{showSnackbar:n}=U(),{createTab:r}=Ee(),s=S.useMutation({mutationFn:async({connectionID:o,resourceKey:a,resourceID:c,resourceData:d,icon:u,label:f,target:p,follow:y=!0,tailLines:m=1e3,params:_})=>{const g=N.CreateSessionOptions.createFrom({resource_key:a,resource_id:c,resource_data:d,options:N.LogSessionOptions.createFrom({target:p??"",follow:y,include_previous:!1,include_timestamps:!0,tail_lines:m,since_seconds:0,limit_bytes:0,include_source_events:!0,params:_??{}})}),h=await E.CreateSession$1(e,o,g);if(!h)throw new Error("Failed to create log session: null response");return r({id:h.id,title:f??`Logs ${h.id.substring(0,8)}`,variant:"logs",icon:u??"LuLogs"}),h},onError:M(n,"Failed to start log session")}),i=S.useMutation({mutationFn:async o=>{await E.CloseSession(o)},onError:M(n,"Failed to close log session")});return{createLogSession:s.mutateAsync,closeLogSession:i.mutateAsync}},Ft=()=>S.useQuery({queryKey:["metric","providers"],queryFn:E.GetProviders,staleTime:3e4}),Ge=t=>S.useQuery({queryKey:["metric","providers",t],queryFn:()=>E.GetProvidersForResource(t),enabled:!!t,staleTime:3e4}),xt=t=>{var g,h;const{connectionID:e,resourceKey:n,resourceID:r,resourceNamespace:s="",resourceData:i={},metricIDs:o=[],shape:a=0,timeRange:c,refreshInterval:d=0,enabled:u=!0}=t,{data:f,isLoading:p}=Ge(n),y=f??[],m=c?Math.max(Math.floor((c.end.getTime()-c.start.getTime())/250),15e3)*1e6:0,_=S.useQuery({queryKey:["metric","query",e,n,r,s,o,a,(g=c==null?void 0:c.start)==null?void 0:g.getTime(),(h=c==null?void 0:c.end)==null?void 0:h.getTime()],queryFn:async()=>{const b=await E.QueryAll(e,n,r,s,i,o,a,((c==null?void 0:c.start)??new Date(0)).toISOString(),((c==null?void 0:c.end)??new Date(0)).toISOString(),m),C={};for(const[v,O]of Object.entries(b))O!=null&&(C[v]=O);return C},enabled:u&&!!e&&!!n&&(n.startsWith("cluster::")||!!r)&&y.length>0,refetchInterval:d>0?d:void 0,staleTime:5e3,placeholderData:S.keepPreviousData});return{data:_.data??void 0,providers:y,isLoading:p||_.isLoading,error:_.error,refetch:_.refetch}},Nt=t=>{const{pluginID:e,connectionID:n,resourceKey:r,resourceID:s,resourceNamespace:i="",resourceData:o={},metricIDs:a=[],interval:c=1e4,enabled:d=!0}=t,u=T(e),[f,p]=l.useState(null),[y,m]=l.useState(null),[_,g]=l.useState(!1),[h,b]=l.useState(null),C=l.useRef(null),v=l.useCallback(async()=>{if(!(!d||!u||!n||!r||!s))try{const w=await E.Subscribe(u,n,{resource_key:r,resource_id:s,resource_namespace:i,resource_data:o,metric_ids:a,interval:c*1e6});m(w),g(!0),b(null);const R=D.On(`core/metrics/data/${w}`,A=>{const q=A.data;try{const k=JSON.parse(q);k.results&&p(k.results)}catch(k){console.error("Failed to parse metric stream data:",k)}}),I=D.On(`core/metrics/error/${w}`,A=>{const q=A.data;try{const k=JSON.parse(q);b(k.error||"Unknown error")}catch{b("Failed to parse metric stream error")}});C.current=()=>{R(),I()}}catch(w){b(w instanceof Error?w.message:String(w))}},[u,n,r,s,i,a,c,d]),O=l.useCallback(async()=>{if(y)try{await E.Unsubscribe(y)}catch(w){console.error("Failed to unsubscribe:",w)}C.current&&(C.current(),C.current=null),m(null),g(!1)},[y]);return l.useEffect(()=>()=>{y&&E.Unsubscribe(y).catch(console.error),C.current&&C.current()},[y]),{data:f,subscriptionID:y,isStreaming:_,error:h,start:v,stop:O}},W=["networker","portforward","all-sessions"];function Lt(){const{showSnackbar:t}=U(),e=S.useQueryClient(),n=S.useQuery({queryKey:[...W],queryFn:async()=>E.ListAllPortForwardSessions().catch(i=>{if(Q(i).detail.includes("not found"))return[];throw i}),retry:!1});l.useEffect(()=>{const i=D.On("core/networker/portforward/created",()=>{e.invalidateQueries({queryKey:[...W]})}),o=D.On("core/networker/portforward/closed",()=>{e.invalidateQueries({queryKey:[...W]})});return()=>{i(),o()}},[e]);const r=n.data??[],s=S.useMutation({mutationFn:async i=>E.ClosePortForwardSession(i),onError:M(t,"Failed to close port forwarding session"),onSuccess:async()=>{await e.invalidateQueries({queryKey:[...W]})}});return{sessions:n,activeSessions:r,closeSession:s.mutateAsync,openInBrowser:i=>D.OpenURL(`http://localhost:${i}`)}}function Mt({pluginID:t,connectionID:e,resourceID:n}){const r=T(t),s=["networker","portforward","sessions",r,e,n],{showSnackbar:i}=U(),o=S.useQueryClient(),a=S.useQuery({queryKey:s,queryFn:async()=>E.FindPortForwardSessions(r,e,N.FindPortForwardSessionRequest.createFrom({resource_id:n,connection_id:e})).catch(u=>{const f=Q(u);return f.detail.includes("not found")?[]:(i({message:"Failed to fetch port forward sessions",status:"error",details:f.detail}),[])}),retry:!1}),c=S.useMutation({mutationFn:async({opts:u})=>{const f=N.PortForwardSessionOptions.createFrom({local_port:u.localPort||0,remote_port:u.remotePort,protocol:u.protocol||"TCP",connection_type:"RESOURCE",connection:{resource_data:u.resource,connection_id:e,plugin_id:r,resource_id:u.resourceId,resource_key:u.resourceKey},labels:u.labels??{},params:u.parameters??{}}),p=await E.StartResourcePortForwardingSession(r,e,f);if(!p)throw new Error("Failed to start port forwarding: null response");return u.openInBrowser&&D.OpenURL(`http://localhost:${p.local_port}`),p},onError:M(i,"Failed to start port forwarding session"),onSuccess:async()=>{await Promise.all([o.invalidateQueries({queryKey:s}),o.invalidateQueries({queryKey:[...W]})])}}),d=S.useMutation({mutationFn:async({opts:u})=>E.ClosePortForwardSession(u.sessionID),onError:M(i,"Failed to close port forwarding session"),onSuccess:async()=>{await Promise.all([o.invalidateQueries({queryKey:s}),o.invalidateQueries({queryKey:[...W]})])}});return{sessions:a,forward:c.mutateAsync,close:d.mutateAsync}}const kt=()=>{const t=l.useContext(Ne);if(!t)throw new Error("useConfirmationModal must be used within a ConfirmationModalProvider");return t},qt=({pluginID:t,connectionID:e,resourceKey:n,resourceID:r,namespace:s=""})=>{const i=T(t),o=S.useQueryClient(),{showSnackbar:a}=U(),c=["RESOURCE",i,e,n,r,s],{mutateAsync:d}=S.useMutation({mutationFn:async p=>E.Update(i,e,n,N.UpdateInput.createFrom({input:p.input,id:r,namespace:s})),onSuccess:async()=>{a(`Resource ${r} updated`,"success"),await o.invalidateQueries({queryKey:c})},onError:M(a,`Failed to update resource ${r}`)}),{mutateAsync:u}=S.useMutation({mutationFn:async(p={})=>E.Delete(i,e,n,N.DeleteInput.createFrom({id:r,namespace:s,gracePeriodSeconds:p.gracePeriodSeconds})),onSuccess:async()=>{a(`Resource ${r} deleted`,"success"),await o.invalidateQueries({queryKey:c})},onError:M(a,`Failed to delete resource ${r}`)});return{resource:S.useQuery({queryKey:c,queryFn:async()=>E.Get$1(i,e,n,N.GetInput.createFrom({id:r,namespace:s})),retry:!1}),update:d,remove:u}},Ut=t=>{const e=["component",t.plugin,t.resource,t.area];return{component:S.useQuery({queryKey:e,queryFn:async()=>E.GetResourceAreaComponent(t)})}},$t=({pluginID:t,connectionID:e})=>{const n=T(t),r=[n,"resource_groups","list"];return{groups:S.useQuery({queryKey:r,queryFn:async()=>E.GetResourceGroups(n,e),retry:!1})}},Qt=({pluginID:t,connectionID:e,searches:n})=>{const r=T(t),s=o=>[r,e,o.key,o.namespaces,"list"];return S.useQueries({queries:n.map(o=>({queryKey:s(o),queryFn:async()=>E.List(r,e,o.key,N.ListInput.createFrom({order:[{field:"name",descending:!1}],pagination:{page:1,pageSize:200},namespaces:o.namespaces})).then(a=>a?(console.log(a.result),a.result&&o.postFilter?Object.values(a.result).filter(o.postFilter):Object.values(a.result||{})):[]),retry:!1}))})},jt=({pluginID:t,resourceKey:e})=>{const n=T(t),r=[n,"resources",e];return{resourceType:S.useQuery({queryKey:r,queryFn:async()=>E.GetResourceType(n,e),retry:!1})}},Wt=({pluginID:t,connectionID:e})=>{const n=T(t),r=[n,"resources","list",e];return{types:S.useQuery({queryKey:r,queryFn:async()=>E.GetResourceTypes(n,e),retry:!1})}};var J=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Gt(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Kt="Expected a function",Ke="__lodash_hash_undefined__",Bt="[object Function]",Ht="[object GeneratorFunction]",zt="[object Symbol]",Vt=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Yt=/^\w*$/,Jt=/^\./,Xt=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Zt=/[\\^$.*+?()[\]{}|]/g,en=/\\(\\)?/g,tn=/^\[object .+?Constructor\]$/,nn=typeof J=="object"&&J&&J.Object===Object&&J,rn=typeof self=="object"&&self&&self.Object===Object&&self,Se=nn||rn||Function("return this")();function sn(t,e){return t==null?void 0:t[e]}function on(t){var e=!1;if(t!=null&&typeof t.toString!="function")try{e=!!(t+"")}catch{}return e}var an=Array.prototype,cn=Function.prototype,Be=Object.prototype,de=Se["__core-js_shared__"],ve=function(){var t=/[^.]+$/.exec(de&&de.keys&&de.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(),He=cn.toString,Ce=Be.hasOwnProperty,ze=Be.toString,un=RegExp("^"+He.call(Ce).replace(Zt,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Ie=Se.Symbol,ln=an.splice,dn=Ve(Se,"Map"),V=Ve(Object,"create"),Oe=Ie?Ie.prototype:void 0,Pe=Oe?Oe.toString:void 0;function G(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function fn(){this.__data__=V?V(null):{}}function pn(t){return this.has(t)&&delete this.__data__[t]}function yn(t){var e=this.__data__;if(V){var n=e[t];return n===Ke?void 0:n}return Ce.call(e,t)?e[t]:void 0}function gn(t){var e=this.__data__;return V?e[t]!==void 0:Ce.call(e,t)}function hn(t,e){var n=this.__data__;return n[t]=V&&e===void 0?Ke:e,this}G.prototype.clear=fn;G.prototype.delete=pn;G.prototype.get=yn;G.prototype.has=gn;G.prototype.set=hn;function B(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function mn(){this.__data__=[]}function En(t){var e=this.__data__,n=re(e,t);if(n<0)return!1;var r=e.length-1;return n==r?e.pop():ln.call(e,n,1),!0}function Sn(t){var e=this.__data__,n=re(e,t);return n<0?void 0:e[n][1]}function Cn(t){return re(this.__data__,t)>-1}function _n(t,e){var n=this.__data__,r=re(n,t);return r<0?n.push([t,e]):n[r][1]=e,this}B.prototype.clear=mn;B.prototype.delete=En;B.prototype.get=Sn;B.prototype.has=Cn;B.prototype.set=_n;function K(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function wn(){this.__data__={hash:new G,map:new(dn||B),string:new G}}function Rn(t){return se(this,t).delete(t)}function bn(t){return se(this,t).get(t)}function vn(t){return se(this,t).has(t)}function In(t,e){return se(this,t).set(t,e),this}K.prototype.clear=wn;K.prototype.delete=Rn;K.prototype.get=bn;K.prototype.has=vn;K.prototype.set=In;function re(t,e){for(var n=t.length;n--;)if(kn(t[n][0],e))return n;return-1}function On(t,e){e=Dn(e,t)?[e]:Tn(e);for(var n=0,r=e.length;t!=null&&n<r;)t=t[Ln(e[n++])];return n&&n==r?t:void 0}function Pn(t){if(!Je(t)||xn(t))return!1;var e=qn(t)||on(t)?un:tn;return e.test(Mn(t))}function An(t){if(typeof t=="string")return t;if(we(t))return Pe?Pe.call(t):"";var e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function Tn(t){return Ye(t)?t:Nn(t)}function se(t,e){var n=t.__data__;return Fn(e)?n[typeof e=="string"?"string":"hash"]:n.map}function Ve(t,e){var n=sn(t,e);return Pn(n)?n:void 0}function Dn(t,e){if(Ye(t))return!1;var n=typeof t;return n=="number"||n=="symbol"||n=="boolean"||t==null||we(t)?!0:Yt.test(t)||!Vt.test(t)||e!=null&&t in Object(e)}function Fn(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}function xn(t){return!!ve&&ve in t}var Nn=_e(function(t){t=$n(t);var e=[];return Jt.test(t)&&e.push(""),t.replace(Xt,function(n,r,s,i){e.push(s?i.replace(en,"$1"):r||n)}),e});function Ln(t){if(typeof t=="string"||we(t))return t;var e=t+"";return e=="0"&&1/t==-1/0?"-0":e}function Mn(t){if(t!=null){try{return He.call(t)}catch{}try{return t+""}catch{}}return""}function _e(t,e){if(typeof t!="function"||e&&typeof e!="function")throw new TypeError(Kt);var n=function(){var r=arguments,s=e?e.apply(this,r):r[0],i=n.cache;if(i.has(s))return i.get(s);var o=t.apply(this,r);return n.cache=i.set(s,o),o};return n.cache=new(_e.Cache||K),n}_e.Cache=K;function kn(t,e){return t===e||t!==t&&e!==e}var Ye=Array.isArray;function qn(t){var e=Je(t)?ze.call(t):"";return e==Bt||e==Ht}function Je(t){var e=typeof t;return!!t&&(e=="object"||e=="function")}function Un(t){return!!t&&typeof t=="object"}function we(t){return typeof t=="symbol"||Un(t)&&ze.call(t)==zt}function $n(t){return t==null?"":An(t)}function Qn(t,e,n){var r=t==null?void 0:On(t,e);return r===void 0?n:r}var jn=Qn;const X=Gt(jn);function Xe(t,e,n){const r=t??{result:[],success:!0,totalCount:0},s=[...r.result??[]];for(const i of e){const o=X(i.payload.data,n);switch(i.type){case"ADD":{s.findIndex(c=>X(c,n)===o)===-1&&s.push(i.payload.data);break}case"UPDATE":{const a=s.findIndex(c=>X(c,n)===o);a!==-1&&(s[a]=i.payload.data);break}case"DELETE":{const a=s.findIndex(c=>X(c,n)===o);a!==-1&&s.splice(a,1);break}}}return{...r,result:s}}function Ze(t,e,n,r,s,i){const o=(i==null?void 0:i.syncWindowMs)??500,a=l.useRef([]),c=l.useRef(null),d=l.useRef(null),u=l.useRef(s);u.current=s;const f=l.useCallback(()=>{const y=a.current;if(a.current=[],c.current!==null&&(clearTimeout(c.current),c.current=null),d.current!==null&&(cancelAnimationFrame(d.current),d.current=null),!(y.length===0||!r)){t.setQueryData(e,m=>Xe(m,y,r));for(const m of y)(m.type==="ADD"||m.type==="UPDATE")&&t.setQueryData(n(m.payload.id,m.payload.namespace),{result:m.payload.data})}},[t,e,n,r]),p=l.useCallback(y=>{a.current.push(y),!(c.current!==null||d.current!==null)&&(c.current=setTimeout(f,o),u.current!==1&&(d.current=requestAnimationFrame(f)))},[f,o]);return l.useEffect(()=>()=>{c.current!==null&&(clearTimeout(c.current),c.current=null),d.current!==null&&(cancelAnimationFrame(d.current),d.current=null)},[]),p}const Wn=({pluginID:t,connectionID:e,resourceKey:n,idAccessor:r,namespaces:s})=>{const i=T(t),o=S.useQueryClient(),{showSnackbar:a}=U(),c=l.useMemo(()=>s??[],[s]),d=l.useMemo(()=>[i,e,n,c,"list"],[i,e,n,c]),u=l.useCallback((g,h)=>[i,e,n,h,g],[i,e,n]),{mutateAsync:f}=S.useMutation({mutationFn:async g=>E.Create(i,e,n,N.CreateInput.createFrom({input:g.input,namespace:g.namespace??(c.length===1?c[0]:"")})),onSuccess:async g=>{var v;const h=g==null?void 0:g.result;let b="";(v=h==null?void 0:h.metadata)!=null&&v.name?b=h.metadata.name:h!=null&&h.id?b=h.id:h!=null&&h.name?b=h.name:h!=null&&h.ID?b=h.ID:h!=null&&h.Name&&(b=h.Name);const C=b?`Resource ${b} created`:"Resource created";a(C,"success"),await o.invalidateQueries({queryKey:d})},onError:M(a,"Failed to create resource")}),p=S.useQuery({queryKey:d,queryFn:async()=>E.List(i,e,n,N.ListInput.createFrom({order:[{field:"name",descending:!1}],pagination:{page:1,pageSize:200},namespaces:c})),placeholderData:(g,h)=>g,retry:!1}),[y,m]=l.useState(P.WatchStateIdle);l.useEffect(()=>D.On(`${i}/${e}/watch/STATE`,h=>{const b=h.data;b.resourceKey===n&&m(b.state)}),[i,e,n]);const _=Ze(o,d,u,r,y);return l.useEffect(()=>{if(!r)return;E.SubscribeResource(i,e,n);const g=D.On(`${i}/${e}/${n}/ADD`,C=>_({type:"ADD",payload:C.data})),h=D.On(`${i}/${e}/${n}/UPDATE`,C=>_({type:"UPDATE",payload:C.data})),b=D.On(`${i}/${e}/${n}/DELETE`,C=>_({type:"DELETE",payload:C.data}));return()=>{g(),h(),b(),E.UnsubscribeResource(i,e,n)}},[i,e,n,_]),{resources:p,create:f,watchState:y,isSyncing:y===P.WatchStateSyncing,isSynced:y===P.WatchStateSynced,watchError:y===P.WatchStateError}},Gn=({pluginID:t})=>{const e=T(t),{showSnackbar:n}=U(),r=S.useMutation({mutationFn:async({opts:o,input:a})=>E.Create(e,o.connectionID,o.resourceKey,N.CreateInput.createFrom({input:a.input,namespace:a.namespace??o.namespace??""})),onSuccess:(o,{opts:a})=>{n(`Resource ${a.resourceID} created`,"success")},onError(o,{opts:a}){j(n,o,`Failed to create resource ${a.resourceID}`)}}),s=S.useMutation({mutationFn:async({opts:o,input:a})=>E.Update(e,o.connectionID,o.resourceKey,N.UpdateInput.createFrom({input:a.input,id:o.resourceID,namespace:o.namespace??""})),onSuccess:(o,{opts:a})=>{n(`Resource ${a.resourceID} updated`,"success")},onError(o,{opts:a}){j(n,o,`Failed to update resource ${a.resourceID}`)}}),i=S.useMutation({mutationFn:async({opts:o,input:a})=>E.Delete(e,o.connectionID,o.resourceKey,N.DeleteInput.createFrom({id:o.resourceID,namespace:o.namespace??"",gracePeriodSeconds:a.gracePeriodSeconds})),onSuccess:(o,{opts:a})=>{n(`Resource ${a.resourceID} deleted`,"success")},onError(o,{opts:a}){j(n,o,`Failed to delete resource ${a.resourceID}`)}});return{create:r.mutateAsync,update:s.mutateAsync,remove:i.mutateAsync}},Kn=({pluginID:t,connectionID:e,resourceKey:n,enabled:r=!0})=>{const s=T(t),i=S.useQuery({queryKey:["RESOURCE_ACTIONS",s,e,n],queryFn:()=>E.GetActions(s,e,n),enabled:r&&!!s&&!!e&&!!n,staleTime:5*60*1e3});return{actions:i.data??[],isLoading:i.isLoading,error:i.error}},Bn=({pluginID:t,connectionID:e,resourceKey:n})=>{const r=T(t),s=S.useQueryClient(),{showSnackbar:i}=U(),o=S.useMutation({mutationFn:async({actionID:a,id:c="",namespace:d="",params:u={}})=>E.ExecuteAction(r,e,n,a,N.ActionInput.createFrom({id:c,namespace:d,params:u})),onSuccess:a=>{a!=null&&a.message&&i(a.message,"success"),s.invalidateQueries({queryKey:["RESOURCES",r,e,n]})},onError:(a,c)=>{j(i,a,`Failed to execute action "${c.actionID}"`)}});return{executeAction:o.mutateAsync,isExecuting:o.isPending,error:o.error}},Hn=({pluginID:t,connectionID:e,enabled:n=!0})=>{const r=T(t),s=S.useQuery({queryKey:["EDITOR_SCHEMAS",r,e],queryFn:()=>E.GetEditorSchemas(r,e),enabled:n&&!!r&&!!e,staleTime:10*60*1e3,retry:1});return{schemas:s.data??[],isLoading:s.isLoading,error:s.error,refetch:s.refetch}},zn=({pluginID:t,connectionID:e,enabled:n=!0})=>{const r=T(t),s=S.useQueryClient(),i=[r,e,"watch-state"],o=l.useRef([]),a=l.useRef(!1),c=l.useCallback(p=>{s.setQueryData(i,y=>{if(!y)return y;const m={...y.resources,[p.resourceKey]:p.state},_={...y.resourceCounts,[p.resourceKey]:p.resourceCount};let g=0,h=0;for(const b of Object.values(m))b===P.WatchStateSynced&&g++,(b===P.WatchStateError||b===P.WatchStateFailed)&&h++;return{...y,resources:m,resourceCounts:_,totalResources:Object.keys(m).length,syncedCount:g,errorCount:h}})},[s,r,e]),d=S.useQuery({queryKey:i,queryFn:async()=>{const p=await E.GetWatchState(r,e);if(!p)throw new Error("Failed to get watch state: null response");const y={};let m=0,_=0;for(const[h,b]of Object.entries(p.resources??{}))b!=null&&(y[h]=b,b===P.WatchStateSynced&&m++,b===P.WatchStateError&&_++);const g={};for(const[h,b]of Object.entries(p.resourceCounts??{}))b!=null&&(g[h]=b);return{connection:p.connectionId,resources:y,resourceCounts:g,totalResources:Object.keys(y).length,syncedCount:m,errorCount:_}},enabled:n&&!!r&&!!e,refetchInterval:p=>{const y=p.state.data;if(!y||y.totalResources===0)return 3e3;let m=0;for(const _ of Object.values(y.resources))(_===P.WatchStateSynced||_===P.WatchStateError||_===P.WatchStateStopped||_===P.WatchStateFailed||_===P.WatchStateForbidden||_===P.WatchStateSkipped)&&m++;return m>=y.totalResources?!1:3e3}});l.useEffect(()=>{if(!d.data||a.current)return;a.current=!0;const p=o.current;o.current=[];for(const y of p)c(y)},[d.data,c]),l.useEffect(()=>{if(!n||!r||!e)return;a.current=!1,o.current=[];const p=D.On(`${r}/${e}/watch/STATE`,y=>{const m=y.data;a.current?c(m):o.current.push(m)});return()=>{p(),a.current=!1,o.current=[]}},[r,e,n,c]);const u=d.data;let f=0;if(u!=null&&u.resources)for(const p of Object.values(u.resources))(p===P.WatchStateSynced||p===P.WatchStateError||p===P.WatchStateStopped||p===P.WatchStateFailed||p===P.WatchStateForbidden||p===P.WatchStateSkipped)&&f++;return{summary:d,getResourceState:p=>u==null?void 0:u.resources[p],isFullySynced:u?u.totalResources>0&&f===u.totalResources:!1,syncProgress:u&&u.totalResources>0?f/u.totalResources:0,errorCount:(u==null?void 0:u.errorCount)??0}},Vn=()=>{const[t,e]=l.useState(new Map),n=l.useRef(new Map),r=l.useRef(new Map),s=l.useCallback(d=>{const u=d.data,f=me(u),p=We(n.current,u),y=ye(p);if(e(m=>{const _=new Map(m);return _.set(f,y),_}),r.current.has(f)&&(clearTimeout(r.current.get(f)),r.current.delete(f)),ee(y)){const m=setTimeout(()=>{e(_=>{const g=new Map(_);return g.delete(f),g}),n.current.delete(f),r.current.delete(f)},5e3);r.current.set(f,m)}},[]);l.useEffect(()=>{const d=D.On("watch/STATE",s);return()=>{d();for(const u of r.current.values())clearTimeout(u)}},[s]);const i=Array.from(t.values()),o=Qe(i),a=i.find(d=>!ee(d))??i[0]??null,c=je(i);return{syncs:i,hasSyncing:o,primarySync:a,aggregateProgress:c}},et=()=>{const t=l.useContext(he);if(!t)throw new Error("useOperations must be used within an OperationsProvider");return t},Yn=({pluginID:t,connectionID:e,resourceKey:n})=>{const r=T(t),{showSnackbar:s}=U(),{addOperation:i,updateOperation:o}=et(),a=l.useRef(new Set),c=l.useCallback((f,p=!1)=>{var y,m,_;f.disposed||(f.disposed=!0,(y=f.unsubscribe)==null||y.call(f),(m=f.open)==null||m.cancel(),(_=f.attach)==null||_.cancel(),f.handle&&(E.CancelStreamAction(f.handle).catch(()=>{}),p&&o(f.handle,{status:"cancelled",message:"Cancelled",completedAt:Date.now()})),a.current.delete(f))},[o]);l.useEffect(()=>()=>{for(const f of a.current)c(f,!0)},[r,e,n,c]);const d=l.useCallback(async({actionID:f,id:p,namespace:y,label:m,params:_={}})=>{const g={disposed:!1,terminal:!1,sequence:0};a.current.add(g);try{g.open=E.StreamAction(r,e,n,f,N.ActionInput.createFrom({id:p,namespace:y,params:_}));const h=await g.open;if(g.open=void 0,g.disposed)return E.CancelStreamAction(h).catch(()=>{}),h;g.handle=h,i({id:h,label:m,resourceKey:n,resourceName:p,namespace:y,connectionID:e,status:"running",startedAt:Date.now()});const b=v=>{if(g.disposed||!Number.isSafeInteger(v.sequence)||v.sequence<=g.sequence)return;g.sequence=v.sequence;const O=v.event,w=O.data??{};if(O.type==="error"){g.terminal=!0;const R=Q(O.error);o(h,{status:z(R)?"cancelled":"error",message:R.title,completedAt:Date.now()}),j(s,R,m),c(g)}else if(O.type==="complete"){g.terminal=!0;const R=typeof w.message=="string"?w.message:`${m} completed`;o(h,{status:"completed",message:R,completedAt:Date.now()}),s(R,"success"),c(g)}else o(h,{message:typeof w.message=="string"?w.message:void 0,progress:typeof w.ready=="number"&&typeof w.desired=="number"?{ready:w.ready,desired:w.desired}:void 0})};g.unsubscribe=D.On(`action/stream/${h}`,v=>b(v.data)),g.attach=E.AttachStreamAction(h);const C=await g.attach;return g.attach=void 0,b(C),h}catch(h){if(g.terminal&&g.handle)return g.handle;throw g.disposed||(g.handle&&o(g.handle,{status:z(h)?"cancelled":"error",message:Q(h).title,completedAt:Date.now()}),j(s,h,`Failed to start "${f}"`)),c(g),h}},[r,e,n,i,o,s,c]),u=l.useCallback(f=>{for(const p of a.current)if(p.handle===f){c(p,!0);return}},[c]);return{startStreamAction:d,cancelStreamAction:u}};function tt(t,e){return`${t}/${e}/graph/CHANGED`}function oe(t,e,n,r){const s=S.useQueryClient(),i=l.useRef(n);i.current=n;const o=JSON.stringify(n);l.useEffect(()=>{if(!r||!t||!e)return;const a=D.On(tt(t,e),()=>{s.invalidateQueries({queryKey:i.current,exact:!0})});return()=>{a()}},[s,t,e,o,r])}const Jn={owns:{outgoing:"Owns",incoming:"Owned by"},runs_on:{outgoing:"Runs on",incoming:"Running here"},uses:{outgoing:"Uses",incoming:"Used by"},exposes:{outgoing:"Exposes",incoming:"Exposed by"},manages:{outgoing:"Manages",incoming:"Managed by"},member_of:{outgoing:"Member of",incoming:"Members"},selects:{outgoing:"Selects",incoming:"Selected by"}};function Xn(t,e){const n=Jn[t];if(n)return n[e];const r=t.replace(/_/g," ");return e==="outgoing"?r:`${r} (incoming)`}function Zn(t,e){return t.pluginId===e.pluginId&&t.connectionId===e.connectionId&&t.resourceKey===e.resourceKey&&t.id===e.id&&(t.namespace??"")===(e.namespace??"")}function nt(t,e){return e.map(n=>{const r=Zn(n.source,t);return{resource:r?n.target:n.source,type:n.type,direction:r?"outgoing":"incoming",label:n.label}})}const er=({pluginID:t,connectionID:e,resourceKey:n,resourceID:r,namespace:s="",direction:i="both",relationshipType:o,enabled:a=!0,refetchInterval:c=!1})=>{const d=T(t),u=["RESOURCE_RELATED",d,e,n,s,r,i,o??null],f=a&&!!d&&!!e&&!!n&&!!r;oe(d,e,u,f);const p=S.useQuery({queryKey:u,queryFn:async()=>E.GetRelated(d,e,n,s,r,i,o??null),enabled:f,refetchInterval:c}),y={pluginId:d,connectionId:e,resourceKey:n,id:r,namespace:s},m=p.data??[];return{related:nt(y,m),edges:m,isLoading:p.isLoading,isFetching:p.isFetching,error:p.error,refetch:p.refetch}},tr=({pluginID:t,connectionID:e,resourceKey:n,resourceID:r,namespace:s="",maxDepth:i=3,enabled:o=!0,refetchInterval:a=!1})=>{const c=T(t),d=["RESOURCE_DEPENDENCY_TREE",c,e,n,s,r,i],u=o&&!!c&&!!e&&!!n&&!!r;oe(c,e,d,u);const f=S.useQuery({queryKey:d,queryFn:async()=>E.GetDependencyTree(c,e,n,s,r,i),enabled:u,refetchInterval:a});return{tree:f.data??null,isLoading:f.isLoading,isFetching:f.isFetching,error:f.error,refetch:f.refetch}},nr=({pluginID:t,connectionID:e,resourceKey:n,resourceID:r,namespace:s="",upDepth:i=2,downDepth:o=3,enabled:a=!0})=>{const c=T(t),d=["RESOURCE_GRAPH",c,e,n,s,r,i,o],u=a&&!!c&&!!e&&!!n&&!!r;oe(c,e,d,u);const f=S.useQuery({queryKey:d,queryFn:async()=>E.GetSubgraph(c,e,n,s,r,i,o),enabled:u});return{graph:f.data??null,isLoading:f.isLoading,isFetching:f.isFetching,error:f.error,refetch:f.refetch}},rr=()=>{const t=l.useContext(ge);if(!t)throw new Error("useSettings must be used within a SettingsProvider");return t},sr=({to:t,withinContext:e,...n})=>{const{pluginId:r}=ne();r||console.error("Link used outside of a plugin context");const s=`/_plugin/${r}${t.startsWith("/")?"":"/"}${t}`;return l.useMemo(()=>x.jsx(H.Link,{style:{textDecoration:"none",color:"inherit"},...n,to:s}),[n,s])};function or(){const t=H.useNavigate(),e=H.useLocation(),{pluginId:n}=ne();n||console.error("usePluginRouter used outside of a plugin context");const r=`/_plugin/${n}`,s=e.pathname.startsWith(r)?e.pathname.slice(r.length)||"/":e.pathname,i=l.useCallback((o,a)=>{const{...c}=a??{};o.startsWith("/")?t(`${r}${o}`,c):t(o,c)},[t,r]);return l.useMemo(()=>({location:e,navigate:i,pluginPath:s}),[e,i,s])}class ir{}class ar{constructor(){L(this,"_extensions");L(this,"root");L(this,"pages");L(this,"_routes")}get extensions(){return this._extensions||[]}get Routes(){var e;if(!this._routes&&this.root)return[{path:"",index:!0,Component:this.root}];if(!((e=this._routes)!=null&&e.length))throw new Error("cannot use plugin without a root page or router");return this._routes}get Window(){if(!this._routes&&this.root)return x.jsx(this.root,{});const e=H.createMemoryRouter(this._routes||[]);return x.jsx(H.RouterProvider,{router:e})}registerExtensionPoints(e){return this._extensions=e||[],this}setRootPage(e){return this.root=e,this}withPage(e,n){return this.pages||(this.pages={}),this.pages[e]?(console.warn("Cannot register page with the same name. Please use a different name."),this):(this.pages[e]=n,this)}withRoutes(e){return this._routes=e,this}}var rt=(t=>(t.MISSING_MANIFEST="MISSING_MANIFEST",t.MISSING_PLUGIN="MISSING_PLUGIN",t.MISSING_ENTRYPOINT="MISSING_ENTRYPOINT",t))(rt||{});const cr=t=>{const e=t.split("::");return e.length===1?{group:"core",version:"",kind:e[0]}:{group:e[0]||"core",version:e[1]||"",kind:e[2]||e[0]}},ur=t=>!t||t==="core"?"Core":t.charAt(0).toUpperCase()+t.slice(1);exports.ALL_SESSIONS_KEY=W;exports.BottomDrawerContext=Fe;exports.ConfirmationModalContext=Ne;exports.ErrorTypes=F;exports.ExtensionPointRegistry=Ct;exports.ExtensionPointStore=qe;exports.ExtensionProvider=St;exports.Link=sr;exports.OperationsContext=he;exports.OperationsProvider=pt;exports.PluginContext=te;exports.PluginContextProvider=ut;exports.PluginErrorCode=rt;exports.PluginWindow=ar;exports.PluginWindowRootProps=ir;exports.RightDrawerContext=xe;exports.SettingsContext=ge;exports.SettingsProvider=dt;exports.SnackbarProvider=wt;exports.WatchState=P;exports.actionToSnackbar=Ae;exports.applyBatch=Xe;exports.connectionListQueryKey=$e;exports.createErrorHandler=M;exports.defaultState=De;exports.formatGroup=ur;exports.graphChangedEvent=tt;exports.isCancelledError=z;exports.parseAppError=Q;exports.parseResourceKey=cr;exports.relationshipLabel=Xn;exports.showAppError=j;exports.toRelatedResources=nt;exports.useActiveSyncs=Vn;exports.useBottomDrawer=Ee;exports.useConfirmationModal=kt;exports.useConnection=Rt;exports.useConnectionNamespaces=vt;exports.useConnectionStatus=It;exports.useConnections=bt;exports.useDependencyTree=tr;exports.useEditorSchemas=Hn;exports.useEventBatcher=Ze;exports.useExec=Tt;exports.useExecuteAction=Bn;exports.useExtensionPoint=Et;exports.useExtensionRegistry=ke;exports.useLogs=Dt;exports.useMetricProviders=Ft;exports.useMetricProvidersForResource=Ge;exports.useMetricStream=Nt;exports.useOperations=et;exports.usePluginContext=ne;exports.usePluginData=Pt;exports.usePluginRouter=or;exports.usePluginSettings=lt;exports.usePortForwardSessions=Lt;exports.useRefetchOnGraphChange=oe;exports.useRelatedResources=er;exports.useResolvedPluginId=T;exports.useResource=qt;exports.useResourceActions=Kn;exports.useResourceAreaComponent=Ut;exports.useResourceGraph=nr;exports.useResourceGroups=$t;exports.useResourceMetrics=xt;exports.useResourceMutations=Gn;exports.useResourcePortForwarder=Mt;exports.useResourceSearch=Qt;exports.useResourceType=jt;exports.useResourceTypes=Wt;exports.useResources=Wn;exports.useRightDrawer=At;exports.useSettings=rr;exports.useSnackbar=U;exports.useStreamAction=Yn;exports.useWatchState=zn;
|