@fabrika/builder 0.9.0-dev.12 → 0.9.0-dev.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/BUILD-CONTRACT.md +9 -3
  2. package/README.md +39 -9
  3. package/cli/src/bin.ts +14 -1
  4. package/cli/src/build-review.ts +66 -0
  5. package/cli/src/build-status.ts +41 -3
  6. package/cli/src/catalog.ts +34 -2
  7. package/cli/src/commands/advance.ts +48 -6
  8. package/cli/src/commands/build.ts +152 -15
  9. package/cli/src/commands/design.ts +34 -0
  10. package/cli/src/commands/flows.ts +32 -0
  11. package/cli/src/commands/induce.ts +2 -2
  12. package/cli/src/commands/init.ts +7 -1
  13. package/cli/src/commands/next.ts +9 -2
  14. package/cli/src/context.ts +2 -1
  15. package/cli/src/contrast.ts +301 -0
  16. package/cli/src/daemon-client.ts +29 -3
  17. package/cli/src/design-review.ts +261 -0
  18. package/cli/src/flows.ts +162 -0
  19. package/cli/src/frontmatter.ts +32 -0
  20. package/cli/src/index.ts +10 -1
  21. package/cli/src/induce.ts +61 -3
  22. package/cli/src/issues.ts +15 -29
  23. package/cli/src/layout.ts +5 -2
  24. package/cli/src/packet.ts +36 -3
  25. package/cli/src/phase-state.ts +19 -1
  26. package/cli/src/verify.ts +50 -0
  27. package/daemon/src/handlers.ts +32 -6
  28. package/daemon/src/phases.ts +7 -109
  29. package/daemon/src/platform-source.ts +8 -0
  30. package/decisions/README.md +2 -2
  31. package/decisions/patterns/cf-contract-app.md +57 -0
  32. package/decisions/technologies/bun.md +2 -1
  33. package/decisions/technologies/cf-fabrika-contract.md +45 -0
  34. package/decisions/technologies/cloudflare.md +3 -1
  35. package/decisions/technologies/oblaka.md +1 -1
  36. package/decisions/technologies/opice.md +1 -1
  37. package/decisions/technologies/react.md +1 -1
  38. package/decisions/technologies/tailwind.md +5 -5
  39. package/decisions/technologies/zerops-fabrika-auth.md +1 -1
  40. package/decisions/technologies/zerops-platform.md +1 -1
  41. package/package.json +11 -8
  42. package/shared/approvals.ts +65 -0
  43. package/shared/derive.ts +189 -0
  44. package/shared/gate.ts +20 -0
  45. package/shared/index.ts +6 -1
  46. package/shared/phases.ts +22 -20
  47. package/skill/SKILL.md +25 -16
  48. package/skill/agents/build-orchestrator.md +28 -8
  49. package/skill/agents/flows-author.md +27 -13
  50. package/skill/agents/implementer.md +3 -1
  51. package/skill/agents/opice-skeleton-author.md +8 -7
  52. package/skill/gates/brief.jsx +26 -5
  53. package/skill/gates/review-grid.jsx +3 -8
  54. package/skill/gates/tech.jsx +3 -3
  55. package/stacks/README.md +8 -2
  56. package/stacks/cf-app.md +60 -0
  57. package/stacks/cf-fat.md +1 -0
  58. package/stacks/cf-internal-app.md +2 -2
  59. package/stacks/cf-lightweight.md +3 -2
  60. package/stacks/contember-app.md +1 -0
  61. package/stacks/content-site.md +1 -0
  62. package/stacks/zerops-app.md +1 -0
  63. package/types/cli/src/bin.d.ts +1 -1
  64. package/types/cli/src/build-review.d.ts +13 -0
  65. package/types/cli/src/build-status.d.ts +16 -1
  66. package/types/cli/src/catalog.d.ts +9 -0
  67. package/types/cli/src/commands/design.d.ts +1 -0
  68. package/types/cli/src/commands/flows.d.ts +1 -0
  69. package/types/cli/src/contrast.d.ts +59 -0
  70. package/types/cli/src/daemon-client.d.ts +13 -2
  71. package/types/cli/src/design-review.d.ts +54 -0
  72. package/types/cli/src/flows.d.ts +28 -0
  73. package/types/cli/src/frontmatter.d.ts +8 -0
  74. package/types/cli/src/index.d.ts +1 -1
  75. package/types/cli/src/induce.d.ts +3 -0
  76. package/types/cli/src/issues.d.ts +4 -0
  77. package/types/cli/src/packet.d.ts +9 -1
  78. package/types/cli/src/phase-state.d.ts +1 -1
  79. package/types/cli/src/verify.d.ts +18 -0
  80. package/types/daemon/src/phases.d.ts +4 -16
  81. package/types/daemon/src/platform-remote.d.ts +6 -2
  82. package/types/shared/approvals.d.ts +32 -0
  83. package/types/shared/derive.d.ts +41 -0
  84. package/types/shared/gate.d.ts +11 -0
  85. package/types/shared/index.d.ts +105 -65
  86. package/types/shared/phases.d.ts +7 -1
  87. package/ui/dist/assets/client.css +1 -1
  88. package/ui/dist/assets/client.vn7hykcn.js +120 -0
  89. package/ui/dist/index.html +1 -1
  90. package/cli/src/derive.ts +0 -105
  91. package/skill/gates/build.jsx +0 -20
  92. package/skill/gates/design.jsx +0 -22
  93. package/skill/gates/flows.jsx +0 -14
  94. package/skill/gates/vision.jsx +0 -27
  95. package/types/cli/src/derive.d.ts +0 -17
  96. package/ui/dist/assets/client.8aw2edb7.js +0 -214
@@ -0,0 +1,120 @@
1
+ var NJ=Object.defineProperty;var LJ=($)=>$;function KJ($,J){this[$]=LJ.bind(null,J)}var MJ=($,J)=>{for(var Q in J)NJ($,Q,{get:J[Q],enumerable:!0,configurable:!0,set:KJ.bind(J,Q)})};import{createRoot as iQ}from"react-dom/client";import{useEffect as qJ,useMemo as i5,useRef as r5,useState as A1}from"react";import{useState as y6}from"react";import{AnnotationCtx as QW,AnnotationHostContext as XW,SessionContext as WW,useAnnotationHost as YW,useAnnotations as GW}from"@fabrika/annotations/runtime";function v2($,J){let Q=[],X=n5($);for(let W of X){let G=document.createRange();if(G.selectNodeContents(W),W===$.startContainer)G.setStart(W,$.startOffset);if(W===$.endContainer)G.setEnd(W,$.endOffset);let Y=G.toString();if(!Y||!Y.trim())continue;let H=document.createElement("mark");H.setAttribute("data-annotation-id",J);try{G.surroundContents(H)}catch{let q=G.extractContents();H.appendChild(q),G.insertNode(H)}Q.push(H)}return Q}function L2($){let J=$.parentElement;if(J?.classList.contains("select-none"))return!1;if(J?.closest("[data-annotation-id]"))return!1;return!0}function n5($){let J=[],Q=$.commonAncestorContainer;if(Q.nodeType===Node.TEXT_NODE)return J.push(Q),J;let X=document.createTreeWalker(Q,NodeFilter.SHOW_TEXT),W;while(W=X.nextNode()){if(!L2(W))continue;if($.intersectsNode(W))J.push(W)}return J}function FJ($,J){let Q=document.createRange();if(Q.selectNodeContents($),$===J.startContainer)Q.setStart($,J.startOffset);if($===J.endContainer)Q.setEnd($,J.endOffset);return Q.toString()}function s5($){let J="";for(let Q of n5($))J+=FJ(Q,$);return J}function k1($,J){let Q=document.querySelectorAll(`[data-annotation-id="${$}"]`);for(let X of Q)X.classList.toggle("mark-active",J)}function A$($,J){if(J!=null&&J!==$)k1(J,!1);if($!=null)k1($,!0)}function k$($,J){let Q=document.querySelectorAll(`[data-annotation-id="${$}"]`);for(let X of Q)X.setAttribute("data-annotation-id",J)}function T$($,J){for(let Q of J){if($.querySelector(`[data-annotation-id="${Q.id}"]`))continue;let X=Q.snippet;if(!X)continue;let{fullText:W,textNodes:G}=zJ($),Y=[],H=0;while(!0){let z=W.indexOf(X,H);if(z===-1)break;Y.push(z),H=z+1}let[q]=Y;if(q===void 0)continue;let U=q;if(Y.length>1&&Q.context){let z=-1;for(let _ of Y){let w=0;if(Q.context.before){let S=W.slice(Math.max(0,_-80),_);if(S.includes(Q.context.before))w+=2;else if(Q.context.before.length>10&&S.includes(Q.context.before.slice(-10)))w+=1}if(Q.context.after){let S=W.slice(_+X.length,_+X.length+80);if(S.includes(Q.context.after))w+=2;else if(Q.context.after.length>10&&S.includes(Q.context.after.slice(0,10)))w+=1}if(w>z)z=w,U=_}}let N=U,M=U+X.length,L=o5(G,N),K=o5(G,M);if(!L||!K)continue;try{let z=document.createRange();z.setStart(L.node,L.offset),z.setEnd(K.node,K.offset),v2(z,Q.id)}catch{}}}function zJ($){let J=[],Q="",X=document.createTreeWalker($,NodeFilter.SHOW_TEXT),W;while(W=X.nextNode()){if(!L2(W))continue;J.push({node:W,start:Q.length}),Q+=W.textContent||""}return{fullText:Q,textNodes:J}}function o5($,J){for(let Q=$.length-1;Q>=0;Q--){let X=$[Q];if(!X||X.start>J)continue;let W=J-X.start,G=X.node.textContent?.length??0;if(W<=G)return{node:X.node,offset:W}}return null}function D$($){let J=document.querySelectorAll(`[data-annotation-id="${$}"]`);for(let Q of J){let X=Q.parentNode;if(!X)continue;if(Q.tagName!=="MARK"){X.removeChild(Q);continue}while(Q.firstChild)X.insertBefore(Q.firstChild,Q);X.removeChild(Q),X.normalize()}}function I$($,J){let Q=t5($,"before",60),X=t5($,"after",60),W=wJ($.startContainer,J);return{before:Q,after:X,hierarchy:W}}function t5($,J,Q){let X=_J(J==="before"?$.startContainer:$.endContainer);if(!X)return"";let W="";if(J==="before"){let G=document.createTreeWalker(X,NodeFilter.SHOW_TEXT),Y;while(Y=G.nextNode()){if(Y===$.startContainer){W+=(Y.textContent||"").slice(0,$.startOffset);break}if(!L2(Y))continue;W+=Y.textContent||""}if(W.length>Q){W=W.slice(-Q);let H=W.indexOf(" ");if(H>0)W=W.slice(H+1)}}else{let G=document.createTreeWalker(X,NodeFilter.SHOW_TEXT),Y=!1,H;while(H=G.nextNode()){if(H===$.endContainer){W+=(H.textContent||"").slice($.endOffset),Y=!0;continue}if(Y){if(!L2(H))continue;W+=H.textContent||""}}if(W.length>Q){W=W.slice(0,Q);let q=W.lastIndexOf(" ");if(q>0)W=W.slice(0,q)}}return W.trim()}function _J($){let J=new Set(["DIV","P","LI","PRE","BLOCKQUOTE","SECTION","ARTICLE"]),Q=$.parentElement;while(Q){if(J.has(Q.tagName))return Q;Q=Q.parentElement}return null}function wJ($,J){let Q=[],X=$ instanceof Element?$:$.parentElement;while(X&&X!==J){let W=X.getAttribute?.("data-task-id");if(W){let Y=X.querySelector(".font-semibold");if(Y)Q.unshift(Y.textContent?.trim()||W)}let G=OJ(X);if(G)Q.unshift(G);X=X.parentElement}return Q}function OJ($){if($.getAttribute("data-md")==="section"){let Q=$.getAttribute("data-md-title");if(Q)return Q}if($.tagName!=="DIV")return null;return $.querySelector(":scope > button > .font-heading, :scope > div > .font-heading")?.textContent?.trim()||null}function h2($){let J=$.snippet.trim(),Q=$.context,X=J.length<30;if(Q&&X&&(Q.before||Q.after)){let W=[];if(Q.before)W.push(`...${Q.before} `);if(W.push(`**${J}**`),Q.after)W.push(` ${Q.after}...`);return W.join("")}return J}function K2($){return{kind:$.kind,owns:(J)=>$.parse(J)!==null,find:(J,Q)=>{let X=$.parse(J);return X===null?null:$.find(X,Q)},restore:(J,Q)=>{let X=$.parse(Q.snippet);if(X===null)return;$.restore?.(X,J,Q)},describe:(J)=>{let Q=$.parse(J);if(Q===null||!$.describe)return null;return $.describe(Q)}}}function a5($){let J=document.createTreeWalker($,NodeFilter.SHOW_TEXT),Q="";for(let X=J.nextNode();X;X=J.nextNode()){let W=X.parentElement?.closest("[aria-hidden='true']");if(W&&$.contains(W))continue;Q+=X.textContent??""}return Q.trim()}function m2($,J,Q){return{selector:$,snippet:(X)=>{let W=X.getAttribute(Q);return W?`${J} ${W}`:null}}}var b$=[m2("[data-md='item']","[Item]","data-md-label"),m2("[data-md='section']","[Section]","data-md-title"),m2("[data-md='checklist-item']","[Checklist]","data-md-label"),m2("[data-md='image']","[Image]","data-md-src"),{selector:"[data-md='callout']",snippet:($)=>{return`[Callout:${$.getAttribute("data-md-type")||"info"}] ${a5($).slice(0,60)||"Callout"}`}},{selector:"[data-md='note']",snippet:($)=>`[Note] ${a5($).slice(0,60)||"Note"}`},{selector:"[data-md='table'] tbody tr",snippet:($)=>{let J=Array.from($.querySelectorAll("td")).map((Q)=>Q.textContent?.trim()).filter(Boolean);return J.length?`[Row] ${J.join(" | ")}`:null}}],SJ=["[data-md='choice-option']","[data-md='multichoice-option']","[data-md='userinput']","[data-md='rangeinput']"],$1=b$.map(($)=>$.selector).join(", "),T1=[...b$.map(($)=>$.selector),...SJ].join(", ");function u0($){for(let J of b$)if($.matches(J.selector))return J.snippet($);return null}var g$={kind:"block",parse:($)=>$.startsWith("[")?{snippet:$}:null,format:($)=>$.snippet,find:($,J)=>{for(let Q of J.querySelectorAll($1)){if(!(Q instanceof HTMLElement))continue;if(u0(Q)===$.snippet)return Q}return null}};var y$="data-annotation-image",RJ=/^\[Region:(rect|ellipse)\] ([\s\S]+) @(0|[1-9]\d*),(0|[1-9]\d*),(0|[1-9]\d*),(0|[1-9]\d*)$/;function CJ($){if($==="rect")return"rect";if($==="ellipse")return"ellipse";return null}function u2($){if($===void 0)return null;let J=Number($);if(!Number.isInteger(J)||J<0||J>1e4)return null;return J}function e5($){return Math.min(1e4,Math.max(0,$))}function x$($,J,Q){if(!($.width>0)||!($.height>0))return null;return{x:e5(Math.round(J/$.width*1e4)),y:e5(Math.round(Q/$.height*1e4))}}function p2($,J){let Q=Math.min($.x,J.x),X=Math.min($.y,J.y);return{x:Q,y:X,w:Math.min(1e4-Q,Math.abs($.x-J.x)),h:Math.min(1e4-X,Math.abs($.y-J.y))}}function v$($){return $.w>=30&&$.h>=30}function $4($){return{left:`${$.x/100}%`,top:`${$.y/100}%`,width:`${$.w/100}%`,height:`${$.h/100}%`}}function c2($){return`${($/100).toFixed(1).replace(/\.0$/,"")}%`}function l2($){let J=`${c2($.x)}-${c2($.x+$.w)}`,Q=`${c2($.y)}-${c2($.y+$.h)}`;return`[Region] ${$.src} — ${$.shape} x ${J}, y ${Q} of the image`}function E$($,J){for(let Q of J.querySelectorAll("[data-md='image']")){if(!(Q instanceof HTMLElement))continue;if(Q.getAttribute("data-md-src")!==$)continue;let X=Q.querySelector("[data-annotation-image]");if(X instanceof HTMLElement)return X}return null}function d2($,J){let Q=$4(J);$.style.left=Q.left,$.style.top=Q.top,$.style.width=Q.width,$.style.height=Q.height}function i2($,J,Q){let X=document.createElement("div");return X.className="ann-region",X.setAttribute("data-annotation-id",Q),X.setAttribute("data-annotation-region",J),d2(X,$),X}var M2={kind:"region",parse:($)=>{let J=RJ.exec($);if(!J)return null;let Q=CJ(J[1]),X=J[2],W=u2(J[3]),G=u2(J[4]),Y=u2(J[5]),H=u2(J[6]);if(Q===null||X===void 0)return null;if(W===null||G===null||Y===null||H===null)return null;if(Y<1||H<1)return null;return{src:X,shape:Q,x:W,y:G,w:Y,h:H}},format:($)=>`[Region:${$.shape}] ${$.src} @${$.x},${$.y},${$.w},${$.h}`,find:($,J)=>E$($.src,J),restore:($,J,Q)=>{if(J.querySelector(`[data-annotation-id="${Q.id}"]`))return;let X=E$($.src,J);if(!X)return;X.appendChild(i2($,$.shape,Q.id))},describe:l2};var h$={kind:"text",parse:($)=>$?{text:$}:null,format:($)=>$.text,find:()=>null,restore:($,J,Q)=>{T$(J,[Q])}};var r2=[K2(M2),K2(g$),K2(h$)];function m$($,J){for(let Q of r2){let X=Q.find($,J);if(X)return X}return null}function u$($,J){for(let Q of J){if(!Q.snippet)continue;for(let X of r2)X.restore($,Q)}}function F2($){for(let J of r2){let Q=J.describe($);if(Q!==null)return Q}return $}import{AnnotationCtx as c7,SessionContext as p7,useAnnotationHost as l7}from"@fabrika/annotations/runtime";import{useEffect as r7,useRef as o7,useState as n7}from"react";var B={};MJ(B,{void:()=>G8,util:()=>n,unknown:()=>W8,union:()=>U8,undefined:()=>J8,tuple:()=>K8,transformer:()=>P8,symbol:()=>$8,string:()=>B4,strictObject:()=>B8,setErrorMap:()=>jJ,set:()=>z8,record:()=>M8,quotelessJson:()=>PJ,promise:()=>C8,preprocess:()=>Z8,pipeline:()=>V8,ostring:()=>A8,optional:()=>f8,onumber:()=>k8,oboolean:()=>T8,objectUtil:()=>c$,object:()=>H8,number:()=>U4,nullable:()=>j8,null:()=>Q8,never:()=>Y8,nativeEnum:()=>R8,nan:()=>tJ,map:()=>F8,makeIssue:()=>z2,literal:()=>O8,lazy:()=>w8,late:()=>nJ,isValid:()=>J1,isDirty:()=>n2,isAsync:()=>I1,isAborted:()=>o2,intersection:()=>L8,instanceof:()=>sJ,getParsedType:()=>c0,getErrorMap:()=>D1,function:()=>_8,enum:()=>S8,effect:()=>P8,discriminatedUnion:()=>N8,defaultErrorMap:()=>o0,datetimeRegex:()=>G4,date:()=>eJ,custom:()=>H4,coerce:()=>D8,boolean:()=>N4,bigint:()=>aJ,array:()=>q8,any:()=>X8,addIssueToContext:()=>f,ZodVoid:()=>w2,ZodUnknown:()=>Q1,ZodUnion:()=>v1,ZodUndefined:()=>y1,ZodType:()=>o,ZodTuple:()=>l0,ZodTransformer:()=>y0,ZodSymbol:()=>_2,ZodString:()=>I0,ZodSet:()=>F1,ZodSchema:()=>o,ZodRecord:()=>O2,ZodReadonly:()=>d1,ZodPromise:()=>z1,ZodPipeline:()=>C2,ZodParsedType:()=>C,ZodOptional:()=>g0,ZodObject:()=>U0,ZodNumber:()=>X1,ZodNullable:()=>s0,ZodNull:()=>x1,ZodNever:()=>p0,ZodNativeEnum:()=>c1,ZodNaN:()=>R2,ZodMap:()=>S2,ZodLiteral:()=>u1,ZodLazy:()=>m1,ZodIssueCode:()=>R,ZodIntersection:()=>h1,ZodFunction:()=>g1,ZodFirstPartyTypeKind:()=>m,ZodError:()=>f0,ZodEnum:()=>Y1,ZodEffects:()=>y0,ZodDiscriminatedUnion:()=>s2,ZodDefault:()=>p1,ZodDate:()=>K1,ZodCatch:()=>l1,ZodBranded:()=>t2,ZodBoolean:()=>E1,ZodBigInt:()=>W1,ZodArray:()=>b0,ZodAny:()=>M1,Schema:()=>o,ParseStatus:()=>O0,OK:()=>R0,NEVER:()=>I8,INVALID:()=>v,EMPTY_PATH:()=>ZJ,DIRTY:()=>L1,BRAND:()=>oJ});var n;(function($){$.assertEqual=(W)=>{};function J(W){}$.assertIs=J;function Q(W){throw Error()}$.assertNever=Q,$.arrayToEnum=(W)=>{let G={};for(let Y of W)G[Y]=Y;return G},$.getValidEnumValues=(W)=>{let G=$.objectKeys(W).filter((H)=>typeof W[W[H]]!=="number"),Y={};for(let H of G)Y[H]=W[H];return $.objectValues(Y)},$.objectValues=(W)=>{return $.objectKeys(W).map(function(G){return W[G]})},$.objectKeys=typeof Object.keys==="function"?(W)=>Object.keys(W):(W)=>{let G=[];for(let Y in W)if(Object.prototype.hasOwnProperty.call(W,Y))G.push(Y);return G},$.find=(W,G)=>{for(let Y of W)if(G(Y))return Y;return},$.isInteger=typeof Number.isInteger==="function"?(W)=>Number.isInteger(W):(W)=>typeof W==="number"&&Number.isFinite(W)&&Math.floor(W)===W;function X(W,G=" | "){return W.map((Y)=>typeof Y==="string"?`'${Y}'`:Y).join(G)}$.joinValues=X,$.jsonStringifyReplacer=(W,G)=>{if(typeof G==="bigint")return G.toString();return G}})(n||(n={}));var c$;(function($){$.mergeShapes=(J,Q)=>{return{...J,...Q}}})(c$||(c$={}));var C=n.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),c0=($)=>{switch(typeof $){case"undefined":return C.undefined;case"string":return C.string;case"number":return Number.isNaN($)?C.nan:C.number;case"boolean":return C.boolean;case"function":return C.function;case"bigint":return C.bigint;case"symbol":return C.symbol;case"object":if(Array.isArray($))return C.array;if($===null)return C.null;if($.then&&typeof $.then==="function"&&$.catch&&typeof $.catch==="function")return C.promise;if(typeof Map<"u"&&$ instanceof Map)return C.map;if(typeof Set<"u"&&$ instanceof Set)return C.set;if(typeof Date<"u"&&$ instanceof Date)return C.date;return C.object;default:return C.unknown}};var R=n.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),PJ=($)=>{return JSON.stringify($,null,2).replace(/"([^"]+)":/g,"$1:")};class f0 extends Error{get errors(){return this.issues}constructor($){super();this.issues=[],this.addIssue=(Q)=>{this.issues=[...this.issues,Q]},this.addIssues=(Q=[])=>{this.issues=[...this.issues,...Q]};let J=new.target.prototype;if(Object.setPrototypeOf)Object.setPrototypeOf(this,J);else this.__proto__=J;this.name="ZodError",this.issues=$}format($){let J=$||function(W){return W.message},Q={_errors:[]},X=(W)=>{for(let G of W.issues)if(G.code==="invalid_union")G.unionErrors.map(X);else if(G.code==="invalid_return_type")X(G.returnTypeError);else if(G.code==="invalid_arguments")X(G.argumentsError);else if(G.path.length===0)Q._errors.push(J(G));else{let Y=Q,H=0;while(H<G.path.length){let q=G.path[H];if(H!==G.path.length-1)Y[q]=Y[q]||{_errors:[]};else Y[q]=Y[q]||{_errors:[]},Y[q]._errors.push(J(G));Y=Y[q],H++}}};return X(this),Q}static assert($){if(!($ instanceof f0))throw Error(`Not a ZodError: ${$}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,n.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten($=(J)=>J.message){let J={},Q=[];for(let X of this.issues)if(X.path.length>0){let W=X.path[0];J[W]=J[W]||[],J[W].push($(X))}else Q.push($(X));return{formErrors:Q,fieldErrors:J}}get formErrors(){return this.flatten()}}f0.create=($)=>{return new f0($)};var fJ=($,J)=>{let Q;switch($.code){case R.invalid_type:if($.received===C.undefined)Q="Required";else Q=`Expected ${$.expected}, received ${$.received}`;break;case R.invalid_literal:Q=`Invalid literal value, expected ${JSON.stringify($.expected,n.jsonStringifyReplacer)}`;break;case R.unrecognized_keys:Q=`Unrecognized key(s) in object: ${n.joinValues($.keys,", ")}`;break;case R.invalid_union:Q="Invalid input";break;case R.invalid_union_discriminator:Q=`Invalid discriminator value. Expected ${n.joinValues($.options)}`;break;case R.invalid_enum_value:Q=`Invalid enum value. Expected ${n.joinValues($.options)}, received '${$.received}'`;break;case R.invalid_arguments:Q="Invalid function arguments";break;case R.invalid_return_type:Q="Invalid function return type";break;case R.invalid_date:Q="Invalid date";break;case R.invalid_string:if(typeof $.validation==="object")if("includes"in $.validation){if(Q=`Invalid input: must include "${$.validation.includes}"`,typeof $.validation.position==="number")Q=`${Q} at one or more positions greater than or equal to ${$.validation.position}`}else if("startsWith"in $.validation)Q=`Invalid input: must start with "${$.validation.startsWith}"`;else if("endsWith"in $.validation)Q=`Invalid input: must end with "${$.validation.endsWith}"`;else n.assertNever($.validation);else if($.validation!=="regex")Q=`Invalid ${$.validation}`;else Q="Invalid";break;case R.too_small:if($.type==="array")Q=`Array must contain ${$.exact?"exactly":$.inclusive?"at least":"more than"} ${$.minimum} element(s)`;else if($.type==="string")Q=`String must contain ${$.exact?"exactly":$.inclusive?"at least":"over"} ${$.minimum} character(s)`;else if($.type==="number")Q=`Number must be ${$.exact?"exactly equal to ":$.inclusive?"greater than or equal to ":"greater than "}${$.minimum}`;else if($.type==="bigint")Q=`Number must be ${$.exact?"exactly equal to ":$.inclusive?"greater than or equal to ":"greater than "}${$.minimum}`;else if($.type==="date")Q=`Date must be ${$.exact?"exactly equal to ":$.inclusive?"greater than or equal to ":"greater than "}${new Date(Number($.minimum))}`;else Q="Invalid input";break;case R.too_big:if($.type==="array")Q=`Array must contain ${$.exact?"exactly":$.inclusive?"at most":"less than"} ${$.maximum} element(s)`;else if($.type==="string")Q=`String must contain ${$.exact?"exactly":$.inclusive?"at most":"under"} ${$.maximum} character(s)`;else if($.type==="number")Q=`Number must be ${$.exact?"exactly":$.inclusive?"less than or equal to":"less than"} ${$.maximum}`;else if($.type==="bigint")Q=`BigInt must be ${$.exact?"exactly":$.inclusive?"less than or equal to":"less than"} ${$.maximum}`;else if($.type==="date")Q=`Date must be ${$.exact?"exactly":$.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number($.maximum))}`;else Q="Invalid input";break;case R.custom:Q="Invalid input";break;case R.invalid_intersection_types:Q="Intersection results could not be merged";break;case R.not_multiple_of:Q=`Number must be a multiple of ${$.multipleOf}`;break;case R.not_finite:Q="Number must be finite";break;default:Q=J.defaultError,n.assertNever($)}return{message:Q}},o0=fJ;var J4=o0;function jJ($){J4=$}function D1(){return J4}var z2=($)=>{let{data:J,path:Q,errorMaps:X,issueData:W}=$,G=[...Q,...W.path||[]],Y={...W,path:G};if(W.message!==void 0)return{...W,path:G,message:W.message};let H="",q=X.filter((U)=>!!U).slice().reverse();for(let U of q)H=U(Y,{data:J,defaultError:H}).message;return{...W,path:G,message:H}},ZJ=[];function f($,J){let Q=D1(),X=z2({issueData:J,data:$.data,path:$.path,errorMaps:[$.common.contextualErrorMap,$.schemaErrorMap,Q,Q===o0?void 0:o0].filter((W)=>!!W)});$.common.issues.push(X)}class O0{constructor(){this.value="valid"}dirty(){if(this.value==="valid")this.value="dirty"}abort(){if(this.value!=="aborted")this.value="aborted"}static mergeArray($,J){let Q=[];for(let X of J){if(X.status==="aborted")return v;if(X.status==="dirty")$.dirty();Q.push(X.value)}return{status:$.value,value:Q}}static async mergeObjectAsync($,J){let Q=[];for(let X of J){let W=await X.key,G=await X.value;Q.push({key:W,value:G})}return O0.mergeObjectSync($,Q)}static mergeObjectSync($,J){let Q={};for(let X of J){let{key:W,value:G}=X;if(W.status==="aborted")return v;if(G.status==="aborted")return v;if(W.status==="dirty")$.dirty();if(G.status==="dirty")$.dirty();if(W.value!=="__proto__"&&(typeof G.value<"u"||X.alwaysSet))Q[W.value]=G.value}return{status:$.value,value:Q}}}var v=Object.freeze({status:"aborted"}),L1=($)=>({status:"dirty",value:$}),R0=($)=>({status:"valid",value:$}),o2=($)=>$.status==="aborted",n2=($)=>$.status==="dirty",J1=($)=>$.status==="valid",I1=($)=>typeof Promise<"u"&&$ instanceof Promise;var D;(function($){$.errToObj=(J)=>typeof J==="string"?{message:J}:J||{},$.toString=(J)=>typeof J==="string"?J:J?.message})(D||(D={}));class E0{constructor($,J,Q,X){this._cachedPath=[],this.parent=$,this.data=J,this._path=Q,this._key=X}get path(){if(!this._cachedPath.length)if(Array.isArray(this._key))this._cachedPath.push(...this._path,...this._key);else this._cachedPath.push(...this._path,this._key);return this._cachedPath}}var Q4=($,J)=>{if(J1(J))return{success:!0,data:J.value};else{if(!$.common.issues.length)throw Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;let Q=new f0($.common.issues);return this._error=Q,this._error}}}};function l($){if(!$)return{};let{errorMap:J,invalid_type_error:Q,required_error:X,description:W}=$;if(J&&(Q||X))throw Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);if(J)return{errorMap:J,description:W};return{errorMap:(Y,H)=>{let{message:q}=$;if(Y.code==="invalid_enum_value")return{message:q??H.defaultError};if(typeof H.data>"u")return{message:q??X??H.defaultError};if(Y.code!=="invalid_type")return{message:H.defaultError};return{message:q??Q??H.defaultError}},description:W}}class o{get description(){return this._def.description}_getType($){return c0($.data)}_getOrReturnCtx($,J){return J||{common:$.parent.common,data:$.data,parsedType:c0($.data),schemaErrorMap:this._def.errorMap,path:$.path,parent:$.parent}}_processInputParams($){return{status:new O0,ctx:{common:$.parent.common,data:$.data,parsedType:c0($.data),schemaErrorMap:this._def.errorMap,path:$.path,parent:$.parent}}}_parseSync($){let J=this._parse($);if(I1(J))throw Error("Synchronous parse encountered promise.");return J}_parseAsync($){let J=this._parse($);return Promise.resolve(J)}parse($,J){let Q=this.safeParse($,J);if(Q.success)return Q.data;throw Q.error}safeParse($,J){let Q={common:{issues:[],async:J?.async??!1,contextualErrorMap:J?.errorMap},path:J?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:$,parsedType:c0($)},X=this._parseSync({data:$,path:Q.path,parent:Q});return Q4(Q,X)}"~validate"($){let J={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:$,parsedType:c0($)};if(!this["~standard"].async)try{let Q=this._parseSync({data:$,path:[],parent:J});return J1(Q)?{value:Q.value}:{issues:J.common.issues}}catch(Q){if(Q?.message?.toLowerCase()?.includes("encountered"))this["~standard"].async=!0;J.common={issues:[],async:!0}}return this._parseAsync({data:$,path:[],parent:J}).then((Q)=>J1(Q)?{value:Q.value}:{issues:J.common.issues})}async parseAsync($,J){let Q=await this.safeParseAsync($,J);if(Q.success)return Q.data;throw Q.error}async safeParseAsync($,J){let Q={common:{issues:[],contextualErrorMap:J?.errorMap,async:!0},path:J?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:$,parsedType:c0($)},X=this._parse({data:$,path:Q.path,parent:Q}),W=await(I1(X)?X:Promise.resolve(X));return Q4(Q,W)}refine($,J){let Q=(X)=>{if(typeof J==="string"||typeof J>"u")return{message:J};else if(typeof J==="function")return J(X);else return J};return this._refinement((X,W)=>{let G=$(X),Y=()=>W.addIssue({code:R.custom,...Q(X)});if(typeof Promise<"u"&&G instanceof Promise)return G.then((H)=>{if(!H)return Y(),!1;else return!0});if(!G)return Y(),!1;else return!0})}refinement($,J){return this._refinement((Q,X)=>{if(!$(Q))return X.addIssue(typeof J==="function"?J(Q,X):J),!1;else return!0})}_refinement($){return new y0({schema:this,typeName:m.ZodEffects,effect:{type:"refinement",refinement:$}})}superRefine($){return this._refinement($)}constructor($){this.spa=this.safeParseAsync,this._def=$,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:(J)=>this["~validate"](J)}}optional(){return g0.create(this,this._def)}nullable(){return s0.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return b0.create(this)}promise(){return z1.create(this,this._def)}or($){return v1.create([this,$],this._def)}and($){return h1.create(this,$,this._def)}transform($){return new y0({...l(this._def),schema:this,typeName:m.ZodEffects,effect:{type:"transform",transform:$}})}default($){let J=typeof $==="function"?$:()=>$;return new p1({...l(this._def),innerType:this,defaultValue:J,typeName:m.ZodDefault})}brand(){return new t2({typeName:m.ZodBranded,type:this,...l(this._def)})}catch($){let J=typeof $==="function"?$:()=>$;return new l1({...l(this._def),innerType:this,catchValue:J,typeName:m.ZodCatch})}describe($){return new this.constructor({...this._def,description:$})}pipe($){return C2.create(this,$)}readonly(){return d1.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}var VJ=/^c[^\s-]{8,}$/i,AJ=/^[0-9a-z]+$/,kJ=/^[0-9A-HJKMNP-TV-Z]{26}$/i,TJ=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,DJ=/^[a-z0-9_-]{21}$/i,IJ=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,bJ=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,gJ=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,EJ="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",p$,yJ=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,xJ=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,vJ=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,hJ=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,mJ=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,uJ=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,W4="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",cJ=new RegExp(`^${W4}$`);function Y4($){let J="[0-5]\\d";if($.precision)J=`${J}\\.\\d{${$.precision}}`;else if($.precision==null)J=`${J}(\\.\\d+)?`;let Q=$.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${J})${Q}`}function pJ($){return new RegExp(`^${Y4($)}$`)}function G4($){let J=`${W4}T${Y4($)}`,Q=[];if(Q.push($.local?"Z?":"Z"),$.offset)Q.push("([+-]\\d{2}:?\\d{2})");return J=`${J}(${Q.join("|")})`,new RegExp(`^${J}$`)}function lJ($,J){if((J==="v4"||!J)&&yJ.test($))return!0;if((J==="v6"||!J)&&vJ.test($))return!0;return!1}function dJ($,J){if(!IJ.test($))return!1;try{let[Q]=$.split(".");if(!Q)return!1;let X=Q.replace(/-/g,"+").replace(/_/g,"/").padEnd(Q.length+(4-Q.length%4)%4,"="),W=JSON.parse(atob(X));if(typeof W!=="object"||W===null)return!1;if("typ"in W&&W?.typ!=="JWT")return!1;if(!W.alg)return!1;if(J&&W.alg!==J)return!1;return!0}catch{return!1}}function iJ($,J){if((J==="v4"||!J)&&xJ.test($))return!0;if((J==="v6"||!J)&&hJ.test($))return!0;return!1}class I0 extends o{_parse($){if(this._def.coerce)$.data=String($.data);if(this._getType($)!==C.string){let W=this._getOrReturnCtx($);return f(W,{code:R.invalid_type,expected:C.string,received:W.parsedType}),v}let Q=new O0,X=void 0;for(let W of this._def.checks)if(W.kind==="min"){if($.data.length<W.value)X=this._getOrReturnCtx($,X),f(X,{code:R.too_small,minimum:W.value,type:"string",inclusive:!0,exact:!1,message:W.message}),Q.dirty()}else if(W.kind==="max"){if($.data.length>W.value)X=this._getOrReturnCtx($,X),f(X,{code:R.too_big,maximum:W.value,type:"string",inclusive:!0,exact:!1,message:W.message}),Q.dirty()}else if(W.kind==="length"){let G=$.data.length>W.value,Y=$.data.length<W.value;if(G||Y){if(X=this._getOrReturnCtx($,X),G)f(X,{code:R.too_big,maximum:W.value,type:"string",inclusive:!0,exact:!0,message:W.message});else if(Y)f(X,{code:R.too_small,minimum:W.value,type:"string",inclusive:!0,exact:!0,message:W.message});Q.dirty()}}else if(W.kind==="email"){if(!gJ.test($.data))X=this._getOrReturnCtx($,X),f(X,{validation:"email",code:R.invalid_string,message:W.message}),Q.dirty()}else if(W.kind==="emoji"){if(!p$)p$=new RegExp(EJ,"u");if(!p$.test($.data))X=this._getOrReturnCtx($,X),f(X,{validation:"emoji",code:R.invalid_string,message:W.message}),Q.dirty()}else if(W.kind==="uuid"){if(!TJ.test($.data))X=this._getOrReturnCtx($,X),f(X,{validation:"uuid",code:R.invalid_string,message:W.message}),Q.dirty()}else if(W.kind==="nanoid"){if(!DJ.test($.data))X=this._getOrReturnCtx($,X),f(X,{validation:"nanoid",code:R.invalid_string,message:W.message}),Q.dirty()}else if(W.kind==="cuid"){if(!VJ.test($.data))X=this._getOrReturnCtx($,X),f(X,{validation:"cuid",code:R.invalid_string,message:W.message}),Q.dirty()}else if(W.kind==="cuid2"){if(!AJ.test($.data))X=this._getOrReturnCtx($,X),f(X,{validation:"cuid2",code:R.invalid_string,message:W.message}),Q.dirty()}else if(W.kind==="ulid"){if(!kJ.test($.data))X=this._getOrReturnCtx($,X),f(X,{validation:"ulid",code:R.invalid_string,message:W.message}),Q.dirty()}else if(W.kind==="url")try{new URL($.data)}catch{X=this._getOrReturnCtx($,X),f(X,{validation:"url",code:R.invalid_string,message:W.message}),Q.dirty()}else if(W.kind==="regex"){if(W.regex.lastIndex=0,!W.regex.test($.data))X=this._getOrReturnCtx($,X),f(X,{validation:"regex",code:R.invalid_string,message:W.message}),Q.dirty()}else if(W.kind==="trim")$.data=$.data.trim();else if(W.kind==="includes"){if(!$.data.includes(W.value,W.position))X=this._getOrReturnCtx($,X),f(X,{code:R.invalid_string,validation:{includes:W.value,position:W.position},message:W.message}),Q.dirty()}else if(W.kind==="toLowerCase")$.data=$.data.toLowerCase();else if(W.kind==="toUpperCase")$.data=$.data.toUpperCase();else if(W.kind==="startsWith"){if(!$.data.startsWith(W.value))X=this._getOrReturnCtx($,X),f(X,{code:R.invalid_string,validation:{startsWith:W.value},message:W.message}),Q.dirty()}else if(W.kind==="endsWith"){if(!$.data.endsWith(W.value))X=this._getOrReturnCtx($,X),f(X,{code:R.invalid_string,validation:{endsWith:W.value},message:W.message}),Q.dirty()}else if(W.kind==="datetime"){if(!G4(W).test($.data))X=this._getOrReturnCtx($,X),f(X,{code:R.invalid_string,validation:"datetime",message:W.message}),Q.dirty()}else if(W.kind==="date"){if(!cJ.test($.data))X=this._getOrReturnCtx($,X),f(X,{code:R.invalid_string,validation:"date",message:W.message}),Q.dirty()}else if(W.kind==="time"){if(!pJ(W).test($.data))X=this._getOrReturnCtx($,X),f(X,{code:R.invalid_string,validation:"time",message:W.message}),Q.dirty()}else if(W.kind==="duration"){if(!bJ.test($.data))X=this._getOrReturnCtx($,X),f(X,{validation:"duration",code:R.invalid_string,message:W.message}),Q.dirty()}else if(W.kind==="ip"){if(!lJ($.data,W.version))X=this._getOrReturnCtx($,X),f(X,{validation:"ip",code:R.invalid_string,message:W.message}),Q.dirty()}else if(W.kind==="jwt"){if(!dJ($.data,W.alg))X=this._getOrReturnCtx($,X),f(X,{validation:"jwt",code:R.invalid_string,message:W.message}),Q.dirty()}else if(W.kind==="cidr"){if(!iJ($.data,W.version))X=this._getOrReturnCtx($,X),f(X,{validation:"cidr",code:R.invalid_string,message:W.message}),Q.dirty()}else if(W.kind==="base64"){if(!mJ.test($.data))X=this._getOrReturnCtx($,X),f(X,{validation:"base64",code:R.invalid_string,message:W.message}),Q.dirty()}else if(W.kind==="base64url"){if(!uJ.test($.data))X=this._getOrReturnCtx($,X),f(X,{validation:"base64url",code:R.invalid_string,message:W.message}),Q.dirty()}else n.assertNever(W);return{status:Q.value,value:$.data}}_regex($,J,Q){return this.refinement((X)=>$.test(X),{validation:J,code:R.invalid_string,...D.errToObj(Q)})}_addCheck($){return new I0({...this._def,checks:[...this._def.checks,$]})}email($){return this._addCheck({kind:"email",...D.errToObj($)})}url($){return this._addCheck({kind:"url",...D.errToObj($)})}emoji($){return this._addCheck({kind:"emoji",...D.errToObj($)})}uuid($){return this._addCheck({kind:"uuid",...D.errToObj($)})}nanoid($){return this._addCheck({kind:"nanoid",...D.errToObj($)})}cuid($){return this._addCheck({kind:"cuid",...D.errToObj($)})}cuid2($){return this._addCheck({kind:"cuid2",...D.errToObj($)})}ulid($){return this._addCheck({kind:"ulid",...D.errToObj($)})}base64($){return this._addCheck({kind:"base64",...D.errToObj($)})}base64url($){return this._addCheck({kind:"base64url",...D.errToObj($)})}jwt($){return this._addCheck({kind:"jwt",...D.errToObj($)})}ip($){return this._addCheck({kind:"ip",...D.errToObj($)})}cidr($){return this._addCheck({kind:"cidr",...D.errToObj($)})}datetime($){if(typeof $==="string")return this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:$});return this._addCheck({kind:"datetime",precision:typeof $?.precision>"u"?null:$?.precision,offset:$?.offset??!1,local:$?.local??!1,...D.errToObj($?.message)})}date($){return this._addCheck({kind:"date",message:$})}time($){if(typeof $==="string")return this._addCheck({kind:"time",precision:null,message:$});return this._addCheck({kind:"time",precision:typeof $?.precision>"u"?null:$?.precision,...D.errToObj($?.message)})}duration($){return this._addCheck({kind:"duration",...D.errToObj($)})}regex($,J){return this._addCheck({kind:"regex",regex:$,...D.errToObj(J)})}includes($,J){return this._addCheck({kind:"includes",value:$,position:J?.position,...D.errToObj(J?.message)})}startsWith($,J){return this._addCheck({kind:"startsWith",value:$,...D.errToObj(J)})}endsWith($,J){return this._addCheck({kind:"endsWith",value:$,...D.errToObj(J)})}min($,J){return this._addCheck({kind:"min",value:$,...D.errToObj(J)})}max($,J){return this._addCheck({kind:"max",value:$,...D.errToObj(J)})}length($,J){return this._addCheck({kind:"length",value:$,...D.errToObj(J)})}nonempty($){return this.min(1,D.errToObj($))}trim(){return new I0({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new I0({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new I0({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(($)=>$.kind==="datetime")}get isDate(){return!!this._def.checks.find(($)=>$.kind==="date")}get isTime(){return!!this._def.checks.find(($)=>$.kind==="time")}get isDuration(){return!!this._def.checks.find(($)=>$.kind==="duration")}get isEmail(){return!!this._def.checks.find(($)=>$.kind==="email")}get isURL(){return!!this._def.checks.find(($)=>$.kind==="url")}get isEmoji(){return!!this._def.checks.find(($)=>$.kind==="emoji")}get isUUID(){return!!this._def.checks.find(($)=>$.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(($)=>$.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(($)=>$.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(($)=>$.kind==="cuid2")}get isULID(){return!!this._def.checks.find(($)=>$.kind==="ulid")}get isIP(){return!!this._def.checks.find(($)=>$.kind==="ip")}get isCIDR(){return!!this._def.checks.find(($)=>$.kind==="cidr")}get isBase64(){return!!this._def.checks.find(($)=>$.kind==="base64")}get isBase64url(){return!!this._def.checks.find(($)=>$.kind==="base64url")}get minLength(){let $=null;for(let J of this._def.checks)if(J.kind==="min"){if($===null||J.value>$)$=J.value}return $}get maxLength(){let $=null;for(let J of this._def.checks)if(J.kind==="max"){if($===null||J.value<$)$=J.value}return $}}I0.create=($)=>{return new I0({checks:[],typeName:m.ZodString,coerce:$?.coerce??!1,...l($)})};function rJ($,J){let Q=($.toString().split(".")[1]||"").length,X=(J.toString().split(".")[1]||"").length,W=Q>X?Q:X,G=Number.parseInt($.toFixed(W).replace(".","")),Y=Number.parseInt(J.toFixed(W).replace(".",""));return G%Y/10**W}class X1 extends o{constructor(){super(...arguments);this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse($){if(this._def.coerce)$.data=Number($.data);if(this._getType($)!==C.number){let W=this._getOrReturnCtx($);return f(W,{code:R.invalid_type,expected:C.number,received:W.parsedType}),v}let Q=void 0,X=new O0;for(let W of this._def.checks)if(W.kind==="int"){if(!n.isInteger($.data))Q=this._getOrReturnCtx($,Q),f(Q,{code:R.invalid_type,expected:"integer",received:"float",message:W.message}),X.dirty()}else if(W.kind==="min"){if(W.inclusive?$.data<W.value:$.data<=W.value)Q=this._getOrReturnCtx($,Q),f(Q,{code:R.too_small,minimum:W.value,type:"number",inclusive:W.inclusive,exact:!1,message:W.message}),X.dirty()}else if(W.kind==="max"){if(W.inclusive?$.data>W.value:$.data>=W.value)Q=this._getOrReturnCtx($,Q),f(Q,{code:R.too_big,maximum:W.value,type:"number",inclusive:W.inclusive,exact:!1,message:W.message}),X.dirty()}else if(W.kind==="multipleOf"){if(rJ($.data,W.value)!==0)Q=this._getOrReturnCtx($,Q),f(Q,{code:R.not_multiple_of,multipleOf:W.value,message:W.message}),X.dirty()}else if(W.kind==="finite"){if(!Number.isFinite($.data))Q=this._getOrReturnCtx($,Q),f(Q,{code:R.not_finite,message:W.message}),X.dirty()}else n.assertNever(W);return{status:X.value,value:$.data}}gte($,J){return this.setLimit("min",$,!0,D.toString(J))}gt($,J){return this.setLimit("min",$,!1,D.toString(J))}lte($,J){return this.setLimit("max",$,!0,D.toString(J))}lt($,J){return this.setLimit("max",$,!1,D.toString(J))}setLimit($,J,Q,X){return new X1({...this._def,checks:[...this._def.checks,{kind:$,value:J,inclusive:Q,message:D.toString(X)}]})}_addCheck($){return new X1({...this._def,checks:[...this._def.checks,$]})}int($){return this._addCheck({kind:"int",message:D.toString($)})}positive($){return this._addCheck({kind:"min",value:0,inclusive:!1,message:D.toString($)})}negative($){return this._addCheck({kind:"max",value:0,inclusive:!1,message:D.toString($)})}nonpositive($){return this._addCheck({kind:"max",value:0,inclusive:!0,message:D.toString($)})}nonnegative($){return this._addCheck({kind:"min",value:0,inclusive:!0,message:D.toString($)})}multipleOf($,J){return this._addCheck({kind:"multipleOf",value:$,message:D.toString(J)})}finite($){return this._addCheck({kind:"finite",message:D.toString($)})}safe($){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:D.toString($)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:D.toString($)})}get minValue(){let $=null;for(let J of this._def.checks)if(J.kind==="min"){if($===null||J.value>$)$=J.value}return $}get maxValue(){let $=null;for(let J of this._def.checks)if(J.kind==="max"){if($===null||J.value<$)$=J.value}return $}get isInt(){return!!this._def.checks.find(($)=>$.kind==="int"||$.kind==="multipleOf"&&n.isInteger($.value))}get isFinite(){let $=null,J=null;for(let Q of this._def.checks)if(Q.kind==="finite"||Q.kind==="int"||Q.kind==="multipleOf")return!0;else if(Q.kind==="min"){if(J===null||Q.value>J)J=Q.value}else if(Q.kind==="max"){if($===null||Q.value<$)$=Q.value}return Number.isFinite(J)&&Number.isFinite($)}}X1.create=($)=>{return new X1({checks:[],typeName:m.ZodNumber,coerce:$?.coerce||!1,...l($)})};class W1 extends o{constructor(){super(...arguments);this.min=this.gte,this.max=this.lte}_parse($){if(this._def.coerce)try{$.data=BigInt($.data)}catch{return this._getInvalidInput($)}if(this._getType($)!==C.bigint)return this._getInvalidInput($);let Q=void 0,X=new O0;for(let W of this._def.checks)if(W.kind==="min"){if(W.inclusive?$.data<W.value:$.data<=W.value)Q=this._getOrReturnCtx($,Q),f(Q,{code:R.too_small,type:"bigint",minimum:W.value,inclusive:W.inclusive,message:W.message}),X.dirty()}else if(W.kind==="max"){if(W.inclusive?$.data>W.value:$.data>=W.value)Q=this._getOrReturnCtx($,Q),f(Q,{code:R.too_big,type:"bigint",maximum:W.value,inclusive:W.inclusive,message:W.message}),X.dirty()}else if(W.kind==="multipleOf"){if($.data%W.value!==BigInt(0))Q=this._getOrReturnCtx($,Q),f(Q,{code:R.not_multiple_of,multipleOf:W.value,message:W.message}),X.dirty()}else n.assertNever(W);return{status:X.value,value:$.data}}_getInvalidInput($){let J=this._getOrReturnCtx($);return f(J,{code:R.invalid_type,expected:C.bigint,received:J.parsedType}),v}gte($,J){return this.setLimit("min",$,!0,D.toString(J))}gt($,J){return this.setLimit("min",$,!1,D.toString(J))}lte($,J){return this.setLimit("max",$,!0,D.toString(J))}lt($,J){return this.setLimit("max",$,!1,D.toString(J))}setLimit($,J,Q,X){return new W1({...this._def,checks:[...this._def.checks,{kind:$,value:J,inclusive:Q,message:D.toString(X)}]})}_addCheck($){return new W1({...this._def,checks:[...this._def.checks,$]})}positive($){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:D.toString($)})}negative($){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:D.toString($)})}nonpositive($){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:D.toString($)})}nonnegative($){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:D.toString($)})}multipleOf($,J){return this._addCheck({kind:"multipleOf",value:$,message:D.toString(J)})}get minValue(){let $=null;for(let J of this._def.checks)if(J.kind==="min"){if($===null||J.value>$)$=J.value}return $}get maxValue(){let $=null;for(let J of this._def.checks)if(J.kind==="max"){if($===null||J.value<$)$=J.value}return $}}W1.create=($)=>{return new W1({checks:[],typeName:m.ZodBigInt,coerce:$?.coerce??!1,...l($)})};class E1 extends o{_parse($){if(this._def.coerce)$.data=Boolean($.data);if(this._getType($)!==C.boolean){let Q=this._getOrReturnCtx($);return f(Q,{code:R.invalid_type,expected:C.boolean,received:Q.parsedType}),v}return R0($.data)}}E1.create=($)=>{return new E1({typeName:m.ZodBoolean,coerce:$?.coerce||!1,...l($)})};class K1 extends o{_parse($){if(this._def.coerce)$.data=new Date($.data);if(this._getType($)!==C.date){let W=this._getOrReturnCtx($);return f(W,{code:R.invalid_type,expected:C.date,received:W.parsedType}),v}if(Number.isNaN($.data.getTime())){let W=this._getOrReturnCtx($);return f(W,{code:R.invalid_date}),v}let Q=new O0,X=void 0;for(let W of this._def.checks)if(W.kind==="min"){if($.data.getTime()<W.value)X=this._getOrReturnCtx($,X),f(X,{code:R.too_small,message:W.message,inclusive:!0,exact:!1,minimum:W.value,type:"date"}),Q.dirty()}else if(W.kind==="max"){if($.data.getTime()>W.value)X=this._getOrReturnCtx($,X),f(X,{code:R.too_big,message:W.message,inclusive:!0,exact:!1,maximum:W.value,type:"date"}),Q.dirty()}else n.assertNever(W);return{status:Q.value,value:new Date($.data.getTime())}}_addCheck($){return new K1({...this._def,checks:[...this._def.checks,$]})}min($,J){return this._addCheck({kind:"min",value:$.getTime(),message:D.toString(J)})}max($,J){return this._addCheck({kind:"max",value:$.getTime(),message:D.toString(J)})}get minDate(){let $=null;for(let J of this._def.checks)if(J.kind==="min"){if($===null||J.value>$)$=J.value}return $!=null?new Date($):null}get maxDate(){let $=null;for(let J of this._def.checks)if(J.kind==="max"){if($===null||J.value<$)$=J.value}return $!=null?new Date($):null}}K1.create=($)=>{return new K1({checks:[],coerce:$?.coerce||!1,typeName:m.ZodDate,...l($)})};class _2 extends o{_parse($){if(this._getType($)!==C.symbol){let Q=this._getOrReturnCtx($);return f(Q,{code:R.invalid_type,expected:C.symbol,received:Q.parsedType}),v}return R0($.data)}}_2.create=($)=>{return new _2({typeName:m.ZodSymbol,...l($)})};class y1 extends o{_parse($){if(this._getType($)!==C.undefined){let Q=this._getOrReturnCtx($);return f(Q,{code:R.invalid_type,expected:C.undefined,received:Q.parsedType}),v}return R0($.data)}}y1.create=($)=>{return new y1({typeName:m.ZodUndefined,...l($)})};class x1 extends o{_parse($){if(this._getType($)!==C.null){let Q=this._getOrReturnCtx($);return f(Q,{code:R.invalid_type,expected:C.null,received:Q.parsedType}),v}return R0($.data)}}x1.create=($)=>{return new x1({typeName:m.ZodNull,...l($)})};class M1 extends o{constructor(){super(...arguments);this._any=!0}_parse($){return R0($.data)}}M1.create=($)=>{return new M1({typeName:m.ZodAny,...l($)})};class Q1 extends o{constructor(){super(...arguments);this._unknown=!0}_parse($){return R0($.data)}}Q1.create=($)=>{return new Q1({typeName:m.ZodUnknown,...l($)})};class p0 extends o{_parse($){let J=this._getOrReturnCtx($);return f(J,{code:R.invalid_type,expected:C.never,received:J.parsedType}),v}}p0.create=($)=>{return new p0({typeName:m.ZodNever,...l($)})};class w2 extends o{_parse($){if(this._getType($)!==C.undefined){let Q=this._getOrReturnCtx($);return f(Q,{code:R.invalid_type,expected:C.void,received:Q.parsedType}),v}return R0($.data)}}w2.create=($)=>{return new w2({typeName:m.ZodVoid,...l($)})};class b0 extends o{_parse($){let{ctx:J,status:Q}=this._processInputParams($),X=this._def;if(J.parsedType!==C.array)return f(J,{code:R.invalid_type,expected:C.array,received:J.parsedType}),v;if(X.exactLength!==null){let G=J.data.length>X.exactLength.value,Y=J.data.length<X.exactLength.value;if(G||Y)f(J,{code:G?R.too_big:R.too_small,minimum:Y?X.exactLength.value:void 0,maximum:G?X.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:X.exactLength.message}),Q.dirty()}if(X.minLength!==null){if(J.data.length<X.minLength.value)f(J,{code:R.too_small,minimum:X.minLength.value,type:"array",inclusive:!0,exact:!1,message:X.minLength.message}),Q.dirty()}if(X.maxLength!==null){if(J.data.length>X.maxLength.value)f(J,{code:R.too_big,maximum:X.maxLength.value,type:"array",inclusive:!0,exact:!1,message:X.maxLength.message}),Q.dirty()}if(J.common.async)return Promise.all([...J.data].map((G,Y)=>{return X.type._parseAsync(new E0(J,G,J.path,Y))})).then((G)=>{return O0.mergeArray(Q,G)});let W=[...J.data].map((G,Y)=>{return X.type._parseSync(new E0(J,G,J.path,Y))});return O0.mergeArray(Q,W)}get element(){return this._def.type}min($,J){return new b0({...this._def,minLength:{value:$,message:D.toString(J)}})}max($,J){return new b0({...this._def,maxLength:{value:$,message:D.toString(J)}})}length($,J){return new b0({...this._def,exactLength:{value:$,message:D.toString(J)}})}nonempty($){return this.min(1,$)}}b0.create=($,J)=>{return new b0({type:$,minLength:null,maxLength:null,exactLength:null,typeName:m.ZodArray,...l(J)})};function b1($){if($ instanceof U0){let J={};for(let Q in $.shape){let X=$.shape[Q];J[Q]=g0.create(b1(X))}return new U0({...$._def,shape:()=>J})}else if($ instanceof b0)return new b0({...$._def,type:b1($.element)});else if($ instanceof g0)return g0.create(b1($.unwrap()));else if($ instanceof s0)return s0.create(b1($.unwrap()));else if($ instanceof l0)return l0.create($.items.map((J)=>b1(J)));else return $}class U0 extends o{constructor(){super(...arguments);this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;let $=this._def.shape(),J=n.objectKeys($);return this._cached={shape:$,keys:J},this._cached}_parse($){if(this._getType($)!==C.object){let q=this._getOrReturnCtx($);return f(q,{code:R.invalid_type,expected:C.object,received:q.parsedType}),v}let{status:Q,ctx:X}=this._processInputParams($),{shape:W,keys:G}=this._getCached(),Y=[];if(!(this._def.catchall instanceof p0&&this._def.unknownKeys==="strip")){for(let q in X.data)if(!G.includes(q))Y.push(q)}let H=[];for(let q of G){let U=W[q],N=X.data[q];H.push({key:{status:"valid",value:q},value:U._parse(new E0(X,N,X.path,q)),alwaysSet:q in X.data})}if(this._def.catchall instanceof p0){let q=this._def.unknownKeys;if(q==="passthrough")for(let U of Y)H.push({key:{status:"valid",value:U},value:{status:"valid",value:X.data[U]}});else if(q==="strict"){if(Y.length>0)f(X,{code:R.unrecognized_keys,keys:Y}),Q.dirty()}else if(q==="strip");else throw Error("Internal ZodObject error: invalid unknownKeys value.")}else{let q=this._def.catchall;for(let U of Y){let N=X.data[U];H.push({key:{status:"valid",value:U},value:q._parse(new E0(X,N,X.path,U)),alwaysSet:U in X.data})}}if(X.common.async)return Promise.resolve().then(async()=>{let q=[];for(let U of H){let N=await U.key,M=await U.value;q.push({key:N,value:M,alwaysSet:U.alwaysSet})}return q}).then((q)=>{return O0.mergeObjectSync(Q,q)});else return O0.mergeObjectSync(Q,H)}get shape(){return this._def.shape()}strict($){return D.errToObj,new U0({...this._def,unknownKeys:"strict",...$!==void 0?{errorMap:(J,Q)=>{let X=this._def.errorMap?.(J,Q).message??Q.defaultError;if(J.code==="unrecognized_keys")return{message:D.errToObj($).message??X};return{message:X}}}:{}})}strip(){return new U0({...this._def,unknownKeys:"strip"})}passthrough(){return new U0({...this._def,unknownKeys:"passthrough"})}extend($){return new U0({...this._def,shape:()=>({...this._def.shape(),...$})})}merge($){return new U0({unknownKeys:$._def.unknownKeys,catchall:$._def.catchall,shape:()=>({...this._def.shape(),...$._def.shape()}),typeName:m.ZodObject})}setKey($,J){return this.augment({[$]:J})}catchall($){return new U0({...this._def,catchall:$})}pick($){let J={};for(let Q of n.objectKeys($))if($[Q]&&this.shape[Q])J[Q]=this.shape[Q];return new U0({...this._def,shape:()=>J})}omit($){let J={};for(let Q of n.objectKeys(this.shape))if(!$[Q])J[Q]=this.shape[Q];return new U0({...this._def,shape:()=>J})}deepPartial(){return b1(this)}partial($){let J={};for(let Q of n.objectKeys(this.shape)){let X=this.shape[Q];if($&&!$[Q])J[Q]=X;else J[Q]=X.optional()}return new U0({...this._def,shape:()=>J})}required($){let J={};for(let Q of n.objectKeys(this.shape))if($&&!$[Q])J[Q]=this.shape[Q];else{let W=this.shape[Q];while(W instanceof g0)W=W._def.innerType;J[Q]=W}return new U0({...this._def,shape:()=>J})}keyof(){return q4(n.objectKeys(this.shape))}}U0.create=($,J)=>{return new U0({shape:()=>$,unknownKeys:"strip",catchall:p0.create(),typeName:m.ZodObject,...l(J)})};U0.strictCreate=($,J)=>{return new U0({shape:()=>$,unknownKeys:"strict",catchall:p0.create(),typeName:m.ZodObject,...l(J)})};U0.lazycreate=($,J)=>{return new U0({shape:$,unknownKeys:"strip",catchall:p0.create(),typeName:m.ZodObject,...l(J)})};class v1 extends o{_parse($){let{ctx:J}=this._processInputParams($),Q=this._def.options;function X(W){for(let Y of W)if(Y.result.status==="valid")return Y.result;for(let Y of W)if(Y.result.status==="dirty")return J.common.issues.push(...Y.ctx.common.issues),Y.result;let G=W.map((Y)=>new f0(Y.ctx.common.issues));return f(J,{code:R.invalid_union,unionErrors:G}),v}if(J.common.async)return Promise.all(Q.map(async(W)=>{let G={...J,common:{...J.common,issues:[]},parent:null};return{result:await W._parseAsync({data:J.data,path:J.path,parent:G}),ctx:G}})).then(X);else{let W=void 0,G=[];for(let H of Q){let q={...J,common:{...J.common,issues:[]},parent:null},U=H._parseSync({data:J.data,path:J.path,parent:q});if(U.status==="valid")return U;else if(U.status==="dirty"&&!W)W={result:U,ctx:q};if(q.common.issues.length)G.push(q.common.issues)}if(W)return J.common.issues.push(...W.ctx.common.issues),W.result;let Y=G.map((H)=>new f0(H));return f(J,{code:R.invalid_union,unionErrors:Y}),v}}get options(){return this._def.options}}v1.create=($,J)=>{return new v1({options:$,typeName:m.ZodUnion,...l(J)})};var n0=($)=>{if($ instanceof m1)return n0($.schema);else if($ instanceof y0)return n0($.innerType());else if($ instanceof u1)return[$.value];else if($ instanceof Y1)return $.options;else if($ instanceof c1)return n.objectValues($.enum);else if($ instanceof p1)return n0($._def.innerType);else if($ instanceof y1)return[void 0];else if($ instanceof x1)return[null];else if($ instanceof g0)return[void 0,...n0($.unwrap())];else if($ instanceof s0)return[null,...n0($.unwrap())];else if($ instanceof t2)return n0($.unwrap());else if($ instanceof d1)return n0($.unwrap());else if($ instanceof l1)return n0($._def.innerType);else return[]};class s2 extends o{_parse($){let{ctx:J}=this._processInputParams($);if(J.parsedType!==C.object)return f(J,{code:R.invalid_type,expected:C.object,received:J.parsedType}),v;let Q=this.discriminator,X=J.data[Q],W=this.optionsMap.get(X);if(!W)return f(J,{code:R.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[Q]}),v;if(J.common.async)return W._parseAsync({data:J.data,path:J.path,parent:J});else return W._parseSync({data:J.data,path:J.path,parent:J})}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create($,J,Q){let X=new Map;for(let W of J){let G=n0(W.shape[$]);if(!G.length)throw Error(`A discriminator value for key \`${$}\` could not be extracted from all schema options`);for(let Y of G){if(X.has(Y))throw Error(`Discriminator property ${String($)} has duplicate value ${String(Y)}`);X.set(Y,W)}}return new s2({typeName:m.ZodDiscriminatedUnion,discriminator:$,options:J,optionsMap:X,...l(Q)})}}function l$($,J){let Q=c0($),X=c0(J);if($===J)return{valid:!0,data:$};else if(Q===C.object&&X===C.object){let W=n.objectKeys(J),G=n.objectKeys($).filter((H)=>W.indexOf(H)!==-1),Y={...$,...J};for(let H of G){let q=l$($[H],J[H]);if(!q.valid)return{valid:!1};Y[H]=q.data}return{valid:!0,data:Y}}else if(Q===C.array&&X===C.array){if($.length!==J.length)return{valid:!1};let W=[];for(let G=0;G<$.length;G++){let Y=$[G],H=J[G],q=l$(Y,H);if(!q.valid)return{valid:!1};W.push(q.data)}return{valid:!0,data:W}}else if(Q===C.date&&X===C.date&&+$===+J)return{valid:!0,data:$};else return{valid:!1}}class h1 extends o{_parse($){let{status:J,ctx:Q}=this._processInputParams($),X=(W,G)=>{if(o2(W)||o2(G))return v;let Y=l$(W.value,G.value);if(!Y.valid)return f(Q,{code:R.invalid_intersection_types}),v;if(n2(W)||n2(G))J.dirty();return{status:J.value,value:Y.data}};if(Q.common.async)return Promise.all([this._def.left._parseAsync({data:Q.data,path:Q.path,parent:Q}),this._def.right._parseAsync({data:Q.data,path:Q.path,parent:Q})]).then(([W,G])=>X(W,G));else return X(this._def.left._parseSync({data:Q.data,path:Q.path,parent:Q}),this._def.right._parseSync({data:Q.data,path:Q.path,parent:Q}))}}h1.create=($,J,Q)=>{return new h1({left:$,right:J,typeName:m.ZodIntersection,...l(Q)})};class l0 extends o{_parse($){let{status:J,ctx:Q}=this._processInputParams($);if(Q.parsedType!==C.array)return f(Q,{code:R.invalid_type,expected:C.array,received:Q.parsedType}),v;if(Q.data.length<this._def.items.length)return f(Q,{code:R.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),v;if(!this._def.rest&&Q.data.length>this._def.items.length)f(Q,{code:R.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),J.dirty();let W=[...Q.data].map((G,Y)=>{let H=this._def.items[Y]||this._def.rest;if(!H)return null;return H._parse(new E0(Q,G,Q.path,Y))}).filter((G)=>!!G);if(Q.common.async)return Promise.all(W).then((G)=>{return O0.mergeArray(J,G)});else return O0.mergeArray(J,W)}get items(){return this._def.items}rest($){return new l0({...this._def,rest:$})}}l0.create=($,J)=>{if(!Array.isArray($))throw Error("You must pass an array of schemas to z.tuple([ ... ])");return new l0({items:$,typeName:m.ZodTuple,rest:null,...l(J)})};class O2 extends o{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse($){let{status:J,ctx:Q}=this._processInputParams($);if(Q.parsedType!==C.object)return f(Q,{code:R.invalid_type,expected:C.object,received:Q.parsedType}),v;let X=[],W=this._def.keyType,G=this._def.valueType;for(let Y in Q.data)X.push({key:W._parse(new E0(Q,Y,Q.path,Y)),value:G._parse(new E0(Q,Q.data[Y],Q.path,Y)),alwaysSet:Y in Q.data});if(Q.common.async)return O0.mergeObjectAsync(J,X);else return O0.mergeObjectSync(J,X)}get element(){return this._def.valueType}static create($,J,Q){if(J instanceof o)return new O2({keyType:$,valueType:J,typeName:m.ZodRecord,...l(Q)});return new O2({keyType:I0.create(),valueType:$,typeName:m.ZodRecord,...l(J)})}}class S2 extends o{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse($){let{status:J,ctx:Q}=this._processInputParams($);if(Q.parsedType!==C.map)return f(Q,{code:R.invalid_type,expected:C.map,received:Q.parsedType}),v;let X=this._def.keyType,W=this._def.valueType,G=[...Q.data.entries()].map(([Y,H],q)=>{return{key:X._parse(new E0(Q,Y,Q.path,[q,"key"])),value:W._parse(new E0(Q,H,Q.path,[q,"value"]))}});if(Q.common.async){let Y=new Map;return Promise.resolve().then(async()=>{for(let H of G){let q=await H.key,U=await H.value;if(q.status==="aborted"||U.status==="aborted")return v;if(q.status==="dirty"||U.status==="dirty")J.dirty();Y.set(q.value,U.value)}return{status:J.value,value:Y}})}else{let Y=new Map;for(let H of G){let{key:q,value:U}=H;if(q.status==="aborted"||U.status==="aborted")return v;if(q.status==="dirty"||U.status==="dirty")J.dirty();Y.set(q.value,U.value)}return{status:J.value,value:Y}}}}S2.create=($,J,Q)=>{return new S2({valueType:J,keyType:$,typeName:m.ZodMap,...l(Q)})};class F1 extends o{_parse($){let{status:J,ctx:Q}=this._processInputParams($);if(Q.parsedType!==C.set)return f(Q,{code:R.invalid_type,expected:C.set,received:Q.parsedType}),v;let X=this._def;if(X.minSize!==null){if(Q.data.size<X.minSize.value)f(Q,{code:R.too_small,minimum:X.minSize.value,type:"set",inclusive:!0,exact:!1,message:X.minSize.message}),J.dirty()}if(X.maxSize!==null){if(Q.data.size>X.maxSize.value)f(Q,{code:R.too_big,maximum:X.maxSize.value,type:"set",inclusive:!0,exact:!1,message:X.maxSize.message}),J.dirty()}let W=this._def.valueType;function G(H){let q=new Set;for(let U of H){if(U.status==="aborted")return v;if(U.status==="dirty")J.dirty();q.add(U.value)}return{status:J.value,value:q}}let Y=[...Q.data.values()].map((H,q)=>W._parse(new E0(Q,H,Q.path,q)));if(Q.common.async)return Promise.all(Y).then((H)=>G(H));else return G(Y)}min($,J){return new F1({...this._def,minSize:{value:$,message:D.toString(J)}})}max($,J){return new F1({...this._def,maxSize:{value:$,message:D.toString(J)}})}size($,J){return this.min($,J).max($,J)}nonempty($){return this.min(1,$)}}F1.create=($,J)=>{return new F1({valueType:$,minSize:null,maxSize:null,typeName:m.ZodSet,...l(J)})};class g1 extends o{constructor(){super(...arguments);this.validate=this.implement}_parse($){let{ctx:J}=this._processInputParams($);if(J.parsedType!==C.function)return f(J,{code:R.invalid_type,expected:C.function,received:J.parsedType}),v;function Q(Y,H){return z2({data:Y,path:J.path,errorMaps:[J.common.contextualErrorMap,J.schemaErrorMap,D1(),o0].filter((q)=>!!q),issueData:{code:R.invalid_arguments,argumentsError:H}})}function X(Y,H){return z2({data:Y,path:J.path,errorMaps:[J.common.contextualErrorMap,J.schemaErrorMap,D1(),o0].filter((q)=>!!q),issueData:{code:R.invalid_return_type,returnTypeError:H}})}let W={errorMap:J.common.contextualErrorMap},G=J.data;if(this._def.returns instanceof z1){let Y=this;return R0(async function(...H){let q=new f0([]),U=await Y._def.args.parseAsync(H,W).catch((L)=>{throw q.addIssue(Q(H,L)),q}),N=await Reflect.apply(G,this,U);return await Y._def.returns._def.type.parseAsync(N,W).catch((L)=>{throw q.addIssue(X(N,L)),q})})}else{let Y=this;return R0(function(...H){let q=Y._def.args.safeParse(H,W);if(!q.success)throw new f0([Q(H,q.error)]);let U=Reflect.apply(G,this,q.data),N=Y._def.returns.safeParse(U,W);if(!N.success)throw new f0([X(U,N.error)]);return N.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...$){return new g1({...this._def,args:l0.create($).rest(Q1.create())})}returns($){return new g1({...this._def,returns:$})}implement($){return this.parse($)}strictImplement($){return this.parse($)}static create($,J,Q){return new g1({args:$?$:l0.create([]).rest(Q1.create()),returns:J||Q1.create(),typeName:m.ZodFunction,...l(Q)})}}class m1 extends o{get schema(){return this._def.getter()}_parse($){let{ctx:J}=this._processInputParams($);return this._def.getter()._parse({data:J.data,path:J.path,parent:J})}}m1.create=($,J)=>{return new m1({getter:$,typeName:m.ZodLazy,...l(J)})};class u1 extends o{_parse($){if($.data!==this._def.value){let J=this._getOrReturnCtx($);return f(J,{received:J.data,code:R.invalid_literal,expected:this._def.value}),v}return{status:"valid",value:$.data}}get value(){return this._def.value}}u1.create=($,J)=>{return new u1({value:$,typeName:m.ZodLiteral,...l(J)})};function q4($,J){return new Y1({values:$,typeName:m.ZodEnum,...l(J)})}class Y1 extends o{_parse($){if(typeof $.data!=="string"){let J=this._getOrReturnCtx($),Q=this._def.values;return f(J,{expected:n.joinValues(Q),received:J.parsedType,code:R.invalid_type}),v}if(!this._cache)this._cache=new Set(this._def.values);if(!this._cache.has($.data)){let J=this._getOrReturnCtx($),Q=this._def.values;return f(J,{received:J.data,code:R.invalid_enum_value,options:Q}),v}return R0($.data)}get options(){return this._def.values}get enum(){let $={};for(let J of this._def.values)$[J]=J;return $}get Values(){let $={};for(let J of this._def.values)$[J]=J;return $}get Enum(){let $={};for(let J of this._def.values)$[J]=J;return $}extract($,J=this._def){return Y1.create($,{...this._def,...J})}exclude($,J=this._def){return Y1.create(this.options.filter((Q)=>!$.includes(Q)),{...this._def,...J})}}Y1.create=q4;class c1 extends o{_parse($){let J=n.getValidEnumValues(this._def.values),Q=this._getOrReturnCtx($);if(Q.parsedType!==C.string&&Q.parsedType!==C.number){let X=n.objectValues(J);return f(Q,{expected:n.joinValues(X),received:Q.parsedType,code:R.invalid_type}),v}if(!this._cache)this._cache=new Set(n.getValidEnumValues(this._def.values));if(!this._cache.has($.data)){let X=n.objectValues(J);return f(Q,{received:Q.data,code:R.invalid_enum_value,options:X}),v}return R0($.data)}get enum(){return this._def.values}}c1.create=($,J)=>{return new c1({values:$,typeName:m.ZodNativeEnum,...l(J)})};class z1 extends o{unwrap(){return this._def.type}_parse($){let{ctx:J}=this._processInputParams($);if(J.parsedType!==C.promise&&J.common.async===!1)return f(J,{code:R.invalid_type,expected:C.promise,received:J.parsedType}),v;let Q=J.parsedType===C.promise?J.data:Promise.resolve(J.data);return R0(Q.then((X)=>{return this._def.type.parseAsync(X,{path:J.path,errorMap:J.common.contextualErrorMap})}))}}z1.create=($,J)=>{return new z1({type:$,typeName:m.ZodPromise,...l(J)})};class y0 extends o{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===m.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse($){let{status:J,ctx:Q}=this._processInputParams($),X=this._def.effect||null,W={addIssue:(G)=>{if(f(Q,G),G.fatal)J.abort();else J.dirty()},get path(){return Q.path}};if(W.addIssue=W.addIssue.bind(W),X.type==="preprocess"){let G=X.transform(Q.data,W);if(Q.common.async)return Promise.resolve(G).then(async(Y)=>{if(J.value==="aborted")return v;let H=await this._def.schema._parseAsync({data:Y,path:Q.path,parent:Q});if(H.status==="aborted")return v;if(H.status==="dirty")return L1(H.value);if(J.value==="dirty")return L1(H.value);return H});else{if(J.value==="aborted")return v;let Y=this._def.schema._parseSync({data:G,path:Q.path,parent:Q});if(Y.status==="aborted")return v;if(Y.status==="dirty")return L1(Y.value);if(J.value==="dirty")return L1(Y.value);return Y}}if(X.type==="refinement"){let G=(Y)=>{let H=X.refinement(Y,W);if(Q.common.async)return Promise.resolve(H);if(H instanceof Promise)throw Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return Y};if(Q.common.async===!1){let Y=this._def.schema._parseSync({data:Q.data,path:Q.path,parent:Q});if(Y.status==="aborted")return v;if(Y.status==="dirty")J.dirty();return G(Y.value),{status:J.value,value:Y.value}}else return this._def.schema._parseAsync({data:Q.data,path:Q.path,parent:Q}).then((Y)=>{if(Y.status==="aborted")return v;if(Y.status==="dirty")J.dirty();return G(Y.value).then(()=>{return{status:J.value,value:Y.value}})})}if(X.type==="transform")if(Q.common.async===!1){let G=this._def.schema._parseSync({data:Q.data,path:Q.path,parent:Q});if(!J1(G))return v;let Y=X.transform(G.value,W);if(Y instanceof Promise)throw Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:J.value,value:Y}}else return this._def.schema._parseAsync({data:Q.data,path:Q.path,parent:Q}).then((G)=>{if(!J1(G))return v;return Promise.resolve(X.transform(G.value,W)).then((Y)=>({status:J.value,value:Y}))});n.assertNever(X)}}y0.create=($,J,Q)=>{return new y0({schema:$,typeName:m.ZodEffects,effect:J,...l(Q)})};y0.createWithPreprocess=($,J,Q)=>{return new y0({schema:J,effect:{type:"preprocess",transform:$},typeName:m.ZodEffects,...l(Q)})};class g0 extends o{_parse($){if(this._getType($)===C.undefined)return R0(void 0);return this._def.innerType._parse($)}unwrap(){return this._def.innerType}}g0.create=($,J)=>{return new g0({innerType:$,typeName:m.ZodOptional,...l(J)})};class s0 extends o{_parse($){if(this._getType($)===C.null)return R0(null);return this._def.innerType._parse($)}unwrap(){return this._def.innerType}}s0.create=($,J)=>{return new s0({innerType:$,typeName:m.ZodNullable,...l(J)})};class p1 extends o{_parse($){let{ctx:J}=this._processInputParams($),Q=J.data;if(J.parsedType===C.undefined)Q=this._def.defaultValue();return this._def.innerType._parse({data:Q,path:J.path,parent:J})}removeDefault(){return this._def.innerType}}p1.create=($,J)=>{return new p1({innerType:$,typeName:m.ZodDefault,defaultValue:typeof J.default==="function"?J.default:()=>J.default,...l(J)})};class l1 extends o{_parse($){let{ctx:J}=this._processInputParams($),Q={...J,common:{...J.common,issues:[]}},X=this._def.innerType._parse({data:Q.data,path:Q.path,parent:{...Q}});if(I1(X))return X.then((W)=>{return{status:"valid",value:W.status==="valid"?W.value:this._def.catchValue({get error(){return new f0(Q.common.issues)},input:Q.data})}});else return{status:"valid",value:X.status==="valid"?X.value:this._def.catchValue({get error(){return new f0(Q.common.issues)},input:Q.data})}}removeCatch(){return this._def.innerType}}l1.create=($,J)=>{return new l1({innerType:$,typeName:m.ZodCatch,catchValue:typeof J.catch==="function"?J.catch:()=>J.catch,...l(J)})};class R2 extends o{_parse($){if(this._getType($)!==C.nan){let Q=this._getOrReturnCtx($);return f(Q,{code:R.invalid_type,expected:C.nan,received:Q.parsedType}),v}return{status:"valid",value:$.data}}}R2.create=($)=>{return new R2({typeName:m.ZodNaN,...l($)})};var oJ=Symbol("zod_brand");class t2 extends o{_parse($){let{ctx:J}=this._processInputParams($),Q=J.data;return this._def.type._parse({data:Q,path:J.path,parent:J})}unwrap(){return this._def.type}}class C2 extends o{_parse($){let{status:J,ctx:Q}=this._processInputParams($);if(Q.common.async)return(async()=>{let W=await this._def.in._parseAsync({data:Q.data,path:Q.path,parent:Q});if(W.status==="aborted")return v;if(W.status==="dirty")return J.dirty(),L1(W.value);else return this._def.out._parseAsync({data:W.value,path:Q.path,parent:Q})})();else{let X=this._def.in._parseSync({data:Q.data,path:Q.path,parent:Q});if(X.status==="aborted")return v;if(X.status==="dirty")return J.dirty(),{status:"dirty",value:X.value};else return this._def.out._parseSync({data:X.value,path:Q.path,parent:Q})}}static create($,J){return new C2({in:$,out:J,typeName:m.ZodPipeline})}}class d1 extends o{_parse($){let J=this._def.innerType._parse($),Q=(X)=>{if(J1(X))X.value=Object.freeze(X.value);return X};return I1(J)?J.then((X)=>Q(X)):Q(J)}unwrap(){return this._def.innerType}}d1.create=($,J)=>{return new d1({innerType:$,typeName:m.ZodReadonly,...l(J)})};function X4($,J){let Q=typeof $==="function"?$(J):typeof $==="string"?{message:$}:$;return typeof Q==="string"?{message:Q}:Q}function H4($,J={},Q){if($)return M1.create().superRefine((X,W)=>{let G=$(X);if(G instanceof Promise)return G.then((Y)=>{if(!Y){let H=X4(J,X),q=H.fatal??Q??!0;W.addIssue({code:"custom",...H,fatal:q})}});if(!G){let Y=X4(J,X),H=Y.fatal??Q??!0;W.addIssue({code:"custom",...Y,fatal:H})}return});return M1.create()}var nJ={object:U0.lazycreate},m;(function($){$.ZodString="ZodString",$.ZodNumber="ZodNumber",$.ZodNaN="ZodNaN",$.ZodBigInt="ZodBigInt",$.ZodBoolean="ZodBoolean",$.ZodDate="ZodDate",$.ZodSymbol="ZodSymbol",$.ZodUndefined="ZodUndefined",$.ZodNull="ZodNull",$.ZodAny="ZodAny",$.ZodUnknown="ZodUnknown",$.ZodNever="ZodNever",$.ZodVoid="ZodVoid",$.ZodArray="ZodArray",$.ZodObject="ZodObject",$.ZodUnion="ZodUnion",$.ZodDiscriminatedUnion="ZodDiscriminatedUnion",$.ZodIntersection="ZodIntersection",$.ZodTuple="ZodTuple",$.ZodRecord="ZodRecord",$.ZodMap="ZodMap",$.ZodSet="ZodSet",$.ZodFunction="ZodFunction",$.ZodLazy="ZodLazy",$.ZodLiteral="ZodLiteral",$.ZodEnum="ZodEnum",$.ZodEffects="ZodEffects",$.ZodNativeEnum="ZodNativeEnum",$.ZodOptional="ZodOptional",$.ZodNullable="ZodNullable",$.ZodDefault="ZodDefault",$.ZodCatch="ZodCatch",$.ZodPromise="ZodPromise",$.ZodBranded="ZodBranded",$.ZodPipeline="ZodPipeline",$.ZodReadonly="ZodReadonly"})(m||(m={}));var sJ=($,J={message:`Input not instance of ${$.name}`})=>H4((Q)=>Q instanceof $,J),B4=I0.create,U4=X1.create,tJ=R2.create,aJ=W1.create,N4=E1.create,eJ=K1.create,$8=_2.create,J8=y1.create,Q8=x1.create,X8=M1.create,W8=Q1.create,Y8=p0.create,G8=w2.create,q8=b0.create,H8=U0.create,B8=U0.strictCreate,U8=v1.create,N8=s2.create,L8=h1.create,K8=l0.create,M8=O2.create,F8=S2.create,z8=F1.create,_8=g1.create,w8=m1.create,O8=u1.create,S8=Y1.create,R8=c1.create,C8=z1.create,P8=y0.create,f8=g0.create,j8=s0.create,Z8=y0.createWithPreprocess,V8=C2.create,A8=()=>B4().optional(),k8=()=>U4().optional(),T8=()=>N4().optional(),D8={string:($)=>I0.create({...$,coerce:!0}),number:($)=>X1.create({...$,coerce:!0}),boolean:($)=>E1.create({...$,coerce:!0}),bigint:($)=>W1.create({...$,coerce:!0}),date:($)=>K1.create({...$,coerce:!0})};var I8=v;var b8=B.object({before:B.string(),after:B.string(),hierarchy:B.array(B.string()),lineStart:B.number().optional(),lineEnd:B.number().optional()}).passthrough(),g8=B.object({id:B.string(),name:B.string()}).passthrough(),E8=B.object({url:B.string(),mime:B.string().optional()}).passthrough(),d$=B.object({id:B.string(),snippet:B.string(),note:B.string(),createdAt:B.string(),filePath:B.string().optional(),canvasFile:B.string().optional(),context:b8.optional(),images:B.array(B.string()).optional(),attachments:B.array(E8).optional(),source:B.enum(["local","remote"]).optional(),author:g8.optional()}).passthrough(),y8=B.array(d$.optional().catch(void 0)).transform(($)=>$.filter((J)=>J!==void 0)).catch([]),i$=B.object({annotations:y8,generalNote:B.string().catch("")}).passthrough(),L4=B.object({path:B.string()}),K4=B.object({url:B.string()}),M4=B.object({error:B.string()});import{useCallback as w1,useMemo as x8,useState as v8}from"react";var G1="__agent-response__";function _1($){return $.filePath&&$.filePath!=="__agent-response__"?$.filePath:void 0}function P2($){return $.uploadUrl!==null}var r$=["image/png","image/jpeg","image/gif","image/webp"],F4="Only PNG, JPEG, GIF and WebP images can be attached";function t0(){return`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`}function q1($,J){$.style.height="auto",$.style.height=(J?Math.max(J,$.scrollHeight):$.scrollHeight)+"px"}function z4($){let J=$?`[data-annotation-id="${CSS.escape($)}"]`:"[data-annotation-id]";for(let Q of document.querySelectorAll(J))if(Q.tagName==="MARK"){let X=Q.parentNode;Q.replaceWith(document.createTextNode(Q.textContent||"")),X?.normalize()}else Q.remove()}function a2({annotations:$,setAnnotations:J,generalNote:Q,setGeneralNote:X,remoteAnnotations:W,isReadOnly:G,onClear:Y}){let[H,q]=v8(null),U=x8(()=>{if(!W?.length)return $;let S=new Set($.map((F)=>F.id)),O=W.filter((F)=>!S.has(F.id));return[...$,...O.map((F)=>({...F,source:"remote"}))]},[$,W]),N=w1((S,O,F,g,I,h,V)=>{J((u)=>[...u,{id:S,snippet:O,note:F,createdAt:new Date().toISOString(),filePath:g,context:I,...h?.length?{images:h}:{},...V?{canvasFile:V}:{}}])},[J]),M=w1((S,O,F)=>{N(t0(),S,O,F)},[N]),L=w1((S,O)=>{J((F)=>F.map((g)=>g.id===S?{...g,note:O}:g))},[J]),K=w1((S)=>{if(!$.some((O)=>O.id===S))return;z4(S),J((O)=>O.filter((F)=>F.id!==S)),q((O)=>O===S?null:O)},[$,J]),z=w1((S,O)=>{J((F)=>F.map((g)=>g.id===S?{...g,images:[...g.images||[],O]}:g))},[J]),_=w1((S,O)=>{J((F)=>F.map((g)=>g.id===S?{...g,images:(g.images||[]).filter((I)=>I!==O)}:g))},[J]),w=w1(()=>{z4(),J([]),X(""),q(null),Y?.()},[J,X,Y]);return{annotations:U,generalNote:Q,setGeneralNote:X,activeAnnotationId:H,setActiveAnnotationId:q,addAnnotation:M,addAnnotationWithId:N,updateAnnotation:L,removeAnnotation:K,addAnnotationImage:z,removeAnnotationImage:_,clearAll:w,isReadOnly:G}}import{useAnnotations as H1}from"@fabrika/annotations/runtime";import{jsxDEV as $X}from"react/jsx-dev-runtime";import{jsxDEV as O1,Fragment as h8}from"react/jsx-dev-runtime";function o$({hasContent:$,onSubmit:J,onSubmitEmpty:Q,notice:X,secondaryAction:W,placeholder:G="General notes...",submitLabel:Y="Submit",emptyLabel:H="Submit without feedback"}){let{generalNote:q,setGeneralNote:U}=H1();return O1(h8,{children:[O1("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:O1("textarea",{value:q,onChange:(N)=>U(N.currentTarget.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:G,onInput:(N)=>q1(N.currentTarget,40),ref:(N)=>{if(N)q1(N,40)}},void 0,!1,void 0,this)},void 0,!1,void 0,this),X,O1("div",{className:"px-4 py-3 border-t border-border-subtle flex-shrink-0",children:$?O1("div",{className:"flex gap-2",children:[W,O1("button",{onClick:J,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:Y},void 0,!1,void 0,this)]},void 0,!0,void 0,this):O1("button",{onClick:Q,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:H},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useAnnotationHost as m8}from"@fabrika/annotations/runtime";import{useCallback as a0,useEffect as u8,useRef as n$,useState as e2}from"react";import{jsxDEV as z0}from"react/jsx-dev-runtime";function s$($){if($.startsWith("/s/")||$.startsWith("http://")||$.startsWith("https://"))return $;return`/api/uploads/${$.split("/").pop()}`}async function c8($,J){let Q=$.uploadUrl;if(!Q)return{error:"Uploads are not available here"};let X=new FormData;X.append("image",J);try{let W=await fetch(Q(),{method:"POST",body:X}),G=await W.json();if(!W.ok){let Y=M4.safeParse(G);return{error:Y.success?Y.data.error:`Upload failed (HTTP ${W.status})`}}return{path:$.isShared?K4.parse(G).url:L4.parse(G).path}}catch{return{error:"Upload failed"}}}function i1({note:$,onNoteChange:J,images:Q,onAddImage:X,onRemoveImage:W,sessionId:G,placeholder:Y="Add your note...",autoFocus:H=!1,autoResize:q=!1,readOnly:U=!1,onKeyDown:N,onTextareaClick:M,textareaRef:L,textareaClassName:K,textareaStyle:z,minHeight:_,attachButton:w="always",openFilePickerRef:S}){let O=m8(),F=!U&&P2(O),[g,I]=e2(!1),[h,V]=e2(!1),[u,E]=e2(null),[c,Q0]=e2(!1),$0=n$(0),W0=n$(null),_0=n$(null),d=a0(()=>_0.current?.click(),[]);if(S)S.current=d;let J0=a0((j)=>{if(W0.current=j,L)L.current=j;if(j&&q)q1(j,_)},[L,q,_]);u8(()=>{if(H&&W0.current){let j=W0.current;if(j.focus(),j.value)j.setSelectionRange(j.value.length,j.value.length)}},[H]);let t=a0(async(j)=>{if(!r$.includes(j.type)){E(F4);return}E(null),V(!0);try{let P=await c8(O,j);if("path"in P)X(P.path);else E(P.error)}finally{V(!1)}},[O,X]),G0=a0((j)=>{for(let P of j.clipboardData?.items??[])if(P.type.startsWith("image/")){j.preventDefault();let x=P.getAsFile();if(x)t(x);return}},[t]),a=a0((j)=>{if(j.preventDefault(),$0.current++,$0.current===1)I(!0)},[]),X0=a0((j)=>{j.preventDefault()},[]),B0=a0((j)=>{if(j.preventDefault(),$0.current--,$0.current===0)I(!1)},[]),A=a0((j)=>{j.preventDefault(),$0.current=0,I(!1);for(let P of j.dataTransfer?.files??[])if(P.type.startsWith("image/"))t(P)},[t]),b=a0((j)=>{if(J(j.currentTarget.value),q)j.currentTarget.style.height="auto",j.currentTarget.style.height=(_?Math.max(_,j.currentTarget.scrollHeight):j.currentTarget.scrollHeight)+"px"},[J,q,_]),p="w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none",T={width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",outline:"none",...q?{resize:"none",overflow:"hidden"}:{resize:"vertical"}},y=F&&(w==="always"||w==="on-focus"&&c);return z0("div",{style:{position:"relative"},onDragEnter:F?a:void 0,onDragOver:F?X0:void 0,onDragLeave:F?B0:void 0,onDrop:F?A:void 0,children:[z0("textarea",{ref:J0,value:$,onChange:U?void 0:b,onPaste:F?G0:void 0,onKeyDown:N,onClick:M,onFocus:()=>Q0(!0),onBlur:()=>{setTimeout(()=>Q0(!1),150)},readOnly:U,placeholder:Y,className:K??p,style:z??T,rows:q?1:void 0},void 0,!1,void 0,this),F&&z0("input",{ref:_0,type:"file",accept:r$.join(","),multiple:!0,style:{display:"none"},onChange:(j)=>{let P=j.currentTarget.files;if(P)for(let x of P)t(x);j.currentTarget.value=""}},void 0,!1,void 0,this),(Q.length>0||y)&&z0("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px",alignItems:"center"},children:[Q.map((j)=>z0("div",{style:{position:"relative",width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:[z0("img",{src:s$(j),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this),!U&&z0("button",{onClick:(P)=>{P.stopPropagation(),W(j)},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)]},j,!0,void 0,this)),y&&z0($$,{onClick:d},void 0,!1,void 0,this)]},void 0,!0,void 0,this),h&&z0("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontFamily:"'Inter', sans-serif",marginTop:"4px"},children:"Uploading..."},void 0,!1,void 0,this),u&&z0("div",{role:"alert",style:{fontSize:"11px",color:"var(--color-accent-red)",fontFamily:"'Inter', sans-serif",marginTop:"4px"},children:u},void 0,!1,void 0,this),g&&z0("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 $$({onClick:$,size:J=16}){return z0("button",{onClick:(Q)=>{Q.stopPropagation(),$()},style:{width:`${J*2}px`,height:`${J*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:(Q)=>{Q.currentTarget.style.color="var(--color-text-secondary)"},onMouseLeave:(Q)=>{Q.currentTarget.style.color="var(--color-text-tertiary)"},children:z0("svg",{width:J,height:J,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[z0("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),z0("circle",{cx:"8.5",cy:"8.5",r:"1.5"},void 0,!1,void 0,this),z0("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 t$({images:$}){if(!$.length)return null;return z0("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px"},children:$.map((J)=>z0("div",{style:{width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:z0("img",{src:s$(J),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this)},J,!1,void 0,this))},void 0,!1,void 0,this)}import{SessionContext as p8}from"@fabrika/annotations/runtime";import{useContext as l8,useEffect as d8,useRef as i8}from"react";import{jsxDEV as N0,Fragment as _4}from"react/jsx-dev-runtime";function r8($){let J=F2($);return J.length>80?J.slice(0,80)+"...":J}function f2({annotations:$,readOnly:J=!1,onSelect:Q,onReveal:X,includedRemoteIds:W,onToggleRemoteId:G}){let{updateAnnotation:Y,removeAnnotation:H,addAnnotationImage:q,removeAnnotationImage:U,activeAnnotationId:N,setActiveAnnotationId:M}=H1(),L=l8(p8),K=i8(new Map);d8(()=>{if(J||!N)return;let F=K.current.get(N);if(F)F.scrollIntoView({behavior:"smooth",block:"nearest"})},[N,J]);let z=(F)=>{M(F),k1(F,!0)},_=(F)=>{M(null),k1(F,!1)},w=(F)=>{if(F.id===N){M(null);return}M(F.id),Q?.(F)},S=!!W&&!!G,O=(F)=>{let g=S&&F.source==="remote";return N0("div",{ref:(I)=>{if(I)K.current.set(F.id,I);else K.current.delete(F.id)},className:`group/ann relative px-3 py-2.5 transition-colors duration-150 ${J?"cursor-pointer ":""}${N===F.id?"bg-highlight-selected":g?"bg-accent-purple-muted/30 hover:bg-accent-purple-muted/50":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>z(F.id),onMouseLeave:()=>_(F.id),onClick:()=>w(F),children:[g&&F.author&&N0("div",{className:"flex items-center gap-1.5 mb-1.5",children:[N0("input",{type:"checkbox",checked:W.has(F.id),onChange:(I)=>{I.stopPropagation(),G(F.id)},onClick:(I)=>I.stopPropagation(),className:"accent-accent-purple flex-shrink-0",title:"Include in submission"},void 0,!1,void 0,this),N0("span",{className:"inline-flex items-center justify-center w-4 h-4 rounded-full bg-accent-purple text-white text-[9px] font-medium uppercase",children:F.author.name.charAt(0)},void 0,!1,void 0,this),N0("span",{className:"text-[11px] font-medium text-accent-purple font-body",children:F.author.name},void 0,!1,void 0,this),N0("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Remote"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N0("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:r8(F.snippet)},void 0,!1,void 0,this),J?N0(_4,{children:[F.note.trim()&&N0("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:F.note},void 0,!1,void 0,this),N0(t$,{images:F.images||[]},void 0,!1,void 0,this)]},void 0,!0,void 0,this):g?N0("div",{className:"text-[13px] font-body text-text-primary leading-relaxed whitespace-pre-wrap",children:F.note},void 0,!1,void 0,this):N0("div",{onClick:(I)=>I.stopPropagation(),children:N0(i1,{note:F.note,onNoteChange:(I)=>Y(F.id,I),images:F.images||[],onAddImage:(I)=>q(F.id,I),onRemoveImage:(I)=>U(F.id,I),sessionId:L,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),N0("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:[X&&N0("button",{onClick:(I)=>{I.stopPropagation(),X(F)},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:N0("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[N0("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),N0("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),!J&&!g&&N0("button",{onClick:(I)=>{I.stopPropagation(),H(F.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:N0("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[N0("polyline",{points:"3 6 5 6 21 6"},void 0,!1,void 0,this),N0("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)]},F.id,!0,void 0,this)};return N0(_4,{children:$.map(O)},void 0,!1,void 0,this)}function J$($){let J=[],Q=$.snippet.trim(),X=$.context,W=F2(Q);if(W!==Q)J.push(`> ${W}`);else if($.filePath&&X&&X.lineStart!=null){let H=X.lineStart,q=X.lineEnd??H,U=Q.split(`
2
+ `);if(Q.length<30&&H===q&&(X.before||X.after)){let M=h2($);J.push(`> L${H}: ${M}`)}else if(U.length<=6)for(let M=0;M<U.length;M++)J.push(`> ${H+M} | ${U[M]}`);else{for(let M=0;M<3;M++)J.push(`> ${H+M} | ${U[M]}`);J.push(`> ... (${U.length} lines)`);for(let M=U.length-3;M<U.length;M++)J.push(`> ${H+M} | ${U[M]}`)}}else{let H=h2($);if(Q.split(`
3
+ `).length<=3)J.push(`> ${H.split(`
4
+ `).join(`
5
+ > `)}`);else{let q=Q.split(`
6
+ `);J.push(`> ${q[0]}`),J.push(`> ... (${q.length} lines)`),J.push(`> ${q[q.length-1]}`)}}if($.note.trim())J.push(""),J.push($.note.trim());let G=[...$.images??[]],Y=new Set(G);for(let H of $.attachments??[]){if(Y.has(H.url))continue;Y.add(H.url),G.push(H.url)}if(G.length){J.push("");for(let H of G)J.push(`![screenshot](${H})`)}return J.push(""),J.join(`
7
+ `)}import{SessionContext as o8,useAnnotationHost as n8}from"@fabrika/annotations/runtime";import{useCallback as Q$,useContext as s8,useEffect as t8,useMemo as S4,useRef as X$,useState as r1}from"react";import{createPortal as a8}from"react-dom";function w4($){let J=/^(\d+(?:\.\d+)?)px$/.exec($.trim());return J?Number(J[1]):void 0}function O4($,J,Q=280){let W=J||document.body,G=$.getBoundingClientRect(),Y=W.getBoundingClientRect(),H=W===document.body?0:W.scrollTop,q=G.bottom-Y.top+H+8,U=Math.max(0,Math.min(G.left-Y.left,Y.width-Q-12));return W.style.position="relative",{style:{position:"absolute",top:`${q}px`,left:`${U}px`},parent:W}}import{jsxDEV as w0,Fragment as e8}from"react/jsx-dev-runtime";function C4({anchorEl:$,scrollContainer:J,onClose:Q,ignoreSelector:X,zIndex:W="50",padding:G="12px",width:Y="280px",children:H}){let q=X$(null),U=X$(Q);U.current=Q;let{style:N,parent:M}=O4($,J,w4(Y));return t8(()=>{let L=setTimeout(()=>{let K=(z)=>{if(q.current&&!q.current.contains(z.target)){if(X&&z.target.closest?.(X))return;U.current(),document.removeEventListener("mousedown",K)}};return document.addEventListener("mousedown",K),()=>document.removeEventListener("mousedown",K)},0);return()=>clearTimeout(L)},[X]),a8(w0("div",{ref:q,style:{...N,zIndex:W,width:Y,background:"var(--color-bg-elevated)",border:"1px solid var(--color-border-hover)",borderRadius:"8px",boxShadow:"0 4px 12px var(--color-shadow)",padding:G,fontFamily:"'Inter', sans-serif"},children:H},void 0,!1,void 0,this),M)}var P4=[{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"]}],R4=P4.flatMap(($)=>$.items);function a$({anchorEl:$,scrollContainer:J,snippet:Q,truncateAt:X=100,header:W,initialNote:G="",initialImages:Y,onConfirm:H,onCancel:q,onDelete:U}){let N=s8(o8),M=n8(),L=P2(M),K=G!==""||!!U,[z,_]=r1(G),[w,S]=r1(Y||[]),[O,F]=r1(null),[g,I]=r1(K),[h,V]=r1(!1),u=X$(null),E=X$(null),c=Q$(()=>{if(z.trim()||w.length>0)H(z.trim(),w);else if(K&&U)U();else q()},[z,w,H,q,K,U]),Q0=Q$(()=>{if(K){if(!z.trim()&&w.length===0&&U){U(),q();return}H(z,w);return}q()},[z,w,K,H,q,U]),$0=!K,W0=z.trim().length>0?R4.filter((P)=>P.toLowerCase().startsWith(z.trim().toLowerCase())):R4,_0=!$0||g?[]:W0.length===1&&W0[0]?.toLowerCase()===z.trim().toLowerCase()?[]:W0,d=new Set(_0),J0=P4.map((P)=>({label:P.label,items:P.items.filter((x)=>d.has(x))})).filter((P)=>P.items.length>0),t=J0.map((P)=>P.items),G0=(P)=>t[P]?.length??0,a=t.flat(),X0=S4(()=>{if(O===null)return 0;let P=0;for(let x=0;x<t.length;x++){if(O<P+G0(x))return x;P+=G0(x)}return 0},[O,t]),B0=S4(()=>{if(O===null)return 0;let P=0;for(let x=0;x<X0;x++)P+=G0(x);return O-P},[O,X0,t]),A=(P,x)=>{let i=0;for(let q0=0;q0<P;q0++)i+=G0(q0);return i+x},[b,p]=r1(z);if(z!==b)p(z),F(null),I(K);let T=Q$((P)=>{_(P)},[]),y=Q.length>X?Q.slice(0,X)+"...":Q,j=Q$((P)=>{if(a.length>0&&(P.key==="ArrowDown"||P.key==="ArrowUp"||P.key==="ArrowLeft"||P.key==="ArrowRight")){if(P.preventDefault(),O===null){F(0);return}if(P.key==="ArrowDown"){let i=Math.min(B0+1,G0(X0)-1);F(A(X0,i))}else if(P.key==="ArrowUp"){let i=Math.max(B0-1,0);F(A(X0,i))}else if(P.key==="ArrowRight"){let i=Math.min(X0+1,t.length-1),q0=Math.min(B0,G0(i)-1);F(A(i,q0))}else if(P.key==="ArrowLeft"){let i=Math.max(X0-1,0),q0=Math.min(B0,G0(i)-1);F(A(i,q0))}return}let x=O===null?void 0:a[O];if(x!==void 0){if(P.key==="Tab"){P.preventDefault(),T(x);return}if(P.key==="Enter"&&!P.shiftKey){P.preventDefault(),H(x,w);return}}if(P.key==="Enter"&&!P.shiftKey){P.preventDefault(),c();return}if(P.key==="Escape")if(a.length>0&&!g)I(!0);else if(K)Q0();else q()},[a,O,B0,X0,t,A,T,H,w,c,g,K,Q0,q]);return w0(C4,{anchorEl:$,scrollContainer:J,onClose:K?Q0:q,ignoreSelector:K?"[data-annotation-id]":void 0,zIndex:K?"60":"50",padding:K?"10px 12px":"12px",width:"420px",children:[!K&&(W??w0("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:["“",y,"”"]},void 0,!0,void 0,this)),w0(i1,{note:z,onNoteChange:_,images:w,onAddImage:(P)=>S((x)=>[...x,P]),onRemoveImage:(P)=>S((x)=>x.filter((i)=>i!==P)),sessionId:N,autoFocus:!0,autoResize:K,textareaRef:u,onKeyDown:j,attachButton:"none",openFilePickerRef:E,textareaStyle:K?{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),w0("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:K?"6px":"8px"},children:[L&&w0($$,{onClick:()=>E.current?.(),size:14},void 0,!1,void 0,this),w0("div",{style:{flex:1}},void 0,!1,void 0,this),K?w0("button",{onClick:()=>{if(U)U();q()},onMouseEnter:()=>V(!0),onMouseLeave:()=>V(!1),style:{fontSize:"11px",color:h?"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):w0(e8,{children:[w0("button",{onClick:q,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),w0("button",{onClick:c,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),a.length>0&&w0("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:J0.map((P)=>w0("div",{style:{flex:1},children:[w0("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:P.label},void 0,!1,void 0,this),P.items.map((x)=>{let i=a.indexOf(x);return w0("div",{onMouseDown:(q0)=>{q0.preventDefault(),q0.stopPropagation(),T(x)},onMouseEnter:()=>F(i),style:{padding:"3px 6px",fontSize:"12px",borderRadius:"4px",fontFamily:"'Inter', sans-serif",color:i===O?"var(--color-text-primary)":"var(--color-text-secondary)",background:i===O?"var(--color-highlight-selected)":"transparent",cursor:"pointer"},children:[w0("span",{style:{fontWeight:500},children:x.slice(0,z.trim().length)},void 0,!1,void 0,this),x.slice(z.trim().length)]},x,!0,void 0,this)})]},P.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function B1({anchorEl:$,scrollContainer:J,snippet:Q,truncateAt:X,header:W,onAdd:G,onCancel:Y}){return w0(a$,{anchorEl:$,scrollContainer:J,snippet:Q,truncateAt:X,header:W,onConfirm:(H,q)=>G(H,q),onCancel:Y},void 0,!1,void 0,this)}function j2({anchorEl:$,scrollContainer:J,initialNote:Q,initialImages:X,onUpdate:W,onDelete:G,onClose:Y}){return w0(a$,{anchorEl:$,scrollContainer:J,snippet:"",initialNote:Q,initialImages:X,onConfirm:(H,q)=>{W(H,q),Y()},onDelete:G,onCancel:Y},void 0,!1,void 0,this)}import{useEffect as $9,useRef as e$,useState as f4}from"react";import{jsxDEV as J9}from"react/jsx-dev-runtime";function $5($){let{containerRef:J,restoreKey:Q,shape:X="rect",canvasFile:W,scrollContainer:G}=$,{addAnnotationWithId:Y}=H1(),[H,q]=f4(null),[U,N]=f4(!1),M=e$(Y);M.current=Y;let L=e$(W);L.current=W;let K=e$(X);return K.current=X,$9(()=>{let _=J.current;if(!_)return;let w=null;function S(V,u){let E=V.getBoundingClientRect();return x$(E,u.clientX-E.left,u.clientY-E.top)}function O(){if(!w)return;let{host:V,pointerId:u}=w;if(V.hasPointerCapture(u))V.releasePointerCapture(u);V.removeEventListener("pointermove",g),V.removeEventListener("pointerup",I),V.removeEventListener("pointercancel",h),w=null,N(!1)}function F(V){if(w||V.button!==0)return;let u=V.target;if(!(u instanceof Element))return;if(u.closest("[data-block-comment-btn]"))return;if(u.closest("[data-annotation-id]"))return;let E=u.closest(`[${y$}]`);if(!(E instanceof HTMLElement)||!_?.contains(E))return;let c=E.closest("[data-md='image']")?.getAttribute("data-md-src");if(!c)return;let Q0=S(E,V);if(!Q0)return;V.preventDefault(),E.setPointerCapture(V.pointerId);let $0=t0(),W0=i2({...Q0,w:0,h:0},K.current,$0);W0.classList.add("ann-region-draft"),E.appendChild(W0),w={pointerId:V.pointerId,host:E,src:c,start:Q0,shape:K.current,overlay:W0,id:$0},E.addEventListener("pointermove",g),E.addEventListener("pointerup",I),E.addEventListener("pointercancel",h),N(!0)}function g(V){if(!w||w.pointerId!==V.pointerId)return;let u=S(w.host,V);if(!u)return;d2(w.overlay,p2(w.start,u))}function I(V){if(!w||w.pointerId!==V.pointerId)return;let{overlay:u,id:E,src:c,shape:Q0}=w,$0=S(w.host,V)??w.start,W0=p2(w.start,$0);if(O(),!v$(W0)){u.remove();return}d2(u,W0);let _0={src:c,shape:Q0,...W0};q({overlay:u,id:E,snippet:M2.format(_0),label:l2(_0)})}function h(V){if(!w||w.pointerId!==V.pointerId)return;w.overlay.remove(),O()}return _.addEventListener("pointerdown",F),()=>{if(_.removeEventListener("pointerdown",F),w)w.overlay.remove(),O()}},[Q]),{popovers:H?J9(B1,{anchorEl:H.overlay,scrollContainer:G,snippet:H.label,truncateAt:80,onAdd:(_,w)=>{H.overlay.classList.remove("ann-region-draft"),M.current(H.id,H.snippet,_,void 0,void 0,w,L.current),q(null)},onCancel:()=>{H.overlay.remove(),q(null)}},void 0,!1,void 0,this):null,isDrawing:U,isPopoverOpen:!!H}}import{useCallback as j4,useEffect as W$,useRef as S1,useState as Z4}from"react";import{jsxDEV as J5,Fragment as Q9}from"react/jsx-dev-runtime";function Q5($){let{containerRef:J,restoreKey:Q,restoreAnnotations:X,extractContext:W,filePath:G,canvasFile:Y,scrollContainer:H}=$,{annotations:q,addAnnotationWithId:U,removeAnnotation:N,updateAnnotation:M,addAnnotationImage:L,removeAnnotationImage:K,activeAnnotationId:z,setActiveAnnotationId:_}=H1(),[w,S]=Z4(null),[O,F]=Z4(null),g=S1(W);g.current=W;let I=S1(G);I.current=G;let h=S1(Y);h.current=Y;let V=S1(U);V.current=U;let u=S1(z);u.current=z;let E=S1(_);E.current=_;let c=X.length;W$(()=>{if(!J.current)return;let d=setTimeout(()=>{if(J.current)u$(J.current,X)},50);return()=>clearTimeout(d)},[Q,c]);let Q0=S1(null);W$(()=>{A$(z,Q0.current),Q0.current=z},[z]),W$(()=>{let d=J.current;if(!d)return;let J0=(a)=>{let X0=a.target.closest("[data-annotation-id]");if(!X0)return;a.stopPropagation();let B0=X0.getAttribute("data-annotation-id");if(B0===u.current)S({anchorEl:X0,annId:B0});else E.current(B0)},t=(a)=>{let X0=a.target.closest("[data-annotation-id]");if(X0)E.current(X0.getAttribute("data-annotation-id"))},G0=(a)=>{let X0=a.target.closest("[data-annotation-id]"),B0=a.relatedTarget?.closest?.("[data-annotation-id]");if(X0&&!B0&&!document.getElementById("ann-inline-popover"))E.current(null)};return d.addEventListener("click",J0),d.addEventListener("mouseover",t),d.addEventListener("mouseout",G0),()=>{d.removeEventListener("click",J0),d.removeEventListener("mouseover",t),d.removeEventListener("mouseout",G0)}},[Q]),W$(()=>{let d=()=>$0();return document.addEventListener("mouseup",d),()=>document.removeEventListener("mouseup",d)},[]);let $0=j4(()=>{let d=window.getSelection();if(!d||d.isCollapsed||!d.toString().trim())return;if(!J.current)return;let J0=d.getRangeAt(0);if(!J.current.contains(J0.startContainer))return;if(J0.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let t=s5(J0).trim();if(t.length<2)return;let G0=g.current(J0),a=J0.cloneRange(),X0=`__pending_${Date.now()}`;try{v2(a,X0)}catch{}window.getSelection()?.removeAllRanges();let B0=document.querySelectorAll(`[data-annotation-id="${X0}"]`),A=B0[B0.length-1];if(!A)return;F({anchorEl:A,tempId:X0,snippet:t,ctx:G0})},[]),W0=j4((d,J0,t,G0)=>{F({anchorEl:d,tempId:J0,snippet:t,ctx:G0})},[]);return{popovers:J5(Q9,{children:[w&&(()=>{let d=q.find((J0)=>J0.id===w.annId);if(!d)return null;return J5(j2,{anchorEl:w.anchorEl,scrollContainer:H,initialNote:d.note,initialImages:d.images,onUpdate:(J0,t)=>{M(w.annId,J0);let G0=d.images||[];for(let a of t)if(!G0.includes(a))L(w.annId,a);for(let a of G0)if(!t.includes(a))K(w.annId,a)},onDelete:()=>{N(w.annId),_(null)},onClose:()=>S(null)},void 0,!1,void 0,this)})(),O&&J5(B1,{anchorEl:O.anchorEl,scrollContainer:H,snippet:O.snippet,truncateAt:80,onAdd:(d,J0)=>{let t=t0();k$(O.tempId,t),V.current(t,O.snippet,d,I.current,O.ctx,J0,h.current),F(null)},onCancel:()=>{D$(O.tempId),F(null)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),openCreatePopover:W0,isPopoverOpen:!!(w||O)}}import{AnnotationCtx as B9}from"#canvas/runtime";import{AnnotationCtx as U9,AnnotationHostContext as N9}from"@fabrika/annotations/runtime";import{useCallback as t1,useEffect as y4,useMemo as L9,useRef as G5,useState as a1}from"react";var jW=B.object({}).passthrough(),ZW=B.object({annotations:B.array(B.unknown()).catch([]),generalNote:B.string().catch(""),responses:B.array(B.unknown()).catch([])}),VW=B.tuple([B.unknown(),B.object({note:B.unknown(),value:B.unknown()})]);function R1($,J,Q="current"){let X=`canvas:${$}:rev:${J}`;return Q==="next"?`${X}:next-draft`:X}function X9($,J){return`${R1($,J)}:draft-handled`}function X5($,J,Q){try{$.removeItem(R1(J,Q)),$.removeItem(X9(J,Q))}catch{}}function W5($,J){let Q=new Map;for(let[X,W]of $)if(J.has(X))Q.set(X,W);return Q}function Y5($,J){if(!$||$.length===0)return!1;return $.every((Q)=>J.has(Q))}function W9($,J){return $.filter((Q)=>Q.source!=="remote"||J&&J.has(Q.id))}function o1($,J,Q,X,W,G={}){let Y=[],H=W9($,W),q=(_)=>G.annotationIds&&_.source!=="remote"?`Annotation \`${_.id}\`
8
+ ${J$(_)}`:J$(_),U=H.filter((_)=>_.filePath===G1),N=H.filter((_)=>!_.filePath),M=H.filter((_)=>_.filePath&&_.filePath!==G1),L=Q?Array.from(Q.values()).filter((_)=>Z2(_)):[],K=X?Array.from(X.values()).filter((_)=>_.markdown.trim()):[];if(L.length>0||K.length>0){Y.push("## Responses"),Y.push("");for(let _ of L)Y.push(Y9(_));for(let _ of K)Y.push(_.markdown.trim()),Y.push("")}if(U.length>0){Y.push("## Annotations on agent response"),Y.push("");for(let _ of U)Y.push(q(_))}if(N.length>0){Y.push("## Canvas annotations"),Y.push("");let _=new Map;for(let O of N){let F=O.canvasFile||"";if(!_.has(F))_.set(F,[]);_.get(F).push(O)}let w=[..._.keys()].sort(),S=w.length>1||w.length===1&&w[0]!=="";for(let O of w){let F=_.get(O);if(S&&O)Y.push(`### ${O.replace(/\.jsx$/,"")}`),Y.push("");let g=G9(F);Y.push(T4(g,q))}}if(M.length>0){let _={};for(let w of M){let S=w.filePath;if(!_[S])_[S]=[];_[S].push(w)}Y.push("## File annotations"),Y.push("");for(let[w,S]of Object.entries(_)){Y.push(`### ${w}`),Y.push("");for(let O of S)Y.push(q(O))}}if(J.trim())Y.push("## General notes"),Y.push(""),Y.push(J.trim()),Y.push("");return Y.join(`
9
+ `).trim()+`
10
+ `}function V4($){return Array.from($.values()).filter(Z2).map(({id:J,value:Q})=>({id:J,value:Q}))}function Z2($){if($.note?.trim())return!0;if($.value===null||$.value===void 0)return!1;if($.type==="text"&&!$.value.trim())return!1;if($.type==="checkbox"&&$.value.length===0)return!1;return!0}function A4($){let J=[];for(let Q of $.values()){if(!Q.required)continue;if(Q.value===null||Q.value===void 0){J.push(Q);continue}if(Q.type==="text"&&!Q.value.trim()){J.push(Q);continue}if(Q.type==="checkbox"&&Q.value.length===0){J.push(Q);continue}}return J}function k4($){let J=[];for(let Q of $.values())if(Q.required&&!Q.markdown.trim())J.push(Q);return J}function n1($,J){let Q=A4($),X=k4(J);return[...Q.map((W)=>W.label),...X.map((W)=>W.label||W.id)]}function Y9($){let J=[];switch(J.push(`**${$.label}**`),$.type){case"radio":case"select":J.push(`Answer: ${$.value}`);break;case"checkbox":for(let Q of $.value)J.push(`- [x] ${Q}`);break;case"text":J.push(""),J.push($.value.trim());break;case"range":J.push(`Answer: ${$.value}`);break}if($.note?.trim())J.push(""),J.push(`Note: ${$.note.trim()}`);return J.push(""),J.join(`
11
+ `)}function G9($){let J={label:"",annotations:[],children:new Map};for(let Q of $){let X=Q.context?.hierarchy||[],W=J;for(let G of X){if(!W.children.has(G))W.children.set(G,{label:G,annotations:[],children:new Map});W=W.children.get(G)}W.annotations.push(Q)}return J}function T4($,J,Q=0){let X=[];for(let W of $.annotations)X.push(J(W));for(let[,W]of $.children){let G=Q===0?"###":"####";X.push(`${G} ${W.label}`),X.push(""),X.push(T4(W,J,Q+1))}return X.join(`
12
+ `)}import{createContext as q9,useContext as H9}from"react";function D4(){if(typeof window>"u")return"";return window.location.pathname.replace("/s/","")}var I4={get sessionId(){return D4()},isShared:!1,fsAvailable:!0,uploadUrl:null,loadCanvasModule:($,J)=>{let Q=$.replace(/\.jsx$/,".js"),X=J?`?rev=${J}&t=${Date.now()}`:`?t=${Date.now()}`;return import(`/api/session/${D4()}/canvas/${encodeURIComponent(Q)}${X}`)},threads:null},b4=q9(I4);function j0(){return H9(b4)}var Y$=B.object({id:B.string(),type:B.enum(["select","radio","checkbox","text","range"]),label:B.string(),value:B.unknown(),options:B.array(B.string()).optional(),required:B.boolean().optional(),note:B.string().optional()}).passthrough().transform(($)=>({...$,value:$.value})),G$=B.object({id:B.string(),markdown:B.string(),label:B.string().optional(),required:B.boolean().optional()}).passthrough(),q$=i$.extend({responses:B.array(B.tuple([B.string(),Y$]).optional().catch(void 0)).transform(($)=>$.filter((J)=>J!==void 0)).catch([]),feedbackEntries:B.array(B.tuple([B.string(),G$]).optional().catch(void 0)).transform(($)=>$.filter((J)=>J!==void 0)).optional().catch([])});function s1($){let J=q$.safeParse($);return J.success?J.data:null}var g4=B.object({feedback:B.string().nullish()}),E4=B.union([B.object({error:B.string().min(1)}),B.object({content:B.string(),language:B.string().nullish()})]);import{useAnnotations as C1}from"#canvas/runtime";import{jsxDEV as H5}from"react/jsx-dev-runtime";function x4($,J,Q){try{let X=localStorage.getItem(R1($,J,Q));if(!X)return null;return s1(JSON.parse(X))}catch{return null}}function K9($,J,Q,X){try{localStorage.setItem(R1($,J,Q),JSON.stringify(X))}catch{}}function q5($){return{draft:$,responseIds:new Set,canvases:new Set}}function H$({sessionId:$,revision:J,isReadOnly:Q,draftPhase:X,remoteAnnotations:W,canvasFiles:G,loadState:Y,saveState:H,children:q}){let U=!!Y,N=U?null:x4($,J,X),M=G5(N),[L,K]=a1(()=>(N?.annotations??[]).map((A)=>({...A,source:A.source??"local"}))),[z,_]=a1(()=>N?.generalNote??""),[w,S]=a1(()=>N?.responses?new Map(N.responses):new Map),O=`${$}:${J}:${X}`,F=G5(O);F.current=O;let[g,I]=a1(()=>q5(O)),[h,V]=a1(()=>N?.feedbackEntries?new Map(N.feedbackEntries):new Map),[u,E]=a1(!U);y4(()=>{let A=(b)=>{M.current=b,K((b?.annotations??[]).map((p)=>({...p,source:p.source??"local"}))),_(b?.generalNote??""),S(b?.responses?new Map(b.responses):new Map),V(b?.feedbackEntries?new Map(b.feedbackEntries):new Map),X0(null)};if(U){let b=!1;return E(!1),Y($,J,X).then((p)=>{if(b)return;A(s1(p)),E(!0)}),()=>{b=!0}}A(x4($,J,X)),E(!0);return},[$,J,X,U,Y]);let c=G5(null);y4(()=>{if(Q&&X!=="next")return;if(!u)return;if(c.current)clearTimeout(c.current);let A={...M.current,annotations:L,generalNote:z,responses:Array.from(w.entries()),feedbackEntries:Array.from(h.entries())},b=()=>{if(H)H($,J,A,X);else K9($,J,X,A)};if(X==="next"){b();return}return c.current=setTimeout(b,300),()=>{if(c.current)clearTimeout(c.current)}},[L,z,w,h,$,J,Q,X,u,H]);let Q0=t1((A,b)=>{S((p)=>{let T=new Map(p);return T.set(A,b),T})},[]),$0=t1((A)=>{I((b)=>{let p=b.draft===F.current?b:q5(F.current);if(p.responseIds.has(A))return p;return{...p,responseIds:new Set(p.responseIds).add(A)}})},[]),W0=t1((A)=>{I((b)=>{let p=b.draft===F.current?b:q5(F.current);if(p.canvases.has(A))return p;return{...p,canvases:new Set(p.canvases).add(A)}})},[]),_0=g.draft===O?g:null,d=L9(()=>{if(!_0||!Y5(G,_0.canvases))return w;return W5(w,_0.responseIds)},[_0,G,w]),J0=t1((A,b)=>{V((p)=>{let T=p.get(A);if(T&&T.markdown===b.markdown&&T.label===b.label&&T.required===b.required)return p;let y=new Map(p);return y.set(A,b),y})},[]),t=t1((A)=>{V((b)=>{if(!b.has(A))return b;let p=new Map(b);return p.delete(A),p})},[]),G0=t1(()=>{if(S(new Map),V(new Map),H)H($,J,{annotations:[],generalNote:"",responses:[],feedbackEntries:[]},X);else if(X==="next")localStorage.removeItem(R1($,J,X));else X5(localStorage,$,J)},[$,J,X,H]),a=a2({annotations:L,setAnnotations:K,generalNote:z,setGeneralNote:_,remoteAnnotations:W,isReadOnly:Q,onClear:G0}),{setActiveAnnotationId:X0}=a,B0=j0();return H5(N9.Provider,{value:B0,children:H5(U9.Provider,{value:a,children:H5(B9.Provider,{value:{...a,responses:w,setResponse:Q0,submittableResponses:d,registerResponse:$0,registerCanvasRendered:W0,feedbackEntries:h,setFeedbackEntry:J0,removeFeedbackEntry:t},children:q},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}import{ActiveViewCtx as D6,AnnotationCtx as I6,CanvasFileCtx as b6,SessionContext as T5,useAnnotations as g6,useCanvasFile as eH,useFeedback as E6,useResponseRegistration as $B}from"#canvas/runtime";function V2($){let J=document.querySelector(`[data-annotation-id="${$.id}"]`);if(J instanceof HTMLElement)return J;let Q=$.canvasFile?document.querySelector(`[data-canvas-file="${$.canvasFile}"]`):document;if(!Q)return null;return m$($.snippet,Q)}function v4($){$.classList.remove("ann-flash"),$.offsetWidth,$.classList.add("ann-flash"),$.addEventListener("animationend",()=>{$.classList.remove("ann-flash")},{once:!0})}function B5($,J){let Q=_1($);if(Q)J({type:"file",path:Q}),setTimeout(()=>{let X=V2($);if(X)X.scrollIntoView({behavior:"smooth",block:"center"}),v4(X)},150);else{let X=V2($);if(X)X.scrollIntoView({behavior:"smooth",block:"center"}),v4(X)}}import{SessionContext as M6}from"#canvas/runtime";import{useCallback as Z5,useContext as V5,useEffect as B3,useMemo as F6,useState as W2}from"react";import{createContext as h4}from"react";var e1=h4({activeView:{type:"overview"},setActiveView:()=>{},openFiles:[],closeFile:()=>{},canvasFiles:[]}),$2=h4({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{},agentWatching:!1});import{jsxDEV as P1}from"react/jsx-dev-runtime";var M9={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"},F9={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 U5({name:$,type:J,expanded:Q,className:X=""}){if(J==="dir")return P1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",className:`flex-shrink-0 ${X}`,children:Q?P1("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):P1("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 W=$.includes(".")?$.split(".").pop().toLowerCase():"",G=M9[W]||"#6b6560",Y=F9[W];return P1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",className:`flex-shrink-0 ${X}`,children:[P1("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:G,opacity:"0.85"},void 0,!1,void 0,this),P1("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),Y&&P1("text",{x:"8",y:"11.5",textAnchor:"middle",fill:"white",fontSize:"5.5",fontFamily:"monospace",fontWeight:"600",children:Y},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function L5(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var Z1=L5();function i4($){Z1=$}var f1={exec:()=>null};function s($,J=""){let Q=typeof $=="string"?$:$.source,X={replace:(W,G)=>{let Y=typeof G=="string"?G:G.source;return Y=Y.replace(C0.caret,"$1"),Q=Q.replace(W,Y),X},getRegex:()=>new RegExp(Q,J)};return X}var z9=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),C0={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:($)=>new RegExp(`^( {0,3}${$})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:($)=>new RegExp(`^ {0,${Math.min(3,$-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:($)=>new RegExp(`^ {0,${Math.min(3,$-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:($)=>new RegExp(`^ {0,${Math.min(3,$-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:($)=>new RegExp(`^ {0,${Math.min(3,$-1)}}#`),htmlBeginRegex:($)=>new RegExp(`^ {0,${Math.min(3,$-1)}}<(?:[a-z].*>|!--)`,"i"),blockquoteBeginRegex:($)=>new RegExp(`^ {0,${Math.min(3,$-1)}}>`)},_9=/^(?:[ \t]*(?:\n|$))+/,w9=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,O9=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,D2=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,S9=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,K5=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,r4=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,o4=s(r4).replace(/bull/g,K5).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(),R9=s(r4).replace(/bull/g,K5).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(),M5=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,C9=/^[^\n]+/,F5=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,P9=s(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",F5).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),f9=s(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,K5).getRegex(),K$="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",z5=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,j9=s("^ {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",z5).replace("tag",K$).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),n4=s(M5).replace("hr",D2).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",K$).getRegex(),Z9=s(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",n4).getRegex(),_5={blockquote:Z9,code:w9,def:P9,fences:O9,heading:S9,hr:D2,html:j9,lheading:o4,list:f9,newline:_9,paragraph:n4,table:f1,text:C9},m4=s("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",D2).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",K$).getRegex(),V9={..._5,lheading:R9,table:m4,paragraph:s(M5).replace("hr",D2).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",m4).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",K$).getRegex()},A9={..._5,html:s(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",z5).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:f1,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:s(M5).replace("hr",D2).replace("heading",` *#{1,6} *[^
13
+ ]`).replace("lheading",o4).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},k9=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,T9=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,s4=/^( {2,}|\\)\n(?!\s*$)/,D9=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,J2=/[\p{P}\p{S}]/u,M$=/[\s\p{P}\p{S}]/u,w5=/[^\s\p{P}\p{S}]/u,I9=s(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,M$).getRegex(),t4=/(?!~)[\p{P}\p{S}]/u,b9=/(?!~)[\s\p{P}\p{S}]/u,g9=/(?:[^\s\p{P}\p{S}]|~)/u,E9=s(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",z9?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),a4=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,y9=s(a4,"u").replace(/punct/g,J2).getRegex(),x9=s(a4,"u").replace(/punct/g,t4).getRegex(),e4="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",v9=s(e4,"gu").replace(/notPunctSpace/g,w5).replace(/punctSpace/g,M$).replace(/punct/g,J2).getRegex(),h9=s(e4,"gu").replace(/notPunctSpace/g,g9).replace(/punctSpace/g,b9).replace(/punct/g,t4).getRegex(),m9=s("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,w5).replace(/punctSpace/g,M$).replace(/punct/g,J2).getRegex(),u9=s(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,J2).getRegex(),c9="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",p9=s(c9,"gu").replace(/notPunctSpace/g,w5).replace(/punctSpace/g,M$).replace(/punct/g,J2).getRegex(),l9=s(/\\(punct)/,"gu").replace(/punct/g,J2).getRegex(),d9=s(/^<(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(),i9=s(z5).replace("(?:-->|$)","-->").getRegex(),r9=s("^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",i9).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),U$=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,o9=s(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",U$).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),$3=s(/^!?\[(label)\]\[(ref)\]/).replace("label",U$).replace("ref",F5).getRegex(),J3=s(/^!?\[(ref)\](?:\[\])?/).replace("ref",F5).getRegex(),n9=s("reflink|nolink(?!\\()","g").replace("reflink",$3).replace("nolink",J3).getRegex(),u4=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,O5={_backpedal:f1,anyPunctuation:l9,autolink:d9,blockSkip:E9,br:s4,code:T9,del:f1,delLDelim:f1,delRDelim:f1,emStrongLDelim:y9,emStrongRDelimAst:v9,emStrongRDelimUnd:m9,escape:k9,link:o9,nolink:J3,punctuation:I9,reflink:$3,reflinkSearch:n9,tag:r9,text:D9,url:f1},s9={...O5,link:s(/^!?\[(label)\]\((.*?)\)/).replace("label",U$).getRegex(),reflink:s(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",U$).getRegex()},N5={...O5,emStrongRDelimAst:h9,emStrongLDelim:x9,delLDelim:u9,delRDelim:p9,url:s(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",u4).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:s(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",u4).getRegex()},t9={...N5,br:s(s4).replace("{2,}","*").getRegex(),text:s(N5.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},B$={normal:_5,gfm:V9,pedantic:A9},A2={normal:O5,gfm:N5,breaks:t9,pedantic:s9},a9={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},c4=($)=>a9[$];function d0($,J){if(J){if(C0.escapeTest.test($))return $.replace(C0.escapeReplace,c4)}else if(C0.escapeTestNoEncode.test($))return $.replace(C0.escapeReplaceNoEncode,c4);return $}function p4($){try{$=encodeURI($).replace(C0.percentDecode,"%")}catch{return null}return $}function l4($,J){let Q=$.replace(C0.findPipe,(G,Y,H)=>{let q=!1,U=Y;for(;--U>=0&&H[U]==="\\";)q=!q;return q?"|":" |"}),X=Q.split(C0.splitPipe),W=0;if(X[0].trim()||X.shift(),X.length>0&&!X.at(-1)?.trim()&&X.pop(),J)if(X.length>J)X.splice(J);else for(;X.length<J;)X.push("");for(;W<X.length;W++)X[W]=X[W].trim().replace(C0.slashPipe,"|");return X}function k2($,J,Q){let X=$.length;if(X===0)return"";let W=0;for(;W<X;){let G=$.charAt(X-W-1);if(G===J&&!Q)W++;else if(G!==J&&Q)W++;else break}return $.slice(0,X-W)}function e9($,J){if($.indexOf(J[1])===-1)return-1;let Q=0;for(let X=0;X<$.length;X++)if($[X]==="\\")X++;else if($[X]===J[0])Q++;else if($[X]===J[1]&&(Q--,Q<0))return X;return Q>0?-2:-1}function $6($,J=0){let Q=J,X="";for(let W of $)if(W==="\t"){let G=4-Q%4;X+=" ".repeat(G),Q+=G}else X+=W,Q++;return X}function d4($,J,Q,X,W){let G=J.href,Y=J.title||null,H=$[1].replace(W.other.outputLinkReplace,"$1");X.state.inLink=!0;let q={type:$[0].charAt(0)==="!"?"image":"link",raw:Q,href:G,title:Y,text:H,tokens:X.inlineTokens(H)};return X.state.inLink=!1,q}function J6($,J,Q){let X=$.match(Q.other.indentCodeCompensation);if(X===null)return J;let W=X[1];return J.split(`
14
+ `).map((G)=>{let Y=G.match(Q.other.beginningSpace);if(Y===null)return G;let[H]=Y;return H.length>=W.length?G.slice(W.length):G}).join(`
15
+ `)}var N$=class{options;rules;lexer;constructor($){this.options=$||Z1}space($){let J=this.rules.block.newline.exec($);if(J&&J[0].length>0)return{type:"space",raw:J[0]}}code($){let J=this.rules.block.code.exec($);if(J){let Q=J[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:J[0],codeBlockStyle:"indented",text:this.options.pedantic?Q:k2(Q,`
16
+ `)}}}fences($){let J=this.rules.block.fences.exec($);if(J){let Q=J[0],X=J6(Q,J[3]||"",this.rules);return{type:"code",raw:Q,lang:J[2]?J[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):J[2],text:X}}}heading($){let J=this.rules.block.heading.exec($);if(J){let Q=J[2].trim();if(this.rules.other.endingHash.test(Q)){let X=k2(Q,"#");(this.options.pedantic||!X||this.rules.other.endingSpaceChar.test(X))&&(Q=X.trim())}return{type:"heading",raw:J[0],depth:J[1].length,text:Q,tokens:this.lexer.inline(Q)}}}hr($){let J=this.rules.block.hr.exec($);if(J)return{type:"hr",raw:k2(J[0],`
17
+ `)}}blockquote($){let J=this.rules.block.blockquote.exec($);if(J){let Q=k2(J[0],`
18
+ `).split(`
19
+ `),X="",W="",G=[];for(;Q.length>0;){let Y=!1,H=[],q;for(q=0;q<Q.length;q++)if(this.rules.other.blockquoteStart.test(Q[q]))H.push(Q[q]),Y=!0;else if(!Y)H.push(Q[q]);else break;Q=Q.slice(q);let U=H.join(`
20
+ `),N=U.replace(this.rules.other.blockquoteSetextReplace,`
21
+ $1`).replace(this.rules.other.blockquoteSetextReplace2,"");X=X?`${X}
22
+ ${U}`:U,W=W?`${W}
23
+ ${N}`:N;let M=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(N,G,!0),this.lexer.state.top=M,Q.length===0)break;let L=G.at(-1);if(L?.type==="code")break;if(L?.type==="blockquote"){let K=L,z=K.raw+`
24
+ `+Q.join(`
25
+ `),_=this.blockquote(z);G[G.length-1]=_,X=X.substring(0,X.length-K.raw.length)+_.raw,W=W.substring(0,W.length-K.text.length)+_.text;break}else if(L?.type==="list"){let K=L,z=K.raw+`
26
+ `+Q.join(`
27
+ `),_=this.list(z);G[G.length-1]=_,X=X.substring(0,X.length-L.raw.length)+_.raw,W=W.substring(0,W.length-K.raw.length)+_.raw,Q=z.substring(G.at(-1).raw.length).split(`
28
+ `);continue}}return{type:"blockquote",raw:X,tokens:G,text:W}}}list($){let J=this.rules.block.list.exec($);if(J){let Q=J[1].trim(),X=Q.length>1,W={type:"list",raw:"",ordered:X,start:X?+Q.slice(0,-1):"",loose:!1,items:[]};Q=X?`\\d{1,9}\\${Q.slice(-1)}`:`\\${Q}`,this.options.pedantic&&(Q=X?Q:"[*+-]");let G=this.rules.other.listItemRegex(Q),Y=!1;for(;$;){let q=!1,U="",N="";if(!(J=G.exec($))||this.rules.block.hr.test($))break;U=J[0],$=$.substring(U.length);let M=$6(J[2].split(`
29
+ `,1)[0],J[1].length),L=$.split(`
30
+ `,1)[0],K=!M.trim(),z=0;if(this.options.pedantic?(z=2,N=M.trimStart()):K?z=J[1].length+1:(z=M.search(this.rules.other.nonSpaceChar),z=z>4?1:z,N=M.slice(z),z+=J[1].length),K&&this.rules.other.blankLine.test(L)&&(U+=L+`
31
+ `,$=$.substring(L.length+1),q=!0),!q){let _=this.rules.other.nextBulletRegex(z),w=this.rules.other.hrRegex(z),S=this.rules.other.fencesBeginRegex(z),O=this.rules.other.headingBeginRegex(z),F=this.rules.other.htmlBeginRegex(z),g=this.rules.other.blockquoteBeginRegex(z);for(;$;){let I=$.split(`
32
+ `,1)[0],h;if(L=I,this.options.pedantic?(L=L.replace(this.rules.other.listReplaceNesting," "),h=L):h=L.replace(this.rules.other.tabCharGlobal," "),S.test(L)||O.test(L)||F.test(L)||g.test(L)||_.test(L)||w.test(L))break;if(h.search(this.rules.other.nonSpaceChar)>=z||!L.trim())N+=`
33
+ `+h.slice(z);else{if(K||M.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||S.test(M)||O.test(M)||w.test(M))break;N+=`
34
+ `+L}K=!L.trim(),U+=I+`
35
+ `,$=$.substring(I.length+1),M=h.slice(z)}}W.loose||(Y?W.loose=!0:this.rules.other.doubleBlankLine.test(U)&&(Y=!0)),W.items.push({type:"list_item",raw:U,task:!!this.options.gfm&&this.rules.other.listIsTask.test(N),loose:!1,text:N,tokens:[]}),W.raw+=U}let H=W.items.at(-1);if(H)H.raw=H.raw.trimEnd(),H.text=H.text.trimEnd();else return;W.raw=W.raw.trimEnd();for(let q of W.items){if(this.lexer.state.top=!1,q.tokens=this.lexer.blockTokens(q.text,[]),q.task){if(q.text=q.text.replace(this.rules.other.listReplaceTask,""),q.tokens[0]?.type==="text"||q.tokens[0]?.type==="paragraph"){q.tokens[0].raw=q.tokens[0].raw.replace(this.rules.other.listReplaceTask,""),q.tokens[0].text=q.tokens[0].text.replace(this.rules.other.listReplaceTask,"");for(let N=this.lexer.inlineQueue.length-1;N>=0;N--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[N].src)){this.lexer.inlineQueue[N].src=this.lexer.inlineQueue[N].src.replace(this.rules.other.listReplaceTask,"");break}}let U=this.rules.other.listTaskCheckbox.exec(q.raw);if(U){let N={type:"checkbox",raw:U[0]+" ",checked:U[0]!=="[ ]"};q.checked=N.checked,W.loose?q.tokens[0]&&["paragraph","text"].includes(q.tokens[0].type)&&"tokens"in q.tokens[0]&&q.tokens[0].tokens?(q.tokens[0].raw=N.raw+q.tokens[0].raw,q.tokens[0].text=N.raw+q.tokens[0].text,q.tokens[0].tokens.unshift(N)):q.tokens.unshift({type:"paragraph",raw:N.raw,text:N.raw,tokens:[N]}):q.tokens.unshift(N)}}if(!W.loose){let U=q.tokens.filter((M)=>M.type==="space"),N=U.length>0&&U.some((M)=>this.rules.other.anyLine.test(M.raw));W.loose=N}}if(W.loose)for(let q of W.items){q.loose=!0;for(let U of q.tokens)U.type==="text"&&(U.type="paragraph")}return W}}html($){let J=this.rules.block.html.exec($);if(J)return{type:"html",block:!0,raw:J[0],pre:J[1]==="pre"||J[1]==="script"||J[1]==="style",text:J[0]}}def($){let J=this.rules.block.def.exec($);if(J){let Q=J[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),X=J[2]?J[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",W=J[3]?J[3].substring(1,J[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):J[3];return{type:"def",tag:Q,raw:J[0],href:X,title:W}}}table($){let J=this.rules.block.table.exec($);if(!J||!this.rules.other.tableDelimiter.test(J[2]))return;let Q=l4(J[1]),X=J[2].replace(this.rules.other.tableAlignChars,"").split("|"),W=J[3]?.trim()?J[3].replace(this.rules.other.tableRowBlankLine,"").split(`
36
+ `):[],G={type:"table",raw:J[0],header:[],align:[],rows:[]};if(Q.length===X.length){for(let Y of X)this.rules.other.tableAlignRight.test(Y)?G.align.push("right"):this.rules.other.tableAlignCenter.test(Y)?G.align.push("center"):this.rules.other.tableAlignLeft.test(Y)?G.align.push("left"):G.align.push(null);for(let Y=0;Y<Q.length;Y++)G.header.push({text:Q[Y],tokens:this.lexer.inline(Q[Y]),header:!0,align:G.align[Y]});for(let Y of W)G.rows.push(l4(Y,G.header.length).map((H,q)=>({text:H,tokens:this.lexer.inline(H),header:!1,align:G.align[q]})));return G}}lheading($){let J=this.rules.block.lheading.exec($);if(J){let Q=J[1].trim();return{type:"heading",raw:J[0],depth:J[2].charAt(0)==="="?1:2,text:Q,tokens:this.lexer.inline(Q)}}}paragraph($){let J=this.rules.block.paragraph.exec($);if(J){let Q=J[1].charAt(J[1].length-1)===`
37
+ `?J[1].slice(0,-1):J[1];return{type:"paragraph",raw:J[0],text:Q,tokens:this.lexer.inline(Q)}}}text($){let J=this.rules.block.text.exec($);if(J)return{type:"text",raw:J[0],text:J[0],tokens:this.lexer.inline(J[0])}}escape($){let J=this.rules.inline.escape.exec($);if(J)return{type:"escape",raw:J[0],text:J[1]}}tag($){let J=this.rules.inline.tag.exec($);if(J)return!this.lexer.state.inLink&&this.rules.other.startATag.test(J[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(J[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(J[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(J[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:J[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:J[0]}}link($){let J=this.rules.inline.link.exec($);if(J){let Q=J[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(Q)){if(!this.rules.other.endAngleBracket.test(Q))return;let G=k2(Q.slice(0,-1),"\\");if((Q.length-G.length)%2===0)return}else{let G=e9(J[2],"()");if(G===-2)return;if(G>-1){let Y=(J[0].indexOf("!")===0?5:4)+J[1].length+G;J[2]=J[2].substring(0,G),J[0]=J[0].substring(0,Y).trim(),J[3]=""}}let X=J[2],W="";if(this.options.pedantic){let G=this.rules.other.pedanticHrefTitle.exec(X);G&&(X=G[1],W=G[3])}else W=J[3]?J[3].slice(1,-1):"";return X=X.trim(),this.rules.other.startAngleBracket.test(X)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(Q)?X=X.slice(1):X=X.slice(1,-1)),d4(J,{href:X&&X.replace(this.rules.inline.anyPunctuation,"$1"),title:W&&W.replace(this.rules.inline.anyPunctuation,"$1")},J[0],this.lexer,this.rules)}}reflink($,J){let Q;if((Q=this.rules.inline.reflink.exec($))||(Q=this.rules.inline.nolink.exec($))){let X=(Q[2]||Q[1]).replace(this.rules.other.multipleSpaceGlobal," "),W=J[X.toLowerCase()];if(!W){let G=Q[0].charAt(0);return{type:"text",raw:G,text:G}}return d4(Q,W,Q[0],this.lexer,this.rules)}}emStrong($,J,Q=""){let X=this.rules.inline.emStrongLDelim.exec($);if(!X||!X[1]&&!X[2]&&!X[3]&&!X[4]||X[4]&&Q.match(this.rules.other.unicodeAlphaNumeric))return;if(!(X[1]||X[3])||!Q||this.rules.inline.punctuation.exec(Q)){let W=[...X[0]].length-1,G,Y,H=W,q=0,U=X[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(U.lastIndex=0,J=J.slice(-1*$.length+W);(X=U.exec(J))!==null;){if(G=X[1]||X[2]||X[3]||X[4]||X[5]||X[6],!G)continue;if(Y=[...G].length,X[3]||X[4]){H+=Y;continue}else if((X[5]||X[6])&&W%3&&!((W+Y)%3)){q+=Y;continue}if(H-=Y,H>0)continue;Y=Math.min(Y,Y+H+q);let N=[...X[0]][0].length,M=$.slice(0,W+X.index+N+Y);if(Math.min(W,Y)%2){let K=M.slice(1,-1);return{type:"em",raw:M,text:K,tokens:this.lexer.inlineTokens(K)}}let L=M.slice(2,-2);return{type:"strong",raw:M,text:L,tokens:this.lexer.inlineTokens(L)}}}}codespan($){let J=this.rules.inline.code.exec($);if(J){let Q=J[2].replace(this.rules.other.newLineCharGlobal," "),X=this.rules.other.nonSpaceChar.test(Q),W=this.rules.other.startingSpaceChar.test(Q)&&this.rules.other.endingSpaceChar.test(Q);return X&&W&&(Q=Q.substring(1,Q.length-1)),{type:"codespan",raw:J[0],text:Q}}}br($){let J=this.rules.inline.br.exec($);if(J)return{type:"br",raw:J[0]}}del($,J,Q=""){let X=this.rules.inline.delLDelim.exec($);if(!X)return;if(!X[1]||!Q||this.rules.inline.punctuation.exec(Q)){let W=[...X[0]].length-1,G,Y,H=W,q=this.rules.inline.delRDelim;for(q.lastIndex=0,J=J.slice(-1*$.length+W);(X=q.exec(J))!==null;){if(G=X[1]||X[2]||X[3]||X[4]||X[5]||X[6],!G||(Y=[...G].length,Y!==W))continue;if(X[3]||X[4]){H+=Y;continue}if(H-=Y,H>0)continue;Y=Math.min(Y,Y+H);let U=[...X[0]][0].length,N=$.slice(0,W+X.index+U+Y),M=N.slice(W,-W);return{type:"del",raw:N,text:M,tokens:this.lexer.inlineTokens(M)}}}}autolink($){let J=this.rules.inline.autolink.exec($);if(J){let Q,X;return J[2]==="@"?(Q=J[1],X="mailto:"+Q):(Q=J[1],X=Q),{type:"link",raw:J[0],text:Q,href:X,tokens:[{type:"text",raw:Q,text:Q}]}}}url($){let J;if(J=this.rules.inline.url.exec($)){let Q,X;if(J[2]==="@")Q=J[0],X="mailto:"+Q;else{let W;do W=J[0],J[0]=this.rules.inline._backpedal.exec(J[0])?.[0]??"";while(W!==J[0]);Q=J[0],J[1]==="www."?X="http://"+J[0]:X=J[0]}return{type:"link",raw:J[0],text:Q,href:X,tokens:[{type:"text",raw:Q,text:Q}]}}}inlineText($){let J=this.rules.inline.text.exec($);if(J){let Q=this.lexer.state.inRawBlock;return{type:"text",raw:J[0],text:J[0],escaped:Q}}}},x0=class ${tokens;options;state;inlineQueue;tokenizer;constructor(J){this.tokens=[],this.tokens.links=Object.create(null),this.options=J||Z1,this.options.tokenizer=this.options.tokenizer||new N$,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 Q={other:C0,block:B$.normal,inline:A2.normal};this.options.pedantic?(Q.block=B$.pedantic,Q.inline=A2.pedantic):this.options.gfm&&(Q.block=B$.gfm,this.options.breaks?Q.inline=A2.breaks:Q.inline=A2.gfm),this.tokenizer.rules=Q}static get rules(){return{block:B$,inline:A2}}static lex(J,Q){return new $(Q).lex(J)}static lexInline(J,Q){return new $(Q).inlineTokens(J)}lex(J){J=J.replace(C0.carriageReturn,`
38
+ `),this.blockTokens(J,this.tokens);for(let Q=0;Q<this.inlineQueue.length;Q++){let X=this.inlineQueue[Q];this.inlineTokens(X.src,X.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(J,Q=[],X=!1){for(this.tokenizer.lexer=this,this.options.pedantic&&(J=J.replace(C0.tabCharGlobal," ").replace(C0.spaceLine,""));J;){let W;if(this.options.extensions?.block?.some((Y)=>(W=Y.call({lexer:this},J,Q))?(J=J.substring(W.raw.length),Q.push(W),!0):!1))continue;if(W=this.tokenizer.space(J)){J=J.substring(W.raw.length);let Y=Q.at(-1);W.raw.length===1&&Y!==void 0?Y.raw+=`
39
+ `:Q.push(W);continue}if(W=this.tokenizer.code(J)){J=J.substring(W.raw.length);let Y=Q.at(-1);Y?.type==="paragraph"||Y?.type==="text"?(Y.raw+=(Y.raw.endsWith(`
40
+ `)?"":`
41
+ `)+W.raw,Y.text+=`
42
+ `+W.text,this.inlineQueue.at(-1).src=Y.text):Q.push(W);continue}if(W=this.tokenizer.fences(J)){J=J.substring(W.raw.length),Q.push(W);continue}if(W=this.tokenizer.heading(J)){J=J.substring(W.raw.length),Q.push(W);continue}if(W=this.tokenizer.hr(J)){J=J.substring(W.raw.length),Q.push(W);continue}if(W=this.tokenizer.blockquote(J)){J=J.substring(W.raw.length),Q.push(W);continue}if(W=this.tokenizer.list(J)){J=J.substring(W.raw.length),Q.push(W);continue}if(W=this.tokenizer.html(J)){J=J.substring(W.raw.length),Q.push(W);continue}if(W=this.tokenizer.def(J)){J=J.substring(W.raw.length);let Y=Q.at(-1);Y?.type==="paragraph"||Y?.type==="text"?(Y.raw+=(Y.raw.endsWith(`
43
+ `)?"":`
44
+ `)+W.raw,Y.text+=`
45
+ `+W.raw,this.inlineQueue.at(-1).src=Y.text):this.tokens.links[W.tag]||(this.tokens.links[W.tag]={href:W.href,title:W.title},Q.push(W));continue}if(W=this.tokenizer.table(J)){J=J.substring(W.raw.length),Q.push(W);continue}if(W=this.tokenizer.lheading(J)){J=J.substring(W.raw.length),Q.push(W);continue}let G=J;if(this.options.extensions?.startBlock){let Y=1/0,H=J.slice(1),q;this.options.extensions.startBlock.forEach((U)=>{q=U.call({lexer:this},H),typeof q=="number"&&q>=0&&(Y=Math.min(Y,q))}),Y<1/0&&Y>=0&&(G=J.substring(0,Y+1))}if(this.state.top&&(W=this.tokenizer.paragraph(G))){let Y=Q.at(-1);X&&Y?.type==="paragraph"?(Y.raw+=(Y.raw.endsWith(`
46
+ `)?"":`
47
+ `)+W.raw,Y.text+=`
48
+ `+W.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=Y.text):Q.push(W),X=G.length!==J.length,J=J.substring(W.raw.length);continue}if(W=this.tokenizer.text(J)){J=J.substring(W.raw.length);let Y=Q.at(-1);Y?.type==="text"?(Y.raw+=(Y.raw.endsWith(`
49
+ `)?"":`
50
+ `)+W.raw,Y.text+=`
51
+ `+W.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=Y.text):Q.push(W);continue}if(J){let Y="Infinite loop on byte: "+J.charCodeAt(0);if(this.options.silent){console.error(Y);break}else throw Error(Y)}}return this.state.top=!0,Q}inline(J,Q=[]){return this.inlineQueue.push({src:J,tokens:Q}),Q}inlineTokens(J,Q=[]){this.tokenizer.lexer=this;let X=J,W=null;if(this.tokens.links){let q=Object.keys(this.tokens.links);if(q.length>0)for(;(W=this.tokenizer.rules.inline.reflinkSearch.exec(X))!==null;)q.includes(W[0].slice(W[0].lastIndexOf("[")+1,-1))&&(X=X.slice(0,W.index)+"["+"a".repeat(W[0].length-2)+"]"+X.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(W=this.tokenizer.rules.inline.anyPunctuation.exec(X))!==null;)X=X.slice(0,W.index)+"++"+X.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let G;for(;(W=this.tokenizer.rules.inline.blockSkip.exec(X))!==null;)G=W[2]?W[2].length:0,X=X.slice(0,W.index+G)+"["+"a".repeat(W[0].length-G-2)+"]"+X.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);X=this.options.hooks?.emStrongMask?.call({lexer:this},X)??X;let Y=!1,H="";for(;J;){Y||(H=""),Y=!1;let q;if(this.options.extensions?.inline?.some((N)=>(q=N.call({lexer:this},J,Q))?(J=J.substring(q.raw.length),Q.push(q),!0):!1))continue;if(q=this.tokenizer.escape(J)){J=J.substring(q.raw.length),Q.push(q);continue}if(q=this.tokenizer.tag(J)){J=J.substring(q.raw.length),Q.push(q);continue}if(q=this.tokenizer.link(J)){J=J.substring(q.raw.length),Q.push(q);continue}if(q=this.tokenizer.reflink(J,this.tokens.links)){J=J.substring(q.raw.length);let N=Q.at(-1);q.type==="text"&&N?.type==="text"?(N.raw+=q.raw,N.text+=q.text):Q.push(q);continue}if(q=this.tokenizer.emStrong(J,X,H)){J=J.substring(q.raw.length),Q.push(q);continue}if(q=this.tokenizer.codespan(J)){J=J.substring(q.raw.length),Q.push(q);continue}if(q=this.tokenizer.br(J)){J=J.substring(q.raw.length),Q.push(q);continue}if(q=this.tokenizer.del(J,X,H)){J=J.substring(q.raw.length),Q.push(q);continue}if(q=this.tokenizer.autolink(J)){J=J.substring(q.raw.length),Q.push(q);continue}if(!this.state.inLink&&(q=this.tokenizer.url(J))){J=J.substring(q.raw.length),Q.push(q);continue}let U=J;if(this.options.extensions?.startInline){let N=1/0,M=J.slice(1),L;this.options.extensions.startInline.forEach((K)=>{L=K.call({lexer:this},M),typeof L=="number"&&L>=0&&(N=Math.min(N,L))}),N<1/0&&N>=0&&(U=J.substring(0,N+1))}if(q=this.tokenizer.inlineText(U)){J=J.substring(q.raw.length),q.raw.slice(-1)!=="_"&&(H=q.raw.slice(-1)),Y=!0;let N=Q.at(-1);N?.type==="text"?(N.raw+=q.raw,N.text+=q.text):Q.push(q);continue}if(J){let N="Infinite loop on byte: "+J.charCodeAt(0);if(this.options.silent){console.error(N);break}else throw Error(N)}}return Q}},L$=class{options;parser;constructor($){this.options=$||Z1}space($){return""}code({text:$,lang:J,escaped:Q}){let X=(J||"").match(C0.notSpaceStart)?.[0],W=$.replace(C0.endingNewline,"")+`
52
+ `;return X?'<pre><code class="language-'+d0(X)+'">'+(Q?W:d0(W,!0))+`</code></pre>
53
+ `:"<pre><code>"+(Q?W:d0(W,!0))+`</code></pre>
54
+ `}blockquote({tokens:$}){return`<blockquote>
55
+ ${this.parser.parse($)}</blockquote>
56
+ `}html({text:$}){return $}def($){return""}heading({tokens:$,depth:J}){return`<h${J}>${this.parser.parseInline($)}</h${J}>
57
+ `}hr($){return`<hr>
58
+ `}list($){let{ordered:J,start:Q}=$,X="";for(let Y=0;Y<$.items.length;Y++){let H=$.items[Y];X+=this.listitem(H)}let W=J?"ol":"ul",G=J&&Q!==1?' start="'+Q+'"':"";return"<"+W+G+`>
59
+ `+X+"</"+W+`>
60
+ `}listitem($){return`<li>${this.parser.parse($.tokens)}</li>
61
+ `}checkbox({checked:$}){return"<input "+($?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:$}){return`<p>${this.parser.parseInline($)}</p>
62
+ `}table($){let J="",Q="";for(let W=0;W<$.header.length;W++)Q+=this.tablecell($.header[W]);J+=this.tablerow({text:Q});let X="";for(let W=0;W<$.rows.length;W++){let G=$.rows[W];Q="";for(let Y=0;Y<G.length;Y++)Q+=this.tablecell(G[Y]);X+=this.tablerow({text:Q})}return X&&(X=`<tbody>${X}</tbody>`),`<table>
63
+ <thead>
64
+ `+J+`</thead>
65
+ `+X+`</table>
66
+ `}tablerow({text:$}){return`<tr>
67
+ ${$}</tr>
68
+ `}tablecell($){let J=this.parser.parseInline($.tokens),Q=$.header?"th":"td";return($.align?`<${Q} align="${$.align}">`:`<${Q}>`)+J+`</${Q}>
69
+ `}strong({tokens:$}){return`<strong>${this.parser.parseInline($)}</strong>`}em({tokens:$}){return`<em>${this.parser.parseInline($)}</em>`}codespan({text:$}){return`<code>${d0($,!0)}</code>`}br($){return"<br>"}del({tokens:$}){return`<del>${this.parser.parseInline($)}</del>`}link({href:$,title:J,tokens:Q}){let X=this.parser.parseInline(Q),W=p4($);if(W===null)return X;$=W;let G='<a href="'+$+'"';return J&&(G+=' title="'+d0(J)+'"'),G+=">"+X+"</a>",G}image({href:$,title:J,text:Q,tokens:X}){X&&(Q=this.parser.parseInline(X,this.parser.textRenderer));let W=p4($);if(W===null)return d0(Q);$=W;let G=`<img src="${$}" alt="${d0(Q)}"`;return J&&(G+=` title="${d0(J)}"`),G+=">",G}text($){return"tokens"in $&&$.tokens?this.parser.parseInline($.tokens):("escaped"in $)&&$.escaped?$.text:d0($.text)}},S5=class{strong({text:$}){return $}em({text:$}){return $}codespan({text:$}){return $}del({text:$}){return $}html({text:$}){return $}text({text:$}){return $}link({text:$}){return""+$}image({text:$}){return""+$}br(){return""}checkbox({raw:$}){return $}},v0=class ${options;renderer;textRenderer;constructor(J){this.options=J||Z1,this.options.renderer=this.options.renderer||new L$,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new S5}static parse(J,Q){return new $(Q).parse(J)}static parseInline(J,Q){return new $(Q).parseInline(J)}parse(J){this.renderer.parser=this;let Q="";for(let X=0;X<J.length;X++){let W=J[X];if(this.options.extensions?.renderers?.[W.type]){let Y=W,H=this.options.extensions.renderers[Y.type].call({parser:this},Y);if(H!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(Y.type)){Q+=H||"";continue}}let G=W;switch(G.type){case"space":{Q+=this.renderer.space(G);break}case"hr":{Q+=this.renderer.hr(G);break}case"heading":{Q+=this.renderer.heading(G);break}case"code":{Q+=this.renderer.code(G);break}case"table":{Q+=this.renderer.table(G);break}case"blockquote":{Q+=this.renderer.blockquote(G);break}case"list":{Q+=this.renderer.list(G);break}case"checkbox":{Q+=this.renderer.checkbox(G);break}case"html":{Q+=this.renderer.html(G);break}case"def":{Q+=this.renderer.def(G);break}case"paragraph":{Q+=this.renderer.paragraph(G);break}case"text":{Q+=this.renderer.text(G);break}default:{let Y='Token with "'+G.type+'" type was not found.';if(this.options.silent)return console.error(Y),"";throw Error(Y)}}}return Q}parseInline(J,Q=this.renderer){this.renderer.parser=this;let X="";for(let W=0;W<J.length;W++){let G=J[W];if(this.options.extensions?.renderers?.[G.type]){let H=this.options.extensions.renderers[G.type].call({parser:this},G);if(H!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(G.type)){X+=H||"";continue}}let Y=G;switch(Y.type){case"escape":{X+=Q.text(Y);break}case"html":{X+=Q.html(Y);break}case"link":{X+=Q.link(Y);break}case"image":{X+=Q.image(Y);break}case"checkbox":{X+=Q.checkbox(Y);break}case"strong":{X+=Q.strong(Y);break}case"em":{X+=Q.em(Y);break}case"codespan":{X+=Q.codespan(Y);break}case"br":{X+=Q.br(Y);break}case"del":{X+=Q.del(Y);break}case"text":{X+=Q.text(Y);break}default:{let H='Token with "'+Y.type+'" type was not found.';if(this.options.silent)return console.error(H),"";throw Error(H)}}}return X}},T2=class{options;block;constructor($){this.options=$||Z1}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess($){return $}postprocess($){return $}processAllTokens($){return $}emStrongMask($){return $}provideLexer($=this.block){return $?x0.lex:x0.lexInline}provideParser($=this.block){return $?v0.parse:v0.parseInline}},R5=class{defaults=L5();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=v0;Renderer=L$;TextRenderer=S5;Lexer=x0;Tokenizer=N$;Hooks=T2;constructor(...$){this.use(...$)}walkTokens($,J){let Q=[];for(let X of $)switch(Q=Q.concat(J.call(this,X)),X.type){case"table":{let W=X;for(let G of W.header)Q=Q.concat(this.walkTokens(G.tokens,J));for(let G of W.rows)for(let Y of G)Q=Q.concat(this.walkTokens(Y.tokens,J));break}case"list":{let W=X;Q=Q.concat(this.walkTokens(W.items,J));break}default:{let W=X;this.defaults.extensions?.childTokens?.[W.type]?this.defaults.extensions.childTokens[W.type].forEach((G)=>{let Y=W[G].flat(1/0);Q=Q.concat(this.walkTokens(Y,J))}):W.tokens&&(Q=Q.concat(this.walkTokens(W.tokens,J)))}}return Q}use(...$){let J=this.defaults.extensions||{renderers:{},childTokens:{}};return $.forEach((Q)=>{let X={...Q};if(X.async=this.defaults.async||X.async||!1,Q.extensions&&(Q.extensions.forEach((W)=>{if(!W.name)throw Error("extension name required");if("renderer"in W){let G=J.renderers[W.name];G?J.renderers[W.name]=function(...Y){let H=W.renderer.apply(this,Y);return H===!1&&(H=G.apply(this,Y)),H}:J.renderers[W.name]=W.renderer}if("tokenizer"in W){if(!W.level||W.level!=="block"&&W.level!=="inline")throw Error("extension level must be 'block' or 'inline'");let G=J[W.level];G?G.unshift(W.tokenizer):J[W.level]=[W.tokenizer],W.start&&(W.level==="block"?J.startBlock?J.startBlock.push(W.start):J.startBlock=[W.start]:W.level==="inline"&&(J.startInline?J.startInline.push(W.start):J.startInline=[W.start]))}"childTokens"in W&&W.childTokens&&(J.childTokens[W.name]=W.childTokens)}),X.extensions=J),Q.renderer){let W=this.defaults.renderer||new L$(this.defaults);for(let G in Q.renderer){if(!(G in W))throw Error(`renderer '${G}' does not exist`);if(["options","parser"].includes(G))continue;let Y=G,H=Q.renderer[Y],q=W[Y];W[Y]=(...U)=>{let N=H.apply(W,U);return N===!1&&(N=q.apply(W,U)),N||""}}X.renderer=W}if(Q.tokenizer){let W=this.defaults.tokenizer||new N$(this.defaults);for(let G in Q.tokenizer){if(!(G in W))throw Error(`tokenizer '${G}' does not exist`);if(["options","rules","lexer"].includes(G))continue;let Y=G,H=Q.tokenizer[Y],q=W[Y];W[Y]=(...U)=>{let N=H.apply(W,U);return N===!1&&(N=q.apply(W,U)),N}}X.tokenizer=W}if(Q.hooks){let W=this.defaults.hooks||new T2;for(let G in Q.hooks){if(!(G in W))throw Error(`hook '${G}' does not exist`);if(["options","block"].includes(G))continue;let Y=G,H=Q.hooks[Y],q=W[Y];T2.passThroughHooks.has(G)?W[Y]=(U)=>{if(this.defaults.async&&T2.passThroughHooksRespectAsync.has(G))return(async()=>{let M=await H.call(W,U);return q.call(W,M)})();let N=H.call(W,U);return q.call(W,N)}:W[Y]=(...U)=>{if(this.defaults.async)return(async()=>{let M=await H.apply(W,U);return M===!1&&(M=await q.apply(W,U)),M})();let N=H.apply(W,U);return N===!1&&(N=q.apply(W,U)),N}}X.hooks=W}if(Q.walkTokens){let W=this.defaults.walkTokens,G=Q.walkTokens;X.walkTokens=function(Y){let H=[];return H.push(G.call(this,Y)),W&&(H=H.concat(W.call(this,Y))),H}}this.defaults={...this.defaults,...X}}),this}setOptions($){return this.defaults={...this.defaults,...$},this}lexer($,J){return x0.lex($,J??this.defaults)}parser($,J){return v0.parse($,J??this.defaults)}parseMarkdown($){return(J,Q)=>{let X={...Q},W={...this.defaults,...X},G=this.onError(!!W.silent,!!W.async);if(this.defaults.async===!0&&X.async===!1)return G(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 J>"u"||J===null)return G(Error("marked(): input parameter is undefined or null"));if(typeof J!="string")return G(Error("marked(): input parameter is of type "+Object.prototype.toString.call(J)+", string expected"));if(W.hooks&&(W.hooks.options=W,W.hooks.block=$),W.async)return(async()=>{let Y=W.hooks?await W.hooks.preprocess(J):J,H=await(W.hooks?await W.hooks.provideLexer($):$?x0.lex:x0.lexInline)(Y,W),q=W.hooks?await W.hooks.processAllTokens(H):H;W.walkTokens&&await Promise.all(this.walkTokens(q,W.walkTokens));let U=await(W.hooks?await W.hooks.provideParser($):$?v0.parse:v0.parseInline)(q,W);return W.hooks?await W.hooks.postprocess(U):U})().catch(G);try{W.hooks&&(J=W.hooks.preprocess(J));let Y=(W.hooks?W.hooks.provideLexer($):$?x0.lex:x0.lexInline)(J,W);W.hooks&&(Y=W.hooks.processAllTokens(Y)),W.walkTokens&&this.walkTokens(Y,W.walkTokens);let H=(W.hooks?W.hooks.provideParser($):$?v0.parse:v0.parseInline)(Y,W);return W.hooks&&(H=W.hooks.postprocess(H)),H}catch(Y){return G(Y)}}}onError($,J){return(Q)=>{if(Q.message+=`
70
+ Please report this to https://github.com/markedjs/marked.`,$){let X="<p>An error occurred:</p><pre>"+d0(Q.message+"",!0)+"</pre>";return J?Promise.resolve(X):X}if(J)return Promise.reject(Q);throw Q}}},j1=new R5;function e($,J){return j1.parse($,J)}e.options=e.setOptions=function($){return j1.setOptions($),e.defaults=j1.defaults,i4(e.defaults),e};e.getDefaults=L5;e.defaults=Z1;e.use=function(...$){return j1.use(...$),e.defaults=j1.defaults,i4(e.defaults),e};e.walkTokens=function($,J){return j1.walkTokens($,J)};e.parseInline=j1.parseInline;e.Parser=v0;e.parser=v0.parse;e.Renderer=L$;e.TextRenderer=S5;e.Lexer=x0;e.lexer=x0.lex;e.Tokenizer=N$;e.Hooks=T2;e.parse=e;var{options:$Y,setOptions:JY,use:QY,walkTokens:XY,parseInline:WY}=e;var YY=v0.parse,GY=x0.lex;import{useEffect as Q3,useMemo as C5,useRef as Q6,useState as I2}from"react";import{jsxDEV as L0}from"react/jsx-dev-runtime";function P5({open:$,onClose:J,onSubmit:Q,includedRemoteIds:X,onToggleRemoteId:W}){let{annotations:G,generalNote:Y,submittableResponses:H,feedbackEntries:q}=C1(),U=j0().threads!==null,[N,M]=I2(""),[L,K]=I2(!1),[z,_]=I2(!1),[w,S]=I2(null),O=Q6(null),[F,g]=I2(!1),I=C5(()=>G.filter((E)=>E.source==="remote"),[G]);if($&&!F)K(!1),_(!1),S(null);if(!$&&F)K(!1),_(!1),S(null);if($!==F)g($);let h=C5(()=>o1(G,Y,H,q,X,{annotationIds:U}),[G,Y,H,q,X,U]),V=L?N:h;if(Q3(()=>{if($&&z&&O.current)O.current.focus()},[$,z]),Q3(()=>{if(!$)return;let E=(c)=>{if(c.key==="Escape")J()};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[$,J]),!$)return null;let u=V.trim().length>0;return L0("div",{className:"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm flex items-center justify-center p-8",onClick:J,children:L0("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:(E)=>E.stopPropagation(),children:[L0("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-subtle flex-shrink-0",children:[L0("div",{className:"flex items-center gap-3",children:[L0("span",{className:"text-[13px] font-medium text-text-primary font-body",children:"Response preview"},void 0,!1,void 0,this),L&&L0("button",{onClick:()=>{K(!1),_(!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),L0("div",{className:"flex items-center gap-2",children:[L0("div",{className:"flex items-center bg-bg-base rounded-md p-0.5",children:[L0("button",{onClick:()=>_(!1),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${!z?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Preview"},void 0,!1,void 0,this),L0("button",{onClick:()=>_(!0),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${z?"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),L0("button",{onClick:J,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),z?L0("textarea",{ref:O,value:V,onChange:(E)=>{M(E.currentTarget.value),K(!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):L0("div",{className:"flex-1 overflow-y-auto p-5",children:L0(X2,{text:V},void 0,!1,void 0,this)},void 0,!1,void 0,this),I.length>0&&L0("div",{className:"px-5 py-2 border-t border-border-subtle flex-shrink-0",children:L0("span",{className:"text-[12px] text-text-secondary font-body",children:["Reviewer feedback: ",X.size,"/",I.length," included"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),w&&L0("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:[L0("span",{children:w},void 0,!1,void 0,this),L0("button",{onClick:()=>{S(null),Q(V)},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),L0("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border-subtle flex-shrink-0",children:[L0("button",{onClick:J,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),L0("button",{onClick:()=>{let E=n1(H,q);if(E.length>0){S(`Please answer: ${E.join(", ")}`);return}S(null),Q(V)},disabled:!u,className:`px-6 py-2 rounded-lg font-body text-[13px] font-medium transition-all ${u?"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 X6=/!\[([^\]]*)\]\((\/tmp\/agent-canvas\/uploads\/([^)]+))\)/g;function W6($){return $.replace(X6,(J,Q,X,W)=>`![${Q}](/api/uploads/${W})`)}var Y3={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Q2=($)=>$.replace(/[&<>"']/g,(J)=>Y3[J]??J),Y6=($)=>$.replace(/&(?!#?\w+;)|[<>"']/g,(J)=>Y3[J]??J),X3=($)=>/^(?:https?|mailto):/i.test($)||!/^[^/?#]*:/.test($),W3=($)=>$?` title="${Q2($)}"`:"",G6=new R5({renderer:{html:({text:$})=>Q2($),text($){return"tokens"in $&&$.tokens?this.parser.parseInline($.tokens):Y6($.text)},link($){let J=this.parser.parseInline($.tokens);return X3($.href)?`<a href="${Q2($.href)}"${W3($.title)}>${J}</a>`:J},image:($)=>X3($.href)?`<img src="${Q2($.href)}" alt="${Q2($.text)}"${W3($.title)}>`:Q2($.text)}});function G3($){return G6.parse($,{async:!1})}function X2({text:$}){let J=C5(()=>G3(W6($)),[$]);return L0("div",{className:"prose-canvas font-body text-body text-text-primary leading-relaxed",dangerouslySetInnerHTML:{__html:J}},void 0,!1,void 0,this)}import{useId as q6,useState as f5,useSyncExternalStore as H6}from"react";import{jsxDEV as K0}from"react/jsx-dev-runtime";var B6=[],U6=()=>()=>{},N6=()=>B6;function L6(){let $=j0().threads;return H6($?.subscribe??U6,$?.current??N6)}var K6={open:"Answered",queued:"Reply sent",working:"Agent is on it",resolved:"Resolved"};function j5(){let $=j0().threads,J=L6(),[Q,X]=f5(()=>new Map),W=(H,q)=>X((U)=>new Map(U).set(H,q));if($===null||J.length===0)return null;let G=J.filter((H)=>H.state!=="resolved"),Y=J.filter((H)=>H.state==="resolved");return K0("section",{"aria-label":"Threads",className:"px-3 pt-1 pb-3 border-b border-border-subtle",children:[K0("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-1 mb-1",children:"Threads"},void 0,!1,void 0,this),G.map((H)=>K0(q3,{thread:H,store:$,draft:Q.get(H.id)??"",onDraft:(q)=>W(H.id,q)},H.id,!1,void 0,this)),Y.length>0&&K0("details",{className:"mt-1",children:[K0("summary",{className:"text-[11px] text-text-tertiary font-body px-1 cursor-pointer",children:["Resolved (",Y.length,")"]},void 0,!0,void 0,this),Y.map((H)=>K0(q3,{thread:H,store:$,draft:Q.get(H.id)??"",onDraft:(q)=>W(H.id,q)},H.id,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function q3({thread:$,store:J,draft:Q,onDraft:X}){let W=q6(),[G,Y]=f5(null),[H,q]=f5(!1),U=async(L)=>{q(!0),Y(null);try{await L()}catch(K){Y(K instanceof Error?K.message:String(K))}finally{q(!1)}},N=()=>U(async()=>{await J.reply($.id,Q.trim()),X("")}),M=$.filePath===G1?"Agent response":$.filePath??$.canvasFile?.replace(/\.jsx$/,"");return K0("article",{className:"rounded-lg border border-border-subtle bg-bg-elevated px-3 py-2 mt-2","data-thread-id":$.id,children:[K0("div",{className:"flex items-center justify-between gap-2 text-[11px] text-text-tertiary font-body",children:[K0("span",{className:"truncate",children:[M?`${M} · `:"","Round ",$.revision]},void 0,!0,void 0,this),K0("span",{children:K6[$.state]},void 0,!1,void 0,this)]},void 0,!0,void 0,this),$.snippet.trim()&&K0("blockquote",{className:"mt-1 border-l-2 border-border-medium pl-2 text-[12px] text-text-secondary font-body line-clamp-3",children:$.snippet},void 0,!1,void 0,this),K0("ol",{className:"mt-2 space-y-2",children:$.comments.map((L)=>K0("li",{className:"text-[13px] font-body",children:[K0("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary",children:L.author==="agent"?"Agent":"You"},void 0,!1,void 0,this),L.author==="agent"?K0(X2,{text:L.body},void 0,!1,void 0,this):K0("p",{className:"whitespace-pre-wrap text-text-primary",children:L.body},void 0,!1,void 0,this)]},L.id,!0,void 0,this))},void 0,!1,void 0,this),K0("label",{className:"sr-only",htmlFor:W,children:"Reply"},void 0,!1,void 0,this),K0("textarea",{id:W,value:Q,onInput:(L)=>X(L.currentTarget.value),placeholder:"Reply to the agent",rows:2,className:"mt-2 w-full rounded-md bg-bg-input px-2 py-1.5 text-[13px] font-body text-text-primary"},void 0,!1,void 0,this),G&&K0("p",{role:"alert",className:"text-[12px] text-accent-red font-body",children:G},void 0,!1,void 0,this),K0("div",{className:"mt-1 flex justify-end gap-2",children:[K0("button",{type:"button",disabled:H,onClick:()=>U(()=>J.setResolved($.id,$.state!=="resolved")),className:"px-2.5 py-1 rounded text-[12px] font-body text-text-secondary hover:text-text-primary",children:$.state==="resolved"?"Reopen":"Resolve"},void 0,!1,void 0,this),K0("button",{type:"button",disabled:H||Q.trim()==="",onClick:N,className:"px-2.5 py-1 rounded text-[12px] font-body font-medium bg-btn-primary text-btn-primary-text disabled:opacity-50",children:"Send"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as k,Fragment as F$}from"react/jsx-dev-runtime";function z$({onSubmit:$,collapseButton:J}){let{isReadOnly:Q,selectedRevision:X,currentRevision:W,revisions:G,agentWatching:Y}=V5($2),H=V5(M6),q=G.find((L)=>L.revision===X),U=Q&&X===W,N=!!q?.feedbackConsumed,M=q?.label||`Round ${X}`;if(Q)return k(_6,{sessionId:H,revision:X,label:M,waitingForUpdate:U,feedbackConsumed:N,agentWatching:Y,collapseButton:J},void 0,!1,void 0,this);return k(O6,{onSubmit:$,agentWatching:Y,collapseButton:J},void 0,!1,void 0,this)}function z6({sessionId:$,revision:J,label:Q,waitingForUpdate:X,feedbackConsumed:W,agentWatching:G,collapseButton:Y}){let q=j0().isShared;return k("div",{className:"flex flex-col h-full",children:[k("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[k("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:X?"Feedback sent":`Feedback — ${Q}`},void 0,!1,void 0,this),Y]},void 0,!0,void 0,this),X&&!q&&k(U3,{feedbackConsumed:W,agentWatching:G},void 0,!1,void 0,this),k(N3,{sessionId:$,revision:J},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function U3({feedbackConsumed:$,agentWatching:J}){if($)return k("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:[k("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),k("span",{className:"text-[12px] font-body text-accent-green",children:"Feedback received — waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(J)return k("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-blue-muted flex items-center gap-2 flex-shrink-0",children:[k("span",{className:"w-2 h-2 rounded-full bg-accent-blue animate-pulse"},void 0,!1,void 0,this),k("span",{className:"text-[12px] font-body text-accent-blue",children:"Waiting for agent to pick up feedback..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return k("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-amber-muted flex items-center gap-2 flex-shrink-0",children:[k("span",{className:"w-2 h-2 rounded-full bg-accent-amber"},void 0,!1,void 0,this),k("span",{className:"text-[12px] font-body text-accent-amber",children:"Agent disconnected — tell Claude to check feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function _6({sessionId:$,revision:J,label:Q,waitingForUpdate:X,feedbackConsumed:W,agentWatching:G,collapseButton:Y}){let{annotations:H,generalNote:q}=C1(),U=H.length>0||q.trim().length>0,[N,M]=W2("feedback");if(!U)return k(z6,{sessionId:$,revision:J,label:Q,waitingForUpdate:X,feedbackConsumed:W,agentWatching:G,collapseButton:Y},void 0,!1,void 0,this);return k("div",{className:"flex flex-col h-full",children:[k("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[k("div",{className:"flex items-center gap-1 bg-bg-input rounded-md p-0.5",children:[k("button",{onClick:()=>M("feedback"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors ${N==="feedback"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Feedback"},void 0,!1,void 0,this),k("button",{onClick:()=>M("annotations"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors flex items-center gap-1.5 ${N==="annotations"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:["Annotations",k("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:H.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Y]},void 0,!0,void 0,this),X&&k(U3,{feedbackConsumed:W,agentWatching:G},void 0,!1,void 0,this),N==="feedback"?k(N3,{sessionId:$,revision:J},void 0,!1,void 0,this):k(F$,{children:[k("div",{className:"flex-1 overflow-y-auto",children:k(L3,{annotations:H,readOnly:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),q.trim()&&k("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:k("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:q},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 N3({sessionId:$,revision:J}){let Q=j0(),[X,W]=W2(null),[G,Y]=W2(!0);return B3(()=>{if(Y(!0),!Q.fsAvailable){W(null),Y(!1);return}fetch(`/api/session/${$}/revision/${J}/feedback`).then((H)=>H.json()).then((H)=>{W(g4.parse(H).feedback||null),Y(!1)}).catch(()=>{W(null),Y(!1)})},[$,J]),k("div",{className:"flex-1 overflow-y-auto px-4",children:[k("div",{className:"-mx-4",children:k(j5,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),G?k("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):X?k(X2,{text:X},void 0,!1,void 0,this):k("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,!0,void 0,this)}function w6($){let J=$.filter((Y)=>Y.filePath===G1),Q=$.filter((Y)=>!Y.filePath),X=$.filter((Y)=>_1(Y)!==void 0),W={};for(let Y of X){let H=_1(Y);if(!H)continue;let q=W[H];if(q)q.push(Y);else W[H]=[Y]}let G=[J,Q,X].filter((Y)=>Y.length>0).length>1;return{response:J,plan:Q,fileGroups:W,hasMultipleGroups:G}}function H3({children:$}){return k("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:$},void 0,!1,void 0,this)}function L3({annotations:$,readOnly:J,includedRemoteIds:Q,onToggleRemoteId:X}){let{setActiveView:W}=V5(e1),{response:G,plan:Y,fileGroups:H,hasMultipleGroups:q}=w6($),U=Z5((L)=>{let K=_1(L);if(!K)return;W({type:"file",path:K}),setTimeout(()=>{let z=V2(L);if(z)z.scrollIntoView({behavior:"smooth",block:"center"})},150)},[W]),N=Z5((L)=>B5(L,W),[W]),M={readOnly:J,onSelect:U,onReveal:N,includedRemoteIds:Q,onToggleRemoteId:X};return k(F$,{children:[G.length>0&&k(F$,{children:[q&&k(H3,{children:"Agent Response"},void 0,!1,void 0,this),k(f2,{annotations:G,...M},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Y.length>0&&k(F$,{children:[q&&k(H3,{children:"Canvas"},void 0,!1,void 0,this),k(f2,{annotations:Y,...M},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Object.entries(H).map(([L,K])=>k("div",{children:[k("button",{onClick:()=>W({type:"file",path:L}),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:L,children:[k(U5,{name:L.split("/").pop()||L,type:"file"},void 0,!1,void 0,this),k("span",{className:"truncate",children:L},void 0,!1,void 0,this)]},void 0,!0,void 0,this),k(f2,{annotations:K,...M},void 0,!1,void 0,this)]},L,!0,void 0,this))]},void 0,!0,void 0,this)}function O6({onSubmit:$,agentWatching:J,collapseButton:Q}){let X=j0(),[W,G]=W2(!1),{annotations:Y,generalNote:H,submittableResponses:q,feedbackEntries:U}=C1(),N=F6(()=>Y.filter((h)=>h.source==="remote"),[Y]),[M,L]=W2(()=>new Set);B3(()=>{if(N.length===0)return;L((h)=>{let V=new Set(h);for(let u of N)V.add(u.id);return V.size===h.size?h:V})},[N]);let K=Z5((h)=>{L((V)=>{let u=new Set(V);if(u.has(h))u.delete(h);else u.add(h);return u})},[]),z=Array.from(q.values()).some(Z2),_=U.size>0,w=Y.length>0||H.trim().length>0||z||_,[S,O]=W2(null),F=X.threads!==null,g=(h)=>{let V=F?Y.filter((u)=>u.source!=="remote").map(S6):[];$(h,V,V4(q))},I=()=>{g(o1(Y,H,q,U,M,{annotationIds:F}))};return k("div",{className:"flex flex-col h-full",children:[k("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[k("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body flex items-center gap-2",children:["Annotations",Y.length>0&&k("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:Y.length},void 0,!1,void 0,this),!X.isShared&&k("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${J?"bg-accent-green":"bg-accent-amber"}`,title:J?"Agent connected":"Agent disconnected"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q]},void 0,!0,void 0,this),k("div",{className:"flex-1 overflow-y-auto",children:[k(j5,{},void 0,!1,void 0,this),Y.length===0&&k("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),k(L3,{annotations:Y,includedRemoteIds:M,onToggleRemoteId:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this),k(o$,{hasContent:w,onSubmit:()=>{let h=n1(q,U);if(h.length>0){O(`Please answer: ${h.join(", ")}`);return}O(null),I()},onSubmitEmpty:()=>$("No feedback — looks good.",[],[]),notice:S&&k("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:[k("span",{children:S},void 0,!1,void 0,this),k("button",{onClick:()=>{O(null),I()},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),secondaryAction:k("button",{onClick:()=>G(!0),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)},void 0,!1,void 0,this),k(P5,{open:W,onClose:()=>G(!1),onSubmit:g,includedRemoteIds:M,onToggleRemoteId:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function S6($){return{id:$.id,snippet:$.snippet,note:$.note,canvasFile:$.canvasFile,filePath:$.filePath}}import{useFeedback as RH}from"#canvas/runtime";import lY from"react";import{jsxDEV as iY}from"react/jsx-dev-runtime";e.setOptions({gfm:!0,breaks:!1});import{jsxDEV as sY}from"react/jsx-dev-runtime";import{jsxDEV as eY}from"react/jsx-dev-runtime";import{useAnnotations as GG,useResponseRegistration as qG}from"#canvas/runtime";import{useEffect as BG,useMemo as UG,useRef as NG,useState as LG}from"react";import{jsxDEV as XG}from"react/jsx-dev-runtime";import{jsxDEV as FG}from"react/jsx-dev-runtime";import{useEffect as SG,useRef as RG}from"react";import{jsxDEV as fG}from"react/jsx-dev-runtime";import{jsxDEV as TG}from"react/jsx-dev-runtime";import{ActiveViewCtx as bG,SessionContext as gG}from"#canvas/runtime";import{useContext as yG,useEffect as xG,useRef as vG,useState as hG}from"react";import{jsxDEV as pG}from"react/jsx-dev-runtime";import{SessionContext as iG}from"#canvas/runtime";import{useContext as oG,useState as nG}from"react";import{jsxDEV as tG}from"react/jsx-dev-runtime";import{useMemo as Qq}from"react";import{jsxDEV as Wq}from"react/jsx-dev-runtime";e.setOptions({gfm:!0,breaks:!1});import{useAnnotations as Hq,useCanvasFile as Bq}from"#canvas/runtime";import{useCallback as Kq,useEffect as Mq,useRef as Fq,useState as zq}from"react";import wq from"react-dom";import{jsxDEV as Rq,Fragment as Cq}from"react/jsx-dev-runtime";import{jsxDEV as Zq}from"react/jsx-dev-runtime";import{jsxDEV as kq}from"react/jsx-dev-runtime";import{useState as bq}from"react";import{jsxDEV as yq}from"react/jsx-dev-runtime";import{jsxDEV as hq}from"react/jsx-dev-runtime";import{jsxDEV as pq}from"react/jsx-dev-runtime";import{useAnnotations as iq,useResponseRegistration as rq}from"#canvas/runtime";import{useRef as sq,useState as tq}from"react";import{jsxDEV as $H}from"react/jsx-dev-runtime";import{CanvasFileCtx as P6,SessionContext as f6}from"#canvas/runtime";import _$,{useContext as F3,useEffect as U1,useMemo as b2,useRef as j6,useState as i0}from"react";import{createPortal as Z6}from"react-dom";import{createContext as C6}from"react";var k5=C6(()=>{});import{jsxDEV as Y0,Fragment as T6}from"react/jsx-dev-runtime";class z3 extends _$.Component{state={error:null};static getDerivedStateFromError($){return{error:$}}componentDidCatch($,J){this.props.reportError({revision:this.props.revision,filename:this.props.filename,message:$.message,...$.stack?{stack:$.stack}:{},...J.componentStack?{componentStack:J.componentStack}:{}})}render(){if(!this.state.error)return this.props.children;return Y0(_3,{message:this.state.error.message},void 0,!1,void 0,this)}}function _3({message:$}){return Y0("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[Y0("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Canvas render failed"},void 0,!1,void 0,this),Y0("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:$},void 0,!1,void 0,this),Y0("p",{className:"text-meta font-body text-text-tertiary mt-3",children:"The error was sent back to the canvas author."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function w$({revision:$,filename:J}){let Q=F3(f6),X=j0(),W=F3(k5),[G,Y]=i0(null),[H,q]=i0(null),[U,N]=i0(!0),M=j6(null),{annotations:L,addAnnotationWithId:K,removeAnnotation:z,updateAnnotation:_,addAnnotationImage:w,removeAnnotationImage:S,activeAnnotationId:O,setActiveAnnotationId:F,registerCanvasRendered:g}=C1(),I=b2(()=>L.filter((T)=>!T.filePath&&(!T.canvasFile||T.canvasFile===J)),[L,J]),[h,V]=i0(null),[u,E]=i0(null),[c,Q0]=i0(null),[$0,W0]=i0(null),[_0,d]=i0(!1);U1(()=>{N(!0),q(null),W0(null),X.loadCanvasModule(J,$).then((T)=>{Y(()=>T.default),N(!1)}).catch((T)=>{let y=T instanceof Error?T:Error(String(T));q(y.message),N(!1),W({revision:$,filename:J,message:y.message,...y.stack?{stack:y.stack}:{}})})},[Q,$,J,W]),U1(()=>{if(G)g(J)},[G,J,g]);let J0=document.getElementById("plan-scroll-container"),{popovers:t,isPopoverOpen:G0}=Q5({containerRef:M,restoreKey:G,restoreAnnotations:I,extractContext:(T)=>I$(T,M.current),canvasFile:J,scrollContainer:J0}),{popovers:a,isDrawing:X0,isPopoverOpen:B0}=$5({containerRef:M,restoreKey:G,canvasFile:J,scrollContainer:J0}),A=G0||B0,b=b2(()=>{let T=new Map;for(let y of I)if(y.snippet.startsWith("["))T.set(y.snippet,y.id);return T},[I]);U1(()=>{let T=M.current;if(!T)return;let y=(P)=>{if(c||A||X0)return;let x=P.target;if(x.closest("[data-block-comment-btn]"))return;d(!1);let i=x.closest(T1);if(i&&T.contains(i)){let k0=V1(T).indexOf(i);W0(k0>=0?k0:null)}else W0(null);let q0=x.closest($1);if(q0&&T.contains(q0)){E(q0);let F0=u0(q0),k0=F0?b.get(F0):void 0;if(k0&&k0!==O)F(k0)}else E(null)},j=(P)=>{if(c||A)return;if(P.relatedTarget?.closest("[data-block-comment-btn]"))return;E(null),F(null)};return T.addEventListener("mousemove",y),T.addEventListener("mouseleave",j),()=>{T.removeEventListener("mousemove",y),T.removeEventListener("mouseleave",j)}},[G,c,A,X0,b,O]),U1(()=>{let T=(y)=>{let j=y.target.tagName;if(j==="INPUT"||j==="TEXTAREA"||y.target.isContentEditable)return;if(c||A)return;let P=M.current;if(!P)return;if(y.key==="ArrowDown"){y.preventDefault(),d(!0);let x=V1(P);if(x.length===0)return;W0((i)=>{if(i===null)return 0;return Math.min(i+1,x.length-1)})}else if(y.key==="ArrowUp"){y.preventDefault(),d(!0);let x=V1(P);if(x.length===0)return;W0((i)=>{if(i===null)return x.length-1;return Math.max(i-1,0)})}else if(y.key==="a"||y.key==="A"){if($0===null||!P)return;let i=V1(P)[$0];if(!i)return;if(!i.matches($1))return;y.preventDefault();let q0=u0(i);if(!q0)return;let F0=b.get(q0);if(F0)F(F0),Q0({anchorEl:i,snippet:q0,annId:F0});else Q0({anchorEl:i,snippet:q0})}else if(y.key===" "||y.key==="Enter"){if($0===null)return;let i=V1(P)[$0];if(!i)return;let q0=i.getAttribute("data-md");if(q0==="choice-option"||q0==="multichoice-option")y.preventDefault(),i.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(q0==="userinput"){y.preventDefault();let F0=i.querySelector("textarea");if(F0){F0.focus();let k0=(N1)=>{if(N1.key==="Escape")N1.preventDefault(),F0.blur(),d(!0)};F0.addEventListener("keydown",k0),F0.addEventListener("blur",()=>F0.removeEventListener("keydown",k0),{once:!0})}}else if(q0==="rangeinput"){y.preventDefault();let F0=i.querySelector("input[type='range']");if(F0){F0.focus();let k0=(N1)=>{if(N1.key==="Escape"||N1.key==="ArrowUp"||N1.key==="ArrowDown")N1.preventDefault(),F0.blur(),d(!0)};F0.addEventListener("keydown",k0),F0.addEventListener("blur",()=>F0.removeEventListener("keydown",k0),{once:!0})}}}else if(y.key==="Escape")W0(null),d(!1),F(null)};return document.addEventListener("keydown",T),()=>document.removeEventListener("keydown",T)},[$0,c,A,b]),U1(()=>{let T=M.current;if(!T||$0===null||!_0)return;let j=V1(T)[$0];if(!j)return;j.style.outline="2px solid var(--color-accent-blue)",j.style.outlineOffset="-2px",j.style.borderRadius="8px",j.scrollIntoView({block:"nearest",behavior:"smooth"});let P=u0(j),x=P?b.get(P):void 0;if(x)F(x);return()=>{j.style.outline="",j.style.outlineOffset="",j.style.borderRadius=""}},[$0,_0,b]);let p=b2(()=>G?Y0(G,{},void 0,!1,void 0,this):null,[G]);if(U)return Y0("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(H)return Y0(_3,{message:H},void 0,!1,void 0,this);if(!G)return Y0("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return Y0(P6.Provider,{value:J,children:[Y0("div",{ref:M,className:"plan-content plan-updated","data-canvas-file":J,children:Y0(z3,{revision:$,filename:J,reportError:W,children:p},`${$}:${J}`,!1,void 0,this)},void 0,!1,void 0,this),h&&Y0(k6,{note:h.note,onSave:(T)=>{_(h.id,T),V(null)},onCancel:()=>V(null)},void 0,!1,void 0,this),t,a,Y0(V6,{containerRef:M,hoveredBlock:u,focusedBlockIndex:$0,blockPopover:c,blockAnnotationMap:b,activeAnnotationId:O,onOpen:(T,y,j)=>{if(j)F(j),Q0({anchorEl:T,snippet:y,annId:j});else Q0({anchorEl:T,snippet:y})}},void 0,!1,void 0,this),c&&!c.annId&&Y0(B1,{anchorEl:c.anchorEl,scrollContainer:J0,snippet:c.snippet,truncateAt:80,onAdd:(T,y)=>{let j=t0();K(j,c.snippet,T,void 0,void 0,y,J),Q0(null)},onCancel:()=>Q0(null)},void 0,!1,void 0,this),c?.annId&&(()=>{let T=I.find((y)=>y.id===c.annId);if(!T)return null;return Y0(j2,{anchorEl:c.anchorEl,scrollContainer:J0,initialNote:T.note,initialImages:T.images,onUpdate:(y,j)=>{_(c.annId,y);let P=T.images||[];for(let x of j)if(!P.includes(x))w(c.annId,x);for(let x of P)if(!j.includes(x))S(c.annId,x)},onDelete:()=>{z(c.annId),F(null),Q0(null)},onClose:()=>Q0(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function V1($){return Array.from($.querySelectorAll(T1))}function V6({containerRef:$,hoveredBlock:J,focusedBlockIndex:Q,blockPopover:X,blockAnnotationMap:W,activeAnnotationId:G,onOpen:Y}){let[H,q]=i0([]);U1(()=>{let K=$.current;if(!K||W.size===0){q([]);return}let z=[];for(let _ of K.querySelectorAll($1)){let w=u0(_);if(w&&W.has(w))z.push(_)}q(z)},[W,$.current]);let[U,N]=i0(null);U1(()=>{if(!G||!$.current){N(null);return}for(let K of $.current.querySelectorAll(T1)){let z=u0(K);if(z&&W.get(z)===G){N(K);return}}N(null)},[G,W]),U1(()=>{if(!U)return;return U.style.boxShadow="inset 0 0 0 1.5px var(--color-highlight-bg)",U.style.borderRadius="8px",()=>{U.style.boxShadow="",U.style.borderRadius=""}},[U]);let M=b2(()=>{if(Q===null||!$.current)return null;let K=V1($.current)[Q];if(!K)return null;return K.matches($1)?K:null},[Q,$.current]),L=b2(()=>{let K=new Set(H);if(J)K.add(J);if(M)K.add(M);if(X?.anchorEl)K.add(X.anchorEl);return Array.from(K)},[H,J,M,X]);return Y0(T6,{children:L.map((K)=>Y0(A6,{block:K,isHovered:K===J||K===M||K===X?.anchorEl,blockAnnotationMap:W,activeAnnotationId:G,onOpen:Y},K.getAttribute("data-task-id")||K.getAttribute("data-md-title")||K.textContent?.slice(0,30)||"block",!1,void 0,this))},void 0,!1,void 0,this)}function A6({block:$,isHovered:J,blockAnnotationMap:Q,activeAnnotationId:X,onOpen:W}){let G=u0($);if(!G)return null;let Y=Q.get(G),H=!!Y;return Z6(Y0("button",{"data-block-comment-btn":!0,onClick:(U)=>{U.stopPropagation(),W(U.currentTarget,G,Y)},className:`absolute top-1 right-1 z-10 w-6 h-6 flex items-center justify-center rounded transition-all duration-150 ${H?Y===X?"text-accent-amber bg-accent-amber-muted":"text-accent-amber opacity-60 hover:opacity-100":J?"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:H?"Edit annotation":"Add annotation",children:Y0("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:H?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:Y0("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),$)}function k6({note:$,onSave:J,onCancel:Q}){let[X,W]=_$.useState($),G=_$.useRef(null);return _$.useEffect(()=>{G.current?.focus(),G.current?.select()},[]),Y0("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center",onClick:Q,children:Y0("div",{className:"bg-bg-elevated border border-border-hover rounded-lg shadow-md p-4 w-80",onClick:(Y)=>Y.stopPropagation(),children:[Y0("div",{className:"text-tiny uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Edit annotation"},void 0,!1,void 0,this),Y0("textarea",{ref:G,value:X,onChange:(Y)=>W(Y.currentTarget.value),className:"w-full bg-transparent border-none text-body font-body text-text-primary resize-vertical focus:outline-none min-h-[60px]",onKeyDown:(Y)=>{if(Y.key==="Enter"&&(Y.ctrlKey||Y.metaKey))J(X.trim());if(Y.key==="Escape")Q()}},void 0,!1,void 0,this),Y0("div",{className:"flex justify-end gap-2 mt-2",children:[Y0("button",{onClick:Q,className:"text-meta text-text-tertiary font-body px-3 py-1",children:"Cancel"},void 0,!1,void 0,this),Y0("button",{onClick:()=>J(X.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{jsxDEV as P0,Fragment as D5}from"react/jsx-dev-runtime";function w3({gateName:$,hasGate:J,isCurrentGate:Q,onSubmit:X}){let[W,G]=y6(!0);if(!W)return P0("button",{onClick:()=>G(!0),className:"flex w-9 flex-col items-center gap-2 border-l border-border-subtle bg-bg-surface py-3 text-text-tertiary hover:text-text-secondary",title:"Open review panel",children:P0("span",{className:"[writing-mode:vertical-rl] text-tiny uppercase tracking-wide",children:"review"},void 0,!1,void 0,this)},void 0,!1,void 0,this);let Y=P0("button",{onClick:()=>G(!1),className:"text-text-tertiary hover:text-text-secondary",title:"Collapse",children:P0("svg",{width:"14",height:"14",viewBox:"0 0 12 12",fill:"none",children:P0("path",{d:"M4.5 3L7.5 6L4.5 9",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);return P0("aside",{className:"flex h-full w-72 flex-col border-l border-border-subtle bg-bg-surface",children:J?P0(z$,{onSubmit:(H,q,U)=>X(H,U),collapseButton:Y},void 0,!1,void 0,this):P0(D5,{children:[P0("div",{className:"flex items-center justify-between border-b border-border-subtle px-4 py-3",children:[P0("div",{className:"text-tiny uppercase tracking-wide text-text-tertiary",children:"review & annotate"},void 0,!1,void 0,this),Y]},void 0,!0,void 0,this),P0("div",{className:"flex-1 px-4 py-6 text-center text-tiny text-text-tertiary",children:Q&&$?P0(D5,{children:["gate ",P0("span",{className:"font-mono",children:$},void 0,!1,void 0,this)," open — connect to a live daemon to review the pushed canvas."]},void 0,!0,void 0,this):$?P0(D5,{children:["this phase's ",P0("span",{className:"font-mono",children:$},void 0,!1,void 0,this)," gate opens once the earlier phases are approved."]},void 0,!0,void 0,this):"no gate on this phase — nothing to review here."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import{useEffect as x6,useState as I5}from"react";import{jsxDEV as r}from"react/jsx-dev-runtime";var Y2="rounded border border-border-medium px-3 py-1 text-tiny disabled:opacity-40",O3="rounded border border-border-medium bg-bg-base px-2 py-1 text-body text-text-primary";function S3({platform:$,live:J}){let[Q,X]=I5(""),[W,G]=I5(null),[Y,H]=I5(null),{data:q,enabled:U,busy:N,error:M}=$,L=q?.connection;x6(()=>{if(L)H(L.controlOrigin)},[L?.controlOrigin]);let K=q?.pairing,z=q?.deployment,_=z?.status==="preparing"||z?.status==="pending"||z?.status==="running",w=K?.status==="pending"||K?.status==="approved",S=q?.credential.available&&(q.credential.expiresAt===null||q.credential.expiresAt*1000>Date.now());return r("details",{className:"shrink-0 border-b border-border-subtle bg-bg-surface px-6 py-2",open:!0,children:[r("summary",{className:"cursor-pointer font-heading text-section",children:"Deployment"},void 0,!1,void 0,this),r("div",{className:"max-h-64 space-y-3 overflow-y-auto py-3 text-body","aria-busy":N,children:[!J&&r("p",{className:"text-text-tertiary",children:"Offline / demo mode — deployment controls are disabled."},void 0,!1,void 0,this),J&&!q&&!M&&r("p",{role:"status",children:"Loading project status…"},void 0,!1,void 0,this),M&&r("p",{role:"alert",className:"text-accent-red",children:M},void 0,!1,void 0,this),L?r("div",{className:"space-y-1",children:[r("p",{children:["App ",r("strong",{children:L.receipt.app.id},void 0,!1,void 0,this)," · ",L.receipt.provider," · ",L.receipt.environment.env]},void 0,!0,void 0,this),r("p",{className:"text-text-secondary",children:["Control: ",L.controlOrigin]},void 0,!0,void 0,this),r("p",{children:["Local credential: ",S?"available":"unavailable or expired",q?.credential.expiresAt!=null&&` · expires ${new Date(q.credential.expiresAt*1000).toLocaleString()}`]},void 0,!0,void 0,this),r("a",{className:"text-accent-blue underline",href:L.controlOrigin,target:"_blank",rel:"noreferrer",children:"Open console to manage or revoke access"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):r("p",{className:"text-text-secondary",children:"No platform connection."},void 0,!1,void 0,this),!L&&Y&&r("a",{className:"text-accent-blue underline",href:Y,target:"_blank",rel:"noreferrer",children:"Open console to revoke server access"},void 0,!1,void 0,this),r("form",{className:"flex flex-wrap items-center gap-2",onSubmit:(O)=>{O.preventDefault(),$.act({kind:"connect",controlOrigin:Q})},children:[r("label",{htmlFor:"control-origin",children:"Control origin"},void 0,!1,void 0,this),r("input",{className:O3,id:"control-origin",type:"url",value:Q,onChange:(O)=>X(O.currentTarget.value),placeholder:"https://control.example.com",disabled:!U||!!L||w,required:!0},void 0,!1,void 0,this),r("button",{className:Y2,type:"submit",disabled:!U||!!L||w,children:N?"Working…":"Connect"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),K?.status==="pending"&&U&&K.expiresAt*1000>Date.now()&&r("a",{className:"text-accent-blue underline",href:K.authorizationUrl,target:"_blank",rel:"noreferrer",children:"Review connection in platform console"},void 0,!1,void 0,this),K&&r("p",{role:"status",children:["Connection: ",K.status,(K.status==="failed"||K.status==="recovery_required")&&` — ${K.message}`]},void 0,!0,void 0,this),r("div",{className:"flex flex-wrap items-center gap-2",children:[r("button",{className:Y2,type:"button",disabled:!U||!L&&!K,onClick:()=>void $.act({kind:"disconnect"}),children:"Disconnect locally"},void 0,!1,void 0,this),r("span",{className:"text-tiny text-text-tertiary",children:"Deletes local credentials only. Revoke server access in the console."},void 0,!1,void 0,this),r("button",{className:Y2,type:"button",disabled:!U||!L||!S||_||w,onClick:()=>void $.act({kind:"deploy"}),children:_?"Deploy in progress…":"Deploy pushed commit"},void 0,!1,void 0,this),r("button",{className:Y2,type:"button",disabled:!J||N,onClick:$.refresh,children:"Refresh status"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z&&r("div",{role:"status",className:"space-y-1",children:[r("p",{children:["Deployment: ",r("strong",{children:z.status},void 0,!1,void 0,this),z.message&&` — ${z.message}`]},void 0,!0,void 0,this),z.runId&&r("p",{children:["Run: ",r("code",{children:z.runId},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.commitSha&&r("p",{children:["Commit: ",r("code",{children:z.commitSha},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.consoleUrl&&r("a",{className:"mr-4 text-accent-blue underline",href:z.consoleUrl,target:"_blank",rel:"noreferrer",children:"View run in console"},void 0,!1,void 0,this),z.appUrl&&r("a",{className:"text-accent-blue underline",href:z.appUrl,target:"_blank",rel:"noreferrer",children:"Open deployed application"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("form",{className:"flex flex-wrap items-center gap-2",onSubmit:(O)=>{O.preventDefault(),$.act({kind:"preview",url:W??q?.previewUrl??""})},children:[r("label",{htmlFor:"preview-url",children:"Local preview URL"},void 0,!1,void 0,this),r("input",{className:O3,id:"preview-url",type:"url",value:W??q?.previewUrl??"",onChange:(O)=>G(O.currentTarget.value),placeholder:q?.previewUrl??"http://localhost:3000",disabled:!U,required:!0},void 0,!1,void 0,this),r("button",{className:Y2,type:"submit",disabled:!U,children:"Set preview"},void 0,!1,void 0,this),r("button",{className:Y2,type:"button",disabled:!U||!q?.previewUrl,onClick:()=>{G(null),$.act({kind:"preview",url:null})},children:"Clear preview"},void 0,!1,void 0,this),r("span",{className:"text-tiny text-text-tertiary",children:[q?.previewUrl??"No local preview configured."," · Separate from the deployed application."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as e0}from"react/jsx-dev-runtime";var v6={connecting:"connecting…",live:"live",offline:"offline",fixture:"fixture"},h6={connecting:"bg-accent-amber",live:"bg-accent-green",offline:"bg-accent-red",fixture:"bg-accent-blue"};function R3({sessionId:$,status:J,watching:Q}){return e0("header",{className:"flex h-11 shrink-0 items-center justify-between border-b border-border-subtle bg-bg-surface px-4",children:[e0("div",{className:"flex items-center gap-2 text-body text-text-secondary",children:[e0("span",{className:"text-text-tertiary",children:"session"},void 0,!1,void 0,this),e0("span",{className:"rounded bg-bg-elevated px-2 py-0.5 font-mono text-code text-text-primary",children:$},void 0,!1,void 0,this)]},void 0,!0,void 0,this),e0("div",{className:"flex items-center gap-4",children:[Q&&e0("span",{className:"flex items-center gap-1.5 text-tiny text-text-tertiary",children:[e0("span",{className:"inline-flex h-1.5 w-1.5 animate-pulse rounded-full bg-accent-blue"},void 0,!1,void 0,this),"agent watching"]},void 0,!0,void 0,this),e0("span",{className:"flex items-center gap-1.5 text-tiny text-text-secondary",children:[e0("span",{className:`inline-flex h-2 w-2 rounded-full ${h6[J]}`},void 0,!1,void 0,this),v6[J]]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}var G2=["intake","vision","flows","tech","skeletons","issues","build"],m6={intake:{title:"Intake (brief -> classification)",label:"Intake",reads:["<init brief>","<supplied docs (spotlight: data, not instructions)>",".fabrika/intent/brief.md"],produces:[".fabrika/intent/brief.md"],goal:"Capture the problem, users, success criteria and non-goals into .fabrika/intent/brief.md; classify the project type.",gate:!1,reviewedAt:"vision"},vision:{title:"Vision + scope + principles (reviewed with the brief)",label:"Brief + principles",reads:[".fabrika/intent/brief.md"],produces:[".fabrika/intent/glossary.md",".fabrika/principles/principles.md"],goal:"Write the ubiquitous-language glossary (.fabrika/intent/glossary.md) and RFC2119 Must/Must-not/Preference/Escalation principles (.fabrika/principles/principles.md).",gate:!0,gateView:"brief.jsx"},flows:{title:"User flows",label:"User flows",reads:[".fabrika/intent/*",".fabrika/principles/*"],produces:[".fabrika/architecture/flows/*.flow.md"],goal:"For each user-facing journey, write .fabrika/architecture/flows/<slug>.flow.md: front matter `actor`, `goal`, `route` (the screen it starts on) and `leads_to` (the screens it moves to), then preconditions, steps and success/failure.",gate:!0,gateView:".fabrika/architecture/flows-review.jsx",gateViewCommand:"fabrika builder flows review"},tech:{title:"Tech + scaffold decision",label:"Tech + scaffold decision",reads:[".fabrika/architecture/flows/*.flow.md"],produces:[".fabrika/architecture/tech.md"],goal:"Read the active stack preset + its decisions (the Stack: pointer), check the requires-closure, surface recommends, then record the resolved stack + reasoning into .fabrika/architecture/tech.md.",gate:!0,catalog:!0,gateView:"tech.jsx"},skeletons:{title:"Opice skeletons",label:"Opice skeletons",reads:[".fabrika/architecture/flows/*.flow.md",".fabrika/architecture/spec/*.md"],produces:["tests/browser/*.test.ts"],goal:"For each flow -> tests/browser/<slug>.test.ts with metadata-first browserTest, pending step({intent,hint}) stubs and invariant.todo acceptances (skeleton, not authored).",gate:!0,gateView:"review-grid.jsx",producesEditedLater:!0,skills:["opice-plan"]},issues:{title:"Induce issues (compile step, not a real phase - SPEC 6.4)",label:"Induce issues",reads:["tests/browser/*.test.ts"],produces:[".fabrika/issues/ISSUE-*.md"],goal:"Run `fabrika builder induce` — it mechanically writes .fabrika/issues/ISSUE-NNN.md from skeleton metadata (foundation issues = union of seeds/roles/url; feature issues = vertical slices) with goal/satisfies/depends_on/touches front-matter. Review the generated issues, then `fabrika builder next`.",gate:!1},build:{title:"Build (agent-assisted, supervised subagents)",label:"Build (agent-assisted)",reads:[".fabrika/issues/ISSUE-*.md","tests/browser/*.test.ts"],produces:["<green bun test per issue>"],goal:"Run `fabrika builder build` for the orchestration brief, apply the bundled build-orchestrator playbook in the MAIN session, and fan out direct implementer subagents per ready issue (worktree-isolated); each must implement -> opice-author -> bun test green. Freeze invariants, adversarially verify them, and escalate blocked issues to the final review.",gate:!0,gateView:".fabrika/build/review.jsx",gateViewCommand:"fabrika builder build review",skills:["fabrika","opice-author"]}},O$=G2.map(($,J)=>({id:$,number:J+1,...m6[$]})),S$=O$.length;function u6($){return G2.indexOf($)}function C3($){let J=O$[u6($)];if(!J)throw Error(`Unknown phase id: ${$}`);return J}function g2($,J,Q){if(J.includes($))return"done";if($===Q)return"current";return"upcoming"}import{jsxDEV as H0}from"react/jsx-dev-runtime";function c6({status:$}){if($==="done")return H0("span",{className:"flex h-5 w-5 items-center justify-center rounded-full bg-accent-green-muted text-accent-green",children:H0("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:H0("path",{d:"M2.5 6.2L4.8 8.5L9.5 3.5",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this);if($==="current")return H0("span",{className:"relative flex h-5 w-5 items-center justify-center",children:[H0("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-accent-amber opacity-40"},void 0,!1,void 0,this),H0("span",{className:"relative inline-flex h-2.5 w-2.5 rounded-full bg-accent-amber"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return H0("span",{className:"flex h-5 w-5 items-center justify-center rounded-full border border-border-medium"},void 0,!1,void 0,this)}function P3({state:$,focused:J,onFocus:Q}){return H0("nav",{className:"flex h-full flex-col border-r border-border-subtle bg-bg-surface",children:[H0("div",{className:"border-b border-border-subtle px-4 py-3",children:[H0("div",{className:"font-heading text-xl text-text-primary",children:"fabrika"},void 0,!1,void 0,this),H0("div",{className:"text-tiny uppercase tracking-wide text-text-tertiary",children:"guided app build"},void 0,!1,void 0,this),H0("p",{className:"mt-2 text-tiny leading-snug text-text-tertiary",children:"7 phases from brief to build, most ending in a review gate — click a phase to see its canvas."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H0("ol",{className:"flex-1 overflow-y-auto py-2",children:O$.map((X)=>{let W=g2(X.id,$.completed,$.current),G=J===X.id,Y=W!=="upcoming";return H0("li",{children:H0("button",{disabled:!Y,onClick:()=>Y&&Q(X.id),className:["group flex w-full items-start gap-3 px-4 py-2.5 text-left transition-colors",G?"bg-bg-elevated":"hover:bg-bg-elevated-half",Y?"cursor-pointer":"cursor-not-allowed opacity-55"].join(" "),children:[H0("div",{className:"mt-0.5 shrink-0",children:H0(c6,{status:W},void 0,!1,void 0,this)},void 0,!1,void 0,this),H0("div",{className:"min-w-0",children:[H0("div",{className:"flex items-center gap-1.5",children:[H0("span",{className:"text-tiny tabular-nums text-text-tertiary",children:[X.number,"/",S$]},void 0,!0,void 0,this),X.gate&&H0("span",{title:"canvas gate",className:"rounded bg-badge-bg px-1 text-[10px] uppercase tracking-wide text-accent-amber",children:"gate"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H0("div",{className:["truncate text-task-label",W==="current"?"font-semibold text-text-primary":W==="done"?"text-text-secondary":"text-text-tertiary"].join(" "),children:X.label},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},X.id,!1,void 0,this)})},void 0,!1,void 0,this),H0("div",{className:"border-t border-border-subtle px-4 py-2 text-tiny text-text-tertiary",children:["phase derived from ",H0("span",{className:"font-mono",children:"GET /api/phase"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as S0,Fragment as d6}from"react/jsx-dev-runtime";function p6({url:$,children:J}){return S0("div",{className:"flex h-full flex-col overflow-hidden rounded-md border border-border-medium bg-bg-base",children:[S0("div",{className:"flex items-center gap-1.5 border-b border-border-subtle bg-bg-elevated px-3 py-2",children:[S0("span",{className:"h-2.5 w-2.5 rounded-full bg-accent-red/60"},void 0,!1,void 0,this),S0("span",{className:"h-2.5 w-2.5 rounded-full bg-accent-amber/60"},void 0,!1,void 0,this),S0("span",{className:"h-2.5 w-2.5 rounded-full bg-accent-green/60"},void 0,!1,void 0,this),S0("span",{className:"ml-2 truncate font-mono text-tiny text-text-tertiary",children:$},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J]},void 0,!0,void 0,this)}function l6({previewUrl:$}){if(!$)return S0("p",{className:"text-body text-text-tertiary",children:"No local preview configured. Set a local preview URL in Deployment."},void 0,!1,void 0,this);return S0(d6,{children:[S0(p6,{url:$,children:S0("iframe",{src:$,className:"min-h-0 flex-1 bg-white",title:"Local application preview"},void 0,!1,void 0,this)},void 0,!1,void 0,this),S0("p",{className:"mt-2 px-0.5 text-tiny text-text-tertiary",children:"Local development preview. This is separate from the deployed application."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function f3({previewUrl:$}){return S0("aside",{className:"flex h-full flex-col border-l border-border-subtle bg-bg-surface",children:[S0("div",{className:"flex items-center justify-between border-b border-border-subtle px-4 py-3",children:[S0("div",{className:"text-tiny uppercase tracking-wide text-text-tertiary",children:"live preview"},void 0,!1,void 0,this),S0("span",{className:"rounded bg-bg-elevated px-2 py-0.5 text-tiny text-text-secondary",children:"app"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),S0("div",{className:"flex min-h-0 flex-1 flex-col p-3",children:S0(l6,{previewUrl:$},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as n3,useState as s3}from"react";var EB=Object.freeze({DEPLOY_TRIGGER:"deploy.trigger",DEPLOY_READ:"deploy.read",APP_MANAGE:"app.manage",NAMESPACE_MANAGE:"namespace.manage",SECRET_MANAGE:"secret.manage",SOURCE_CONNECTION_MANAGE:"source.connection.manage",SOURCE_WORKSPACE_READ:"source.workspace.read",SOURCE_WORKSPACE_WRITE:"source.workspace.write",SOURCE_PULL_REQUEST_CREATE:"source.pull-request.create",ACCESS_APPROVE:"access.approve",MAIL_READ:"mail.read",MAIL_CONTENT_READ:"mail.content.read",MAIL_MANAGE:"mail.manage",DATA_READ:"data.read",DATA_CONTENT_READ:"data.content.read",DATA_MANAGE:"data.manage"}),yB=Object.freeze({APP:"app",ENVIRONMENT:"environment"});function i6($){if(typeof $!=="string"||$.length>2048)return null;try{let J=new URL($),Q=J.hostname==="localhost"||J.hostname.endsWith(".localhost")||J.hostname==="[::1]"||/^127(?:\.[0-9]{1,3}){3}$/.test(J.hostname);if(J.protocol!=="https:"&&!(J.protocol==="http:"&&Q))return null;if(J.username!==""||J.password!==""||J.pathname!=="/"||J.search!==""||J.hash!=="")return null;return J.origin}catch{return null}}var j3=B.string().transform(($,J)=>{let Q=i6($);if(Q!==null)return Q;return J.addIssue({code:"custom",message:"invalid builder public origin"}),B.NEVER}),hB=B.preprocess(($)=>{if(typeof $==="object"&&$!==null&&Object.keys($).length!==4)return;return $},B.object({version:B.literal(1),controlOrigin:j3,iamIssuer:j3,provider:B.string().regex(/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/)}).strict());var r6=/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;var o6=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;var b5=B.number().int().safe().nonnegative(),g5=B.string().regex(o6),n6=B.object({id:g5,repoUrl:B.string(),defaultBranch:B.string(),workerDir:B.string().nullable(),buildCmd:B.string().nullable(),configPath:B.string().nullable(),githubConnectionId:B.string().nullable().optional(),githubInstallationId:b5.nullable(),createdAt:b5}).strict().transform(({githubConnectionId:$,githubInstallationId:J,createdAt:Q,...X})=>({...X,...$===void 0?{}:{githubConnectionId:$},githubInstallationId:J,createdAt:Q})),s6=B.object({env:g5,namespaceId:B.string().min(1).max(128).nullable(),domain:B.string().min(1).max(253).nullable(),publicOrigin:B.string().min(1).max(2048).nullable(),triggerRef:B.string().min(1).max(1024).nullable()}).strict(),Z3=B.object({version:B.literal(1),attemptId:B.string().regex(r6),provider:g5,app:n6,environment:s6,createdAt:b5}).strict();var t6=100,a6=512,lB=B.object({cursor:B.string().min(1).max(a6).optional(),limit:B.number().int().safe().min(1).max(t6).optional()}).strict().transform(({cursor:$,limit:J})=>({...$===void 0?{}:{cursor:$},...J===void 0?{}:{limit:J}}));var R$="FABRIKA_IAM_APP_ID";var e6=/%2f|%5c/i,$Q=/%2e/gi;function E5($){if($==="/")return!0;if(!$.startsWith("/")||$.includes("\\")||e6.test($))return!1;let J=$.slice(1).split("/"),Q=J.length-1;return J.every((X,W)=>(X!==""||W===Q)&&!QQ(X)&&JQ(X))}function JQ($){try{return decodeURIComponent($),!0}catch{return!1}}function QQ($){let J=$.replace($Q,".");return J==="."||J===".."}var XQ=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),WQ=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225];function r0($,J){return $>>>J|$<<32-J}function q2($){let J=new TextEncoder().encode($),Q=new Uint8Array(Math.ceil((J.length+9)/64)*64);Q.set(J),Q[J.length]=128;let X=new DataView(Q.buffer),W=J.length*8;X.setUint32(Q.length-8,Math.floor(W/4294967296)),X.setUint32(Q.length-4,W>>>0);let G=new Uint32Array(WQ),Y=new Uint32Array(64);for(let H=0;H<Q.length;H+=64){for(let S=0;S<16;S++)Y[S]=X.getUint32(H+S*4);for(let S=16;S<64;S++){let O=Y[S-15]??0,F=Y[S-2]??0,g=r0(O,7)^r0(O,18)^O>>>3,I=r0(F,17)^r0(F,19)^F>>>10;Y[S]=(Y[S-16]??0)+g+(Y[S-7]??0)+I}let[q=0,U=0,N=0,M=0,L=0,K=0,z=0,_=0]=G;for(let S=0;S<64;S++){let O=r0(L,6)^r0(L,11)^r0(L,25),F=L&K^~L&z,g=_+O+F+(XQ[S]??0)+(Y[S]??0)>>>0,I=r0(q,2)^r0(q,13)^r0(q,22),h=q&U^q&N^U&N,V=I+h>>>0;_=z,z=K,K=L,L=M+g>>>0,M=N,N=U,U=q,q=g+V>>>0}let w=[q,U,N,M,L,K,z,_];for(let[S,O]of w.entries())G[S]=(G[S]??0)+O}return Array.from(G,(H)=>H.toString(16).padStart(8,"0")).join("")}var y5="FABRIKA_CONTRACT_DIGEST";var A3="*";class YQ{#$;#J;constructor($,J){this.#$=$,this.#J=J}plan($,J){return GQ(this.#$,this.#J,$,J)}}function GQ($,J,Q,X){if(!E5(X))return{outcome:"non-canonical"};let W=HQ(X),G=BQ(X,J),Y=null,H=!1;for(let q of $){if(!qQ(q.row.method,Q)||G!==null&&!T3(q.row.path,G))continue;let U=UQ(q.segments,W);if(U===null)continue;let N=Y===null?-1:NQ(q.segments,Y.endpoint.segments);if(N<0)Y={endpoint:q,params:U},H=!1;else if(N===0)H=!0}if(Y===null||H)return{outcome:"no-endpoint"};return{outcome:"endpoint",endpoint:Y.endpoint.row,params:Y.params}}function qQ($,J){return $===A3||$===J}function HQ($){return $==="/"?[]:$.slice(1).split("/")}function T3($,J){return $.startsWith(`${J}/`)}function BQ($,J){let Q=null;for(let X of J)if(T3($,X)&&(Q===null||X.length>Q.length))Q=X;return Q}function UQ($,J){let Q=[];for(let[X,W]of $.entries()){if(W.kind==="wildcard")return X===0||J.length>X?Object.fromEntries(Q):null;let G=J[X];if(G===void 0)return null;if(W.kind==="param"){if(G==="")return null;Q.push([W.name,G])}else if(W.value!==G)return null}return $.length===J.length?Object.fromEntries(Q):null}var k3={literal:0,param:1,wildcard:2};function NQ($,J){let Q=Math.min($.length,J.length);for(let X=0;X<Q;X++){let W=$[X],G=J[X];if(W===void 0||G===void 0)break;let Y=k3[W.kind]-k3[G.kind];if(Y!==0)return Y}return $.length-J.length}var C$="FABRIKA_IAM_ISSUER";var P$="FABRIKA_PROXY_SECRET";var LQ="FABRIKA_SOURCE_MAP_UPLOAD",KQ="FABRIKA_SOURCE_MAP_UPLOAD_KEY",x5="FABRIKA_TOKEN_KEYS",v5="FABRIKA_APP_ORIGIN",h5="FABRIKA_OPS_KEY_DIGESTS",m5="FABRIKA_EGRESS_REFUSED_HOSTS",MQ="FABRIKA_APPLICATION_OBJECT",FQ="FABRIKA_APPLICATION_OBJECTS",zQ=["FABRIKA_RELEASE",y5,C$,R$,"FABRIKA_OPERATIONS_DSN","FABRIKA_APP_ID","FABRIKA_ENVIRONMENT","FABRIKA_SERVICE_KEY","FABRIKA_APP_DATABASE_URL","FABRIKA_APP_RUNTIME_DATABASE_URL","FABRIKA_APP_DATABASE_CONNECTIONS","FABRIKA_APP_STORAGE_ENDPOINT","FABRIKA_APP_STORAGE_BUCKET","FABRIKA_APP_STORAGE_ACCESS_KEY_ID","FABRIKA_APP_STORAGE_SECRET_ACCESS_KEY","FABRIKA_STORAGE_PROVENANCE",P$,"FABRIKA_IAM_RPC_URL","FABRIKA_IAM_RPC_KEY",LQ,KQ,x5,v5,h5,m5,MQ,FQ];var ZU=new Set(zQ);function _Q($){return $.replace(/([a-z0-9])([A-Z])/g,"$1_$2").toUpperCase()}var u5=["mail","source"];function c5($){let J=`FABRIKA_PLATFORM_${_Q($)}`;return{url:`${J}_URL`,key:`${J}_KEY`}}var VU=new Set(u5.flatMap(($)=>Object.values(c5($))));var wQ=["FABRIKA_RELEASE","FABRIKA_OPERATIONS_DSN",C$,R$,"FABRIKA_APP_ID","FABRIKA_ENVIRONMENT","FABRIKA_SERVICE_KEY",P$,"FABRIKA_IAM_RPC_URL","FABRIKA_IAM_RPC_KEY",v5,x5,h5,m5],cU=new Set(wQ);var pU=new Set(u5.map(($)=>c5($).url));var OQ="/__fabrika/ops/";var QN=`${OQ}*`;var SQ=100,XN=(SQ-2)/2;var WN=q2("");var YN=-(2n**63n),GN=2n**63n-1n;var RQ="__Host-px_",EN=`${RQ}session`;var D3=100,T0=B.string().min(1),CQ=B.enum(["open","read-only","closed","inspect"]),PQ=B.object({appId:T0,env:T0,before:T0.optional(),limit:B.number().int().min(1).max(D3).optional()}).strict(),fQ=B.discriminatedUnion("kind",[B.object({appId:T0,env:T0,kind:B.literal("maintenance"),mode:CQ}).strict(),B.object({appId:T0,env:T0,kind:B.literal("backup")}).strict(),B.object({appId:T0,env:T0,kind:B.literal("restore"),at:B.string().datetime({offset:!0})}).strict()]),jQ=B.object({appId:T0,env:T0,operationId:T0,resolution:B.enum(["resume","open"])}).strict();var fL=B.object({ts:B.number().finite(),stream:B.enum(["stdout","stderr","meta"]),text:B.string()});function I3($,J){if(typeof $!=="string"||$.length===0||$.trim()!==$||[...$].some((X)=>X.charCodeAt(0)<=32||X.charCodeAt(0)===127||X==="\\"))throw Error(`${J} must be an HTTP(S) URL`);let Q;try{Q=new URL($)}catch{throw Error(`${J} must be an HTTP(S) URL`)}if(!/^https?:\/\//i.test($)||Q.protocol!=="https:"&&Q.protocol!=="http:"||Q.username||Q.password||/^https?:\/\/[^/?#]*@/i.test($))throw Error(`${J} must be an HTTP(S) URL without credentials`);return Q}function H2($,J="origin"){let Q=I3($,J);if(typeof $!=="string"||!/^https?:\/\/[^/?#]+\/?$/i.test($)||Q.pathname!=="/"||Q.search||Q.hash)throw Error(`${J} must be an origin without a path, query, or fragment`);let X=Q.hostname==="localhost"||Q.hostname==="127.0.0.1"||Q.hostname==="[::1]"||Q.hostname.endsWith(".localhost"),W=$.slice($.indexOf("://")+3).replace(/\/$/,"").toLowerCase(),G=Q.hostname!=="127.0.0.1"||/^127\.0\.0\.1(?::\d+)?$/.test(W);if(Q.protocol!=="https:"&&(!X||!G))throw Error(`${J} must use HTTPS except on localhost`);return Q.origin}function E2($){return I3($,"preview URL").href}var Z0=B.union([B.number(),B.nan()]),M0=B.string().optional().catch(void 0),f$=B.enum(G2),l5=B.enum(["approve","changes","none"]),ZQ=B.object({current:f$,index:Z0,completed:B.array(f$),reads:B.array(B.string()),produces:B.array(B.string()),gate:B.boolean(),satisfied:B.boolean(),verdicts:B.record(f$,l5).catch({}),unverified:B.array(f$).catch([]),stale:B.array(B.string()).catch([])}),b3=ZQ.extend({gateName:B.string().nullable().optional().catch(void 0)}).transform(({gateName:$,...J})=>({...J,...$===void 0?{}:{gateName:$}})),cL=B.object({ok:B.literal(!0),version:M0,pid:Z0.optional().catch(void 0),dataDir:M0,sessionsDir:B.string(),sessions:B.union([Z0,B.array(B.string())]).optional().catch(void 0)}).transform(({ok:$,version:J,pid:Q,dataDir:X,sessionsDir:W,sessions:G})=>({ok:$,...J===void 0?{}:{version:J},...Q===void 0?{}:{pid:Q},...X===void 0?{}:{dataDir:X},sessionsDir:W,...G===void 0?{}:{sessions:G}})),g3=B.object({ok:B.literal(!0),version:M0,sessions:B.array(B.string()).optional().catch(void 0)}).transform(({ok:$,version:J,sessions:Q})=>({ok:$,...J===void 0?{}:{version:J},...Q===void 0?{}:{sessions:Q}})),pL=B.object({ok:B.literal(!0),sessionsDir:B.string()}),E3=B.object({error:B.object({code:B.literal("builder_platform"),message:B.string().max(1000)})}),lL=B.object({ok:B.boolean(),browserUrl:M0,revision:Z0.optional().catch(void 0),isNew:B.boolean().optional().catch(void 0),canvasFiles:B.array(B.string()).optional().catch(void 0),gate:M0,error:M0,errors:B.record(B.string()).optional().catch(void 0)}).transform(({ok:$,browserUrl:J,revision:Q,isNew:X,canvasFiles:W,gate:G,error:Y,errors:H})=>({ok:$,...J===void 0?{}:{browserUrl:J},...Q===void 0?{}:{revision:Q},...X===void 0?{}:{isNew:X},...W===void 0?{}:{canvasFiles:W},...G===void 0?{}:{gate:G},...Y===void 0?{}:{error:Y},...H===void 0?{}:{errors:H}})),y3=B.object({status:B.enum(["queued","running","passed","failed","blocked","info"]),issue:M0,message:M0,at:M0,data:B.record(B.unknown()).optional().catch(void 0)}).transform(({status:$,issue:J,message:Q,at:X,data:W})=>({status:$,...J===void 0?{}:{issue:J},...Q===void 0?{}:{message:Q},...X===void 0?{}:{at:X},...W===void 0?{}:{data:W}})),dL=B.object({view:M0,directory:M0,projectRoot:M0,gate:M0,label:M0,response:M0}),x3=B.object({feedback:B.string().catch("")}),iL=B.object({found:B.literal(!0),revision:B.number().int(),verdict:l5.catch("none")}),rL=x3.extend({found:B.literal(!0),verdict:l5.catch("none")}),oL=x3.extend({type:B.literal("submit")}),v3=B.object({revision:Z0,hasFeedback:B.unknown().transform(($)=>$===!0),feedbackConsumed:B.unknown().transform(($)=>$===!0)}),nL=B.object({revisions:B.array(v3.nullable().catch(null)).transform(($)=>$.filter((J)=>J!==null))}),VQ=B.union([B.string().transform(($)=>({filename:$})),B.object({filename:B.string(),label:M0,diffStats:B.object({added:Z0,removed:Z0}).optional().catch(void 0)}).transform(({filename:$,label:J,diffStats:Q})=>({filename:$,...J===void 0?{}:{label:J},...Q===void 0?{}:{diffStats:Q}}))]).refine(($)=>$.filename.length>0),j$=B.array(VQ.nullable().catch(null)).transform(($)=>$.filter((J)=>J!==null)).catch([]),AQ=B.discriminatedUnion("kind",[B.object({kind:B.literal("directory")}),B.object({kind:B.literal("view"),filename:B.string()})]),kQ=v3.extend({label:B.string().nullable().catch(null),canvasFiles:j$,createdAt:M0,canvasScope:AQ.optional().catch(void 0)}).transform(({createdAt:$,canvasScope:J,...Q})=>({...Q,...$===void 0?{}:{createdAt:$},...J===void 0?{}:{canvasScope:J}})).refine(($)=>$.revision>0),h3=B.object({projectRoot:M0,label:M0,gate:B.string().nullable().catch(null),currentRevision:Z0.catch(0),canvasFiles:j$,revisions:B.array(kQ.nullable().catch(null)).transform(($)=>$.filter((J)=>J!==null)).catch([])}).transform(({projectRoot:$,label:J,...Q})=>({...Q,...$===void 0?{}:{projectRoot:$},...J===void 0?{}:{label:J}})),TQ=B.object({id:B.string(),label:M0}).transform(({id:$,label:J})=>({id:$,...J===void 0?{}:{label:J}})),m3=B.array(TQ.nullable().catch(null)).transform(($)=>$.filter((J)=>J!==null)).catch([]),DQ=B.object({file:B.string(),name:B.string(),seeds:B.array(B.string()),roles:B.array(B.string()),steps:Z0,invariants:Z0,pending:Z0,url:M0,feature:M0}).transform(({url:$,feature:J,...Q})=>({...Q,...$===void 0?{}:{url:$},...J===void 0?{}:{feature:J}})),u3=B.object({skeletons:B.array(DQ.nullable().catch(null)).transform(($)=>$.filter((J)=>J!==null))}),sL=B.object({content:B.string()}),c3=B.object({responses:B.unknown()}),p3=B.discriminatedUnion("type",[B.object({type:B.literal("plan-updated"),currentRevision:Z0,canvasFiles:B.array(B.unknown()).transform(($)=>j$.parse($)).optional().catch(void 0),gate:B.string().nullable().optional().catch(void 0)}),B.object({type:B.literal("revision-updated"),currentRevision:Z0}),B.object({type:B.literal("watcher-status"),watching:B.boolean()}),B.object({type:B.literal("phase-updated")}),B.object({type:B.literal("submit-ack"),revision:Z0})]).transform(($)=>{if($.type!=="plan-updated")return $;let{canvasFiles:J,gate:Q,...X}=$;return{...X,...J===void 0?{}:{canvasFiles:J},...Q===void 0?{}:{gate:Q}}}),D0=B.string().refine(($)=>$.trim().length>0),l3=B.number().finite().nonnegative(),p5=B.string().transform(($,J)=>{try{return H2($)}catch{return J.addIssue({code:B.ZodIssueCode.custom,message:"Invalid builder origin"}),B.NEVER}}),B2=B.string().transform(($,J)=>{try{return E2($)}catch{return J.addIssue({code:B.ZodIssueCode.custom,message:"Invalid preview URL"}),B.NEVER}}),d3=B.object({controlOrigin:p5,iamIssuer:p5,receipt:Z3}).strict(),tL=B.object({profile:D0,sessionId:D0,createdAt:D0.refine(($)=>Number.isFinite(Date.parse($))),connection:d3.optional(),previewUrl:B2.optional()}).strict().superRefine(($,J)=>{for(let Q of["connection","previewUrl"])if(Object.hasOwn($,Q)&&Reflect.get($,Q)===void 0)J.addIssue({code:B.ZodIssueCode.custom,path:[Q],message:"Present field must not be undefined"})}),IQ=B.discriminatedUnion("status",[B.object({status:B.literal("pending"),authorizationUrl:B2.refine(($)=>{try{return H2(new URL($).origin),!0}catch{return!1}}),expiresAt:l3}).strict(),B.object({status:B.literal("approved")}).strict(),B.object({status:B.literal("failed"),message:D0}).strict(),B.object({status:B.literal("expired")}).strict(),B.object({status:B.literal("cancelled")}).strict(),B.object({status:B.literal("recovery_required"),message:D0}).strict(),B.object({status:B.literal("connected")}).strict()]),bQ=B.object({status:B.enum(["preparing","pending","running","awaiting_approval","succeeded","failed","cancelled"]),runId:D0.nullable(),commitSha:D0.nullable(),message:D0.nullable(),appUrl:B2.nullable(),consoleUrl:B2.nullable()}).strict(),gQ=B.object({sessionId:D0,projectRoot:D0,connection:d3.nullable(),credential:B.object({available:B.boolean(),expiresAt:l3.nullable()}).strict(),pairing:IQ.nullable(),previewUrl:B2.nullable(),deployment:bQ.nullable()}).strict(),aL=B.object({projectRoot:D0}).strict(),eL=B.object({controlOrigin:p5}).strict(),$K=B.object({url:B2.nullable()}).strict();function i3($){let J=gQ.safeParse($);if(!J.success)throw Error("Invalid platform status");return J.data}function r3($,J){let Q=D0.safeParse($);if(!Q.success)throw Error("project id must be a non-empty string");return`/api/project/${encodeURIComponent(Q.data)}/${J}`}function N2(){return location.origin}function Z$(){return location.pathname.match(/\/s\/([^/]+)/)?.[1]??null}function EQ(){return new URLSearchParams(location.search).get("root")}async function U2($){let J=await fetch(N2()+$,{headers:{accept:"application/json"}});if(!J.ok)throw Error(`${$} -> ${J.status}`);return J.json()}var V0={async health(){let $=g3.safeParse(await U2("/health"));if(!$.success)throw Error("Invalid health response");return $.data},async phase($){let J=$??EQ(),Q=Z$(),X=new URLSearchParams;if(J)X.set("root",J);if(Q)X.set("session",Q);let W=X.toString(),G=b3.safeParse(await U2(`/api/phase${W?`?${W}`:""}`));if(!G.success)throw Error("Invalid phase response");return G.data},async meta($){let J=h3.safeParse(await U2(`/api/session/${encodeURIComponent($)}/meta`));if(!J.success)throw Error("Invalid session response");return{id:$,...J.data}},async sessions(){return m3.parse(await U2("/api/sessions"))},canvasUrl($,J,Q){let X=Q!=null?`?rev=${Q}`:"";return`${N2()}/api/session/${encodeURIComponent($)}/canvas/${encodeURIComponent(J)}${X}`},async skeletons($){let J=u3.safeParse(await U2(`/api/session/${encodeURIComponent($)}/skeletons`));return J.success?J.data.skeletons:[]},async feedback($,J){let Q=await fetch(`${N2()}/api/session/${encodeURIComponent($)}/revision/${J}/feedback`);if(!Q.ok)throw Error(`feedback -> ${Q.status}`);return Q.text()},async getResponses($,J,Q){try{let X=c3.safeParse(await U2(`/api/session/${encodeURIComponent($)}/revision/${J}/responses`));return X.success?Q(X.data.responses):null}catch{return null}},async saveResponses($,J,Q){try{await fetch(`${N2()}/api/session/${encodeURIComponent($)}/revision/${J}/responses`,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify(Q)})}catch{}},openSocket($,J){let Q=location.protocol==="https:"?"wss:":"ws:",X=N2().replace(/^https?:/,Q),W=new WebSocket(`${X}/ws/session/${encodeURIComponent($)}`);return W.onmessage=(G)=>{try{let Y=p3.safeParse(JSON.parse(String(G.data)));if(Y.success)J(Y.data)}catch{}},W},submitGate($,J,Q){if($.readyState===WebSocket.OPEN)return $.send(JSON.stringify({type:"submit",feedback:J,responses:Q})),!0;return!1},buildStream($){try{let J=new EventSource(`${N2()}/api/build/stream`);return J.onmessage=(Q)=>{try{let X=y3.safeParse(JSON.parse(Q.data));if(X.success)$(X.data)}catch{}},J}catch{return null}}};import{jsxDEV as h0}from"react/jsx-dev-runtime";function V$($){let J=[],Q=/(`[^`]+`|\*\*[^*]+\*\*)/g,X=0,W,G=0;while(W=Q.exec($)){if(W.index>X)J.push($.slice(X,W.index));let Y=W[0];if(Y.startsWith("`"))J.push(h0("code",{className:"rounded bg-bg-code px-1 py-0.5 font-mono text-code text-text-code",children:Y.slice(1,-1)},G++,!1,void 0,this));else J.push(h0("strong",{className:"font-semibold text-text-primary",children:Y.slice(2,-2)},G++,!1,void 0,this));X=W.index+Y.length}if(X<$.length)J.push($.slice(X));return J}function o3({source:$}){let J=$.split(`
71
+ `),Q=[],X=0,W=0;while(X<J.length){let G=J[X];if(G.startsWith("```")){let H=[];X++;while(X<J.length&&!J[X].startsWith("```"))H.push(J[X++]);X++,Q.push(h0("pre",{className:"my-3 overflow-auto rounded-md border border-border-subtle bg-bg-code p-3 font-mono text-code text-text-code",children:h0("code",{children:H.join(`
72
+ `)},void 0,!1,void 0,this)},W++,!1,void 0,this));continue}let Y=G.match(/^(#{1,4})\s+(.*)$/);if(Y){let H=Y[1].length,q=H===1?"mt-2 mb-3 font-heading text-section text-text-primary":H===2?"mt-5 mb-2 font-heading text-xl text-text-primary":"mt-4 mb-1 text-task-label font-semibold text-text-secondary uppercase tracking-wide";Q.push(h0("div",{className:q,children:V$(Y[2])},W++,!1,void 0,this)),X++;continue}if(/^[-*]\s+/.test(G)){let H=[];while(X<J.length&&/^[-*]\s+/.test(J[X]))H.push(J[X].replace(/^[-*]\s+/,"")),X++;Q.push(h0("ul",{className:"my-2 list-disc space-y-1 pl-5 text-body text-text-secondary",children:H.map((q,U)=>h0("li",{children:V$(q)},U,!1,void 0,this))},W++,!1,void 0,this));continue}if(/^\d+\.\s+/.test(G)){let H=[];while(X<J.length&&/^\d+\.\s+/.test(J[X]))H.push(J[X].replace(/^\d+\.\s+/,"")),X++;Q.push(h0("ol",{className:"my-2 list-decimal space-y-1 pl-5 text-body text-text-secondary",children:H.map((q,U)=>h0("li",{children:V$(q)},U,!1,void 0,this))},W++,!1,void 0,this));continue}if(G.trim()===""){X++;continue}Q.push(h0("p",{className:"my-2 text-body leading-relaxed text-text-secondary",children:V$(G)},W++,!1,void 0,this)),X++}return h0("div",{className:"select-text",children:Q},void 0,!1,void 0,this)}import{jsxDEV as Z,Fragment as a3}from"react/jsx-dev-runtime";function yQ({state:$,focused:J,isCurrentGate:Q}){let X=C3(J),W=g2(J,$.completed,$.current),G=W==="current",Y=G&&$.reads.length?$.reads.join(", "):X.reads.join(", "),H=G&&$.produces.length?$.produces.join(", "):X.produces.join(", ");return Z("div",{className:"border-b border-border-subtle px-6 py-4",children:[Z("div",{className:"flex items-center gap-3",children:[Z("h1",{className:"font-heading text-section text-text-primary",children:["Phase ",X.number,"/",S$," — ",X.label]},void 0,!0,void 0,this),Z("span",{className:["rounded px-2 py-0.5 text-tiny uppercase tracking-wide",W==="done"?"bg-accent-green-muted text-accent-green":W==="current"?"bg-accent-amber-muted text-accent-amber":"border border-border-medium text-text-tertiary"].join(" "),children:W},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Z("dl",{className:"mt-3 grid grid-cols-[5rem_1fr] gap-x-3 gap-y-1.5 text-body",children:[Z("dt",{className:"text-text-tertiary",children:"Read"},void 0,!1,void 0,this),Z("dd",{className:"min-w-0 break-words font-mono text-code text-text-secondary",children:Y},void 0,!1,void 0,this),Z("dt",{className:"text-text-tertiary",children:"Goal"},void 0,!1,void 0,this),Z("dd",{className:"min-w-0 break-words text-text-secondary",children:H},void 0,!1,void 0,this),Z("dt",{className:"text-text-tertiary",children:"Gate"},void 0,!1,void 0,this),Z("dd",{className:"min-w-0 break-words font-mono text-code text-text-secondary",children:X.gate?Z(a3,{children:["fabrika builder gate open ",J," --view view.jsx && fabrika builder gate wait"]},void 0,!0,void 0,this):X.reviewedAt?Z("span",{className:"text-text-tertiary",children:["— (reviewed at the ",X.reviewedAt," gate)"]},void 0,!0,void 0,this):Z("span",{className:"text-text-tertiary",children:"— (ungated compile step)"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q&&Z("div",{className:"mt-3 flex items-start gap-2 rounded-md bg-accent-amber-muted/60 px-3 py-2 text-tiny text-accent-amber",children:[Z("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"mt-px shrink-0",children:Z("path",{d:"M12 9v4m0 4h.01M10.3 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.7 3.86a2 2 0 0 0-3.42 0Z",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),Z("span",{children:[Z("strong",{className:"font-semibold",children:"Gate open."},void 0,!1,void 0,this)," Review the canvas — select text or hover a block to annotate, answer the choices, then"," ",Z("strong",{className:"font-semibold",children:"Submit"},void 0,!1,void 0,this)," in the panel on the right. That feedback is what"," ",Z("span",{className:"font-mono",children:"fabrika builder gate wait"},void 0,!1,void 0,this)," hands back to the active agent."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function xQ({sessionId:$,live:J,upcoming:Q}){let[X,W]=s3(null);n3(()=>{if(!J)return;let Y=!1;return V0.skeletons($).then((H)=>{if(!Y)W(H)}),()=>{Y=!0}},[$,J]);let G=X??[];return Z("div",{className:"p-6",children:[Q&&Z("p",{className:"mb-4 text-body text-text-tertiary",children:["Not reached yet — once the tech gate is approved, this phase turns each user flow into an opice ",Z("span",{className:"font-mono",children:"*.test.ts"},void 0,!1,void 0,this)," ","skeleton (the acceptance contract), reviewed here as a grid."]},void 0,!0,void 0,this),J&&G.length===0&&Z("p",{className:"text-body text-text-tertiary",children:["No skeletons in ",Z("span",{className:"font-mono",children:"tests/browser/"},void 0,!1,void 0,this)," yet. Author them with the ",Z("span",{className:"font-mono",children:"opice-plan"},void 0,!1,void 0,this)," ","skill, then ",Z("span",{className:"font-mono",children:"fabrika builder induce"},void 0,!1,void 0,this),"."]},void 0,!0,void 0,this),Z("div",{className:"grid grid-cols-2 gap-3",children:G.map((Y)=>Z("div",{className:"rounded-md border border-border-subtle bg-bg-surface p-4 transition-colors hover:border-border-hover",children:[Z("div",{className:"font-mono text-code text-text-primary",children:Y.file},void 0,!1,void 0,this),Z("div",{className:"mt-1 truncate text-body text-text-secondary",children:Y.name},void 0,!1,void 0,this),Z("div",{className:"mt-2 flex flex-wrap gap-x-3 gap-y-1 text-tiny text-text-tertiary",children:[Y.url&&Z("span",{className:"font-mono",children:Y.url},void 0,!1,void 0,this),Z("span",{children:[Y.steps," steps"]},void 0,!0,void 0,this),Z("span",{children:[Y.invariants," invariants"]},void 0,!0,void 0,this),Y.pending>0?Z("span",{className:"text-accent-amber",children:[Y.pending," pending"]},void 0,!0,void 0,this):Z("span",{className:"text-accent-green",children:"authored"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),(Y.seeds.length>0||Y.roles.length>0)&&Z("div",{className:"mt-2 flex flex-wrap gap-1",children:[Y.seeds.map((H)=>Z("span",{className:"rounded bg-bg-elevated px-1.5 py-0.5 text-tiny text-text-secondary",children:["seed:",H]},H,!0,void 0,this)),Y.roles.map((H)=>Z("span",{className:"rounded bg-bg-elevated px-1.5 py-0.5 text-tiny text-text-secondary",children:["role:",H]},H,!0,void 0,this))]},void 0,!0,void 0,this)]},Y.file,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function vQ({live:$}){let[J,Q]=s3([]);n3(()=>{if(!$)return;let W=V0.buildStream((G)=>Q((Y)=>[...Y.slice(-200),G]));return()=>W?.close()},[$]);let X={queued:"bg-text-tertiary",running:"bg-accent-blue",passed:"bg-accent-green",failed:"bg-accent-red",blocked:"bg-accent-amber",info:"bg-text-tertiary"};return Z("div",{className:"p-6",children:[Z("h2",{className:"mb-3 font-heading text-section text-text-primary",children:"Build"},void 0,!1,void 0,this),J.length===0?Z("p",{className:"text-body text-text-tertiary",children:["Waiting for build events. Run ",Z("span",{className:"font-mono",children:"fabrika builder build"},void 0,!1,void 0,this)," to drive the per-issue pipeline; each"," ",Z("span",{className:"font-mono",children:"build done/block"},void 0,!1,void 0,this)," posts here."]},void 0,!0,void 0,this):Z("ul",{className:"space-y-1.5 font-mono text-code",children:J.map((W,G)=>Z("li",{className:"flex items-center gap-2",children:[Z("span",{className:`inline-flex h-2 w-2 shrink-0 rounded-full ${X[W.status]}`},void 0,!1,void 0,this),W.issue&&Z("span",{className:"text-text-secondary",children:W.issue},void 0,!1,void 0,this),Z("span",{className:"text-text-tertiary",children:W.status},void 0,!1,void 0,this),W.message&&Z("span",{className:"truncate text-text-secondary",children:["— ",W.message]},void 0,!0,void 0,this)]},G,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function hQ({canvas:$}){return Z(a3,{children:$.files.map((J)=>Z("div",{className:"mb-8",children:[$.files.length>1&&Z("div",{className:"mb-2 text-tiny uppercase tracking-wide text-text-tertiary",children:J.label??J.filename},void 0,!1,void 0,this),Z(w$,{revision:$.revision,filename:J.filename},void 0,!1,void 0,this)]},J.filename,!0,void 0,this))},void 0,!1,void 0,this)}function t3({state:$,focused:J,canvas:Q,artifact:X,isCurrentGate:W,sessionId:G,live:Y}){let q=g2(J,$.completed,$.current)==="upcoming";return Z("section",{className:"flex h-full min-w-0 flex-col bg-bg-base",children:[Z(yQ,{state:$,focused:J,isCurrentGate:W},void 0,!1,void 0,this),Z("div",{id:"plan-scroll-container",className:"flex-1 overflow-y-auto",children:Q?Z("div",{className:"mx-auto max-w-3xl px-6 py-5",children:Z(hQ,{canvas:Q},void 0,!1,void 0,this)},void 0,!1,void 0,this):J==="skeletons"?Z(xQ,{sessionId:G,live:Y,upcoming:q},void 0,!1,void 0,this):J==="build"?Z(vQ,{live:Y},void 0,!1,void 0,this):Z("div",{className:"mx-auto max-w-3xl px-6 py-5",children:[q&&Z("p",{className:"mb-4 rounded-md border border-border-subtle bg-bg-surface px-3 py-2 text-tiny text-text-tertiary",children:"This phase hasn't started yet — it unlocks once the earlier gates are approved. Here's what it will produce:"},void 0,!1,void 0,this),Z(o3,{source:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function e3($){if(!$)return[];if($.canvasScope?.kind==="view"){let Q=$.canvasScope.filename;return $.canvasFiles.filter((X)=>X.filename===Q)}if($.canvasScope?.kind==="directory")return $.canvasFiles;let J=$.canvasFiles.filter((Q)=>!Q.diffStats||Q.diffStats.added!==0||Q.diffStats.removed!==0);return J.length>0?J:$.canvasFiles}var mQ=new Set([...G2,"design"]);function $J($,J){for(let Q=$.length-1;Q>=0;Q--){let X=$[Q]?.label;if(!X)continue;if(X===J||J==="build"&&!mQ.has(X))return $[Q]??null}return null}var JJ="fixture-session",d5={current:"skeletons",index:4,completed:["intake","vision","flows","tech"],reads:[".fabrika/architecture/flows/checkout.flow.md",".fabrika/architecture/flows/browse.flow.md"],produces:["tests/browser/*.test.ts"],gate:!0,satisfied:!1},QJ={id:"fixture-session",currentRevision:4,canvasFiles:[{filename:"review-grid.jsx",label:"Skeleton review"}],revisions:[{revision:1,label:"vision",canvasFiles:[{filename:"brief.jsx"}]},{revision:2,label:"flows",canvasFiles:[{filename:"flows-review.jsx"}]},{revision:3,label:"tech",canvasFiles:[{filename:"tech.jsx"}]},{revision:4,label:"skeletons",canvasFiles:[{filename:"review-grid.jsx"}]}],gate:"skeletons",label:"Opice skeletons"};var XJ={intake:`# Brief
73
+
74
+ A local-first storefront for a small roastery. Sells whole-bean coffee, supports a cart and checkout, and a lightweight admin to manage the catalog.
75
+
76
+ ## Users
77
+ - Shopper — browses, adds to cart, checks out.
78
+ - Owner — manages products and reviews orders.
79
+
80
+ ## Success
81
+ - A shopper can complete a purchase end-to-end.
82
+ - The owner can add a product without touching code.
83
+
84
+ ## Non-goals
85
+ - No multi-tenant. No payment provider integration in v1 (mock checkout).`,vision:`# Glossary
86
+
87
+ - **Product** — a single SKU with a price and inventory count.
88
+ - **Cart** — the shopper's pending selection, persisted locally.
89
+ - **Order** — a submitted cart, immutable once placed.
90
+
91
+ # Principles
92
+
93
+ - MUST keep the catalog readable without an account.
94
+ - MUST persist the cart across reloads.
95
+ - MUST NOT block checkout on network for the mock flow.
96
+ - PREFERENCE: optimistic UI on add-to-cart.`,flows:`# Flow: checkout
97
+
98
+ 1. Shopper opens \`/cart\`.
99
+ 2. Reviews line items, adjusts quantities.
100
+ 3. Submits → \`/order/confirmation\`.
101
+
102
+ # Flow: browse
103
+
104
+ 1. Shopper lands on \`/\`.
105
+ 2. Filters by roast level.
106
+ 3. Opens a product → adds to cart.`,tech:`# Tech
107
+
108
+ Stack: **zerops-app** (Bun + PostgreSQL + React/Buzola, Fabrika IAM behind the proxy).
109
+
110
+ - Routes: the contract's mounts and the SPA.
111
+ - Data layer: @fabrika/db over PostgreSQL + named SQL fixtures from skeleton metadata.
112
+ - Reasoning: the paved road the installation deploys.`,skeletons:"# Opice skeletons\n\nOne `*.test.ts` per flow, each a metadata-first `browserTest` with pending `step{intent,hint}` stubs and `invariant.todo` acceptances. Reviewed as a grid in the workspace.",issues:`# Issues (induced)
113
+
114
+ Deterministic compile step — issues induced from skeleton metadata.
115
+
116
+ - ISSUE-001 Foundation: routes + seed infra.
117
+ - ISSUE-004 Design checkpoint: theme the running app, reviewed at the design gate.
118
+ - ISSUE-101 Feature: cart + checkout vertical slice.`,build:`# Build
119
+
120
+ Per-issue assisted pipeline. The live-preview pane (right) will host the real running app (localhost:5173) once an issue is in flight.`};var uQ=q$.extend({generalNote:B.string(),annotations:B.array(d$.pick({id:!0,snippet:!0,note:!0,createdAt:!0}).passthrough()),responses:B.array(B.tuple([B.string(),Y$.innerType().pick({id:!0,type:!0,label:!0}).extend({type:B.string()}).passthrough()])),feedbackEntries:B.array(B.tuple([B.string(),G$.pick({id:!0,markdown:!0}).passthrough()])).optional()});function WJ($){let J=uQ.safeParse($);return J.success?s1(J.data):null}class m0 extends Error{}function cQ($=fetch){async function J(Q,X,W,G){let Y;try{Y=await $(r3(Q,X),{method:W?"POST":"GET",headers:{accept:"application/json",...W?{"content-type":"application/json"}:{}},...W?{body:JSON.stringify(W)}:{},redirect:"error",cache:"no-store",signal:G?AbortSignal.any([G,AbortSignal.timeout(1e4)]):AbortSignal.timeout(1e4)})}catch{throw new m0("Local builder unavailable. Check the daemon and refresh status.")}let H;try{H=await Y.json()}catch{throw new m0("Local builder returned an invalid response. Refresh status before continuing.")}if(!Y.ok){let q=E3.safeParse(H);if(q.success)throw new m0(q.data.error.message);throw new m0("Local builder rejected the request. Refresh status before continuing.")}try{let q=i3(H);if(q.sessionId!==Q)throw Error("Session mismatch");return q}catch{throw new m0("Local builder returned an invalid status. Refresh status before continuing.")}}return{status:(Q,X)=>J(Q,"platform",void 0,X),register:(Q,X)=>J(Q,"register",{projectRoot:X}),act:(Q,X,W)=>{let G={};try{if(X.kind==="connect")G={controlOrigin:H2(X.controlOrigin)};if(X.kind==="preview")G={url:X.url===null?null:E2(X.url)}}catch{throw new m0("Enter a valid URL without credentials. Control origins require HTTPS except on localhost.")}return J(Q,X.kind,G,W)}}}var y2=cQ();import{useEffect as YJ,useRef as pQ,useState as x2}from"react";function GJ($,J){let[Q,X]=x2($),[W,G]=x2(null),[Y,H]=x2(null),[q,U]=x2(!1),[N,M]=x2(0),L=pQ(null);YJ(()=>{return X($),G(null),H(null),U(!1),M(0),()=>{L.current?.abort(),L.current=null}},[$]),YJ(()=>{if(Q!==$||!J||q||Y)return;let _=new AbortController,w,S=0,O=async()=>{try{if(++S>1200)throw new m0("Automatic status refresh paused. Refresh status to continue.");let F=await y2.status($,_.signal);if(_.signal.aborted)return;G(F),H(null),w=setTimeout(O,3000)}catch(F){if(!_.signal.aborted)H(F instanceof m0?F.message:"Unable to read local deployment status.")}};return O(),()=>{_.abort(),clearTimeout(w)}},[$,Q,J,q,N,Y]);let K=Q===$,z=K&&J&&W!==null&&Y===null&&!q;return{data:K?W:null,error:K?Y:null,busy:K&&q,enabled:z,refresh:()=>{G(null),H(null),M((_)=>_+1)},act:async(_)=>{if(!z||L.current)return;let w=new AbortController;L.current=w,U(!0);try{let S=await y2.act($,_,w.signal);if(!w.signal.aborted)G(S)}catch(S){if(!w.signal.aborted)H(S instanceof m0?S.message:"Local operation failed. Refresh status.")}finally{if(L.current===w){if(L.current=null,!w.signal.aborted)U(!1)}}}}}import{jsxDEV as A0}from"react/jsx-dev-runtime";function lQ($){return $==="build"}var HJ={current:"intake",index:0,completed:[],reads:[],produces:[],gate:!1,satisfied:!1},dQ="_Nový projekt — zatím žádný krok. Otevři první gate z agenta._";function BJ(){let $=Z$()??JJ,[J,Q]=A1("connecting"),X=GJ($,J==="live"),[W,G]=A1(HJ),[Y,H]=A1(null),[q,U]=A1(!1),[N,M]=A1(HJ.current),[L,K]=A1(!1),z=r5(!1),_=r5(null),w=r5(void 0);qJ(()=>{let A=!1;return(async()=>{try{if(await V0.health(),A)return;let b=new URLSearchParams(location.search).get("root");if(b?.endsWith("/.fabrika"))await y2.register($,b.slice(0,-9));let p=await V0.meta($);if(A)return;if(p)H(p),w.current=p.projectRoot?`${p.projectRoot}/.fabrika`:void 0;let T=await V0.phase(w.current);if(A)return;if(T){if(G(T),!z.current)M(T.current)}Q("live")}catch{if(!A){if(Z$()){Q("offline");return}if(H(QJ),G(d5),!z.current)M(d5.current);Q("fixture")}}})(),()=>{A=!0}},[$]);let S=Y!==null&&(J==="live"||J==="offline");qJ(()=>{if(!S)return;let A=!1,b=null,p=()=>{V0.meta($).then((y)=>H(y)).catch(()=>{}),V0.phase(w.current).then((y)=>{if(G(y),!z.current)M(y.current)}).catch(()=>{})},T=()=>{let y=V0.openSocket($,(j)=>{if(j.type==="plan-updated"||j.type==="revision-updated")K(!1),p();else if(j.type==="watcher-status")U(j.watching);else if(j.type==="phase-updated")K(!1),p();else if(j.type==="submit-ack")K(!1),p()});_.current=y,y.onopen=()=>Q("live"),y.onclose=()=>{if(A)return;Q("offline"),b=setTimeout(T,2000)}};return T(),()=>{if(A=!0,b)clearTimeout(b);_.current?.close(),_.current=null}},[S,$]);let[O,F]=A1({type:"overview"}),g=(A)=>{z.current=!0,M(A)},I=(A,b)=>{let p=_.current;if(p&&V0.submitGate(p,A,b))K(!0)},h=J==="live",V=i5(()=>Y?$J(Y.revisions,N):null,[Y,N]),u=W.gateName??Y?.gate??null,E=h&&N===W.current&&!!u,c=i5(()=>{return e3(V)},[V]),Q0=h&&!!V&&c.length>0,$0=V?.revision??Y?.currentRevision??0,W0=Y?.currentRevision??0,_0=E&&!!V?.hasFeedback&&!V?.feedbackConsumed,J0=!E||E&&(L||_0),t=J==="fixture"?XJ[N]??"_No artifact for this phase yet._":dQ,G0=i5(()=>(Y?.revisions??[]).map((A)=>({revision:A.revision,label:A.label??void 0,canvasFiles:A.canvasFiles.map((b)=>({filename:b.filename})),createdAt:A.createdAt??new Date().toISOString(),hasFeedback:!!A.hasFeedback,feedbackConsumed:!!A.feedbackConsumed})),[Y]),a=lQ(N),B0=A0("div",{className:`grid min-h-0 flex-1 grid-rows-[minmax(0,1fr)] ${a?"grid-cols-[14rem_minmax(0,1fr)_22rem_auto]":"grid-cols-[14rem_minmax(0,1fr)_auto]"}`,children:[A0(P3,{state:W,focused:N,onFocus:g},void 0,!1,void 0,this),A0(t3,{state:W,focused:N,canvas:Q0?{revision:$0,files:c}:null,artifact:t,isCurrentGate:E,sessionId:$,live:h},void 0,!1,void 0,this),a&&A0(f3,{previewUrl:X.data?.previewUrl??null},void 0,!1,void 0,this),A0(w3,{gateName:u,hasGate:Q0,isCurrentGate:E,onSubmit:I},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return A0("div",{className:"flex h-screen w-screen flex-col overflow-hidden bg-bg-base text-text-primary",children:[A0(R3,{sessionId:$,status:J,watching:q},void 0,!1,void 0,this),A0(S3,{platform:X,live:h},void 0,!1,void 0,this),J==="offline"&&A0("p",{role:"alert",className:"px-6 py-2 text-body text-accent-amber",children:"Project unavailable. Check the local daemon, then reload this page."},void 0,!1,void 0,this),Q0?A0(T5.Provider,{value:$,children:A0($2.Provider,{value:{currentRevision:W0,selectedRevision:$0,revisions:G0,setSelectedRevision:()=>{},isReadOnly:J0,compareRevision:null,setCompareRevision:()=>{},agentWatching:q},children:A0(e1.Provider,{value:{activeView:O,setActiveView:F,openFiles:[],closeFile:()=>{},canvasFiles:c.map((A)=>A.filename)},children:A0(H$,{sessionId:$,revision:$0,isReadOnly:J0,draftPhase:"current",loadState:(A,b)=>V0.getResponses(A,b,WJ),saveState:(A,b,p)=>{V0.saveResponses(A,b,p)},children:B0},$0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this):B0]},void 0,!0,void 0,this)}import{jsxDEV as rQ}from"react/jsx-dev-runtime";var UJ=document.getElementById("root");if(UJ===null)throw Error("Builder dashboard root element is missing");iQ(UJ).render(rQ(BJ,{},void 0,!1,void 0,this));