shraga 0.1.7 → 0.1.8

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.
@@ -1936,5 +1936,5 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
1936
1936
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Fxe(e,t){if(e){if(typeof e=="string")return FR(e,t);var n={}.toString.call(e).slice(8,-1);return n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set"?Array.from(e):n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?FR(e,t):void 0}}function FR(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function Hxe(e,t){var n=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(n!=null){var r,i,a,s,c=[],u=!0,f=!1;try{if(a=(n=n.call(e)).next,t!==0)for(;!(u=(r=a.call(n)).done)&&(c.push(r.value),c.length!==t);u=!0);}catch(h){f=!0,i=h}finally{try{if(!u&&n.return!=null&&(s=n.return(),Object(s)!==s))return}finally{if(f)throw i}}return c}}function qxe(e){if(Array.isArray(e))return e}var Kxe=()=>(Bhe(),null);function mg(e){if(typeof e=="number")return e;if(typeof e=="string"){var t=parseFloat(e);if(!Number.isNaN(t))return t}return 0}var Gxe=b.forwardRef((e,t)=>{var n,r,i=b.useRef(null),a=b.useState({containerWidth:mg((n=e.style)===null||n===void 0?void 0:n.width),containerHeight:mg((r=e.style)===null||r===void 0?void 0:r.height)}),s=pg(a,2),c=s[0],u=s[1],f=b.useCallback((p,g)=>{u(v=>{var w=Math.round(p),y=Math.round(g);return v.containerWidth===w&&v.containerHeight===y?v:{containerWidth:w,containerHeight:y}})},[]),h=b.useCallback(p=>{if(typeof t=="function"&&t(p),i.current!=null&&(i.current.disconnect(),i.current=null),p!=null&&typeof ResizeObserver<"u"){var g=p.getBoundingClientRect(),v=g.width,w=g.height;f(v,w);var y=k=>{var O=k[0];if(O!=null){var A=O.contentRect,C=A.width,I=A.height;f(C,I)}},E=new ResizeObserver(y);E.observe(p),i.current=E}},[t,f]);return b.useEffect(()=>()=>{var p=i.current;p!=null&&p.disconnect()},[f]),b.createElement(b.Fragment,null,b.createElement(Cd,{width:c.containerWidth,height:c.containerHeight}),b.createElement("div",Jo({ref:h},e)))}),Vxe=b.forwardRef((e,t)=>{var n=e.width,r=e.height,i=b.useState({containerWidth:mg(n),containerHeight:mg(r)}),a=pg(i,2),s=a[0],c=a[1],u=b.useCallback((h,p)=>{c(g=>{var v=Math.round(h),w=Math.round(p);return g.containerWidth===v&&g.containerHeight===w?g:{containerWidth:v,containerHeight:w}})},[]),f=b.useCallback(h=>{if(typeof t=="function"&&t(h),h!=null){var p=h.getBoundingClientRect(),g=p.width,v=p.height;u(g,v)}},[t,u]);return b.createElement(b.Fragment,null,b.createElement(Cd,{width:s.containerWidth,height:s.containerHeight}),b.createElement("div",Jo({ref:f},e)))}),Wxe=b.forwardRef((e,t)=>{var n=e.width,r=e.height;return b.createElement(b.Fragment,null,b.createElement(Cd,{width:n,height:r}),b.createElement("div",Jo({ref:t},e)))}),Yxe=b.forwardRef((e,t)=>{var n=e.width,r=e.height;return typeof n=="string"||typeof r=="string"?b.createElement(Vxe,Jo({},e,{ref:t})):typeof n=="number"&&typeof r=="number"?b.createElement(Wxe,Jo({},e,{width:n,height:r,ref:t})):b.createElement(b.Fragment,null,b.createElement(Cd,{width:n,height:r}),b.createElement("div",Jo({ref:t},e)))});function Xxe(e){return e?Gxe:Yxe}var Zxe=b.forwardRef((e,t)=>{var n=e.children,r=e.className,i=e.height,a=e.onClick,s=e.onContextMenu,c=e.onDoubleClick,u=e.onMouseDown,f=e.onMouseEnter,h=e.onMouseLeave,p=e.onMouseMove,g=e.onMouseUp,v=e.onTouchEnd,w=e.onTouchMove,y=e.onTouchStart,E=e.style,k=e.width,O=e.responsive,A=e.dispatchTouchEvents,C=A===void 0?!0:A,I=b.useRef(null),T=jt(),D=b.useState(null),P=pg(D,2),j=P[0],M=P[1],B=b.useState(null),R=pg(B,2),H=R[0],Y=R[1],K=jxe(),U=z1(),G=(U==null?void 0:U.width)>0?U.width:k,q=(U==null?void 0:U.height)>0?U.height:i,ee=b.useCallback(Oe=>{K(Oe),typeof t=="function"&&t(Oe),M(Oe),Y(Oe),Oe!=null&&(I.current=Oe)},[K,t,M,Y]),L=b.useCallback(Oe=>{T(GU(Oe)),T(di({handler:a,reactEvent:Oe}))},[T,a]),F=b.useCallback(Oe=>{T(vw(Oe)),T(di({handler:f,reactEvent:Oe}))},[T,f]),J=b.useCallback(Oe=>{T(SB()),T(di({handler:h,reactEvent:Oe}))},[T,h]),$=b.useCallback(Oe=>{T(vw(Oe)),T(di({handler:p,reactEvent:Oe}))},[T,p]),de=b.useCallback(()=>{T(QU())},[T]),xe=b.useCallback(()=>{T(JU())},[T]),ve=b.useCallback(Oe=>{T(ZU(Oe.key))},[T]),Me=b.useCallback(Oe=>{T(di({handler:s,reactEvent:Oe}))},[T,s]),Qe=b.useCallback(Oe=>{T(di({handler:c,reactEvent:Oe}))},[T,c]),fe=b.useCallback(Oe=>{T(di({handler:u,reactEvent:Oe}))},[T,u]),Te=b.useCallback(Oe=>{T(di({handler:g,reactEvent:Oe}))},[T,g]),we=b.useCallback(Oe=>{T(di({handler:y,reactEvent:Oe}))},[T,y]),ue=b.useCallback(Oe=>{C&&T(n4(Oe)),T(di({handler:w,reactEvent:Oe}))},[T,C,w]),St=b.useCallback(Oe=>{T(di({handler:v,reactEvent:Oe}))},[T,v]),Ve=Xxe(O);return b.createElement(KB.Provider,{value:j},b.createElement(Vj.Provider,{value:H},b.createElement(Ve,{width:G??(E==null?void 0:E.width),height:q??(E==null?void 0:E.height),className:vt("recharts-wrapper",r),style:Lxe({position:"relative",cursor:"default",width:G,height:q},E),onClick:L,onContextMenu:Me,onDoubleClick:Qe,onFocus:de,onBlur:xe,onKeyDown:ve,onMouseDown:fe,onMouseEnter:F,onMouseLeave:J,onMouseMove:$,onMouseUp:Te,onTouchEnd:St,onTouchMove:ue,onTouchStart:we,ref:ee},b.createElement(Kxe,null),n)))}),Qxe=["width","height","responsive","children","className","style","compact","title","desc"];function Jxe(e,t){if(e==null)return{};var n,r,i=ewe(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function ewe(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var c4=b.forwardRef((e,t)=>{var n=e.width,r=e.height,i=e.responsive,a=e.children,s=e.className,c=e.style,u=e.compact,f=e.title,h=e.desc,p=Jxe(e,Qxe),g=Xr(p);return u?b.createElement(b.Fragment,null,b.createElement(Cd,{width:n,height:r}),b.createElement(BR,{otherAttributes:g,title:f,desc:h},a)):b.createElement(Zxe,{className:s,style:c,width:n,height:r,responsive:i??!1,onClick:e.onClick,onMouseLeave:e.onMouseLeave,onMouseEnter:e.onMouseEnter,onMouseMove:e.onMouseMove,onMouseDown:e.onMouseDown,onMouseUp:e.onMouseUp,onContextMenu:e.onContextMenu,onDoubleClick:e.onDoubleClick,onTouchStart:e.onTouchStart,onTouchMove:e.onTouchMove,onTouchEnd:e.onTouchEnd},b.createElement(BR,{otherAttributes:g,title:f,desc:h,ref:t},b.createElement(Vve,null,a)))});function yw(){return yw=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},yw.apply(null,arguments)}function HR(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),n.push.apply(n,r)}return n}function twe(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?HR(Object(n),!0).forEach(function(r){nwe(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):HR(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function nwe(e,t,n){return(t=rwe(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function rwe(e){var t=iwe(e,"string");return typeof t=="symbol"?t:t+""}function iwe(e,t){if(typeof e!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}var awe={top:5,right:5,bottom:5,left:5},owe=twe({accessibilityLayer:!0,barCategoryGap:"10%",barGap:4,layout:"horizontal",margin:awe,responsive:!1,reverseStackOrder:!1,stackOffset:"none",syncMethod:"index"},CS),u4=b.forwardRef(function(t,n){var r,i=Rn(t.categoricalChartProps,owe),a=t.chartName,s=t.defaultTooltipEventType,c=t.validateTooltipEventTypes,u=t.tooltipPayloadSearcher,f=t.categoricalChartProps,h={chartName:a,defaultTooltipEventType:s,validateTooltipEventTypes:c,tooltipPayloadSearcher:u,eventEmitter:void 0};return b.createElement(a4,{preloadedState:{options:h},reduxStoreName:(r=f.id)!==null&&r!==void 0?r:a},b.createElement(_U,{chartData:f.data}),b.createElement(o4,{layout:i.layout,margin:i.margin}),b.createElement(l4,{throttleDelay:i.throttleDelay,throttledEvents:i.throttledEvents}),b.createElement(s4,{baseValue:i.baseValue,accessibilityLayer:i.accessibilityLayer,barCategoryGap:i.barCategoryGap,maxBarSize:i.maxBarSize,stackOffset:i.stackOffset,barGap:i.barGap,barSize:i.barSize,syncId:i.syncId,syncMethod:i.syncMethod,className:i.className,reverseStackOrder:i.reverseStackOrder}),b.createElement(c4,yw({},i,{ref:n})))}),swe=["axis"],lwe=b.forwardRef((e,t)=>b.createElement(u4,{chartName:"LineChart",defaultTooltipEventType:"axis",validateTooltipEventTypes:swe,tooltipPayloadSearcher:eS,categoricalChartProps:e,ref:t})),cwe=["axis","item"],uwe=b.forwardRef((e,t)=>b.createElement(u4,{chartName:"BarChart",defaultTooltipEventType:"axis",validateTooltipEventTypes:cwe,tooltipPayloadSearcher:eS,categoricalChartProps:e,ref:t}));function fwe(e){var t=jt();return b.useEffect(()=>{t(mxe(e))},[t,e]),null}var dwe=["layout"];function bw(){return bw=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},bw.apply(null,arguments)}function hwe(e,t){if(e==null)return{};var n,r,i=pwe(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function pwe(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function qR(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),n.push.apply(n,r)}return n}function mwe(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?qR(Object(n),!0).forEach(function(r){gwe(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):qR(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function gwe(e,t,n){return(t=vwe(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function vwe(e){var t=ywe(e,"string");return typeof t=="symbol"?t:t+""}function ywe(e,t){if(typeof e!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}var bwe={top:5,right:5,bottom:5,left:5},f4=mwe({accessibilityLayer:!0,stackOffset:"none",barCategoryGap:"10%",barGap:4,margin:bwe,reverseStackOrder:!1,syncMethod:"index",layout:"radial",responsive:!1,cx:"50%",cy:"50%",innerRadius:0,outerRadius:"80%"},CS),xwe=b.forwardRef(function(t,n){var r,i=Rn(t.categoricalChartProps,f4),a=i.layout,s=hwe(i,dwe),c=t.chartName,u=t.defaultTooltipEventType,f=t.validateTooltipEventTypes,h=t.tooltipPayloadSearcher,p={chartName:c,defaultTooltipEventType:u,validateTooltipEventTypes:f,tooltipPayloadSearcher:h,eventEmitter:void 0};return b.createElement(a4,{preloadedState:{options:p},reduxStoreName:(r=i.id)!==null&&r!==void 0?r:c},b.createElement(_U,{chartData:i.data}),b.createElement(o4,{layout:a,margin:i.margin}),b.createElement(l4,{throttleDelay:i.throttleDelay,throttledEvents:i.throttledEvents}),b.createElement(s4,{baseValue:void 0,accessibilityLayer:i.accessibilityLayer,barCategoryGap:i.barCategoryGap,maxBarSize:i.maxBarSize,stackOffset:i.stackOffset,barGap:i.barGap,barSize:i.barSize,syncId:i.syncId,syncMethod:i.syncMethod,className:i.className,reverseStackOrder:i.reverseStackOrder}),b.createElement(fwe,{cx:i.cx,cy:i.cy,startAngle:i.startAngle,endAngle:i.endAngle,innerRadius:i.innerRadius,outerRadius:i.outerRadius}),b.createElement(c4,bw({},s,{ref:n})))});function KR(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),n.push.apply(n,r)}return n}function GR(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?KR(Object(n),!0).forEach(function(r){wwe(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):KR(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function wwe(e,t,n){return(t=Ewe(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Ewe(e){var t=Swe(e,"string");return typeof t=="symbol"?t:t+""}function Swe(e,t){if(typeof e!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}var _we=["item"],kwe=GR(GR({},f4),{},{layout:"centric",startAngle:0,endAngle:360}),Awe=b.forwardRef((e,t)=>{var n=Rn(e,kwe);return b.createElement(xwe,{chartName:"PieChart",defaultTooltipEventType:"item",validateTooltipEventTypes:_we,tooltipPayloadSearcher:eS,categoricalChartProps:n,ref:t})});const wc=["#6366f1","#f59e0b","#10b981","#ef4444","#8b5cf6","#ec4899","#14b8a6","#f97316"];function Owe(e){const t=e.trim();if(!t.startsWith("{")&&!t.startsWith("["))return null;try{return JSON.parse(t)}catch{return null}}function Twe(e){var s;const t=((s=e.data)==null?void 0:s.values)??e.values??e.series;if(!t||typeof t!="object")return null;const n=t,r=Object.keys(n);if(r.length===0)return null;const i=n[r[0]];return!i||typeof i!="object"?null:Object.keys(i).map(c=>{var f;const u={label:c};for(const h of r)u[h]=((f=n[h])==null?void 0:f[c])??0;return u})}function Cwe(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;const t=e;return"file"in t&&"sizeBytes"in t}function Nwe(e){if(Cwe(e))return null;if(Array.isArray(e))return e.length===0?null:typeof e[0]=="object"&&e[0]!==null?e:null;if(typeof e=="object"&&e!==null){const t=Twe(e);if(t)return t}return null}function Iwe(e,t,n){return n.length===0?"table":n.length===1&&e.length<=8?"pie":e.map(a=>String(a[t]??"")).some(a=>/^\d{4}-\d{2}/.test(a))||e.length>20?"line":"bar"}function Mwe(e){const t=[...new Set(e.flatMap(Object.keys))],n=[];let r="";for(const i of t){const a=e.map(c=>c[i]).filter(c=>c!=null);a.filter(c=>typeof c=="number").length>a.length*.5?n.push(i):r||(r=i)}return r||(r=t[0]??"label"),{labelKey:r,numericKeys:n}}function Rwe({data:e}){const{rows:t,labelKey:n,numericKeys:r,chartType:i}=b.useMemo(()=>{const a=Nwe(e);if(!a||a.length===0)return{rows:null,labelKey:"",numericKeys:[],chartType:"table"};const{labelKey:s,numericKeys:c}=Mwe(a),u=Iwe(a,s,c);return{rows:a,labelKey:s,numericKeys:c,chartType:u}},[e]);return t?i==="table"?_.jsx(VR,{rows:t}):_.jsxs("div",{className:"space-y-2",children:[_.jsx("div",{className:"h-64 w-full",children:_.jsx(qie,{width:"100%",height:"100%",children:i==="pie"?_.jsxs(Awe,{children:[_.jsx(wU,{data:t,dataKey:r[0],nameKey:n,cx:"50%",cy:"50%",outerRadius:80,label:!0,children:t.map((a,s)=>_.jsx(Kd,{fill:wc[s%wc.length]},s))}),_.jsx(U0,{}),_.jsx(em,{})]}):i==="line"?_.jsxs(lwe,{data:t,children:[_.jsx(lw,{strokeDasharray:"3 3",className:"opacity-30"}),_.jsx(hw,{dataKey:n,tick:{fontSize:11}}),_.jsx(gw,{tick:{fontSize:11}}),_.jsx(U0,{}),r.length>1&&_.jsx(em,{}),r.map((a,s)=>_.jsx(BU,{type:"monotone",dataKey:a,stroke:wc[s%wc.length],strokeWidth:2,dot:!1},a))]}):_.jsxs(uwe,{data:t,children:[_.jsx(lw,{strokeDasharray:"3 3",className:"opacity-30"}),_.jsx(hw,{dataKey:n,tick:{fontSize:11}}),_.jsx(gw,{tick:{fontSize:11}}),_.jsx(U0,{}),r.length>1&&_.jsx(em,{}),r.map((a,s)=>_.jsx(qU,{dataKey:a,fill:wc[s%wc.length],radius:[3,3,0,0]},a))]})})}),_.jsx(VR,{rows:t})]}):_.jsx("pre",{className:"text-xs whitespace-pre-wrap break-words",children:JSON.stringify(e,null,2)})}function VR({rows:e}){const t=[...new Set(e.flatMap(Object.keys))];return _.jsx("div",{className:"overflow-auto max-h-96 rounded border text-xs",children:_.jsxs("table",{className:"w-full text-left",children:[_.jsx("thead",{className:"bg-muted sticky top-0",children:_.jsx("tr",{children:t.map(n=>_.jsx("th",{className:"px-2 py-1 font-medium",children:n},n))})}),_.jsx("tbody",{children:e.map((n,r)=>_.jsx("tr",{className:"border-t",children:t.map(i=>{const a=n[i],s=a==null?"":typeof a=="object"?JSON.stringify(a,null,2):String(a);return _.jsx("td",{className:"px-2 py-1 max-w-[400px] whitespace-pre-wrap break-words align-top",title:s,children:s},i)})},r))})]})})}const xw=/^\/uploads\//;function NS({src:e,alt:t,className:n,onClick:r}){const{getToken:i}=Lw(),[a,s]=b.useState(xw.test(e)?null:e);return b.useEffect(()=>{if(!xw.test(e)){s(e);return}let c=null,u=!1;return s(null),(async()=>{try{const f=await i(),h=await fetch(e,{headers:f?{Authorization:`Bearer ${f}`}:{}});if(!h.ok)throw new Error(`${h.status} ${h.statusText}`);c=URL.createObjectURL(await h.blob()),u?URL.revokeObjectURL(c):s(c)}catch(f){console.error("[authed-image] load failed:",e,f)}})(),()=>{u=!0,c&&URL.revokeObjectURL(c)}},[e,i]),a?_.jsx("img",{src:a,alt:t??"",className:n,onClick:()=>r==null?void 0:r(a)}):_.jsx("div",{className:n,"aria-busy":"true"})}function Dwe({src:e,name:t,className:n}){const{getToken:r}=Lw(),i=async a=>{if(xw.test(e)){a.preventDefault();try{const s=await r(),c=await fetch(e,{headers:s?{Authorization:`Bearer ${s}`}:{}});if(!c.ok)throw new Error(`${c.status} ${c.statusText}`);const u=URL.createObjectURL(await c.blob()),f=document.createElement("a");f.href=u,f.download=t,f.click(),setTimeout(()=>URL.revokeObjectURL(u),1e4)}catch(s){console.error("[authed-file] open failed:",e,s)}}};return _.jsxs("a",{href:e,onClick:i,target:"_blank",rel:"noopener noreferrer",className:n,children:[_.jsx(Uw,{className:"w-4 h-4 shrink-0"}),_.jsx("span",{className:"truncate max-w-[200px]",children:t})]})}const ww=1,d4=10,jf={scale:1,tx:0,ty:0},WR=e=>Math.min(d4,Math.max(ww,e));function Pwe({src:e,alt:t=""}){const n=b.useRef(null),r=b.useRef(null),[i,a]=b.useState(jf),[s,c]=b.useState(!1),u=(k,O)=>{var C;const A=(C=n.current)==null?void 0:C.getBoundingClientRect();return A?{cx:k-A.left-A.width/2,cy:O-A.top-A.height/2}:{cx:0,cy:0}},f=b.useCallback((k,O,A)=>{a(C=>{const I=WR(k);if(I===C.scale)return C;if(I<=ww)return jf;const T=I/C.scale;return{scale:I,tx:O-T*(O-C.tx),ty:A-T*(A-C.ty)}})},[]),h=k=>{k.preventDefault();const{cx:O,cy:A}=u(k.clientX,k.clientY),C=k.deltaY<0?1.15:1/1.15;a(I=>{const T=WR(I.scale*C);if(T===I.scale)return I;if(T<=ww)return jf;const D=T/I.scale;return{scale:T,tx:O-D*(O-I.tx),ty:A-D*(A-I.ty)}})},p=k=>{i.scale<=1||(k.currentTarget.setPointerCapture(k.pointerId),r.current={x:k.clientX,y:k.clientY,tx:i.tx,ty:i.ty},c(!0))},g=k=>{const O=r.current;O&&a(A=>({...A,tx:O.tx+(k.clientX-O.x),ty:O.ty+(k.clientY-O.y)}))},v=()=>{r.current=null,c(!1)},w=k=>{const{cx:O,cy:A}=u(k.clientX,k.clientY);i.scale>1?a(jf):f(2.5,O,A)},y=k=>f(i.scale*k,0,0),E=i.scale>1;return _.jsxs("div",{className:"relative w-full h-full flex items-center justify-center",children:[_.jsx("div",{ref:n,className:"w-full h-full overflow-hidden flex items-center justify-center",onWheel:h,onPointerDown:p,onPointerMove:g,onPointerUp:v,onPointerCancel:v,onDoubleClick:w,style:{cursor:E?s?"grabbing":"grab":"zoom-in",touchAction:"none"},children:_.jsx("img",{src:e,alt:t,draggable:!1,className:"max-w-full max-h-[85vh] object-contain rounded-lg select-none",style:{transform:`translate(${i.tx}px, ${i.ty}px) scale(${i.scale})`,transition:s?"none":"transform 0.08s ease-out",transformOrigin:"center center"}})}),_.jsxs("div",{className:"absolute bottom-3 left-1/2 -translate-x-1/2 flex items-center gap-1 rounded-full bg-background/90 border shadow-sm px-1.5 py-1 backdrop-blur",children:[_.jsx("button",{type:"button",onClick:()=>y(1/1.4),title:"Zoom out",className:"p-1.5 rounded-full hover:bg-muted transition-colors disabled:opacity-40",disabled:!E,children:_.jsx(L7,{className:"w-4 h-4"})}),_.jsxs("span",{className:"text-xs tabular-nums w-11 text-center text-muted-foreground select-none",children:[Math.round(i.scale*100),"%"]}),_.jsx("button",{type:"button",onClick:()=>y(1.4),title:"Zoom in",className:"p-1.5 rounded-full hover:bg-muted transition-colors disabled:opacity-40",disabled:i.scale>=d4,children:_.jsx(j7,{className:"w-4 h-4"})}),_.jsx("button",{type:"button",onClick:()=>a(jf),title:"Reset",className:"p-1.5 rounded-full hover:bg-muted transition-colors disabled:opacity-40",disabled:!E,children:_.jsx($w,{className:"w-4 h-4"})})]})]})}const jwe=new Set(["p","li","h1","h2","h3","h4","h5","h6","blockquote","td","th"]),Lwe=()=>e=>{const t=n=>{for(const r of n.children??[])r.type==="element"&&(jwe.has(r.tagName)&&(r.properties??(r.properties={}),r.properties.dir="auto"),t(r))};t(e)};var fD,dD;const zwe=typeof window<"u"&&!!((dD=(fD=window.webkit)==null?void 0:fD.messageHandlers)!=null&&dD.appwrap);function Bwe({text:e,onImageClick:t}){const n=e.replace(/\[Image #\d+\]\s*/g,"").trim();return zwe?_.jsx("div",{className:"prose prose-sm max-w-none dark:prose-invert break-words min-w-0 whitespace-pre-wrap",children:n}):_.jsx(_P,{remarkPlugins:[WP],rehypePlugins:[gj,Lwe],className:"prose prose-sm max-w-none dark:prose-invert prose-pre:bg-muted prose-pre:border prose-code:before:content-none prose-code:after:content-none break-words min-w-0",components:{pre:({children:r,...i})=>_.jsx(Jwe,{...i,children:r}),a:({href:r,children:i})=>_.jsx("a",{href:r,target:"_blank",rel:"noopener noreferrer",children:i}),img:({src:r,alt:i})=>_.jsx(NS,{src:r??"",alt:i??"",className:"max-h-[80vh] max-w-full rounded-xl border object-contain cursor-pointer hover:opacity-80 transition-opacity",onClick:a=>t==null?void 0:t(a)})},children:n})}function YR(e){const t=new Date(e),n=new Date,r=t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});if(t.toDateString()===n.toDateString())return r;const i=t.getFullYear()===n.getFullYear();return`${t.toLocaleDateString([],{month:"short",day:"numeric",...!i&&{year:"numeric"}})}, ${r}`}const XR="shraga:showDetails";function Uwe({messages:e,busy:t,connectionStatus:n,onPermissionRespond:r,onQuestionRespond:i,onReplay:a,onEdit:s,onFork:c,multiParticipant:u,statusItems:f}){var I;const h=ua(),p=b.useRef(null),g=b.useRef(null),v=b.useRef(!0),[w,y]=b.useState(()=>localStorage.getItem(XR)==="true"),[E,k]=b.useState(null),O=()=>{const T=g.current;T&&(v.current=T.scrollHeight-T.scrollTop-T.clientHeight<80)},A=b.useMemo(()=>Gwe(e),[e]);if(b.useEffect(()=>{var T;v.current&&((T=p.current)==null||T.scrollIntoView({behavior:"smooth"}))},[e,t]),e.length===0&&!t)return _.jsx("div",{className:"flex-1 flex items-center justify-center",children:_.jsxs("div",{className:"text-center space-y-3 max-w-md px-4",children:[_.jsx("div",{className:"mx-auto w-12 h-12 rounded-full bg-muted flex items-center justify-center",children:_.jsx(Dc,{className:"w-6 h-6 text-muted-foreground"})}),_.jsx("h2",{className:"text-lg font-medium",children:"How can I help?"}),_.jsx("p",{className:"text-sm text-muted-foreground",children:"I can read files, edit code, run commands, search the web, and use any configured MCP tools on the remote machine."})]})});const C=()=>{y(T=>(localStorage.setItem(XR,String(!T)),!T))};return _.jsxs("div",{ref:g,onScroll:O,className:"flex-1 overflow-y-auto overflow-x-hidden",children:[_.jsxs("div",{className:"max-w-3xl mx-auto px-2 sm:px-4 py-4 sm:py-6 space-y-1",children:[_.jsx("div",{className:"flex justify-end mb-2",children:_.jsxs("button",{onClick:C,className:"flex items-center gap-1.5 px-2 py-1 rounded-md text-xs text-muted-foreground hover:text-foreground hover:bg-muted transition-colors",title:w?"Hide tool details":"Show tool details",children:[w?_.jsx(g7,{className:"w-3.5 h-3.5"}):_.jsx(m7,{className:"w-3.5 h-3.5"}),"Details"]})}),e.map((T,D)=>_.jsx($we,{message:T,messageIndex:D,isLast:D===e.length-1,showDetails:w,onPermissionRespond:r,onQuestionRespond:i,onReplay:a,onEdit:s,onFork:c,onImageClick:k,busy:t&&D===e.length-1,screenMap:A,multiParticipant:u},T.id)),t&&((I=e[e.length-1])==null?void 0:I.role)!=="assistant"&&_.jsxs("div",{className:"flex gap-3 py-4",children:[_.jsx("div",{className:"w-7 h-7 rounded-full bg-muted flex items-center justify-center shrink-0 mt-0.5",children:_.jsx(Dc,{className:"w-4 h-4 text-muted-foreground"})}),_.jsx("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:_.jsxs("span",{className:"inline-flex gap-1",children:[_.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-muted-foreground animate-bounce",style:{animationDelay:"0ms"}}),_.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-muted-foreground animate-bounce",style:{animationDelay:"150ms"}}),_.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-muted-foreground animate-bounce",style:{animationDelay:"300ms"}})]})})]}),!!(f!=null&&f.length)&&h.statusChips&&_.jsxs("div",{className:"flex gap-3 py-2",children:[_.jsx("div",{className:"w-7 h-7 rounded-full bg-muted flex items-center justify-center shrink-0 mt-0.5",children:_.jsx(Dc,{className:"w-4 h-4 text-muted-foreground"})}),_.jsx("div",{className:"flex-1 min-w-0 pt-1",children:h.statusChips(f)})]}),n&&n!=="update_available"&&_.jsx("div",{className:Ze("text-center text-xs py-1.5 rounded-md transition-opacity",n==="reconnected"?"text-green-600 dark:text-green-400":"text-amber-600 dark:text-amber-400"),children:n==="server_restarting"?"Server updating — reconnecting automatically…":n==="disconnected"?"Connection lost — reconnecting...":"Reconnected."}),_.jsx("div",{ref:p})]}),_.jsx(sl,{open:!!E,onOpenChange:T=>{T||k(null)},children:_.jsx(es,{className:"max-w-[90vw] max-h-[90vh] w-[90vw] h-[90vh] p-2 flex items-center justify-center bg-background/95",children:E&&_.jsx(Pwe,{src:E})})})]})}function $we({message:e,messageIndex:t,isLast:n,showDetails:r,onPermissionRespond:i,onQuestionRespond:a,onReplay:s,onEdit:c,onFork:u,onImageClick:f,busy:h,screenMap:p,multiParticipant:g}){var M;const v=e.blocks.find(B=>B.type==="compact_marker");if(v&&v.type==="compact_marker")return _.jsx(Fwe,{summary:v.summary,compactedCount:v.compactedCount});const w=e.role==="user",y=w?((M=e.blocks.find(B=>B.type==="text"))==null?void 0:M.text)??"":"",E=w?e.blocks.filter(B=>B.type==="image"||B.type==="file").map(B=>B.type==="image"?{url:B.src,name:B.src.split("/").pop()??"image",mimeType:"image/png",path:B.src}:{url:B.src,name:B.name,mimeType:B.mimeType,path:B.src}):void 0,[k,O]=b.useState(!1),[A,C]=b.useState(""),[I,T]=b.useState(!1),D=b.useRef(null),P=()=>{C(y),O(!0),setTimeout(()=>{const B=D.current;B&&(B.style.height="auto",B.style.height=B.scrollHeight+"px",B.focus(),B.setSelectionRange(B.value.length,B.value.length))},0)},j=()=>{const B=A.trim();B&&(O(!1),c==null||c(e.id,B,E!=null&&E.length?E:void 0))};return _.jsxs("div",{className:Ze("flex gap-3 py-4 group/row",w&&"flex-row-reverse"),onTouchStart:B=>{B.target.closest("button")||T(R=>!R)},children:[!w&&_.jsx("div",{className:"w-7 h-7 rounded-full bg-primary/10 flex items-center justify-center shrink-0 mt-0.5",children:_.jsx(Dc,{className:"w-4 h-4 text-primary"})}),w&&_.jsx("div",{className:"w-7 h-7 rounded-full bg-muted flex items-center justify-center shrink-0 mt-0.5",children:_.jsx(D7,{className:"w-4 h-4 text-muted-foreground"})}),_.jsxs("div",{className:Ze("min-w-0 max-w-[92%] sm:max-w-[85%] space-y-2"),children:[g&&w&&e.senderName&&_.jsx("div",{className:"text-[11px] font-medium text-muted-foreground text-right px-1",children:e.senderName}),k?_.jsxs("div",{className:"inline-block text-left w-full",children:[_.jsx("textarea",{ref:D,value:A,onChange:B=>{C(B.target.value),B.target.style.height="auto",B.target.style.height=B.target.scrollHeight+"px"},onKeyDown:B=>{B.key==="Enter"&&!B.shiftKey&&(B.preventDefault(),j()),B.key==="Escape"&&O(!1)},className:"w-full rounded-xl border bg-muted/50 px-4 py-2.5 text-sm resize-none outline-none focus:ring-1 focus:ring-primary min-h-[40px]"}),_.jsxs("div",{className:"flex gap-1 justify-end mt-1",children:[_.jsx("button",{onClick:()=>O(!1),className:"p-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted transition-colors",title:"Cancel",children:_.jsx(al,{className:"w-3.5 h-3.5"})}),_.jsx("button",{onClick:j,className:"p-1 rounded-md text-primary hover:bg-primary/10 transition-colors",title:"Send",children:_.jsx(dm,{className:"w-3.5 h-3.5"})})]})]}):_.jsxs(_.Fragment,{children:[e.blocks.filter(B=>r?!0:B.type==="tool_use"&&B.tool==="AskUserQuestion"?e.blocks.some(R=>R.type==="tool_result"&&R.toolUseId===B.toolUseId):B.type!=="tool_use"&&B.type!=="tool_result"&&B.type!=="thinking").filter(B=>B.type!=="tool_result"?!0:!e.blocks.some(R=>R.type==="tool_use"&&R.toolUseId===B.toolUseId)).map((B,R,H)=>{const Y=B.type==="tool_use"?e.blocks.find(K=>K.type==="tool_result"&&K.toolUseId===B.toolUseId):void 0;return _.jsx(Hwe,{block:B,isUser:w,onPermissionRespond:i,onQuestionRespond:a,pairedResult:Y,onImageClick:f,busy:h,screenMap:p},R)}),w&&y&&_.jsxs("div",{className:Ze("flex gap-1 items-center justify-end transition-opacity",I?"opacity-100":"opacity-0 group-hover/row:opacity-100"),children:[e.ts&&_.jsx("span",{className:"text-[10px] text-muted-foreground/50 select-none mr-1",children:YR(e.ts)}),_.jsx("button",{onClick:()=>s==null?void 0:s(e.id,y,E!=null&&E.length?E:void 0),className:"p-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted transition-colors",title:"Replay",children:_.jsx(C7,{className:"w-3.5 h-3.5"})}),_.jsx("button",{onClick:P,className:"p-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted transition-colors",title:"Edit & resend",children:_.jsx(Hw,{className:"w-3.5 h-3.5"})})]}),!w&&!(h&&n)&&_.jsxs("div",{className:Ze("flex gap-1 items-center transition-opacity",I?"opacity-100":"opacity-0 group-hover/row:opacity-100"),children:[e.ts&&_.jsx("span",{className:"text-[10px] text-muted-foreground/40 select-none mr-1",children:YR(e.ts)}),_.jsx("button",{onClick:()=>u==null?void 0:u(t),className:"p-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted transition-colors",title:"Fork from here",children:_.jsx(w2,{className:"w-3.5 h-3.5"})})]})]})]})]})}function Fwe({summary:e,compactedCount:t}){const[n,r]=b.useState(!1);return _.jsxs("div",{className:"py-3",children:[_.jsxs("div",{className:"flex items-center gap-3",children:[_.jsx("div",{className:"flex-1 border-t border-amber-500/30"}),_.jsxs("button",{onClick:()=>r(!n),className:"flex items-center gap-1.5 px-3 py-1 rounded-full text-xs font-medium bg-amber-500/10 text-amber-600 dark:text-amber-400 border border-amber-500/20 hover:bg-amber-500/20 transition-colors",children:[_.jsx(Fw,{className:"w-3 h-3"}),"Compacted · ",t," messages",_.jsx(vl,{className:Ze("w-3 h-3 transition-transform",n&&"rotate-90")})]}),_.jsx("div",{className:"flex-1 border-t border-amber-500/30"})]}),n&&_.jsx("div",{className:"mt-2 mx-auto max-w-2xl px-4 py-3 rounded-lg border border-amber-500/20 bg-amber-500/5 text-xs text-muted-foreground whitespace-pre-wrap",children:e})]})}function Hwe({block:e,isUser:t,onPermissionRespond:n,onQuestionRespond:r,pairedResult:i,onImageClick:a,busy:s,screenMap:c}){var f;const u=ua();return e.type==="image"?_.jsx(NS,{src:e.src,className:"max-h-[80vh] max-w-full rounded-xl border object-contain cursor-pointer hover:opacity-80 transition-opacity",onClick:h=>a==null?void 0:a(h)}):e.type==="file"?_.jsx("div",{children:_.jsx(Dwe,{src:e.src,name:e.name,className:"inline-flex items-center gap-2 px-3 py-2 rounded-lg border bg-muted/50 text-sm text-muted-foreground hover:bg-muted transition-colors"})}):e.type==="context"?_.jsx(qwe,{label:e.label,text:e.text}):e.type==="thinking"?_.jsx(Kwe,{text:e.text}):e.type==="text"?t?_.jsx("div",{dir:"auto",className:"inline-block bg-primary text-primary-foreground rounded-2xl rounded-tr-sm px-4 py-2.5 text-sm break-words min-w-0 max-w-full whitespace-pre-wrap",children:e.text}):_.jsx("div",{className:"text-sm",dir:"auto",children:_.jsx(Bwe,{text:e.text,onImageClick:a})}):e.type==="tool_use"?e.tool==="AskUserQuestion"&&(i!=null&&i.output)?_.jsx(Wwe,{input:e.input,result:i.output}):_.jsx(Ywe,{block:e,tool:e.tool,input:e.input,result:i==null?void 0:i.output,busy:s,screenMap:c}):e.type==="tool_result"?_.jsx(Xwe,{output:e.output}):e.type==="permission_request"?_.jsx(Zwe,{id:e.id,tool:e.tool,input:e.input,onRespond:n}):e.type==="question_request"?_.jsx(Qwe,{id:e.id,questions:e.questions,onRespond:r}):((f=u.extensionBlocks)==null?void 0:f.call(u,{block:e,onImageClick:a}))??null}function qwe({label:e,text:t}){const[n,r]=b.useState(!1);return _.jsxs("div",{className:"border border-blue-500/20 rounded-lg overflow-hidden text-xs bg-blue-500/5",children:[_.jsxs("button",{onClick:()=>r(!n),className:"flex items-center gap-1.5 w-full px-3 py-2 hover:bg-blue-500/10 transition-colors text-left",children:[_.jsx(w7,{className:"w-3.5 h-3.5 text-blue-400 shrink-0"}),_.jsx("span",{className:"text-blue-300 font-medium",children:e}),_.jsx(vl,{className:Ze("w-3.5 h-3.5 text-muted-foreground transition-transform shrink-0 ml-auto",n&&"rotate-90")})]}),n&&_.jsx("div",{className:"px-3 py-2 border-t border-blue-500/20 text-muted-foreground whitespace-pre-wrap",children:t})]})}function Kwe({text:e}){const[t,n]=b.useState(!1),r=e.slice(0,120).replace(/\n/g," ");return _.jsxs("div",{className:"border border-violet-500/20 rounded-lg overflow-hidden text-xs bg-violet-500/5",children:[_.jsxs("button",{onClick:()=>n(!t),className:"flex items-center gap-1.5 w-full px-3 py-2 hover:bg-violet-500/10 transition-colors text-left",children:[_.jsx(d7,{className:"w-3.5 h-3.5 text-violet-400 shrink-0"}),_.jsx("span",{className:"text-violet-300 font-medium",children:"Thinking"}),_.jsx("span",{className:"text-muted-foreground truncate",children:r}),_.jsx(vl,{className:Ze("w-3.5 h-3.5 text-muted-foreground transition-transform shrink-0 ml-auto",t&&"rotate-90")})]}),t&&_.jsx("div",{className:"px-3 py-2 border-t border-violet-500/20 text-muted-foreground whitespace-pre-wrap",children:e})]})}function Gwe(e){const t=new Map;for(const n of e)for(const r of n.blocks)if(!(r.type!=="tool_result"||!r.output))try{const i=JSON.parse(r.output);typeof(i==null?void 0:i.sessionId)=="string"&&Array.isArray(i==null?void 0:i.screen)&&t.set(i.sessionId,i.screen)}catch{}return t}function Vwe(e){const t={},n=/"([^"]+)"="([^"]+)"/g;let r;for(;(r=n.exec(e))!==null;)t[r[1]]=r[2];return t}function Wwe({input:e,result:t}){const n=e,r=(n==null?void 0:n.questions)??[],i=Vwe(t);return!r.length||!Object.keys(i).length?null:_.jsxs("div",{className:"border rounded-lg overflow-hidden text-xs bg-blue-500/5 border-blue-500/20",children:[_.jsxs("div",{className:"flex items-center gap-1.5 px-2 sm:px-3 py-2 bg-blue-50 dark:bg-blue-950/40",children:[_.jsx(qw,{className:"w-3.5 h-3.5 text-blue-400 shrink-0"}),_.jsx("span",{className:"font-medium text-blue-300",children:"Questions answered"})]}),_.jsx("div",{className:"px-2 sm:px-3 py-2 space-y-2",children:r.map((a,s)=>{const c=i[a.question];return c?_.jsxs("div",{className:"space-y-0.5",children:[_.jsxs("div",{className:"text-muted-foreground",children:[a.header?`${a.header}: `:"",a.question]}),_.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded bg-blue-500/20 text-blue-300 font-medium",children:[_.jsx(Va,{className:"w-2.5 h-2.5"}),c]})]},s):null})})]})}function Ywe({block:e,tool:t,input:n,result:r,busy:i,screenMap:a}){var E;const s=ua(),[c,u]=b.useState(!1),f=typeof n=="string"?n:JSON.stringify(n,null,2),h=typeof n=="object"&&n!==null&&Object.keys(n).length===0,p=h?"":typeof n=="object"&&n!==null?Object.keys(n).join(", "):String(n).slice(0,60),g=r!=null?h4(r.trim().replace(/\[Image #\d+\]\s*/g,"").trim()):void 0,v=r!=null,w=g?/^(Error|ERROR)|"status"\s*:\s*[45]\d\d|ENOENT|EACCES|Permission denied|command not found|No such file/i.test(g):!1,y=v?w?_.jsx(fm,{className:"w-3 h-3 text-red-400 shrink-0"}):_.jsx(Va,{className:"w-3 h-3 text-green-400 shrink-0"}):null;return _.jsxs("div",{className:"text-xs min-w-0 space-y-2",children:[_.jsxs("div",{className:"border rounded-lg overflow-hidden",children:[_.jsxs("button",{onClick:()=>u(!c),className:"flex items-center gap-1.5 w-full px-2 sm:px-3 py-2 bg-muted/50 hover:bg-muted transition-colors text-left min-w-0",children:[_.jsx(P7,{className:"w-3.5 h-3.5 text-muted-foreground shrink-0"}),_.jsx("span",{className:"font-medium text-foreground shrink-0",children:t}),!h&&_.jsx("span",{className:"text-muted-foreground truncate min-w-0",children:p}),v?y:i?_.jsx(E2,{className:"w-3 h-3 text-muted-foreground animate-spin shrink-0"}):_.jsx("span",{title:"Interrupted",children:_.jsx(fm,{className:"w-3 h-3 text-amber-400 shrink-0"})}),_.jsx(vl,{className:Ze("w-3.5 h-3.5 text-muted-foreground transition-transform shrink-0 ml-auto",c&&"rotate-90")})]}),c&&_.jsxs("div",{className:"border-t",children:[!h&&_.jsx("pre",{className:"p-3 overflow-auto max-h-64 text-xs bg-background whitespace-pre-wrap break-all",children:f}),g&&_.jsx("pre",{className:Ze("p-3 overflow-auto max-h-64 text-xs whitespace-pre-wrap break-words",!h&&"border-t",w?"bg-red-50 dark:bg-red-950/20 text-red-700 dark:text-red-300":"bg-muted/30 text-foreground/80"),children:g})]})]}),(E=s.toolRenderers)==null?void 0:E.call(s,{block:e,result:r,screens:a})]})}function h4(e){const t=e.split(`
1937
1937
  `);return t.length<2||!t.filter(r=>r.length>0).every(r=>/^\s*\d+\t/.test(r))?e:t.map(r=>r.replace(/^\s*\d+\t/,"")).join(`
1938
1938
  `)}function Xwe({output:e}){const[t,n]=b.useState(!1),r=e.trim().replace(/\[Image #\d+\]\s*/g,"").trim(),i=h4(r);if(!i)return null;const a=/^(Error|ERROR)|"status"\s*:\s*[45]\d\d|ENOENT|EACCES|Permission denied|command not found|No such file/i.test(i),s=a?null:Owe(i),c=i.length>200,u=i.slice(0,120).replace(/\n/g," "),f=a?fm:Va,h=a?"border-red-200 dark:border-red-900":"border-green-200 dark:border-green-900",p=a?"bg-red-50 dark:bg-red-950/30 hover:bg-red-100 dark:hover:bg-red-950/50":"bg-green-50 dark:bg-green-950/30 hover:bg-green-100 dark:hover:bg-green-950/50",g=a?"text-red-600 dark:text-red-400":"text-green-600 dark:text-green-400";return _.jsxs("div",{className:Ze("border rounded-lg overflow-hidden text-xs min-w-0",h),children:[_.jsxs("button",{onClick:()=>n(!t),className:Ze("flex items-center gap-1.5 w-full px-2 sm:px-3 py-2 transition-colors text-left min-w-0",p),children:[_.jsx(f,{className:Ze("w-3.5 h-3.5 shrink-0",g)}),_.jsx("span",{className:"text-muted-foreground truncate flex-1 min-w-0",children:c?u+"…":u}),_.jsx(vl,{className:Ze("w-3.5 h-3.5 text-muted-foreground transition-transform shrink-0",t&&"rotate-90")})]}),t&&_.jsx("div",{className:"p-3 bg-background border-t",children:s?_.jsx(Rwe,{data:s}):_.jsx("pre",{className:"overflow-auto max-h-96 text-xs whitespace-pre-wrap break-words",children:i})})]})}function Zwe({id:e,tool:t,input:n,onRespond:r}){const[i,a]=b.useState(!1),s=JSON.stringify(n,null,2),c=Object.keys(n).join(", ");return _.jsxs("div",{className:"border-2 rounded-lg overflow-hidden text-xs border-amber-300 dark:border-amber-700 animate-in fade-in slide-in-from-bottom-2 min-w-0",children:[_.jsxs("div",{className:"flex items-center gap-1.5 px-2 sm:px-3 py-2 bg-amber-50 dark:bg-amber-950/40 min-w-0",children:[_.jsx(qw,{className:"w-4 h-4 text-amber-600 dark:text-amber-400 shrink-0"}),_.jsx("span",{className:"font-medium text-foreground shrink-0",children:t}),_.jsxs("button",{onClick:()=>a(!i),className:"text-muted-foreground truncate min-w-0 text-left hover:text-foreground transition-colors",children:[c,_.jsx(vl,{className:Ze("w-3.5 h-3.5 inline ml-1 transition-transform",i&&"rotate-90")})]})]}),i&&_.jsx("pre",{className:"p-3 overflow-auto max-h-48 text-xs bg-background border-t border-amber-200 dark:border-amber-800 whitespace-pre-wrap break-all",children:s}),_.jsxs("div",{className:"flex flex-wrap gap-2 px-2 sm:px-3 py-2 bg-amber-50/50 dark:bg-amber-950/20 border-t border-amber-200 dark:border-amber-800",children:[_.jsxs("button",{onClick:()=>r==null?void 0:r(e,!0),className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium bg-green-600 text-white hover:bg-green-700 transition-colors",children:[_.jsx(tT,{className:"w-3.5 h-3.5"}),"Allow"]}),_.jsxs("button",{onClick:()=>r==null?void 0:r(e,!0,!0),className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium border border-green-600 text-green-700 dark:text-green-400 hover:bg-green-50 dark:hover:bg-green-950/30 transition-colors",children:[_.jsx(tT,{className:"w-3.5 h-3.5"}),"Always Allow"]}),_.jsxs("button",{onClick:()=>r==null?void 0:r(e,!1),className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium bg-red-600 text-white hover:bg-red-700 transition-colors",children:[_.jsx(fm,{className:"w-3.5 h-3.5"}),"Deny"]})]})]})}function Qwe({id:e,questions:t,onRespond:n}){const[r,i]=b.useState({}),[a,s]=b.useState({}),[c,u]=b.useState(!1),f=ua();b.useEffect(()=>{var y;return(y=f.onCardInteraction)==null?void 0:y.call(f,{id:e,questions:t,onAnswers:E=>{i(()=>{const k={};return t.forEach((O,A)=>{const C=E[O.question];C!=null&&(k[A]=new Set(Array.isArray(C)?C:[C]))}),k})}})},[e,t,f]);const h=(y,E,k)=>{i(O=>{const A=new Set(O[y]??[]);return k?A.has(E)?A.delete(E):A.add(E):(A.clear(),A.add(E)),{...O,[y]:A}})},p="__other__",g=t.filter((y,E)=>{var O;const k=r[E];return!(!k||k.size===0||k.has(p)&&!((O=a[E])!=null&&O.trim()))}).length,v=g===t.length,w=()=>{if(!v||c)return;const y={};t.forEach((E,k)=>{const O=[...r[k]??[]].map(A=>A===p?a[k].trim():A);y[E.question]=E.multiSelect?O:O[0]}),u(!0),n==null||n(e,y)};return _.jsxs("div",{className:"border-2 rounded-lg overflow-hidden text-xs border-blue-300 dark:border-blue-700 animate-in fade-in slide-in-from-bottom-2 min-w-0",children:[_.jsxs("div",{className:"flex items-center gap-1.5 px-2 sm:px-3 py-2 bg-blue-50 dark:bg-blue-950/40",children:[_.jsx(qw,{className:"w-4 h-4 text-blue-600 dark:text-blue-400 shrink-0"}),_.jsx("span",{className:"font-medium text-foreground",children:"Questions for you"})]}),_.jsx("div",{className:"px-2 sm:px-3 py-2 space-y-4 bg-background",children:t.map((y,E)=>{const k=!!y.multiSelect,O=r[E]??new Set;return _.jsxs("div",{className:"space-y-1.5",children:[_.jsx("div",{className:"font-medium text-foreground",children:y.question}),_.jsxs("div",{className:"space-y-1",children:[y.options.map(A=>_.jsxs("button",{disabled:c,onClick:()=>h(E,A.label,k),className:Ze("flex items-start gap-2 w-full text-left px-2 py-1.5 rounded-md border transition-colors",O.has(A.label)?"border-blue-500 bg-blue-50 dark:bg-blue-950/40":"border-border hover:bg-muted/50"),children:[_.jsx("span",{className:Ze("mt-0.5 w-3.5 h-3.5 shrink-0 border flex items-center justify-center",k?"rounded-sm":"rounded-full",O.has(A.label)?"bg-blue-500 border-blue-500":"border-muted-foreground"),children:O.has(A.label)&&_.jsx(Va,{className:"w-2.5 h-2.5 text-white"})}),_.jsxs("span",{className:"min-w-0",children:[_.jsx("span",{className:"font-medium text-foreground",children:A.label}),A.description&&_.jsxs("span",{className:"text-muted-foreground",children:[" — ",A.description]})]})]},A.label)),_.jsxs("div",{className:Ze("flex items-center gap-2 px-2 py-1.5 rounded-md border",O.has(p)?"border-blue-500 bg-blue-50 dark:bg-blue-950/40":"border-border"),children:[_.jsx("button",{disabled:c,onClick:()=>h(E,p,k),className:Ze("w-3.5 h-3.5 shrink-0 border flex items-center justify-center",k?"rounded-sm":"rounded-full",O.has(p)?"bg-blue-500 border-blue-500":"border-muted-foreground"),children:O.has(p)&&_.jsx(Va,{className:"w-2.5 h-2.5 text-white"})}),_.jsx("input",{type:"text",disabled:c,value:a[E]??"",placeholder:"Other…",onChange:A=>{s(C=>({...C,[E]:A.target.value})),A.target.value&&!O.has(p)&&h(E,p,k)},className:"flex-1 bg-transparent outline-none text-foreground placeholder:text-muted-foreground"})]})]})]},E)})}),_.jsxs("div",{className:"flex items-center gap-2 px-2 sm:px-3 py-2 bg-blue-50/50 dark:bg-blue-950/20 border-t border-blue-200 dark:border-blue-800",children:[_.jsxs("button",{onClick:w,disabled:!v||c,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium bg-blue-600 text-white hover:bg-blue-700 transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:[_.jsx(dm,{className:"w-3.5 h-3.5"}),c?"Sent":"Submit"]}),_.jsxs("span",{className:"text-muted-foreground",children:[g,"/",t.length," answered"]})]})]})}function Jwe({children:e,...t}){const n=b.useRef(null);return _.jsxs("div",{className:"relative group",children:[_.jsx("pre",{ref:n,...t,className:"rounded-lg border bg-muted p-4 overflow-x-auto text-xs text-foreground",children:e}),_.jsx(e1e,{getText:()=>{var r;return((r=n.current)==null?void 0:r.textContent)||""}})]})}function e1e({getText:e}){const[t,n]=b.useState(!1);return _.jsx("button",{onClick:()=>{navigator.clipboard.writeText(e()),n(!0),setTimeout(()=>n(!1),2e3)},className:"absolute top-2 right-2 p-1.5 rounded-md bg-background/80 border opacity-0 group-hover:opacity-100 transition-opacity",title:"Copy",children:t?_.jsx(Va,{className:"w-3 h-3"}):_.jsx(Bw,{className:"w-3 h-3"})})}const p4=b.forwardRef(function({value:t,onChange:n,onKeyDown:r,onPaste:i,skills:a=[],workspaceFiles:s=[],placeholder:c,className:u,rows:f=1,disabled:h,autoResize:p=!0,maxHeight:g=200},v){const w=b.useRef(null),[y,E]=b.useState(null),[k,O]=b.useState(0);b.useImperativeHandle(v,()=>({focus:()=>{var P;return(P=w.current)==null?void 0:P.focus()},setValue:P=>{n(P),p&&C()}}));const A=y?[...a.filter(P=>P.toLowerCase().includes(y.query.toLowerCase())).map(P=>({kind:"skill",value:P})),...y.kind==="mention"?s.filter(P=>P.toLowerCase().includes(y.query.toLowerCase())).map(P=>({kind:"workspace",value:P})):[]]:[];function C(){setTimeout(()=>{const P=w.current;P&&(P.style.height="auto",P.style.height=Math.min(P.scrollHeight,g)+"px")},0)}const I=P=>{if(!y)return;const j=y.kind==="command"?"/":"@",M=t.slice(0,y.start),B=t.slice(y.start+y.query.length+1),R=`${M}${j}${P} ${B}`;n(R),E(null),setTimeout(()=>{const H=w.current;if(!H)return;p&&(H.style.height="auto",H.style.height=Math.min(H.scrollHeight,g)+"px");const Y=M.length+P.length+2;H.setSelectionRange(Y,Y),H.focus()},0)},T=P=>{if(y&&A.length>0){if(P.key==="ArrowDown"){P.preventDefault(),O(j=>(j+1)%A.length);return}if(P.key==="ArrowUp"){P.preventDefault(),O(j=>(j-1+A.length)%A.length);return}if(P.key==="Enter"||P.key==="Tab"){P.preventDefault(),I(A[k].value);return}if(P.key==="Escape"){E(null);return}}r==null||r(P)},D=P=>{const j=P.target.value;n(j);const M=P.target;p&&(M.style.height="auto",M.style.height=Math.min(M.scrollHeight,g)+"px");const B=M.selectionStart??j.length,R=j.slice(0,B),H=R.match(/(?:^|\n)\/([\w-]*)$/),Y=R.match(/@([\w\-./]*)$/);H?(E({query:H[1],start:H.index+(R[H.index]===`
1939
- `?1:0),kind:"command"}),O(0)):Y?(E({query:Y[1],start:Y.index,kind:"mention"}),O(0)):E(null)};return b.useEffect(()=>{const P=()=>E(null);return y&&document.addEventListener("mousedown",P),()=>document.removeEventListener("mousedown",P)},[y]),_.jsxs("div",{className:"relative flex-1 min-w-0",children:[y&&A.length>0&&_.jsx("div",{className:"absolute bottom-full mb-1 left-0 z-50 bg-background border rounded-lg shadow-lg overflow-hidden min-w-[220px] max-h-64 overflow-y-auto",children:A.map((P,j)=>_.jsxs("button",{onMouseDown:M=>{M.preventDefault(),I(P.value)},className:`w-full text-left px-3 py-1.5 text-sm hover:bg-accent transition-colors flex items-center gap-2 ${j===k?"bg-accent":""}`,children:[_.jsx("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground shrink-0 w-14",children:(y==null?void 0:y.kind)==="command"?"cmd":P.kind==="skill"?"skill":"file"}),_.jsxs("span",{className:"truncate",children:[_.jsx("span",{className:"text-muted-foreground",children:(y==null?void 0:y.kind)==="command"?"/":"@"}),P.value]})]},`${P.kind}:${P.value}`))}),_.jsx("textarea",{ref:w,value:t,onChange:D,onKeyDown:T,onPaste:i,placeholder:c,disabled:h,rows:f,dir:"auto",className:u})]})}),IS="shraga:draft:";function Y0(e,t){const n=IS+(e??"new");t.trim()?localStorage.setItem(n,t):localStorage.removeItem(n)}function ZR(e){return localStorage.getItem(IS+(e??"new"))??""}function QR(e){localStorage.removeItem(IS+(e??"new"))}const t1e=b.forwardRef(function({onSend:t,onSteer:n,onQueue:r,onRemoveQueued:i,queue:a,onUpload:s,onCancel:c,disabled:u,busy:f,skills:h=[],workspaceFiles:p=[],sessionId:g,inputCtx:v},w){var U,G;const y=ua(),[E,k]=b.useState(()=>ZR(g)),[O,A]=b.useState([]),[C,I]=b.useState(!1),T=b.useRef(null),D=b.useRef(null),P=b.useRef(g);b.useEffect(()=>{var L;if(P.current===g)return;const q=P.current;if(P.current=g,!g){QR(q),Y0(void 0,E);return}Y0(q,E);const ee=ZR(g);k(ee),(L=D.current)==null||L.setValue(ee)},[g]);const j=b.useCallback(q=>{k(q),Y0(P.current,q)},[]);b.useImperativeHandle(w,()=>({prefill(q){var ee,L;j(q),(ee=D.current)==null||ee.setValue(q),(L=D.current)==null||L.focus()},setText(q){var ee;j(q),(ee=D.current)==null||ee.setValue(q)},focus(){var q;(q=D.current)==null||q.focus()}}));const M=(q="send")=>{var L;const ee=E.trim();!ee&&O.length===0||(q==="steer"?n(ee):q==="queue"?r(ee):t(ee,O.length>0?O:void 0),k(""),QR(P.current),A([]),(L=D.current)==null||L.setValue(""))},B=typeof window<"u"&&((U=window.matchMedia)==null?void 0:U.call(window,"(pointer: coarse)").matches),R=q=>{if(q.key==="Enter"&&!q.shiftKey&&(!B||q.metaKey||q.ctrlKey)){q.preventDefault(),M(f?"steer":"send");return}if(q.key==="Tab"&&f&&E.trim()){q.preventDefault(),M("queue");return}},H=b.useCallback(async q=>{I(!0);try{const ee=await s(q);ee&&A(L=>[...L,ee])}finally{I(!1)}},[s]),Y=b.useCallback(q=>{const ee=Array.from(q.clipboardData.items);for(const L of ee)if(L.type.startsWith("image/")||L.type==="application/pdf"){const F=L.getAsFile();F&&H(F)}},[H]),K=q=>{var L;const ee=(L=q.target.files)==null?void 0:L[0];ee&&(H(ee),q.target.value="")};return _.jsx("div",{className:"border-t bg-background",style:{paddingBottom:"env(safe-area-inset-bottom)"},children:_.jsxs("div",{className:"max-w-3xl mx-auto px-2 sm:px-4 py-3",children:[(O.length>0||C)&&_.jsxs("div",{className:"flex gap-2 mb-2 flex-wrap items-center",children:[O.map((q,ee)=>_.jsxs("div",{className:"relative group",children:[q.mimeType.startsWith("image/")?_.jsx(NS,{src:q.url,alt:q.name,className:"h-16 w-16 object-cover rounded-lg border"}):_.jsxs("div",{className:"h-16 px-3 flex items-center gap-2 rounded-lg border bg-muted/50 text-xs text-muted-foreground",children:[_.jsx(Uw,{className:"w-4 h-4 shrink-0"}),_.jsx("span",{className:"truncate max-w-[120px]",children:q.name})]}),_.jsx("button",{onClick:()=>A(L=>L.filter((F,J)=>J!==ee)),className:"absolute -top-1.5 -right-1.5 bg-destructive text-destructive-foreground rounded-full w-5 h-5 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity shadow-sm",children:_.jsx(al,{className:"w-3 h-3"})})]},ee)),C&&_.jsx("span",{className:"text-xs text-muted-foreground animate-pulse",children:"Uploading…"})]}),_.jsxs("div",{className:"flex items-center gap-2 bg-muted/50 rounded-xl border px-3 py-2",children:[_.jsx(Pe,{variant:"ghost",size:"icon",className:"h-9 w-9 sm:h-8 sm:w-8 shrink-0",onClick:()=>{var q;return(q=T.current)==null?void 0:q.click()},disabled:u,title:"Attach file or image",children:_.jsx(A7,{className:"w-4 h-4"})}),_.jsx("input",{ref:T,type:"file",className:"hidden",onChange:K}),_.jsx(p4,{ref:D,value:E,onChange:j,onKeyDown:R,onPaste:Y,skills:h,workspaceFiles:p,placeholder:f?"Steer or queue…":"Message Claude…",disabled:u,rows:1,className:"w-full bg-transparent border-none outline-none resize-none text-sm py-1.5 placeholder:text-muted-foreground min-h-[28px] max-h-[200px]"}),(G=y.inputAdornments)==null?void 0:G.call(y,v),f?_.jsxs("div",{className:"flex items-center gap-2",children:[E.trim()&&_.jsx(Pe,{size:"icon",className:"h-9 w-9 sm:h-8 sm:w-8 shrink-0 rounded-lg",onClick:()=>M("steer"),title:"Steer (inject into current turn)",children:_.jsx(dm,{className:"w-4 h-4"})}),_.jsx(Pe,{variant:"destructive",size:"icon",className:"h-9 w-9 sm:h-8 sm:w-8 shrink-0 rounded-lg",onClick:()=>c(),title:"Stop generation",children:_.jsx(k2,{className:"w-3.5 h-3.5"})})]}):_.jsx(Pe,{size:"icon",className:"h-9 w-9 sm:h-8 sm:w-8 shrink-0 rounded-lg",onClick:()=>M(),disabled:u||C||!E.trim()&&O.length===0,children:_.jsx(dm,{className:"w-4 h-4"})})]}),a.length>0&&_.jsx("div",{className:"flex gap-1.5 flex-wrap mt-2",children:a.map((q,ee)=>_.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-blue-50 dark:bg-blue-950/40 px-2.5 py-1 text-xs text-blue-700 dark:text-blue-300 ring-1 ring-inset ring-blue-600/20 dark:ring-blue-400/30",children:[_.jsx("span",{className:"truncate max-w-[200px]",children:q}),_.jsx("button",{onClick:()=>i(ee),className:"hover:text-blue-900 dark:hover:text-blue-100",children:_.jsx(al,{className:"w-3 h-3"})})]},ee))}),_.jsx("p",{className:"text-[10px] text-muted-foreground text-center mt-2",children:f?"Enter to steer (redirect) · Tab to queue (after done) · Shift+Enter for newline":"Enter to send · Shift+Enter for newline · @ for skills · / for commands"})]})})}),n1e={"fb-feed":[1080,1080],"fb-story":[1080,1920],"fb-landscape":[1200,628],"ig-square":[1080,1080],"ig-story":[1080,1920],"ig-landscape":[1080,566],"banner-leaderboard":[728,90],"banner-medium":[300,250]};function r1e({artifacts:e,selectedId:t,sessionId:n,getToken:r,onSelect:i,onClose:a}){var D;const[s,c]=b.useState(!1),[u,f]=b.useState(!1),[h,p]=b.useState(!1),[g,v]=b.useState(1),w=b.useRef(null),y=e.find(P=>P.id===t),E=b.useCallback(()=>{if(!w.current||!y)return;const{clientWidth:P,clientHeight:j}=w.current,M=32,B=P-M,R=j-M,[H,Y]=y.dimensions;v(Math.min(B/H,R/Y,1))},[y]);b.useEffect(()=>{let P=!0;return r().then(j=>fetch("/api/features",{headers:j?{Authorization:`Bearer ${j}`}:{}})).then(j=>j.json()).then(j=>{P&&p(!!j.artifactPngExport)}).catch(j=>console.error("[artifact] features fetch failed:",j)),()=>{P=!1}},[r]),b.useEffect(()=>{E();const P=w.current;if(!P)return;const j=new ResizeObserver(E);return j.observe(P),()=>j.disconnect()},[E]);const k=async()=>{if(y){f(!0);try{const P=await r(),j=await fetch(`/api/artifacts/${n}/${y.id}/export`,{method:"POST",headers:{"Content-Type":"application/json",...P?{Authorization:`Bearer ${P}`}:{}},body:JSON.stringify({dimensions:y.dimensions})});if(!j.ok)throw new Error(await j.text());const M=await j.blob(),B=URL.createObjectURL(M),R=document.createElement("a");R.href=B,R.download=`${y.title.replace(/\s+/g,"-").toLowerCase()}.png`,R.click(),URL.revokeObjectURL(B)}catch(P){console.error("[artifact] export failed:",P)}finally{f(!1)}}},O=y?(D=Object.entries(n1e).find(([,P])=>P[0]===y.dimensions[0]&&P[1]===y.dimensions[1]))==null?void 0:D[0]:null,[A,C]=(y==null?void 0:y.dimensions)??[0,0],I=A*g,T=C*g;return _.jsxs("div",{className:Ze("flex flex-col border-l bg-background transition-all",s?"fixed inset-0 z-50":"fixed inset-0 z-50 sm:relative sm:inset-auto sm:z-auto sm:w-[480px] sm:shrink-0"),children:[_.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1.5 border-b bg-muted/30",children:[_.jsx(Pe,{variant:"ghost",size:"icon",className:"h-7 w-7 sm:hidden shrink-0",onClick:a,title:"Back to chat",children:_.jsx(x2,{className:"w-4 h-4"})}),e.length>1&&_.jsx("select",{className:"text-xs bg-transparent border rounded px-1 py-0.5 max-w-[160px] truncate",value:t??"",onChange:P=>i(P.target.value),children:e.map(P=>_.jsx("option",{value:P.id,children:P.title},P.id))}),e.length<=1&&y&&_.jsx("span",{className:"text-xs font-medium truncate max-w-[160px]",children:y.title}),y&&_.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[O??`${A}×${C}`,g<1&&` · ${Math.round(g*100)}%`]}),_.jsx("div",{className:"flex-1"}),h&&_.jsx(Pe,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:k,disabled:!y||u,title:"Export PNG",children:u?_.jsx("span",{className:"w-3 h-3 border-2 border-current border-t-transparent rounded-full animate-spin"}):_.jsx(x7,{className:"w-3.5 h-3.5"})}),_.jsx(Pe,{variant:"ghost",size:"icon",className:"h-6 w-6 hidden sm:inline-flex",onClick:()=>c(!s),title:s?"Minimize":"Maximize",children:s?_.jsx(Fw,{className:"w-3.5 h-3.5"}):_.jsx($w,{className:"w-3.5 h-3.5"})}),_.jsx(Pe,{variant:"ghost",size:"icon",className:"h-6 w-6 hidden sm:inline-flex",onClick:a,title:"Close",children:_.jsx(al,{className:"w-3.5 h-3.5"})})]}),_.jsx("div",{ref:w,className:"flex-1 overflow-hidden flex items-center justify-center bg-muted/10",children:y?_.jsx("div",{style:{width:I,height:T},children:_.jsx("iframe",{src:`/api/artifacts/${n}/${y.id}`,sandbox:"allow-scripts",className:"border shadow-sm bg-white origin-top-left",style:{width:A,height:C,transform:`scale(${g})`},title:y.title})}):_.jsx("p",{className:"text-sm text-muted-foreground",children:"No artifact selected"})})]})}const bv=b.forwardRef(({className:e,...t},n)=>_.jsx("textarea",{className:Ze("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 resize-none",e),ref:n,...t}));bv.displayName="Textarea";const i1e=[{value:"",label:"Default (claude-sonnet-4-6)"},{value:"claude-fable-5",label:"Fable 5 — frontier, most capable"},{value:"claude-opus-4-8",label:"Opus 4.8 — most capable, best for complex/agentic tasks"},{value:"claude-opus-4-7",label:"Opus 4.7"},{value:"claude-opus-4-6",label:"Opus 4.6"},{value:"claude-sonnet-4-6",label:"Sonnet 4.6 — balanced speed & intelligence"},{value:"claude-haiku-4-5",label:"Haiku 4.5 — fastest"}],a1e=[{value:"acceptEdits",label:"Accept Edits (auto-approve file changes)"},{value:"plan",label:"Plan (read-only, suggest changes)"},{value:"bypassPermissions",label:"Bypass All (dangerous — no prompts)"}];function o1e({getToken:e,onSaved:t,trigger:n,sessionId:r,sessionDirectives:i,onDirectivesSaved:a}){var j;const s=ua(),[c,u]=b.useState({}),[f,h]=b.useState(!1),[p,g]=b.useState(!1),[v,w]=b.useState([]),[y,E]=b.useState(!1),k=b.useRef({});b.useEffect(()=>{f&&e().then(M=>{M&&(fetch("/api/config",{headers:{Authorization:`Bearer ${M}`}}).then(B=>B.json()).then(B=>{k.current=B;const R=r?i:void 0;u({...B,...(R==null?void 0:R.engine)!==void 0?{engine:R.engine}:{},...(R==null?void 0:R.model)!==void 0?{model:R.model}:{},...(R==null?void 0:R.turns)!==void 0?{maxTurns:R.turns}:{},...(R==null?void 0:R.thinking)!==void 0?{thinking:R.thinking}:{}})}).catch(()=>{}),fetch("/api/engines",{headers:{Authorization:`Bearer ${M}`}}).then(B=>B.json()).then(B=>{w(B.engines??[]),E(B.multiEngine??!1)}).catch(()=>{}))})},[f,e,r,i]);const O=async()=>{g(!0);const B={Authorization:`Bearer ${await e()??""}`,"Content-Type":"application/json"};try{if(r){const R={engine:c.engine,model:c.model,turns:c.maxTurns,thinking:c.thinking},H=await fetch(`/api/sessions/${r}/directives`,{method:"PUT",headers:B,body:JSON.stringify(R)}).then(K=>K.json()).catch(K=>(console.warn("[config] directives save failed",K),null));H!=null&&H.directives&&(a==null||a(H.directives));const Y={...c,engine:k.current.engine,model:k.current.model,maxTurns:k.current.maxTurns,thinking:k.current.thinking};await fetch("/api/config",{method:"PUT",headers:B,body:JSON.stringify(Y)}),t==null||t(Y)}else await fetch("/api/config",{method:"PUT",headers:B,body:JSON.stringify(c)}),t==null||t(c);h(!1)}finally{g(!1)}},A=c.engine||"claude-code",C=v.find(M=>M.name===A),I=(C==null?void 0:C.models)??i1e;b.useEffect(()=>{!C||!I.length||I.some(M=>(M.value||"")===(c.model??""))||u(M=>({...M,model:I[0].value||void 0}))},[C,I,c.model]);const D=I.some(M=>M.provider)?Array.from(I.reduce((M,B)=>{const R=B.provider||"default";return M.has(R)||M.set(R,[]),M.get(R).push(B),M},new Map)):null,P="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2";return _.jsxs(sl,{open:f,onOpenChange:h,children:[_.jsx(Ng,{asChild:!0,children:n||_.jsx(Pe,{variant:"ghost",size:"icon",title:"Agent Config",children:_.jsx(I7,{className:"w-4 h-4"})})}),_.jsxs(es,{className:"max-w-lg",children:[_.jsx(Gc,{children:_.jsx(ll,{children:"Agent Configuration"})}),_.jsxs(Fj,{className:"space-y-4",children:[r&&_.jsxs("p",{className:"text-xs text-muted-foreground rounded-md bg-muted/50 px-3 py-2",children:["Engine, Model, Max Turns & Thinking apply to ",_.jsx("strong",{children:"this conversation"}),". Other settings are global defaults for new sessions."]}),y&&_.jsxs("div",{children:[_.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Engine"}),_.jsx("select",{value:c.engine??"",onChange:M=>{const B=M.target.value||void 0;u(R=>({...R,engine:B,model:void 0}))},className:P,children:v.map(M=>_.jsx("option",{value:M.name,children:M.name==="claude-code"?"Claude Code (default)":M.name},M.name))})]}),_.jsxs("div",{children:[_.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Model"}),_.jsx("select",{value:c.model??"",onChange:M=>u(B=>({...B,model:M.target.value||void 0})),className:P,children:D?D.map(([M,B])=>_.jsx("optgroup",{label:M.charAt(0).toUpperCase()+M.slice(1),children:B.map(R=>_.jsx("option",{value:R.value,children:R.label},R.value))},M)):I.map(M=>_.jsx("option",{value:M.value,children:M.label},M.value))})]}),(j=s.settingsSections)==null?void 0:j.call(s,{getToken:e,sessionId:r}),_.jsxs("div",{children:[_.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Permission Mode"}),_.jsx("select",{value:c.permissionMode??"acceptEdits",onChange:M=>u(B=>({...B,permissionMode:M.target.value})),className:P,children:a1e.map(M=>_.jsx("option",{value:M.value,children:M.label},M.value))})]}),_.jsxs("div",{children:[_.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Max Turns"}),_.jsx(Un,{type:"number",min:1,max:200,value:c.maxTurns??50,onChange:M=>u(B=>({...B,maxTurns:Number(M.target.value)||50}))})]}),_.jsxs("div",{children:[_.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Thinking"}),_.jsxs("select",{value:c.thinking??"",onChange:M=>u(B=>({...B,thinking:M.target.value||void 0})),className:P,children:[_.jsx("option",{value:"",children:"Default (off)"}),_.jsx("option",{value:"adaptive",children:"Adaptive (Claude decides)"}),_.jsx("option",{value:"enabled",children:"Enabled (always think)"}),_.jsx("option",{value:"disabled",children:"Disabled"})]})]}),_.jsxs("div",{children:[_.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Effort"}),_.jsxs("select",{value:c.effort??"",onChange:M=>u(B=>({...B,effort:M.target.value||void 0})),className:P,children:[_.jsx("option",{value:"",children:"Default"}),_.jsx("option",{value:"low",children:"Low — fast"}),_.jsx("option",{value:"medium",children:"Medium"}),_.jsx("option",{value:"high",children:"High"}),_.jsx("option",{value:"max",children:"Max"})]})]}),_.jsxs("div",{children:[_.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Allowed Tools"}),_.jsx(Un,{placeholder:"Read, Edit, Bash, WebSearch, Glob, LS",value:(c.allowedTools??[]).join(", "),onChange:M=>u(B=>({...B,allowedTools:M.target.value.split(",").map(R=>R.trim()).filter(Boolean)}))}),_.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Comma-separated list of tools Claude can use"})]}),_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("label",{className:"text-sm font-medium",children:"Skill Discovery"}),_.jsx("p",{className:"text-xs text-muted-foreground",children:"Index all skills + auto-inject on trigger match"})]}),_.jsx("button",{type:"button",role:"switch","aria-checked":c.skillDiscovery!==!1,onClick:()=>u(M=>({...M,skillDiscovery:M.skillDiscovery===!1})),className:`relative inline-flex h-6 w-11 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors ${c.skillDiscovery!==!1?"bg-primary":"bg-muted"}`,children:_.jsx("span",{className:`pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform ${c.skillDiscovery!==!1?"translate-x-5":"translate-x-0"}`})})]}),_.jsxs("div",{children:[_.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"System Prompt (optional)"}),_.jsx(bv,{placeholder:"Additional instructions appended to Claude's system prompt…",value:c.systemPrompt??"",onChange:M=>u(B=>({...B,systemPrompt:M.target.value||void 0})),rows:4})]})]}),_.jsx(Hj,{children:_.jsx(Pe,{onClick:O,disabled:p,children:p?"Saving…":"Save Configuration"})})]})]})}function s1e({sessionId:e,config:t,sessionDirectives:n,actualModel:r,scheduleId:i,onScheduleClick:a}){const[s,c]=b.useState(!1),u=(n==null?void 0:n.engine)||t.engine||"claude-code",f=r?!r.includes("/"):void 0,h=u==="claude-code"||u==="cursor",g=(f!==void 0&&f===h?r:void 0)||(n==null?void 0:n.model)||t.model||(u==="cursor"?"cursor/composer-2.5":"sonnet-4-6"),v=h?g.replace("claude-",""):`${u} · ${g.replace("claude-","")}`,w=t.permissionMode||"acceptEdits",y=w==="bypassPermissions"?"bypass":w==="plan"?"plan":w==="default"?"prompt":"edits",E=(n==null?void 0:n.thinking)||t.thinking,k=()=>{e&&(navigator.clipboard.writeText(e),c(!0),setTimeout(()=>c(!1),1500))};return _.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[_.jsx("span",{className:"inline-flex items-center rounded-md bg-blue-50 px-1.5 py-0.5 text-[10px] font-medium text-blue-700 ring-1 ring-inset ring-blue-600/20 dark:bg-blue-950/50 dark:text-blue-300 dark:ring-blue-400/30",children:v}),_.jsx("span",{className:"inline-flex items-center rounded-md bg-amber-50 px-1.5 py-0.5 text-[10px] font-medium text-amber-700 ring-1 ring-inset ring-amber-600/20 dark:bg-amber-950/50 dark:text-amber-300 dark:ring-amber-400/30",children:y}),_.jsxs("span",{className:"inline-flex items-center rounded-md bg-green-50 px-1.5 py-0.5 text-[10px] font-medium text-green-700 ring-1 ring-inset ring-green-600/20 dark:bg-green-950/50 dark:text-green-300 dark:ring-green-400/30",children:[(n==null?void 0:n.turns)??t.maxTurns??50," steps"]}),E&&E!=="disabled"&&_.jsx("span",{className:"inline-flex items-center rounded-md bg-violet-50 px-1.5 py-0.5 text-[10px] font-medium text-violet-700 ring-1 ring-inset ring-violet-600/20 dark:bg-violet-950/50 dark:text-violet-300 dark:ring-violet-400/30",children:"think"}),e&&_.jsxs("button",{onClick:k,className:"inline-flex items-center gap-0.5 rounded-md bg-muted px-1.5 py-0.5 text-[10px] font-mono text-muted-foreground ring-1 ring-inset ring-border hover:bg-accent transition-colors",title:`Session: ${e}
1939
+ `?1:0),kind:"command"}),O(0)):Y?(E({query:Y[1],start:Y.index,kind:"mention"}),O(0)):E(null)};return b.useEffect(()=>{const P=()=>E(null);return y&&document.addEventListener("mousedown",P),()=>document.removeEventListener("mousedown",P)},[y]),_.jsxs("div",{className:"relative flex-1 min-w-0",children:[y&&A.length>0&&_.jsx("div",{className:"absolute bottom-full mb-1 left-0 z-50 bg-background border rounded-lg shadow-lg overflow-hidden min-w-[220px] max-h-64 overflow-y-auto",children:A.map((P,j)=>_.jsxs("button",{onMouseDown:M=>{M.preventDefault(),I(P.value)},className:`w-full text-left px-3 py-1.5 text-sm hover:bg-accent transition-colors flex items-center gap-2 ${j===k?"bg-accent":""}`,children:[_.jsx("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground shrink-0 w-14",children:(y==null?void 0:y.kind)==="command"?"cmd":P.kind==="skill"?"skill":"file"}),_.jsxs("span",{className:"truncate",children:[_.jsx("span",{className:"text-muted-foreground",children:(y==null?void 0:y.kind)==="command"?"/":"@"}),P.value]})]},`${P.kind}:${P.value}`))}),_.jsx("textarea",{ref:w,value:t,onChange:D,onKeyDown:T,onPaste:i,placeholder:c,disabled:h,rows:f,dir:"auto",className:u})]})}),IS="shraga:draft:";function Y0(e,t){const n=IS+(e??"new");t.trim()?localStorage.setItem(n,t):localStorage.removeItem(n)}function ZR(e){return localStorage.getItem(IS+(e??"new"))??""}function QR(e){localStorage.removeItem(IS+(e??"new"))}const t1e=b.forwardRef(function({onSend:t,onSteer:n,onQueue:r,onRemoveQueued:i,queue:a,onUpload:s,onCancel:c,disabled:u,busy:f,skills:h=[],workspaceFiles:p=[],sessionId:g,inputCtx:v},w){var U,G;const y=ua(),[E,k]=b.useState(()=>ZR(g)),[O,A]=b.useState([]),[C,I]=b.useState(!1),T=b.useRef(null),D=b.useRef(null),P=b.useRef(g);b.useEffect(()=>{var L;if(P.current===g)return;const q=P.current;if(P.current=g,!g){QR(q),Y0(void 0,E);return}Y0(q,E);const ee=ZR(g);k(ee),(L=D.current)==null||L.setValue(ee)},[g]);const j=b.useCallback(q=>{k(q),Y0(P.current,q)},[]);b.useImperativeHandle(w,()=>({prefill(q){var ee,L;j(q),(ee=D.current)==null||ee.setValue(q),(L=D.current)==null||L.focus()},setText(q){var ee;j(q),(ee=D.current)==null||ee.setValue(q)},focus(){var q;(q=D.current)==null||q.focus()}}));const M=(q="send")=>{var L;const ee=E.trim();!ee&&O.length===0||(q==="steer"?n(ee):q==="queue"?r(ee):t(ee,O.length>0?O:void 0),k(""),QR(P.current),A([]),(L=D.current)==null||L.setValue(""))},B=typeof window<"u"&&((U=window.matchMedia)==null?void 0:U.call(window,"(pointer: coarse)").matches),R=q=>{if(q.key==="Enter"&&!q.shiftKey&&(!B||q.metaKey||q.ctrlKey)){q.preventDefault(),M(f?"steer":"send");return}if(q.key==="Tab"&&f&&E.trim()){q.preventDefault(),M("queue");return}},H=b.useCallback(async q=>{I(!0);try{const ee=await s(q);ee&&A(L=>[...L,ee])}finally{I(!1)}},[s]),Y=b.useCallback(q=>{const ee=Array.from(q.clipboardData.items);for(const L of ee)if(L.type.startsWith("image/")||L.type==="application/pdf"){const F=L.getAsFile();F&&H(F)}},[H]),K=q=>{var L;const ee=(L=q.target.files)==null?void 0:L[0];ee&&(H(ee),q.target.value="")};return _.jsx("div",{className:"border-t bg-background",style:{paddingBottom:"env(safe-area-inset-bottom)"},children:_.jsxs("div",{className:"max-w-3xl mx-auto px-2 sm:px-4 py-3",children:[(O.length>0||C)&&_.jsxs("div",{className:"flex gap-2 mb-2 flex-wrap items-center",children:[O.map((q,ee)=>_.jsxs("div",{className:"relative group",children:[q.mimeType.startsWith("image/")?_.jsx(NS,{src:q.url,alt:q.name,className:"h-16 w-16 object-cover rounded-lg border"}):_.jsxs("div",{className:"h-16 px-3 flex items-center gap-2 rounded-lg border bg-muted/50 text-xs text-muted-foreground",children:[_.jsx(Uw,{className:"w-4 h-4 shrink-0"}),_.jsx("span",{className:"truncate max-w-[120px]",children:q.name})]}),_.jsx("button",{onClick:()=>A(L=>L.filter((F,J)=>J!==ee)),className:"absolute -top-1.5 -right-1.5 bg-destructive text-destructive-foreground rounded-full w-5 h-5 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity shadow-sm",children:_.jsx(al,{className:"w-3 h-3"})})]},ee)),C&&_.jsx("span",{className:"text-xs text-muted-foreground animate-pulse",children:"Uploading…"})]}),_.jsxs("div",{className:"flex items-center gap-2 bg-muted/50 rounded-xl border px-3 py-2",children:[_.jsx(Pe,{variant:"ghost",size:"icon",className:"h-9 w-9 sm:h-8 sm:w-8 shrink-0",onClick:()=>{var q;return(q=T.current)==null?void 0:q.click()},disabled:u,title:"Attach file or image",children:_.jsx(A7,{className:"w-4 h-4"})}),_.jsx("input",{ref:T,type:"file",className:"hidden",onChange:K}),_.jsx(p4,{ref:D,value:E,onChange:j,onKeyDown:R,onPaste:Y,skills:h,workspaceFiles:p,placeholder:f?"Steer or queue…":"Message Claude…",disabled:u,rows:1,className:"w-full bg-transparent border-none outline-none resize-none text-sm py-1.5 placeholder:text-muted-foreground min-h-[28px] max-h-[200px]"}),(G=y.inputAdornments)==null?void 0:G.call(y,v),f?_.jsxs("div",{className:"flex items-center gap-2",children:[E.trim()&&_.jsx(Pe,{size:"icon",className:"h-9 w-9 sm:h-8 sm:w-8 shrink-0 rounded-lg",onClick:()=>M("steer"),title:"Steer (inject into current turn)",children:_.jsx(dm,{className:"w-4 h-4"})}),_.jsx(Pe,{variant:"destructive",size:"icon",className:"h-9 w-9 sm:h-8 sm:w-8 shrink-0 rounded-lg",onClick:()=>c(),title:"Stop generation",children:_.jsx(k2,{className:"w-3.5 h-3.5"})})]}):_.jsx(Pe,{size:"icon",className:"h-9 w-9 sm:h-8 sm:w-8 shrink-0 rounded-lg",onClick:()=>M(),disabled:u||C||!E.trim()&&O.length===0,children:_.jsx(dm,{className:"w-4 h-4"})})]}),a.length>0&&_.jsx("div",{className:"flex gap-1.5 flex-wrap mt-2",children:a.map((q,ee)=>_.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-blue-50 dark:bg-blue-950/40 px-2.5 py-1 text-xs text-blue-700 dark:text-blue-300 ring-1 ring-inset ring-blue-600/20 dark:ring-blue-400/30",children:[_.jsx("span",{className:"truncate max-w-[200px]",children:q}),_.jsx("button",{onClick:()=>i(ee),className:"hover:text-blue-900 dark:hover:text-blue-100",children:_.jsx(al,{className:"w-3 h-3"})})]},ee))}),_.jsx("p",{className:"text-[10px] text-muted-foreground text-center mt-2",children:f?"Enter to steer (redirect) · Tab to queue (after done) · Shift+Enter for newline":"Enter to send · Shift+Enter for newline · @ for skills · / for commands"})]})})}),n1e={"fb-feed":[1080,1080],"fb-story":[1080,1920],"fb-landscape":[1200,628],"ig-square":[1080,1080],"ig-story":[1080,1920],"ig-landscape":[1080,566],"banner-leaderboard":[728,90],"banner-medium":[300,250]};function r1e({artifacts:e,selectedId:t,sessionId:n,getToken:r,onSelect:i,onClose:a}){var D;const[s,c]=b.useState(!1),[u,f]=b.useState(!1),[h,p]=b.useState(!1),[g,v]=b.useState(1),w=b.useRef(null),y=e.find(P=>P.id===t),E=b.useCallback(()=>{if(!w.current||!y)return;const{clientWidth:P,clientHeight:j}=w.current,M=32,B=P-M,R=j-M,[H,Y]=y.dimensions;v(Math.min(B/H,R/Y,1))},[y]);b.useEffect(()=>{let P=!0;return r().then(j=>fetch("/api/features",{headers:j?{Authorization:`Bearer ${j}`}:{}})).then(j=>j.json()).then(j=>{P&&p(!!j.artifactPngExport)}).catch(j=>console.error("[artifact] features fetch failed:",j)),()=>{P=!1}},[r]),b.useEffect(()=>{E();const P=w.current;if(!P)return;const j=new ResizeObserver(E);return j.observe(P),()=>j.disconnect()},[E]);const k=async()=>{if(y){f(!0);try{const P=await r(),j=await fetch(`/api/artifacts/${n}/${y.id}/export`,{method:"POST",headers:{"Content-Type":"application/json",...P?{Authorization:`Bearer ${P}`}:{}},body:JSON.stringify({dimensions:y.dimensions})});if(!j.ok)throw new Error(await j.text());const M=await j.blob(),B=URL.createObjectURL(M),R=document.createElement("a");R.href=B,R.download=`${y.title.replace(/\s+/g,"-").toLowerCase()}.png`,R.click(),URL.revokeObjectURL(B)}catch(P){console.error("[artifact] export failed:",P)}finally{f(!1)}}},O=y?(D=Object.entries(n1e).find(([,P])=>P[0]===y.dimensions[0]&&P[1]===y.dimensions[1]))==null?void 0:D[0]:null,[A,C]=(y==null?void 0:y.dimensions)??[0,0],I=A*g,T=C*g;return _.jsxs("div",{className:Ze("flex flex-col border-l bg-background transition-all",s?"fixed inset-0 z-50":"fixed inset-0 z-50 sm:relative sm:inset-auto sm:z-auto sm:w-[480px] sm:shrink-0"),children:[_.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1.5 border-b bg-muted/30",children:[_.jsx(Pe,{variant:"ghost",size:"icon",className:"h-7 w-7 sm:hidden shrink-0",onClick:a,title:"Back to chat",children:_.jsx(x2,{className:"w-4 h-4"})}),e.length>1&&_.jsx("select",{className:"text-xs bg-transparent border rounded px-1 py-0.5 max-w-[160px] truncate",value:t??"",onChange:P=>i(P.target.value),children:e.map(P=>_.jsx("option",{value:P.id,children:P.title},P.id))}),e.length<=1&&y&&_.jsx("span",{className:"text-xs font-medium truncate max-w-[160px]",children:y.title}),y&&_.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[O??`${A}×${C}`,g<1&&` · ${Math.round(g*100)}%`]}),_.jsx("div",{className:"flex-1"}),h&&_.jsx(Pe,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:k,disabled:!y||u,title:"Export PNG",children:u?_.jsx("span",{className:"w-3 h-3 border-2 border-current border-t-transparent rounded-full animate-spin"}):_.jsx(x7,{className:"w-3.5 h-3.5"})}),_.jsx(Pe,{variant:"ghost",size:"icon",className:"h-6 w-6 hidden sm:inline-flex",onClick:()=>c(!s),title:s?"Minimize":"Maximize",children:s?_.jsx(Fw,{className:"w-3.5 h-3.5"}):_.jsx($w,{className:"w-3.5 h-3.5"})}),_.jsx(Pe,{variant:"ghost",size:"icon",className:"h-6 w-6 hidden sm:inline-flex",onClick:a,title:"Close",children:_.jsx(al,{className:"w-3.5 h-3.5"})})]}),_.jsx("div",{ref:w,className:"flex-1 overflow-hidden flex items-center justify-center bg-muted/10",children:y?_.jsx("div",{style:{width:I,height:T},children:_.jsx("iframe",{src:`/api/artifacts/${n}/${y.id}`,sandbox:"allow-scripts",className:"border shadow-sm bg-white origin-top-left",style:{width:A,height:C,transform:`scale(${g})`},title:y.title})}):_.jsx("p",{className:"text-sm text-muted-foreground",children:"No artifact selected"})})]})}const bv=b.forwardRef(({className:e,...t},n)=>_.jsx("textarea",{className:Ze("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 resize-none",e),ref:n,...t}));bv.displayName="Textarea";const i1e=[{value:"",label:"Default (claude-sonnet-5)"},{value:"claude-fable-5",label:"Fable 5 — frontier, most capable"},{value:"claude-opus-4-8",label:"Opus 4.8 — most capable, best for complex/agentic tasks"},{value:"claude-opus-4-7",label:"Opus 4.7"},{value:"claude-opus-4-6",label:"Opus 4.6"},{value:"claude-sonnet-5",label:"Sonnet 5 — balanced speed & intelligence"},{value:"claude-sonnet-4-6",label:"Sonnet 4.6"},{value:"claude-haiku-4-5",label:"Haiku 4.5 — fastest"}],a1e=[{value:"acceptEdits",label:"Accept Edits (auto-approve file changes)"},{value:"plan",label:"Plan (read-only, suggest changes)"},{value:"bypassPermissions",label:"Bypass All (dangerous — no prompts)"}];function o1e({getToken:e,onSaved:t,trigger:n,sessionId:r,sessionDirectives:i,onDirectivesSaved:a}){var j;const s=ua(),[c,u]=b.useState({}),[f,h]=b.useState(!1),[p,g]=b.useState(!1),[v,w]=b.useState([]),[y,E]=b.useState(!1),k=b.useRef({});b.useEffect(()=>{f&&e().then(M=>{M&&(fetch("/api/config",{headers:{Authorization:`Bearer ${M}`}}).then(B=>B.json()).then(B=>{k.current=B;const R=r?i:void 0;u({...B,...(R==null?void 0:R.engine)!==void 0?{engine:R.engine}:{},...(R==null?void 0:R.model)!==void 0?{model:R.model}:{},...(R==null?void 0:R.turns)!==void 0?{maxTurns:R.turns}:{},...(R==null?void 0:R.thinking)!==void 0?{thinking:R.thinking}:{}})}).catch(()=>{}),fetch("/api/engines",{headers:{Authorization:`Bearer ${M}`}}).then(B=>B.json()).then(B=>{w(B.engines??[]),E(B.multiEngine??!1)}).catch(()=>{}))})},[f,e,r,i]);const O=async()=>{g(!0);const B={Authorization:`Bearer ${await e()??""}`,"Content-Type":"application/json"};try{if(r){const R={engine:c.engine,model:c.model,turns:c.maxTurns,thinking:c.thinking},H=await fetch(`/api/sessions/${r}/directives`,{method:"PUT",headers:B,body:JSON.stringify(R)}).then(K=>K.json()).catch(K=>(console.warn("[config] directives save failed",K),null));H!=null&&H.directives&&(a==null||a(H.directives));const Y={...c,engine:k.current.engine,model:k.current.model,maxTurns:k.current.maxTurns,thinking:k.current.thinking};await fetch("/api/config",{method:"PUT",headers:B,body:JSON.stringify(Y)}),t==null||t(Y)}else await fetch("/api/config",{method:"PUT",headers:B,body:JSON.stringify(c)}),t==null||t(c);h(!1)}finally{g(!1)}},A=c.engine||"claude-code",C=v.find(M=>M.name===A),I=(C==null?void 0:C.models)??i1e;b.useEffect(()=>{!C||!I.length||I.some(M=>(M.value||"")===(c.model??""))||u(M=>({...M,model:I[0].value||void 0}))},[C,I,c.model]);const D=I.some(M=>M.provider)?Array.from(I.reduce((M,B)=>{const R=B.provider||"default";return M.has(R)||M.set(R,[]),M.get(R).push(B),M},new Map)):null,P="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2";return _.jsxs(sl,{open:f,onOpenChange:h,children:[_.jsx(Ng,{asChild:!0,children:n||_.jsx(Pe,{variant:"ghost",size:"icon",title:"Agent Config",children:_.jsx(I7,{className:"w-4 h-4"})})}),_.jsxs(es,{className:"max-w-lg",children:[_.jsx(Gc,{children:_.jsx(ll,{children:"Agent Configuration"})}),_.jsxs(Fj,{className:"space-y-4",children:[r&&_.jsxs("p",{className:"text-xs text-muted-foreground rounded-md bg-muted/50 px-3 py-2",children:["Engine, Model, Max Turns & Thinking apply to ",_.jsx("strong",{children:"this conversation"}),". Other settings are global defaults for new sessions."]}),y&&_.jsxs("div",{children:[_.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Engine"}),_.jsx("select",{value:c.engine??"",onChange:M=>{const B=M.target.value||void 0;u(R=>({...R,engine:B,model:void 0}))},className:P,children:v.map(M=>_.jsx("option",{value:M.name,children:M.name==="claude-code"?"Claude Code (default)":M.name},M.name))})]}),_.jsxs("div",{children:[_.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Model"}),_.jsx("select",{value:c.model??"",onChange:M=>u(B=>({...B,model:M.target.value||void 0})),className:P,children:D?D.map(([M,B])=>_.jsx("optgroup",{label:M.charAt(0).toUpperCase()+M.slice(1),children:B.map(R=>_.jsx("option",{value:R.value,children:R.label},R.value))},M)):I.map(M=>_.jsx("option",{value:M.value,children:M.label},M.value))})]}),(j=s.settingsSections)==null?void 0:j.call(s,{getToken:e,sessionId:r}),_.jsxs("div",{children:[_.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Permission Mode"}),_.jsx("select",{value:c.permissionMode??"acceptEdits",onChange:M=>u(B=>({...B,permissionMode:M.target.value})),className:P,children:a1e.map(M=>_.jsx("option",{value:M.value,children:M.label},M.value))})]}),_.jsxs("div",{children:[_.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Max Turns"}),_.jsx(Un,{type:"number",min:1,max:200,value:c.maxTurns??50,onChange:M=>u(B=>({...B,maxTurns:Number(M.target.value)||50}))})]}),_.jsxs("div",{children:[_.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Thinking"}),_.jsxs("select",{value:c.thinking??"",onChange:M=>u(B=>({...B,thinking:M.target.value||void 0})),className:P,children:[_.jsx("option",{value:"",children:"Default (off)"}),_.jsx("option",{value:"adaptive",children:"Adaptive (Claude decides)"}),_.jsx("option",{value:"enabled",children:"Enabled (always think)"}),_.jsx("option",{value:"disabled",children:"Disabled"})]})]}),_.jsxs("div",{children:[_.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Effort"}),_.jsxs("select",{value:c.effort??"",onChange:M=>u(B=>({...B,effort:M.target.value||void 0})),className:P,children:[_.jsx("option",{value:"",children:"Default"}),_.jsx("option",{value:"low",children:"Low — fast"}),_.jsx("option",{value:"medium",children:"Medium"}),_.jsx("option",{value:"high",children:"High"}),_.jsx("option",{value:"max",children:"Max"})]})]}),_.jsxs("div",{children:[_.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Allowed Tools"}),_.jsx(Un,{placeholder:"Read, Edit, Bash, WebSearch, Glob, LS",value:(c.allowedTools??[]).join(", "),onChange:M=>u(B=>({...B,allowedTools:M.target.value.split(",").map(R=>R.trim()).filter(Boolean)}))}),_.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Comma-separated list of tools Claude can use"})]}),_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("label",{className:"text-sm font-medium",children:"Skill Discovery"}),_.jsx("p",{className:"text-xs text-muted-foreground",children:"Index all skills + auto-inject on trigger match"})]}),_.jsx("button",{type:"button",role:"switch","aria-checked":c.skillDiscovery!==!1,onClick:()=>u(M=>({...M,skillDiscovery:M.skillDiscovery===!1})),className:`relative inline-flex h-6 w-11 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors ${c.skillDiscovery!==!1?"bg-primary":"bg-muted"}`,children:_.jsx("span",{className:`pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform ${c.skillDiscovery!==!1?"translate-x-5":"translate-x-0"}`})})]}),_.jsxs("div",{children:[_.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"System Prompt (optional)"}),_.jsx(bv,{placeholder:"Additional instructions appended to Claude's system prompt…",value:c.systemPrompt??"",onChange:M=>u(B=>({...B,systemPrompt:M.target.value||void 0})),rows:4})]})]}),_.jsx(Hj,{children:_.jsx(Pe,{onClick:O,disabled:p,children:p?"Saving…":"Save Configuration"})})]})]})}function s1e({sessionId:e,config:t,sessionDirectives:n,actualModel:r,scheduleId:i,onScheduleClick:a}){const[s,c]=b.useState(!1),u=(n==null?void 0:n.engine)||t.engine||"claude-code",f=r?!r.includes("/"):void 0,h=u==="claude-code"||u==="cursor",g=(f!==void 0&&f===h?r:void 0)||(n==null?void 0:n.model)||t.model||(u==="cursor"?"cursor/composer-2.5":"sonnet-4-6"),v=h?g.replace("claude-",""):`${u} · ${g.replace("claude-","")}`,w=t.permissionMode||"acceptEdits",y=w==="bypassPermissions"?"bypass":w==="plan"?"plan":w==="default"?"prompt":"edits",E=(n==null?void 0:n.thinking)||t.thinking,k=()=>{e&&(navigator.clipboard.writeText(e),c(!0),setTimeout(()=>c(!1),1500))};return _.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[_.jsx("span",{className:"inline-flex items-center rounded-md bg-blue-50 px-1.5 py-0.5 text-[10px] font-medium text-blue-700 ring-1 ring-inset ring-blue-600/20 dark:bg-blue-950/50 dark:text-blue-300 dark:ring-blue-400/30",children:v}),_.jsx("span",{className:"inline-flex items-center rounded-md bg-amber-50 px-1.5 py-0.5 text-[10px] font-medium text-amber-700 ring-1 ring-inset ring-amber-600/20 dark:bg-amber-950/50 dark:text-amber-300 dark:ring-amber-400/30",children:y}),_.jsxs("span",{className:"inline-flex items-center rounded-md bg-green-50 px-1.5 py-0.5 text-[10px] font-medium text-green-700 ring-1 ring-inset ring-green-600/20 dark:bg-green-950/50 dark:text-green-300 dark:ring-green-400/30",children:[(n==null?void 0:n.turns)??t.maxTurns??50," steps"]}),E&&E!=="disabled"&&_.jsx("span",{className:"inline-flex items-center rounded-md bg-violet-50 px-1.5 py-0.5 text-[10px] font-medium text-violet-700 ring-1 ring-inset ring-violet-600/20 dark:bg-violet-950/50 dark:text-violet-300 dark:ring-violet-400/30",children:"think"}),e&&_.jsxs("button",{onClick:k,className:"inline-flex items-center gap-0.5 rounded-md bg-muted px-1.5 py-0.5 text-[10px] font-mono text-muted-foreground ring-1 ring-inset ring-border hover:bg-accent transition-colors",title:`Session: ${e}
1940
1940
  Click to copy`,children:[e.slice(0,8),s?_.jsx(Va,{className:"w-2.5 h-2.5"}):_.jsx(Bw,{className:"w-2.5 h-2.5"})]}),i&&_.jsxs("button",{onClick:a,className:"inline-flex items-center gap-0.5 rounded-md bg-purple-50 px-1.5 py-0.5 text-[10px] font-mono text-purple-700 ring-1 ring-inset ring-purple-600/20 dark:bg-purple-950/50 dark:text-purple-300 dark:ring-purple-400/30 hover:bg-purple-100 dark:hover:bg-purple-950/70 transition-colors",title:"Open schedule details",children:[_.jsx(zw,{className:"w-2.5 h-2.5"}),i.slice(0,8)]})]})}function l1e({sessionId:e,agentConfig:t,sessionDirectives:n,sessionLastModel:r,sessionScheduleId:i,artifactCount:a,getToken:s,onConfigSaved:c,onDirectivesSaved:u,onFork:f,onToggleArtifacts:h,onScheduleClick:p}){return _.jsxs("div",{className:"flex items-center gap-1.5 px-2 sm:px-3 py-1.5 border-b bg-background/60 overflow-x-auto",children:[_.jsx(s1e,{sessionId:e,config:t,sessionDirectives:n,actualModel:r,scheduleId:i,onScheduleClick:p}),_.jsx("div",{className:"flex-1"}),e&&_.jsx(Pe,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:f,title:"Fork conversation",children:_.jsx(w2,{className:"w-3.5 h-3.5"})}),_.jsx(o1e,{getToken:s,onSaved:c,sessionId:e,sessionDirectives:n,onDirectivesSaved:u}),a>0&&_.jsx(Pe,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:h,title:"Toggle artifacts panel",children:_.jsx(E7,{className:"w-3.5 h-3.5"})})]})}function c1e({nodeId:e,sessionId:t}){var U;const n=Lw(),r=ua(),i=b.useRef(null),[a,s]=b.useState(),[c,u]=b.useState([]),f=b.useRef(void 0),[h,p]=b.useState(t),g=b.useRef(h);g.current=h;const v=b.useRef(t).current,[w,y]=b.useState(),[E,k]=b.useState(),[O,A]=b.useState(),[C,I]=b.useState(!1),T=dee(h,n.getToken,n.token),D=b.useRef(!1),P=b.useCallback(G=>{n.bumpSidebar(),G!==g.current&&(p(G),n.assignSession(e,G))},[n,e]),j=b.useCallback(G=>{G.type==="artifact"?G.sessionId===g.current&&T.handleArtifactEvent(G):G.type==="directives"?D.current&&A(void 0):G.type==="model_resolved"&&G.sessionId===g.current&&A(G.model)},[n,e,T]),M=cee(n.socket,{getToken:n.getToken,initialSessionId:t,onNewSession:P,onDirectivesChanged:y,onParticipantsChanged:I,onEvent:j});D.current=M.busy,b.useEffect(()=>{if(!v)return;let G=!1;return(async()=>{try{const ee=await(await Ks(`/api/sessions/${v}/messages`,n.getToken)).json();if(G)return;M.setMessages(g2(ee)),I(Array.isArray(ee.participants)&&ee.participants.length>1),ee.busy&&M.setBusy(!0)}catch(q){G||console.error("[pane] history load failed:",q)}})(),()=>{G=!0}},[v]),b.useEffect(()=>{if(!h){y(void 0),k(void 0),A(void 0);return}Ks(`/api/sessions/${h}/meta`,n.getToken).then(G=>G.json()).then(G=>{y(G.directives),k(G.scheduleId),A(G.lastModel),G.runStatus==="running"&&M.setBusy(!0)}).catch(()=>{})},[h,n.getToken]);const B=b.useCallback((G,q,ee)=>{var L;M.sendMessage(G,g.current,ee,q,(L=f.current)==null?void 0:L.call(f))},[M]),R={sessionId:h,busy:M.busy,socket:n.socket,getToken:n.getToken,setInputCtx:s,setSendOptions:G=>{f.current=G},setInputText:G=>{var q;return(q=i.current)==null?void 0:q.setText(G)},send:(G,q,ee)=>M.sendMessage(G,g.current,void 0,void 0,q,(ee==null?void 0:ee.echo)!==!1),appendAssistant:G=>M.setMessages(q=>q.concat({id:Yo(),role:"assistant",blocks:G})),setStatusItems:u},H=b.useCallback(async G=>{const q=await n.getToken();if(!q)return null;try{return await(await fetch("/api/upload",{method:"POST",headers:{Authorization:`Bearer ${q}`,"x-filename":encodeURIComponent(G.name),"Content-Type":G.type||"application/octet-stream","x-session-id":g.current||""},body:G})).json()}catch(ee){return console.error("[upload] Failed:",ee),null}},[n]),Y=b.useCallback(async G=>{const q=g.current;if(!q)return;const ee=await n.getToken();if(ee)try{const L=await fetch(`/api/sessions/${q}/fork`,{method:"POST",headers:{Authorization:`Bearer ${ee}`,"Content-Type":"application/json"},body:JSON.stringify(G!=null?{truncateAtIndex:G}:{})});if(!L.ok){console.error("[fork] server error:",(await L.json().catch(()=>({}))).error||L.status);return}const{sessionId:F}=await L.json();n.bumpSidebar(),n.openSession(F)}catch(L){console.error("[fork] failed:",L)}},[n]),K=b.useCallback((G,q,ee)=>{if(M.busy)return;const L=M.messages.findIndex(F=>F.id===G);L>=0&&M.setMessages(M.messages.slice(0,L)),B(q,L>=0?L:void 0,ee)},[M,B]);return _.jsxs("div",{className:"flex flex-col h-full min-h-0",children:[(U=r.conversationController)==null?void 0:U.call(r,R),_.jsx(l1e,{sessionId:h,agentConfig:n.agentConfig,sessionDirectives:w,sessionLastModel:O,sessionScheduleId:E,artifactCount:T.artifacts.length,getToken:n.getToken,onConfigSaved:n.setAgentConfig,onDirectivesSaved:y,onFork:()=>Y(),onToggleArtifacts:T.togglePanel,onScheduleClick:n.openSchedules}),_.jsxs("div",{className:"flex-1 flex min-h-0",children:[_.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[_.jsx(Uwe,{messages:M.messages,busy:M.busy,multiParticipant:C,connectionStatus:n.connectionStatus??void 0,onPermissionRespond:M.respondPermission,onQuestionRespond:M.respondQuestion,onReplay:K,onEdit:K,onFork:G=>Y(G),statusItems:c}),_.jsx(t1e,{ref:i,onSend:(G,q)=>B(G,void 0,q),onSteer:M.steer,onQueue:M.addToQueue,onRemoveQueued:M.removeFromQueue,queue:M.queue,onUpload:H,onCancel:M.cancel,disabled:!1,busy:M.busy,skills:n.skills,workspaceFiles:n.workspaceFiles,sessionId:h,inputCtx:a})]}),T.panelOpen&&T.artifacts.length>0&&h&&_.jsx(r1e,{artifacts:T.artifacts,selectedId:T.selectedId,sessionId:h,getToken:n.getToken,onSelect:T.selectArtifact,onClose:T.closePanel})]})]})}const u1e=()=>({command:"",args:[],env:{}});function JR({getToken:e,trigger:t}){const[n,r]=b.useState({}),[i,a]=b.useState(!1),[s,c]=b.useState(!1),[u,f]=b.useState(new Set),h=A=>f(C=>{const I=new Set(C);return I.has(A)?I.delete(A):I.add(A),I});b.useEffect(()=>{i&&e().then(A=>{A&&fetch("/api/mcps",{headers:{Authorization:`Bearer ${A}`}}).then(C=>{if(!C.ok)throw new Error(`HTTP ${C.status}`);return C.json()}).then(r).catch(C=>console.error("[McpManager] fetch failed",C))})},[i,e]);const p=async()=>{c(!0);const A=await e();try{await fetch("/api/mcps",{method:"PUT",headers:{Authorization:`Bearer ${A??""}`,"Content-Type":"application/json"},body:JSON.stringify(n)}),a(!1)}finally{c(!1)}},g=()=>{const A=`server-${Date.now()}`;r(C=>({...C,[A]:u1e()}))},v=A=>{r(C=>{const I={...C};return delete I[A],I})},w=(A,C,I)=>{r(T=>({...T,[A]:{...T[A],[C]:C==="args"?I.split(" "):I}}))},y=(A,C,I)=>{r(T=>{const D={...T[A].env},P=D[C]??"";return delete D[C],I.trim()&&(D[I.trim()]=P),{...T,[A]:{...T[A],env:D}}})},E=(A,C,I)=>{r(T=>({...T,[A]:{...T[A],env:{...T[A].env,[C]:I}}}))},k=(A,C)=>{r(I=>{const T={...I[A].env};return delete T[C],{...I,[A]:{...I[A],env:T}}})},O=A=>{const C=`KEY_${Date.now()}`;r(I=>({...I,[A]:{...I[A],env:{...I[A].env,[C]:""}}}))};return _.jsxs(sl,{open:i,onOpenChange:a,children:[_.jsx(Ng,{asChild:!0,children:t||_.jsx(Pe,{variant:"ghost",size:"icon",title:"MCP Servers",children:_.jsx(S2,{className:"w-4 h-4"})})}),_.jsxs(es,{className:"max-w-[95vw] sm:max-w-2xl",children:[_.jsx(Gc,{children:_.jsx(ll,{children:"MCP Servers"})}),_.jsxs(Fj,{className:"space-y-4",children:[Object.entries(n).map(([A,C])=>{const I=!!C.readonly;return _.jsxs("div",{className:`border rounded-lg p-4 space-y-3 ${I?"opacity-70":""}`,children:[_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("span",{className:"font-medium text-sm flex items-center gap-1.5",children:[I&&_.jsx(Gp,{className:"w-3 h-3 text-muted-foreground"}),A]}),!I&&_.jsx(Pe,{variant:"ghost",size:"icon",onClick:()=>v(A),children:_.jsx(hm,{className:"w-4 h-4 text-destructive"})})]}),I?_.jsx("p",{className:"text-xs text-muted-foreground",children:"Configured in shraga.config.ts"}):_.jsxs("div",{className:"grid gap-2",children:[_.jsx(Un,{placeholder:"Command (e.g. npx)",value:C.command,onChange:T=>w(A,"command",T.target.value)}),_.jsx(Un,{placeholder:"Args (space-separated)",value:(C.args||[]).join(" "),onChange:T=>w(A,"args",T.target.value)}),Object.entries(C.env||{}).length>0&&_.jsxs("div",{className:"space-y-2",children:[_.jsx("span",{className:"text-xs text-muted-foreground",children:"Environment variables"}),Object.entries(C.env||{}).map(([T,D])=>_.jsxs("div",{className:"flex gap-2 items-center",children:[_.jsx(Un,{className:"w-1/3 font-mono text-xs",value:T,onChange:P=>y(A,T,P.target.value),placeholder:"KEY"}),u.has(`${A}:${T}`)?_.jsx(Un,{className:"flex-1 font-mono text-xs",placeholder:"paste new value",autoFocus:!0,onChange:P=>E(A,T,P.target.value),onBlur:()=>h(`${A}:${T}`)}):_.jsx("span",{className:"flex-1 font-mono text-xs text-muted-foreground truncate cursor-pointer px-3 py-2 border rounded-md bg-background hover:border-ring",onClick:()=>h(`${A}:${T}`),title:"Click to change",children:D||"(empty — click to set)"}),_.jsx(Pe,{variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0",onClick:()=>k(A,T),children:_.jsx(hm,{className:"w-3 h-3 text-muted-foreground"})})]},T))]}),_.jsx(Pe,{variant:"ghost",size:"sm",className:"text-xs text-muted-foreground",onClick:()=>O(A),children:"+ Add env var"})]})]},A)}),Object.keys(n).length===0&&_.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No MCP servers configured"})]}),_.jsxs(Hj,{className:"flex gap-2",children:[_.jsxs(Pe,{variant:"outline",onClick:g,className:"gap-2",children:[_.jsx(xg,{className:"w-4 h-4"})," Add Server"]}),_.jsx(Pe,{onClick:p,disabled:s,children:s?"Saving…":"Save"})]})]})]})}function MS(e){return typeof e=="string"?e:e.name}function eD(e){return typeof e=="string"?!1:e.capped===!0||typeof e.capped=="number"&&e.capped>0}function Lf(e,t){return e.some(n=>MS(n)===t)}function tD(e,t){return e.find(n=>MS(n)===t)}async function ja(e,t,n){return fetch(e,{...n,headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json",...(n==null?void 0:n.headers)??{}}})}function nD({getToken:e,onSkillsChange:t,trigger:n}){const[r,i]=b.useState(!1),[a,s]=b.useState([]),[c,u]=b.useState([]),[f,h]=b.useState([]),[p,g]=b.useState(null),[v,w]=b.useState(""),[y,E]=b.useState(!1),[k,O]=b.useState(null),[A,C]=b.useState(""),I=p?c.includes(p):!1,T=async()=>{const K=await e();if(!K)return;const[U,G]=await Promise.all([ja("/api/skills",K),ja("/api/skills-defaults",K)]),q=await U.json(),ee=await G.json();s(q.skills),u(q.builtins),h(ee),t==null||t(q.skills)},D=async K=>{const U=await e();if(!U)return;const q=await(await ja(`/api/skills/${K}`,U)).json();w(q.content),g(K),E(!1)},P=async()=>{if(!p||I)return;const K=await e();K&&(await ja(`/api/skills/${p}`,K,{method:"PUT",body:JSON.stringify({content:v})}),E(!1))},j=async()=>{const K=A.trim().replace(/\s+/g,"-");if(!K)return;const U=await e();if(U){if(k==="create")await ja(`/api/skills/${K}`,U,{method:"PUT",body:JSON.stringify({content:""})}),await T(),await D(K);else if(k==="duplicate"&&p){if(!(await ja(`/api/skills/${p}/duplicate`,U,{method:"POST",body:JSON.stringify({newName:K})})).ok)return;await T(),await D(K)}else if(k==="rename"&&p){if(!(await ja(`/api/skills/${p}/rename`,U,{method:"POST",body:JSON.stringify({newName:K})})).ok)return;await T(),await D(K)}O(null),C("")}},M=async K=>{const U=await e();!U||!(await ja(`/api/skills/${K}`,U,{method:"DELETE"})).ok||(p===K&&(g(null),w("")),await T())},B=async K=>{const U=await e();if(!U)return;const G=Lf(f,K)?f.filter(q=>MS(q)!==K):[...f,K];await ja("/api/skills-defaults",U,{method:"PUT",body:JSON.stringify(G)}),h(G)},R=K=>{O(K),C(K==="rename"&&p?p:K==="duplicate"&&p?`${p}-copy`:"")},H=()=>{O(null),C("")};b.useEffect(()=>{r&&T()},[r]);const Y=k==="create"?"skill-name":k==="rename"?"new-name":"copy-name";return _.jsxs(sl,{open:r,onOpenChange:i,children:[_.jsx(Ng,{asChild:!0,children:n||_.jsx(Pe,{variant:"ghost",size:"icon",title:"Skills",className:"h-8 w-8",children:_.jsx(sx,{className:"w-4 h-4"})})}),_.jsxs(es,{className:"max-w-[95vw] sm:max-w-2xl h-[70dvh] sm:h-[520px] flex flex-col gap-0 p-0",children:[_.jsx(Gc,{className:"px-4 pt-4 pb-2 border-b shrink-0",children:_.jsxs(ll,{className:"flex items-center gap-2",children:[_.jsx(sx,{className:"w-4 h-4"})," Skills"]})}),_.jsxs("div",{className:"flex flex-col sm:flex-row flex-1 overflow-hidden",children:[_.jsxs("div",{className:`sm:w-52 border-r flex flex-col shrink-0 ${p?"hidden sm:flex":"flex"}`,children:[_.jsx("div",{className:"flex-1 overflow-y-auto py-1",children:a.map(K=>_.jsxs("div",{className:`group flex items-center gap-1.5 px-3 py-1.5 cursor-pointer text-sm hover:bg-accent transition-colors ${p===K?"bg-accent font-medium":""}`,onClick:()=>D(K),children:[_.jsx("button",{className:`shrink-0 transition-colors ${Lf(f,K)?"text-amber-500":"text-muted-foreground/30 hover:text-amber-400"}`,onClick:U=>{U.stopPropagation(),B(K)},title:Lf(f,K)?"Remove from defaults":"Set as default (always active)",children:_.jsx(iT,{className:`w-3 h-3 ${Lf(f,K)?"fill-current":""}`})}),_.jsxs("span",{className:"truncate flex-1",children:["@",K]}),c.includes(K)&&_.jsx("span",{title:"Built-in (read-only)",children:_.jsx(Gp,{className:"w-2.5 h-2.5 text-muted-foreground/40 shrink-0"})}),!c.includes(K)&&_.jsx("button",{className:"opacity-0 group-hover:opacity-100 text-muted-foreground hover:text-destructive transition-opacity shrink-0",onClick:U=>{U.stopPropagation(),M(K)},title:"Delete",children:_.jsx(hm,{className:"w-3 h-3"})})]},K))}),_.jsx("div",{className:"border-t p-2",children:k?_.jsxs("div",{className:"flex gap-1",children:[_.jsx(Un,{value:A,onChange:K=>C(K.target.value),onKeyDown:K=>{K.key==="Enter"&&j(),K.key==="Escape"&&H()},placeholder:Y,className:"h-7 text-xs",autoFocus:!0}),_.jsx(Pe,{size:"icon",className:"h-7 w-7 shrink-0",onClick:j,children:_.jsx(Va,{className:"w-3 h-3"})}),_.jsx(Pe,{size:"icon",variant:"ghost",className:"h-7 w-7 shrink-0",onClick:H,children:_.jsx(al,{className:"w-3 h-3"})})]}):_.jsxs(Pe,{variant:"outline",size:"sm",className:"w-full h-7 text-xs",onClick:()=>R("create"),children:[_.jsx(xg,{className:"w-3 h-3 mr-1"})," New skill"]})})]}),_.jsx("div",{className:`flex-1 flex flex-col overflow-hidden ${p?"":"hidden sm:flex"}`,children:p?_.jsxs(_.Fragment,{children:[_.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b text-sm shrink-0",children:[_.jsxs("div",{className:"flex items-center gap-0.5 font-medium",children:[_.jsx("button",{className:"sm:hidden mr-1.5 text-muted-foreground",onClick:()=>{g(null),w(""),E(!1)},children:_.jsx(x2,{className:"w-4 h-4"})}),_.jsx("span",{className:"text-muted-foreground",children:"@"}),_.jsx("span",{children:p})]}),_.jsxs("div",{className:"flex items-center gap-1.5",children:[I&&_.jsxs("span",{className:"text-[10px] text-muted-foreground bg-muted px-1.5 py-0.5 rounded font-medium flex items-center gap-0.5",children:[_.jsx(Gp,{className:"w-2.5 h-2.5"})," read-only"]}),Lf(f,p)&&_.jsxs(_.Fragment,{children:[_.jsx("span",{className:"text-[10px] text-amber-600 bg-amber-50 dark:bg-amber-950/50 dark:text-amber-400 px-1.5 py-0.5 rounded font-medium",children:"default"}),_.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium ${eD(tD(f,p))?"text-blue-600 bg-blue-50 dark:bg-blue-950/50 dark:text-blue-400":"text-emerald-600 bg-emerald-50 dark:bg-emerald-950/50 dark:text-emerald-400"}`,children:eD(tD(f,p))?"capped":"full"})]}),_.jsx(Pe,{variant:"ghost",size:"sm",className:"h-6 text-xs px-1.5",onClick:()=>R("duplicate"),title:"Duplicate",children:_.jsx(Bw,{className:"w-3 h-3"})}),!I&&_.jsx(Pe,{variant:"ghost",size:"sm",className:"h-6 text-xs px-1.5",onClick:()=>R("rename"),title:"Rename",children:_.jsx(Hw,{className:"w-3 h-3"})}),y&&!I&&_.jsxs(Pe,{size:"sm",className:"h-6 text-xs",onClick:P,children:[_.jsx(Va,{className:"w-3 h-3 mr-1"})," Save"]})]})]}),_.jsx(bv,{value:v,onChange:K=>{I||(w(K.target.value),E(!0))},readOnly:I,className:`flex-1 resize-none rounded-none border-0 font-mono text-xs focus-visible:ring-0 ${I?"opacity-70 cursor-default":""}`,placeholder:"Write the skill instructions here…"})]}):_.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center text-muted-foreground text-sm gap-1",children:[_.jsx("p",{children:"Select or create a skill"}),_.jsxs("p",{className:"text-xs",children:[_.jsx(iT,{className:"w-3 h-3 inline fill-amber-500 text-amber-500"})," = injected in every conversation"]}),_.jsxs("p",{className:"text-xs",children:[_.jsx(Gp,{className:"w-3 h-3 inline"})," = built-in, duplicate to customize"]})]})})]})]})]})}async function Bs(e,t,n){const r=await t(),i=await fetch(e,{...n,headers:{Authorization:`Bearer ${r??""}`,"Content-Type":"application/json",...n==null?void 0:n.headers}});if(!i.ok){const a=await i.json().catch(()=>({}));throw new Error(a.error||`${i.status} ${i.statusText}`)}return i.json()}function f1e(e,t,n=0){const[r,i]=b.useState([]),[a,s]=b.useState(new Set),[c,u]=b.useState(!1),[f,h]=b.useState(null),p=b.useCallback(async()=>{u(!0),h(null);try{const O=await Bs("/api/schedules",e);i(O.schedules),s(new Set(O.runningIds))}catch(O){h(O.message)}finally{u(!1)}},[e]);b.useEffect(()=>{t&&p()},[t,p,n]);const g=b.useCallback(async O=>{const A=await Bs("/api/schedules",e,{method:"POST",body:JSON.stringify(O)});return await p(),A},[e,p]),v=b.useCallback(async(O,A)=>{const C=await Bs(`/api/schedules/${O}`,e,{method:"PUT",body:JSON.stringify(A)});return await p(),C},[e,p]),w=b.useCallback(async O=>{await Bs(`/api/schedules/${O}`,e,{method:"DELETE"}),await p()},[e,p]),y=b.useCallback(async(O,A)=>{await Bs(`/api/schedules/${O}/toggle`,e,{method:"POST",body:JSON.stringify({enabled:A})}),await p()},[e,p]),E=b.useCallback(async(O,A)=>{const C=await Bs(`/api/schedules/${O}/run`,e,{method:"POST",body:JSON.stringify(A?{override:A}:{})});return await p(),C.sessionId},[e,p]),k=b.useCallback(async O=>{await Bs(`/api/schedules/${O}/cancel`,e,{method:"POST"}),await p()},[e,p]);return{schedules:r,serverRunningIds:a,loading:c,error:f,refresh:p,create:g,update:v,remove:w,toggle:y,runNow:E,cancelRun:k}}var X0={exports:{}},rD;function d1e(){return rD||(rD=1,(function(e,t){(function(r,i){e.exports=i()})(globalThis,()=>(()=>{var n={949(s,c,u){Object.defineProperty(c,"__esModule",{value:!0}),c.CronParser=void 0;var f=u(515),h=(function(){function p(g,v,w){v===void 0&&(v=!0),w===void 0&&(w=!1),this.expression=g,this.dayOfWeekStartIndexZero=v,this.monthStartIndexZero=w}return p.prototype.parse=function(){var g,v,w=(g=this.expression)!==null&&g!==void 0?g:"";if(w==="@reboot")return v=["@reboot","","","","","",""],v;if(w.startsWith("@")){var y=this.parseSpecial(this.expression);v=this.extractParts(y)}else v=this.extractParts(this.expression);return this.normalize(v),this.validate(v),v},p.prototype.parseSpecial=function(g){var v={"@yearly":"0 0 1 1 *","@annually":"0 0 1 1 *","@monthly":"0 0 1 * *","@weekly":"0 0 * * 0","@daily":"0 0 * * *","@midnight":"0 0 * * *","@hourly":"0 * * * *","@reboot":"@reboot"},w=v[g];if(!w)throw new Error("Unknown special expression.");return w},p.prototype.extractParts=function(g){if(!this.expression)throw new Error("cron expression is empty");for(var v=g.trim().split(/[ ]+/),w=0;w<v.length;w++)if(v[w].includes(",")){var y=v[w].split(",").map(function(k){return k.trim()}).filter(function(k){return k!==""}).map(function(k){return isNaN(Number(k))?k:Number(k)}).filter(function(k){return k!==null&&k!==""});y.length===0&&y.push("*"),y.sort(function(k,O){return k!==null&&O!==null?k-O:0}),v[w]=y.map(function(k){return k!==null?k.toString():""}).join(",")}if(v.length<5)throw new Error("Expression has only ".concat(v.length," part").concat(v.length==1?"":"s",". At least 5 parts are required."));if(v.length==5)v.unshift(""),v.push("");else if(v.length==6){var E=/\d{4}$/.test(v[5])||v[4]=="?"||v[2]=="?";E?v.unshift(""):v.push("")}else if(v.length>7)throw new Error("Expression has ".concat(v.length," parts; too many!"));return v},p.prototype.normalize=function(g){var v=this;if(g[3]=g[3].replace("?","*"),g[5]=g[5].replace("?","*"),g[2]=g[2].replace("?","*"),g[0].indexOf("0/")==0&&(g[0]=g[0].replace("0/","*/")),g[1].indexOf("0/")==0&&(g[1]=g[1].replace("0/","*/")),g[2].indexOf("0/")==0&&(g[2]=g[2].replace("0/","*/")),g[3].indexOf("1/")==0&&(g[3]=g[3].replace("1/","*/")),g[4].indexOf("1/")==0&&(g[4]=g[4].replace("1/","*/")),g[6].indexOf("1/")==0&&(g[6]=g[6].replace("1/","*/")),g[5]=g[5].replace(/(^\d)|([^#/\s]\d)/g,function(I){var T=I.replace(/\D/,""),D=T;return v.dayOfWeekStartIndexZero?T=="7"&&(D="0"):D=(parseInt(T)-1).toString(),I.replace(T,D)}),g[5]=="L"&&(g[5]="6"),g[3]=="?"&&(g[3]="*"),g[3].indexOf("W")>-1&&(g[3].indexOf(",")>-1||g[3].indexOf("-")>-1))throw new Error("The 'W' character can be specified only when the day-of-month is a single day, not a range or list of days.");var w={SUN:0,MON:1,TUE:2,WED:3,THU:4,FRI:5,SAT:6};for(var y in w)g[5]=g[5].replace(new RegExp(y,"gi"),w[y].toString());g[4]=g[4].replace(/(^\d{1,2})|([^#/\s]\d{1,2})/g,function(I){var T=I.replace(/\D/,""),D=T;return v.monthStartIndexZero&&(D=(parseInt(T)+1).toString()),I.replace(T,D)});var E={JAN:1,FEB:2,MAR:3,APR:4,MAY:5,JUN:6,JUL:7,AUG:8,SEP:9,OCT:10,NOV:11,DEC:12};for(var k in E)g[4]=g[4].replace(new RegExp(k,"gi"),E[k].toString());g[0]=="0"&&(g[0]=""),!/\*|\-|\,|\//.test(g[2])&&(/\*|\//.test(g[1])||/\*|\//.test(g[0]))&&(g[2]+="-".concat(g[2]));for(var O=0;O<g.length;O++)if(g[O].indexOf(",")!=-1&&(g[O]=g[O].split(",").filter(function(I){return I!==""}).join(",")||"*"),g[O]=="*/1"&&(g[O]="*"),g[O].indexOf("/")>-1&&!/^\*|\-|\,/.test(g[O])){var A=null;switch(O){case 4:A="12";break;case 5:A="6";break;case 6:A="9999";break;default:A=null;break}if(A!==null){var C=g[O].split("/");g[O]="".concat(C[0],"-").concat(A,"/").concat(C[1])}}},p.prototype.validate=function(g){var v="0-9,\\-*/";this.validateOnlyExpectedCharactersFound(g[0],v),this.validateOnlyExpectedCharactersFound(g[1],v),this.validateOnlyExpectedCharactersFound(g[2],v),this.validateOnlyExpectedCharactersFound(g[3],"0-9,\\-*/LW"),this.validateOnlyExpectedCharactersFound(g[4],v),this.validateOnlyExpectedCharactersFound(g[5],"0-9,\\-*/L#"),this.validateOnlyExpectedCharactersFound(g[6],v),this.validateAnyRanges(g)},p.prototype.validateAnyRanges=function(g){f.default.secondRange(g[0]),f.default.minuteRange(g[1]),f.default.hourRange(g[2]),f.default.dayOfMonthRange(g[3]),f.default.monthRange(g[4],this.monthStartIndexZero),f.default.dayOfWeekRange(g[5],this.dayOfWeekStartIndexZero)},p.prototype.validateOnlyExpectedCharactersFound=function(g,v){var w=g.match(new RegExp("[^".concat(v,"]+"),"gi"));if(w&&w.length)throw new Error("Expression contains invalid values: '".concat(w.toString(),"'"))},p})();c.CronParser=h},333(s,c,u){Object.defineProperty(c,"__esModule",{value:!0}),c.ExpressionDescriptor=void 0;var f=u(823),h=u(949),p=(function(){function g(v,w){if(this.expression=v,this.options=w,this.expressionParts=new Array(5),!this.options.locale&&g.defaultLocale&&(this.options.locale=g.defaultLocale),!g.locales[this.options.locale]){var y=Object.keys(g.locales)[0];console.warn("Locale '".concat(this.options.locale,"' could not be found; falling back to '").concat(y,"'.")),this.options.locale=y}this.i18n=g.locales[this.options.locale],w.use24HourTimeFormat===void 0&&(w.use24HourTimeFormat=this.i18n.use24HourTimeFormatByDefault())}return g.toString=function(v,w){var y=w===void 0?{}:w,E=y.throwExceptionOnParseError,k=E===void 0?!0:E,O=y.verbose,A=O===void 0?!1:O,C=y.dayOfWeekStartIndexZero,I=C===void 0?!0:C,T=y.monthStartIndexZero,D=T===void 0?!1:T,P=y.use24HourTimeFormat,j=y.trimHoursLeadingZero,M=j===void 0?!1:j,B=y.locale,R=B===void 0?null:B,H=y.logicalAndDayFields,Y=H===void 0?!1:H,K={throwExceptionOnParseError:k,verbose:A,dayOfWeekStartIndexZero:I,monthStartIndexZero:D,use24HourTimeFormat:P,trimHoursLeadingZero:M,locale:R,logicalAndDayFields:Y};K.tzOffset&&console.warn("'tzOffset' option has been deprecated and is no longer supported.");var U=new g(v,K);return U.getFullDescription()},g.initialize=function(v,w){w===void 0&&(w="en"),g.specialCharacters=["/","-",",","*"],g.defaultLocale=w,v.load(g.locales)},g.prototype.getFullDescription=function(){var v,w,y="";try{var E=new h.CronParser(this.expression,this.options.dayOfWeekStartIndexZero,this.options.monthStartIndexZero);if(this.expressionParts=E.parse(),this.expressionParts[0]==="@reboot")return((w=(v=this.i18n).atReboot)===null||w===void 0?void 0:w.call(v))||"Run once, at startup";var k=this.getTimeOfDayDescription(),O=this.getDayOfMonthDescription(),A=this.getMonthDescription(),C=this.getDayOfWeekDescription(),I=this.getYearDescription();y+=k+O+C+A+I,y=this.transformVerbosity(y,!!this.options.verbose),y=y.charAt(0).toLocaleUpperCase()+y.substr(1)}catch(T){if(!this.options.throwExceptionOnParseError)y=this.i18n.anErrorOccuredWhenGeneratingTheExpressionD();else throw"".concat(T)}return y},g.prototype.getTimeOfDayDescription=function(){var v=this.expressionParts[0],w=this.expressionParts[1],y=this.expressionParts[2],E="";if(!f.StringUtilities.containsAny(w,g.specialCharacters)&&!f.StringUtilities.containsAny(y,g.specialCharacters)&&!f.StringUtilities.containsAny(v,g.specialCharacters))E+=this.i18n.atSpace()+this.formatTime(y,w,v);else if(!v&&w.indexOf("-")>-1&&!(w.indexOf(",")>-1)&&!(w.indexOf("/")>-1)&&!f.StringUtilities.containsAny(y,g.specialCharacters)){var k=w.split("-");E+=f.StringUtilities.format(this.i18n.everyMinuteBetweenX0AndX1(),this.formatTime(y,k[0],""),this.formatTime(y,k[1],""))}else if(!v&&y.indexOf(",")>-1&&y.indexOf("-")==-1&&y.indexOf("/")==-1&&!f.StringUtilities.containsAny(w,g.specialCharacters)){var O=y.split(",");E+=this.i18n.at();for(var A=0;A<O.length;A++)E&&(E+=" "),E+=this.formatTime(O[A],w,""),A<O.length-2&&(E+=","),A==O.length-2&&(E+=this.i18n.spaceAnd())}else{var C=this.getSecondsDescription(),I=this.getMinutesDescription(),T=this.getHoursDescription();if(E+=C,E&&I&&(E+=", "),E+=I,I===T)return E;E&&T&&(E+=", "),E+=T}return E},g.prototype.getSecondsDescription=function(){var v=this,w=this.getSegmentDescription(this.expressionParts[0],this.i18n.everySecond(),function(y){return y},function(y){return f.StringUtilities.format(v.i18n.everyX0Seconds(y),y)},function(y){return v.i18n.secondsX0ThroughX1PastTheMinute()},function(y){return y=="0"?"":parseInt(y)<20?v.i18n.atX0SecondsPastTheMinute(y):v.i18n.atX0SecondsPastTheMinuteGt20()||v.i18n.atX0SecondsPastTheMinute(y)});return w},g.prototype.getMinutesDescription=function(){var v=this,w=this.expressionParts[0],y=this.expressionParts[2],E=this.getSegmentDescription(this.expressionParts[1],this.i18n.everyMinute(),function(k){return k},function(k){return f.StringUtilities.format(v.i18n.everyX0Minutes(k),k)},function(k){return v.i18n.minutesX0ThroughX1PastTheHour()},function(k){var O,A;try{return k=="0"&&y.indexOf("/")==-1&&w==""?v.i18n.everyHour():k=="0"?((A=(O=v.i18n).onTheHour)===null||A===void 0?void 0:A.call(O))||v.i18n.atX0MinutesPastTheHour(k):parseInt(k)<20?v.i18n.atX0MinutesPastTheHour(k):v.i18n.atX0MinutesPastTheHourGt20()||v.i18n.atX0MinutesPastTheHour(k)}catch{return v.i18n.atX0MinutesPastTheHour(k)}});return E},g.prototype.getHoursDescription=function(){var v=this,w=this.expressionParts[2],y=0,E=[];w.split("/")[0].split(",").forEach(function(A){var C=A.split("-");C.length===2&&E.push({value:C[1],index:y+1}),y+=C.length});var k=0,O=this.getSegmentDescription(w,this.i18n.everyHour(),function(A){var C=E.find(function(T){return T.value===A&&T.index===k}),I=C&&v.expressionParts[1]!=="0";return k++,I?v.formatTime(A,"59",""):v.formatTime(A,"0","")},function(A){return f.StringUtilities.format(v.i18n.everyX0Hours(A),A)},function(A){return v.i18n.betweenX0AndX1()},function(A){return v.i18n.atX0()});return O},g.prototype.getDayOfWeekDescription=function(){var v=this,w=this.i18n.daysOfTheWeek(),y=null;return this.expressionParts[5]=="*"?y="":y=this.getSegmentDescription(this.expressionParts[5],this.i18n.commaEveryDay(),function(E,k){var O=E;E.indexOf("#")>-1?O=E.substring(0,E.indexOf("#")):E.indexOf("L")>-1&&(O=O.replace("L",""));var A=parseInt(O),C=v.i18n.daysOfTheWeekInCase?v.i18n.daysOfTheWeekInCase(k)[A]:w[A];if(E.indexOf("#")>-1){var I=null,T=E.substring(E.indexOf("#")+1),D=E.substring(0,E.indexOf("#"));switch(T){case"1":I=v.i18n.first(D);break;case"2":I=v.i18n.second(D);break;case"3":I=v.i18n.third(D);break;case"4":I=v.i18n.fourth(D);break;case"5":I=v.i18n.fifth(D);break}C=I+" "+C}return C},function(E){return parseInt(E)==1?"":f.StringUtilities.format(v.i18n.commaEveryX0DaysOfTheWeek(E),E)},function(E){var k=E.substring(0,E.indexOf("-")),O=v.expressionParts[3]!="*";return O?v.i18n.commaAndX0ThroughX1(k):v.i18n.commaX0ThroughX1(k)},function(E){var k=null;if(E.indexOf("#")>-1){var O=E.substring(E.indexOf("#")+1),A=E.substring(0,E.indexOf("#"));k=v.i18n.commaOnThe(O,A).trim()+v.i18n.spaceX0OfTheMonth()}else if(E.indexOf("L")>-1)k=v.i18n.commaOnTheLastX0OfTheMonth(E.replace("L",""));else{var C=v.expressionParts[3]!="*";C?v.options.logicalAndDayFields?k=v.i18n.commaOnlyOnX0(E):k=v.i18n.commaAndOnX0():k=v.i18n.commaOnlyOnX0(E)}return k}),y},g.prototype.getMonthDescription=function(){var v=this,w=this.i18n.monthsOfTheYear(),y=this.getSegmentDescription(this.expressionParts[4],"",function(E,k){return k&&v.i18n.monthsOfTheYearInCase?v.i18n.monthsOfTheYearInCase(k)[parseInt(E)-1]:w[parseInt(E)-1]},function(E){return parseInt(E)==1?"":f.StringUtilities.format(v.i18n.commaEveryX0Months(E),E)},function(E){return v.i18n.commaMonthX0ThroughMonthX1()||v.i18n.commaX0ThroughX1()},function(E){return v.i18n.commaOnlyInMonthX0?v.i18n.commaOnlyInMonthX0():v.i18n.commaOnlyInX0()});return y},g.prototype.getDayOfMonthDescription=function(){var v=this,w=null,y=this.expressionParts[3];switch(y){case"L":w=this.i18n.commaOnTheLastDayOfTheMonth();break;case"WL":case"LW":w=this.i18n.commaOnTheLastWeekdayOfTheMonth();break;default:var E=y.match(/(\d{1,2}W)|(W\d{1,2})/);if(E){var k=parseInt(E[0].replace("W","")),O=k==1?this.i18n.firstWeekday():f.StringUtilities.format(this.i18n.weekdayNearestDayX0(),k.toString());w=f.StringUtilities.format(this.i18n.commaOnTheX0OfTheMonth(),O);break}else{var A=y.match(/L-(\d{1,2})/);if(A){var C=A[1];w=f.StringUtilities.format(this.i18n.commaDaysBeforeTheLastDayOfTheMonth(C),C);break}else{if(y=="*"&&this.expressionParts[5]!="*")return"";w=this.getSegmentDescription(y,this.i18n.commaEveryDay(),function(I){return I=="L"?v.i18n.lastDay():v.i18n.dayX0?f.StringUtilities.format(v.i18n.dayX0(),I):I},function(I){return I=="1"?v.i18n.commaEveryDay():v.i18n.commaEveryX0Days(I)},function(I){return v.i18n.commaBetweenDayX0AndX1OfTheMonth(I)},function(I){return v.i18n.commaOnDayX0OfTheMonth(I)})}break}}return w},g.prototype.getYearDescription=function(){var v=this,w=this.getSegmentDescription(this.expressionParts[6],"",function(y){return/^\d+$/.test(y)?new Date(parseInt(y),1).getFullYear().toString():y},function(y){return f.StringUtilities.format(v.i18n.commaEveryX0Years(y),y)},function(y){return v.i18n.commaYearX0ThroughYearX1()||v.i18n.commaX0ThroughX1()},function(y){return v.i18n.commaOnlyInYearX0?v.i18n.commaOnlyInYearX0():v.i18n.commaOnlyInX0()});return w},g.prototype.getSegmentDescription=function(v,w,y,E,k,O){var A=null,C=v.indexOf("/")>-1,I=v.indexOf("-")>-1,T=v.indexOf(",")>-1;if(!v)A="";else if(v==="*")A=w;else if(!C&&!I&&!T)A=f.StringUtilities.format(O(v),y(v));else if(T){for(var D=v.split(","),P="",j=this.i18n.spaceAnd(),M=0;M<D.length;M++)if(M>0&&D.length>2&&(P+=",",M<D.length-1&&(P+=" ")),M>0&&D.length>1&&(M==D.length-1||D.length==2)&&(P+=j==","&&D.length>2?" ":"".concat(j," ")),D[M].indexOf("/")>-1||D[M].indexOf("-")>-1){var B=D[M].indexOf("-")>-1&&D[M].indexOf("/")==-1,R=this.getSegmentDescription(D[M],w,y,E,B?this.i18n.commaX0ThroughX1:k,O);B&&(R=R.replace(", ","")),P+=R}else if(!C)P+=y(D[M]);else{var H=this.getSegmentDescription(D[M],w,y,E,k,O);H&&H.startsWith(", ")&&(H=H.substring(2)),P+=H}C?A=P:A=f.StringUtilities.format(O(v),P)}else if(C){var D=v.split("/");if(A=f.StringUtilities.format(E(D[1]),D[1]),D[0].indexOf("-")>-1){var Y=this.generateRangeSegmentDescription(D[0],k,y);Y.indexOf(", ")!=0&&(A+=", "),A+=Y}else if(D[0].indexOf("*")==-1){var K=f.StringUtilities.format(O(D[0]),y(D[0]));K=K.replace(", ",""),A+=f.StringUtilities.format(this.i18n.commaStartingX0(),K)}}else I&&(A=this.generateRangeSegmentDescription(v,k,y));return A},g.prototype.generateRangeSegmentDescription=function(v,w,y){var E="",k=v.split("-"),O=y(k[0],1),A=y(k[1],2),C=w(v);return E+=f.StringUtilities.format(C,O,A),E},g.prototype.formatTime=function(v,w,y){var E=0,k=0,O=parseInt(v)+E,A=parseInt(w)+k;A>=60?(A-=60,O+=1):A<0&&(A+=60,O-=1),O>=24?O=O-24:O<0&&(O=24+O);var C="",I=!1;this.options.use24HourTimeFormat||(I=!!(this.i18n.setPeriodBeforeTime&&this.i18n.setPeriodBeforeTime()),C=I?"".concat(this.getPeriod(O)," "):" ".concat(this.getPeriod(O)),O>12&&(O-=12),O===0&&(O=12));var T="";y&&(T=":".concat(("00"+y).substring(y.length)));var D=O.toString(),P=("00"+D).substring(D.length),j=A.toString(),M=("00"+j).substring(j.length),B=this.options.trimHoursLeadingZero?D:P;return"".concat(I?C:"").concat(B,":").concat(M).concat(T).concat(I?"":C)},g.prototype.transformVerbosity=function(v,w){if(!w&&(v=v.replace(new RegExp(", ".concat(this.i18n.everyMinute()),"g"),""),v=v.replace(new RegExp(", ".concat(this.i18n.everyHour()),"g"),""),v=v.replace(new RegExp(this.i18n.commaEveryDay(),"g"),""),v=v.replace(/\, ?$/,""),this.i18n.conciseVerbosityReplacements))for(var y=0,E=Object.entries(this.i18n.conciseVerbosityReplacements());y<E.length;y++){var k=E[y],O=k[0],A=k[1];v=v.replace(new RegExp(O,"g"),A)}return v},g.prototype.getPeriod=function(v){return v>=12?this.i18n.pm&&this.i18n.pm()||"PM":this.i18n.am&&this.i18n.am()||"AM"},g.locales={},g})();c.ExpressionDescriptor=p},747(s,c,u){Object.defineProperty(c,"__esModule",{value:!0}),c.enLocaleLoader=void 0;var f=u(486),h=(function(){function p(){}return p.prototype.load=function(g){g.en=new f.en},p})();c.enLocaleLoader=h},486(s,c){Object.defineProperty(c,"__esModule",{value:!0}),c.en=void 0;var u=(function(){function f(){}return f.prototype.atX0SecondsPastTheMinuteGt20=function(){return null},f.prototype.atX0MinutesPastTheHourGt20=function(){return null},f.prototype.commaMonthX0ThroughMonthX1=function(){return null},f.prototype.commaYearX0ThroughYearX1=function(){return null},f.prototype.use24HourTimeFormatByDefault=function(){return!1},f.prototype.anErrorOccuredWhenGeneratingTheExpressionD=function(){return"An error occurred when generating the expression description. Check the cron expression syntax."},f.prototype.everyMinute=function(){return"every minute"},f.prototype.everyHour=function(){return"every hour"},f.prototype.atSpace=function(){return"At "},f.prototype.everyMinuteBetweenX0AndX1=function(){return"Every minute between %s and %s"},f.prototype.at=function(){return"At"},f.prototype.spaceAnd=function(){return" and"},f.prototype.everySecond=function(){return"every second"},f.prototype.everyX0Seconds=function(){return"every %s seconds"},f.prototype.secondsX0ThroughX1PastTheMinute=function(){return"seconds %s through %s past the minute"},f.prototype.atX0SecondsPastTheMinute=function(){return"at %s seconds past the minute"},f.prototype.everyX0Minutes=function(){return"every %s minutes"},f.prototype.minutesX0ThroughX1PastTheHour=function(){return"minutes %s through %s past the hour"},f.prototype.atX0MinutesPastTheHour=function(){return"at %s minutes past the hour"},f.prototype.everyX0Hours=function(){return"every %s hours"},f.prototype.betweenX0AndX1=function(){return"between %s and %s"},f.prototype.atX0=function(){return"at %s"},f.prototype.commaEveryDay=function(){return", every day"},f.prototype.commaEveryX0DaysOfTheWeek=function(){return", every %s days of the week"},f.prototype.commaX0ThroughX1=function(){return", %s through %s"},f.prototype.commaAndX0ThroughX1=function(){return", %s through %s"},f.prototype.first=function(){return"first"},f.prototype.second=function(){return"second"},f.prototype.third=function(){return"third"},f.prototype.fourth=function(){return"fourth"},f.prototype.fifth=function(){return"fifth"},f.prototype.commaOnThe=function(){return", on the "},f.prototype.spaceX0OfTheMonth=function(){return" %s of the month"},f.prototype.lastDay=function(){return"the last day"},f.prototype.commaOnTheLastX0OfTheMonth=function(){return", on the last %s of the month"},f.prototype.commaOnlyOnX0=function(){return", only on %s"},f.prototype.commaAndOnX0=function(){return", and on %s"},f.prototype.commaEveryX0Months=function(){return", every %s months"},f.prototype.commaOnlyInX0=function(){return", only in %s"},f.prototype.commaOnTheLastDayOfTheMonth=function(){return", on the last day of the month"},f.prototype.commaOnTheLastWeekdayOfTheMonth=function(){return", on the last weekday of the month"},f.prototype.commaDaysBeforeTheLastDayOfTheMonth=function(){return", %s days before the last day of the month"},f.prototype.firstWeekday=function(){return"first weekday"},f.prototype.weekdayNearestDayX0=function(){return"weekday nearest day %s"},f.prototype.commaOnTheX0OfTheMonth=function(){return", on the %s of the month"},f.prototype.commaEveryX0Days=function(){return", every %s days in a month"},f.prototype.commaBetweenDayX0AndX1OfTheMonth=function(){return", between day %s and %s of the month"},f.prototype.commaOnDayX0OfTheMonth=function(){return", on day %s of the month"},f.prototype.commaEveryHour=function(){return", every hour"},f.prototype.commaEveryX0Years=function(){return", every %s years"},f.prototype.commaStartingX0=function(){return", starting %s"},f.prototype.daysOfTheWeek=function(){return["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},f.prototype.monthsOfTheYear=function(){return["January","February","March","April","May","June","July","August","September","October","November","December"]},f.prototype.atReboot=function(){return"Run once, at startup"},f.prototype.onTheHour=function(){return"on the hour"},f})();c.en=u},515(s,c){Object.defineProperty(c,"__esModule",{value:!0});function u(h,p){if(!h)throw new Error(p)}var f=(function(){function h(){}return h.secondRange=function(p){for(var g=p.split(","),v=0;v<g.length;v++)if(!isNaN(parseInt(g[v],10))){var w=parseInt(g[v],10);u(w>=0&&w<=59,"seconds part must be >= 0 and <= 59")}},h.minuteRange=function(p){for(var g=p.split(","),v=0;v<g.length;v++)if(!isNaN(parseInt(g[v],10))){var w=parseInt(g[v],10);u(w>=0&&w<=59,"minutes part must be >= 0 and <= 59")}},h.hourRange=function(p){for(var g=p.split(","),v=0;v<g.length;v++)if(!isNaN(parseInt(g[v],10))){var w=parseInt(g[v],10);u(w>=0&&w<=23,"hours part must be >= 0 and <= 23")}},h.dayOfMonthRange=function(p){for(var g=p.split(","),v=0;v<g.length;v++)if(!isNaN(parseInt(g[v],10))){var w=parseInt(g[v],10);u(w>=1&&w<=31,"DOM part must be >= 1 and <= 31")}},h.monthRange=function(p,g){for(var v=p.split(","),w=0;w<v.length;w++)if(!isNaN(parseInt(v[w],10))){var y=parseInt(v[w],10);u(y>=1&&y<=12,g?"month part must be >= 0 and <= 11":"month part must be >= 1 and <= 12")}},h.dayOfWeekRange=function(p,g){for(var v=p.split(","),w=0;w<v.length;w++)if(!isNaN(parseInt(v[w],10))){var y=parseInt(v[w],10);u(y>=0&&y<=6,g?"DOW part must be >= 0 and <= 6":"DOW part must be >= 1 and <= 7")}},h})();c.default=f},823(s,c){Object.defineProperty(c,"__esModule",{value:!0}),c.StringUtilities=void 0;var u=(function(){function f(){}return f.format=function(h){for(var p=[],g=1;g<arguments.length;g++)p[g-1]=arguments[g];return h.replace(/%s/g,function(v){return p.shift()})},f.containsAny=function(h,p){return p.some(function(g){return h.indexOf(g)>-1})},f})();c.StringUtilities=u}},r={};function i(s){var c=r[s];if(c!==void 0)return c.exports;var u=r[s]={exports:{}};return n[s](u,u.exports,i),u.exports}var a={};return(()=>{var s=a;Object.defineProperty(s,"__esModule",{value:!0}),s.toString=void 0;var c=i(333),u=i(747);c.ExpressionDescriptor.initialize(new u.enLocaleLoader),s.default=c.ExpressionDescriptor;var f=c.ExpressionDescriptor.toString;s.toString=f})(),a})())})(X0)),X0.exports}var h1e=d1e();const m4=tu(h1e);function p1e(e){return e.trigger.kind}function m1e(e){var n;const t=e.trigger;if(t.kind==="once")return`Once at ${new Date(t.at).toLocaleString()}`;if(t.kind==="interval"){const r=Math.round(t.everyMs/1e3);return r>=86400?`Every ${Math.round(r/86400)}d`:r>=3600?`Every ${Math.round(r/3600)}h`:r>=60?`Every ${Math.round(r/60)}m`:`Every ${r}s`}if(t.kind==="event"){const r=t.match?Object.entries(t.match).map(([i,a])=>`${i}=${a}`).join(", "):"";return`On event "${t.source}"${r?` where ${r}`:""}`}try{const r=t.tz||"UTC",i=g1e(t.expr,r),a=m4.toString(t.expr),s=r==="UTC"?"UTC":((n=r.split("/").pop())==null?void 0:n.replace(/_/g," "))||r;return i?`${i} (${a} ${s})`:`${a} ${s}`}catch{return t.expr}}function g1e(e,t){try{const n=e.split(/\s+/);if(n.length<5)return null;const r=parseInt(n[0],10),i=parseInt(n[1],10);if(isNaN(r)||isNaN(i))return null;const a=new Date,s=new Date(a.toLocaleString("en-US",{timeZone:t})).getTime()-new Date(a.toLocaleString("en-US",{timeZone:"UTC"})).getTime(),c=new Date;return c.setUTCHours(i,r,0,0),new Date(c.getTime()-s).toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit",hour12:!1,timeZone:"UTC"})}catch{return null}}function iD(e){if(!e)return"—";const t=e-Date.now(),n=Math.abs(t),r=Math.round(n/6e4);if(n<6e4)return t>0?"in <1m":"<1m ago";if(r<60)return t>0?`in ${r}m`:`${r}m ago`;const i=Math.round(r/60);if(i<24)return t>0?`in ${i}h`:`${i}h ago`;const a=Math.round(i/24);return t>0?`in ${a}d`:`${a}d ago`}const v1e={ok:"bg-green-50 text-green-700 dark:bg-green-950/50 dark:text-green-300",error:"bg-red-50 text-red-700 dark:bg-red-950/50 dark:text-red-300",running:"bg-blue-50 text-blue-700 dark:bg-blue-950/50 dark:text-blue-300",aborted:"bg-amber-50 text-amber-700 dark:bg-amber-950/50 dark:text-amber-300"};function y1e(e){return e.scope==="system"}function b1e(e){return e==="prompt"?"Additional instructions (appended to prompt)":e==="bash"?"Override command":"Override args"}function x1e(e){return e==="prompt"?"e.g. Dry run — compose the message but do NOT post to Slack":e==="bash"?"e.g. bun run report:fb-ads-spend --dry-run":"e.g. --dry-run"}function w1e(e,t){var n;return e.scope==="system"?"system":((n=e.createdBy)==null?void 0:n.uid)===t?"mine":"others"}function E1e({schedules:e,currentUserUid:t,onCreate:n,onEdit:r,onDelete:i,onToggle:a,onRunNow:s,onCancel:c,onOpenRun:u,runningIds:f=new Set}){const[h,p]=b.useState(null),[g,v]=b.useState(""),[w,y]=b.useState({mine:!0,others:!0,system:!0}),[E,k]=b.useState({once:!0,interval:!0,cron:!0,event:!0}),[O,A]=b.useState(!1),C=j=>y(M=>{if(Object.values(M).every(Boolean))return{mine:!1,others:!1,system:!1,[j]:!0};const R={...M,[j]:!M[j]};return Object.values(R).some(Boolean)?R:{mine:!0,others:!0,system:!0}}),I=j=>k(M=>{if(Object.values(M).every(Boolean))return{once:!1,interval:!1,cron:!1,event:!1,[j]:!0};const R={...M,[j]:!M[j]};return Object.values(R).some(Boolean)?R:{once:!0,interval:!0,cron:!0,event:!0}}),T=e.filter(j=>w[w1e(j,t)]&&E[p1e(j)]),D=j=>{const M=localStorage.getItem(`schedule-override-${j.id}`);v(M??""),p(j.id)},P=async()=>{if(h){A(!0);try{const j=g.trim()||void 0;j&&localStorage.setItem(`schedule-override-${h}`,j);const M=await s(h,j);p(null),v(""),M&&u(M)}finally{A(!1)}}};return _.jsxs("div",{className:"space-y-3",children:[_.jsxs("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[_.jsxs("div",{className:"flex gap-1 flex-wrap",children:[["mine","others","system"].map(j=>_.jsx("button",{onClick:()=>C(j),className:`text-[11px] px-2 py-0.5 rounded-full border transition-colors ${w[j]?"bg-primary text-primary-foreground border-primary":"bg-transparent text-muted-foreground border-border hover:border-muted-foreground"}`,children:j},j)),_.jsx("span",{className:"w-px h-4 bg-border mx-1"}),["once","interval","cron","event"].map(j=>_.jsx("button",{onClick:()=>I(j),className:`text-[11px] px-2 py-0.5 rounded-full border transition-colors ${E[j]?"bg-primary text-primary-foreground border-primary":"bg-transparent text-muted-foreground border-border hover:border-muted-foreground"}`,children:j},j))]}),_.jsxs(Pe,{size:"sm",onClick:n,className:"gap-1",children:[_.jsx(xg,{className:"w-4 h-4"})," New schedule"]})]}),T.length===0&&_.jsx("p",{className:"text-sm text-muted-foreground text-center py-8",children:e.length===0?"No schedules yet.":"No schedules match filters."}),T.map(j=>{var M,B;return _.jsxs("div",{className:"border rounded-lg p-3 space-y-2 overflow-hidden",children:[_.jsxs("div",{className:"flex items-start justify-between gap-2 flex-wrap",children:[_.jsxs("div",{className:"min-w-0 flex-1",children:[_.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-wrap",children:[_.jsx("input",{type:"checkbox",checked:j.enabled,onChange:R=>a(j.id,R.target.checked),title:j.enabled?"Disable":"Enable",className:"shrink-0"}),_.jsx("span",{className:"font-medium text-sm truncate max-w-[280px]",title:j.name,children:j.name}),_.jsx("span",{className:"shrink-0 text-[10px] font-mono px-1.5 py-0.5 rounded bg-muted text-muted-foreground",children:j.task.kind}),_.jsx("span",{className:"shrink-0 text-[10px] font-mono px-1.5 py-0.5 rounded bg-muted text-muted-foreground",children:j.trigger.kind}),f.has(j.id)&&_.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-blue-50 text-blue-700 dark:bg-blue-950/50 dark:text-blue-300",children:[_.jsx(E2,{className:"w-3 h-3 animate-spin"}),"running"]}),_.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-blue-50 text-blue-700 dark:bg-blue-950/50 dark:text-blue-300",children:y1e(j)?"system":((B=(M=j.createdBy)==null?void 0:M.email)==null?void 0:B.split("@")[0])??"unknown"})]}),_.jsx("div",{className:"mt-1 text-xs text-muted-foreground truncate",children:m1e(j)}),_.jsxs("div",{className:"mt-1 flex items-center gap-3 text-xs text-muted-foreground",children:[_.jsxs("span",{children:["Next: ",j.enabled?iD(j.nextRun):"disabled"]}),j.lastRun&&_.jsxs("button",{className:`px-1.5 py-0.5 rounded text-[10px] ${v1e[j.lastRun.status]??""}`,onClick:()=>u(j.lastRun.sessionId),title:"Open last run",children:["last: ",j.lastRun.status," ",iD(j.lastRun.at)]}),_.jsxs("span",{children:["runs: ",j.runCount??0]})]})]}),_.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[f.has(j.id)?_.jsx(Pe,{variant:"ghost",size:"icon",title:"Stop run",onClick:()=>c(j.id),children:_.jsx(k2,{className:"w-4 h-4 text-destructive"})}):_.jsx(Pe,{variant:"ghost",size:"icon",title:"Run now",onClick:()=>D(j),children:_.jsx(O7,{className:"w-4 h-4"})}),_.jsx(Pe,{variant:"ghost",size:"icon",title:"Edit",onClick:()=>r(j),children:_.jsx(Hw,{className:"w-4 h-4"})}),_.jsx(Pe,{variant:"ghost",size:"icon",title:"Delete",onClick:()=>i(j.id),children:_.jsx(hm,{className:"w-4 h-4 text-destructive"})})]})]}),h===j.id&&_.jsxs("div",{className:"border-t pt-2 mt-2 space-y-2",children:[_.jsx("label",{className:"text-xs text-muted-foreground",children:b1e(j.task.kind)}),_.jsx("input",{type:"text",className:"w-full text-sm border rounded px-2 py-1.5 bg-background",placeholder:x1e(j.task.kind),value:g,onChange:R=>v(R.target.value),onKeyDown:R=>{R.key==="Enter"&&!O&&P(),R.key==="Escape"&&p(null)},disabled:O,autoFocus:!0}),_.jsxs("div",{className:"flex gap-2 justify-end",children:[_.jsx(Pe,{size:"sm",variant:"ghost",onClick:()=>p(null),disabled:O,children:"Cancel"}),_.jsx(Pe,{size:"sm",onClick:P,disabled:O,children:O?"Running...":"Run"})]})]})]},j.id)})]})}function S1e(e){const t=new Date(e??Date.now()+6e4),n=r=>String(r).padStart(2,"0");return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}const _1e=[{label:"1 min",ms:6e4},{label:"5 min",ms:5*6e4},{label:"15 min",ms:15*6e4},{label:"1 hour",ms:60*6e4},{label:"6 hours",ms:360*6e4},{label:"1 day",ms:1440*6e4}],k1e=[{label:"Every hour",expr:"0 * * * *"},{label:"Daily 9am",expr:"0 9 * * *"},{label:"Weekdays 9am",expr:"0 9 * * 1-5"},{label:"Mondays 9am",expr:"0 9 * * 1"}];function A1e({match:e,onChange:t}){const n=Object.entries(e),r=(s,c,u)=>{const f={};n.forEach(([h,p],g)=>{f[g===s?c:h]=g===s?u:p}),t(f)},i=s=>t(Object.fromEntries(n.filter((c,u)=>u!==s))),a=()=>t({...e,"":""});return _.jsxs("div",{className:"space-y-1",children:[_.jsx("label",{className:"text-xs text-muted-foreground",children:"Match filter (optional — all must match)"}),n.map(([s,c],u)=>_.jsxs("div",{className:"flex gap-1",children:[_.jsx(Un,{className:"text-xs font-mono",value:s,onChange:f=>r(u,f.target.value,c),placeholder:"payload.path (e.g. type)"}),_.jsx(Un,{className:"text-xs font-mono",value:c,onChange:f=>r(u,s,f.target.value),placeholder:"value (e.g. invoice.paid)"}),_.jsx(Pe,{type:"button",variant:"ghost",size:"sm",onClick:()=>i(u),children:"×"})]},u)),_.jsx(Pe,{type:"button",variant:"outline",size:"sm",onClick:a,children:"+ Add filter"})]})}function aD({initial:e,onSave:t,onCancel:n,skills:r=[],workspaceFiles:i=[]}){const a=b.useMemo(()=>Intl.DateTimeFormat().resolvedOptions().timeZone,[]),[s,c]=b.useState((e==null?void 0:e.name)??"New schedule"),[u,f]=b.useState((e==null?void 0:e.enabled)??!0),[h,p]=b.useState((e==null?void 0:e.trigger)??{kind:"cron",expr:"0 9 * * *",tz:a}),[g,v]=b.useState((e==null?void 0:e.task)??{kind:"prompt",prompt:""}),[w,y]=b.useState(!1),[E,k]=b.useState(null),O=b.useMemo(()=>{if(h.kind!=="cron")return"";try{return m4.toString(h.expr)}catch{return"Invalid cron"}},[h]),A=async()=>{y(!0),k(null);try{await t({name:s,enabled:u,trigger:h,task:g})}catch(C){k(C.message)}finally{y(!1)}};return _.jsxs("div",{className:"space-y-4",children:[_.jsxs("div",{className:"space-y-1",children:[_.jsx("label",{className:"text-xs text-muted-foreground",children:"Name"}),_.jsx(Un,{value:s,onChange:C=>c(C.target.value),placeholder:"e.g. Daily standup summary"})]}),_.jsxs("div",{className:"space-y-2",children:[_.jsx("label",{className:"text-xs text-muted-foreground",children:"Trigger"}),_.jsx("div",{className:"flex gap-1",children:["once","interval","cron","event"].map(C=>_.jsx(Pe,{type:"button",variant:h.kind===C?"default":"outline",size:"sm",onClick:()=>{p(C==="once"?{kind:"once",at:Date.now()+5*6e4}:C==="interval"?{kind:"interval",everyMs:60*6e4}:C==="event"?{kind:"event",source:""}:{kind:"cron",expr:"0 9 * * *",tz:a})},children:C},C))}),h.kind==="once"&&_.jsx(Un,{type:"datetime-local",value:S1e(h.at),onChange:C=>{const I=new Date(C.target.value);isNaN(I.getTime())||p({kind:"once",at:I.getTime()})}}),h.kind==="interval"&&_.jsxs("div",{className:"space-y-2",children:[_.jsx("div",{className:"flex gap-1 flex-wrap",children:_1e.map(C=>_.jsx(Pe,{type:"button",variant:h.everyMs===C.ms?"default":"outline",size:"sm",onClick:()=>p({kind:"interval",everyMs:C.ms}),children:C.label},C.ms))}),_.jsx(Un,{type:"number",min:1,value:Math.round(h.everyMs/1e3),onChange:C=>p({kind:"interval",everyMs:Math.max(1,Number(C.target.value))*1e3}),placeholder:"seconds"}),_.jsxs("p",{className:"text-xs text-muted-foreground",children:["Every ",Math.round(h.everyMs/1e3),"s"]})]}),h.kind==="cron"&&_.jsxs("div",{className:"space-y-2",children:[_.jsx("div",{className:"flex gap-1 flex-wrap",children:k1e.map(C=>_.jsx(Pe,{type:"button",variant:"outline",size:"sm",onClick:()=>p({kind:"cron",expr:C.expr,tz:a}),children:C.label},C.expr))}),_.jsx(Un,{className:"font-mono text-xs",value:h.expr,onChange:C=>p({...h,expr:C.target.value}),placeholder:"0 9 * * *"}),_.jsx(Un,{className:"text-xs",value:h.tz,onChange:C=>p({...h,tz:C.target.value}),placeholder:"IANA timezone"}),_.jsxs("p",{className:"text-xs text-muted-foreground",children:[O," (",h.tz,")"]})]}),h.kind==="event"&&_.jsxs("div",{className:"space-y-2",children:[_.jsx(Un,{value:h.source,onChange:C=>p({...h,source:C.target.value}),placeholder:"Event source (e.g. stripe, github, deploy)"}),_.jsxs("p",{className:"text-xs text-muted-foreground",children:["Fires when an event with this source arrives via ",_.jsxs("code",{children:["POST /api/events/",h.source||":source"]})," or ",_.jsx("code",{children:"ctx.emitEvent()"}),"."]}),_.jsx(A1e,{match:h.match??{},onChange:C=>p({...h,match:C})})]})]}),_.jsxs("div",{className:"space-y-2",children:[_.jsx("label",{className:"text-xs text-muted-foreground",children:"Task"}),_.jsx("div",{className:"flex gap-1",children:["prompt","bash"].map(C=>_.jsx(Pe,{type:"button",variant:g.kind===C?"default":"outline",size:"sm",onClick:()=>v(C==="prompt"?{kind:"prompt",prompt:""}:{kind:"bash",command:""}),children:C==="prompt"?"Prompt":"Bash command"},C))}),g.kind==="prompt"?_.jsx(p4,{rows:5,value:g.prompt,onChange:C=>v({...g,prompt:C}),placeholder:"What should the agent do? (@ for skills, / for commands)",skills:r,workspaceFiles:i,autoResize:!1,className:"flex min-h-[80px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"}):g.kind==="bash"?_.jsx(bv,{rows:3,className:"font-mono text-xs",value:g.command,onChange:C=>v({...g,command:C.target.value}),placeholder:"ls -la ~/"}):_.jsxs("p",{className:"text-xs text-muted-foreground",children:["Command: ",g.command]})]}),_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx("input",{id:"sched-enabled",type:"checkbox",checked:u,onChange:C=>f(C.target.checked)}),_.jsx("label",{htmlFor:"sched-enabled",className:"text-sm",children:"Enabled"})]}),E&&_.jsx("p",{className:"text-xs text-destructive",children:E}),_.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[_.jsx(Pe,{variant:"outline",onClick:n,disabled:w,children:"Cancel"}),_.jsx(Pe,{onClick:A,disabled:w,children:w?"Saving…":"Save"})]})]})}const oD=b.forwardRef(function({getToken:t,onOpenSession:n,refreshKey:r=0,runningIds:i=new Set,skills:a=[],workspaceFiles:s=[],trigger:c},u){const[f,h]=b.useState(!1),{user:p}=s2(),{schedules:g,serverRunningIds:v,create:w,update:y,remove:E,toggle:k,runNow:O,cancelRun:A}=f1e(t,f,r);b.useImperativeHandle(u,()=>({open:()=>h(!0)}),[]);const[C,I]=b.useState(null),[T,D]=b.useState(!1),[P,j]=b.useState(new Set),M=()=>{I(null),D(!1)},B=async(R,H)=>{j(Y=>new Set(Y).add(R));try{return await O(R,H)}finally{setTimeout(()=>{j(Y=>{const K=new Set(Y);return K.delete(R),K})},1500)}};return _.jsxs(sl,{open:f,onOpenChange:R=>{h(R),R||M()},children:[_.jsx(Ng,{asChild:!0,children:c||_.jsx(Pe,{variant:"ghost",size:"icon",className:"h-8 w-8",title:"Scheduled Tasks",children:_.jsx(zw,{className:"w-4 h-4"})})}),_.jsxs(es,{className:"max-w-[95vw] sm:max-w-2xl",children:[_.jsx(Gc,{children:_.jsx(ll,{children:T?"New Schedule":C?`Edit: ${C.name}`:"Scheduled Tasks"})}),T?_.jsx(aD,{onSave:async R=>{await w(R),M()},onCancel:M,skills:a,workspaceFiles:s},"__new__"):C?_.jsx(aD,{initial:C,onSave:async R=>{await y(C.id,R),M()},onCancel:M,skills:a,workspaceFiles:s},C.id):_.jsx(E1e,{schedules:g,currentUserUid:p==null?void 0:p.uid,onCreate:()=>D(!0),onEdit:R=>I(R),onDelete:R=>{confirm("Delete this schedule?")&&E(R)},onToggle:k,onRunNow:B,onCancel:A,runningIds:new Set([...i,...v,...P]),onOpenRun:R=>{h(!1),n(R)}})]})]})});function g4(){const e=localStorage.getItem("dark-mode");return e!==null?e==="true":window.matchMedia("(prefers-color-scheme: dark)").matches}let rl=typeof window<"u"?g4():!0;const Ew=new Set;function v4(){document.documentElement.classList.toggle("dark",rl),localStorage.setItem("dark-mode",String(rl)),Ew.forEach(e=>e())}typeof window<"u"&&v4();function y4(e){e!==rl&&(rl=e,v4())}function O1e(e){Ew.add(e);const t=n=>{n.key==="dark-mode"&&y4(g4())};return window.addEventListener("storage",t),()=>{Ew.delete(e),window.removeEventListener("storage",t)}}function T1e(){return{dark:b.useSyncExternalStore(O1e,()=>rl,()=>rl),toggle:()=>y4(!rl)}}const sD=4;function C1e(e,t){const[n,r]=b.useState({}),[i,a]=b.useState([]),s=b.useRef(t);s.current=t;const c=b.useRef(!document.hidden),u=b.useRef(e);u.current=e,b.useEffect(()=>{const y=()=>{var O;c.current=!document.hidden,(O=u.current)==null||O.sendPresence(s.current,c.current),c.current&&s.current&&h(s.current)},E=()=>{var O;c.current=!0,(O=u.current)==null||O.sendPresence(s.current,!0),s.current&&h(s.current)},k=()=>{var O;c.current=!1,(O=u.current)==null||O.sendPresence(s.current,!1)};return document.addEventListener("visibilitychange",y),window.addEventListener("focus",E),window.addEventListener("blur",k),()=>{document.removeEventListener("visibilitychange",y),window.removeEventListener("focus",E),window.removeEventListener("blur",k)}},[]),b.useEffect(()=>{e==null||e.sendPresence(t,c.current),t&&c.current&&h(t)},[t,e]),b.useEffect(()=>{},[i.length]);const f=b.useCallback(y=>{var E,k;if(y.type==="unread"){if(s.current===y.sessionId&&c.current){(E=u.current)==null||E.markRead(y.sessionId);return}r(A=>({...A,[y.sessionId]:{count:y.count,preview:y.preview,source:y.source,title:y.title}})),a(A=>{const C=A.filter(T=>T.sessionId!==y.sessionId);return[{id:`${y.sessionId}-${Date.now()}`,sessionId:y.sessionId,preview:y.preview,title:y.title,ts:Date.now()},...C].slice(0,sD)})}if(y.type==="unread_sync"){const O={};for(const[A,C]of Object.entries(y.sessions)){if(A===s.current&&c.current){(k=u.current)==null||k.markRead(A);continue}O[A]={count:C.count,preview:C.preview,source:C.source,title:C.title}}r(O)}y.type==="unread_cleared"&&r(O=>{const A={...O};return delete A[y.sessionId],A})},[]),h=b.useCallback(y=>{var E;r(k=>{if(!k[y])return k;const O={...k};return delete O[y],O}),a(k=>k.filter(O=>O.sessionId!==y)),(E=u.current)==null||E.markRead(y)},[]),p=b.useCallback(y=>{a(E=>E.filter(k=>k.id!==y))},[]),g=b.useCallback(y=>{s.current===y.sessionId&&c.current||a(E=>{const k=E.filter(A=>A.sessionId!==y.sessionId);return[{id:`${y.sessionId}-${Date.now()}`,sessionId:y.sessionId,preview:y.preview,title:y.title,ts:Date.now()},...k].slice(0,sD)})},[]),v=Object.keys(n).length;b.useEffect(()=>{const y="Shraga";document.title=v>0?`(${v}) ${y}`:y,N1e(v)},[v]);const w=b.useRef(0);return b.useEffect(()=>{a7(v),v>w.current&&m2(!1),w.current=v},[v]),{unreads:n,toasts:i,totalUnread:v,markRead:h,dismissToast:p,addToast:g,handleUnreadEvent:f}}let Ec=null,Z0=null;function N1e(e){if(typeof document>"u")return;if(!Z0){const n=document.querySelector('link[rel="icon"]');Z0=(n==null?void 0:n.href)??""}if(e===0){lD(Z0||"");return}Ec||(Ec=document.createElement("canvas"),Ec.width=32,Ec.height=32);const t=Ec.getContext("2d");t&&(t.clearRect(0,0,32,32),t.fillStyle="#6366f1",t.beginPath(),t.arc(16,16,14,0,Math.PI*2),t.fill(),t.fillStyle="#ef4444",t.beginPath(),t.arc(24,8,8,0,Math.PI*2),t.fill(),t.fillStyle="#fff",t.font="bold 10px sans-serif",t.textAlign="center",t.textBaseline="middle",t.fillText(e>9?"9+":String(e),24,8),lD(Ec.toDataURL()))}function lD(e){let t=document.querySelector('link[rel="icon"]');t||(t=document.createElement("link"),t.rel="icon",document.head.appendChild(t)),t.href!==e&&(t.href=e)}function I1e({toasts:e,onDismiss:t,onOpen:n}){return e.length===0?null:_.jsx("div",{className:"fixed bottom-4 right-4 z-[100] flex flex-col-reverse gap-2 max-w-sm w-full pointer-events-none",children:e.map((r,i)=>_.jsxs("div",{className:Ze("pointer-events-auto bg-white dark:bg-zinc-800 border border-zinc-300 dark:border-zinc-600 rounded-lg shadow-[0_8px_30px_rgb(0,0,0,0.12)] dark:shadow-[0_8px_30px_rgb(0,0,0,0.5)] p-3 pr-7 cursor-pointer relative","transform transition-all duration-300 ease-out","hover:bg-zinc-50 dark:hover:bg-zinc-700 group",i===0?"animate-in slide-in-from-bottom-2 fade-in":""),onClick:()=>{n(r.sessionId),t(r.id)},children:[_.jsx("button",{onClick:a=>{a.stopPropagation(),t(r.id)},className:"absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity p-0.5 hover:bg-muted rounded",children:_.jsx(al,{className:"w-3 h-3 text-muted-foreground"})}),_.jsxs("div",{className:"flex items-start gap-2.5",children:[_.jsx(lx,{className:"w-4 h-4 mt-0.5 shrink-0 text-blue-500"}),_.jsxs("div",{className:"flex-1 min-w-0",children:[_.jsx("div",{className:"text-xs font-medium text-foreground truncate",children:r.title||`Session ${r.sessionId.slice(0,8)}`}),_.jsx("div",{className:"text-xs text-muted-foreground mt-0.5 line-clamp-2",children:r.preview})]})]})]},r.id))})}function cD(){return new URLSearchParams(window.location.search).get("session")||void 0}function M1e(e){const t=new URL(window.location.href);e?t.searchParams.set("session",e):t.searchParams.delete("session");const n=t.toString()!==window.location.href;e&&n?window.history.pushState(null,"",t.toString()):window.history.replaceState(null,"",t.toString())}function R1e(){return _.jsx(s7,{value:{},children:_.jsx(D1e,{})})}function D1e(){var Ln,br;const e=ua(),{dark:t,toggle:n}=T1e(),{user:r,token:i,getToken:a,loading:s,mode:c,needsSetup:u,loginLocal:f,registerLocal:h,logout:p}=s2(),[g,v]=b.useState(()=>localStorage.getItem("shraga:sidebarOpen")!=="false"),w=b.useCallback(he=>{v(Fe=>{const st=typeof he=="function"?he(Fe):he;return localStorage.setItem("shraga:sidebarOpen",String(st)),st})},[]),[y,E]=b.useState(!1),[k,O]=b.useState({top:52,right:8}),A=b.useRef(null),C=b.useCallback(()=>{var Fe;const he=(Fe=A.current)==null?void 0:Fe.getBoundingClientRect();he&&O({top:he.bottom+4,right:Math.max(4,window.innerWidth-he.right)}),E(st=>!st)},[]),[I,T]=b.useState({}),D=b.useRef(null),[P,j]=b.useState(0),[M,B]=b.useState(0),[R,H]=b.useState(new Set),[Y,K]=b.useState([]),[U,G]=b.useState([]),[q,ee]=b.useState(0),[L,F]=b.useState(new Set),[J,$]=b.useState(!1),[de,xe]=b.useState(()=>localStorage.getItem("shraga:authorized")==="1"?!0:null),[ve,Me]=b.useState(()=>cD()),Qe=b.useCallback((he,Fe)=>Me(he),[]),fe=b.useCallback((he,Fe)=>Me(Fe),[]),Te=b.useCallback((he,Fe)=>{},[]),we=b.useCallback(()=>j(he=>he+1),[]),ue=b.useRef(!1);b.useEffect(()=>{if(!i){!ue.current&&localStorage.getItem("shraga:authorized")!=="1"&&xe(null);return}a().then(async he=>{var Fe,st,mt;if(!he)return xe(!1);try{const fn=await fetch("/api/config",{headers:{Authorization:`Bearer ${he}`}});if(fn.ok)return ue.current=!0,localStorage.setItem("shraga:authorized","1"),xe(!0);const On=await fn.json().catch(()=>({}));if(fn.status===401&&((Fe=On.error)!=null&&Fe.includes("audience")||(st=On.error)!=null&&st.includes("aud"))){console.warn("[auth] Token audience mismatch — signing out stale session"),p();return}if(fn.status===403&&((mt=On.error)!=null&&mt.toLowerCase().includes("whitelist")))return localStorage.removeItem("shraga:authorized"),xe(!1);if(ue.current)return;xe(fn.status!==401&&fn.status!==403)}catch{if(ue.current)return;xe(!0)}})},[i,a]);const St=b.useCallback(()=>{i&&(ee(he=>he+1),Ks("/api/workspace",a).then(he=>he.json()).then(he=>G(he.entries??[])).catch(he=>console.warn("[workspace] refresh failed",he)))},[i,a]),Ve=b.useCallback(he=>{B(Fe=>Fe+1),he.type==="schedule:run_started"?(H(Fe=>new Set(Fe).add(he.scheduleId)),we()):he.type==="schedule:run_finished"?(H(Fe=>{const st=new Set(Fe);return st.delete(he.scheduleId),st}),we()):he.type==="schedule:deleted"&&H(Fe=>{const st=new Set(Fe);return st.delete(he.id),st})},[we]),Oe=b.useRef(null),Le=b.useRef(null),on=b.useRef(ve);on.current=ve;const qn=b.useCallback(he=>{var Fe,st;if((Fe=Le.current)==null||Fe.call(Le,he),he.type.startsWith("schedule:")){Ve(he);return}switch(he.type==="permission_request"&&m2(!0),he.type){case"workspace_change":St();break;case"session_title_updated":we();break;case"session_messages_changed":we(),he.sessionId===on.current&&((st=Oe.current)==null||st.call(Oe,he.sessionId));break;case"session_busy":F(mt=>{const fn=new Set(mt);return he.busy?fn.add(he.sessionId):fn.delete(he.sessionId),fn}),he.busy||we();break}},[Ve,St,we]),{socket:Jn,connectionStatus:Pr,authError:pa}=yH(i,a,qn),{unreads:ds,toasts:oo,markRead:_t,dismissToast:so,addToast:ae,handleUnreadEvent:ge}=C1e(Jn,ve);Le.current=ge,Oe.current=_t,n7({socket:Jn,getToken:a,pushEnabled:J,activeSessionId:ve,switchTo:()=>{},openSession:Qe,onForegroundMessage:he=>{var st;const Fe=typeof((st=he.data)==null?void 0:st.session)=="string"?he.data.session:void 0;Fe&&ae({sessionId:Fe,preview:he.body||"New message",title:he.title})}}),b.useEffect(()=>{r7()},[]),b.useEffect(()=>{M1e(ve),ve&&_t(ve)},[ve,_t]),b.useEffect(()=>{const he=()=>Me(cD());return window.addEventListener("popstate",he),()=>window.removeEventListener("popstate",he)},[]),b.useEffect(()=>{i&&(Ks("/api/config",a).then(he=>he.json()).then(T).catch(()=>{}),Ks("/api/skills",a).then(he=>he.json()).then(he=>K(he.skills)).catch(()=>{}),Ks("/api/features",a).then(he=>he.json()).then(he=>$(!!he.push)).catch(()=>{}))},[i,a]),b.useEffect(()=>{St()},[St]);const ze=b.useCallback(()=>{Me(void 0),window.innerWidth<640&&w(!1)},[w]),Ye=b.useMemo(()=>U.filter(he=>he.type==="file").map(he=>he.path),[U]),pt=b.useMemo(()=>({socket:Jn,connectionStatus:Pr,getToken:a,token:i,agentConfig:I,setAgentConfig:T,activeSessionId:ve,skills:Y,workspaceFiles:Ye,openSchedules:()=>{var he;return(he=D.current)==null?void 0:he.open()},markRead:_t,bumpSidebar:we,assignSession:fe,renameTab:Te,openSession:Qe}),[Jn,Pr,a,i,I,ve,Y,Ye,_t,we,fe,Te,Qe]);return s?_.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground text-sm",children:"Loading…"}):!r||!i?_.jsx(Z7,{mode:c,needsSetup:u,onLoginLocal:f,onRegisterLocal:h}):de===null?_.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground text-sm",children:"Verifying access…"}):!de||pa?_.jsx("div",{className:"flex h-full items-center justify-center bg-background",children:_.jsxs("div",{className:"flex flex-col items-center gap-4 p-8 rounded-xl border bg-card shadow-sm w-full max-w-sm text-center",children:[_.jsx("div",{className:"flex items-center justify-center w-12 h-12 rounded-full bg-destructive/10 text-destructive",children:_.jsx(zb,{className:"w-6 h-6"})}),_.jsx("h2",{className:"text-lg font-semibold",children:"Access Denied"}),_.jsx("p",{className:"text-sm text-muted-foreground",children:"Your account is not authorized to use this app."}),_.jsxs("p",{className:"text-xs text-muted-foreground",children:["Signed in as ",r.email]}),_.jsx(Pe,{variant:"outline",onClick:()=>p(),children:"Sign out"})]})}):window.location.pathname==="/oauth/authorize"?_.jsx(Q7,{getToken:a,userEmail:r.email??""}):window.location.pathname==="/cli-auth"?_.jsx(J7,{getToken:a,userEmail:r.email??""}):_.jsxs("div",{className:"flex h-full",children:[g&&_.jsxs("div",{className:"fixed inset-0 z-50 bg-background sm:relative sm:inset-auto sm:z-auto sm:w-64 sm:shrink-0 sm:border-r flex flex-col",children:[_.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b sm:hidden",style:{paddingTop:"max(0.5rem, env(safe-area-inset-top))"},children:[_.jsx("span",{className:"text-sm font-medium",children:"Sessions"}),_.jsx(Pe,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>w(!1),children:_.jsx(rT,{className:"w-4 h-4"})})]}),_.jsx("div",{className:"flex-1 min-h-0",children:_.jsx(lee,{getToken:a,activeSessionId:ve,onSelect:(he,Fe)=>{Qe(he,Fe),_t(he),window.innerWidth<640&&w(!1)},onNew:ze,refreshKey:P,workspaceRefreshKey:q,onRefreshWorkspace:St,userUid:r.uid,userEmail:r.email||"",unreads:ds,busySessions:L,socket:Jn})})]}),_.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[_.jsx("header",{className:"border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60",style:{paddingTop:"env(safe-area-inset-top)"},children:_.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2 px-2 sm:px-3 py-1.5",children:[_.jsx(Pe,{variant:"ghost",size:"icon",className:"h-9 w-9 sm:h-8 sm:w-8 shrink-0",onClick:()=>w(!g),title:"Toggle sidebar",children:g?_.jsx(rT,{className:"w-4 h-4"}):_.jsx(k7,{className:"w-4 h-4"})}),_.jsx(Pe,{variant:"ghost",size:"icon",className:"h-9 w-9 sm:h-8 sm:w-8 shrink-0",onClick:ze,title:"New chat (⌘N)",children:_.jsx(M7,{className:"w-4 h-4"})}),_.jsx("div",{className:"flex-1"}),_.jsxs("div",{className:"hidden sm:flex items-center gap-0.5 shrink-0",children:[_.jsx(Pe,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:n,title:t?"Light mode":"Dark mode",children:t?_.jsx(aT,{className:"w-4 h-4"}):_.jsx(nT,{className:"w-4 h-4"})}),(Ln=e.headerActions)==null?void 0:Ln.call(e),_.jsx(JR,{getToken:a}),_.jsx(nD,{getToken:a,onSkillsChange:K}),_.jsx(oD,{ref:D,getToken:a,refreshKey:M,runningIds:R,onOpenSession:he=>Qe(he),skills:Y,workspaceFiles:Ye}),_.jsx(Pe,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>p(),title:"Sign out",children:_.jsx(zb,{className:"w-4 h-4"})})]}),_.jsxs("div",{className:"relative sm:hidden shrink-0",children:[_.jsx(Pe,{ref:A,variant:"ghost",size:"icon",className:"h-9 w-9",onClick:C,children:_.jsx(p7,{className:"w-4 h-4"})}),y&&ru.createPortal(_.jsxs(_.Fragment,{children:[_.jsx("div",{className:"fixed inset-0 z-[1090] cursor-pointer",onClick:()=>E(!1)}),_.jsxs("div",{className:"fixed z-[1100] border rounded-lg shadow-lg p-1 min-w-[170px] bg-white dark:bg-zinc-900 whitespace-nowrap",style:{top:k.top,right:k.right},children:[(br=e.headerActions)==null?void 0:br.call(e),_.jsx(JR,{getToken:a,trigger:_.jsxs("button",{className:"flex w-full items-center gap-2.5 rounded-md px-3 py-2.5 text-sm hover:bg-accent",children:[_.jsx(S2,{className:"w-3.5 h-3.5"})," MCPs"]})}),_.jsx(nD,{getToken:a,onSkillsChange:K,trigger:_.jsxs("button",{className:"flex w-full items-center gap-2.5 rounded-md px-3 py-2.5 text-sm hover:bg-accent",children:[_.jsx(sx,{className:"w-3.5 h-3.5"})," Skills"]})}),_.jsx(oD,{getToken:a,refreshKey:M,runningIds:R,onOpenSession:he=>Qe(he),skills:Y,workspaceFiles:Ye,trigger:_.jsxs("button",{className:"flex w-full items-center gap-2.5 rounded-md px-3 py-2.5 text-sm hover:bg-accent",children:[_.jsx(zw,{className:"w-3.5 h-3.5"})," Schedules"]})}),_.jsx("div",{className:"border-t my-1"}),_.jsxs("button",{className:"flex w-full items-center gap-2.5 rounded-md px-3 py-2.5 text-sm hover:bg-accent",onClick:()=>{E(!1),n()},children:[t?_.jsx(aT,{className:"w-3.5 h-3.5"}):_.jsx(nT,{className:"w-3.5 h-3.5"}),t?"Light mode":"Dark mode"]}),_.jsxs("button",{className:"flex w-full items-center gap-2.5 rounded-md px-3 py-2.5 text-sm hover:bg-accent",onClick:()=>p(),children:[_.jsx(zb,{className:"w-3.5 h-3.5"})," Sign out"]})]})]}),document.body)]})]})}),Pr==="update_available"&&_.jsxs("div",{className:"flex items-center justify-center gap-3 py-2.5 px-4 bg-amber-500 dark:bg-amber-600 text-white text-sm font-medium animate-pulse",children:[_.jsx("span",{children:"A new version is available"}),_.jsx("button",{onClick:()=>window.location.reload(),className:"px-3 py-1 bg-white text-amber-700 rounded font-semibold text-xs hover:bg-amber-50 transition-colors",children:"Reload now"})]}),_.jsx(o7,{value:pt,children:_.jsx("div",{className:"flex-1 min-h-0",children:_.jsx(c1e,{nodeId:"main",sessionId:ve},ve??"new")})})]}),_.jsx(I1e,{toasts:oo,onDismiss:so,onOpen:he=>{Qe(he),_t(he)}})]})}const uD="unclaw:",P1e="shraga:";function j1e(){try{const e=Object.keys(localStorage).filter(t=>t.startsWith(uD));for(const t of e){const n=P1e+t.slice(uD.length);if(localStorage.getItem(n)===null){const r=localStorage.getItem(t);r!==null&&localStorage.setItem(n,r)}localStorage.removeItem(t)}}catch(e){console.warn("[storage] legacy key migration skipped:",e instanceof Error?e.message:String(e))}}j1e();R$.createRoot(document.getElementById("root")).render(_.jsx(b.StrictMode,{children:_.jsx(R1e,{})}));
@@ -13,7 +13,7 @@
13
13
  <link rel="preconnect" href="https://fonts.googleapis.com" />
14
14
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
15
15
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet" />
16
- <script type="module" crossorigin src="/assets/index-Cqpw0NtH.js"></script>
16
+ <script type="module" crossorigin src="/assets/index-FM42KQNo.js"></script>
17
17
  <link rel="stylesheet" crossorigin href="/assets/index-DdibEb2O.css">
18
18
  </head>
19
19
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shraga",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "The teammate you delegate coding to — a self-hostable, multi-user AI coding agent web UI (Claude Code, with a pluggable engine seam).",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -30,12 +30,13 @@ interface EngineInfo {
30
30
  }
31
31
 
32
32
  const FALLBACK_MODELS: EngineModel[] = [
33
- { value: '', label: 'Default (claude-sonnet-4-6)' },
33
+ { value: '', label: 'Default (claude-sonnet-5)' },
34
34
  { value: 'claude-fable-5', label: 'Fable 5 — frontier, most capable' },
35
35
  { value: 'claude-opus-4-8', label: 'Opus 4.8 — most capable, best for complex/agentic tasks' },
36
36
  { value: 'claude-opus-4-7', label: 'Opus 4.7' },
37
37
  { value: 'claude-opus-4-6', label: 'Opus 4.6' },
38
- { value: 'claude-sonnet-4-6', label: 'Sonnet 4.6 — balanced speed & intelligence' },
38
+ { value: 'claude-sonnet-5', label: 'Sonnet 5 — balanced speed & intelligence' },
39
+ { value: 'claude-sonnet-4-6', label: 'Sonnet 4.6' },
39
40
  { value: 'claude-haiku-4-5', label: 'Haiku 4.5 — fastest' },
40
41
  ];
41
42
 
@@ -536,7 +536,7 @@ export class DataSync {
536
536
  emitEvent('data-sync', { kind: 'deploy', owners, text });
537
537
  }
538
538
 
539
- private async askClaude(prompt: string, model = 'claude-sonnet-4-6', maxTokens = 8192): Promise<string> {
539
+ private async askClaude(prompt: string, model = 'claude-sonnet-5', maxTokens = 8192): Promise<string> {
540
540
  const apiKey = process.env.ANTHROPIC_API_KEY;
541
541
  if (!apiKey) throw new Error('ANTHROPIC_API_KEY not set');
542
542
  const resp = await fetch('https://api.anthropic.com/v1/messages', {
@@ -14,7 +14,7 @@ export interface ParsedPrompt {
14
14
  /** Model used when neither directives nor config specify one. Always passed
15
15
  * explicitly to the SDK — the CLI's own default silently drifts (it picked
16
16
  * Opus 4.7), which burns rate limits and budget. */
17
- export const DEFAULT_MODEL = 'claude-sonnet-4-6';
17
+ export const DEFAULT_MODEL = 'claude-sonnet-5';
18
18
 
19
19
  // Canonical model aliases + label. Vendored, pure, dependency-free (src/server/model-aliases.ts).
20
20
  // Re-exported here so the rest of shraga keeps importing model helpers from one place.
@@ -166,7 +166,8 @@ export class ClaudeCodeEngine implements AgentEngine {
166
166
  { value: 'claude-opus-4-8', label: 'Opus 4.8 — most capable' },
167
167
  { value: 'claude-opus-4-7', label: 'Opus 4.7' },
168
168
  { value: 'claude-opus-4-6', label: 'Opus 4.6' },
169
- { value: 'claude-sonnet-4-6', label: 'Sonnet 4.6 — balanced' },
169
+ { value: 'claude-sonnet-5', label: 'Sonnet 5 — balanced' },
170
+ { value: 'claude-sonnet-4-6', label: 'Sonnet 4.6' },
170
171
  { value: 'claude-haiku-4-5', label: 'Haiku 4.5 — fastest' },
171
172
  ];
172
173
  }
@@ -14,7 +14,9 @@ export const MODEL_ALIASES: Record<string, string> = {
14
14
  'opus-4-8': 'claude-opus-4-8',
15
15
  'opus-4-7': 'claude-opus-4-7',
16
16
  'opus-4-6': 'claude-opus-4-6',
17
- sonnet: 'claude-sonnet-4-6',
17
+ sonnet: 'claude-sonnet-5',
18
+ 'sonnet-5': 'claude-sonnet-5',
19
+ 'sonnet-4-6': 'claude-sonnet-4-6',
18
20
  haiku: 'claude-haiku-4-5-20251001',
19
21
  };
20
22