@duckcodeailabs/dql-cli 1.12.2 → 1.12.4
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.
- package/dist/assets/dql-notebook/assets/AgentAnswerCard-BJAnjaLA.js +5 -0
- package/dist/assets/dql-notebook/assets/AgentLogPage-J72WR6hk.js +1 -0
- package/dist/assets/dql-notebook/assets/AiBuildDialog-CHJZfDmp.js +1 -0
- package/dist/assets/dql-notebook/assets/AiBuildResult-Da7_Cn12.js +33 -0
- package/dist/assets/dql-notebook/assets/AiSidePanel-BY6W_5aC.js +6 -0
- package/dist/assets/dql-notebook/assets/AnalyticsHome-u-buXgdv.js +6 -0
- package/dist/assets/dql-notebook/assets/AppsView-3k7ftDpd.js +4471 -0
- package/dist/assets/dql-notebook/assets/BlockStudio-CLX4EUyO.js +60 -0
- package/dist/assets/dql-notebook/assets/BusinessArtifactView-3THMNeyO.js +1 -0
- package/dist/assets/dql-notebook/assets/DbtFirstModelingPage-BwBPwtdA.js +22 -0
- package/dist/assets/dql-notebook/assets/GitPage-CvEki0pe.js +7 -0
- package/dist/assets/dql-notebook/assets/GlobalAiRail-NXdk9kNy.js +1 -0
- package/dist/assets/dql-notebook/assets/GovernedContextPage-DILbw-Vr.js +7 -0
- package/dist/assets/dql-notebook/assets/HelpDocsPage-DgCu4bvY.js +22 -0
- package/dist/assets/dql-notebook/assets/HomePage-CK3fXTQo.js +117 -0
- package/dist/assets/dql-notebook/assets/LineageDAG-DW_NO3P2.js +1 -0
- package/dist/assets/dql-notebook/assets/LineageDetailView-VT7DLJOB.js +1 -0
- package/dist/assets/dql-notebook/assets/LineageDrawer-DSTm8aXw.js +1 -0
- package/dist/assets/dql-notebook/assets/LineagePathBreadcrumb-DRlAYasJ.js +14 -0
- package/dist/assets/dql-notebook/assets/MiniLineageGraph-CR_nhwhZ.js +1 -0
- package/dist/assets/dql-notebook/assets/NewBlockModal-CJvjYiBF.js +1 -0
- package/dist/assets/dql-notebook/assets/NewNotebookModal-BEpPH93n.js +46 -0
- package/dist/assets/dql-notebook/assets/NotebookEditor-C7GDFwhF.js +202 -0
- package/dist/assets/dql-notebook/assets/ReadinessPage-rZiOp2xr.js +1 -0
- package/dist/assets/dql-notebook/assets/SetupOnboarding-BWjhTjPB.js +6 -0
- package/dist/assets/dql-notebook/assets/TrustBadge-RvZ9s6OQ.js +1 -0
- package/dist/assets/dql-notebook/assets/UnifiedAgentRunPanel-CGPcpY1B.js +83 -0
- package/dist/assets/dql-notebook/assets/ai-build-bus-1BR770pY.js +1 -0
- package/dist/assets/dql-notebook/assets/answer-to-notebook-Di227Cd4.js +2 -0
- package/dist/assets/dql-notebook/assets/arrow-left-BZHDcWHR.js +6 -0
- package/dist/assets/dql-notebook/assets/arrow-right-DlM1pC3_.js +6 -0
- package/dist/assets/dql-notebook/assets/book-open-text-DBcXFQAu.js +6 -0
- package/dist/assets/dql-notebook/assets/bot-BAywbvPm.js +6 -0
- package/dist/assets/dql-notebook/assets/chevron-up-B_GfKE_F.js +6 -0
- package/dist/assets/dql-notebook/assets/circle-x-BcxtZ-ym.js +6 -0
- package/dist/assets/dql-notebook/assets/{codemirror-Co0dCEDr.js → codemirror-1_I9gm6Z.js} +1 -1
- package/dist/assets/dql-notebook/assets/dagre-BZV40eAE.css +1 -0
- package/dist/assets/dql-notebook/assets/dagre.esm-Bqs0lsEz.js +23 -0
- package/dist/assets/dql-notebook/assets/external-link-B24Dk9_t.js +6 -0
- package/dist/assets/dql-notebook/assets/grip-vertical-D9g31N3j.js +6 -0
- package/dist/assets/dql-notebook/assets/{index-DvLT6Kls.css → index-DKu4CZt3.css} +1 -1
- package/dist/assets/dql-notebook/assets/index-DU7j3Sqk.js +644 -0
- package/dist/assets/dql-notebook/assets/link-2-B36oR5Bj.js +6 -0
- package/dist/assets/dql-notebook/assets/list-tree-B9ZzGc4U.js +6 -0
- package/dist/assets/dql-notebook/assets/maximize-2-BrvQLPoj.js +6 -0
- package/dist/assets/dql-notebook/assets/minimize-2-BrpFmsxS.js +6 -0
- package/dist/assets/dql-notebook/assets/panel-right-open-B1g1qhh5.js +6 -0
- package/dist/assets/dql-notebook/assets/pencil-DwywbTqQ.js +6 -0
- package/dist/assets/dql-notebook/assets/{react-BRY8hXab.js → react-CRB3T2We.js} +2 -2
- package/dist/assets/dql-notebook/assets/rotate-ccw-Db_KVs3J.js +6 -0
- package/dist/assets/dql-notebook/assets/semantic-fields-BIVuvP2l.js +3 -0
- package/dist/assets/dql-notebook/assets/triangle-alert-Cne6C2aG.js +6 -0
- package/dist/assets/dql-notebook/assets/usePersistedAgentThreadId-D6mtrJ-_.js +18 -0
- package/dist/assets/dql-notebook/assets/user-round-DkzxN1xD.js +11 -0
- package/dist/assets/dql-notebook/assets/wand-sparkles-CJUvFtur.js +6 -0
- package/dist/assets/dql-notebook/assets/workflow-BOvVTg7R.js +6 -0
- package/dist/assets/dql-notebook/assets/wrench-YeSpzZRt.js +6 -0
- package/dist/assets/dql-notebook/assets/x-C6tsHUR7.js +6 -0
- package/dist/assets/dql-notebook/index.html +3 -4
- package/dist/block-invocation.js +4 -0
- package/dist/block-invocation.js.map +1 -1
- package/dist/llm/answer-loop-tools.d.ts +8 -2
- package/dist/llm/answer-loop-tools.d.ts.map +1 -1
- package/dist/llm/answer-loop-tools.js +29 -2
- package/dist/llm/answer-loop-tools.js.map +1 -1
- package/dist/llm/providers/dql-agent-provider.d.ts +27 -1
- package/dist/llm/providers/dql-agent-provider.d.ts.map +1 -1
- package/dist/llm/providers/dql-agent-provider.js +79 -15
- package/dist/llm/providers/dql-agent-provider.js.map +1 -1
- package/dist/llm/types.d.ts +8 -1
- package/dist/llm/types.d.ts.map +1 -1
- package/dist/local-runtime.d.ts +56 -2
- package/dist/local-runtime.d.ts.map +1 -1
- package/dist/local-runtime.js +735 -104
- package/dist/local-runtime.js.map +1 -1
- package/dist/package.json +10 -10
- package/dist/sql-result-filter.d.ts +39 -0
- package/dist/sql-result-filter.d.ts.map +1 -0
- package/dist/sql-result-filter.js +256 -0
- package/dist/sql-result-filter.js.map +1 -0
- package/dist/warehouse-metadata.d.ts +1 -1
- package/dist/warehouse-metadata.d.ts.map +1 -1
- package/dist/warehouse-metadata.js +2 -2
- package/dist/warehouse-metadata.js.map +1 -1
- package/package.json +10 -10
- package/dist/assets/dql-notebook/assets/index-BRCtmVPa.js +0 -5952
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{u as G,r,a as I,j as e,S as H,Y as P,az as _,L as N,h as q,b as Q,d as V,B as U,e as K}from"./index-DU7j3Sqk.js";import{T as Y}from"./TrustBadge-RvZ9s6OQ.js";import{o as O}from"./ai-build-bus-1BR770pY.js";import{W as M}from"./wand-sparkles-CJUvFtur.js";import{U as J,G as X}from"./user-round-DkzxN1xD.js";import{T as B}from"./triangle-alert-Cne6C2aG.js";import{A as Z}from"./arrow-right-DlM1pC3_.js";import"./react-CRB3T2We.js";function Ce(){const{state:s,dispatch:c}=G(),[o,y]=r.useState(null),[w,u]=r.useState(!0),[p,f]=r.useState(new Set),[l,k]=r.useState(!1),[R,T]=r.useState(null),[W,z]=r.useState(null);r.useEffect(()=>{let t=!1;return I.getIdentity().then(n=>{!t&&(n!=null&&n.owner)&&z(n.owner)}).catch(()=>{}),()=>{t=!0}},[]);const C=r.useCallback(async(t,n)=>{const i={name:t.split("/").pop()??`${n}.dql`,path:t,type:"block",folder:"blocks"};s.files.some(a=>a.path===t)||c({type:"FILE_ADDED",file:i});const x=await I.openBlockStudio(t);c({type:"OPEN_BLOCK_STUDIO",file:i,payload:x})},[c,s.files]),b=r.useCallback(()=>{let t=!1;return u(!0),I.getProposeReadiness().then(n=>{if(t)return;y(n);const i=n.ready?n.plan.domains.flatMap(x=>x.candidates.map(a=>a.slug)):[];f(new Set(i)),u(!1)}),()=>{t=!0}},[]);r.useEffect(()=>b(),[b]);const m=r.useCallback(()=>{c({type:"SET_MAIN_VIEW",view:"block_studio"})},[c]),D=r.useCallback(t=>{f(n=>{const i=new Set(n);return i.has(t)?i.delete(t):i.add(t),i})},[]),v=r.useCallback(t=>{f(n=>{const i=new Set(n),x=t.candidates.map(g=>g.slug),a=x.every(g=>i.has(g));for(const g of x)a?i.delete(g):i.add(g);return i})},[]),L=r.useCallback(async()=>{const t=[...p];if(t.length===0)return;k(!0),T(null);const n=await I.generateProposeDrafts({slugs:t});if(k(!1),!n.ready){T(n.reason??"Could not generate drafts.");return}const i=n.proposals.find(x=>x.path);i!=null&&i.path?C(i.path,i.slug):m()},[p,m,C]),d=o==null?void 0:o.summary,h=o!=null&&o.ready?o.plan:null;return e.jsx("div",{style:{flex:1,minWidth:0,overflow:"auto"},children:e.jsxs("div",{style:{maxWidth:980,margin:"0 auto",padding:"22px 28px 40px",display:"grid",gap:16},children:[e.jsxs("header",{style:{display:"grid",gap:6},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx(H,{size:20}),e.jsx("div",{style:{fontSize:22,fontWeight:750},children:"Get started"}),e.jsx("div",{style:{flex:1}}),e.jsxs("button",{type:"button",onClick:()=>O({target:"block",lockTarget:!0,sourceLabel:"Describe a block to draft from your project context."}),style:ue,children:[e.jsx(M,{size:14})," Ask AI to build a block"]})]}),e.jsx("div",{style:{fontSize:13,opacity:.72,maxWidth:760,lineHeight:1.55},children:d!=null&&d.modelsScanned?`I scanned your dbt project and found ${d.businessModels} ${d.businessModels===1?"thing":"things"} worth governing — here's what each one does. Expand a row to see the SQL it would run and what's still missing to certify. Plumbing and low-value models are left out. Nothing is drafted or certified until you approve it.`:"I scanned your dbt project for the business models worth governing — here's what each one does. Expand a row to see the SQL it would run and what's still missing to certify. Nothing is drafted or certified until you approve it."}),W?e.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:11.5,opacity:.62},children:[e.jsx(J,{size:12})," drafting as ",W]}):null,e.jsxs("button",{type:"button",onClick:()=>c({type:"SET_MAIN_VIEW",view:"skills"}),style:{display:"inline-flex",alignItems:"center",gap:6,alignSelf:"start",marginTop:2,padding:0,border:"none",background:"transparent",color:"var(--color-accent-blue, #6b5dd3)",fontSize:12,fontWeight:650,cursor:"pointer"},children:[e.jsx(X,{size:13})," Teach the AI your business rules →"]})]}),w?e.jsx("div",{style:E,children:"Classifying dbt models and planning the business seed…"}):o?o.ready?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:10},children:[e.jsx(S,{label:"dbt models scanned",value:d.modelsScanned}),e.jsx(S,{label:"Business models",value:d.businessModels,tone:"success"}),e.jsx(S,{label:"Plumbing excluded",value:d.plumbingExcluded}),e.jsx(S,{label:"Metrics found",value:d.metricsFound})]}),d.reviewTelemetry&&d.reviewTelemetry.existingDrafts>0?e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, minmax(0, 1fr))",gap:10},children:[e.jsx(S,{label:"Drafts ready for review",value:`${Math.round((d.reviewTelemetry.readyForReviewRate??0)*100)}%`,tone:"success"}),e.jsx(S,{label:"Median draft age",value:d.reviewTelemetry.medianReviewAgeHours!=null?`${d.reviewTelemetry.medianReviewAgeHours.toFixed(1)}h`:"—"}),e.jsx(S,{label:"Est. review time",value:`~${d.reviewTelemetry.estimatedReviewMinutes} min`})]}):null,e.jsxs("div",{style:ye,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx(_,{size:16}),e.jsxs("div",{style:{fontSize:13},children:[e.jsxs("strong",{children:["Will generate ",p.size]}),e.jsxs("span",{style:{opacity:.65},children:[" ","of ",h.willGenerate," planned · skipping ",h.willSkip," · ≤ ",h.config.maxPerDomain," per domain"]})]})]}),e.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[e.jsxs("button",{type:"button",onClick:b,style:$,children:[e.jsx(P,{size:13})," Refresh"]}),e.jsxs("button",{type:"button",onClick:()=>void L(),disabled:l||p.size===0,style:{...he,opacity:l||p.size===0?.6:1},children:[l?e.jsx(N,{size:13,className:"spin"}):e.jsx(q,{size:13}),l?"Generating…":e.jsxs(e.Fragment,{children:["Approve & generate ",p.size>0?`(${p.size})`:""]})]})]})]}),R?e.jsxs("div",{style:{...E,display:"flex",gap:8,alignItems:"center",borderColor:"var(--status-error, #cf222e)"},children:[e.jsx(B,{size:16})," ",R]}):null,e.jsx("div",{style:{display:"grid",gap:12},children:h.domains.length===0?e.jsxs("div",{style:E,children:["No business models found to govern. Tag a layer in ",e.jsx("code",{children:"dql.config.json"})," ","(",e.jsx("code",{children:"propose.businessLayers"}),") or add ",e.jsx("code",{children:"meta.dql.business"})," to your dbt models."]}):h.domains.map(t=>e.jsx(ee,{domain:t,selected:p,onToggleSlug:D,onToggleDomain:v,onOpenInBlockStudio:C},t.name))}),e.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:e.jsxs("button",{type:"button",onClick:m,style:fe,children:["Open Block Studio ",e.jsx(Z,{size:13})]})})]}):e.jsxs("div",{style:{...E,display:"flex",alignItems:"flex-start",gap:10},children:[e.jsx(B,{size:18,style:{flexShrink:0,marginTop:1}}),e.jsxs("div",{style:{display:"grid",gap:8},children:[e.jsx("div",{style:{fontWeight:650},children:"Not ready to propose yet"}),e.jsx("div",{style:{opacity:.8},children:o.reason}),e.jsxs("button",{type:"button",onClick:b,style:$,children:[e.jsx(P,{size:13})," Re-check"]})]})]}):e.jsx("div",{style:E,children:"Could not load readiness."})]})})}function ee({domain:s,selected:c,onToggleSlug:o,onToggleDomain:y,onOpenInBlockStudio:w}){const u=s.candidates.map(l=>l.slug),p=u.every(l=>c.has(l)),f=u.some(l=>c.has(l));return e.jsxs("div",{style:ie,children:[e.jsxs("div",{style:le,children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:p,ref:l=>{l&&(l.indeterminate=!p&&f)},onChange:()=>y(s)}),e.jsx("span",{style:{fontSize:13,fontWeight:700},children:s.name}),e.jsxs("span",{style:{fontSize:11,opacity:.6},children:[s.modelCount," model",s.modelCount===1?"":"s"]})]}),s.owner?e.jsxs("span",{style:{fontSize:11,opacity:.6},children:["owner ",s.owner]}):null]}),e.jsx("div",{style:{display:"grid",gap:6},children:s.candidates.map(l=>e.jsx(se,{candidate:l,checked:c.has(l.slug),onToggle:()=>o(l.slug),onOpenInBlockStudio:w},l.slug))})]})}function se({candidate:s,checked:c,onToggle:o,onOpenInBlockStudio:y}){const w=r.useMemo(()=>s.evidence.slice(0,3),[s.evidence]),[u,p]=r.useState(!1),[f,l]=r.useState(null),[k,R]=r.useState(!1),[T,W]=r.useState(null),[z,C]=r.useState(!1),[b,m]=r.useState(null),D=r.useCallback(()=>{p(a=>{const g=!a;return g&&!f&&!k&&(R(!0),W(null),I.proposePreview(s.slug).then(j=>l(j.candidate)).catch(j=>W(j instanceof Error?j.message:"Could not load the preview.")).finally(()=>R(!1))),g})},[s.slug,f,k]),v=f??s,L=v.sqlPreview,d=v.outputs??[],h=v.examples??[],t=v.certifierVerdict,n=v.description,i=r.useCallback(async()=>{C(!0),m(null);try{const a=await I.generateProposeDrafts({slugs:[s.slug]}),g=a.proposals.find(F=>F.slug===s.slug)??a.proposals[0],j=g==null?void 0:g.path;if(!j){m("No draft path was returned for this model yet.");return}await y(j,s.model)}catch(a){m(a instanceof Error?a.message:"Could not open this draft.")}finally{C(!1)}},[s.model,s.slug,y]),x=r.useCallback(()=>{O({target:"block",lockTarget:!0,prompt:`Refine the "${s.model}" block: ${n??`a ${s.pattern??"business"} model${s.grain?` at ${s.grain} grain`:""}`}.`,sourceLabel:`Refining ${s.model}`})},[s.grain,s.model,s.pattern,n]);return e.jsxs("div",{style:{...oe,opacity:c?1:.7},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"auto minmax(0, 1fr) auto",gap:10,alignItems:"start"},children:[e.jsx("input",{type:"checkbox",checked:c,onChange:o,style:{marginTop:3},"aria-label":`Include ${s.model}`}),e.jsxs("div",{style:{display:"grid",gap:4,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center",flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:14,fontWeight:700},children:s.model}),e.jsx(Y,{state:"ai_generated"}),s.pattern?e.jsx(ne,{children:s.pattern}):null,s.grain?e.jsxs("span",{style:{fontSize:11,opacity:.6},children:["grain ",s.grain]}):null]}),w.length>0?e.jsxs("div",{style:{fontSize:11,opacity:.66},children:[e.jsx("span",{style:{opacity:.8},children:"why: "}),w.join(" · ")]}):null]}),e.jsxs("button",{type:"button",onClick:D,"aria-expanded":u,style:de,children:[u?e.jsx(Q,{size:13}):e.jsx(V,{size:13}),u?"Hide":"Details"]})]}),u?e.jsx("div",{style:ae,children:k?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:12,opacity:.75},children:[e.jsx(N,{size:13,className:"spin"})," Loading the generated SQL and verdict…"]}):T?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:12,color:"var(--status-error, #cf222e)"},children:[e.jsx(B,{size:14})," ",T]}):e.jsxs(e.Fragment,{children:[n?e.jsx("div",{style:{fontSize:12,opacity:.82,lineHeight:1.5},children:n}):null,e.jsxs("div",{style:{display:"grid",gap:5},children:[e.jsx(A,{children:"SQL this block will run"}),L?e.jsx("pre",{style:ce,children:e.jsx("code",{style:{fontFamily:"var(--font-mono, monospace)",fontSize:11.5,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:L.trim()})}):e.jsx("div",{style:{fontSize:11.5,opacity:.6},children:"The generated SQL is not available for this model yet."})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(220px, 1fr))",gap:12},children:[e.jsxs("div",{style:{display:"grid",gap:5,alignContent:"start"},children:[e.jsx(A,{children:"Outputs"}),d.length>0?e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:d.map(a=>e.jsx(re,{children:a},a))}):e.jsx("div",{style:{fontSize:11,opacity:.6},children:"No declared outputs yet."})]}),e.jsxs("div",{style:{display:"grid",gap:5,alignContent:"start"},children:[e.jsx(A,{children:"Answers questions like"}),h.length>0?e.jsx("ul",{style:{margin:0,padding:"0 0 0 16px",display:"grid",gap:3},children:h.slice(0,3).map(a=>e.jsx("li",{style:{fontSize:11.5,opacity:.82,lineHeight:1.45},children:a},a))}):e.jsx("div",{style:{fontSize:11,opacity:.6},children:"No example questions yet."})]})]}),e.jsx(te,{verdict:t}),e.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[e.jsxs("button",{type:"button",onClick:()=>void i(),disabled:z,style:{...pe,opacity:z?.65:1},children:[z?e.jsx(N,{size:13,className:"spin"}):e.jsx(U,{size:13}),z?"Opening…":"Open in Block Studio"]}),e.jsxs("button",{type:"button",onClick:x,style:ge,children:[e.jsx(M,{size:13})," Refine with AI"]})]}),b?e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:11.5,color:"var(--status-error, #cf222e)"},children:[e.jsx(B,{size:13})," ",b]}):null]})}):null]})}function te({verdict:s}){const c=!!(s!=null&&s.ready&&s.blocking.length===0),o=s?[...s.blocking,...s.warnings]:[];return e.jsxs("div",{style:{display:"grid",gap:5},children:[e.jsx(A,{children:"What's missing to certify"}),c?e.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:6,fontSize:12,color:"var(--status-success, #1f883d)"},children:[e.jsx(K,{size:14})," Grain, outputs, and context are set."]}):e.jsxs("div",{style:{display:"grid",gap:4},children:[e.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:6,fontSize:12,color:"var(--status-warning, #9a6700)"},children:[e.jsx(B,{size:14})," Needs an owner and passing tests before it can be certified."]}),o.length>0?e.jsx("ul",{style:{margin:0,padding:"0 0 0 16px",display:"grid",gap:2},children:o.map(y=>e.jsx("li",{style:{fontSize:11,opacity:.78,lineHeight:1.4},children:y},y))}):s?null:e.jsx("div",{style:{fontSize:11,opacity:.6},children:"Expand to load the Certifier verdict."})]})]})}function A({children:s}){return e.jsx("div",{style:{fontSize:10,fontWeight:800,letterSpacing:"0.05em",textTransform:"uppercase",opacity:.55},children:s})}function re({children:s}){return e.jsx("span",{style:{fontSize:11,fontWeight:600,padding:"3px 8px",borderRadius:6,border:"1px solid var(--border-color, rgba(0,0,0,0.12))",background:"var(--surface-hover, rgba(0,0,0,0.04))",fontFamily:"var(--font-mono, monospace)"},children:s})}function S({label:s,value:c,tone:o}){return e.jsxs("div",{style:{...xe,borderTop:`2px solid ${o==="success"?"var(--status-success, #1f883d)":"var(--border-color, rgba(0,0,0,0.10))"}`},children:[e.jsx("div",{style:{fontSize:11,opacity:.62},children:s}),e.jsx("div",{style:{fontSize:24,fontWeight:800},children:c})]})}function ne({children:s}){return e.jsx("span",{style:{fontSize:10,padding:"2px 7px",borderRadius:4,background:"var(--surface-hover, rgba(0,0,0,0.06))",opacity:.82},children:s})}const ie={border:"1px solid var(--border-color, rgba(0,0,0,0.10))",borderRadius:8,background:"var(--surface, rgba(0,0,0,0.02))",padding:12,display:"grid",gap:8},le={display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,paddingBottom:6,borderBottom:"1px solid var(--border-color, rgba(0,0,0,0.08))"},oe={width:"100%",border:"1px solid var(--border-color, rgba(0,0,0,0.10))",borderLeft:"3px solid var(--status-warning, #9a6700)",borderRadius:7,background:"var(--surface, rgba(0,0,0,0.02))",padding:10,display:"grid",gap:10},ae={borderTop:"1px solid var(--border-color, rgba(0,0,0,0.08))",paddingTop:10,marginLeft:26,display:"grid",gap:12},de={display:"inline-flex",alignItems:"center",gap:4,padding:"4px 8px",borderRadius:6,border:"1px solid var(--border-color, rgba(0,0,0,0.12))",background:"transparent",color:"inherit",fontSize:11,fontWeight:600,cursor:"pointer",whiteSpace:"nowrap",alignSelf:"start"},ce={margin:0,border:"1px solid var(--border-color, rgba(0,0,0,0.12))",borderRadius:8,background:"var(--color-bg-primary, rgba(0,0,0,0.03))",padding:"9px 11px",overflow:"auto",maxHeight:280},pe={display:"inline-flex",alignItems:"center",gap:6,padding:"6px 11px",borderRadius:6,border:"1px solid var(--color-accent-blue, #6b5dd3)",background:"var(--color-accent-blue, #6b5dd3)",color:"#fff",fontSize:12,fontWeight:650,cursor:"pointer",whiteSpace:"nowrap"},ge={display:"inline-flex",alignItems:"center",gap:6,padding:"6px 11px",borderRadius:6,border:"1px solid var(--border-color, rgba(0,0,0,0.12))",background:"transparent",color:"inherit",fontSize:12,fontWeight:600,cursor:"pointer",whiteSpace:"nowrap"},ue={display:"inline-flex",alignItems:"center",gap:6,padding:"7px 13px",borderRadius:7,border:"1px solid var(--color-clay, #b4593f)",background:"var(--color-clay, #b4593f)",color:"#fff",fontSize:12.5,fontWeight:700,cursor:"pointer",whiteSpace:"nowrap"},xe={border:"1px solid var(--border-color, rgba(0,0,0,0.10))",borderRadius:7,background:"var(--surface, rgba(0,0,0,0.02))",padding:12},ye={display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,border:"1px solid var(--border-color, rgba(0,0,0,0.10))",borderRadius:8,background:"var(--surface, rgba(0,0,0,0.02))",padding:"10px 12px"},fe={display:"inline-flex",alignItems:"center",gap:5,padding:"6px 11px",borderRadius:6,border:"1px solid var(--border-color, rgba(0,0,0,0.12))",background:"var(--surface, transparent)",color:"inherit",fontSize:12,fontWeight:600,cursor:"pointer",whiteSpace:"nowrap"},he={display:"inline-flex",alignItems:"center",gap:6,padding:"7px 13px",borderRadius:6,border:"1px solid var(--status-success, #1f883d)",background:"var(--status-success, #1f883d)",color:"#fff",fontSize:12,fontWeight:650,cursor:"pointer",whiteSpace:"nowrap"},$={display:"inline-flex",alignItems:"center",gap:5,padding:"6px 11px",borderRadius:6,border:"1px solid var(--border-color, rgba(0,0,0,0.12))",background:"transparent",color:"inherit",fontSize:12,cursor:"pointer"},E={border:"1px dashed var(--border-color, rgba(0,0,0,0.16))",borderRadius:8,padding:24,fontSize:13,opacity:.85};export{Ce as ReadinessPage};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{g as ne,u as ae,t as de,r as a,a as S,j as t,Z as le,_ as pe,$ as ce,a0 as fe,k as ue,S as ge}from"./index-DU7j3Sqk.js";import{A as xe}from"./arrow-left-BZHDcWHR.js";import{A as ye}from"./arrow-right-DlM1pC3_.js";import"./react-CRB3T2We.js";/**
|
|
2
|
+
* @license lucide-react v0.563.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const me=[["path",{d:"M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719",key:"1sd12s"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["path",{d:"M12 17h.01",key:"p32p05"}]],Se=ne("message-circle-question-mark",me);function he(e){return Object.values(e).some(p=>{if(!p||typeof p!="object")return!1;const c=p,l=String(c.driver??c.type??"").toLowerCase();if(l!=="duckdb")return!!l;const i=String(c.filepath??c.path??"").trim();return!!(i&&i!==":memory:")})}function ve(e){return e?`${e.label}${e.model?` · ${e.model}`:""}`:"No AI provider configured."}function Ce({launch:e,onAcknowledged:p}){const{state:c,dispatch:l}=ae(),i=de[c.themeMode],[s,r]=a.useState(1),[R,X]=a.useState(!0),[h,z]=a.useState("missing"),[v,$]=a.useState("missing"),[x,B]=a.useState("missing"),[P,T]=a.useState("Choose a local dbt project or Git repository."),[k,M]=a.useState("Import a dbt profile or enter warehouse credentials."),[L,O]=a.useState(null),[m,E]=a.useState(!1),[u,W]=a.useState(!1),[Y,I]=a.useState(!(e!=null&&e.requiresDbtReapply)),[_,w]=a.useState(null),d=!!((e==null?void 0:e.reason)==="version_upgrade"&&e.requiresDbtReapply&&!Y);a.useEffect(()=>{I(!(e!=null&&e.requiresDbtReapply)),w(null),e!=null&&e.requiresDbtReapply&&r(1)},[e==null?void 0:e.requiresDbtReapply,e==null?void 0:e.version]),a.useEffect(()=>{let o=!0;return Promise.all([S.getOnboardingStatus().catch(()=>null),S.getBlockStudioDbtStatus().catch(()=>null),S.getConnections().catch(()=>null),S.getProviderSettings().catch(()=>null)]).then(([n,g,b,y])=>{var U,V,G,K,Z,J;if(!o)return;if(((U=n==null?void 0:n.dbt)!=null&&U.configured||g!=null&&g.configured&&g.artifacts.manifest.exists)&&(z(((V=n==null?void 0:n.modeling)==null?void 0:V.snapshotState)==="ready"?"passed":"configured"),T(((G=n==null?void 0:n.preparation)==null?void 0:G.message)||((K=n==null?void 0:n.dbt)==null?void 0:K.repoUrl)||((Z=n==null?void 0:n.dbt)==null?void 0:Z.projectDir)||(g==null?void 0:g.projectPath)||"dbt project configured")),b&&he(b.connections??{})){$("configured");const f=(J=b.connections)==null?void 0:J[b.default],re=f&&typeof f=="object"?String(f.driver??f.type??"Database"):"Database";M(`${re} configured — test to verify reachability.`)}const H=(y==null?void 0:y.providers.find(f=>f.active&&f.configured))??(y==null?void 0:y.providers.find(f=>f.enabled&&f.configured))??null;H&&(O(H),B("configured"))}).finally(()=>o&&X(!1)),()=>{o=!1}},[]);const q=async()=>{W(!0),w(null);try{return await S.acknowledgeSetupLaunch(),p==null||p(),!0}catch(o){return w(o instanceof Error?o.message:String(o)),!1}finally{W(!1)}},ee=()=>{u||d||q().then(o=>{o&&l({type:"CLOSE_SETUP"})})},j=o=>{u||d||q().then(n=>{n&&(l({type:"SET_MAIN_VIEW",view:o}),o==="notebook"&&l({type:"OPEN_NEW_NOTEBOOK_MODAL"}),l({type:"CLOSE_SETUP"}))})},te=o=>{I(!0),z(o.readiness==="ready"?"passed":"configured"),T(o.readinessDetail||`${o.name} · ${o.summary}`)},ie=o=>{E(!1),B("passed"),O(o)},se=a.useMemo(()=>R?"Loading existing project-local configuration…":s===1?d?`Required for DQL ${e==null?void 0:e.version}: Preview and Reapply the prefilled dbt project.`:h==="missing"?"Preview before applying; existing dbt settings stay untouched.":`${h==="passed"?"Ready":"Configured"} · ${P}`:s===2?v==="passed"?`Test passed · ${k}`:v==="configured"?k:"A failed test rolls back to the previous connection.":s===3?m?"AI skipped · limited-AI mode remains available.":x==="missing"?"Optional · skip for now or configure a provider.":`${x==="passed"?"Test passed":"Configured"} · ${ve(L)}`:"Setup complete",[L,m,x,k,v,e==null?void 0:e.version,R,P,h,d,s]),Q=i.textSecondary,N={display:"inline-flex",alignItems:"center",gap:7,height:34,padding:"0 16px",borderRadius:8,border:"none",background:i.accent,color:"#fff",fontSize:12.5,fontWeight:700,cursor:"pointer",fontFamily:i.font},C={display:"inline-flex",alignItems:"center",gap:7,height:34,padding:"0 14px",borderRadius:8,border:`1px solid ${i.headerBorder}`,background:i.cellBg,color:i.textSecondary,fontSize:12.5,fontWeight:650,cursor:"pointer",fontFamily:i.font},oe=(e==null?void 0:e.reason)==="version_upgrade"?`DQL ${e.version} update review`:(e==null?void 0:e.reason)==="first_install"?`Welcome to DQL ${e.version}`:"Guided Setup",F=(e==null?void 0:e.reason)==="version_upgrade"?d?`DQL was updated${e.acknowledgedVersion?` from ${e.acknowledgedVersion}`:""} to ${e.version}. Reapply the prefilled dbt project to rebuild its OSS governed snapshot with this version. Saved paths and credentials remain unchanged until Apply succeeds.`:`DQL was updated${e.acknowledgedVersion?` from ${e.acknowledgedVersion}`:""} to ${e.version}. The dbt project was reapplied with this version; review the remaining saved connections before finishing.`:(e==null?void 0:e.reason)==="first_install"?`DQL ${e.version} is installed. Connect the project and database before entering the workspace; AI remains optional.`:null;return t.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":"Guided Setup",style:{position:"fixed",inset:0,zIndex:1e3,background:i.appBg,color:i.textPrimary,display:"flex",flexDirection:"column",fontFamily:i.font},children:[t.jsxs("header",{style:{height:54,flexShrink:0,borderBottom:`1px solid ${i.headerBorder}`,background:i.headerBg,display:"flex",alignItems:"center",gap:11,padding:"0 20px"},children:[t.jsx("span",{style:{width:29,height:29,borderRadius:7,background:"linear-gradient(135deg, #5b8cff 0%, #7c5cff 100%)",color:"#fff",display:"inline-flex",alignItems:"center",justifyContent:"center",fontFamily:i.fontMono,fontSize:10,fontWeight:800},children:"DQL"}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:13.5,fontWeight:700},children:oe}),t.jsx("div",{style:{fontSize:10.5,color:i.textMuted},children:"Project → Database → optional AI → Finish"})]}),t.jsxs("div",{style:{marginLeft:"auto",display:"flex",alignItems:"center",gap:10},children:[t.jsxs("span",{style:{fontSize:11.5,color:i.textMuted},children:["Step ",s," of 4"]}),t.jsx("div",{style:{display:"flex",gap:4},"aria-hidden":!0,children:[1,2,3,4].map(o=>t.jsx("span",{style:{width:23,height:4,borderRadius:999,background:o<=s?i.accent:i.pillBg}},o))})]})]}),t.jsx("main",{style:{flex:1,minHeight:0,overflow:"auto"},children:t.jsxs("div",{style:{width:"min(760px, calc(100% - 36px))",margin:"0 auto",padding:"26px 0 34px"},children:[F?t.jsx("div",{style:{marginBottom:18,border:"1px solid var(--status-info-border)",background:"var(--status-info-bg)",borderRadius:10,padding:"11px 13px",color:Q,fontSize:11.5,lineHeight:1.55},children:F}):null,s===1?t.jsx(D,{eyebrow:"Step 1 of 4",title:"Connect your dbt project",description:"Preview a local project or Git repository, then apply it only after the manifest is valid.",t:i,children:t.jsx(le,{compact:!0,reapplyRequired:d,onConfigured:te})}):null,s===2?t.jsx(D,{eyebrow:"Step 2 of 4",title:"Connect your database",description:"Use the same profile import, enterprise authentication fields, test, and rollback flow available in Settings.",t:i,children:t.jsx(pe,{variant:"setup",onConfigured:o=>{$("passed"),M(o)}})}):null,s===3?t.jsxs(D,{eyebrow:"Step 3 of 4",title:"Set up an AI provider",description:"Optional. AI powers governed Ask and assisted authoring; deterministic queries and non-AI product paths remain available without it.",badge:"Optional",t:i,children:[t.jsx(ce,{embedded:!0,includeMemory:!1,section:"providers",editorMode:"setup",onProviderConfigured:ie}),t.jsxs("div",{style:{border:"1px solid var(--status-info-border)",background:"var(--status-info-bg)",borderRadius:10,padding:"11px 13px",display:"flex",alignItems:"center",gap:12},children:[t.jsx("div",{style:{flex:1,fontSize:11.5,color:Q,lineHeight:1.5},children:"Continue in limited-AI mode and configure a provider later in Settings."}),t.jsx("button",{type:"button",onClick:()=>{E(!0),r(4)},style:C,children:"Skip AI for now"})]})]}):null,s===4?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:20},children:[t.jsxs("div",{style:{textAlign:"center"},children:[t.jsx("div",{style:{fontSize:11,fontWeight:750,letterSpacing:"0.06em",textTransform:"uppercase",color:i.accent},children:"Step 4 of 4 · Setup complete"}),t.jsx("h2",{style:{margin:"7px 0 0",fontSize:22,color:i.textPrimary},children:"Where do you want to start?"}),x==="missing"||m?t.jsx("div",{style:{fontSize:12,color:i.textMuted,marginTop:7},children:"AI is not configured. Deterministic and non-AI workflows remain available; return to Settings when you want governed Ask."}):null]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(190px, 1fr))",gap:11},children:[t.jsx(A,{icon:t.jsx(fe,{size:17}),title:"Build your domain",body:"Model entities, prove joins, and add governed context.",action:"Open Domains",onClick:()=>j("domains"),t:i,primary:!0}),t.jsx(A,{icon:t.jsx(Se,{size:17}),title:"Ask",body:x==="missing"||m?"Open Ask in limited mode; configure AI before a governed model answer.":"Ask a business question grounded in your governed context.",action:"Open Ask",onClick:()=>j("ask"),t:i}),t.jsx(A,{icon:t.jsx(ue,{size:17}),title:"Research notebook",body:"Work with SQL, DQL, and charts, then save reusable blocks.",action:"New notebook",onClick:()=>j("notebook"),t:i})]})]}):null]})}),t.jsxs("footer",{style:{flexShrink:0,minHeight:58,borderTop:`1px solid ${i.headerBorder}`,background:i.headerBg,display:"flex",alignItems:"center",gap:10,padding:"11px 22px"},children:[s>1?t.jsxs("button",{type:"button",onClick:()=>r(o=>Math.max(1,o-1)),style:C,children:[t.jsx(xe,{size:13})," Back"]}):null,t.jsx("div",{style:{flex:1}}),t.jsx("span",{style:{fontSize:11,color:i.textMuted,maxWidth:420,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:se}),_?t.jsx("span",{role:"alert",style:{fontSize:11,color:"var(--status-error)",maxWidth:320},children:_}):null,t.jsx("button",{type:"button",disabled:u||d,onClick:ee,style:{...C,opacity:u||d?.5:1,cursor:u||d?"not-allowed":"pointer"},children:u?"Saving review…":d?"Reapply required":(e==null?void 0:e.reason)==="version_upgrade"?"Close update review":h==="missing"&&v==="missing"?"Skip setup":"Close setup"}),s<4?t.jsxs("button",{type:"button",disabled:s===1&&d,onClick:()=>r(o=>Math.min(4,o+1)),style:{...N,opacity:s===1&&d?.5:1,cursor:s===1&&d?"not-allowed":"pointer"},children:[s===1?"Continue to database":s===2?"Continue to optional AI":"Continue to finish"," ",t.jsx(ye,{size:13})]}):t.jsxs("button",{type:"button",disabled:u,onClick:()=>j(x==="missing"||m?"domains":"ask"),style:{...N,opacity:u?.65:1},children:[t.jsx(ge,{size:13})," Finish setup"]})]})]})}function D({eyebrow:e,title:p,description:c,badge:l,children:i,t:s}){return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:17},children:[t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:750,letterSpacing:"0.06em",textTransform:"uppercase",color:s.accent},children:e}),t.jsxs("h2",{style:{margin:"6px 0 0",fontSize:21,fontWeight:750,color:s.textPrimary,display:"flex",alignItems:"center",gap:8},children:[p,l?t.jsx("span",{style:{border:`1px solid ${s.headerBorder}`,color:s.textMuted,borderRadius:999,padding:"2px 9px",fontSize:10,fontWeight:750},children:l}):null]}),t.jsx("div",{style:{marginTop:6,fontSize:12.5,color:s.textSecondary,lineHeight:1.55},children:c})]}),i]})}function A({icon:e,title:p,body:c,action:l,onClick:i,primary:s=!1,t:r}){return t.jsxs("button",{type:"button",onClick:i,style:{border:`1.5px solid ${s?r.accent:r.headerBorder}`,borderRadius:12,background:s?"var(--accent-dim)":r.cellBg,padding:17,textAlign:"left",cursor:"pointer",fontFamily:r.font,minHeight:170,display:"flex",flexDirection:"column"},children:[t.jsx("span",{style:{width:34,height:34,borderRadius:9,color:s?r.accent:r.textSecondary,background:s?r.cellBg:r.appBg,display:"inline-flex",alignItems:"center",justifyContent:"center"},children:e}),t.jsx("span",{style:{marginTop:12,fontSize:13.5,fontWeight:750,color:r.textPrimary},children:p}),t.jsx("span",{style:{marginTop:6,fontSize:11.5,color:r.textSecondary,lineHeight:1.5},children:c}),t.jsxs("span",{style:{marginTop:"auto",paddingTop:12,fontSize:11.5,fontWeight:700,color:s?r.accent:r.textSecondary},children:[l," →"]})]})}export{Ce as SetupOnboarding};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as c,aN as l}from"./index-DU7j3Sqk.js";const e={certified:{base:"Certified",tone:"success"},reviewed:{base:"Reviewed",tone:"info"},ai_generated:{base:"AI-Generated",tone:"warning"},insufficient_context:{base:"Insufficient-Context",tone:"neutral"},conflict:{base:"Conflict",tone:"error"}},s="insufficient_context";function d({state:t,qualifier:i,label:a}){if(!t)return null;const n=o[t]??o[s],r=i?`${n.label} · ${i}`:n.label;return c.jsx(l,{tone:n.tone,children:a??r})}const o={certified:{tone:e.certified.tone,label:e.certified.base},reviewed:{tone:e.reviewed.tone,label:e.reviewed.base},ai_generated:{tone:e.ai_generated.tone,label:e.ai_generated.base},insufficient_context:{tone:e.insufficient_context.tone,label:e.insufficient_context.base},conflict:{tone:e.conflict.tone,label:e.conflict.base},draft:{tone:"warning",label:"Draft"},pending:{tone:"warning",label:"Pending review"},review:{tone:"warning",label:"Review"},uncertified:{tone:"warning",label:"Uncertified"},deprecated:{tone:"neutral",label:"Deprecated"},no_answer:{tone:"error",label:"No answer"}};export{d as T};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import{g as Ae,r as p,a as ie,j as t,b as Ct,f as Ye,h as xe,aI as Ir,e as Je,L as Pe,aA as Br,aK as Qn,B as rt,d as Vn,u as zt,t as Gn,aL as Xe,z as Tr,A as $r,aM as Mr,q as Lr,S as Fe,ax as Kn,c as qt,aJ as Ze,P as Ue,D as Er,G as Un,aH as Vt,Y as Mt}from"./index-DU7j3Sqk.js";import{S as mt,R as en,d as Wr}from"./AgentAnswerCard-BJAnjaLA.js";import{S as Pr,F as et,d as tn,e as Fr,A as Nr,u as Dr}from"./usePersistedAgentThreadId-D6mtrJ-_.js";import{C as Hr}from"./AiBuildResult-Da7_Cn12.js";import{T as Lt}from"./triangle-alert-Cne6C2aG.js";import{U as Or}from"./user-round-DkzxN1xD.js";import{X as bt}from"./x-C6tsHUR7.js";import{P as Qr}from"./pencil-DwywbTqQ.js";import{L as tt}from"./list-tree-B9ZzGc4U.js";import{W as nn}from"./wrench-YeSpzZRt.js";import{A as Vr}from"./arrow-right-DlM1pC3_.js";import{C as Yn}from"./chevron-up-B_GfKE_F.js";/**
|
|
2
|
+
* @license lucide-react v0.563.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const Gr=[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]],Kr=Ae("archive",Gr);/**
|
|
7
|
+
* @license lucide-react v0.563.0 - ISC
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the ISC license.
|
|
10
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/const Ur=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],Yr=Ae("circle",Ur);/**
|
|
12
|
+
* @license lucide-react v0.563.0 - ISC
|
|
13
|
+
*
|
|
14
|
+
* This source code is licensed under the ISC license.
|
|
15
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
+
*/const Jr=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],Jn=Ae("copy",Jr);/**
|
|
17
|
+
* @license lucide-react v0.563.0 - ISC
|
|
18
|
+
*
|
|
19
|
+
* This source code is licensed under the ISC license.
|
|
20
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
+
*/const Xr=[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]],Zr=Ae("ellipsis",Xr);/**
|
|
22
|
+
* @license lucide-react v0.563.0 - ISC
|
|
23
|
+
*
|
|
24
|
+
* This source code is licensed under the ISC license.
|
|
25
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
+
*/const ei=[["path",{d:"M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5",key:"1gvzjb"}],["path",{d:"M9 18h6",key:"x1upvd"}],["path",{d:"M10 22h4",key:"ceow96"}]],vt=Ae("lightbulb",ei);/**
|
|
27
|
+
* @license lucide-react v0.563.0 - ISC
|
|
28
|
+
*
|
|
29
|
+
* This source code is licensed under the ISC license.
|
|
30
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
31
|
+
*/const ti=[["circle",{cx:"6",cy:"19",r:"3",key:"1kj8tv"}],["path",{d:"M9 19h8.5a3.5 3.5 0 0 0 0-7h-11a3.5 3.5 0 0 1 0-7H15",key:"1d8sl"}],["circle",{cx:"18",cy:"5",r:"3",key:"gq8acd"}]],Gt=Ae("route",ti);/**
|
|
32
|
+
* @license lucide-react v0.563.0 - ISC
|
|
33
|
+
*
|
|
34
|
+
* This source code is licensed under the ISC license.
|
|
35
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
36
|
+
*/const ni=[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]],rn=Ae("save",ni);/**
|
|
37
|
+
* @license lucide-react v0.563.0 - ISC
|
|
38
|
+
*
|
|
39
|
+
* This source code is licensed under the ISC license.
|
|
40
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
41
|
+
*/const ri=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],vn=Ae("square",ri);/**
|
|
42
|
+
* @license lucide-react v0.563.0 - ISC
|
|
43
|
+
*
|
|
44
|
+
* This source code is licensed under the ISC license.
|
|
45
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
46
|
+
*/const ii=[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]],si=Ae("zap",ii),Et=[{mode:"auto",label:"Auto",hint:"Adapts per question — fast for lookups, thorough for hard ones"},{mode:"low",label:"Low · fast",hint:"Fewer thinking tokens, skips extra verification"},{mode:"medium",label:"Medium · balanced",hint:"More thinking, still skips the heavy verification"},{mode:"high",label:"High · thorough",hint:"Most thinking, cross-checks the number — slower"}];function jn({t:e,value:n,onChange:r}){const[i,s]=p.useState(null),[o,a]=p.useState(!1),u=p.useRef(null);p.useEffect(()=>{let f=!1;return ie.getProviderSettings().then(({providers:l})=>{f||s(l.find(c=>c.active)??null)}).catch(()=>{}),()=>{f=!0}},[]),p.useEffect(()=>{if(!o)return;const f=l=>{u.current&&!u.current.contains(l.target)&&a(!1)};return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[o]);const d=Et.find(f=>f.mode===n)??Et[0],m=i?[i.label,i.model].filter(Boolean).join(" · "):null;return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[m?t.jsxs("span",{title:"Connected model",style:Sn(e),children:[t.jsx(Yr,{size:7,fill:e.success,color:e.success}),t.jsx("span",{style:{color:e.textSecondary},children:m})]}):null,t.jsxs("div",{ref:u,style:{position:"relative"},children:[t.jsxs("button",{type:"button",onClick:()=>a(f=>!f),title:"How hard the model thinks for this thread",style:{...Sn(e),cursor:"pointer"},children:[t.jsx(si,{size:12,color:e.textMuted}),t.jsxs("span",{style:{color:e.textSecondary},children:["Thinking: ",d.label]}),t.jsx(Ct,{size:12,color:e.textMuted})]}),o?t.jsx("div",{role:"menu",style:oi(e),children:Et.map(f=>{const l=f.mode===n;return t.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":l,onClick:()=>{r(f.mode),a(!1)},style:li(e,l),children:[t.jsxs("span",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[t.jsx("span",{style:{fontWeight:l?600:500,color:e.textPrimary},children:f.label}),l?t.jsx(Ye,{size:13,color:e.accent}):null]}),t.jsx("span",{style:{display:"block",fontSize:11,color:e.textMuted,marginTop:2},children:f.hint})]},f.mode)})}):null]})]})}function Sn(e){return{display:"inline-flex",alignItems:"center",gap:6,padding:"4px 9px",borderRadius:8,border:`1px solid ${e.btnBorder}`,background:e.btnBg,fontSize:12,lineHeight:1.2,whiteSpace:"nowrap"}}function oi(e){return{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:30,width:264,background:e.cellBg,border:`1px solid ${e.cellBorder}`,borderRadius:10,padding:4,boxShadow:"0 8px 24px rgba(0,0,0,0.18)"}}function li(e,n){return{display:"block",width:"100%",textAlign:"left",padding:"8px 10px",borderRadius:7,border:"none",background:n?e.pillBg:"transparent",cursor:"pointer"}}const ai={draft:"#8b949e",review:"#d29922",certified:"#3fb950",deprecated:"#f85149",pending_recertification:"#db6d28"},ci={queued:"#8b949e",generating:"#4c8dff",running:"#4c8dff",saving:"#4c8dff",saved:"#2ea043",ready:"#2ea043",blocked:"#f85149",needs_attention:"#d29922"},di={queued:"Queued",generating:"Generating",running:"Running",saving:"Saving",saved:"Saved",ready:"Ready",blocked:"Blocked",needs_attention:"Needs review",draft:"Draft",review:"In review",certified:"Certified",deprecated:"Deprecated",pending_recertification:"Recertify"},ui={draft:Qn,queued:Br,generating:Pe,running:Pe,saving:Pe,ready:Je,saved:Je,blocked:Lt,needs_attention:Lt,review:Ir,certified:xe,deprecated:Kr,pending_recertification:Lt},pi=new Set(["generating","running","saving"]);function fi(e){return ai[e]??ci[e]??"#8b949e"}function gi(e){return di[e]??e.charAt(0).toUpperCase()+e.slice(1).replace(/_/g," ")}function xi({status:e,t:n,label:r}){const i=fi(e),s=ui[e]??Qn,o=r??gi(e);return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:10,fontWeight:800,color:i,background:`${i}18`,border:`1px solid ${i}33`,borderRadius:999,padding:"2px 8px",fontFamily:n.font,textTransform:"uppercase",letterSpacing:"0.03em",whiteSpace:"nowrap"},children:[t.jsx(s,{size:11,strokeWidth:2.2,className:pi.has(e)?"spin":void 0}),o]})}function hi(e){const{t:n,name:r,status:i="draft",description:s,dql:o,sqlPreview:a,grain:u,outputs:d=[],dimensions:m=[],entities:f=[],examples:l=[],sourceTables:c=[],evidence:y=[],certifierVerdict:x,owner:v,actions:g}=e,[R,I]=p.useState(!1),[L,D]=p.useState(!1);return t.jsxs("section",{style:{border:`1px solid ${n.cellBorder}`,borderRadius:10,background:n.cellBg,padding:14,display:"grid",gap:10,fontFamily:n.font},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[t.jsx(rt,{size:14,strokeWidth:2,color:n.accent}),t.jsx("div",{style:{fontSize:13,fontWeight:850,color:n.textPrimary,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r}),t.jsx(xi,{status:i,t:n}),u?t.jsxs("span",{style:Kt(n),children:["grain ",u]}):null]}),s?t.jsx("div",{style:{fontSize:12,color:n.textSecondary,lineHeight:1.5},children:s}):null,o?t.jsx(wn,{open:R,onToggle:()=>I(z=>!z),label:"Governed DQL",t:n,lead:!0,children:t.jsx("pre",{style:kn(n),children:o})}):null,a?t.jsx(wn,{open:L,onToggle:()=>D(z=>!z),label:o?"Compiled SQL preview":"SQL this block will run",t:n,children:t.jsx("pre",{style:kn(n),children:a})}):null,t.jsx(Wt,{label:"Outputs",items:d,t:n}),t.jsx(Wt,{label:"Dimensions",items:m,t:n}),t.jsx(Wt,{label:"Entities",items:f,t:n}),l.length>0?t.jsxs("div",{style:{display:"grid",gap:5},children:[t.jsx(Xn,{t:n,children:"Answers questions like"}),t.jsx("ul",{style:{margin:0,padding:"0 0 0 16px",display:"grid",gap:3},children:l.slice(0,3).map(z=>t.jsx("li",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.45},children:z},z))})]}):null,c.length>0||y.length>0?t.jsxs("div",{style:{display:"grid",gap:6,border:`1px solid ${n.headerBorder}`,borderRadius:8,background:n.appBg,padding:10},children:[t.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:10.5,fontWeight:800,color:n.textSecondary,textTransform:"uppercase"},children:[t.jsx(xe,{size:12,color:n.accent})," Grounded on"]}),c.length>0?t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:c.map(z=>t.jsx("span",{style:Kt(n),children:z},z))}):null,y.slice(0,5).map((z,O)=>t.jsxs("div",{style:{border:`1px solid ${n.headerBorder}`,borderRadius:7,padding:8,background:n.cellBg},children:[t.jsx("div",{style:{fontSize:11,fontWeight:800,color:n.textSecondary,overflowWrap:"anywhere"},children:z.name}),t.jsxs("div",{style:{fontSize:10,color:n.textMuted,marginTop:3},children:[z.kind,z.reason?` · ${z.reason}`:""]}),z.description?t.jsx("div",{style:{fontSize:11,color:n.textMuted,lineHeight:1.35,marginTop:5},children:z.description}):null]},`${z.objectKey??z.name}-${O}`))]}):null,t.jsx(Hr,{t:n,verdict:x}),v?t.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:11,color:n.textMuted},children:[t.jsx(Or,{size:12,strokeWidth:2})," drafting as ",v]}):null,g?t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:g}):null]})}function wn({open:e,onToggle:n,label:r,t:i,lead:s,children:o}){return t.jsxs("div",{children:[t.jsxs("button",{type:"button",onClick:n,style:{display:"inline-flex",alignItems:"center",gap:5,border:"none",background:"transparent",cursor:"pointer",color:s?i.accent:i.textSecondary,fontSize:11.5,fontWeight:s?800:700,fontFamily:i.font,padding:0},children:[e?t.jsx(Ct,{size:13,strokeWidth:2}):t.jsx(Vn,{size:13,strokeWidth:2}),e?`Hide ${r.toLowerCase()}`:r]}),e?t.jsx("div",{style:{marginTop:7},children:o}):null]})}function Wt({label:e,items:n,t:r}){return n.length===0?null:t.jsxs("div",{style:{display:"grid",gap:5},children:[t.jsx(Xn,{t:r,children:e}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:n.map(i=>t.jsx("span",{style:Kt(r),children:i},i))})]})}function Xn({t:e,children:n}){return t.jsx("div",{style:{fontSize:10,fontWeight:800,letterSpacing:"0.05em",textTransform:"uppercase",color:e.textMuted},children:n})}function Kt(e){return{fontSize:10.5,fontWeight:700,color:e.textSecondary,background:e.pillBg,borderRadius:999,padding:"2px 8px",fontFamily:e.fontMono}}function kn(e){return{margin:0,fontFamily:e.fontMono,fontSize:11.5,whiteSpace:"pre-wrap",color:e.textSecondary,background:e.appBg,border:`1px solid ${e.headerBorder}`,borderRadius:7,padding:10,maxHeight:240,overflow:"auto"}}function Cn(){return t.jsx("span",{style:{color:"#ff7b72",marginLeft:2},children:"*"})}function Pt(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function yi(e){const n=new Set,r=/@(metric|dim)\(([^)]+)\)/gi;let i;for(;i=r.exec(e);)n.add(i[2].trim());return Array.from(n)}function zn({cell:e,onClose:n,onSaved:r,initialContent:i,initialName:s,initialDescription:o,initialTags:a,initialDomain:u,initialOwner:d}){var C;const{state:m,dispatch:f}=zt(),l=Gn[m.themeMode],c=p.useRef(null),[y,x]=p.useState(s||e.name||"new_block"),[v,g]=p.useState(u??""),[R,I]=p.useState(d??""),[L,D]=p.useState(o??m.notebookMetadata.description??""),[z,O]=p.useState((a??m.notebookMetadata.categories??[]).join(", ")),[B,E]=p.useState(i??e.content),[F,N]=p.useState(""),[T,b]=p.useState(""),[k,K]=p.useState([]),[W,V]=p.useState(!1),[U,Z]=p.useState(null),Y=p.useMemo(()=>yi(B),[B]),Q=p.useMemo(()=>z.split(",").map(S=>S.trim()).filter(Boolean),[z]),le=[{id:"has-name",label:"Block has name",severity:"error",passed:!!y.trim()},{id:"has-owner",label:"Block has owner",severity:"error",passed:!!R.trim()},{id:"has-description",label:"Description",severity:"warning",passed:!!L.trim()},{id:"has-domain",label:"Domain",severity:"warning",passed:!!v.trim()},{id:"has-tags",label:"Has at least one tag",severity:"warning",passed:Q.length>0},{id:"has-llm-context",label:"Has LLM context (for agents)",severity:"warning",passed:!!F.trim()}],G=le.some(S=>S.severity==="error"&&!S.passed);p.useEffect(()=>{var S;(S=c.current)==null||S.focus()},[]),p.useEffect(()=>{const S=te=>{te.key==="Escape"&&n()};return document.addEventListener("keydown",S),()=>document.removeEventListener("keydown",S)},[n]);const H=m.semanticLayer.domains,q=`${v.trim()?`blocks/${Pt(v)}/`:"blocks/"}${Pt(y)||"new-block"}.dql`,ee=async()=>{var S,te,ae;if(G){Z("Enter the block name and owner before saving.");return}if(!B.trim()){Z("Block content is required.");return}V(!0),Z(null);try{const ne=T.split(`
|
|
47
|
+
`).map(j=>j.trim()).filter(Boolean),He=k.map(j=>({question:j.question.trim(),sql:j.sql.trim()||void 0})).filter(j=>j.question),ve=await ie.saveAsBlock({cellId:e.id,notebookPath:((S=m.activeFile)==null?void 0:S.path)??null,name:y.trim(),domain:v.trim()||void 0,owner:R.trim()||void 0,content:B,description:L.trim()||void 0,tags:Q,metricRefs:Y,llmContext:F.trim()||void 0,examples:He.length>0?He:void 0,invariants:ne.length>0?ne:void 0,reviewRequired:!!((te=e.datasetRefs)!=null&&te.length),datasetRefs:e.datasetRefs,lineage:(ae=e.dqlArtifact)==null?void 0:ae.lineage}),Re={name:`${Pt(y)||"new-block"}.dql`,path:ve.path,type:"block",folder:"blocks"};m.files.some(j=>j.path===ve.path)||f({type:"FILE_ADDED",file:Re});const we=await ie.openBlockStudio(ve.path);f({type:"OPEN_BLOCK_STUDIO",file:Re,payload:we}),r==null||r({...ve,name:y.trim()}),n()}catch(ne){Z(ne instanceof Error?ne.message:String(ne))}finally{V(!1)}},$={width:"100%",background:l.inputBg,border:`1px solid ${U?l.error:l.inputBorder}`,borderRadius:6,color:l.textPrimary,fontSize:13,fontFamily:l.font,padding:"8px 12px",outline:"none",boxSizing:"border-box"};return t.jsx("div",{onClick:S=>{S.target===S.currentTarget&&n()},style:{position:"fixed",inset:0,background:l.modalOverlay,display:"flex",alignItems:"center",justifyContent:"center",zIndex:1100,backdropFilter:"blur(4px)"},children:t.jsxs("div",{style:{width:760,maxWidth:"calc(100vw - 48px)",maxHeight:"calc(100vh - 48px)",overflow:"auto",background:l.modalBg,border:`1px solid ${l.cellBorder}`,borderRadius:12,boxShadow:"0 20px 60px rgba(0,0,0,0.5)"},children:[t.jsxs("div",{style:{padding:"20px 24px 0",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsx("h2",{style:{margin:0,fontSize:16,fontWeight:600,color:l.textPrimary,fontFamily:l.font},children:"Save as Block"}),t.jsx("button",{onClick:n,style:{background:"transparent",border:"none",color:l.textMuted,cursor:"pointer",fontSize:18},children:"×"})]}),t.jsxs("div",{style:{padding:"20px 24px 24px",display:"flex",flexDirection:"column",gap:16},children:[t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsxs("label",{style:{fontSize:12,color:l.textSecondary,fontFamily:l.font},children:["Block Name ",t.jsx(Cn,{})]}),t.jsx("input",{ref:c,value:y,onChange:S=>x(S.target.value),style:$})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsx("label",{style:{fontSize:12,color:l.textSecondary,fontFamily:l.font},children:"Domain"}),t.jsx("input",{value:v,onChange:S=>g(S.target.value),list:"semantic-domain-options",style:$,placeholder:"finance"}),t.jsx("datalist",{id:"semantic-domain-options",children:H.map(S=>t.jsx("option",{value:S},S))})]})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsxs("label",{style:{fontSize:12,color:l.textSecondary,fontFamily:l.font},children:["Owner ",t.jsx(Cn,{})]}),t.jsx("input",{value:R,onChange:S=>I(S.target.value),style:$,placeholder:"data-platform@company.com"})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsx("label",{style:{fontSize:12,color:l.textSecondary,fontFamily:l.font},children:"Tags"}),t.jsx("input",{value:z,onChange:S=>O(S.target.value),style:$,placeholder:"revenue, dashboard"})]})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsx("label",{style:{fontSize:12,color:l.textSecondary,fontFamily:l.font},children:"Description"}),t.jsx("input",{value:L,onChange:S=>D(S.target.value),style:$})]}),t.jsxs("details",{style:{border:`1px solid ${l.cellBorder}`,borderRadius:6,padding:"8px 12px"},children:[t.jsx("summary",{style:{fontSize:12,fontWeight:600,color:l.textSecondary,fontFamily:l.font,cursor:"pointer"},children:"Agent-facing metadata (optional — helps AI tools ground answers on this block)"}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10,paddingTop:10},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsx("label",{style:{fontSize:12,color:l.textSecondary,fontFamily:l.font},children:"How should an AI describe this block?"}),t.jsx("textarea",{value:F,onChange:S=>N(S.target.value),rows:3,placeholder:'One paragraph. E.g. "Monthly revenue recognized from closed-won deals, grouped by billing month. Excludes refunds."',style:{...$,fontFamily:l.font,lineHeight:1.5,resize:"vertical"}})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsx("label",{style:{fontSize:12,color:l.textSecondary,fontFamily:l.font},children:"Invariants (one per line)"}),t.jsx("textarea",{value:T,onChange:S=>b(S.target.value),rows:2,placeholder:`Revenue is never negative
|
|
48
|
+
Each row is a unique month`,style:{...$,fontFamily:l.fontMono,lineHeight:1.5,resize:"vertical"}})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsx("label",{style:{fontSize:12,color:l.textSecondary,fontFamily:l.font},children:"Example questions (grounding for chat cells)"}),k.map((S,te)=>t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr auto",gap:6},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[t.jsx("input",{value:S.question,onChange:ae=>{const ne=[...k];ne[te]={...ne[te],question:ae.target.value},K(ne)},placeholder:"What was revenue last month?",style:$}),t.jsx("input",{value:S.sql,onChange:ae=>{const ne=[...k];ne[te]={...ne[te],sql:ae.target.value},K(ne)},placeholder:"Optional SQL snippet",style:{...$,fontFamily:l.fontMono,fontSize:12}})]}),t.jsx("button",{type:"button",onClick:()=>K(k.filter((ae,ne)=>ne!==te)),style:{background:"transparent",border:`1px solid ${l.cellBorder}`,borderRadius:6,color:l.textMuted,cursor:"pointer",fontSize:12,padding:"0 10px"},children:"×"})]},te)),t.jsx("button",{type:"button",onClick:()=>K([...k,{question:"",sql:""}]),style:{alignSelf:"flex-start",background:l.btnBg,border:`1px solid ${l.btnBorder}`,borderRadius:6,color:l.textSecondary,cursor:"pointer",fontSize:12,fontFamily:l.font,padding:"4px 10px"},children:"+ Add example"})]})]})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6,padding:"10px 12px",background:l.pillBg,borderRadius:6,border:`1px solid ${l.cellBorder}`},children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:l.textSecondary,fontFamily:l.font,letterSpacing:"0.06em",textTransform:"uppercase"},children:"Governance checks"}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:le.map(S=>{const te=S.passed?"#3fb950":S.severity==="error"?"#ff7b72":"#e3b341",ae=S.passed?"✓":S.severity==="error"?"✕":"!";return t.jsxs("span",{title:S.passed?`${S.label} — passed`:`${S.label} — ${S.severity}`,style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,fontFamily:l.font,color:te,background:`${te}18`,border:`1px solid ${te}55`,borderRadius:999,padding:"2px 10px"},children:[t.jsx("span",{style:{fontWeight:700},children:ae}),S.label]},S.id)})})]}),t.jsx("div",{style:{fontSize:12,color:l.textMuted,fontFamily:l.fontMono,padding:"8px 12px",background:l.pillBg,borderRadius:6},children:q}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsx("label",{style:{fontSize:12,color:l.textSecondary,fontFamily:l.font},children:"Content Preview"}),t.jsx("textarea",{value:B,onChange:S=>E(S.target.value),style:{...$,minHeight:220,resize:"vertical",fontFamily:l.fontMono,lineHeight:1.5}})]}),Y.length>0&&t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6,padding:"10px 12px",background:l.pillBg,borderRadius:6},children:[t.jsx("span",{style:{fontSize:11,color:l.textMuted,fontFamily:l.font},children:"Detected semantic refs:"}),Y.map(S=>t.jsx("span",{style:{fontSize:11,color:l.accent,fontFamily:l.fontMono,background:`${l.accent}18`,borderRadius:999,padding:"2px 8px"},children:S},S))]}),U&&t.jsx("div",{style:{fontSize:12,color:l.error,fontFamily:l.font},children:U})]}),t.jsxs("div",{style:{padding:"14px 24px",borderTop:`1px solid ${l.cellBorder}`,display:"flex",justifyContent:"flex-end",gap:10},children:[t.jsx("span",{style:{fontSize:11.5,color:l.textMuted,marginRight:"auto",alignSelf:"center"},children:(C=e.datasetRefs)!=null&&C.length?"This analysis uses imported or staged data, so it will be saved as a review-required draft. Certification requires project-controlled, contracted, tested, reproducible sources.":"DQL will certify this block now when its local checks pass; otherwise it is saved as a draft."}),t.jsx("button",{onClick:n,style:{background:l.btnBg,border:`1px solid ${l.btnBorder}`,borderRadius:6,color:l.textSecondary,cursor:"pointer",fontSize:13,fontFamily:l.font,padding:"7px 16px"},children:"Cancel"}),t.jsx("button",{onClick:ee,disabled:W||G,title:G?"Fix governance errors to enable Save":void 0,style:{background:l.accent,border:`1px solid ${l.accent}`,borderRadius:6,color:"#fff",cursor:W||G?"not-allowed":"pointer",fontSize:13,fontFamily:l.font,padding:"7px 20px",opacity:W||G?.5:1},children:W?"Saving & checking…":"Save block"})]})]})})}function Zn(e){return e.policy==="dynamic"||e.policy==="optional"}function mi({parameters:e,values:n,onChange:r,onReset:i,t:s,includeNonRuntime:o=!1,card:a=!1}){const u=e.filter(d=>o||Zn(d));return u.length===0?null:t.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(170px, 1fr))",gap:8},children:u.map(d=>{const m=Object.prototype.hasOwnProperty.call(n,d.name),f=m?n[d.name]:d.default,l=y=>r(d.name,y),c=d.type==="boolean"?t.jsxs("select",{"aria-label":d.name,value:String(f??""),onChange:y=>l(y.target.value),style:qn(s),children:[t.jsx("option",{value:"",children:"Select…"}),t.jsx("option",{value:"true",children:"True"}),t.jsx("option",{value:"false",children:"False"})]}):t.jsx("input",{"aria-label":d.name,type:d.type==="number"?"number":d.type==="date"?"date":"text",value:Array.isArray(f)?f.join(", "):f==null?"":String(f),placeholder:d.type.endsWith("[]")?"Comma-separated values":d.required?"Required value":"Use default",onChange:y=>l(y.target.value),style:qn(s)});return t.jsxs("label",{style:{display:"grid",gap:4,minWidth:0,...a?{padding:9,border:`1px solid ${s.cellBorder}`,borderRadius:7,background:s.appBg}:{}},children:[t.jsxs("span",{style:{display:"flex",gap:5,alignItems:"center",fontSize:10.5,fontWeight:750,color:s.textSecondary},children:[bi(d.name),d.required?t.jsx("span",{style:{color:s.error},children:"*"}):null]}),c,t.jsxs("span",{style:{display:"flex",alignItems:"center",gap:5,minHeight:14,fontSize:9.5,color:s.textMuted},children:[t.jsxs("span",{children:[d.type,o?` · ${d.policy}`:""]}),m&&i?t.jsx("button",{type:"button",onClick:()=>i(d.name),style:{marginLeft:"auto",border:0,padding:0,background:"transparent",color:s.accent,fontSize:9.5,cursor:"pointer"},children:"Reset"}):null]})]},d.name)})})}function bi(e){return e.replace(/[_-]+/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function qn(e){return{width:"100%",minWidth:0,boxSizing:"border-box",background:e.inputBg,border:`1px solid ${e.inputBorder}`,borderRadius:5,color:e.textPrimary,padding:"5px 7px",fontSize:11,fontFamily:e.font}}function vi(e){const n=e.filter(o=>o.kind==="run").map(ji).filter(o=>!!o).slice(-6);if(n.length===0)return;const r=[...n].reverse().find(o=>{var a;return(a=o.result)==null?void 0:a.columns.length})??n[n.length-1],i=r.result,s=er(An(r));return Ut({activeSurface:"notebook",conversationStateVersion:1,activeTurnId:r.id,activeTopic:r.question,conversationSummary:qi(n),turns:n,sourceAnswerId:r.id,sourceCertifiedBlock:r.sourceCertifiedBlock,sourceQuestion:r.question,sourceAnswerSummary:r.answerSummary,answerContract:An(r),dqlArtifact:r.dqlArtifact,cascade:r.cascade,resultColumns:i==null?void 0:i.columns,resultRowsSample:i==null?void 0:i.rowsSample,resultDimensionValues:i==null?void 0:i.dimensionValues,outputColumns:i==null?void 0:i.columns,requestedFilters:r.requestedFilters??Qe(s==null?void 0:s.filters),requestedDimensions:r.requestedDimensions??Qe(s==null?void 0:s.dimensions),priorLimit:r.topN??tr(s),priorMeasures:r.requestedMeasures??(i==null?void 0:i.measureColumns),contextPackId:r.contextPackId,trustLabel:r.trustLabel,reviewStatus:r.reviewStatus,certification:r.certification,route:r.route,sourceSql:r.sourceSql,updatedAt:r.completedAt})}function ji(e){var l,c,y,x;const n=e.run.artifacts.find(v=>v.kind==="answer")??e.run.artifacts.find(v=>v.kind==="research_run")??e.run.artifacts[0],r=ue(n==null?void 0:n.payload),i=Si(r),s=Ri(i),o=Array.isArray(i==null?void 0:i.rows)?i.rows.filter(v=>!!(v&&typeof v=="object"&&!Array.isArray(v))).slice(0,24):[],a=((l=ue(r==null?void 0:r.contextPack))==null?void 0:l.questionPlan)??(r==null?void 0:r.analysisPlan),u=er(a),d=Ii(s,o),m=Ai(u,s),f=re(r==null?void 0:r.sourceCertifiedBlock)??((n==null?void 0:n.kind)==="answer"?re(n.ref):void 0)??re((c=ue(r==null?void 0:r.block))==null?void 0:c.name);return Ut({id:e.run.id,question:e.run.question,answerSummary:e.run.answer??e.run.summary,completedAt:e.run.completedAt,artifactKind:n==null?void 0:n.kind,sourceCertifiedBlock:f,route:re((y=ue(r==null?void 0:r.route))==null?void 0:y.label)??re((x=ue(r==null?void 0:r.route))==null?void 0:x.tier),trustLabel:re(r==null?void 0:r.trustLabel),reviewStatus:re(r==null?void 0:r.reviewStatus),certification:re(r==null?void 0:r.certification),contextPackId:re(r==null?void 0:r.contextPackId),requestedFilters:Qe(u==null?void 0:u.filters),requestedDimensions:Qe(u==null?void 0:u.dimensions),requestedMeasures:Qe(u==null?void 0:u.measures),answerContract:a,dqlArtifact:Ci(r),cascade:zi(r),topN:tr(u),result:s.length>0||o.length>0?Ut({columns:s,rowsSample:o,dimensionValues:d,measureColumns:m,rowCount:wi(i)}):void 0,sourceSql:ki(r,i)})}function An(e){return e.answerContract}function er(e){const n=ue(e);return ue(n==null?void 0:n.requestedShape)}function Si(e){const n=ue(e==null?void 0:e.researchRun),r=ue(e==null?void 0:e.result);return[e==null?void 0:e.result,e==null?void 0:e.resultPreview,n==null?void 0:n.resultPreview,n==null?void 0:n.result,r==null?void 0:r.result].map(ue).filter(s=>!!(s&&(Array.isArray(s.rows)||Array.isArray(s.columns)))).sort((s,o)=>Rn(o)-Rn(s))[0]}function Rn(e){const n=Array.isArray(e.rows)?e.rows.length:0,r=typeof e.rowCount=="number"&&Number.isFinite(e.rowCount)?e.rowCount:0;return n*1e5+r}function wi(e){const n=e==null?void 0:e.rowCount;return typeof n=="number"&&Number.isFinite(n)?n:Array.isArray(e==null?void 0:e.rows)?e.rows.length:void 0}function ki(e,n){var r,i;return re(e==null?void 0:e.proposedSql)??re(e==null?void 0:e.sql)??re(n==null?void 0:n.sql)??re((r=ue(e==null?void 0:e.query))==null?void 0:r.sql)??re((i=ue(e==null?void 0:e.plan))==null?void 0:i.sql)}function Ci(e){var r,i;const n=Xe(e==null?void 0:e.dqlArtifact);return n?{...n,source:n.source.slice(0,3e3),filters:(r=n.filters)==null?void 0:r.filter(s=>s.values.length>0).slice(0,12).map(s=>({...s,values:s.values.slice(0,12)})),orderBy:(i=n.orderBy)==null?void 0:i.slice(0,8)}:void 0}function zi(e){const n=ue(e==null?void 0:e.cascade);if(!n)return;const r=re(n.terminalLane),i=re(n.routeTier);if(!(!r&&!i))return{terminalLane:r,routeTier:i,label:re(n.label),ref:re(n.ref),artifactKind:re(n.artifactKind),refusalCode:re(n.refusalCode),outcome:ue(n.outcome)}}function qi(e){const n=e.slice(-3).map(r=>{var o,a;const i=(o=r.result)==null?void 0:o.columns.slice(0,5).join(", "),s=(a=r.result)!=null&&a.dimensionValues?Object.entries(r.result.dimensionValues).slice(0,3).map(([u,d])=>`${u}: ${d.slice(0,3).join(", ")}`).join("; "):"";return[`Q: ${r.question}`,r.answerSummary?`A: ${r.answerSummary}`:"",i?`Columns: ${i}`:"",s?`Values: ${s}`:""].filter(Boolean).join(" | ")}).filter(Boolean);return n.length>0?n.join(`
|
|
49
|
+
`):void 0}function tr(e){const n=ue(e==null?void 0:e.topN),r=n==null?void 0:n.n;return typeof r=="number"&&Number.isFinite(r)&&r>0?r:void 0}function Ai(e,n){const r=[...Qe(e==null?void 0:e.measures)??[],...n.filter(s=>/\b(revenue|sales|amount|total|count|average|avg|sum|spend|cost|margin|profit|value|points?|score|quantity|units?|rate|volume)\b/i.test(s.replace(/_/g," ")))],i=Array.from(new Set(r.map(s=>s.trim()).filter(Boolean))).slice(0,12);return i.length>0?i:void 0}function ue(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function Ri(e){const r=(Array.isArray(e==null?void 0:e.columns)?e.columns:[]).map(_i).filter(o=>!!o),i=Array.isArray(e==null?void 0:e.rows)?e.rows.find(o=>o&&typeof o=="object"&&!Array.isArray(o)):void 0,s=i?Object.keys(i):[];return Array.from(new Set([...r,...s])).slice(0,32)}function Qe(e){if(!Array.isArray(e))return;const n=e.map(i=>typeof i=="string"?i.trim():"").filter(Boolean),r=Array.from(new Set(n)).slice(0,24);return r.length>0?r:void 0}function _i(e){if(typeof e=="string"&&e.trim())return e.trim();if(e&&typeof e=="object"){const n=e;return re(n.name)??re(n.field)??re(n.key)}}function Ii(e,n){const r=e.filter(s=>/\b(category|product|customer|account|user|segment|region|channel|type|name)\b/i.test(s.replace(/_/g," "))).slice(0,12),i={};for(const s of r){const o=[];for(const a of n){const u=ue(a),d=u==null?void 0:u[s],m=typeof d=="string"||typeof d=="number"?String(d).trim():"";if(!(!m||o.includes(m))&&(o.push(m),o.length>=24))break}o.length>0&&(i[Bi(s)]=o)}return Object.keys(i).length>0?i:void 0}function Bi(e){const n=e.toLowerCase();return n.includes("category")?"category":n.includes("product")?n.includes("name")?"product_name":"product":n.includes("customer")?n.includes("name")?"customer_name":"customer":n.includes("segment")?"segment":n.includes("region")?"region":n.includes("channel")?"channel":n.replace(/[^a-z0-9_]+/g,"_")}function re(e){return typeof e=="string"&&e.trim()?e.trim():void 0}function Ut(e){const n={};for(const[r,i]of Object.entries(e))i!=null&&(Array.isArray(i)&&i.length===0||typeof i=="object"&&!Array.isArray(i)&&Object.keys(i).length===0||(n[r]=i));return Object.keys(n).length>0?n:void 0}function Ti(e){return JSON.stringify([e.kind,e.name??null,e.source,e.persistence??null,e.parameters??[],Object.entries(e.parameterValues??{}).sort(([n],[r])=>n.localeCompare(r)),e.executionReceipt??null])}function nr(e,n){if(e.kind==="sql_block"){const s=new Map(n.columns.map(o=>[o.toLowerCase(),o]));return(e.filterableColumns??[]).flatMap(o=>{const a=s.get(o.column.toLowerCase());return a?[{column:a,field:o.predicateTarget,values:_n(n.rows.map(u=>u[a]))}]:[]})}if(e.kind!=="semantic_block"||e.persistence!=="transient")return[];const r=new Map(n.columns.map(s=>[s.toLowerCase(),s])),i=new Set((e.parameters??[]).flatMap(s=>{var o;return((o=s.binding)==null?void 0:o.kind)==="semantic_filter"?[s.binding.field.toLowerCase()]:[]}));return(e.dimensions??[]).flatMap(s=>{if(i.has(s.toLowerCase()))return[];const o=s.split(".").at(-1)??s,a=r.get(s.toLowerCase())??r.get(o.toLowerCase())??r.get(s.split(".").join("_").toLowerCase());if(!a)return[];const u=_n(n.rows.map(d=>d[a]));return[{column:a,field:s,values:u}]})}function $i(e,n,r,i){const s=nr(e,n).find(g=>g.column===r);if(!s)throw new Error(`"${r}" is not an available semantic result filter.`);if(i==null||String(i).trim()==="")throw new Error("Choose a default filter value before adding the input.");const o=new Set((e.parameters??[]).map(g=>g.name)),a=Mi(s.field.split(".").at(-1)??s.column);let u=a,d=2;for(;o.has(u);)u=`${a}_${d++}`;const m=Array.isArray(i)?i.map(String).join(", "):String(i),f=Tr(m,u);let l=$r(e.source,{name:u,type:f,required:!1,defaultText:m,policy:"dynamic"});l=Mr(l,u,s.field);const c=Lr(l).map(g=>{var R,I,L;return{...g,...((R=g.binding)==null?void 0:R.kind)==="semantic_filter"&&g.binding.field?{binding:{kind:"semantic_filter",field:g.binding.field,operator:g.binding.operator??"equals"}}:((I=g.binding)==null?void 0:I.kind)==="limit"?{binding:{kind:"limit"}}:((L=g.binding)==null?void 0:L.kind)==="sql_value"?{binding:{kind:"sql_value"}}:{binding:void 0}}}),{executionReceipt:y,compiledSql:x,...v}=e;return{artifact:{...v,source:l,parameters:c,parameterValues:{...e.parameterValues??{},[u]:i}},parameterName:u}}function _n(e){const n=new Set,r=[];for(const i of e){if(typeof i!="string"&&typeof i!="number"&&typeof i!="boolean")continue;const s=`${typeof i}:${String(i)}`;if(!n.has(s)&&(n.add(s),r.push(i),r.length>=50))break}return r}function Mi(e){const n=e.trim().toLowerCase().replace(/[^a-z0-9_]+/g,"_").replace(/^_+|_+$/g,"");return/^[a-z_][a-z0-9_]*$/.test(n)?n:"result_filter"}function rr(e){return e.map(n=>{var r;return n.kind==="user"?{role:"user",text:n.text}:{role:"assistant",text:((r=n.run.answer)==null?void 0:r.trim())||n.run.summary}}).slice(-12)}const sn="dql.agent.active-runs.v1",ir={conversation:"Chat",certified_answer:"Certified answer",semantic_answer:"Governed semantic answer",generated_answer:"Generated answer",research:"Research plan",sql_cell:"SQL cell",dql_block_draft:"DQL block draft",app_build:"App plan",clarify:"Clarify",blocked:"Blocked"};function Li({themeMode:e,title:n="AI Copilot",scopeHint:r="Auto routes to answer, research, SQL, block, or app",onClearScope:i,examplePrompts:s,emptyHint:o,notebookPath:a,selectedObject:u,workspaceContext:d,initialMode:m="auto",initialInput:f="",initialItems:l,onItemsChange:c,threadId:y,onThreadIdChange:x,audience:v="analyst",autoRun:g,onInsertSql:R,onInsertDql:I,onReplaceDql:L,onArtifactReady:D,onOpenBlock:z,onOpenResearch:O,onOpenApp:B,onRunningChange:E,answerFirstCards:F=!1,insertDqlActionLabel:N,replaceDqlActionLabel:T,askLayout:b=!1}){const k=Gn[e],K=p.useRef(void 0),[W,V]=p.useState(f),[U,Z]=p.useState(l??[]),[Y,Q]=p.useState([]),[le,G]=p.useState(""),[H,q]=p.useState(!1),[ee,$]=p.useState(null),[C,S]=p.useState(null),[te,ae]=p.useState(null),[ne,He]=p.useState(()=>Ei()),[ve,Re]=p.useState([]),[we,j]=p.useState(),ce=p.useCallback(h=>{He(h);try{window.localStorage.setItem(sr,h)}catch{}},[]),je=p.useRef(null),fn=p.useRef(f),gn=p.useRef(null),$e=p.useRef(null),me=p.useRef(null),Me=p.useRef(null),fe=p.useRef(null),_e=p.useRef(0),Se=d==null?void 0:d.executionTarget,xn=Se&&typeof Se=="object"&&!Array.isArray(Se)&&Se.target==="connection"&&typeof Se.connectionName=="string"?String(Se.connectionName):void 0,Cr=Se&&typeof Se=="object"&&!Array.isArray(Se)&&Se.target==="local";p.useEffect(()=>{let h=!1;return ie.getConnections().then(w=>{if(h)return;const _=Object.keys(w.connections??{}).sort((M,X)=>M.localeCompare(X));Re(_),j(or(_,w.default,xn))}).catch(()=>{h||(Re([]),j(void 0))}),()=>{h=!0}},[xn]);const hn=p.useCallback(h=>{j(h)},[]),[Ie,It]=p.useState(null),[ke,Oe]=p.useState(null),[zr,Bt]=p.useState(""),yn=p.useRef(null),ot=p.useRef(null);p.useEffect(()=>{!f||H||f!==fn.current&&(fn.current=f,V(f))},[f,H]);const qr=p.useMemo(()=>rr(U),[U]),lt=p.useRef(c);lt.current=c;const at=p.useRef(D);at.current=D,p.useEffect(()=>{var h;(h=lt.current)==null||h.call(lt,U)},[U]);const he=p.useRef(y),ct=p.useRef(x);ct.current=x;const Tt=p.useCallback((h,w)=>{var _;if(fe.current!==null&&(window.clearTimeout(fe.current),fe.current=null),Ft(h.id),me.current===h.id&&(me.current=null),Me.current=null,$(null),Q(h.events.slice(-8)),G(""),Z(M=>{if(M.some(se=>se.kind==="run"&&se.run.id===h.id))return M.map(se=>se.kind==="run"&&se.run.id===h.id?{...se,id:h.id,run:h}:se);const X=M.some(se=>se.kind==="user"&&se.text===w.question);return[...M,...X?[]:[{kind:"user",id:`${h.id}-question`,text:w.question}],{kind:"run",id:h.id,run:h}]}),h.route!=="certified_answer"){const M=pn(h);M&&((_=at.current)==null||_.call(at,M,h))}},[]),Ke=p.useCallback(h=>{fe.current!==null&&window.clearTimeout(fe.current);const w=++_e.current;me.current=h.id,Me.current=h,$(h),q(!0),G(""),Q([]);const _=async()=>{if(!(w!==_e.current||me.current!==h.id))try{const M=await ie.getAgentRunState(h.id);if(w!==_e.current||me.current!==h.id)return;if(M.lifecycleState==="terminal"){Tt(M.run,h),q(!1);return}Q(M.progress.events.slice(-8)),fe.current=window.setTimeout(()=>{_()},600)}catch{if(w!==_e.current||me.current!==h.id)return;fe.current=window.setTimeout(()=>{_()},1200)}};return _(),()=>{w===_e.current&&(_e.current+=1),fe.current!==null&&(window.clearTimeout(fe.current),fe.current=null)}},[Tt]),mn=p.useRef(!1);p.useEffect(()=>{if(!y||mn.current)return;mn.current=!0,he.current??(he.current=y);let h=!1;return ie.getAgentThread(y).then(({turns:w,runs:_})=>{h||w.length===0||Z(M=>{const X=M.filter(oe=>oe.kind==="run").length,se=lr(w,_);if(w.length>=X)return se;const ye=new Map(se.flatMap(oe=>oe.kind==="run"?[[oe.run.id,oe.run]]:[]));return M.map(oe=>oe.kind==="run"&&ye.has(oe.run.id)?{...oe,run:ye.get(oe.run.id)}:oe)})}).catch(()=>{!h&&he.current===y&&(he.current=void 0)}),()=>{h=!0}},[y]),p.useEffect(()=>{const h=$n(y??he.current);if(!(!h||$e.current))return Ke(h)},[Ke,y]),p.useEffect(()=>{const h=()=>{if(document.visibilityState!=="visible"||$e.current)return;const w=Me.current??$n(y??he.current);w&&Ke(w)};return document.addEventListener("visibilitychange",h),()=>document.removeEventListener("visibilitychange",h)},[Ke,y]);const Ce=async(h,w,_)=>{var xt;const M=(h??W).trim();if(!M||H)return;const X=w??K.current??m;K.current=void 0;const se={kind:"user",id:Fn("user"),text:M};Z(de=>[...de,se]),V(""),ae(null),q(!0),Q([]),G("");const ye=new AbortController;$e.current=ye;const oe=Fn("run");let ge={id:oe,question:M,threadId:he.current,startedAt:new Date().toISOString()};me.current=oe,Me.current=ge,$(ge),Tn(ge);let Le=!1,gt=!1;try{if(!he.current)try{const ze=await ie.createAgentThread({surface:b?"ask":typeof(d==null?void 0:d.surface)=="string"?d.surface:a?"notebook":"agent",title:M,...a?{notebookPath:a}:{}});he.current=ze.id,(xt=ct.current)==null||xt.call(ct,ze.id),ge={...ge,threadId:ze.id},Me.current=ge,$(ge),Tn(ge)}catch{}const de={question:M,..._?{selectedEvidenceId:_}:{},requestedMode:X,audience:v,selectedObject:u??(a?{kind:"notebook",path:a}:void 0),...Cr?{executionTarget:{target:"local"}}:we?{executionTarget:{target:"connection",connectionName:we}}:{},workspaceContext:{...d??{},...a?{notebookPath:a}:{}},conversationContext:vi(U),history:qr,thinkingMode:ne,runId:oe,...he.current?{threadId:he.current}:{}},_r=await ie.createAgentRunStream(de,ze=>{Le=!0,ze.kind==="event"?Q($t=>[...$t,ze.event].slice(-8)):ze.kind==="answer-delta"?G($t=>$t+ze.delta):Q(ze.run.events.slice(-8))},ye.signal);Tt(_r,ge)}catch(de){ye.signal.aborted||(ae(de instanceof Error?de.message:String(de)),V(M),Le?(gt=!0,Ke(ge)):(Ft(oe),me.current===oe&&(me.current=null),Me.current=null,$(null)))}finally{$e.current===ye&&($e.current=null),gt||q(!1)}},dt=()=>{Ce()},bn=()=>{var w;const h=me.current;h&&ie.cancelAgentRun(h).catch(()=>{}),(w=$e.current)==null||w.abort(),_e.current+=1,fe.current!==null&&window.clearTimeout(fe.current),Ft(h??""),me.current=null,Me.current=null,$(null),G(""),Q([]),q(!1),ae("Stopped. No answer or draft was saved.")},ut=p.useRef(E);ut.current=E,p.useEffect(()=>{var h;(h=ut.current)==null||h.call(ut,H)},[H]),p.useEffect(()=>{!(g!=null&&g.text)||H||gn.current!==g.nonce&&(gn.current=g.nonce,Ce(g.text,g.mode??m))},[g==null?void 0:g.nonce,g==null?void 0:g.text,g==null?void 0:g.mode,m,H]),p.useEffect(()=>()=>{var h;(h=$e.current)==null||h.abort(),_e.current+=1,fe.current!==null&&window.clearTimeout(fe.current)},[]);const pt={appId:typeof(d==null?void 0:d.appId)=="string"?d.appId:void 0,dashboardId:typeof(d==null?void 0:d.dashboardId)=="string"?d.dashboardId:void 0},ft=(h,w)=>{var _,M;if(w.id==="save-dql-block"){const X=Te(h),se=((_=X==null?void 0:X.source)==null?void 0:_.trim())??((M=De(h))==null?void 0:M.trim());if(!se){ae("This answer does not include a reusable DQL or SQL artifact yet.");return}S({runId:h.id,source:se,name:(X==null?void 0:X.name)??`${h.question.slice(0,48).trim()||"saved_answer"}`,dqlArtifact:X});return}if(w.id==="research-deeper"){Ce(h.question,"research");return}if(w.id.startsWith("suggest-question")){Ce(w.label,"auto");return}K.current=os(w.route),V(ls(h,w.route)),requestAnimationFrame(()=>{var X;return(X=je.current)==null?void 0:X.focus()})},Ar=p.useCallback((h,w,_="trust")=>{It({runId:h,artifactId:w,tab:_})},[]),Rr=p.useCallback(h=>{var M,X;const w=h.trim();if(!w)return;const _=(M=ke==null?void 0:ke.text)==null?void 0:M.trim();Oe(null),Bt("");try{(X=window.getSelection())==null||X.removeAllRanges()}catch{}Ce(_?`${w}
|
|
50
|
+
|
|
51
|
+
Regarding: "${_}"`:w),requestAnimationFrame(()=>{ot.current&&(ot.current.scrollTop=ot.current.scrollHeight)})},[ke,Ce]);if(p.useEffect(()=>{if(!b)return;const h=_=>{const M=_.target;M&&M.closest("[data-selpop]")||window.setTimeout(()=>{const X=window.getSelection(),se=X&&X.rangeCount?X.toString().trim():"";if(!se||se.length<3){Oe(de=>de&&null);return}const ye=X.anchorNode,oe=ye&&(ye.nodeType===1?ye:ye.parentElement),ge=oe==null?void 0:oe.closest("[data-followup]");if(!ge){Oe(de=>de&&null);return}const Le=X.getRangeAt(0).getBoundingClientRect(),gt=Math.max(12,Math.min(Le.left,window.innerWidth-340)),xt=Le.bottom+176>window.innerHeight?Math.max(12,Le.top-176):Le.bottom+8;Oe({text:se.slice(0,220),source:ge.getAttribute("data-followup")||"answer",left:gt,top:xt}),Bt(""),requestAnimationFrame(()=>{var de;return(de=yn.current)==null?void 0:de.focus()})},0)},w=_=>{_.key==="Escape"&&Oe(null)};return document.addEventListener("mouseup",h),document.addEventListener("keydown",w),()=>{document.removeEventListener("mouseup",h),document.removeEventListener("keydown",w)}},[b]),b){const h=Ie?(()=>{const w=U.find(M=>M.kind==="run"&&M.run.id===Ie.runId);if(!w||w.kind!=="run")return null;const _=w.run.artifacts.find(M=>M.id===Ie.artifactId);return _?{run:w.run,artifact:_}:null})():null;return t.jsxs("div",{style:{display:"flex",height:"100%",minHeight:0,flex:1,minWidth:0,width:"100%",background:"var(--bg-canvas)"},children:[C?t.jsx(zn,{cell:{id:`agent-${C.runId}`,type:C.dqlArtifact?"dql":"sql",content:C.source,name:C.name,status:"success",...C.dqlArtifact?{dqlArtifact:C.dqlArtifact}:{}},initialContent:C.source,initialName:C.name,onClose:()=>S(null),onSaved:()=>S(null)}):null,t.jsx("style",{children:Vi}),t.jsxs("div",{style:{flex:1,minWidth:360,display:"flex",flexDirection:"column",overflow:"hidden",background:"var(--bg-canvas)"},children:[t.jsxs("div",{style:{height:46,flexShrink:0,borderBottom:"1px solid var(--border-subtle)",display:"flex",alignItems:"center",gap:9,padding:"0 24px"},children:[t.jsx("div",{style:{width:24,height:24,borderRadius:7,background:"var(--accent-dim)",border:"1px solid var(--status-info-border)",color:"var(--accent)",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:t.jsx(Fe,{size:13})}),t.jsx("span",{style:{fontSize:13.5,fontWeight:650,color:k.textPrimary,whiteSpace:"nowrap"},children:n==="AI Copilot"?"Ask your data":n}),t.jsx("div",{style:{flex:1}}),t.jsx("span",{style:{fontSize:11,color:k.textMuted,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",minWidth:0},children:"Certified first · semantic next · generated SQL last"})]}),t.jsxs("div",{ref:ot,style:{flex:1,minHeight:0,overflowY:"auto",overflowX:"hidden",display:"flex",flexDirection:"column"},children:[t.jsxs("div",{style:{width:"min(720px, 100% - 48px)",margin:"0 auto",padding:"26px 0 12px",display:"flex",flexDirection:"column",gap:26},children:[U.length===0&&!H?t.jsxs("div",{style:{margin:"auto 0",display:"grid",gap:14,justifyItems:"center",textAlign:"center",color:k.textSecondary,paddingTop:40},children:[t.jsx("div",{style:Nn(k),children:t.jsx(Fe,{size:20})}),t.jsx("div",{style:{fontSize:13.5,lineHeight:1.5,maxWidth:400,color:k.textSecondary},children:o??In}),t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap",justifyContent:"center",maxWidth:520},children:(s??Bn).map(w=>t.jsx("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>{V(w.prompt),requestAnimationFrame(()=>{var _;return(_=je.current)==null?void 0:_.focus()})},style:kt(k),children:w.label},w.label))})]}):null,U.map(w=>w.kind==="user"?t.jsx("div",{style:Gi(k),children:w.text},w.id):t.jsx(Pn,{run:w.run,t:k,themeMode:e,appContext:pt,selectedArtifactId:(Ie==null?void 0:Ie.runId)===w.run.id?Ie.artifactId:void 0,onOpenArtifact:(_,M)=>Ar(w.run.id,_,M),onOpenApp:B,onInsertSql:R,onInsertDql:I,onOpenBlock:z,onOpenResearch:O,onSelectClarification:_=>{const M=yt(_);Ce(M.question,void 0,M.selectedEvidenceId)},onNextAction:_=>ft(w.run,_)},w.id)),H&&t.jsx(Ln,{events:Y,t:k,streamingAnswer:le,thinkingMode:ne,backgroundRun:ee})]}),t.jsxs("div",{style:{width:"min(720px, 100% - 48px)",margin:"auto auto 0",padding:"10px 0 16px",position:"sticky",bottom:0,background:"linear-gradient(to top, var(--bg-canvas) 82%, transparent)"},children:[te?t.jsx("div",{style:{color:k.error,fontSize:12,marginBottom:8},children:te}):null,i?t.jsxs("div",{style:{width:"fit-content",maxWidth:"100%",marginBottom:7,padding:"4px 7px 4px 9px",border:"1px solid var(--border-default)",borderRadius:999,background:"var(--bg-2)",color:k.textMuted,fontSize:10.5,display:"flex",alignItems:"center",gap:5},children:[t.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r}),t.jsx("button",{type:"button",onClick:i,"aria-label":"Clear modeling scope",title:"Clear modeling scope",style:{border:0,background:"transparent",color:k.textMuted,cursor:"pointer",display:"grid",placeItems:"center",padding:1},children:t.jsx(bt,{size:12})})]}):null,t.jsxs("div",{style:{background:"var(--bg-2)",border:"1px solid var(--border-default)",borderRadius:14,boxShadow:"0 1px 2px rgba(26,26,26,0.03), 0 6px 22px rgba(26,26,26,0.05)",display:"flex",flexDirection:"column"},children:[t.jsx("textarea",{ref:je,value:W,onChange:w=>{V(w.target.value),K.current=void 0},rows:2,placeholder:"Ask anything about your data…",onKeyDown:w=>{w.key==="Enter"&&!w.shiftKey&&(w.preventDefault(),dt())},style:{border:"none",background:"transparent",resize:"none",outline:"none",boxShadow:"none",padding:"13px 15px 4px",fontSize:13.5,lineHeight:1.5,color:k.textPrimary,fontFamily:k.font}}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 10px 10px 12px"},children:[t.jsx(jn,{t:k,value:ne,onChange:ce}),t.jsx(Mn,{names:ve,value:we,onChange:hn,t:k}),t.jsx("div",{style:{flex:1}}),H?t.jsxs("button",{type:"button",className:"dql-hover",onClick:bn,title:"Stop the active agent run",style:{height:34,padding:"0 12px",borderRadius:10,border:`1px solid ${k.error}`,background:k.btnBg,color:k.error,display:"inline-flex",alignItems:"center",gap:6,cursor:"pointer",fontFamily:k.font,fontSize:12.5,fontWeight:600},children:[t.jsx(vn,{size:13,fill:"currentColor"})," Stop"]}):null,t.jsx("button",{type:"button",className:"dql-hover dql-lift",title:"Ask",onClick:dt,disabled:!W.trim()||H,style:{width:34,height:34,borderRadius:10,border:"none",background:W.trim()&&!H?"var(--accent)":"var(--bg-4)",color:"#fff",display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:W.trim()&&!H?"pointer":"default",boxShadow:W.trim()&&!H?"0 1px 5px rgba(107,93,211,0.3)":"none"},children:H?t.jsx(Pe,{size:15,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):t.jsx(Kn,{size:15})})]})]}),t.jsx("div",{style:{textAlign:"center",fontSize:10.5,color:k.textMuted,marginTop:8},children:"Every answer is grounded in your certified metrics and dbt lineage."})]})]})]}),h?t.jsx(Xi,{run:h.run,artifact:h.artifact,tab:Ie.tab,t:k,appContext:pt,onOpenApp:B,onChangeTab:w=>It(_=>_&&{..._,tab:w}),onClose:()=>It(null),onSaveBlock:()=>ft(h.run,{id:"save-dql-block",label:"Save as block",route:"dql_block_draft"}),onInsertSql:R,onInsertDql:I}):null,ke?t.jsx(Zi,{t:k,text:ke.text,source:ke.source,left:ke.left,top:ke.top,draft:zr,inputRef:yn,onDraftChange:Bt,onClose:()=>Oe(null),onSend:Rr}):null]})}return t.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0,flex:1,minWidth:0,width:"100%",background:k.cellBg},children:[C?t.jsx(zn,{cell:{id:`agent-${C.runId}`,type:C.dqlArtifact?"dql":"sql",content:C.source,name:C.name,status:"success",...C.dqlArtifact?{dqlArtifact:C.dqlArtifact}:{}},initialContent:C.source,initialName:C.name,onClose:()=>S(null),onSaved:()=>S(null)}):null,t.jsx("style",{children:`
|
|
52
|
+
@keyframes dql-agent-run-spin { to { transform: rotate(360deg); } }
|
|
53
|
+
@keyframes dql-agent-fadein { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
|
|
54
|
+
@keyframes dql-agent-thinking-dot { 0%, 65%, 100% { opacity: .28; transform: translateY(0); } 32% { opacity: 1; transform: translateY(-2px); } }
|
|
55
|
+
@keyframes dql-agent-activity-in { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }
|
|
56
|
+
.dql-agent-thinking-dot { animation: dql-agent-thinking-dot 1.05s ease-in-out infinite; }
|
|
57
|
+
.dql-agent-activity { animation: dql-agent-activity-in .22s ease-out; }
|
|
58
|
+
.dql-hover { transition: filter .15s ease, transform .12s ease, box-shadow .15s ease, background .15s ease, color .15s ease, border-color .15s ease; }
|
|
59
|
+
.dql-hover:hover { filter: brightness(1.07); }
|
|
60
|
+
.dql-hover:active { transform: translateY(0.5px); }
|
|
61
|
+
.dql-lift:hover { transform: translateY(-1px); }
|
|
62
|
+
details > summary::-webkit-details-marker { display: none; }
|
|
63
|
+
@media (prefers-reduced-motion: reduce) { .dql-agent-thinking-dot, .dql-agent-activity { animation: none !important; } }
|
|
64
|
+
`}),t.jsxs("div",{style:{flex:1,minHeight:0,overflow:"auto",padding:"14px 16px",display:"flex",flexDirection:"column",gap:12},children:[U.length===0&&!H?t.jsxs("div",{style:{margin:"auto 0",display:"grid",gap:14,justifyItems:"center",textAlign:"center",color:k.textSecondary},children:[t.jsx("div",{style:Nn(k),children:t.jsx(Fe,{size:20})}),t.jsx("div",{style:{fontSize:13,lineHeight:1.5,maxWidth:380,color:k.textSecondary},children:o??In}),t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap",justifyContent:"center",maxWidth:520},children:(s??Bn).map(h=>t.jsx("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>{V(h.prompt),requestAnimationFrame(()=>{var w;return(w=je.current)==null?void 0:w.focus()})},style:kt(k),children:h.label},h.label))})]}):null,U.map(h=>h.kind==="user"?t.jsx("div",{style:bs(k),children:h.text},h.id):F?t.jsx(Pn,{run:h.run,t:k,themeMode:e,appContext:pt,onOpenApp:B,onInsertSql:R,onInsertDql:I,onReplaceDql:L,insertDqlActionLabel:N,replaceDqlActionLabel:T,onOpenBlock:z,onOpenResearch:O,onSelectClarification:w=>{const _=yt(w);Ce(_.question,void 0,_.selectedEvidenceId)},onNextAction:w=>ft(h.run,w)},h.id):t.jsx(Qi,{run:h.run,t:k,themeMode:e,appContext:pt,onOpenApp:B,onInsertSql:R,onInsertDql:I,onOpenBlock:z,onOpenResearch:O,onSelectClarification:w=>{const _=yt(w);Ce(_.question,void 0,_.selectedEvidenceId)},onNextAction:w=>ft(h.run,w)},h.id)),H&&t.jsx(Ln,{events:Y,t:k,streamingAnswer:le,thinkingMode:ne,backgroundRun:ee})]}),te?t.jsx("div",{style:{margin:"0 16px 8px",color:k.error,fontSize:12},children:te}):null,t.jsxs("div",{style:{padding:"10px 16px 14px",borderTop:`1px solid ${k.headerBorder}`,display:"grid",gap:8},children:[t.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center",justifyContent:"space-between",flexWrap:"wrap"},children:[t.jsxs("div",{style:{fontSize:11,color:k.textMuted,flex:1,minWidth:180,display:"flex",alignItems:"center",gap:6},children:[t.jsx("span",{children:r}),i?t.jsx("button",{type:"button",onClick:i,"aria-label":"Clear modeling scope",title:"Clear modeling scope",style:{border:0,background:"transparent",color:k.textMuted,cursor:"pointer",display:"grid",placeItems:"center",padding:2},children:t.jsx(bt,{size:12})}):null]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(Mn,{names:ve,value:we,onChange:hn,t:k}),t.jsx(jn,{t:k,value:ne,onChange:ce})]})]}),t.jsxs("div",{style:{display:"flex",gap:8,alignItems:"flex-end"},children:[t.jsx("textarea",{ref:je,value:W,onChange:h=>{V(h.target.value),K.current=void 0},rows:2,placeholder:"Ask anything about your data…",onKeyDown:h=>{h.key==="Enter"&&!h.shiftKey&&(h.preventDefault(),dt())},style:xs(k)}),t.jsxs("button",{type:"button",className:"dql-hover dql-lift",onClick:dt,disabled:!W.trim()||H,style:Dn(k,!!W.trim()&&!H),children:[H?t.jsx(Pe,{size:15,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):t.jsx(Pr,{size:15}),t.jsx("span",{children:H?"Working":"Ask"})]}),H?t.jsxs("button",{type:"button",className:"dql-hover",onClick:bn,style:{...Dn(k,!0),background:k.btnBg,borderColor:k.error,color:k.error},title:"Stop the active agent run",children:[t.jsx(vn,{size:13,fill:"currentColor"}),t.jsx("span",{children:"Stop"})]}):null]})]})]})}const In="Ask a question — every answer is grounded in your certified metrics and dbt lineage. Use Research deeper on any answer for a slower investigation.",Bn=[{label:"What is total revenue?",prompt:"What is total revenue?"},{label:"Why is revenue down by region?",prompt:"Why is revenue down by region?"},{label:"Top customers by revenue this quarter",prompt:"Top customers by revenue this quarter"},{label:"How have orders trended over the last 6 months?",prompt:"How have orders trended over the last 6 months?"}];function on(){try{const e=JSON.parse(window.localStorage.getItem(sn)??"[]");return Array.isArray(e)?e.filter(n=>{if(!n||typeof n!="object")return!1;const r=n;return typeof r.id=="string"&&typeof r.question=="string"&&typeof r.startedAt=="string"&&(r.threadId===void 0||typeof r.threadId=="string")}):[]}catch{return[]}}function Tn(e){try{const n=on().filter(r=>r.id!==e.id);window.localStorage.setItem(sn,JSON.stringify([...n,e].slice(-12)))}catch{}}function Ft(e){try{const n=on().filter(r=>r.id!==e);window.localStorage.setItem(sn,JSON.stringify(n))}catch{}}function $n(e){const n=on().sort((r,i)=>i.startedAt.localeCompare(r.startedAt));return e?n.find(r=>r.threadId===e):n.find(r=>!r.threadId)}const sr="dql.agent.thinkingMode";function or(e,n,r){return r&&e.includes(r)?r:n&&e.includes(n)?n:e[0]}function Mn({names:e,value:n,onChange:r,t:i}){return e.length===0||!n?null:t.jsxs("label",{title:"Database connection used for metadata, compilation, and execution in this conversation",style:{height:30,display:"inline-flex",alignItems:"center",gap:5,padding:"0 7px",border:"1px solid var(--border-default)",borderRadius:8,background:"var(--bg-2)",color:i.textMuted,fontSize:11},children:[t.jsx(Er,{size:12}),t.jsx("select",{"aria-label":"Ask AI database connection",value:n,onChange:s=>r(s.target.value),style:{maxWidth:150,border:0,outline:0,background:"transparent",color:i.textSecondary,font:"inherit",cursor:e.length>1?"pointer":"default"},children:e.map(s=>t.jsx("option",{value:s,children:s},s))})]})}function Ei(){try{const e=window.localStorage.getItem(sr);return e==="low"||e==="medium"||e==="high"||e==="auto"?e:"auto"}catch{return"auto"}}const Wi=new Set(["conversation","certified_answer","semantic_answer","generated_answer","research","sql_cell","dql_block_draft","app_build","clarify","blocked"]),Pi=new Set(["certified","governed","grounded","review_required","blocked","not_applicable"]),Fi=new Set(["completed","needs_review","needs_clarification","blocked"]),Ni=new Set(["conversational_reply","certified_answer_found","governed_semantic_answer","generated_review_required","artifact_created","needs_clarification","human_review_required","blocked"]);function lr(e,n=[]){const r=new Map(n.map(i=>[i.id,i]));return e.flatMap(i=>{const s=i.agentRunId?r.get(i.agentRunId):void 0;return[{kind:"user",id:`${i.id}-q`,text:i.question},{kind:"run",id:(s==null?void 0:s.id)??i.id,run:s??Di(i)}]})}function Di(e){var m,f,l;const n=Wi.has(e.route)?e.route:"generated_answer",r=Pi.has(e.trustLabel)?e.trustLabel:e.certification==="certified"?"certified":"not_applicable",i=Fi.has(e.runStatus)?e.runStatus:"completed",s=Ni.has(e.stopReason)?e.stopReason:i==="blocked"?"blocked":i==="needs_clarification"?"needs_clarification":i==="needs_review"?"human_review_required":n==="conversation"?"conversational_reply":r==="certified"?"certified_answer_found":"artifact_created",o=(((m=e.result)==null?void 0:m.columns)??[]).filter(c=>typeof c=="string"),a=(((f=e.result)==null?void 0:f.rowsSample)??[]).filter(c=>Array.isArray(c)).map(c=>Object.fromEntries(o.map((y,x)=>[y,c[x]]))),u=o.length>0?{columns:o,rows:a,rowCount:((l=e.result)==null?void 0:l.rowCount)??a.length}:void 0,d=u||e.sql||e.dqlArtifact||e.sourceCertifiedBlock?{id:`${e.id}-artifact`,kind:"answer",title:e.sourceCertifiedBlock??e.question,trustState:r,ref:e.sourceCertifiedBlock,payload:{...e.sourceCertifiedBlock?{sourceCertifiedBlock:e.sourceCertifiedBlock}:{},...e.certification?{certification:e.certification}:{},...e.contextPackId?{contextPackId:e.contextPackId}:{},...e.sql?{sql:e.sql}:{},...e.dqlArtifact?{dqlArtifact:e.dqlArtifact}:{},...e.cascade?{cascade:e.cascade}:{},...u?{result:u}:{},...e.contract&&Object.keys(e.contract).length>0?{contextPack:{questionPlan:{requestedShape:e.contract}}}:{}}}:void 0;return{id:e.id,question:e.question,requestedMode:"auto",route:n,status:i,trustState:r,stopReason:s,startedAt:e.createdAt,completedAt:e.createdAt,summary:e.answerSummary??e.question,answer:e.answerText??e.answerSummary,answerKind:n==="conversation"?"conversational":void 0,steps:[],artifacts:d?[d]:[],evaluations:[],events:[],nextActions:[],repairAttempts:0}}function Hi(e){switch(e){case"certified_answer":return"Found a compatible certified block";case"semantic_answer":return"Found a compatible semantic metric";case"generated_answer":return"Identified the relevant tables and columns";case"research":return"Identified evidence for deeper analysis";case"app_build":return"Found governed assets for the app";case"sql_cell":return"Identified the query context";case"dql_block_draft":return"Identified reusable governed logic";case"clarify":return"Identified a missing business detail";default:return"Identified the best answer path"}}function Oi(e,n){if(n.some(r=>r.type==="repair.attempted"))return"Refining the query and trying again";if(n.some(r=>r.type==="escalated"))return"Expanding the evidence search";switch(e){case"certified_answer":case"semantic_answer":return"Running the governed query";case"generated_answer":return"Building and running a grounded query";case"research":return"Researching the strongest evidence";case"app_build":return"Assembling the app from governed assets";case"sql_cell":return"Building and checking the SQL";case"dql_block_draft":return"Drafting the governed logic";case"clarify":return"Preparing a focused clarification";default:return"Preparing the answer"}}function Yt(e){for(let n=e.length-1;n>=0;n-=1)if(e[n].route)return e[n].route}function ar(e,n,r=!1){return e<12?null:!n&&e<24&&!r?{title:"Still resolving the governed evidence",detail:"The bounded request is still selecting its answer path. DQL will stop at the normal deadline instead of silently switching to a longer workflow."}:n==="research"?{title:"Deep research is validating the analysis",detail:"This can use several AI and SQL steps. Reusable relationships and semantic metrics make future investigations faster; reviewed repeat answers can be saved as blocks and certified."}:{title:r?"Applying one bounded query repair":"Finishing the bounded query path",detail:"DQL is compiling or running the selected governed path. An ordinary lookup stops at its deadline instead of silently restarting as Research."}}function cr(e,n,r,i){return r==="certified"||e<20&&i===0||n!=="research"&&n!=="generated_answer"?null:{title:n==="research"?"Make future research faster":"Make this question faster next time",detail:"If this analysis is reusable, save it as a block, review it, then certify it. Add repeated joins to Domain Modeling and reusable measures to the semantic layer to reduce future AI work and token usage."}}function dr(e,n=!1){if(e.length===0&&n)return[{id:"background",label:"Continuing this request in the background",state:"active"}];const r=Yt(e);if(r==="conversation")return[];const i=e.some(u=>u.type==="route.decided"),s=e.some(u=>u.type==="executor.started"||u.type==="step.started"||u.type==="repair.attempted"||u.type==="escalated"),o=e.some(u=>u.type==="evaluation.recorded"),a=[{id:"search",label:"Resolving governed evidence and business meaning",state:i?"complete":"active"}];return i&&a.push({id:"match",label:Hi(r),state:s||o?"complete":"active"}),(s||o)&&a.push({id:"execute",label:Oi(r,e),state:o?"complete":"active"}),o&&a.push({id:"verify",label:"Checking the result against governed evidence",state:"active"}),a}function Ln({events:e,t:n,streamingAnswer:r,thinkingMode:i,backgroundRun:s}){var x;const[o,a]=p.useState(()=>Date.now());p.useEffect(()=>{const v=window.setInterval(()=>a(Date.now()),1e3);return()=>window.clearInterval(v)},[]);const u=(s==null?void 0:s.startedAt)??((x=e.find(v=>v.type==="run.started"))==null?void 0:x.at),d=u?Date.parse(u):o,m=Number.isFinite(d)?Math.max(0,Math.floor((o-d)/1e3)):0,f=ar(m,Yt(e),e.some(v=>v.type==="repair.attempted"));if(r)return t.jsx("div",{style:{alignSelf:"stretch",padding:"4px 2px 8px",fontSize:13.5,lineHeight:1.55,color:n.textPrimary,whiteSpace:"pre-wrap",animation:"dql-agent-fadein 0.22s ease-out"},children:r});if(Yt(e)==="conversation")return t.jsxs("div",{role:"status","aria-live":"polite",style:{alignSelf:"stretch",display:"flex",alignItems:"center",gap:9,padding:"5px 2px 9px",color:n.textSecondary,animation:"dql-agent-fadein 0.22s ease-out"},children:[t.jsx(En,{}),t.jsx("span",{style:{fontSize:13,lineHeight:1.4},children:"Replying…"})]});const c=dr(e,!!s),y=m>=12?f==null?void 0:f.title:i==="high"?"Thorough mode is cross-checking the result.":null;return t.jsxs("div",{role:"status","aria-live":"polite","aria-label":"Agent activity",style:{alignSelf:"stretch",display:"grid",gap:7,padding:"5px 2px 10px",animation:"dql-agent-fadein 0.22s ease-out"},children:[c.map(v=>t.jsxs("div",{className:"dql-agent-activity",style:{display:"flex",alignItems:"center",gap:9,minHeight:18,color:v.state==="active"?n.textPrimary:n.textMuted},children:[t.jsx("span",{"aria-hidden":"true",style:{width:16,height:16,display:"inline-flex",alignItems:"center",justifyContent:"center",flex:"0 0 auto",color:v.state==="active"?n.accent:n.textMuted},children:v.state==="active"?t.jsx(En,{}):t.jsx(Ye,{size:13,strokeWidth:2.2})}),t.jsxs("span",{style:{fontSize:12.5,lineHeight:1.4,fontWeight:v.state==="active"?620:450},children:[v.label,v.state==="active"?"…":""]})]},v.id)),y?t.jsx("span",{style:{paddingLeft:25,fontSize:10.5,lineHeight:1.4,color:n.textMuted},children:y}):null]})}function En(){return t.jsx("span",{"aria-hidden":"true",style:{width:16,height:10,display:"inline-flex",alignItems:"center",justifyContent:"center",gap:2},children:[0,1,2].map(e=>t.jsx("span",{className:"dql-agent-thinking-dot",style:{width:3,height:3,borderRadius:999,background:"var(--accent)",animationDelay:`${e*120}ms`}},e))})}function Wn({items:e,t:n,renderItem:r,cap:i=4}){const[s,o]=p.useState(!1),a=s?e:e.slice(0,i);return t.jsxs(t.Fragment,{children:[a.map((u,d)=>r(u,d)),e.length>i?t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>o(u=>!u),style:{alignSelf:"flex-start",background:"none",border:"none",cursor:"pointer",color:n.accent,fontSize:11,padding:"2px 0",display:"inline-flex",alignItems:"center",gap:4},children:[s?t.jsx(Yn,{size:11}):t.jsx(Ct,{size:11}),s?"Show less":`Show all (${e.length})`]}):null]})}function Qi({run:e,t:n,themeMode:r,appContext:i,onOpenApp:s,onInsertSql:o,onInsertDql:a,onOpenBlock:u,onOpenResearch:d,onSelectClarification:m,onNextAction:f}){var T;const{dispatch:l}=zt();if(e.route==="conversation"){const b=e.answerKind==="general_knowledge";return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8,animation:"dql-agent-fadein 0.3s ease-out"},children:[t.jsxs("div",{style:vs(n),children:[b?t.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:10.5,color:n.textMuted,marginBottom:6,fontWeight:650},children:[t.jsx(vt,{size:11})," General knowledge — not from your data"]}):null,t.jsx("div",{style:{fontSize:13.5,lineHeight:1.55,color:n.textPrimary},children:e.answer?t.jsx(mt,{text:Ve(e.answer),t:n}):e.summary})]}),e.nextActions.length>0?t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:e.nextActions.map(k=>t.jsx("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>f(k),style:kt(n),children:k.label},k.id))}):null]})}const c=e.steps??[],y=c.length>1,x=((T=e.plan)==null?void 0:T.source)==="llm",v=un(e),g=cn(e),R=it(e),I=e.route==="certified_answer"||e.route==="generated_answer",L=e.nextActions.some(b=>b.route==="research"),D=I&&R&&!L,z=Te(e),O=R&&!(z!=null&&z.sourcePath)&&!!((z==null?void 0:z.source)??De(e)),B=Date.parse(e.startedAt),E=Date.parse(e.completedAt),F=Number.isFinite(B)&&Number.isFinite(E)?Math.max(0,Math.round((E-B)/1e3)):0,N=cr(F,e.route,e.trustState,e.repairAttempts);return t.jsxs("div",{style:js(n),children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(rs,{run:e}),t.jsx("div",{style:{minWidth:0,flex:1},children:t.jsx("div",{style:{fontSize:12.5,fontWeight:850,color:n.textPrimary},children:es(e)})}),t.jsx(is,{run:e,t:n})]}),g?t.jsxs("div",{style:{display:"flex",gap:6,alignItems:"flex-start",fontSize:11,color:n.textMuted,lineHeight:1.4},children:[e.trustState==="certified"?t.jsx(xe,{size:12,color:n.success,style:{flex:"0 0 auto",marginTop:1}}):e.trustState==="governed"||e.trustState==="grounded"?t.jsx(xe,{size:12,color:n.accent,style:{flex:"0 0 auto",marginTop:1}}):t.jsx(Ze,{size:12,color:n.warning,style:{flex:"0 0 auto",marginTop:1}}),t.jsx("span",{children:g})]}):null,x||y||e.repairAttempts>0?t.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[x?t.jsx(Ot,{t:n,icon:t.jsx(tt,{size:11}),label:"AI plan",tone:"accent"}):null,y?t.jsx(Ot,{t:n,icon:t.jsx(Gt,{size:11}),label:`${c.length} steps`,tone:"muted"}):null,e.repairAttempts>0?t.jsx(Ot,{t:n,icon:t.jsx(nn,{size:11}),label:`${e.repairAttempts} repair${e.repairAttempts>1?"s":""}`,tone:"warning"}):null]}):null,e.summary&&!(e.answer&&as(Be(e.summary),Ve(e.answer)))?t.jsx("div",{style:{fontSize:12.5,lineHeight:1.45,color:n.textSecondary},children:Be(e.summary)}):null,e.answer?t.jsx("div",{style:Ss(n),children:t.jsx(mt,{text:Ve(e.answer),t:n})}):null,t.jsx(fr,{run:e,t:n,onSelect:m}),v.length>0?t.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"center"},children:[t.jsx("span",{style:{fontSize:11,color:n.textMuted},children:"Evidence:"}),v.map(b=>t.jsxs("span",{style:kr(n,b.certified),children:[b.certified?t.jsx(xe,{size:11}):t.jsx(et,{size:11}),t.jsx("span",{children:b.label})]},b.label))]}):null,t.jsx(wr,{run:e,t:n}),e.artifacts.length>0?t.jsx("div",{style:{display:"grid",gap:8,gridTemplateColumns:"minmax(0, 1fr)",minWidth:0},children:e.artifacts.map(b=>t.jsx(mr,{artifact:b,t:n,themeMode:r,onInsertSql:o,onInsertDql:a,sourceRunId:e.id,sourceQuestion:e.question,onOpenBlock:u,onOpenResearch:d,onOpenApp:s,onNextAction:f},b.id))}):null,y?t.jsx(vr,{steps:c,t:n}):t.jsx(br,{evaluations:e.evaluations,t:n}),e.events.length>0?t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>l({type:"OPEN_AGENT_LOG",run:e}),style:{display:"inline-flex",alignItems:"center",gap:5,alignSelf:"flex-start",background:"transparent",border:"none",cursor:"pointer",padding:0,color:n.textMuted,fontSize:11.5,fontFamily:n.font},title:"See what the agent did and where the time went",children:[t.jsx(tt,{size:12})," View steps · where the time went"]}):null,N?t.jsxs("div",{style:{display:"grid",gap:3,padding:"8px 9px",border:`1px solid ${n.accent}33`,borderRadius:7,background:`${n.accent}0a`},children:[t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,color:n.textSecondary,fontSize:11,fontWeight:800},children:[t.jsx(vt,{size:11,color:n.accent})," ",N.title]}),t.jsx("span",{style:{fontSize:10.5,color:n.textMuted,lineHeight:1.45},children:N.detail})]}):null,R||D||e.nextActions.length>0?t.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"center"},children:[R?t.jsx(an,{run:e,t:n,appContext:i,onOpenApp:s}):null,O?t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>f({id:"save-dql-block",label:"Save as block",route:"dql_block_draft"}),style:J(n),children:[t.jsx(rn,{size:11})," Save as block"]}):null,D?t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>f({id:"research-deeper",label:"Research this deeper",route:"research"}),style:J(n),title:"Run a slower, multi-step investigation on this question",children:[t.jsx(et,{size:11}),"Research this deeper"]}):null,e.nextActions.filter(b=>b.id!=="pin-to-app"&&b.id!=="research-deeper"&&b.id!=="confirm-app-build"&&b.id!=="request-certification").map(b=>t.jsx("button",{type:"button",className:"dql-hover",onClick:()=>f(b),style:J(n),children:b.label},b.id))]}):null]})}function ur(e){const n=[];return e.analytical&&n.push({id:"how",label:"How it answered"}),(e.hasDql||e.analytical&&e.blocked)&&n.push({id:"dql",label:"DQL"}),(e.hasSql||e.analytical&&e.blocked)&&n.push({id:"sql",label:"SQL"}),e.hasLineage&&n.push({id:"lineage",label:"Lineage"}),n.push({id:"trust",label:"Trust & steps"}),n}const Vi=`
|
|
65
|
+
@keyframes dql-agent-run-spin { to { transform: rotate(360deg); } }
|
|
66
|
+
@keyframes dql-agent-fadein { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
|
|
67
|
+
@keyframes dql-agent-thinking-dot { 0%, 65%, 100% { opacity: .28; transform: translateY(0); } 32% { opacity: 1; transform: translateY(-2px); } }
|
|
68
|
+
@keyframes dql-agent-activity-in { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }
|
|
69
|
+
.dql-agent-thinking-dot { animation: dql-agent-thinking-dot 1.05s ease-in-out infinite; }
|
|
70
|
+
.dql-agent-activity { animation: dql-agent-activity-in .22s ease-out; }
|
|
71
|
+
.dql-hover { transition: filter .15s ease, transform .12s ease, box-shadow .15s ease, background .15s ease, color .15s ease, border-color .15s ease; }
|
|
72
|
+
.dql-hover:hover { filter: brightness(1.03); }
|
|
73
|
+
.dql-hover:active { transform: translateY(0.5px); }
|
|
74
|
+
.dql-lift:hover { transform: translateY(-1px); }
|
|
75
|
+
.dql-ask-ghost:hover { background: var(--bg-0); color: var(--text-primary) !important; }
|
|
76
|
+
.dql-ask-chip:hover { border-color: var(--accent) !important; box-shadow: 0 1px 6px rgba(107,93,211,0.12); }
|
|
77
|
+
details > summary::-webkit-details-marker { display: none; }
|
|
78
|
+
@media (prefers-reduced-motion: reduce) { .dql-agent-thinking-dot, .dql-agent-activity { animation: none !important; } }
|
|
79
|
+
`;function Gi(e){return{alignSelf:"flex-end",maxWidth:"82%",background:"var(--bg-0)",color:e.textPrimary,borderRadius:"16px 16px 4px 16px",padding:"10px 14px",fontSize:13.5,lineHeight:1.5,whiteSpace:"pre-wrap",animation:"dql-agent-fadein 0.25s ease-out"}}function Ee(e){return qt(e,{variant:"ghost",size:"sm"})}function Nt(e,n){return e.kind==="app_proposal"||e.kind==="dql_block_draft"||e.kind==="research_run"||!!_t(n)}function At(e,n){var a,u;const r=[],i=Ne(n),s=e.kind==="answer"?(a=i==null?void 0:i.rows)!=null&&a.length?"Table":"Answer":e.kind==="sql_cell"?"SQL":e.kind==="dql_block_draft"?"DQL block":e.kind==="research_run"?"Research":"Result";r.push(s);const o=(i==null?void 0:i.rowCount)??((u=i==null?void 0:i.rows)==null?void 0:u.length);return typeof o=="number"&&r.push(`${o} row${o===1?"":"s"}`),typeof(i==null?void 0:i.executionTime)=="number"&&r.push(i.executionTime>=1e3?`${(i.executionTime/1e3).toFixed(1)}s`:`${i.executionTime.toFixed(i.executionTime<10?1:0)}ms`),r.push(e.trustState==="certified"?"certified block":e.trustState==="governed"||e.trustState==="grounded"?"governed":"AI-generated"),r.join(" · ")}function jt(e,n){const i=/^(?:certified|governed semantic|review-required|exploratory dbt-grounded) answer$/i.test(n.title.trim())?e.question:n.title,s=Be(i).replace(/[?.!]+$/,"").trim();if(!s)return"Answer result";const o=s.charAt(0).toUpperCase()+s.slice(1);return o.length>88?`${o.slice(0,85).trimEnd()}…`:o}function P(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function pr(e){const n=[],r=new Set,i=(s,o)=>{const a=P(s);if(!a)return;const u=[a.name,a.label,a.relation,a.objectName].find(l=>typeof l=="string"&&l.trim().length>0);if(!u)return;const d=typeof a.kind=="string"?a.kind:o,m=`${d??""}:${u}`;if(r.has(m))return;r.add(m);const f=[a.description,a.provenance,a.sourceTier,a.source].find(l=>typeof l=="string"&&l.trim().length>0);n.push({name:u,kind:d,detail:f})};for(const s of e.artifacts){const o=pe(s),a=P(o.evidence);for(const m of["lineage","sourceTables","semanticObjects","selectedAssets"]){const f=a==null?void 0:a[m];Array.isArray(f)&&f.forEach(l=>i(l,m==="sourceTables"?"source":void 0))}const u=P(o.analysisPlan)??P(a==null?void 0:a.analysisPlan),d=u==null?void 0:u.candidateTables;Array.isArray(d)&&d.forEach(m=>i(m,"relation"))}return n.slice(0,24)}function ln(e,n){var i;const r=pe(n);return Rt(r)?"how":(i=Te(e)??st(r))!=null&&i.source?"dql":De(e)??(typeof r.sql=="string"?r.sql:void 0)?"sql":pr(e).length>0?"lineage":"trust"}function Ki({run:e,artifact:n,selected:r,t:i,themeMode:s,onInspect:o}){const a=pe(n),u=Ne(a);if(!u)return null;const d=jr(a,u),m=ln(e,n),f=Te(e)??st(a),l=n.trustState==="certified"?yr(n,a):void 0;return t.jsxs("section",{"data-followup":"table","aria-label":`${jt(e,n)} result`,style:{border:`1px solid ${r?"var(--accent)":"var(--border-default)"}`,borderRadius:12,background:"var(--bg-2)",overflow:"hidden",boxShadow:r?"0 2px 10px rgba(107,93,211,0.12)":"0 1px 3px rgba(26,26,26,0.04)"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"11px 13px",borderBottom:"1px solid var(--border-subtle)"},children:[t.jsx("span",{style:{width:30,height:30,borderRadius:8,background:n.trustState==="certified"?"var(--status-success-bg)":"var(--accent-dim)",color:n.trustState==="certified"?"var(--status-success)":"var(--accent)",display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:t.jsx(Ge,{kind:n.kind})}),t.jsxs("div",{style:{minWidth:0,flex:1},children:[t.jsx("div",{style:{fontSize:12.5,fontWeight:700,color:i.textPrimary,lineHeight:1.35},children:jt(e,n)}),t.jsx("div",{style:{fontSize:11,color:i.textMuted,marginTop:2},children:At(n,a)})]}),t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>o(m),style:Ee(i),children:[t.jsx(tt,{size:12})," Inspect"]})]}),f?t.jsx(hr,{artifact:f,certifiedBlockName:l,initialResult:u,initialChartConfig:d,payload:a,t:i,themeMode:s,embedded:!0}):t.jsx(en,{result:u,themeMode:s,t:i,chartConfig:d,embedded:!0,tabLabels:{table:"Results",chart:"Visualization"}})]})}function Pn({run:e,t:n,themeMode:r,appContext:i,selectedArtifactId:s,onOpenArtifact:o,onOpenApp:a,onInsertSql:u,onInsertDql:d,onReplaceDql:m,insertDqlActionLabel:f,replaceDqlActionLabel:l,onOpenBlock:c,onOpenResearch:y,onSelectClarification:x,onNextAction:v}){var ee,$;const{dispatch:g}=zt(),[R,I]=p.useState(!1),L=o??(()=>g({type:"OPEN_AGENT_LOG",run:e}));if(e.route==="conversation"){const C=e.answerKind==="general_knowledge";return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8,animation:"dql-agent-fadein 0.3s ease-out",maxWidth:"100%"},children:[C?t.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:5,fontSize:10.5,color:n.textMuted,fontWeight:650},children:[t.jsx(vt,{size:11})," General knowledge — not from your data"]}):null,t.jsx("div",{"data-followup":"answer",style:{fontSize:14.5,lineHeight:1.65,color:n.textPrimary},children:e.answer?t.jsx(mt,{text:Ve(e.answer),t:n}):e.summary}),e.nextActions.length>0?t.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:e.nextActions.map(S=>t.jsx("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>v(S),style:kt(n),children:S.label},S.id))}):null]})}const D=e.trustState==="certified",z=e.status==="blocked",O=e.status==="needs_clarification",B=z||O?void 0:e.answer,E=z?"Blocked — no answer produced":O?"Needs clarification":D?"Certified answer":"AI-generated answer",F=z?(($=(ee=e.diagnosticReceipt)==null?void 0:ee.failure)==null?void 0:$.message)??e.summary:void 0,N=e.evaluations.filter(C=>C.severity==="info").length,T=un(e),b=e.artifacts.filter(C=>{const S=pe(C);return!Nt(C,S)&&!!Ne(S)}),k=new Set(b.map(C=>C.id)),K=e.artifacts.filter(C=>!Nt(C,pe(C))&&!k.has(C.id)),W=e.artifacts.filter(C=>Nt(C,pe(C))),V=b[0]??K[0]??e.artifacts[0],U=it(e),Z=e.route==="certified_answer"||e.route==="semantic_answer"||e.route==="generated_answer",Y=e.nextActions.some(C=>C.route==="research"),Q=Z&&U&&!Y,le=Te(e),G=U&&!(le!=null&&le.sourcePath)&&!!((le==null?void 0:le.source)??De(e)),H=f&&d||l&&m?pn(e):void 0,q=()=>{var S;const C=B?Ve(B):F??e.summary;C&&((S=navigator.clipboard)==null||S.writeText(C).catch(()=>{}),I(!0),window.setTimeout(()=>I(!1),1400))};return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10,maxWidth:"100%",animation:"dql-agent-fadein 0.3s ease-out"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:7,flexWrap:"wrap"},children:[z?t.jsx(Ze,{size:14,color:n.error}):D?t.jsx(xe,{size:14,color:n.success}):t.jsx(Fe,{size:14,color:n.accent}),t.jsx("span",{style:{fontSize:12,fontWeight:650,color:z?n.error:n.textSecondary},children:E}),D&&T[0]?t.jsxs("span",{style:{fontSize:11,color:n.textMuted},children:["from ",t.jsx("span",{style:{color:n.accent,fontWeight:600},children:T[0].label})]}):!z&&V&&N>0?t.jsxs("button",{type:"button",onClick:()=>L(V.id,"trust"),style:{fontSize:11,color:n.textMuted,background:"none",border:"none",cursor:"pointer",padding:0,fontFamily:n.font,display:"inline-flex",alignItems:"center",gap:4},children:[t.jsx(Ye,{size:11,color:n.success})," ",N," check",N===1?"":"s"," passed"]}):null]}),B?t.jsx("div",{"data-followup":"answer",style:{fontSize:14.5,lineHeight:1.65,color:n.textPrimary},children:t.jsx(mt,{text:Ve(B),t:n})}):F?t.jsx("div",{"data-followup":"answer",style:{fontSize:13.5,lineHeight:1.6,color:n.textSecondary},children:Be(F)}):e.summary?t.jsx("div",{"data-followup":"answer",style:{fontSize:14,lineHeight:1.6,color:n.textSecondary},children:Be(e.summary)}):null,t.jsx(fr,{run:e,t:n,onSelect:x}),b.map(C=>t.jsx(Ki,{run:e,artifact:C,selected:C.id===s,t:n,themeMode:r,onInspect:S=>L(C.id,S)},C.id)),K.map(C=>{const S=pe(C),te=C.id===s;return t.jsxs("button",{type:"button",className:"dql-ask-chip",onClick:()=>L(C.id,ln(e,C)),style:{display:"flex",alignItems:"center",gap:10,width:"fit-content",maxWidth:"100%",padding:"9px 12px",borderRadius:10,border:`1px solid ${te?"var(--accent)":"var(--border-default)"}`,background:"var(--bg-2)",boxShadow:te?"0 1px 6px rgba(107,93,211,0.12)":"none",cursor:"pointer",textAlign:"left",fontFamily:n.font},children:[t.jsx("span",{style:{width:30,height:30,borderRadius:7,background:C.trustState==="certified"?"var(--status-success-bg)":"var(--accent-dim)",color:C.trustState==="certified"?"var(--status-success)":"var(--accent)",display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:t.jsx(Ge,{kind:C.kind})}),t.jsxs("span",{style:{display:"flex",flexDirection:"column",gap:1,minWidth:0},children:[t.jsx("span",{style:{fontSize:12.5,fontWeight:650,color:n.textPrimary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Be(C.title)}),t.jsx("span",{style:{fontSize:11,color:n.textMuted},children:At(C,S)})]}),t.jsx(Vn,{size:14,color:n.textMuted,style:{flexShrink:0,marginLeft:6}})]},C.id)}),W.length>0?t.jsx("div",{style:{display:"grid",gap:8,gridTemplateColumns:"minmax(0, 1fr)",minWidth:0},children:W.map(C=>t.jsx(mr,{artifact:C,t:n,themeMode:r,onInsertSql:u,onInsertDql:d,insertDqlActionLabel:f,sourceRunId:e.id,sourceQuestion:e.question,onOpenBlock:c,onOpenResearch:y,onOpenApp:a,onNextAction:v},C.id))}):null,B||F||H||U||G||Q||V?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:2,flexWrap:"wrap",marginTop:-2},children:[H&&d?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>d(H),style:Ee(n),children:[t.jsx(Ue,{size:12})," ",f]}):null,H&&m&&l?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>m(H),style:Ee(n),children:[t.jsx(Qr,{size:12})," ",l]}):null,B||F?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:q,style:Ee(n),children:[R?t.jsx(Ye,{size:12}):t.jsx(Jn,{size:12})," ",R?"Copied":"Copy"]}):null,U?t.jsx(an,{run:e,t:n,appContext:i,onOpenApp:a}):null,G?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>v({id:"save-dql-block",label:"Save as block",route:"dql_block_draft"}),style:Ee(n),children:[t.jsx(rt,{size:12})," Save as block"]}):null,Q?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>v({id:"research-deeper",label:"Research this deeper",route:"research"}),style:Ee(n),children:[t.jsx(et,{size:12})," Research deeper"]}):null,V?t.jsxs("button",{type:"button",className:"dql-ask-ghost",onClick:()=>L(V.id,Rt(pe(V))?"how":"trust"),style:Ee(n),children:[t.jsx(tt,{size:12})," How it was answered"]}):null]}):null]})}function fr({run:e,t:n,onSelect:r}){var i;return e.status!=="needs_clarification"||!((i=e.clarificationOptions)!=null&&i.length)||!r?null:t.jsx("div",{"aria-label":"Choose a governed meaning",style:{display:"grid",gap:7,maxWidth:620},children:e.clarificationOptions.map(s=>t.jsxs("button",{type:"button",className:"dql-hover dql-lift",onClick:()=>r(s),title:`Use governed evidence ${s.id}`,style:{display:"grid",gap:3,width:"100%",padding:"10px 12px",borderRadius:10,border:"1px solid var(--border-default)",background:"var(--bg-2)",color:n.textPrimary,cursor:"pointer",textAlign:"left",fontFamily:n.font},children:[t.jsx("span",{style:{fontSize:12.5,fontWeight:700},children:s.label}),s.description?t.jsx("span",{style:{fontSize:11,lineHeight:1.4,color:n.textMuted},children:s.description}):null]},s.id))})}function gr(e){const n=e.executionError;if(typeof n=="string"&&n.trim())return{stage:"execution",message:n};const r=P(n);if(r)return{stage:"execution",...r};const i=typeof e.refusalCode=="string"?e.refusalCode:void 0;if(i){const s=P(e.refusalDetails),o=typeof(s==null?void 0:s.message)=="string"&&s.message.trim()?s.message:typeof e.answer=="string"&&e.answer.trim()?e.answer:"No answer was accepted for this question.";return{stage:"answer",code:i,message:o}}}function Rt(e){return!!(P(e.resolvedAnalyticalPlan)||P(e.analyticalExecutionGraph)||P(e.analyticalExecutionReceipt)||P(e.analyticalFailure)||P(e.semanticExecutionTrace)||P(e.diagnosticReceipt)||gr(e))}function xr(e){if(!Rt(e))return;const n=P(e.diagnosticReceipt),r=P(e.resolvedAnalyticalPlan)??P(n==null?void 0:n.resolvedAnalyticalPlan);return{plan:r,frame:P(r==null?void 0:r.analyticalFrame),graph:P(e.analyticalExecutionGraph),receipt:P(e.analyticalExecutionReceipt),facts:P(e.analyticalFacts),narrative:P(e.analyticalNarrative),freshness:P(e.analyticalFreshnessObservation),failure:P(e.analyticalFailure)??P(n==null?void 0:n.failure)??gr(e),semantic:P(e.semanticExecutionTrace),diagnostic:n}}function Ui(){return["Plan","DQL","Compiled SQL","Lineage","Trust & evidence","Actual steps","Failure & repair"]}function Yi(e){return[e.includes("retry_same_plan")?"Retry same plan":void 0,e.includes("refresh_snapshot")?"Refresh snapshot and prepare retry":void 0,e.includes("request_access")||e.includes("change_authorized_connection")?"Change connection or request access":void 0,e.includes("edit_dql")?"Open DQL to repair":void 0,e.includes("open_sql_notebook")?"Open SQL in Notebook":void 0,e.includes("reapply_semantic_runtime")?"Reapply semantic runtime settings":void 0].filter(n=>!!n)}function Ji({run:e,contract:n,dqlArtifact:r,sql:i,lineage:s,t:o,onInsertSql:a,onInsertDql:u,onSaveBlock:d}){var ve,Re,we;const{dispatch:m}=zt(),f=n.plan,l=n.frame,c=n.graph,y=n.receipt,x=n.semantic,v=P(x==null?void 0:x.failure),g=n.failure??v,R=P(x==null?void 0:x.authoringRequest),I=P(x==null?void 0:x.runtimeRequest),L=qe(x==null?void 0:x.bindings),D=qe(x==null?void 0:x.steps),z=P(x==null?void 0:x.targetBinding),O=P(z==null?void 0:z.semanticSnapshot),B=P(z==null?void 0:z.executionTarget),E=P(B==null?void 0:B.redactedContext),F=P(z==null?void 0:z.compileTarget),N=P(x==null?void 0:x.executionReceipt),T=qe(v==null?void 0:v.candidates),b=P(l==null?void 0:l.timeContext),k=P(l==null?void 0:l.comparison),K=P(l==null?void 0:l.ranking),W=qe(l==null?void 0:l.dimensions),V=qe(l==null?void 0:l.memberBindings),U=qe(b==null?void 0:b.periods),Z=qe(l==null?void 0:l.requestedOutputs),Y=qe(c==null?void 0:c.nodes),Q=Array.from(new Set([...be(g==null?void 0:g.safeActions),...be(v==null?void 0:v.safeActions)])),le=qe(g==null?void 0:g.failedBindings),G=P(v==null?void 0:v.sqlExcerpt),H=e.artifacts.map(j=>Ne(pe(j))).find(Boolean),q=(r==null?void 0:r.name)??e.question,[ee,$]=p.useState(null),C=(j,ce)=>{const je=ce.derivation.trustTransition;return`${j} as immutable derivation ${ce.derivation.derivationId}. Trust: ${je.previous} → ${je.next}${je.requiresReview?" (review required)":""}.`},S=async()=>{if(!(!(r!=null&&r.source)||!u))try{const j=await ie.deriveAnalyticalRepair(e.id,{version:1,action:"edit_dql",dqlSource:r.source});u({sql:i,dqlArtifact:r,result:H,title:q,sourceRunId:e.id,question:e.question}),$(C("Opened DQL in Notebook",j))}catch(j){$(j instanceof Error?j.message:String(j))}},te=async()=>{if(!(!i||!a))try{const j=await ie.deriveAnalyticalRepair(e.id,{version:1,action:"open_sql_notebook",sqlText:i});a(i,`${q} repair`,{question:e.question,sourceRunId:e.id}),$(C("Opened SQL in Notebook",j))}catch(j){$(j instanceof Error?j.message:String(j))}},ae=async j=>{try{const ce=await ie.deriveAnalyticalRepair(e.id,{version:1,action:j});$(C(j==="retry_same_plan"?"Prepared the same bounded plan for retry":"Refreshed the governed snapshot and prepared the same plan for retry",ce))}catch(ce){$(ce instanceof Error?ce.message:String(ce))}},ne=async()=>{try{const j=await ie.deriveAnalyticalRepair(e.id,{version:1,action:"request_access"});$(C("Recorded the access/connection repair and opened Database settings",j)),m({type:"SET_SETTINGS_TAB",tab:"database"}),m({type:"SET_MAIN_VIEW",view:"settings"})}catch(j){$(j instanceof Error?j.message:String(j))}},He=()=>{m({type:"SET_SETTINGS_TAB",tab:"project"}),m({type:"SET_MAIN_VIEW",view:"settings"}),$("Opened Project & dbt settings. Test and apply the intended dbt Cloud Semantic Layer environment to refresh its verified metric inventory.")};return t.jsxs("div",{style:{display:"grid",gap:9},"aria-label":"How it answered",children:[t.jsxs("div",{role:"status",style:{display:"flex",gap:8,alignItems:"flex-start",padding:"10px 12px",borderRadius:8,border:`1px solid ${g?"var(--status-error-border)":"var(--status-success-border)"}`,background:g?"var(--status-error-bg)":"var(--status-success-bg)"},children:[g?t.jsx(Ze,{size:13,color:"var(--status-error)",style:{flexShrink:0,marginTop:2}}):t.jsx(xe,{size:13,color:"var(--status-success)",style:{flexShrink:0,marginTop:2}}),t.jsxs("div",{style:{fontSize:12,color:o.textSecondary,lineHeight:1.5,minWidth:0},children:[t.jsx("div",{style:{fontWeight:700,color:g?"var(--status-error)":"var(--status-success)"},children:g?"Execution failed":"Answered successfully"}),g?t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{marginTop:3,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:o.fontMono,fontSize:11},children:typeof g.message=="string"&&g.message.trim()?g.message:"The engine did not report a message. Open the DQL and SQL tabs to inspect what ran."}),t.jsx("div",{style:{marginTop:4,fontSize:10.5,color:o.textMuted},children:[g.code,g.phase?`during ${g.phase}`:""].filter(Boolean).map(A).join(" · ")})]}):t.jsx("div",{style:{marginTop:2},children:typeof(y==null?void 0:y.rowCount)=="number"?`Returned ${y.rowCount} row${y.rowCount===1?"":"s"}.`:"The query ran and returned a result."})]})]}),t.jsx(ht,{index:1,label:"Plan",t:o,open:!g,children:t.jsx(Dt,{rows:[["Question type",A((l==null?void 0:l.questionType)??(f==null?void 0:f.questionType))],["Selected route",A((c==null?void 0:c.route)??(f==null?void 0:f.recommendedRoute))],["Metric",be(l==null?void 0:l.metricConceptIds).join(", ")],["Entity grain",be(l==null?void 0:l.entityGrainIds).join(", ")],["Dimensions",W.map(j=>`${A(j.dimensionId)} (${A(j.role)})`).join(", ")],["Member filters",V.map(j=>`${A(j.dimensionId)}: ${Array.isArray(j.canonicalValues)?j.canonicalValues.length:0} bound value(s)`).join(", ")],["Time policy",[b==null?void 0:b.timeRole,b==null?void 0:b.grain,b==null?void 0:b.timezone,b==null?void 0:b.completenessPolicy].map(A).filter(Boolean).join(" · ")],["Periods",U.map(j=>`${A(j.id)}: ${A(j.start)} → ${A(j.end)}`).join(`
|
|
80
|
+
`)],["Comparison",k?`${A(k.basePeriodId)} vs ${be(k.comparisonPeriodIds).join(", ")} · ${A(k.alignment)}`:l?"Not requested":"Not available — analytical planning did not complete"],["Ranking",K?`${A(K.direction)} · top ${A(K.limit)} · ${A(K.tiePolicy)}`:l?"Not requested":"Not available — analytical planning did not complete"],["Outputs",Z.map(j=>`${A(j.id)} (${A(j.kind)})`).join(", ")],["Semantic metrics",be(R==null?void 0:R.metrics).join(", ")],["Semantic dimensions",be(R==null?void 0:R.dimensions).join(", ")]],t:o})}),t.jsx(ht,{index:2,label:"Trust & evidence",t:o,children:t.jsx(Dt,{rows:[["Trust state",e.trustState],["Snapshot",A((f==null?void 0:f.snapshotId)??(c==null?void 0:c.snapshotId))],["Plan fingerprint",A((f==null?void 0:f.fingerprint)??(c==null?void 0:c.planFingerprint))],["Graph fingerprint",A(c==null?void 0:c.fingerprint)],["Receipt",A(y==null?void 0:y.receiptId)],["Result fingerprint",A(y==null?void 0:y.resultFingerprint)],["Freshness observed through",A((ve=n.freshness)==null?void 0:ve.observedThrough)],["Fact set",A((Re=n.facts)==null?void 0:Re.fingerprint)],["Semantic adapter",A(x==null?void 0:x.adapter)],["Semantic compile status",A(x==null?void 0:x.status)],["Target proof",A((we=P(z==null?void 0:z.proof))==null?void 0:we.status)],["Target binding",A(z==null?void 0:z.bindingFingerprint)],["Compile target",A(F==null?void 0:F.kind)],["Local semantic snapshot",A((O==null?void 0:O.semanticCatalogFingerprint)??(O==null?void 0:O.sourceFingerprint))],["Runtime metric inventory proof",A(F==null?void 0:F.semanticCatalogFingerprint)],["Execution target",[B==null?void 0:B.driver,E==null?void 0:E.account,E==null?void 0:E.database,E==null?void 0:E.schema,E==null?void 0:E.role,E==null?void 0:E.warehouse].map(A).filter(Boolean).join(" · ")],["Semantic receipt",A(N==null?void 0:N.receiptId)],["Warehouse query ID",A(N==null?void 0:N.queryId)],["Executed SQL proof",A(N==null?void 0:N.executedSqlFingerprint)],["Runtime metrics",be(I==null?void 0:I.metrics).join(", ")],["Runtime dimensions",be(I==null?void 0:I.dimensions).join(", ")],["Member bindings",L.map(j=>`${A(j.authoringReference)} → ${A(j.runtimeReference)}${be(j.entityPath).length?` via ${be(j.entityPath).join(" → ")}`:""} (${A(j.status)})`).join(`
|
|
81
|
+
`)]],t:o,mono:!0})}),t.jsx(ht,{index:3,label:"Actual steps",t:o,children:t.jsxs("div",{style:{display:"grid",gap:6},children:[D.map((j,ce)=>t.jsxs("div",{style:{fontSize:11.5,color:o.textSecondary},children:[t.jsxs("strong",{style:{color:A(j.status)==="failed"?"var(--status-error)":o.textPrimary},children:[ce+1,". ",A(j.label)]})," ","— ",A(j.status)," · ",A(j.detail)]},`semantic:${A(j.id)||ce}`)),e.steps.map(j=>t.jsxs("div",{style:{fontSize:11.5,color:o.textSecondary},children:[t.jsxs("strong",{style:{color:o.textPrimary},children:[j.index+1,". ",j.goal]})," — ",j.status,", ",j.attempts," attempt",j.attempts===1?"":"s"]},j.id)),Y.map((j,ce)=>t.jsxs("div",{style:{fontSize:11.5,color:o.textSecondary},children:[t.jsxs("span",{style:{color:o.accent,fontFamily:o.fontMono},children:[ce+1,". ",A(j.kind)]})," ","· ",A(j.id)]},A(j.id)||ce)),D.length===0&&e.steps.length===0&&Y.length===0?t.jsx(St,{t:o,children:"No executable steps were recorded."}):null]})}),t.jsx(ht,{index:4,label:"Failure & repair",t:o,open:!!g,children:g?t.jsxs("div",{style:{display:"grid",gap:9},children:[t.jsx(Dt,{rows:[["Failure ID",A(g.failureId)],["Recoverability",A(g.recoverability)],["Failed bindings",le.map(j=>`${A(j.qualifiedId??j.role)} (${A(j.reasonCode)})`).join(", ")],["Safe actions",Q.join(", ")],["DQL fingerprint",A(g.dqlFingerprint)],["SQL fingerprint",A(g.sqlFingerprint)],["Semantic failure code",A(v==null?void 0:v.code)],["Failing identifier",A(v==null?void 0:v.identifier)],["Compiled SQL proof",A(v==null?void 0:v.compiledSqlFingerprint)],["Path candidates",T.map(j=>`${A(j.label)}
|
|
82
|
+
${A(j.runtimeReference)}`).join(`
|
|
83
|
+
`)]],t:o,mono:!0}),A(G==null?void 0:G.text)?t.jsxs("div",{children:[t.jsxs("div",{style:{fontSize:10.5,fontWeight:700,color:o.textSecondary,marginBottom:5},children:["Failing SQL context · lines ",A(G==null?void 0:G.startLine),"–",A(G==null?void 0:G.endLine)]}),t.jsx("pre",{style:nt(o),children:A(G==null?void 0:G.text)})]}):null,t.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6},"aria-label":"Safe repair actions",children:[Q.includes("edit_dql")&&u?t.jsxs("button",{type:"button",onClick:()=>void S(),style:J(o),children:[t.jsx(nn,{size:12})," Open DQL to repair"]}):null,Q.includes("open_sql_notebook")&&a?t.jsxs("button",{type:"button",onClick:()=>void te(),style:J(o),children:[t.jsx(tn,{size:12})," Open SQL in Notebook"]}):null,Q.includes("retry_same_plan")?t.jsxs("button",{type:"button",onClick:()=>void ae("retry_same_plan"),style:J(o),children:[t.jsx(Mt,{size:12})," Retry same plan"]}):null,Q.includes("refresh_snapshot")?t.jsxs("button",{type:"button",onClick:()=>void ae("refresh_snapshot"),style:J(o),children:[t.jsx(Mt,{size:12})," Refresh snapshot and prepare retry"]}):null,Q.includes("request_access")||Q.includes("change_authorized_connection")?t.jsxs("button",{type:"button",onClick:()=>void ne(),style:J(o),children:[t.jsx(Ze,{size:12})," Change connection or request access"]}):null,Q.includes("reapply_semantic_runtime")?t.jsxs("button",{type:"button",onClick:He,style:J(o),children:[t.jsx(Mt,{size:12})," Reapply semantic runtime settings"]}):null]})]}):t.jsxs("div",{style:{display:"grid",gap:8},children:[t.jsx(St,{t:o,children:"No failure was recorded for this run."}),r!=null&&r.sourcePath?null:r!=null&&r.source?t.jsxs("button",{type:"button",onClick:d,style:J(o),children:[t.jsx(rn,{size:12})," Save as draft block"]}):null]})}),ee?t.jsx("div",{role:"status",style:{fontSize:10.5,color:ee.toLowerCase().includes("created")?"var(--status-success)":"var(--status-error)"},children:ee}):null]})}function ht({index:e,label:n,t:r,open:i=!1,children:s}){return t.jsxs("details",{open:i,style:{border:"1px solid var(--border-subtle)",borderRadius:8,background:"var(--bg-1)",overflow:"hidden"},children:[t.jsxs("summary",{style:{cursor:"pointer",listStyle:"none",padding:"8px 10px",display:"flex",gap:7,alignItems:"center",fontSize:11.5,fontWeight:700,color:r.textPrimary},children:[t.jsx("span",{style:{width:18,height:18,borderRadius:999,display:"inline-flex",alignItems:"center",justifyContent:"center",background:"var(--accent-dim)",color:"var(--accent)",fontSize:10},children:e}),n]}),t.jsx("div",{style:{display:"grid",gap:8,padding:"0 10px 10px"},children:s})]})}function Dt({rows:e,t:n,mono:r=!1}){return t.jsx("div",{style:{display:"grid",gap:6},children:e.filter(([,i])=>i).map(([i,s])=>t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"112px minmax(0, 1fr)",gap:8,alignItems:"start"},children:[t.jsx("span",{style:{fontSize:10.5,color:n.textMuted},children:i}),t.jsx("span",{style:{fontSize:10.5,color:n.textSecondary,fontFamily:r?n.fontMono:n.font,whiteSpace:"pre-wrap",overflowWrap:"anywhere"},children:s})]},i))})}function St({t:e,children:n}){return t.jsx("div",{style:{fontSize:11,color:e.textMuted},children:n})}function qe(e){return Array.isArray(e)?e.flatMap(n=>P(n)?[P(n)]:[]):[]}function be(e){return Array.isArray(e)?e.filter(n=>typeof n=="string"):[]}function A(e){return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):""}function yt(e){return{question:e.question??e.label,selectedEvidenceId:e.id}}function it(e){return!e.artifacts.some(r=>!!_t(pe(r)))&&e.status!=="blocked"&&e.status!=="needs_clarification"&&e.artifacts.some(r=>r.kind==="answer"||r.kind==="research_run")}function Xi({run:e,artifact:n,tab:r,t:i,appContext:s,onOpenApp:o,onChangeTab:a,onClose:u,onSaveBlock:d,onInsertSql:m,onInsertDql:f}){const l=pe(n),c=Te(e)??st(l),y=De(e)??(typeof l.sql=="string"?l.sql:void 0),x=Ne(l),v=jt(e,n),g=un(e),R=pr(e),I=cn(e),L=n.trustState==="certified",D=e.status==="blocked"||n.trustState==="blocked",z=it(e),O=xr(l),B=ur({analytical:!!O,blocked:D,hasDql:!!(c!=null&&c.source),hasSql:!!y,hasLineage:R.length>0}),E=B.some(b=>b.id===r)?r:B[0].id,F=D?"Blocked":L?"Certified":n.trustState==="governed"||n.trustState==="grounded"?"Governed":"AI-generated",N=D?"var(--status-error)":L?"var(--status-success)":n.trustState==="governed"||n.trustState==="grounded"?"var(--accent)":"var(--status-warning)",T=D?"var(--status-error-bg)":L?"var(--status-success-bg)":n.trustState==="governed"||n.trustState==="grounded"?"var(--accent-dim)":"var(--status-warning-bg)";return t.jsxs("div",{style:{width:"clamp(300px, 34vw, 440px)",flexShrink:0,background:"var(--bg-2)",borderLeft:"1px solid var(--border-default)",display:"flex",flexDirection:"column",minHeight:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:10,padding:"14px 16px 12px",borderBottom:"1px solid var(--border-subtle)"},children:[t.jsx("span",{style:{width:32,height:32,borderRadius:8,background:T,color:N,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0,border:"1px solid var(--border-subtle)"},children:t.jsx(Ge,{kind:n.kind})}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("div",{style:{fontSize:13,fontWeight:650,color:i.textPrimary,lineHeight:1.35},children:jt(e,n)}),t.jsx("div",{style:{fontSize:11,color:i.textMuted,marginTop:2},children:At(n,l)})]}),t.jsx("span",{style:{border:`1px solid ${N}`,color:N,background:T,borderRadius:999,padding:"2px 8px",fontSize:10,fontWeight:700,flexShrink:0,marginTop:2},children:F}),t.jsx("button",{type:"button",onClick:u,title:"Close",className:"dql-ask-ghost",style:{width:24,height:24,borderRadius:6,border:"none",background:"none",color:i.textMuted,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer",flexShrink:0},children:t.jsx(bt,{size:14})})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"10px 16px",borderBottom:"1px solid var(--border-subtle)"},children:[z?t.jsx(an,{run:e,t:i,appContext:s,onOpenApp:o}):null,z?t.jsxs("button",{type:"button",className:"dql-hover",onClick:d,style:{display:"inline-flex",alignItems:"center",gap:6,padding:"7px 13px",borderRadius:8,border:"1px solid var(--border-default)",background:"var(--bg-2)",color:i.textSecondary,fontSize:12,fontWeight:600,cursor:"pointer",fontFamily:i.font},children:[t.jsx(rt,{size:13})," Save as block"]}):null,t.jsx("div",{style:{flex:1}}),t.jsx("button",{type:"button",title:"More",className:"dql-hover",style:{width:28,height:28,borderRadius:7,border:"1px solid var(--border-default)",background:"var(--bg-2)",color:i.textMuted,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer"},children:t.jsx(Zr,{size:14})})]}),t.jsx("div",{style:{display:"flex",alignItems:"center",gap:16,padding:"0 16px",borderBottom:"1px solid var(--border-subtle)",flexShrink:0},children:B.map(b=>t.jsx("button",{type:"button",onClick:()=>a(b.id),style:{padding:"10px 1px",fontSize:12,fontWeight:600,cursor:"pointer",border:"none",background:"none",fontFamily:i.font,whiteSpace:"nowrap",color:E===b.id?i.textPrimary:i.textMuted,boxShadow:E===b.id?`inset 0 -2px 0 0 ${i.accent}`:"none"},children:b.label},b.id))}),t.jsxs("div",{style:{flex:1,minHeight:0,overflow:"auto",padding:"14px 16px 20px"},children:[E==="how"&&O?t.jsx(Ji,{run:e,contract:O,dqlArtifact:c,sql:y,lineage:R,t:i,onInsertSql:m,onInsertDql:f,onSaveBlock:d}):null,E==="dql"?c!=null&&c.source?t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[t.jsx("span",{style:{fontSize:11,color:i.textMuted},children:"Reusable governed artifact — save it as a block to certify."}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[f?t.jsx("button",{type:"button",onClick:()=>f({sql:y,dqlArtifact:c,result:x,chartConfig:x?We(l,x):void 0,title:v,sourceRunId:e.id,question:e.question}),style:J(i),children:"Open DQL in notebook"}):null,t.jsx(wt,{text:c.source,t:i,title:"Copy DQL"})]})]}),t.jsx("pre",{style:nt(i),children:c.source})]}):t.jsx(St,{t:i,children:"The selected plan failed before a DQL source could be materialized. Review the Plan and Failure & repair sections."}):null,E==="sql"?y?t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[t.jsx("span",{style:{fontSize:11,color:i.textMuted},children:"Attempted compiled SQL — open it in Notebook to inspect or repair."}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[m?t.jsx("button",{type:"button",onClick:()=>m(y,v,{question:e.question,sourceRunId:e.id}),style:J(i),children:"Open SQL in notebook"}):null,t.jsx(wt,{text:y,t:i,title:"Copy SQL"})]})]}),t.jsx("pre",{style:nt(i),children:y})]}):t.jsx(St,{t:i,children:"Compilation stopped before SQL was produced. The DQL, plan, trust evidence, and failure steps are still retained."}):null,E==="lineage"?t.jsxs("div",{style:{display:"grid",gap:8},children:[t.jsx("div",{style:{fontSize:11,color:i.textMuted,lineHeight:1.5},children:"Governed semantic objects and physical sources used to produce this result."}),R.map(b=>t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:9,padding:"9px 10px",border:"1px solid var(--border-subtle)",borderRadius:8,background:"var(--bg-1)"},children:[t.jsx(Un,{size:13,color:i.accent,style:{flexShrink:0,marginTop:2}}),t.jsxs("div",{style:{minWidth:0},children:[t.jsx("div",{style:{fontSize:12,fontWeight:650,color:i.textPrimary},children:b.name}),t.jsx("div",{style:{fontSize:10.5,color:i.textMuted,marginTop:2},children:[b.kind,b.detail].filter(Boolean).join(" · ")})]})]},`${b.kind??"asset"}:${b.name}`))]}):null,E==="trust"?t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[I?t.jsxs("div",{style:{display:"flex",gap:8,alignItems:"flex-start",padding:"10px 12px",borderRadius:8,background:L?"var(--status-success-bg)":"var(--status-warning-bg)",border:`1px solid ${L?"var(--status-success-border)":"var(--status-warning-border)"}`},children:[L?t.jsx(xe,{size:13,color:"var(--status-success)",style:{flexShrink:0,marginTop:1}}):t.jsx(Ze,{size:13,color:"var(--status-warning)",style:{flexShrink:0,marginTop:1}}),t.jsx("span",{style:{fontSize:12,color:i.textSecondary,lineHeight:1.5},children:I})]}):null,g.length>0?t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:i.textMuted,textTransform:"uppercase",letterSpacing:"0.05em",marginBottom:8},children:"Evidence"}),t.jsx("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:g.map(b=>t.jsxs("span",{style:kr(i,b.certified),children:[b.certified?t.jsx(xe,{size:11}):t.jsx(et,{size:11}),t.jsx("span",{children:b.label})]},b.label))})]}):null,e.evaluations.length>0?t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:i.textMuted,textTransform:"uppercase",letterSpacing:"0.05em",marginBottom:8},children:"Verification checks"}),t.jsx(br,{evaluations:e.evaluations,t:i})]}):null,e.steps.length>0?t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:11,fontWeight:700,color:i.textMuted,textTransform:"uppercase",letterSpacing:"0.05em",marginBottom:8},children:"Steps"}),t.jsx(vr,{steps:e.steps,t:i})]}):null,t.jsx(wr,{run:e,t:i})]}):null]})]})}function Zi({t:e,text:n,source:r,left:i,top:s,draft:o,inputRef:a,onDraftChange:u,onClose:d,onSend:m}){const f=(l,c)=>t.jsx("button",{type:"button",onClick:()=>m(c),style:{border:"1px solid var(--border-subtle)",background:"var(--bg-1)",color:e.textSecondary,borderRadius:999,padding:"3px 10px",fontSize:11,fontWeight:550,cursor:"pointer",fontFamily:e.font},children:l});return t.jsxs("div",{"data-selpop":"true",style:{position:"fixed",left:i,top:s,zIndex:90,width:324,background:"var(--bg-2)",border:"1px solid var(--border-default)",borderRadius:12,boxShadow:"0 10px 32px rgba(26,26,26,0.16)",padding:10,display:"flex",flexDirection:"column",gap:8,animation:"dql-agent-fadein 0.14s ease-out",fontFamily:e.font},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[t.jsx(Fe,{size:12,color:e.accent}),t.jsx("span",{style:{fontSize:11,fontWeight:700,color:e.textSecondary},children:"Follow up on this"}),t.jsx("span",{style:{fontSize:10,color:e.textMuted},children:r==="table"?"from the result":"from the answer"}),t.jsx("div",{style:{flex:1}}),t.jsx("button",{type:"button",onClick:d,style:{width:20,height:20,borderRadius:5,border:"none",background:"none",color:e.textMuted,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0},children:t.jsx(bt,{size:12})})]}),t.jsxs("div",{style:{borderLeft:`2px solid ${e.accent}`,background:"var(--accent-dim)",borderRadius:"0 6px 6px 0",padding:"5px 9px",fontSize:11.5,color:e.textSecondary,lineHeight:1.45,display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"},children:["“",n,"”"]}),t.jsxs("div",{style:{display:"flex",gap:6},children:[t.jsx("input",{ref:a,value:o,onChange:l=>u(l.target.value),onKeyDown:l=>{l.key==="Enter"&&(l.preventDefault(),m(o))},placeholder:"Ask about this…",style:{flex:1,minWidth:0,border:"1px solid var(--border-default)",borderRadius:8,padding:"7px 10px",fontSize:12.5,fontFamily:e.font,color:e.textPrimary,background:"var(--bg-1)",outline:"none"}}),t.jsx("button",{type:"button",onClick:()=>m(o),title:"Send follow-up",style:{width:30,height:30,flexShrink:0,borderRadius:8,border:"none",background:"var(--accent)",color:"#fff",display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer"},children:t.jsx(Kn,{size:13})})]}),t.jsxs("div",{style:{display:"flex",gap:5,flexWrap:"wrap"},children:[f("Why is this?","Why is this happening?"),f("Root cause","What is the root cause?"),f("Break it down","Break this down further")]})]})}function Ht(e){const n=e.replace(/^\/\w+\s+/,"").trim().replace(/[?.!]+$/,"");return(n?n.charAt(0).toUpperCase()+n.slice(1):"New app").slice(0,60)}function an({run:e,t:n,appContext:r,onOpenApp:i}){const[s,o]=p.useState(!1),[a,u]=p.useState(null),[d,m]=p.useState(!1),[f,l]=p.useState("list"),[c,y]=p.useState(""),[x,v]=p.useState(!1),[g,R]=p.useState(null),[I,L]=p.useState(null),D=p.useRef(null),z=async()=>{u(null),m(!1);try{const T=await ie.listAppsStrict();u(T),T.length===0&&l("new")}catch{u([]),m(!0)}},O=()=>{o(!0),R(null),l("list"),D.current=null,y(Ht(e.question)),z()},B=()=>{x||(o(!1),R(null))},E=async(T,b,k)=>{const K=Te(e);if(!(await ie.createAiPin(T,{dashboardId:b,title:Ht(e.question),answer:e.answer??e.summary,question:e.question,sql:De(e),certification:e.trustState==="certified"?"certified":"ai_generated",reviewStatus:e.trustState==="certified"?"certified":"needs_review",analysisPlan:K?{dqlArtifact:K}:void 0})).ok)throw new Error("Could not add to app.");L({appId:T,dashboardId:b,name:k}),o(!1)},F=async T=>{var b,k,K;if(!x){v(!0),R(null);try{let W=(r==null?void 0:r.appId)===T.id?r.dashboardId:void 0;if(!W){const V=await ie.getApp(T.id),U=(b=V==null?void 0:V.app)==null?void 0:b.homepage;if(W=(U==null?void 0:U.type)==="dashboard"?U.id:(K=(k=V==null?void 0:V.dashboards)==null?void 0:k[0])==null?void 0:K.id,!W){const Z=await ie.createAppDashboard(T.id,{title:"Overview"});if(!Z.ok)throw new Error(Z.error);W=Z.dashboard.id}}await E(T.id,W,T.name)}catch(W){R(W instanceof Error?W.message:"Could not add to app.")}finally{v(!1)}}},N=async()=>{if(x)return;const T=c.trim()||Ht(e.question);v(!0),R(null);try{if(!D.current){const b=await ie.createApp({name:T,domain:"general",dashboardTitle:"Overview",tags:[],owners:[],selectedBlockIds:[]});D.current={appId:b.app.id,dashboardId:b.dashboardId}}await E(D.current.appId,D.current.dashboardId,T),D.current=null}catch(b){R(b instanceof Error?b.message:"Could not create the app.")}finally{v(!1)}};return t.jsxs("div",{style:{position:"relative",display:"inline-flex",alignItems:"center",gap:6},children:[I?t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>i==null?void 0:i(I.appId,I.dashboardId),style:{...Qt(n),background:`${n.success}1a`,color:n.success,border:`1px solid ${n.success}55`,boxShadow:"none",cursor:i?"pointer":"default"},title:i?"Open the app":void 0,children:[t.jsx(Je,{size:13}),"Added to ",I.name,i?t.jsx(Vr,{size:13}):null]}):null,t.jsxs("button",{type:"button",className:"dql-hover dql-lift",onClick:O,style:I?J(n):Qt(n),children:[t.jsx(Vt,{size:13}),I?"Add to another":"Add to app"]}),s?t.jsxs(t.Fragment,{children:[t.jsx("div",{onClick:B,style:{position:"fixed",inset:0,zIndex:40}}),t.jsxs("div",{style:hs(n),children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:8},children:[t.jsx("span",{style:{fontSize:12,fontWeight:700,color:n.textPrimary},children:f==="new"?"Name the new app":"Add to an app"}),t.jsx("button",{type:"button",onClick:B,style:{border:"none",background:"transparent",color:n.textMuted,cursor:"pointer",fontSize:15,lineHeight:1},children:"×"})]}),g?t.jsx("div",{style:{fontSize:11,color:n.error,marginBottom:7,lineHeight:1.4},children:g}):null,f==="new"?t.jsxs("div",{style:{display:"grid",gap:8},children:[t.jsx("input",{autoFocus:!0,value:c,onChange:T=>y(T.target.value),onKeyDown:T=>{T.key==="Enter"&&N()},placeholder:"App name",style:ms(n)}),t.jsxs("div",{style:{display:"flex",gap:6},children:[a&&a.length>0?t.jsx("button",{type:"button",className:"dql-hover",onClick:()=>l("list"),style:J(n),children:"Back"}):null,t.jsxs("button",{type:"button",className:"dql-hover",disabled:x||!c.trim(),onClick:()=>void N(),style:{...Qt(n),flex:1,justifyContent:"center"},children:[x?t.jsx(Pe,{size:13,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):t.jsx(Ue,{size:13}),"Create & add"]})]})]}):a===null?t.jsx("div",{style:{fontSize:11.5,color:n.textMuted,padding:"8px 2px"},children:"Loading apps…"}):d?t.jsxs("div",{style:{display:"grid",gap:8},children:[t.jsx("div",{style:{fontSize:11.5,color:n.error,lineHeight:1.4},children:"Couldn't load your apps."}),t.jsxs("div",{style:{display:"flex",gap:6},children:[t.jsx("button",{type:"button",className:"dql-hover",onClick:()=>void z(),style:J(n),children:"Retry"}),t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>l("new"),style:{...Hn(n),width:"auto",flex:1,marginBottom:0,justifyContent:"center"},children:[t.jsx(Ue,{size:13})," New app…"]})]})]}):t.jsxs("div",{style:{display:"grid",gap:3,maxHeight:244,overflow:"auto"},children:[t.jsxs("button",{type:"button",className:"dql-hover",onClick:()=>l("new"),style:Hn(n),children:[t.jsx(Ue,{size:13})," New app…"]}),a.map(T=>t.jsxs("button",{type:"button",className:"dql-hover",disabled:x,onClick:()=>void F(T),style:ys(n),children:[t.jsx(Vt,{size:13,style:{flex:"0 0 auto",opacity:.7}}),t.jsx("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",textAlign:"left"},children:T.name})]},T.id))]})]})]}):null]})}function cn(e){var n;if(e.trustState==="certified")return"Answered from a certified block.";if(e.route==="dql_block_draft")return"Prepared an ownerless review draft. Add it to Block Studio when you are ready to save it.";if(e.trustState==="governed")return"Built from governed metrics and dimensions.";if(e.trustState==="grounded")return"Ran cleanly against your data. Save it as a block when it is reusable.";if(dn(e)){const r=e.artifacts.map(o=>o.payload).filter(o=>!!(o&&typeof o=="object"&&!Array.isArray(o)));if(r.some(o=>{const a=o.result;return!!(a&&typeof a=="object"&&!Array.isArray(a))}))return"Exploratory · DBT-grounded. The query and bounded join probes ran, but no certified relationship path covers it yet.";const s=(n=r.find(o=>typeof o.executionError=="string"))==null?void 0:n.executionError;return typeof s=="string"&&s.trim()?"Exploratory · DBT-grounded. DQL prepared a review-required query, but its bounded execution failed. Inspect the error and DQL artifact before reuse.":"Exploratory · DBT-grounded. DQL prepared a review-required query, but it has not executed yet."}return e.trustState==="review_required"?"AI-generated answer. Save it as a block when you want to keep it.":(e.trustState==="blocked",null)}function dn(e){return e.artifacts.some(n=>{const r=n.payload;return!!(r&&typeof r=="object"&&!Array.isArray(r)&&r.exploratoryCandidate)})}function es(e){return e.trustState==="certified"?"Certified answer":e.route==="dql_block_draft"?"Draft block":dn(e)?"Exploratory DBT-grounded answer":e.route==="semantic_answer"?"Semantic answer":e.route==="generated_answer"?"AI-generated answer":ir[e.route]}function ts({artifact:e,payload:n,t:r,onOpenApp:i}){const s=typeof n.sessionId=="string"?n.sessionId:void 0,o=n.proposal&&typeof n.proposal=="object"?n.proposal:void 0,a=typeof n.proposalHash=="string"?n.proposalHash:void 0,[u,d]=p.useState(()=>o?Fr(o):new Set),[m,f]=p.useState(!1),[l,c]=p.useState(null),[y,x]=p.useState(null);if(!o||!s)return t.jsxs("div",{style:Zt(r),children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(Ge,{kind:e.kind}),t.jsx("div",{style:{fontSize:12,fontWeight:800,color:r.textPrimary},children:e.title})]}),t.jsx("div",{style:{fontSize:11.5,color:r.textMuted},children:"This proposal is no longer available. Ask again to rebuild it."})]});const v=async()=>{var R,I;f(!0),c(null);const g=await ie.commitAppAiBuild(s,{selectedTileIds:Array.from(u),expectedProposalHash:a});if(f(!1),!g.ok){c(g.error);return}x({appId:((R=g.app)==null?void 0:R.id)??g.session.appId??"",dashboardId:g.dashboardId??void 0,name:((I=g.app)==null?void 0:I.name)??e.title})};return t.jsxs("div",{style:Zt(r),children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(Ge,{kind:e.kind}),t.jsx("div",{style:{fontSize:12,fontWeight:800,color:r.textPrimary,flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Be(e.title)})]}),y?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:6,color:r.success,fontSize:12,fontWeight:750},children:[t.jsx(Je,{size:13})," Created ",y.name]}),y.appId&&i?t.jsx("button",{type:"button",className:"dql-hover",onClick:()=>i(y.appId,y.dashboardId),style:J(r),children:"Open app"}):null]}):t.jsx(Nr,{proposal:o,t:r,selected:u,onToggle:g=>{d(R=>{const I=new Set(R);return I.has(g)?I.delete(g):I.add(g),I})},onCreate:()=>void v(),busy:m,error:l,compact:!0})]})}function hr({artifact:e,certifiedBlockName:n,initialResult:r,initialChartConfig:i,payload:s,t:o,themeMode:a,embedded:u=!1}){var H;const[d,m]=p.useState(e),[f,l]=p.useState(()=>e.parameters??[]),[c,y]=p.useState(()=>({...e.parameterValues??{},...Jt(s)})),[x,v]=p.useState(r),[g,R]=p.useState(i),[I,L]=p.useState(!!n),[D,z]=p.useState(!1),[O,B]=p.useState(null),[E,F]=p.useState(!1),[N,T]=p.useState(""),[b,k]=p.useState(""),K=p.useRef(!1),W=p.useRef(e);W.current=e;const V=Ti(e);p.useEffect(()=>{const q=W.current;if(m(q),F(!1),!n){l(q.parameters??[]),y({...q.parameterValues??{},...Jt(s)}),L(!1);return}let ee=!1;return L(!0),ie.getCertifiedBlockParameters(n).then($=>{ee||(l($.parameters),y(C=>({...Object.fromEntries($.parameters.flatMap(S=>S.default===void 0?[]:[[S.name,S.default]])),...C})))}).catch($=>{ee||B($ instanceof Error?$.message:String($))}).finally(()=>{ee||L(!1)}),()=>{ee=!0}},[V,n]);const U=async()=>{if(!K.current){K.current=!0,z(!0),B(null);try{const q=await ie.invokeDqlArtifact(d,c,void 0,n);v(q.result),m(q.artifact),q.result.chartConfig&&typeof q.result.chartConfig=="object"&&R(q.result.chartConfig),q.parameters.length>0&&l(q.parameters)}catch(q){B(q instanceof Error?q.message:String(q))}finally{K.current=!1,z(!1)}}},Z=p.useMemo(()=>nr(d,x),[d,x]),Y=()=>{const q=Z[0];q&&(T(q.column),k(q.values[0]==null?"":String(q.values[0])),F(!0),B(null))},Q=async()=>{try{const q=d.kind==="sql_block"?await ie.addDqlArtifactResultFilter(d,x.columns,N,b):$i(d,x,N,b);m(q.artifact),l(q.artifact.parameters??[]),y(ee=>({...ee,...q.artifact.parameterValues??{}})),F(!1),B(null)}catch(q){B(q instanceof Error?q.message:String(q))}},le=f.some(Zn),G=Object.entries(c).filter(([,q])=>q!=null&&q!=="");return t.jsxs("div",{style:{display:"grid",gap:9},children:[G.length>0?t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap",padding:u?"8px 12px 0":0},children:[t.jsx("span",{style:{fontSize:10.5,fontWeight:750,color:o.textMuted},children:"Applied inputs"}),G.map(([q,ee])=>t.jsxs("span",{style:{fontSize:10.5,color:o.textSecondary,border:`1px solid ${o.cellBorder}`,background:o.appBg,borderRadius:999,padding:"2px 7px"},children:[q.replace(/_/g," ")," = ",ns(ee)]},q))]}):null,I?t.jsx("div",{style:{fontSize:10.5,color:o.textMuted},children:"Loading reusable inputs…"}):le||Z.length>0?t.jsxs("div",{style:{display:"grid",gap:8,padding:9,margin:u?"0 12px":0,border:`1px solid ${o.cellBorder}`,borderRadius:7,background:o.appBg},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("div",{style:{fontSize:11,fontWeight:800,color:o.textPrimary},children:"Change DQL inputs"}),t.jsx("div",{style:{fontSize:10,color:o.textMuted},children:"Reruns this DQL artifact directly. It does not start another AI search."})]}),Z.length>0?t.jsxs("button",{type:"button",onClick:Y,style:J(o),children:[t.jsx(Ue,{size:11})," Add result filter"]}):null,t.jsxs("button",{type:"button",disabled:D,onClick:()=>void U(),style:{...J(o),color:o.accent,opacity:D?.65:1},children:[D?t.jsx(Pe,{size:11,style:{animation:"dql-agent-run-spin 0.8s linear infinite"}}):t.jsx(Fe,{size:11}),D?"Running…":"Apply"]})]}),E?t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"minmax(150px, 1fr) minmax(150px, 1fr) auto auto",gap:7,alignItems:"end",padding:8,border:`1px solid ${o.cellBorder}`,borderRadius:7,background:o.cellBg},children:[t.jsxs("label",{style:{display:"grid",gap:4,fontSize:10,fontWeight:750,color:o.textSecondary},children:["Result column",t.jsx("select",{"aria-label":"Result column for new DQL input",value:N,onChange:q=>{const ee=q.target.value,$=Z.find(C=>C.column===ee);T(ee),k(($==null?void 0:$.values[0])==null?"":String($.values[0]))},style:On(o),children:Z.map(q=>t.jsx("option",{value:q.column,children:q.column.split("_").join(" ")},q.column))})]}),t.jsxs("label",{style:{display:"grid",gap:4,fontSize:10,fontWeight:750,color:o.textSecondary},children:["Default value",t.jsx("input",{"aria-label":"Default value for new DQL input",value:b,list:`ask-filter-${N}`,onChange:q=>k(q.target.value),style:On(o)}),t.jsx("datalist",{id:`ask-filter-${N}`,children:(((H=Z.find(q=>q.column===N))==null?void 0:H.values)??[]).map(q=>t.jsx("option",{value:String(q)},`${typeof q}:${String(q)}`))})]}),t.jsx("button",{type:"button",onClick:()=>{Q()},style:{...J(o),color:o.accent},children:"Add input"}),t.jsx("button",{type:"button",onClick:()=>F(!1),style:J(o),children:"Cancel"})]}):null,f.length>0?t.jsx(mi,{parameters:f,values:c,onChange:(q,ee)=>y($=>({...$,[q]:ee})),t:o}):null,Z.length>0?t.jsx("div",{style:{fontSize:9.5,color:o.textMuted},children:"Extra filters are available only for semantic dimensions in this result. They stay transient until you explicitly save a block."}):null]}):null,O?t.jsx("div",{style:{fontSize:10.5,color:o.error},children:O}):null,t.jsx(en,{result:x,themeMode:a,t:o,chartConfig:g,embedded:u,tabLabels:u?{table:"Results",chart:"Visualization"}:void 0})]})}function Jt(e){const n=e.result&&typeof e.result=="object"&&!Array.isArray(e.result)?e.result:void 0,r=Array.isArray(n==null?void 0:n.parameters)?n.parameters:Array.isArray(e.parameters)?e.parameters:[];return Object.fromEntries(r.flatMap(i=>{if(!i||typeof i!="object")return[];const s=i;return typeof s.name=="string"?[[s.name,s.value]]:[]}))}function ns(e){return Array.isArray(e)?e.map(n=>String(n)).join(", "):typeof e=="boolean"?e?"true":"false":String(e)}function yr(e,n){const r=n.result&&typeof n.result=="object"&&!Array.isArray(n.result)?n.result:void 0,i=n.block&&typeof n.block=="object"&&!Array.isArray(n.block)?n.block:void 0;return[r==null?void 0:r.blockName,n.sourceCertifiedBlock,i==null?void 0:i.name,e.ref].find(o=>typeof o=="string"&&o.trim().length>0)}function mr({artifact:e,t:n,themeMode:r,onInsertSql:i,onInsertDql:s,insertDqlActionLabel:o,sourceRunId:a,sourceQuestion:u,onOpenBlock:d,onOpenResearch:m,onOpenApp:f,onNextAction:l}){const c=e.payload&&typeof e.payload=="object"?e.payload:{};if(e.kind==="app_proposal")return t.jsx(ts,{artifact:e,payload:c,t:n,onOpenApp:f});const y=Ne(c),x=st(c),v=_t(c),g=typeof c.sql=="string"?c.sql:typeof c.sqlPreview=="string"?c.sqlPreview:typeof c.proposedSql=="string"?c.proposedSql:void 0,R=typeof c.name=="string"?c.name:e.title,I=typeof c.path=="string"?c.path:e.ref,L=c.draftBlock&&typeof c.draftBlock=="object"&&!Array.isArray(c.draftBlock)?c.draftBlock:void 0,D=typeof(L==null?void 0:L.path)=="string"?L.path:void 0,z=typeof(L==null?void 0:L.name)=="string"?L.name:void 0,O=(x==null?void 0:x.sourcePath)??D??(e.kind==="dql_block_draft"?I:void 0),B=(x==null?void 0:x.name)??z??R,E=(x==null?void 0:x.kind)==="sql_block"||e.kind==="dql_block_draft"?"Open DQL draft":"Open DQL artifact",F=c.plan&&typeof c.plan=="object"?c.plan:void 0,N=Array.isArray(F==null?void 0:F.steps)?F.steps:[],T=Array.isArray(F==null?void 0:F.gaps)?F.gaps.map(String):[],b=typeof c.researchRunId=="string"?c.researchRunId:e.kind==="research_run"&&typeof e.ref=="string"?e.ref:void 0,k=typeof c.notebookPath=="string"?c.notebookPath:void 0,K=Array.isArray(c.generatedPaths)?c.generatedPaths.filter(Y=>typeof Y=="string"):[],W=c.narration&&typeof c.narration=="object"?c.narration:void 0,V=Array.isArray(W==null?void 0:W.keyFindings)?W.keyFindings.filter(Y=>typeof Y=="string"):[],U=typeof(W==null?void 0:W.recommendation)=="string"?W.recommendation:void 0,Z=e.trustState==="certified"?yr(e,c):void 0;if(e.kind==="dql_block_draft"){const Y=le=>Array.isArray(le)?le.filter(G=>typeof G=="string"):void 0,Q=c.certifierVerdict&&typeof c.certifierVerdict=="object"?c.certifierVerdict:void 0;return t.jsx(hi,{t:n,name:typeof c.name=="string"?c.name:R,status:"draft",description:typeof c.description=="string"?c.description:void 0,dql:(x==null?void 0:x.source)??(typeof c.dqlSource=="string"?c.dqlSource:void 0),sqlPreview:g,grain:typeof c.grain=="string"?c.grain:void 0,outputs:Y(c.outputs),dimensions:Y(c.dimensions)??(x==null?void 0:x.dimensions),entities:Y(c.entities),certifierVerdict:Q?{blocking:Y(Q.blocking)??[],warnings:Y(Q.warnings)??[],ready:!!Q.ready}:void 0,actions:t.jsxs(t.Fragment,{children:[g&&s?t.jsx("button",{type:"button",onClick:()=>s({sql:g,dqlArtifact:x,result:y,chartConfig:y?We(c,y):void 0,title:R,sourceRunId:a,question:u}),style:J(n),children:o??"Insert as DQL cell"}):g&&i?t.jsx("button",{type:"button",onClick:()=>i(g,R,{question:u,sourceRunId:a}),style:J(n),children:"Insert SQL preview"}):null,O&&d?t.jsx("button",{type:"button",onClick:()=>d(O,B),style:J(n),children:E}):null]})})}return t.jsxs("div",{style:Zt(n),children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx(Ge,{kind:e.kind}),t.jsx("div",{style:{fontSize:12,fontWeight:800,color:n.textPrimary,flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:Be(e.title)})]}),V.length>0?t.jsxs("div",{style:{display:"grid",gap:4},children:[t.jsx("div",{style:{fontSize:11,fontWeight:800,color:n.textSecondary},children:"Key findings"}),t.jsx(Wn,{items:V,t:n,renderItem:(Y,Q)=>t.jsxs("div",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.4,display:"flex",gap:6},children:[t.jsx("span",{style:{color:n.accent},children:"•"}),t.jsx("span",{children:Y})]},Q)})]}):N.length>0?t.jsx("div",{style:{display:"grid",gap:5},children:t.jsx(Wn,{items:N,t:n,renderItem:(Y,Q)=>t.jsxs("div",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.35},children:[Q+1,". ",String(Y.thought??Y.expectation??"Research step")]},Q)})}):null,U?t.jsxs("div",{style:{fontSize:11.5,color:n.textPrimary,lineHeight:1.4,display:"flex",gap:6},children:[t.jsx("span",{style:{color:n.accent},children:"→"}),t.jsx("span",{children:U})]}):null,y?x?t.jsx(hr,{artifact:x,certifiedBlockName:Z,initialResult:y,initialChartConfig:We(c,y),payload:c,t:n,themeMode:r}):t.jsx(en,{result:y,themeMode:r,t:n,chartConfig:We(c,y)}):null,x?t.jsxs("details",{children:[t.jsxs("summary",{style:{cursor:"pointer",fontSize:11,color:n.textSecondary,listStyle:"none",display:"flex",alignItems:"center",gap:5},children:[t.jsx(rt,{size:12}),t.jsx("span",{children:"View DQL artifact"}),t.jsxs("span",{style:{marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:4},children:[x.source?t.jsx(wt,{text:x.source,t:n,title:"Copy DQL"}):null,!O&&l?t.jsxs("button",{type:"button",className:"dql-hover",title:"Save this DQL as a reusable block",onClick:Y=>{Y.preventDefault(),Y.stopPropagation(),l({id:"save-dql-block",label:"Save as DQL block",route:"dql_block_draft"})},style:{border:"none",background:"transparent",cursor:"pointer",color:n.accent,display:"inline-flex",alignItems:"center",gap:3,fontSize:10.5,fontWeight:700,padding:"2px 4px"},children:[t.jsx(rn,{size:12})," Save as block"]}):null]})]}),x.sourcePath?t.jsx("div",{style:{marginTop:6,fontSize:10.5,color:n.textMuted},children:x.sourcePath}):null,t.jsx("pre",{style:{...nt(n),marginTop:6},children:x.source})]}):null,g?t.jsxs("details",{children:[t.jsxs("summary",{style:{cursor:"pointer",fontSize:11,color:n.textSecondary,listStyle:"none",display:"flex",alignItems:"center",gap:5},children:[t.jsx(tn,{size:12}),t.jsx("span",{children:Sr(!!x)}),t.jsx("span",{style:{marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:4},children:t.jsx(wt,{text:g,t:n,title:"Copy SQL"})})]}),t.jsx("pre",{style:{...nt(n),marginTop:6},children:g})]}):null,T.length>0?t.jsxs("div",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.4},children:["Gaps: ",T.join(", ")]}):null,K.length>0?t.jsxs("div",{style:{fontSize:11.5,color:n.textSecondary,lineHeight:1.4},children:["Files: ",K.join(", ")]}):null,t.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[b&&m?t.jsx("button",{type:"button",onClick:()=>m(b,k),style:J(n),children:"Open research"}):null,g&&s?t.jsx("button",{type:"button",onClick:()=>s({sql:g,dqlArtifact:x,result:y,chartConfig:y?We(c,y):void 0,title:R,mixedSourcePlan:v,sourceRunId:a,question:u}),style:v?{...J(n),background:n.accent,borderColor:n.accent,color:"#fff",fontWeight:850,padding:"7px 11px"}:J(n),children:v?"Add workflow to notebook":x?"Insert as DQL cell":"Add SQL to notebook"}):g&&i?t.jsx("button",{type:"button",onClick:()=>i(g,R,{question:u,sourceRunId:a}),style:J(n),children:"Insert SQL preview"}):null,O&&d?t.jsx("button",{type:"button",onClick:()=>d(O,B),style:J(n),children:E}):null]})]})}function rs({run:e}){return e.trustState==="certified"?t.jsx(xe,{size:16,color:"#16a34a"}):e.trustState==="governed"?t.jsx(xe,{size:16,color:"#2563eb"}):e.trustState==="grounded"?t.jsx(xe,{size:16,color:"#2563eb"}):e.status==="completed"?t.jsx(Je,{size:16,color:"#16a34a"}):e.status==="blocked"?t.jsx(Gt,{size:16,color:"#ef4444"}):t.jsx(Gt,{size:16,color:"#d97706"})}function Ge({kind:e}){return e==="sql_cell"?t.jsx(tn,{size:14}):e==="dql_block_draft"?t.jsx(rt,{size:14}):e==="app_draft"||e==="app_proposal"?t.jsx(Vt,{size:14}):e==="research_run"?t.jsx(et,{size:14}):t.jsx(Fe,{size:14})}function is({run:e,t:n}){const r=e.trustState==="certified"?n.success:e.trustState==="governed"||e.trustState==="grounded"?n.accent:e.trustState==="blocked"?n.error:e.trustState==="not_applicable"?n.textMuted:n.warning,i=e.trustState==="certified"?"Certified":e.route==="dql_block_draft"?"Draft":dn(e)?"Exploratory":e.trustState==="blocked"?"Needs input":"AI-generated";return t.jsx("span",{style:{border:`1px solid ${r}55`,color:r,background:`${r}12`,borderRadius:999,padding:"3px 7px",fontSize:10,fontWeight:850},children:i})}function br({evaluations:e,t:n}){if(e.length===0)return null;const r=e.filter(s=>!s.passed),i=e.filter(s=>s.passed);return t.jsxs("div",{style:{display:"grid",gap:6,gridTemplateColumns:"minmax(0, 1fr)",minWidth:0},children:[r.map(s=>t.jsx(Xt,{evaluation:s,t:n},s.id)),i.length>0?t.jsxs("details",{children:[t.jsxs("summary",{className:"dql-hover",style:{cursor:"pointer",listStyle:"none",display:"inline-flex",alignItems:"center",gap:6,fontSize:11,fontWeight:700,color:n.textMuted,width:"fit-content"},children:[t.jsx(xe,{size:12,color:n.success}),t.jsxs("span",{children:[i.length," check",i.length>1?"s":""," verified"]})]}),t.jsx("div",{style:{display:"grid",gap:5,marginTop:7},children:i.map(s=>t.jsx(Xt,{evaluation:s,t:n},s.id))})]}):null]})}function Xt({evaluation:e,t:n}){const r=e.passed?n.success:e.severity==="blocking"?n.error:n.warning;return t.jsxs("div",{style:{display:"flex",gap:7,alignItems:"flex-start",fontSize:11.5,color:n.textSecondary,minWidth:0},children:[t.jsx("span",{style:{color:r,lineHeight:"16px",flex:"0 0 auto",fontWeight:800},children:e.passed?"OK":e.severity==="blocking"?"Stop":"Review"}),t.jsxs("span",{style:{lineHeight:1.4,minWidth:0,flex:1,overflowWrap:"anywhere"},children:[e.message,!e.passed&&e.suggestedRepair?t.jsxs("span",{style:{display:"block",color:n.textMuted,marginTop:1},children:["↳ ",e.suggestedRepair]}):null]})]})}function Ot({t:e,icon:n,label:r,tone:i}){const s=i==="accent"?e.accent:i==="warning"?e.warning:e.textMuted;return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,border:`1px solid ${s}44`,color:s,background:`${s}10`,borderRadius:999,padding:"2px 7px",fontSize:10,fontWeight:800},children:[n,t.jsx("span",{children:r})]})}function ss(e,n){switch(e){case"passed":return n.success;case"repaired":return n.accent;case"escalated":return n.accent;case"blocked":return n.error;default:return n.warning}}function vr({steps:e,t:n}){return t.jsxs("details",{style:{border:`1px solid ${n.headerBorder}`,background:n.cellBg,borderRadius:8,padding:"6px 9px"},children:[t.jsxs("summary",{style:{cursor:"pointer",fontSize:11.5,fontWeight:800,color:n.textSecondary,listStyle:"none",display:"flex",alignItems:"center",gap:6},children:[t.jsx(tt,{size:13}),t.jsxs("span",{children:["Plan trace · ",e.length," steps"]})]}),t.jsx("div",{style:{display:"grid",gap:10,marginTop:8},children:e.map(r=>{const i=ss(r.status,n);return t.jsxs("div",{style:{display:"grid",gap:4,paddingLeft:8,borderLeft:`2px solid ${i}55`},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[t.jsxs("span",{style:{fontSize:11.5,fontWeight:850,color:n.textPrimary},children:[r.index,". ",ir[r.route]]}),t.jsxs("span",{style:{border:`1px solid ${i}55`,color:i,background:`${i}12`,borderRadius:999,padding:"1px 6px",fontSize:9.5,fontWeight:850,display:"inline-flex",alignItems:"center",gap:3},children:[r.status==="escalated"?t.jsx(Un,{size:10}):r.status==="repaired"?t.jsx(nn,{size:10}):null,r.status.split("_").join(" ")]}),r.attempts>1?t.jsxs("span",{style:{fontSize:10,color:n.textMuted},children:[r.attempts," attempts"]}):null]}),r.goal?t.jsx("div",{style:{fontSize:11,color:n.textMuted,lineHeight:1.35},children:r.goal}):null,r.evaluations.length>0?t.jsx("div",{style:{display:"grid",gap:4},children:r.evaluations.map(s=>t.jsx(Xt,{evaluation:s,t:n},s.id))}):null]},r.id)})})]})}function os(e){if(e==="research")return"research";if(e==="sql_cell")return"sql";if(e==="dql_block_draft")return"block";if(e==="app_build")return"app";if(e==="certified_answer"||e==="semantic_answer"||e==="generated_answer")return"ask"}function ls(e,n){return n==="sql_cell"?`Create a SQL cell for: ${e.question}`:n==="dql_block_draft"?`Create a DQL block draft for: ${e.question}`:n==="app_build"?`Build an app for: ${e.question}`:n==="research"?`Research deeper: ${e.question}`:e.question}function Fn(e){return`${e}_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function Ve(e){return e.replace(/^\s*Outcome\s*:\s*[^\n]*\n+/i,"").replace(/^\s*Review required:\s*/gim,"").replace(/\breview-required\b/gi,"AI-generated").replace(/\*\*(.+?)\*\*/g,"$1").replace(/`([^`]+)`/g,"$1").replace(/^_(.+?)_$/gm,"$1").trim()}function Be(e){return e.replace(/^\s*Review required:\s*/gim,"").replace(/\breview-required\b/gi,"AI-generated").replace(/\bqueued for review\b/gi,"saved as a draft").trim()}function as(e,n){const r=i=>i.toLowerCase().replace(/[\s.,!?'"()`*_-]+/g," ").trim();return r(e)===r(n)}function Ne(e){var r,i;const n=[e.result,e.resultPreview,(r=e.researchRun)==null?void 0:r.resultPreview,(i=e.result)==null?void 0:i.result];for(const s of n){if(!s||typeof s!="object")continue;const o=s;if(!Array.isArray(o.rows)&&!Array.isArray(o.columns))continue;const a=Array.isArray(o.rows)?o.rows.filter(d=>!!(d&&typeof d=="object")):[],u=Array.isArray(o.columns)&&o.columns.length>0?o.columns.map(d=>typeof d=="string"?d:(d==null?void 0:d.name)??String(d)):a.length>0?Object.keys(a[0]):[];if(!(a.length===0&&u.length===0&&typeof o.rowCount!="number"))return{columns:u,rows:a,rowCount:typeof o.rowCount=="number"?o.rowCount:a.length,...typeof o.executionTime=="number"?{executionTime:o.executionTime}:{}}}}function We(e,n){const r=e.result&&typeof e.result=="object"?e.result:void 0,i=r!=null&&r.chartConfig&&typeof r.chartConfig=="object"?r.chartConfig:e.chartConfig&&typeof e.chartConfig=="object"?e.chartConfig:{},s=typeof e.suggestedViz=="string"?e.suggestedViz:typeof(r==null?void 0:r.suggestedViz)=="string"?r.suggestedViz:void 0,o=i.decisionSource==="authored"||i.decisionSource==="agent"||i.decisionSource==="data"||i.decisionSource==="user"?i.decisionSource:void 0,a=typeof i.chart=="string"?i.chart:s,u=a?a.toLowerCase().replace(/_/g,"-")==="single-value"?"kpi":a:void 0,d=n.columns,m=c=>typeof i[c]=="string"&&d.includes(i[c])?i[c]:void 0,f=Array.isArray(i.metrics)?i.metrics.filter(c=>typeof c=="string"&&d.includes(c)):[],l={...u?{chart:u}:{},...u?{decisionSource:o??"agent"}:{},...typeof i.rationale=="string"?{rationale:i.rationale}:{},...m("x")?{x:m("x")}:{},...m("y")?{y:m("y")}:{},...f.length>0?{metrics:f}:{},...m("color")?{color:m("color")}:{},...typeof i.title=="string"?{title:i.title}:{},...typeof i.colorPalette=="string"?{colorPalette:i.colorPalette}:{},...typeof i.maxItems=="number"?{maxItems:i.maxItems}:{}};return Object.keys(l).length>0?l:void 0}function jr(e,n){var i;const r=We(e,n);return(r==null?void 0:r.chart)==="table"&&(((i=r.metrics)==null?void 0:i.length)??0)<=1&&r.decisionSource!=="authored"&&r.decisionSource!=="user"?{...r,chart:void 0}:r}function st(e){const n=Xe(e.dqlArtifact);if(n)return n;const r=e.researchRun&&typeof e.researchRun=="object"&&!Array.isArray(e.researchRun)?e.researchRun:void 0;return Xe(r==null?void 0:r.dqlArtifact)}function Sr(e){return e?"View compiled SQL preview":"View SQL preview"}function wt({text:e,t:n,title:r="Copy"}){const[i,s]=p.useState(!1),o=async a=>{a.preventDefault(),a.stopPropagation();try{await navigator.clipboard.writeText(e),s(!0),setTimeout(()=>s(!1),1500)}catch{}};return t.jsxs("button",{type:"button",onClick:o,title:r,className:"dql-hover",style:{border:"none",background:"transparent",cursor:"pointer",color:i?n.success:n.textMuted,display:"inline-flex",alignItems:"center",gap:3,fontSize:10.5,fontWeight:650,padding:"2px 4px"},children:[i?t.jsx(Ye,{size:12}):t.jsx(Jn,{size:12}),i?"Copied":null]})}function pe(e){return e.payload&&typeof e.payload=="object"&&!Array.isArray(e.payload)?e.payload:{}}function cs(e){var i,s,o;const n=[],r=new Set;for(const a of e.artifacts){const u=pe(a),d=Array.isArray(u.memoryContext)?u.memoryContext:[];for(const f of d){if(!f||typeof f!="object")continue;const l=f,c=typeof l.title=="string"?l.title.trim():"";!c||r.has(`m:${c}`)||(r.add(`m:${c}`),n.push({kind:"memory",id:typeof l.id=="string"?l.id:void 0,label:c,detail:typeof l.content=="string"?l.content:void 0}))}const m=Array.isArray(u.appliedHints)?u.appliedHints:[];for(const f of m){if(!f||typeof f!="object")continue;const l=f,c=typeof l.title=="string"?l.title.trim():"";if(!c||r.has(`h:${c}`))continue;r.add(`h:${c}`);const y=typeof((i=l.lesson)==null?void 0:i.rule)=="string"?l.lesson.rule:typeof l.guidance=="string"?l.guidance:void 0,x=[typeof l.scopeReason=="string"?l.scopeReason:void 0,typeof l.graphReason=="string"?l.graphReason:void 0].filter(Boolean).join("; "),v=typeof((s=l.matchSignals)==null?void 0:s.lexicalScore)=="number"?l.matchSignals.lexicalScore:void 0,g=typeof((o=l.matchSignals)==null?void 0:o.graphScore)=="number"?l.matchSignals.graphScore:void 0,R=v!==void 0||g!==void 0?`Signals: lexical ${(v??0).toFixed(2)}, graph ${(g??0).toFixed(2)}`:void 0;n.push({kind:"hint",id:typeof l.hintId=="string"?l.hintId:void 0,label:c,detail:[y,x?`Matched: ${x}`:void 0,R].filter(Boolean).join(" · ")||void 0})}}return n.slice(0,6)}function wr({run:e,t:n}){const[r,i]=p.useState(!1),[s,o]=p.useState(new Set),a=p.useMemo(()=>cs(e).filter(d=>!d.id||!s.has(d.id)),[e,s]);if(a.length===0)return null;const u=async d=>{try{await ie.deleteAgentMemory(d),o(m=>new Set(m).add(d))}catch{}};return t.jsxs("div",{style:{display:"grid",gap:6,gridTemplateColumns:"minmax(0, 1fr)",minWidth:0},children:[t.jsxs("button",{type:"button",onClick:()=>i(d=>!d),style:ds(n),children:[t.jsx(vt,{size:11}),t.jsxs("span",{children:["Applied ",a.length," learning",a.length>1?"s":""]}),r?t.jsx(Yn,{size:11}):t.jsx(Ct,{size:11})]}),r?t.jsxs("div",{style:us(n),children:[a.map(d=>t.jsxs("div",{style:{display:"flex",gap:8,alignItems:"flex-start"},children:[t.jsx("span",{style:ps(n,d.kind),children:d.kind==="hint"?"governed lesson":"memory"}),t.jsxs("div",{style:{minWidth:0,flex:1},children:[t.jsx("div",{style:{fontSize:11.5,fontWeight:650,color:n.textPrimary},children:d.label}),d.detail?t.jsx("div",{style:{fontSize:11,color:n.textMuted,lineHeight:1.4,marginTop:1},children:d.detail}):null]}),d.kind==="memory"&&d.id?t.jsx("button",{type:"button",onClick:()=>void u(d.id),style:fs(n),children:"Stop using"}):null]},`${d.kind}:${d.label}`)),t.jsx("div",{style:{fontSize:10.5,color:n.textMuted},children:"Advisory only — learnings never override a certified answer. Manage them under Settings → Agent learning."})]}):null]})}function un(e){const n=[],r=new Set,i=e.trustState==="certified",s=(o,a)=>{typeof o!="string"||!o.trim()||r.has(o)||(r.add(o),n.push({label:o,certified:a}))};for(const o of e.artifacts){const a=pe(o);o.ref&&s(o.ref,i);const u=a.plan&&typeof a.plan=="object"?a.plan:void 0;Array.isArray(u==null?void 0:u.sources)&&u.sources.forEach(d=>s(d,i)),s(a.sourceCertifiedBlock,!0)}return n.slice(0,4)}function De(e){for(const n of e.artifacts){const r=pe(n),i=r.researchRun&&typeof r.researchRun=="object"?r.researchRun:void 0,s=r.proposedSql??r.sql??r.sqlPreview??(i==null?void 0:i.generatedSql)??(i==null?void 0:i.reviewedSql);if(typeof s=="string"&&s.trim())return s}}function Te(e){for(const n of e.artifacts){const r=pe(n),i=Xe(r.dqlArtifact);if(i)return i;const s=r.researchRun&&typeof r.researchRun=="object"&&!Array.isArray(r.researchRun)?r.researchRun:void 0,o=Xe(s==null?void 0:s.dqlArtifact);if(o)return o}}function pn(e){const n=e.route==="dql_block_draft"&&e.status!=="blocked"&&e.status!=="needs_clarification";if(e.route==="certified_answer"||!it(e)&&!n)return;const r=Te(e),i=De(e);if(!((!(r!=null&&r.source)||r.sourcePath)&&!i)){for(const s of e.artifacts){const o=pe(s),a=Ne(o),u=_t(o);if(a)return{sql:i,dqlArtifact:r,result:a,chartConfig:We(o,a),title:(r==null?void 0:r.name)??s.title??e.question,mixedSourcePlan:u,sourceRunId:e.id,question:e.question,executionTarget:e.executionTarget};if(u)return{sql:i,dqlArtifact:r,title:(r==null?void 0:r.name)??s.title??e.question,mixedSourcePlan:u,sourceRunId:e.id,question:e.question,executionTarget:e.executionTarget}}return{sql:i,dqlArtifact:r,title:(r==null?void 0:r.name)??e.question,sourceRunId:e.id,question:e.question,executionTarget:e.executionTarget}}}function _t(e){const n=e.mixedSourcePlan;if(!n||typeof n!="object"||Array.isArray(n))return;const r=n;if(["localDataset","localAlias","localKey","warehouseKey","warehouseExpression","warehouseSql"].every(s=>typeof r[s]=="string"&&String(r[s]).trim()))return{datasetId:typeof r.datasetId=="string"?r.datasetId:void 0,datasetName:typeof r.datasetName=="string"?r.datasetName:void 0,localDataset:String(r.localDataset),localAlias:String(r.localAlias),localKey:String(r.localKey),warehouseKey:String(r.warehouseKey),warehouseExpression:String(r.warehouseExpression),warehouseSql:String(r.warehouseSql),warehouseRelations:Array.isArray(r.warehouseRelations)?r.warehouseRelations.filter(s=>typeof s=="string"):void 0}}function kr(e,n){return{display:"inline-flex",alignItems:"center",gap:4,fontSize:10.5,padding:"2px 7px",borderRadius:999,background:n?`${e.success}14`:e.cellBg,color:n?e.success:e.textMuted,border:`1px solid ${n?`${e.success}44`:e.headerBorder}`}}function ds(e){return{display:"inline-flex",alignItems:"center",gap:5,alignSelf:"flex-start",fontSize:10.5,fontWeight:600,padding:"2px 8px",borderRadius:999,background:`${e.accent}14`,color:e.accent,border:`1px solid ${e.accent}33`,cursor:"pointer"}}function us(e){return{display:"grid",gap:8,padding:10,borderRadius:8,background:e.cellBg,border:`1px solid ${e.headerBorder}`}}function ps(e,n){const r=n==="hint";return{flex:"0 0 auto",fontSize:9,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.04em",padding:"2px 6px",borderRadius:4,marginTop:1,background:r?`${e.accent}1f`:`${e.textMuted}1f`,color:r?e.accent:e.textMuted}}function fs(e){return{flex:"0 0 auto",fontSize:10.5,border:`1px solid ${e.headerBorder}`,background:"transparent",color:e.textMuted,borderRadius:6,padding:"2px 7px",cursor:"pointer"}}function gs(e){return{width:30,height:30,borderRadius:8,background:`${e.accent}14`,border:`1px solid ${e.accent}36`,color:e.accent,display:"inline-flex",alignItems:"center",justifyContent:"center",flex:"0 0 auto"}}function Nn(e){return{...gs(e),width:40,height:40}}function kt(e){return{...qt(e,{variant:"secondary",size:"md",pill:!0}),fontWeight:550}}function xs(e){return{flex:1,minHeight:54,maxHeight:140,resize:"none",border:`1px solid ${e.btnBorder}`,background:e.inputBg,color:e.textPrimary,borderRadius:12,padding:"11px 13px",fontSize:13,lineHeight:1.45,fontFamily:e.font,outline:"none",boxShadow:"none"}}function Dn(e,n){return{...qt(e,{variant:n?"primary":"secondary",size:"lg"}),...n?{}:{color:e.textMuted}}}function Qt(e){return{border:"none",background:e.accent,color:"#fff",borderRadius:8,padding:"7px 13px",display:"inline-flex",alignItems:"center",gap:6,fontSize:12,fontWeight:700,fontFamily:e.font,cursor:"pointer",boxShadow:`0 1px 5px ${e.accent}4d`}}function hs(e){return{position:"absolute",bottom:"calc(100% + 6px)",left:0,zIndex:41,width:264,background:e.cellBg,border:`1px solid ${e.headerBorder}`,borderRadius:10,boxShadow:"0 12px 32px rgba(0,0,0,0.2)",padding:10}}function ys(e){return{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"8px 9px",borderRadius:7,border:"none",background:"transparent",color:e.textSecondary,fontSize:12.5,fontWeight:550,fontFamily:e.font,cursor:"pointer"}}function Hn(e){return{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"8px 9px",borderRadius:7,border:`1px dashed ${e.accent}66`,background:`${e.accent}0d`,color:e.accent,fontSize:12.5,fontWeight:650,fontFamily:e.font,cursor:"pointer",marginBottom:2}}function ms(e){return{width:"100%",boxSizing:"border-box",border:`1px solid ${e.btnBorder}`,background:e.inputBg,color:e.textPrimary,borderRadius:8,padding:"8px 10px",fontSize:12.5,fontFamily:e.font,outline:"none"}}function bs(e){return{alignSelf:"flex-end",maxWidth:"88%",background:`${e.accent}16`,color:e.textPrimary,border:`1px solid ${e.accent}32`,borderRadius:8,padding:"8px 10px",fontSize:12.5,lineHeight:1.45}}function vs(e){return{alignSelf:"flex-start",maxWidth:"92%",color:e.textPrimary,border:`1px solid ${e.cellBorder}`,background:e.appBg,borderRadius:10,padding:"10px 12px"}}function js(e){return{border:`1px solid ${e.cellBorder}`,background:e.appBg,borderRadius:8,padding:10,display:"grid",gap:10,gridTemplateColumns:"minmax(0, 1fr)",minWidth:0,maxWidth:"100%"}}function Zt(e){return{border:`1px solid ${e.headerBorder}`,background:e.cellBg,borderRadius:8,padding:9,display:"grid",gap:8,gridTemplateColumns:"minmax(0, 1fr)",minWidth:0,maxWidth:"100%"}}function Ss(e){return{border:`1px solid ${e.headerBorder}`,background:e.cellBg,borderRadius:8,padding:9,fontSize:12.5,color:e.textPrimary,lineHeight:1.45}}function nt(e){return{margin:0,maxHeight:180,overflow:"auto",border:`1px solid ${e.headerBorder}`,background:e.editorBg,color:e.textPrimary,borderRadius:7,padding:9,fontSize:11,lineHeight:1.45,fontFamily:e.fontMono,whiteSpace:"pre-wrap"}}function On(e){return{width:"100%",minWidth:0,boxSizing:"border-box",background:e.inputBg,border:`1px solid ${e.inputBorder}`,borderRadius:5,color:e.textPrimary,padding:"5px 7px",fontSize:11,fontFamily:e.font}}function J(e){return qt(e,{variant:"secondary",size:"sm"})}const Ms=Object.freeze(Object.defineProperty({__proto__:null,UnifiedAgentRunPanel:Li,agentRunHistoryFromItems:rr,analyticalInspectorContract:xr,analyticalInspectorSections:Ui,analyticalRepairActionLabels:Yi,artifactReadyPayloadFromRun:pn,artifactSqlDisclosureLabel:Sr,askArtifactMeta:At,askInspectorTabsForState:ur,clarificationSelectionInput:yt,completedRunGuidanceFor:cr,deriveResultChartConfig:Wr,hasAnalyticalInspectorContract:Rt,inlineAskChartConfig:jr,isAgentRunPinnable:it,liveAgentActivityFor:dr,longRunGuidanceFor:ar,preferredAskInspectorTab:ln,resolveArtifactDqlView:st,resolvedParameterValues:Jt,selectAgentExecutionConnection:or,threadItemsFromTurns:lr,trustExplainer:cn,usePersistedAgentThreadId:Dr},Symbol.toStringTag,{value:"Module"}));export{mi as B,Zr as E,zn as S,Li as U,ai as a,xi as b,Ms as c};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const n="dql:ai-build-open";function d(e){window.dispatchEvent(new CustomEvent(n,{detail:e}))}function s(e){const i=o=>{const t=o.detail;t&&e(t)};return window.addEventListener(n,i),()=>window.removeEventListener(n,i)}export{d as o,s};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{u as x,r as w,a as k,m}from"./index-DU7j3Sqk.js";const C="dql:focus-notebook-cell";function h(e){window.setTimeout(()=>{window.dispatchEvent(new CustomEvent(C,{detail:{cellId:e}}))},0)}function S(e){var t,a,c;const i=(t=e.question)==null?void 0:t.trim(),n=(a=e.generatedSql)==null?void 0:a.trim(),s=(c=e.generatedDql)==null?void 0:c.trim();if(!(!i||!n&&!s))return{version:1,source:"agent_run",question:i,...n?{generatedSql:n}:{},...s?{generatedDql:s}:{},...e.sourceRunId?{sourceRunId:e.sourceRunId}:{}}}function g(e){return e.replace(/[^a-zA-Z0-9_ -]+/g," ").replace(/\s+/g,"_").replace(/^_+|_+$/g,"").slice(0,48)||"ai_analysis"}function E(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function I(e,i){var c,o,u,f,l,q;const n=(o=(c=e.dqlArtifact)==null?void 0:c.source)==null?void 0:o.trim(),s=(e.sql??n??"").trim();if(!s&&!n)return[];if(e.mixedSourcePlan){const r=e.mixedSourcePlan,A=m("markdown",[`### ${e.title??"Mixed-source analysis"}`,"",`This analysis combines a bounded warehouse extraction with the local dataset \`${r.localDataset}\`.`,"",...(u=r.warehouseRelations)!=null&&u.length?[`- Warehouse sources: ${r.warehouseRelations.map(b=>`\`${b}\``).join(", ")}`]:[],`- Join: \`${r.warehouseKey}\` = \`${r.localKey}\``,"- Trust: local mixed-source analysis · review required"].join(`
|
|
2
|
+
`));A.name=g("Analysis context");const d=m("sql",s);return d.name=g(e.title??"Warehouse extraction"),d.mixedSourcePlan=r,d.executionTarget=((f=e.executionTarget)==null?void 0:f.target)==="connection"?e.executionTarget:{target:"connection"},d.datasetRefs=[{id:r.datasetId??r.localDataset,alias:r.localDataset,role:"source"}],[A,d]}const t=m(n?"dql":"sql",n||s);t.name=g(e.title??((l=e.dqlArtifact)==null?void 0:l.name)??"AI analysis"),e.result&&(t.result=e.result,t.status="success",t.executionCount=1),e.chartConfig&&(t.chartConfig=e.chartConfig),e.executionTarget&&(t.executionTarget=e.executionTarget),t.correctionProvenance=S({question:e.question,generatedSql:e.sql??((q=e.dqlArtifact)==null?void 0:q.compiledSql),generatedDql:n,sourceRunId:e.sourceRunId}),e.dqlArtifact&&(t.dqlArtifact={source:e.dqlArtifact.source,sql:e.sql,name:e.dqlArtifact.name,sourcePath:e.dqlArtifact.sourcePath,kind:e.dqlArtifact.kind,metrics:e.dqlArtifact.metrics,dimensions:e.dqlArtifact.dimensions,parameters:e.dqlArtifact.parameters,parameterValues:e.dqlArtifact.parameterValues,persistence:e.dqlArtifact.persistence,trustState:e.dqlArtifact.trustState,compiledSql:e.dqlArtifact.compiledSql??e.sql,...e.question?{question:e.question}:{}},t.dqlParameterValues=e.dqlArtifact.parameterValues);const a=i.filter(r=>new RegExp(`\\b${E(r.alias)}\\b`,"i").test(s)).map(r=>({id:r.id,alias:r.alias,role:r.storageMode==="staged"?"staged":"source",fingerprint:r.fileFingerprint}));return a.length>0&&(t.executionTarget={target:"local"},t.datasetRefs=a,t.dqlArtifact&&(t.dqlArtifact.reviewState="review_required")),[t]}function _(e){return(e??"ai analysis").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,48)||"ai-analysis"}function v(){const{state:e,dispatch:i}=x();return w.useCallback(async(n,s)=>{var f;const t=I(n,(s==null?void 0:s.datasets)??[]);if(t.length===0)return;if(e.activeFile&&e.activeFile.type!=="block"){let l=s==null?void 0:s.afterId;for(const q of t)i({type:"ADD_CELL",cell:q,...l?{afterId:l}:{}}),l=q.id;h(t[t.length-1].id);return}const a=n.title??((f=n.dqlArtifact)==null?void 0:f.name)??"AI analysis",c=_(a);let o=`notebooks/${c}.dqlnb`;try{o=(await k.createNotebook(c,"blank")).path}catch{}const u={name:o.split("/").pop()??`${c}.dqlnb`,path:o,type:"notebook",folder:"notebooks",isNew:!0};i({type:"FILE_ADDED",file:u}),i({type:"OPEN_FILE",file:u,cells:t,title:a}),h(t[t.length-1].id)},[i,e.activeFile])}export{C as N,S as c,h as f,v as u};
|