"use strict";exports.id=4107,exports.ids=[4107],exports.modules={24107:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{$E:()=>w,At:()=>r,H7:()=>y,Li:()=>x,Ok:()=>o,Pf:()=>v,Z1:()=>s,aH:()=>n,dM:()=>A,gu:()=>l,j3:()=>p,pE:()=>m,vX:()=>q});var e=c(34255),f=c(60105),g=c(77296),h=c(49017),i=a([e,f,g]);function j(a){return a?{...a,is_practitioner_note:void 0}:null}function k(a){return a?{...a,is_practitioner_note:1===a.is_practitioner_note}:null}function l(a){return a?j((0,e.getDb)().prepare("SELECT * FROM hail_interviews WHERE id = ?").get(a)):null}function m(a){return a?(0,e.getDb)().prepare("SELECT * FROM hail_interviews WHERE engagement_id = ? ORDER BY created_at ASC").all(a).map(j):[]}function n({engagement_id:a,title:b=null,conducted_by_user_id:c=null}){if(!a)throw Error("startInterview: engagement_id is required");let d=(0,g.SA)(a);if(!d)throw Error(`startInterview: engagement "${a}" not found`);let i=(0,e.getDb)(),j=(0,e.newId)("hailiv"),k=(0,e.nowIso)();return i.prepare(`
    INSERT INTO hail_interviews
      (id, engagement_id, title, status, section_cursor, conducted_by_user_id, created_at, updated_at)
    VALUES (?, ?, ?, 'in_progress', ?, ?, ?, ?)
  `).run(j,a,b||`Configuration Interview — ${d.principal_name}`,h.Fc[0].slug,c,k,k),(0,f.appendAudit)({type:"hail.interview.start",summary:`HAIL interview started for ${d.principal_name}`,status:"ok",meta:{engagement_id:a,interview_id:j}}),l(j)}function o(a){if(!l(a))throw Error(`pauseInterview: interview "${a}" not found`);return(0,e.getDb)().prepare("UPDATE hail_interviews SET status = 'paused', updated_at = ? WHERE id = ?").run((0,e.nowIso)(),a),l(a)}function p(a,{section_cursor:b=null}={}){let c=l(a);if(!c)throw Error(`resumeInterview: interview "${a}" not found`);if(null!=b&&!h.pl.has(b))throw Error(`resumeInterview: unknown section "${b}"`);let d=(0,e.getDb)(),f=b||c.section_cursor;return d.prepare("UPDATE hail_interviews SET status = 'in_progress', section_cursor = ?, updated_at = ? WHERE id = ?").run(f,(0,e.nowIso)(),a),l(a)}function q(a){if(!l(a))throw Error(`completeInterview: interview "${a}" not found`);return(0,e.getDb)().prepare("UPDATE hail_interviews SET status = 'complete', updated_at = ? WHERE id = ?").run((0,e.nowIso)(),a),l(a)}function r(a,b){if(!h.pl.has(b))throw Error(`setSectionCursor: unknown section "${b}"`);if(!l(a))throw Error(`setSectionCursor: interview "${a}" not found`);return(0,e.getDb)().prepare("UPDATE hail_interviews SET section_cursor = ?, updated_at = ? WHERE id = ?").run(b,(0,e.nowIso)(),a),l(a)}function s({interview_id:a,section:b,question_key:c,answer:d=null,sensitivity:g,confidence:i=null,evidence:j=null,is_practitioner_note:m=!1}){let n;if(!a)throw B("interview_id is required");let o=l(a);if(!o)throw C(`interview "${a}" not found`);if(!b||!h.pl.has(b))throw B(`unknown section "${b}"`);if(!c||"string"!=typeof c)throw B("question_key is required");if(!g||!h.ZV.has(g))throw B(`sensitivity is required and must be one of ${[...h.ZV].join(", ")}`,"sensitivity_required");if(null!=i&&!h.SZ.has(i))throw B(`unknown confidence "${i}"`);let p="refused"===g||null==d?null:String(d),q="refused"===g?null:j,r=+!!m,s=(0,e.getDb)(),t=(0,e.nowIso)(),u=s.prepare("SELECT id FROM hail_interview_responses WHERE interview_id = ? AND question_key = ? AND is_practitioner_note = ?").get(a,c,r);return u?(n=u.id,s.prepare(`
      UPDATE hail_interview_responses
         SET section = ?, answer = ?, sensitivity = ?, confidence = ?, evidence = ?, updated_at = ?
       WHERE id = ?
    `).run(b,p,g,i,q,t,n)):(n=(0,e.newId)("hailresp"),s.prepare(`
      INSERT INTO hail_interview_responses
        (id, interview_id, engagement_id, section, question_key, answer, sensitivity,
         confidence, evidence, is_practitioner_note, created_at, updated_at)
      VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    `).run(n,a,o.engagement_id,b,c,p,g,i,q,r,t,t)),(0,f.appendAudit)({type:"hail.interview.response",summary:`HAIL interview response (${g}) for ${c}`,status:"ok",meta:{engagement_id:o.engagement_id,interview_id:a,section:b,question_key:c,sensitivity:g,is_practitioner_note:1===r}}),k(s.prepare("SELECT * FROM hail_interview_responses WHERE id = ?").get(n))}function t(a,{include_practitioner_notes:b=!0}={}){if(!a)return[];let c=(0,e.getDb)();return(b?c.prepare("SELECT * FROM hail_interview_responses WHERE interview_id = ? ORDER BY created_at ASC").all(a):c.prepare("SELECT * FROM hail_interview_responses WHERE interview_id = ? AND is_practitioner_note = 0 ORDER BY created_at ASC").all(a)).map(k)}function u(a){return a?"refused"===a.sensitivity?"[declined by principal]":"restricted"===a.sensitivity?"[restricted — withheld from artifact]":null==a.answer?"":String(a.answer):""}function v(a){return a?{id:a.id,section:a.section,question_key:a.question_key,sensitivity:a.sensitivity,confidence:a.confidence,is_practitioner_note:!0===a.is_practitioner_note||1===a.is_practitioner_note,redacted:"restricted"===a.sensitivity||"refused"===a.sensitivity,display:u(a)}:null}function w(a,{include_practitioner_notes:b=!0}={}){return t(a,{include_practitioner_notes:b}).map(v)}function x(a,b,{include_practitioner_notes:c=!0}={}){if(!a)return[];if(!b)throw Error("listResponsesForEngagementEngine: engine is required");let d=(0,e.getDb)();return(c?d.prepare("SELECT * FROM hail_interview_responses WHERE engagement_id = ? ORDER BY created_at ASC").all(a):d.prepare("SELECT * FROM hail_interview_responses WHERE engagement_id = ? AND is_practitioner_note = 0 ORDER BY created_at ASC").all(a)).map(k).map(a=>(function(a,b){if(!a)return null;let c=a.answer,d=!1;return"refused"===a.sensitivity?c=null:"restricted"!==a.sensitivity||(0,h.wS)(b)||(c="[restricted: withheld from non-local engine]",d=!0),{section:a.section,question_key:a.question_key,sensitivity:a.sensitivity,confidence:a.confidence,is_practitioner_note:!0===a.is_practitioner_note||1===a.is_practitioner_note,answer:c,masked:d}})(a,b))}function y(a){let b=l(a);if(!b)throw C(`interview "${a}" not found`);let c=t(a,{include_practitioner_notes:!1}),d=new Map(h.Fc.map(a=>[a.slug,[]]));for(let a of c)d.has(a.section)||d.set(a.section,[]),d.get(a.section).push({question_key:a.question_key,sensitivity:a.sensitivity,confidence:a.confidence,value:u(a),redacted:"restricted"===a.sensitivity||"refused"===a.sensitivity});let e=h.Fc.map(a=>({slug:a.slug,label:a.label,items:d.get(a.slug)||[]})).filter(a=>a.items.length>0);return{interview_id:b.id,engagement_id:b.engagement_id,status:b.status,section_cursor:b.section_cursor,sections:e}}function z(a){return String(null==a?"":a).replace(/[\\`*_{}\[\]<>]/g,a=>`\\${a}`)}function A(a){let b=y(a),c=l(a),d=(0,g.SA)(c.engagement_id),e=[];for(let a of(e.push(`# HAIL Configuration Interview — ${z(d?.principal_name||"Principal")}`),e.push(""),e.push("> Principal-facing transcript. Restricted answers are withheld; declined answers are marked. Practitioner notes are excluded."),e.push(""),b.sections)){for(let b of(e.push(`## ${z(a.label)}`),e.push(""),a.items)){let a=b.redacted?b.value:z(b.value);e.push(`- **${z(b.question_key)}** _(${b.sensitivity})_: ${a}`)}e.push("")}let h=e.join("\n"),i=(0,f.Dg)({title:`HAIL Interview transcript — ${d?.principal_name||c.engagement_id}`,kind:"markdown",content:h,project_id:d?.project_id||null,agent_id:"hail-interview"});return(0,f.appendAudit)({type:"hail.interview.transcript",summary:`HAIL interview transcript rendered for ${d?.principal_name||c.engagement_id}`,status:"ok",meta:{engagement_id:c.engagement_id,interview_id:a,artifact_id:i.artifact_id}}),i}function B(a,b="bad_request"){let c=Error(a);return c.status=422,c.code=b,c}function C(a){let b=Error(a);return b.status=404,b.code="not_found",b}[e,f,g]=i.then?(await i)():i,d()}catch(a){d(a)}})},77296:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{Q8:()=>o,SA:()=>l,XK:()=>n,wz:()=>m});var e=c(34255),f=c(61423),g=c(60105),h=c(25185),i=c(7945);c(49017);var j=a([e,f,g,h,i]);function k(a){return a?{...a}:null}function l(a){return a?k((0,e.getDb)().prepare("SELECT * FROM hail_engagements WHERE id = ?").get(a)):null}function m(a){return a?k((0,e.getDb)().prepare("SELECT * FROM hail_engagements WHERE process_case_id = ?").get(a)):null}function n({status:a=null,limit:b=100}={}){let c=(0,e.getDb)();return(a?c.prepare("SELECT * FROM hail_engagements WHERE status = ? ORDER BY created_at DESC LIMIT ?").all(a,b):c.prepare("SELECT * FROM hail_engagements ORDER BY created_at DESC LIMIT ?").all(b)).map(k)}function o(a={}){let b,c=String(a.principal_name||"").trim();if(!c)throw Error("createEngagement: principal_name is required");let d=String(a.accountable_human||"").trim();if(!d){let a=Error("createEngagement: accountable_human is required (HAIL will not proceed without a named accountable counterparty)");throw a.code="HAIL_NO_ACCOUNTABLE_HUMAN",a}let j=(0,e.getDb)(),m=(0,e.nowIso)(),n=(0,e.newId)("hailengg");if(a.project_id&&(0,f.U1)(a.project_id)){var p;if((p=a.project_id)?k((0,e.getDb)().prepare("SELECT * FROM hail_engagements WHERE project_id = ? ORDER BY created_at ASC LIMIT 1").get(p)):null){let b=Error(`createEngagement: project "${a.project_id}" already owns an engagement`);throw b.code="HAIL_PROJECT_IN_USE",b}b=(0,f.U1)(a.project_id)}else b=(0,f.gA)({name:`HAIL — ${c}`,description:`HAIL operating-model engagement for ${c}.`,color:"#c2452a"});let q=(0,h.NZ)({definition_slug:i.WV,project_id:b.id,title:`HAIL engagement — ${c}`,created_by_user_id:a.created_by_user_id||null});return j.prepare(`
    INSERT INTO hail_engagements
      (id, principal_name, institution_type, accountable_human, confidentiality_posture,
       project_id, process_case_id, current_stage, status, org_id, created_by_user_id,
       created_at, updated_at)
    VALUES (?, ?, ?, ?, ?, ?, ?, 'diagnostic', 'active', ?, ?, ?, ?)
  `).run(n,c,a.institution_type||null,d,a.confidentiality_posture||"local_first_strict",b.id,q.id,a.org_id||null,a.created_by_user_id||null,m,m),(0,g.appendAudit)({type:"hail.engagement.create",summary:`HAIL engagement created for ${c}`,status:"ok",meta:{engagement_id:n,project_id:b.id,process_case_id:q.id}}),l(n)}[e,f,g,h,i]=j.then?(await j)():j,d()}catch(a){d(a)}})}};