"use strict";exports.id=3332,exports.ids=[3332],exports.modules={63332:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{Ij:()=>v,oC:()=>u,vG:()=>q});var e=c(34255),f=c(40718),g=c(1423),h=c(72326),i=c(58708),j=c(60105),k=c(9001),l=c(81833),m=c(97190),n=c(48409),o=a([e,f,g,h,i,j,k,l,m,n]);[e,f,g,h,i,j,k,l,m,n]=o.then?(await o)():o;let w={"mines-data-interpreter":["mines_project_read","mines_document_extract","mines_extract_facts","mines_assumption_validate"],"mines-report-packager":["mines_project_read","mines_report_generate"],"mines-valuation-analyst":["mines_project_read","mines_assumption_validate","mines_valuation_run","mines_sensitivity_run"],"mines-feasibility-lead":["mines_project_read","mines_report_generate"],"mines-analyst":["mines_project_read","mines_extract_facts","mines_report_generate"]};function p(){let a=(0,e.getDb)();for(let[b,c]of Object.entries(w))if(a.prepare("SELECT 1 FROM agents WHERE id = ?").get(b))for(let a of c)try{(0,j.Xr)(b,a,"auto")}catch{}}function q(a={}){if(a.engine)return(0,h.$k)(a.engine);try{let a=(0,e.getDb)().prepare("SELECT engine FROM agents WHERE id = 'mines-data-interpreter'").get();if(a?.engine)return(0,h.$k)(a.engine)}catch{}return"claude-code"}let x={investor_presentation:{hero_headline:{type:"string",description:"One punchy line, < 12 words."},hero_subhead:{type:"string",description:"1–2 sentences framing the opportunity."},opportunity:{type:"array",items:{type:"string"},description:"2–3 short paragraphs on why this ground."},findings_lead:{type:"string"},upside_lead:{type:"string"},risk_lead:{type:"string",description:"Lead with the risk honestly."},the_ask:{type:"string"}},data_quality_report:{lead:{type:"string",description:"One short paragraph introducing the state and coverage of the project data archive."},gaps:{type:"string",description:"One short paragraph assessing data gaps and what would raise confidence."}},interpretation_memo:{lead:{type:"string",description:"One short paragraph framing the geological interpretation."},interpretation:{type:"string",description:"1–2 paragraphs interpreting the geology and mineralization qualitatively."}},due_diligence_memo:{exec_summary:{type:"string",description:"1–2 paragraph executive summary of the opportunity."},thesis:{type:"string",description:"One paragraph investment thesis."},overview:{type:"string",description:"One short paragraph project overview."},geology:{type:"string",description:"One short paragraph on geology and mineralization."},exploration:{type:"string",description:"One short paragraph framing exploration results."},comparables:{type:"string",description:"One short paragraph on comparable assets / analogues in the belt."},risk_intro:{type:"string",description:"One short paragraph introducing the risk register."},recommendation:{type:"string",description:"A short recommended next-phase work program, as prose or a numbered list."}},pfs_readiness_report:{verdict:{type:"string",description:"Lead with the honest verdict: is a PFS supportable, and if not, the single hard blocker (almost always: no maiden mineral resource). Qualitative only."},gap_intro:{type:"string",description:"One short paragraph introducing the data/gate gaps between today and PFS confidence."},work_program:{type:"string",description:"The critical-path work program to reach PFS, ordered to the decision gates. Prose or a numbered list. No figures."},recommendation:{type:"string",description:"A short closing recommendation on the next phase of work."}}},y={investor_presentation:"Write for a non-technical investor. Lead with the risk.",data_quality_report:"Write for a diligence analyst assessing data completeness.",interpretation_memo:"Write for a technical reviewer interpreting the geology.",due_diligence_memo:"Write a credible institutional investment memorandum. Lead with the risk.",pfs_readiness_report:"Write as a Feasibility Lead assessing PFS readiness. A PFS requires a Mineral Reserve converted from Measured & Indicated Resources. If there is no declared resource, say plainly that a PFS cannot be produced and frame the path to a maiden resource. Never present an exploration target as a resource."};async function r(a,b,c,d,e){if(!x[c])return{};let f=e||g.k,h=a.prepare("SELECT fact_type, value_text FROM mines_extracted_facts WHERE project_id = ? ORDER BY fact_type").all(b.id),j="";try{let{chunks:a}=await (0,i.P)(b.id,`${b.name} geology mineralization targets copper porphyry exploration`,5);j=a.map(a=>`- (p${a.page??"?"}) ${String(a.text||"").replace(/\s+/g," ").slice(0,300)}`).join("\n")}catch{}let k=`You are a mining-advisory analyst authoring the prose for a ${c.replace(/_/g," ")}. ${y[c]||""}
Rules:
1. NEVER state a numeric figure (grade, tonnage, value, percentage, depth, or digit count). Numbers are rendered separately from cited database rows. Write qualitative prose only.
2. Never present a conceptual exploration target as a mineral resource.
3. Ground every claim in the supplied facts. No outside knowledge, no invented geology.
4. Fill every slot.`,l=c.replace(/_/g," "),m=`PROJECT: ${b.name} (${b.commodity||"Cu"}, ${b.asset_stage||"exploration"}).

EXTRACTED FACTS:
${h.map(a=>`- ${a.fact_type}: ${a.value_text}`).join("\n")||"(none)"}

SOURCE EXCERPTS:
${j||"(none)"}

Write the ${l} narrative now.`;try{return await f({engine:d,schema:x[c],system:k,user:m,label:l,temperature:.3,max_tokens:2048})}catch{return{}}}async function s({db:a,project:b,space:c,kind:d,engine:e,user_id:g,org_id:h,authorFn:i}){let j=await r(a,b,d,e,i),k=await (0,f.executeRegistryTool)("mines_report_generate",{project_id:b.id,report_kind:d,space_id:c.id,narrative:j},{agent_id:"pfs_readiness_report"===d?"mines-feasibility-lead":"mines-report-packager",acting_on_behalf_of_user_id:g,org_id:h,engine:e});return{ok:!!(k&&("ok"===k.status||k.artifact_id)),result:k,narrative:j}}function t(a,b,c){let d=c?(0,l.pp)(c):null;return!d&&b.default_space_id&&(d=(0,l.pp)(b.default_space_id)),d||(d=(0,l.iF)().spaces.find(a=>a.name===b.name)||(0,l.bz)({name:b.name}),a.prepare("UPDATE mines_projects SET default_space_id = ?, updated_at = ? WHERE id = ?").run(d.id,(0,e.nowIso)(),b.id)),d}async function u({projectId:a,user_id:b="local-user",org_id:c="personal-org",space_id:d=null,engine:g=null,wipeFacts:h=!1,run_id:i=null,_authorJson:j=null}={}){let o=(0,e.getDb)(),r=o.prepare("SELECT * FROM mines_projects WHERE id = ?").get(a);if(!r)return{status:"error",error:"project_not_found"};let v=q({engine:g}),w=i||(0,e.newId)("mdil"),x=(b,c,d,e={})=>{try{(0,k.AC)({type:"mines_diligence",project_id:a,run_id:w,phase:b,status:c,message:d,engine:v,...e})}catch{}};p();let y=t(o,r,d);x("start","running",`Generating diligence for ${r.name} (${v})`,{space_id:y.id});let z=o.prepare("SELECT id, file_name FROM mines_source_documents WHERE project_id = ? AND (file_name LIKE '%43-101%' OR file_name LIKE '%43_101%') ORDER BY id LIMIT 1").get(a);h&&o.prepare("DELETE FROM mines_extracted_facts WHERE project_id = ?").run(a),x("extract","running","Extracting cited facts from the technical report…");try{let d=await (0,f.executeRegistryTool)("mines_extract_facts",{project_id:a,source_document_id:z?.id||void 0,char_budget:9e4},{agent_id:"mines-data-interpreter",acting_on_behalf_of_user_id:b,org_id:c,engine:v});d?.status&&"ok"!==d.status&&x("extract","warn",`extract: ${d.error||d.status}`)}catch(a){x("extract","warn",`extract error: ${a.message}`)}let A=o.prepare("SELECT COUNT(*) n FROM mines_extracted_facts WHERE project_id = ?").get(a).n;x("extract",A>0?"done":"warn",`${A} cited facts available`,{facts:A}),x("valuation","running","Running tiered valuation…");let B=null;try{await (0,n.w)({project_id:a},{agent_id:"mines-valuation-analyst",user_id:b,org_id:c}),B=await (0,m.R)({project_id:a},{agent_id:"mines-valuation-analyst",user_id:b,org_id:c})}catch(a){x("valuation","warn",`valuation error: ${a.message}`)}x("valuation","done",`tier ${B?.tier||"n/a"}`);let C=[{kind:"investor_presentation",title:`Investor Presentation — ${r.name}`},{kind:"data_quality_report",title:`Data Quality Report — ${r.name}`},{kind:"interpretation_memo",title:`Interpretation Memo — ${r.name}`},{kind:"due_diligence_memo",title:`Investment Diligence Memo — ${r.name}`},{kind:"pfs_readiness_report",title:`PFS-Readiness Assessment — ${r.name}`}],D=[];for(let a of C){let d=a.kind.replace(/_/g," ");x("reports","running",`Authoring + generating ${d}…`,{kind:a.kind});let e=!1;try{let{ok:d}=await s({db:o,project:r,space:y,kind:a.kind,engine:v,user_id:b,org_id:c,authorFn:j});e=d}catch(b){x("reports","warn",`${a.kind} error: ${b.message}`,{kind:a.kind})}e?x("reports","done",`${d} ready`,{kind:a.kind}):(D.push(a.kind),x("reports","warn",`${a.kind} not produced`,{kind:a.kind}))}D.length&&x("reports","error",`Incomplete package — ${D.length} report(s) failed: ${D.join(", ")}`,{failed_kinds:D}),o.prepare("UPDATE mines_projects SET has_technical_report = 1, updated_at = ? WHERE id = ?").run((0,e.nowIso)(),a);{let a=o.prepare("SELECT id, title FROM artifacts WHERE space_id = ? ORDER BY created_at DESC, id DESC").all(y.id),b=new Set,c=o.prepare("DELETE FROM artifacts WHERE id = ?");for(let d of a)b.has(d.title)?c.run(d.id):b.add(d.title)}let E=o.prepare("SELECT id, kind, title FROM artifacts WHERE space_id = ? ORDER BY created_at DESC").all(y.id);for(let a of E)try{(0,l.h5)(a.id,y.id)}catch{}let F=D.length>0,G=F?`Done with gaps — ${E.length} artifacts in "${y.name}" (${D.length} report(s) failed)`:`Done — ${E.length} artifacts in "${y.name}"`;return x("complete",F?"warn":"done",G,{space_id:y.id,space_name:y.name,artifacts:E,failed_kinds:D}),{status:F?"partial":"ok",run_id:w,space_id:y.id,space_name:y.name,engine:v,facts:A,artifacts:E,failed_kinds:D}}async function v({projectId:a,report_kind:b,engine:c=null,user_id:d="local-user",org_id:f="personal-org",space_id:g=null,_authorJson:h=null}={}){let i;if(!a)return{status:"error",error:"project_id_required"};if(!b)return{status:"error",error:"report_kind_required"};if(!x[b])return{status:"error",error:"unsupported_report_kind",report_kind:b,supported:Object.keys(x)};let j=(0,e.getDb)(),l=j.prepare("SELECT * FROM mines_projects WHERE id = ?").get(a);if(!l)return{status:"error",error:"project_not_found"};let m=q({engine:c});p();let n=t(j,l,g),o=(0,e.newId)("mrep");try{(0,k.AC)({type:"mines_diligence",project_id:a,run_id:o,phase:"reports",status:"running",message:`Generating ${b.replace(/_/g," ")} (${m})`,engine:m,kind:b})}catch{}try{i=await s({db:j,project:l,space:n,kind:b,engine:m,user_id:d,org_id:f,authorFn:h})}catch(a){return{status:"error",error:"report_failed",report_kind:b,engine:m,reason:a.message}}if(!i.ok)return{status:"error",error:"report_not_produced",report_kind:b,engine:m,tool_result:i.result};try{(0,k.AC)({type:"mines_diligence",project_id:a,run_id:o,phase:"complete",status:"done",message:`${b.replace(/_/g," ")} ready`,engine:m,kind:b,space_id:n.id})}catch{}return{status:"ok",report_kind:b,engine:m,artifact_id:i.result?.artifact_id||null,space_id:n.id,space_name:n.name}}d()}catch(a){d(a)}})}};