@duckcodeailabs/dql-cli 1.12.8 → 1.12.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/dist/assets/dql-notebook/assets/{AgentAnswerCard-D1VcQOTJ.js → AgentAnswerCard-Dp4odOLE.js} +1 -1
  2. package/dist/assets/dql-notebook/assets/{AgentLogPage-DKvtW4Fq.js → AgentLogPage-uvVs284-.js} +1 -1
  3. package/dist/assets/dql-notebook/assets/{AiBuildDialog-apJ4HoK3.js → AiBuildDialog-DEUS19WF.js} +1 -1
  4. package/dist/assets/dql-notebook/assets/{AiBuildResult-CvNitmsw.js → AiBuildResult-B9KmBRsh.js} +1 -1
  5. package/dist/assets/dql-notebook/assets/{AiSidePanel-B2cqbPJr.js → AiSidePanel-C7BZVSkM.js} +1 -1
  6. package/dist/assets/dql-notebook/assets/{AnalyticsHome-D5I-Okbz.js → AnalyticsHome-4TgtH6SB.js} +1 -1
  7. package/dist/assets/dql-notebook/assets/{AppsView-DLtjogVz.js → AppsView-CnfNtk5W.js} +3 -3
  8. package/dist/assets/dql-notebook/assets/{BlockStudio-BmNsIfNK.js → BlockStudio-DUXN3MKz.js} +1 -1
  9. package/dist/assets/dql-notebook/assets/{BusinessArtifactView-Bvn5X8uW.js → BusinessArtifactView-D8FIgrkF.js} +1 -1
  10. package/dist/assets/dql-notebook/assets/{DbtFirstModelingPage-DnpVGZJv.js → DbtFirstModelingPage-DR8hTZ95.js} +1 -1
  11. package/dist/assets/dql-notebook/assets/{GitPage-C_5u2aCj.js → GitPage-BS2sm9zh.js} +1 -1
  12. package/dist/assets/dql-notebook/assets/{GlobalAiRail-ZOHo4H6j.js → GlobalAiRail-B_MZsB0z.js} +1 -1
  13. package/dist/assets/dql-notebook/assets/{GovernedContextPage-CUaYIqfd.js → GovernedContextPage-CNM5UCAH.js} +1 -1
  14. package/dist/assets/dql-notebook/assets/{HelpDocsPage-6SmmBvJh.js → HelpDocsPage-Bc5pLakt.js} +1 -1
  15. package/dist/assets/dql-notebook/assets/{HomePage-LDu8z_nW.js → HomePage-DQSo-K4y.js} +1 -1
  16. package/dist/assets/dql-notebook/assets/{LineageDAG-VFSCvevO.js → LineageDAG-RdpWmGmR.js} +1 -1
  17. package/dist/assets/dql-notebook/assets/{LineageDetailView-CuGG_JDv.js → LineageDetailView-CZEx2r1H.js} +1 -1
  18. package/dist/assets/dql-notebook/assets/{LineageDrawer-B2SVsEw1.js → LineageDrawer-P7ZdOW8-.js} +1 -1
  19. package/dist/assets/dql-notebook/assets/{LineagePathBreadcrumb-qWhGM3bh.js → LineagePathBreadcrumb-DTUMFkJ8.js} +1 -1
  20. package/dist/assets/dql-notebook/assets/{MiniLineageGraph-BHxUFWDi.js → MiniLineageGraph-Ctp_yFh8.js} +1 -1
  21. package/dist/assets/dql-notebook/assets/{NewBlockModal-oo3fU5OW.js → NewBlockModal-BLtjuWGy.js} +1 -1
  22. package/dist/assets/dql-notebook/assets/{NewNotebookModal-Bl78Nnjz.js → NewNotebookModal-xgaKB2kI.js} +1 -1
  23. package/dist/assets/dql-notebook/assets/NotebookEditor-D6RgLQw-.js +202 -0
  24. package/dist/assets/dql-notebook/assets/{ReadinessPage-CL2EJLKo.js → ReadinessPage-C8hATaT_.js} +1 -1
  25. package/dist/assets/dql-notebook/assets/{SetupOnboarding-Cqw2NuAn.js → SetupOnboarding-DX2f53J2.js} +1 -1
  26. package/dist/assets/dql-notebook/assets/{TrustBadge-C4jIUuEE.js → TrustBadge-DPnKzRSY.js} +1 -1
  27. package/dist/assets/dql-notebook/assets/UnifiedAgentRunPanel-CwxQ4T19.js +83 -0
  28. package/dist/assets/dql-notebook/assets/{answer-to-notebook-mhY-MBsX.js → answer-to-notebook-Bm9oByWA.js} +1 -1
  29. package/dist/assets/dql-notebook/assets/{arrow-left-CwMW-Dnz.js → arrow-left-D2FbLWqh.js} +1 -1
  30. package/dist/assets/dql-notebook/assets/{arrow-right-CJ_6d0z7.js → arrow-right-OYItAZ-s.js} +1 -1
  31. package/dist/assets/dql-notebook/assets/{book-open-text-B2q44mou.js → book-open-text-BnnirfAc.js} +1 -1
  32. package/dist/assets/dql-notebook/assets/{bot-CbsSLtXR.js → bot-BJNxPYFm.js} +1 -1
  33. package/dist/assets/dql-notebook/assets/{chevron-up-DSMkEFrK.js → chevron-up-DM5LX-26.js} +1 -1
  34. package/dist/assets/dql-notebook/assets/{circle-x-C5hi2hCq.js → circle-x-Dic_-4tF.js} +1 -1
  35. package/dist/assets/dql-notebook/assets/{dagre.esm-BT65gOyC.js → dagre.esm-C9zxjHHX.js} +1 -1
  36. package/dist/assets/dql-notebook/assets/{external-link-sDmXu1pG.js → external-link-DHxAcoCE.js} +1 -1
  37. package/dist/assets/dql-notebook/assets/{grip-vertical-Ca_E_fRZ.js → grip-vertical-02I-EOjL.js} +1 -1
  38. package/dist/assets/dql-notebook/assets/{index-CcZ8Dw84.js → index-Ca3UeUWI.js} +3 -3
  39. package/dist/assets/dql-notebook/assets/{link-2-DaVaJfdX.js → link-2-Delh-lai.js} +1 -1
  40. package/dist/assets/dql-notebook/assets/{list-tree-DMGqPCsV.js → list-tree-BrIZg6l6.js} +1 -1
  41. package/dist/assets/dql-notebook/assets/{maximize-2-CVJP65sF.js → maximize-2-CQOA-bbN.js} +1 -1
  42. package/dist/assets/dql-notebook/assets/{minimize-2-BnsbPUr5.js → minimize-2-CUDBPkwe.js} +1 -1
  43. package/dist/assets/dql-notebook/assets/{panel-right-open-BTTos1w4.js → panel-right-open-CwhZfkKJ.js} +1 -1
  44. package/dist/assets/dql-notebook/assets/{pencil-BDR0kEX-.js → pencil-Cf6-MgpT.js} +1 -1
  45. package/dist/assets/dql-notebook/assets/{rotate-ccw-DrQw5ZrW.js → rotate-ccw-DndbJAiz.js} +1 -1
  46. package/dist/assets/dql-notebook/assets/{semantic-fields-CgqeBot0.js → semantic-fields-DwKPY_mU.js} +1 -1
  47. package/dist/assets/dql-notebook/assets/{star-DBVkbHOE.js → star-DvcMC9wZ.js} +1 -1
  48. package/dist/assets/dql-notebook/assets/{triangle-alert-_FtKJhjm.js → triangle-alert-DUf4Ook0.js} +1 -1
  49. package/dist/assets/dql-notebook/assets/{usePersistedAgentThreadId-BG1TZXp_.js → usePersistedAgentThreadId-DbdBi0oH.js} +1 -1
  50. package/dist/assets/dql-notebook/assets/{user-round-DkUToep7.js → user-round-DSt0xU3K.js} +1 -1
  51. package/dist/assets/dql-notebook/assets/{wand-sparkles-TgacCrJg.js → wand-sparkles-ro8Cq0ro.js} +1 -1
  52. package/dist/assets/dql-notebook/assets/{workflow-z-B8gUF9.js → workflow-DVJXehjU.js} +1 -1
  53. package/dist/assets/dql-notebook/assets/{wrench-CgXGBYJ-.js → wrench-DxUnoHtz.js} +1 -1
  54. package/dist/assets/dql-notebook/assets/{x-FQc3jbQ8.js → x-9Gtb3EAd.js} +1 -1
  55. package/dist/assets/dql-notebook/index.html +1 -1
  56. package/dist/local-runtime.d.ts +71 -1
  57. package/dist/local-runtime.d.ts.map +1 -1
  58. package/dist/local-runtime.js +558 -54
  59. package/dist/local-runtime.js.map +1 -1
  60. package/dist/package.json +10 -10
  61. package/package.json +10 -10
  62. package/dist/assets/dql-notebook/assets/NotebookEditor-BWMX6Xfi.js +0 -202
  63. package/dist/assets/dql-notebook/assets/UnifiedAgentRunPanel-CZjUHLl5.js +0 -83
@@ -1,4 +1,4 @@
1
- import{R as O,j as i,aN as We,r as $,u as $t,t as Ct,a as E}from"./index-CcZ8Dw84.js";import{C as ce,b as Ke,T as Ze,a as Bt,f as At}from"./usePersistedAgentThreadId-BG1TZXp_.js";import{T as zt}from"./TrustBadge-C4jIUuEE.js";import{R as Lt,G as Tt}from"./AiBuildResult-CvNitmsw.js";const Rt={value:"Value",block:"Certified block",term:"Business term",metric:"Metric",dimension:"Dimension",model:"dbt model",source:"Source table",consumer:"Used by"};function Oe(e){const t=(e??"").toLowerCase();return t==="certified"?"success":t==="deprecated"?"neutral":t.includes("review")||t==="draft"||t==="pending"?"warning":"neutral"}function Mt({walk:e,defaultOpen:t=!1,triggerLabel:r}){const[n,o]=O.useState(t),s=Math.min(e.steps.length,2),[a,d]=O.useState(s),u=()=>d(s),l=e.steps.slice(0,a),p=e.steps.length-a;return i.jsxs("div",{style:{border:"1px solid var(--border-subtle, rgba(127,127,127,0.25))",borderRadius:8,background:"var(--bg-1, transparent)",overflow:"hidden"},children:[i.jsxs("button",{type:"button","aria-expanded":n,onClick:()=>{o(c=>!c),n&&u()},style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,border:0,background:"transparent",color:"var(--text-secondary, inherit)",cursor:"pointer",padding:"8px 11px",font:"inherit",fontSize:12,fontWeight:700},children:[i.jsxs("span",{style:{display:"flex",alignItems:"center",gap:7},children:[i.jsx("span",{"aria-hidden":!0,style:{transform:n?"rotate(90deg)":"none",transition:"transform 120ms",display:"inline-block"},children:"▸"}),r??"Why?"]}),i.jsx("span",{style:{fontSize:11,color:"var(--text-tertiary, inherit)",fontWeight:600},children:n?"Hide derivation":"Show how this was derived"})]}),n&&i.jsxs("div",{style:{padding:"2px 11px 11px",display:"flex",flexDirection:"column",gap:10},children:[i.jsx("div",{style:{fontSize:12.5,lineHeight:1.5,color:"var(--text-primary, inherit)"},children:e.summary}),(e.trustLabel||e.freshness)&&i.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"center"},children:[e.trustLabel&&i.jsx(We,{tone:Oe(e.trustLabel),children:Pe(e.trustLabel)}),e.freshness&&i.jsxs("span",{style:{fontSize:11,color:"var(--text-tertiary, inherit)"},children:["Fresh as of ",_t(e.freshness)]})]}),i.jsx("ol",{style:{listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:7},children:l.map((c,f)=>i.jsxs("li",{style:{display:"flex",gap:9,alignItems:"flex-start",paddingLeft:2},children:[i.jsx("span",{"aria-hidden":!0,style:{marginTop:3,width:7,height:7,borderRadius:999,flexShrink:0,background:"var(--accent, currentColor)",opacity:.7}}),i.jsxs("div",{style:{minWidth:0,display:"flex",flexDirection:"column",gap:2},children:[i.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center",flexWrap:"wrap"},children:[i.jsx("span",{style:{fontSize:10,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.04em",color:"var(--text-tertiary, inherit)"},children:Rt[c.kind]}),i.jsx("span",{style:{fontSize:12.5,fontWeight:700,color:"var(--text-primary, inherit)",overflowWrap:"anywhere"},children:c.name}),c.status&&i.jsx(We,{tone:Oe(c.status),children:Pe(c.status)})]}),(c.owner||c.detail)&&i.jsxs("div",{style:{fontSize:11.5,color:"var(--text-secondary, inherit)",lineHeight:1.45},children:[c.owner&&i.jsxs("span",{children:["Owner: ",c.owner,". "]}),c.detail]})]})]},`${c.kind}-${c.name}-${f}`))}),p>0&&i.jsxs("button",{type:"button",onClick:()=>d(c=>Math.min(e.steps.length,c+1)),style:{alignSelf:"flex-start",border:"1px solid var(--border-default, rgba(127,127,127,0.3))",borderRadius:6,background:"transparent",color:"var(--accent, inherit)",cursor:"pointer",padding:"4px 9px",fontSize:11,fontWeight:700},children:["Show next step (",p," more)"]}),e.caveats&&e.caveats.length>0&&i.jsxs("div",{style:{borderLeft:"3px solid var(--status-warning, #d29922)",background:"var(--status-warning-bg, rgba(210,153,34,0.08))",borderRadius:6,padding:"8px 10px",display:"flex",flexDirection:"column",gap:4},children:[i.jsx("span",{style:{fontSize:10,fontWeight:800,textTransform:"uppercase",letterSpacing:"0.04em",color:"var(--status-warning, inherit)"},children:"Caveats"}),e.caveats.map((c,f)=>i.jsx("span",{style:{fontSize:11.5,color:"var(--text-secondary, inherit)",lineHeight:1.45},children:c},f))]})]})]})}function Pe(e){return e.replace(/[_-]+/g," ").replace(/\b\w/g,t=>t.toUpperCase())}function _t(e){const t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleDateString()}const ue=/date|time|day|month|year|week|quarter|period|_at$|^at$/i,fe=/(?:^|_)(?:id|uuid|key|code)$/i,he=/(?:name|title|label|display|description|customer|account|product|region|segment|category|channel)$/i,Dt=new Set(["bar","grouped-bar","stacked-bar","line","area","scatter","pie","donut","heatmap","histogram","funnel","sankey","waterfall","gauge","kpi","table"]);function qe(e){return typeof e=="number"?Number.isFinite(e):typeof e=="string"?e.trim()!==""&&Number.isFinite(Number(e)):!1}function et(e){const t=e.rows.slice(0,20);return t.length===0?[]:e.columns.filter(r=>t.some(n=>qe(n[r]))&&t.every(n=>{const o=n[r];return o==null||o===""||qe(o)}))}function It(e,t){const r=e.columns.filter(n=>!t.includes(n));return r.find(n=>he.test(n)&&!fe.test(n))??r.find(n=>!fe.test(n))??r[0]??e.columns[0]}function Wt(e){return e.columns.filter(t=>{if(!fe.test(t))return!1;const r=t.replace(/(?:_)?(?:id|uuid|key|code)$/i,"").replace(/_+$/,"");return e.columns.some(n=>n!==t&&(r.length>0&&n.toLowerCase().startsWith(r.toLowerCase())&&he.test(n)||r.length===0&&he.test(n)))})}function Ot(e,t){if(t.length===0)return e;const r=new Set(t);return{...e,columns:e.columns.filter(n=>!r.has(n)),rows:e.rows.map(n=>Object.fromEntries(Object.entries(n).filter(([o])=>!r.has(o))))}}function tt(e,t){const r=et(e),n=e.rows.length>0,o=e.columns.filter(g=>!r.includes(g));if(!(n&&r.length>=1))return{config:{...t??{},chart:"table",decisionSource:"data",rationale:"The returned rows do not contain a numeric measure to plot."},chartable:!1,reason:"No numeric measure"};const a=It(e,r),d=t!=null&&t.x&&e.columns.includes(t.x)?t.x:a,u=t!=null&&t.y&&e.columns.includes(t.y)?t.y:r.find(g=>g!==d)??r[0],l=qt(e,r,o,d),p=Pt(t==null?void 0:t.chart),c=t==null?void 0:t.decisionSource,f=c==="authored"||c==="user",h=f&&p||p&&Ft(p,e,r,o,d,u)?p:l.chart,x=!!(p&&p!==h&&!f),b=t!=null&&t.color&&e.columns.includes(t.color)?t.color:h==="sankey"?o.find(g=>g!==d):t==null?void 0:t.color,S=x?`${l.reason}; replaced the agent suggestion because the returned data is not compatible.`:p&&!f?"Agent-selected visualization validated against the returned data.":l.reason;return{config:{...t??{},chart:h,x:d,y:u,...b?{color:b}:{},decisionSource:f?c:p&&!x?"agent":"data",rationale:S},chartable:h!=="table",reason:S}}function Pt(e){if(typeof e!="string")return;const t=e.toLowerCase().replace(/_/g,"-").replace("single-value","kpi");return Dt.has(t)?t:void 0}function qt(e,t,r,n){return e.rows.length===1&&t.length>=1?{chart:"kpi",reason:"Single returned value"}:ue.test(n)&&t.length>=1?{chart:"line",reason:`Time-like field ${n}`}:r.length>0&&t.length>=2?{chart:"grouped-bar",reason:"One category with multiple numeric measures"}:r.length>0&&t.length===1?{chart:"bar",reason:"Categorical comparison with one numeric measure"}:t.length>=2?{chart:"scatter",reason:"Two continuous numeric measures"}:{chart:"table",reason:"No comparable category or time axis was returned"}}function Ft(e,t,r,n,o,s){return e==="table"?!0:e==="kpi"||e==="gauge"?r.length>=1&&t.rows.length===1:e==="line"||e==="area"?r.includes(s)&&ue.test(o):e==="scatter"?r.length>=2:e==="sankey"?n.length>=2&&r.length>=1:e==="histogram"?r.length>=1:e==="grouped-bar"||e==="stacked-bar"?n.length>=1&&r.length>=2:e==="pie"||e==="donut"?n.length>=1&&r.length>=1&&t.rows.length>=2&&t.rows.length<=8:e==="heatmap"?t.columns.length>=3&&r.length>=1:e==="funnel"||e==="waterfall"?n.length>=1&&r.length>=1:e==="bar"?n.length>=1&&r.length>=1&&!ue.test(o):!1}function Qn({result:e,themeMode:t,t:r,chartConfig:n,embedded:o=!1,tabLabels:s}){const a=e.rows.length===0,[d,u]=$.useState(),[l,p]=$.useState(!1),c=$.useMemo(()=>({...n??{},...d??{}}),[n,d]),{config:f,chartable:h}=tt(e,c),x=$.useMemo(()=>et(e),[e]),b=$.useMemo(()=>Wt(e),[e]),S=$.useMemo(()=>l?e:Ot(e,b),[b,e,l]),[g,j]=$.useState("table"),w=m=>({border:"none",background:"transparent",cursor:"pointer",fontFamily:r.font,fontSize:11,fontWeight:700,padding:"2px 4px",color:m?r.accent:r.textMuted,borderBottom:`2px solid ${m?r.accent:"transparent"}`}),T=ce.some(m=>m.value===f.chart)?f.chart:"bar";return i.jsxs("div",{style:{border:o?"none":`1px solid ${r.headerBorder}`,background:r.cellBg,borderRadius:o?0:8,overflow:"hidden"},children:[i.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center",padding:o?"9px 14px":"5px 9px",borderBottom:`1px solid ${r.headerBorder}`},children:[h&&i.jsx("button",{type:"button",onClick:()=>j("table"),style:w(g==="table"),children:(s==null?void 0:s.table)??"Table"}),h&&i.jsx("button",{type:"button",onClick:()=>j("chart"),style:w(g==="chart"),children:(s==null?void 0:s.chart)??"Chart"}),!h&&!a&&i.jsx("span",{style:{fontSize:11,fontWeight:700,color:r.textMuted},children:(s==null?void 0:s.table)??"Table"}),h&&g==="chart"?i.jsx("select",{value:T,onChange:m=>u(A=>({...A??{},chart:m.target.value,decisionSource:"user",rationale:"Selected manually."})),title:"Chart type",style:{fontFamily:r.font,fontSize:10.5,fontWeight:600,color:r.textSecondary,background:r.cellBg,border:`1px solid ${r.headerBorder}`,borderRadius:5,padding:"1px 4px",cursor:"pointer"},children:ce.map(m=>i.jsx("option",{value:m.value,children:m.label},m.value))}):null,h&&g==="chart"?i.jsxs(i.Fragment,{children:[i.jsxs("label",{style:{display:"inline-flex",alignItems:"center",gap:3,color:r.textMuted,fontSize:10.5},children:["X",i.jsx("select",{"aria-label":"X-axis field",value:f.x??"",onChange:m=>u(A=>({...A??{},x:m.target.value,decisionSource:"user",rationale:"Axis selected manually."})),style:{fontFamily:r.font,fontSize:10.5,color:r.textSecondary,background:r.cellBg,border:`1px solid ${r.headerBorder}`,borderRadius:5,padding:"1px 3px",cursor:"pointer",maxWidth:120},children:e.columns.map(m=>i.jsx("option",{value:m,children:m},m))})]}),x.length>0?i.jsxs("label",{style:{display:"inline-flex",alignItems:"center",gap:3,color:r.textMuted,fontSize:10.5},children:["Y",i.jsx("select",{"aria-label":"Y-axis field",value:f.y??"",onChange:m=>u(A=>({...A??{},y:m.target.value,decisionSource:"user",rationale:"Axis selected manually."})),style:{fontFamily:r.font,fontSize:10.5,color:r.textSecondary,background:r.cellBg,border:`1px solid ${r.headerBorder}`,borderRadius:5,padding:"1px 3px",cursor:"pointer",maxWidth:120},children:x.map(m=>i.jsx("option",{value:m,children:m},m))})]}):null,f.chart==="sankey"?i.jsxs("label",{style:{display:"inline-flex",alignItems:"center",gap:3,color:r.textMuted,fontSize:10.5},children:["Target",i.jsx("select",{"aria-label":"Sankey target field",value:f.color??"",onChange:m=>u(A=>({...A??{},color:m.target.value,decisionSource:"user",rationale:"Sankey target selected manually."})),style:{fontFamily:r.font,fontSize:10.5,color:r.textSecondary,background:r.cellBg,border:`1px solid ${r.headerBorder}`,borderRadius:5,padding:"1px 3px",cursor:"pointer",maxWidth:120},children:e.columns.filter(m=>!x.includes(m)&&m!==f.x).map(m=>i.jsx("option",{value:m,children:m},m))})]}):null]}):null,h&&g==="chart"&&f.rationale?i.jsxs("span",{title:f.rationale,style:{fontSize:10.5,color:r.textMuted,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:230},children:["Smart chart · ",f.chart]}):null,i.jsxs("span",{style:{marginLeft:"auto",fontSize:10.5,color:r.textMuted,alignSelf:"center"},children:[e.rowCount??e.rows.length," rows"]})]}),i.jsx("div",{style:{padding:o?12:8,minHeight:h&&g==="chart"?200:void 0,maxHeight:o?380:320,overflow:"auto"},children:a?i.jsxs("div",{style:{padding:"18px 8px",textAlign:"center",color:r.textMuted,fontSize:12},children:["The query ran successfully and matched 0 rows",e.columns.length>0?` (columns: ${e.columns.join(", ")})`:"","."]}):h&&g==="chart"?i.jsx(Ke,{result:e,themeMode:t,chartConfig:f,onConfigChange:m=>u(A=>({...A??{},...m,decisionSource:"user",rationale:"Adjusted manually."}))}):i.jsxs(i.Fragment,{children:[b.length>0?i.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:6},children:i.jsx("button",{type:"button",onClick:()=>p(m=>!m),style:{border:"none",background:"transparent",color:r.accent,cursor:"pointer",fontSize:10.5,padding:0},children:l?"Hide technical fields":"Show IDs"})}):null,i.jsx(Ze,{result:S,themeMode:t})]})})]})}const Et=3;function Qt(e){const{business360:t,block:r,value:n,generated:o=!1}=e,s=e.maxPerKind??Et,a=t.focus,d=[];n&&d.push({kind:"value",name:n,detail:a.name?`Reported by ${a.name}.`:void 0});const u=(r==null?void 0:r.owner)??a.owner,l=(r==null?void 0:r.status)??a.status,p=(r==null?void 0:r.reviewCadence)??oe(a.metadata,"reviewCadence");d.push({kind:"block",name:a.name,owner:u,status:l,detail:Nt({reviewCadence:p,businessOutcome:(r==null?void 0:r.businessOutcome)??oe(a.metadata,"businessOutcome"),decisionUse:r==null?void 0:r.decisionUse})});const c=Fe([...t.businessDefinition.terms,...t.businessDefinition.definedByTerms]);for(const x of c.slice(0,s))x.id!==a.id&&d.push({kind:"term",name:x.name,owner:x.owner,detail:"Business term this answer is defined in."});for(const x of se(r==null?void 0:r.metricRefs).slice(0,s))d.push({kind:"metric",name:x,detail:"Governed metric used in the calculation."});for(const x of se(r==null?void 0:r.dimensionRefs).slice(0,s))d.push({kind:"dimension",name:x,detail:"Dimension used to slice the value."});for(const x of t.technicalSources.dbtModels.slice(0,s))d.push({kind:"model",name:x.name,detail:"dbt model the certified SQL builds on."});const f=Fe([...t.technicalSources.dbtSources,...t.technicalSources.sourceTables]);for(const x of f.slice(0,s))d.push({kind:"source",name:x.name,detail:"Raw source table the data originates from."});const h=se((r==null?void 0:r.caveats)??Vt(a.metadata,"caveats"));return{value:n,summary:Ut({focus:a,blockOwner:u,reviewCadence:p,generated:o,sourceAssets:f}),steps:d,trustLabel:e.trustLabel??(o?"review_required":void 0),freshness:e.freshness??Ht(r==null?void 0:r.dataState,r==null?void 0:r.dataStateDetail)??oe(a.metadata,"freshness"),caveats:h.length>0?h:void 0}}function Ht(e,t){switch(e){case"failed":return t?`upstream failed — ${t}`:"upstream failed";case"stale":return t?`stale data — ${t}`:"stale data";default:return}}function Nt(e){const t=[];return e.businessOutcome?t.push(e.businessOutcome):e.decisionUse&&t.push(`Supports: ${e.decisionUse}.`),e.reviewCadence&&t.push(`Reviewed ${e.reviewCadence}.`),t.length>0?t.join(" "):void 0}function Ut(e){const t=e.blockOwner?` owned by ${e.blockOwner}`:"",r=e.sourceAssets.length>0?` It traces back to ${e.sourceAssets[0].name}.`:"";if(e.generated)return`This value was generated from ${e.focus.name}${t} and still needs analyst review before it can be certified.${r}`;const n=e.reviewCadence?`, reviewed ${e.reviewCadence}`:"";return`This value comes from the certified ${e.focus.name}${t}${n}.${r}`}function oe(e,t){const r=e==null?void 0:e[t];return typeof r=="string"&&r.trim().length>0?r:void 0}function Vt(e,t){const r=e==null?void 0:e[t];return Array.isArray(r)?r.filter(n=>typeof n=="string"&&n.trim().length>0):[]}function se(e){if(!e)return[];const t=new Set,r=[];for(const n of e){const o=typeof n=="string"?n.trim():"";!o||t.has(o.toLowerCase())||(t.add(o.toLowerCase()),r.push(o))}return r}function Fe(e){const t=new Set,r=[];for(const n of e)t.has(n.id)||(t.add(n.id),r.push(n));return r}function nt(e){var n,o;const t=e.dqlArtifact,r=(n=t==null?void 0:t.source)==null?void 0:n.trim();return r?{source:r,kind:t==null?void 0:t.kind,name:t==null?void 0:t.name,sourcePath:t==null?void 0:t.sourcePath,metrics:le(t==null?void 0:t.metrics),dimensions:le(t==null?void 0:t.dimensions),filters:((t==null?void 0:t.filters)??[]).map(s=>{var l,p;const a=(l=s.dimension)==null?void 0:l.trim(),d=((p=s.operator)==null?void 0:p.trim())||"equals",u=le(s.values);return!a||u.length===0?"":`${a} ${d} ${u.join(", ")}`}).filter(Boolean),timeDimension:(o=t==null?void 0:t.timeDimension)!=null&&o.name?[t.timeDimension.name,t.timeDimension.granularity].filter(Boolean).join(" / "):void 0,orderBy:((t==null?void 0:t.orderBy)??[]).map(s=>{var u,l;const a=(u=s.name)==null?void 0:u.trim(),d=(l=s.direction)==null?void 0:l.trim();return a&&d?`${a} ${d}`:""}).filter(Boolean),limit:typeof(t==null?void 0:t.limit)=="number"&&Number.isFinite(t.limit)?t.limit:void 0}:null}function Jt(e){for(let t=e.length-1;t>=0;t--){const r=e[t];if(r.kind!=="tool_result"||r.id!=="governed_answer")continue;const n=r.output;if(n&&typeof n=="object"&&"kind"in n)return n}return null}function le(e){return Array.isArray(e)?e.map(t=>typeof t=="string"?t.trim():"").filter(Boolean):[]}function Gt(e){const t=e.result;if(!t||!Array.isArray(t.rows))return null;const n=(Array.isArray(t.columns)?t.columns:[]).map(s=>typeof s=="string"?s:s&&typeof s=="object"&&typeof s.name=="string"?String(s.name):String(s)),o=t.rows.filter(s=>!!(s&&typeof s=="object"&&!Array.isArray(s))).map(s=>s);return{columns:n,rows:o,rowCount:typeof t.rowCount=="number"?t.rowCount:o.length,executionTime:t.executionTime}}function Xt(e,t){const r=e&&typeof e=="object"?e:{},n=typeof r.chart=="string"?r.chart:void 0,o=r.decisionSource==="authored"||r.decisionSource==="agent"||r.decisionSource==="data"||r.decisionSource==="user"?r.decisionSource:void 0,s=n||(typeof t.suggestedViz=="string"?t.suggestedViz:void 0),a=s?s.toLowerCase().replace(/_/g,"-")==="single-value"?"kpi":s:void 0;return{...a?{chart:a}:{},...a?{decisionSource:o??(n?"authored":"agent")}:{},...typeof r.rationale=="string"?{rationale:r.rationale}:{},...typeof r.x=="string"?{x:r.x}:{},...typeof r.y=="string"?{y:r.y}:{},...typeof r.color=="string"?{color:r.color}:{},...typeof r.title=="string"?{title:r.title}:{}}}function Yt(e,t){return!t||t.columns.length===0?e:tt(t,e).config}function ae(e){if(typeof e!="string")return;const t=e.replace(/\s+/g," ").trim();if(t)return t.length>180?`${t.slice(0,177)}...`:t}function rt(e){const t=Kt(e,["Answer","Business summary","Summary"]);if(t)return Ee(t,340);const r=/^(?:reuse evidence|certified result preview|result preview|result summary|trust status|next action|recommended action|sql used by block|reusable block sql|proposed sql|sql generated|sql draft|evidence|parameters|lineage|technical lineage)\s*:/i,n=/^(?:SELECT|WITH|FROM|WHERE|GROUP BY|ORDER BY|LIMIT)\b/i,o=[];for(const a of e.split(/\r?\n/)){const d=a.trim();if(!(!d||/^#{1,6}\s*/.test(d)||/^```/.test(d)||/^\|/.test(d))&&!/^outcome\s*:/i.test(d)){if(r.test(d)||n.test(d)){if(o.length>0)break;continue}if(o.push(d),o.length>=5)break}}const s=o.join(" ").replace(/[*_`]+/g,"").replace(/\s+/g," ").trim();return Ee(s,340)}function Kt(e,t){var p,c,f;const r=e.split(/\r?\n/),n=t.map(h=>h.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|"),o=new RegExp(`^\\s*(?:#{1,6}\\s*)?(?:[-*]\\s*)?(?:\\*\\*)?(${n})(?:\\*\\*)?\\s*:\\s*(.*)$`,"i"),s=/^\s*(?:#{1,6}\s*)?(?:[-*]\s*)?(?:\*\*)?[A-Z][A-Za-z /-]{2,42}(?:\*\*)?\s*:/,a=r.findIndex(h=>o.test(h));if(a<0)return;const d=((f=(c=(p=r[a])==null?void 0:p.match(o))==null?void 0:c[2])==null?void 0:f.trim())??"",u=d?[d]:[];for(let h=a+1;h<r.length;h+=1){const x=r[h]??"";if(s.test(x)||/^\s*```/.test(x))break;x.trim()&&u.push(x.trim())}return u.join(" ").replace(/[*_`]+/g,"").replace(/\s+/g," ").trim()||void 0}function Ee(e,t){const r=e.replace(/\s+/g," ").trim();if(r.length<=t)return r;const n=r.slice(0,t-1),o=Math.max(n.lastIndexOf(". "),n.lastIndexOf("; "));if(o>100)return n.slice(0,o+1).trim();const s=n.lastIndexOf(" ");return`${n.slice(0,s>80?s:n.length).trim()}...`}function Zt({answer:e,themeMode:t,showSql:r=!0,compact:n=!1,addToAppTarget:o,sourceQuestion:s,onInvestigate:a,onInsertSql:d,onCreateBlock:u}){var we,ke,$e,Ce,Be,Ae,ze,Le,Te,Re,Me,_e,De;const l=Ct[t],{dispatch:p}=$t(),c=Gt(e),f=Xt((we=e.result)==null?void 0:we.chartConfig,e),[h,x]=$.useState(),b=Yt({...f??{},...h??{}},c),S=!!(c&&Bt(c,b)!=="table"),g=e.analysisPlan??((ke=e.evidence)==null?void 0:ke.analysisPlan),j=r?e.sql??(($e=e.result)==null?void 0:$e.sql)??e.proposedSql??(g==null?void 0:g.sql):void 0,w=nt(e),T=e.executionError??(((Be=(Ce=e.evidence)==null?void 0:Ce.execution)==null?void 0:Be.status)==="failed"?e.evidence.execution.message:void 0),m=((Ae=e.result)==null?void 0:Ae.blockPath)??((ze=e.block)==null?void 0:ze.sourcePath),A=!!(j||T||r&&m),ee=!!e.evidence,[U,pe]=$.useState("answer"),[ct,xe]=$.useState(!1),[ge,ut]=$.useState(!1),me=dt(e),ye=zn(me,l),be=(e.answer??e.text??"").replace(/\n\n_Question:_[\s\S]*$/m,"").trim(),M=n?rt(be):be,k=((Le=e.result)==null?void 0:Le.blockName)??((Te=e.block)==null?void 0:Te.name)??((Me=(Re=e.citations)==null?void 0:Re.find(y=>y.kind==="block"))==null?void 0:Me.name),te=Mn(e,k),ft=Ln(e,c,k,m),[ht,ve]=$.useState(!1),[V,J]=$.useState(null),[je,pt]=$.useState(null),xt=!!(o&&(c||j||M||k)),gt=!!(d&&j),mt=!!(u&&j),P=ae(g==null?void 0:g.question)??ae(s)??ae(M)??"Investigate this answer",yt=!!(a&&P),bt=it(e,{sql:j,executionError:T,blockName:k,result:c}),vt=()=>{!d||!j||(d(j,k??(g==null?void 0:g.question)??"AI SQL preview",{question:s??(g==null?void 0:g.question)}),pt("Inserted SQL preview cell for review."))},jt=()=>{!u||!j||u(j,{title:(w==null?void 0:w.name)??k??(g==null?void 0:g.question)??"AI DQL draft",description:M||(g==null?void 0:g.routeReason)||"AI generated DQL draft.",tags:["ai-generated","review-required"]})},St=async(y="auto")=>{if(!o)return;const W=y==="both"?["chart","data"]:y==="data"?["data"]:y==="chart"?["chart"]:c?[S?"chart":"data"]:[];ve(!0),xe(!1),J(null);try{if(e.certification==="certified"&&k){const B=await E.getDashboard(o.appId,o.dashboardId);if(!B)throw new Error("Dashboard could not be loaded.");const _=[...B.dashboard.layout.items],R=W.length>0?W:["chart"];for(const F of R){const X=R.length>1?`${k}_${F}`:k,Ie={...B.dashboard,layout:{...B.dashboard.layout,items:_}},kt=In(Ie,X);_.push({i:kt,...Dn(Ie),block:{blockId:k},viz:{type:F==="data"?"table":Wn(b==null?void 0:b.chart)},title:R.length>1?`${k} ${F==="data"?"data":"chart"}`:k})}const q={...B.dashboard.layout,items:_},L=await E.patchDashboardLayout(o.appId,o.dashboardId,q);if(!L.ok)throw new Error(L.error);J(R.length>1?"Added certified chart and data tiles.":"Added certified block tile.")}else{const B=!!(j&&window.confirm("Keep this AI result refreshed daily?")),_=k??(M.slice(0,60)||"AI result"),R=W.length>0?W:["data"];let q=c??void 0;if(!q&&j){const L=await E.previewGeneratedSql(j);if(!L.ok)throw new Error(`SQL preview failed: ${L.error}`);q=L.result}for(const L of R){const F=L==="data"?{...b??{},chart:"table",title:`${_} data`}:b,X=await E.createAiPin(o.appId,{dashboardId:o.dashboardId,title:R.length>1?`${_} ${L==="data"?"data":"chart"}`:_,answer:M||e.answer||e.text||"AI generated answer",question:g==null?void 0:g.question,sql:j,sourceTier:e.sourceTier,certification:e.certification==="certified"?"certified":"ai_generated",reviewStatus:"needs_review",refreshCadence:B?"daily":"none",chartConfig:F,result:q,citations:e.citations,analysisPlan:g,evidence:e.evidence,followUps:g==null?void 0:g.followUps});if(!X.ok)throw new Error(X.error)}J(R.length>1?"Pinned chart and data tiles for review.":"Pinned AI result for review.")}window.dispatchEvent(new CustomEvent("dql-app-dashboard-updated",{detail:o}))}catch(B){J(B instanceof Error?B.message:String(B))}finally{ve(!1)}},wt=()=>{!a||!P||a({question:P,title:te?`${te}: ${P}`:P,answerSummary:M,blockName:te,sql:j,evidence:e.evidence})},ne=[{id:"answer",label:n?"Summary":"Answer",visible:!0},{id:"dql",label:"DQL",visible:!!w},{id:"visual",label:n?"Chart":"Visualization",visible:S},{id:"data",label:"Data",visible:!!c},{id:"sql",label:"SQL / Block",visible:r&&A},{id:"lineage",label:n?"Trace":"Lineage",visible:ee},{id:"context",label:n?"Context":"Business Context",visible:ee},{id:"review",label:n?"Trust":"Review",visible:ee||!!((_e=e.citations)!=null&&_e.length)}].filter(y=>y.visible),Se=ne.some(y=>y.id===U)?U:"answer",G=ne.filter(y=>y.id!=="answer"),re=G.some(y=>y.id===U)?U:(De=G[0])==null?void 0:De.id,ie=y=>y==="answer"?i.jsx(on,{summary:M,answer:e,blockName:k,evidence:e.evidence,analysisPlan:g,result:c,sourceTier:e.sourceTier,compact:n,t:l}):y==="dql"&&w?i.jsx(Sn,{artifact:w,t:l}):y==="visual"&&c&&S?i.jsxs("div",{style:{padding:n?"8px 10px":"10px 12px",minHeight:n?180:220,display:"grid",gap:10},children:[i.jsx($n,{result:c,chartConfig:b,t:l,onChange:W=>x(B=>({...B??{},...W,decisionSource:"user",rationale:"Adjusted manually."}))}),i.jsx(Ke,{result:c,themeMode:t,chartConfig:b})]}):y==="data"&&c?i.jsx("div",{style:{maxHeight:n?320:420,overflow:"auto"},children:i.jsx(Ze,{result:c,themeMode:t})}):y==="lineage"?i.jsx(bn,{evidence:e.evidence,t:l}):y==="context"?i.jsx(vn,{evidence:e.evidence,t:l}):y==="sql"&&r&&A?i.jsx(wn,{sql:j,blockPath:m,executionError:T,t:l}):y==="review"?i.jsx(jn,{answer:e,t:l}):null;return i.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:n?8:10,whiteSpace:"normal"},children:[i.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center",flexWrap:"wrap"},children:[i.jsx(zt,{state:me}),i.jsx(Lt,{t:l,route:e.route}),I(e.cascade)&&i.jsx("span",{style:{border:`1px solid ${l.cellBorder}`,borderRadius:999,padding:"3px 8px",fontSize:11,fontWeight:700,color:l.textSecondary,background:l.tableHeaderBg},children:I(e.cascade)}),!n&&k&&i.jsxs("span",{style:{fontSize:12,fontFamily:l.fontMono,color:l.textSecondary},children:["block: ",k]}),c&&i.jsxs("span",{style:{fontSize:12,color:l.textMuted},children:[(c.rowCount??c.rows.length).toLocaleString()," rows",c.executionTime!==void 0&&i.jsxs(i.Fragment,{children:[" - ",Math.round(c.executionTime),"ms"]})]}),xt&&i.jsx(Cn,{t:l,adding:ht,hasResult:!!c,hasChart:S,fallbackLabel:e.certification==="certified"&&k?n?"Add":"Add block":"Pin answer",open:ct,onToggle:()=>xe(y=>!y),onAdd:y=>void St(y)}),yt&&i.jsx("button",{type:"button",onClick:wt,style:{border:`1px solid ${l.accent}`,borderRadius:6,background:`${l.accent}12`,color:l.accent,cursor:"pointer",padding:n?"4px 8px":"5px 10px",fontSize:11,fontFamily:l.font,fontWeight:800},children:n?"Investigate":"Investigate deeper"}),mt&&i.jsx("button",{type:"button",onClick:jt,style:{border:`1px solid ${l.accent}`,borderRadius:6,background:l.cellBg,color:l.accent,cursor:"pointer",padding:n?"4px 8px":"5px 10px",fontSize:11,fontFamily:l.font,fontWeight:700},children:n?"DQL draft":w?"Review DQL draft":"Create DQL draft"}),gt&&i.jsx("button",{type:"button",onClick:vt,style:{border:`1px solid ${l.accent}`,borderRadius:6,background:`${l.accent}18`,color:l.accent,cursor:"pointer",padding:n?"4px 8px":"5px 10px",fontSize:11,fontFamily:l.font,fontWeight:700},children:n?"SQL preview":"Insert SQL preview"})]}),V&&i.jsx("div",{style:{fontSize:11,color:V.toLowerCase().includes("added")||V.toLowerCase().includes("pinned")?"#3fb950":"#ff7b72"},children:V}),je&&i.jsx("div",{style:{fontSize:11,color:"#3fb950"},children:je}),i.jsx(en,{outcome:bt,t:l,compact:n}),i.jsxs("div",{style:{border:`1px solid ${l.cellBorder}`,borderTop:`2px solid ${ye}`,borderRadius:n?10:6,overflow:"hidden",background:l.cellBg},children:[!n&&i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:14,padding:"4px 10px",borderBottom:`1px solid ${l.cellBorder}`,background:`${l.tableHeaderBg}70`,flexWrap:"wrap"},children:[ne.map(y=>i.jsx(Xe,{active:Se===y.id,label:y.label,onClick:()=>pe(y.id),t:l},y.id)),!r&&m&&i.jsx("span",{style:{marginLeft:"auto",minWidth:0,fontSize:11,fontFamily:l.fontMono,color:l.textMuted,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:m})]}),ie(n?"answer":Se),n&&G.length>0&&i.jsxs("div",{style:{borderTop:`1px solid ${l.cellBorder}`,background:`${l.tableHeaderBg}45`},children:[i.jsxs("button",{type:"button",onClick:()=>ut(y=>!y),style:{width:"100%",border:0,background:"transparent",color:l.textSecondary,padding:"8px 12px",display:"flex",justifyContent:"space-between",alignItems:"center",cursor:"pointer",fontSize:11,fontWeight:800},children:[i.jsx("span",{children:"Details"}),i.jsx("span",{style:{color:l.textMuted,fontFamily:l.fontMono},children:ge?"hide":"show evidence"})]}),ge&&i.jsxs("div",{style:{borderTop:`1px solid ${l.cellBorder}`},children:[i.jsx("div",{style:{display:"flex",alignItems:"center",gap:14,padding:"4px 12px",flexWrap:"wrap"},children:G.map(y=>i.jsx(Xe,{active:re===y.id,label:y.label,onClick:()=>pe(y.id),t:l},y.id))}),re?ie(re):null]})]}),i.jsx(kn,{items:ft,t:l,accent:ye}),i.jsx(Tt,{t:l,skills:e.appliedSkills,onOpenSkills:()=>p({type:"SET_MAIN_VIEW",view:"skills"})})]})]})}function it(e,t){var r,n,o,s,a;if(e.kind==="no_answer")return{kind:"cannot_answer",label:"Cannot answer yet",detail:"The assistant did not find enough trusted context to safely answer or generate SQL.",nextAction:"Clarify the business object, metric, grain, or source table.",tone:"error"};if(e.certification==="certified"||e.kind==="certified"){const d=t.blockName??e.sourceCertifiedBlock??((r=e.block)==null?void 0:r.name);return{kind:"reuse_certified_block",label:"Reuse certified block",detail:d?`Existing DQL block ${d} answers this request.`:"A certified DQL artifact answers this request.",nextAction:"Use the certified block instead of creating duplicate SQL.",tone:"success"}}return t.executionError||e.executionError?{kind:"fix_sql",label:"Fix SQL",detail:"The generated or selected SQL needs correction before it can become reusable DQL.",nextAction:"Ask AI to repair, edit manually, then rerun preview.",tone:"error"}:(n=e.draftBlock)!=null&&n.path||e.draftBlockId?{kind:"use_existing_draft",label:"Use existing draft",detail:`A review-required DQL draft is available at ${((o=e.draftBlock)==null?void 0:o.path)??e.draftBlockId}.`,nextAction:"Open the draft, review metadata/tests/lineage, then certify manually.",tone:"accent"}:(a=(s=e.dqlArtifact)==null?void 0:s.source)!=null&&a.trim()?{kind:"create_dql_draft",label:"Review DQL draft",detail:"A review-required DQL artifact is available for analyst review.",nextAction:"Review DQL metadata, query logic, lineage, and result preview before certification.",tone:"warning"}:t.sql?{kind:t.result?"generate_sql_cell":"create_dql_draft",label:t.result?"Review SQL preview":"Create DQL draft",detail:t.result?`Review-required SQL preview returned ${(t.result.rowCount??t.result.rows.length).toLocaleString()} row${(t.result.rowCount??t.result.rows.length)===1?"":"s"}.`:"Review-required SQL is available but still needs preview and DQL metadata review.",nextAction:t.result?"Create a DQL draft after reviewing parameters and lineage; insert SQL only as a notebook preview.":"Run preview, inspect parameters, then create a draft block.",tone:"warning"}:{kind:"needs_review",label:"Needs review",detail:"The assistant returned business context but no executable certified answer or SQL draft.",nextAction:"Review evidence and ask for a specific SQL, reuse, or DQL draft action.",tone:"muted"}}function en({outcome:e,t,compact:r}){const n=tn(e.tone,t);return i.jsxs("div",{style:{border:`1px solid ${n}45`,borderLeft:`3px solid ${n}`,borderRadius:r?10:7,background:`${n}10`,padding:r?"9px 10px":"10px 12px",display:"grid",gap:r?4:5},children:[i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,minWidth:0},children:[i.jsx("span",{style:{border:`1px solid ${n}55`,background:`${n}14`,color:n,borderRadius:999,padding:"2px 7px",fontSize:10,fontWeight:850,lineHeight:1.1,textTransform:"uppercase",letterSpacing:0,flexShrink:0},children:e.label}),i.jsx("span",{style:{fontSize:r?12:12.5,color:t.textPrimary,fontWeight:750,overflow:"hidden",textOverflow:"ellipsis"},children:e.detail})]}),i.jsxs("div",{style:{fontSize:r?11.5:12,color:t.textSecondary,lineHeight:1.45},children:["Next: ",e.nextAction]})]})}function tn(e,t){switch(e){case"success":return t.success;case"accent":return t.accent;case"warning":return t.warning;case"error":return t.error;case"muted":default:return t.textMuted}}function nn({answer:e,blockName:t}){const[r,n]=$.useState(null),[o,s]=$.useState(!1),[a,d]=$.useState(!1),u=O.useCallback(async()=>{var l,p;if(!a){d(!0),s(!0);try{const c=await E.fetchBusiness360(t);if(!c){n(null);return}const f=(l=e.evidence)==null?void 0:l.outcome,h=Qe(e,"metric"),x=Qe(e,"dimension"),b=e.certification!=="certified"&&e.kind!=="certified",S=Qt({business360:c,block:{name:t,owner:f==null?void 0:f.owner,status:((p=e.block)==null?void 0:p.status)??e.certification,reviewCadence:f==null?void 0:f.reviewCadence,caveats:f==null?void 0:f.caveats,decisionUse:f==null?void 0:f.decisionUse,metricRefs:h,dimensionRefs:x},value:rn(e),generated:b,trustLabel:e.trustLabel});n(S)}catch{n(null)}finally{s(!1)}}},[e,t,a]);return a?o?i.jsx("div",{style:{fontSize:11.5,color:"var(--text-tertiary, inherit)"},children:"Assembling derivation…"}):r?i.jsx(Mt,{walk:r,defaultOpen:!0}):null:i.jsx("button",{type:"button",onClick:()=>void u(),"aria-expanded":!1,style:{alignSelf:"flex-start",border:0,background:"transparent",color:"var(--accent, inherit)",cursor:"pointer",padding:"4px 0",fontSize:12,fontWeight:700,textDecoration:"underline",textUnderlineOffset:3},children:"Why? Show how this was derived"})}function Qe(e,t){var o,s;const r=(((o=e.evidence)==null?void 0:o.semanticObjects)??[]).filter(a=>a.kind===t).map(a=>a.name).filter(a=>!!a);if(r.length>0)return r;const n=e.analysisPlan??((s=e.evidence)==null?void 0:s.analysisPlan);return(t==="metric"?n==null?void 0:n.measures:n==null?void 0:n.dimensions)??[]}function rn(e){const t=e.result;if(t&&Array.isArray(t.rows)&&t.rows.length===1){const r=t.rows[0];if(r&&typeof r=="object"&&!Array.isArray(r)){const n=Object.values(r);if(n.length===1&&(typeof n[0]=="number"||typeof n[0]=="string"))return String(n[0])}}}function on({summary:e,answer:t,blockName:r,evidence:n,analysisPlan:o,result:s,sourceTier:a,compact:d,t:u}){var p,c,f,h,x,b,S,g,j;const l=(p=o==null?void 0:o.followUps)==null?void 0:p[0];return i.jsxs("div",{style:{padding:d?14:12,display:"flex",flexDirection:"column",gap:d?10:12},children:[e?i.jsx(ot,{text:e,t:u,compact:d,summaryOnly:d}):i.jsx("div",{style:{fontSize:12,color:u.textMuted},children:"No summary text was returned."}),t&&r&&i.jsx(nn,{answer:t,blockName:r}),d?i.jsx("div",{style:{fontSize:11.5,color:u.textMuted,display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},children:[a?An(a):null,s?`${(s.rowCount??s.rows.length).toLocaleString()} rows`:null,((c=n==null?void 0:n.validation)==null?void 0:c.status)==="failed"?"needs review":null,((f=n==null?void 0:n.execution)==null?void 0:f.status)==="failed"?"data check failed":null].filter(Boolean).map((w,T)=>i.jsxs(O.Fragment,{children:[T>0&&i.jsx("span",{style:{color:u.cellBorder},children:"·"}),i.jsx("span",{children:w})]},`${w}-${T}`))}):i.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[a&&i.jsx(z,{label:C(a),t:u}),s&&i.jsx(z,{label:`${(s.rowCount??s.rows.length).toLocaleString()} rows`,t:u}),((h=n==null?void 0:n.validation)==null?void 0:h.status)&&i.jsx(z,{label:`validation: ${n.validation.status}`,t:u}),((x=n==null?void 0:n.execution)==null?void 0:x.status)&&i.jsx(z,{label:`execution: ${n.execution.status}`,t:u})]}),s&&!d&&i.jsx(yn,{result:s,t:u,compact:d}),o&&!d&&i.jsxs("div",{style:{display:"grid",gap:7,padding:d?"9px 10px":10,border:`1px solid ${u.cellBorder}`,borderRadius:8,background:`${u.tableHeaderBg}45`},children:[o.routeReason&&i.jsx("div",{style:{fontSize:d?12.5:12,lineHeight:1.45,color:u.textSecondary},children:o.routeReason}),(o.grain||((b=o.measures)==null?void 0:b.length)||((S=o.dimensions)==null?void 0:S.length))&&i.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[o.grain&&i.jsx(z,{label:`grain: ${o.grain}`,t:u}),(g=o.measures)==null?void 0:g.slice(0,2).map(w=>i.jsx(z,{label:w,t:u},`measure-${w}`)),(j=o.dimensions)==null?void 0:j.slice(0,2).map(w=>i.jsx(z,{label:w,t:u},`dimension-${w}`))]}),o.candidateJoins&&o.candidateJoins.length>0&&i.jsxs("div",{style:{fontSize:12,color:u.textMuted},children:["Join: ",i.jsx("span",{style:{color:u.textSecondary},children:at(o.candidateJoins[0])})]}),l&&i.jsxs("div",{style:{fontSize:12,color:u.textMuted},children:["Next: ",i.jsx("span",{style:{color:u.textSecondary},children:l})]})]})]})}function ot({text:e,t,compact:r=!1,summaryOnly:n=!1}){const o=n?rt(e):e,s=sn(o,t,r);return i.jsx("div",{style:{display:"flex",flexDirection:"column",gap:r?7:8,color:t.textPrimary,fontFamily:t.font,overflowWrap:"anywhere"},children:s})}function sn(e,t,r){var d;const n=ln(e).split(`
1
+ import{R as O,j as i,aN as We,r as $,u as $t,t as Ct,a as E}from"./index-Ca3UeUWI.js";import{C as ce,b as Ke,T as Ze,a as Bt,f as At}from"./usePersistedAgentThreadId-DbdBi0oH.js";import{T as zt}from"./TrustBadge-DPnKzRSY.js";import{R as Lt,G as Tt}from"./AiBuildResult-B9KmBRsh.js";const Rt={value:"Value",block:"Certified block",term:"Business term",metric:"Metric",dimension:"Dimension",model:"dbt model",source:"Source table",consumer:"Used by"};function Oe(e){const t=(e??"").toLowerCase();return t==="certified"?"success":t==="deprecated"?"neutral":t.includes("review")||t==="draft"||t==="pending"?"warning":"neutral"}function Mt({walk:e,defaultOpen:t=!1,triggerLabel:r}){const[n,o]=O.useState(t),s=Math.min(e.steps.length,2),[a,d]=O.useState(s),u=()=>d(s),l=e.steps.slice(0,a),p=e.steps.length-a;return i.jsxs("div",{style:{border:"1px solid var(--border-subtle, rgba(127,127,127,0.25))",borderRadius:8,background:"var(--bg-1, transparent)",overflow:"hidden"},children:[i.jsxs("button",{type:"button","aria-expanded":n,onClick:()=>{o(c=>!c),n&&u()},style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,border:0,background:"transparent",color:"var(--text-secondary, inherit)",cursor:"pointer",padding:"8px 11px",font:"inherit",fontSize:12,fontWeight:700},children:[i.jsxs("span",{style:{display:"flex",alignItems:"center",gap:7},children:[i.jsx("span",{"aria-hidden":!0,style:{transform:n?"rotate(90deg)":"none",transition:"transform 120ms",display:"inline-block"},children:"▸"}),r??"Why?"]}),i.jsx("span",{style:{fontSize:11,color:"var(--text-tertiary, inherit)",fontWeight:600},children:n?"Hide derivation":"Show how this was derived"})]}),n&&i.jsxs("div",{style:{padding:"2px 11px 11px",display:"flex",flexDirection:"column",gap:10},children:[i.jsx("div",{style:{fontSize:12.5,lineHeight:1.5,color:"var(--text-primary, inherit)"},children:e.summary}),(e.trustLabel||e.freshness)&&i.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"center"},children:[e.trustLabel&&i.jsx(We,{tone:Oe(e.trustLabel),children:Pe(e.trustLabel)}),e.freshness&&i.jsxs("span",{style:{fontSize:11,color:"var(--text-tertiary, inherit)"},children:["Fresh as of ",_t(e.freshness)]})]}),i.jsx("ol",{style:{listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:7},children:l.map((c,f)=>i.jsxs("li",{style:{display:"flex",gap:9,alignItems:"flex-start",paddingLeft:2},children:[i.jsx("span",{"aria-hidden":!0,style:{marginTop:3,width:7,height:7,borderRadius:999,flexShrink:0,background:"var(--accent, currentColor)",opacity:.7}}),i.jsxs("div",{style:{minWidth:0,display:"flex",flexDirection:"column",gap:2},children:[i.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center",flexWrap:"wrap"},children:[i.jsx("span",{style:{fontSize:10,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.04em",color:"var(--text-tertiary, inherit)"},children:Rt[c.kind]}),i.jsx("span",{style:{fontSize:12.5,fontWeight:700,color:"var(--text-primary, inherit)",overflowWrap:"anywhere"},children:c.name}),c.status&&i.jsx(We,{tone:Oe(c.status),children:Pe(c.status)})]}),(c.owner||c.detail)&&i.jsxs("div",{style:{fontSize:11.5,color:"var(--text-secondary, inherit)",lineHeight:1.45},children:[c.owner&&i.jsxs("span",{children:["Owner: ",c.owner,". "]}),c.detail]})]})]},`${c.kind}-${c.name}-${f}`))}),p>0&&i.jsxs("button",{type:"button",onClick:()=>d(c=>Math.min(e.steps.length,c+1)),style:{alignSelf:"flex-start",border:"1px solid var(--border-default, rgba(127,127,127,0.3))",borderRadius:6,background:"transparent",color:"var(--accent, inherit)",cursor:"pointer",padding:"4px 9px",fontSize:11,fontWeight:700},children:["Show next step (",p," more)"]}),e.caveats&&e.caveats.length>0&&i.jsxs("div",{style:{borderLeft:"3px solid var(--status-warning, #d29922)",background:"var(--status-warning-bg, rgba(210,153,34,0.08))",borderRadius:6,padding:"8px 10px",display:"flex",flexDirection:"column",gap:4},children:[i.jsx("span",{style:{fontSize:10,fontWeight:800,textTransform:"uppercase",letterSpacing:"0.04em",color:"var(--status-warning, inherit)"},children:"Caveats"}),e.caveats.map((c,f)=>i.jsx("span",{style:{fontSize:11.5,color:"var(--text-secondary, inherit)",lineHeight:1.45},children:c},f))]})]})]})}function Pe(e){return e.replace(/[_-]+/g," ").replace(/\b\w/g,t=>t.toUpperCase())}function _t(e){const t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleDateString()}const ue=/date|time|day|month|year|week|quarter|period|_at$|^at$/i,fe=/(?:^|_)(?:id|uuid|key|code)$/i,he=/(?:name|title|label|display|description|customer|account|product|region|segment|category|channel)$/i,Dt=new Set(["bar","grouped-bar","stacked-bar","line","area","scatter","pie","donut","heatmap","histogram","funnel","sankey","waterfall","gauge","kpi","table"]);function qe(e){return typeof e=="number"?Number.isFinite(e):typeof e=="string"?e.trim()!==""&&Number.isFinite(Number(e)):!1}function et(e){const t=e.rows.slice(0,20);return t.length===0?[]:e.columns.filter(r=>t.some(n=>qe(n[r]))&&t.every(n=>{const o=n[r];return o==null||o===""||qe(o)}))}function It(e,t){const r=e.columns.filter(n=>!t.includes(n));return r.find(n=>he.test(n)&&!fe.test(n))??r.find(n=>!fe.test(n))??r[0]??e.columns[0]}function Wt(e){return e.columns.filter(t=>{if(!fe.test(t))return!1;const r=t.replace(/(?:_)?(?:id|uuid|key|code)$/i,"").replace(/_+$/,"");return e.columns.some(n=>n!==t&&(r.length>0&&n.toLowerCase().startsWith(r.toLowerCase())&&he.test(n)||r.length===0&&he.test(n)))})}function Ot(e,t){if(t.length===0)return e;const r=new Set(t);return{...e,columns:e.columns.filter(n=>!r.has(n)),rows:e.rows.map(n=>Object.fromEntries(Object.entries(n).filter(([o])=>!r.has(o))))}}function tt(e,t){const r=et(e),n=e.rows.length>0,o=e.columns.filter(g=>!r.includes(g));if(!(n&&r.length>=1))return{config:{...t??{},chart:"table",decisionSource:"data",rationale:"The returned rows do not contain a numeric measure to plot."},chartable:!1,reason:"No numeric measure"};const a=It(e,r),d=t!=null&&t.x&&e.columns.includes(t.x)?t.x:a,u=t!=null&&t.y&&e.columns.includes(t.y)?t.y:r.find(g=>g!==d)??r[0],l=qt(e,r,o,d),p=Pt(t==null?void 0:t.chart),c=t==null?void 0:t.decisionSource,f=c==="authored"||c==="user",h=f&&p||p&&Ft(p,e,r,o,d,u)?p:l.chart,x=!!(p&&p!==h&&!f),b=t!=null&&t.color&&e.columns.includes(t.color)?t.color:h==="sankey"?o.find(g=>g!==d):t==null?void 0:t.color,S=x?`${l.reason}; replaced the agent suggestion because the returned data is not compatible.`:p&&!f?"Agent-selected visualization validated against the returned data.":l.reason;return{config:{...t??{},chart:h,x:d,y:u,...b?{color:b}:{},decisionSource:f?c:p&&!x?"agent":"data",rationale:S},chartable:h!=="table",reason:S}}function Pt(e){if(typeof e!="string")return;const t=e.toLowerCase().replace(/_/g,"-").replace("single-value","kpi");return Dt.has(t)?t:void 0}function qt(e,t,r,n){return e.rows.length===1&&t.length>=1?{chart:"kpi",reason:"Single returned value"}:ue.test(n)&&t.length>=1?{chart:"line",reason:`Time-like field ${n}`}:r.length>0&&t.length>=2?{chart:"grouped-bar",reason:"One category with multiple numeric measures"}:r.length>0&&t.length===1?{chart:"bar",reason:"Categorical comparison with one numeric measure"}:t.length>=2?{chart:"scatter",reason:"Two continuous numeric measures"}:{chart:"table",reason:"No comparable category or time axis was returned"}}function Ft(e,t,r,n,o,s){return e==="table"?!0:e==="kpi"||e==="gauge"?r.length>=1&&t.rows.length===1:e==="line"||e==="area"?r.includes(s)&&ue.test(o):e==="scatter"?r.length>=2:e==="sankey"?n.length>=2&&r.length>=1:e==="histogram"?r.length>=1:e==="grouped-bar"||e==="stacked-bar"?n.length>=1&&r.length>=2:e==="pie"||e==="donut"?n.length>=1&&r.length>=1&&t.rows.length>=2&&t.rows.length<=8:e==="heatmap"?t.columns.length>=3&&r.length>=1:e==="funnel"||e==="waterfall"?n.length>=1&&r.length>=1:e==="bar"?n.length>=1&&r.length>=1&&!ue.test(o):!1}function Qn({result:e,themeMode:t,t:r,chartConfig:n,embedded:o=!1,tabLabels:s}){const a=e.rows.length===0,[d,u]=$.useState(),[l,p]=$.useState(!1),c=$.useMemo(()=>({...n??{},...d??{}}),[n,d]),{config:f,chartable:h}=tt(e,c),x=$.useMemo(()=>et(e),[e]),b=$.useMemo(()=>Wt(e),[e]),S=$.useMemo(()=>l?e:Ot(e,b),[b,e,l]),[g,j]=$.useState("table"),w=m=>({border:"none",background:"transparent",cursor:"pointer",fontFamily:r.font,fontSize:11,fontWeight:700,padding:"2px 4px",color:m?r.accent:r.textMuted,borderBottom:`2px solid ${m?r.accent:"transparent"}`}),T=ce.some(m=>m.value===f.chart)?f.chart:"bar";return i.jsxs("div",{style:{border:o?"none":`1px solid ${r.headerBorder}`,background:r.cellBg,borderRadius:o?0:8,overflow:"hidden"},children:[i.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center",padding:o?"9px 14px":"5px 9px",borderBottom:`1px solid ${r.headerBorder}`},children:[h&&i.jsx("button",{type:"button",onClick:()=>j("table"),style:w(g==="table"),children:(s==null?void 0:s.table)??"Table"}),h&&i.jsx("button",{type:"button",onClick:()=>j("chart"),style:w(g==="chart"),children:(s==null?void 0:s.chart)??"Chart"}),!h&&!a&&i.jsx("span",{style:{fontSize:11,fontWeight:700,color:r.textMuted},children:(s==null?void 0:s.table)??"Table"}),h&&g==="chart"?i.jsx("select",{value:T,onChange:m=>u(A=>({...A??{},chart:m.target.value,decisionSource:"user",rationale:"Selected manually."})),title:"Chart type",style:{fontFamily:r.font,fontSize:10.5,fontWeight:600,color:r.textSecondary,background:r.cellBg,border:`1px solid ${r.headerBorder}`,borderRadius:5,padding:"1px 4px",cursor:"pointer"},children:ce.map(m=>i.jsx("option",{value:m.value,children:m.label},m.value))}):null,h&&g==="chart"?i.jsxs(i.Fragment,{children:[i.jsxs("label",{style:{display:"inline-flex",alignItems:"center",gap:3,color:r.textMuted,fontSize:10.5},children:["X",i.jsx("select",{"aria-label":"X-axis field",value:f.x??"",onChange:m=>u(A=>({...A??{},x:m.target.value,decisionSource:"user",rationale:"Axis selected manually."})),style:{fontFamily:r.font,fontSize:10.5,color:r.textSecondary,background:r.cellBg,border:`1px solid ${r.headerBorder}`,borderRadius:5,padding:"1px 3px",cursor:"pointer",maxWidth:120},children:e.columns.map(m=>i.jsx("option",{value:m,children:m},m))})]}),x.length>0?i.jsxs("label",{style:{display:"inline-flex",alignItems:"center",gap:3,color:r.textMuted,fontSize:10.5},children:["Y",i.jsx("select",{"aria-label":"Y-axis field",value:f.y??"",onChange:m=>u(A=>({...A??{},y:m.target.value,decisionSource:"user",rationale:"Axis selected manually."})),style:{fontFamily:r.font,fontSize:10.5,color:r.textSecondary,background:r.cellBg,border:`1px solid ${r.headerBorder}`,borderRadius:5,padding:"1px 3px",cursor:"pointer",maxWidth:120},children:x.map(m=>i.jsx("option",{value:m,children:m},m))})]}):null,f.chart==="sankey"?i.jsxs("label",{style:{display:"inline-flex",alignItems:"center",gap:3,color:r.textMuted,fontSize:10.5},children:["Target",i.jsx("select",{"aria-label":"Sankey target field",value:f.color??"",onChange:m=>u(A=>({...A??{},color:m.target.value,decisionSource:"user",rationale:"Sankey target selected manually."})),style:{fontFamily:r.font,fontSize:10.5,color:r.textSecondary,background:r.cellBg,border:`1px solid ${r.headerBorder}`,borderRadius:5,padding:"1px 3px",cursor:"pointer",maxWidth:120},children:e.columns.filter(m=>!x.includes(m)&&m!==f.x).map(m=>i.jsx("option",{value:m,children:m},m))})]}):null]}):null,h&&g==="chart"&&f.rationale?i.jsxs("span",{title:f.rationale,style:{fontSize:10.5,color:r.textMuted,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:230},children:["Smart chart · ",f.chart]}):null,i.jsxs("span",{style:{marginLeft:"auto",fontSize:10.5,color:r.textMuted,alignSelf:"center"},children:[e.rowCount??e.rows.length," rows"]})]}),i.jsx("div",{style:{padding:o?12:8,minHeight:h&&g==="chart"?200:void 0,maxHeight:o?380:320,overflow:"auto"},children:a?i.jsxs("div",{style:{padding:"18px 8px",textAlign:"center",color:r.textMuted,fontSize:12},children:["The query ran successfully and matched 0 rows",e.columns.length>0?` (columns: ${e.columns.join(", ")})`:"","."]}):h&&g==="chart"?i.jsx(Ke,{result:e,themeMode:t,chartConfig:f,onConfigChange:m=>u(A=>({...A??{},...m,decisionSource:"user",rationale:"Adjusted manually."}))}):i.jsxs(i.Fragment,{children:[b.length>0?i.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:6},children:i.jsx("button",{type:"button",onClick:()=>p(m=>!m),style:{border:"none",background:"transparent",color:r.accent,cursor:"pointer",fontSize:10.5,padding:0},children:l?"Hide technical fields":"Show IDs"})}):null,i.jsx(Ze,{result:S,themeMode:t})]})})]})}const Et=3;function Qt(e){const{business360:t,block:r,value:n,generated:o=!1}=e,s=e.maxPerKind??Et,a=t.focus,d=[];n&&d.push({kind:"value",name:n,detail:a.name?`Reported by ${a.name}.`:void 0});const u=(r==null?void 0:r.owner)??a.owner,l=(r==null?void 0:r.status)??a.status,p=(r==null?void 0:r.reviewCadence)??oe(a.metadata,"reviewCadence");d.push({kind:"block",name:a.name,owner:u,status:l,detail:Nt({reviewCadence:p,businessOutcome:(r==null?void 0:r.businessOutcome)??oe(a.metadata,"businessOutcome"),decisionUse:r==null?void 0:r.decisionUse})});const c=Fe([...t.businessDefinition.terms,...t.businessDefinition.definedByTerms]);for(const x of c.slice(0,s))x.id!==a.id&&d.push({kind:"term",name:x.name,owner:x.owner,detail:"Business term this answer is defined in."});for(const x of se(r==null?void 0:r.metricRefs).slice(0,s))d.push({kind:"metric",name:x,detail:"Governed metric used in the calculation."});for(const x of se(r==null?void 0:r.dimensionRefs).slice(0,s))d.push({kind:"dimension",name:x,detail:"Dimension used to slice the value."});for(const x of t.technicalSources.dbtModels.slice(0,s))d.push({kind:"model",name:x.name,detail:"dbt model the certified SQL builds on."});const f=Fe([...t.technicalSources.dbtSources,...t.technicalSources.sourceTables]);for(const x of f.slice(0,s))d.push({kind:"source",name:x.name,detail:"Raw source table the data originates from."});const h=se((r==null?void 0:r.caveats)??Vt(a.metadata,"caveats"));return{value:n,summary:Ut({focus:a,blockOwner:u,reviewCadence:p,generated:o,sourceAssets:f}),steps:d,trustLabel:e.trustLabel??(o?"review_required":void 0),freshness:e.freshness??Ht(r==null?void 0:r.dataState,r==null?void 0:r.dataStateDetail)??oe(a.metadata,"freshness"),caveats:h.length>0?h:void 0}}function Ht(e,t){switch(e){case"failed":return t?`upstream failed — ${t}`:"upstream failed";case"stale":return t?`stale data — ${t}`:"stale data";default:return}}function Nt(e){const t=[];return e.businessOutcome?t.push(e.businessOutcome):e.decisionUse&&t.push(`Supports: ${e.decisionUse}.`),e.reviewCadence&&t.push(`Reviewed ${e.reviewCadence}.`),t.length>0?t.join(" "):void 0}function Ut(e){const t=e.blockOwner?` owned by ${e.blockOwner}`:"",r=e.sourceAssets.length>0?` It traces back to ${e.sourceAssets[0].name}.`:"";if(e.generated)return`This value was generated from ${e.focus.name}${t} and still needs analyst review before it can be certified.${r}`;const n=e.reviewCadence?`, reviewed ${e.reviewCadence}`:"";return`This value comes from the certified ${e.focus.name}${t}${n}.${r}`}function oe(e,t){const r=e==null?void 0:e[t];return typeof r=="string"&&r.trim().length>0?r:void 0}function Vt(e,t){const r=e==null?void 0:e[t];return Array.isArray(r)?r.filter(n=>typeof n=="string"&&n.trim().length>0):[]}function se(e){if(!e)return[];const t=new Set,r=[];for(const n of e){const o=typeof n=="string"?n.trim():"";!o||t.has(o.toLowerCase())||(t.add(o.toLowerCase()),r.push(o))}return r}function Fe(e){const t=new Set,r=[];for(const n of e)t.has(n.id)||(t.add(n.id),r.push(n));return r}function nt(e){var n,o;const t=e.dqlArtifact,r=(n=t==null?void 0:t.source)==null?void 0:n.trim();return r?{source:r,kind:t==null?void 0:t.kind,name:t==null?void 0:t.name,sourcePath:t==null?void 0:t.sourcePath,metrics:le(t==null?void 0:t.metrics),dimensions:le(t==null?void 0:t.dimensions),filters:((t==null?void 0:t.filters)??[]).map(s=>{var l,p;const a=(l=s.dimension)==null?void 0:l.trim(),d=((p=s.operator)==null?void 0:p.trim())||"equals",u=le(s.values);return!a||u.length===0?"":`${a} ${d} ${u.join(", ")}`}).filter(Boolean),timeDimension:(o=t==null?void 0:t.timeDimension)!=null&&o.name?[t.timeDimension.name,t.timeDimension.granularity].filter(Boolean).join(" / "):void 0,orderBy:((t==null?void 0:t.orderBy)??[]).map(s=>{var u,l;const a=(u=s.name)==null?void 0:u.trim(),d=(l=s.direction)==null?void 0:l.trim();return a&&d?`${a} ${d}`:""}).filter(Boolean),limit:typeof(t==null?void 0:t.limit)=="number"&&Number.isFinite(t.limit)?t.limit:void 0}:null}function Jt(e){for(let t=e.length-1;t>=0;t--){const r=e[t];if(r.kind!=="tool_result"||r.id!=="governed_answer")continue;const n=r.output;if(n&&typeof n=="object"&&"kind"in n)return n}return null}function le(e){return Array.isArray(e)?e.map(t=>typeof t=="string"?t.trim():"").filter(Boolean):[]}function Gt(e){const t=e.result;if(!t||!Array.isArray(t.rows))return null;const n=(Array.isArray(t.columns)?t.columns:[]).map(s=>typeof s=="string"?s:s&&typeof s=="object"&&typeof s.name=="string"?String(s.name):String(s)),o=t.rows.filter(s=>!!(s&&typeof s=="object"&&!Array.isArray(s))).map(s=>s);return{columns:n,rows:o,rowCount:typeof t.rowCount=="number"?t.rowCount:o.length,executionTime:t.executionTime}}function Xt(e,t){const r=e&&typeof e=="object"?e:{},n=typeof r.chart=="string"?r.chart:void 0,o=r.decisionSource==="authored"||r.decisionSource==="agent"||r.decisionSource==="data"||r.decisionSource==="user"?r.decisionSource:void 0,s=n||(typeof t.suggestedViz=="string"?t.suggestedViz:void 0),a=s?s.toLowerCase().replace(/_/g,"-")==="single-value"?"kpi":s:void 0;return{...a?{chart:a}:{},...a?{decisionSource:o??(n?"authored":"agent")}:{},...typeof r.rationale=="string"?{rationale:r.rationale}:{},...typeof r.x=="string"?{x:r.x}:{},...typeof r.y=="string"?{y:r.y}:{},...typeof r.color=="string"?{color:r.color}:{},...typeof r.title=="string"?{title:r.title}:{}}}function Yt(e,t){return!t||t.columns.length===0?e:tt(t,e).config}function ae(e){if(typeof e!="string")return;const t=e.replace(/\s+/g," ").trim();if(t)return t.length>180?`${t.slice(0,177)}...`:t}function rt(e){const t=Kt(e,["Answer","Business summary","Summary"]);if(t)return Ee(t,340);const r=/^(?:reuse evidence|certified result preview|result preview|result summary|trust status|next action|recommended action|sql used by block|reusable block sql|proposed sql|sql generated|sql draft|evidence|parameters|lineage|technical lineage)\s*:/i,n=/^(?:SELECT|WITH|FROM|WHERE|GROUP BY|ORDER BY|LIMIT)\b/i,o=[];for(const a of e.split(/\r?\n/)){const d=a.trim();if(!(!d||/^#{1,6}\s*/.test(d)||/^```/.test(d)||/^\|/.test(d))&&!/^outcome\s*:/i.test(d)){if(r.test(d)||n.test(d)){if(o.length>0)break;continue}if(o.push(d),o.length>=5)break}}const s=o.join(" ").replace(/[*_`]+/g,"").replace(/\s+/g," ").trim();return Ee(s,340)}function Kt(e,t){var p,c,f;const r=e.split(/\r?\n/),n=t.map(h=>h.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|"),o=new RegExp(`^\\s*(?:#{1,6}\\s*)?(?:[-*]\\s*)?(?:\\*\\*)?(${n})(?:\\*\\*)?\\s*:\\s*(.*)$`,"i"),s=/^\s*(?:#{1,6}\s*)?(?:[-*]\s*)?(?:\*\*)?[A-Z][A-Za-z /-]{2,42}(?:\*\*)?\s*:/,a=r.findIndex(h=>o.test(h));if(a<0)return;const d=((f=(c=(p=r[a])==null?void 0:p.match(o))==null?void 0:c[2])==null?void 0:f.trim())??"",u=d?[d]:[];for(let h=a+1;h<r.length;h+=1){const x=r[h]??"";if(s.test(x)||/^\s*```/.test(x))break;x.trim()&&u.push(x.trim())}return u.join(" ").replace(/[*_`]+/g,"").replace(/\s+/g," ").trim()||void 0}function Ee(e,t){const r=e.replace(/\s+/g," ").trim();if(r.length<=t)return r;const n=r.slice(0,t-1),o=Math.max(n.lastIndexOf(". "),n.lastIndexOf("; "));if(o>100)return n.slice(0,o+1).trim();const s=n.lastIndexOf(" ");return`${n.slice(0,s>80?s:n.length).trim()}...`}function Zt({answer:e,themeMode:t,showSql:r=!0,compact:n=!1,addToAppTarget:o,sourceQuestion:s,onInvestigate:a,onInsertSql:d,onCreateBlock:u}){var we,ke,$e,Ce,Be,Ae,ze,Le,Te,Re,Me,_e,De;const l=Ct[t],{dispatch:p}=$t(),c=Gt(e),f=Xt((we=e.result)==null?void 0:we.chartConfig,e),[h,x]=$.useState(),b=Yt({...f??{},...h??{}},c),S=!!(c&&Bt(c,b)!=="table"),g=e.analysisPlan??((ke=e.evidence)==null?void 0:ke.analysisPlan),j=r?e.sql??(($e=e.result)==null?void 0:$e.sql)??e.proposedSql??(g==null?void 0:g.sql):void 0,w=nt(e),T=e.executionError??(((Be=(Ce=e.evidence)==null?void 0:Ce.execution)==null?void 0:Be.status)==="failed"?e.evidence.execution.message:void 0),m=((Ae=e.result)==null?void 0:Ae.blockPath)??((ze=e.block)==null?void 0:ze.sourcePath),A=!!(j||T||r&&m),ee=!!e.evidence,[U,pe]=$.useState("answer"),[ct,xe]=$.useState(!1),[ge,ut]=$.useState(!1),me=dt(e),ye=zn(me,l),be=(e.answer??e.text??"").replace(/\n\n_Question:_[\s\S]*$/m,"").trim(),M=n?rt(be):be,k=((Le=e.result)==null?void 0:Le.blockName)??((Te=e.block)==null?void 0:Te.name)??((Me=(Re=e.citations)==null?void 0:Re.find(y=>y.kind==="block"))==null?void 0:Me.name),te=Mn(e,k),ft=Ln(e,c,k,m),[ht,ve]=$.useState(!1),[V,J]=$.useState(null),[je,pt]=$.useState(null),xt=!!(o&&(c||j||M||k)),gt=!!(d&&j),mt=!!(u&&j),P=ae(g==null?void 0:g.question)??ae(s)??ae(M)??"Investigate this answer",yt=!!(a&&P),bt=it(e,{sql:j,executionError:T,blockName:k,result:c}),vt=()=>{!d||!j||(d(j,k??(g==null?void 0:g.question)??"AI SQL preview",{question:s??(g==null?void 0:g.question)}),pt("Inserted SQL preview cell for review."))},jt=()=>{!u||!j||u(j,{title:(w==null?void 0:w.name)??k??(g==null?void 0:g.question)??"AI DQL draft",description:M||(g==null?void 0:g.routeReason)||"AI generated DQL draft.",tags:["ai-generated","review-required"]})},St=async(y="auto")=>{if(!o)return;const W=y==="both"?["chart","data"]:y==="data"?["data"]:y==="chart"?["chart"]:c?[S?"chart":"data"]:[];ve(!0),xe(!1),J(null);try{if(e.certification==="certified"&&k){const B=await E.getDashboard(o.appId,o.dashboardId);if(!B)throw new Error("Dashboard could not be loaded.");const _=[...B.dashboard.layout.items],R=W.length>0?W:["chart"];for(const F of R){const X=R.length>1?`${k}_${F}`:k,Ie={...B.dashboard,layout:{...B.dashboard.layout,items:_}},kt=In(Ie,X);_.push({i:kt,...Dn(Ie),block:{blockId:k},viz:{type:F==="data"?"table":Wn(b==null?void 0:b.chart)},title:R.length>1?`${k} ${F==="data"?"data":"chart"}`:k})}const q={...B.dashboard.layout,items:_},L=await E.patchDashboardLayout(o.appId,o.dashboardId,q);if(!L.ok)throw new Error(L.error);J(R.length>1?"Added certified chart and data tiles.":"Added certified block tile.")}else{const B=!!(j&&window.confirm("Keep this AI result refreshed daily?")),_=k??(M.slice(0,60)||"AI result"),R=W.length>0?W:["data"];let q=c??void 0;if(!q&&j){const L=await E.previewGeneratedSql(j);if(!L.ok)throw new Error(`SQL preview failed: ${L.error}`);q=L.result}for(const L of R){const F=L==="data"?{...b??{},chart:"table",title:`${_} data`}:b,X=await E.createAiPin(o.appId,{dashboardId:o.dashboardId,title:R.length>1?`${_} ${L==="data"?"data":"chart"}`:_,answer:M||e.answer||e.text||"AI generated answer",question:g==null?void 0:g.question,sql:j,sourceTier:e.sourceTier,certification:e.certification==="certified"?"certified":"ai_generated",reviewStatus:"needs_review",refreshCadence:B?"daily":"none",chartConfig:F,result:q,citations:e.citations,analysisPlan:g,evidence:e.evidence,followUps:g==null?void 0:g.followUps});if(!X.ok)throw new Error(X.error)}J(R.length>1?"Pinned chart and data tiles for review.":"Pinned AI result for review.")}window.dispatchEvent(new CustomEvent("dql-app-dashboard-updated",{detail:o}))}catch(B){J(B instanceof Error?B.message:String(B))}finally{ve(!1)}},wt=()=>{!a||!P||a({question:P,title:te?`${te}: ${P}`:P,answerSummary:M,blockName:te,sql:j,evidence:e.evidence})},ne=[{id:"answer",label:n?"Summary":"Answer",visible:!0},{id:"dql",label:"DQL",visible:!!w},{id:"visual",label:n?"Chart":"Visualization",visible:S},{id:"data",label:"Data",visible:!!c},{id:"sql",label:"SQL / Block",visible:r&&A},{id:"lineage",label:n?"Trace":"Lineage",visible:ee},{id:"context",label:n?"Context":"Business Context",visible:ee},{id:"review",label:n?"Trust":"Review",visible:ee||!!((_e=e.citations)!=null&&_e.length)}].filter(y=>y.visible),Se=ne.some(y=>y.id===U)?U:"answer",G=ne.filter(y=>y.id!=="answer"),re=G.some(y=>y.id===U)?U:(De=G[0])==null?void 0:De.id,ie=y=>y==="answer"?i.jsx(on,{summary:M,answer:e,blockName:k,evidence:e.evidence,analysisPlan:g,result:c,sourceTier:e.sourceTier,compact:n,t:l}):y==="dql"&&w?i.jsx(Sn,{artifact:w,t:l}):y==="visual"&&c&&S?i.jsxs("div",{style:{padding:n?"8px 10px":"10px 12px",minHeight:n?180:220,display:"grid",gap:10},children:[i.jsx($n,{result:c,chartConfig:b,t:l,onChange:W=>x(B=>({...B??{},...W,decisionSource:"user",rationale:"Adjusted manually."}))}),i.jsx(Ke,{result:c,themeMode:t,chartConfig:b})]}):y==="data"&&c?i.jsx("div",{style:{maxHeight:n?320:420,overflow:"auto"},children:i.jsx(Ze,{result:c,themeMode:t})}):y==="lineage"?i.jsx(bn,{evidence:e.evidence,t:l}):y==="context"?i.jsx(vn,{evidence:e.evidence,t:l}):y==="sql"&&r&&A?i.jsx(wn,{sql:j,blockPath:m,executionError:T,t:l}):y==="review"?i.jsx(jn,{answer:e,t:l}):null;return i.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:n?8:10,whiteSpace:"normal"},children:[i.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center",flexWrap:"wrap"},children:[i.jsx(zt,{state:me}),i.jsx(Lt,{t:l,route:e.route}),I(e.cascade)&&i.jsx("span",{style:{border:`1px solid ${l.cellBorder}`,borderRadius:999,padding:"3px 8px",fontSize:11,fontWeight:700,color:l.textSecondary,background:l.tableHeaderBg},children:I(e.cascade)}),!n&&k&&i.jsxs("span",{style:{fontSize:12,fontFamily:l.fontMono,color:l.textSecondary},children:["block: ",k]}),c&&i.jsxs("span",{style:{fontSize:12,color:l.textMuted},children:[(c.rowCount??c.rows.length).toLocaleString()," rows",c.executionTime!==void 0&&i.jsxs(i.Fragment,{children:[" - ",Math.round(c.executionTime),"ms"]})]}),xt&&i.jsx(Cn,{t:l,adding:ht,hasResult:!!c,hasChart:S,fallbackLabel:e.certification==="certified"&&k?n?"Add":"Add block":"Pin answer",open:ct,onToggle:()=>xe(y=>!y),onAdd:y=>void St(y)}),yt&&i.jsx("button",{type:"button",onClick:wt,style:{border:`1px solid ${l.accent}`,borderRadius:6,background:`${l.accent}12`,color:l.accent,cursor:"pointer",padding:n?"4px 8px":"5px 10px",fontSize:11,fontFamily:l.font,fontWeight:800},children:n?"Investigate":"Investigate deeper"}),mt&&i.jsx("button",{type:"button",onClick:jt,style:{border:`1px solid ${l.accent}`,borderRadius:6,background:l.cellBg,color:l.accent,cursor:"pointer",padding:n?"4px 8px":"5px 10px",fontSize:11,fontFamily:l.font,fontWeight:700},children:n?"DQL draft":w?"Review DQL draft":"Create DQL draft"}),gt&&i.jsx("button",{type:"button",onClick:vt,style:{border:`1px solid ${l.accent}`,borderRadius:6,background:`${l.accent}18`,color:l.accent,cursor:"pointer",padding:n?"4px 8px":"5px 10px",fontSize:11,fontFamily:l.font,fontWeight:700},children:n?"SQL preview":"Insert SQL preview"})]}),V&&i.jsx("div",{style:{fontSize:11,color:V.toLowerCase().includes("added")||V.toLowerCase().includes("pinned")?"#3fb950":"#ff7b72"},children:V}),je&&i.jsx("div",{style:{fontSize:11,color:"#3fb950"},children:je}),i.jsx(en,{outcome:bt,t:l,compact:n}),i.jsxs("div",{style:{border:`1px solid ${l.cellBorder}`,borderTop:`2px solid ${ye}`,borderRadius:n?10:6,overflow:"hidden",background:l.cellBg},children:[!n&&i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:14,padding:"4px 10px",borderBottom:`1px solid ${l.cellBorder}`,background:`${l.tableHeaderBg}70`,flexWrap:"wrap"},children:[ne.map(y=>i.jsx(Xe,{active:Se===y.id,label:y.label,onClick:()=>pe(y.id),t:l},y.id)),!r&&m&&i.jsx("span",{style:{marginLeft:"auto",minWidth:0,fontSize:11,fontFamily:l.fontMono,color:l.textMuted,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:m})]}),ie(n?"answer":Se),n&&G.length>0&&i.jsxs("div",{style:{borderTop:`1px solid ${l.cellBorder}`,background:`${l.tableHeaderBg}45`},children:[i.jsxs("button",{type:"button",onClick:()=>ut(y=>!y),style:{width:"100%",border:0,background:"transparent",color:l.textSecondary,padding:"8px 12px",display:"flex",justifyContent:"space-between",alignItems:"center",cursor:"pointer",fontSize:11,fontWeight:800},children:[i.jsx("span",{children:"Details"}),i.jsx("span",{style:{color:l.textMuted,fontFamily:l.fontMono},children:ge?"hide":"show evidence"})]}),ge&&i.jsxs("div",{style:{borderTop:`1px solid ${l.cellBorder}`},children:[i.jsx("div",{style:{display:"flex",alignItems:"center",gap:14,padding:"4px 12px",flexWrap:"wrap"},children:G.map(y=>i.jsx(Xe,{active:re===y.id,label:y.label,onClick:()=>pe(y.id),t:l},y.id))}),re?ie(re):null]})]}),i.jsx(kn,{items:ft,t:l,accent:ye}),i.jsx(Tt,{t:l,skills:e.appliedSkills,onOpenSkills:()=>p({type:"SET_MAIN_VIEW",view:"skills"})})]})]})}function it(e,t){var r,n,o,s,a;if(e.kind==="no_answer")return{kind:"cannot_answer",label:"Cannot answer yet",detail:"The assistant did not find enough trusted context to safely answer or generate SQL.",nextAction:"Clarify the business object, metric, grain, or source table.",tone:"error"};if(e.certification==="certified"||e.kind==="certified"){const d=t.blockName??e.sourceCertifiedBlock??((r=e.block)==null?void 0:r.name);return{kind:"reuse_certified_block",label:"Reuse certified block",detail:d?`Existing DQL block ${d} answers this request.`:"A certified DQL artifact answers this request.",nextAction:"Use the certified block instead of creating duplicate SQL.",tone:"success"}}return t.executionError||e.executionError?{kind:"fix_sql",label:"Fix SQL",detail:"The generated or selected SQL needs correction before it can become reusable DQL.",nextAction:"Ask AI to repair, edit manually, then rerun preview.",tone:"error"}:(n=e.draftBlock)!=null&&n.path||e.draftBlockId?{kind:"use_existing_draft",label:"Use existing draft",detail:`A review-required DQL draft is available at ${((o=e.draftBlock)==null?void 0:o.path)??e.draftBlockId}.`,nextAction:"Open the draft, review metadata/tests/lineage, then certify manually.",tone:"accent"}:(a=(s=e.dqlArtifact)==null?void 0:s.source)!=null&&a.trim()?{kind:"create_dql_draft",label:"Review DQL draft",detail:"A review-required DQL artifact is available for analyst review.",nextAction:"Review DQL metadata, query logic, lineage, and result preview before certification.",tone:"warning"}:t.sql?{kind:t.result?"generate_sql_cell":"create_dql_draft",label:t.result?"Review SQL preview":"Create DQL draft",detail:t.result?`Review-required SQL preview returned ${(t.result.rowCount??t.result.rows.length).toLocaleString()} row${(t.result.rowCount??t.result.rows.length)===1?"":"s"}.`:"Review-required SQL is available but still needs preview and DQL metadata review.",nextAction:t.result?"Create a DQL draft after reviewing parameters and lineage; insert SQL only as a notebook preview.":"Run preview, inspect parameters, then create a draft block.",tone:"warning"}:{kind:"needs_review",label:"Needs review",detail:"The assistant returned business context but no executable certified answer or SQL draft.",nextAction:"Review evidence and ask for a specific SQL, reuse, or DQL draft action.",tone:"muted"}}function en({outcome:e,t,compact:r}){const n=tn(e.tone,t);return i.jsxs("div",{style:{border:`1px solid ${n}45`,borderLeft:`3px solid ${n}`,borderRadius:r?10:7,background:`${n}10`,padding:r?"9px 10px":"10px 12px",display:"grid",gap:r?4:5},children:[i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,minWidth:0},children:[i.jsx("span",{style:{border:`1px solid ${n}55`,background:`${n}14`,color:n,borderRadius:999,padding:"2px 7px",fontSize:10,fontWeight:850,lineHeight:1.1,textTransform:"uppercase",letterSpacing:0,flexShrink:0},children:e.label}),i.jsx("span",{style:{fontSize:r?12:12.5,color:t.textPrimary,fontWeight:750,overflow:"hidden",textOverflow:"ellipsis"},children:e.detail})]}),i.jsxs("div",{style:{fontSize:r?11.5:12,color:t.textSecondary,lineHeight:1.45},children:["Next: ",e.nextAction]})]})}function tn(e,t){switch(e){case"success":return t.success;case"accent":return t.accent;case"warning":return t.warning;case"error":return t.error;case"muted":default:return t.textMuted}}function nn({answer:e,blockName:t}){const[r,n]=$.useState(null),[o,s]=$.useState(!1),[a,d]=$.useState(!1),u=O.useCallback(async()=>{var l,p;if(!a){d(!0),s(!0);try{const c=await E.fetchBusiness360(t);if(!c){n(null);return}const f=(l=e.evidence)==null?void 0:l.outcome,h=Qe(e,"metric"),x=Qe(e,"dimension"),b=e.certification!=="certified"&&e.kind!=="certified",S=Qt({business360:c,block:{name:t,owner:f==null?void 0:f.owner,status:((p=e.block)==null?void 0:p.status)??e.certification,reviewCadence:f==null?void 0:f.reviewCadence,caveats:f==null?void 0:f.caveats,decisionUse:f==null?void 0:f.decisionUse,metricRefs:h,dimensionRefs:x},value:rn(e),generated:b,trustLabel:e.trustLabel});n(S)}catch{n(null)}finally{s(!1)}}},[e,t,a]);return a?o?i.jsx("div",{style:{fontSize:11.5,color:"var(--text-tertiary, inherit)"},children:"Assembling derivation…"}):r?i.jsx(Mt,{walk:r,defaultOpen:!0}):null:i.jsx("button",{type:"button",onClick:()=>void u(),"aria-expanded":!1,style:{alignSelf:"flex-start",border:0,background:"transparent",color:"var(--accent, inherit)",cursor:"pointer",padding:"4px 0",fontSize:12,fontWeight:700,textDecoration:"underline",textUnderlineOffset:3},children:"Why? Show how this was derived"})}function Qe(e,t){var o,s;const r=(((o=e.evidence)==null?void 0:o.semanticObjects)??[]).filter(a=>a.kind===t).map(a=>a.name).filter(a=>!!a);if(r.length>0)return r;const n=e.analysisPlan??((s=e.evidence)==null?void 0:s.analysisPlan);return(t==="metric"?n==null?void 0:n.measures:n==null?void 0:n.dimensions)??[]}function rn(e){const t=e.result;if(t&&Array.isArray(t.rows)&&t.rows.length===1){const r=t.rows[0];if(r&&typeof r=="object"&&!Array.isArray(r)){const n=Object.values(r);if(n.length===1&&(typeof n[0]=="number"||typeof n[0]=="string"))return String(n[0])}}}function on({summary:e,answer:t,blockName:r,evidence:n,analysisPlan:o,result:s,sourceTier:a,compact:d,t:u}){var p,c,f,h,x,b,S,g,j;const l=(p=o==null?void 0:o.followUps)==null?void 0:p[0];return i.jsxs("div",{style:{padding:d?14:12,display:"flex",flexDirection:"column",gap:d?10:12},children:[e?i.jsx(ot,{text:e,t:u,compact:d,summaryOnly:d}):i.jsx("div",{style:{fontSize:12,color:u.textMuted},children:"No summary text was returned."}),t&&r&&i.jsx(nn,{answer:t,blockName:r}),d?i.jsx("div",{style:{fontSize:11.5,color:u.textMuted,display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},children:[a?An(a):null,s?`${(s.rowCount??s.rows.length).toLocaleString()} rows`:null,((c=n==null?void 0:n.validation)==null?void 0:c.status)==="failed"?"needs review":null,((f=n==null?void 0:n.execution)==null?void 0:f.status)==="failed"?"data check failed":null].filter(Boolean).map((w,T)=>i.jsxs(O.Fragment,{children:[T>0&&i.jsx("span",{style:{color:u.cellBorder},children:"·"}),i.jsx("span",{children:w})]},`${w}-${T}`))}):i.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[a&&i.jsx(z,{label:C(a),t:u}),s&&i.jsx(z,{label:`${(s.rowCount??s.rows.length).toLocaleString()} rows`,t:u}),((h=n==null?void 0:n.validation)==null?void 0:h.status)&&i.jsx(z,{label:`validation: ${n.validation.status}`,t:u}),((x=n==null?void 0:n.execution)==null?void 0:x.status)&&i.jsx(z,{label:`execution: ${n.execution.status}`,t:u})]}),s&&!d&&i.jsx(yn,{result:s,t:u,compact:d}),o&&!d&&i.jsxs("div",{style:{display:"grid",gap:7,padding:d?"9px 10px":10,border:`1px solid ${u.cellBorder}`,borderRadius:8,background:`${u.tableHeaderBg}45`},children:[o.routeReason&&i.jsx("div",{style:{fontSize:d?12.5:12,lineHeight:1.45,color:u.textSecondary},children:o.routeReason}),(o.grain||((b=o.measures)==null?void 0:b.length)||((S=o.dimensions)==null?void 0:S.length))&&i.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[o.grain&&i.jsx(z,{label:`grain: ${o.grain}`,t:u}),(g=o.measures)==null?void 0:g.slice(0,2).map(w=>i.jsx(z,{label:w,t:u},`measure-${w}`)),(j=o.dimensions)==null?void 0:j.slice(0,2).map(w=>i.jsx(z,{label:w,t:u},`dimension-${w}`))]}),o.candidateJoins&&o.candidateJoins.length>0&&i.jsxs("div",{style:{fontSize:12,color:u.textMuted},children:["Join: ",i.jsx("span",{style:{color:u.textSecondary},children:at(o.candidateJoins[0])})]}),l&&i.jsxs("div",{style:{fontSize:12,color:u.textMuted},children:["Next: ",i.jsx("span",{style:{color:u.textSecondary},children:l})]})]})]})}function ot({text:e,t,compact:r=!1,summaryOnly:n=!1}){const o=n?rt(e):e,s=sn(o,t,r);return i.jsx("div",{style:{display:"flex",flexDirection:"column",gap:r?7:8,color:t.textPrimary,fontFamily:t.font,overflowWrap:"anywhere"},children:s})}function sn(e,t,r){var d;const n=ln(e).split(`
2
2
  `),o=[];let s=0,a=0;for(;s<n.length;){const l=n[s].trim();if(!l){s+=1;continue}if(l.startsWith("```")){const h=l.replace(/^```/,"").trim(),x=[];for(s+=1;s<n.length&&!n[s].trim().startsWith("```");)x.push(n[s]),s+=1;s<n.length&&(s+=1),o.push(i.jsx("pre",{style:mn(t,r),"aria-label":h?`${h} code`:"code",children:x.join(`
3
3
  `)},`code-${a++}`));continue}const p=l.match(/^(#{1,4})\s+(.+)$/);if(p){const h=p[1].length;o.push(i.jsx("div",{style:hn(t,r,h),children:D(p[2],t)},`heading-${a++}`)),s+=1;continue}if(/^[-*_]{3,}$/.test(l)){o.push(i.jsx("hr",{style:{width:"100%",border:0,borderTop:`1px solid ${t.cellBorder}`,margin:r?"2px 0":"4px 0"}},`hr-${a++}`)),s+=1;continue}if(an(n,s)){const h=[];for(;s<n.length&&Z(n[s].trim());)h.push(n[s].trim()),s+=1;o.push(i.jsx(cn,{lines:h,t,compact:r},`table-${a++}`));continue}if(l.startsWith(">")){const h=[];for(;s<n.length&&n[s].trim().startsWith(">");)h.push(n[s].trim().replace(/^>\s?/,"")),s+=1;o.push(i.jsx("div",{style:Ne(t,r),children:D(h.join(" "),t)},`quote-${a++}`));continue}if(/^[-*+]\s+/.test(l)){const h=[];for(;s<n.length&&/^[-*+]\s+/.test(n[s].trim());)h.push(n[s].trim().replace(/^[-*+]\s+/,"")),s+=1;o.push(i.jsx("ul",{style:Ue(t,r),children:h.map((x,b)=>i.jsx("li",{style:Ve(t,r),children:D(x,t)},`${x}-${b}`))},`ul-${a++}`));continue}if(/^\d+\.\s+/.test(l)){const h=[];for(;s<n.length&&/^\d+\.\s+/.test(n[s].trim());)h.push(n[s].trim().replace(/^\d+\.\s+/,"")),s+=1;o.push(i.jsx("ol",{style:Ue(t,r),children:h.map((x,b)=>i.jsx("li",{style:Ve(t,r),children:D(x,t)},`${x}-${b}`))},`ol-${a++}`));continue}const c=[];for(;s<n.length;){const h=n[s].trim();if(!h||He(h)&&c.length>0||(c.push(h),s+=1,He(((d=n[s])==null?void 0:d.trim())??"")))break}const f=c.join(" ");o.push(i.jsx("div",{style:o.length===0&&un(f)?Ne(t,r):fn(t,r),children:D(f,t)},`p-${a++}`))}return o}function ln(e){return e.replace(/\r\n/g,`
4
4
  `).replace(/\|\s+\|(?=[^\n]*\|)/g,`|
@@ -1 +1 @@
1
- import{u as x,t as m,j as n,G as y,aA as j,r as b,e as k}from"./index-CcZ8Dw84.js";import{A as S}from"./arrow-left-CwMW-Dnz.js";import{W as M}from"./wrench-CgXGBYJ-.js";import{C as v}from"./circle-x-C5hi2hCq.js";import"./react-CRB3T2We.js";function H(){const{state:e,dispatch:t}=x(),r=m[e.themeMode],s=e.agentLogRun;return s?n.jsxs("div",{style:{padding:"20px 28px",fontFamily:r.font,color:r.textPrimary,maxWidth:900,margin:"0 auto"},children:[n.jsxs("button",{type:"button",onClick:()=>t({type:"SET_MAIN_VIEW",view:"ask"}),style:D(r),children:[n.jsx(S,{size:14})," Back to Ask AI"]}),n.jsx(w,{run:s,t:r}),n.jsx(z,{run:s,t:r}),u(s).reason&&n.jsx(W,{run:s,t:r}),s.evaluations.length>0&&n.jsx(I,{run:s,t:r})]}):n.jsx("div",{style:{padding:32,color:r.textMuted,fontFamily:r.font},children:"No agent run selected. Open one from the “View steps” link on an AI answer."})}function w({run:e,t}){const r=f(e.startedAt,e.completedAt);return n.jsxs("div",{style:{marginBottom:20},children:[n.jsx("div",{style:{fontSize:18,fontWeight:600,marginBottom:8,lineHeight:1.35},children:e.question}),n.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap",alignItems:"center"},children:[n.jsxs("span",{style:c(t),children:[n.jsx(y,{size:12})," ",p(e.route)]}),n.jsx("span",{style:N(t,e.trustState),children:C(e.trustState)}),r!=null&&n.jsxs("span",{style:c(t),children:[n.jsx(j,{size:12})," ",g(r)," total"]}),n.jsx("span",{style:{...c(t),color:t.textMuted},children:e.status})]})]})}function z({run:e,t}){const r=b.useMemo(()=>$(e),[e]),s=r.reduce((i,o)=>Math.max(i,o.deltaMs),0);return n.jsxs("section",{style:{marginBottom:22},children:[n.jsx(d,{t,children:"What the agent did · where the time went"}),n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:r.map(i=>{const o=s>0&&i.deltaMs===s&&i.deltaMs>=250;return n.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:10,padding:"8px 10px",borderRadius:8,background:o?l(t.warning,.1):t.cellBg,border:`1px solid ${o?l(t.warning,.4):t.cellBorder}`},children:[n.jsx("span",{style:{marginTop:1,color:i.isTool?t.accent:t.textMuted,flexShrink:0},children:i.isTool?n.jsx(M,{size:13}):n.jsx("span",{style:{fontSize:13},children:"•"})}),n.jsxs("div",{style:{flex:1,minWidth:0},children:[n.jsx("div",{style:{fontSize:13,fontWeight:500},children:i.label}),i.detail&&n.jsx("div",{style:{fontSize:12,color:t.textMuted,marginTop:2,wordBreak:"break-word"},children:i.detail})]}),n.jsx("span",{style:{fontSize:12,fontFamily:t.fontMono,color:o?t.warning:t.textMuted,fontWeight:o?600:400,flexShrink:0,whiteSpace:"nowrap"},children:i.deltaMs>0?`+${g(i.deltaMs)}`:"—"})]},i.key)})}),s>=1e3&&n.jsx("div",{style:{fontSize:12,color:t.textMuted,marginTop:8},children:"The highlighted step took the longest. Long generation/tool steps usually mean the question fell through to LLM generation — a governed metric or certified block would answer it instantly."})]})}function W({run:e,t}){const r=u(e);return n.jsxs("section",{style:{marginBottom:22},children:[n.jsx(d,{t,children:"Why this route"}),n.jsxs("div",{style:{fontSize:13,color:t.textSecondary,lineHeight:1.5},children:[r.reason,typeof r.confidence=="number"&&n.jsxs("span",{style:{color:t.textMuted},children:[" · confidence ",(r.confidence*100).toFixed(0),"%"]})]})]})}function u(e){const t=e.routeDecision;return{reason:typeof(t==null?void 0:t.reason)=="string"?t.reason:void 0,confidence:typeof(t==null?void 0:t.confidence)=="number"?t.confidence:void 0}}function I({run:e,t}){return n.jsxs("section",{style:{marginBottom:22},children:[n.jsx(d,{t,children:"Governance checks"}),n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:e.evaluations.map(r=>n.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:8,fontSize:13},children:[n.jsx("span",{style:{marginTop:1,color:r.passed?t.success:t.error,flexShrink:0},children:r.passed?n.jsx(k,{size:14}):n.jsx(v,{size:14})}),n.jsxs("div",{children:[n.jsx("span",{style:{fontWeight:500},children:r.label}),!r.passed&&r.message&&n.jsxs("span",{style:{color:t.textMuted},children:[" — ",r.message]})]})]},r.id))})]})}function d({t:e,children:t}){return n.jsx("div",{style:{fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:.6,color:e.textMuted,marginBottom:10},children:t})}function $(e){var i;const t=[...e.events].sort((o,a)=>o.at.localeCompare(a.at)),r=[];let s=e.startedAt??((i=t[0])==null?void 0:i.at);for(const o of t){const a=B(o);if(!a)continue;const h=f(s,o.at)??0;r.push({key:o.id,label:a,detail:T(o),deltaMs:h,isTool:A(o)}),s=o.at}return r}function A(e){const t=e.payload;return typeof(t==null?void 0:t.tool)=="string"}function B(e){switch(e.type){case"run.started":return"Started";case"route.decided":return`Routed to ${p(e.route)}`;case"plan.created":return"Planned the approach";case"step.started":return L(e)??"Working";case"executor.started":return R(e.route);case"evaluation.recorded":return"Checked grounding & trust";case"repair.attempted":return"Repaired and retried";case"replan.decided":return"Re-planned";case"escalated":return"Escalated to a deeper approach";case"artifact.created":return"Produced the answer";case"step.completed":return"Step complete";case"run.completed":return"Done";case"run.failed":return"Failed";default:return null}}function T(e){const t=e.payload;if(typeof(t==null?void 0:t.tool)=="string")return`tool: ${t.tool}`;if(e.type==="route.decided"||e.type==="run.failed")return e.message||void 0}function L(e){var r;const t=(r=e.payload)==null?void 0:r.goal;return t?`Working on: ${_(t,80)}`:null}function R(e){switch(e){case"certified_answer":return"Searching certified blocks & governed metrics";case"generated_answer":return"Composing the answer (semantic compile → generation)";case"research":return"Researching across governed data";case"app_build":return"Assembling the app";case"sql_cell":return"Writing the query";case"dql_block_draft":return"Drafting the block";case"conversation":return"Replying";default:return"Working"}}function p(e){return e?e.replace(/_/g," "):"the answer"}function C(e){return String(e).replace(/_/g," ")}function f(e,t){if(!e||!t)return null;const r=Date.parse(e),s=Date.parse(t);return Number.isNaN(r)||Number.isNaN(s)?null:Math.max(0,s-r)}function g(e){return e<1e3?`${Math.round(e)}ms`:`${(e/1e3).toFixed(e<1e4?1:0)}s`}function _(e,t){return e.length<=t?e:`${e.slice(0,t-1)}…`}function l(e,t){const r=e.trim(),s=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(r);if(!s)return e;let i,o,a;return s[1].length===3?(i=parseInt(s[1][0]+s[1][0],16),o=parseInt(s[1][1]+s[1][1],16),a=parseInt(s[1][2]+s[1][2],16)):(i=parseInt(s[1].slice(0,2),16),o=parseInt(s[1].slice(2,4),16),a=parseInt(s[1].slice(4,6),16)),`rgba(${i}, ${o}, ${a}, ${t})`}function D(e){return{display:"inline-flex",alignItems:"center",gap:6,marginBottom:16,background:"transparent",border:"none",cursor:"pointer",color:e.textMuted,fontSize:13,fontFamily:e.font,padding:0}}function c(e){return{display:"inline-flex",alignItems:"center",gap:5,fontSize:12,padding:"3px 9px",borderRadius:999,background:e.pillBg,border:`1px solid ${e.cellBorder}`,color:e.textSecondary}}function N(e,t){const r=t==="certified"?e.success:t==="blocked"?e.error:e.accent;return{display:"inline-flex",alignItems:"center",gap:5,fontSize:12,padding:"3px 9px",borderRadius:999,background:l(r,.12),border:`1px solid ${l(r,.4)}`,color:r,fontWeight:500}}export{H as AgentLogPage};
1
+ import{u as x,t as m,j as n,G as y,aA as j,r as b,e as k}from"./index-Ca3UeUWI.js";import{A as S}from"./arrow-left-D2FbLWqh.js";import{W as M}from"./wrench-DxUnoHtz.js";import{C as v}from"./circle-x-Dic_-4tF.js";import"./react-CRB3T2We.js";function H(){const{state:e,dispatch:t}=x(),r=m[e.themeMode],s=e.agentLogRun;return s?n.jsxs("div",{style:{padding:"20px 28px",fontFamily:r.font,color:r.textPrimary,maxWidth:900,margin:"0 auto"},children:[n.jsxs("button",{type:"button",onClick:()=>t({type:"SET_MAIN_VIEW",view:"ask"}),style:D(r),children:[n.jsx(S,{size:14})," Back to Ask AI"]}),n.jsx(w,{run:s,t:r}),n.jsx(z,{run:s,t:r}),u(s).reason&&n.jsx(W,{run:s,t:r}),s.evaluations.length>0&&n.jsx(I,{run:s,t:r})]}):n.jsx("div",{style:{padding:32,color:r.textMuted,fontFamily:r.font},children:"No agent run selected. Open one from the “View steps” link on an AI answer."})}function w({run:e,t}){const r=f(e.startedAt,e.completedAt);return n.jsxs("div",{style:{marginBottom:20},children:[n.jsx("div",{style:{fontSize:18,fontWeight:600,marginBottom:8,lineHeight:1.35},children:e.question}),n.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap",alignItems:"center"},children:[n.jsxs("span",{style:c(t),children:[n.jsx(y,{size:12})," ",p(e.route)]}),n.jsx("span",{style:N(t,e.trustState),children:C(e.trustState)}),r!=null&&n.jsxs("span",{style:c(t),children:[n.jsx(j,{size:12})," ",g(r)," total"]}),n.jsx("span",{style:{...c(t),color:t.textMuted},children:e.status})]})]})}function z({run:e,t}){const r=b.useMemo(()=>$(e),[e]),s=r.reduce((i,o)=>Math.max(i,o.deltaMs),0);return n.jsxs("section",{style:{marginBottom:22},children:[n.jsx(d,{t,children:"What the agent did · where the time went"}),n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:r.map(i=>{const o=s>0&&i.deltaMs===s&&i.deltaMs>=250;return n.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:10,padding:"8px 10px",borderRadius:8,background:o?l(t.warning,.1):t.cellBg,border:`1px solid ${o?l(t.warning,.4):t.cellBorder}`},children:[n.jsx("span",{style:{marginTop:1,color:i.isTool?t.accent:t.textMuted,flexShrink:0},children:i.isTool?n.jsx(M,{size:13}):n.jsx("span",{style:{fontSize:13},children:"•"})}),n.jsxs("div",{style:{flex:1,minWidth:0},children:[n.jsx("div",{style:{fontSize:13,fontWeight:500},children:i.label}),i.detail&&n.jsx("div",{style:{fontSize:12,color:t.textMuted,marginTop:2,wordBreak:"break-word"},children:i.detail})]}),n.jsx("span",{style:{fontSize:12,fontFamily:t.fontMono,color:o?t.warning:t.textMuted,fontWeight:o?600:400,flexShrink:0,whiteSpace:"nowrap"},children:i.deltaMs>0?`+${g(i.deltaMs)}`:"—"})]},i.key)})}),s>=1e3&&n.jsx("div",{style:{fontSize:12,color:t.textMuted,marginTop:8},children:"The highlighted step took the longest. Long generation/tool steps usually mean the question fell through to LLM generation — a governed metric or certified block would answer it instantly."})]})}function W({run:e,t}){const r=u(e);return n.jsxs("section",{style:{marginBottom:22},children:[n.jsx(d,{t,children:"Why this route"}),n.jsxs("div",{style:{fontSize:13,color:t.textSecondary,lineHeight:1.5},children:[r.reason,typeof r.confidence=="number"&&n.jsxs("span",{style:{color:t.textMuted},children:[" · confidence ",(r.confidence*100).toFixed(0),"%"]})]})]})}function u(e){const t=e.routeDecision;return{reason:typeof(t==null?void 0:t.reason)=="string"?t.reason:void 0,confidence:typeof(t==null?void 0:t.confidence)=="number"?t.confidence:void 0}}function I({run:e,t}){return n.jsxs("section",{style:{marginBottom:22},children:[n.jsx(d,{t,children:"Governance checks"}),n.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:e.evaluations.map(r=>n.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:8,fontSize:13},children:[n.jsx("span",{style:{marginTop:1,color:r.passed?t.success:t.error,flexShrink:0},children:r.passed?n.jsx(k,{size:14}):n.jsx(v,{size:14})}),n.jsxs("div",{children:[n.jsx("span",{style:{fontWeight:500},children:r.label}),!r.passed&&r.message&&n.jsxs("span",{style:{color:t.textMuted},children:[" — ",r.message]})]})]},r.id))})]})}function d({t:e,children:t}){return n.jsx("div",{style:{fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:.6,color:e.textMuted,marginBottom:10},children:t})}function $(e){var i;const t=[...e.events].sort((o,a)=>o.at.localeCompare(a.at)),r=[];let s=e.startedAt??((i=t[0])==null?void 0:i.at);for(const o of t){const a=B(o);if(!a)continue;const h=f(s,o.at)??0;r.push({key:o.id,label:a,detail:T(o),deltaMs:h,isTool:A(o)}),s=o.at}return r}function A(e){const t=e.payload;return typeof(t==null?void 0:t.tool)=="string"}function B(e){switch(e.type){case"run.started":return"Started";case"route.decided":return`Routed to ${p(e.route)}`;case"plan.created":return"Planned the approach";case"step.started":return L(e)??"Working";case"executor.started":return R(e.route);case"evaluation.recorded":return"Checked grounding & trust";case"repair.attempted":return"Repaired and retried";case"replan.decided":return"Re-planned";case"escalated":return"Escalated to a deeper approach";case"artifact.created":return"Produced the answer";case"step.completed":return"Step complete";case"run.completed":return"Done";case"run.failed":return"Failed";default:return null}}function T(e){const t=e.payload;if(typeof(t==null?void 0:t.tool)=="string")return`tool: ${t.tool}`;if(e.type==="route.decided"||e.type==="run.failed")return e.message||void 0}function L(e){var r;const t=(r=e.payload)==null?void 0:r.goal;return t?`Working on: ${_(t,80)}`:null}function R(e){switch(e){case"certified_answer":return"Searching certified blocks & governed metrics";case"generated_answer":return"Composing the answer (semantic compile → generation)";case"research":return"Researching across governed data";case"app_build":return"Assembling the app";case"sql_cell":return"Writing the query";case"dql_block_draft":return"Drafting the block";case"conversation":return"Replying";default:return"Working"}}function p(e){return e?e.replace(/_/g," "):"the answer"}function C(e){return String(e).replace(/_/g," ")}function f(e,t){if(!e||!t)return null;const r=Date.parse(e),s=Date.parse(t);return Number.isNaN(r)||Number.isNaN(s)?null:Math.max(0,s-r)}function g(e){return e<1e3?`${Math.round(e)}ms`:`${(e/1e3).toFixed(e<1e4?1:0)}s`}function _(e,t){return e.length<=t?e:`${e.slice(0,t-1)}…`}function l(e,t){const r=e.trim(),s=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(r);if(!s)return e;let i,o,a;return s[1].length===3?(i=parseInt(s[1][0]+s[1][0],16),o=parseInt(s[1][1]+s[1][1],16),a=parseInt(s[1][2]+s[1][2],16)):(i=parseInt(s[1].slice(0,2),16),o=parseInt(s[1].slice(2,4),16),a=parseInt(s[1].slice(4,6),16)),`rgba(${i}, ${o}, ${a}, ${t})`}function D(e){return{display:"inline-flex",alignItems:"center",gap:6,marginBottom:16,background:"transparent",border:"none",cursor:"pointer",color:e.textMuted,fontSize:13,fontFamily:e.font,padding:0}}function c(e){return{display:"inline-flex",alignItems:"center",gap:5,fontSize:12,padding:"3px 9px",borderRadius:999,background:e.pillBg,border:`1px solid ${e.cellBorder}`,color:e.textSecondary}}function N(e,t){const r=t==="certified"?e.success:t==="blocked"?e.error:e.accent;return{display:"inline-flex",alignItems:"center",gap:5,fontSize:12,padding:"3px 9px",borderRadius:999,background:l(r,.12),border:`1px solid ${l(r,.4)}`,color:r,fontWeight:500}}export{H as AgentLogPage};
@@ -1 +1 @@
1
- import{u,t as f,r as a,j as o,S as h,m as b}from"./index-CcZ8Dw84.js";import{s as g}from"./ai-build-bus-1BR770pY.js";import{u as y,A as k}from"./AiBuildResult-CvNitmsw.js";import{X as j}from"./x-FQc3jbQ8.js";import"./react-CRB3T2We.js";import"./user-round-DkUToep7.js";import"./triangle-alert-_FtKJhjm.js";import"./rotate-ccw-DrQw5ZrW.js";function z(){const{state:n,dispatch:c}=u(),t=f[n.themeMode],[e,l]=a.useState(null),p=y();if(a.useEffect(()=>g(i=>l(i)),[]),!e)return null;const s=()=>l(null),m=i=>{const r=i.trim();if(!r)return;const d=b("sql",r);d.name="ai_sql_preview",c({type:"ADD_CELL",cell:d})},x=(i,r)=>{p(i,r).finally(s)};return o.jsx("div",{role:"dialog","aria-modal":"true","aria-label":"Ask AI to build",style:v,children:o.jsxs("div",{style:{width:"min(720px, calc(100vw - 32px))",maxHeight:"min(760px, calc(100vh - 64px))",background:t.appBg,border:`1px solid ${t.headerBorder}`,borderRadius:12,boxShadow:"0 24px 80px rgba(0,0,0,0.34)",display:"flex",flexDirection:"column",overflow:"hidden"},children:[o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"11px 14px",borderBottom:`1px solid ${t.headerBorder}`},children:[o.jsx("div",{style:{width:30,height:30,borderRadius:8,background:`${t.accent}16`,border:`1px solid ${t.accent}38`,color:t.accent,display:"inline-flex",alignItems:"center",justifyContent:"center",flex:"0 0 auto"},children:o.jsx(h,{size:16,strokeWidth:2.2})}),o.jsxs("div",{style:{flex:1,minWidth:0},children:[o.jsx("div",{style:{fontSize:14,fontWeight:850,color:t.textPrimary,fontFamily:t.font},children:e.mode==="edit"?"Ask AI to modify a block":"Ask AI to build a block"}),o.jsx("div",{style:{fontSize:11.5,color:t.textMuted,fontFamily:t.font,marginTop:1},children:e.sourceLabel??(e.mode==="edit"?"Describe the change and review a before/after diff. Nothing is certified.":"Generate a draft from your dbt + semantic context. Nothing is certified.")})]}),o.jsx("button",{type:"button",onClick:s,title:"Close",style:{width:28,height:28,borderRadius:6,border:`1px solid ${t.btnBorder}`,background:t.btnBg,color:t.textSecondary,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer"},children:o.jsx(j,{size:15,strokeWidth:2})})]}),o.jsx("div",{style:{flex:1,minHeight:0,overflow:"auto"},children:o.jsx(k,{themeMode:n.themeMode,initialTarget:e.target,lockTarget:e.lockTarget,initialPrompt:e.prompt,context:e.context,initialMode:e.mode,initialBlockPath:e.blockPath,onInsertCell:m,onOpenBlock:x},`${e.target}:${e.mode??"create"}:${e.blockPath??""}:${e.prompt??""}:${e.sourceLabel??""}`)})]})})}const v={position:"fixed",inset:0,zIndex:60,background:"rgba(0,0,0,0.32)",display:"flex",alignItems:"center",justifyContent:"center",padding:16};export{z as AiBuildDialog};
1
+ import{u,t as f,r as a,j as o,S as h,m as b}from"./index-Ca3UeUWI.js";import{s as g}from"./ai-build-bus-1BR770pY.js";import{u as y,A as k}from"./AiBuildResult-B9KmBRsh.js";import{X as j}from"./x-9Gtb3EAd.js";import"./react-CRB3T2We.js";import"./user-round-DSt0xU3K.js";import"./triangle-alert-DUf4Ook0.js";import"./rotate-ccw-DndbJAiz.js";function z(){const{state:n,dispatch:c}=u(),t=f[n.themeMode],[e,l]=a.useState(null),p=y();if(a.useEffect(()=>g(i=>l(i)),[]),!e)return null;const s=()=>l(null),m=i=>{const r=i.trim();if(!r)return;const d=b("sql",r);d.name="ai_sql_preview",c({type:"ADD_CELL",cell:d})},x=(i,r)=>{p(i,r).finally(s)};return o.jsx("div",{role:"dialog","aria-modal":"true","aria-label":"Ask AI to build",style:v,children:o.jsxs("div",{style:{width:"min(720px, calc(100vw - 32px))",maxHeight:"min(760px, calc(100vh - 64px))",background:t.appBg,border:`1px solid ${t.headerBorder}`,borderRadius:12,boxShadow:"0 24px 80px rgba(0,0,0,0.34)",display:"flex",flexDirection:"column",overflow:"hidden"},children:[o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"11px 14px",borderBottom:`1px solid ${t.headerBorder}`},children:[o.jsx("div",{style:{width:30,height:30,borderRadius:8,background:`${t.accent}16`,border:`1px solid ${t.accent}38`,color:t.accent,display:"inline-flex",alignItems:"center",justifyContent:"center",flex:"0 0 auto"},children:o.jsx(h,{size:16,strokeWidth:2.2})}),o.jsxs("div",{style:{flex:1,minWidth:0},children:[o.jsx("div",{style:{fontSize:14,fontWeight:850,color:t.textPrimary,fontFamily:t.font},children:e.mode==="edit"?"Ask AI to modify a block":"Ask AI to build a block"}),o.jsx("div",{style:{fontSize:11.5,color:t.textMuted,fontFamily:t.font,marginTop:1},children:e.sourceLabel??(e.mode==="edit"?"Describe the change and review a before/after diff. Nothing is certified.":"Generate a draft from your dbt + semantic context. Nothing is certified.")})]}),o.jsx("button",{type:"button",onClick:s,title:"Close",style:{width:28,height:28,borderRadius:6,border:`1px solid ${t.btnBorder}`,background:t.btnBg,color:t.textSecondary,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer"},children:o.jsx(j,{size:15,strokeWidth:2})})]}),o.jsx("div",{style:{flex:1,minHeight:0,overflow:"auto"},children:o.jsx(k,{themeMode:n.themeMode,initialTarget:e.target,lockTarget:e.lockTarget,initialPrompt:e.prompt,context:e.context,initialMode:e.mode,initialBlockPath:e.blockPath,onInsertCell:m,onOpenBlock:x},`${e.target}:${e.mode??"create"}:${e.blockPath??""}:${e.prompt??""}:${e.sourceLabel??""}`)})]})})}const v={position:"fixed",inset:0,zIndex:60,background:"rgba(0,0,0,0.32)",display:"flex",alignItems:"center",justifyContent:"center",padding:16};export{z as AiBuildDialog};
@@ -1,4 +1,4 @@
1
- import{g as M,u as U,r as f,a as D,j as t,B as Q,t as Ce,S as V,L as se,ai as Be,e as K,c as oe,T as re,b as le,d as ae,R as de}from"./index-CcZ8Dw84.js";import{U as ce,G as pe}from"./user-round-DkUToep7.js";import{T as ue}from"./triangle-alert-_FtKJhjm.js";import{R as Y}from"./rotate-ccw-DrQw5ZrW.js";/**
1
+ import{g as M,u as U,r as f,a as D,j as t,B as Q,t as Ce,S as V,L as se,ai as Be,e as K,c as oe,T as re,b as le,d as ae,R as de}from"./index-Ca3UeUWI.js";import{U as ce,G as pe}from"./user-round-DSt0xU3K.js";import{T as ue}from"./triangle-alert-DUf4Ook0.js";import{R as Y}from"./rotate-ccw-DndbJAiz.js";/**
2
2
  * @license lucide-react v0.563.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import{g,j as i,S as j,L as w}from"./index-CcZ8Dw84.js";import{M as v}from"./minimize-2-BnsbPUr5.js";import{M as k}from"./maximize-2-CVJP65sF.js";import{X as I}from"./x-FQc3jbQ8.js";/**
1
+ import{g,j as i,S as j,L as w}from"./index-Ca3UeUWI.js";import{M as v}from"./minimize-2-CUDBPkwe.js";import{M as k}from"./maximize-2-CQOA-bbN.js";import{X as I}from"./x-9Gtb3EAd.js";/**
2
2
  * @license lucide-react v0.563.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import{g as ne,u as re,t as ie,r as f,a as R,j as o,m as oe,P as se,L as J,h as ae,T as de}from"./index-CcZ8Dw84.js";import{u as ce,f as le,c as ue}from"./answer-to-notebook-mhY-MBsX.js";import{U as fe}from"./UnifiedAgentRunPanel-CZjUHLl5.js";import{S as G}from"./star-DBVkbHOE.js";import{P as pe}from"./pencil-BDR0kEX-.js";import"./react-CRB3T2We.js";import"./AgentAnswerCard-D1VcQOTJ.js";import"./usePersistedAgentThreadId-BG1TZXp_.js";import"./TrustBadge-C4jIUuEE.js";import"./AiBuildResult-CvNitmsw.js";import"./user-round-DkUToep7.js";import"./triangle-alert-_FtKJhjm.js";import"./rotate-ccw-DrQw5ZrW.js";import"./x-FQc3jbQ8.js";import"./list-tree-DMGqPCsV.js";import"./wrench-CgXGBYJ-.js";import"./arrow-right-CJ_6d0z7.js";import"./chevron-up-DSMkEFrK.js";/**
1
+ import{g as ne,u as re,t as ie,r as f,a as R,j as o,m as oe,P as se,L as J,h as ae,T as de}from"./index-Ca3UeUWI.js";import{u as ce,f as le,c as ue}from"./answer-to-notebook-Bm9oByWA.js";import{U as fe}from"./UnifiedAgentRunPanel-CwxQ4T19.js";import{S as G}from"./star-DvcMC9wZ.js";import{P as pe}from"./pencil-Cf6-MgpT.js";import"./react-CRB3T2We.js";import"./AgentAnswerCard-Dp4odOLE.js";import"./usePersistedAgentThreadId-DbdBi0oH.js";import"./TrustBadge-DPnKzRSY.js";import"./AiBuildResult-B9KmBRsh.js";import"./user-round-DSt0xU3K.js";import"./triangle-alert-DUf4Ook0.js";import"./rotate-ccw-DndbJAiz.js";import"./x-9Gtb3EAd.js";import"./list-tree-BrIZg6l6.js";import"./wrench-DxUnoHtz.js";import"./arrow-right-OYItAZ-s.js";import"./chevron-up-DM5LX-26.js";/**
2
2
  * @license lucide-react v0.563.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.