agent-canvas 0.1.13 → 0.1.15
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/bin/lib/commands/push.ts +26 -10
- package/bun.lock +3 -0
- package/daemon/client/AnnotationProvider.tsx +2 -2
- package/daemon/client/App.tsx +125 -47
- package/daemon/client/CompareView.tsx +161 -31
- package/daemon/client/OverviewView.tsx +326 -0
- package/daemon/client/PlanRenderer.tsx +13 -8
- package/daemon/client/RevisionSelect.tsx +16 -7
- package/daemon/client/components/Mermaid.tsx +3 -2
- package/daemon/client/generateMarkdown.ts +24 -5
- package/daemon/client/runtime.ts +9 -2
- package/daemon/client/useTextAnnotation.tsx +6 -2
- package/daemon/dist/client.css +1 -1
- package/daemon/dist/client.js +58 -58
- package/daemon/dist/components.js +23 -23
- package/daemon/dist/runtime.js +1 -1
- package/daemon/src/compiler.ts +100 -0
- package/daemon/src/handlers/api.ts +59 -24
- package/daemon/src/session.ts +140 -41
- package/daemon/src/watcher.ts +42 -30
- package/package.json +4 -3
- package/skills/canvas/SKILL.md +24 -19
- package/skills/canvas/components.md +29 -15
- package/skills/canvas/flows.md +1 -1
package/daemon/dist/client.js
CHANGED
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
import
|
|
2
|
-
]`).replace("lheading",
|
|
3
|
-
`).map((
|
|
4
|
-
`)}var
|
|
5
|
-
`)}}}fences(J){let $=this.rules.block.fences.exec(J);if($){let Y=$[0],Z=
|
|
6
|
-
`)}}blockquote(J){let $=this.rules.block.blockquote.exec(J);if($){let Y=
|
|
1
|
+
import A1,{useEffect as M1,useLayoutEffect as F4,useState as $1,useCallback as u0,useRef as I1,createContext as D2,useMemo as j2}from"react";import{createRoot as L4}from"react-dom/client";function f0(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var V1=f0();function M5(J){V1=J}var R1={exec:()=>null};function l(J,$=""){let Y=typeof J=="string"?J:J.source,Z={replace:(Q,q)=>{let X=typeof q=="string"?q:q.source;return X=X.replace(Z1.caret,"$1"),Y=Y.replace(Q,X),Z},getRegex:()=>new RegExp(Y,$)};return Z}var E2=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),Z1={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:(J)=>new RegExp(`^( {0,3}${J})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}#`),htmlBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}<(?:[a-z].*>|!--)`,"i"),blockquoteBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}>`)},v2=/^(?:[ \t]*(?:\n|$))+/,x2=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,f2=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,n1=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,h2=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,h0=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,P5=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,S5=l(P5).replace(/bull/g,h0).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),p2=l(P5).replace(/bull/g,h0).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),p0=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,c2=/^[^\n]+/,c0=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,d2=l(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",c0).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),r2=l(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,h0).getRegex(),N0="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",d0=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,l2=l("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$))","i").replace("comment",d0).replace("tag",N0).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),b5=l(p0).replace("hr",n1).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",N0).getRegex(),i2=l(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",b5).getRegex(),r0={blockquote:i2,code:x2,def:d2,fences:f2,heading:h2,hr:n1,html:l2,lheading:S5,list:r2,newline:v2,paragraph:b5,table:R1,text:c2},T5=l("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",n1).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3}\t)[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",N0).getRegex(),a2={...r0,lheading:p2,table:T5,paragraph:l(p0).replace("hr",n1).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",T5).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",N0).getRegex()},o2={...r0,html:l(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",d0).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:R1,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:l(p0).replace("hr",n1).replace("heading",` *#{1,6} *[^
|
|
2
|
+
]`).replace("lheading",S5).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},s2=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,t2=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,w5=/^( {2,}|\\)\n(?!\s*$)/,n2=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,T0=/[\p{P}\p{S}]/u,l0=/[\s\p{P}\p{S}]/u,A5=/[^\s\p{P}\p{S}]/u,e2=l(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,l0).getRegex(),I5=/(?!~)[\p{P}\p{S}]/u,$3=/(?!~)[\s\p{P}\p{S}]/u,J3=/(?:[^\s\p{P}\p{S}]|~)/u,C5=/(?![*_])[\p{P}\p{S}]/u,Y3=/(?![*_])[\s\p{P}\p{S}]/u,Q3=/(?:[^\s\p{P}\p{S}]|[*_])/u,Z3=l(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",E2?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),j5=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,X3=l(j5,"u").replace(/punct/g,T0).getRegex(),q3=l(j5,"u").replace(/punct/g,I5).getRegex(),R5="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",_3=l(R5,"gu").replace(/notPunctSpace/g,A5).replace(/punctSpace/g,l0).replace(/punct/g,T0).getRegex(),z3=l(R5,"gu").replace(/notPunctSpace/g,J3).replace(/punctSpace/g,$3).replace(/punct/g,I5).getRegex(),G3=l("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,A5).replace(/punctSpace/g,l0).replace(/punct/g,T0).getRegex(),U3=l(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,C5).getRegex(),K3="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",H3=l(K3,"gu").replace(/notPunctSpace/g,Q3).replace(/punctSpace/g,Y3).replace(/punct/g,C5).getRegex(),W3=l(/\\(punct)/,"gu").replace(/punct/g,T0).getRegex(),N3=l(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),T3=l(d0).replace("(?:-->|$)","-->").getRegex(),O3=l("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",T3).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),K0=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/,F3=l(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",K0).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),k5=l(/^!?\[(label)\]\[(ref)\]/).replace("label",K0).replace("ref",c0).getRegex(),V5=l(/^!?\[(ref)\](?:\[\])?/).replace("ref",c0).getRegex(),L3=l("reflink|nolink(?!\\()","g").replace("reflink",k5).replace("nolink",V5).getRegex(),O5=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,i0={_backpedal:R1,anyPunctuation:W3,autolink:N3,blockSkip:Z3,br:w5,code:t2,del:R1,delLDelim:R1,delRDelim:R1,emStrongLDelim:X3,emStrongRDelimAst:_3,emStrongRDelimUnd:G3,escape:s2,link:F3,nolink:V5,punctuation:e2,reflink:k5,reflinkSearch:L3,tag:O3,text:n2,url:R1},B3={...i0,link:l(/^!?\[(label)\]\((.*?)\)/).replace("label",K0).getRegex(),reflink:l(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",K0).getRegex()},x0={...i0,emStrongRDelimAst:z3,emStrongLDelim:q3,delLDelim:U3,delRDelim:H3,url:l(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",O5).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:l(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",O5).getRegex()},y3={...x0,br:l(w5).replace("{2,}","*").getRegex(),text:l(x0.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},U0={normal:r0,gfm:a2,pedantic:o2},o1={normal:i0,gfm:x0,breaks:y3,pedantic:B3},M3={"&":"&","<":"<",">":">",'"':""","'":"'"},F5=(J)=>M3[J];function K1(J,$){if($){if(Z1.escapeTest.test(J))return J.replace(Z1.escapeReplace,F5)}else if(Z1.escapeTestNoEncode.test(J))return J.replace(Z1.escapeReplaceNoEncode,F5);return J}function L5(J){try{J=encodeURI(J).replace(Z1.percentDecode,"%")}catch{return null}return J}function B5(J,$){let Y=J.replace(Z1.findPipe,(q,X,G)=>{let _=!1,z=X;for(;--z>=0&&G[z]==="\\";)_=!_;return _?"|":" |"}),Z=Y.split(Z1.splitPipe),Q=0;if(Z[0].trim()||Z.shift(),Z.length>0&&!Z.at(-1)?.trim()&&Z.pop(),$)if(Z.length>$)Z.splice($);else for(;Z.length<$;)Z.push("");for(;Q<Z.length;Q++)Z[Q]=Z[Q].trim().replace(Z1.slashPipe,"|");return Z}function s1(J,$,Y){let Z=J.length;if(Z===0)return"";let Q=0;for(;Q<Z;){let q=J.charAt(Z-Q-1);if(q===$&&!Y)Q++;else if(q!==$&&Y)Q++;else break}return J.slice(0,Z-Q)}function P3(J,$){if(J.indexOf($[1])===-1)return-1;let Y=0;for(let Z=0;Z<J.length;Z++)if(J[Z]==="\\")Z++;else if(J[Z]===$[0])Y++;else if(J[Z]===$[1]&&(Y--,Y<0))return Z;return Y>0?-2:-1}function S3(J,$=0){let Y=$,Z="";for(let Q of J)if(Q==="\t"){let q=4-Y%4;Z+=" ".repeat(q),Y+=q}else Z+=Q,Y++;return Z}function y5(J,$,Y,Z,Q){let q=$.href,X=$.title||null,G=J[1].replace(Q.other.outputLinkReplace,"$1");Z.state.inLink=!0;let _={type:J[0].charAt(0)==="!"?"image":"link",raw:Y,href:q,title:X,text:G,tokens:Z.inlineTokens(G)};return Z.state.inLink=!1,_}function b3(J,$,Y){let Z=J.match(Y.other.indentCodeCompensation);if(Z===null)return $;let Q=Z[1];return $.split(`
|
|
3
|
+
`).map((q)=>{let X=q.match(Y.other.beginningSpace);if(X===null)return q;let[G]=X;return G.length>=Q.length?q.slice(Q.length):q}).join(`
|
|
4
|
+
`)}var H0=class{options;rules;lexer;constructor(J){this.options=J||V1}space(J){let $=this.rules.block.newline.exec(J);if($&&$[0].length>0)return{type:"space",raw:$[0]}}code(J){let $=this.rules.block.code.exec(J);if($){let Y=$[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:$[0],codeBlockStyle:"indented",text:this.options.pedantic?Y:s1(Y,`
|
|
5
|
+
`)}}}fences(J){let $=this.rules.block.fences.exec(J);if($){let Y=$[0],Z=b3(Y,$[3]||"",this.rules);return{type:"code",raw:Y,lang:$[2]?$[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):$[2],text:Z}}}heading(J){let $=this.rules.block.heading.exec(J);if($){let Y=$[2].trim();if(this.rules.other.endingHash.test(Y)){let Z=s1(Y,"#");(this.options.pedantic||!Z||this.rules.other.endingSpaceChar.test(Z))&&(Y=Z.trim())}return{type:"heading",raw:$[0],depth:$[1].length,text:Y,tokens:this.lexer.inline(Y)}}}hr(J){let $=this.rules.block.hr.exec(J);if($)return{type:"hr",raw:s1($[0],`
|
|
6
|
+
`)}}blockquote(J){let $=this.rules.block.blockquote.exec(J);if($){let Y=s1($[0],`
|
|
7
7
|
`).split(`
|
|
8
|
-
`),Z="",Q="",
|
|
9
|
-
`),
|
|
8
|
+
`),Z="",Q="",q=[];for(;Y.length>0;){let X=!1,G=[],_;for(_=0;_<Y.length;_++)if(this.rules.other.blockquoteStart.test(Y[_]))G.push(Y[_]),X=!0;else if(!X)G.push(Y[_]);else break;Y=Y.slice(_);let z=G.join(`
|
|
9
|
+
`),H=z.replace(this.rules.other.blockquoteSetextReplace,`
|
|
10
10
|
$1`).replace(this.rules.other.blockquoteSetextReplace2,"");Z=Z?`${Z}
|
|
11
|
-
${
|
|
12
|
-
${
|
|
11
|
+
${z}`:z,Q=Q?`${Q}
|
|
12
|
+
${H}`:H;let U=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(H,q,!0),this.lexer.state.top=U,Y.length===0)break;let W=q.at(-1);if(W?.type==="code")break;if(W?.type==="blockquote"){let N=W,K=N.raw+`
|
|
13
13
|
`+Y.join(`
|
|
14
|
-
`),
|
|
14
|
+
`),T=this.blockquote(K);q[q.length-1]=T,Z=Z.substring(0,Z.length-N.raw.length)+T.raw,Q=Q.substring(0,Q.length-N.text.length)+T.text;break}else if(W?.type==="list"){let N=W,K=N.raw+`
|
|
15
15
|
`+Y.join(`
|
|
16
|
-
`),
|
|
17
|
-
`);continue}}return{type:"blockquote",raw:Z,tokens:
|
|
18
|
-
`,1)[0],$[1].length),
|
|
19
|
-
`,1)[0],
|
|
20
|
-
`,J=J.substring(
|
|
21
|
-
`,1)[0],
|
|
22
|
-
`+
|
|
23
|
-
`+
|
|
24
|
-
`,J=J.substring(
|
|
25
|
-
`):[],
|
|
26
|
-
`?$[1].slice(0,-1):$[1];return{type:"paragraph",raw:$[0],text:Y,tokens:this.lexer.inline(Y)}}}text(J){let $=this.rules.block.text.exec(J);if($)return{type:"text",raw:$[0],text:$[0],tokens:this.lexer.inline($[0])}}escape(J){let $=this.rules.inline.escape.exec(J);if($)return{type:"escape",raw:$[0],text:$[1]}}tag(J){let $=this.rules.inline.tag.exec(J);if($)return!this.lexer.state.inLink&&this.rules.other.startATag.test($[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test($[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test($[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test($[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:$[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:$[0]}}link(J){let $=this.rules.inline.link.exec(J);if($){let Y=$[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(Y)){if(!this.rules.other.endAngleBracket.test(Y))return;let
|
|
27
|
-
`),this.blockTokens($,this.tokens);for(let Y=0;Y<this.inlineQueue.length;Y++){let Z=this.inlineQueue[Y];this.inlineTokens(Z.src,Z.tokens)}return this.inlineQueue=[],this.tokens}blockTokens($,Y=[],Z=!1){for(this.options.pedantic&&($=$.replace(
|
|
28
|
-
`:Y.push(Q);continue}if(Q=this.tokenizer.code($)){$=$.substring(Q.raw.length);let
|
|
16
|
+
`),T=this.list(K);q[q.length-1]=T,Z=Z.substring(0,Z.length-W.raw.length)+T.raw,Q=Q.substring(0,Q.length-N.raw.length)+T.raw,Y=K.substring(q.at(-1).raw.length).split(`
|
|
17
|
+
`);continue}}return{type:"blockquote",raw:Z,tokens:q,text:Q}}}list(J){let $=this.rules.block.list.exec(J);if($){let Y=$[1].trim(),Z=Y.length>1,Q={type:"list",raw:"",ordered:Z,start:Z?+Y.slice(0,-1):"",loose:!1,items:[]};Y=Z?`\\d{1,9}\\${Y.slice(-1)}`:`\\${Y}`,this.options.pedantic&&(Y=Z?Y:"[*+-]");let q=this.rules.other.listItemRegex(Y),X=!1;for(;J;){let _=!1,z="",H="";if(!($=q.exec(J))||this.rules.block.hr.test(J))break;z=$[0],J=J.substring(z.length);let U=S3($[2].split(`
|
|
18
|
+
`,1)[0],$[1].length),W=J.split(`
|
|
19
|
+
`,1)[0],N=!U.trim(),K=0;if(this.options.pedantic?(K=2,H=U.trimStart()):N?K=$[1].length+1:(K=U.search(this.rules.other.nonSpaceChar),K=K>4?1:K,H=U.slice(K),K+=$[1].length),N&&this.rules.other.blankLine.test(W)&&(z+=W+`
|
|
20
|
+
`,J=J.substring(W.length+1),_=!0),!_){let T=this.rules.other.nextBulletRegex(K),O=this.rules.other.hrRegex(K),S=this.rules.other.fencesBeginRegex(K),L=this.rules.other.headingBeginRegex(K),j=this.rules.other.htmlBeginRegex(K),V=this.rules.other.blockquoteBeginRegex(K);for(;J;){let M=J.split(`
|
|
21
|
+
`,1)[0],I;if(W=M,this.options.pedantic?(W=W.replace(this.rules.other.listReplaceNesting," "),I=W):I=W.replace(this.rules.other.tabCharGlobal," "),S.test(W)||L.test(W)||j.test(W)||V.test(W)||T.test(W)||O.test(W))break;if(I.search(this.rules.other.nonSpaceChar)>=K||!W.trim())H+=`
|
|
22
|
+
`+I.slice(K);else{if(N||U.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||S.test(U)||L.test(U)||O.test(U))break;H+=`
|
|
23
|
+
`+W}N=!W.trim(),z+=M+`
|
|
24
|
+
`,J=J.substring(M.length+1),U=I.slice(K)}}Q.loose||(X?Q.loose=!0:this.rules.other.doubleBlankLine.test(z)&&(X=!0)),Q.items.push({type:"list_item",raw:z,task:!!this.options.gfm&&this.rules.other.listIsTask.test(H),loose:!1,text:H,tokens:[]}),Q.raw+=z}let G=Q.items.at(-1);if(G)G.raw=G.raw.trimEnd(),G.text=G.text.trimEnd();else return;Q.raw=Q.raw.trimEnd();for(let _ of Q.items){if(this.lexer.state.top=!1,_.tokens=this.lexer.blockTokens(_.text,[]),_.task){if(_.text=_.text.replace(this.rules.other.listReplaceTask,""),_.tokens[0]?.type==="text"||_.tokens[0]?.type==="paragraph"){_.tokens[0].raw=_.tokens[0].raw.replace(this.rules.other.listReplaceTask,""),_.tokens[0].text=_.tokens[0].text.replace(this.rules.other.listReplaceTask,"");for(let H=this.lexer.inlineQueue.length-1;H>=0;H--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[H].src)){this.lexer.inlineQueue[H].src=this.lexer.inlineQueue[H].src.replace(this.rules.other.listReplaceTask,"");break}}let z=this.rules.other.listTaskCheckbox.exec(_.raw);if(z){let H={type:"checkbox",raw:z[0]+" ",checked:z[0]!=="[ ]"};_.checked=H.checked,Q.loose?_.tokens[0]&&["paragraph","text"].includes(_.tokens[0].type)&&"tokens"in _.tokens[0]&&_.tokens[0].tokens?(_.tokens[0].raw=H.raw+_.tokens[0].raw,_.tokens[0].text=H.raw+_.tokens[0].text,_.tokens[0].tokens.unshift(H)):_.tokens.unshift({type:"paragraph",raw:H.raw,text:H.raw,tokens:[H]}):_.tokens.unshift(H)}}if(!Q.loose){let z=_.tokens.filter((U)=>U.type==="space"),H=z.length>0&&z.some((U)=>this.rules.other.anyLine.test(U.raw));Q.loose=H}}if(Q.loose)for(let _ of Q.items){_.loose=!0;for(let z of _.tokens)z.type==="text"&&(z.type="paragraph")}return Q}}html(J){let $=this.rules.block.html.exec(J);if($)return{type:"html",block:!0,raw:$[0],pre:$[1]==="pre"||$[1]==="script"||$[1]==="style",text:$[0]}}def(J){let $=this.rules.block.def.exec(J);if($){let Y=$[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),Z=$[2]?$[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",Q=$[3]?$[3].substring(1,$[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):$[3];return{type:"def",tag:Y,raw:$[0],href:Z,title:Q}}}table(J){let $=this.rules.block.table.exec(J);if(!$||!this.rules.other.tableDelimiter.test($[2]))return;let Y=B5($[1]),Z=$[2].replace(this.rules.other.tableAlignChars,"").split("|"),Q=$[3]?.trim()?$[3].replace(this.rules.other.tableRowBlankLine,"").split(`
|
|
25
|
+
`):[],q={type:"table",raw:$[0],header:[],align:[],rows:[]};if(Y.length===Z.length){for(let X of Z)this.rules.other.tableAlignRight.test(X)?q.align.push("right"):this.rules.other.tableAlignCenter.test(X)?q.align.push("center"):this.rules.other.tableAlignLeft.test(X)?q.align.push("left"):q.align.push(null);for(let X=0;X<Y.length;X++)q.header.push({text:Y[X],tokens:this.lexer.inline(Y[X]),header:!0,align:q.align[X]});for(let X of Q)q.rows.push(B5(X,q.header.length).map((G,_)=>({text:G,tokens:this.lexer.inline(G),header:!1,align:q.align[_]})));return q}}lheading(J){let $=this.rules.block.lheading.exec(J);if($)return{type:"heading",raw:$[0],depth:$[2].charAt(0)==="="?1:2,text:$[1],tokens:this.lexer.inline($[1])}}paragraph(J){let $=this.rules.block.paragraph.exec(J);if($){let Y=$[1].charAt($[1].length-1)===`
|
|
26
|
+
`?$[1].slice(0,-1):$[1];return{type:"paragraph",raw:$[0],text:Y,tokens:this.lexer.inline(Y)}}}text(J){let $=this.rules.block.text.exec(J);if($)return{type:"text",raw:$[0],text:$[0],tokens:this.lexer.inline($[0])}}escape(J){let $=this.rules.inline.escape.exec(J);if($)return{type:"escape",raw:$[0],text:$[1]}}tag(J){let $=this.rules.inline.tag.exec(J);if($)return!this.lexer.state.inLink&&this.rules.other.startATag.test($[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test($[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test($[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test($[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:$[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:$[0]}}link(J){let $=this.rules.inline.link.exec(J);if($){let Y=$[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(Y)){if(!this.rules.other.endAngleBracket.test(Y))return;let q=s1(Y.slice(0,-1),"\\");if((Y.length-q.length)%2===0)return}else{let q=P3($[2],"()");if(q===-2)return;if(q>-1){let X=($[0].indexOf("!")===0?5:4)+$[1].length+q;$[2]=$[2].substring(0,q),$[0]=$[0].substring(0,X).trim(),$[3]=""}}let Z=$[2],Q="";if(this.options.pedantic){let q=this.rules.other.pedanticHrefTitle.exec(Z);q&&(Z=q[1],Q=q[3])}else Q=$[3]?$[3].slice(1,-1):"";return Z=Z.trim(),this.rules.other.startAngleBracket.test(Z)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(Y)?Z=Z.slice(1):Z=Z.slice(1,-1)),y5($,{href:Z&&Z.replace(this.rules.inline.anyPunctuation,"$1"),title:Q&&Q.replace(this.rules.inline.anyPunctuation,"$1")},$[0],this.lexer,this.rules)}}reflink(J,$){let Y;if((Y=this.rules.inline.reflink.exec(J))||(Y=this.rules.inline.nolink.exec(J))){let Z=(Y[2]||Y[1]).replace(this.rules.other.multipleSpaceGlobal," "),Q=$[Z.toLowerCase()];if(!Q){let q=Y[0].charAt(0);return{type:"text",raw:q,text:q}}return y5(Y,Q,Y[0],this.lexer,this.rules)}}emStrong(J,$,Y=""){let Z=this.rules.inline.emStrongLDelim.exec(J);if(!Z||Z[3]&&Y.match(this.rules.other.unicodeAlphaNumeric))return;if(!(Z[1]||Z[2])||!Y||this.rules.inline.punctuation.exec(Y)){let Q=[...Z[0]].length-1,q,X,G=Q,_=0,z=Z[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(z.lastIndex=0,$=$.slice(-1*J.length+Q);(Z=z.exec($))!=null;){if(q=Z[1]||Z[2]||Z[3]||Z[4]||Z[5]||Z[6],!q)continue;if(X=[...q].length,Z[3]||Z[4]){G+=X;continue}else if((Z[5]||Z[6])&&Q%3&&!((Q+X)%3)){_+=X;continue}if(G-=X,G>0)continue;X=Math.min(X,X+G+_);let H=[...Z[0]][0].length,U=J.slice(0,Q+Z.index+H+X);if(Math.min(Q,X)%2){let N=U.slice(1,-1);return{type:"em",raw:U,text:N,tokens:this.lexer.inlineTokens(N)}}let W=U.slice(2,-2);return{type:"strong",raw:U,text:W,tokens:this.lexer.inlineTokens(W)}}}}codespan(J){let $=this.rules.inline.code.exec(J);if($){let Y=$[2].replace(this.rules.other.newLineCharGlobal," "),Z=this.rules.other.nonSpaceChar.test(Y),Q=this.rules.other.startingSpaceChar.test(Y)&&this.rules.other.endingSpaceChar.test(Y);return Z&&Q&&(Y=Y.substring(1,Y.length-1)),{type:"codespan",raw:$[0],text:Y}}}br(J){let $=this.rules.inline.br.exec(J);if($)return{type:"br",raw:$[0]}}del(J,$,Y=""){let Z=this.rules.inline.delLDelim.exec(J);if(!Z)return;if(!Z[1]||!Y||this.rules.inline.punctuation.exec(Y)){let Q=[...Z[0]].length-1,q,X,G=Q,_=this.rules.inline.delRDelim;for(_.lastIndex=0,$=$.slice(-1*J.length+Q);(Z=_.exec($))!=null;){if(q=Z[1]||Z[2]||Z[3]||Z[4]||Z[5]||Z[6],!q||(X=[...q].length,X!==Q))continue;if(Z[3]||Z[4]){G+=X;continue}if(G-=X,G>0)continue;X=Math.min(X,X+G);let z=[...Z[0]][0].length,H=J.slice(0,Q+Z.index+z+X),U=H.slice(Q,-Q);return{type:"del",raw:H,text:U,tokens:this.lexer.inlineTokens(U)}}}}autolink(J){let $=this.rules.inline.autolink.exec(J);if($){let Y,Z;return $[2]==="@"?(Y=$[1],Z="mailto:"+Y):(Y=$[1],Z=Y),{type:"link",raw:$[0],text:Y,href:Z,tokens:[{type:"text",raw:Y,text:Y}]}}}url(J){let $;if($=this.rules.inline.url.exec(J)){let Y,Z;if($[2]==="@")Y=$[0],Z="mailto:"+Y;else{let Q;do Q=$[0],$[0]=this.rules.inline._backpedal.exec($[0])?.[0]??"";while(Q!==$[0]);Y=$[0],$[1]==="www."?Z="http://"+$[0]:Z=$[0]}return{type:"link",raw:$[0],text:Y,href:Z,tokens:[{type:"text",raw:Y,text:Y}]}}}inlineText(J){let $=this.rules.inline.text.exec(J);if($){let Y=this.lexer.state.inRawBlock;return{type:"text",raw:$[0],text:$[0],escaped:Y}}}},z1=class J{tokens;options;state;inlineQueue;tokenizer;constructor($){this.tokens=[],this.tokens.links=Object.create(null),this.options=$||V1,this.options.tokenizer=this.options.tokenizer||new H0,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let Y={other:Z1,block:U0.normal,inline:o1.normal};this.options.pedantic?(Y.block=U0.pedantic,Y.inline=o1.pedantic):this.options.gfm&&(Y.block=U0.gfm,this.options.breaks?Y.inline=o1.breaks:Y.inline=o1.gfm),this.tokenizer.rules=Y}static get rules(){return{block:U0,inline:o1}}static lex($,Y){return new J(Y).lex($)}static lexInline($,Y){return new J(Y).inlineTokens($)}lex($){$=$.replace(Z1.carriageReturn,`
|
|
27
|
+
`),this.blockTokens($,this.tokens);for(let Y=0;Y<this.inlineQueue.length;Y++){let Z=this.inlineQueue[Y];this.inlineTokens(Z.src,Z.tokens)}return this.inlineQueue=[],this.tokens}blockTokens($,Y=[],Z=!1){for(this.options.pedantic&&($=$.replace(Z1.tabCharGlobal," ").replace(Z1.spaceLine,""));$;){let Q;if(this.options.extensions?.block?.some((X)=>(Q=X.call({lexer:this},$,Y))?($=$.substring(Q.raw.length),Y.push(Q),!0):!1))continue;if(Q=this.tokenizer.space($)){$=$.substring(Q.raw.length);let X=Y.at(-1);Q.raw.length===1&&X!==void 0?X.raw+=`
|
|
28
|
+
`:Y.push(Q);continue}if(Q=this.tokenizer.code($)){$=$.substring(Q.raw.length);let X=Y.at(-1);X?.type==="paragraph"||X?.type==="text"?(X.raw+=(X.raw.endsWith(`
|
|
29
29
|
`)?"":`
|
|
30
|
-
`)+Q.raw,
|
|
31
|
-
`+Q.text,this.inlineQueue.at(-1).src=
|
|
30
|
+
`)+Q.raw,X.text+=`
|
|
31
|
+
`+Q.text,this.inlineQueue.at(-1).src=X.text):Y.push(Q);continue}if(Q=this.tokenizer.fences($)){$=$.substring(Q.raw.length),Y.push(Q);continue}if(Q=this.tokenizer.heading($)){$=$.substring(Q.raw.length),Y.push(Q);continue}if(Q=this.tokenizer.hr($)){$=$.substring(Q.raw.length),Y.push(Q);continue}if(Q=this.tokenizer.blockquote($)){$=$.substring(Q.raw.length),Y.push(Q);continue}if(Q=this.tokenizer.list($)){$=$.substring(Q.raw.length),Y.push(Q);continue}if(Q=this.tokenizer.html($)){$=$.substring(Q.raw.length),Y.push(Q);continue}if(Q=this.tokenizer.def($)){$=$.substring(Q.raw.length);let X=Y.at(-1);X?.type==="paragraph"||X?.type==="text"?(X.raw+=(X.raw.endsWith(`
|
|
32
32
|
`)?"":`
|
|
33
|
-
`)+Q.raw,
|
|
34
|
-
`+Q.raw,this.inlineQueue.at(-1).src=
|
|
33
|
+
`)+Q.raw,X.text+=`
|
|
34
|
+
`+Q.raw,this.inlineQueue.at(-1).src=X.text):this.tokens.links[Q.tag]||(this.tokens.links[Q.tag]={href:Q.href,title:Q.title},Y.push(Q));continue}if(Q=this.tokenizer.table($)){$=$.substring(Q.raw.length),Y.push(Q);continue}if(Q=this.tokenizer.lheading($)){$=$.substring(Q.raw.length),Y.push(Q);continue}let q=$;if(this.options.extensions?.startBlock){let X=1/0,G=$.slice(1),_;this.options.extensions.startBlock.forEach((z)=>{_=z.call({lexer:this},G),typeof _=="number"&&_>=0&&(X=Math.min(X,_))}),X<1/0&&X>=0&&(q=$.substring(0,X+1))}if(this.state.top&&(Q=this.tokenizer.paragraph(q))){let X=Y.at(-1);Z&&X?.type==="paragraph"?(X.raw+=(X.raw.endsWith(`
|
|
35
35
|
`)?"":`
|
|
36
|
-
`)+Q.raw,
|
|
37
|
-
`+Q.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=
|
|
36
|
+
`)+Q.raw,X.text+=`
|
|
37
|
+
`+Q.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=X.text):Y.push(Q),Z=q.length!==$.length,$=$.substring(Q.raw.length);continue}if(Q=this.tokenizer.text($)){$=$.substring(Q.raw.length);let X=Y.at(-1);X?.type==="text"?(X.raw+=(X.raw.endsWith(`
|
|
38
38
|
`)?"":`
|
|
39
|
-
`)+Q.raw,
|
|
40
|
-
`+Q.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=
|
|
39
|
+
`)+Q.raw,X.text+=`
|
|
40
|
+
`+Q.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=X.text):Y.push(Q);continue}if($){let X="Infinite loop on byte: "+$.charCodeAt(0);if(this.options.silent){console.error(X);break}else throw Error(X)}}return this.state.top=!0,Y}inline($,Y=[]){return this.inlineQueue.push({src:$,tokens:Y}),Y}inlineTokens($,Y=[]){let Z=$,Q=null;if(this.tokens.links){let _=Object.keys(this.tokens.links);if(_.length>0)for(;(Q=this.tokenizer.rules.inline.reflinkSearch.exec(Z))!=null;)_.includes(Q[0].slice(Q[0].lastIndexOf("[")+1,-1))&&(Z=Z.slice(0,Q.index)+"["+"a".repeat(Q[0].length-2)+"]"+Z.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(Q=this.tokenizer.rules.inline.anyPunctuation.exec(Z))!=null;)Z=Z.slice(0,Q.index)+"++"+Z.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let q;for(;(Q=this.tokenizer.rules.inline.blockSkip.exec(Z))!=null;)q=Q[2]?Q[2].length:0,Z=Z.slice(0,Q.index+q)+"["+"a".repeat(Q[0].length-q-2)+"]"+Z.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);Z=this.options.hooks?.emStrongMask?.call({lexer:this},Z)??Z;let X=!1,G="";for(;$;){X||(G=""),X=!1;let _;if(this.options.extensions?.inline?.some((H)=>(_=H.call({lexer:this},$,Y))?($=$.substring(_.raw.length),Y.push(_),!0):!1))continue;if(_=this.tokenizer.escape($)){$=$.substring(_.raw.length),Y.push(_);continue}if(_=this.tokenizer.tag($)){$=$.substring(_.raw.length),Y.push(_);continue}if(_=this.tokenizer.link($)){$=$.substring(_.raw.length),Y.push(_);continue}if(_=this.tokenizer.reflink($,this.tokens.links)){$=$.substring(_.raw.length);let H=Y.at(-1);_.type==="text"&&H?.type==="text"?(H.raw+=_.raw,H.text+=_.text):Y.push(_);continue}if(_=this.tokenizer.emStrong($,Z,G)){$=$.substring(_.raw.length),Y.push(_);continue}if(_=this.tokenizer.codespan($)){$=$.substring(_.raw.length),Y.push(_);continue}if(_=this.tokenizer.br($)){$=$.substring(_.raw.length),Y.push(_);continue}if(_=this.tokenizer.del($,Z,G)){$=$.substring(_.raw.length),Y.push(_);continue}if(_=this.tokenizer.autolink($)){$=$.substring(_.raw.length),Y.push(_);continue}if(!this.state.inLink&&(_=this.tokenizer.url($))){$=$.substring(_.raw.length),Y.push(_);continue}let z=$;if(this.options.extensions?.startInline){let H=1/0,U=$.slice(1),W;this.options.extensions.startInline.forEach((N)=>{W=N.call({lexer:this},U),typeof W=="number"&&W>=0&&(H=Math.min(H,W))}),H<1/0&&H>=0&&(z=$.substring(0,H+1))}if(_=this.tokenizer.inlineText(z)){$=$.substring(_.raw.length),_.raw.slice(-1)!=="_"&&(G=_.raw.slice(-1)),X=!0;let H=Y.at(-1);H?.type==="text"?(H.raw+=_.raw,H.text+=_.text):Y.push(_);continue}if($){let H="Infinite loop on byte: "+$.charCodeAt(0);if(this.options.silent){console.error(H);break}else throw Error(H)}}return Y}},W0=class{options;parser;constructor(J){this.options=J||V1}space(J){return""}code({text:J,lang:$,escaped:Y}){let Z=($||"").match(Z1.notSpaceStart)?.[0],Q=J.replace(Z1.endingNewline,"")+`
|
|
41
41
|
`;return Z?'<pre><code class="language-'+K1(Z)+'">'+(Y?Q:K1(Q,!0))+`</code></pre>
|
|
42
42
|
`:"<pre><code>"+(Y?Q:K1(Q,!0))+`</code></pre>
|
|
43
43
|
`}blockquote({tokens:J}){return`<blockquote>
|
|
44
44
|
${this.parser.parse(J)}</blockquote>
|
|
45
45
|
`}html({text:J}){return J}def(J){return""}heading({tokens:J,depth:$}){return`<h${$}>${this.parser.parseInline(J)}</h${$}>
|
|
46
46
|
`}hr(J){return`<hr>
|
|
47
|
-
`}list(J){let{ordered:$,start:Y}=J,Z="";for(let
|
|
47
|
+
`}list(J){let{ordered:$,start:Y}=J,Z="";for(let X=0;X<J.items.length;X++){let G=J.items[X];Z+=this.listitem(G)}let Q=$?"ol":"ul",q=$&&Y!==1?' start="'+Y+'"':"";return"<"+Q+q+`>
|
|
48
48
|
`+Z+"</"+Q+`>
|
|
49
49
|
`}listitem(J){return`<li>${this.parser.parse(J.tokens)}</li>
|
|
50
50
|
`}checkbox({checked:J}){return"<input "+(J?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:J}){return`<p>${this.parser.parseInline(J)}</p>
|
|
51
|
-
`}table(J){let $="",Y="";for(let Q=0;Q<J.header.length;Q++)Y+=this.tablecell(J.header[Q]);$+=this.tablerow({text:Y});let Z="";for(let Q=0;Q<J.rows.length;Q++){let
|
|
51
|
+
`}table(J){let $="",Y="";for(let Q=0;Q<J.header.length;Q++)Y+=this.tablecell(J.header[Q]);$+=this.tablerow({text:Y});let Z="";for(let Q=0;Q<J.rows.length;Q++){let q=J.rows[Q];Y="";for(let X=0;X<q.length;X++)Y+=this.tablecell(q[X]);Z+=this.tablerow({text:Y})}return Z&&(Z=`<tbody>${Z}</tbody>`),`<table>
|
|
52
52
|
<thead>
|
|
53
53
|
`+$+`</thead>
|
|
54
54
|
`+Z+`</table>
|
|
55
55
|
`}tablerow({text:J}){return`<tr>
|
|
56
56
|
${J}</tr>
|
|
57
57
|
`}tablecell(J){let $=this.parser.parseInline(J.tokens),Y=J.header?"th":"td";return(J.align?`<${Y} align="${J.align}">`:`<${Y}>`)+$+`</${Y}>
|
|
58
|
-
`}strong({tokens:J}){return`<strong>${this.parser.parseInline(J)}</strong>`}em({tokens:J}){return`<em>${this.parser.parseInline(J)}</em>`}codespan({text:J}){return`<code>${K1(J,!0)}</code>`}br(J){return"<br>"}del({tokens:J}){return`<del>${this.parser.parseInline(J)}</del>`}link({href:J,title:$,tokens:Y}){let Z=this.parser.parseInline(Y),Q=
|
|
59
|
-
Please report this to https://github.com/markedjs/marked.`,J){let Z="<p>An error occurred:</p><pre>"+K1(Y.message+"",!0)+"</pre>";return $?Promise.resolve(Z):Z}if($)return Promise.reject(Y);throw Y}}},P1=new N3;function l(J,$){return P1.parse(J,$)}l.options=l.setOptions=function(J){return P1.setOptions(J),l.defaults=P1.defaults,H5(l.defaults),l};l.getDefaults=C0;l.defaults=S1;l.use=function(...J){return P1.use(...J),l.defaults=P1.defaults,H5(l.defaults),l};l.walkTokens=function(J,$){return P1.walkTokens(J,$)};l.parseInline=P1.parseInline;l.Parser=z1;l.parser=z1.parse;l.Renderer=Q0;l.TextRenderer=u0;l.Lexer=q1;l.lexer=q1.lex;l.Tokenizer=Y0;l.Hooks=r1;l.parse=l;var{options:X4,setOptions:q4,use:z4,walkTokens:_4,parseInline:K4}=l;var U4=z1.parse,G4=q1.lex;import{SessionContext as b2,ActiveViewCtx as n$}from"#canvas/runtime";import{useState as a1,useCallback as U1,useEffect as T3,useRef as y3}from"react";import{AnnotationCtx as O3}from"#canvas/runtime";var X1="__agent-response__";function _1(){return`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`}function i1(J,$){J.style.height="auto",J.style.height=($?Math.max($,J.scrollHeight):J.scrollHeight)+"px"}import{useAnnotations as t}from"#canvas/runtime";import{jsxDEV as P3}from"react/jsx-dev-runtime";function E0(J,$){return`canvas:${J}:rev:${$}`}function q0(J,$){try{let Y=localStorage.getItem(E0(J,$));if(!Y)return null;return JSON.parse(Y)}catch{return null}}function L3(J,$,Y){try{localStorage.setItem(E0(J,$),JSON.stringify(Y))}catch{}}function M3(J,$){try{localStorage.removeItem(E0(J,$))}catch{}}function b5({sessionId:J,revision:$,isReadOnly:Y,children:Z}){let[Q,X]=a1(()=>{return q0(J,$)?.annotations??[]}),[q,_]=a1(()=>{return q0(J,$)?.generalNote??""}),[z,K]=a1(null),[G,U]=a1(()=>{let V=q0(J,$);return V?.responses?new Map(V.responses):new Map}),[H,F]=a1(()=>{let V=q0(J,$);return V?.feedbackEntries?new Map(V.feedbackEntries):new Map}),W=y3(null);T3(()=>{if(Y)return;if(W.current)clearTimeout(W.current);return W.current=setTimeout(()=>{L3(J,$,{annotations:Q,generalNote:q,responses:Array.from(G.entries()),feedbackEntries:Array.from(H.entries())})},300),()=>{if(W.current)clearTimeout(W.current)}},[Q,q,G,H,J,$,Y]);let L=U1((V,I,f,A,v,M)=>{X((w)=>[...w,{id:V,snippet:I,note:f,createdAt:new Date().toISOString(),filePath:A,context:v,...M?.length?{images:M}:{}}])},[]),T=U1((V,I,f)=>{L(_1(),V,I,f)},[L]),S=U1((V,I)=>{X((f)=>f.map((A)=>A.id===V?{...A,note:I}:A))},[]),O=U1((V)=>{B3(V),X((I)=>I.filter((f)=>f.id!==V)),K((I)=>I===V?null:I)},[]),j=U1((V,I)=>{X((f)=>f.map((A)=>A.id===V?{...A,images:[...A.images||[],I]}:A))},[]),m=U1((V,I)=>{X((f)=>f.map((A)=>A.id===V?{...A,images:(A.images||[]).filter((v)=>v!==I)}:A))},[]),B=U1((V,I)=>{U((f)=>{let A=new Map(f);return A.set(V,I),A})},[]),R=U1((V,I)=>{F((f)=>{let A=f.get(V);if(A&&A.markdown===I.markdown&&A.label===I.label&&A.required===I.required)return f;let v=new Map(f);return v.set(V,I),v})},[]),g=U1((V)=>{F((I)=>{if(!I.has(V))return I;let f=new Map(I);return f.delete(V),f})},[]),u=U1(()=>{for(let V of document.querySelectorAll("[data-annotation-id]"))w5(V);X([]),_(""),K(null),U(new Map),F(new Map),M3(J,$)},[J,$]);return P3(O3.Provider,{value:{annotations:Q,addAnnotation:T,addAnnotationWithId:L,updateAnnotation:S,removeAnnotation:O,addAnnotationImage:j,removeAnnotationImage:m,generalNote:q,setGeneralNote:_,clearAll:u,activeAnnotationId:z,setActiveAnnotationId:K,responses:G,setResponse:B,feedbackEntries:H,setFeedbackEntry:R,removeFeedbackEntry:g},children:Z},void 0,!1,void 0,this)}function B3(J){let $=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Y of $)w5(Y)}function w5(J){let $=J.parentNode;if(!$)return;let Y=document.createTextNode(J.textContent||"");$.replaceChild(Y,J),$.normalize()}import r0,{useEffect as j1,useState as G1,useRef as f3,useContext as v3,useMemo as N0}from"react";import{createPortal as g3}from"react-dom";import{SessionContext as u3}from"#canvas/runtime";function b1(J,$){let Y=A5(J,"before",60),Z=A5(J,"after",60),Q=b3(J.startContainer,$);return{before:Y,after:Z,hierarchy:Q}}function A5(J,$,Y){let Z=S3($==="before"?J.startContainer:J.endContainer);if(!Z)return"";let Q="";if($==="before"){let X=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),q;while(q=X.nextNode()){if(q===J.startContainer){Q+=(q.textContent||"").slice(0,J.startOffset);break}if(q.parentElement?.hasAttribute("data-annotation-id"))continue;Q+=q.textContent||""}if(Q.length>Y){Q=Q.slice(-Y);let _=Q.indexOf(" ");if(_>0)Q=Q.slice(_+1)}}else{let X=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),q=!1,_;while(_=X.nextNode()){if(_===J.endContainer){Q+=(_.textContent||"").slice(J.endOffset),q=!0;continue}if(q){if(_.parentElement?.hasAttribute("data-annotation-id"))continue;Q+=_.textContent||""}}if(Q.length>Y){Q=Q.slice(0,Y);let z=Q.lastIndexOf(" ");if(z>0)Q=Q.slice(0,z)}}return Q.trim()}function S3(J){let $=new Set(["DIV","P","LI","PRE","BLOCKQUOTE","SECTION","ARTICLE"]),Y=J.parentElement;while(Y){if($.has(Y.tagName))return Y;Y=Y.parentElement}return null}function b3(J,$){let Y=[],Z=J instanceof Element?J:J.parentElement;while(Z&&Z!==$){let Q=Z.getAttribute?.("data-task-id");if(Q){let X=Z.querySelector(".font-semibold");if(X)Y.unshift(X.textContent?.trim()||Q)}if(Z.tagName==="DIV"&&Z.querySelector(":scope > button .font-heading, :scope > div .font-heading")){let X=Z.querySelector(".font-heading");if(X)Y.unshift(X.textContent?.trim()||"")}Z=Z.parentElement}return Y}function x0(J){let $=J.snippet.trim(),Y=J.context,Z=$.length<30;if(Y&&Z&&(Y.before||Y.after)){let Q=[];if(Y.before)Q.push(`...${Y.before} `);if(Q.push(`**${$}**`),Y.after)Q.push(` ${Y.after}...`);return Q.join("")}return $}import{useEffect as R3,useRef as K0,useState as k1,useCallback as _0,useMemo as C5,useContext as I3}from"react";import{createPortal as j3}from"react-dom";function R5(J,$){let Q=$||document.body,X=J.getBoundingClientRect(),q=Q.getBoundingClientRect(),_=Q===document.body?window.scrollY:Q.scrollTop,z=X.bottom-q.top+_+8,K=Math.max(0,Math.min(X.left-q.left,q.width-280-12));return Q.style.position="relative",{style:{position:"absolute",top:`${z}px`,left:`${K}px`},parent:Q}}import{useState as h0,useRef as p0,useCallback as F1,useEffect as w3}from"react";import{jsxDEV as n}from"react/jsx-dev-runtime";function I5(J){return`/api/uploads/${J.split("/").pop()}`}async function A3(J,$){let Y=new FormData;Y.append("image",$);try{return(await(await fetch(`/api/session/${J}/upload`,{method:"POST",body:Y})).json()).path||null}catch{return null}}function z0({note:J,onNoteChange:$,images:Y,onAddImage:Z,onRemoveImage:Q,sessionId:X,placeholder:q="Add your note...",autoFocus:_=!1,autoResize:z=!1,readOnly:K=!1,onKeyDown:G,onTextareaClick:U,textareaRef:H,textareaClassName:F,textareaStyle:W,minHeight:L,attachButton:T="always",openFilePickerRef:S}){let[O,j]=h0(!1),[m,B]=h0(!1),[R,g]=h0(!1),u=p0(0),V=p0(null),I=p0(null),f=F1(()=>I.current?.click(),[]);if(S)S.current=f;let A=F1((C)=>{if(V.current=C,H)H.current=C;if(C&&z)i1(C,L)},[H,z,L]);w3(()=>{if(_&&V.current){let C=V.current;if(C.focus(),C.value)C.setSelectionRange(C.value.length,C.value.length)}},[_]);let v=F1(async(C)=>{if(!C.type.startsWith("image/"))return;B(!0);try{let i=await A3(X,C);if(i)Z(i)}finally{B(!1)}},[X,Z]),M=F1((C)=>{let i=C.clipboardData.items;for(let D of i)if(D.type.startsWith("image/")){C.preventDefault();let h=D.getAsFile();if(h)v(h);return}},[v]),w=F1((C)=>{if(C.preventDefault(),u.current++,u.current===1)j(!0)},[]),y=F1((C)=>{C.preventDefault()},[]),P=F1((C)=>{if(C.preventDefault(),u.current--,u.current===0)j(!1)},[]),k=F1((C)=>{C.preventDefault(),u.current=0,j(!1);for(let i of C.dataTransfer.files)if(i.type.startsWith("image/"))v(i)},[v]),E=F1((C)=>{if($(C.target.value),z)C.target.style.height="auto",C.target.style.height=(L?Math.max(L,C.target.scrollHeight):C.target.scrollHeight)+"px"},[$,z,L]),r="w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none",c={width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",outline:"none",...z?{resize:"none",overflow:"hidden"}:{resize:"vertical"}},a=!K&&(T==="always"||T==="on-focus"&&R);return n("div",{style:{position:"relative"},onDragEnter:K?void 0:w,onDragOver:K?void 0:y,onDragLeave:K?void 0:P,onDrop:K?void 0:k,children:[n("textarea",{ref:A,value:J,onChange:K?void 0:E,onPaste:K?void 0:M,onKeyDown:G,onClick:U,onFocus:()=>g(!0),onBlur:()=>{setTimeout(()=>g(!1),150)},readOnly:K,placeholder:q,className:F??r,style:W??c,rows:z?1:void 0},void 0,!1,void 0,this),!K&&n("input",{ref:I,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:(C)=>{let i=C.target.files;if(i)for(let D of i)v(D);C.target.value=""}},void 0,!1,void 0,this),(Y.length>0||a)&&n("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px",alignItems:"center"},children:[Y.map((C)=>n("div",{style:{position:"relative",width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:[n("img",{src:I5(C),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this),!K&&n("button",{onClick:(i)=>{i.stopPropagation(),Q(C)},style:{position:"absolute",top:"2px",right:"2px",width:"16px",height:"16px",borderRadius:"50%",background:"rgba(0,0,0,0.6)",color:"white",border:"none",cursor:"pointer",fontSize:"11px",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,padding:0},title:"Remove image",children:"×"},void 0,!1,void 0,this)]},C,!0,void 0,this)),a&&n(c0,{onClick:f},void 0,!1,void 0,this)]},void 0,!0,void 0,this),m&&n("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontFamily:"'Inter', sans-serif",marginTop:"4px"},children:"Uploading..."},void 0,!1,void 0,this),O&&n("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",background:"var(--color-highlight-bg)",opacity:0.9,border:"2px dashed var(--color-highlight-border)",borderRadius:"6px",zIndex:10,pointerEvents:"none",fontSize:"12px",fontFamily:"'Inter', sans-serif",color:"var(--color-text-secondary)"},children:"Drop image"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function c0({onClick:J,size:$=16}){return n("button",{onClick:(Y)=>{Y.stopPropagation(),J()},style:{width:`${$*2}px`,height:`${$*2}px`,borderRadius:"6px",border:"none",background:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--color-text-tertiary)",flexShrink:0,transition:"color 0.15s"},title:"Attach image",onMouseEnter:(Y)=>{Y.currentTarget.style.color="var(--color-text-secondary)"},onMouseLeave:(Y)=>{Y.currentTarget.style.color="var(--color-text-tertiary)"},children:n("svg",{width:$,height:$,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[n("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),n("circle",{cx:"8.5",cy:"8.5",r:"1.5"},void 0,!1,void 0,this),n("polyline",{points:"21 15 16 10 5 21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function j5({images:J}){if(!J.length)return null;return n("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px"},children:J.map(($)=>n("div",{style:{width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:n("img",{src:I5($),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this)},$,!1,void 0,this))},void 0,!1,void 0,this)}import{SessionContext as C3}from"#canvas/runtime";import{jsxDEV as e,Fragment as D3}from"react/jsx-dev-runtime";function V3({anchorEl:J,scrollContainer:$,onClose:Y,ignoreSelector:Z,zIndex:Q="50",padding:X="12px",width:q="280px",children:_}){let z=K0(null),K=K0(Y);K.current=Y;let{style:G,parent:U}=R5(J,$);return R3(()=>{let H=setTimeout(()=>{let F=(W)=>{if(z.current&&!z.current.contains(W.target)){if(Z&&W.target.closest?.(Z))return;K.current(),document.removeEventListener("mousedown",F)}};return document.addEventListener("mousedown",F),()=>document.removeEventListener("mousedown",F)},0);return()=>clearTimeout(H)},[Z]),j3(e("div",{ref:z,style:{...G,zIndex:Q,width:q,background:"var(--color-bg-elevated)",border:"1px solid var(--color-border-hover)",borderRadius:"8px",boxShadow:"0 4px 12px var(--color-shadow)",padding:X,fontFamily:"'Inter', sans-serif"},children:_},void 0,!1,void 0,this),U)}var D5=[{label:"Clarity",items:["Unclear","Why?","Needs example","Missing context"]},{label:"Scope",items:["Overkill","Out of scope","Important","Risky"]},{label:"Action",items:["Simplify","Rethink","Expand on this","Skip this"]}],V5=D5.flatMap((J)=>J.items);function m5({anchorEl:J,scrollContainer:$,snippet:Y,truncateAt:Z=100,header:Q,initialNote:X="",initialImages:q,onConfirm:_,onCancel:z,onDelete:K}){let G=I3(C3),U=X!==""||!!K,[H,F]=k1(X),[W,L]=k1(q||[]),[T,S]=k1(null),[O,j]=k1(U),[m,B]=k1(!1),R=K0(null),g=K0(null),u=_0(()=>{if(H.trim()||W.length>0)_(H.trim(),W);else if(U&&K)K();else z()},[H,W,_,z,U,K]),V=_0(()=>{if(U){if(!H.trim()&&W.length===0&&K){K(),z();return}_(H,W);return}z()},[H,W,U,_,z,K]),I=!U,f=H.trim().length>0?V5.filter((D)=>D.toLowerCase().startsWith(H.trim().toLowerCase())):V5,A=!I||O?[]:f.length===1&&f[0].toLowerCase()===H.trim().toLowerCase()?[]:f,v=new Set(A),M=D5.map((D)=>({label:D.label,items:D.items.filter((h)=>v.has(h))})).filter((D)=>D.items.length>0),w=M.map((D)=>D.items),y=w.flat(),P=C5(()=>{if(T===null)return 0;let D=0;for(let h=0;h<w.length;h++){if(T<D+w[h].length)return h;D+=w[h].length}return 0},[T,w]),k=C5(()=>{if(T===null)return 0;let D=0;for(let h=0;h<P;h++)D+=w[h].length;return T-D},[T,P,w]),E=(D,h)=>{let J1=0;for(let W1=0;W1<D;W1++)J1+=w[W1].length;return J1+h},[r,c]=k1(H);if(H!==r)c(H),S(null),j(U);let a=_0((D)=>{F(D)},[]),C=Y.length>Z?Y.slice(0,Z)+"...":Y,i=_0((D)=>{if(y.length>0&&(D.key==="ArrowDown"||D.key==="ArrowUp"||D.key==="ArrowLeft"||D.key==="ArrowRight")){if(D.preventDefault(),T===null){S(0);return}if(D.key==="ArrowDown"){let h=Math.min(k+1,w[P].length-1);S(E(P,h))}else if(D.key==="ArrowUp"){let h=Math.max(k-1,0);S(E(P,h))}else if(D.key==="ArrowRight"){let h=Math.min(P+1,w.length-1),J1=Math.min(k,w[h].length-1);S(E(h,J1))}else if(D.key==="ArrowLeft"){let h=Math.max(P-1,0),J1=Math.min(k,w[h].length-1);S(E(h,J1))}return}if(T!==null&&y.length>0){if(D.key==="Tab"){D.preventDefault(),a(y[T]);return}if(D.key==="Enter"&&!D.shiftKey){D.preventDefault(),_(y[T],W);return}}if(D.key==="Enter"&&!D.shiftKey){D.preventDefault(),u();return}if(D.key==="Escape")if(y.length>0&&!O)j(!0);else if(U)V();else z()},[y,T,k,P,w,E,a,_,W,u,O,U,V,z]);return e(V3,{anchorEl:J,scrollContainer:$,onClose:U?V:z,ignoreSelector:U?"[data-annotation-id]":void 0,zIndex:U?"60":"50",padding:U?"10px 12px":"12px",width:"420px",children:[!U&&(Q??e("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontStyle:"italic",marginBottom:"8px",lineHeight:"1.4",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"},children:["“",C,"”"]},void 0,!0,void 0,this)),e(z0,{note:H,onNoteChange:F,images:W,onAddImage:(D)=>L((h)=>[...h,D]),onRemoveImage:(D)=>L((h)=>h.filter((J1)=>J1!==D)),sessionId:G,autoFocus:!0,autoResize:U,textareaRef:R,onKeyDown:i,attachButton:"none",openFilePickerRef:g,textareaStyle:U?{width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"none",outline:"none",overflow:"hidden"}:{width:"100%",minHeight:"60px",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"vertical",outline:"none"},placeholder:"Add your note..."},void 0,!1,void 0,this),e("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:U?"6px":"8px"},children:[e(c0,{onClick:()=>g.current?.(),size:14},void 0,!1,void 0,this),e("div",{style:{flex:1}},void 0,!1,void 0,this),U?e("button",{onClick:()=>{if(K)K();z()},onMouseEnter:()=>B(!0),onMouseLeave:()=>B(!1),style:{fontSize:"11px",color:m?"var(--color-accent-red)":"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"2px 0",fontFamily:"'Inter', sans-serif"},children:"Delete"},void 0,!1,void 0,this):e(D3,{children:[e("button",{onClick:z,style:{fontSize:"11px",color:"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"4px 12px",fontFamily:"'Inter', sans-serif"},children:"Cancel"},void 0,!1,void 0,this),e("button",{onClick:u,style:{fontSize:"11px",fontWeight:500,padding:"4px 12px",borderRadius:"6px",background:"var(--color-highlight-bg)",color:"var(--color-text-primary)",border:"1px solid var(--color-highlight-border)",cursor:"pointer",fontFamily:"'Inter', sans-serif"},children:"Add"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),y.length>0&&e("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:M.map((D)=>e("div",{style:{flex:1},children:[e("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--color-text-disabled)",textTransform:"uppercase",letterSpacing:"0.05em",padding:"2px 6px",marginBottom:"2px",fontFamily:"'Inter', sans-serif"},children:D.label},void 0,!1,void 0,this),D.items.map((h)=>{let J1=y.indexOf(h);return e("div",{onMouseDown:(W1)=>{W1.preventDefault(),W1.stopPropagation(),a(h)},onMouseEnter:()=>S(J1),style:{padding:"3px 6px",fontSize:"12px",borderRadius:"4px",fontFamily:"'Inter', sans-serif",color:J1===T?"var(--color-text-primary)":"var(--color-text-secondary)",background:J1===T?"var(--color-highlight-selected)":"transparent",cursor:"pointer"},children:[e("span",{style:{fontWeight:500},children:h.slice(0,H.trim().length)},void 0,!1,void 0,this),h.slice(H.trim().length)]},h,!0,void 0,this)})]},D.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function f1({anchorEl:J,scrollContainer:$,snippet:Y,truncateAt:Z,header:Q,onAdd:X,onCancel:q}){return e(m5,{anchorEl:J,scrollContainer:$,snippet:Y,truncateAt:Z,header:Q,onConfirm:(_,z)=>X(_,z),onCancel:q},void 0,!1,void 0,this)}function v1({anchorEl:J,scrollContainer:$,initialNote:Y,initialImages:Z,onUpdate:Q,onDelete:X,onClose:q}){return e(m5,{anchorEl:J,scrollContainer:$,snippet:"",initialNote:Y,initialImages:Z,onConfirm:(_,z)=>{Q(_,z),q()},onDelete:X,onCancel:q},void 0,!1,void 0,this)}import{useEffect as F0,useState as f5,useRef as g1,useCallback as v5}from"react";function A1(J,$){let Y=[],Z=m3(J);for(let Q of Z){let X=document.createRange();if(X.selectNodeContents(Q),Q===J.startContainer)X.setStart(Q,J.startOffset);if(Q===J.endContainer)X.setEnd(Q,J.endOffset);let q=X.toString();if(!q||!q.trim())continue;let _=document.createElement("mark");_.setAttribute("data-annotation-id",$);try{X.surroundContents(_)}catch{let z=X.extractContents();_.appendChild(z),X.insertNode(_)}Y.push(_)}return Y}function m3(J){let $=[],Y=J.commonAncestorContainer;if(Y.nodeType===Node.TEXT_NODE)return $.push(Y),$;let Z=document.createTreeWalker(Y,NodeFilter.SHOW_TEXT),Q;while(Q=Z.nextNode()){if(Q.parentElement?.classList.contains("select-none"))continue;if(J.intersectsNode(Q))$.push(Q)}return $}function w1(J,$){let Y=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Z of Y)Z.classList.toggle("mark-active",$)}function U0(J,$){if($!=null&&$!==J)w1($,!1);if(J!=null)w1(J,!0)}function G0(J,$){let Y=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Z of Y)Z.setAttribute("data-annotation-id",$)}function H0(J,$){let Y=$.filter((_)=>!document.querySelector(`[data-annotation-id="${_.id}"]`));if(!Y.length)return;let Z=[],Q="",X=document.createTreeWalker(J,NodeFilter.SHOW_TEXT),q;while(q=X.nextNode()){if(q.parentElement?.classList.contains("select-none"))continue;Z.push({node:q,start:Q.length}),Q+=q.textContent||""}for(let _ of Y){let z=_.snippet;if(!z)continue;let K=[],G=0;while(!0){let T=Q.indexOf(z,G);if(T===-1)break;K.push(T),G=T+1}if(K.length===0)continue;let U=K[0];if(K.length>1&&_.context){let T=-1;for(let S of K){let O=0;if(_.context.before){let j=Q.slice(Math.max(0,S-80),S);if(j.includes(_.context.before))O+=2;else if(_.context.before.length>10&&j.includes(_.context.before.slice(-10)))O+=1}if(_.context.after){let j=Q.slice(S+z.length,S+z.length+80);if(j.includes(_.context.after))O+=2;else if(_.context.after.length>10&&j.includes(_.context.after.slice(0,10)))O+=1}if(O>T)T=O,U=S}}let H=U,F=U+z.length,W=k5(Z,H),L=k5(Z,F);if(!W||!L)continue;try{let T=document.createRange();T.setStart(W.node,W.offset),T.setEnd(L.node,L.offset),A1(T,_.id)}catch{}}}function k5(J,$){for(let Y=J.length-1;Y>=0;Y--)if(J[Y].start<=$){let Z=$-J[Y].start,Q=J[Y].node.textContent?.length??0;if(Z<=Q)return{node:J[Y].node,offset:Z}}return null}function W0(J){let $=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Y of $){let Z=Y.parentNode;if(!Z)continue;while(Y.firstChild)Z.insertBefore(Y.firstChild,Y);Z.removeChild(Y),Z.normalize()}}import{jsxDEV as d0,Fragment as k3}from"react/jsx-dev-runtime";function R1(J){let{containerRef:$,restoreKey:Y,restoreAnnotations:Z,extractContext:Q,filePath:X,scrollContainer:q}=J,{annotations:_,addAnnotationWithId:z,removeAnnotation:K,updateAnnotation:G,addAnnotationImage:U,removeAnnotationImage:H,activeAnnotationId:F,setActiveAnnotationId:W}=t(),[L,T]=f5(null),[S,O]=f5(null),j=g1(Q);j.current=Q;let m=g1(X);m.current=X;let B=g1(z);B.current=z;let R=g1(F);R.current=F;let g=g1(W);g.current=W,F0(()=>{if(!$.current)return;let A=setTimeout(()=>{if($.current)H0($.current,Z)},50);return()=>clearTimeout(A)},[Y]);let u=g1(null);F0(()=>{U0(F,u.current),u.current=F},[F]),F0(()=>{let A=$.current;if(!A)return;let v=(y)=>{let P=y.target.closest("[data-annotation-id]");if(!P)return;y.stopPropagation();let k=P.getAttribute("data-annotation-id");if(k===R.current)T({anchorEl:P,annId:k});else g.current(k)},M=(y)=>{let P=y.target.closest("[data-annotation-id]");if(P)g.current(P.getAttribute("data-annotation-id"))},w=(y)=>{let P=y.target.closest("[data-annotation-id]"),k=y.relatedTarget?.closest?.("[data-annotation-id]");if(P&&!k&&!document.getElementById("ann-inline-popover"))g.current(null)};return A.addEventListener("click",v),A.addEventListener("mouseover",M),A.addEventListener("mouseout",w),()=>{A.removeEventListener("click",v),A.removeEventListener("mouseover",M),A.removeEventListener("mouseout",w)}},[Y]),F0(()=>{let A=()=>V();return document.addEventListener("mouseup",A),()=>document.removeEventListener("mouseup",A)},[]);let V=v5(()=>{let A=window.getSelection();if(!A||A.isCollapsed||!A.toString().trim())return;if(!$.current)return;let v=A.getRangeAt(0);if(!$.current.contains(v.startContainer))return;if(v.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let M=A.toString().trim();if(M.length<2)return;let w=j.current(v),y=v.cloneRange(),P=`__pending_${Date.now()}`;try{A1(y,P)}catch{}window.getSelection()?.removeAllRanges();let k=document.querySelectorAll(`[data-annotation-id="${P}"]`),E=k[k.length-1];if(!E)return;O({anchorEl:E,tempId:P,snippet:M,ctx:w})},[]),I=v5((A,v,M,w)=>{O({anchorEl:A,tempId:v,snippet:M,ctx:w})},[]);return{popovers:d0(k3,{children:[L&&(()=>{let A=_.find((v)=>v.id===L.annId);if(!A)return null;return d0(v1,{anchorEl:L.anchorEl,scrollContainer:q,initialNote:A.note,initialImages:A.images,onUpdate:(v,M)=>{G(L.annId,v);let w=A.images||[];for(let y of M)if(!w.includes(y))U(L.annId,y);for(let y of w)if(!M.includes(y))H(L.annId,y)},onDelete:()=>{K(L.annId),W(null)},onClose:()=>T(null)},void 0,!1,void 0,this)})(),S&&d0(f1,{anchorEl:S.anchorEl,scrollContainer:q,snippet:S.snippet,truncateAt:80,onAdd:(A,v)=>{let M=_1();G0(S.tempId,M),B.current(M,S.snippet,A,m.current,S.ctx,v),O(null)},onCancel:()=>{W0(S.tempId),O(null)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),openCreatePopover:I,isPopoverOpen:!!(L||S)}}import{jsxDEV as s,Fragment as u5}from"react/jsx-dev-runtime";var i0="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='choice-option'], [data-md='multichoice-option'], [data-md='userinput'], [data-md='rangeinput'], [data-md='image']",l0="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='image']";function g5({revision:J}){let $=v3(u3),[Y,Z]=G1(null),[Q,X]=G1(null),[q,_]=G1(!0),z=f3(null),{annotations:K,addAnnotationWithId:G,removeAnnotation:U,updateAnnotation:H,addAnnotationImage:F,removeAnnotationImage:W,activeAnnotationId:L,setActiveAnnotationId:T}=t(),[S,O]=G1(null),[j,m]=G1(null),[B,R]=G1(null),[g,u]=G1(null),[V,I]=G1(!1);j1(()=>{_(!0),X(null),u(null),import(`/api/session/${$}/plan.js?rev=${J}&t=${Date.now()}`).then((y)=>{Z(()=>y.default),_(!1)}).catch((y)=>{X(y.message),_(!1)})},[$,J]);let f=document.getElementById("plan-scroll-container"),{popovers:A,isPopoverOpen:v}=R1({containerRef:z,restoreKey:Y,restoreAnnotations:K,extractContext:(y)=>b1(y,z.current),scrollContainer:f}),M=N0(()=>{let y=new Map;for(let P of K)if(P.snippet.startsWith("["))y.set(P.snippet,P.id);return y},[K]);j1(()=>{let y=z.current;if(!y)return;let P=(E)=>{if(B||v)return;let r=E.target;if(r.closest("[data-block-comment-btn]"))return;I(!1);let c=r.closest(i0);if(c&&y.contains(c)){let i=I1(y).indexOf(c);u(i>=0?i:null)}else u(null);let a=r.closest(l0);if(a&&y.contains(a)){m(a);let C=u1(a),i=C?M.get(C):void 0;if(i&&i!==L)T(i)}else m(null)},k=(E)=>{if(B||v)return;if(E.relatedTarget?.closest("[data-block-comment-btn]"))return;m(null),T(null)};return y.addEventListener("mousemove",P),y.addEventListener("mouseleave",k),()=>{y.removeEventListener("mousemove",P),y.removeEventListener("mouseleave",k)}},[Y,B,v,M,L]),j1(()=>{let y=(P)=>{let k=P.target.tagName;if(k==="INPUT"||k==="TEXTAREA"||P.target.isContentEditable)return;if(B||v)return;let E=z.current;if(!E)return;if(P.key==="ArrowDown"){P.preventDefault(),I(!0);let r=I1(E);if(r.length===0)return;u((c)=>{if(c===null)return 0;return Math.min(c+1,r.length-1)})}else if(P.key==="ArrowUp"){P.preventDefault(),I(!0);let r=I1(E);if(r.length===0)return;u((c)=>{if(c===null)return r.length-1;return Math.max(c-1,0)})}else if(P.key==="a"||P.key==="A"){if(g===null||!E)return;P.preventDefault();let c=I1(E)[g];if(!c)return;let a=u1(c);if(!a)return;let C=M.get(a);if(C)T(C),R({anchorEl:c,snippet:a,annId:C});else R({anchorEl:c,snippet:a})}else if(P.key===" "||P.key==="Enter"){if(g===null)return;let c=I1(E)[g];if(!c)return;let a=c.getAttribute("data-md");if(a==="choice-option"||a==="multichoice-option")P.preventDefault(),c.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(a==="userinput"){P.preventDefault();let C=c.querySelector("textarea");if(C){C.focus();let i=(D)=>{if(D.key==="Escape")D.preventDefault(),C.blur(),I(!0)};C.addEventListener("keydown",i),C.addEventListener("blur",()=>C.removeEventListener("keydown",i),{once:!0})}}else if(a==="rangeinput"){P.preventDefault();let C=c.querySelector("input[type='range']");if(C){C.focus();let i=(D)=>{if(D.key==="Escape"||D.key==="ArrowUp"||D.key==="ArrowDown")D.preventDefault(),C.blur(),I(!0)};C.addEventListener("keydown",i),C.addEventListener("blur",()=>C.removeEventListener("keydown",i),{once:!0})}}}else if(P.key==="Escape")u(null),I(!1),T(null)};return document.addEventListener("keydown",y),()=>document.removeEventListener("keydown",y)},[g,B,v,M]),j1(()=>{let y=z.current;if(!y||g===null||!V)return;let k=I1(y)[g];if(!k)return;k.style.outline="2px solid var(--color-accent-blue)",k.style.outlineOffset="-2px",k.style.borderRadius="8px",k.scrollIntoView({block:"nearest",behavior:"smooth"});let E=u1(k),r=E?M.get(E):void 0;if(r)T(r);return()=>{k.style.outline="",k.style.outlineOffset="",k.style.borderRadius=""}},[g,V,M]);let w=N0(()=>Y?s(Y,{},void 0,!1,void 0,this):null,[Y]);if(q)return s("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading canvas..."},void 0,!1,void 0,this);if(Q)return s("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[s("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Compilation Error"},void 0,!1,void 0,this),s("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:Q},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!Y)return s("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return s(u5,{children:[s("div",{ref:z,className:"plan-content plan-updated",children:w},void 0,!1,void 0,this),S&&s(h3,{note:S.note,onSave:(y)=>{H(S.id,y),O(null)},onCancel:()=>O(null)},void 0,!1,void 0,this),A,s(E3,{containerRef:z,hoveredBlock:j,focusedBlockIndex:g,blockPopover:B,blockAnnotationMap:M,activeAnnotationId:L,onOpen:(y,P,k)=>{if(k)T(k),R({anchorEl:y,snippet:P,annId:k});else R({anchorEl:y,snippet:P})}},void 0,!1,void 0,this),B&&!B.annId&&s(f1,{anchorEl:B.anchorEl,scrollContainer:f,snippet:B.snippet,truncateAt:80,onAdd:(y,P)=>{let k=_1();G(k,B.snippet,y,void 0,void 0,P),R(null)},onCancel:()=>R(null)},void 0,!1,void 0,this),B?.annId&&(()=>{let y=K.find((P)=>P.id===B.annId);if(!y)return null;return s(v1,{anchorEl:B.anchorEl,scrollContainer:f,initialNote:y.note,initialImages:y.images,onUpdate:(P,k)=>{H(B.annId,P);let E=y.images||[];for(let r of k)if(!E.includes(r))F(B.annId,r);for(let r of E)if(!k.includes(r))W(B.annId,r)},onDelete:()=>{U(B.annId),T(null),R(null)},onClose:()=>R(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function I1(J){return Array.from(J.querySelectorAll(i0))}function u1(J){let $=J.getAttribute("data-md");if($==="item"){let Y=J.getAttribute("data-md-label");return Y?`[Item] ${Y}`:null}if($==="section"){let Y=J.getAttribute("data-md-title");return Y?`[Section] ${Y}`:null}if($==="callout"){let Y=J.getAttribute("data-md-type")||"info",Z=J.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${Y}] ${Z}`}if($==="note")return`[Note] ${J.textContent?.trim().slice(0,60)||"Note"}`;if(J.tagName==="TR"){let Y=Array.from(J.querySelectorAll("td")).map((Z)=>Z.textContent?.trim()).filter(Boolean);return Y.length?`[Row] ${Y.join(" | ")}`:null}if($==="checklist-item"){let Y=J.getAttribute("data-md-label");return Y?`[Checklist] ${Y}`:null}if($==="choice-option"||$==="multichoice-option"){let Y=J.getAttribute("data-md-label");return Y?`[Option] ${Y}`:null}if($==="userinput"){let Y=J.getAttribute("data-md-label");return Y?`[Input] ${Y}`:null}if($==="rangeinput"){let Y=J.getAttribute("data-md-label");return Y?`[Range] ${Y}`:null}if($==="image"){let Y=J.getAttribute("data-md-src");return Y?`[Image] ${Y}`:null}return null}function E3({containerRef:J,hoveredBlock:$,focusedBlockIndex:Y,blockPopover:Z,blockAnnotationMap:Q,activeAnnotationId:X,onOpen:q}){let[_,z]=G1([]);j1(()=>{let F=J.current;if(!F||Q.size===0){z([]);return}let W=[];for(let L of F.querySelectorAll(l0)){let T=u1(L);if(T&&Q.has(T))W.push(L)}z(W)},[Q,J.current]);let[K,G]=G1(null);j1(()=>{if(!X||!J.current){G(null);return}for(let F of J.current.querySelectorAll(i0)){let W=u1(F);if(W&&Q.get(W)===X){G(F);return}}G(null)},[X,Q]),j1(()=>{if(!K)return;return K.style.boxShadow="inset 0 0 0 1.5px var(--color-highlight-bg)",K.style.borderRadius="8px",()=>{K.style.boxShadow="",K.style.borderRadius=""}},[K]);let U=N0(()=>{if(Y===null||!J.current)return null;let F=I1(J.current)[Y];if(!F)return null;return F.matches(l0)?F:null},[Y,J.current]),H=N0(()=>{let F=new Set(_);if($)F.add($);if(U)F.add(U);if(Z?.anchorEl)F.add(Z.anchorEl);return Array.from(F)},[_,$,U,Z]);return s(u5,{children:H.map((F)=>s(x3,{block:F,isHovered:F===$||F===U||F===Z?.anchorEl,blockAnnotationMap:Q,activeAnnotationId:X,onOpen:q},F.getAttribute("data-task-id")||F.getAttribute("data-md-title")||F.textContent?.slice(0,30)||"block",!1,void 0,this))},void 0,!1,void 0,this)}function x3({block:J,isHovered:$,blockAnnotationMap:Y,activeAnnotationId:Z,onOpen:Q}){let X=u1(J);if(!X)return null;let q=Y.get(X),_=!!q;return g3(s("button",{"data-block-comment-btn":!0,onClick:(K)=>{K.stopPropagation(),Q(K.currentTarget,X,q)},className:`absolute top-1 right-1 z-10 w-6 h-6 flex items-center justify-center rounded transition-all duration-150 ${_?q===Z?"text-accent-amber bg-accent-amber-muted":"text-accent-amber opacity-60 hover:opacity-100":$?"text-text-disabled hover:text-text-tertiary opacity-50 hover:opacity-100":"text-text-disabled opacity-0 group-hover/section:opacity-20 hover:!opacity-80"}`,title:_?"Edit annotation":"Add annotation",children:s("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:_?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:s("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),J)}function h3({note:J,onSave:$,onCancel:Y}){let[Z,Q]=r0.useState(J),X=r0.useRef(null);return r0.useEffect(()=>{X.current?.focus(),X.current?.select()},[]),s("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center",onClick:Y,children:s("div",{className:"bg-bg-elevated border border-border-hover rounded-lg shadow-md p-4 w-80",onClick:(q)=>q.stopPropagation(),children:[s("div",{className:"text-tiny uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Edit annotation"},void 0,!1,void 0,this),s("textarea",{ref:X,value:Z,onChange:(q)=>Q(q.target.value),className:"w-full bg-transparent border-none text-body font-body text-text-primary resize-vertical focus:outline-none min-h-[60px]",onKeyDown:(q)=>{if(q.key==="Enter"&&(q.ctrlKey||q.metaKey))$(Z.trim());if(q.key==="Escape")Y()}},void 0,!1,void 0,this),s("div",{className:"flex justify-end gap-2 mt-2",children:[s("button",{onClick:Y,className:"text-meta text-text-tertiary font-body px-3 py-1",children:"Cancel"},void 0,!1,void 0,this),s("button",{onClick:()=>$(Z.trim()),className:"text-meta font-medium font-body px-3 py-1 rounded-md bg-highlight-bg text-text-primary border border-highlight-border",children:"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import n3,{useRef as d5,useEffect as t0,useCallback as r5,useState as E1,useContext as L0}from"react";function s1(J,$,Y,Z){let Q=[],X=J.filter((U)=>U.filePath===X1),q=J.filter((U)=>!U.filePath),_=J.filter((U)=>U.filePath&&U.filePath!==X1),z=Y?Array.from(Y.values()).filter((U)=>s0(U)):[],K=Z?Array.from(Z.values()).filter((U)=>U.markdown.trim()):[];if(z.length>0||K.length>0){Q.push("## Responses"),Q.push("");for(let U of z)Q.push(d3(U));for(let U of K)Q.push(U.markdown.trim()),Q.push("")}if(X.length>0){Q.push("## Annotations on agent response"),Q.push("");for(let U of X)Q.push(a0(U))}if(q.length>0){Q.push("## Canvas annotations"),Q.push("");let U=r3(q);Q.push(E5(U))}if(_.length>0){let U={};for(let H of _){let F=H.filePath;if(!U[F])U[F]=[];U[F].push(H)}Q.push("## File annotations"),Q.push("");for(let[H,F]of Object.entries(U)){Q.push(`### ${H}`),Q.push("");for(let W of F)Q.push(a0(W))}}if($.trim())Q.push("## General notes"),Q.push(""),Q.push($.trim()),Q.push("");return Q.join(`
|
|
58
|
+
`}strong({tokens:J}){return`<strong>${this.parser.parseInline(J)}</strong>`}em({tokens:J}){return`<em>${this.parser.parseInline(J)}</em>`}codespan({text:J}){return`<code>${K1(J,!0)}</code>`}br(J){return"<br>"}del({tokens:J}){return`<del>${this.parser.parseInline(J)}</del>`}link({href:J,title:$,tokens:Y}){let Z=this.parser.parseInline(Y),Q=L5(J);if(Q===null)return Z;J=Q;let q='<a href="'+J+'"';return $&&(q+=' title="'+K1($)+'"'),q+=">"+Z+"</a>",q}image({href:J,title:$,text:Y,tokens:Z}){Z&&(Y=this.parser.parseInline(Z,this.parser.textRenderer));let Q=L5(J);if(Q===null)return K1(Y);J=Q;let q=`<img src="${J}" alt="${K1(Y)}"`;return $&&(q+=` title="${K1($)}"`),q+=">",q}text(J){return"tokens"in J&&J.tokens?this.parser.parseInline(J.tokens):("escaped"in J)&&J.escaped?J.text:K1(J.text)}},a0=class{strong({text:J}){return J}em({text:J}){return J}codespan({text:J}){return J}del({text:J}){return J}html({text:J}){return J}text({text:J}){return J}link({text:J}){return""+J}image({text:J}){return""+J}br(){return""}checkbox({raw:J}){return J}},G1=class J{options;renderer;textRenderer;constructor($){this.options=$||V1,this.options.renderer=this.options.renderer||new W0,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new a0}static parse($,Y){return new J(Y).parse($)}static parseInline($,Y){return new J(Y).parseInline($)}parse($){let Y="";for(let Z=0;Z<$.length;Z++){let Q=$[Z];if(this.options.extensions?.renderers?.[Q.type]){let X=Q,G=this.options.extensions.renderers[X.type].call({parser:this},X);if(G!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(X.type)){Y+=G||"";continue}}let q=Q;switch(q.type){case"space":{Y+=this.renderer.space(q);break}case"hr":{Y+=this.renderer.hr(q);break}case"heading":{Y+=this.renderer.heading(q);break}case"code":{Y+=this.renderer.code(q);break}case"table":{Y+=this.renderer.table(q);break}case"blockquote":{Y+=this.renderer.blockquote(q);break}case"list":{Y+=this.renderer.list(q);break}case"checkbox":{Y+=this.renderer.checkbox(q);break}case"html":{Y+=this.renderer.html(q);break}case"def":{Y+=this.renderer.def(q);break}case"paragraph":{Y+=this.renderer.paragraph(q);break}case"text":{Y+=this.renderer.text(q);break}default:{let X='Token with "'+q.type+'" type was not found.';if(this.options.silent)return console.error(X),"";throw Error(X)}}}return Y}parseInline($,Y=this.renderer){let Z="";for(let Q=0;Q<$.length;Q++){let q=$[Q];if(this.options.extensions?.renderers?.[q.type]){let G=this.options.extensions.renderers[q.type].call({parser:this},q);if(G!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(q.type)){Z+=G||"";continue}}let X=q;switch(X.type){case"escape":{Z+=Y.text(X);break}case"html":{Z+=Y.html(X);break}case"link":{Z+=Y.link(X);break}case"image":{Z+=Y.image(X);break}case"checkbox":{Z+=Y.checkbox(X);break}case"strong":{Z+=Y.strong(X);break}case"em":{Z+=Y.em(X);break}case"codespan":{Z+=Y.codespan(X);break}case"br":{Z+=Y.br(X);break}case"del":{Z+=Y.del(X);break}case"text":{Z+=Y.text(X);break}default:{let G='Token with "'+X.type+'" type was not found.';if(this.options.silent)return console.error(G),"";throw Error(G)}}}return Z}},t1=class{options;block;constructor(J){this.options=J||V1}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(J){return J}postprocess(J){return J}processAllTokens(J){return J}emStrongMask(J){return J}provideLexer(){return this.block?z1.lex:z1.lexInline}provideParser(){return this.block?G1.parse:G1.parseInline}},w3=class{defaults=f0();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=G1;Renderer=W0;TextRenderer=a0;Lexer=z1;Tokenizer=H0;Hooks=t1;constructor(...J){this.use(...J)}walkTokens(J,$){let Y=[];for(let Z of J)switch(Y=Y.concat($.call(this,Z)),Z.type){case"table":{let Q=Z;for(let q of Q.header)Y=Y.concat(this.walkTokens(q.tokens,$));for(let q of Q.rows)for(let X of q)Y=Y.concat(this.walkTokens(X.tokens,$));break}case"list":{let Q=Z;Y=Y.concat(this.walkTokens(Q.items,$));break}default:{let Q=Z;this.defaults.extensions?.childTokens?.[Q.type]?this.defaults.extensions.childTokens[Q.type].forEach((q)=>{let X=Q[q].flat(1/0);Y=Y.concat(this.walkTokens(X,$))}):Q.tokens&&(Y=Y.concat(this.walkTokens(Q.tokens,$)))}}return Y}use(...J){let $=this.defaults.extensions||{renderers:{},childTokens:{}};return J.forEach((Y)=>{let Z={...Y};if(Z.async=this.defaults.async||Z.async||!1,Y.extensions&&(Y.extensions.forEach((Q)=>{if(!Q.name)throw Error("extension name required");if("renderer"in Q){let q=$.renderers[Q.name];q?$.renderers[Q.name]=function(...X){let G=Q.renderer.apply(this,X);return G===!1&&(G=q.apply(this,X)),G}:$.renderers[Q.name]=Q.renderer}if("tokenizer"in Q){if(!Q.level||Q.level!=="block"&&Q.level!=="inline")throw Error("extension level must be 'block' or 'inline'");let q=$[Q.level];q?q.unshift(Q.tokenizer):$[Q.level]=[Q.tokenizer],Q.start&&(Q.level==="block"?$.startBlock?$.startBlock.push(Q.start):$.startBlock=[Q.start]:Q.level==="inline"&&($.startInline?$.startInline.push(Q.start):$.startInline=[Q.start]))}"childTokens"in Q&&Q.childTokens&&($.childTokens[Q.name]=Q.childTokens)}),Z.extensions=$),Y.renderer){let Q=this.defaults.renderer||new W0(this.defaults);for(let q in Y.renderer){if(!(q in Q))throw Error(`renderer '${q}' does not exist`);if(["options","parser"].includes(q))continue;let X=q,G=Y.renderer[X],_=Q[X];Q[X]=(...z)=>{let H=G.apply(Q,z);return H===!1&&(H=_.apply(Q,z)),H||""}}Z.renderer=Q}if(Y.tokenizer){let Q=this.defaults.tokenizer||new H0(this.defaults);for(let q in Y.tokenizer){if(!(q in Q))throw Error(`tokenizer '${q}' does not exist`);if(["options","rules","lexer"].includes(q))continue;let X=q,G=Y.tokenizer[X],_=Q[X];Q[X]=(...z)=>{let H=G.apply(Q,z);return H===!1&&(H=_.apply(Q,z)),H}}Z.tokenizer=Q}if(Y.hooks){let Q=this.defaults.hooks||new t1;for(let q in Y.hooks){if(!(q in Q))throw Error(`hook '${q}' does not exist`);if(["options","block"].includes(q))continue;let X=q,G=Y.hooks[X],_=Q[X];t1.passThroughHooks.has(q)?Q[X]=(z)=>{if(this.defaults.async&&t1.passThroughHooksRespectAsync.has(q))return(async()=>{let U=await G.call(Q,z);return _.call(Q,U)})();let H=G.call(Q,z);return _.call(Q,H)}:Q[X]=(...z)=>{if(this.defaults.async)return(async()=>{let U=await G.apply(Q,z);return U===!1&&(U=await _.apply(Q,z)),U})();let H=G.apply(Q,z);return H===!1&&(H=_.apply(Q,z)),H}}Z.hooks=Q}if(Y.walkTokens){let Q=this.defaults.walkTokens,q=Y.walkTokens;Z.walkTokens=function(X){let G=[];return G.push(q.call(this,X)),Q&&(G=G.concat(Q.call(this,X))),G}}this.defaults={...this.defaults,...Z}}),this}setOptions(J){return this.defaults={...this.defaults,...J},this}lexer(J,$){return z1.lex(J,$??this.defaults)}parser(J,$){return G1.parse(J,$??this.defaults)}parseMarkdown(J){return($,Y)=>{let Z={...Y},Q={...this.defaults,...Z},q=this.onError(!!Q.silent,!!Q.async);if(this.defaults.async===!0&&Z.async===!1)return q(Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof $>"u"||$===null)return q(Error("marked(): input parameter is undefined or null"));if(typeof $!="string")return q(Error("marked(): input parameter is of type "+Object.prototype.toString.call($)+", string expected"));if(Q.hooks&&(Q.hooks.options=Q,Q.hooks.block=J),Q.async)return(async()=>{let X=Q.hooks?await Q.hooks.preprocess($):$,G=await(Q.hooks?await Q.hooks.provideLexer():J?z1.lex:z1.lexInline)(X,Q),_=Q.hooks?await Q.hooks.processAllTokens(G):G;Q.walkTokens&&await Promise.all(this.walkTokens(_,Q.walkTokens));let z=await(Q.hooks?await Q.hooks.provideParser():J?G1.parse:G1.parseInline)(_,Q);return Q.hooks?await Q.hooks.postprocess(z):z})().catch(q);try{Q.hooks&&($=Q.hooks.preprocess($));let X=(Q.hooks?Q.hooks.provideLexer():J?z1.lex:z1.lexInline)($,Q);Q.hooks&&(X=Q.hooks.processAllTokens(X)),Q.walkTokens&&this.walkTokens(X,Q.walkTokens);let G=(Q.hooks?Q.hooks.provideParser():J?G1.parse:G1.parseInline)(X,Q);return Q.hooks&&(G=Q.hooks.postprocess(G)),G}catch(X){return q(X)}}}onError(J,$){return(Y)=>{if(Y.message+=`
|
|
59
|
+
Please report this to https://github.com/markedjs/marked.`,J){let Z="<p>An error occurred:</p><pre>"+K1(Y.message+"",!0)+"</pre>";return $?Promise.resolve(Z):Z}if($)return Promise.reject(Y);throw Y}}},k1=new w3;function a(J,$){return k1.parse(J,$)}a.options=a.setOptions=function(J){return k1.setOptions(J),a.defaults=k1.defaults,M5(a.defaults),a};a.getDefaults=f0;a.defaults=V1;a.use=function(...J){return k1.use(...J),a.defaults=k1.defaults,M5(a.defaults),a};a.walkTokens=function(J,$){return k1.walkTokens(J,$)};a.parseInline=k1.parseInline;a.Parser=G1;a.parser=G1.parse;a.Renderer=W0;a.TextRenderer=a0;a.Lexer=z1;a.lexer=z1.lex;a.Tokenizer=H0;a.Hooks=t1;a.parse=a;var{options:w4,setOptions:A4,use:I4,walkTokens:C4,parseInline:j4}=a;var R4=G1.parse,k4=z1.lex;import{SessionContext as m2,ActiveViewCtx as B4}from"#canvas/runtime";import{useState as $0,useCallback as H1,useEffect as A3,useRef as I3}from"react";import{AnnotationCtx as C3}from"#canvas/runtime";var q1="__agent-response__";function U1(){return`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`}function e1(J,$){J.style.height="auto",J.style.height=($?Math.max($,J.scrollHeight):J.scrollHeight)+"px"}import{useAnnotations as e}from"#canvas/runtime";import{jsxDEV as V3}from"react/jsx-dev-runtime";function o0(J,$){return`canvas:${J}:rev:${$}`}function O0(J,$){try{let Y=localStorage.getItem(o0(J,$));if(!Y)return null;return JSON.parse(Y)}catch{return null}}function j3(J,$,Y){try{localStorage.setItem(o0(J,$),JSON.stringify(Y))}catch{}}function R3(J,$){try{localStorage.removeItem(o0(J,$))}catch{}}function D5({sessionId:J,revision:$,isReadOnly:Y,children:Z}){let[Q,q]=$0(()=>{return O0(J,$)?.annotations??[]}),[X,G]=$0(()=>{return O0(J,$)?.generalNote??""}),[_,z]=$0(null),[H,U]=$0(()=>{let C=O0(J,$);return C?.responses?new Map(C.responses):new Map}),[W,N]=$0(()=>{let C=O0(J,$);return C?.feedbackEntries?new Map(C.feedbackEntries):new Map}),K=I3(null);A3(()=>{if(Y)return;if(K.current)clearTimeout(K.current);return K.current=setTimeout(()=>{j3(J,$,{annotations:Q,generalNote:X,responses:Array.from(H.entries()),feedbackEntries:Array.from(W.entries())})},300),()=>{if(K.current)clearTimeout(K.current)}},[Q,X,H,W,J,$,Y]);let T=H1((C,R,v,m,c,y,P)=>{q((x)=>[...x,{id:C,snippet:R,note:v,createdAt:new Date().toISOString(),filePath:m,context:c,...y?.length?{images:y}:{},...P?{canvasFile:P}:{}}])},[]),O=H1((C,R,v)=>{T(U1(),C,R,v)},[T]),S=H1((C,R)=>{q((v)=>v.map((m)=>m.id===C?{...m,note:R}:m))},[]),L=H1((C)=>{k3(C),q((R)=>R.filter((v)=>v.id!==C)),z((R)=>R===C?null:R)},[]),j=H1((C,R)=>{q((v)=>v.map((m)=>m.id===C?{...m,images:[...m.images||[],R]}:m))},[]),V=H1((C,R)=>{q((v)=>v.map((m)=>m.id===C?{...m,images:(m.images||[]).filter((c)=>c!==R)}:m))},[]),M=H1((C,R)=>{U((v)=>{let m=new Map(v);return m.set(C,R),m})},[]),I=H1((C,R)=>{N((v)=>{let m=v.get(C);if(m&&m.markdown===R.markdown&&m.label===R.label&&m.required===R.required)return v;let c=new Map(v);return c.set(C,R),c})},[]),D=H1((C)=>{N((R)=>{if(!R.has(C))return R;let v=new Map(R);return v.delete(C),v})},[]),E=H1(()=>{for(let C of document.querySelectorAll("[data-annotation-id]"))m5(C);q([]),G(""),z(null),U(new Map),N(new Map),R3(J,$)},[J,$]);return V3(C3.Provider,{value:{annotations:Q,addAnnotation:O,addAnnotationWithId:T,updateAnnotation:S,removeAnnotation:L,addAnnotationImage:j,removeAnnotationImage:V,generalNote:X,setGeneralNote:G,clearAll:E,activeAnnotationId:_,setActiveAnnotationId:z,responses:H,setResponse:M,feedbackEntries:W,setFeedbackEntry:I,removeFeedbackEntry:D},children:Z},void 0,!1,void 0,this)}function k3(J){let $=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Y of $)m5(Y)}function m5(J){let $=J.parentNode;if(!$)return;let Y=document.createTextNode(J.textContent||"");$.replaceChild(Y,J),$.normalize()}import J5,{useEffect as x1,useState as W1,useRef as r3,useContext as l3,useMemo as J0}from"react";import{createPortal as i3}from"react-dom";import{SessionContext as a3,CanvasFileCtx as o3}from"#canvas/runtime";function D1(J,$){let Y=g5(J,"before",60),Z=g5(J,"after",60),Q=m3(J.startContainer,$);return{before:Y,after:Z,hierarchy:Q}}function g5(J,$,Y){let Z=D3($==="before"?J.startContainer:J.endContainer);if(!Z)return"";let Q="";if($==="before"){let q=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),X;while(X=q.nextNode()){if(X===J.startContainer){Q+=(X.textContent||"").slice(0,J.startOffset);break}if(X.parentElement?.hasAttribute("data-annotation-id"))continue;Q+=X.textContent||""}if(Q.length>Y){Q=Q.slice(-Y);let G=Q.indexOf(" ");if(G>0)Q=Q.slice(G+1)}}else{let q=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),X=!1,G;while(G=q.nextNode()){if(G===J.endContainer){Q+=(G.textContent||"").slice(J.endOffset),X=!0;continue}if(X){if(G.parentElement?.hasAttribute("data-annotation-id"))continue;Q+=G.textContent||""}}if(Q.length>Y){Q=Q.slice(0,Y);let _=Q.lastIndexOf(" ");if(_>0)Q=Q.slice(0,_)}}return Q.trim()}function D3(J){let $=new Set(["DIV","P","LI","PRE","BLOCKQUOTE","SECTION","ARTICLE"]),Y=J.parentElement;while(Y){if($.has(Y.tagName))return Y;Y=Y.parentElement}return null}function m3(J,$){let Y=[],Z=J instanceof Element?J:J.parentElement;while(Z&&Z!==$){let Q=Z.getAttribute?.("data-task-id");if(Q){let q=Z.querySelector(".font-semibold");if(q)Y.unshift(q.textContent?.trim()||Q)}if(Z.tagName==="DIV"&&Z.querySelector(":scope > button .font-heading, :scope > div .font-heading")){let q=Z.querySelector(".font-heading");if(q)Y.unshift(q.textContent?.trim()||"")}Z=Z.parentElement}return Y}function s0(J){let $=J.snippet.trim(),Y=J.context,Z=$.length<30;if(Y&&Z&&(Y.before||Y.after)){let Q=[];if(Y.before)Q.push(`...${Y.before} `);if(Q.push(`**${$}**`),Y.after)Q.push(` ${Y.after}...`);return Q.join("")}return $}import{useEffect as E3,useRef as B0,useState as p1,useCallback as L0,useMemo as x5,useContext as v3}from"react";import{createPortal as x3}from"react-dom";function u5(J,$){let Q=$||document.body,q=J.getBoundingClientRect(),X=Q.getBoundingClientRect(),G=Q===document.body?window.scrollY:Q.scrollTop,_=q.bottom-X.top+G+8,z=Math.max(0,Math.min(q.left-X.left,X.width-280-12));return Q.style.position="relative",{style:{position:"absolute",top:`${_}px`,left:`${z}px`},parent:Q}}import{useState as t0,useRef as n0,useCallback as O1,useEffect as g3}from"react";import{jsxDEV as J1}from"react/jsx-dev-runtime";function E5(J){return`/api/uploads/${J.split("/").pop()}`}async function u3(J,$){let Y=new FormData;Y.append("image",$);try{return(await(await fetch(`/api/session/${J}/upload`,{method:"POST",body:Y})).json()).path||null}catch{return null}}function F0({note:J,onNoteChange:$,images:Y,onAddImage:Z,onRemoveImage:Q,sessionId:q,placeholder:X="Add your note...",autoFocus:G=!1,autoResize:_=!1,readOnly:z=!1,onKeyDown:H,onTextareaClick:U,textareaRef:W,textareaClassName:N,textareaStyle:K,minHeight:T,attachButton:O="always",openFilePickerRef:S}){let[L,j]=t0(!1),[V,M]=t0(!1),[I,D]=t0(!1),E=n0(0),C=n0(null),R=n0(null),v=O1(()=>R.current?.click(),[]);if(S)S.current=v;let m=O1((k)=>{if(C.current=k,W)W.current=k;if(k&&_)e1(k,T)},[W,_,T]);g3(()=>{if(G&&C.current){let k=C.current;if(k.focus(),k.value)k.setSelectionRange(k.value.length,k.value.length)}},[G]);let c=O1(async(k)=>{if(!k.type.startsWith("image/"))return;M(!0);try{let r=await u3(q,k);if(r)Z(r)}finally{M(!1)}},[q,Z]),y=O1((k)=>{let r=k.clipboardData.items;for(let A of r)if(A.type.startsWith("image/")){k.preventDefault();let u=A.getAsFile();if(u)c(u);return}},[c]),P=O1((k)=>{if(k.preventDefault(),E.current++,E.current===1)j(!0)},[]),x=O1((k)=>{k.preventDefault()},[]),p=O1((k)=>{if(k.preventDefault(),E.current--,E.current===0)j(!1)},[]),B=O1((k)=>{k.preventDefault(),E.current=0,j(!1);for(let r of k.dataTransfer.files)if(r.type.startsWith("image/"))c(r)},[c]),b=O1((k)=>{if($(k.target.value),_)k.target.style.height="auto",k.target.style.height=(T?Math.max(T,k.target.scrollHeight):k.target.scrollHeight)+"px"},[$,_,T]),g="w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none",o={width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",outline:"none",..._?{resize:"none",overflow:"hidden"}:{resize:"vertical"}},i=!z&&(O==="always"||O==="on-focus"&&I);return J1("div",{style:{position:"relative"},onDragEnter:z?void 0:P,onDragOver:z?void 0:x,onDragLeave:z?void 0:p,onDrop:z?void 0:B,children:[J1("textarea",{ref:m,value:J,onChange:z?void 0:b,onPaste:z?void 0:y,onKeyDown:H,onClick:U,onFocus:()=>D(!0),onBlur:()=>{setTimeout(()=>D(!1),150)},readOnly:z,placeholder:X,className:N??g,style:K??o,rows:_?1:void 0},void 0,!1,void 0,this),!z&&J1("input",{ref:R,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:(k)=>{let r=k.target.files;if(r)for(let A of r)c(A);k.target.value=""}},void 0,!1,void 0,this),(Y.length>0||i)&&J1("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px",alignItems:"center"},children:[Y.map((k)=>J1("div",{style:{position:"relative",width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:[J1("img",{src:E5(k),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this),!z&&J1("button",{onClick:(r)=>{r.stopPropagation(),Q(k)},style:{position:"absolute",top:"2px",right:"2px",width:"16px",height:"16px",borderRadius:"50%",background:"rgba(0,0,0,0.6)",color:"white",border:"none",cursor:"pointer",fontSize:"11px",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,padding:0},title:"Remove image",children:"×"},void 0,!1,void 0,this)]},k,!0,void 0,this)),i&&J1(e0,{onClick:v},void 0,!1,void 0,this)]},void 0,!0,void 0,this),V&&J1("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontFamily:"'Inter', sans-serif",marginTop:"4px"},children:"Uploading..."},void 0,!1,void 0,this),L&&J1("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",background:"var(--color-highlight-bg)",opacity:0.9,border:"2px dashed var(--color-highlight-border)",borderRadius:"6px",zIndex:10,pointerEvents:"none",fontSize:"12px",fontFamily:"'Inter', sans-serif",color:"var(--color-text-secondary)"},children:"Drop image"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function e0({onClick:J,size:$=16}){return J1("button",{onClick:(Y)=>{Y.stopPropagation(),J()},style:{width:`${$*2}px`,height:`${$*2}px`,borderRadius:"6px",border:"none",background:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--color-text-tertiary)",flexShrink:0,transition:"color 0.15s"},title:"Attach image",onMouseEnter:(Y)=>{Y.currentTarget.style.color="var(--color-text-secondary)"},onMouseLeave:(Y)=>{Y.currentTarget.style.color="var(--color-text-tertiary)"},children:J1("svg",{width:$,height:$,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[J1("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),J1("circle",{cx:"8.5",cy:"8.5",r:"1.5"},void 0,!1,void 0,this),J1("polyline",{points:"21 15 16 10 5 21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function v5({images:J}){if(!J.length)return null;return J1("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px"},children:J.map(($)=>J1("div",{style:{width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:J1("img",{src:E5($),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this)},$,!1,void 0,this))},void 0,!1,void 0,this)}import{SessionContext as f3}from"#canvas/runtime";import{jsxDEV as Y1,Fragment as p3}from"react/jsx-dev-runtime";function h3({anchorEl:J,scrollContainer:$,onClose:Y,ignoreSelector:Z,zIndex:Q="50",padding:q="12px",width:X="280px",children:G}){let _=B0(null),z=B0(Y);z.current=Y;let{style:H,parent:U}=u5(J,$);return E3(()=>{let W=setTimeout(()=>{let N=(K)=>{if(_.current&&!_.current.contains(K.target)){if(Z&&K.target.closest?.(Z))return;z.current(),document.removeEventListener("mousedown",N)}};return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},0);return()=>clearTimeout(W)},[Z]),x3(Y1("div",{ref:_,style:{...H,zIndex:Q,width:X,background:"var(--color-bg-elevated)",border:"1px solid var(--color-border-hover)",borderRadius:"8px",boxShadow:"0 4px 12px var(--color-shadow)",padding:q,fontFamily:"'Inter', sans-serif"},children:G},void 0,!1,void 0,this),U)}var h5=[{label:"Clarity",items:["Unclear","Why?","Needs example","Missing context"]},{label:"Scope",items:["Overkill","Out of scope","Important","Risky"]},{label:"Action",items:["Simplify","Rethink","Expand on this","Skip this"]}],f5=h5.flatMap((J)=>J.items);function p5({anchorEl:J,scrollContainer:$,snippet:Y,truncateAt:Z=100,header:Q,initialNote:q="",initialImages:X,onConfirm:G,onCancel:_,onDelete:z}){let H=v3(f3),U=q!==""||!!z,[W,N]=p1(q),[K,T]=p1(X||[]),[O,S]=p1(null),[L,j]=p1(U),[V,M]=p1(!1),I=B0(null),D=B0(null),E=L0(()=>{if(W.trim()||K.length>0)G(W.trim(),K);else if(U&&z)z();else _()},[W,K,G,_,U,z]),C=L0(()=>{if(U){if(!W.trim()&&K.length===0&&z){z(),_();return}G(W,K);return}_()},[W,K,U,G,_,z]),R=!U,v=W.trim().length>0?f5.filter((A)=>A.toLowerCase().startsWith(W.trim().toLowerCase())):f5,m=!R||L?[]:v.length===1&&v[0].toLowerCase()===W.trim().toLowerCase()?[]:v,c=new Set(m),y=h5.map((A)=>({label:A.label,items:A.items.filter((u)=>c.has(u))})).filter((A)=>A.items.length>0),P=y.map((A)=>A.items),x=P.flat(),p=x5(()=>{if(O===null)return 0;let A=0;for(let u=0;u<P.length;u++){if(O<A+P[u].length)return u;A+=P[u].length}return 0},[O,P]),B=x5(()=>{if(O===null)return 0;let A=0;for(let u=0;u<p;u++)A+=P[u].length;return O-A},[O,p,P]),b=(A,u)=>{let s=0;for(let _1=0;_1<A;_1++)s+=P[_1].length;return s+u},[g,o]=p1(W);if(W!==g)o(W),S(null),j(U);let i=L0((A)=>{N(A)},[]),k=Y.length>Z?Y.slice(0,Z)+"...":Y,r=L0((A)=>{if(x.length>0&&(A.key==="ArrowDown"||A.key==="ArrowUp"||A.key==="ArrowLeft"||A.key==="ArrowRight")){if(A.preventDefault(),O===null){S(0);return}if(A.key==="ArrowDown"){let u=Math.min(B+1,P[p].length-1);S(b(p,u))}else if(A.key==="ArrowUp"){let u=Math.max(B-1,0);S(b(p,u))}else if(A.key==="ArrowRight"){let u=Math.min(p+1,P.length-1),s=Math.min(B,P[u].length-1);S(b(u,s))}else if(A.key==="ArrowLeft"){let u=Math.max(p-1,0),s=Math.min(B,P[u].length-1);S(b(u,s))}return}if(O!==null&&x.length>0){if(A.key==="Tab"){A.preventDefault(),i(x[O]);return}if(A.key==="Enter"&&!A.shiftKey){A.preventDefault(),G(x[O],K);return}}if(A.key==="Enter"&&!A.shiftKey){A.preventDefault(),E();return}if(A.key==="Escape")if(x.length>0&&!L)j(!0);else if(U)C();else _()},[x,O,B,p,P,b,i,G,K,E,L,U,C,_]);return Y1(h3,{anchorEl:J,scrollContainer:$,onClose:U?C:_,ignoreSelector:U?"[data-annotation-id]":void 0,zIndex:U?"60":"50",padding:U?"10px 12px":"12px",width:"420px",children:[!U&&(Q??Y1("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontStyle:"italic",marginBottom:"8px",lineHeight:"1.4",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"},children:["“",k,"”"]},void 0,!0,void 0,this)),Y1(F0,{note:W,onNoteChange:N,images:K,onAddImage:(A)=>T((u)=>[...u,A]),onRemoveImage:(A)=>T((u)=>u.filter((s)=>s!==A)),sessionId:H,autoFocus:!0,autoResize:U,textareaRef:I,onKeyDown:r,attachButton:"none",openFilePickerRef:D,textareaStyle:U?{width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"none",outline:"none",overflow:"hidden"}:{width:"100%",minHeight:"60px",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"vertical",outline:"none"},placeholder:"Add your note..."},void 0,!1,void 0,this),Y1("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:U?"6px":"8px"},children:[Y1(e0,{onClick:()=>D.current?.(),size:14},void 0,!1,void 0,this),Y1("div",{style:{flex:1}},void 0,!1,void 0,this),U?Y1("button",{onClick:()=>{if(z)z();_()},onMouseEnter:()=>M(!0),onMouseLeave:()=>M(!1),style:{fontSize:"11px",color:V?"var(--color-accent-red)":"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"2px 0",fontFamily:"'Inter', sans-serif"},children:"Delete"},void 0,!1,void 0,this):Y1(p3,{children:[Y1("button",{onClick:_,style:{fontSize:"11px",color:"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"4px 12px",fontFamily:"'Inter', sans-serif"},children:"Cancel"},void 0,!1,void 0,this),Y1("button",{onClick:E,style:{fontSize:"11px",fontWeight:500,padding:"4px 12px",borderRadius:"6px",background:"var(--color-highlight-bg)",color:"var(--color-text-primary)",border:"1px solid var(--color-highlight-border)",cursor:"pointer",fontFamily:"'Inter', sans-serif"},children:"Add"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),x.length>0&&Y1("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:y.map((A)=>Y1("div",{style:{flex:1},children:[Y1("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--color-text-disabled)",textTransform:"uppercase",letterSpacing:"0.05em",padding:"2px 6px",marginBottom:"2px",fontFamily:"'Inter', sans-serif"},children:A.label},void 0,!1,void 0,this),A.items.map((u)=>{let s=x.indexOf(u);return Y1("div",{onMouseDown:(_1)=>{_1.preventDefault(),_1.stopPropagation(),i(u)},onMouseEnter:()=>S(s),style:{padding:"3px 6px",fontSize:"12px",borderRadius:"4px",fontFamily:"'Inter', sans-serif",color:s===O?"var(--color-text-primary)":"var(--color-text-secondary)",background:s===O?"var(--color-highlight-selected)":"transparent",cursor:"pointer"},children:[Y1("span",{style:{fontWeight:500},children:u.slice(0,W.trim().length)},void 0,!1,void 0,this),u.slice(W.trim().length)]},u,!0,void 0,this)})]},A.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function c1({anchorEl:J,scrollContainer:$,snippet:Y,truncateAt:Z,header:Q,onAdd:q,onCancel:X}){return Y1(p5,{anchorEl:J,scrollContainer:$,snippet:Y,truncateAt:Z,header:Q,onConfirm:(G,_)=>q(G,_),onCancel:X},void 0,!1,void 0,this)}function d1({anchorEl:J,scrollContainer:$,initialNote:Y,initialImages:Z,onUpdate:Q,onDelete:q,onClose:X}){return Y1(p5,{anchorEl:J,scrollContainer:$,snippet:"",initialNote:Y,initialImages:Z,onConfirm:(G,_)=>{Q(G,_),X()},onDelete:q,onCancel:X},void 0,!1,void 0,this)}import{useEffect as b0,useState as d5,useRef as u1,useCallback as r5}from"react";function g1(J,$){let Y=[],Z=c3(J);for(let Q of Z){let q=document.createRange();if(q.selectNodeContents(Q),Q===J.startContainer)q.setStart(Q,J.startOffset);if(Q===J.endContainer)q.setEnd(Q,J.endOffset);let X=q.toString();if(!X||!X.trim())continue;let G=document.createElement("mark");G.setAttribute("data-annotation-id",$);try{q.surroundContents(G)}catch{let _=q.extractContents();G.appendChild(_),q.insertNode(G)}Y.push(G)}return Y}function c3(J){let $=[],Y=J.commonAncestorContainer;if(Y.nodeType===Node.TEXT_NODE)return $.push(Y),$;let Z=document.createTreeWalker(Y,NodeFilter.SHOW_TEXT),Q;while(Q=Z.nextNode()){if(Q.parentElement?.classList.contains("select-none"))continue;if(J.intersectsNode(Q))$.push(Q)}return $}function m1(J,$){let Y=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Z of Y)Z.classList.toggle("mark-active",$)}function y0(J,$){if($!=null&&$!==J)m1($,!1);if(J!=null)m1(J,!0)}function M0(J,$){let Y=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Z of Y)Z.setAttribute("data-annotation-id",$)}function P0(J,$){let Y=$.filter((G)=>!document.querySelector(`[data-annotation-id="${G.id}"]`));if(!Y.length)return;let Z=[],Q="",q=document.createTreeWalker(J,NodeFilter.SHOW_TEXT),X;while(X=q.nextNode()){if(X.parentElement?.classList.contains("select-none"))continue;Z.push({node:X,start:Q.length}),Q+=X.textContent||""}for(let G of Y){let _=G.snippet;if(!_)continue;let z=[],H=0;while(!0){let O=Q.indexOf(_,H);if(O===-1)break;z.push(O),H=O+1}if(z.length===0)continue;let U=z[0];if(z.length>1&&G.context){let O=-1;for(let S of z){let L=0;if(G.context.before){let j=Q.slice(Math.max(0,S-80),S);if(j.includes(G.context.before))L+=2;else if(G.context.before.length>10&&j.includes(G.context.before.slice(-10)))L+=1}if(G.context.after){let j=Q.slice(S+_.length,S+_.length+80);if(j.includes(G.context.after))L+=2;else if(G.context.after.length>10&&j.includes(G.context.after.slice(0,10)))L+=1}if(L>O)O=L,U=S}}let W=U,N=U+_.length,K=c5(Z,W),T=c5(Z,N);if(!K||!T)continue;try{let O=document.createRange();O.setStart(K.node,K.offset),O.setEnd(T.node,T.offset),g1(O,G.id)}catch{}}}function c5(J,$){for(let Y=J.length-1;Y>=0;Y--)if(J[Y].start<=$){let Z=$-J[Y].start,Q=J[Y].node.textContent?.length??0;if(Z<=Q)return{node:J[Y].node,offset:Z}}return null}function S0(J){let $=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Y of $){let Z=Y.parentNode;if(!Z)continue;while(Y.firstChild)Z.insertBefore(Y.firstChild,Y);Z.removeChild(Y),Z.normalize()}}import{jsxDEV as $5,Fragment as d3}from"react/jsx-dev-runtime";function E1(J){let{containerRef:$,restoreKey:Y,restoreAnnotations:Z,extractContext:Q,filePath:q,canvasFile:X,scrollContainer:G}=J,{annotations:_,addAnnotationWithId:z,removeAnnotation:H,updateAnnotation:U,addAnnotationImage:W,removeAnnotationImage:N,activeAnnotationId:K,setActiveAnnotationId:T}=e(),[O,S]=d5(null),[L,j]=d5(null),V=u1(Q);V.current=Q;let M=u1(q);M.current=q;let I=u1(X);I.current=X;let D=u1(z);D.current=z;let E=u1(K);E.current=K;let C=u1(T);C.current=T,b0(()=>{if(!$.current)return;let y=setTimeout(()=>{if($.current)P0($.current,Z)},50);return()=>clearTimeout(y)},[Y]);let R=u1(null);b0(()=>{y0(K,R.current),R.current=K},[K]),b0(()=>{let y=$.current;if(!y)return;let P=(B)=>{let b=B.target.closest("[data-annotation-id]");if(!b)return;B.stopPropagation();let g=b.getAttribute("data-annotation-id");if(g===E.current)S({anchorEl:b,annId:g});else C.current(g)},x=(B)=>{let b=B.target.closest("[data-annotation-id]");if(b)C.current(b.getAttribute("data-annotation-id"))},p=(B)=>{let b=B.target.closest("[data-annotation-id]"),g=B.relatedTarget?.closest?.("[data-annotation-id]");if(b&&!g&&!document.getElementById("ann-inline-popover"))C.current(null)};return y.addEventListener("click",P),y.addEventListener("mouseover",x),y.addEventListener("mouseout",p),()=>{y.removeEventListener("click",P),y.removeEventListener("mouseover",x),y.removeEventListener("mouseout",p)}},[Y]),b0(()=>{let y=()=>v();return document.addEventListener("mouseup",y),()=>document.removeEventListener("mouseup",y)},[]);let v=r5(()=>{let y=window.getSelection();if(!y||y.isCollapsed||!y.toString().trim())return;if(!$.current)return;let P=y.getRangeAt(0);if(!$.current.contains(P.startContainer))return;if(P.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let x=y.toString().trim();if(x.length<2)return;let p=V.current(P),B=P.cloneRange(),b=`__pending_${Date.now()}`;try{g1(B,b)}catch{}window.getSelection()?.removeAllRanges();let g=document.querySelectorAll(`[data-annotation-id="${b}"]`),o=g[g.length-1];if(!o)return;j({anchorEl:o,tempId:b,snippet:x,ctx:p})},[]),m=r5((y,P,x,p)=>{j({anchorEl:y,tempId:P,snippet:x,ctx:p})},[]);return{popovers:$5(d3,{children:[O&&(()=>{let y=_.find((P)=>P.id===O.annId);if(!y)return null;return $5(d1,{anchorEl:O.anchorEl,scrollContainer:G,initialNote:y.note,initialImages:y.images,onUpdate:(P,x)=>{U(O.annId,P);let p=y.images||[];for(let B of x)if(!p.includes(B))W(O.annId,B);for(let B of p)if(!x.includes(B))N(O.annId,B)},onDelete:()=>{H(O.annId),T(null)},onClose:()=>S(null)},void 0,!1,void 0,this)})(),L&&$5(c1,{anchorEl:L.anchorEl,scrollContainer:G,snippet:L.snippet,truncateAt:80,onAdd:(y,P)=>{let x=U1();M0(L.tempId,x),D.current(x,L.snippet,y,M.current,L.ctx,P,I.current),j(null)},onCancel:()=>{S0(L.tempId),j(null)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),openCreatePopover:m,isPopoverOpen:!!(O||L)}}import{jsxDEV as t,Fragment as e3}from"react/jsx-dev-runtime";var Q5="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='choice-option'], [data-md='multichoice-option'], [data-md='userinput'], [data-md='rangeinput'], [data-md='image']",Y5="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='image']";function Y0({revision:J,filename:$}){let Y=l3(a3),[Z,Q]=W1(null),[q,X]=W1(null),[G,_]=W1(!0),z=r3(null),{annotations:H,addAnnotationWithId:U,removeAnnotation:W,updateAnnotation:N,addAnnotationImage:K,removeAnnotationImage:T,activeAnnotationId:O,setActiveAnnotationId:S}=e(),L=J0(()=>H.filter((B)=>!B.filePath&&(!B.canvasFile||B.canvasFile===$)),[H,$]),[j,V]=W1(null),[M,I]=W1(null),[D,E]=W1(null),[C,R]=W1(null),[v,m]=W1(!1);x1(()=>{_(!0),X(null),R(null);let B=$.replace(/\.jsx$/,".js");import(`/api/session/${Y}/canvas/${encodeURIComponent(B)}?rev=${J}&t=${Date.now()}`).then((b)=>{Q(()=>b.default),_(!1)}).catch((b)=>{X(b.message),_(!1)})},[Y,J,$]);let c=document.getElementById("plan-scroll-container"),{popovers:y,isPopoverOpen:P}=E1({containerRef:z,restoreKey:Z,restoreAnnotations:L,extractContext:(B)=>D1(B,z.current),canvasFile:$,scrollContainer:c}),x=J0(()=>{let B=new Map;for(let b of L)if(b.snippet.startsWith("["))B.set(b.snippet,b.id);return B},[L]);x1(()=>{let B=z.current;if(!B)return;let b=(o)=>{if(D||P)return;let i=o.target;if(i.closest("[data-block-comment-btn]"))return;m(!1);let k=i.closest(Q5);if(k&&B.contains(k)){let u=v1(B).indexOf(k);R(u>=0?u:null)}else R(null);let r=i.closest(Y5);if(r&&B.contains(r)){I(r);let A=r1(r),u=A?x.get(A):void 0;if(u&&u!==O)S(u)}else I(null)},g=(o)=>{if(D||P)return;if(o.relatedTarget?.closest("[data-block-comment-btn]"))return;I(null),S(null)};return B.addEventListener("mousemove",b),B.addEventListener("mouseleave",g),()=>{B.removeEventListener("mousemove",b),B.removeEventListener("mouseleave",g)}},[Z,D,P,x,O]),x1(()=>{let B=(b)=>{let g=b.target.tagName;if(g==="INPUT"||g==="TEXTAREA"||b.target.isContentEditable)return;if(D||P)return;let o=z.current;if(!o)return;if(b.key==="ArrowDown"){b.preventDefault(),m(!0);let i=v1(o);if(i.length===0)return;R((k)=>{if(k===null)return 0;return Math.min(k+1,i.length-1)})}else if(b.key==="ArrowUp"){b.preventDefault(),m(!0);let i=v1(o);if(i.length===0)return;R((k)=>{if(k===null)return i.length-1;return Math.max(k-1,0)})}else if(b.key==="a"||b.key==="A"){if(C===null||!o)return;b.preventDefault();let k=v1(o)[C];if(!k)return;let r=r1(k);if(!r)return;let A=x.get(r);if(A)S(A),E({anchorEl:k,snippet:r,annId:A});else E({anchorEl:k,snippet:r})}else if(b.key===" "||b.key==="Enter"){if(C===null)return;let k=v1(o)[C];if(!k)return;let r=k.getAttribute("data-md");if(r==="choice-option"||r==="multichoice-option")b.preventDefault(),k.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(r==="userinput"){b.preventDefault();let A=k.querySelector("textarea");if(A){A.focus();let u=(s)=>{if(s.key==="Escape")s.preventDefault(),A.blur(),m(!0)};A.addEventListener("keydown",u),A.addEventListener("blur",()=>A.removeEventListener("keydown",u),{once:!0})}}else if(r==="rangeinput"){b.preventDefault();let A=k.querySelector("input[type='range']");if(A){A.focus();let u=(s)=>{if(s.key==="Escape"||s.key==="ArrowUp"||s.key==="ArrowDown")s.preventDefault(),A.blur(),m(!0)};A.addEventListener("keydown",u),A.addEventListener("blur",()=>A.removeEventListener("keydown",u),{once:!0})}}}else if(b.key==="Escape")R(null),m(!1),S(null)};return document.addEventListener("keydown",B),()=>document.removeEventListener("keydown",B)},[C,D,P,x]),x1(()=>{let B=z.current;if(!B||C===null||!v)return;let g=v1(B)[C];if(!g)return;g.style.outline="2px solid var(--color-accent-blue)",g.style.outlineOffset="-2px",g.style.borderRadius="8px",g.scrollIntoView({block:"nearest",behavior:"smooth"});let o=r1(g),i=o?x.get(o):void 0;if(i)S(i);return()=>{g.style.outline="",g.style.outlineOffset="",g.style.borderRadius=""}},[C,v,x]);let p=J0(()=>Z?t(Z,{},void 0,!1,void 0,this):null,[Z]);if(G)return t("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading canvas..."},void 0,!1,void 0,this);if(q)return t("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[t("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Compilation Error"},void 0,!1,void 0,this),t("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!Z)return t("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return t(o3.Provider,{value:$,children:[t("div",{ref:z,className:"plan-content plan-updated",children:p},void 0,!1,void 0,this),j&&t(n3,{note:j.note,onSave:(B)=>{N(j.id,B),V(null)},onCancel:()=>V(null)},void 0,!1,void 0,this),y,t(s3,{containerRef:z,hoveredBlock:M,focusedBlockIndex:C,blockPopover:D,blockAnnotationMap:x,activeAnnotationId:O,onOpen:(B,b,g)=>{if(g)S(g),E({anchorEl:B,snippet:b,annId:g});else E({anchorEl:B,snippet:b})}},void 0,!1,void 0,this),D&&!D.annId&&t(c1,{anchorEl:D.anchorEl,scrollContainer:c,snippet:D.snippet,truncateAt:80,onAdd:(B,b)=>{let g=U1();U(g,D.snippet,B,void 0,void 0,b,$),E(null)},onCancel:()=>E(null)},void 0,!1,void 0,this),D?.annId&&(()=>{let B=L.find((b)=>b.id===D.annId);if(!B)return null;return t(d1,{anchorEl:D.anchorEl,scrollContainer:c,initialNote:B.note,initialImages:B.images,onUpdate:(b,g)=>{N(D.annId,b);let o=B.images||[];for(let i of g)if(!o.includes(i))K(D.annId,i);for(let i of o)if(!g.includes(i))T(D.annId,i)},onDelete:()=>{W(D.annId),S(null),E(null)},onClose:()=>E(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function v1(J){return Array.from(J.querySelectorAll(Q5))}function r1(J){let $=J.getAttribute("data-md");if($==="item"){let Y=J.getAttribute("data-md-label");return Y?`[Item] ${Y}`:null}if($==="section"){let Y=J.getAttribute("data-md-title");return Y?`[Section] ${Y}`:null}if($==="callout"){let Y=J.getAttribute("data-md-type")||"info",Z=J.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${Y}] ${Z}`}if($==="note")return`[Note] ${J.textContent?.trim().slice(0,60)||"Note"}`;if(J.tagName==="TR"){let Y=Array.from(J.querySelectorAll("td")).map((Z)=>Z.textContent?.trim()).filter(Boolean);return Y.length?`[Row] ${Y.join(" | ")}`:null}if($==="checklist-item"){let Y=J.getAttribute("data-md-label");return Y?`[Checklist] ${Y}`:null}if($==="choice-option"||$==="multichoice-option"){let Y=J.getAttribute("data-md-label");return Y?`[Option] ${Y}`:null}if($==="userinput"){let Y=J.getAttribute("data-md-label");return Y?`[Input] ${Y}`:null}if($==="rangeinput"){let Y=J.getAttribute("data-md-label");return Y?`[Range] ${Y}`:null}if($==="image"){let Y=J.getAttribute("data-md-src");return Y?`[Image] ${Y}`:null}return null}function s3({containerRef:J,hoveredBlock:$,focusedBlockIndex:Y,blockPopover:Z,blockAnnotationMap:Q,activeAnnotationId:q,onOpen:X}){let[G,_]=W1([]);x1(()=>{let N=J.current;if(!N||Q.size===0){_([]);return}let K=[];for(let T of N.querySelectorAll(Y5)){let O=r1(T);if(O&&Q.has(O))K.push(T)}_(K)},[Q,J.current]);let[z,H]=W1(null);x1(()=>{if(!q||!J.current){H(null);return}for(let N of J.current.querySelectorAll(Q5)){let K=r1(N);if(K&&Q.get(K)===q){H(N);return}}H(null)},[q,Q]),x1(()=>{if(!z)return;return z.style.boxShadow="inset 0 0 0 1.5px var(--color-highlight-bg)",z.style.borderRadius="8px",()=>{z.style.boxShadow="",z.style.borderRadius=""}},[z]);let U=J0(()=>{if(Y===null||!J.current)return null;let N=v1(J.current)[Y];if(!N)return null;return N.matches(Y5)?N:null},[Y,J.current]),W=J0(()=>{let N=new Set(G);if($)N.add($);if(U)N.add(U);if(Z?.anchorEl)N.add(Z.anchorEl);return Array.from(N)},[G,$,U,Z]);return t(e3,{children:W.map((N)=>t(t3,{block:N,isHovered:N===$||N===U||N===Z?.anchorEl,blockAnnotationMap:Q,activeAnnotationId:q,onOpen:X},N.getAttribute("data-task-id")||N.getAttribute("data-md-title")||N.textContent?.slice(0,30)||"block",!1,void 0,this))},void 0,!1,void 0,this)}function t3({block:J,isHovered:$,blockAnnotationMap:Y,activeAnnotationId:Z,onOpen:Q}){let q=r1(J);if(!q)return null;let X=Y.get(q),G=!!X;return i3(t("button",{"data-block-comment-btn":!0,onClick:(z)=>{z.stopPropagation(),Q(z.currentTarget,q,X)},className:`absolute top-1 right-1 z-10 w-6 h-6 flex items-center justify-center rounded transition-all duration-150 ${G?X===Z?"text-accent-amber bg-accent-amber-muted":"text-accent-amber opacity-60 hover:opacity-100":$?"text-text-disabled hover:text-text-tertiary opacity-50 hover:opacity-100":"text-text-disabled opacity-0 group-hover/section:opacity-20 hover:!opacity-80"}`,title:G?"Edit annotation":"Add annotation",children:t("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:G?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),J)}function n3({note:J,onSave:$,onCancel:Y}){let[Z,Q]=J5.useState(J),q=J5.useRef(null);return J5.useEffect(()=>{q.current?.focus(),q.current?.select()},[]),t("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center",onClick:Y,children:t("div",{className:"bg-bg-elevated border border-border-hover rounded-lg shadow-md p-4 w-80",onClick:(X)=>X.stopPropagation(),children:[t("div",{className:"text-tiny uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Edit annotation"},void 0,!1,void 0,this),t("textarea",{ref:q,value:Z,onChange:(X)=>Q(X.target.value),className:"w-full bg-transparent border-none text-body font-body text-text-primary resize-vertical focus:outline-none min-h-[60px]",onKeyDown:(X)=>{if(X.key==="Enter"&&(X.ctrlKey||X.metaKey))$(Z.trim());if(X.key==="Escape")Y()}},void 0,!1,void 0,this),t("div",{className:"flex justify-end gap-2 mt-2",children:[t("button",{onClick:Y,className:"text-meta text-text-tertiary font-body px-3 py-1",children:"Cancel"},void 0,!1,void 0,this),t("button",{onClick:()=>$(Z.trim()),className:"text-meta font-medium font-body px-3 py-1 rounded-md bg-highlight-bg text-text-primary border border-highlight-border",children:"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import U$,{useRef as t5,useEffect as _5,useCallback as n5,useState as l1,useContext as C0}from"react";function Q0(J,$,Y,Z){let Q=[],q=J.filter((U)=>U.filePath===q1),X=J.filter((U)=>!U.filePath),G=J.filter((U)=>U.filePath&&U.filePath!==q1),_=Y?Array.from(Y.values()).filter((U)=>X5(U)):[],z=Z?Array.from(Z.values()).filter((U)=>U.markdown.trim()):[];if(_.length>0||z.length>0){Q.push("## Responses"),Q.push("");for(let U of _)Q.push(Y$(U));for(let U of z)Q.push(U.markdown.trim()),Q.push("")}if(q.length>0){Q.push("## Annotations on agent response"),Q.push("");for(let U of q)Q.push(Z5(U))}if(X.length>0){Q.push("## Canvas annotations"),Q.push("");let U=new Map;for(let K of X){let T=K.canvasFile||"";if(!U.has(T))U.set(T,[]);U.get(T).push(K)}let W=[...U.keys()].sort(),N=W.length>1||W.length===1&&W[0]!=="";for(let K of W){let T=U.get(K);if(N&&K)Q.push(`### ${K.replace(/\.jsx$/,"")}`),Q.push("");let O=Q$(T);Q.push(l5(O))}}if(G.length>0){let U={};for(let W of G){let N=W.filePath;if(!U[N])U[N]=[];U[N].push(W)}Q.push("## File annotations"),Q.push("");for(let[W,N]of Object.entries(U)){Q.push(`### ${W}`),Q.push("");for(let K of N)Q.push(Z5(K))}}if($.trim())Q.push("## General notes"),Q.push(""),Q.push($.trim()),Q.push("");return Q.join(`
|
|
60
60
|
`).trim()+`
|
|
61
|
-
`}function
|
|
62
|
-
`)}function
|
|
63
|
-
`);if(Y.length<30&&X
|
|
64
|
-
`).length<=3)$.push(`> ${
|
|
61
|
+
`}function X5(J){if(J.note?.trim())return!0;if(J.value===null||J.value===void 0)return!1;if(J.type==="text"&&!J.value.trim())return!1;if(J.type==="checkbox"&&J.value.length===0)return!1;return!0}function $$(J){let $=[];for(let Y of J.values()){if(!Y.required)continue;if(Y.value===null||Y.value===void 0){$.push(Y);continue}if(Y.type==="text"&&!Y.value.trim()){$.push(Y);continue}if(Y.type==="checkbox"&&Y.value.length===0){$.push(Y);continue}}return $}function J$(J){let $=[];for(let Y of J.values())if(Y.required&&!Y.markdown.trim())$.push(Y);return $}function w0(J,$){let Y=$$(J),Z=J$($);return[...Y.map((Q)=>Q.label),...Z.map((Q)=>Q.label||Q.id)]}function Y$(J){let $=[];switch($.push(`**${J.label}**`),J.type){case"radio":case"select":$.push(`Answer: ${J.value}`);break;case"checkbox":for(let Y of J.value)$.push(`- [x] ${Y}`);break;case"text":$.push(""),$.push(J.value.trim());break;case"range":$.push(`Answer: ${J.value}`);break}if(J.note?.trim())$.push(""),$.push(`Note: ${J.note.trim()}`);return $.push(""),$.join(`
|
|
62
|
+
`)}function Z5(J){let $=[],Y=J.snippet.trim(),Z=J.context,Q=Z?.lineStart!=null;if(J.filePath&&Q){let q=Z.lineStart,X=Z.lineEnd??q,G=Y.split(`
|
|
63
|
+
`);if(Y.length<30&&q===X&&(Z.before||Z.after)){let z=s0(J);$.push(`> L${q}: ${z}`)}else if(G.length<=6)for(let z=0;z<G.length;z++)$.push(`> ${q+z} | ${G[z]}`);else{for(let z=0;z<3;z++)$.push(`> ${q+z} | ${G[z]}`);$.push(`> ... (${G.length} lines)`);for(let z=G.length-3;z<G.length;z++)$.push(`> ${q+z} | ${G[z]}`)}}else{let q=s0(J);if(Y.split(`
|
|
64
|
+
`).length<=3)$.push(`> ${q.split(`
|
|
65
65
|
`).join(`
|
|
66
|
-
> `)}`);else{let
|
|
67
|
-
`);$.push(`> ${
|
|
68
|
-
`)}function
|
|
69
|
-
`)}import{SessionContext as l5}from"#canvas/runtime";import{useEffect as x5,useState as o1,useRef as l3,useMemo as h5}from"react";import{jsxDEV as o}from"react/jsx-dev-runtime";function p5({open:J,onClose:$,onSubmit:Y}){let{annotations:Z,generalNote:Q,responses:X,feedbackEntries:q}=t(),[_,z]=o1(""),[K,G]=o1(!1),[U,H]=o1(!1),[F,W]=o1(null),L=l3(null),[T,S]=o1(!1);if(J&&!T)G(!1),H(!1),W(null);if(!J&&T)G(!1),H(!1),W(null);if(J!==T)S(J);let O=h5(()=>s1(Z,Q,X,q),[Z,Q,X,q]),j=K?_:O;if(x5(()=>{if(J&&U&&L.current)L.current.focus()},[J,U]),x5(()=>{if(!J)return;let B=(R)=>{if(R.key==="Escape")$()};return window.addEventListener("keydown",B),()=>window.removeEventListener("keydown",B)},[J,$]),!J)return null;let m=j.trim().length>0;return o("div",{className:"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm flex items-center justify-center p-8",onClick:$,children:o("div",{className:"bg-bg-surface border border-border-medium rounded-xl shadow-lg w-full max-w-2xl flex flex-col",style:{height:"80vh"},onClick:(B)=>B.stopPropagation(),children:[o("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-subtle flex-shrink-0",children:[o("div",{className:"flex items-center gap-3",children:[o("span",{className:"text-[13px] font-medium text-text-primary font-body",children:"Response preview"},void 0,!1,void 0,this),K&&o("button",{onClick:()=>{G(!1),H(!1)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body",children:"Reset"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),o("div",{className:"flex items-center gap-2",children:[o("div",{className:"flex items-center bg-bg-base rounded-md p-0.5",children:[o("button",{onClick:()=>H(!1),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${!U?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Preview"},void 0,!1,void 0,this),o("button",{onClick:()=>H(!0),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${U?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Edit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),o("button",{onClick:$,className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center rounded-md hover:bg-border-subtle transition-colors",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),U?o("textarea",{ref:L,value:j,onChange:(B)=>{z(B.target.value),G(!0)},className:"flex-1 w-full bg-bg-base p-5 text-[13px] font-mono text-text-code resize-none focus:outline-none leading-relaxed placeholder:text-text-disabled",placeholder:"Your feedback will appear here..."},void 0,!1,void 0,this):o("div",{className:"flex-1 overflow-y-auto p-5",children:o(y0,{text:j},void 0,!1,void 0,this)},void 0,!1,void 0,this),F&&o("div",{className:"px-5 py-2 text-[12px] text-accent-red font-body border-t border-border-subtle flex-shrink-0 flex items-center justify-between gap-2",children:[o("span",{children:F},void 0,!1,void 0,this),o("button",{onClick:()=>{W(null),Y(j)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),o("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border-subtle flex-shrink-0",children:[o("button",{onClick:$,className:"px-4 py-2 rounded-lg text-[13px] font-body text-text-tertiary hover:text-text-secondary transition-colors",children:"Cancel"},void 0,!1,void 0,this),o("button",{onClick:()=>{let B=T0(X,q);if(B.length>0){W(`Please answer: ${B.join(", ")}`);return}W(null),Y(j)},disabled:!m,className:`px-6 py-2 rounded-lg font-body text-[13px] font-medium transition-all ${m?"bg-btn-primary text-btn-primary-text hover:opacity-90":"bg-bg-input text-text-disabled cursor-default"}`,children:"Submit feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var i3=/!\[([^\]]*)\]\((\/tmp\/agent-canvas\/uploads\/([^)]+))\)/g;function a3(J){return J.replace(i3,($,Y,Z,Q)=>``)}function y0({text:J}){let $=h5(()=>l.parse(a3(J),{async:!1}),[J]);return o("div",{className:"prose-canvas font-body text-body text-text-primary leading-relaxed",dangerouslySetInnerHTML:{__html:$}},void 0,!1,void 0,this)}import{jsxDEV as C1}from"react/jsx-dev-runtime";var s3={ts:"#3178c6",tsx:"#3178c6",js:"#e8a32e",jsx:"#4ba0c8",html:"#e34c26",css:"#264de4",scss:"#c69",json:"#7a7568",yaml:"#cb171e",yml:"#cb171e",toml:"#9c4221",rs:"#dea584",go:"#00add8",c:"#6a6a6a",cpp:"#f34b7d",h:"#6a6a6a",py:"#3572a5",rb:"#cc342d",sh:"#5a8c3c",bash:"#5a8c3c",md:"#3573b5",txt:"#6b6560",lock:"#6b6560",gitignore:"#6b6560",svg:"#d9952e",png:"#6a9c2e",jpg:"#6a9c2e",gif:"#6a9c2e"},o3={ts:"TS",tsx:"TX",js:"JS",jsx:"JX",py:"PY",rs:"RS",go:"GO",rb:"RB",json:"{}",yaml:"YM",yml:"YM",toml:"TM",html:"<>",css:"#",scss:"#",md:"M↓",sh:"$",bash:"$",c:"C",cpp:"C+",h:"H",svg:"◇",png:"▣",jpg:"▣"};function y1({name:J,type:$,expanded:Y,className:Z=""}){if($==="dir")return C1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",className:`flex-shrink-0 ${Z}`,children:Y?C1("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill-active)",stroke:"var(--color-folder-stroke-active)"},strokeWidth:"1"},void 0,!1,void 0,this):C1("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill)",stroke:"var(--color-folder-stroke)"},strokeWidth:"1"},void 0,!1,void 0,this)},void 0,!1,void 0,this);let Q=J.includes(".")?J.split(".").pop().toLowerCase():"",X=s3[Q]||"#6b6560",q=o3[Q];return C1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",className:`flex-shrink-0 ${Z}`,children:[C1("path",{d:"M2 1.5h8l3.5 3.5v9.5a1 1 0 01-1 1H3a1 1 0 01-1-1v-12a1 1 0 011-1z",fill:X,opacity:"0.85"},void 0,!1,void 0,this),C1("path",{d:"M10 1.5v2.5a1 1 0 001 1h2.5",fill:"none",stroke:"white",strokeWidth:"0.5",opacity:"0.5"},void 0,!1,void 0,this),q&&C1("text",{x:"8",y:"11.5",textAnchor:"middle",fill:"white",fontSize:"5.5",fontFamily:"monospace",fontWeight:"600",children:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function t3(J){let $=J.getAttribute("data-md");if($==="item"){let Y=J.getAttribute("data-md-label");return Y?`[Item] ${Y}`:null}if($==="section"){let Y=J.getAttribute("data-md-title");return Y?`[Section] ${Y}`:null}if($==="callout"){let Y=J.getAttribute("data-md-type")||"info",Z=J.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${Y}] ${Z}`}if($==="note")return`[Note] ${J.textContent?.trim().slice(0,60)||"Note"}`;if(J.tagName==="TR"){let Y=Array.from(J.querySelectorAll("td")).map((Z)=>Z.textContent?.trim()).filter(Boolean);return Y.length?`[Row] ${Y.join(" | ")}`:null}if($==="checklist-item"){let Y=J.getAttribute("data-md-label");return Y?`[Checklist] ${Y}`:null}if($==="choice-option"||$==="multichoice-option"){let Y=J.getAttribute("data-md-label");return Y?`[Option] ${Y}`:null}if($==="userinput"){let Y=J.getAttribute("data-md-label");return Y?`[Input] ${Y}`:null}if($==="rangeinput"){let Y=J.getAttribute("data-md-label");return Y?`[Range] ${Y}`:null}if($==="image"){let Y=J.getAttribute("data-md-src");return Y?`[Image] ${Y}`:null}return null}function t1(J){let $=document.querySelector(`[data-annotation-id="${J.id}"]`);if($)return $;if(J.snippet.startsWith("[")){for(let Y of document.querySelectorAll("[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='image']"))if(t3(Y)===J.snippet)return Y}return null}function c5(J){J.classList.remove("ann-flash"),J.offsetWidth,J.classList.add("ann-flash"),J.addEventListener("animationend",()=>{J.classList.remove("ann-flash")},{once:!0})}function o0(J,$){if(J.filePath)$({type:"file",path:J.filePath}),setTimeout(()=>{let Y=t1(J);if(Y)Y.scrollIntoView({behavior:"smooth",block:"center"}),c5(Y)},150);else{let Y=t1(J);if(Y)Y.scrollIntoView({behavior:"smooth",block:"center"}),c5(Y)}}import{jsxDEV as b,Fragment as O0}from"react/jsx-dev-runtime";function n0({onPreview:J,onSubmit:$,collapseButton:Y}){let{isReadOnly:Z,selectedRevision:Q,currentRevision:X,revisions:q}=L0(x1),_=L0(l5),z=Z&&Q===X,G=q.find((U)=>U.revision===Q)?.label||`Round ${Q}`;if(Z)return b($$,{sessionId:_,revision:Q,label:G,waitingForUpdate:z,collapseButton:Y},void 0,!1,void 0,this);return b(Q$,{onPreview:J,onSubmit:$,collapseButton:Y},void 0,!1,void 0,this)}function e3({sessionId:J,revision:$,label:Y,waitingForUpdate:Z,collapseButton:Q}){let[X,q]=E1(null),[_,z]=E1(!0);return t0(()=>{z(!0),fetch(`/api/session/${J}/revision/${$}/feedback`).then((K)=>K.json()).then((K)=>{q(K.feedback||null),z(!1)}).catch(()=>{q(null),z(!1)})},[J,$]),b("div",{className:"flex flex-col h-full",children:[b("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[b("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:Z?"Feedback sent":`Feedback — ${Y}`},void 0,!1,void 0,this),Q]},void 0,!0,void 0,this),Z&&b("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-green-muted flex items-center gap-2 flex-shrink-0",children:[b("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),b("span",{className:"text-[12px] font-body text-accent-green",children:"Waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b("div",{className:"flex-1 overflow-y-auto px-4",children:_?b("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):X?b(y0,{text:X},void 0,!1,void 0,this):b("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"No feedback was submitted for this revision."},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function $$({sessionId:J,revision:$,label:Y,waitingForUpdate:Z,collapseButton:Q}){let{annotations:X,generalNote:q,activeAnnotationId:_,setActiveAnnotationId:z}=t(),{setActiveView:K}=L0(V1),G=X.length>0||q.trim().length>0,[U,H]=E1("feedback");if(!G)return b(e3,{sessionId:J,revision:$,label:Y,waitingForUpdate:Z,collapseButton:Q},void 0,!1,void 0,this);return b("div",{className:"flex flex-col h-full",children:[b("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[b("div",{className:"flex items-center gap-1 bg-bg-input rounded-md p-0.5",children:[b("button",{onClick:()=>H("feedback"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors ${U==="feedback"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Feedback"},void 0,!1,void 0,this),b("button",{onClick:()=>H("annotations"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors flex items-center gap-1.5 ${U==="annotations"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:["Annotations",b("span",{className:"inline-flex items-center justify-center min-w-[16px] h-[16px] px-1 rounded-full bg-border-subtle text-[10px] font-medium",children:X.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Q]},void 0,!0,void 0,this),Z&&b("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-green-muted flex items-center gap-2 flex-shrink-0",children:[b("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),b("span",{className:"text-[12px] font-body text-accent-green",children:"Waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U==="feedback"?b(J$,{sessionId:J,revision:$},void 0,!1,void 0,this):b(Y$,{annotations:X,generalNote:q,activeAnnotationId:_,setActiveAnnotationId:z,setActiveView:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function J$({sessionId:J,revision:$}){let[Y,Z]=E1(null),[Q,X]=E1(!0);return t0(()=>{X(!0),fetch(`/api/session/${J}/revision/${$}/feedback`).then((q)=>q.json()).then((q)=>{Z(q.feedback||null),X(!1)}).catch(()=>{Z(null),X(!1)})},[J,$]),b("div",{className:"flex-1 overflow-y-auto px-4",children:Q?b("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):Y?b(y0,{text:Y},void 0,!1,void 0,this):b("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"No feedback was submitted for this revision."},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Y$({annotations:J,generalNote:$,activeAnnotationId:Y,setActiveAnnotationId:Z,setActiveView:Q}){let X=J.filter((W)=>W.filePath===X1),q=J.filter((W)=>!W.filePath),_=J.filter((W)=>W.filePath&&W.filePath!==X1),z={};for(let W of _){let L=W.filePath;if(!z[L])z[L]=[];z[L].push(W)}let K=(W)=>{Z(W),w1(W,!0)},G=(W)=>{Z(null),w1(W,!1)},U=(W)=>{if(W.id===Y)Z(null);else if(Z(W.id),W.filePath)Q({type:"file",path:W.filePath}),setTimeout(()=>{let L=t1(W);if(L)L.scrollIntoView({behavior:"smooth",block:"center"})},150)},H=(W)=>b("div",{className:`group/ann relative px-3 py-2.5 transition-colors duration-150 cursor-pointer ${Y===W.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>K(W.id),onMouseLeave:()=>G(W.id),onClick:()=>U(W),children:[b("div",{className:"text-[11px] text-text-tertiary italic line-clamp-2 mb-1.5 leading-snug font-body border-l-2 border-border-medium pl-2",children:W.snippet.length>80?W.snippet.slice(0,80)+"...":W.snippet},void 0,!1,void 0,this),W.note.trim()&&b("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:W.note},void 0,!1,void 0,this),b(j5,{images:W.images||[]},void 0,!1,void 0,this),b("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100",children:b("button",{onClick:(L)=>{L.stopPropagation(),o0(W,Q)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-input transition-colors",title:"Scroll to annotation",children:b("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[b("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),b("path",{d:"M12 2v4M12 18v4M2 12h4M18 12h4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},W.id,!0,void 0,this),F=[X,q,_].filter((W)=>W.length>0).length>1;return b(O0,{children:[b("div",{className:"flex-1 overflow-y-auto",children:[X.length>0&&b(O0,{children:[F&&b("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Agent Response"},void 0,!1,void 0,this),X.map(H)]},void 0,!0,void 0,this),q.length>0&&b(O0,{children:[F&&b("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Canvas"},void 0,!1,void 0,this),q.map(H)]},void 0,!0,void 0,this),Object.entries(z).map(([W,L])=>b("div",{children:[b("button",{onClick:()=>Q({type:"file",path:W}),className:"flex items-center gap-1.5 text-[10px] uppercase tracking-widest text-text-tertiary hover:text-text-secondary font-body px-3 pt-3 pb-1 truncate transition-colors w-full text-left",title:W,children:[b(y1,{name:W.split("/").pop()||W,type:"file"},void 0,!1,void 0,this),b("span",{className:"truncate",children:W},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L.map(H)]},W,!0,void 0,this))]},void 0,!0,void 0,this),$.trim()&&b("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:b("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:$},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Q$({onPreview:J,onSubmit:$,collapseButton:Y}){let{annotations:Z,updateAnnotation:Q,removeAnnotation:X,addAnnotationImage:q,removeAnnotationImage:_,generalNote:z,setGeneralNote:K,activeAnnotationId:G,setActiveAnnotationId:U,responses:H,feedbackEntries:F}=t(),W=L0(l5),{setActiveView:L}=n3.useContext(V1),T=d5(null),S=d5(new Map),O=Z.filter((M)=>M.filePath===X1),j=Z.filter((M)=>!M.filePath),m=Z.filter((M)=>M.filePath&&M.filePath!==X1),B={};for(let M of m){let w=M.filePath;if(!B[w])B[w]=[];B[w].push(M)}t0(()=>{if(!G)return;let M=S.current.get(G);if(M)M.scrollIntoView({behavior:"smooth",block:"nearest"})},[G]);let R=r5((M)=>{U(M),w1(M,!0)},[U]),g=r5((M)=>{U(null),w1(M,!1)},[G]),u=Array.from(H.values()).some(s0),V=F.size>0,I=Z.length>0||z.trim().length>0||u||V,[f,A]=E1(null),v=(M)=>b("div",{ref:(w)=>{if(w)S.current.set(M.id,w);else S.current.delete(M.id)},className:`group/ann relative px-3 py-2.5 transition-colors duration-150 ${G===M.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>R(M.id),onMouseLeave:()=>g(M.id),onClick:()=>{if(M.id===G)U(null);else if(U(M.id),M.filePath)L({type:"file",path:M.filePath}),setTimeout(()=>{let w=t1(M);if(w)w.scrollIntoView({behavior:"smooth",block:"center"})},150)},children:[b("div",{className:"text-[11px] text-text-tertiary italic line-clamp-2 mb-1.5 leading-snug font-body border-l-2 border-border-medium pl-2",children:M.snippet.length>80?M.snippet.slice(0,80)+"...":M.snippet},void 0,!1,void 0,this),b("div",{onClick:(w)=>w.stopPropagation(),children:b(z0,{note:M.note,onNoteChange:(w)=>Q(M.id,w),images:M.images||[],onAddImage:(w)=>q(M.id,w),onRemoveImage:(w)=>_(M.id,w),sessionId:W,autoResize:!0,minHeight:20,textareaClassName:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none min-h-[20px]",textareaStyle:{height:"auto",overflow:"hidden"},placeholder:"Add your note...",attachButton:"on-focus"},void 0,!1,void 0,this)},void 0,!1,void 0,this),b("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100 flex items-center gap-0.5",children:[b("button",{onClick:(w)=>{w.stopPropagation(),o0(M,L)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-input transition-colors",title:"Scroll to annotation",children:b("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[b("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),b("path",{d:"M12 2v4M12 18v4M2 12h4M18 12h4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),b("button",{onClick:(w)=>{w.stopPropagation(),X(M.id)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-accent-red hover:bg-accent-red-muted transition-colors",title:"Delete annotation",children:b("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[b("polyline",{points:"3 6 5 6 21 6"},void 0,!1,void 0,this),b("path",{d:"M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},M.id,!0,void 0,this);return b("div",{className:"flex flex-col h-full",children:[b("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[b("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body flex items-center gap-2",children:["Annotations",Z.length>0&&b("span",{className:"inline-flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full bg-border-subtle text-[10px] font-medium text-text-secondary",children:Z.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Y]},void 0,!0,void 0,this),b("div",{ref:T,className:"flex-1 overflow-y-auto",children:[Z.length===0&&b("p",{className:"text-[12px] text-text-tertiary px-3 py-4 leading-relaxed font-body",children:"Select text in the canvas or in files to add annotations."},void 0,!1,void 0,this),O.length>0&&b(O0,{children:[(j.length>0||m.length>0)&&b("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Agent Response"},void 0,!1,void 0,this),O.map(v)]},void 0,!0,void 0,this),j.length>0&&(O.length>0||m.length>0)&&b("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Canvas"},void 0,!1,void 0,this),j.map(v),Object.entries(B).map(([M,w])=>b("div",{children:[b("button",{onClick:()=>L({type:"file",path:M}),className:"flex items-center gap-1.5 text-[10px] uppercase tracking-widest text-text-tertiary hover:text-text-secondary font-body px-3 pt-3 pb-1 truncate transition-colors w-full text-left",title:M,children:[b(y1,{name:M.split("/").pop()||M,type:"file"},void 0,!1,void 0,this),b("span",{className:"truncate",children:M},void 0,!1,void 0,this)]},void 0,!0,void 0,this),w.map(v)]},M,!0,void 0,this))]},void 0,!0,void 0,this),b("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:b("textarea",{value:z,onChange:(M)=>K(M.target.value),className:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none leading-relaxed p-0 border-none ring-0 shadow-none outline-none focus:outline-none focus:ring-0 focus:border-none placeholder:text-text-disabled min-h-[40px]",placeholder:"General notes...",onInput:(M)=>i1(M.target,40),ref:(M)=>{if(M)i1(M,40)}},void 0,!1,void 0,this)},void 0,!1,void 0,this),f&&b("div",{className:"px-4 py-2 text-[12px] text-accent-red font-body border-t border-border-subtle flex-shrink-0 flex items-center justify-between gap-2",children:[b("span",{children:f},void 0,!1,void 0,this),b("button",{onClick:()=>{A(null);let M=s1(Z,z,H,F);$(M)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b("div",{className:"px-4 py-3 border-t border-border-subtle flex-shrink-0",children:I?b("div",{className:"flex gap-2",children:[b("button",{onClick:J,className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-border-subtle text-text-secondary hover:bg-border-medium hover:text-text-primary",children:"Preview"},void 0,!1,void 0,this),b("button",{onClick:()=>{let M=T0(H,F);if(M.length>0){A(`Please answer: ${M.join(", ")}`);return}A(null);let w=s1(Z,z,H,F);$(w)},className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-btn-primary text-btn-primary-text hover:opacity-90 hover:-translate-y-px shadow-sm",children:"Submit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):b("button",{onClick:()=>$("No feedback — looks good."),className:"w-full py-2 rounded-lg font-body text-[13px] font-medium border border-border-medium text-text-secondary hover:text-text-primary hover:border-border-hover hover:bg-bg-input transition-all",children:"Submit without feedback"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as Z$,useState as i5,useContext as a5,useMemo as X$}from"react";import{SessionContext as q$}from"#canvas/runtime";import{jsxDEV as p,Fragment as e0}from"react/jsx-dev-runtime";function s5({embedded:J}={}){let $=a5(q$),{annotations:Y,addAnnotation:Z}=t(),{setActiveView:Q}=a5(V1),[X,q]=i5(!1),[_,z]=i5({}),{annCountMap:K,annotatedFiles:G}=X$(()=>{let O=new Map;for(let j of Y)if(j.filePath&&j.filePath!==X1)O.set(j.filePath,(O.get(j.filePath)||0)+1);return{annCountMap:O,annotatedFiles:[...O.keys()]}},[Y]),U=async(O)=>{let m=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(O)}`)).json();if(m.entries)z((B)=>({...B,[O]:{entries:m.entries,expanded:!0,loaded:!0}}))};Z$(()=>{if(!X&&!_[""])U("")},[X]);let H=(O)=>{if(_[O]?.loaded)z((j)=>({...j,[O]:{...j[O],expanded:!j[O].expanded}}));else U(O)},F=(O)=>{Q({type:"file",path:O})},W=async(O)=>{let m=await(await fetch(`/api/file?session=${$}&path=${encodeURIComponent(O)}`)).json();if(!m.error){let B=m.content.split(`
|
|
66
|
+
> `)}`);else{let X=Y.split(`
|
|
67
|
+
`);$.push(`> ${X[0]}`),$.push(`> ... (${X.length} lines)`),$.push(`> ${X[X.length-1]}`)}}if(J.note.trim())$.push(""),$.push(J.note.trim());if(J.images?.length){$.push("");for(let q of J.images)$.push(``)}return $.push(""),$.join(`
|
|
68
|
+
`)}function Q$(J){let $={label:"",annotations:[],children:new Map};for(let Y of J){let Z=Y.context?.hierarchy||[],Q=$;for(let q of Z){if(!Q.children.has(q))Q.children.set(q,{label:q,annotations:[],children:new Map});Q=Q.children.get(q)}Q.annotations.push(Y)}return $}function l5(J,$=0){let Y=[];for(let Z of J.annotations)Y.push(Z5(Z));for(let[,Z]of J.children){let Q=$===0?"###":"####";Y.push(`${Q} ${Z.label}`),Y.push(""),Y.push(l5(Z,$+1))}return Y.join(`
|
|
69
|
+
`)}import{SessionContext as e5}from"#canvas/runtime";import{useEffect as i5,useState as Z0,useRef as Z$,useMemo as a5}from"react";import{jsxDEV as n}from"react/jsx-dev-runtime";function o5({open:J,onClose:$,onSubmit:Y}){let{annotations:Z,generalNote:Q,responses:q,feedbackEntries:X}=e(),[G,_]=Z0(""),[z,H]=Z0(!1),[U,W]=Z0(!1),[N,K]=Z0(null),T=Z$(null),[O,S]=Z0(!1);if(J&&!O)H(!1),W(!1),K(null);if(!J&&O)H(!1),W(!1),K(null);if(J!==O)S(J);let L=a5(()=>Q0(Z,Q,q,X),[Z,Q,q,X]),j=z?G:L;if(i5(()=>{if(J&&U&&T.current)T.current.focus()},[J,U]),i5(()=>{if(!J)return;let M=(I)=>{if(I.key==="Escape")$()};return window.addEventListener("keydown",M),()=>window.removeEventListener("keydown",M)},[J,$]),!J)return null;let V=j.trim().length>0;return n("div",{className:"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm flex items-center justify-center p-8",onClick:$,children:n("div",{className:"bg-bg-surface border border-border-medium rounded-xl shadow-lg w-full max-w-2xl flex flex-col",style:{height:"80vh"},onClick:(M)=>M.stopPropagation(),children:[n("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-subtle flex-shrink-0",children:[n("div",{className:"flex items-center gap-3",children:[n("span",{className:"text-[13px] font-medium text-text-primary font-body",children:"Response preview"},void 0,!1,void 0,this),z&&n("button",{onClick:()=>{H(!1),W(!1)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body",children:"Reset"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),n("div",{className:"flex items-center gap-2",children:[n("div",{className:"flex items-center bg-bg-base rounded-md p-0.5",children:[n("button",{onClick:()=>W(!1),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${!U?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Preview"},void 0,!1,void 0,this),n("button",{onClick:()=>W(!0),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${U?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Edit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),n("button",{onClick:$,className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center rounded-md hover:bg-border-subtle transition-colors",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),U?n("textarea",{ref:T,value:j,onChange:(M)=>{_(M.target.value),H(!0)},className:"flex-1 w-full bg-bg-base p-5 text-[13px] font-mono text-text-code resize-none focus:outline-none leading-relaxed placeholder:text-text-disabled",placeholder:"Your feedback will appear here..."},void 0,!1,void 0,this):n("div",{className:"flex-1 overflow-y-auto p-5",children:n(A0,{text:j},void 0,!1,void 0,this)},void 0,!1,void 0,this),N&&n("div",{className:"px-5 py-2 text-[12px] text-accent-red font-body border-t border-border-subtle flex-shrink-0 flex items-center justify-between gap-2",children:[n("span",{children:N},void 0,!1,void 0,this),n("button",{onClick:()=>{K(null),Y(j)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),n("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border-subtle flex-shrink-0",children:[n("button",{onClick:$,className:"px-4 py-2 rounded-lg text-[13px] font-body text-text-tertiary hover:text-text-secondary transition-colors",children:"Cancel"},void 0,!1,void 0,this),n("button",{onClick:()=>{let M=w0(q,X);if(M.length>0){K(`Please answer: ${M.join(", ")}`);return}K(null),Y(j)},disabled:!V,className:`px-6 py-2 rounded-lg font-body text-[13px] font-medium transition-all ${V?"bg-btn-primary text-btn-primary-text hover:opacity-90":"bg-bg-input text-text-disabled cursor-default"}`,children:"Submit feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var X$=/!\[([^\]]*)\]\((\/tmp\/agent-canvas\/uploads\/([^)]+))\)/g;function q$(J){return J.replace(X$,($,Y,Z,Q)=>``)}function A0({text:J}){let $=a5(()=>a.parse(q$(J),{async:!1}),[J]);return n("div",{className:"prose-canvas font-body text-body text-text-primary leading-relaxed",dangerouslySetInnerHTML:{__html:$}},void 0,!1,void 0,this)}import{jsxDEV as f1}from"react/jsx-dev-runtime";var _$={ts:"#3178c6",tsx:"#3178c6",js:"#e8a32e",jsx:"#4ba0c8",html:"#e34c26",css:"#264de4",scss:"#c69",json:"#7a7568",yaml:"#cb171e",yml:"#cb171e",toml:"#9c4221",rs:"#dea584",go:"#00add8",c:"#6a6a6a",cpp:"#f34b7d",h:"#6a6a6a",py:"#3572a5",rb:"#cc342d",sh:"#5a8c3c",bash:"#5a8c3c",md:"#3573b5",txt:"#6b6560",lock:"#6b6560",gitignore:"#6b6560",svg:"#d9952e",png:"#6a9c2e",jpg:"#6a9c2e",gif:"#6a9c2e"},z$={ts:"TS",tsx:"TX",js:"JS",jsx:"JX",py:"PY",rs:"RS",go:"GO",rb:"RB",json:"{}",yaml:"YM",yml:"YM",toml:"TM",html:"<>",css:"#",scss:"#",md:"M↓",sh:"$",bash:"$",c:"C",cpp:"C+",h:"H",svg:"◇",png:"▣",jpg:"▣"};function P1({name:J,type:$,expanded:Y,className:Z=""}){if($==="dir")return f1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",className:`flex-shrink-0 ${Z}`,children:Y?f1("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill-active)",stroke:"var(--color-folder-stroke-active)"},strokeWidth:"1"},void 0,!1,void 0,this):f1("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill)",stroke:"var(--color-folder-stroke)"},strokeWidth:"1"},void 0,!1,void 0,this)},void 0,!1,void 0,this);let Q=J.includes(".")?J.split(".").pop().toLowerCase():"",q=_$[Q]||"#6b6560",X=z$[Q];return f1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",className:`flex-shrink-0 ${Z}`,children:[f1("path",{d:"M2 1.5h8l3.5 3.5v9.5a1 1 0 01-1 1H3a1 1 0 01-1-1v-12a1 1 0 011-1z",fill:q,opacity:"0.85"},void 0,!1,void 0,this),f1("path",{d:"M10 1.5v2.5a1 1 0 001 1h2.5",fill:"none",stroke:"white",strokeWidth:"0.5",opacity:"0.5"},void 0,!1,void 0,this),X&&f1("text",{x:"8",y:"11.5",textAnchor:"middle",fill:"white",fontSize:"5.5",fontFamily:"monospace",fontWeight:"600",children:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function G$(J){let $=J.getAttribute("data-md");if($==="item"){let Y=J.getAttribute("data-md-label");return Y?`[Item] ${Y}`:null}if($==="section"){let Y=J.getAttribute("data-md-title");return Y?`[Section] ${Y}`:null}if($==="callout"){let Y=J.getAttribute("data-md-type")||"info",Z=J.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${Y}] ${Z}`}if($==="note")return`[Note] ${J.textContent?.trim().slice(0,60)||"Note"}`;if(J.tagName==="TR"){let Y=Array.from(J.querySelectorAll("td")).map((Z)=>Z.textContent?.trim()).filter(Boolean);return Y.length?`[Row] ${Y.join(" | ")}`:null}if($==="checklist-item"){let Y=J.getAttribute("data-md-label");return Y?`[Checklist] ${Y}`:null}if($==="choice-option"||$==="multichoice-option"){let Y=J.getAttribute("data-md-label");return Y?`[Option] ${Y}`:null}if($==="userinput"){let Y=J.getAttribute("data-md-label");return Y?`[Input] ${Y}`:null}if($==="rangeinput"){let Y=J.getAttribute("data-md-label");return Y?`[Range] ${Y}`:null}if($==="image"){let Y=J.getAttribute("data-md-src");return Y?`[Image] ${Y}`:null}return null}function X0(J){let $=document.querySelector(`[data-annotation-id="${J.id}"]`);if($)return $;if(J.snippet.startsWith("[")){for(let Y of document.querySelectorAll("[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='image']"))if(G$(Y)===J.snippet)return Y}return null}function s5(J){J.classList.remove("ann-flash"),J.offsetWidth,J.classList.add("ann-flash"),J.addEventListener("animationend",()=>{J.classList.remove("ann-flash")},{once:!0})}function q5(J,$){if(J.filePath)$({type:"file",path:J.filePath}),setTimeout(()=>{let Y=X0(J);if(Y)Y.scrollIntoView({behavior:"smooth",block:"center"}),s5(Y)},150);else{let Y=X0(J);if(Y)Y.scrollIntoView({behavior:"smooth",block:"center"}),s5(Y)}}import{jsxDEV as w,Fragment as I0}from"react/jsx-dev-runtime";function z5({onPreview:J,onSubmit:$,collapseButton:Y}){let{isReadOnly:Z,selectedRevision:Q,currentRevision:q,revisions:X}=C0(N1),G=C0(e5),_=Z&&Q===q,H=X.find((U)=>U.revision===Q)?.label||`Round ${Q}`;if(Z)return w(H$,{sessionId:G,revision:Q,label:H,waitingForUpdate:_,collapseButton:Y},void 0,!1,void 0,this);return w(T$,{onPreview:J,onSubmit:$,collapseButton:Y},void 0,!1,void 0,this)}function K$({sessionId:J,revision:$,label:Y,waitingForUpdate:Z,collapseButton:Q}){let[q,X]=l1(null),[G,_]=l1(!0);return _5(()=>{_(!0),fetch(`/api/session/${J}/revision/${$}/feedback`).then((z)=>z.json()).then((z)=>{X(z.feedback||null),_(!1)}).catch(()=>{X(null),_(!1)})},[J,$]),w("div",{className:"flex flex-col h-full",children:[w("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[w("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:Z?"Feedback sent":`Feedback — ${Y}`},void 0,!1,void 0,this),Q]},void 0,!0,void 0,this),Z&&w("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-green-muted flex items-center gap-2 flex-shrink-0",children:[w("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),w("span",{className:"text-[12px] font-body text-accent-green",children:"Waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),w("div",{className:"flex-1 overflow-y-auto px-4",children:G?w("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):q?w(A0,{text:q},void 0,!1,void 0,this):w("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"No feedback was submitted for this revision."},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function H$({sessionId:J,revision:$,label:Y,waitingForUpdate:Z,collapseButton:Q}){let{annotations:q,generalNote:X,activeAnnotationId:G,setActiveAnnotationId:_}=e(),{setActiveView:z}=C0(F1),H=q.length>0||X.trim().length>0,[U,W]=l1("feedback");if(!H)return w(K$,{sessionId:J,revision:$,label:Y,waitingForUpdate:Z,collapseButton:Q},void 0,!1,void 0,this);return w("div",{className:"flex flex-col h-full",children:[w("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[w("div",{className:"flex items-center gap-1 bg-bg-input rounded-md p-0.5",children:[w("button",{onClick:()=>W("feedback"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors ${U==="feedback"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Feedback"},void 0,!1,void 0,this),w("button",{onClick:()=>W("annotations"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors flex items-center gap-1.5 ${U==="annotations"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:["Annotations",w("span",{className:"inline-flex items-center justify-center min-w-[16px] h-[16px] px-1 rounded-full bg-border-subtle text-[10px] font-medium",children:q.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Q]},void 0,!0,void 0,this),Z&&w("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-green-muted flex items-center gap-2 flex-shrink-0",children:[w("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),w("span",{className:"text-[12px] font-body text-accent-green",children:"Waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U==="feedback"?w(W$,{sessionId:J,revision:$},void 0,!1,void 0,this):w(N$,{annotations:q,generalNote:X,activeAnnotationId:G,setActiveAnnotationId:_,setActiveView:z},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function W$({sessionId:J,revision:$}){let[Y,Z]=l1(null),[Q,q]=l1(!0);return _5(()=>{q(!0),fetch(`/api/session/${J}/revision/${$}/feedback`).then((X)=>X.json()).then((X)=>{Z(X.feedback||null),q(!1)}).catch(()=>{Z(null),q(!1)})},[J,$]),w("div",{className:"flex-1 overflow-y-auto px-4",children:Q?w("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):Y?w(A0,{text:Y},void 0,!1,void 0,this):w("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"No feedback was submitted for this revision."},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function N$({annotations:J,generalNote:$,activeAnnotationId:Y,setActiveAnnotationId:Z,setActiveView:Q}){let q=J.filter((K)=>K.filePath===q1),X=J.filter((K)=>!K.filePath),G=J.filter((K)=>K.filePath&&K.filePath!==q1),_={};for(let K of G){let T=K.filePath;if(!_[T])_[T]=[];_[T].push(K)}let z=(K)=>{Z(K),m1(K,!0)},H=(K)=>{Z(null),m1(K,!1)},U=(K)=>{if(K.id===Y)Z(null);else if(Z(K.id),K.filePath)Q({type:"file",path:K.filePath}),setTimeout(()=>{let T=X0(K);if(T)T.scrollIntoView({behavior:"smooth",block:"center"})},150)},W=(K)=>w("div",{className:`group/ann relative px-3 py-2.5 transition-colors duration-150 cursor-pointer ${Y===K.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>z(K.id),onMouseLeave:()=>H(K.id),onClick:()=>U(K),children:[w("div",{className:"text-[11px] text-text-tertiary italic line-clamp-2 mb-1.5 leading-snug font-body border-l-2 border-border-medium pl-2",children:K.snippet.length>80?K.snippet.slice(0,80)+"...":K.snippet},void 0,!1,void 0,this),K.note.trim()&&w("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:K.note},void 0,!1,void 0,this),w(v5,{images:K.images||[]},void 0,!1,void 0,this),w("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100",children:w("button",{onClick:(T)=>{T.stopPropagation(),q5(K,Q)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-input transition-colors",title:"Scroll to annotation",children:w("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[w("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),w("path",{d:"M12 2v4M12 18v4M2 12h4M18 12h4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},K.id,!0,void 0,this),N=[q,X,G].filter((K)=>K.length>0).length>1;return w(I0,{children:[w("div",{className:"flex-1 overflow-y-auto",children:[q.length>0&&w(I0,{children:[N&&w("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Agent Response"},void 0,!1,void 0,this),q.map(W)]},void 0,!0,void 0,this),X.length>0&&w(I0,{children:[N&&w("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Canvas"},void 0,!1,void 0,this),X.map(W)]},void 0,!0,void 0,this),Object.entries(_).map(([K,T])=>w("div",{children:[w("button",{onClick:()=>Q({type:"file",path:K}),className:"flex items-center gap-1.5 text-[10px] uppercase tracking-widest text-text-tertiary hover:text-text-secondary font-body px-3 pt-3 pb-1 truncate transition-colors w-full text-left",title:K,children:[w(P1,{name:K.split("/").pop()||K,type:"file"},void 0,!1,void 0,this),w("span",{className:"truncate",children:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T.map(W)]},K,!0,void 0,this))]},void 0,!0,void 0,this),$.trim()&&w("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:w("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:$},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function T$({onPreview:J,onSubmit:$,collapseButton:Y}){let{annotations:Z,updateAnnotation:Q,removeAnnotation:q,addAnnotationImage:X,removeAnnotationImage:G,generalNote:_,setGeneralNote:z,activeAnnotationId:H,setActiveAnnotationId:U,responses:W,feedbackEntries:N}=e(),K=C0(e5),{setActiveView:T}=U$.useContext(F1),O=t5(null),S=t5(new Map),L=Z.filter((y)=>y.filePath===q1),j=Z.filter((y)=>!y.filePath),V=Z.filter((y)=>y.filePath&&y.filePath!==q1),M={};for(let y of V){let P=y.filePath;if(!M[P])M[P]=[];M[P].push(y)}_5(()=>{if(!H)return;let y=S.current.get(H);if(y)y.scrollIntoView({behavior:"smooth",block:"nearest"})},[H]);let I=n5((y)=>{U(y),m1(y,!0)},[U]),D=n5((y)=>{U(null),m1(y,!1)},[H]),E=Array.from(W.values()).some(X5),C=N.size>0,R=Z.length>0||_.trim().length>0||E||C,[v,m]=l1(null),c=(y)=>w("div",{ref:(P)=>{if(P)S.current.set(y.id,P);else S.current.delete(y.id)},className:`group/ann relative px-3 py-2.5 transition-colors duration-150 ${H===y.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>I(y.id),onMouseLeave:()=>D(y.id),onClick:()=>{if(y.id===H)U(null);else if(U(y.id),y.filePath)T({type:"file",path:y.filePath}),setTimeout(()=>{let P=X0(y);if(P)P.scrollIntoView({behavior:"smooth",block:"center"})},150)},children:[w("div",{className:"text-[11px] text-text-tertiary italic line-clamp-2 mb-1.5 leading-snug font-body border-l-2 border-border-medium pl-2",children:y.snippet.length>80?y.snippet.slice(0,80)+"...":y.snippet},void 0,!1,void 0,this),w("div",{onClick:(P)=>P.stopPropagation(),children:w(F0,{note:y.note,onNoteChange:(P)=>Q(y.id,P),images:y.images||[],onAddImage:(P)=>X(y.id,P),onRemoveImage:(P)=>G(y.id,P),sessionId:K,autoResize:!0,minHeight:20,textareaClassName:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none min-h-[20px]",textareaStyle:{height:"auto",overflow:"hidden"},placeholder:"Add your note...",attachButton:"on-focus"},void 0,!1,void 0,this)},void 0,!1,void 0,this),w("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100 flex items-center gap-0.5",children:[w("button",{onClick:(P)=>{P.stopPropagation(),q5(y,T)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-input transition-colors",title:"Scroll to annotation",children:w("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[w("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),w("path",{d:"M12 2v4M12 18v4M2 12h4M18 12h4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),w("button",{onClick:(P)=>{P.stopPropagation(),q(y.id)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-accent-red hover:bg-accent-red-muted transition-colors",title:"Delete annotation",children:w("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[w("polyline",{points:"3 6 5 6 21 6"},void 0,!1,void 0,this),w("path",{d:"M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},y.id,!0,void 0,this);return w("div",{className:"flex flex-col h-full",children:[w("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[w("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body flex items-center gap-2",children:["Annotations",Z.length>0&&w("span",{className:"inline-flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full bg-border-subtle text-[10px] font-medium text-text-secondary",children:Z.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Y]},void 0,!0,void 0,this),w("div",{ref:O,className:"flex-1 overflow-y-auto",children:[Z.length===0&&w("p",{className:"text-[12px] text-text-tertiary px-3 py-4 leading-relaxed font-body",children:"Select text in the canvas or in files to add annotations."},void 0,!1,void 0,this),L.length>0&&w(I0,{children:[(j.length>0||V.length>0)&&w("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Agent Response"},void 0,!1,void 0,this),L.map(c)]},void 0,!0,void 0,this),j.length>0&&(L.length>0||V.length>0)&&w("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Canvas"},void 0,!1,void 0,this),j.map(c),Object.entries(M).map(([y,P])=>w("div",{children:[w("button",{onClick:()=>T({type:"file",path:y}),className:"flex items-center gap-1.5 text-[10px] uppercase tracking-widest text-text-tertiary hover:text-text-secondary font-body px-3 pt-3 pb-1 truncate transition-colors w-full text-left",title:y,children:[w(P1,{name:y.split("/").pop()||y,type:"file"},void 0,!1,void 0,this),w("span",{className:"truncate",children:y},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P.map(c)]},y,!0,void 0,this))]},void 0,!0,void 0,this),w("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:w("textarea",{value:_,onChange:(y)=>z(y.target.value),className:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none leading-relaxed p-0 border-none ring-0 shadow-none outline-none focus:outline-none focus:ring-0 focus:border-none placeholder:text-text-disabled min-h-[40px]",placeholder:"General notes...",onInput:(y)=>e1(y.target,40),ref:(y)=>{if(y)e1(y,40)}},void 0,!1,void 0,this)},void 0,!1,void 0,this),v&&w("div",{className:"px-4 py-2 text-[12px] text-accent-red font-body border-t border-border-subtle flex-shrink-0 flex items-center justify-between gap-2",children:[w("span",{children:v},void 0,!1,void 0,this),w("button",{onClick:()=>{m(null);let y=Q0(Z,_,W,N);$(y)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),w("div",{className:"px-4 py-3 border-t border-border-subtle flex-shrink-0",children:R?w("div",{className:"flex gap-2",children:[w("button",{onClick:J,className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-border-subtle text-text-secondary hover:bg-border-medium hover:text-text-primary",children:"Preview"},void 0,!1,void 0,this),w("button",{onClick:()=>{let y=w0(W,N);if(y.length>0){m(`Please answer: ${y.join(", ")}`);return}m(null);let P=Q0(Z,_,W,N);$(P)},className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-btn-primary text-btn-primary-text hover:opacity-90 hover:-translate-y-px shadow-sm",children:"Submit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):w("button",{onClick:()=>$("No feedback — looks good."),className:"w-full py-2 rounded-lg font-body text-[13px] font-medium border border-border-medium text-text-secondary hover:text-text-primary hover:border-border-hover hover:bg-bg-input transition-all",children:"Submit without feedback"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as O$,useState as $2,useContext as J2,useMemo as F$}from"react";import{SessionContext as L$}from"#canvas/runtime";import{jsxDEV as d,Fragment as G5}from"react/jsx-dev-runtime";function Y2({embedded:J}={}){let $=J2(L$),{annotations:Y,addAnnotation:Z}=e(),{setActiveView:Q}=J2(F1),[q,X]=$2(!1),[G,_]=$2({}),{annCountMap:z,annotatedFiles:H}=F$(()=>{let L=new Map;for(let j of Y)if(j.filePath&&j.filePath!==q1)L.set(j.filePath,(L.get(j.filePath)||0)+1);return{annCountMap:L,annotatedFiles:[...L.keys()]}},[Y]),U=async(L)=>{let V=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(L)}`)).json();if(V.entries)_((M)=>({...M,[L]:{entries:V.entries,expanded:!0,loaded:!0}}))};O$(()=>{if(!q&&!G[""])U("")},[q]);let W=(L)=>{if(G[L]?.loaded)_((j)=>({...j,[L]:{...j[L],expanded:!j[L].expanded}}));else U(L)},N=(L)=>{Q({type:"file",path:L})},K=async(L)=>{let V=await(await fetch(`/api/file?session=${$}&path=${encodeURIComponent(L)}`)).json();if(!V.error){let M=V.content.split(`
|
|
70
70
|
`).slice(0,3).join(`
|
|
71
|
-
`)+(
|
|
71
|
+
`)+(V.content.split(`
|
|
72
72
|
`).length>3?`
|
|
73
|
-
...`:"");Z(
|
|
74
|
-
`);if(!
|
|
75
|
-
`)}catch{return null}},[
|
|
76
|
-
`);
|
|
73
|
+
...`:"");Z(M,"Include this file for context",L)}},T=async(L)=>{let j=[];if(G[L]?.loaded)j=G[L].entries;else{let M=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(L)}`)).json();if(M.entries)j=M.entries}await Promise.all(j.filter((V)=>V.type==="file").map((V)=>K(L?`${L}/${V.name}`:V.name)))},O=(L)=>z.get(L)||0,S=(L,j=0)=>{let V=G[L];if(!V?.expanded)return null;return V.entries.map((M)=>{let I=L?`${L}/${M.name}`:M.name,D=O(I);return d("div",{children:[d("div",{className:"group/item flex items-center py-[3px] hover:bg-bg-elevated text-[13px] font-body cursor-default transition-colors duration-100",style:{paddingLeft:`${16+j*16}px`,paddingRight:"8px"},children:M.type==="dir"?d(G5,{children:[d("span",{onClick:()=>W(I),className:"flex items-center gap-1.5 flex-1 text-text-secondary hover:text-text-primary cursor-pointer truncate",children:[d(P1,{name:M.name,type:"dir",expanded:G[I]?.expanded},void 0,!1,void 0,this),d("span",{className:"truncate",children:M.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),d("button",{onClick:(E)=>{E.stopPropagation(),T(I)},className:"text-[11px] text-text-tertiary hover:text-text-secondary opacity-0 group-hover/item:opacity-100 transition-opacity px-1 flex-shrink-0",title:"Add all files in folder",children:"+"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):d(G5,{children:[d("span",{onClick:()=>N(I),className:`flex-1 truncate cursor-pointer flex items-center gap-1.5 ${D>0?"text-text-primary":"text-text-secondary hover:text-text-primary"}`,children:[d(P1,{name:M.name,type:"file"},void 0,!1,void 0,this),d("span",{className:"truncate",children:M.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),d("div",{className:"flex items-center gap-1 flex-shrink-0 ml-1",children:[D>0&&d("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center",children:D},void 0,!1,void 0,this),d("button",{onClick:(E)=>{E.stopPropagation(),K(I)},className:"text-[11px] text-text-tertiary hover:text-text-secondary opacity-0 group-hover/item:opacity-100 transition-opacity px-1",title:"Add file to context",children:"+"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),M.type==="dir"&&S(I,j+1)]},I,!0,void 0,this)})};if(J)return d(G5,{children:[d("div",{className:"flex items-center justify-between px-4 pt-3 pb-2 flex-shrink-0",children:d("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Files"},void 0,!1,void 0,this)},void 0,!1,void 0,this),d("div",{className:"flex-1 overflow-y-auto",children:S("")},void 0,!1,void 0,this),H.length>0&&d("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[d("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),H.map((L)=>d("div",{onClick:()=>N(L),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[d("span",{className:"truncate",children:L.split("/").pop()},void 0,!1,void 0,this),d("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center flex-shrink-0 ml-1",children:O(L)},void 0,!1,void 0,this)]},L,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(q)return d("div",{className:"hidden lg:flex w-8 border-r border-border-subtle bg-bg-surface flex-col items-center flex-shrink-0",children:d("button",{onClick:()=>X(!1),className:"mt-3 p-1 text-text-tertiary hover:text-text-secondary transition-colors",children:d("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:d("path",{d:"M5 3l4 4-4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this);return d("div",{className:"hidden lg:flex w-60 border-r border-border-subtle bg-bg-surface flex-col flex-shrink-0 overflow-hidden",children:[d("div",{className:"flex items-center justify-between px-4 pt-4 pb-3 flex-shrink-0",children:[d("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Files"},void 0,!1,void 0,this),d("button",{onClick:()=>X(!0),className:"text-text-tertiary hover:text-text-secondary transition-colors p-0.5",children:d("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:d("path",{d:"M9 3l-4 4 4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),d("div",{className:"flex-1 overflow-y-auto",children:S("")},void 0,!1,void 0,this),H.length>0&&d("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[d("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),H.map((L)=>d("div",{onClick:()=>N(L),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[d("span",{className:"truncate",children:L.split("/").pop()},void 0,!1,void 0,this),d("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center flex-shrink-0 ml-1",children:O(L)},void 0,!1,void 0,this)]},L,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as Q2,useState as i1,useContext as B$,useCallback as y$,useRef as R0,useMemo as Z2}from"react";import{SessionContext as M$}from"#canvas/runtime";var j0={ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",py:"python",rs:"rust",go:"go",rb:"ruby",java:"java",json:"json",yaml:"yaml",yml:"yaml",md:"markdown",css:"css",html:"html",sh:"bash",bash:"bash",toml:"toml",sql:"sql",xml:"xml",c:"c",cpp:"cpp",h:"c"};import{jsxDEV as S1}from"react/jsx-dev-runtime";function X2(J){let $=J instanceof HTMLElement?J:J.parentElement;while($){if($.hasAttribute("data-line-num"))return $;$=$.parentElement}return null}function P$(J){let $=J.toString().trim(),Y=X2(J.startContainer),Z=X2(J.endContainer),Q=Y?parseInt(Y.getAttribute("data-line-num"),10):void 0,q=Z?parseInt(Z.getAttribute("data-line-num"),10):void 0,X="",G="";if($.length<30&&Y&&Y===Z){let _=Y.querySelector("code");if(_){let z=_.textContent||"",H=z.indexOf($);if(H>=0)X=z.slice(0,H).trimStart(),G=z.slice(H+$.length).trimEnd()}}return{before:X,after:G,hierarchy:[],lineStart:Q,lineEnd:q}}function q2({path:J}){let $=B$(M$),{annotations:Y,addAnnotationWithId:Z,activeAnnotationId:Q,setActiveAnnotationId:q}=e(),[X,G]=i1(null),[_,z]=i1("text"),[H,U]=i1(!0),[W,N]=i1(null),K=R0(null),[T,O]=i1(null),[S,L]=i1(null),j=R0(null),V=R0(null),M=R0([]),I=Y.filter((P)=>P.filePath===J),D=K.current?.closest("#plan-scroll-container"),{popovers:E,openCreatePopover:C}=E1({containerRef:K,restoreKey:`${X}:${J}`,restoreAnnotations:I,extractContext:P$,filePath:J,scrollContainer:D});Q2(()=>{U(!0),N(null),fetch(`/api/file?session=${$}&path=${encodeURIComponent(J)}`).then((P)=>P.json()).then((P)=>{if(P.error)N(P.error),U(!1);else G(P.content),z(P.language||"text"),U(!1)}).catch(()=>{N("Failed to fetch file"),U(!1)})},[$,J]);let R=y$((P,x)=>{P.preventDefault(),j.current=x,V.current=x,O(x),L(x)},[]);Q2(()=>{let P=(p)=>{if(j.current===null)return;let B=p.target.closest("[data-line-num]");if(B){let b=parseInt(B.getAttribute("data-line-num"),10);V.current=b,L(b)}},x=()=>{let p=j.current;if(p===null)return;j.current=null;let B=V.current??p,b=Math.min(p,B),g=Math.max(p,B),i=M.current.slice(b-1,g).join(`
|
|
74
|
+
`);if(!i.trim()){O(null),L(null);return}let k=`__pending_${Date.now()}`,r={before:"",after:"",hierarchy:[],lineStart:b,lineEnd:g};if(K.current){let A=K.current.querySelectorAll("[data-line-num]"),u=A[b-1],s=A[g-1];if(u&&s){let C1=u.querySelector("code"),j1=s.querySelector("code");if(C1&&j1)try{let v0=document.createRange();v0.setStartBefore(C1.firstChild||C1),v0.setEndAfter(j1.lastChild||j1),g1(v0,k)}catch{}}let _1=A[g-1];if(_1)C(_1,k,i,r)}O(null),L(null)};return document.addEventListener("mousemove",P),document.addEventListener("mouseup",x),()=>{document.removeEventListener("mousemove",P),document.removeEventListener("mouseup",x)}},[]);let v=Z2(()=>{if(!X)return null;let P=window.hljs;if(!P)return null;let x=J.split(".").pop()||"",p=j0[x];try{return(p?P.highlight(X,{language:p}):P.highlightAuto(X)).value.split(`
|
|
75
|
+
`)}catch{return null}},[X,J]);if(H)return S1("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-[13px]",children:["Loading ",J,"..."]},void 0,!0,void 0,this);if(W)return S1("div",{className:"p-8 text-accent-red font-body text-[13px]",children:W},void 0,!1,void 0,this);if(!X)return null;let m=X.split(`
|
|
76
|
+
`);M.current=m;let c=Z2(()=>{if(T===null)return null;let P=S??T;return{start:Math.min(T,P),end:Math.max(T,P)}},[T,S]),y=()=>{let P=X.split(`
|
|
77
77
|
`).slice(0,3).join(`
|
|
78
|
-
`)+(
|
|
79
|
-
...`:""),
|
|
78
|
+
`)+(m.length>3?`
|
|
79
|
+
...`:""),x=U1();Z(x,P,"",J),q(x)};return S1("div",{children:[S1("pre",{ref:K,className:"text-code font-mono text-text-code bg-bg-base select-text cursor-text py-3 hljs",children:m.map((P,x)=>{let p=x+1,B=c&&p>=c.start&&p<=c.end;return S1("div",{"data-line-num":p,className:`flex px-5 ${B?"bg-accent-blue/10":"hover:bg-bg-elevated-half"}`,children:[S1("span",{className:"text-text-tertiary select-none w-10 text-right pr-4 shrink-0 py-px text-[12px] cursor-pointer opacity-40 hover:opacity-100 hover:text-accent-blue",onMouseDown:(b)=>R(b,p),children:p},void 0,!1,void 0,this),v?S1("code",{className:"py-px",dangerouslySetInnerHTML:{__html:v[x]||" "}},void 0,!1,void 0,this):S1("code",{className:"py-px",children:P||" "},void 0,!1,void 0,this)]},x,!0,void 0,this)})},void 0,!1,void 0,this),E]},void 0,!0,void 0,this)}import{useEffect as _2,useState as z2,useRef as S$}from"react";import{jsxDEV as T1}from"react/jsx-dev-runtime";function G2(J,$){if($){let Y=$.replace(/\/+$/,"").split("/");return Y[Y.length-1]||J}return J.length>30?J.slice(0,30)+"...":J}function U5({currentSessionId:J,projectRoot:$}){let[Y,Z]=z2([]),[Q,q]=z2(!1),X=S$(null);_2(()=>{let z=async()=>{try{let W=await(await fetch("/api/sessions")).json();Z((N)=>{let K=JSON.stringify(W);return JSON.stringify(N)===K?N:W})}catch{}};z();let H=setInterval(z,5000);return()=>clearInterval(H)},[]),_2(()=>{if(!Q)return;let z=(H)=>{if(X.current&&!X.current.contains(H.target))q(!1)};return document.addEventListener("mousedown",z),()=>document.removeEventListener("mousedown",z)},[Q]);let G=Y.filter((z)=>z.id!==J),_=G2(J,$);return T1("div",{className:"relative",ref:X,children:[T1("div",{className:"flex items-center gap-1.5 font-body text-body font-medium",children:[T1("a",{href:`/s/${J}`,className:"text-text-primary hover:text-text-secondary transition-colors",children:_},void 0,!1,void 0,this),G.length>0&&T1("button",{onClick:()=>q(!Q),className:"flex items-center justify-center text-text-tertiary hover:text-text-secondary transition-colors",children:T1("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:`transition-transform duration-200 ${Q?"rotate-180":""}`,children:T1("path",{d:"M3 5l3 3 3-3",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q&&G.length>0&&T1("div",{className:"absolute top-full left-0 mt-2 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 overflow-hidden",children:G.map((z)=>T1("a",{href:`/s/${z.id}`,className:"flex items-center gap-2.5 px-4 py-2.5 text-body font-body text-text-secondary hover:bg-bg-surface hover:text-text-primary transition-colors",children:[T1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${z.currentRevision>0?"bg-accent-green":"bg-border-hover"}`},void 0,!1,void 0,this),T1("span",{className:"truncate",children:G2(z.id,z.projectRoot)},void 0,!1,void 0,this)]},z.id,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function U2(J){let $=[];return k0(J,$,0),$.join(`
|
|
80
80
|
`).replace(/\n{3,}/g,`
|
|
81
81
|
|
|
82
82
|
`).trim()+`
|
|
83
|
-
`}var H$=new Set(["CODE","SPAN","STRONG","EM","A","B","I","U","SMALL","SUB","SUP","MARK","ABBR"]);function P0(J,$,Y){if(W$(J)){let Z=F$(J);if(Z)$.push(Z,"");return}for(let Z of J.childNodes)if(Z.nodeType===Node.ELEMENT_NODE)N$(Z,$,Y);else if(Z.nodeType===Node.TEXT_NODE){let Q=Z.textContent?.trim();if(Q)$.push(Q,"")}}function W$(J){for(let $ of J.childNodes){if($.nodeType===Node.TEXT_NODE)continue;if($.nodeType===Node.ELEMENT_NODE){let Y=$;if(!H$.has(Y.tagName)||Y.hasAttribute("data-md"))return!1}}return J.childNodes.length>0}function F$(J){let $="";for(let Y of J.childNodes)if(Y.nodeType===Node.TEXT_NODE)$+=Y.textContent||"";else if(Y.nodeType===Node.ELEMENT_NODE){let Z=Y;if(Z.tagName==="CODE")$+="`"+(Z.textContent||"")+"`";else $+=Z.textContent||""}return $.trim()}function N$(J,$,Y){let Z=J.getAttribute("data-md");if(Z)switch(Z){case"section":return T$(J,$,Y);case"item":return y$(J,$);case"codeblock":return O$(J,$);case"callout":return L$(J,$);case"note":return M$(J,$);case"table":return B$(J,$);case"checklist":return P$(J,$);case"diff":return S$(J,$);case"mermaid":return b$(J,$);case"choice":return w$(J,$);case"multichoice":return A$(J,$);case"choice-option":case"multichoice-option":return;case"userinput":return R$(J,$);case"rangeinput":return I$(J,$);case"checklist-item":return;case"filepreview":return j$(J,$);case"priority":return C$(J,$)}if(J.querySelector("button, input, select, textarea"))return;if(J.children.length>0)P0(J,$,Y);else{let Q=J.textContent?.trim();if(Q)$.push(Q,"")}}function T$(J,$,Y){let Z=J.getAttribute("data-md-title")||"Untitled",Q=Y===0?"##":"###";$.push(`${Q} ${Z}`,"");let X=J.querySelector(":scope > div:last-of-type");if(X)P0(X,$,Y+1)}function y$(J,$){let Y=J.getAttribute("data-md-label")||"",Z=J.getAttribute("data-md-status"),Q=J.getAttribute("data-md-badge"),X="-";if(Z==="done")X="- [x]";else if(Z)X="- [ ]";let q=`${X} **${Y}**`;if(Q)q+=` \`${Q}\``;$.push(q);let _=J.querySelector(".text-text-secondary");if(_){let z=[];P0(_,z,0);for(let K of z)$.push(K?` ${K}`:"")}$.push("")}function O$(J,$){let Y=J.getAttribute("data-md-language")||"",Q=J.querySelector("code")?.textContent||"";$.push(`\`\`\`${Y}`,Q,"```","")}function L$(J,$){let Y=J.getAttribute("data-md-type")||"info",Z={info:"Info",warning:"Warning",danger:"Danger",tip:"Tip"},Q=V$(J.querySelector(".text-text-secondary")||J);$.push(`> **${Z[Y]||Y}:** ${Q}`,"")}function M$(J,$){let Y=J.textContent?.trim()||"";$.push(`> *${Y}*`,"")}function B$(J,$){let Y=J.querySelector("table");if(!Y)return;let Z=[];for(let Q of Y.querySelectorAll("thead th"))Z.push(Q.textContent?.trim()||"");if(Z.length===0)return;$.push(`| ${Z.join(" | ")} |`),$.push(`| ${Z.map(()=>"---").join(" | ")} |`);for(let Q of Y.querySelectorAll("tbody tr")){let X=[];for(let q of Q.querySelectorAll("td"))X.push(q.textContent?.trim()||"");$.push(`| ${X.join(" | ")} |`)}$.push("")}function P$(J,$){for(let Y of J.querySelectorAll("li")){let Z=Y.querySelector(".bg-accent-green")!==null,Q=Y.textContent?.trim()||"";$.push(`- [${Z?"x":" "}] ${Q}`)}$.push("")}function S$(J,$){let Y=J.getAttribute("data-md-language")||"";$.push(`\`\`\`diff${Y?` (${Y})`:""}`);for(let Z of J.querySelectorAll("[class*='flex']")){let Q=Z.querySelector(".text-accent-red")?"-":Z.querySelector(".text-accent-green")?"+":" ",X=Z.querySelector("code");if(X)$.push(`${Q} ${X.textContent}`)}$.push("```","")}function b$(J,$){let Y=J.getAttribute("data-md-source")||"";if(Y)$.push("```mermaid",Y,"```","")}function w$(J,$){let Y=J.getAttribute("data-md-label")||"";$.push(`**${Y}:**`);for(let Z of J.querySelectorAll("[data-md='choice-option']")){let Q=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",X=Z.querySelector(".bg-accent-amber")!==null;$.push(`- ${X?"(x)":"( )"} ${Q}`)}$.push("")}function A$(J,$){let Y=J.getAttribute("data-md-label")||"";$.push(`**${Y}:**`);for(let Z of J.querySelectorAll("[data-md='multichoice-option']")){let Q=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",X=Z.querySelector(".bg-accent-amber")!==null;$.push(`- [${X?"x":" "}] ${Q}`)}$.push("")}function R$(J,$){let Y=J.getAttribute("data-md-label")||"",Q=J.querySelector("textarea")?.value?.trim()||"";$.push(`**${Y}:** ${Q||"_empty_"}`,"")}function I$(J,$){let Y=J.getAttribute("data-md-label")||"",Z=J.querySelector("input[type='range']"),X=J.querySelector(".font-mono")?.textContent?.trim()||Z?.value||"—";$.push(`**${Y}:** ${X}`,"")}function j$(J,$){let Y=J.getAttribute("data-md-path")||"",Z=J.getAttribute("data-md-lines")||"",X=J.querySelector("code")?.textContent||"",q=Y.split(".").pop()||"",_=M0[q]||"",z=Z?`${Y} (L${Z})`:Y;$.push(z,"",`\`\`\`${_}`,X,"```","")}function C$(J,$){}function V$(J){return J?.textContent?.trim()||""}import y2,{useEffect as p1,useState as Z1,useRef as N1,useCallback as O2,useMemo as l$}from"react";import{useEffect as D$,useState as m$,useRef as k$,useContext as f$}from"react";import{jsxDEV as Q1,Fragment as Z2}from"react/jsx-dev-runtime";function v$(J){return J.label||`Round ${J.revision}`}function g$(J){let $=Date.now()-new Date(J).getTime(),Y=Math.floor($/1000);if(Y<60)return"just now";let Z=Math.floor(Y/60);if(Z<60)return`${Z}m ago`;let Q=Math.floor(Z/60);if(Q<24)return`${Q}h ago`;return`${Math.floor(Q/24)}d ago`}function n1({value:J,onChange:$,accent:Y="default",className:Z}){let{currentRevision:Q,revisions:X}=f$(x1),[q,_]=m$(!1),z=k$(null);D$(()=>{if(!q)return;let U=(H)=>{if(z.current&&!z.current.contains(H.target))_(!1)};return document.addEventListener("mousedown",U),()=>document.removeEventListener("mousedown",U)},[q]);let K=X.find((U)=>U.revision===J);return Q1("div",{className:"relative",ref:z,children:[Q1("button",{onClick:()=>_(!q),className:`flex items-center gap-1.5 text-[12px] font-body font-medium px-2 py-1 rounded-md transition-colors hover:bg-bg-elevated ${{default:"text-text-secondary hover:text-text-primary",red:"text-accent-red",green:"text-accent-green",amber:"text-accent-amber bg-highlight-selected"}[Y]} ${Z||""}`,children:[K?v$(K):`Round ${J}`,Q1("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${q?"rotate-180":""}`,children:Q1("path",{d:"M2.5 4l2.5 2.5L7.5 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),q&&Q1("div",{className:"absolute top-full left-0 mt-1 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 max-h-80 overflow-y-auto",children:[...X].reverse().map((U)=>Q1("button",{onClick:()=>{$(U.revision),_(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-body transition-colors ${U.revision===J?"bg-bg-surface text-text-primary":"text-text-secondary hover:bg-bg-surface hover:text-text-primary"}`,children:[Q1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${U.revision===Q?"bg-accent-green":U.hasFeedback?"bg-accent-amber":"bg-border-hover"}`},void 0,!1,void 0,this),Q1("span",{className:"flex-1 text-left truncate",children:U.label?Q1(Z2,{children:[U.label," ",Q1("span",{className:"text-text-tertiary",children:["#",U.revision]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):Q1(Z2,{children:["Round ",U.revision]},void 0,!0,void 0,this)},void 0,!1,void 0,this),Q1("span",{className:"text-[10px] text-text-tertiary flex-shrink-0 flex items-center gap-1.5",children:[U.diffStats&&Q1("span",{className:"font-mono",children:[Q1("span",{className:"text-accent-green",children:["+",U.diffStats.added]},void 0,!0,void 0,this)," ",Q1("span",{className:"text-accent-red",children:["-",U.diffStats.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),U.revision===Q?"current":U.hasFeedback?"sent":g$(U.createdAt)]},void 0,!0,void 0,this)]},U.revision,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function L1(J,$){let Y=J.length,Z=$.length;if(Y===0||Z===0)return[];let Q=Array.from({length:Y+1},()=>Array(Z+1).fill(0));for(let z=1;z<=Y;z++)for(let K=1;K<=Z;K++)Q[z][K]=J[z-1]===$[K-1]?Q[z-1][K-1]+1:Math.max(Q[z-1][K],Q[z][K-1]);let X=[],q=Y,_=Z;while(q>0&&_>0)if(J[q-1]===$[_-1])X.unshift(J[q-1]),q--,_--;else if(Q[q-1][_]>Q[q][_-1])q--;else _--;return X}function X2(J){let $=[],Y=[],Z=document.createTreeWalker(J,NodeFilter.SHOW_TEXT,{acceptNode(X){let q=X.parentElement;if(!q)return NodeFilter.FILTER_REJECT;if(q.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;return NodeFilter.FILTER_ACCEPT}}),Q;while(Q=Z.nextNode()){let q=(Q.nodeValue||"").match(/\S+|\s+/g);if(!q)continue;let _=0;for(let z of q)$.push(z),Y.push({text:z,node:Q,offset:_}),_+=z.length}return{words:$,map:Y}}function J5(J,$){if(J.length>5000||$.length>5000)return u$(J,$);return _2(J,$)}function _2(J,$){let Y=S0(J,$),Z=[],Q=[],X=0,q=0,_=0;while(X<J.length||q<$.length)if(_<Y.length&&X<J.length&&q<$.length&&J[X]===Y[_]&&$[q]===Y[_])Z.push({type:"same",index:X}),Q.push({type:"same",index:q}),X++,q++,_++;else if(X<J.length&&(_>=Y.length||J[X]!==Y[_]))Z.push({type:"removed",index:X}),X++;else if(q<$.length)Q.push({type:"added",index:q}),q++;return{oldOps:Z,newOps:Q}}function S0(J,$){let Y=J.length,Z=$.length;if(Y===0||Z===0)return[];if(Y===1)return $.includes(J[0])?[J[0]]:[];if(Z===1)return J.includes($[0])?[$[0]]:[];if(Y*Z<=1e6)return L1(J,$);let Q=Math.floor(Y/2),X=J.slice(0,Q),q=J.slice(Q),_=q2(X,$),z=q2([...q].reverse(),[...$].reverse()),K=0,G=0;for(let F=0;F<=Z;F++){let W=_[F]+z[Z-F];if(W>K)K=W,G=F}let U=$.slice(0,G),H=$.slice(G);return[...S0(X,U),...S0(q,H)]}function q2(J,$){let Y=$.length,Z=Array(Y+1).fill(0),Q=Array(Y+1).fill(0);for(let X=0;X<J.length;X++){for(let q=1;q<=Y;q++)Q[q]=J[X]===$[q-1]?Z[q-1]+1:Math.max(Z[q],Q[q-1]);[Z,Q]=[Q,Z],Q.fill(0)}return Z}function u$(J,$){let Z=(W)=>{let L=[];for(let T=0;T<W.length;T+=200){let S=Math.min(T+200,W.length);L.push({start:T,end:S,text:W.slice(T,S).join("")})}return L},Q=Z(J),X=Z($),q=Q.map((W)=>W.text),_=X.map((W)=>W.text),z=S0(q,_),K=[],G=[],U=0,H=0,F=0;while(U<Q.length||H<X.length)if(F<z.length&&U<Q.length&&H<X.length&&q[U]===z[F]&&_[H]===z[F]){for(let W=Q[U].start;W<Q[U].end;W++)K.push({type:"same",index:W});for(let W=X[H].start;W<X[H].end;W++)G.push({type:"same",index:W});U++,H++,F++}else if(U<Q.length&&(F>=z.length||q[U]!==z[F]))if(H<X.length&&(F>=z.length||_[H]!==z[F])){let W=_2(J.slice(Q[U].start,Q[U].end),$.slice(X[H].start,X[H].end));for(let L of W.oldOps)K.push({type:L.type,index:L.index+Q[U].start});for(let L of W.newOps)G.push({type:L.type,index:L.index+X[H].start});U++,H++}else{for(let W=Q[U].start;W<Q[U].end;W++)K.push({type:"removed",index:W});U++}else if(H<X.length){for(let W=X[H].start;W<X[H].end;W++)G.push({type:"added",index:W});H++}return{oldOps:K,newOps:G}}function z2(J,$,Y){let Z=new Map;for(let Q of J){if(Q.type==="same")continue;let X=$[Q.index];if(!X||!X.node.parentNode)continue;let q=Z.get(X.node);if(!q)q=[],Z.set(X.node,q);q.push({offset:X.offset,length:X.text.length})}for(let[Q,X]of Z){if(!Q.parentNode)continue;let q=Q.nodeValue||"";X.sort((U,H)=>U.offset-H.offset);let _=[];for(let U of X){let H=_[_.length-1];if(H&&U.offset<=H.offset+H.length)H.length=Math.max(H.length,U.offset+U.length-H.offset);else _.push({...U})}let z=Q.parentNode,K=document.createDocumentFragment(),G=0;for(let U of _){if(U.offset>G)K.appendChild(document.createTextNode(q.slice(G,U.offset)));let H=document.createElement("span");H.className=Y,H.textContent=q.slice(U.offset,U.offset+U.length),K.appendChild(H),G=U.offset+U.length}if(G<q.length)K.appendChild(document.createTextNode(q.slice(G)));z.replaceChild(K,Q)}}function K2(J,$){let Y=E$(J,$),Z=X2(J),Q=X2($),{oldOps:X,newOps:q}=J5(Z.words,Q.words),_=X.some((z)=>z.type==="removed")||q.some((z)=>z.type==="added");return z2(X,Z.map,"diff-removed"),z2(q,Q.map,"diff-added"),_||Y}function E$(J,$){let Y=Array.from(J.querySelectorAll('[data-md="mermaid"]')),Z=Array.from($.querySelectorAll('[data-md="mermaid"]')),Q=!1,X=Math.max(Y.length,Z.length);for(let q=0;q<X;q++){let _=Y[q],z=Z[q];if(!_&&z){z.classList.add("diff-block-added"),z.style.position="relative",Q=!0;continue}if(_&&!z){_.classList.add("diff-block-removed"),_.style.position="relative",Q=!0;continue}if(!_||!z)continue;let K=(_.getAttribute("data-md-source")||"").trim(),G=(z.getAttribute("data-md-source")||"").trim();if(K===G)continue;Q=!0,_.style.borderLeft="3px solid var(--color-accent-red)",_.style.paddingLeft="8px",z.style.borderLeft="3px solid var(--color-accent-green)",z.style.paddingLeft="8px";let U=K.split(`
|
|
84
|
-
`),H
|
|
85
|
-
`),F=L1(U,H),W=(L,T,S)=>{let O=document.createElement("div");O.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",O.setAttribute("data-no-diff","true");let j=0,m=0;while(m<L.length){let B=document.createElement("div");if(B.className="px-3 py-0.5 whitespace-pre-wrap",j<T.length&&L[m]===T[j])B.textContent=" "+L[m],m++,j++;else B.classList.add(S==="old"?"diff-removed":"diff-added"),B.textContent=(S==="old"?"- ":"+ ")+L[m],m++;O.appendChild(B)}return O};_.appendChild(W(U,F,"old")),z.appendChild(W(H,F,"new"))}return Q}function Y5(J){let $=[],Y=J.querySelectorAll(":scope > [data-md]");for(let Z of Y)$.push(e1(Z));if($.length===0){let Z=J.querySelectorAll("[data-md]"),Q=new Set;for(let X of Z){let q=X.parentElement?.closest("[data-md]");if(q&&J.contains(q))continue;if(Q.has(X))continue;Q.add(X),$.push(e1(X))}}return $}function e1(J){let $=J.getAttribute("data-md")||"unknown",Y=x$(J,$),Z=[];if($==="section"){let Q=J.querySelector(":scope > div.mt-6, :scope > div:last-child");if(Q)for(let X of Q.querySelectorAll(":scope > [data-md]"))Z.push(e1(X))}else if($==="table")for(let Q of J.querySelectorAll(":scope table > tbody > tr"))Z.push({key:"tr:"+(Q.textContent||"").slice(0,80),type:"tr",element:Q,children:[]});else if($==="checklist")for(let Q of J.querySelectorAll(":scope > [data-md='checklist-item']"))Z.push(e1(Q));else for(let Q of J.querySelectorAll("[data-md]"))if(Q.parentElement?.closest("[data-md]")===J)Z.push(e1(Q));return{key:Y,type:$,element:J,children:Z}}function x$(J,$){switch($){case"section":return"section:"+(J.getAttribute("data-md-title")||"");case"item":return"item:"+(J.getAttribute("data-task-id")||J.getAttribute("data-md-label")||"");case"codeblock":case"diff":return $+":"+(J.textContent||"").slice(0,80);case"checklist-item":return"checklist-item:"+(J.getAttribute("data-md-label")||J.textContent?.slice(0,60)||"");case"checklist":return"checklist:"+J.querySelectorAll("[data-md='checklist-item']").length;case"markdown":return"markdown:"+(J.getAttribute("data-md-file")||"inline");case"mermaid":return"mermaid:"+(J.getAttribute("data-md-source")||"").slice(0,80);case"callout":return"callout:"+(J.getAttribute("data-md-type")||"")+":"+(J.textContent||"").slice(0,60);default:return $+":"+(J.getAttribute("data-md-label")||J.textContent?.slice(0,60)||"")}}function Q5(J,$){let Y=J.map((K)=>K.key),Z=$.map((K)=>K.key),Q=L1(Y,Z),X=[],q=0,_=0,z=0;while(q<J.length||_<$.length)if(z<Q.length&&q<J.length&&_<$.length&&Y[q]===Q[z]&&Z[_]===Q[z]){let K=J[q],G=$[_],U=K.children.length>0||G.children.length>0?Q5(K.children,G.children):void 0;X.push({kind:"matched",oldBlock:K,newBlock:G,childMatches:U}),q++,_++,z++}else if(q<J.length&&(z>=Q.length||Y[q]!==Q[z]))X.push({kind:"removed",oldBlock:J[q]}),q++;else if(_<$.length)X.push({kind:"added",newBlock:$[_]}),_++;return X}function G2(J){let $=document.createDocumentFragment(),Y=!1;for(let Z of J)if(Z.kind==="removed")Y=!0,$.appendChild(H2(Z.oldBlock.element));else if(Z.kind==="added")Y=!0,$.appendChild(h$(Z.newBlock.element));else{let Q=Z.newBlock.element.cloneNode(!0),X=Z.newBlock.type;if(X==="mermaid"){if(T2(Z.oldBlock.element,Q))Y=!0}else if(Z.childMatches&&Z.childMatches.length>0&&(X==="table"||X==="checklist")){if(F2(Q,Z.childMatches,X))Y=!0}else if(Z.childMatches&&Z.childMatches.length>0){if(W2(Z.oldBlock,Q,Z.childMatches,X))Y=!0}else if(X==="markdown"){if(N2(Z.oldBlock.element,Q))Y=!0}else if(D1(Z.oldBlock.element,Q,!1))Y=!0;$.appendChild(Q)}return{fragment:$,hasChanges:Y}}function H2(J){let $=J.cloneNode(!0);return $.classList.add("diff-block-removed"),$.style.position="relative",Z5($,"Removed","var(--color-accent-red)"),$}function h$(J){let $=J.cloneNode(!0);return $.classList.add("diff-block-added"),$.style.position="relative",Z5($,"Added","var(--color-accent-green)"),$}function W2(J,$,Y,Z){let Q=!1,X=p$(J,$),q,_;if(Z==="section"){let z=J.element.querySelector(":scope > div:first-child"),K=$.querySelector(":scope > div:first-child");if(z&&K){if(D1(z,K,!1))Q=!0}q=J.element.querySelector(":scope > div.mt-6, :scope > div:last-child"),_=$.querySelector(":scope > div.mt-6, :scope > div:last-child")}else q=J.element,_=$;if(!q||!_)return Q;for(let z of Y)if(z.kind==="matched"){let K=X.newMap.get(z.newBlock.element);if(K){if(z.newBlock.type==="mermaid"){if(T2(z.oldBlock.element,K))Q=!0}else if(z.childMatches&&z.childMatches.length>0&&(z.newBlock.type==="table"||z.newBlock.type==="checklist")){if(F2(K,z.childMatches,z.newBlock.type))Q=!0}else if(z.childMatches&&z.childMatches.length>0){if(W2(z.oldBlock,K,z.childMatches,z.newBlock.type))Q=!0}else if(z.newBlock.type==="markdown"){if(N2(z.oldBlock.element,K))Q=!0}else if(D1(z.oldBlock.element,K,!1))Q=!0}}else if(z.kind==="removed"){Q=!0;let K=H2(z.oldBlock.element),G=d$(Y,z,X.newMap);_.insertBefore(K,G)}else if(z.kind==="added"){Q=!0;let K=X.newMap.get(z.newBlock.element);if(K)K.classList.add("diff-block-added"),K.style.position="relative",Z5(K,"Added","var(--color-accent-green)")}if(D1(q,_,!0))Q=!0;return Q}function F2(J,$,Y){let Z=Y==="table"?J.querySelector(":scope table > tbody"):J;if(!Z)return!1;let Q=!1;Z.innerHTML="";for(let X of $)if(X.kind==="removed"){Q=!0;let q=X.oldBlock.element.cloneNode(!0);q.classList.add(Y==="table"?"diff-row-removed":"diff-item-removed"),Z.appendChild(q)}else if(X.kind==="added"){Q=!0;let q=X.newBlock.element.cloneNode(!0);q.classList.add(Y==="table"?"diff-row-added":"diff-item-added"),Z.appendChild(q)}else{let q=X.newBlock.element.cloneNode(!0);if(D1(X.oldBlock.element,q,!1))Q=!0;Z.appendChild(q)}return Q}function p$(J,$){let Y=new Map,Z=J.element.querySelectorAll("[data-md]"),Q=$.querySelectorAll("[data-md]");return{newMap:{get(X){return c$($,X)}}}}function c$(J,$){let Y=$.getAttribute("data-md");if(!Y)return null;let Z=$.getAttribute("data-md-label"),Q=$.getAttribute("data-md-title"),X=`[data-md="${Y}"]`;if(Q)X+=`[data-md-title="${CSS.escape(Q)}"]`;else if(Z)X+=`[data-md-label="${CSS.escape(Z)}"]`;let q=J.querySelectorAll(X);if(q.length===1)return q[0];let _=($.textContent||"").slice(0,100),z=null,K=-1;for(let G of q){let U=(G.textContent||"").slice(0,100),H=0;for(let F=0;F<Math.min(_.length,U.length);F++)if(_[F]===U[F])H++;if(H>K)K=H,z=G}return z}function d$(J,$,Y){let Z=J.indexOf($);for(let Q=Z+1;Q<J.length;Q++){let X=J[Q];if((X.kind==="matched"||X.kind==="added")&&X.newBlock)return Y.get(X.newBlock.element)||null}return null}function N2(J,$){let Y=Array.from(J.children),Z=Array.from($.children);if(Y.length===0&&Z.length===0)return D1(J,$,!1);let Q=Y.map((H)=>H.tagName.toLowerCase()),X=Z.map((H)=>H.tagName.toLowerCase()),q=L1(Q,X),_=[],z=0,K=0,G=0;while(z<Y.length||K<Z.length)if(G<q.length&&z<Y.length&&K<Z.length&&Q[z]===q[G]&&X[K]===q[G])_.push({kind:"matched",oldChild:Y[z],newChild:Z[K]}),z++,K++,G++;else if(z<Y.length&&(G>=q.length||Q[z]!==q[G]))_.push({kind:"removed",oldChild:Y[z]}),z++;else if(K<Z.length)_.push({kind:"added",newChild:Z[K]}),K++;let U=!1;while($.firstChild)$.removeChild($.firstChild);for(let H of _)if(H.kind==="matched"){let F=(H.oldChild.textContent||"").match(/\S+/g)||[],W=(H.newChild.textContent||"").match(/\S+/g)||[],L=L1(F,W),T=Math.max(F.length,W.length);if((T>0?1-L.length/T:0)>0.5){U=!0;let O=H.oldChild.cloneNode(!0);O.classList.add("diff-block-removed"),$.appendChild(O),H.newChild.classList.add("diff-block-added"),$.appendChild(H.newChild)}else{if(D1(H.oldChild,H.newChild,!1))U=!0;$.appendChild(H.newChild)}}else if(H.kind==="removed"){U=!0;let F=H.oldChild.cloneNode(!0);F.classList.add("diff-block-removed"),$.appendChild(F)}else U=!0,H.newChild.classList.add("diff-block-added"),$.appendChild(H.newChild);return U}function U2(J,$){let Y=$?new Set(Array.from(J.querySelectorAll("[data-md]"))):new Set,Z=[],Q=[],X=document.createTreeWalker(J,NodeFilter.SHOW_TEXT,{acceptNode(_){let z=_.parentElement;if(!z)return NodeFilter.FILTER_REJECT;if(z.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;if($){for(let K of Y)if(K.contains(_))return NodeFilter.FILTER_REJECT}return NodeFilter.FILTER_ACCEPT}}),q;while(q=X.nextNode()){let z=(q.nodeValue||"").match(/\S+|\s+/g);if(!z)continue;let K=0;for(let G of z)Z.push(G),Q.push({text:G,node:q,offset:K}),K+=G.length}return{words:Z,map:Q}}function D1(J,$,Y){let Z=U2(J,Y),Q=U2($,Y);if(Z.words.length===0&&Q.words.length===0)return!1;let{oldOps:X,newOps:q}=J5(Z.words,Q.words),_=X.some((T)=>T.type==="removed"),z=q.some((T)=>T.type==="added");if(!_&&!z)return!1;let K=[],G=[];for(let T of X)if(T.type==="same")K.push(T.index);for(let T of q)if(T.type==="same")G.push(T.index);let U=new Map;for(let T=0;T<K.length&&T<G.length;T++)U.set(K[T],G[T]);let H=[];{let T=[],S=-1;for(let O of X)if(O.type==="same"){if(T.length>0)H.push({text:T.join(""),anchorNewIdx:S>=0?U.get(S)??null:null}),T=[];S=O.index}else if(O.type==="removed")T.push(Z.words[O.index]);if(T.length>0)H.push({text:T.join(""),anchorNewIdx:S>=0?U.get(S)??null:null})}let F=new Map,W=new Map;for(let T of q){if(T.type!=="added")continue;let S=Q.map[T.index];if(!S?.node.parentNode)continue;let O=F.get(S.node);if(!O)O=[],F.set(S.node,O);O.push({start:S.offset,end:S.offset+S.text.length})}for(let T of H)if(T.anchorNewIdx===null){if(Q.map.length>0){let S=Q.map[0].node,O=W.get(S);if(!O)O=[],W.set(S,O);O.push({offset:0,text:T.text})}}else{let S=Q.map[T.anchorNewIdx];if(!S)continue;let O=W.get(S.node);if(!O)O=[],W.set(S.node,O);O.push({offset:S.offset+S.text.length,text:T.text})}let L=new Set([...F.keys(),...W.keys()]);for(let T of L)r$(T,F.get(T)||[],W.get(T)||[]);return!0}function r$(J,$,Y){if(!J.parentNode)return;let Z=J.nodeValue||"";$.sort((G,U)=>G.start-U.start);let Q=[];for(let G of $){let U=Q[Q.length-1];if(U&&G.start<=U.end)U.end=Math.max(U.end,G.end);else Q.push({...G})}Y.sort((G,U)=>G.offset-U.offset);let X=J.parentNode,q=document.createDocumentFragment(),_=0,z=0,K=0;while(_<=Z.length){let G=z<Q.length?Q[z].start:1/0,U=K<Y.length?Y[K].offset:1/0,H=Math.min(G,U);if(H===1/0){if(_<Z.length)q.appendChild(document.createTextNode(Z.slice(_)));break}let F=Math.max(H,_);if(F>_)q.appendChild(document.createTextNode(Z.slice(_,F))),_=F;while(K<Y.length&&Y[K].offset<=_){let W=document.createElement("span");W.className="diff-removed",W.textContent=Y[K].text,q.appendChild(W),K++}if(z<Q.length&&Q[z].start<=_){let W=Q[z],L=document.createElement("span");L.className="diff-added",L.textContent=Z.slice(_,W.end),q.appendChild(L),_=W.end,z++;while(K<Y.length&&Y[K].offset<=_){let T=document.createElement("span");T.className="diff-removed",T.textContent=Y[K].text,q.appendChild(T),K++}}}while(K<Y.length){let G=document.createElement("span");G.className="diff-removed",G.textContent=Y[K].text,q.appendChild(G),K++}X.replaceChild(q,J)}function T2(J,$){let Y=(J.getAttribute("data-md-source")||"").trim(),Z=($.getAttribute("data-md-source")||"").trim();if(Y===Z)return!1;let Q=Y.split(`
|
|
86
|
-
`),
|
|
87
|
-
`),q=L1(Q,X),_=[],z=0,K=0,G=0;while(z<Q.length||K<X.length)if(G<q.length&&z<Q.length&&K<X.length&&Q[z]===q[G]&&X[K]===q[G])_.push({type:"same",line:Q[z]}),z++,K++,G++;else if(z<Q.length&&(G>=q.length||Q[z]!==q[G]))_.push({type:"removed",line:Q[z]}),z++;else if(K<X.length)_.push({type:"added",line:X[K]}),K++;let U=document.createElement("div");U.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",U.setAttribute("data-no-diff","true");for(let H of _){let F=document.createElement("div");if(F.className="px-3 py-0.5 whitespace-pre-wrap",H.type==="removed")F.classList.add("diff-removed"),F.textContent="- "+H.line;else if(H.type==="added")F.classList.add("diff-added"),F.textContent="+ "+H.line;else F.textContent=" "+H.line;U.appendChild(F)}return $.appendChild(U),!0}function Z5(J,$,Y){let Z=document.createElement("span");Z.className="diff-block-label",Z.textContent=$,Z.style.color=Y,Z.style.backgroundColor=`color-mix(in srgb, ${Y} 12%, transparent)`,J.appendChild(Z)}import{jsxDEV as x}from"react/jsx-dev-runtime";function L2({initialLeft:J,initialRight:$,sessionId:Y,onExit:Z}){let[Q,X]=Z1(J),[q,_]=Z1($),[z,K]=Z1("unified"),[G,U]=Z1(!0),[H,F]=Z1(!1);return x("div",{className:"flex flex-col h-screen",children:[x("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border-subtle bg-bg-surface flex-shrink-0",children:[x("div",{className:"flex items-center gap-3",children:[x("span",{className:"text-[13px] font-body font-medium text-text-primary",children:"Compare"},void 0,!1,void 0,this),x(n1,{value:Q,onChange:X,accent:"red"},void 0,!1,void 0,this),x("span",{className:"text-text-tertiary text-[13px]",children:"→"},void 0,!1,void 0,this),x(n1,{value:q,onChange:_,accent:"green"},void 0,!1,void 0,this),H&&!G&&x("span",{className:"text-[11px] font-body text-text-tertiary bg-bg-elevated px-2 py-0.5 rounded",children:"No changes"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),x("div",{className:"flex items-center gap-4",children:[x("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:[x("button",{onClick:()=>K("unified"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${z==="unified"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Unified"},void 0,!1,void 0,this),x("button",{onClick:()=>K("side-by-side"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${z==="side-by-side"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Side-by-side"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z==="side-by-side"&&x(i$,{},void 0,!1,void 0,this),x("button",{onClick:Z,className:"text-[12px] font-body font-medium text-text-secondary hover:text-text-primary px-3 py-1.5 rounded-md hover:bg-bg-elevated transition-colors",children:"Exit Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z==="unified"?x(a$,{sessionId:Y,leftRev:Q,rightRev:q,onDiffResult:(W,L)=>{F(W),U(L)}},`unified-${Q}-${q}`,!1,void 0,this):x(s$,{sessionId:Y,leftRev:Q,rightRev:q,onDiffResult:(W,L)=>{F(W),U(L)}},`sbs-${Q}-${q}`,!1,void 0,this)]},void 0,!0,void 0,this)}function i$(){let[J,$]=Z1(!0);return p1(()=>{return document.documentElement.dataset.syncScroll=J?"1":"0",()=>{delete document.documentElement.dataset.syncScroll}},[J]),x("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[x("input",{type:"checkbox",checked:J,onChange:(Y)=>$(Y.target.checked),className:"accent-accent-amber w-3.5 h-3.5"},void 0,!1,void 0,this),x("span",{className:"text-[11px] font-body text-text-secondary",children:"Sync scroll"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function a$({sessionId:J,leftRev:$,rightRev:Y,onDiffResult:Z}){let Q=N1(null),X=N1(null),q=N1(null),[_,z]=Z1(!1),[K,G]=Z1(!1),[U,H]=Z1(!1),{annotations:F}=t(),W=F.filter((T)=>!T.filePath),{popovers:L}=R1({containerRef:q,restoreKey:U,restoreAnnotations:W,extractContext:(T)=>b1(T,q.current)});return p1(()=>{if(!_||!K||U)return;if(!Q.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Q.current||!X.current||!q.current)return;let T=Y5(Q.current),S=Y5(X.current),O=Q5(T,S),{fragment:j,hasChanges:m}=G2(O);q.current.innerHTML="",q.current.appendChild(j),H(!0),Z(!0,m)})})},[_,K,U]),x("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[!U&&x("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[x(b0,{ref:Q,sessionId:J,revision:$,onReady:()=>z(!0)},void 0,!1,void 0,this),x(b0,{ref:X,sessionId:J,revision:Y,onReady:()=>G(!0)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),x("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:[!U&&x("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this),x("div",{ref:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L]},void 0,!0,void 0,this)}function s$({sessionId:J,leftRev:$,rightRev:Y,onDiffResult:Z}){let Q=N1(null),X=N1(null),[q,_]=Z1(!1),[z,K]=Z1(!1),[G,U]=Z1(!1),H=N1(null),F=N1(null),W=N1(null),L=N1(!1),T=O2(()=>_(!0),[]),S=O2(()=>K(!0),[]),{annotations:O}=t(),j=O.filter((B)=>!B.filePath),{popovers:m}=R1({containerRef:H,restoreKey:G,restoreAnnotations:j,extractContext:(B)=>b1(B,H.current)});return p1(()=>{if(!q||!z||G)return;if(!Q.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Q.current||!X.current)return;let B=K2(Q.current,X.current);U(!0),Z(!0,B)})})},[q,z,G]),p1(()=>{let B=F.current,R=W.current;if(!B||!R)return;let g=(I,f)=>{if(document.documentElement.dataset.syncScroll==="0")return;if(L.current)return;L.current=!0;let A=I.scrollHeight-I.clientHeight,v=f.scrollHeight-f.clientHeight;if(A>0&&v>0)f.scrollTop=I.scrollTop/A*v;requestAnimationFrame(()=>{L.current=!1})},u=()=>g(B,R),V=()=>g(R,B);return B.addEventListener("scroll",u),R.addEventListener("scroll",V),()=>{B.removeEventListener("scroll",u),R.removeEventListener("scroll",V)}},[]),x("div",{ref:H,className:"flex flex-1 min-h-0",children:[x("div",{ref:F,className:"w-1/2 overflow-y-auto border-r border-border-subtle",children:x("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:x(b0,{ref:Q,sessionId:J,revision:$,onReady:T},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),x("div",{ref:W,className:"w-1/2 overflow-y-auto",children:x("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:x(b0,{ref:X,sessionId:J,revision:Y,onReady:S},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),m]},void 0,!0,void 0,this)}var b0=y2.memo(y2.forwardRef(({sessionId:J,revision:$,onReady:Y},Z)=>{let[Q,X]=Z1(null),[q,_]=Z1(null),[z,K]=Z1(!0);p1(()=>{K(!0),_(null),import(`/api/session/${J}/plan.js?rev=${$}&t=${Date.now()}`).then((U)=>{X(()=>U.default),K(!1)}).catch((U)=>{_(U.message),K(!1)})},[J,$]),p1(()=>{if(!Q)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{Y()})})},[Q]);let G=l$(()=>Q?x(Q,{},void 0,!1,void 0,this):null,[Q]);if(z)return x("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this);if(q)return x("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[x("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Error"},void 0,!1,void 0,this),x("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!Q)return x("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return x("div",{ref:Z,children:G},void 0,!1,void 0,this)}));import{jsxDEV as N,Fragment as X5}from"react/jsx-dev-runtime";var V1=S2({activeView:{type:"plan"},setActiveView:()=>{},openFiles:[],closeFile:()=>{}}),x1=S2({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{}});function e$(J){if(J==="auto")return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";return J}function B2(J){document.documentElement.dataset.theme=e$(J)}function w2(){let[J,$]=$1(()=>{let Q=localStorage.getItem("canvas-theme");if(Q==="light"||Q==="dark"||Q==="auto")return Q;return"auto"});return T1(()=>{if(B2(J),J!=="auto")return;let Q=window.matchMedia("(prefers-color-scheme: dark)"),X=()=>B2("auto");return Q.addEventListener("change",X),()=>Q.removeEventListener("change",X)},[J]),N("button",{onClick:()=>{let Q=J==="auto"?"light":J==="light"?"dark":"auto";localStorage.setItem("canvas-theme",Q),$(Q)},className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:{auto:"Theme: system (click for light)",light:"Theme: light (click for dark)",dark:"Theme: dark (click for system)"}[J],children:J==="auto"?N("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[N("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"},void 0,!1,void 0,this),N("line",{x1:"8",y1:"21",x2:"16",y2:"21"},void 0,!1,void 0,this),N("line",{x1:"12",y1:"17",x2:"12",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):J==="dark"?N("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:N("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"},void 0,!1,void 0,this)},void 0,!1,void 0,this):N("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[N("circle",{cx:"12",cy:"12",r:"5"},void 0,!1,void 0,this),N("line",{x1:"12",y1:"1",x2:"12",y2:"3"},void 0,!1,void 0,this),N("line",{x1:"12",y1:"21",x2:"12",y2:"23"},void 0,!1,void 0,this),N("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"},void 0,!1,void 0,this),N("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"},void 0,!1,void 0,this),N("line",{x1:"1",y1:"12",x2:"3",y2:"12"},void 0,!1,void 0,this),N("line",{x1:"21",y1:"12",x2:"23",y2:"12"},void 0,!1,void 0,this),N("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"},void 0,!1,void 0,this),N("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function A2(){let{currentRevision:J,selectedRevision:$,revisions:Y,setSelectedRevision:Z,setCompareRevision:Q}=m1.useContext(x1);if(Y.length<=1){let _=Y[0]?.label||`Round ${J}`;return N("span",{className:"text-[11px] text-text-tertiary font-body",children:_},void 0,!1,void 0,this)}return N("div",{className:"flex flex-col gap-1",children:[N(n1,{value:$,onChange:Z,accent:$===J?"default":"amber"},void 0,!1,void 0,this),N("button",{onClick:()=>{let _=Y.find((K)=>K.revision===$)?.sourceFile,z;if($===J)z=[...Y].reverse().find((G)=>G.revision<J&&(!_||G.sourceFile===_))?.revision??Math.max(1,J-1);else z=$;Q({left:z,right:J})},className:"text-[11px] font-body font-medium px-2 py-0.5 rounded-md text-accent-blue hover:bg-accent-blue-muted transition-colors self-start",children:"Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function $4(){let J=window.location.pathname.replace("/s/","")||"",[$,Y]=$1(1),[Z,Q]=$1(1),[X,q]=$1([]),[_,z]=$1(null),[K,G]=$1(!1),[U,H]=$1(!1),[F,W]=$1({type:"plan"}),[L,T]=$1([]),S=M1(null),[O,j]=$1(),[m,B]=$1(!1),[R,g]=$1(!1),[u,V]=$1(!1);T1(()=>{let y=["Agent Canvas"];if(O){let P=O.replace(/\/+$/,"").split("/");y.push(P[P.length-1]||J)}else if(J)y.push(J);if(F.type==="file")y.push(F.path.split("/").pop()||F.path);else if(_)y.push("Compare");document.title=y.join(" — ")},[J,O,F,_]);let I=M1(new Map),f=X.find((y)=>y.revision===Z),A=Z!==$||!!f?.hasFeedback,v=w0((y)=>{if(I.current.set(F.type==="plan"?"plan":`file:${F.path}`,window.scrollY),W(y),y.type==="file")T((P)=>P.includes(y.path)?P:[...P,y.path])},[F]),M=w0((y)=>{I.current.delete(`file:${y}`),T((P)=>P.filter((k)=>k!==y)),W((P)=>{if(P.type==="file"&&P.path===y)return I.current.set(`file:${y}`,window.scrollY),{type:"plan"};return P})},[]);o$(()=>{let y=F.type==="plan"?"plan":`file:${F.path}`;window.scrollTo(0,I.current.get(y)||0)},[F]),T1(()=>{if(!J)return;fetch(`/api/session/${J}/meta`).then((y)=>y.json()).then((y)=>{if(y.currentRevision)Y(y.currentRevision),Q(y.currentRevision),q(y.revisions||[]);if(y.projectRoot)j(y.projectRoot)}).catch(()=>{})},[J]),T1(()=>{if(!J)return;let y=null,P=()=>{let k=window.location.protocol==="https:"?"wss:":"ws:",E=new WebSocket(`${k}//${window.location.host}/ws/session/${J}`);S.current=E,E.onopen=()=>G(!0),E.onclose=()=>{G(!1),y=setTimeout(P,2000)},E.onmessage=(r)=>{try{let c=JSON.parse(r.data);if(c.type==="plan-updated"){if(Y(c.currentRevision),Q(c.currentRevision),z(null),c.revisions)q(c.revisions)}if(c.type==="revision-updated"){if(c.revisions)q(c.revisions)}}catch{}}};return P(),()=>{if(y)clearTimeout(y);S.current?.close()}},[J]);let w=w0((y)=>{if(S.current?.readyState===WebSocket.OPEN)S.current.send(JSON.stringify({type:"submit",feedback:y})),H(!1)},[]);if(!J)return N("div",{className:"flex items-center justify-center h-screen text-text-tertiary font-body",children:"No session selected."},void 0,!1,void 0,this);return N(b2.Provider,{value:J,children:N(x1.Provider,{value:{currentRevision:$,selectedRevision:Z,revisions:X,setSelectedRevision:Q,isReadOnly:A,compareRevision:_,setCompareRevision:z},children:N(b5,{sessionId:J,revision:Z,isReadOnly:A,children:N(V1.Provider,{value:{activeView:F,setActiveView:v,openFiles:L,closeFile:M},children:N(n$.Provider,{value:{setActiveView:v},children:N("div",{className:"min-h-screen bg-bg-base",children:[N(J4,{sessionId:J,projectRoot:O,connected:K,onMobileSidebar:()=>B(!m),collapsed:R,onToggle:()=>g((y)=>!y)},void 0,!1,void 0,this),N(Y4,{collapsed:u,onToggle:()=>V((y)=>!y),children:N(n0,{onPreview:()=>H(!0),onSubmit:w},void 0,!1,void 0,this)},void 0,!1,void 0,this),_!==null?N("div",{className:`${R?"lg:ml-0":"lg:ml-60"} ${u?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,children:N(L2,{initialLeft:_.left,initialRight:_.right,sessionId:J,onExit:()=>z(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):N("div",{className:`relative ${R?"lg:ml-0":"lg:ml-60"} ${u?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,id:"plan-scroll-container",children:[N("div",{className:"lg:hidden sticky top-0 z-20 flex items-center justify-between px-4 py-2 border-b border-border-subtle bg-bg-surface",children:[N("div",{className:"flex items-center gap-2",children:[N($5,{currentSessionId:J,projectRoot:O},void 0,!1,void 0,this),N("span",{className:`w-1.5 h-1.5 rounded-full ${K?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N("div",{className:"flex items-center gap-1",children:[N(A2,{},void 0,!1,void 0,this),N("button",{onClick:()=>B(!m),className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Annotations",children:N("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:N("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),N(w2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),N(Z4,{},void 0,!1,void 0,this),N("div",{style:{display:F.type==="plan"?void 0:"none"},children:N("div",{className:"relative max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[N("button",{onClick:()=>{let y=document.querySelector(".plan-content");if(!y)return;let P=Q2(y);navigator.clipboard.writeText(P).then(()=>{let k=document.getElementById("export-md-btn");if(k)k.setAttribute("data-copied","true"),setTimeout(()=>{k.removeAttribute("data-copied")},1500)})},id:"export-md-btn",className:"group absolute top-3 right-6 p-1.5 text-text-tertiary hover:text-text-secondary transition-colors z-10",title:"Copy as Markdown",children:[N("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"group-[[data-copied=true]]:hidden",children:[N("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"},void 0,!1,void 0,this),N("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"hidden group-[[data-copied=true]]:block text-green-500",children:N("polyline",{points:"20 6 9 17 4 12"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f?.response&&N(Q4,{markdown:f.response},void 0,!1,void 0,this),N(g5,{revision:Z},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),L.map((y)=>N("div",{style:{display:F.type==="file"&&F.path===y?void 0:"none"},children:N(e5,{path:y},void 0,!1,void 0,this)},y,!1,void 0,this))]},void 0,!0,void 0,this),m&&N("div",{className:"lg:hidden fixed inset-0 z-40 flex",children:[N("div",{className:"flex-1",onClick:()=>B(!1)},void 0,!1,void 0,this),N("div",{className:"w-80 max-w-[85vw] bg-bg-surface border-l border-border-subtle flex flex-col shadow-lg",children:[N("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border-subtle flex-shrink-0",children:[N("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Sidebar"},void 0,!1,void 0,this),N("button",{onClick:()=>B(!1),className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N("div",{className:"flex-1 overflow-hidden",children:N(n0,{onPreview:()=>H(!0),onSubmit:w},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),N(p5,{open:U,onClose:()=>H(!1),onSubmit:w},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},`${J}:${Z}`,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function J4({sessionId:J,projectRoot:$,connected:Y,onMobileSidebar:Z,collapsed:Q,onToggle:X}){return N(X5,{children:[Q&&N("button",{onClick:X,className:"hidden lg:flex fixed top-3 left-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show sidebar",children:N("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[N("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),N("line",{x1:"9",y1:"3",x2:"9",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),N("div",{className:`hidden lg:flex w-60 flex-col fixed top-0 left-0 bottom-0 bg-bg-surface border-r border-border-subtle z-10 transition-transform duration-200 ${Q?"-translate-x-full":""}`,children:[N("div",{className:"px-4 pt-4 pb-3 flex-shrink-0 border-b border-border-subtle",children:[N("div",{className:"flex items-center gap-2 mb-2",children:[N("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"text-text-tertiary flex-shrink-0",children:N("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),N($5,{currentSessionId:J,projectRoot:$},void 0,!1,void 0,this),N("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${Y?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this),N("button",{onClick:X,className:"ml-auto w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide sidebar",children:N("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[N("polyline",{points:"11 17 6 12 11 7"},void 0,!1,void 0,this),N("polyline",{points:"18 17 13 12 18 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N(A2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N("div",{className:"flex-1 flex flex-col overflow-hidden",children:N(s5,{embedded:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),N("div",{className:"px-4 py-3 border-t border-border-subtle flex items-center justify-between flex-shrink-0",children:[N("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Theme"},void 0,!1,void 0,this),N(w2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Y4({children:J,collapsed:$,onToggle:Y}){let[Z,Q]=$1(()=>{let G=localStorage.getItem("canvas-sidebar-width");return G?parseInt(G,10):320}),X=M1(!1),q=M1(0),_=M1(0),z=M1(Z);z.current=Z;let K=w0((G)=>{G.preventDefault(),X.current=!0,q.current=G.clientX,_.current=z.current;let U=(F)=>{if(!X.current)return;let W=q.current-F.clientX,L=Math.max(240,Math.min(600,_.current+W));Q(L),z.current=L},H=()=>{X.current=!1,localStorage.setItem("canvas-sidebar-width",String(z.current)),document.removeEventListener("mousemove",U),document.removeEventListener("mouseup",H),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",U),document.addEventListener("mouseup",H),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);return T1(()=>{return document.documentElement.style.setProperty("--sidebar-width",`${Z}px`),()=>{document.documentElement.style.removeProperty("--sidebar-width")}},[Z]),N(X5,{children:[$&&N("button",{onClick:Y,className:"hidden lg:flex fixed top-3 right-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show annotations",children:N("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:N("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),N("div",{className:`hidden lg:flex flex-col fixed top-0 right-0 bottom-0 bg-bg-surface border-l border-border-subtle z-10 transition-transform duration-200 ${$?"translate-x-full":""}`,style:{width:Z},children:[N("div",{onMouseDown:K,className:"absolute left-0 top-0 bottom-0 w-1 cursor-col-resize hover:bg-accent-blue/30 transition-colors z-20",style:{marginLeft:"-2px"}},void 0,!1,void 0,this),m1.Children.map(J,(G)=>m1.isValidElement(G)?m1.cloneElement(G,{collapseButton:N("button",{onClick:Y,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide annotations",children:N("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[N("polyline",{points:"13 17 18 12 13 7"},void 0,!1,void 0,this),N("polyline",{points:"6 17 11 12 6 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}):G)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Q4({markdown:J}){let[$,Y]=$1(!1),Z=M2(()=>l.parse(J,{async:!1}),[J]),Q=M1(null),{annotations:X,addAnnotationWithId:q,removeAnnotation:_,updateAnnotation:z,addAnnotationImage:K,removeAnnotationImage:G,activeAnnotationId:U,setActiveAnnotationId:H}=t(),[F,W]=$1(null),[L,T]=$1(null),S=M2(()=>X.filter((R)=>R.filePath===X1),[X]),[O,j]=$1(J);if(J!==O)j(J),Y(!1);T1(()=>{if(!Q.current||S.length===0)return;let R=setTimeout(()=>{if(Q.current)H0(Q.current,S)},50);return()=>clearTimeout(R)},[Z,S.length]);let m=M1(null);if(T1(()=>{U0(U,m.current),m.current=U},[U]),T1(()=>{let R=Q.current;if(!R)return;let g=(I)=>{let f=I.target.closest("[data-annotation-id]");if(!f)return;I.stopPropagation();let A=f.getAttribute("data-annotation-id");if(A===U)T({anchorEl:f,annId:A});else H(A)},u=(I)=>{let f=I.target.closest("[data-annotation-id]");if(f)H(f.getAttribute("data-annotation-id"))},V=(I)=>{let f=I.target.closest("[data-annotation-id]"),A=I.relatedTarget?.closest?.("[data-annotation-id]");if(f&&!A)H(null)};return R.addEventListener("click",g),R.addEventListener("mouseover",u),R.addEventListener("mouseout",V),()=>{R.removeEventListener("click",g),R.removeEventListener("mouseover",u),R.removeEventListener("mouseout",V)}},[Z,U]),T1(()=>{let R=()=>{let g=window.getSelection();if(!g||g.isCollapsed||!g.toString().trim())return;if(!Q.current)return;let u=g.getRangeAt(0);if(!Q.current.contains(u.startContainer))return;if(u.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let V=g.toString().trim();if(V.length<2)return;let I=u.cloneRange(),f=b1(u,Q.current),A=`__pending_${Date.now()}`;try{A1(I,A)}catch{}window.getSelection()?.removeAllRanges();let v=document.querySelectorAll(`[data-annotation-id="${A}"]`),M=v[v.length-1];if(!M)return;W({anchorEl:M,tempId:A,snippet:V,ctx:f})};return document.addEventListener("mouseup",R),()=>document.removeEventListener("mouseup",R)},[]),$)return null;let B=document.getElementById("plan-scroll-container");return N("div",{className:"mb-6 rounded-lg border border-accent-blue/20 bg-accent-blue/5 relative",children:[N("button",{onClick:()=>Y(!0),className:"absolute top-2 right-2 w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:N("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this),N("div",{className:"px-4 py-3 pr-10",children:[N("div",{className:"flex items-center gap-2 mb-1.5",children:[N("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-accent-blue flex-shrink-0",children:N("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this),N("span",{className:"text-[11px] font-medium uppercase tracking-widest text-accent-blue font-body",children:"Agent Response"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N("div",{ref:Q,className:"prose-canvas text-sm",dangerouslySetInnerHTML:{__html:Z}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F&&N(f1,{anchorEl:F.anchorEl,scrollContainer:B,snippet:F.snippet,truncateAt:80,onAdd:(R,g)=>{let u=_1();G0(F.tempId,u),q(u,F.snippet,R,X1,F.ctx,g),W(null)},onCancel:()=>{W0(F.tempId),W(null)}},void 0,!1,void 0,this),L&&(()=>{let R=X.find((g)=>g.id===L.annId);if(!R)return null;return N(v1,{anchorEl:L.anchorEl,scrollContainer:B,initialNote:R.note,initialImages:R.images,onUpdate:(g,u)=>{z(L.annId,g);let V=R.images||[];for(let I of u)if(!V.includes(I))K(L.annId,I);for(let I of V)if(!u.includes(I))G(L.annId,I)},onDelete:()=>{_(L.annId),H(null)},onClose:()=>T(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function Z4(){let{activeView:J,setActiveView:$,openFiles:Y,closeFile:Z}=m1.useContext(V1),Q=m1.useContext(b2),{addAnnotationWithId:X,setActiveAnnotationId:q}=t(),_=Y.length>0;if(!_)return null;return N("div",{className:"flex items-center border-b border-border-medium bg-bg-surface overflow-x-auto sticky top-0 z-10",children:[_&&N("button",{onClick:()=>$({type:"plan"}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${J.type==="plan"?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[N("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"opacity-60",children:N("path",{d:"M12 7L2 12l10 5 10-5-10-5z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Canvas",J.type==="plan"&&N("span",{className:"absolute bottom-0 left-3 right-3 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),_&&N(X5,{children:[N("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this),Y.map((z,K)=>{let G=z.split("/").pop()||z,U=J.type==="file"&&J.path===z;return N(m1.Fragment,{children:[N("div",{className:"flex items-center",children:[N("button",{onClick:()=>$({type:"file",path:z}),className:`flex items-center gap-1.5 pl-3 pr-1 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${U?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[N(y1,{name:G,type:"file"},void 0,!1,void 0,this),G,U&&N("span",{className:"absolute bottom-0 left-3 right-1 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N("button",{onClick:(H)=>{H.stopPropagation(),Z(z)},className:"text-text-tertiary hover:text-text-secondary px-1.5 py-1 text-[10px] transition-colors rounded hover:bg-bg-input",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),K<Y.length-1&&N("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},z,!0,void 0,this)})]},void 0,!0,void 0,this),N("div",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:J.type==="file"&&N("button",{onClick:async()=>{let z=J.path;try{let G=await(await fetch(`/api/file?session=${Q}&path=${encodeURIComponent(z)}`)).json();if(!G.error){let U=G.content.split(`
|
|
83
|
+
`}var b$=new Set(["CODE","SPAN","STRONG","EM","A","B","I","U","SMALL","SUB","SUP","MARK","ABBR"]);function k0(J,$,Y){if(w$(J)){let Z=A$(J);if(Z)$.push(Z,"");return}for(let Z of J.childNodes)if(Z.nodeType===Node.ELEMENT_NODE)I$(Z,$,Y);else if(Z.nodeType===Node.TEXT_NODE){let Q=Z.textContent?.trim();if(Q)$.push(Q,"")}}function w$(J){for(let $ of J.childNodes){if($.nodeType===Node.TEXT_NODE)continue;if($.nodeType===Node.ELEMENT_NODE){let Y=$;if(!b$.has(Y.tagName)||Y.hasAttribute("data-md"))return!1}}return J.childNodes.length>0}function A$(J){let $="";for(let Y of J.childNodes)if(Y.nodeType===Node.TEXT_NODE)$+=Y.textContent||"";else if(Y.nodeType===Node.ELEMENT_NODE){let Z=Y;if(Z.tagName==="CODE")$+="`"+(Z.textContent||"")+"`";else $+=Z.textContent||""}return $.trim()}function I$(J,$,Y){let Z=J.getAttribute("data-md");if(Z)switch(Z){case"section":return C$(J,$,Y);case"item":return j$(J,$);case"codeblock":return R$(J,$);case"callout":return k$(J,$);case"note":return V$(J,$);case"table":return D$(J,$);case"checklist":return m$(J,$);case"diff":return g$(J,$);case"mermaid":return u$(J,$);case"choice":return E$(J,$);case"multichoice":return v$(J,$);case"choice-option":case"multichoice-option":return;case"userinput":return x$(J,$);case"rangeinput":return f$(J,$);case"checklist-item":return;case"filepreview":return h$(J,$);case"priority":return p$(J,$)}if(J.querySelector("button, input, select, textarea"))return;if(J.children.length>0)k0(J,$,Y);else{let Q=J.textContent?.trim();if(Q)$.push(Q,"")}}function C$(J,$,Y){let Z=J.getAttribute("data-md-title")||"Untitled",Q=Y===0?"##":"###";$.push(`${Q} ${Z}`,"");let q=J.querySelector(":scope > div:last-of-type");if(q)k0(q,$,Y+1)}function j$(J,$){let Y=J.getAttribute("data-md-label")||"",Z=J.getAttribute("data-md-status"),Q=J.getAttribute("data-md-badge"),q="-";if(Z==="done")q="- [x]";else if(Z)q="- [ ]";let X=`${q} **${Y}**`;if(Q)X+=` \`${Q}\``;$.push(X);let G=J.querySelector(".text-text-secondary");if(G){let _=[];k0(G,_,0);for(let z of _)$.push(z?` ${z}`:"")}$.push("")}function R$(J,$){let Y=J.getAttribute("data-md-language")||"",Q=J.querySelector("code")?.textContent||"";$.push(`\`\`\`${Y}`,Q,"```","")}function k$(J,$){let Y=J.getAttribute("data-md-type")||"info",Z={info:"Info",warning:"Warning",danger:"Danger",tip:"Tip"},Q=c$(J.querySelector(".text-text-secondary")||J);$.push(`> **${Z[Y]||Y}:** ${Q}`,"")}function V$(J,$){let Y=J.textContent?.trim()||"";$.push(`> *${Y}*`,"")}function D$(J,$){let Y=J.querySelector("table");if(!Y)return;let Z=[];for(let Q of Y.querySelectorAll("thead th"))Z.push(Q.textContent?.trim()||"");if(Z.length===0)return;$.push(`| ${Z.join(" | ")} |`),$.push(`| ${Z.map(()=>"---").join(" | ")} |`);for(let Q of Y.querySelectorAll("tbody tr")){let q=[];for(let X of Q.querySelectorAll("td"))q.push(X.textContent?.trim()||"");$.push(`| ${q.join(" | ")} |`)}$.push("")}function m$(J,$){for(let Y of J.querySelectorAll("li")){let Z=Y.querySelector(".bg-accent-green")!==null,Q=Y.textContent?.trim()||"";$.push(`- [${Z?"x":" "}] ${Q}`)}$.push("")}function g$(J,$){let Y=J.getAttribute("data-md-language")||"";$.push(`\`\`\`diff${Y?` (${Y})`:""}`);for(let Z of J.querySelectorAll("[class*='flex']")){let Q=Z.querySelector(".text-accent-red")?"-":Z.querySelector(".text-accent-green")?"+":" ",q=Z.querySelector("code");if(q)$.push(`${Q} ${q.textContent}`)}$.push("```","")}function u$(J,$){let Y=J.getAttribute("data-md-source")||"";if(Y)$.push("```mermaid",Y,"```","")}function E$(J,$){let Y=J.getAttribute("data-md-label")||"";$.push(`**${Y}:**`);for(let Z of J.querySelectorAll("[data-md='choice-option']")){let Q=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",q=Z.querySelector(".bg-accent-amber")!==null;$.push(`- ${q?"(x)":"( )"} ${Q}`)}$.push("")}function v$(J,$){let Y=J.getAttribute("data-md-label")||"";$.push(`**${Y}:**`);for(let Z of J.querySelectorAll("[data-md='multichoice-option']")){let Q=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",q=Z.querySelector(".bg-accent-amber")!==null;$.push(`- [${q?"x":" "}] ${Q}`)}$.push("")}function x$(J,$){let Y=J.getAttribute("data-md-label")||"",Q=J.querySelector("textarea")?.value?.trim()||"";$.push(`**${Y}:** ${Q||"_empty_"}`,"")}function f$(J,$){let Y=J.getAttribute("data-md-label")||"",Z=J.querySelector("input[type='range']"),q=J.querySelector(".font-mono")?.textContent?.trim()||Z?.value||"—";$.push(`**${Y}:** ${q}`,"")}function h$(J,$){let Y=J.getAttribute("data-md-path")||"",Z=J.getAttribute("data-md-lines")||"",q=J.querySelector("code")?.textContent||"",X=Y.split(".").pop()||"",G=j0[X]||"",_=Z?`${Y} (L${Z})`:Y;$.push(_,"",`\`\`\`${G}`,q,"```","")}function p$(J,$){}function c$(J){return J?.textContent?.trim()||""}import P2,{useEffect as w1,useState as Q1,useRef as L1,useCallback as S2,useMemo as g0,useContext as Z4}from"react";import{useEffect as d$,useState as r$,useRef as l$,useContext as i$}from"react";import{jsxDEV as X1,Fragment as K2}from"react/jsx-dev-runtime";function a$(J){return J.label||`Round ${J.revision}`}function o$(J){let $=Date.now()-new Date(J).getTime(),Y=Math.floor($/1000);if(Y<60)return"just now";let Z=Math.floor(Y/60);if(Z<60)return`${Z}m ago`;let Q=Math.floor(Z/60);if(Q<24)return`${Q}h ago`;return`${Math.floor(Q/24)}d ago`}function q0({value:J,onChange:$,accent:Y="default",className:Z}){let{currentRevision:Q,revisions:q}=i$(N1),[X,G]=r$(!1),_=l$(null);d$(()=>{if(!X)return;let U=(W)=>{if(_.current&&!_.current.contains(W.target))G(!1)};return document.addEventListener("mousedown",U),()=>document.removeEventListener("mousedown",U)},[X]);let z=q.find((U)=>U.revision===J);return X1("div",{className:"relative",ref:_,children:[X1("button",{onClick:()=>G(!X),className:`flex items-center gap-1.5 text-[12px] font-body font-medium px-2 py-1 rounded-md transition-colors hover:bg-bg-elevated ${{default:"text-text-secondary hover:text-text-primary",red:"text-accent-red",green:"text-accent-green",amber:"text-accent-amber bg-highlight-selected"}[Y]} ${Z||""}`,children:[z?a$(z):`Round ${J}`,X1("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${X?"rotate-180":""}`,children:X1("path",{d:"M2.5 4l2.5 2.5L7.5 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X&&X1("div",{className:"absolute top-full left-0 mt-1 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 max-h-80 overflow-y-auto",children:[...q].reverse().map((U)=>X1("button",{onClick:()=>{$(U.revision),G(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-body transition-colors ${U.revision===J?"bg-bg-surface text-text-primary":"text-text-secondary hover:bg-bg-surface hover:text-text-primary"}`,children:[X1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${U.revision===Q?"bg-accent-green":U.hasFeedback?"bg-accent-amber":"bg-border-hover"}`},void 0,!1,void 0,this),X1("span",{className:"flex-1 text-left truncate",children:U.label?X1(K2,{children:[U.label," ",X1("span",{className:"text-text-tertiary",children:["#",U.revision]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):X1(K2,{children:["Round ",U.revision]},void 0,!0,void 0,this)},void 0,!1,void 0,this),X1("span",{className:"text-[10px] text-text-tertiary flex-shrink-0 flex items-center gap-1.5",children:[(()=>{let W=U.canvasFiles?.reduce((N,K)=>{if(K.diffStats)N.added+=K.diffStats.added,N.removed+=K.diffStats.removed;return N},{added:0,removed:0});if(W&&(W.added>0||W.removed>0))return X1("span",{className:"font-mono",children:[X1("span",{className:"text-accent-green",children:["+",W.added]},void 0,!0,void 0,this)," ",X1("span",{className:"text-accent-red",children:["-",W.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return null})(),U.revision===Q?"current":U.hasFeedback?"sent":o$(U.createdAt)]},void 0,!0,void 0,this)]},U.revision,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function b1(J,$){let Y=J.length,Z=$.length;if(Y===0||Z===0)return[];let Q=Array.from({length:Y+1},()=>Array(Z+1).fill(0));for(let _=1;_<=Y;_++)for(let z=1;z<=Z;z++)Q[_][z]=J[_-1]===$[z-1]?Q[_-1][z-1]+1:Math.max(Q[_-1][z],Q[_][z-1]);let q=[],X=Y,G=Z;while(X>0&&G>0)if(J[X-1]===$[G-1])q.unshift(J[X-1]),X--,G--;else if(Q[X-1][G]>Q[X][G-1])X--;else G--;return q}function H2(J){let $=[],Y=[],Z=document.createTreeWalker(J,NodeFilter.SHOW_TEXT,{acceptNode(q){let X=q.parentElement;if(!X)return NodeFilter.FILTER_REJECT;if(X.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;return NodeFilter.FILTER_ACCEPT}}),Q;while(Q=Z.nextNode()){let X=(Q.nodeValue||"").match(/\S+|\s+/g);if(!X)continue;let G=0;for(let _ of X)$.push(_),Y.push({text:_,node:Q,offset:G}),G+=_.length}return{words:$,map:Y}}function K5(J,$){if(J.length>5000||$.length>5000)return s$(J,$);return T2(J,$)}function T2(J,$){let Y=V0(J,$),Z=[],Q=[],q=0,X=0,G=0;while(q<J.length||X<$.length)if(G<Y.length&&q<J.length&&X<$.length&&J[q]===Y[G]&&$[X]===Y[G])Z.push({type:"same",index:q}),Q.push({type:"same",index:X}),q++,X++,G++;else if(q<J.length&&(G>=Y.length||J[q]!==Y[G]))Z.push({type:"removed",index:q}),q++;else if(X<$.length)Q.push({type:"added",index:X}),X++;return{oldOps:Z,newOps:Q}}function V0(J,$){let Y=J.length,Z=$.length;if(Y===0||Z===0)return[];if(Y===1)return $.includes(J[0])?[J[0]]:[];if(Z===1)return J.includes($[0])?[$[0]]:[];if(Y*Z<=1e6)return b1(J,$);let Q=Math.floor(Y/2),q=J.slice(0,Q),X=J.slice(Q),G=W2(q,$),_=W2([...X].reverse(),[...$].reverse()),z=0,H=0;for(let N=0;N<=Z;N++){let K=G[N]+_[Z-N];if(K>z)z=K,H=N}let U=$.slice(0,H),W=$.slice(H);return[...V0(q,U),...V0(X,W)]}function W2(J,$){let Y=$.length,Z=Array(Y+1).fill(0),Q=Array(Y+1).fill(0);for(let q=0;q<J.length;q++){for(let X=1;X<=Y;X++)Q[X]=J[q]===$[X-1]?Z[X-1]+1:Math.max(Z[X],Q[X-1]);[Z,Q]=[Q,Z],Q.fill(0)}return Z}function s$(J,$){let Z=(K)=>{let T=[];for(let O=0;O<K.length;O+=200){let S=Math.min(O+200,K.length);T.push({start:O,end:S,text:K.slice(O,S).join("")})}return T},Q=Z(J),q=Z($),X=Q.map((K)=>K.text),G=q.map((K)=>K.text),_=V0(X,G),z=[],H=[],U=0,W=0,N=0;while(U<Q.length||W<q.length)if(N<_.length&&U<Q.length&&W<q.length&&X[U]===_[N]&&G[W]===_[N]){for(let K=Q[U].start;K<Q[U].end;K++)z.push({type:"same",index:K});for(let K=q[W].start;K<q[W].end;K++)H.push({type:"same",index:K});U++,W++,N++}else if(U<Q.length&&(N>=_.length||X[U]!==_[N]))if(W<q.length&&(N>=_.length||G[W]!==_[N])){let K=T2(J.slice(Q[U].start,Q[U].end),$.slice(q[W].start,q[W].end));for(let T of K.oldOps)z.push({type:T.type,index:T.index+Q[U].start});for(let T of K.newOps)H.push({type:T.type,index:T.index+q[W].start});U++,W++}else{for(let K=Q[U].start;K<Q[U].end;K++)z.push({type:"removed",index:K});U++}else if(W<q.length){for(let K=q[W].start;K<q[W].end;K++)H.push({type:"added",index:K});W++}return{oldOps:z,newOps:H}}function N2(J,$,Y){let Z=new Map;for(let Q of J){if(Q.type==="same")continue;let q=$[Q.index];if(!q||!q.node.parentNode)continue;let X=Z.get(q.node);if(!X)X=[],Z.set(q.node,X);X.push({offset:q.offset,length:q.text.length})}for(let[Q,q]of Z){if(!Q.parentNode)continue;let X=Q.nodeValue||"";q.sort((U,W)=>U.offset-W.offset);let G=[];for(let U of q){let W=G[G.length-1];if(W&&U.offset<=W.offset+W.length)W.length=Math.max(W.length,U.offset+U.length-W.offset);else G.push({...U})}let _=Q.parentNode,z=document.createDocumentFragment(),H=0;for(let U of G){if(U.offset>H)z.appendChild(document.createTextNode(X.slice(H,U.offset)));let W=document.createElement("span");W.className=Y,W.textContent=X.slice(U.offset,U.offset+U.length),z.appendChild(W),H=U.offset+U.length}if(H<X.length)z.appendChild(document.createTextNode(X.slice(H)));_.replaceChild(z,Q)}}function D0(J,$){let Y=t$(J,$),Z=H2(J),Q=H2($),{oldOps:q,newOps:X}=K5(Z.words,Q.words),G=q.some((_)=>_.type==="removed")||X.some((_)=>_.type==="added");return N2(q,Z.map,"diff-removed"),N2(X,Q.map,"diff-added"),G||Y}function t$(J,$){let Y=Array.from(J.querySelectorAll('[data-md="mermaid"]')),Z=Array.from($.querySelectorAll('[data-md="mermaid"]')),Q=!1,q=Math.max(Y.length,Z.length);for(let X=0;X<q;X++){let G=Y[X],_=Z[X];if(!G&&_){_.classList.add("diff-block-added"),_.style.position="relative",Q=!0;continue}if(G&&!_){G.classList.add("diff-block-removed"),G.style.position="relative",Q=!0;continue}if(!G||!_)continue;let z=(G.getAttribute("data-md-source")||"").trim(),H=(_.getAttribute("data-md-source")||"").trim();if(z===H)continue;Q=!0,G.style.borderLeft="3px solid var(--color-accent-red)",G.style.paddingLeft="8px",_.style.borderLeft="3px solid var(--color-accent-green)",_.style.paddingLeft="8px";let U=z.split(`
|
|
84
|
+
`),W=H.split(`
|
|
85
|
+
`),N=b1(U,W),K=(T,O,S)=>{let L=document.createElement("div");L.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",L.setAttribute("data-no-diff","true");let j=0,V=0;while(V<T.length){let M=document.createElement("div");if(M.className="px-3 py-0.5 whitespace-pre-wrap",j<O.length&&T[V]===O[j])M.textContent=" "+T[V],V++,j++;else M.classList.add(S==="old"?"diff-removed":"diff-added"),M.textContent=(S==="old"?"- ":"+ ")+T[V],V++;L.appendChild(M)}return L};G.appendChild(K(U,N,"old")),_.appendChild(K(W,N,"new"))}return Q}function a1(J){let $=[],Y=J.querySelectorAll(":scope > [data-md]");for(let Z of Y)$.push(_0(Z));if($.length===0){let Z=J.querySelectorAll("[data-md]"),Q=new Set;for(let q of Z){let X=q.parentElement?.closest("[data-md]");if(X&&J.contains(X))continue;if(Q.has(q))continue;Q.add(q),$.push(_0(q))}}return $}function _0(J){let $=J.getAttribute("data-md")||"unknown",Y=n$(J,$),Z=[];if($==="section"){let Q=J.querySelector(":scope > div.mt-6, :scope > div:last-child");if(Q)for(let q of Q.querySelectorAll(":scope > [data-md]"))Z.push(_0(q))}else if($==="table")for(let Q of J.querySelectorAll(":scope table > tbody > tr"))Z.push({key:"tr:"+(Q.textContent||"").slice(0,80),type:"tr",element:Q,children:[]});else if($==="checklist")for(let Q of J.querySelectorAll(":scope > [data-md='checklist-item']"))Z.push(_0(Q));else for(let Q of J.querySelectorAll("[data-md]"))if(Q.parentElement?.closest("[data-md]")===J)Z.push(_0(Q));return{key:Y,type:$,element:J,children:Z}}function n$(J,$){switch($){case"section":return"section:"+(J.getAttribute("data-md-title")||"");case"item":return"item:"+(J.getAttribute("data-task-id")||J.getAttribute("data-md-label")||"");case"codeblock":case"diff":return $+":"+(J.textContent||"").slice(0,80);case"checklist-item":return"checklist-item:"+(J.getAttribute("data-md-label")||J.textContent?.slice(0,60)||"");case"checklist":return"checklist:"+J.querySelectorAll("[data-md='checklist-item']").length;case"markdown":return"markdown:"+(J.getAttribute("data-md-file")||"inline");case"mermaid":return"mermaid:"+(J.getAttribute("data-md-source")||"").slice(0,80);case"callout":return"callout:"+(J.getAttribute("data-md-type")||"")+":"+(J.textContent||"").slice(0,60);default:return $+":"+(J.getAttribute("data-md-label")||J.textContent?.slice(0,60)||"")}}function z0(J,$){let Y=J.map((z)=>z.key),Z=$.map((z)=>z.key),Q=b1(Y,Z),q=[],X=0,G=0,_=0;while(X<J.length||G<$.length)if(_<Q.length&&X<J.length&&G<$.length&&Y[X]===Q[_]&&Z[G]===Q[_]){let z=J[X],H=$[G],U=z.children.length>0||H.children.length>0?z0(z.children,H.children):void 0;q.push({kind:"matched",oldBlock:z,newBlock:H,childMatches:U}),X++,G++,_++}else if(X<J.length&&(_>=Q.length||Y[X]!==Q[_]))q.push({kind:"removed",oldBlock:J[X]}),X++;else if(G<$.length)q.push({kind:"added",newBlock:$[G]}),G++;return q}function m0(J){let $=document.createDocumentFragment(),Y=!1;for(let Z of J)if(Z.kind==="removed")Y=!0,$.appendChild(F2(Z.oldBlock.element));else if(Z.kind==="added")Y=!0,$.appendChild(e$(Z.newBlock.element));else{let Q=Z.newBlock.element.cloneNode(!0),q=Z.newBlock.type;if(q==="mermaid"){if(M2(Z.oldBlock.element,Q))Y=!0}else if(Z.childMatches&&Z.childMatches.length>0&&(q==="table"||q==="checklist")){if(B2(Q,Z.childMatches,q))Y=!0}else if(Z.childMatches&&Z.childMatches.length>0){if(L2(Z.oldBlock,Q,Z.childMatches,q))Y=!0}else if(q==="markdown"){if(y2(Z.oldBlock.element,Q))Y=!0}else if(h1(Z.oldBlock.element,Q,!1))Y=!0;$.appendChild(Q)}return{fragment:$,hasChanges:Y}}function F2(J){let $=J.cloneNode(!0);return $.classList.add("diff-block-removed"),$.style.position="relative",H5($,"Removed","var(--color-accent-red)"),$}function e$(J){let $=J.cloneNode(!0);return $.classList.add("diff-block-added"),$.style.position="relative",H5($,"Added","var(--color-accent-green)"),$}function L2(J,$,Y,Z){let Q=!1,q=$4(J,$),X,G;if(Z==="section"){let _=J.element.querySelector(":scope > div:first-child"),z=$.querySelector(":scope > div:first-child");if(_&&z){if(h1(_,z,!1))Q=!0}X=J.element.querySelector(":scope > div.mt-6, :scope > div:last-child"),G=$.querySelector(":scope > div.mt-6, :scope > div:last-child")}else X=J.element,G=$;if(!X||!G)return Q;for(let _ of Y)if(_.kind==="matched"){let z=q.newMap.get(_.newBlock.element);if(z){if(_.newBlock.type==="mermaid"){if(M2(_.oldBlock.element,z))Q=!0}else if(_.childMatches&&_.childMatches.length>0&&(_.newBlock.type==="table"||_.newBlock.type==="checklist")){if(B2(z,_.childMatches,_.newBlock.type))Q=!0}else if(_.childMatches&&_.childMatches.length>0){if(L2(_.oldBlock,z,_.childMatches,_.newBlock.type))Q=!0}else if(_.newBlock.type==="markdown"){if(y2(_.oldBlock.element,z))Q=!0}else if(h1(_.oldBlock.element,z,!1))Q=!0}}else if(_.kind==="removed"){Q=!0;let z=F2(_.oldBlock.element),H=Y4(Y,_,q.newMap);G.insertBefore(z,H)}else if(_.kind==="added"){Q=!0;let z=q.newMap.get(_.newBlock.element);if(z)z.classList.add("diff-block-added"),z.style.position="relative",H5(z,"Added","var(--color-accent-green)")}if(h1(X,G,!0))Q=!0;return Q}function B2(J,$,Y){let Z=Y==="table"?J.querySelector(":scope table > tbody"):J;if(!Z)return!1;let Q=!1;Z.innerHTML="";for(let q of $)if(q.kind==="removed"){Q=!0;let X=q.oldBlock.element.cloneNode(!0);X.classList.add(Y==="table"?"diff-row-removed":"diff-item-removed"),Z.appendChild(X)}else if(q.kind==="added"){Q=!0;let X=q.newBlock.element.cloneNode(!0);X.classList.add(Y==="table"?"diff-row-added":"diff-item-added"),Z.appendChild(X)}else{let X=q.newBlock.element.cloneNode(!0);if(h1(q.oldBlock.element,X,!1))Q=!0;Z.appendChild(X)}return Q}function $4(J,$){let Y=new Map,Z=J.element.querySelectorAll("[data-md]"),Q=$.querySelectorAll("[data-md]");return{newMap:{get(q){return J4($,q)}}}}function J4(J,$){let Y=$.getAttribute("data-md");if(!Y)return null;let Z=$.getAttribute("data-md-label"),Q=$.getAttribute("data-md-title"),q=`[data-md="${Y}"]`;if(Q)q+=`[data-md-title="${CSS.escape(Q)}"]`;else if(Z)q+=`[data-md-label="${CSS.escape(Z)}"]`;let X=J.querySelectorAll(q);if(X.length===1)return X[0];let G=($.textContent||"").slice(0,100),_=null,z=-1;for(let H of X){let U=(H.textContent||"").slice(0,100),W=0;for(let N=0;N<Math.min(G.length,U.length);N++)if(G[N]===U[N])W++;if(W>z)z=W,_=H}return _}function Y4(J,$,Y){let Z=J.indexOf($);for(let Q=Z+1;Q<J.length;Q++){let q=J[Q];if((q.kind==="matched"||q.kind==="added")&&q.newBlock)return Y.get(q.newBlock.element)||null}return null}function y2(J,$){let Y=Array.from(J.children),Z=Array.from($.children);if(Y.length===0&&Z.length===0)return h1(J,$,!1);let Q=Y.map((W)=>W.tagName.toLowerCase()),q=Z.map((W)=>W.tagName.toLowerCase()),X=b1(Q,q),G=[],_=0,z=0,H=0;while(_<Y.length||z<Z.length)if(H<X.length&&_<Y.length&&z<Z.length&&Q[_]===X[H]&&q[z]===X[H])G.push({kind:"matched",oldChild:Y[_],newChild:Z[z]}),_++,z++,H++;else if(_<Y.length&&(H>=X.length||Q[_]!==X[H]))G.push({kind:"removed",oldChild:Y[_]}),_++;else if(z<Z.length)G.push({kind:"added",newChild:Z[z]}),z++;let U=!1;while($.firstChild)$.removeChild($.firstChild);for(let W of G)if(W.kind==="matched"){let N=(W.oldChild.textContent||"").match(/\S+/g)||[],K=(W.newChild.textContent||"").match(/\S+/g)||[],T=b1(N,K),O=Math.max(N.length,K.length);if((O>0?1-T.length/O:0)>0.5){U=!0;let L=W.oldChild.cloneNode(!0);L.classList.add("diff-block-removed"),$.appendChild(L),W.newChild.classList.add("diff-block-added"),$.appendChild(W.newChild)}else{if(h1(W.oldChild,W.newChild,!1))U=!0;$.appendChild(W.newChild)}}else if(W.kind==="removed"){U=!0;let N=W.oldChild.cloneNode(!0);N.classList.add("diff-block-removed"),$.appendChild(N)}else U=!0,W.newChild.classList.add("diff-block-added"),$.appendChild(W.newChild);return U}function O2(J,$){let Y=$?new Set(Array.from(J.querySelectorAll("[data-md]"))):new Set,Z=[],Q=[],q=document.createTreeWalker(J,NodeFilter.SHOW_TEXT,{acceptNode(G){let _=G.parentElement;if(!_)return NodeFilter.FILTER_REJECT;if(_.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;if($){for(let z of Y)if(z.contains(G))return NodeFilter.FILTER_REJECT}return NodeFilter.FILTER_ACCEPT}}),X;while(X=q.nextNode()){let _=(X.nodeValue||"").match(/\S+|\s+/g);if(!_)continue;let z=0;for(let H of _)Z.push(H),Q.push({text:H,node:X,offset:z}),z+=H.length}return{words:Z,map:Q}}function h1(J,$,Y){let Z=O2(J,Y),Q=O2($,Y);if(Z.words.length===0&&Q.words.length===0)return!1;let{oldOps:q,newOps:X}=K5(Z.words,Q.words),G=q.some((O)=>O.type==="removed"),_=X.some((O)=>O.type==="added");if(!G&&!_)return!1;let z=[],H=[];for(let O of q)if(O.type==="same")z.push(O.index);for(let O of X)if(O.type==="same")H.push(O.index);let U=new Map;for(let O=0;O<z.length&&O<H.length;O++)U.set(z[O],H[O]);let W=[];{let O=[],S=-1;for(let L of q)if(L.type==="same"){if(O.length>0)W.push({text:O.join(""),anchorNewIdx:S>=0?U.get(S)??null:null}),O=[];S=L.index}else if(L.type==="removed")O.push(Z.words[L.index]);if(O.length>0)W.push({text:O.join(""),anchorNewIdx:S>=0?U.get(S)??null:null})}let N=new Map,K=new Map;for(let O of X){if(O.type!=="added")continue;let S=Q.map[O.index];if(!S?.node.parentNode)continue;let L=N.get(S.node);if(!L)L=[],N.set(S.node,L);L.push({start:S.offset,end:S.offset+S.text.length})}for(let O of W)if(O.anchorNewIdx===null){if(Q.map.length>0){let S=Q.map[0].node,L=K.get(S);if(!L)L=[],K.set(S,L);L.push({offset:0,text:O.text})}}else{let S=Q.map[O.anchorNewIdx];if(!S)continue;let L=K.get(S.node);if(!L)L=[],K.set(S.node,L);L.push({offset:S.offset+S.text.length,text:O.text})}let T=new Set([...N.keys(),...K.keys()]);for(let O of T)Q4(O,N.get(O)||[],K.get(O)||[]);return!0}function Q4(J,$,Y){if(!J.parentNode)return;let Z=J.nodeValue||"";$.sort((H,U)=>H.start-U.start);let Q=[];for(let H of $){let U=Q[Q.length-1];if(U&&H.start<=U.end)U.end=Math.max(U.end,H.end);else Q.push({...H})}Y.sort((H,U)=>H.offset-U.offset);let q=J.parentNode,X=document.createDocumentFragment(),G=0,_=0,z=0;while(G<=Z.length){let H=_<Q.length?Q[_].start:1/0,U=z<Y.length?Y[z].offset:1/0,W=Math.min(H,U);if(W===1/0){if(G<Z.length)X.appendChild(document.createTextNode(Z.slice(G)));break}let N=Math.max(W,G);if(N>G)X.appendChild(document.createTextNode(Z.slice(G,N))),G=N;while(z<Y.length&&Y[z].offset<=G){let K=document.createElement("span");K.className="diff-removed",K.textContent=Y[z].text,X.appendChild(K),z++}if(_<Q.length&&Q[_].start<=G){let K=Q[_],T=document.createElement("span");T.className="diff-added",T.textContent=Z.slice(G,K.end),X.appendChild(T),G=K.end,_++;while(z<Y.length&&Y[z].offset<=G){let O=document.createElement("span");O.className="diff-removed",O.textContent=Y[z].text,X.appendChild(O),z++}}}while(z<Y.length){let H=document.createElement("span");H.className="diff-removed",H.textContent=Y[z].text,X.appendChild(H),z++}q.replaceChild(X,J)}function M2(J,$){let Y=(J.getAttribute("data-md-source")||"").trim(),Z=($.getAttribute("data-md-source")||"").trim();if(Y===Z)return!1;let Q=Y.split(`
|
|
86
|
+
`),q=Z.split(`
|
|
87
|
+
`),X=b1(Q,q),G=[],_=0,z=0,H=0;while(_<Q.length||z<q.length)if(H<X.length&&_<Q.length&&z<q.length&&Q[_]===X[H]&&q[z]===X[H])G.push({type:"same",line:Q[_]}),_++,z++,H++;else if(_<Q.length&&(H>=X.length||Q[_]!==X[H]))G.push({type:"removed",line:Q[_]}),_++;else if(z<q.length)G.push({type:"added",line:q[z]}),z++;let U=document.createElement("div");U.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",U.setAttribute("data-no-diff","true");for(let W of G){let N=document.createElement("div");if(N.className="px-3 py-0.5 whitespace-pre-wrap",W.type==="removed")N.classList.add("diff-removed"),N.textContent="- "+W.line;else if(W.type==="added")N.classList.add("diff-added"),N.textContent="+ "+W.line;else N.textContent=" "+W.line;U.appendChild(N)}return $.appendChild(U),!0}function H5(J,$,Y){let Z=document.createElement("span");Z.className="diff-block-label",Z.textContent=$,Z.style.color=Y,Z.style.backgroundColor=`color-mix(in srgb, ${Y} 12%, transparent)`,J.appendChild(Z)}import{jsxDEV as f}from"react/jsx-dev-runtime";function X4(J,$,Y){let Z=J.find((X)=>X.revision===$),Q=J.find((X)=>X.revision===Y),q=new Set;for(let X of Z?.canvasFiles||[])q.add(X.filename);for(let X of Q?.canvasFiles||[])q.add(X.filename);return[...q].sort()}function b2({initialLeft:J,initialRight:$,sessionId:Y,onExit:Z}){let[Q,q]=Q1(J),[X,G]=Q1($),[_,z]=Q1("unified"),[H,U]=Q1(!0),[W,N]=Q1(!1),{revisions:K}=Z4(N1),T=g0(()=>X4(K,Q,X),[K,Q,X]),[O,S]=Q1(()=>T[0]||"plan.jsx");w1(()=>{if(!T.includes(O))S(T[0]||"plan.jsx")},[T,O]);let L=g0(()=>{return K.find((M)=>M.revision===Q)?.canvasFiles.some((M)=>M.filename===O)??!1},[K,Q,O]),j=g0(()=>{return K.find((M)=>M.revision===X)?.canvasFiles.some((M)=>M.filename===O)??!1},[K,X,O]);return f("div",{className:"flex flex-col h-screen",children:[f("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border-subtle bg-bg-surface flex-shrink-0",children:[f("div",{className:"flex items-center gap-3",children:[f("span",{className:"text-[13px] font-body font-medium text-text-primary",children:"Compare"},void 0,!1,void 0,this),f(q0,{value:Q,onChange:q,accent:"red"},void 0,!1,void 0,this),f("span",{className:"text-text-tertiary text-[13px]",children:"→"},void 0,!1,void 0,this),f(q0,{value:X,onChange:G,accent:"green"},void 0,!1,void 0,this),W&&!H&&f("span",{className:"text-[11px] font-body text-text-tertiary bg-bg-elevated px-2 py-0.5 rounded",children:"No changes"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("div",{className:"flex items-center gap-4",children:[f("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:[f("button",{onClick:()=>z("unified"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${_==="unified"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Unified"},void 0,!1,void 0,this),f("button",{onClick:()=>z("side-by-side"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${_==="side-by-side"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Side-by-side"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),_==="side-by-side"&&f(q4,{},void 0,!1,void 0,this),f("button",{onClick:Z,className:"text-[12px] font-body font-medium text-text-secondary hover:text-text-primary px-3 py-1.5 rounded-md hover:bg-bg-elevated transition-colors",children:"Exit Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),T.length>1&&f("div",{className:"flex items-center gap-1 px-6 py-2 border-b border-border-subtle bg-bg-surface flex-shrink-0 overflow-x-auto",children:T.map((V)=>{let M=V.replace(/\.jsx$/,""),I=V===O,D=K.find((R)=>R.revision===Q)?.canvasFiles.some((R)=>R.filename===V),E=K.find((R)=>R.revision===X)?.canvasFiles.some((R)=>R.filename===V),C=!D?" (added)":!E?" (removed)":"";return f("button",{onClick:()=>S(V),className:`text-[12px] font-body px-3 py-1 rounded-md transition-colors whitespace-nowrap ${I?"bg-bg-elevated text-text-primary font-medium":"text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated"}`,children:[M,C&&f("span",{className:`ml-1 text-[10px] ${!D?"text-accent-green":"text-accent-red"}`,children:C},void 0,!1,void 0,this)]},V,!0,void 0,this)})},void 0,!1,void 0,this),!L||!j?f("div",{className:"flex-1 flex items-center justify-center",children:f("div",{className:"text-center text-text-tertiary font-body",children:[f("div",{className:"text-lg mb-2",children:!L?"New file":"Removed file"},void 0,!1,void 0,this),f("div",{className:"text-[13px]",children:[O.replace(/\.jsx$/,"")," ",!L?"was added":"was removed"," in this revision"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this):_==="unified"?f(_4,{sessionId:Y,leftRev:Q,rightRev:X,filename:O,onDiffResult:(V,M)=>{N(V),U(M)}},`unified-${Q}-${X}-${O}`,!1,void 0,this):f(z4,{sessionId:Y,leftRev:Q,rightRev:X,filename:O,onDiffResult:(V,M)=>{N(V),U(M)}},`sbs-${Q}-${X}-${O}`,!1,void 0,this)]},void 0,!0,void 0,this)}function q4(){let[J,$]=Q1(!0);return w1(()=>{return document.documentElement.dataset.syncScroll=J?"1":"0",()=>{delete document.documentElement.dataset.syncScroll}},[J]),f("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[f("input",{type:"checkbox",checked:J,onChange:(Y)=>$(Y.target.checked),className:"accent-accent-amber w-3.5 h-3.5"},void 0,!1,void 0,this),f("span",{className:"text-[11px] font-body text-text-secondary",children:"Sync scroll"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function _4({sessionId:J,leftRev:$,rightRev:Y,filename:Z,onDiffResult:Q}){let q=L1(null),X=L1(null),G=L1(null),[_,z]=Q1(!1),[H,U]=Q1(!1),[W,N]=Q1(!1),[K,T]=Q1(null),[O,S]=Q1(!1),{annotations:L}=e(),j=L.filter((M)=>!M.filePath&&(!M.canvasFile||M.canvasFile===Z)),{popovers:V}=E1({containerRef:G,restoreKey:W,restoreAnnotations:j,extractContext:(M)=>D1(M,G.current)});return w1(()=>{if(W||K)return;let M=setTimeout(()=>{console.warn("[unified-diff] still loading after 10s",{leftReady:_,rightReady:H,oldRef:!!q.current,newRef:!!X.current}),S(!0)},1e4);return()=>clearTimeout(M)},[W,K,_,H]),w1(()=>{if(!_||!H||W)return;if(!q.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!q.current||!X.current||!G.current){console.warn("[unified-diff] refs lost between rAF frames",{old:!!q.current,new:!!X.current,unified:!!G.current});return}try{let M=a1(q.current),I=a1(X.current),D=z0(M,I),{fragment:E,hasChanges:C}=m0(D);G.current.innerHTML="",G.current.appendChild(E),N(!0),Q(!0,C)}catch(M){console.error("[unified-diff] diff computation failed",M),T(M instanceof Error?M.message:String(M))}})})},[_,H,W]),f("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[!W&&!K&&f("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[f(B1,{ref:q,sessionId:J,revision:$,filename:Z,onReady:()=>z(!0),onError:(M)=>T(`Rev ${$}: ${M}`)},void 0,!1,void 0,this),f(B1,{ref:X,sessionId:J,revision:Y,filename:Z,onReady:()=>U(!0),onError:(M)=>T(`Rev ${Y}: ${M}`)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:[!W&&!K&&f("div",{className:"flex flex-col items-center justify-center h-64 text-text-tertiary font-body text-body gap-2",children:[f("span",{children:"Loading..."},void 0,!1,void 0,this),O&&f("span",{className:"text-[11px]",children:"Taking longer than expected — check Network tab for pending requests"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),K&&f("div",{className:"bg-accent-red-muted rounded-lg p-5 mt-8",children:[f("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Failed to load revision"},void 0,!1,void 0,this),f("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("div",{ref:G},void 0,!1,void 0,this)]},void 0,!0,void 0,this),V]},void 0,!0,void 0,this)}function z4({sessionId:J,leftRev:$,rightRev:Y,filename:Z,onDiffResult:Q}){let q=L1(null),X=L1(null),[G,_]=Q1(!1),[z,H]=Q1(!1),[U,W]=Q1(!1),N=L1(null),K=L1(null),T=L1(null),O=L1(!1),S=S2(()=>_(!0),[]),L=S2(()=>H(!0),[]),{annotations:j}=e(),V=j.filter((I)=>!I.filePath&&(!I.canvasFile||I.canvasFile===Z)),{popovers:M}=E1({containerRef:N,restoreKey:U,restoreAnnotations:V,extractContext:(I)=>D1(I,N.current)});return w1(()=>{if(!G||!z||U)return;if(!q.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!q.current||!X.current)return;let I=D0(q.current,X.current);W(!0),Q(!0,I)})})},[G,z,U]),w1(()=>{let I=K.current,D=T.current;if(!I||!D)return;let E=(v,m)=>{if(document.documentElement.dataset.syncScroll==="0")return;if(O.current)return;O.current=!0;let c=v.scrollHeight-v.clientHeight,y=m.scrollHeight-m.clientHeight;if(c>0&&y>0)m.scrollTop=v.scrollTop/c*y;requestAnimationFrame(()=>{O.current=!1})},C=()=>E(I,D),R=()=>E(D,I);return I.addEventListener("scroll",C),D.addEventListener("scroll",R),()=>{I.removeEventListener("scroll",C),D.removeEventListener("scroll",R)}},[]),f("div",{ref:N,className:"flex flex-1 min-h-0",children:[f("div",{ref:K,className:"w-1/2 overflow-y-auto border-r border-border-subtle",children:f("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:f(B1,{ref:q,sessionId:J,revision:$,filename:Z,onReady:S},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),f("div",{ref:T,className:"w-1/2 overflow-y-auto",children:f("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:f(B1,{ref:X,sessionId:J,revision:Y,filename:Z,onReady:L},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),M]},void 0,!0,void 0,this)}var B1=P2.memo(P2.forwardRef(({sessionId:J,revision:$,filename:Y,onReady:Z,onError:Q},q)=>{let[X,G]=Q1(null),[_,z]=Q1(null),[H,U]=Q1(!0);w1(()=>{U(!0),z(null);let N=Y.replace(/\.jsx$/,".js");import(`/api/session/${J}/canvas/${encodeURIComponent(N)}?rev=${$}&t=${Date.now()}`).then((K)=>{if(!K.default){z("Module has no default export"),U(!1),Q?.("Module has no default export");return}G(()=>K.default),U(!1)}).catch((K)=>{z(K.message),U(!1),Q?.(K.message)})},[J,$,Y]),w1(()=>{if(!X)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{Z()})})},[X]);let W=g0(()=>X?f(X,{},void 0,!1,void 0,this):null,[X]);if(H)return f("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this);if(_)return f("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[f("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Error"},void 0,!1,void 0,this),f("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:_},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!X)return f("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return f("div",{ref:q,children:W},void 0,!1,void 0,this)}));import{useState as y1,useContext as W5,useMemo as G4,useRef as G0,useEffect as A2,useCallback as w2}from"react";import{SessionContext as U4}from"#canvas/runtime";import{jsxDEV as h}from"react/jsx-dev-runtime";function N5(J,$){if(!J)return[];return J.canvasFiles.map((Y)=>{if(!Y.diffStats)return{filename:Y.filename,status:"new"};if(Y.diffStats.added===0&&Y.diffStats.removed===0)return{filename:Y.filename,status:"unchanged",diffStats:Y.diffStats};return{filename:Y.filename,status:"changed",diffStats:Y.diffStats}})}function I2(J){return J.filter(($)=>$.status!=="unchanged").map(($)=>$.filename)}function C2({revision:J,responseBanner:$}){let{setActiveView:Y}=W5(F1),{revisions:Z}=W5(N1),Q=Z.find((z)=>z.revision===J),q=Z.find((z)=>z.revision===J-1),X=G4(()=>N5(Q,q),[Q,q]),G=X.filter((z)=>z.status!=="unchanged"),_=X.filter((z)=>z.status==="unchanged");return h("div",{className:"max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[$,G.map((z)=>h(H4,{change:z,revision:J,previousRevision:q?.revision,onOpenTab:()=>Y({type:"canvas",filename:z.filename})},z.filename,!1,void 0,this)),_.length>0&&h("div",{className:"mt-8 border-t border-border-subtle pt-4",children:[h("div",{className:"text-[11px] font-body font-medium uppercase tracking-widest text-text-tertiary mb-3",children:"Unchanged"},void 0,!1,void 0,this),_.map((z)=>h(O4,{change:z,revision:J,onOpenTab:()=>Y({type:"canvas",filename:z.filename})},z.filename,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function K4({mode:J,onChange:$,showDiff:Y}){if(!Y)return null;return h("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:["rendered","unified","side-by-side"].map((Z)=>h("button",{onClick:()=>$(Z),className:`text-[10px] font-body px-2 py-0.5 rounded transition-colors ${J===Z?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:Z==="rendered"?"Full":Z==="unified"?"Unified":"Split"},Z,!1,void 0,this))},void 0,!1,void 0,this)}function H4({change:J,revision:$,previousRevision:Y,onOpenTab:Z}){let Q=J.filename.replace(/\.jsx$/,""),q=J.status==="new",X=J.diffStats,G=J.status==="changed"&&Y!=null,[_,z]=y1("rendered");return h("div",{className:"mb-8",children:[h("div",{className:"flex items-center gap-2 mb-3 pb-2 border-b border-border-subtle",children:[h("span",{className:`text-[11px] font-mono px-1.5 py-0.5 rounded ${q?"bg-accent-green/10 text-accent-green border border-accent-green/20":"bg-accent-amber/10 text-accent-amber border border-accent-amber/20"}`,children:q?"new":"modified"},void 0,!1,void 0,this),h("span",{className:"text-[14px] font-body font-medium text-text-primary",children:Q},void 0,!1,void 0,this),X&&(X.added>0||X.removed>0)&&h("span",{className:"text-[11px] font-mono text-text-tertiary",children:[h("span",{className:"text-accent-green",children:["+",X.added]},void 0,!0,void 0,this)," ",h("span",{className:"text-accent-red",children:["-",X.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),h(K4,{mode:_,onChange:z,showDiff:G},void 0,!1,void 0,this),h("button",{onClick:Z,className:`${G?"":"ml-auto"} text-[11px] font-body font-medium text-accent-blue hover:text-accent-blue/80 transition-colors`,children:"Open in tab"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),_==="rendered"?h("div",{"data-canvas-file":J.filename,children:h(Y0,{revision:$,filename:J.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this):G&&Y!=null?h(W4,{filename:J.filename,leftRev:Y,rightRev:$,mode:_},`${_}-${$}-${Y}`,!1,void 0,this):null]},void 0,!0,void 0,this)}function W4({filename:J,leftRev:$,rightRev:Y,mode:Z}){let Q=W5(U4);if(Z==="unified")return h(N4,{sessionId:Q,filename:J,leftRev:$,rightRev:Y},void 0,!1,void 0,this);return h(T4,{sessionId:Q,filename:J,leftRev:$,rightRev:Y},void 0,!1,void 0,this)}function N4({sessionId:J,filename:$,leftRev:Y,rightRev:Z}){let Q=G0(null),q=G0(null),X=G0(null),[G,_]=y1(!1),[z,H]=y1(!1),[U,W]=y1(!1),[N,K]=y1(null);return A2(()=>{if(!G||!z||U)return;if(!Q.current||!q.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Q.current||!q.current||!X.current)return;try{let T=a1(Q.current),O=a1(q.current),S=z0(T,O),{fragment:L}=m0(S);X.current.innerHTML="",X.current.appendChild(L),W(!0)}catch(T){K(T instanceof Error?T.message:String(T))}})})},[G,z,U]),h("div",{children:[!U&&!N&&h("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[h(B1,{ref:Q,sessionId:J,revision:Y,filename:$,onReady:()=>_(!0),onError:(T)=>K(T)},void 0,!1,void 0,this),h(B1,{ref:q,sessionId:J,revision:Z,filename:$,onReady:()=>H(!0),onError:(T)=>K(T)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!U&&!N&&h("div",{className:"flex items-center justify-center h-24 text-text-tertiary font-body text-[13px]",children:"Computing diff..."},void 0,!1,void 0,this),N&&h("div",{className:"text-accent-red text-[13px] font-body p-3 bg-accent-red-muted rounded-lg",children:N},void 0,!1,void 0,this),h("div",{ref:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function T4({sessionId:J,filename:$,leftRev:Y,rightRev:Z}){let Q=G0(null),q=G0(null),[X,G]=y1(!1),[_,z]=y1(!1),[H,U]=y1(!1),W=w2(()=>G(!0),[]),N=w2(()=>z(!0),[]);return A2(()=>{if(!X||!_||H)return;if(!Q.current||!q.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Q.current||!q.current)return;D0(Q.current,q.current),U(!0)})})},[X,_,H]),h("div",{className:"flex gap-0 border-y border-border-subtle overflow-hidden w-screen relative left-1/2 -translate-x-1/2",children:[h("div",{className:"w-1/2 border-r border-border-subtle",children:[h("div",{className:"px-2 py-1 text-[10px] font-body font-medium text-text-tertiary bg-bg-elevated border-b border-border-subtle",children:["Rev ",Y]},void 0,!0,void 0,this),h("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:h(B1,{ref:Q,sessionId:J,revision:Y,filename:$,onReady:W},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),h("div",{className:"w-1/2",children:[h("div",{className:"px-2 py-1 text-[10px] font-body font-medium text-text-tertiary bg-bg-elevated border-b border-border-subtle",children:["Rev ",Z]},void 0,!0,void 0,this),h("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:h(B1,{ref:q,sessionId:J,revision:Z,filename:$,onReady:N},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function O4({change:J,revision:$,onOpenTab:Y}){let[Z,Q]=y1(!1),q=J.filename.replace(/\.jsx$/,"");return h("div",{className:"mb-2",children:[h("div",{className:"flex items-center gap-2 py-1.5",children:[h("button",{onClick:()=>Q(!Z),className:"text-text-tertiary hover:text-text-secondary transition-colors",children:h("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`transition-transform duration-150 ${Z?"rotate-90":""}`,children:h("path",{d:"M3.5 2L6.5 5L3.5 8",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),h("span",{className:"text-[13px] font-body text-text-secondary",children:q},void 0,!1,void 0,this),h("button",{onClick:Y,className:"ml-auto text-[11px] font-body text-text-tertiary hover:text-accent-blue transition-colors",children:"Open in tab"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Z&&h("div",{className:"ml-5 mt-1 mb-3","data-canvas-file":J.filename,children:h(Y0,{revision:$,filename:J.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as F,Fragment as E0}from"react/jsx-dev-runtime";var F1=D2({activeView:{type:"overview"},setActiveView:()=>{},openFiles:[],closeFile:()=>{},canvasFiles:[]}),N1=D2({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{}});function y4(J){if(J==="auto")return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";return J}function R2(J){document.documentElement.dataset.theme=y4(J)}function g2(){let[J,$]=$1(()=>{let Q=localStorage.getItem("canvas-theme");if(Q==="light"||Q==="dark"||Q==="auto")return Q;return"auto"});return M1(()=>{if(R2(J),J!=="auto")return;let Q=window.matchMedia("(prefers-color-scheme: dark)"),q=()=>R2("auto");return Q.addEventListener("change",q),()=>Q.removeEventListener("change",q)},[J]),F("button",{onClick:()=>{let Q=J==="auto"?"light":J==="light"?"dark":"auto";localStorage.setItem("canvas-theme",Q),$(Q)},className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:{auto:"Theme: system (click for light)",light:"Theme: light (click for dark)",dark:"Theme: dark (click for system)"}[J],children:J==="auto"?F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"},void 0,!1,void 0,this),F("line",{x1:"8",y1:"21",x2:"16",y2:"21"},void 0,!1,void 0,this),F("line",{x1:"12",y1:"17",x2:"12",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):J==="dark"?F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"},void 0,!1,void 0,this)},void 0,!1,void 0,this):F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("circle",{cx:"12",cy:"12",r:"5"},void 0,!1,void 0,this),F("line",{x1:"12",y1:"1",x2:"12",y2:"3"},void 0,!1,void 0,this),F("line",{x1:"12",y1:"21",x2:"12",y2:"23"},void 0,!1,void 0,this),F("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"},void 0,!1,void 0,this),F("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"},void 0,!1,void 0,this),F("line",{x1:"1",y1:"12",x2:"3",y2:"12"},void 0,!1,void 0,this),F("line",{x1:"21",y1:"12",x2:"23",y2:"12"},void 0,!1,void 0,this),F("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"},void 0,!1,void 0,this),F("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function u2(){let{currentRevision:J,selectedRevision:$,revisions:Y,setSelectedRevision:Z,setCompareRevision:Q}=A1.useContext(N1);if(Y.length<=1){let G=Y[0]?.label||`Round ${J}`;return F("span",{className:"text-[11px] text-text-tertiary font-body",children:G},void 0,!1,void 0,this)}return F("div",{className:"flex flex-col gap-1",children:[F(q0,{value:$,onChange:Z,accent:$===J?"default":"amber"},void 0,!1,void 0,this),F("button",{onClick:()=>{let X;if($===J)X=[...Y].reverse().find((_)=>_.revision<J)?.revision??Math.max(1,J-1);else X=$;Q({left:X,right:J})},className:"text-[11px] font-body font-medium px-2 py-0.5 rounded-md text-accent-blue hover:bg-accent-blue-muted transition-colors self-start",children:"Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function M4(){let J=window.location.pathname.replace("/s/","")||"",[$,Y]=$1(1),[Z,Q]=$1(1),[q,X]=$1([]),[G,_]=$1(null),[z,H]=$1(!1),[U,W]=$1(!1),[N,K]=$1([]),[T,O]=$1({type:"overview"}),[S,L]=$1([]),j=I1(null),[V,M]=$1(),[I,D]=$1(!1),[E,C]=$1(!1),[R,v]=$1(!1);M1(()=>{let B=["Agent Canvas"];if(V){let b=V.replace(/\/+$/,"").split("/");B.push(b[b.length-1]||J)}else if(J)B.push(J);if(T.type==="file")B.push(T.path.split("/").pop()||T.path);else if(T.type==="overview")B.push("Overview");else if(T.type==="canvas"&&N.length>1&&T.filename)B.push(T.filename.replace(/\.jsx$/,""));else if(G)B.push("Compare");document.title=B.join(" — ")},[J,V,T,G]);let m=I1(new Map),c=q.find((B)=>B.revision===Z),y=Z!==$||!!c?.hasFeedback,P=u0((B)=>{let b=T.type==="overview"?"overview":T.type==="canvas"?`canvas:${T.filename}`:`file:${T.path}`;if(m.current.set(b,window.scrollY),O(B),B.type==="file")L((g)=>g.includes(B.path)?g:[...g,B.path])},[T]),x=u0((B)=>{m.current.delete(`file:${B}`),L((b)=>b.filter((g)=>g!==B)),O((b)=>{if(b.type==="file"&&b.path===B)return N.length>1?{type:"overview"}:{type:"canvas",filename:N[0]||""};return b})},[N]);F4(()=>{let B=T.type==="overview"?"overview":T.type==="canvas"?`canvas:${T.filename}`:`file:${T.path}`;window.scrollTo(0,m.current.get(B)||0)},[T]),M1(()=>{if(!J)return;fetch(`/api/session/${J}/meta`).then((B)=>B.json()).then((B)=>{if(B.currentRevision)Y(B.currentRevision),Q(B.currentRevision),X(B.revisions||[]);if(B.canvasFiles){let b=B.canvasFiles.sort();K(b),O((g)=>{if(g.type==="overview")return b.length>1?g:{type:"canvas",filename:b[0]||""};if(g.type==="canvas"&&(!g.filename||!b.includes(g.filename)))return{type:"canvas",filename:b[0]||""};return g})}if(B.projectRoot)M(B.projectRoot)}).catch(()=>{})},[J]),M1(()=>{if(!J)return;let B=null,b=()=>{let g=window.location.protocol==="https:"?"wss:":"ws:",o=new WebSocket(`${g}//${window.location.host}/ws/session/${J}`);j.current=o,o.onopen=()=>H(!0),o.onclose=()=>{H(!1),B=setTimeout(b,2000)},o.onmessage=(i)=>{try{let k=JSON.parse(i.data);if(k.type==="plan-updated"){if(Y(k.currentRevision),Q(k.currentRevision),_(null),k.revisions){let r=k.revisions;X(r);let A=r.find((u)=>u.revision===k.currentRevision);if(A?.canvasFiles){let u=A.canvasFiles.map((j1)=>j1.filename).sort();K(u);let s=r.find((j1)=>j1.revision===k.currentRevision-1),_1=N5(A,s),C1=I2(_1);if(C1.length===1)O({type:"canvas",filename:C1[0]});else if(C1.length>1||u.length>1)O({type:"overview"});else O({type:"canvas",filename:u[0]||""})}}}if(k.type==="revision-updated"){if(k.revisions)X(k.revisions)}}catch{}}};return b(),()=>{if(B)clearTimeout(B);j.current?.close()}},[J]);let p=u0((B)=>{if(j.current?.readyState===WebSocket.OPEN)j.current.send(JSON.stringify({type:"submit",feedback:B})),W(!1)},[]);if(!J)return F("div",{className:"flex items-center justify-center h-screen text-text-tertiary font-body",children:"No session selected."},void 0,!1,void 0,this);return F(m2.Provider,{value:J,children:F(N1.Provider,{value:{currentRevision:$,selectedRevision:Z,revisions:q,setSelectedRevision:Q,isReadOnly:y,compareRevision:G,setCompareRevision:_},children:F(D5,{sessionId:J,revision:Z,isReadOnly:y,children:F(F1.Provider,{value:{activeView:T,setActiveView:P,openFiles:S,closeFile:x,canvasFiles:N},children:F(B4.Provider,{value:{setActiveView:P},children:F("div",{className:"min-h-screen bg-bg-base",children:[F(P4,{sessionId:J,projectRoot:V,connected:z,onMobileSidebar:()=>D(!I),collapsed:E,onToggle:()=>C((B)=>!B)},void 0,!1,void 0,this),F(S4,{collapsed:R,onToggle:()=>v((B)=>!B),children:F(z5,{onPreview:()=>W(!0),onSubmit:p},void 0,!1,void 0,this)},void 0,!1,void 0,this),G!==null?F("div",{className:`${E?"lg:ml-0":"lg:ml-60"} ${R?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,children:F(b2,{initialLeft:G.left,initialRight:G.right,sessionId:J,onExit:()=>_(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):F("div",{className:`relative ${E?"lg:ml-0":"lg:ml-60"} ${R?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,id:"plan-scroll-container",children:[F("div",{className:"lg:hidden sticky top-0 z-20 flex items-center justify-between px-4 py-2 border-b border-border-subtle bg-bg-surface",children:[F("div",{className:"flex items-center gap-2",children:[F(U5,{currentSessionId:J,projectRoot:V},void 0,!1,void 0,this),F("span",{className:`w-1.5 h-1.5 rounded-full ${z?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex items-center gap-1",children:[F(u2,{},void 0,!1,void 0,this),F("button",{onClick:()=>D(!I),className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Annotations",children:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),F(g2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),F(b4,{},void 0,!1,void 0,this),T.type==="overview"&&F(C2,{revision:Z,responseBanner:c?.response?F(k2,{markdown:c.response},void 0,!1,void 0,this):void 0},void 0,!1,void 0,this),T.type==="canvas"&&N.includes(T.filename)&&F("div",{className:"relative max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[F("button",{onClick:()=>{let B=document.querySelector(`[data-canvas-file="${T.filename}"] .plan-content`);if(!B)return;let b=U2(B);navigator.clipboard.writeText(b).then(()=>{let g=document.getElementById("export-md-btn");if(g)g.setAttribute("data-copied","true"),setTimeout(()=>{g.removeAttribute("data-copied")},1500)})},id:"export-md-btn",className:"group absolute top-3 right-6 p-1.5 text-text-tertiary hover:text-text-secondary transition-colors z-10",title:"Copy as Markdown",children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"group-[[data-copied=true]]:hidden",children:[F("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"},void 0,!1,void 0,this),F("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"hidden group-[[data-copied=true]]:block text-green-500",children:F("polyline",{points:"20 6 9 17 4 12"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N.length<=1&&c?.response&&F(k2,{markdown:c.response},void 0,!1,void 0,this),F("div",{"data-canvas-file":T.filename,children:F(Y0,{revision:Z,filename:T.filename},T.filename,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),S.map((B)=>F("div",{style:{display:T.type==="file"&&T.path===B?void 0:"none"},children:F(q2,{path:B},void 0,!1,void 0,this)},B,!1,void 0,this))]},void 0,!0,void 0,this),I&&F("div",{className:"lg:hidden fixed inset-0 z-40 flex",children:[F("div",{className:"flex-1",onClick:()=>D(!1)},void 0,!1,void 0,this),F("div",{className:"w-80 max-w-[85vw] bg-bg-surface border-l border-border-subtle flex flex-col shadow-lg",children:[F("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border-subtle flex-shrink-0",children:[F("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Sidebar"},void 0,!1,void 0,this),F("button",{onClick:()=>D(!1),className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex-1 overflow-hidden",children:F(z5,{onPreview:()=>W(!0),onSubmit:p},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),F(o5,{open:U,onClose:()=>W(!1),onSubmit:p},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},`${J}:${Z}`,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function P4({sessionId:J,projectRoot:$,connected:Y,onMobileSidebar:Z,collapsed:Q,onToggle:q}){return F(E0,{children:[Q&&F("button",{onClick:q,className:"hidden lg:flex fixed top-3 left-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show sidebar",children:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),F("line",{x1:"9",y1:"3",x2:"9",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),F("div",{className:`hidden lg:flex w-60 flex-col fixed top-0 left-0 bottom-0 bg-bg-surface border-r border-border-subtle z-10 transition-transform duration-200 ${Q?"-translate-x-full":""}`,children:[F("div",{className:"px-4 pt-4 pb-3 flex-shrink-0 border-b border-border-subtle",children:[F("div",{className:"flex items-center gap-2 mb-2",children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"text-text-tertiary flex-shrink-0",children:F("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F(U5,{currentSessionId:J,projectRoot:$},void 0,!1,void 0,this),F("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${Y?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this),F("button",{onClick:q,className:"ml-auto w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide sidebar",children:F("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("polyline",{points:"11 17 6 12 11 7"},void 0,!1,void 0,this),F("polyline",{points:"18 17 13 12 18 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F(u2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex-1 flex flex-col overflow-hidden",children:F(Y2,{embedded:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("div",{className:"px-4 py-3 border-t border-border-subtle flex items-center justify-between flex-shrink-0",children:[F("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Theme"},void 0,!1,void 0,this),F(g2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function S4({children:J,collapsed:$,onToggle:Y}){let[Z,Q]=$1(()=>{let H=localStorage.getItem("canvas-sidebar-width");return H?parseInt(H,10):320}),q=I1(!1),X=I1(0),G=I1(0),_=I1(Z);_.current=Z;let z=u0((H)=>{H.preventDefault(),q.current=!0,X.current=H.clientX,G.current=_.current;let U=(N)=>{if(!q.current)return;let K=X.current-N.clientX,T=Math.max(240,Math.min(600,G.current+K));Q(T),_.current=T},W=()=>{q.current=!1,localStorage.setItem("canvas-sidebar-width",String(_.current)),document.removeEventListener("mousemove",U),document.removeEventListener("mouseup",W),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",U),document.addEventListener("mouseup",W),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);return M1(()=>{return document.documentElement.style.setProperty("--sidebar-width",`${Z}px`),()=>{document.documentElement.style.removeProperty("--sidebar-width")}},[Z]),F(E0,{children:[$&&F("button",{onClick:Y,className:"hidden lg:flex fixed top-3 right-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show annotations",children:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("div",{className:`hidden lg:flex flex-col fixed top-0 right-0 bottom-0 bg-bg-surface border-l border-border-subtle z-10 transition-transform duration-200 ${$?"translate-x-full":""}`,style:{width:Z},children:[F("div",{onMouseDown:z,className:"absolute left-0 top-0 bottom-0 w-1 cursor-col-resize hover:bg-accent-blue/30 transition-colors z-20",style:{marginLeft:"-2px"}},void 0,!1,void 0,this),A1.Children.map(J,(H)=>A1.isValidElement(H)?A1.cloneElement(H,{collapseButton:F("button",{onClick:Y,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide annotations",children:F("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("polyline",{points:"13 17 18 12 13 7"},void 0,!1,void 0,this),F("polyline",{points:"6 17 11 12 6 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}):H)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function k2({markdown:J}){let[$,Y]=$1(!1),Z=j2(()=>a.parse(J,{async:!1}),[J]),Q=I1(null),{annotations:q,addAnnotationWithId:X,removeAnnotation:G,updateAnnotation:_,addAnnotationImage:z,removeAnnotationImage:H,activeAnnotationId:U,setActiveAnnotationId:W}=e(),[N,K]=$1(null),[T,O]=$1(null),S=j2(()=>q.filter((I)=>I.filePath===q1),[q]),[L,j]=$1(J);if(J!==L)j(J),Y(!1);M1(()=>{if(!Q.current||S.length===0)return;let I=setTimeout(()=>{if(Q.current)P0(Q.current,S)},50);return()=>clearTimeout(I)},[Z,S.length]);let V=I1(null);if(M1(()=>{y0(U,V.current),V.current=U},[U]),M1(()=>{let I=Q.current;if(!I)return;let D=(R)=>{let v=R.target.closest("[data-annotation-id]");if(!v)return;R.stopPropagation();let m=v.getAttribute("data-annotation-id");if(m===U)O({anchorEl:v,annId:m});else W(m)},E=(R)=>{let v=R.target.closest("[data-annotation-id]");if(v)W(v.getAttribute("data-annotation-id"))},C=(R)=>{let v=R.target.closest("[data-annotation-id]"),m=R.relatedTarget?.closest?.("[data-annotation-id]");if(v&&!m)W(null)};return I.addEventListener("click",D),I.addEventListener("mouseover",E),I.addEventListener("mouseout",C),()=>{I.removeEventListener("click",D),I.removeEventListener("mouseover",E),I.removeEventListener("mouseout",C)}},[Z,U]),M1(()=>{let I=()=>{let D=window.getSelection();if(!D||D.isCollapsed||!D.toString().trim())return;if(!Q.current)return;let E=D.getRangeAt(0);if(!Q.current.contains(E.startContainer))return;if(E.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let C=D.toString().trim();if(C.length<2)return;let R=E.cloneRange(),v=D1(E,Q.current),m=`__pending_${Date.now()}`;try{g1(R,m)}catch{}window.getSelection()?.removeAllRanges();let c=document.querySelectorAll(`[data-annotation-id="${m}"]`),y=c[c.length-1];if(!y)return;K({anchorEl:y,tempId:m,snippet:C,ctx:v})};return document.addEventListener("mouseup",I),()=>document.removeEventListener("mouseup",I)},[]),$)return null;let M=document.getElementById("plan-scroll-container");return F("div",{className:"mb-6 rounded-lg border border-accent-blue/20 bg-accent-blue/5 relative",children:[F("button",{onClick:()=>Y(!0),className:"absolute top-2 right-2 w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:F("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("div",{className:"px-4 py-3 pr-10",children:[F("div",{className:"flex items-center gap-2 mb-1.5",children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-accent-blue flex-shrink-0",children:F("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("span",{className:"text-[11px] font-medium uppercase tracking-widest text-accent-blue font-body",children:"Agent Response"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{ref:Q,className:"prose-canvas text-sm",dangerouslySetInnerHTML:{__html:Z}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N&&F(c1,{anchorEl:N.anchorEl,scrollContainer:M,snippet:N.snippet,truncateAt:80,onAdd:(I,D)=>{let E=U1();M0(N.tempId,E),X(E,N.snippet,I,q1,N.ctx,D),K(null)},onCancel:()=>{S0(N.tempId),K(null)}},void 0,!1,void 0,this),T&&(()=>{let I=q.find((D)=>D.id===T.annId);if(!I)return null;return F(d1,{anchorEl:T.anchorEl,scrollContainer:M,initialNote:I.note,initialImages:I.images,onUpdate:(D,E)=>{_(T.annId,D);let C=I.images||[];for(let R of E)if(!C.includes(R))z(T.annId,R);for(let R of C)if(!E.includes(R))H(T.annId,R)},onDelete:()=>{G(T.annId),W(null)},onClose:()=>O(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function b4(){let{activeView:J,setActiveView:$,openFiles:Y,closeFile:Z,canvasFiles:Q}=A1.useContext(F1),q=A1.useContext(m2),{addAnnotationWithId:X,setActiveAnnotationId:G}=e();if(!(Q.length>1||Y.length>0))return null;return F("div",{className:"flex items-center border-b border-border-medium bg-bg-surface overflow-x-auto sticky top-0 z-10",children:[Q.length>1&&F(E0,{children:[F("button",{onClick:()=>$({type:"overview"}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${J.type==="overview"?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"opacity-60",children:F("path",{d:"M12 7L2 12l10 5 10-5-10-5z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Overview",J.type==="overview"&&F("span",{className:"absolute bottom-0 left-3 right-3 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q.map((z,H)=>{let U=z.replace(/\.jsx$/,""),W=J.type==="canvas"&&J.filename===z;return F(A1.Fragment,{children:[F("button",{onClick:()=>$({type:"canvas",filename:z}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${W?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[U,W&&F("span",{className:"absolute bottom-0 left-3 right-3 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H<Q.length-1&&F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},z,!0,void 0,this)}),Y.length>0&&F(E0,{children:[F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this),Y.map((z,H)=>{let U=z.split("/").pop()||z,W=J.type==="file"&&J.path===z;return F(A1.Fragment,{children:[F("div",{className:"flex items-center",children:[F("button",{onClick:()=>$({type:"file",path:z}),className:`flex items-center gap-1.5 pl-3 pr-1 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${W?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[F(P1,{name:U,type:"file"},void 0,!1,void 0,this),U,W&&F("span",{className:"absolute bottom-0 left-3 right-1 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("button",{onClick:(N)=>{N.stopPropagation(),Z(z)},className:"text-text-tertiary hover:text-text-secondary px-1.5 py-1 text-[10px] transition-colors rounded hover:bg-bg-input",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H<Y.length-1&&F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},z,!0,void 0,this)})]},void 0,!0,void 0,this),F("div",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:J.type==="file"&&F("button",{onClick:async()=>{let z=J.path;try{let U=await(await fetch(`/api/file?session=${q}&path=${encodeURIComponent(z)}`)).json();if(!U.error){let W=U.content.split(`
|
|
88
88
|
`).slice(0,3).join(`
|
|
89
|
-
`)+(
|
|
89
|
+
`)+(U.content.split(`
|
|
90
90
|
`).length>3?`
|
|
91
|
-
...`:""),
|
|
91
|
+
...`:""),N=U1();X(N,W,"",z),G(N)}}catch{}},className:"flex items-center gap-1 px-3 py-1.5 text-[11px] font-medium font-body text-text-tertiary hover:text-text-secondary whitespace-nowrap transition-colors",children:[F("span",{className:"text-[13px] leading-none",children:"+"},void 0,!1,void 0,this),"Add to context"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var V2=document.getElementById("root");if(V2)L4(V2).render(F(M4,{},void 0,!1,void 0,this));export{N1 as RevisionContext,F1 as ActiveViewContext};
|