@corsair-dev/studio 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server/index.js +4 -2
- package/dist/src/server/handlers/credentials-internal.d.ts.map +1 -1
- package/dist/src/server/handlers/credentials.d.ts.map +1 -1
- package/dist/web/assets/{index-BkR9qC-P.js → index-W9OL2bnx.js} +2 -2
- package/dist/web/assets/{index-BkR9qC-P.js.map → index-W9OL2bnx.js.map} +1 -1
- package/dist/web/index.html +1 -1
- package/package.json +4 -4
package/dist/server/index.js
CHANGED
|
@@ -940,7 +940,8 @@ var BASE_FIELDS = {
|
|
|
940
940
|
managed: {
|
|
941
941
|
integration: [],
|
|
942
942
|
account: ["access_token", "refresh_token", "expires_at"]
|
|
943
|
-
}
|
|
943
|
+
},
|
|
944
|
+
managed_pricing: { integration: [], account: [] }
|
|
944
945
|
};
|
|
945
946
|
function getCustomFields(plugin, authType) {
|
|
946
947
|
const authConfig = plugin.authConfig;
|
|
@@ -1011,7 +1012,8 @@ var BASE = {
|
|
|
1011
1012
|
managed: {
|
|
1012
1013
|
integration: [],
|
|
1013
1014
|
account: ["access_token", "refresh_token", "expires_at"]
|
|
1014
|
-
}
|
|
1015
|
+
},
|
|
1016
|
+
managed_pricing: { integration: [], account: [] }
|
|
1015
1017
|
};
|
|
1016
1018
|
var getCredentials = async (ctx) => {
|
|
1017
1019
|
const body = await readJsonBody(ctx.req);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credentials-internal.d.ts","sourceRoot":"","sources":["../../../../src/server/handlers/credentials-internal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAoB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"credentials-internal.d.ts","sourceRoot":"","sources":["../../../../src/server/handlers/credentials-internal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAoB,MAAM,cAAc,CAAC;AAmB/E,MAAM,MAAM,WAAW,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,aAAa,GAAG,SAAS,CAAC;IACjC,GAAG,EAAE,OAAO,CAAC;CACb,CAAC;AAEF,wBAAgB,eAAe,CAC9B,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,SAAS,GACjB;IAAE,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAOhE;AAED,wBAAsB,kBAAkB,CAAC,IAAI,EAAE;IAC9C,QAAQ,EAAE,SAAS,GAAG,SAAS,CAAC;IAChC,gBAAgB,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACrD,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACjD,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,cAAc,CAAC,EAAE,OAAO,CAAC;CACzB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAmCzB;AAYD,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAK7D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../../../../src/server/handlers/credentials.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../../../../src/server/handlers/credentials.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AA4B1C,eAAO,MAAM,cAAc,EAAE,SAuE5B,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,SAmE5B,CAAC"}
|
|
@@ -51,5 +51,5 @@ Error generating stack: `+a.message+`
|
|
|
51
51
|
`).map(m=>m.trim()).filter(Boolean)):Array.isArray(s)?Qd(s.filter(m=>typeof m=="string").map(m=>m.trim()).filter(Boolean)):s??{}}function Qd(s){const m={};for(const y of s){const r=y.split(".",1)[0];r&&(m[r]||(m[r]=[]),m[r].push(y))}for(const y of Object.keys(m)){const r=m[y];r&&r.sort((b,D)=>b.localeCompare(D))}return m}function Vh(s){if(!s)return[];if(Array.isArray(s))return s.filter(m=>!!m&&typeof m=="object"&&!Array.isArray(m));if(typeof s=="object"&&s&&"rows"in s){const m=s.rows;if(Array.isArray(m))return m.filter(y=>!!y&&typeof y=="object"&&!Array.isArray(y))}return[]}function Wu(s){if(s.optional)return null;switch(s.kind){case"string":return"";case"number":return 0;case"boolean":return!1;case"literal":return s.value;case"object":{const m={};for(const[y,r]of Object.entries(s.fields))m[y]=Wu(r);return m}case"array":return[];default:return null}}function Tf(s){if(s!=null){if(Array.isArray(s))return s.map(Tf);if(typeof s=="object"){const m={};for(const[y,r]of Object.entries(s)){const b=Tf(r);b!==void 0&&(m[y]=b)}return m}return s}}function Jh({name:s,schema:m,htmlFor:y}){const r="block text-xs font-medium text-[var(--color-text)] mb-1",b=i.jsxs(i.Fragment,{children:[s,!m.optional&&i.jsx("span",{className:"text-[var(--color-err)] ml-0.5",children:"*"}),m.description&&i.jsx("span",{className:"text-[var(--color-text-muted)] font-normal ml-1.5",children:m.description})]});return y?i.jsx("label",{htmlFor:y,className:r,children:b}):i.jsx("div",{className:r,children:b})}function Kh({id:s,schema:m,value:y,onChange:r}){return m.enum&&m.enum.length>0?i.jsxs("select",{id:s,className:"w-full h-8 px-2 rounded-md text-xs bg-[var(--color-bg)] border border-[var(--color-border)] focus:outline-none focus:border-[var(--color-accent-dim)]",value:String(y??""),onChange:b=>r(b.target.value),children:[i.jsx("option",{value:"",children:"-- select --"}),m.enum.map(b=>i.jsx("option",{value:b,children:b},b))]}):i.jsx(Me,{id:s,type:"text",value:String(y??""),onChange:b=>r(b.target.value)})}function wh({id:s,value:m,onChange:y}){return i.jsx(Me,{id:s,type:"number",value:m==null?"":String(m),onChange:r=>{const b=r.target.value;y(b===""?null:Number(b))}})}function kh({id:s,value:m,onChange:y}){return i.jsxs("div",{className:"inline-flex items-center gap-2 text-xs",children:[i.jsx("input",{id:s,type:"checkbox",className:"accent-[var(--color-accent)]",checked:!!m,onChange:r=>y(r.target.checked)}),i.jsx("span",{className:"text-[var(--color-text-muted)]",children:m?"true":"false"})]})}function wd({schema:s,value:m,onChange:y,path:r}){const b=typeof m=="object"&&m!==null&&!Array.isArray(m)?m:{},D=U.useCallback((N,B)=>{y({...b,[N]:B})},[b,y]);return i.jsx("div",{className:"border border-[var(--color-border)] rounded-md p-3 space-y-3 bg-[var(--color-bg)]/50",children:Object.entries(s.fields).map(([N,B])=>i.jsx(kd,{name:N,schema:B,value:b[N]??Wu(B),onChange:O=>D(N,O),path:`${r}.${N}`},N))})}function $h({schema:s,value:m,onChange:y,path:r}){const b=Array.isArray(m)?m:[],D=U.useCallback(()=>{y([...b,Wu(s.items)])},[b,y,s.items]),N=U.useCallback(O=>{y(b.filter((j,R)=>R!==O))},[b,y]),B=U.useCallback((O,j)=>{const R=[...b];R[O]=j,y(R)},[b,y]);return i.jsxs("div",{className:"space-y-2",children:[b.map((O,j)=>i.jsxs("div",{className:"flex items-start gap-2",children:[i.jsx("div",{className:"flex-1",children:i.jsx(kd,{name:`[${j}]`,schema:s.items,value:O,onChange:R=>B(j,R),path:`${r}[${j}]`})}),i.jsx(Pt,{type:"button",variant:"ghost",className:"mt-5 text-[var(--color-err)] shrink-0",onClick:()=>N(j),children:"Remove"})]},`${r}-${j}`)),i.jsx(Pt,{type:"button",variant:"ghost",onClick:D,children:"+ Add item"})]})}function kd({name:s,schema:m,value:y,onChange:r,path:b=""}){const D=U.useId(),N=m.kind!=="object"&&m.kind!=="array";return i.jsxs("div",{children:[i.jsx(Jh,{name:s,schema:m,htmlFor:N?D:void 0}),m.kind==="string"&&i.jsx(Kh,{id:D,schema:m,value:y,onChange:r}),m.kind==="number"&&i.jsx(wh,{id:D,value:y,onChange:r}),m.kind==="boolean"&&i.jsx(kh,{id:D,value:y,onChange:r}),m.kind==="object"&&i.jsx(wd,{schema:m,value:y,onChange:r,path:b}),m.kind==="array"&&i.jsx($h,{schema:m,value:y,onChange:r,path:b}),m.kind==="literal"&&i.jsx(Me,{id:D,type:"text",value:String(y??m.value),disabled:!0,className:"opacity-70"}),m.kind==="unknown"&&i.jsx(Me,{id:D,type:"text",placeholder:"(unsupported field type — use JSON editor)",disabled:!0})]})}function Wh({schema:s,onChange:m,initialValue:y}){const r=U.useMemo(()=>y&&typeof y=="object"?y:Wu(s),[]),[b,D]=U.useState(r);return U.useEffect(()=>{const N=Tf(b);m(N&&typeof N=="object"&&!Array.isArray(N)?N:{})},[b,m]),s.kind!=="object"?i.jsx("div",{className:"text-xs text-[var(--color-text-muted)]",children:"Top-level schema is not an object. Use the JSON editor."}):i.jsx(wd,{schema:s,value:b,onChange:D,path:""})}function Fh({value:s,onChange:m,rows:y=8}){const[r,b]=U.useState(null),D=U.useCallback(N=>{m(N);try{JSON.parse(N),b(null)}catch(B){b(B.message)}},[m]);return i.jsxs("div",{children:[i.jsx(Ef,{value:s,onChange:N=>D(N.target.value),rows:y,"aria-label":"JSON input",className:"font-mono"}),r&&i.jsxs("div",{className:"text-xs text-[var(--color-err)] mt-1",children:["JSON: ",r]})]})}function Ih({tenant:s}){const[m,y]=U.useState("api"),[r,b]=U.useState(null),[D,N]=U.useState(""),[B,O]=U.useState(null),[j,R]=U.useState(null),[C,V]=U.useState(null),[et,F]=U.useState("form"),[ot,xt]=U.useState({}),[k,it]=U.useState(`{
|
|
52
52
|
|
|
53
53
|
}`),[pt,St]=U.useState(!1),[$,jt]=U.useState(null),[q,ht]=U.useState(null);U.useEffect(()=>{b(null),O(null),R(null),V(null),jt(null),Gt.listOperations({type:m}).then(Y=>b(Ph(Y))).catch(Y=>ht(Y.message))},[m]),U.useEffect(()=>{B&&(R(null),V(null),Gt.schema(B).then(Y=>R(Y.schema)).catch(Y=>ht(Y.message)),Gt.structuredSchema(B).then(Y=>{var gt,_t;V(((gt=Y.structured)==null?void 0:gt.input)??null),F((_t=Y.structured)!=null&&_t.input?"form":"json")}).catch(()=>{V(null),F("json")}))},[B]);const dt=U.useCallback(Y=>{xt(Y),it(JSON.stringify(Y,null,2))},[]),K=U.useMemo(()=>{if(!r)return{};const Y=D.trim().toLowerCase();if(!Y)return r;const gt={};for(const[_t,Ht]of Object.entries(r)){const g=Ht.filter(M=>M.toLowerCase().includes(Y));g.length>0&&(gt[_t]=g)}return gt},[r,D]),at=async()=>{if(B){ht(null),St(!0);try{let Y;if(et==="form")Y=ot;else try{Y=JSON.parse(k||"{}")}catch{throw new Error("Input is not valid JSON.")}const gt=await Gt.runOperation({path:B,input:Y,tenant:s});jt(gt)}catch(Y){ht(Y.message)}finally{St(!1)}}};return i.jsxs("div",{className:"grid grid-cols-[320px_1fr] gap-6 h-full min-h-0",children:[i.jsxs("div",{className:"flex flex-col gap-3 min-h-0",children:[i.jsx("div",{className:"flex gap-1",children:["api","webhooks","db"].map(Y=>i.jsx(Pt,{variant:m===Y?"primary":"default",onClick:()=>y(Y),children:Y},Y))}),i.jsx("input",{placeholder:"Filter…",className:"h-8 px-2 rounded-md text-xs bg-[var(--color-bg)] border border-[var(--color-border)] focus:outline-none focus:border-[var(--color-accent-dim)]",value:D,onChange:Y=>N(Y.target.value),"aria-label":"Filter operations"}),i.jsx("div",{className:"flex-1 min-h-0 overflow-auto border border-[var(--color-border)] rounded-lg",children:r?Object.keys(K).length===0?i.jsx("div",{className:"p-4 text-xs text-[var(--color-text-muted)]",children:"Nothing matches."}):Object.entries(K).map(([Y,gt])=>i.jsxs("div",{className:"border-b border-[var(--color-border)] last:border-b-0",children:[i.jsx("div",{className:"px-3 py-1.5 text-[10px] uppercase tracking-wide text-[var(--color-text-subtle)] bg-[var(--color-bg-elevated)]",children:Y}),gt.map(_t=>i.jsx("button",{type:"button",onClick:()=>O(_t),className:`block w-full text-left px-3 py-1.5 text-xs font-mono truncate ${B===_t?"bg-[var(--color-bg-hover)] text-[var(--color-accent)]":"hover:bg-[var(--color-bg-hover)] text-[var(--color-text)]"}`,children:_t},_t))]},Y)):i.jsx("div",{className:"p-4 text-xs text-[var(--color-text-muted)]",children:"Loading…"})})]}),i.jsxs("div",{className:"flex flex-col gap-4 min-h-0 overflow-auto",children:[q?i.jsx("div",{className:"text-xs text-[var(--color-err)] border border-[var(--color-err)]/40 rounded p-2 bg-[var(--color-err)]/5",children:q}):null,B?i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("code",{className:"text-sm text-[var(--color-accent)]",children:B}),i.jsx(ne,{children:m})]}),i.jsx(Hl,{title:"Schema",children:i.jsx(ol,{className:"p-0",children:i.jsx("pre",{className:"p-3 overflow-auto max-h-[320px] text-[11px] leading-relaxed",children:j??"Loading…"})})}),m==="webhooks"?null:i.jsx(Hl,{title:"Run",action:i.jsxs("div",{className:"flex items-center gap-2",children:[C&&i.jsxs("div",{className:"flex gap-1",children:[i.jsx(Pt,{variant:et==="form"?"primary":"ghost",onClick:()=>{try{const Y=JSON.parse(k||"{}");Y&&typeof Y=="object"&&!Array.isArray(Y)&&xt(Y)}catch{}F("form")},children:"Form"}),i.jsx(Pt,{variant:et==="json"?"primary":"ghost",onClick:()=>F("json"),children:"JSON"})]}),i.jsx(Pt,{variant:"primary",onClick:at,disabled:pt,children:pt?"Running…":m==="db"?"Query":"▶ Execute"})]}),children:i.jsx(ol,{className:"p-3",children:et==="form"&&C?i.jsxs("div",{className:"space-y-1",children:[i.jsx("div",{className:"text-[11px] text-[var(--color-text-muted)] mb-2",children:"Input"}),i.jsx(Wh,{schema:C,onChange:dt}),i.jsxs("details",{className:"mt-3",children:[i.jsx("summary",{className:"text-[10px] text-[var(--color-text-muted)] cursor-pointer hover:text-[var(--color-text)]",children:"JSON preview"}),i.jsx("pre",{className:"mt-1 p-2 rounded bg-[var(--color-bg)] border border-[var(--color-border)] text-[10px] overflow-auto max-h-[200px]",children:JSON.stringify(ot,null,2)})]})]}):i.jsxs("div",{className:"space-y-1",children:[i.jsx("div",{className:"text-[11px] text-[var(--color-text-muted)] mb-1",children:"Input (JSON)"}),i.jsx(Fh,{value:k,onChange:it,rows:8})]})})}),$?i.jsx(Hl,{title:`Result · ${$.durationMs}ms`,action:i.jsx(ne,{tone:$.ok?"ok":"err",children:$.ok?"ok":"error"}),children:$.ok?i.jsx(Dn,{value:$.result}):i.jsx("pre",{className:"rounded-md bg-[var(--color-err)]/5 border border-[var(--color-err)]/30 p-3 overflow-auto max-h-[480px] text-xs whitespace-pre-wrap text-[var(--color-err)]",children:$.error})}):null]}):i.jsx(al,{title:"Select an operation",hint:"Pick a plugin endpoint, webhook, or DB query from the left."})]})]})}function Ph(s){return typeof s=="string"?Xd(s.split(`
|
|
54
|
-
`).map(m=>m.trim()).filter(Boolean)):Array.isArray(s)?Xd(s.filter(m=>typeof m=="string").map(m=>m.trim()).filter(Boolean)):s??{}}function Xd(s){var y;const m={};for(const r of s){const b=r.split(".",1)[0];b&&(m[b]||(m[b]=[]),m[b].push(r))}for(const r of Object.keys(m))(y=m[r])==null||y.sort((b,D)=>b.localeCompare(D));return m}function ty(){const[s,m]=U.useState(null),[y,r]=U.useState(null),[b,D]=U.useState(null);return U.useEffect(()=>{let N=!1;const B=()=>Gt.permissions().then(j=>{N||(m(j.rows),D(j.note??null))}).catch(j=>!N&&r(j.message));B();const O=setInterval(B,5e3);return()=>{N=!0,clearInterval(O)}},[]),y?i.jsx(al,{title:"Permissions unavailable",hint:y}):s?s.length===0?i.jsx(al,{title:"No approval requests yet",hint:b??"Pending agent actions show up here in real time."}):i.jsx("div",{className:"flex flex-col gap-3",children:s.map(N=>i.jsxs(ol,{className:"p-4 flex flex-col gap-3",children:[i.jsxs("div",{className:"flex items-start justify-between gap-3",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"font-mono text-sm",children:[String(N.plugin),".",String(N.endpoint)]}),i.jsxs("div",{className:"text-[11px] text-[var(--color-text-muted)] mt-0.5",children:["expires ",String(N.expires_at)]})]}),i.jsx(ly,{status:String(N.status)})]}),i.jsxs("details",{children:[i.jsx("summary",{className:"cursor-pointer text-xs text-[var(--color-text-muted)]",children:"Args"}),i.jsx("div",{className:"pt-2",children:i.jsx(Dn,{value:ey(String(N.args))})})]}),N.error?i.jsx("pre",{className:"text-xs whitespace-pre-wrap rounded bg-[var(--color-err)]/5 border border-[var(--color-err)]/30 p-2 text-[var(--color-err)]",children:String(N.error)}):null]},N.id))}):i.jsx(al,{title:"Loading…"})}function ly({status:s}){const m=s==="approved"||s==="completed"?"ok":s==="failed"||s==="denied"||s==="expired"?"err":"warn";return i.jsx(ne,{tone:m,children:s})}function ey(s){try{return JSON.parse(s)}catch{return s}}function ay({pluginId:s,tenant:m,scope:y,onBack:r}){const[b,D]=U.useState(null),[N,B]=U.useState(null),[O,j]=U.useState({}),[R,C]=U.useState(!1),[V,et]=U.useState(!1),[F,ot]=U.useState(null),[xt,k]=U.useState(""),it=()=>{B(null),Gt.getCredentials({pluginId:s,tenantId:m,scope:y}).then(D).catch(K=>B(K.message))};U.useEffect(it,[s,m,y]);const pt=U.useMemo(()=>Object.entries((b==null?void 0:b.integration)??{}),[b]),St=U.useMemo(()=>Object.entries((b==null?void 0:b.account)??{}),[b]),$=!!N&&(N.includes('Integration "')||N.includes("Account not found for tenant")),jt=async()=>{C(!0),B(null);try{await Gt.setCredentials({pluginId:s,tenantId:m,scope:y,fields:O}),j({}),it()}catch(K){B(K.message)}finally{C(!1)}},q=async()=>{et(!0),B(null);try{await Gt.setupPlugin({pluginId:s,tenantId:m}),await it()}catch(K){B(K.message)}finally{et(!1)}},ht=async()=>{try{const K=await Gt.startOAuth({pluginId:s,tenantId:m});ot(K),window.open(K.authUrl,"_blank");const at=setInterval(async()=>{try{const Y=await Gt.getCredentials({pluginId:s,tenantId:m,scope:y});(Y.account.access_token||y==="main")&&(clearInterval(at),ot(null),D(Y))}catch{}},2e3);setTimeout(()=>clearInterval(at),300*1e3)}catch(K){B(K.message)}},dt=async()=>{if(xt.trim())try{await Gt.exchangeOAuth({pluginId:s,tenantId:m,code:xt.trim()}),k(""),ot(null),it()}catch(K){B(K.message)}};return i.jsxs("div",{className:"flex flex-col gap-6",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx(Pt,{variant:"ghost",onClick:r,children:"← Back"}),i.jsx("h1",{className:"text-lg font-semibold",children:s}),b!=null&&b.authType?i.jsx(ne,{children:b.authType}):null,i.jsx(ne,{children:y==="main"?"main scope":`tenant: ${m}`})]}),N?i.jsxs("div",{className:"text-xs text-[var(--color-err)] border border-[var(--color-err)]/40 rounded p-2 bg-[var(--color-err)]/5 flex items-center justify-between gap-3",children:[i.jsx("span",{children:N}),$?i.jsx(Pt,{variant:"primary",onClick:q,disabled:V,className:"whitespace-nowrap",children:V?"Creating…":y==="main"?"Create integration + account":"Create integration/account"}):null]}):null,y==="tenant"&&(b==null?void 0:b.authType)==="oauth_2"?i.jsx(Hl,{title:"OAuth",action:i.jsx(Pt,{variant:"primary",onClick:ht,children:"Start OAuth flow"}),children:i.jsx(ol,{className:"p-4 flex flex-col gap-2 text-xs",children:F?i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsxs("div",{className:"text-[var(--color-text-muted)]",children:["Redirect listening at:"," ",i.jsx("code",{className:"text-[var(--color-text)]",children:F.redirectUri})]}),i.jsx("div",{children:"Authorize in the browser tab. If your provider doesn't redirect to localhost, paste the code below."}),F.note?i.jsx("div",{className:"text-[var(--color-warn)]",children:F.note}):null,i.jsxs("div",{className:"flex gap-2 items-center",children:[i.jsx(Me,{value:xt,onChange:K=>k(K.target.value),"aria-label":"OAuth code",placeholder:"OAuth code…"}),i.jsx(Pt,{onClick:dt,disabled:!xt.trim(),children:"Exchange"})]})]}):i.jsx("div",{className:"text-[var(--color-text-muted)]",children:"Starts a local listener, opens your browser to the provider, and saves tokens when it returns."})})}):null,pt.length>0?i.jsx(Hl,{title:"Integration credentials",children:i.jsx(ol,{className:"p-4",children:i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-x-6 gap-y-3",children:pt.map(([K,at])=>i.jsx(Zd,{name:K,masked:at,value:O[K]??"",onChange:Y=>j(gt=>({...gt,[K]:Y}))},K))})})}):null,y==="tenant"&&St.length>0?i.jsx(Hl,{title:`Account credentials · ${m}`,children:i.jsx(ol,{className:"p-4",children:i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-x-6 gap-y-3",children:St.map(([K,at])=>i.jsx(Zd,{name:K,masked:at,value:O[K]??"",onChange:Y=>j(gt=>({...gt,[K]:Y}))},K))})})}):null,i.jsxs("div",{className:"flex justify-end gap-2",children:[i.jsx(Pt,{variant:"ghost",onClick:it,children:"↻ Refresh"}),i.jsx(Pt,{variant:"primary",onClick:jt,disabled:R||Object.values(O).every(K=>!K),children:R?"Saving…":"Save changes"})]})]})}function Zd({name:s,masked:m,value:y,onChange:r}){return i.jsxs("label",{className:"flex flex-col gap-1",children:[i.jsxs("span",{className:"text-[11px] text-[var(--color-text-muted)] uppercase tracking-wide flex items-center gap-2",children:[s,m?i.jsx(ne,{tone:"ok",children:"set"}):i.jsx(ne,{tone:"err",children:"empty"})]}),i.jsx(Me,{type:"text",value:y,placeholder:m??"unset",onChange:b=>r(b.target.value)})]})}function ny({tenant:s,multiTenancy:m,selectedPluginId:y,onSelectPlugin:r}){const[b,D]=U.useState(null),[N,B]=U.useState([]),[O,j]=U.useState(null),[R,C]=U.useState("main"),[V,et]=U.useState(s),[F,ot]=U.useState(""),[xt,k]=U.useState(!1),it=()=>{Gt.plugins(R==="tenant"?V:void 0,R).then(D).catch($=>j($.message))},pt=()=>{Gt.listTenants().then($=>B($.tenants)).catch($=>j($.message))};U.useEffect(()=>{it()},[R,V]),U.useEffect(()=>{et(s)},[s]),U.useEffect(()=>{m&&pt()},[m]),U.useEffect(()=>{N.length!==0&&(N.includes(V)||et(N[0]))},[N,V]);const St=async()=>{const $=F.trim();if($){k(!0),j(null);try{await Gt.createTenant({tenantId:$}),ot(""),C("tenant"),et($),await pt(),await it()}catch(jt){j(jt.message)}finally{k(!1)}}};return O?i.jsx(al,{title:"Couldn't load plugins",hint:O}):b?y?i.jsx(ay,{pluginId:y,tenant:V,scope:R,onBack:()=>{r(null),it()}}):b.length===0?i.jsxs("div",{className:"flex flex-col gap-4",children:[i.jsx(Ld,{multiTenancy:m,scope:R,setScope:C,activeTenant:V,setActiveTenant:et,tenants:N,newTenant:F,setNewTenant:ot,creatingTenant:xt,onCreateTenant:St}),i.jsx(al,{title:"No plugins configured",hint:"Add a plugin to your corsair instance, then refresh."})]}):i.jsxs("div",{className:"flex flex-col gap-4",children:[i.jsx(Ld,{multiTenancy:m,scope:R,setScope:C,activeTenant:V,setActiveTenant:et,tenants:N,newTenant:F,setNewTenant:ot,creatingTenant:xt,onCreateTenant:St}),i.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",children:[b.map($=>{var jt;return i.jsx(ol,{className:"p-4 cursor-pointer hover:border-[var(--color-border-strong)] transition-colors",children:i.jsxs("button",{type:"button",onClick:()=>r($.id),className:"w-full text-left flex flex-col gap-3",children:[i.jsx("div",{className:"text-sm font-semibold",children:$.id}),i.jsxs("div",{className:"text-[11px] text-[var(--color-text-muted)]",children:["auth: ",$.authType,(jt=$.oauth)!=null&&jt.available?" · OAuth":"",R==="main"?" · integration scope":""]}),i.jsx("div",{className:"flex flex-wrap gap-1",children:$.requiredFields.map(q=>i.jsx(ne,{tone:q.set?"ok":"err",children:q.name},`${q.level}:${q.name}`))})]})},$.id)}),i.jsx("div",{className:"col-span-full flex justify-end",children:i.jsx(Pt,{variant:"ghost",onClick:it,children:"↻ Refresh"})})]})]}):i.jsx(al,{title:"Loading plugins…"})}function Ld({multiTenancy:s,scope:m,setScope:y,activeTenant:r,setActiveTenant:b,tenants:D,newTenant:N,setNewTenant:B,creatingTenant:O,onCreateTenant:j}){if(!s)return null;const R=D.length>0?D:["default"];return i.jsxs("div",{className:"grid gap-3 lg:grid-cols-2",children:[i.jsx(Hl,{title:"View scope",children:i.jsxs(ol,{className:"p-3 flex items-center gap-2",children:[i.jsxs("select",{value:m,onChange:C=>y(C.target.value==="main"?"main":"tenant"),"aria-label":"Credential scope",className:"h-8 px-2 rounded-md text-xs bg-[var(--color-bg)] border border-[var(--color-border)] focus:outline-none focus:border-[var(--color-accent-dim)]",children:[i.jsx("option",{value:"main",children:"Main (integration keys)"}),i.jsx("option",{value:"tenant",children:"Tenant (account keys)"})]}),m==="tenant"?i.jsx("select",{value:r,"aria-label":"Active tenant",onChange:C=>b(C.target.value),className:"h-8 px-2 rounded-md text-xs bg-[var(--color-bg)] border border-[var(--color-border)] focus:outline-none focus:border-[var(--color-accent-dim)]",children:R.map(C=>i.jsx("option",{value:C,children:C},C))}):null]})}),i.jsx(Hl,{title:"Create tenant",children:i.jsxs(ol,{className:"p-3 flex items-center gap-2",children:[i.jsx(Me,{value:N,onChange:C=>B(C.target.value),"aria-label":"New tenant ID",placeholder:"tenant-id"}),i.jsx(Pt,{variant:"primary",disabled:O||!N.trim(),onClick:j,children:O?"Creating…":"Create"})]})})]})}const uy="// `corsair` is the resolved client (tenant-scoped if multi-tenant).\n// Use `return` to surface a value. Filter inline — don't return giant lists.\nconst channels = await corsair.slack?.db.channels.list({});\nreturn channels?.slice(0, 5);";function cy({tenant:s}){const[m,y]=U.useState(uy),[r,b]=U.useState(null),[D,N]=U.useState(!1),[B,O]=U.useState(null),[j,R]=U.useState([]),[C,V]=U.useState(""),[et,F]=U.useState(!1),ot=()=>{Gt.listTenants().then(k=>R(k.tenants)).catch(k=>O(k.message))};U.useEffect(()=>{(async()=>{try{const it=await Gt.status();F(it.multiTenancy),it.multiTenancy&&ot()}catch(it){console.error(it)}})()},[]),U.useEffect(()=>{j.length!==0&&C&&!j.includes(C)&&V("")},[j]);const xt=async()=>{if(et&&!C){O("Please select a tenant before running the script.");return}O(null),N(!0);try{const k=await Gt.runScript({code:m,tenant:et?C:void 0});b(k)}catch(k){O(k.message)}finally{N(!1)}};return i.jsxs("div",{className:"flex flex-col gap-4",children:[et&&i.jsx(Hl,{title:"Tenant",children:i.jsx(ol,{className:"p-3 flex items-center gap-2",children:i.jsxs("select",{value:C,"aria-label":"Tenant",onChange:k=>V(k.target.value),className:"h-8 px-2 rounded-md text-xs bg-[var(--color-bg)] border border-[var(--color-border)] focus:outline-none focus:border-[var(--color-accent-dim)]","aria-label":"Active Tenant",children:[i.jsx("option",{value:"",children:"Select tenant"}),j.map(k=>i.jsx("option",{value:k,children:k},k))]})})}),i.jsx(Hl,{title:"Script",action:i.jsx(Pt,{variant:"primary",onClick:xt,disabled:D||et&&!C,children:D?"Running…":"▶ Run"}),children:i.jsx(ol,{className:"p-3",children:i.jsx(Ef,{rows:14,value:m,onChange:k=>y(k.target.value),"aria-label":"Script",spellCheck:!1,"aria-label":"Script Source"})})}),B?i.jsx("div",{className:"text-xs text-[var(--color-err)] border border-[var(--color-err)]/40 rounded p-2 bg-[var(--color-err)]/5",children:B}):null,r?i.jsx(Hl,{title:`Result · ${r.durationMs}ms`,action:i.jsx(ne,{tone:r.ok?"ok":"err",children:r.ok?"ok":"error"}),children:r.ok?i.jsx(Dn,{value:r.result}):i.jsx("pre",{className:"rounded-md bg-[var(--color-err)]/5 border border-[var(--color-err)]/30 p-3 overflow-auto max-h-[480px] text-xs whitespace-pre-wrap text-[var(--color-err)]",children:r.error})}):null]})}const Vd={plugins:"Plugins",operations:"Operations",database:"Data",permissions:"Permissions",script:"Script",chat:"Chat"},iy=new Set(["plugins","operations","database","permissions","script","chat"]);function Jd(s){const m=s.split("/").filter(Boolean),y=m[0];return!y||!iy.has(y)?{route:"plugins",pluginId:null}:y==="plugins"&&m[1]?{route:"plugins",pluginId:decodeURIComponent(m[1])}:{route:y,pluginId:null}}function fy({route:s,pluginId:m}){return s==="plugins"?m?`/plugins/${encodeURIComponent(m)}`:"/plugins":`/${s}`}function sy(){const[s,m]=U.useState(()=>Jd(window.location.pathname)),[y,r]=U.useState(()=>localStorage.getItem("corsair-studio:tenant")??"default"),[b,D]=U.useState(null),[N,B]=U.useState(null),O=s.route,j=R=>{m(R);const C=fy(R);window.location.pathname!==C&&window.history.pushState({},"",C)};return U.useEffect(()=>{Gt.status().then(D).catch(R=>B(R.message))},[]),U.useEffect(()=>{localStorage.setItem("corsair-studio:tenant",y)},[y]),U.useEffect(()=>{const R=new EventSource("/api/events"),C=()=>{window.location.reload()};return R.addEventListener("corsair-changed",C),()=>{R.removeEventListener("corsair-changed",C),R.close()}},[]),U.useEffect(()=>{const R=()=>{m(Jd(window.location.pathname))};return window.addEventListener("popstate",R),()=>{window.removeEventListener("popstate",R)}},[]),N?i.jsx("div",{className:"h-full flex items-center justify-center p-6",children:i.jsxs("div",{className:"max-w-xl",children:[i.jsx("h1",{className:"text-xl font-semibold mb-2",children:"Couldn't load Corsair"}),i.jsx("pre",{className:"text-xs rounded-md bg-[var(--color-err)]/5 border border-[var(--color-err)]/30 p-3 whitespace-pre-wrap text-[var(--color-err)]",children:N}),i.jsxs("p",{className:"text-xs text-[var(--color-text-muted)] mt-3",children:["Make sure a ",i.jsx("code",{children:"corsair.ts"})," exists in your project root (or"," ",i.jsx("code",{children:"src/"}),", ",i.jsx("code",{children:"lib/"}),", ",i.jsx("code",{children:"server/"}),") and exports your corsair instance."]})]})}):i.jsxs("div",{className:"h-full flex",children:[i.jsx(Mh,{current:O,onNavigate:R=>{j({route:R,pluginId:null})},tenant:y,setTenant:r,multiTenancy:!!(b!=null&&b.multiTenancy),cwd:(b==null?void 0:b.cwd)??null}),i.jsxs("main",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[i.jsxs("header",{className:"h-12 px-6 flex items-center justify-between border-b border-[var(--color-border)]",children:[i.jsx("h1",{className:"text-sm font-semibold",children:O==="plugins"&&s.pluginId?`${Vd[O]} / ${s.pluginId}`:Vd[O]}),b?i.jsxs("div",{className:"text-[11px] text-[var(--color-text-subtle)]",children:[b.pluginCount," plugins ·"," ",b.hasDatabase?"DB":"no DB"]}):null]}),i.jsxs("div",{className:`flex-1 min-h-0 ${O==="chat"?"overflow-hidden":"overflow-auto p-6"}`,children:[O==="plugins"?i.jsx(ny,{tenant:y,multiTenancy:!!(b!=null&&b.multiTenancy),selectedPluginId:s.pluginId,onSelectPlugin:R=>{j({route:"plugins",pluginId:R})}}):null,O==="operations"?i.jsx(Ih,{tenant:y}):null,O==="database"?i.jsx(Bh,{}):null,O==="permissions"?i.jsx(ty,{}):null,O==="script"?i.jsx(cy,{tenant:y}):null,O==="chat"?i.jsx(qh,{tenant:y}):null]})]})]})}const $d=document.getElementById("root");if(!$d)throw new Error("#root element missing");Oh.createRoot($d).render(i.jsx(U.StrictMode,{children:i.jsx(sy,{})}));
|
|
55
|
-
//# sourceMappingURL=index-
|
|
54
|
+
`).map(m=>m.trim()).filter(Boolean)):Array.isArray(s)?Xd(s.filter(m=>typeof m=="string").map(m=>m.trim()).filter(Boolean)):s??{}}function Xd(s){var y;const m={};for(const r of s){const b=r.split(".",1)[0];b&&(m[b]||(m[b]=[]),m[b].push(r))}for(const r of Object.keys(m))(y=m[r])==null||y.sort((b,D)=>b.localeCompare(D));return m}function ty(){const[s,m]=U.useState(null),[y,r]=U.useState(null),[b,D]=U.useState(null);return U.useEffect(()=>{let N=!1;const B=()=>Gt.permissions().then(j=>{N||(m(j.rows),D(j.note??null))}).catch(j=>!N&&r(j.message));B();const O=setInterval(B,5e3);return()=>{N=!0,clearInterval(O)}},[]),y?i.jsx(al,{title:"Permissions unavailable",hint:y}):s?s.length===0?i.jsx(al,{title:"No approval requests yet",hint:b??"Pending agent actions show up here in real time."}):i.jsx("div",{className:"flex flex-col gap-3",children:s.map(N=>i.jsxs(ol,{className:"p-4 flex flex-col gap-3",children:[i.jsxs("div",{className:"flex items-start justify-between gap-3",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"font-mono text-sm",children:[String(N.plugin),".",String(N.endpoint)]}),i.jsxs("div",{className:"text-[11px] text-[var(--color-text-muted)] mt-0.5",children:["expires ",String(N.expires_at)]})]}),i.jsx(ly,{status:String(N.status)})]}),i.jsxs("details",{children:[i.jsx("summary",{className:"cursor-pointer text-xs text-[var(--color-text-muted)]",children:"Args"}),i.jsx("div",{className:"pt-2",children:i.jsx(Dn,{value:ey(String(N.args))})})]}),N.error?i.jsx("pre",{className:"text-xs whitespace-pre-wrap rounded bg-[var(--color-err)]/5 border border-[var(--color-err)]/30 p-2 text-[var(--color-err)]",children:String(N.error)}):null]},N.id))}):i.jsx(al,{title:"Loading…"})}function ly({status:s}){const m=s==="approved"||s==="completed"?"ok":s==="failed"||s==="denied"||s==="expired"?"err":"warn";return i.jsx(ne,{tone:m,children:s})}function ey(s){try{return JSON.parse(s)}catch{return s}}function ay({pluginId:s,tenant:m,scope:y,onBack:r}){const[b,D]=U.useState(null),[N,B]=U.useState(null),[O,j]=U.useState({}),[R,C]=U.useState(!1),[V,et]=U.useState(!1),[F,ot]=U.useState(null),[xt,k]=U.useState(""),it=()=>{B(null),Gt.getCredentials({pluginId:s,tenantId:m,scope:y}).then(D).catch(K=>B(K.message))};U.useEffect(it,[s,m,y]);const pt=U.useMemo(()=>Object.entries((b==null?void 0:b.integration)??{}),[b]),St=U.useMemo(()=>Object.entries((b==null?void 0:b.account)??{}),[b]),$=!!N&&(N.includes('Integration "')||N.includes("Account not found for tenant")),jt=async()=>{C(!0),B(null);try{await Gt.setCredentials({pluginId:s,tenantId:m,scope:y,fields:O}),j({}),it()}catch(K){B(K.message)}finally{C(!1)}},q=async()=>{et(!0),B(null);try{await Gt.setupPlugin({pluginId:s,tenantId:m}),await it()}catch(K){B(K.message)}finally{et(!1)}},ht=async()=>{try{const K=await Gt.startOAuth({pluginId:s,tenantId:m});ot(K),window.open(K.authUrl,"_blank");const at=setInterval(async()=>{try{const Y=await Gt.getCredentials({pluginId:s,tenantId:m,scope:y});(Y.account.access_token||y==="main")&&(clearInterval(at),ot(null),D(Y))}catch{}},2e3);setTimeout(()=>clearInterval(at),300*1e3)}catch(K){B(K.message)}},dt=async()=>{if(xt.trim())try{await Gt.exchangeOAuth({pluginId:s,tenantId:m,code:xt.trim()}),k(""),ot(null),it()}catch(K){B(K.message)}};return i.jsxs("div",{className:"flex flex-col gap-6",children:[i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx(Pt,{variant:"ghost",onClick:r,children:"← Back"}),i.jsx("h1",{className:"text-lg font-semibold",children:s}),b!=null&&b.authType?i.jsx(ne,{children:b.authType}):null,i.jsx(ne,{children:y==="main"?"main scope":`tenant: ${m}`})]}),N?i.jsxs("div",{className:"text-xs text-[var(--color-err)] border border-[var(--color-err)]/40 rounded p-2 bg-[var(--color-err)]/5 flex items-center justify-between gap-3",children:[i.jsx("span",{children:N}),$?i.jsx(Pt,{variant:"primary",onClick:q,disabled:V,className:"whitespace-nowrap",children:V?"Creating…":y==="main"?"Create integration + account":"Create integration/account"}):null]}):null,y==="tenant"&&(b==null?void 0:b.authType)==="oauth_2"?i.jsx(Hl,{title:"OAuth",action:i.jsx(Pt,{variant:"primary",onClick:ht,children:"Start OAuth flow"}),children:i.jsx(ol,{className:"p-4 flex flex-col gap-2 text-xs",children:F?i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsxs("div",{className:"text-[var(--color-text-muted)]",children:["Redirect listening at:"," ",i.jsx("code",{className:"text-[var(--color-text)]",children:F.redirectUri})]}),i.jsx("div",{children:"Authorize in the browser tab. If your provider doesn't redirect to localhost, paste the code below."}),F.note?i.jsx("div",{className:"text-[var(--color-warn)]",children:F.note}):null,i.jsxs("div",{className:"flex gap-2 items-center",children:[i.jsx(Me,{value:xt,onChange:K=>k(K.target.value),"aria-label":"OAuth code",placeholder:"OAuth code…"}),i.jsx(Pt,{onClick:dt,disabled:!xt.trim(),children:"Exchange"})]})]}):i.jsx("div",{className:"text-[var(--color-text-muted)]",children:"Starts a local listener, opens your browser to the provider, and saves tokens when it returns."})})}):null,pt.length>0?i.jsx(Hl,{title:"Integration credentials",children:i.jsx(ol,{className:"p-4",children:i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-x-6 gap-y-3",children:pt.map(([K,at])=>i.jsx(Zd,{name:K,masked:at,value:O[K]??"",onChange:Y=>j(gt=>({...gt,[K]:Y}))},K))})})}):null,y==="tenant"&&St.length>0?i.jsx(Hl,{title:`Account credentials · ${m}`,children:i.jsx(ol,{className:"p-4",children:i.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-x-6 gap-y-3",children:St.map(([K,at])=>i.jsx(Zd,{name:K,masked:at,value:O[K]??"",onChange:Y=>j(gt=>({...gt,[K]:Y}))},K))})})}):null,i.jsxs("div",{className:"flex justify-end gap-2",children:[i.jsx(Pt,{variant:"ghost",onClick:it,children:"↻ Refresh"}),i.jsx(Pt,{variant:"primary",onClick:jt,disabled:R||Object.values(O).every(K=>!K),children:R?"Saving…":"Save changes"})]})]})}function Zd({name:s,masked:m,value:y,onChange:r}){return i.jsxs("label",{className:"flex flex-col gap-1",children:[i.jsxs("span",{className:"text-[11px] text-[var(--color-text-muted)] uppercase tracking-wide flex items-center gap-2",children:[s,m?i.jsx(ne,{tone:"ok",children:"set"}):i.jsx(ne,{tone:"err",children:"empty"})]}),i.jsx(Me,{type:"text",value:y,placeholder:m??"unset",onChange:b=>r(b.target.value)})]})}function ny({tenant:s,multiTenancy:m,selectedPluginId:y,onSelectPlugin:r}){const[b,D]=U.useState(null),[N,B]=U.useState([]),[O,j]=U.useState(null),[R,C]=U.useState("main"),[V,et]=U.useState(s),[F,ot]=U.useState(""),[xt,k]=U.useState(!1),it=()=>{Gt.plugins(R==="tenant"?V:void 0,R).then(D).catch($=>j($.message))},pt=()=>{Gt.listTenants().then($=>B($.tenants)).catch($=>j($.message))};U.useEffect(()=>{it()},[R,V]),U.useEffect(()=>{et(s)},[s]),U.useEffect(()=>{m&&pt()},[m]),U.useEffect(()=>{N.length!==0&&(N.includes(V)||et(N[0]))},[N,V]);const St=async()=>{const $=F.trim();if($){k(!0),j(null);try{await Gt.createTenant({tenantId:$}),ot(""),C("tenant"),et($),await pt(),await it()}catch(jt){j(jt.message)}finally{k(!1)}}};return O?i.jsx(al,{title:"Couldn't load plugins",hint:O}):b?y?i.jsx(ay,{pluginId:y,tenant:V,scope:R,onBack:()=>{r(null),it()}}):b.length===0?i.jsxs("div",{className:"flex flex-col gap-4",children:[i.jsx(Ld,{multiTenancy:m,scope:R,setScope:C,activeTenant:V,setActiveTenant:et,tenants:N,newTenant:F,setNewTenant:ot,creatingTenant:xt,onCreateTenant:St}),i.jsx(al,{title:"No plugins configured",hint:"Add a plugin to your corsair instance, then refresh."})]}):i.jsxs("div",{className:"flex flex-col gap-4",children:[i.jsx(Ld,{multiTenancy:m,scope:R,setScope:C,activeTenant:V,setActiveTenant:et,tenants:N,newTenant:F,setNewTenant:ot,creatingTenant:xt,onCreateTenant:St}),i.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",children:[b.map($=>{var jt;return i.jsx(ol,{className:"p-4 cursor-pointer hover:border-[var(--color-border-strong)] transition-colors",children:i.jsxs("button",{type:"button",onClick:()=>r($.id),className:"w-full text-left flex flex-col gap-3",children:[i.jsx("div",{className:"text-sm font-semibold",children:$.id}),i.jsxs("div",{className:"text-[11px] text-[var(--color-text-muted)]",children:["auth: ",$.authType,(jt=$.oauth)!=null&&jt.available?" · OAuth":"",R==="main"?" · integration scope":""]}),i.jsx("div",{className:"flex flex-wrap gap-1",children:$.requiredFields.map(q=>i.jsx(ne,{tone:q.set?"ok":"err",children:q.name},`${q.level}:${q.name}`))})]})},$.id)}),i.jsx("div",{className:"col-span-full flex justify-end",children:i.jsx(Pt,{variant:"ghost",onClick:it,children:"↻ Refresh"})})]})]}):i.jsx(al,{title:"Loading plugins…"})}function Ld({multiTenancy:s,scope:m,setScope:y,activeTenant:r,setActiveTenant:b,tenants:D,newTenant:N,setNewTenant:B,creatingTenant:O,onCreateTenant:j}){if(!s)return null;const R=D.length>0?D:["default"];return i.jsxs("div",{className:"grid gap-3 lg:grid-cols-2",children:[i.jsx(Hl,{title:"View scope",children:i.jsxs(ol,{className:"p-3 flex items-center gap-2",children:[i.jsxs("select",{value:m,onChange:C=>y(C.target.value==="main"?"main":"tenant"),"aria-label":"Credential scope",className:"h-8 px-2 rounded-md text-xs bg-[var(--color-bg)] border border-[var(--color-border)] focus:outline-none focus:border-[var(--color-accent-dim)]",children:[i.jsx("option",{value:"main",children:"Main (integration keys)"}),i.jsx("option",{value:"tenant",children:"Tenant (account keys)"})]}),m==="tenant"?i.jsx("select",{value:r,"aria-label":"Active tenant",onChange:C=>b(C.target.value),className:"h-8 px-2 rounded-md text-xs bg-[var(--color-bg)] border border-[var(--color-border)] focus:outline-none focus:border-[var(--color-accent-dim)]",children:R.map(C=>i.jsx("option",{value:C,children:C},C))}):null]})}),i.jsx(Hl,{title:"Create tenant",children:i.jsxs(ol,{className:"p-3 flex items-center gap-2",children:[i.jsx(Me,{value:N,onChange:C=>B(C.target.value),"aria-label":"New tenant ID",placeholder:"tenant-id"}),i.jsx(Pt,{variant:"primary",disabled:O||!N.trim(),onClick:j,children:O?"Creating…":"Create"})]})})]})}const uy="// `corsair` is the resolved client (tenant-scoped if multi-tenant).\n// Use `return` to surface a value. Filter inline — don't return giant lists.\nconst channels = await corsair.slack?.db.channels.list({});\nreturn channels?.slice(0, 5);";function cy({tenant:s}){const[m,y]=U.useState(uy),[r,b]=U.useState(null),[D,N]=U.useState(!1),[B,O]=U.useState(null),[j,R]=U.useState([]),[C,V]=U.useState(""),[et,F]=U.useState(!1),ot=()=>{Gt.listTenants().then(k=>R(k.tenants)).catch(k=>O(k.message))};U.useEffect(()=>{(async()=>{try{const it=await Gt.status();F(it.multiTenancy),it.multiTenancy&&ot()}catch(it){console.error(it)}})()},[]),U.useEffect(()=>{j.length!==0&&C&&!j.includes(C)&&V("")},[j]);const xt=async()=>{if(et&&!C){O("Please select a tenant before running the script.");return}O(null),N(!0);try{const k=await Gt.runScript({code:m,tenant:et?C:void 0});b(k)}catch(k){O(k.message)}finally{N(!1)}};return i.jsxs("div",{className:"flex flex-col gap-4",children:[et&&i.jsx(Hl,{title:"Tenant",children:i.jsx(ol,{className:"p-3 flex items-center gap-2",children:i.jsxs("select",{value:C,onChange:k=>V(k.target.value),className:"h-8 px-2 rounded-md text-xs bg-[var(--color-bg)] border border-[var(--color-border)] focus:outline-none focus:border-[var(--color-accent-dim)]","aria-label":"Active Tenant",children:[i.jsx("option",{value:"",children:"Select tenant"}),j.map(k=>i.jsx("option",{value:k,children:k},k))]})})}),i.jsx(Hl,{title:"Script",action:i.jsx(Pt,{variant:"primary",onClick:xt,disabled:D||et&&!C,children:D?"Running…":"▶ Run"}),children:i.jsx(ol,{className:"p-3",children:i.jsx(Ef,{rows:14,value:m,onChange:k=>y(k.target.value),spellCheck:!1,"aria-label":"Script Source"})})}),B?i.jsx("div",{className:"text-xs text-[var(--color-err)] border border-[var(--color-err)]/40 rounded p-2 bg-[var(--color-err)]/5",children:B}):null,r?i.jsx(Hl,{title:`Result · ${r.durationMs}ms`,action:i.jsx(ne,{tone:r.ok?"ok":"err",children:r.ok?"ok":"error"}),children:r.ok?i.jsx(Dn,{value:r.result}):i.jsx("pre",{className:"rounded-md bg-[var(--color-err)]/5 border border-[var(--color-err)]/30 p-3 overflow-auto max-h-[480px] text-xs whitespace-pre-wrap text-[var(--color-err)]",children:r.error})}):null]})}const Vd={plugins:"Plugins",operations:"Operations",database:"Data",permissions:"Permissions",script:"Script",chat:"Chat"},iy=new Set(["plugins","operations","database","permissions","script","chat"]);function Jd(s){const m=s.split("/").filter(Boolean),y=m[0];return!y||!iy.has(y)?{route:"plugins",pluginId:null}:y==="plugins"&&m[1]?{route:"plugins",pluginId:decodeURIComponent(m[1])}:{route:y,pluginId:null}}function fy({route:s,pluginId:m}){return s==="plugins"?m?`/plugins/${encodeURIComponent(m)}`:"/plugins":`/${s}`}function sy(){const[s,m]=U.useState(()=>Jd(window.location.pathname)),[y,r]=U.useState(()=>localStorage.getItem("corsair-studio:tenant")??"default"),[b,D]=U.useState(null),[N,B]=U.useState(null),O=s.route,j=R=>{m(R);const C=fy(R);window.location.pathname!==C&&window.history.pushState({},"",C)};return U.useEffect(()=>{Gt.status().then(D).catch(R=>B(R.message))},[]),U.useEffect(()=>{localStorage.setItem("corsair-studio:tenant",y)},[y]),U.useEffect(()=>{const R=new EventSource("/api/events"),C=()=>{window.location.reload()};return R.addEventListener("corsair-changed",C),()=>{R.removeEventListener("corsair-changed",C),R.close()}},[]),U.useEffect(()=>{const R=()=>{m(Jd(window.location.pathname))};return window.addEventListener("popstate",R),()=>{window.removeEventListener("popstate",R)}},[]),N?i.jsx("div",{className:"h-full flex items-center justify-center p-6",children:i.jsxs("div",{className:"max-w-xl",children:[i.jsx("h1",{className:"text-xl font-semibold mb-2",children:"Couldn't load Corsair"}),i.jsx("pre",{className:"text-xs rounded-md bg-[var(--color-err)]/5 border border-[var(--color-err)]/30 p-3 whitespace-pre-wrap text-[var(--color-err)]",children:N}),i.jsxs("p",{className:"text-xs text-[var(--color-text-muted)] mt-3",children:["Make sure a ",i.jsx("code",{children:"corsair.ts"})," exists in your project root (or"," ",i.jsx("code",{children:"src/"}),", ",i.jsx("code",{children:"lib/"}),", ",i.jsx("code",{children:"server/"}),") and exports your corsair instance."]})]})}):i.jsxs("div",{className:"h-full flex",children:[i.jsx(Mh,{current:O,onNavigate:R=>{j({route:R,pluginId:null})},tenant:y,setTenant:r,multiTenancy:!!(b!=null&&b.multiTenancy),cwd:(b==null?void 0:b.cwd)??null}),i.jsxs("main",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[i.jsxs("header",{className:"h-12 px-6 flex items-center justify-between border-b border-[var(--color-border)]",children:[i.jsx("h1",{className:"text-sm font-semibold",children:O==="plugins"&&s.pluginId?`${Vd[O]} / ${s.pluginId}`:Vd[O]}),b?i.jsxs("div",{className:"text-[11px] text-[var(--color-text-subtle)]",children:[b.pluginCount," plugins ·"," ",b.hasDatabase?"DB":"no DB"]}):null]}),i.jsxs("div",{className:`flex-1 min-h-0 ${O==="chat"?"overflow-hidden":"overflow-auto p-6"}`,children:[O==="plugins"?i.jsx(ny,{tenant:y,multiTenancy:!!(b!=null&&b.multiTenancy),selectedPluginId:s.pluginId,onSelectPlugin:R=>{j({route:"plugins",pluginId:R})}}):null,O==="operations"?i.jsx(Ih,{tenant:y}):null,O==="database"?i.jsx(Bh,{}):null,O==="permissions"?i.jsx(ty,{}):null,O==="script"?i.jsx(cy,{tenant:y}):null,O==="chat"?i.jsx(qh,{tenant:y}):null]})]})]})}const $d=document.getElementById("root");if(!$d)throw new Error("#root element missing");Oh.createRoot($d).render(i.jsx(U.StrictMode,{children:i.jsx(sy,{})}));
|
|
55
|
+
//# sourceMappingURL=index-W9OL2bnx.js.map
|