1var e=Object.defineProperty,s=(s,t,n)=>((s,t,n)=>t in s?e(s,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):s[t]=n)(s,"symbol"!=typeof t?t+"":t,n);import{r as t,j as n}from"./B8-FzGqy.js";import{F as i,X as a,P as r,L as o,R as c,e as l}from"./KGpMGeUI.js";import{w as d}from"./DHz5e6_e.js";import{u}from"./CEmRXc5a.js";import"./DiuheSsM.js";import"./Ds7E4n62.js";import"./CsepoBIk.js";import"./BjQ-J_pT.js";import"./LOg_l7kj.js";const p=5242880,m=1e4;function _(e){return`${e.name}\0${e.size}\0${e.lastModified}`}function x(e){const s=e.name.toLowerCase().split(".").at(-1);return s&&["pdf","docx","txt"].includes(s)?0===e.size?`${e.name} is empty.`:null:"Clinic supports PDF, DOCX and TXT files only."}function h({busy:e,onBuild:s}){const[l,d]=t.useState(""),[u,h]=t.useState([]),[f,g]=t.useState(null),[b,v]=t.useState(!1),y=t.useRef(null),j=t.useMemo(()=>u.reduce((e,s)=>e+s.size,0),[u]),N=(l.trim().length>=3||u.length>0)&&l.length<=m&&j<=p&&!f,$=e=>{const s=[...u],t=new Set(s.map(_)),n=new Set(s.map(e=>e.name.toLowerCase()));for(const i of e){const e=x(i);if(e)return void g(e);if(!t.has(_(i))){if(n.has(i.name.toLowerCase()))return void g("Clinic file names must be unique.");if(s.length>=3)return void g("Clinic accepts at most 3 files.");if(s.reduce((e,s)=>e+s.size,0)+i.size>p)return void g("Combined file material must not exceed 5 MB.");s.push(i),t.add(_(i)),n.add(i.name.toLowerCase())}}g(null),h(Object.freeze(s))};return n.jsxs("div",{className:"relative rounded-3xl border bg-white shadow-xl transition "+(b?"border-blue-500 ring-4 ring-blue-100":"border-slate-300"),onDragEnter:e=>{e.preventDefault(),v(!0)},onDragOver:e=>e.preventDefault(),onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||v(!1)},onDrop:e=>{e.preventDefault(),v(!1),$([...e.dataTransfer.files])},children:[b&&n.jsx("div",{className:"pointer-events-none absolute inset-0 z-10 flex items-center justify-center rounded-3xl bg-blue-50/95 text-sm font-semibold text-blue-800",children:"Drop case materials here"}),u.length>0&&n.jsx("ul",{className:"flex flex-wrap gap-2 px-4 pt-4","aria-label":"Selected case files",children:u.map(s=>{return n.jsxs("li",{className:"flex max-w-full items-center gap-2 rounded-xl border border-slate-200 bg-slate-50 px-3 py-2",children:[n.jsx(i,{className:"h-4 w-4 shrink-0 text-blue-700","aria-hidden":"true"}),n.jsxs("span",{className:"min-w-0",children:[n.jsx("span",{className:"block truncate text-xs font-semibold text-slate-800",children:s.name}),n.jsxs("span",{className:"block text-[11px] text-slate-500",children:[(t=s.size,t<1024?`${t} B`:t<1048576?`${Math.ceil(t/1024)} KB`:`${(t/1048576).toFixed(1)} MB`)," · ",e?"Reading securelyâ¦":"Ready to read"]})]}),n.jsx("button",{type:"button","aria-label":`Remove ${s.name}`,disabled:e,className:"rounded p-1 text-slate-500 hover:bg-slate-200 hover:text-slate-900 disabled:opacity-50",onClick:()=>{h(u.filter(e=>_(e)!==_(s))),g(null)},children:n.jsx(a,{className:"h-4 w-4","aria-hidden":"true"})})]},_(s));var t})}),n.jsx("textarea",{"aria-label":"Practice matter request",value:l,disabled:e,maxLength:m,rows:7,className:"w-full resize-y border-0 bg-transparent px-5 py-5 text-base leading-7 text-slate-900 outline-none placeholder:text-slate-400 disabled:bg-slate-50",placeholder:"Describe the practice matter you want, or add supporting documents",onChange:e=>{d(e.target.value),g(null)},onPaste:e=>{const s=[...e.clipboardData.files];0!==s.length&&(e.preventDefault(),$(s))}}),n.jsx("input",{ref:y,type:"file",className:"hidden",accept:".pdf,.docx,.txt,application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,text/plain",multiple:!0,onChange:e=>{e.target.files&&$([...e.target.files]),e.target.value=""}}),n.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 border-t border-slate-100 px-4 py-3",children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[n.jsxs("button",{type:"button",disabled:e||u.length>=3,className:"inline-flex min-h-10 items-center gap-2 rounded-xl px-3 text-sm font-semibold text-slate-700 hover:bg-slate-100 disabled:opacity-50",onClick:()=>y.current?.click(),children:[n.jsx(r,{className:"h-4 w-4","aria-hidden":"true"}
1),"Add files"]}),n.jsxs("span",{className:"text-xs text-slate-500",children:[u.length,"/",3," files · ",l.length.toLocaleString(),"/",m.toLocaleString()," characters"]})]}),n.jsxs("button",{type:"button",disabled:e||!N,className:"inline-flex min-h-11 items-center justify-center gap-2 rounded-xl bg-blue-700 px-5 py-2 text-sm font-semibold text-white hover:bg-blue-800 disabled:cursor-not-allowed disabled:opacity-50",onClick:()=>s(l,u),children:[e?n.jsx(o,{className:"h-4 w-4 animate-spin","aria-hidden":"true"}):null,e?"Preparing materialsâ¦":"Build practice matter"]})]}),f&&n.jsxs("div",{role:"alert",className:"flex items-center justify-between gap-3 border-t border-red-100 bg-red-50 px-4 py-3 text-xs text-red-800",children:[n.jsx("span",{children:f}),n.jsxs("button",{type:"button",className:"inline-flex items-center gap-1 font-semibold",onClick:()=>{g(null),y.current?.click()},children:[n.jsx(c,{className:"h-3.5 w-3.5","aria-hidden":"true"}),"Retry selection"]})]})]})}function f({label:e,value:s,title:t,detail:i,active:a=!1}){const r=Math.min(100,Math.max(0,Math.round(s)));return n.jsxs("section",{className:"rounded-xl border border-blue-200 bg-white p-4 shadow-sm","aria-label":`${e} status`,children:[n.jsxs("div",{className:"flex items-start justify-between gap-4",children:[n.jsxs("div",{children:[n.jsx("p",{className:"text-xs font-bold uppercase tracking-widest text-blue-700",children:e}),n.jsx("p",{className:"mt-1 font-semibold text-slate-950",children:t})]}),n.jsxs("p",{className:"shrink-0 text-sm font-bold tabular-nums text-blue-800",children:[r,"%"]})]}),n.jsx("div",{role:"progressbar","aria-label":e,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":r,"aria-valuetext":`${t}. ${i}`,className:"relative mt-3 h-2 overflow-hidden rounded-full bg-blue-100",children:n.jsx("div",{className:"h-full rounded-full bg-blue-700 transition-[width] duration-500 "+(a?"animate-pulse":""),style:{width:`${r}%`}})}),n.jsx("p",{role:"status",className:"mt-3 text-sm leading-6 text-slate-600",children:i})]})}const g=["NOT_FOUND","STALE_VERSION","IDEMPOTENCY_CONFLICT","INVALID_TRANSITION","INVALID_INPUT","INVALID_REQUEST","INVALID_REQUEST_BODY","INCOMPLETE","TOO_MANY_ACTIVE_RUNS","ALREADY_SUBMITTED","CONCURRENT_REQUEST","REQUEST_TOO_LARGE","UNSUPPORTED_MEDIA_TYPE","SERVICE_UNAVAILABLE","INTERNAL_ERROR","RATE_LIMITED","COMPILATION_FAILED","INVALID_MODEL_OUTPUT","MODEL_UNAVAILABLE","UNAUTHENTICATED"];class b extends Error{constructor(e,s){super(`Parse failed at ${e}: ${s}`),this.name="ParseError"}}const v=["PREPARING","ACTIVE","SUBMITTED"],y=["decision","revision","tutor_question","final_submission"],j=["strong","defensible","partially_defensible","unsupported","overconfident","dangerously_incorrect"],N=["student_action","source_span"],$=["aligned","partially_aligned","contradictory"],w=["issue_framing","material_fact_use","fact_inference_distinction","competing_interpretations","uncertainty_calibration","proposed_next_action","escalation_and_professional_judgement","clarity_and_structure"],k=["submission_excerpt","frozen_spec_omission"],I=["premature_conclusion","decision_reasoning_mismatch","overconfidence","missing_evidence","incomplete_reasoning","unsafe_or_unsupported_action"];function E(e,s){if("object"!=typeof e||null===e||Array.isArray(e)||Object.getPrototypeOf(e)!==Object.prototype)throw new b(s,"expected plain object");return e}function R(e,s,t){const n=new Set(s);for(const i of Object.keys(e))if(!n.has(i))throw new b(t,`unexpected key "${i}"`);for(const i of s)if(!(i in e))throw new b(t,`missing key "${i}"`)}function C(e,s){if("string"!=typeof e||0===e.length)throw new b(s,"expected non-empty string");return e}function T(e,s){return null===e?null:C(e,s)}function S(e,s,t=0,n=Number.MAX_SAFE_INTEGER){if("number"!=typeof e||!Number.isSafeInteger(e)||e<t||e>n)throw new b(s,"expected bounded integer");return e}function D(e,s){if("number"!=typeof e||!Number.isFinite(e))throw new b(s,"expected finite number");return e}function A(e,s){if("boolean"!=typeof e)throw new b(s,"expected boolean");return e}function q(e,s){if(!Array.isArray(e))throw new b(s,"expected array");return e}function O(e,s){return q(e,s).map((e,t)=>C(e,`${s}[${t}]`))}function L(e,s,t){const n=C(e,t);if(!s.includes(n))throw new b(t,`invalid enum "${n}"`);return n}function P(e,s){const t=E(e,s);return R(t,["span_id","source_id","source_display_name","page_or_section","quoted_excerpt"],s),{span_id:C(t.span_id,`${s}.span_id`),source_id:C(t.source_id,`${s}.source_id`),source_display_name:C(t.source_display_name,`${s}.source_display_name`),page_or_section:T(t.page_or_section,`${s}.page_or_section`),quoted_excerpt:C(t.quoted_excerpt,`${s}.quoted_excerpt`)}}function M(e,s){const t=E(e,s);
1return R(t,["node_id","question","source_span_ids","competency_ids","options"],s),{node_id:C(t.node_id,`${s}.node_id`),question:C(t.question,`${s}.question`),source_span_ids:O(t.source_span_ids,`${s}.source_span_ids`),competency_ids:O(t.competency_ids,`${s}.competency_ids`),options:q(t.options,`${s}.options`).map((e,t)=>function(e,s){const t=E(e,s);return R(t,["option_id","text"],s),{option_id:C(t.option_id,`${s}.option_id`),text:C(t.text,`${s}.text`)}}(e,`${s}.options[${t}]`))}}function U(e,s){const t=E(e,s);return R(t,["spec_id","spec_version","spec_fingerprint","title","scenario_summary","student_role","learning_objectives","sources","source_spans","facts","ambiguities","issues","competencies"],s),{spec_id:C(t.spec_id,`${s}.spec_id`),spec_version:C(t.spec_version,`${s}.spec_version`),spec_fingerprint:C(t.spec_fingerprint,`${s}.spec_fingerprint`),title:C(t.title,`${s}.title`),scenario_summary:C(t.scenario_summary,`${s}.scenario_summary`),student_role:C(t.student_role,`${s}.student_role`),learning_objectives:O(t.learning_objectives,`${s}.learning_objectives`),sources:q(t.sources,`${s}.sources`).map((e,t)=>function(e,s){const t=E(e,s);return R(t,["source_id","display_name","media_type","text","text_sha256"],s),{source_id:C(t.source_id,`${s}.source_id`),display_name:C(t.display_name,`${s}.display_name`),media_type:C(t.media_type,`${s}.media_type`),text:C(t.text,`${s}.text`),text_sha256:C(t.text_sha256,`${s}.text_sha256`)}}(e,`${s}.sources[${t}]`)),source_spans:q(t.source_spans,`${s}.source_spans`).map((e,t)=>function(e,s){const t=E(e,s);return R(t,["span_id","source_id","page_or_section","start_offset","end_offset","quoted_text","grounding_allowed"],s),{span_id:C(t.span_id,`${s}.span_id`),source_id:C(t.source_id,`${s}.source_id`),page_or_section:T(t.page_or_section,`${s}.page_or_section`),start_offset:S(t.start_offset,`${s}.start_offset`),end_offset:S(t.end_offset,`${s}.end_offset`,1),quoted_text:C(t.quoted_text,`${s}.quoted_text`),grounding_allowed:A(t.grounding_allowed,`${s}.grounding_allowed`)}}(e,`${s}.source_spans[${t}]`)),facts:q(t.facts,`${s}.facts`).map((e,t)=>function(e,s){const t=E(e,s);return R(t,["fact_id","statement","kind","source_span_ids"],s),{fact_id:C(t.fact_id,`${s}.fact_id`),statement:C(t.statement,`${s}.statement`),kind:C(t.kind,`${s}.kind`),source_span_ids:O(t.source_span_ids,`${s}.source_span_ids`)}}(e,`${s}.facts[${t}]`)),ambiguities:q(t.ambiguities,`${s}.ambiguities`).map((e,t)=>function(e,s){const t=E(e,s);return R(t,["ambiguity_id","description","source_span_ids"],s),{ambiguity_id:C(t.ambiguity_id,`${s}.ambiguity_id`),description:C(t.description,`${s}.description`),source_span_ids:O(t.source_span_ids,`${s}.source_span_ids`)}}(e,`${s}.ambiguities[${t}]`)),issues:q(t.issues,`${s}.issues`).map((e,t)=>function(e,s){const t=E(e,s);return R(t,["issue_id","title","question","source_span_ids"],s),{issue_id:C(t.issue_id,`${s}.issue_id`),title:C(t.title,`${s}.title`),question:C(t.question,`${s}.question`),source_span_ids:O(t.source_span_ids,`${s}.source_span_ids`)}}(e,`${s}.issues[${t}]`)),competencies:q(t.competencies,`${s}.competencies`).map((e,t)=>function(e,s){const t=E(e,s);return R(t,["competency_id","label","description"],s),{competency_id:C(t.competency_id,`${s}.competency_id`),label:C(t.label,`${s}.label`),description:C(t.description,`${s}.description`)}}(e,`${s}.competencies[${t}]`))}}function V(e,s){const t=E(e,s);return R(t,["assessment_event_id","action_id","competency_id","result","score_awarded","score_available","evidence","source_evidence","feedback","confidence","decision_reasoning_alignment","alignment_explanation"],s),{assessment_event_id:C(t.assessment_event_id,`${s}.assessment_event_id`),action_id:C(t.action_id,`${s}.action_id`),competency_id:C(t.competency_id,`${s}.competency_id`),result:L(t.result,j,`${s}.result`),score_awarded:S(t.score_awarded,`${s}.score_awarded`),score_available:S(t.score_available,`${s}.score_available`,1),evidence:q(t.evidence,`${s}.evidence`).map((e,t)=>function(e,s){const t=E(e,s);return R(t,["kind","evidence_id","explanation"],s),{kind:L(t.kind,N,`${s}.kind`),evidence_id:C(t.evidence_id,`${s}.evidence_id`),explanation:C(t.explanation,`${s}.explanation`)}}(e,`${s}.evidence[${t}]`)),source_evidence:q(t.source_evidence,`${s}.source_evidence`).map((e,t)=>P(e,`${s}.source_evidence[${t}]`)),feedback:C(t.feedback,`${s}.feedback`),confidence:D(t.confidence,`${s}.confidence`),decision_reasoning_alignment:L(t.decision_reasoning_alignment,$,`${s}.decision_reasoning_alignment`),alignment_explanation:C(t.alignment_explanation,`${s}.alignment_explanation`)}}function B(e,s){const t=E(e,s);R(t,["dimension","competency_id","score_awarded","score_available","evidence","feedback"],s);if(2!==S(t.score_available,`${s}.score_available`,1))throw new b(`${s}.score_available`,"expected 2");return{dimension:L(t.dimension,w,`${s}.dimension`),competency_id:C(t.competency_id,`${s}
1.competency_id`),score_awarded:S(t.score_awarded,`${s}.score_awarded`),score_available:2,evidence:q(t.evidence,`${s}.evidence`).map((e,t)=>function(e,s){const t=E(e,s);return R(t,["kind","excerpt","spec_reference_id","explanation"],s),{kind:L(t.kind,k,`${s}.kind`),excerpt:T(t.excerpt,`${s}.excerpt`),spec_reference_id:T(t.spec_reference_id,`${s}.spec_reference_id`),explanation:C(t.explanation,`${s}.explanation`)}}(e,`${s}.evidence[${t}]`)),feedback:C(t.feedback,`${s}.feedback`)}}function F(e,s){if(null===e)return null;const t=E(e,s);R(t,["assessment_event_id","action_id","dimensions","score_awarded","score_available","feedback"],s);if(16!==S(t.score_available,`${s}.score_available`,1))throw new b(`${s}.score_available`,"expected 16");return{assessment_event_id:C(t.assessment_event_id,`${s}.assessment_event_id`),action_id:C(t.action_id,`${s}.action_id`),dimensions:q(t.dimensions,`${s}.dimensions`).map((e,t)=>B(e,`${s}.dimensions[${t}]`)),score_awarded:S(t.score_awarded,`${s}.score_awarded`),score_available:16,feedback:C(t.feedback,`${s}.feedback`)}}function G(e,s){const t=E(e,s);return R(t,["node_id","student_action_id","expert_option_id","student_option_ids","divergence_type","student_choice","student_reasoning_summary","expert_reference","misconception_id","decision_reasoning_alignment","overlooked_source_span_ids","overlooked_evidence","why_the_choice_was_plausible","why_it_was_incomplete_or_wrong","downstream_effect","corrective_principle","next_practice"],s),{node_id:C(t.node_id,`${s}.node_id`),student_action_id:C(t.student_action_id,`${s}.student_action_id`),expert_option_id:C(t.expert_option_id,`${s}.expert_option_id`),student_option_ids:O(t.student_option_ids,`${s}.student_option_ids`),divergence_type:L(t.divergence_type,I,`${s}.divergence_type`),student_choice:C(t.student_choice,`${s}.student_choice`),student_reasoning_summary:C(t.student_reasoning_summary,`${s}.student_reasoning_summary`),expert_reference:C(t.expert_reference,`${s}.expert_reference`),misconception_id:T(t.misconception_id,`${s}.misconception_id`),decision_reasoning_alignment:L(t.decision_reasoning_alignment,$,`${s}.decision_reasoning_alignment`),overlooked_source_span_ids:O(t.overlooked_source_span_ids,`${s}.overlooked_source_span_ids`),overlooked_evidence:q(t.overlooked_evidence,`${s}.overlooked_evidence`).map((e,t)=>P(e,`${s}.overlooked_evidence[${t}]`)),why_the_choice_was_plausible:C(t.why_the_choice_was_plausible,`${s}.why_the_choice_was_plausible`),why_it_was_incomplete_or_wrong:C(t.why_it_was_incomplete_or_wrong,`${s}.why_it_was_incomplete_or_wrong`),downstream_effect:C(t.downstream_effect,`${s}.downstream_effect`),corrective_principle:C(t.corrective_principle,`${s}.corrective_principle`),next_practice:C(t.next_practice,`${s}.next_practice`)}}function z(e,s){if(null===e)return null;const t=E(e,s);return R(t,["student_path","expert_path","all_material_divergences","first_material_divergence","downstream_effects","competency_scores","strengths","improvement_points","structured_reasoning_map","misconceptions"],s),{student_path:q(t.student_path,`${s}.student_path`).map((e,t)=>function(e,s){const t=E(e,s);R(t,["action_id","node_id","node_question","selected_option_ids","selected_option_texts","student_reasoning","assessment_result","is_revision"],s);const n=O(t.selected_option_ids,`${s}.selected_option_ids`),i=O(t.selected_option_texts,`${s}.selected_option_texts`);if(n.length!==i.length)throw new b(s,"selected option IDs and display texts must reconcile");return{action_id:C(t.action_id,`${s}.action_id`),node_id:C(t.node_id,`${s}.node_id`),node_question:C(t.node_question,`${s}.node_question`),selected_option_ids:n,selected_option_texts:i,student_reasoning:C(t.student_reasoning,`${s}.student_reasoning`),assessment_result:L(t.assessment_result,j,`${s}.assessment_result`),is_revision:A(t.is_revision,`${s}.is_revision`)}}(e,`${s}.student_path[${t}]`)),expert_path:q(t.expert_path,`${s}.expert_path`).map((e,t)=>function(e,s){const t=E(e,s);return R(t,["node_id","node_question","recommended_option_id","recommended_option_text","rationale","source_span_ids"],s),{node_id:C(t.node_id,`${s}.node_id`),node_question:C(t.node_question,`${s}.node_question`),recommended_option_id:C(t.recommended_option_id,`${s}.recommended_option_id`),recommended_option_text:C(t.recommended_option_text,`${s}.recommended_option_text`),rationale:C(t.rationale,`${s}.rationale`),source_span_ids:O(t.source_span_ids,`${s}.source_span_ids`)}}(e,`${s}.expert_path[${t}]`)),all_material_divergences:q(t.all_material_divergences,`${s}.all_material_divergences`).map((e,t)=>G(e,`${s}.all_material_divergences[${t}]`)),first_material_divergence:null===t.first_material_divergence?null:G(t.first_material_divergence,`${s}.first_material_divergence`),downstream_effects:O(t.downstream_effects,`${s}.downstream_effects`),competency_scores:q(t.competency_scores,`${s}
1.competency_scores`).map((e,t)=>function(e,s){const t=E(e,s);return R(t,["competency_id","score_awarded","score_available"],s),{competency_id:C(t.competency_id,`${s}.competency_id`),score_awarded:S(t.score_awarded,`${s}.score_awarded`),score_available:S(t.score_available,`${s}.score_available`,1)}}(e,`${s}.competency_scores[${t}]`)),strengths:O(t.strengths,`${s}.strengths`),improvement_points:O(t.improvement_points,`${s}.improvement_points`),structured_reasoning_map:q(t.structured_reasoning_map,`${s}.structured_reasoning_map`).map((e,t)=>function(e,s){const t=E(e,s);return R(t,["node_id","decision","relevant_fact_span_ids","competing_interpretations","supporting_evidence_span_ids","countervailing_evidence_span_ids","missing_information","current_conclusion","confidence","next_professional_step"],s),{node_id:C(t.node_id,`${s}.node_id`),decision:C(t.decision,`${s}.decision`),relevant_fact_span_ids:O(t.relevant_fact_span_ids,`${s}.relevant_fact_span_ids`),competing_interpretations:O(t.competing_interpretations,`${s}.competing_interpretations`),supporting_evidence_span_ids:O(t.supporting_evidence_span_ids,`${s}.supporting_evidence_span_ids`),countervailing_evidence_span_ids:O(t.countervailing_evidence_span_ids,`${s}.countervailing_evidence_span_ids`),missing_information:O(t.missing_information,`${s}.missing_information`),current_conclusion:C(t.current_conclusion,`${s}.current_conclusion`),confidence:D(t.confidence,`${s}.confidence`),next_professional_step:C(t.next_professional_step,`${s}.next_professional_step`)}}(e,`${s}.structured_reasoning_map[${t}]`)),misconceptions:q(t.misconceptions,`${s}.misconceptions`).map((e,t)=>function(e,s){const t=E(e,s);return R(t,["misconception_id","label","explanation"],s),{misconception_id:C(t.misconception_id,`${s}.misconception_id`),label:C(t.label,`${s}.label`),explanation:C(t.explanation,`${s}.explanation`)}}(e,`${s}.misconceptions[${t}]`))}}function X(e,s){const t=E(e,s);return R(t,["can_decide","can_ask_tutor","can_submit","can_delete"],s),{can_decide:A(t.can_decide,`${s}.can_decide`),can_ask_tutor:A(t.can_ask_tutor,`${s}.can_ask_tutor`),can_submit:A(t.can_submit,`${s}.can_submit`),can_delete:A(t.can_delete,`${s}.can_delete`)}}function Y(e,s){const t=E(e,s);return R(t,["reasoning_max_chars","tutor_question_max_chars","final_response_max_chars","tutor_turn_limit"],s),{reasoning_max_chars:S(t.reasoning_max_chars,`${s}.reasoning_max_chars`,1),tutor_question_max_chars:S(t.tutor_question_max_chars,`${s}.tutor_question_max_chars`,1),final_response_max_chars:S(t.final_response_max_chars,`${s}.final_response_max_chars`,1),tutor_turn_limit:S(t.tutor_turn_limit,`${s}.tutor_turn_limit`,1)}}function W(e,s="progress"){const t=E(e,s);R(t,["completed_decisions","total_decisions","current_decision"],s);const n=S(t.completed_decisions,`${s}.completed_decisions`,0,5),i=S(t.total_decisions,`${s}.total_decisions`,0,5),a=null===t.current_decision?null:S(t.current_decision,`${s}.current_decision`,1,5);if(n>i)throw new b(s,"completed_decisions must not exceed total_decisions");if(null!==a&&a>i)throw new b(s,"current_decision must not exceed total_decisions");return{completed_decisions:n,total_decisions:i,current_decision:a}}function Q(e,s,t="run"){const n=E(e,t);R(n,["run_id","status","version","current_node","spec","materials","actions","assessments","tutor_turns","final_response","final_assessment","replay","created_at_epoch","updated_at_epoch","expires_at_epoch","submitted_at_epoch","allowed_actions","constraints"],t);const i=L(n.status,v,`${t}.status`),a=W(s,`${t}.progress`);return function(e,s,t){const{completed_decisions:n,total_decisions:i}=s,a=s.current_decision;if("PREPARING"===e){if(0!==n||0!==i||null!==a)throw new b(t,"PREPARING progress must be empty");return}if(i<3)throw new b(t,"compiled progress requires at least 3 decisions");if("SUBMITTED"===e){if(n!==i||null!==a)throw new b(t,"SUBMITTED progress must be complete");return}if(a!==(n<i?n+1:null))throw new b(t,"ACTIVE progress does not match the current decision")}(i,a,`${t}.progress`),{run_id:C(n.run_id,`${t}.run_id`),status:i,version:S(n.version,`${t}.version`,1),progress:a,current_node:null===n.current_node?null:M(n.current_node,`${t}.current_node`),spec:null===n.spec?null:U(n.spec,`${t}.spec`),materials:q(n.materials,`${t}.materials`).map((e,s)=>function(e,s){const t=E(e,s);return R(t,["source_id","display_name","media_type","character_count","text_sha256"],s),{source_id:C(t.source_id,`${s}.source_id`),display_name:C(t.display_name,`${s}.display_name`),media_type:C(t.media_type,`${s}.media_type`),character_count:S(t.character_count,`${s}.character_count`,1),text_sha256:C(t.text_sha256,`${s}.text_sha256`)}}(e,`${t}.materials[${s}]`)),actions:q(n.actions,`${t}.actions`).map((e,s)=>function(e,s){const t=E(e,s);return R(t,["action_id","action_type","node_id","selected_option_ids","student_reasoning","student_question","created_at_epoch"],s),{action_id:C(t.action_id,`${s}.action_id`),action_type:L(t.action_type,y,`${s}.action_type`),node_id:T(t.node_id,`${s}.node_id`),selected_option_ids:O(t.selected_option_ids,`${s}.selected_option_ids`),student_reasoning:T(t.student_reasoning,`${s}.student_reasoning`),student_question:T(t.student_question,`${s}.student_question`),created_at_epoch:S(t.created_at_epoch,`${s}.created_at_epoch`,1)}}(e,`${t}.actions[${s}]`)),assessments:q(n.assessments,`${t}.assessments`).map((e,s)=>V(e,`${t}.assessments[${s}]`)),tutor_turns:q(n.tutor_turns,`${t}.tutor_turns`).map((e,s)=>function(e,s){const t=E(e,s);return R(t,["tutor_turn_id","action_id","node_id","intent","pedagogical_move","response","focused_question","option_prompts","source_span_ids","confidence"],s),{tutor_turn_id:C(t.tutor_turn_id,`${s}.tutor_turn_id`),action_id:C(t.action_id,`${s}.action_id`),node_id:C(t.node_id,`${s}.node_id`),intent:C(t.intent,`${s}.intent`),pedagogical_move:C(t.pedagogical_move,`${s}.pedagogical_move`),response:C(t.response,`${s}.response`),focused_question:T(t.focused_question,`${s}.focused_question`),option_prompts:O(t.option_prompts,`${s}.option_prompts`),source_span_ids:O(t.source_span_ids,`${s}.source_span_ids`),confidence:D(t.confidence,`${s}.confidence`)}}(e,`${t}.tutor_turns[${s}]`)),final_response:T(n.final_response,`${t}.final_response`),final_assessment:F(n.final_assessment,`${t}.final_assessment`),replay:z(n.replay,`${t}.replay`),created_at_epoch:S(n.created_at_epoch,`${t}.created_at_epoch`,1),updated_at_epoch:S(n.updated_at_epoch,`${t}.updated_at_epoch`,1),expires_at_epoch:S(n.expires_at_epoch,`${t}.expires_at_epoch`,1),submitted_at_epoch:null===n.submitted_at_epoch?null:S(n.submitted_at_epoch,`${t}.submitted_at_epoch`,1),allowed_actions:X(n.allowed_actions,`${t}.allowed_actions`),constraints:Y(n.constraints,`${t}.constraints`)}}const K=(""||"/api/education").replace(/\/+$/,"")||"/api/education";
1class H extends Error{constructor(e){super(e),this.name="ClinicNetworkError"}}class J extends Error{constructor(e){super(e.message),s(this,"error"),this.name="ClinicResponseError",this.error=e}}function Z(){const e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-",s=new Uint8Array(24);crypto.getRandomValues(s);let t="";for(const n of s)t+=e[n%64];return t}async function ee(e,s,t){const n={Authorization:`Bearer ${t.authToken}`};let i;"undefined"!=typeof FormData&&t.body instanceof FormData?i=t.body:void 0!==t.body&&(n["Content-Type"]="application/json",i=JSON.stringify(t.body)),t.operationId&&(n["X-Operation-Id"]=t.operationId);try{return await fetch(d(`${K}${s}`,e),{method:e,headers:n,body:i,signal:t.signal})}catch(a){if(a instanceof DOMException&&"AbortError"===a.name)throw a;throw new H("Network request failed")}}function se(e){return new J({code:"UNKNOWN",message:"Invalid server response.",retryable:!1,httpStatus:e})}async function te(e){let s;try{s=await e.json()}catch{s=null}throw new J(function(e,s){try{const t=E(s,"error_response");R(t,["error"],"error_response");const n=E(t.error,"error_response.error");R(n,["code","message","retryable"],"error_response.error");const i=C(n.code,"error_response.error.code"),a=C(n.message,"error_response.error.message"),r=A(n.retryable,"error_response.error.retryable"),o=g.includes(i);return{code:o?i:"UNKNOWN",message:o?a:"An unexpected error occurred.",retryable:r,httpStatus:e}}catch{return{code:"UNKNOWN",message:"An unexpected error occurred.",retryable:e>=500,httpStatus:e}}}(e.status,s))}async function ne(e,s,t){if(!e.ok)return te(e);if(e.status!==s)throw se(e.status);let n;try{n=await e.json()}catch{throw se(e.status)}try{return t(n)}catch(i){if(i instanceof b)throw se(e.status);throw i}}function ie(e){const s=s=>{const t=e.headers.get(s);if(null===t||!/^(0|[1-9]\d*)$/.test(t))throw new b(`response.headers.${s}`,"expected integer header");return Number(t)},t=e.headers.get("X-Clinic-Current-Decision");if(null===t||"none"!==t&&!/^[1-9]\d*$/.test(t))throw new b("response.headers.X-Clinic-Current-Decision","expected decision number or none");return W({completed_decisions:s("X-Clinic-Completed-Decisions"),total_decisions:s("X-Clinic-Total-Decisions"),current_decision:"none"===t?null:Number(t)},"response.headers.progress")}function ae(e){return s=>function(e,s){const t=E(e,"response");return R(t,["run"],"response"),Q(t.run,s)}(s,ie(e))}function re(e){return s=>function(e,s){const t=E(e,"response");R(t,["action","run"],"response");const n=E(t.action,"response.action");return R(n,["fresh","resulting_version"],"response.action"),{action:{fresh:A(n.fresh,"response.action.fresh"),resulting_version:S(n.resulting_version,"response.action.resulting_version",1)},run:Q(t.run,s)}}(s,ie(e))}async function oe(e,s,t,n,i){const a=await ee("POST",`/clinic/runs/${e}/compile`,{operationId:t,authToken:n,signal:i,body:{expected_version:s}});return ne(a,200,re(a))}const ce="lawg_clinic_run_id";function le(){try{return localStorage.getItem(ce)}catch{return null}}function de(e){try{localStorage.setItem(ce,e)}catch{}}function ue(){try{localStorage.removeItem(ce)}catch{}}const pe={run:null,loading:!1,pending:null,error:null};function me(e,s){switch(s.type){case"LOADING":return{...e,loading:!0,error:null};case"PENDING":return{...e,loading:!0,error:null,pending:s.pending};case"RUN":return{run:s.run,loading:!1,pending:null,error:null};case"ERROR":return{...e,loading:!1,error:s.message,pending:s.keepPending?e.pending:null};case"CLEAR_ERROR":return{...e,error:null};case"CANCEL":return{...e,loading:!1,pending:null,error:null};case"RESET":return pe}}function _e(e){return`compile_${e}`}function xe(){const{getAuthToken:e}=u(),[s,n]=t.useReducer(me,pe),i=t.useRef(null),a=t.useRef(null),r=t.useRef(0),o=t.useCallback(async s=>{try{const t=await e(),i=await async function(e,s,t){const n=await ee("GET",`/clinic/runs/${e}`,{authToken:s,signal:t});return ne(n,200,ae(n))}(s,t);return de(i.run_id),n({type:"RUN",run:i}),i}catch(t){if(t instanceof J&&"NOT_FOUND"===t.error.code)return ue(),n({type:"RESET"}),null;const e=t instanceof J?t.error.message:"Unable to refresh this matter.";return n({type:"ERROR",message:e,keepPending:!1}),null}},[e]),c=t.useCallback(async(s,t,a)=>{let c=s;try{const o=await e();let l=null;switch(s.kind){case"create":{const e=await async function(e,s,t,n){const i=new FormData;e.buildRequest.trim()&&i.append("build_request",e.buildRequest.trim()),e.files.forEac
1h(e=>i.append("files",e,e.name));const a=await ee("POST","/clinic/runs",{operationId:s,authToken:t,signal:n,body:i});return ne(a,201,ae(a))}({buildRequest:s.buildRequest,files:s.files},s.operationId,o,t);if(a!==r.current)return;if(de(e.run_id),n({type:"RUN",run:e}),"PREPARING"!==e.status){l=e;break}const d={kind:"compile",operationId:_e(e.run_id),runId:e.run_id,expectedVersion:e.version};c=d,i.current=d,n({type:"PENDING",pending:d}),l=(await oe(e.run_id,e.version,d.operationId,o,t)).run;break}case"compile":l=(await oe(s.runId,s.expectedVersion,s.operationId,o,t)).run;break;case"decision":l=(await async function(e,s,t,n,i){const a=await ee("POST",`/clinic/runs/${e}/decisions`,{operationId:t,authToken:n,signal:i,body:{expected_version:s.expectedVersion,node_id:s.nodeId,selected_option_ids:[...s.selectedOptionIds],reasoning:s.reasoning}});return ne(a,200,re(a))}(s.runId,{expectedVersion:s.expectedVersion,nodeId:s.nodeId,selectedOptionIds:s.selectedOptionIds,reasoning:s.reasoning},s.operationId,o,t)).run;break;case"tutor":l=(await async function(e,s,t,n,i,a){const r=await ee("POST",`/clinic/runs/${e}/tutor`,{operationId:n,authToken:i,signal:a,body:{expected_version:s,question:t}});return ne(r,200,re(r))}(s.runId,s.expectedVersion,s.question,s.operationId,o,t)).run;break;case"submit":l=(await async function(e,s,t,n,i,a){const r=await ee("POST",`/clinic/runs/${e}/submit`,{operationId:n,authToken:i,signal:a,body:{expected_version:s,final_response:t}});return ne(r,200,re(r))}(s.runId,s.expectedVersion,s.finalResponse,s.operationId,o,t)).run;break;case"delete":if(await async function(e,s,t){const n=await ee("DELETE",`/clinic/runs/${e}`,{authToken:s,signal:t});204!==n.status&&await ne(n,204,()=>{})}(s.runId,o,t),a!==r.current)return;return ue(),i.current=null,void n({type:"RESET"})}if(a!==r.current||null===l)return;i.current=null,de(l.run_id),n({type:"RUN",run:l})}catch(l){if(a!==r.current)return;if(l instanceof DOMException&&"AbortError"===l.name)return;if(l instanceof J&&["STALE_VERSION","ALREADY_SUBMITTED","INVALID_TRANSITION"].includes(l.error.code)&&"create"!==c.kind)return i.current=null,void(await o(c.runId));if(l instanceof J&&"NOT_FOUND"===l.error.code)return ue(),i.current=null,void n({type:"RESET"});const e=l instanceof H||l instanceof J&&l.error.retryable;e||(i.current=null);const s=l instanceof J?l.error.message:l instanceof H?l.message:"An unexpected Clinic response was received.";n({type:"ERROR",message:s,keepPending:e})}},[e,o]),l=t.useCallback(e=>{if(null!==i.current)return;i.current=e,a.current?.abort(),a.current=new AbortController;const s=++r.current;n({type:"PENDING",pending:e}),c(e,a.current.signal,s)},[c]),d=t.useCallback(async()=>{const e=le();if(!e)return!1;n({type:"LOADING"});const s=await o(e);return"PREPARING"===s?.status&&l({kind:"compile",operationId:_e(s.run_id),runId:s.run_id,expectedVersion:s.version}),!0},[o,l]),p=t.useCallback(()=>{const e=s.pending;if(!e)return;i.current=e,a.current?.abort(),a.current=new AbortController;const t=++r.current;n({type:"PENDING",pending:e}),c(e,a.current.signal,t)},[c,s.pending]),m=t.useCallback(()=>{r.current+=1,a.current?.abort(),i.current=null,n({type:"CANCEL"}),s.run&&o(s.run.run_id)},[o,s.run]),_=t.useCallback(()=>{r.current+=1,a.current?.abort(),i.current=null,ue(),n({type:"RESET"})},[]);return{state:s,hasSavedRun:null!==le(),resume:d,retry:p,cancel:m,clearLocal:_,clearError:()=>n({type:"CLEAR_ERROR"}),create:(e,s)=>l({kind:"create",operationId:Z(),buildRequest:e,files:Object.freeze([...s])}),decide:(e,t,n)=>{s.run&&l({kind:"decision",operationId:Z(),runId:s.run.run_id,expectedVersion:s.run.version,nodeId:e,selectedOptionIds:Object.freeze([...t]),reasoning:n})},askTutor:e=>{s.run&&l({kind:"tutor",operationId:Z(),runId:s.run.run_id,expectedVersion:s.run.version,question:e})},submit:e=>{s.run&&l({kind:"submit",operationId:Z(),runId:s.run.run_id,expectedVersion:s.run.version,finalResponse:e})},deleteRun:()=>{s.run&&l({kind:"delete",runId:s.run.run_id})}}}const he="rounded-xl border border-slate-200 bg-white p-5 shadow-sm sm:p-6",fe="mt-2 w-full rounded-lg border border-slate-300 bg-white px-3 py-2 text-sm text-slate-950 outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-100 disabled:bg-slate-100",ge="inline-flex min-h-10 items-center justify-center rounded-lg bg-blue-700 px-4 py-2 text-sm font-semibold text-white hover:bg-blue-800 disabled:cursor-not-allowed disabled:opacity-50",be="inline-flex min-h-10 items-center justify-center rounded-lg border border-slate-300 bg-white px-4 py-2 text-sm font-semibold text-slate-800 hover:bg-slate-50 disabled:cursor-not-allowed disabled:opacity-50";function ve({message:e,retryable:s,onRetry:t,onCancel:i,onDismiss:a}){return n.jsxs("div",{role:"alert",className:"rounded-lg border border-red-200 bg-red-50 p-4 text-sm text-red-900",children:[n.jsx("p",{className:"font-semibold",children:"Clinic could not complete that action"}),n.jsx("p",{className:"mt-1",children:e}),n.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[s&&n.jsx("button",{className:be,onClick:t,children:"Retry same operation"}),s&&n.jsx("button",{className:be,onClick:i,children:"Cancel and refresh"}),!s&&n.jsx("button",{className:be,onClick:a,children:"Dismiss"})]})]})}function ye({busy:e,pending:s,hasSavedRun:t,onStart:i,onResume:a,onClear:r}){return n.jsx("main",{className:"mx-auto max-w-4xl px-4 py-16 sm:px-6",children:n.jsxs("section",{children:[n.jsx("p",{className:"text-xs font-bold uppercase tracking-widest text-blue-700",children:"Prompt-compiled Clinic"}),n.jsx("h1",{className:"mt-3 text-4xl font-semibold tracking-tight text-slate-950",children:"What case would you like to practise?"}),n.jsx("p",{className:"mt-4 max-w-2xl text-base leading-7 text-slate-600",children:"Describe a fictional case to generate, or add authorised supporting documents such as invoices, certificates, bills and correspondence. Clinic will preserve each document's evidence anchors and build a structured practice matter."}),n.jsx("div",{className:"mt-8",children:n.jsx(h,{busy:e,onBuild:i})}),"create"===s?.kind&&n.jsx("div",{className:"mt-5",children:n.jsx(f,{label:"Matter preparation",value:20,title:e?s.files.length>0?"Reading and anchoring case materials":"Starting your practice matter":"Matter preparation paused",detail
1:e?s.files.length>0?"Clinic is validating the files, extracting supported text and creating source anchors.":"Clinic is validating the request and creating a recoverable matter.":"The operation is retained for a safe retry. No duplicate matter will be created.",active:e})}),n.jsx("p",{className:"mt-4 text-center text-xs leading-5 text-slate-500",children:"PDF, DOCX or TXT · up to 3 files and 5 MB · no scanned PDFs or OCR"}),n.jsx("div",{className:"mt-6 flex flex-wrap justify-center gap-3",children:t&&n.jsxs(n.Fragment,{children:[n.jsx("button",{className:be,disabled:e,onClick:a,children:"Resume saved run"}),n.jsx("button",{className:be,disabled:e,onClick:r,children:"Forget local run ID"})]})})]})})}function je({run:e,pending:s,busy:t}){const{completed_decisions:i,total_decisions:a}=e.progress,r=Math.max(1,a+1),o="SUBMITTED"===e.status?r:i,c=Math.round(o/r*100),l=e.progress.current_decision??Math.min(i+1,a),d="decision"===s?.kind&&e.actions.some(e=>e.node_id===s.nodeId&&("decision"===e.action_type||"revision"===e.action_type));let u=i>=a?"Final professional response":`Decision ${l} of ${a}`,p=i>=a?"All required decisions are complete. Submit the final response to unlock assessment and replay.":`${i} of ${a} required decisions complete. Tutor turns and revisions do not add artificial progress.`;return"SUBMITTED"===e.status?(u="Practice complete",p="The final response has been assessed and the expert replay is ready."):s&&!t?p="This operation is paused before confirmation. Retry resumes the same idempotent operation.":"decision"===s?.kind?p=d?"Assessing your revision. It can improve the evidence, but it will not count as another completed decision.":"Assessing your reasoning. Progress advances only after the server records the assessment.":"tutor"===s?.kind?p="The Socratic tutor is preparing a focused prompt. Tutor turns do not advance scored progress.":"submit"===s?.kind?(u="Final professional response",p="Assessing the final response and building the expert replay."):"delete"===s?.kind&&(u="Deleting practice matter",p="Clinic is removing this matter and its retained run state."),n.jsx(f,{label:"Practice progress",value:c,title:u,detail:p,active:t})}function Ne({evidence:e,onSelect:s}){return n.jsxs("button",{type:"button",className:"w-full rounded-lg border border-blue-100 bg-blue-50 p-3 text-left text-xs text-blue-950 hover:border-blue-300 hover:bg-blue-100",onClick:()=>s(e.span_id),children:[n.jsxs("span",{className:"font-semibold",children:[e.source_display_name,e.page_or_section?` · ${e.page_or_section}`:""]}),n.jsxs("span",{className:"mt-1 block leading-5",children:["â",e.quoted_excerpt,"â"]}),n.jsxs("span",{className:"mt-1 block font-mono text-[10px] text-blue-700",children:[e.span_id," · View in source"]})]})}function $e({spec:e,highlightedSpanId:s,panelRef:t,mobileExpanded:i,onToggleMobile:a}){return n.jsxs("section",{ref:t,"aria-labelledby":"clinic-source-materials-heading",className:`${he} max-h-[70vh] overflow-y-auto overscroll-contain lg:max-h-[calc(100vh-3rem)]`,children:[n.jsxs("div",{className:"flex items-center justify-between gap-4",children:[n.jsx("h2",{id:"clinic-source-materials-heading",className:"text-lg font-semibold",children:"Source materials"}),n.jsxs("button",{type:"button",className:"inline-flex min-h-10 items-center gap-2 rounded-lg border border-slate-200 bg-slate-50 px-3 py-2 text-xs font-semibold text-slate-700 hover:border-slate-300 hover:bg-slate-100 lg:hidden","aria-expanded":i,"aria-controls":"clinic-source-materials-content",onClick:a,children:[i?"Hide sources":"Show sources",n.jsx(l,{"aria-hidden":"true",className:"h-4 w-4 transition-transform "+(i?"rotate-180":"")})]})]}),n.jsxs("div",{id:"clinic-source-materials-content",className:(i?"block":"hidden")+" lg:block",children:[n.jsx("p",{className:"mt-1 text-xs text-slate-500",children:"Select assessment evidence to locate and highlight its anchored source text."}),e.sources.map(t=>{const i=e.source_spans.filter(e=>e.source_id===t.source_id).sort((e,s)=>e.start_offset-s.start_offset),a=[];let r=0;return i.forEach(e=>{e.start_offset>r&&a.push(n.jsx("span",{children:t.text.slice(r,e.start_offset)},`${e.span_id}-before`)),a.push(n.jsx("mark",{id:`clinic-source-${e.span_id}`,"data-span-id":e.span_id,className:"scroll-mt-24 rounded px-0.5 transition-colors "+(s===e.span_id?"bg-amber-200 ring-2 ring-amber-400":"bg-transparent"),children:t.text.slice(e.start_offset,e.end_offset)},e.span_id)),r=Math.max(r,e.end_offset)}),r<t.text.length&&a.push(n.jsx("span",{children:t.text.slice(r)},"tail")),n.jsxs("article",{className:"mt-5 border-t border-slate-200 pt-4 first:border-0 first:pt-0",children:[n.jsx("p",{className:"text-sm font-semibold text-slate-900",children:t.display_name}),n.jsx("p",{className:"mt-1 text-[11px] text-slate-500",children:t.media_type}),n.jsx("div",{className:"mt-3 whitespace-pre-wrap text-sm leading-7 text-slate-700",children:a})]},t.source_id)})]})]})}function we({spec:e}){const[s,i]=t.useState(!0);
1return n.jsxs("section",{className:he,"aria-labelledby":"clinic-compiled-issues-heading",children:[n.jsxs("div",{className:"flex items-start justify-between gap-4",children:[n.jsxs("div",{children:[n.jsx("p",{className:"text-xs font-bold uppercase tracking-widest text-blue-700",children:"Matter overview"}),n.jsx("h2",{id:"clinic-compiled-issues-heading",className:"mt-2 text-lg font-semibold text-slate-950",children:"Compiled issues"})]}),n.jsxs("button",{type:"button",className:"inline-flex min-h-10 shrink-0 items-center gap-2 rounded-lg border border-slate-200 bg-slate-50 px-3 py-2 text-xs font-semibold text-slate-700 hover:border-slate-300 hover:bg-slate-100","aria-expanded":s,"aria-controls":"clinic-compiled-issues-list",onClick:()=>i(e=>!e),children:[e.issues.length," ",1===e.issues.length?"issue":"issues",n.jsx(l,{"aria-hidden":"true",className:"h-4 w-4 transition-transform "+(s?"rotate-180":"")}),n.jsxs("span",{className:"sr-only",children:[s?"Collapse":"Expand"," compiled issues"]})]})]}),s&&n.jsx("ul",{id:"clinic-compiled-issues-list",className:"mt-4 space-y-3 text-sm leading-6 text-slate-700",children:e.issues.map(e=>n.jsxs("li",{className:"rounded-lg border border-slate-100 bg-slate-50/70 px-4 py-3",children:[n.jsxs("span",{className:"font-semibold text-slate-900",children:[e.title,":"]})," ",e.question]},e.issue_id))})]})}function ke({run:e,onEvidence:s}){return 0===e.assessments.length?null:n.jsxs("section",{className:he,"aria-labelledby":"clinic-assessment-heading",children:[n.jsx("h2",{id:"clinic-assessment-heading",className:"text-lg font-semibold text-slate-950",children:"Assessment evidence"}),n.jsx("div",{className:"mt-4 space-y-4",children:e.assessments.map(e=>n.jsxs("article",{className:"rounded-lg border border-slate-200 p-4",children:[n.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[n.jsx("p",{className:"font-semibold capitalize text-slate-900",children:e.result.replaceAll("_"," ")}),n.jsxs("p",{className:"text-sm font-bold text-blue-800",children:[e.score_awarded,"/",e.score_available]})]}),n.jsx("p",{className:"mt-2 text-sm leading-6 text-slate-700",children:e.feedback}),n.jsxs("div",{className:"mt-3 rounded-md bg-slate-50 p-3 text-xs leading-5 text-slate-700",children:[n.jsxs("p",{className:"font-semibold",children:["Decisionâreasoning alignment: ",e.decision_reasoning_alignment.replaceAll("_"," ")]}),n.jsx("p",{className:"mt-1",children:e.alignment_explanation})]}),n.jsx("ul",{className:"mt-3 space-y-2",children:e.source_evidence.map(t=>n.jsx("li",{children:n.jsx(Ne,{evidence:t,onSelect:s})},`${e.assessment_event_id}-${t.span_id}`))})]},e.assessment_event_id))})]})}function Ie({run:e,onEvidence:s}){const t=e.replay,i=e.spec;if(!t||!i)return null;const a=new Map(i.competencies.map(e=>[e.competency_id,e])),r=new Map(t.expert_path.map((e,s)=>[e.node_id,s+1])),o=new Map(t.expert_path.map(e=>[e.node_id,e.node_question]));return n.jsxs("div",{className:"space-y-6",children:[e.final_assessment&&n.jsxs("section",{className:he,children:[n.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[n.jsx("h2",{className:"text-xl font-semibold text-slate-950",children:"Final submission assessment"}),n.jsxs("p",{className:"font-bold text-blue-800",children:[e.final_assessment.score_awarded,"/",e.final_assessment.score_available]})]}),n.jsx("p",{className:"mt-3 text-sm leading-6 text-slate-700",children:e.final_assessment.feedback}),n.jsx("div",{className:"mt-4 grid gap-3 md:grid-cols-2",children:e.final_assessment.dimensions.map(e=>n.jsxs("article",{className:"rounded-lg border border-slate-200 p-4 text-sm",children:[n.jsxs("div",{className:"flex justify-between gap-3",children:[n.jsx("p",{className:"font-semibold capitalize text-slate-950",children:e.dimension.replaceAll("_"," ")}),n.jsxs("p",{className:"font-bold text-blue-800",children:[e.score_awarded,"/",e.score_available]})]}),n.jsx("p",{className:"mt-2 leading-6 text-slate-700",children:e.feedback}),e.evidence.map((s,t)=>n.jsx("blockquote",{className:"mt-2 border-l-2 border-slate-300 pl-3 text-xs text-slate-600",children:s.excerpt??s.explanation},`${e.dimension}-${t}`))]},e.dimension))})]}),n.jsxs("section",{className:he,children:[n.jsx("h2",{className:"text-xl font-semibold text-slate-950",children:"Combined competency score"}),n.jsx("p",{className:"mt-2 text-sm text-slate-600",children:"Includes every assessed decision and revision plus the final submission."}),n.jsx("div",{className:"mt-4 overflow-hidden rounded-lg border border-slate-200",children:n.jsxs("table",{className:"w-full text-left text-sm",children:[n.jsx("thead",{className:"bg-slate-50 text-slate-600",children:n.jsxs("tr",{children:[n.jsx("th",{className:"px-4 py-3",children:"Competency"}),n.jsx("th",{className:"px-4 py-3",children:"Evidence score"})]})}),n.jsx("tbody",{children:t.competency_scores.map(e=>n.jsxs("tr",{className:"border-t border-slate-200",children:[n.jsxs("td",{className:"px-4 py-3",children:[n.jsx("p",{className:"font-medium",children:a.get(e.competency_id)?.label??"Competency"}),n.jsx("p",{className:"mt-1 text-xs text-slate-500",children:a.get(e.competency_id)?.description})]}),n.jsxs("td",{className:"px-4 py-3",children:[e.score_awarded,"/",e.score_available]})]},e.competency_id))})]})})]}),n.jsxs("section",{className:he,children:[n.jsx("h2",{className:"text-xl font-semibold text-slate-950",children:"Student path and expert reference"}),n.jsxs("div",{className:"mt-5 grid gap-5 lg:grid-cols-2",children:[n.jsxs("div",{children:[n.jsx("h3",{className:"text-sm font-bold uppercase tracking-wider text-slate-600",children:"Your path"}),n.jsx("ol",{className:"mt-3 space-y-3",children:t.student_path.map(e=>n.jsxs("li",{className:"rounded-lg border border-slate-200 p-4 text-sm",children:[n.jsxs("p",{className:"text-xs font-bold uppercase tracking-wide text-slate-500",children:["Decision ",r.get(e.node_id)??"â",e.is_revision?" · Revision":""]}),n.jsx("p",{className:"mt-2 font-semibold leading-6 text-slate-950",children:e.node_question}),n.jsx("p",{className:"mt-3 text-xs font-semibold uppercase tracking-wide text-slate-500",children:"Your choice"}),n.jsx("p",{className:"mt-1 leading-6 text-slate-800",children:e.selected_option_texts.join(" / ")}),n.jsx("p",{className:"mt-3 text-xs font-semibold uppercase tracking-wide text-slate-500",children:"Your reasoning"}),n.jsx("p",{className:"mt-1 leading-6 text-slate-600",children:e.student_reasoning})]},e.action_id))})]}),n.jsxs("div",{children:[n.jsx("h3",{className:"text-sm font-bold uppercase tracking-wider text-blue-700",children:"Expert reference"}),n.jsx("ol",{className:"mt-3 space-y-3",children:t.expert_path.map((e,s)=>n.jsxs("li",{className:"rounded-lg border border-blue-200 bg-blue-50 p-4 text-sm",children:[n.jsxs("p",{className:"text-xs font-bold uppercase tracking-wide text-blue-700",children:["Decision ",s+1]}),n.jsx("p",{className:"mt-2 font-semibold leading-6 text-blue-950",children:e.node_question}),n.jsx("p",{className:"mt-3 text-xs font-semibold uppercase tracking-wide text-blue-700",children:"Recommended approach"}),n.jsx("p",{className:"mt-1 leading-6 text-blue-950",children:e.recommended_option_text}),n.jsx("p",{className:"mt-3 text-xs font-semibold uppercase tracking-wide text-blue-700",children:"Why"}),n.jsx("p",{className:"mt-1 leading-6 text-blue-900",children:e.rationale})]},e.node_id))})]})]})]}),n.jsxs("section",{className:he,children:[n.jsx("h2",{className:"text-xl font-semibold text-slate-950",children:"All material divergences"}),t.all_material_divergences.length>0?n.jsx("ol",{className:"mt-4 space-y-4",children:t.all_material_divergences.map((e,i)=>{const a=t.first_material_divergence?.student_action_id===e.student_action_id;return n.jsxs("li",{className:"rounded-lg border p-4 text-sm "+(a?"border-amber-300 bg-amber-50":"border-slate-200 bg-white"),children:[n.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[n.jsxs("p",{className:"font-semibold text-slate-950",children:["Decision ",r.get(e.node_id)??i+1,a?" â first material divergence":""]}),n.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide text-slate-600",children:e.divergence_type.replaceAll("_"," ")})]}),n.jsx("p",{className:"mt-2 font-medium leading-6 text-slate-800",children:o.get(e.node_id)??"Decision review"}),n.jsxs("p",{className:"mt-3",children:[n.jsx("span",{className:"font-semibold",children:"Student choice:"})," ",e.student_choice]}),n.jsxs("p",{className:"mt-2",children:[n.jsx("span",{className:"font-semibold",children:"Reasoning:"})," ",e.student_reasoning_summary]}),n.jsxs("p",{className:"mt-2",children:[n.jsx("span",{className:"font-semibold",children:"Alignment:"})," ",e.decision_reasoning_alignment.replaceAll("_"," ")]}),n.jsxs("p",{className:"mt-2",children:[n.jsx("span",{className:"font-semibold",children:"Why plausible:"})," ",e.why_the_choice_was_plausible]}),n.jsxs("p",{className:"mt-2",children:[n.jsx("span",{className:"font-semibold",children:"Why incomplete or wrong:"})," ",e.why_it_was_incomplete_or_wrong]}),n.jsxs("p",{className:"mt-2",children:[n.jsx("span",{className:"font-semibold",children:"Expert reference:"})," ",e.expert_reference]}),n.jsxs("p",{className:"mt-2",children:[n.jsx("span",{className:"font-semibold",children:"Downstream effect:"})," ",e.downstream_effect]}),n.jsxs("p",{className:"mt-2",children:[n.jsx("span",{className:"font-semibold",children:"Corrective principle:"})," ",e.corrective_principle]}),n.jsxs("p",{className:"mt-2",children:[n.jsx("span",{className:"font-semibold",children:"Next practice:"})," ",e.next_practice]}),e.overlooked_evidence.length>0&&n.jsx("ul",{className:"mt-3 space-y-2",children:e.overlooked_evidence.map(t=>n.jsx("li",{children:n.jsx(Ne,{evidence:t,onSelect:s})},`${e.student_action_id}-${t.span_id}`))})]},e.student_action_id)})}):n.jsx("p",{className:"mt-3 text-sm text-slate-600",children:"No material divergence was identified."})]}),n.jsxs("section",{className:he,children:[n.jsx("h2",{className:"text-xl font-semibold text-slate-950",children:"Structured reasoning map"}),n.jsx("ol",{className:"mt-4 space-y-4",children:t.structured_reasoning_map.map(e=>n.jsxs("li",{className:"rounded-lg border border-slate-200 p-4 text-sm leading-6 text-slate-700",children:[n.jsxs("p",{className:"text-xs font-bold uppercase tracking-wide text-slate-500",children:["Decision ",r.get(e.node_id)??"â"]}
1),n.jsx("p",{className:"mt-2 font-semibold text-slate-950",children:o.get(e.node_id)??e.decision}),n.jsxs("p",{className:"mt-2",children:[n.jsx("span",{className:"font-semibold",children:"Decision:"})," ",e.decision]}),n.jsxs("p",{children:[n.jsx("span",{className:"font-semibold",children:"Alternatives:"})," ",e.competing_interpretations.join(" / ")]}),n.jsxs("p",{children:[n.jsx("span",{className:"font-semibold",children:"Conclusion:"})," ",e.current_conclusion]}),n.jsxs("p",{children:[n.jsx("span",{className:"font-semibold",children:"Confidence:"})," ",Math.round(100*e.confidence),"%"]}),n.jsxs("p",{children:[n.jsx("span",{className:"font-semibold",children:"Next step:"})," ",e.next_professional_step]})]},e.node_id))})]})]})}function Ee(){const e=xe(),{state:s}=e,i=t.useRef(!1),[a,r]=t.useState(""),[o,c]=t.useState(""),[l,d]=t.useState(""),[u,p]=t.useState(""),[m,_]=t.useState(null),[x,h]=t.useState(!1),g=t.useRef(null),b=s.loading;if(t.useEffect(()=>{i.current||(i.current=!0,e.hasSavedRun&&e.resume())},[e.hasSavedRun,e.resume]),t.useEffect(()=>{r(""),c("")},[s.run?.current_node?.node_id]),!s.run)return n.jsxs("div",{className:"min-h-screen bg-slate-100 text-slate-950",children:[n.jsx("header",{className:"border-b border-slate-200 bg-white",children:n.jsxs("div",{className:"mx-auto max-w-7xl px-4 py-4 sm:px-6",children:[n.jsx("p",{className:"font-semibold",children:"Lawg Clinic"}),n.jsx("p",{className:"text-xs text-slate-500",children:"Internal synthetic educational demonstration. Not legal or tax advice."})]})}),s.error&&n.jsx("div",{className:"mx-auto max-w-4xl px-4 pt-6 sm:px-6",children:n.jsx(ve,{message:s.error,retryable:null!==s.pending,onRetry:e.retry,onCancel:e.cancel,onDismiss:e.clearError})}),n.jsx(ye,{busy:b,pending:s.pending,hasSavedRun:e.hasSavedRun,onStart:e.create,onResume:()=>{e.resume()},onClear:e.clearLocal})]});const v=s.run;if("PREPARING"===v.status)return n.jsxs("div",{className:"min-h-screen bg-slate-100 text-slate-950",children:[n.jsx("header",{className:"border-b border-slate-200 bg-white",children:n.jsxs("div",{className:"mx-auto flex max-w-4xl items-center justify-between gap-3 px-4 py-4 sm:px-6",children:[n.jsxs("div",{children:[n.jsx("p",{className:"font-semibold",children:"Lawg Clinic"}),n.jsxs("p",{className:"text-xs text-slate-500",children:["Preparing practice matter · version ",v.version]})]}),n.jsx("button",{className:be,disabled:b,onClick:e.deleteRun,children:"Delete matter"})]})}),n.jsxs("main",{className:"mx-auto max-w-4xl px-4 py-12 sm:px-6",children:[s.error&&n.jsx(ve,{message:s.error,retryable:null!==s.pending,onRetry:e.retry,onCancel:e.cancel,onDismiss:e.clearError}),n.jsxs("section",{className:`${he} mt-6`,children:[n.jsx("p",{className:"text-xs font-bold uppercase tracking-widest text-blue-700",children:"Case-building preparation"}),n.jsx("h1",{className:"mt-3 text-2xl font-semibold",children:"Building your practice matter"}),n.jsx("p",{role:"status",className:"mt-3 text-sm leading-6 text-slate-600",children:"Clinic has retained the run ID. It is interpreting your request, anchoring any supporting documents and compiling a decision path. Reconnecting resumes this same operation."}),v.materials.length>0?n.jsx("ul",{className:"mt-5 space-y-2",children:v.materials.map(e=>n.jsxs("li",{className:"rounded-lg border border-slate-200 bg-slate-50 px-4 py-3 text-sm",children:[n.jsx("span",{className:"font-semibold",children:e.display_name}),n.jsxs("span",{className:"ml-2 text-xs text-slate-500",children:[e.media_type," · ",e.character_count.toLocaleString()," characters"]})]},e.source_id))}):n.jsx("p",{className:"mt-5 rounded-lg border border-slate-200 bg-slate-50 px-4 py-3 text-sm text-slate-600",children:"Generating fictional source material from your request before compilation."}),n.jsx("div",{className:"mt-5",children:n.jsx(f,{label:"Matter preparation",value:"compile"===s.pending?.kind?65:50,title:"delete"===s.pending?.kind?"Deleting practice matter":b?v.materials.length>0?"Compiling the practice matter":"Generating and compiling the practice matter":"Matter build paused safely",detail
1:"delete"===s.pending?.kind?"Clinic is removing this matter and its retained run state.":b?v.materials.length>0?"Source anchors are ready. Clinic is building the issues and decision path.":"Clinic is generating synthetic source material before building the decision path.":"The run ID is retained. Resume continues this same build without creating a duplicate.",active:b})}),!b&&null===s.pending&&null===s.error&&n.jsx("button",{type:"button",className:`${ge} mt-5`,onClick:()=>{e.resume()},children:"Resume build"})]})]})]});const y=v.spec;if(!y)return n.jsx("div",{role:"alert",children:"Clinic returned an invalid compiled matter."});const j=v.current_node,N=e=>{_(e),h(!0),requestAnimationFrame(()=>{const s=g.current,t=document.getElementById(`clinic-source-${e}`);if(!s||!t||!s.contains(t))return;const n=s.getBoundingClientRect(),i=t.getBoundingClientRect(),a=s.scrollTop+i.top-n.top-(s.clientHeight-i.height)/2;s.scrollTo({top:Math.max(0,a),behavior:"smooth"});const r=s.closest("[data-clinic-source-rail]");r&&"sticky"===window.getComputedStyle(r).position||s.scrollIntoView({behavior:"smooth",block:"start"})})},$=Boolean(j&&a&&o.trim()&&o.length<=v.constraints.reasoning_max_chars);return n.jsxs("div",{className:"min-h-screen bg-slate-100 text-slate-950",children:[n.jsx("header",{className:"border-b border-slate-200 bg-white",children:n.jsxs("div",{className:"mx-auto flex max-w-7xl flex-wrap items-center justify-between gap-3 px-4 py-4 sm:px-6",children:[n.jsxs("div",{children:[n.jsx("p",{className:"font-semibold",children:"Lawg Clinic"}),n.jsxs("p",{className:"text-xs text-slate-500",children:[y.title," · version ",v.version," · ",v.status.toLowerCase()]})]}),n.jsx("button",{className:be,disabled:b,onClick:e.deleteRun,children:"Delete matter"})]})}),n.jsxs("div",{className:"mx-auto max-w-7xl px-4 py-6 sm:px-6",children:[n.jsx("p",{className:"mb-4 text-xs text-slate-500",children:"Internal synthetic educational demonstration. Not legal or tax advice."}),s.error&&n.jsx(ve,{message:s.error,retryable:null!==s.pending,onRetry:e.retry,onCancel:e.cancel,onDismiss:e.clearError}),n.jsx(je,{run:v,pending:s.pending,busy:b}),"SUBMITTED"===v.status&&v.replay?n.jsxs("main",{className:"mt-6 grid items-start gap-6 xl:grid-cols-[minmax(0,1fr)_24rem]",children:[n.jsx(Ie,{run:v,onEvidence:N}),n.jsx("aside",{"aria-label":"Evidence reference","data-clinic-source-rail":!0,className:"min-w-0 xl:sticky xl:top-6 xl:self-start",children:n.jsx($e,{spec:y,highlightedSpanId:m,panelRef:g,mobileExpanded:x,onToggleMobile:()=>h(e=>!e)})})]}):n.jsxs("main",{className:"mt-6 grid items-start gap-6 lg:grid-cols-[minmax(0,1.35fr)_minmax(20rem,.65fr)]",children:[n.jsxs("section",{"aria-label":"Practice workspace",className:"min-w-0 space-y-6",children:[n.jsx(we,{spec:y}),n.jsxs("section",{className:he,children:[n.jsx("p",{className:"text-xs font-bold uppercase tracking-widest text-blue-700",children:"Current decision"}),n.jsx("h1",{className:"mt-3 text-2xl font-semibold tracking-tight text-slate-950",children:j?.question}),n.jsxs("fieldset",{className:"mt-6 space-y-3",disabled:b,children:[n.jsx("legend",{className:"sr-only",children:"Decision options"}),j?.options.map(e=>n.jsxs("label",{className:"flex cursor-pointer gap-3 rounded-lg border p-4 "+(a===e.option_id?"border-blue-500 bg-blue-50":"border-slate-200"),children:[n.jsx("input",{type:"radio",name:"clinic-option",value:e.option_id,checked:a===e.option_id,onChange:()=>r(e.option_id)}),n.jsx("span",{className:"text-sm leading-6 text-slate-800",children:e.text})]},e.option_id))]}),n.jsxs("div",{className:"mt-5",children:[n.jsxs("div",{className:"flex justify-between gap-4",children:[n.jsx("label",{htmlFor:"clinic-reasoning",className:"text-sm font-semibold",children:"Your reasoning"}),n.jsxs("span",{className:"text-xs text-slate-500",children:[o.length,"/",v.constraints.reasoning_max_chars]})]}),n.jsx("textarea",{id:"clinic-reasoning",className:`${fe} min-h-32`,value:o,maxLength:v.constraints.reasoning_max_chars,disabled:b,onChange:e=>c(e.target.value)})]}),n.jsx("button",{className:`${ge} mt-4`,disabled:b||!$,onClick:()=>j&&e.decide(j.node_id,[a],o),children:"Submit decision"})]}),n.jsxs("section",{className:he,children:[n.jsx("h2",{className:"text-lg font-semibold",children:"Socratic tutor"}),n.jsx("p",{className:"mt-2 text-sm text-slate-600",children:"Ask for a focused prompt. The tutor cannot reveal the hidden expert path."}),n.jsx("textarea",{className:`${fe} min-h-24`,"aria-label":"Question for the Socratic tutor",value:l,maxLength:v.constraints.tutor_question_max_chars,disabled:b,onChange:e=>d(e.target.value)}),n.jsx("button",{className:`${be} mt-3`,disabled:b||!l.trim(),onClick:()=>{e.askTutor(l),d("")},children:"Ask tutor"}),v.tutor_turns.at(-1)&&n.jsx("div",{className:"mt-4 rounded-lg border border-slate-200 bg-slate-50 p-4 text-sm leading-6 text-slate-700",children:v.tutor_turns.at(-1)?.response})]}),n.jsx(ke,{run:v,onEvidence:N}),v.allowed_actions.can_submit&&n.jsxs("section",{className:he,children:[n.jsx("h2",{className:"text-lg font-semibold",children:"Final professional response"}),n.jsx("p",{className:"mt-2 text-sm text-slate-600",children:"Submission freezes the path and unlocks the expert replay."}),n.jsx("textarea",{className:`${fe} min-h-40`,value:u,maxLength:v.constraints.final_response_max_chars,disabled:b,onChange:e=>p(e.target.value)}),n.jsx("button",{className:`${ge} mt-3`,disabled:b||u.trim().length<20,onClick:()=>e.submit(u),children:"Submit and build replay"})]})]}),n.jsx("aside",{"aria-label":"Evidence reference","data-clinic-source-rail":!0,className:"min-w-0 lg:sticky lg:top-6 lg:self-start",children:n.jsx($e,{spec:y,highlightedSpanId:m,panelRef:g,mobileExpanded:x,onToggleMobile:()=>h(e=>!e)})})]})]})]})}export{Ee as ClinicPage};
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.