PageSourceSearch

https://incommand.ai/assets/ComposeEditor-x8l4i_1E.js

js incommand.ai collected 2026-10-05 15:02:13 UTC 32,870 bytes, 267 lines download raw bytes

1import{j as e}from"./vendor-radix-BnNg3BH5.js";import{r as o,i as ke,d as Se}from"./vendor-react-67mgcWXU.js";import{a as oe,u as Ce}from"./vendor-query-PMAhJHCS.js";import{d as _e,X as le,k as ae,L as O,B as w,a4 as ce,S as de,a5 as Ee,F as V,s as _,q as C,b as $e}from"./index-Epr9psQo.js";import{u as ze}from"./useStreamingAI-P9mQEfIN.js";import{B as D}from"./badge-Cl7apleB.js";import{R as Ie,a as re,b as Me}from"./resizable-ChtCGw24.js";import{S as me}from"./scroll-area-OnGFamwr.js";import{P as Te,a as Ae,b as Re}from"./popover-C2IiMjDe.js";import{C as De}from"./ComposeDocumentUpload-Trk-2Fwu.js";import{B as U}from"./bot-CsO_sZDW.js";import{M as ie}from"./index-BMcbOcU5.js";import{U as Pe}from"./user-BG8cpmCD.js";import{P as Be}from"./paperclip-BZ4mElSl.js";import{a as Oe,M as qe,P as He,C as Fe}from"./MultiPassProgress-DS7fBcN5.js";import{A as Le,m as K}from"./vendor-motion-CSzk-Fqg.js";import{A as Ge}from"./arrow-right-LjC5fuTq.js";import{C as Ue}from"./card-DpKBVi42.js";import{M as Ke}from"./message-square-7cL_4-It.js";import{R as pe}from"./rotate-ccw-C8K84F0R.js";import{E as Ve}from"./expand-DtiOAWfU.js";import{W as Qe}from"./wand-sparkles-CP9Guegx.js";import{S as Je,e as We,a as Ye,b as Xe,c as Ze,d as et}from"./sheet-BMVGKQ_l.js";import{H as F}from"./history-B94lpOJ0.js";import{C as tt}from"./clock-BYWbH6MV.js";import{f as st}from"./format-Bw8okCdv.js";import{A as at}from"./arrow-left-BKCvbsa9.js";import{G as rt}from"./globe-DQzIP_ik.js";import{D as it}from"./download-CDzT20jl.js";import{P as nt}from"./panel-left-1hXsOURo.js";import{P as ot}from"./presentation-LZafSl8u.js";import{T as lt}from"./table-2-DacAplAG.js";import"./vendor-supabase-CTlrDMdV.js";import"./vendor-charts-Dck3qfzI.js";import"./grip-vertical-eNKORDT2.js";import"./index-OJZrzQMP.js";import"./link-2-Bu8oQt2W.js";import"./upload-2-rh2XwF.js";import"./collapsible-CKRfPF8i.js";import"./index-Jdtl9AIN.js";import"./database-C-966MCo.js";import"./downloadExport-C6IbRcl6.js";import"./jszip.min-C-g80qGt.js";import"./_commonjs-dynamic-modules-TDtrdbi3.js";import"./refresh-cw-j1umLsSM.js";import"./circle-check-Cv8aCTuA.js";import"./circle-alert-CFN03ksH.js";import"./formatDistanceToNow--Gw1Xv78.js";import"./constructNow-LutmP3uJ.js";import"./en-US-DJiZ5LCQ.js";import"./differenceInMonths-ODK8TVL-.js";import"./differenceInCalendarMonths-CBq9QhqA.js";import"./endOfDay-CV7hhp0x.js";import"./endOfMonth-BJH_LSY0.js";import"./differenceInMilliseconds-BS2m-4UB.js";import"./sparkles-BcySMUTB.js";import"./circle-CPv7M1K7.js";import"./skip-forward-BuHNhAIv.js";/**
2 * @license lucide-react v0.462.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 ct=_e("Shrink",[["path",{d:"m15 15 6 6m-6-6v4.8m0-4.8h4.8",key:"17vawe"}],["path",{d:"M9 19.8V15m0 0H4.2M9 15l-6 6",key:"chjx8e"}],["path",{d:"M15 4.2V9m0 0h4.8M15 9l6-6",key:"lav6yq"}],["path",{d:"M9 4.2V9m0 0H4.2M9 9 3 3",key:"1pxi2q"}]]);function dt({messages:t,onSendMessage:y,isStreaming:n,streamingContent:f,initialBrief:m,tenantId:x,referenceFiles:g,onReferenceFilesChange:E}){const[v,i]=o.useState(""),[b,l]=o.useState(!1),[c,r]=o.useState(!1),M=o.useRef(null),T=o.useRef(null);o.useEffect(()=>{M.current&&(M.current.scrollTop=M.current.scrollHeight)},[t,f]),o.useEffect(()=>{m&&!b&&t.length===0&&!n&&(i(m),l(!0))},[m,b,t.length,n]);const z=()=>{const p=v.trim();!p||n||(y(p),i(""))},P=p=>{p.key==="Enter"&&!p.shiftKey&&(p.preventDefault(),z())},q=p=>{const N=p.indexOf("```json");return N>0?p.slice(0,N).trim()||"Blueprint generated. See preview →":p.trim().startsWith("{")||p.trim().startsWith("```")?"Blueprint generated. See preview →":p};return e.jsxs("div",{className:"flex flex-col h-full",children:[g.length>0&&e.jsx("div",{className:"px-3 pt-2 flex flex-wrap gap-1.5 border-b pb-2",children:g.map((p,N)=>e.jsxs(D,{variant:"secondary",className:"text-caption gap-1 pr-1",children:[p.name,e.jsx("button",{onClick:()=>E(g.filter((H,$)=>$!==N)),className:"ml-0.5 hover:text-destructive",children:e.jsx(le,{className:"h-2.5 w-2.5"})})]},N))}),e.jsx(me,{className:"flex-1",ref:M,children:e.jsxs("div",{className:"p-4 space-y-4",children:[t.length===0&&!n&&e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(U,{className:"h-10 w-10 mx-auto mb-3 opacity-30"}),e.jsx("p",{className:"text-sm",children:"I'm ready to build your deliverable."}),e.jsx("p",{className:"text-xs mt-1",children:'Click "Generate" to start, then iterate here.'})]}),t.map((p,N)=>e.jsxs("div",{className:ae("flex gap-3",p.role==="user"?"justify-end":"justify-start"),children:[p.role==="assistant"&&e.jsx("div",{className:"flex-shrink-0 w-7 h-7 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx(U,{className:"h-4 w-4 text-primary"})}),e.jsx("div",{className:ae("max-w-[85%] rounded-lg px-3 py-2 text-sm",p.role==="user"?"bg-primary text-primary-foreground":"bg-muted"),children:p.role==="assistant"?e.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none [&>p]:mb-1 [&>p]:mt-0",children:e.jsx(ie,{children:q(p.content)})}):e.jsx("p",{className:"whitespace-pre-wrap",children:p.content})}),p.role==="user"&&e.jsx("div",{className:"flex-shrink-0 w-7 h-7 rounded-full bg-muted flex items-center justify-center",children:e.jsx(Pe,{className:"h-4 w-4 text-muted-foreground"})})]},N)),n&&e.jsxs("div",{className:"flex gap-3",children:[e.jsx("div",{className:"flex-shrink-0 w-7 h-7 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx(U,{className:"h-4 w-4 text-primary"})}),e.jsx("div",{className:"bg-muted rounded-lg px-3 py-2 text-sm max-w-[85%]",children:f?e.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none",children:e.jsx(ie,{children:q(f)})}):e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(O,{className:"h-3 w-3 animate-spin"}),e.jsx("span",{children:"Thinking..."})]})})]})]})}),e.jsxs("div",{className:"border-t p-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(Te,{open:c,onOpenChange:r,children:[e.jsx(Ae,{asChild:!0,children:e.jsx(w,{variant:"ghost",size:"icon",className:"flex-shrink-0",title:"Attach reference documents","aria-label":"Attach file",children:e.jsx(Be,{className:"h-4 w-4"})})}),e.jsx(Re,{className:"w-80",align:"start",side:"top",children:e.jsx(De,{tenantId:x,files:g,onChange:p=>{E(p),p.length>g.length&&r(!1)}})})]}
6),e.jsx(ce,{ref:T,value:v,onChange:p=>{i(p.target.value);const N=p.target;N.style.height="auto",N.style.height=Math.min(N.scrollHeight,200)+"px"},onKeyDown:P,placeholder:"Ask to revise, expand, or refine...",className:"min-h-[80px] max-h-[200px] resize-y text-sm",rows:3,disabled:n}),e.jsx(w,{size:"icon",onClick:z,disabled:!v.trim()||n,"aria-label":"Send",children:e.jsx(de,{className:"h-4 w-4"})})]}),e.jsx("p",{className:"text-caption text-muted-foreground mt-1",children:'Shift+Enter for new line • Try "revise section 3" or "add a risk matrix"'})]})]})}function mt({show:t,documentTitle:y,onDismiss:n}){const[f,m]=o.useState(!1);return o.useEffect(()=>{if(t){m(!0);const x=setTimeout(()=>{m(!1),n()},4e3);return()=>clearTimeout(x)}else m(!1)},[t,n]),e.jsx(Le,{children:f&&e.jsx(K.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},transition:{duration:.3,ease:"easeOut"},className:"absolute inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm",children:e.jsxs(K.div,{initial:{scale:.9},animate:{scale:1},transition:{delay:.1,duration:.3},className:"text-center space-y-4 p-8 max-w-md",children:[e.jsx(K.div,{initial:{scale:0},animate:{scale:1},transition:{delay:.2,type:"spring",stiffness:200},children:e.jsx(Ee,{className:"h-16 w-16 mx-auto text-success"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xl font-bold",children:"Blueprint Ready"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Your deliverable blueprint has been generated. Review it in the preview panel or continue refining with the AI."}),e.jsx("p",{className:"text-xs text-muted-foreground font-medium truncate max-w-[280px] mx-auto",children:y})]}),e.jsxs(w,{onClick:()=>{m(!1),n()},className:"gap-2",children:[e.jsx(V,{className:"h-4 w-4"}),"View Blueprint",e.jsx(Ge,{className:"h-4 w-4"})]})]})})})}const pt=[{id:"rewrite",label:"Rewrite",icon:pe,desc:"Rewrite this section from scratch"},{id:"expand",label:"Expand",icon:Ve,desc:"Add more depth and detail"},{id:"shorten",label:"Shorten",icon:ct,desc:"Make it more concise"},{id:"improve",label:"Improve",icon:Qe,desc:"Improve quality and specificity"}];function ut({sectionIndex:t,sectionTitle:y,onAction:n,onClose:f,isStreaming:m}){const[x,g]=o.useState(""),E=i=>{n(i)},v=()=>{x.trim()&&(n("custom",x.trim()),g(""))};return e.jsx(Ue,{className:"absolute bottom-4 left-4 right-4 z-20 p-4 shadow-lg border-primary/30 bg-background/95 backdrop-blur-sm",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ke,{className:"h-4 w-4 text-primary"}),e.jsxs("span",{className:"text-sm font-medium",children:["Edit Section ",t+1]}),e.jsx(D,{variant:"outline",className:"text-caption max-w-[200px] truncate",children:y})]}),e.jsx(w,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:f,"aria-label":"Close",children:e.jsx(le,{className:"h-3.5 w-3.5"})})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:pt.map(i=>e.jsxs(w,{variant:"outline",size:"sm",className:"h-7 text-xs gap-1.5",onClick:()=>E(i.id),disabled:m,title:i.desc,children:[e.jsx(i.icon,{className:"h-3 w-3"}),i.label]},i.id))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ce,{value:x,onChange:i=>g(i.target.value),placeholder:"Custom instruction for this section...",className:"min-h-[60
6px] max-h-[100px] text-sm resize-none",disabled:m,onKeyDown:i=>{i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),v())}}),e.jsx(w,{size:"icon",className:"flex-shrink-0",onClick:v,disabled:!x.trim()||m,"aria-label":"Send",children:e.jsx(de,{className:"h-3.5 w-3.5"})})]})]})})}function ft({documentId:t,onRestore:y}){const[n,f]=o.useState(!1),[m,x]=o.useState(null),{data:g,isLoading:E}=oe({queryKey:["compose-versions",t],queryFn:async()=>{const{data:i,error:b}=await _.from("compose_document_versions").select("*").eq("document_id",t).order("version_number",{ascending:!1});if(b)throw b;return i||[]},enabled:n&&!!t}),v=async i=>{x(i.id);try{y(i.blueprint_json,i.chat_messages||[]),C.success(`Restored to version ${i.version_number}`),f(!1)}catch(b){C.error("Failed to restore: "+b.message)}finally{x(null)}};return e.jsxs(Je,{open:n,onOpenChange:f,children:[e.jsx(We,{asChild:!0,children:e.jsxs(w,{variant:"ghost",size:"sm",className:"h-7 text-xs gap-1.5",children:[e.jsx(F,{className:"h-3 w-3"}),"History"]})}),e.jsxs(Ye,{children:[e.jsxs(Xe,{children:[e.jsxs(Ze,{className:"flex items-center gap-2",children:[e.jsx(F,{className:"h-4 w-4"}),"Version History"]}),e.jsx(et,{children:"Browse and restore previous versions of this document"})]}),e.jsx(me,{className:"h-[calc(100vh-12rem)] mt-4",children:E?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(O,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):!g||g.length===0?e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(F,{className:"h-8 w-8 mx-auto mb-3 opacity-30"}),e.jsx("p",{className:"text-sm",children:"No versions yet"}),e.jsx("p",{className:"text-xs mt-1",children:"Versions are created each time you regenerate"})]}):e.jsx("div",{className:"space-y-3",children:g.map(i=>e.jsxs("div",{className:"p-3 rounded-lg border bg-card hover:bg-accent/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsxs(D,{variant:"outline",className:"text-caption",children:["v",i.version_number]}),e.jsxs(w,{variant:"ghost",size:"sm",className:"h-6 text-caption gap-1",onClick:()=>v(i),disabled:m===i.id,children:[m===i.id?e.jsx(O,{className:"h-3 w-3 animate-spin"}):e.jsx(pe,{className:"h-3 w-3"}),"Restore"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-caption text-muted-foreground",children:[e.jsx(tt,{className:"h-3 w-3"}),e.jsx("span",{children:i.created_at?st(new Date(i.created_at),"MMM d, yyyy h:mm a"):"Unknown date"})]}),i.change_summary&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1.5 line-clamp-2",children:i.change_summary}),i.blueprint_json&&e.jsxs("p",{className:"text-caption text-muted-foreground mt-1",children:[i.blueprint_json?.sections?.length||0," sections"]})]},i.id))})})]})]})}function ht({title:t,subtitle:y,blueprint:n,brandName:f}){if(!n)return"";const m=n.sections||[],x=n.kpiMetrics||[],g=n.explicitAsk,E=n.nextSteps||[],v=n.riskMatrix||[],i=n.assumptions||[],b=n.narrativeArc,l=r=>(r||"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");let c=`<!DOCTYPE html>
7<html lang="en">
8<head>
9<meta charset="UTF-8">
10<meta name="viewport" content="width=device-width, initial-scale=1.0">
11<title>${l(t)}</title>
12<style>
13  :root {
14    --primary: #6C3AED;
15    --primary-light: #EDE9FE;
16    --accent: #0D9488;
17    --accent-light: #CCFBF1;
18    --amber: #D97706;
19    --amber-light: #FEF3C7;
20    --red: #DC2626;
21    --red-light: #FEE2E2;
22    --bg: #0F172A;
23    --surface: #1E293B;
24    --surface-alt: #334155;
25    --text: #F1F5F9;
26    --text-muted: #94A3B8;
27    --border: #475569;
28  }
29  * { box-sizing: border-box; margin: 0; padding: 0; }
30  body {
31    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
32    background: var(--bg);
33    color: var(--text);
34    line-height: 1.6;
35    padding: 2rem;
36    max-width: 1000px;
37    margin: 0 auto;
38  }
39  h1 { font-size: 1.75rem; font-weight: 700; margin-bottom: 0.25rem; }
40  h2 { font-size: 1.25rem; font-weight: 600; margin-bottom: 0.5rem; }
41  h3 { font-size: 1rem; font-weight: 600; margin-bottom: 0.5rem; }
42  .subtitle { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 2rem; }
43  .brand { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.5rem; }
44  .card {
45    background: var(--surface);
46    border: 1px solid var(--border);
47    border-radius: 0.75rem;
48    padding: 1.25rem;
49    margin-bottom: 1rem;
50  }
51  .card-accent {
52    border-left: 4px solid var(--primary);
53    background: linear-gradient(135deg, rgba(108,58,237,0.08), var(--surface));
54  }
55  .card-amber {
56    border-left: 4px solid var(--amber);
57    background: linear-gradient(135deg, rgba(217,119,6,0.08), var(--surface));
58  }
59  .card-red {
60    border-left: 4px solid var(--red);
61    background: linear-gradient(135deg, rgba(220,38,38,0.08), var(--surface));
62  }
63  .label {
64    font-size: 0.7rem;
65    font-weight: 600;
66    text-transform: uppercase;
67    letter-spacing: 0.06em;
68    color: var(--primary);
69    margin-bottom: 0.25rem;
70  }
71  .label-amber { color: var(--amber); }
72  .label-accent { color: var(--accent); }
73  .kpi-grid {
74    display: grid;
75    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
76    gap: 0.75rem;
77    margin-bottom: 1rem;
78  }
79  .kpi {
80    background: var(--surface);
81    border: 1px solid var(--border);
82    border-radius: 0.5rem;
83    padding: 1rem;
84  }
85  .kpi-value { font-size: 1.5rem; font-weight: 700; }
86  .kpi-label { font-size: 0.8rem; color: var(--text-muted); }
87  .badge {
88    display: inline-block;
89    font-size: 0.65rem;
90    font-weight: 600;
91    padding: 0.15rem 0.5rem;
92    border-radius: 999px;
93    border: 1px solid var(--border);
94    color: var(--text-muted);
95    margin-left: 0.5rem;
96    vertical-align: middle;
97  }
98  .narrative-arc {
99    display: grid;
100    grid-template-columns: repeat(3, 1fr);
101    gap: 0.75rem;
102    margin-bottom: 1rem;
103  }
104  .arc-card {
105    padding: 0.75rem;
106    border-radius: 0.5rem;
107    font-size: 0.85rem;
108  }
109  .arc-situation { background: rgba(16,185,129,0.1); border: 1px solid rgba(16,185,129,0.3); }
110  .arc-complication { background: rgba(217,119,6,0.1); border: 1px solid rgba(217,119,6,0.3); }
111  .arc-resolution { background: rgba(59,130,246,0.1); border: 1px solid rgba(59,130,246,0.3); }
112  .arc-label { font-weight: 600; font-size: 0.7rem; text-transform: uppercase; margin-bottom: 0.25rem; }
113  .arc-situation .arc-label { color: #10B981; }
114  .arc-complication .arc-label { color: #D97706; }
115  .arc-resolution .arc-label { color: #3B82F6; }
116  .section-header {
117    display: flex;
118    align-items: center;
119    gap: 0.5rem;
120    margin-bottom: 0.5rem;
121  }
122  .section-number {
123    font-size: 0.75rem;
124    font-weight: 600;
125    color: var(--text-muted);
126    min-width: 1.5rem;
127  }
128  .implication {
129    margin-top: 0.75rem;
130    padding: 0.5rem 0.75rem;
131    background: rgba(217,119,6,0.08);
132    border: 1px solid rgba(217,119,6,0.2);
133    border-radius: 0.375rem;
134    font-size: 0.85rem;
135  }
136  .implication strong { color: var(--amber); }
137  .takeaway-list { list-style: none; padding: 0; }
138  .takeaway-list li {
139    padding: 0.25rem 0;
140    font-size: 0.85rem;
141    display: flex;
142    align-items: flex-start;
143    gap: 0.5rem;
144  }
145  .takeaway-list li::before { content: "✓"; color: #10B981; font-weight: 700; flex-shrink: 0; }
146  .risk-row {
147    display: flex;
148    justify-content: space-between;
149    align-items: flex-start;
150    padding: 0.75rem 0;
151    border-bottom: 1px solid var(--border);
152  }
153  .risk-row:last-child { border-bottom: none; }
154  .meta-grid {
155    display: grid;
156    grid-template-columns: repeat(3, 1fr);
157    gap: 0.75rem;
158    margin-top: 0.75rem;
159  }
160  .meta-label { font-size: 0.7rem; color: var(--text-muted); }
161  .meta-value { font-weight: 600; font-size: 0.9rem; }
162  .next-steps ol { padding-left: 0; counter-reset: step; list-style: none; }
163  .next-steps li {
164    counter-increment: step;
165    padding: 0.5rem 0;
166    display: flex;
167    align-items: flex-start;
168    gap: 0.75rem;
169    font-size: 0.9rem;
170  }
171  .next-steps li::before {
172    content: counter(step);
173    display: flex;
174    align-items: center;
175    justify-content: center;
176    min-width: 1.5rem;
177    height: 1.5rem;
178    border-radius: 50%;
179    background: rgba(108,58,237,0.15);
180    color: var(--primary);
181    font-size: 0.75rem;
182    font-weight: 600;
183    flex-shrink: 0;
184  }
185  .owner { color: var(--text-muted); }
186  .divider { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }
187  .content-text { font-size: 0.9rem; color: var(--text-muted); line-height: 1.7; }
188  .assumption-list { list-style: disc; padding-left: 1.25rem; }
189  .assumption-list li { font-size: 0.85rem; padding: 0.15rem 0; }
190</style>
191</head>
192<body>
193`;return f&&(c+=`<div class="brand">${l(f)}</div>
194`),c+=`<h1>${l(t)}</h1>
195`,y&&(c+=`<div class="subtitle">${l(y)}</div>
196`),n.governingThought&&(c+=`<div class="card card-accent">
197  <div class="label">Governing Thought</div>
198  <p style="font-weight:600">${l(n.governingThought)}</p>
199</div>
200`),n.keyLineArguments?.length&&(c+='<div class="card"><div class="label">Key Arguments</div><div>',n.keyLineArguments.forEach(r=>{c+=`<span class="badge">${l(r)}</span> `}),c+=`</div></div>
201`),x.length>0&&(c+=`<div class="kpi-grid">
202`,x.forEach(r=>{c+=`  <div class="kpi">
203    <div class="kpi-value">${l(r.value)}</div>
204    <div class="kpi-label">${l(r.label)}</div>
205  </div>
206`}),c+=`</div>
207`),b&&(c+=`<div class="narrative-arc">
208  <div class="arc-card arc-situation"><div class="arc-label">Situation</div>${l(b.situation)}</div>
209  <div class="arc-card arc-complication"><div class="arc-label">Complication</div>${l(b.complication)}</div>
210  <div class="arc-card arc-resolution"><div class="arc-label">Resolution</div>${l(b.resolution)}</div>
211</div>
212`),c+=`<hr class="divider">
213`,m.forEach((r,M)=>{c+=`<div class="card">
214  <div class="section-header">
215    <span class="section-number">${String(M+1).padStart(2,"0")}</span>
216    <h3>${l(r.title)}</h3>
217    ${r.type?`<span class="badge">${l(r.type.replace(/_/g," "))}</span>`:""}
218  </div>
219`,r.objective&&(c+=`  <p class="content-text" style="margin-bottom:0.5rem"><em>${l(r.objective)}</em></p>
220`),r.narrativeContent&&(c+=`  <p class="content-text">${l(r.narrativeContent)}</p>
221`),Array.isArray(r.content)&&(c+=`  <ul class="takeaway-list" style="margin-top:0.5rem">
222`,r.content.forEach(T=>{c+=`    <li>${l(T)}</li>
223`}),c+=`  </ul>
224`),r.keyTakeaways?.length&&(c+=`  <ul class="takeaway-list" style="margin-top:0.5rem">
225`,r.keyTakeaways.forEach(T=>{c+=`    <li>${l(T)}</li>
226`}),c+=`  </ul>
227`),r.implication&&(c+=`  <div class="implication"><strong>SO WHAT:</strong> ${l(r.implication)}</div>
228`),r.speakerNotes&&(c+=`  <p style="margin-top:0.5rem;font-size:0.8rem;color:var(--text-muted);font-style:italic">🎤 ${l(r.speakerNotes)}</p>
229`),c+=`</div>
230`}),g&&(c+=`<div class="card card-amber">
231  <div class="label label-amber">The Ask</div>
232  <p style="font-size:1.1rem;font-weight:600;margin-bottom:0.5rem">${l(g.ask)}</p>
233  <div class="meta-grid">
234    <div><div class="meta-label">Owner</div><div class="meta-value">${l(g.owner)}</div></div>
235    <div><div class="meta-label">Timeline</div><div class="meta-value">${l(g.timeline)}</div></div>
236    <div><div class="meta-label">Investment</div><div class="meta-value">${l(g.investment)}</div></div>
237  </div>
238  ${g.rationale?`<p class="content-text" style="margin-top:0.75rem">${l(g.rationale)}</p>`:""}
239</div>
240`),v.length>0&&(c+=`<div class="card card-red">
241  <div class="label" style="color:var(--red)">Risk Matrix</div>
242`,v.forEach(r=>{c+=`  <div class="risk-row">
243    <div style="flex:1">
244      <p style="font-weight:600;font-size:0.9rem">${l(r.risk)}</p>
245      <p class="content-text" style="font-size:0.8rem"><strong>Mitigation:</strong> ${l(r.mitigation)}</p>
246    </div>
247    <div style="display:flex;gap:0.5rem">
248      <span class="badge">${l(r.likelihood)}</span>
249      <span class="badge">${l(r.impact)}</span>
250    </div>
251  </div>
252`}),c+=`</div>
253`),E.length>0&&(c+=`<div class="card next-steps">
254  <div class="label label-accent">Next Steps</div>
255  <ol>
256`,E.forEach(r=>{c+=`    <li><div>${l(r.action)}${r.owner?` <span class="owner">— ${l(r.owner)}</span>`:""}${r.timeline?` <span class="badge">${l(r.timeline)}</span>`:""}</div></li>
257`}),c+=`  </ol>
258</div>
259`),i.length>0&&(c+=`<div class="card">
260  <div class="label">Assumptions</div>
261  <ul class="assumption-list">
262`,i.forEach(r=>{c+=`    <li>${l(r.assumption)}${r.source?` <span class="badge">${l(r.source)}</span>`:""}</li>
263`}),c+=`  </ul>
264</div>
265`),c+=`</body>
266</html>`,c}function xt(t){const y=ht(t),n=new Blob([y],{type:"text/html;charset=utf-8"}),f=URL.createObjectURL(n),m=document.createElement("a");m.href=f,m.download=`${t.title.replace(/[^a-zA-Z0-9]/g,"_")}_blueprint.html`,document.body.appendChild(m),m.click(),document.body.removeChild(m),URL.revokeObjectURL(f)}const gt={docx:V,pptx:ot,xlsx:lt},ne={draft:"bg-muted text-muted-foreground",generating:"bg-info-soft text-info-soft-foreground",review:"bg-warning-soft text-warning-soft-foreground",approved:"bg-success-soft text-success-soft-foreground",exported:"bg-accent-purple-soft text-accent-purple-soft-foreground"};function vt(){const{id:t}=ke(),y=Se(),n=Ce(),{currentTenant:f}=$e(),{isStreaming:m,partialContent:x,stream:g,cancel:E}=ze(),[v,i]=o.useState([]),[b,l]=o.useState(!1),[c,r]=o.useState(!1),[M,T]=o.useState(null),[z,P]=o.useState(!1),[q,p]=o.use
266State({plan:"idle",write:"idle",critique:"idle"}),[N,H]=o.useState(null),$=o.useRef(null),Q=o.useRef(""),A=o.useRef("");o.useEffect(()=>{A.current=x},[x]);const J=o.useRef([]);o.useEffect(()=>{J.current=v},[v]);const[ue,L]=o.useState(!1),[fe,W]=o.useState(!1),[he,Y]=o.useState(""),[xe,X]=o.useState([]),[I,G]=o.useState(null),[Z,ee]=o.useState(!1),{data:a,isLoading:ge}=oe({queryKey:["compose-document",t],queryFn:async()=>{if(!t)return null;const{data:s,error:d}=await _.from("compose_documents").select("*").eq("id",t).single();if(d)throw d;return s},enabled:!!t});o.useEffect(()=>{a?.chat_messages&&Array.isArray(a.chat_messages)&&(i(a.chat_messages),a.chat_messages.length>0&&l(!0))},[a?.chat_messages]),o.useEffect(()=>{a?.blueprint_json&&l(!0)},[a?.blueprint_json]),o.useEffect(()=>{a&&a.reference_files&&X(a.reference_files)},[a]),o.useEffect(()=>{if(!(!a||!t)&&a.status==="generating"){const s=new Date(a.updated_at).getTime(),d=Date.now()-5*60*1e3;s<d&&_.from("compose_documents").update({status:"draft",partial_content:null,updated_at:new Date().toISOString()}).eq("id",t).then(()=>{n.invalidateQueries({queryKey:["compose-document",t]}),C.warning("Previous generation timed out. Document reset to draft — try generating again.")})}},[a,t,n]),o.useEffect(()=>(m&&x&&t?$.current||($.current=setInterval(async()=>{const s=A.current;s&&s!==Q.current&&(Q.current=s,await _.from("compose_documents").update({partial_content:s}).eq("id",t))},5e3)):$.current&&(clearInterval($.current),$.current=null),()=>{$.current&&(clearInterval($.current),$.current=null)}),[m,x,t]),o.useEffect(()=>{if(x)try{const s=x.match(/```(?:json)?\s*([\s\S]*?)```/),d=s?s[1].trim():x.match(/\{[\s\S]*\}/)?.[0];if(d){const h=JSON.parse(d);h&&(h.sections||h.sheets||h.governingThought)&&T(h)}}catch{}},[x]);const B=o.useCallback(async(s,d)=>{if(!t)return;let h=null;try{const S=s.match(/```(?:json)?\s*([\s\S]*?)```/),j=S?S[1].trim():s.match(/\{[\s\S]*\}/)?.[0]||s;h=JSON.parse(j)}catch{}const u=[...J.current];u.push({role:"assistant",content:d,timestamp:new Date().toISOString()}),await _.from("compose_documents").update({status:"review",blueprint_json:h,chat_messages:u,partial_content:null,updated_at:new Date().toISOString()}).eq("id",t),i(u),n.invalidateQueries({queryKey:["compose-document",t]})},[t,n]),ve=o.useCallback(async()=>{if(!t||!f?.id)return;const s=a?.model_id||"google/gemini-2.5-pro";p({plan:"idle",write:"idle",critique:"idle"}),H(null);try{const d=await g({functionName:"compose-generate",body:{documentId:t,tenantId:f.id,modelId:s,messages:[]},onProgress:(h,u)=>{p(S=>({...S,[h]:u}))},onCritique:h=>{try{const u=typeof h=="string"?JSON.parse(h):h;u?.overallScore&&H(u.overallScore)}catch{}},onComplete:async h=>{const u=typeof h=="string"?h:A.current;u&&await B(u,u),n.invalidateQueries({queryKey:["compose-document",t]}),l(!0),r(!0),C.success("Blueprint generated!")},onError:h=>{const u=A.current;u&&t&&_.from("compose_documents").update({partial_content:u,status:"draft"}).eq("id",t),C.error("Generation failed: "+h.message)}});d&&typeof d=="string"&&!A.current&&(await B(d,d),l(!0),r(!0))}catch(d){console.error("Generation error:",d)}},[t,f?.id,a,g,n,B]),te=o.useCallback(async s=>{if(!t||!f?.id)return;const d={role:"user",content:s,timestamp:new Date().toISOString()},h=[...v,d];i(h);const u=[...h];a?.blueprint_json&&!b&&u.unshift({role:"assistant",content:"```json\n"+JSON.stringify(a.blueprint_json)+"\n```"});const S=a?.model_id||"google/gemini-2.5-pro";p({plan:"idle",write:"idle",critique:"idle"});try{await g({functionName:"compose-generate",body:{documentId:t,tenantId:f.id,modelId:S,messages:u},onProgress:(j,k)=>{p(Ne=>({...Ne,[j]:k}))},onCritique:j=>{try{const k=typeof j=="string"?JSON.parse(j):j;k?.overallScore&&H(k.overallScore)}catch{}},onComplete:async j=>{const k=typeof j=="string"?j:A.current;k&&await B(k,k),n.invalidateQueries({queryKey:["compose-document",t]}),C.success("Updated!")},onError:j=>{const k=A.current;k&&t&&_.from("compose_documents").update({partial_content:k}).eq("id",t),C.error("Failed: "+j.message)}})}catch(j){console.error("Chat error:",j)}},[t,f?.id,v,a,b,g,n,B]),be=o.useCallback(async s=>{X(s),t&&await _.from("compose_documents").update({reference_files:s,updated_at:new Date().toISOString()}).eq("id",t)},[t]),ye=async(s,d)=>
266{if(!a?.blueprint_json){C.error("Generate the document first");return}const h=a.artifact_type||a.format;W(!0),Y("Starting background export...");try{const{data:u}=await _.auth.getUser();if(!u?.user?.id)throw new Error("Not authenticated");const S=d==="default"?a?.model_id||"google/gemini-2.5-pro":d,{data:j,error:k}=await _.functions.invoke("compose-export-job",{body:{documentId:a.id,format:h||"docx",depth:s,modelId:S,tenantId:f?.id,userId:u.user.id}});if(k)throw k;C.success("Export started! You'll be notified when it's ready.",{description:"You can navigate away — the job runs in the background.",duration:5e3}),L(!1)}catch(u){console.error("[EXPORT] Error:",u),C.error("Failed to start export: "+(u.message||"Unknown error"))}finally{W(!1),Y("")}};if(ge)return e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(O,{className:"h-8 w-8 animate-spin text-muted-foreground"})});if(!a)return e.jsxs("div",{className:"flex flex-col items-center justify-center min-h-[400px] gap-4",children:[e.jsx("p",{className:"text-muted-foreground",children:"Document not found"}),e.jsx(w,{variant:"outline",onClick:()=>y("/compose"),children:"Back to Compose"})]});const se=a.artifact_type||a.format,je=gt[se]||V,R=a.blueprint_json||M,we=(()=>{const s=a?.intake_brief;if(!s||typeof s!="object")return;const d=[];return d.push("Generate based on the content provided."),s.audience&&d.push(`Audience: ${s.audience}`),s.tone&&d.push(`Tone: ${s.tone}`),s.depth&&d.push(`Depth: ${s.depth}`),s.objectives&&d.push(`Objectives: ${s.objectives}`),s.context_scope&&d.push(`Context scope: ${s.context_scope}`),s.key_points&&d.push(`Key points: ${s.key_points}`),s.additional_instructions&&d.push(`Instructions: ${s.additional_instructions}`),d.length>1?d.join(`
267`):void 0})();return e.jsxs("div",{className:"h-[calc(100vh-8rem)] flex flex-col relative",children:[e.jsx(mt,{show:c,documentTitle:a.title,onDismiss:()=>r(!1)}),e.jsx(Oe,{open:ue,onOpenChange:L,onExport:ye,isExporting:fe,exportPhase:he,currentDepth:a?.document_depth||"detailed",currentModel:a?.model_id,documentId:a.id}),e.jsxs("div",{className:"flex items-center justify-between px-2 py-2 border-b flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(w,{variant:"ghost",size:"icon",onClick:()=>y("/compose"),"aria-label":"Back",children:e.jsx(at,{className:"h-4 w-4"})}),e.jsx(je,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"font-semibold text-sm truncate max-w-[300px]",children:a.title}),e.jsx(D,{className:ne[a.status]||ne.draft,variant:"outline",children:a.status}),a.model_id&&e.jsx(D,{variant:"outline",className:"text-caption font-mono",children:a.model_id.split("/").pop()})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[m&&e.jsx(qe,{progress:q}),N!==null&&!m&&e.jsxs(D,{variant:"outline",className:"text-caption font-medium",children:["Quality: ",N,"/100"]}),!b&&e.jsx(w,{size:"sm",onClick:ve,disabled:m,children:m?e.jsxs(e.Fragment,{children:[e.jsx(O,{className:"mr-2 h-3 w-3 animate-spin"}),"Generating..."]}):"Generate"}),a.blueprint_json&&e.jsxs(w,{size:"sm",variant:"ghost",onClick:()=>ee(!Z),title:"Version history",children:[e.jsx(F,{className:"mr-2 h-3 w-3"}),"Versions"]}),e.jsxs(w,{size:"sm",variant:"ghost",onClick:()=>{R&&(xt({title:a.title,subtitle:a.purpose||"",blueprint:R,brandName:f?.name}),C.success("HTML exported!"))},disabled:!R,title:"Export preview as HTML",children:[e.jsx(rt,{className:"mr-2 h-3 w-3"}),"HTML"]}),e.jsxs(w,{size:"sm",variant:"outline",onClick:()=>L(!0),disabled:!a.blueprint_json,children:[e.jsx(it,{className:"mr-2 h-3 w-3"}),"Export"]})]})]}),e.jsxs(Ie,{direction:"horizontal",className:"flex-1",children:[e.jsx(re,{defaultSize:40,minSize:z?0:25,collapsible:!0,collapsedSize:0,onCollapse:()=>P(!0),onExpand:()=>P(!1),className:z?"hidden":"",children:e.jsx(dt,{messages:v,onSendMessage:te,isStreaming:m,streamingContent:x,initialBrief:we,tenantId:f?.id||"",referenceFiles:xe,onReferenceFilesChange:be})}),!z&&e.jsx(Me,{withHandle:!0}),e.jsx(re,{defaultSize:60,minSize:30,children:e.jsxs("div",{className:"relative h-full",children:[e.jsx(w,{variant:"ghost",size:"icon",className:"absolute top-2 left-2 z-10 h-7 w-7 bg-background/80 backdrop-blur-sm border shadow-sm hover:bg-accent",onClick:()=>P(!z),title:z?"Show chat panel":"Hide chat panel","aria-label":"Toggle sidebar",children:z?e.jsx(nt,{className:"h-4 w-4"}):e.jsx(He,{className:"h-4 w-4"})}),e.jsx(Fe,{blueprint:R,artifactType:se,contextSources:a.context_sources_used,isStreaming:m,rawContent:x,brandingConfig:a.branding_config,onSectionSelect:s=>G(s===I?null:s),selectedSectionIndex:I}),I!==null&&R?.sections?.[I]&&e.jsx(ut,{sectionIndex:I,sectionTitle:R.sections[I].title||`Section ${I+1}`,onAction:(s,d)=>{const h=R.sections[I],u=`[SECTION ${I+1}: "${h.title}"]`;let S="";s==="custom"&&d?S=`${u} ${d}`:S=`${u} ${s} this section`,te(S),G(null)},onClose:()=>G(null),isStreaming:m}),Z&&e.jsx(ft,{documentId:t||"",onRestore:async(s,d)=>{t&&(await _.from("compose_documents").update({blueprint_json:s,status:"review",updated_at:new Date().toISOString()}).eq("id",t),n.invalidateQueries({queryKey:["compose-document",t]}),ee(!1),C.success("Version restored!"))}})]})})]})]})}function Ns(){return e.jsx(vt,{})}export{Ns as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.