1import{u as e,j as t,S as o,a7 as s}from"./app-DpXMweAS.js";import{w as r}from"./vendor-C1tsdjlK.js";import{M as n}from"./Modal-5rQFnFuY.js";import{B as i}from"./Button-1vSrqVHP.js";import{L as a,g as l,v as c,s as d}from"./llmCredential-BBf8E6hB.js";import{t as m,P as p}from"./index-Rj6ZRufS.js";import{m as u}from"./mapLlmErrorMessage-qHIpVlq_.js";import{I as y}from"./Checkbox-y1WNLIeU.js";import"./selectField-pUbsJRka.js";import{C as x}from"./circle-check-CdZZ3iCN.js";import"./vendor-table-CVLkqsJc.js";import"./vendor-i18n-D3nfHCJR.js";import"./vendor-inertia-DtgBf29N.js";import"./ModalBackdrop-DPdp3gJ3.js";import"./useDialogFocusTrap-zJowLw3Q.js";import"./themeColors-qtr-6vFf.js";import"./features-Dv694woc.js";import"./react-select.esm-6zeiMWNj.js";function WelcomeBody(){const{t:s}=e("common");return t.jsxs("div",{className:"space-y-4 text-body-sm text-[var(--ink-2)]",children:[t.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-[var(--border-subtle)] bg-[var(--surface-2)] px-4 py-3",children:[t.jsx(o,{className:"h-5 w-5 text-[var(--primary-color)]"}),t.jsx("p",{children:s("llmSetup.welcomeLead","AI activity tools use your own OpenAI or Anthropic account â you stay in control of cost and billing.")})]}),t.jsxs("ul",{className:"list-disc space-y-2 pl-5",children:[t.jsx("li",{children:s("llmSetup.welcomePoint1","We never see your credit card â billing stays with your AI provider.")}),t.jsx("li",{children:s("llmSetup.welcomePoint2","Setup takes about two minutes: pick a provider, paste an API key, and test it.")}),t.jsx("li",{children:s("llmSetup.welcomePoint3","You only need to do this once for your practice.")})]})]})}function ChooseProviderBody({provider:o,onSelect:s}){const{t:r}=e("common");return t.jsxs("div",{className:"space-y-3",children:[t.jsx("p",{className:"text-body-sm text-[var(--ink-2)]",children:r("llmSetup.chooseProvider","Choose which AI provider you want to use. Either works â pick the one you already have an account with.")}),t.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:a.map(e=>{const r=o===e.id;return t.jsxs("button",{type:"button",onClick:()=>s(e.id),className:"rounded-xl border-2 p-4 text-left transition "+(r?"border-[var(--primary-color)] bg-[var(--primary-50)] shadow-[var(--shadow-sm)] ring-1 ring-[var(--primary-200)]":"border-[var(--border-subtle)] bg-[var(--surface-elevated)] hover:border-[var(--border-strong)]"),"aria-pressed":r,children:[t.jsxs("div",{className:"flex items-start justify-between gap-2",children:[t.jsx("p",{className:"text-body font-semibold text-[var(--ink)]",children:e.label}),r?t.jsx(x,{className:"h-5 w-5 shrink-0 text-[var(--primary-color)]","aria-hidden":!0}):null]}),t.jsx("p",{className:"mt-1 text-body-sm text-[var(--ink-2)]",children:e.subt
1itle})]},e.id)})})]})}function GetKeyBody({providerOption:o}){const{t:r}=e("common");return t.jsxs("div",{className:"space-y-4",children:[t.jsx("p",{className:"text-body-sm text-[var(--ink-2)]",children:r("llmSetup.getKeyIntro","Follow these steps on {{provider}}. When you have your key, come back here.",{provider:o.label})}),t.jsx("ol",{className:"list-decimal space-y-2 pl-5 text-body-sm text-[var(--ink-2)]",children:o.steps.map(e=>t.jsx("li",{children:e},e))}),t.jsxs("a",{href:o.portalUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 text-body-sm font-medium text-[var(--primary-color)] hover:underline",children:[o.portalLabel,t.jsx(s,{className:"h-4 w-4"})]})]})}function PasteKeyBody({providerOption:o,apiKey:s,onApiKeyChange:r,testing:n,testPassed:a,errorMessage:l,onTest:c}){const{t:d}=e("common");return t.jsxs("div",{className:"space-y-4",children:[t.jsx("p",{className:"text-body-sm text-[var(--ink-2)]",children:d("llmSetup.pasteKeyIntro","Paste your {{provider}} API key below, then test the connection before saving.",{provider:o.label})}),t.jsx(y,{name:"llm_api_key",type:"password",label:d("organization.llm.apiKey","API Key"),value:s,onChange:e=>r(e.target.value),autoComplete:"one-time-code","data-1p-ignore":!0,"data-lpignore":"true","data-bwignore":!0}),t.jsx("p",{className:"text-body-xs text-[var(--ink-3)]",children:o.keyHint}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(i,{type:"button",variant:"secondary",onClick:c,isBusy:n,disabled:!s.trim()||n,children:d("llmSetup.testConnection","Test connection")}),a?t.jsxs("span",{className:"inline-flex items-center gap-1 text-body-sm text-[var(--success-color)]",children:[t.jsx(x,{className:"h-4 w-4"}),d("llmSetup.testPassed","Connection successful")]}):null]}),l?t.jsx("p",{className:"text-body-sm text-[var(--danger-color)]",role:"alert",children:l}):null]})}function DoneBody({providerLabel:o}){const{t:s}=e("common");return t.jsxs("div",{className:"space-y-3 text-center",children:[t.jsx(x,{className:"mx-auto h-10 w-10 text-[var(--success-color)]"}),t.jsx("p",{className:"text-body font-medium text-[var(--ink)]",children:s("llmSetup.doneTitle","You are all set!")}),t.jsx("p",{className:"text-body-sm text-[var(--ink-2)]",children:s("llmSetup.doneBody","Your {{provider}} account is connected. You can now generate and refine activities with AI.",{provider:o})})]})}function NoPermissionBody({onClose:o}){const{t:s}=e("common");return t.jsxs("div",{className:"space-y-4 text-body-sm text-[var(--ink-2)]",children:[t.jsx("p",{children:s("llmSetup.noPermission","Only a practice administrator can connect an AI provider. Ask your administrator to complete setup in Organization Settings.")}),t.jsx("a",{href:"/organization/settings",className:"inline-flex text-body-sm font-medium text-[var(--primary-color)] hover:underline",onClick:o,children:s("llmSetup.openSettings","Open organization settings")})]})}const v=["welcome","choose_provider","get_key","paste_key","done"];function LlmSetupWizard({open:o,organizationUuid:s,initialStep:a,provider:y,source:x,onProviderChange:h,onStepChange:j,onComplete:b,onClose:f}){const{t:g}=e("common"),[k,C]=r.useState(a),[_,N]=r.useState(""),[S,w]=r.useState(!1),[P,A]=r.useState(!1),[L,I]=r.useState(!1),[B,E]=r.useState(null),T=l(y);r.useEffect(()=>{o&&(C(a),N(""),w(!1),A(!1),I(!1),E(null),m(p.LLM_SETUP_WIZARD_OPENED,{source:x,screen_name:"refine_button"===x?"ActivityBuilderV2":"ActivitiesIndex"}))},[o,a,x]);const goToStep=e=>{C(e),j(e),"paste_key"!==e&&(w(!1),E(null)),v.includes(e)&&m(p.LLM_SETUP_WIZARD_STEP_COMPLETED,{step:e,llm_provider:y})},handleSave=async()=>{if(S&&_.trim()){I(!0),E(null);try{await d(s,{provider:y,api_key:_.trim()}),m(p.LLM_SETUP_WIZARD_COMPLETED,{llm_provider:y}),goToStep("done")}catch(e){const t=u(e instanceof Error?e.message:null,e.errorCode??null);E(t.message)}finally{I(!1)}}},D="no_permission"===k?t.jsx("div",{className:"flex justify-end",children:t.jsx(i,{type:"button",onClick:f,children:g("common.close","Close")})}):"done"===k?t.jsx("div",{className:"flex justify-end",children:t.jsx(i,{type:"button",onClick:b,children:g("llmSetup.continueToAi","Continue to AI")})}):"welcome"===k?t.jsx("div",{className:"flex justify-end",children:t.jsx(i,{type:"button",onClick:()=>goToStep("choose_provider"),children:g("common.continue","Continue")})}):"choose_provider"===k?t.jsxs("div",{className:"flex justify-between gap-3",children:[t.jsx(i,{type:"button",variant:"secondary",onClick:()=>goToStep("welcome"),children:g("common.back","Back")}),t.jsx(i,{type:"button",onClick:()=>goToStep("get_key"),children:g("common.continue","Continue")})]}):"get_key"===k?t.jsxs("div",{className:"flex justify-between gap-3",children:[t.jsx(i,{type:"button",variant:"secondary",onClick:()=>goToStep("choose_provider"),children:g("common.back","Back")}),t.jsx(i,{type:"button",onClick:()=>goToStep("paste_key"),children:g("llmSetup.haveKey","I have my key")})]}):t.jsxs("div",{className:"flex justify-between gap-3",children:[t.jsx(i,{type:"button",variant:"secondary",onClick:()=>goToStep("get_key"),children:g("common.back","Back")}),t.jsx(i,{type:"button",onClick:handleSave,isBusy:L,disabled:!S||L,children:g("llmSetup.saveAndContinue","Save & continue")})]});return t.jsxs(n,{open:o,onClose:f,title:g("llmSetup.title","Set up AI for your practice"),size:"lg",footer:D,children:["no_permission"===k?t.jsx(NoPermissionBody,{onClose:f}):null,"welcome"===k?t.jsx(WelcomeBody,{}):null,"choose_provider"===k?t.jsx(ChooseProviderBody,{provider:y,onSelect:e=>{h(e),w(!1),N("")}}):null,"get_key"===k?t.jsx(GetKeyBody,{providerOption:T}):null,"paste_key"===k?t.jsx(PasteKeyBody,{providerOption:T,apiKey:_,onApiKeyChange:e=>{N(e),w(!1),E(null)},testing:P,testPassed:S,errorMessage:B,onTest:async()=>
1{if(_.trim()){A(!0),E(null),w(!1);try{const e=await c(s,y,_.trim());if(e.ok)w(!0),m(p.LLM_CREDENTIAL_VALIDATED,{llm_provider:y,result:"success"});else{const t=u(e.message,e.error_code??null);E(t.message),m(p.LLM_CREDENTIAL_VALIDATED,{llm_provider:y,result:"failure",error_code:t.errorCode??"unknown"})}}catch{E(g("llmSetup.testFailed","We could not test your key. Please try again."))}finally{A(!1)}}}}):null,"done"===k?t.jsx(DoneBody,{providerLabel:T.label}):null]})}export{LlmSetupWizard 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.