1import{A as f,o as h,q as D,O as w,P as R,a8 as x,s as g,j as e,bc as W,bd as X,aU as Z,be as J,r as S,C as M,c as K,bI as U,d as I,B as N,e as B,X as Q,Z as V,W as b,aq as Y,ar as ee,as as re,at as ae,aG as se,L as ie,h as T,S as ne,i as te,k as le,l as oe,m as ce,w as de}from"./index-D1uZ7Gx7.js";import{g as y}from"./errors-ClvoLezE.js";import{P as me,a as ue,A as $,g as O}from"./ASRProviderForm-DmmNiQG2.js";import{B as z}from"./badge-5q6xRBXs.js";import{P as ge}from"./pencil-C7MSHlTs.js";import{A as fe,a as xe,b as pe,c as ve,d as he,e as je,f as be,g as ye}from"./alert-dialog-C4gzwhU-.js";const C={current:{primary_provider:"assemblyai",fallback_provider:"elevenlabs",scope:"platform",organization_id:null}},E={"org-1":{primary_provider:"openai",fallback_provider:null,scope:"organization",organization_id:"org-1"}};function q(){return C.current}function Ae(r){return E[r]??{...C.current,scope:"platform",organization_id:null}}function Se(r){C.current={...C.current,...r}}function Ne(r,a){E[r]=a}function Oe(r){delete E[r]}function L(r){return r?me.includes(r)?r:(console.warn(`[asr-config] Unknown provider id: "${r}", defaulting to 'assemblyai'`),"assemblyai"):null}function d(r){return{primary:L(r.primary_provider)??"assemblyai",fallback:L(r.fallback_provider),scope:r.scope,organizationId:r.organization_id}}const j=()=>({baseUrl:f.ADMIN_BASE_URL}),A={async getPlatformConfig(){if(f.USE_MOCK_DATA)return d(q());const r=await h("/asr-config/platform",j());return d(r)},async updatePlatformConfig(r){if(f.USE_MOCK_DATA)return Se({primary_provider:r.primary_provider,fallback_provider:r.fallback_provider??null}),d(q());const a=await h("/asr-config/platform",{...j(),method:"PUT",body:r});return d(a)},async getOrgConfig(r){if(f.USE_MOCK_DATA)return d(Ae(r));const a=await h(`/asr-config/organizations/${r}`,j());return d(a)},async setOrgOverride(r,a){if(f.USE_MOCK_DATA){const n={primary_provider:a.primary_provider,fallback_provider:a.fallback_provider??null,scope:"organization",organization_id:r};return Ne(r,n),d(n)}const s=await h(`/asr-config/organizations/${r}`,{...j(),method:"PUT",body:a});return d(s)},async removeOrgOverride(r){return f.USE_MOCK_DATA?(Oe(r),{message:"Override removed."}):h(`/asr-config/organizations/${r}`,{...j(),method:"DELETE"})}};function H(){return D({queryKey:g.admin.asrConfig.platform(),queryFn:()=>A.getPlatformConfig()})}function Ce(r,a){return D({queryKey:g.admin.asrConfig.org(r??""),queryFn:()=>A.getOrgConfig(r),enabled:!!r&&(a==null?void 0:a.enabled)!==!1})}function ke(){const r=w();return R({mutationFn:a=>A.updatePlatformConfig(a),onSuccess:()=>{r.invalidateQueries({queryKey:g.admin.asrConfig.platform()}),r.invalidateQueries({queryKey:g.admin.asrConfig.orgPrefix}),x.success("Platform ASR configuration updated")},onError:a=>{x.error(y(a,"ASR config update failed"))}})}function Pe(r){const a=w();return R({mutationFn:s=>A.setOrgOverride(r,s),onSuccess:()=>{a.invalidateQueries({queryKey:g.admin.asrConfig.org(r)}),x.success("Organization override saved")},onError:s=>{x.error(y(s,"ASR config update failed"))}})}function _e(r){const a=w();return R({mutationFn:()=>A.removeOrgOverride(r),onSuccess:()=>{a.invalidateQueries({queryKey:g.admin.asrConfig.org(r)}),x.success("Override removed â using platform default")},onError:s=>{x.error(y(s,"Failed to remove override"))}})}function k({label:r,providerId:a}){const s=a?ue(a):null,n=(s==null?void 0:s.label)??a??"None",t=(s==null?void 0:s.description)??"";return e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:r}),e.jsxs("div",{className:"flex items-center gap-2",children:[a?e.jsx(z,{className:"bg-primary/10 text-primary border border-primary/30 rounded-full text-xs px-2.5 py-0.5",children:n}):e.jsx("span",{className:"text-sm text-muted-foreground",children:"None"}),t&&e.jsxs(W,{children:[e.jsx(X,{asChild:!0,children:e.jsx(Z,{className:"h-3.5 w-3.5 text-muted-foreground cursor-help"})}),e.jsx(J,{className:"max-w-xs text-xs",children:t})]})]})]})}function ze(){const[r,a]=S.useState(!1),{data:s,isLoading:n,isError:t}=H(),l=ke();async function c(o,i){try{await l.mutateAsync({primary_provider:o.primary,fallback_provider:o.fallback??null}),a(!1)}catch(p){const v=y(p,"Failed to save ASR configuration");i("fallback",v)}}return e.jsxs(M,{className:"card-elevated",children:[e.jsxs(K,{className:"flex flex-row items-center justify-between pb-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(U,{className:"h-5 w-5 text-primary"})}),e.jsx(I,{className:"text-base",children:"Platform Defaults"})]}),!r&&e.jsxs(N,{variant:"outline",size:"sm",onClick:()=>a(!0),disabled:n||!s,children:[e.jsx(ge,{className:"h-3.5 w-3.5 mr-1.5"}),"Edit"]})]}),e.jsx(B,{children:t?e.jsx(Q,{variant:"destructive",children:e.jsx(V,{children:"Failed to load platform ASR configuration. Please refresh."})}
1):n?e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsx(b,{className:"h-12"}),e.jsx(b,{className:"h-12"})]}):r&&s?e.jsx($,{defaultValues:{primary:s.primary,fallback:s.fallback},onSubmit:c,onCancel:()=>a(!1),isSubmitting:l.isPending,submitLabel:"Save Changes"}):s?e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsx(k,{label:"Primary",providerId:s.primary}),e.jsx(k,{label:"Fallback",providerId:s.fallback})]}):null})]})}function De({open:r,onOpenChange:a,orgId:s,orgName:n,defaultValues:t}){const l=Pe(s);async function c(o,i){try{await l.mutateAsync({primary_provider:o.primary,fallback_provider:o.fallback??null}),a(!1)}catch(p){const v=y(p,"Failed to save ASR configuration");i("fallback",v)}}return e.jsx(Y,{open:r,onOpenChange:a,children:e.jsxs(ee,{className:"sm:max-w-md",children:[e.jsxs(re,{children:[e.jsxs(ae,{children:["Override ASR Config â ",n]}),e.jsx(se,{children:"Set a custom ASR provider configuration for this organization."})]}),e.jsx($,{defaultValues:t,onSubmit:c,onCancel:()=>a(!1),isSubmitting:l.isPending,submitLabel:"Save Override"})]})})}function we({open:r,onOpenChange:a,orgId:s,orgName:n,platformConfig:t}){const l=_e(s);async function c(){try{await l.mutateAsync(),a(!1)}catch{a(!1)}}const o=O(t.primary)??t.primary,i=t.fallback?O(t.fallback)??t.fallback:"None";return e.jsx(fe,{open:r,onOpenChange:a,children:e.jsxs(xe,{children:[e.jsxs(pe,{children:[e.jsxs(ve,{children:["Remove ASR Override â ",n,"?"]}),e.jsxs(he,{children:["This organization will fall back to platform defaults: Primary:"," ",o," · Fallback: ",i,"."]})]}),e.jsxs(je,{children:[e.jsx(be,{disabled:l.isPending,children:"Cancel"}),e.jsxs(ye,{onClick:c,disabled:l.isPending,children:[l.isPending&&e.jsx(ie,{className:"h-4 w-4 mr-2 animate-spin"}),"Remove Override"]})]})]})})}function Re(){const[r,a]=S.useState(null),[s,n]=S.useState(!1),[t,l]=S.useState(!1),{data:c,isLoading:o}=D({queryKey:g.admin.organizations.list({page:1,page_size:200}),queryFn:()=>de.listOrganizations({page:1,page_size:200})}),{data:i,isLoading:p,isError:v}=Ce(r),{data:m}=H(),P=(c==null?void 0:c.data)??[],_=P.find(u=>u.id===r),F=(i==null?void 0:i.scope)==="organization",G={primary:(i==null?void 0:i.primary)??(m==null?void 0:m.primary)??"assemblyai",fallback:(i==null?void 0:i.fallback)??null};return e.jsxs(M,{className:"card-elevated",children:[e.jsx(K,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(T,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx(I,{className:"text-base",children:"Organization Overrides"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:"Select an organization to view or override its ASR configuration."})]})]})}),e.jsxs(B,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs(ne,{value:r??"",onValueChange:u=>a(u||null),disabled:o,children:[e.jsx(te,{className:"w-full sm:w-72",children:e.jsx(le,{placeholder:o?"Loading organizations...":"Select an organization"})}),e.jsx(oe,{children:P.map(u=>e.jsx(ce,{value:u.id,children:u.name},u.id))})]}),!o&&P.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:"No organizations found."})]}),r?p?e.jsxs("div",{className:"space-y-3",children:[e.jsx(b,{className:"h-8 w-40"}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsx(b,{className:"h-12"}),e.jsx(b,{className:"h-12"})]})]}):v?e.jsx(Q,{variant:"destructive",children:e.jsx(V,{children:"Failed to load ASR configuration for this organization."})}):i?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[F?e.jsx(z,{className:"bg-primary/15 text-primary border border-primary/30",children:"Organization override"}):e.jsx(z,{variant:"outline",className:"text-muted-foreground border-border",children:"Platform default"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Primary: ",O(i.primary)??i.primary,i.fallback&&` · Fallback: ${O(i.fallback)??i.fallback}`]})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsx(k,{label:"Primary",providerId:i.primary}),e.jsx(k,{label:"Fallback",providerId:i.fallback})]}),e.jsx("div",{className:"flex items-center gap-2",children:F?e.jsxs(e.Fragment,{children:[e.jsx(N,{variant:"outline",size:"sm",onClick:()=>n(!0),disabled:!m,children:"Edit override"}),e.jsx(N,{variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>l(!0),children:"Remove override"})]}):e.jsx(N,{size:"sm",onClick:()=>n(!0),disabled:!m,children:"Override"})})]}):null:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(T,{className:"h-8 w-8 text-muted-foreground
1/50 mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select an organization above to view its ASR configuration"})]}),r&&_&&m&&e.jsxs(e.Fragment,{children:[e.jsx(De,{open:s,onOpenChange:n,orgId:r,orgName:_.name,defaultValues:G}),e.jsx(we,{open:t,onOpenChange:l,orgId:r,orgName:_.name,platformConfig:m})]})]})]})}function Ee(){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(U,{className:"h-6 w-6 text-primary"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:"ASR Provider Configuration"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:"Manage speech-to-text providers platform-wide and per organization."})]})]}),e.jsx(ze,{}),e.jsx(Re,{})]})}function Ue(){return e.jsx(Ee,{})}export{Ue as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.