shraga 0.1.89 → 0.1.90
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.
|
@@ -1942,5 +1942,5 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
1942
1942
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function cAe(e,t){if(e){if(typeof e=="string")return $2(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)?$2(e,t):void 0}}function $2(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 uAe(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 fAe(e){if(Array.isArray(e))return e}var dAe=()=>(obe(),null);function sv(e){if(typeof e=="number")return e;if(typeof e=="string"){var t=parseFloat(e);if(!Number.isNaN(t))return t}return 0}var hAe=y.forwardRef((e,t)=>{var n,r,i=y.useRef(null),a=y.useState({containerWidth:sv((n=e.style)===null||n===void 0?void 0:n.width),containerHeight:sv((r=e.style)===null||r===void 0?void 0:r.height)}),s=ov(a,2),c=s[0],u=s[1],f=y.useCallback((p,m)=>{u(v=>{var x=Math.round(p),b=Math.round(m);return v.containerWidth===x&&v.containerHeight===b?v:{containerWidth:x,containerHeight:b}})},[]),h=y.useCallback(p=>{if(typeof t=="function"&&t(p),i.current!=null&&(i.current.disconnect(),i.current=null),p!=null&&typeof ResizeObserver<"u"){var m=p.getBoundingClientRect(),v=m.width,x=m.height;f(v,x);var b=_=>{var O=_[0];if(O!=null){var k=O.contentRect,C=k.width,N=k.height;f(C,N)}},S=new ResizeObserver(b);S.observe(p),i.current=S}},[t,f]);return y.useEffect(()=>()=>{var p=i.current;p!=null&&p.disconnect()},[f]),y.createElement(y.Fragment,null,y.createElement(hh,{width:c.containerWidth,height:c.containerHeight}),y.createElement("div",ws({ref:h},e)))}),pAe=y.forwardRef((e,t)=>{var n=e.width,r=e.height,i=y.useState({containerWidth:sv(n),containerHeight:sv(r)}),a=ov(i,2),s=a[0],c=a[1],u=y.useCallback((h,p)=>{c(m=>{var v=Math.round(h),x=Math.round(p);return m.containerWidth===v&&m.containerHeight===x?m:{containerWidth:v,containerHeight:x}})},[]),f=y.useCallback(h=>{if(typeof t=="function"&&t(h),h!=null){var p=h.getBoundingClientRect(),m=p.width,v=p.height;u(m,v)}},[t,u]);return y.createElement(y.Fragment,null,y.createElement(hh,{width:s.containerWidth,height:s.containerHeight}),y.createElement("div",ws({ref:f},e)))}),mAe=y.forwardRef((e,t)=>{var n=e.width,r=e.height;return y.createElement(y.Fragment,null,y.createElement(hh,{width:n,height:r}),y.createElement("div",ws({ref:t},e)))}),gAe=y.forwardRef((e,t)=>{var n=e.width,r=e.height;return typeof n=="string"||typeof r=="string"?y.createElement(pAe,ws({},e,{ref:t})):typeof n=="number"&&typeof r=="number"?y.createElement(mAe,ws({},e,{width:n,height:r,ref:t})):y.createElement(y.Fragment,null,y.createElement(hh,{width:n,height:r}),y.createElement("div",ws({ref:t},e)))});function vAe(e){return e?hAe:gAe}var yAe=y.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,m=e.onMouseUp,v=e.onTouchEnd,x=e.onTouchMove,b=e.onTouchStart,S=e.style,_=e.width,O=e.responsive,k=e.dispatchTouchEvents,C=k===void 0?!0:k,N=y.useRef(null),T=Dt(),R=y.useState(null),L=ov(R,2),D=L[0],P=L[1],F=y.useState(null),I=ov(F,2),U=I[0],G=I[1],q=rAe(),$=ES(),W=($==null?void 0:$.width)>0?$.width:_,K=($==null?void 0:$.height)>0?$.height:i,X=y.useCallback(_e=>{q(_e),typeof t=="function"&&t(_e),P(_e),G(_e),_e!=null&&(N.current=_e)},[q,t,P,G]),j=y.useCallback(_e=>{T(i6(_e)),T(pi({handler:a,reactEvent:_e}))},[T,a]),H=y.useCallback(_e=>{T($1(_e)),T(pi({handler:f,reactEvent:_e}))},[T,f]),Q=y.useCallback(_e=>{T(D4()),T(pi({handler:h,reactEvent:_e}))},[T,h]),B=y.useCallback(_e=>{T($1(_e)),T(pi({handler:p,reactEvent:_e}))},[T,p]),de=y.useCallback(()=>{T(u6())},[T]),be=y.useCallback(()=>{T(f6())},[T]),ge=y.useCallback(_e=>{T(c6(_e.key))},[T]),Ie=y.useCallback(_e=>{T(pi({handler:s,reactEvent:_e}))},[T,s]),Ve=y.useCallback(_e=>{T(pi({handler:c,reactEvent:_e}))},[T,c]),fe=y.useCallback(_e=>{T(pi({handler:u,reactEvent:_e}))},[T,u]),ke=y.useCallback(_e=>{T(pi({handler:m,reactEvent:_e}))},[T,m]),we=y.useCallback(_e=>{T(pi({handler:b,reactEvent:_e}))},[T,b]),ue=y.useCallback(_e=>{C&&T(p6(_e)),T(pi({handler:x,reactEvent:_e}))},[T,C,x]),ht=y.useCallback(_e=>{T(pi({handler:v,reactEvent:_e}))},[T,v]),qe=vAe(O);return y.createElement(rU.Provider,{value:D},y.createElement(a$.Provider,{value:U},y.createElement(qe,{width:W??(S==null?void 0:S.width),height:K??(S==null?void 0:S.height),className:vt("recharts-wrapper",r),style:iAe({position:"relative",cursor:"default",width:W,height:K},S),onClick:j,onContextMenu:Ie,onDoubleClick:Ve,onFocus:de,onBlur:be,onKeyDown:ge,onMouseDown:fe,onMouseEnter:H,onMouseLeave:Q,onMouseMove:B,onMouseUp:ke,onTouchEnd:ht,onTouchMove:ue,onTouchStart:we,ref:X},y.createElement(dAe,null),n)))}),bAe=["width","height","responsive","children","className","style","compact","title","desc"];function xAe(e,t){if(e==null)return{};var n,r,i=wAe(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 wAe(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 w6=y.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=xAe(e,bAe),m=Zr(p);return u?y.createElement(y.Fragment,null,y.createElement(hh,{width:n,height:r}),y.createElement(j2,{otherAttributes:m,title:f,desc:h},a)):y.createElement(yAe,{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},y.createElement(j2,{otherAttributes:m,title:f,desc:h,ref:t},y.createElement(p1e,null,a)))});function B1(){return B1=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},B1.apply(null,arguments)}function B2(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 EAe(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?B2(Object(n),!0).forEach(function(r){SAe(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):B2(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function SAe(e,t,n){return(t=_Ae(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function _Ae(e){var t=AAe(e,"string");return typeof t=="symbol"?t:t+""}function AAe(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 kAe={top:5,right:5,bottom:5,left:5},OAe=EAe({accessibilityLayer:!0,barCategoryGap:"10%",barGap:4,layout:"horizontal",margin:kAe,responsive:!1,reverseStackOrder:!1,stackOffset:"none",syncMethod:"index"},hA),E6=y.forwardRef(function(t,n){var r,i=Pn(t.categoricalChartProps,OAe),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 y.createElement(v6,{preloadedState:{options:h},reduxStoreName:(r=f.id)!==null&&r!==void 0?r:a},y.createElement(jU,{chartData:f.data}),y.createElement(y6,{layout:i.layout,margin:i.margin}),y.createElement(x6,{throttleDelay:i.throttleDelay,throttledEvents:i.throttledEvents}),y.createElement(b6,{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}),y.createElement(w6,B1({},i,{ref:n})))}),CAe=["axis"],TAe=y.forwardRef((e,t)=>y.createElement(E6,{chartName:"LineChart",defaultTooltipEventType:"axis",validateTooltipEventTypes:CAe,tooltipPayloadSearcher:z_,categoricalChartProps:e,ref:t})),NAe=["axis","item"],MAe=y.forwardRef((e,t)=>y.createElement(E6,{chartName:"BarChart",defaultTooltipEventType:"axis",validateTooltipEventTypes:NAe,tooltipPayloadSearcher:z_,categoricalChartProps:e,ref:t}));function IAe(e){var t=Dt();return y.useEffect(()=>{t(j_e(e))},[t,e]),null}var RAe=["layout"];function U1(){return U1=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},U1.apply(null,arguments)}function PAe(e,t){if(e==null)return{};var n,r,i=DAe(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 DAe(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 U2(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 jAe(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?U2(Object(n),!0).forEach(function(r){LAe(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):U2(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function LAe(e,t,n){return(t=zAe(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function zAe(e){var t=$Ae(e,"string");return typeof t=="symbol"?t:t+""}function $Ae(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 BAe={top:5,right:5,bottom:5,left:5},S6=jAe({accessibilityLayer:!0,stackOffset:"none",barCategoryGap:"10%",barGap:4,margin:BAe,reverseStackOrder:!1,syncMethod:"index",layout:"radial",responsive:!1,cx:"50%",cy:"50%",innerRadius:0,outerRadius:"80%"},hA),UAe=y.forwardRef(function(t,n){var r,i=Pn(t.categoricalChartProps,S6),a=i.layout,s=PAe(i,RAe),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 y.createElement(v6,{preloadedState:{options:p},reduxStoreName:(r=i.id)!==null&&r!==void 0?r:c},y.createElement(jU,{chartData:i.data}),y.createElement(y6,{layout:a,margin:i.margin}),y.createElement(x6,{throttleDelay:i.throttleDelay,throttledEvents:i.throttledEvents}),y.createElement(b6,{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}),y.createElement(IAe,{cx:i.cx,cy:i.cy,startAngle:i.startAngle,endAngle:i.endAngle,innerRadius:i.innerRadius,outerRadius:i.outerRadius}),y.createElement(w6,U1({},s,{ref:n})))});function F2(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 H2(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?F2(Object(n),!0).forEach(function(r){FAe(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):F2(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function FAe(e,t,n){return(t=HAe(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function HAe(e){var t=KAe(e,"string");return typeof t=="symbol"?t:t+""}function KAe(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 qAe=["item"],GAe=H2(H2({},S6),{},{layout:"centric",startAngle:0,endAngle:360}),WAe=y.forwardRef((e,t)=>{var n=Pn(e,GAe);return y.createElement(UAe,{chartName:"PieChart",defaultTooltipEventType:"item",validateTooltipEventTypes:qAe,tooltipPayloadSearcher:z_,categoricalChartProps:n,ref:t})});const Yc=["#6366f1","#f59e0b","#10b981","#ef4444","#8b5cf6","#ec4899","#14b8a6","#f97316"];function VAe(e){const t=e.trim();if(!t.startsWith("{")&&!t.startsWith("["))return null;try{return JSON.parse(t)}catch{return null}}function YAe(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 XAe(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;const t=e;return"file"in t&&"sizeBytes"in t}function ZAe(e){if(XAe(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=YAe(e);if(t)return t}return null}function QAe(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 JAe(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 eke({data:e}){const{rows:t,labelKey:n,numericKeys:r,chartType:i}=y.useMemo(()=>{const a=ZAe(e);if(!a||a.length===0)return{rows:null,labelKey:"",numericKeys:[],chartType:"table"};const{labelKey:s,numericKeys:c}=JAe(a),u=QAe(a,s,c);return{rows:a,labelKey:s,numericKeys:c,chartType:u}},[e]);return t?i==="table"?E.jsx(K2,{rows:t}):E.jsxs("div",{className:"space-y-2",children:[E.jsx("div",{className:"h-64 w-full",children:E.jsx(fue,{width:"100%",height:"100%",children:i==="pie"?E.jsxs(WAe,{children:[E.jsx(RU,{data:t,dataKey:r[0],nameKey:n,cx:"50%",cy:"50%",outerRadius:80,label:!0,children:t.map((a,s)=>E.jsx(Th,{fill:Yc[s%Yc.length]},s))}),E.jsx(qx,{}),E.jsx(Km,{})]}):i==="line"?E.jsxs(TAe,{data:t,children:[E.jsx(N1,{strokeDasharray:"3 3",className:"opacity-30"}),E.jsx(D1,{dataKey:n,tick:{fontSize:11}}),E.jsx(z1,{tick:{fontSize:11}}),E.jsx(qx,{}),r.length>1&&E.jsx(Km,{}),r.map((a,s)=>E.jsx(ZU,{type:"monotone",dataKey:a,stroke:Yc[s%Yc.length],strokeWidth:2,dot:!1},a))]}):E.jsxs(MAe,{data:t,children:[E.jsx(N1,{strokeDasharray:"3 3",className:"opacity-30"}),E.jsx(D1,{dataKey:n,tick:{fontSize:11}}),E.jsx(z1,{tick:{fontSize:11}}),E.jsx(qx,{}),r.length>1&&E.jsx(Km,{}),r.map((a,s)=>E.jsx(n6,{dataKey:a,fill:Yc[s%Yc.length],radius:[3,3,0,0]},a))]})})}),E.jsx(K2,{rows:t})]}):E.jsx("pre",{className:"text-xs whitespace-pre-wrap break-words",children:JSON.stringify(e,null,2)})}function K2({rows:e}){const t=[...new Set(e.flatMap(Object.keys))];return E.jsx("div",{className:"overflow-auto max-h-96 rounded border text-xs",children:E.jsxs("table",{className:"w-full text-left",children:[E.jsx("thead",{className:"bg-muted sticky top-0",children:E.jsx("tr",{children:t.map(n=>E.jsx("th",{className:"px-2 py-1 font-medium",children:n},n))})}),E.jsx("tbody",{children:e.map((n,r)=>E.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 E.jsx("td",{className:"px-2 py-1 max-w-[400px] whitespace-pre-wrap break-words align-top",title:s,children:s},i)})},r))})]})})}const F1=/^\/uploads\//;function pA({src:e,alt:t,className:n,onClick:r}){const{getToken:i}=iE(),[a,s]=y.useState(F1.test(e)?null:e);return y.useEffect(()=>{if(!F1.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?E.jsx("img",{src:a,alt:t??"",className:n,onClick:()=>r==null?void 0:r(a)}):E.jsx("div",{className:n,"aria-busy":"true"})}function tke({src:e,name:t,className:n}){const{getToken:r}=iE(),i=async a=>{if(F1.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 E.jsxs("a",{href:e,onClick:i,target:"_blank",rel:"noopener noreferrer",className:n,children:[E.jsx(sE,{className:"w-4 h-4 shrink-0"}),E.jsx("span",{className:"truncate max-w-[200px]",children:t})]})}const H1=1,_6=10,pd={scale:1,tx:0,ty:0},q2=e=>Math.min(_6,Math.max(H1,e));function nke({src:e,alt:t=""}){const n=y.useRef(null),r=y.useRef(null),[i,a]=y.useState(pd),[s,c]=y.useState(!1),u=(_,O)=>{var C;const k=(C=n.current)==null?void 0:C.getBoundingClientRect();return k?{cx:_-k.left-k.width/2,cy:O-k.top-k.height/2}:{cx:0,cy:0}},f=y.useCallback((_,O,k)=>{a(C=>{const N=q2(_);if(N===C.scale)return C;if(N<=H1)return pd;const T=N/C.scale;return{scale:N,tx:O-T*(O-C.tx),ty:k-T*(k-C.ty)}})},[]),h=_=>{_.preventDefault();const{cx:O,cy:k}=u(_.clientX,_.clientY),C=_.deltaY<0?1.15:1/1.15;a(N=>{const T=q2(N.scale*C);if(T===N.scale)return N;if(T<=H1)return pd;const R=T/N.scale;return{scale:T,tx:O-R*(O-N.tx),ty:k-R*(k-N.ty)}})},p=_=>{i.scale<=1||(_.currentTarget.setPointerCapture(_.pointerId),r.current={x:_.clientX,y:_.clientY,tx:i.tx,ty:i.ty},c(!0))},m=_=>{const O=r.current;O&&a(k=>({...k,tx:O.tx+(_.clientX-O.x),ty:O.ty+(_.clientY-O.y)}))},v=()=>{r.current=null,c(!1)},x=_=>{const{cx:O,cy:k}=u(_.clientX,_.clientY);i.scale>1?a(pd):f(2.5,O,k)},b=_=>f(i.scale*_,0,0),S=i.scale>1;return E.jsxs("div",{className:"relative w-full h-full flex items-center justify-center",children:[E.jsx("div",{ref:n,className:"w-full h-full overflow-hidden flex items-center justify-center",onWheel:h,onPointerDown:p,onPointerMove:m,onPointerUp:v,onPointerCancel:v,onDoubleClick:x,style:{cursor:S?s?"grabbing":"grab":"zoom-in",touchAction:"none"},children:E.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"}})}),E.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:[E.jsx("button",{type:"button",onClick:()=>b(1/1.4),title:"Zoom out",className:"p-1.5 rounded-full hover:bg-muted transition-colors disabled:opacity-40",disabled:!S,children:E.jsx(sG,{className:"w-4 h-4"})}),E.jsxs("span",{className:"text-xs tabular-nums w-11 text-center text-muted-foreground select-none",children:[Math.round(i.scale*100),"%"]}),E.jsx("button",{type:"button",onClick:()=>b(1.4),title:"Zoom in",className:"p-1.5 rounded-full hover:bg-muted transition-colors disabled:opacity-40",disabled:i.scale>=_6,children:E.jsx(oG,{className:"w-4 h-4"})}),E.jsx("button",{type:"button",onClick:()=>a(pd),title:"Reset",className:"p-1.5 rounded-full hover:bg-muted transition-colors disabled:opacity-40",disabled:!S,children:E.jsx(lE,{className:"w-4 h-4"})})]})]})}const rke=new Set(["p","li","h1","h2","h3","h4","h5","h6","blockquote","td","th"]),ike=()=>e=>{const t=n=>{for(const r of n.children??[])r.type==="element"&&(rke.has(r.tagName)&&(r.properties??(r.properties={}),r.properties.dir="auto"),t(r))};t(e)};var uD,fD;const ake=typeof window<"u"&&!!((fD=(uD=window.webkit)==null?void 0:uD.messageHandlers)!=null&&fD.appwrap);function oke({text:e,onImageClick:t}){const n=e.replace(/\[Image #\d+\]\s*/g,"").trim();return ake?E.jsx("div",{className:"prose prose-sm max-w-none dark:prose-invert break-words min-w-0 whitespace-pre-wrap",children:n}):E.jsx(bL,{remarkPlugins:[HL],rehypePlugins:[fz,ike],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})=>E.jsx(wke,{...i,children:r}),a:({href:r,children:i})=>E.jsx("a",{href:r,target:"_blank",rel:"noopener noreferrer",children:i}),img:({src:r,alt:i})=>E.jsx(pA,{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 G2(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 W2="shraga:showDetails";function ske({messages:e,busy:t,connectionStatus:n,onPermissionRespond:r,onQuestionRespond:i,onReplay:a,onEdit:s,onFork:c,multiParticipant:u,statusItems:f}){var N;const h=Sa(),p=y.useRef(null),m=y.useRef(null),v=y.useRef(!0),[x,b]=y.useState(()=>localStorage.getItem(W2)==="true"),[S,_]=y.useState(null),O=()=>{const T=m.current;T&&(v.current=T.scrollHeight-T.scrollTop-T.clientHeight<80)},k=y.useMemo(()=>pke(e),[e]);if(y.useEffect(()=>{var T;v.current&&((T=p.current)==null||T.scrollIntoView({behavior:"smooth"}))},[e,t]),e.length===0&&!t)return E.jsx("div",{className:"flex-1 flex items-center justify-center",children:E.jsxs("div",{className:"text-center space-y-3 max-w-md px-4",children:[E.jsx("div",{className:"mx-auto w-12 h-12 rounded-full bg-muted flex items-center justify-center",children:E.jsx(cu,{className:"w-6 h-6 text-muted-foreground"})}),E.jsx("h2",{className:"text-lg font-medium",children:"How can I help?"}),E.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=()=>{b(T=>(localStorage.setItem(W2,String(!T)),!T))};return E.jsxs("div",{ref:m,onScroll:O,className:"flex-1 overflow-y-auto overflow-x-hidden",children:[E.jsxs("div",{className:"max-w-3xl mx-auto px-2 sm:px-4 py-4 sm:py-6 space-y-1",children:[E.jsx("div",{className:"flex justify-end mb-2",children:E.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:x?"Hide tool details":"Show tool details",children:[x?E.jsx(Bq,{className:"w-3.5 h-3.5"}):E.jsx($q,{className:"w-3.5 h-3.5"}),"Details"]})}),e.map((T,R)=>E.jsx(lke,{message:T,messageIndex:R,isLast:R===e.length-1,showDetails:x,onPermissionRespond:r,onQuestionRespond:i,onReplay:a,onEdit:s,onFork:c,onImageClick:_,busy:t&&R===e.length-1,screenMap:k,multiParticipant:u},T.id)),t&&((N=e[e.length-1])==null?void 0:N.role)!=="assistant"&&E.jsxs("div",{className:"flex gap-3 py-4",children:[E.jsx("div",{className:"w-7 h-7 rounded-full bg-muted flex items-center justify-center shrink-0 mt-0.5",children:E.jsx(cu,{className:"w-4 h-4 text-muted-foreground"})}),E.jsx("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:E.jsxs("span",{className:"inline-flex gap-1",children:[E.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-muted-foreground animate-bounce",style:{animationDelay:"0ms"}}),E.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-muted-foreground animate-bounce",style:{animationDelay:"150ms"}}),E.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&&E.jsxs("div",{className:"flex gap-3 py-2",children:[E.jsx("div",{className:"w-7 h-7 rounded-full bg-muted flex items-center justify-center shrink-0 mt-0.5",children:E.jsx(cu,{className:"w-4 h-4 text-muted-foreground"})}),E.jsx("div",{className:"flex-1 min-w-0 pt-1",children:h.statusChips(f)})]}),n&&n!=="update_available"&&E.jsx("div",{className:He("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."}),E.jsx("div",{ref:p})]}),E.jsx(Es,{open:!!S,onOpenChange:T=>{T||_(null)},children:E.jsx(uo,{className:"max-w-[90vw] max-h-[90vh] w-[90vw] h-[90vh] p-2 flex items-center justify-center bg-background/95",children:S&&E.jsx(nke,{src:S})})})]})}function lke({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:m}){var P;const v=e.blocks.find(F=>F.type==="compact_marker");if(v&&v.type==="compact_marker")return E.jsx(cke,{summary:v.summary,compactedCount:v.compactedCount});const x=e.role==="user",b=x?((P=e.blocks.find(F=>F.type==="text"))==null?void 0:P.text)??"":"",S=x?e.blocks.filter(F=>F.type==="image"||F.type==="file").map(F=>F.type==="image"?{url:F.src,name:F.src.split("/").pop()??"image",mimeType:"image/png",path:F.src}:{url:F.src,name:F.name,mimeType:F.mimeType,path:F.src}):void 0,[_,O]=y.useState(!1),[k,C]=y.useState(""),[N,T]=y.useState(!1),R=y.useRef(null),L=()=>{C(b),O(!0),setTimeout(()=>{const F=R.current;F&&(F.style.height="auto",F.style.height=F.scrollHeight+"px",F.focus(),F.setSelectionRange(F.value.length,F.value.length))},0)},D=()=>{const F=k.trim();F&&(O(!1),c==null||c(e.id,F,S!=null&&S.length?S:void 0))};return E.jsxs("div",{className:He("flex gap-3 py-4 group/row",x&&"flex-row-reverse"),onTouchStart:F=>{F.target.closest("button")||T(I=>!I)},children:[!x&&E.jsx("div",{className:"w-7 h-7 rounded-full bg-primary/10 flex items-center justify-center shrink-0 mt-0.5",children:E.jsx(cu,{className:"w-4 h-4 text-primary"})}),x&&E.jsx("div",{className:"w-7 h-7 rounded-full bg-muted flex items-center justify-center shrink-0 mt-0.5",children:E.jsx(iG,{className:"w-4 h-4 text-muted-foreground"})}),E.jsxs("div",{className:He("min-w-0 max-w-[92%] sm:max-w-[85%] space-y-2"),children:[m&&x&&e.senderName&&E.jsx("div",{className:"text-[11px] font-medium text-muted-foreground text-right px-1",children:e.senderName}),_?E.jsxs("div",{className:"inline-block text-left w-full",children:[E.jsx("textarea",{ref:R,value:k,onChange:F=>{C(F.target.value),F.target.style.height="auto",F.target.style.height=F.target.scrollHeight+"px"},onKeyDown:F=>{F.key==="Enter"&&!F.shiftKey&&(F.preventDefault(),D()),F.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]"}),E.jsxs("div",{className:"flex gap-1 justify-end mt-1",children:[E.jsx("button",{onClick:()=>O(!1),className:"p-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted transition-colors",title:"Cancel",children:E.jsx(Rl,{className:"w-3.5 h-3.5"})}),E.jsx("button",{onClick:D,className:"p-1 rounded-md text-primary hover:bg-primary/10 transition-colors",title:"Send",children:E.jsx(tg,{className:"w-3.5 h-3.5"})})]})]}):E.jsxs(E.Fragment,{children:[e.blocks.filter(F=>r?!0:F.type==="tool_use"&&F.tool==="AskUserQuestion"?e.blocks.some(I=>I.type==="tool_result"&&I.toolUseId===F.toolUseId):F.type!=="tool_use"&&F.type!=="tool_result"&&F.type!=="thinking").filter(F=>F.type!=="tool_result"?!0:!e.blocks.some(I=>I.type==="tool_use"&&I.toolUseId===F.toolUseId)).map((F,I,U)=>{const G=F.type==="tool_use"?e.blocks.find(q=>q.type==="tool_result"&&q.toolUseId===F.toolUseId):void 0;return E.jsx(uke,{block:F,isUser:x,ts:e.ts,onPermissionRespond:i,onQuestionRespond:a,pairedResult:G,onImageClick:f,busy:h,screenMap:p},I)}),x&&b&&E.jsxs("div",{className:He("flex gap-1 items-center justify-end transition-opacity",N?"opacity-100":"opacity-0 group-hover/row:opacity-100"),children:[e.ts&&E.jsx("span",{className:"text-[10px] text-muted-foreground/50 select-none mr-1",children:G2(e.ts)}),E.jsx("button",{onClick:()=>s==null?void 0:s(e.id,b,S!=null&&S.length?S:void 0),className:"p-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted transition-colors",title:"Replay",children:E.jsx(Jq,{className:"w-3.5 h-3.5"})}),E.jsx("button",{onClick:L,className:"p-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted transition-colors",title:"Edit & resend",children:E.jsx(uE,{className:"w-3.5 h-3.5"})})]}),!x&&!(h&&n)&&E.jsxs("div",{className:He("flex gap-1 items-center transition-opacity",N?"opacity-100":"opacity-0 group-hover/row:opacity-100"),children:[e.ts&&E.jsx("span",{className:"text-[10px] text-muted-foreground/40 select-none mr-1",children:G2(e.ts)}),E.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:E.jsx(vj,{className:"w-3.5 h-3.5"})})]})]})]})]})}function cke({summary:e,compactedCount:t}){const[n,r]=y.useState(!1);return E.jsxs("div",{className:"py-3",children:[E.jsxs("div",{className:"flex items-center gap-3",children:[E.jsx("div",{className:"flex-1 border-t border-amber-500/30"}),E.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:[E.jsx(cE,{className:"w-3 h-3"}),"Compacted · ",t," messages",E.jsx(Is,{className:He("w-3 h-3 transition-transform",n&&"rotate-90")})]}),E.jsx("div",{className:"flex-1 border-t border-amber-500/30"})]}),n&&E.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 uke({block:e,isUser:t,ts:n,onPermissionRespond:r,onQuestionRespond:i,pairedResult:a,onImageClick:s,busy:c,screenMap:u}){var h;const f=Sa();return e.type==="image"?E.jsx(pA,{src:e.src,className:"max-h-[80vh] max-w-full rounded-xl border object-contain cursor-pointer hover:opacity-80 transition-opacity",onClick:p=>s==null?void 0:s(p)}):e.type==="file"?E.jsx("div",{children:E.jsx(tke,{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"?E.jsx(dke,{label:e.label,text:e.text}):e.type==="thinking"?E.jsx(hke,{text:e.text}):e.type==="error"?E.jsx(fke,{text:e.text,ts:n}):e.type==="text"?t?E.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}):E.jsx("div",{className:"text-sm",dir:"auto",children:E.jsx(oke,{text:e.text,onImageClick:s})}):e.type==="tool_use"?e.tool==="AskUserQuestion"&&(a!=null&&a.output)?E.jsx(gke,{input:e.input,result:a.output}):E.jsx(vke,{block:e,tool:e.tool,input:e.input,result:a==null?void 0:a.output,busy:c,screenMap:u}):e.type==="tool_result"?E.jsx(yke,{output:e.output}):e.type==="permission_request"?E.jsx(bke,{id:e.id,tool:e.tool,input:e.input,onRespond:r}):e.type==="question_request"?E.jsx(xke,{id:e.id,questions:e.questions,onRespond:i}):((h=f.extensionBlocks)==null?void 0:h.call(f,{block:e,onImageClick:s}))??null}function fke({text:e,ts:t}){const n=kne(e,t??Date.now());return E.jsxs("div",{dir:"auto",className:"border border-destructive/40 rounded-lg bg-destructive/10 px-3 py-2 text-sm text-destructive break-words",children:[E.jsx("span",{className:"font-medium",children:"⚠️ Run failed"}),E.jsx("div",{className:"mt-1 text-xs opacity-90 whitespace-pre-wrap font-mono",children:n})]})}function dke({label:e,text:t}){const[n,r]=y.useState(!1);return E.jsxs("div",{className:"border border-blue-500/20 rounded-lg overflow-hidden text-xs bg-blue-500/5",children:[E.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:[E.jsx(qq,{className:"w-3.5 h-3.5 text-blue-400 shrink-0"}),E.jsx("span",{className:"text-blue-300 font-medium",children:e}),E.jsx(Is,{className:He("w-3.5 h-3.5 text-muted-foreground transition-transform shrink-0 ml-auto",n&&"rotate-90")})]}),n&&E.jsx("div",{className:"px-3 py-2 border-t border-blue-500/20 text-muted-foreground whitespace-pre-wrap",children:t})]})}function hke({text:e}){const[t,n]=y.useState(!1),r=e.slice(0,120).replace(/\n/g," ");return E.jsxs("div",{className:"border border-violet-500/20 rounded-lg overflow-hidden text-xs bg-violet-500/5",children:[E.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:[E.jsx(jq,{className:"w-3.5 h-3.5 text-violet-400 shrink-0"}),E.jsx("span",{className:"text-violet-300 font-medium",children:"Thinking"}),E.jsx("span",{className:"text-muted-foreground truncate",children:r}),E.jsx(Is,{className:He("w-3.5 h-3.5 text-muted-foreground transition-transform shrink-0 ml-auto",t&&"rotate-90")})]}),t&&E.jsx("div",{className:"px-3 py-2 border-t border-violet-500/20 text-muted-foreground whitespace-pre-wrap",children:e})]})}function pke(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 mke(e){const t={},n=/"([^"]+)"="([^"]+)"/g;let r;for(;(r=n.exec(e))!==null;)t[r[1]]=r[2];return t}function gke({input:e,result:t}){const n=e,r=(n==null?void 0:n.questions)??[],i=mke(t);return!r.length||!Object.keys(i).length?null:E.jsxs("div",{className:"border rounded-lg overflow-hidden text-xs bg-blue-500/5 border-blue-500/20",children:[E.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:[E.jsx(fE,{className:"w-3.5 h-3.5 text-blue-400 shrink-0"}),E.jsx("span",{className:"font-medium text-blue-300",children:"Questions answered"})]}),E.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?E.jsxs("div",{className:"space-y-0.5",children:[E.jsxs("div",{className:"text-muted-foreground",children:[a.header?`${a.header}: `:"",a.question]}),E.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:[E.jsx(ha,{className:"w-2.5 h-2.5"}),c]})]},s):null})})]})}function vke({block:e,tool:t,input:n,result:r,busy:i,screenMap:a}){var S;const s=Sa(),[c,u]=y.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),m=r!=null?A6(r.trim().replace(/\[Image #\d+\]\s*/g,"").trim()):void 0,v=r!=null,x=m?/^(Error|ERROR)|"status"\s*:\s*[45]\d\d|ENOENT|EACCES|Permission denied|command not found|No such file/i.test(m):!1,b=v?x?E.jsx(eg,{className:"w-3 h-3 text-red-400 shrink-0"}):E.jsx(ha,{className:"w-3 h-3 text-green-400 shrink-0"}):null;return E.jsxs("div",{className:"text-xs min-w-0 space-y-2",children:[E.jsxs("div",{className:"border rounded-lg overflow-hidden",children:[E.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:[E.jsx(aG,{className:"w-3.5 h-3.5 text-muted-foreground shrink-0"}),E.jsx("span",{className:"font-medium text-foreground shrink-0",children:t}),!h&&E.jsx("span",{className:"text-muted-foreground truncate min-w-0",children:p}),v?b:i?E.jsx(Nd,{className:"w-3 h-3 text-muted-foreground animate-spin shrink-0"}):E.jsx("span",{title:"Interrupted",children:E.jsx(eg,{className:"w-3 h-3 text-amber-400 shrink-0"})}),E.jsx(Is,{className:He("w-3.5 h-3.5 text-muted-foreground transition-transform shrink-0 ml-auto",c&&"rotate-90")})]}),c&&E.jsxs("div",{className:"border-t",children:[!h&&E.jsx("pre",{className:"p-3 overflow-auto max-h-64 text-xs bg-background whitespace-pre-wrap break-all",children:f}),m&&E.jsx("pre",{className:He("p-3 overflow-auto max-h-64 text-xs whitespace-pre-wrap break-words",!h&&"border-t",x?"bg-red-50 dark:bg-red-950/20 text-red-700 dark:text-red-300":"bg-muted/30 text-foreground/80"),children:m})]})]}),(S=s.toolRenderers)==null?void 0:S.call(s,{block:e,result:r,screens:a})]})}function A6(e){const t=e.split(`
|
|
1943
1943
|
`);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(`
|
|
1944
1944
|
`)}function yke({output:e}){const[t,n]=y.useState(!1),r=e.trim().replace(/\[Image #\d+\]\s*/g,"").trim(),i=A6(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:VAe(i),c=i.length>200,u=i.slice(0,120).replace(/\n/g," "),f=a?eg:ha,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",m=a?"text-red-600 dark:text-red-400":"text-green-600 dark:text-green-400";return E.jsxs("div",{className:He("border rounded-lg overflow-hidden text-xs min-w-0",h),children:[E.jsxs("button",{onClick:()=>n(!t),className:He("flex items-center gap-1.5 w-full px-2 sm:px-3 py-2 transition-colors text-left min-w-0",p),children:[E.jsx(f,{className:He("w-3.5 h-3.5 shrink-0",m)}),E.jsx("span",{className:"text-muted-foreground truncate flex-1 min-w-0",children:c?u+"…":u}),E.jsx(Is,{className:He("w-3.5 h-3.5 text-muted-foreground transition-transform shrink-0",t&&"rotate-90")})]}),t&&E.jsx("div",{className:"p-3 bg-background border-t",children:s?E.jsx(eke,{data:s}):E.jsx("pre",{className:"overflow-auto max-h-96 text-xs whitespace-pre-wrap break-words",children:i})})]})}function bke({id:e,tool:t,input:n,onRespond:r}){const[i,a]=y.useState(!1),s=JSON.stringify(n,null,2),c=Object.keys(n).join(", ");return E.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:[E.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:[E.jsx(fE,{className:"w-4 h-4 text-amber-600 dark:text-amber-400 shrink-0"}),E.jsx("span",{className:"font-medium text-foreground shrink-0",children:t}),E.jsxs("button",{onClick:()=>a(!i),className:"text-muted-foreground truncate min-w-0 text-left hover:text-foreground transition-colors",children:[c,E.jsx(Is,{className:He("w-3.5 h-3.5 inline ml-1 transition-transform",i&&"rotate-90")})]})]}),i&&E.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}),E.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:[E.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:[E.jsx(RT,{className:"w-3.5 h-3.5"}),"Allow"]}),E.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:[E.jsx(RT,{className:"w-3.5 h-3.5"}),"Always Allow"]}),E.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:[E.jsx(eg,{className:"w-3.5 h-3.5"}),"Deny"]})]})]})}function xke({id:e,questions:t,onRespond:n}){const[r,i]=y.useState({}),[a,s]=y.useState({}),[c,u]=y.useState(!1),f=Sa();y.useEffect(()=>{var b;return(b=f.onCardInteraction)==null?void 0:b.call(f,{id:e,questions:t,onAnswers:S=>{i(()=>{const _={};return t.forEach((O,k)=>{const C=S[O.question];C!=null&&(_[k]=new Set(Array.isArray(C)?C:[C]))}),_})}})},[e,t,f]);const h=(b,S,_)=>{i(O=>{const k=new Set(O[b]??[]);return _?k.has(S)?k.delete(S):k.add(S):(k.clear(),k.add(S)),{...O,[b]:k}})},p="__other__",m=t.filter((b,S)=>{var O;const _=r[S];return!(!_||_.size===0||_.has(p)&&!((O=a[S])!=null&&O.trim()))}).length,v=m===t.length,x=()=>{if(!v||c)return;const b={};t.forEach((S,_)=>{const O=[...r[_]??[]].map(k=>k===p?a[_].trim():k);b[S.question]=S.multiSelect?O:O[0]}),u(!0),n==null||n(e,b)};return E.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:[E.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:[E.jsx(fE,{className:"w-4 h-4 text-blue-600 dark:text-blue-400 shrink-0"}),E.jsx("span",{className:"font-medium text-foreground",children:"Questions for you"})]}),E.jsx("div",{className:"px-2 sm:px-3 py-2 space-y-4 bg-background",children:t.map((b,S)=>{const _=!!b.multiSelect,O=r[S]??new Set;return E.jsxs("div",{className:"space-y-1.5",children:[E.jsx("div",{className:"font-medium text-foreground",children:b.question}),E.jsxs("div",{className:"space-y-1",children:[b.options.map(k=>E.jsxs("button",{disabled:c,onClick:()=>h(S,k.label,_),className:He("flex items-start gap-2 w-full text-left px-2 py-1.5 rounded-md border transition-colors",O.has(k.label)?"border-blue-500 bg-blue-50 dark:bg-blue-950/40":"border-border hover:bg-muted/50"),children:[E.jsx("span",{className:He("mt-0.5 w-3.5 h-3.5 shrink-0 border flex items-center justify-center",_?"rounded-sm":"rounded-full",O.has(k.label)?"bg-blue-500 border-blue-500":"border-muted-foreground"),children:O.has(k.label)&&E.jsx(ha,{className:"w-2.5 h-2.5 text-white"})}),E.jsxs("span",{className:"min-w-0",children:[E.jsx("span",{className:"font-medium text-foreground",children:k.label}),k.description&&E.jsxs("span",{className:"text-muted-foreground",children:[" — ",k.description]})]})]},k.label)),E.jsxs("div",{className:He("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:[E.jsx("button",{disabled:c,onClick:()=>h(S,p,_),className:He("w-3.5 h-3.5 shrink-0 border flex items-center justify-center",_?"rounded-sm":"rounded-full",O.has(p)?"bg-blue-500 border-blue-500":"border-muted-foreground"),children:O.has(p)&&E.jsx(ha,{className:"w-2.5 h-2.5 text-white"})}),E.jsx("input",{type:"text",disabled:c,value:a[S]??"",placeholder:"Other…",onChange:k=>{s(C=>({...C,[S]:k.target.value})),k.target.value&&!O.has(p)&&h(S,p,_)},className:"flex-1 bg-transparent outline-none text-foreground placeholder:text-muted-foreground"})]})]})]},S)})}),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:[E.jsxs("button",{onClick:x,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:[E.jsx(tg,{className:"w-3.5 h-3.5"}),c?"Sent":"Submit"]}),E.jsxs("span",{className:"text-muted-foreground",children:[m,"/",t.length," answered"]})]})]})}function wke({children:e,...t}){const n=y.useRef(null);return E.jsxs("div",{className:"relative group",children:[E.jsx("pre",{ref:n,...t,className:"rounded-lg border bg-muted p-4 overflow-x-auto text-xs text-foreground",children:e}),E.jsx(Eke,{getText:()=>{var r;return((r=n.current)==null?void 0:r.textContent)||""}})]})}function Eke({getText:e}){const[t,n]=y.useState(!1);return E.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?E.jsx(ha,{className:"w-3 h-3"}):E.jsx(oE,{className:"w-3 h-3"})})}const k6=y.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:m=200},v){const x=y.useRef(null),[b,S]=y.useState(null),[_,O]=y.useState(0);y.useImperativeHandle(v,()=>({focus:()=>{var L;return(L=x.current)==null?void 0:L.focus()},setValue:L=>{n(L),p&&C()}}));const k=b?[...a.filter(L=>L.toLowerCase().includes(b.query.toLowerCase())).map(L=>({kind:"skill",value:L})),...b.kind==="mention"?s.filter(L=>L.toLowerCase().includes(b.query.toLowerCase())).map(L=>({kind:"workspace",value:L})):[]]:[];function C(){setTimeout(()=>{const L=x.current;L&&(L.style.height="auto",L.style.height=Math.min(L.scrollHeight,m)+"px")},0)}const N=L=>{if(!b)return;const D=b.kind==="command"?"/":"@",P=t.slice(0,b.start),F=t.slice(b.start+b.query.length+1),I=`${P}${D}${L} ${F}`;n(I),S(null),setTimeout(()=>{const U=x.current;if(!U)return;p&&(U.style.height="auto",U.style.height=Math.min(U.scrollHeight,m)+"px");const G=P.length+L.length+2;U.setSelectionRange(G,G),U.focus()},0)},T=L=>{if(b&&k.length>0){if(L.key==="ArrowDown"){L.preventDefault(),O(D=>(D+1)%k.length);return}if(L.key==="ArrowUp"){L.preventDefault(),O(D=>(D-1+k.length)%k.length);return}if(L.key==="Enter"||L.key==="Tab"){L.preventDefault(),N(k[_].value);return}if(L.key==="Escape"){S(null);return}}r==null||r(L)},R=L=>{const D=L.target.value;n(D);const P=L.target;p&&(P.style.height="auto",P.style.height=Math.min(P.scrollHeight,m)+"px");const F=P.selectionStart??D.length,I=D.slice(0,F),U=I.match(/(?:^|\n)\/([\w-]*)$/),G=I.match(/@([\w\-./]*)$/);U?(S({query:U[1],start:U.index+(I[U.index]===`
|
|
1945
|
-
`?1:0),kind:"command"}),O(0)):G?(S({query:G[1],start:G.index,kind:"mention"}),O(0)):S(null)};return y.useEffect(()=>{const L=()=>S(null);return b&&document.addEventListener("mousedown",L),()=>document.removeEventListener("mousedown",L)},[b]),E.jsxs("div",{className:"relative flex-1 min-w-0",children:[b&&k.length>0&&E.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:k.map((L,D)=>E.jsxs("button",{onMouseDown:P=>{P.preventDefault(),N(L.value)},className:`w-full text-left px-3 py-1.5 text-sm hover:bg-accent transition-colors flex items-center gap-2 ${D===_?"bg-accent":""}`,children:[E.jsx("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground shrink-0 w-14",children:(b==null?void 0:b.kind)==="command"?"cmd":L.kind==="skill"?"skill":"file"}),E.jsxs("span",{className:"truncate",children:[E.jsx("span",{className:"text-muted-foreground",children:(b==null?void 0:b.kind)==="command"?"/":"@"}),L.value]})]},`${L.kind}:${L.value}`))}),E.jsx("textarea",{ref:x,value:t,onChange:R,onKeyDown:T,onPaste:i,placeholder:c,disabled:h,rows:f,dir:"auto",className:u})]})}),mA="shraga:draft:";function ew(e,t){const n=mA+(e??"new");t.trim()?localStorage.setItem(n,t):localStorage.removeItem(n)}function V2(e){return localStorage.getItem(mA+(e??"new"))??""}function Y2(e){localStorage.removeItem(mA+(e??"new"))}const Ske=y.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:m,inputCtx:v},x){var $,W;const b=Sa(),[S,_]=y.useState(()=>V2(m)),[O,k]=y.useState([]),[C,N]=y.useState(!1),T=y.useRef(null),R=y.useRef(null),L=y.useRef(m);y.useEffect(()=>{var j;if(L.current===m)return;const K=L.current;if(L.current=m,!m){Y2(K),ew(void 0,S);return}ew(K,S);const X=V2(m);_(X),(j=R.current)==null||j.setValue(X)},[m]);const D=y.useCallback(K=>{_(K),ew(L.current,K)},[]);y.useImperativeHandle(x,()=>({prefill(K){var X,j;D(K),(X=R.current)==null||X.setValue(K),(j=R.current)==null||j.focus()},setText(K){var X;D(K),(X=R.current)==null||X.setValue(K)},focus(){var K;(K=R.current)==null||K.focus()}}));const P=(K="send")=>{var j;const X=S.trim();!X&&O.length===0||(K==="steer"?n(X):K==="queue"?r(X):t(X,O.length>0?O:void 0),_(""),Y2(L.current),k([]),(j=R.current)==null||j.setValue(""))},F=typeof window<"u"&&(($=window.matchMedia)==null?void 0:$.call(window,"(pointer: coarse)").matches),I=K=>{if(K.key==="Enter"&&!K.shiftKey&&(!F||K.metaKey||K.ctrlKey)){K.preventDefault(),P(f?"steer":"send");return}if(K.key==="Tab"&&f&&S.trim()){K.preventDefault(),P("queue");return}},U=y.useCallback(async K=>{N(!0);try{const X=await s(K);X&&k(j=>[...j,X])}finally{N(!1)}},[s]),G=y.useCallback(K=>{const X=Array.from(K.clipboardData.items);for(const j of X)if(j.type.startsWith("image/")||j.type==="application/pdf"){const H=j.getAsFile();H&&U(H)}},[U]),q=K=>{var j;const X=(j=K.target.files)==null?void 0:j[0];X&&(U(X),K.target.value="")};return E.jsx("div",{className:"border-t bg-background",style:{paddingBottom:"env(safe-area-inset-bottom)"},children:E.jsxs("div",{className:"max-w-3xl mx-auto px-2 sm:px-4 py-3",children:[(O.length>0||C)&&E.jsxs("div",{className:"flex gap-2 mb-2 flex-wrap items-center",children:[O.map((K,X)=>E.jsxs("div",{className:"relative group",children:[K.mimeType.startsWith("image/")?E.jsx(pA,{src:K.url,alt:K.name,className:"h-16 w-16 object-cover rounded-lg border"}):E.jsxs("div",{className:"h-16 px-3 flex items-center gap-2 rounded-lg border bg-muted/50 text-xs text-muted-foreground",children:[E.jsx(sE,{className:"w-4 h-4 shrink-0"}),E.jsx("span",{className:"truncate max-w-[120px]",children:K.name})]}),E.jsx("button",{onClick:()=>k(j=>j.filter((H,Q)=>Q!==X)),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:E.jsx(Rl,{className:"w-3 h-3"})})]},X)),C&&E.jsx("span",{className:"text-xs text-muted-foreground animate-pulse",children:"Uploading…"})]}),E.jsxs("div",{className:"flex items-center gap-2 bg-muted/50 rounded-xl border px-3 py-2",children:[E.jsx(Re,{variant:"ghost",size:"icon",className:"h-9 w-9 sm:h-8 sm:w-8 shrink-0",onClick:()=>{var K;return(K=T.current)==null?void 0:K.click()},disabled:u,title:"Attach file or image",children:E.jsx(Xq,{className:"w-4 h-4"})}),E.jsx("input",{ref:T,type:"file",className:"hidden",onChange:q}),E.jsx(k6,{ref:R,value:S,onChange:D,onKeyDown:I,onPaste:G,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]"}),(W=b.inputAdornments)==null?void 0:W.call(b,v),f?E.jsxs("div",{className:"flex items-center gap-2",children:[S.trim()&&E.jsx(Re,{size:"icon",className:"h-9 w-9 sm:h-8 sm:w-8 shrink-0 rounded-lg",onClick:()=>P("steer"),title:"Steer (inject into current turn)",children:E.jsx(tg,{className:"w-4 h-4"})}),E.jsx(Re,{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:E.jsx(xj,{className:"w-3.5 h-3.5"})})]}):E.jsx(Re,{size:"icon",className:"h-9 w-9 sm:h-8 sm:w-8 shrink-0 rounded-lg",onClick:()=>P(),disabled:u||C||!S.trim()&&O.length===0,children:E.jsx(tg,{className:"w-4 h-4"})})]}),a.length>0&&E.jsx("div",{className:"flex gap-1.5 flex-wrap mt-2",children:a.map((K,X)=>E.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:[E.jsx("span",{className:"truncate max-w-[200px]",children:K}),E.jsx("button",{onClick:()=>i(X),className:"hover:text-blue-900 dark:hover:text-blue-100",children:E.jsx(Rl,{className:"w-3 h-3"})})]},X))}),E.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"})]})})}),_ke={"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 Ake({artifacts:e,selectedId:t,sessionId:n,getToken:r,onSelect:i,onClose:a}){var R;const[s,c]=y.useState(!1),[u,f]=y.useState(!1),[h,p]=y.useState(!1),[m,v]=y.useState(1),x=y.useRef(null),b=e.find(L=>L.id===t),S=y.useCallback(()=>{if(!x.current||!b)return;const{clientWidth:L,clientHeight:D}=x.current,P=32,F=L-P,I=D-P,[U,G]=b.dimensions;v(Math.min(F/U,I/G,1))},[b]);y.useEffect(()=>{let L=!0;return r().then(D=>fetch("/api/features",{headers:D?{Authorization:`Bearer ${D}`}:{}})).then(D=>D.json()).then(D=>{L&&p(!!D.artifactPngExport)}).catch(D=>console.error("[artifact] features fetch failed:",D)),()=>{L=!1}},[r]),y.useEffect(()=>{S();const L=x.current;if(!L)return;const D=new ResizeObserver(S);return D.observe(L),()=>D.disconnect()},[S]);const _=async()=>{if(b){f(!0);try{const L=await r(),D=await fetch(`/api/artifacts/${n}/${b.id}/export`,{method:"POST",headers:{"Content-Type":"application/json",...L?{Authorization:`Bearer ${L}`}:{}},body:JSON.stringify({dimensions:b.dimensions})});if(!D.ok)throw new Error(await D.text());const P=await D.blob(),F=URL.createObjectURL(P),I=document.createElement("a");I.href=F,I.download=`${b.title.replace(/\s+/g,"-").toLowerCase()}.png`,I.click(),URL.revokeObjectURL(F)}catch(L){console.error("[artifact] export failed:",L)}finally{f(!1)}}},O=b?(R=Object.entries(_ke).find(([,L])=>L[0]===b.dimensions[0]&&L[1]===b.dimensions[1]))==null?void 0:R[0]:null,[k,C]=(b==null?void 0:b.dimensions)??[0,0],N=k*m,T=C*m;return E.jsxs("div",{className:He("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:[E.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1.5 border-b bg-muted/30",children:[E.jsx(Re,{variant:"ghost",size:"icon",className:"h-7 w-7 sm:hidden shrink-0",onClick:a,title:"Back to chat",children:E.jsx(mj,{className:"w-4 h-4"})}),e.length>1&&E.jsx("select",{className:"text-xs bg-transparent border rounded px-1 py-0.5 max-w-[160px] truncate",value:t??"",onChange:L=>i(L.target.value),children:e.map(L=>E.jsx("option",{value:L.id,children:L.title},L.id))}),e.length<=1&&b&&E.jsx("span",{className:"text-xs font-medium truncate max-w-[160px]",children:b.title}),b&&E.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[O??`${k}×${C}`,m<1&&` · ${Math.round(m*100)}%`]}),E.jsx("div",{className:"flex-1"}),h&&E.jsx(Re,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:_,disabled:!b||u,title:"Export PNG",children:u?E.jsx("span",{className:"w-3 h-3 border-2 border-current border-t-transparent rounded-full animate-spin"}):E.jsx(Kq,{className:"w-3.5 h-3.5"})}),E.jsx(Re,{variant:"ghost",size:"icon",className:"h-6 w-6 hidden sm:inline-flex",onClick:()=>c(!s),title:s?"Minimize":"Maximize",children:s?E.jsx(cE,{className:"w-3.5 h-3.5"}):E.jsx(lE,{className:"w-3.5 h-3.5"})}),E.jsx(Re,{variant:"ghost",size:"icon",className:"h-6 w-6 hidden sm:inline-flex",onClick:a,title:"Close",children:E.jsx(Rl,{className:"w-3.5 h-3.5"})})]}),E.jsx("div",{ref:x,className:"flex-1 overflow-hidden flex items-center justify-center bg-muted/10",children:b?E.jsx("div",{style:{width:N,height:T},children:E.jsx("iframe",{src:`/api/artifacts/${n}/${b.id}`,sandbox:"allow-scripts",className:"border shadow-sm bg-white origin-top-left",style:{width:k,height:C,transform:`scale(${m})`},title:b.title})}):E.jsx("p",{className:"text-sm text-muted-foreground",children:"No artifact selected"})})]})}const by=y.forwardRef(({className:e,...t},n)=>E.jsx("textarea",{className:He("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}));by.displayName="Textarea";const kke=[{value:"",label:"Default (claude-sonnet-5)"},{value:"claude-fable-5",label:"Fable 5 — frontier, most capable"},{value:"claude-opus-5",label:"Opus 5 — most capable, best for complex/agentic tasks"},{value:"claude-opus-4-8",label:"Opus 4.8"},{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"}],Oke=[{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 Cke({getToken:e,onSaved:t,trigger:n,sessionId:r,sessionDirectives:i,onDirectivesSaved:a}){var F;const s=Sa(),[c,u]=y.useState({}),[f,h]=y.useState(!1),[p,m]=y.useState(!1),[v,x]=y.useState([]),[b,S]=y.useState(!1),_=y.useRef({}),[O,k]=y.useState(!1);y.useEffect(()=>{f&&(k(!1),e().then(I=>{I&&(fetch("/api/config",{headers:{Authorization:`Bearer ${I}`}}).then(U=>U.json()).then(U=>{_.current=U;const G=r?i:void 0;u({...U,...(G==null?void 0:G.engine)!==void 0?{engine:G.engine}:{},...(G==null?void 0:G.model)!==void 0?{model:G.model}:{},...(G==null?void 0:G.turns)!==void 0?{maxTurns:G.turns}:{},...(G==null?void 0:G.thinking)!==void 0?{thinking:G.thinking}:{}})}).catch(()=>{}),fetch("/api/engines",{headers:{Authorization:`Bearer ${I}`}}).then(U=>U.json()).then(U=>{x(U.engines??[]),S(U.multiEngine??!1)}).catch(()=>{}))}))},[f,e,r,i]);const C=async()=>{m(!0);const U={Authorization:`Bearer ${await e()??""}`,"Content-Type":"application/json"};try{if(r){const G=O?{engine:"",model:"",turns:null,thinking:""}:{engine:c.engine,model:c.model,turns:c.maxTurns,thinking:c.thinking},q=await fetch(`/api/sessions/${r}/directives`,{method:"PUT",headers:U,body:JSON.stringify(G)}).then(W=>W.json()).catch(W=>(console.warn("[config] directives save failed",W),null));q!=null&&q.directives&&(a==null||a(q.directives));const $=O?c:{...c,engine:_.current.engine,model:_.current.model,maxTurns:_.current.maxTurns,thinking:_.current.thinking};await fetch("/api/config",{method:"PUT",headers:U,body:JSON.stringify($)}),t==null||t($)}else await fetch("/api/config",{method:"PUT",headers:U,body:JSON.stringify(c)}),t==null||t(c);h(!1)}finally{m(!1)}},N=c.engine||"claude-code",T=v.find(I=>I.name===N),R=(T==null?void 0:T.models)??kke;y.useEffect(()=>{!T||!R.length||R.some(I=>(I.value||"")===(c.model??""))||u(I=>({...I,model:R[0].value||void 0}))},[T,R,c.model]);const D=R.some(I=>I.provider)?Array.from(R.reduce((I,U)=>{const G=U.provider||"default";return I.has(G)||I.set(G,[]),I.get(G).push(U),I},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 E.jsxs(Es,{open:f,onOpenChange:h,children:[E.jsx(oh,{asChild:!0,children:n||E.jsx(Re,{variant:"ghost",size:"icon",title:"Agent Config",children:E.jsx(tG,{className:"w-4 h-4"})})}),E.jsxs(uo,{className:"max-w-lg",children:[E.jsx(Dl,{children:E.jsx(Ss,{children:"Agent Configuration"})}),E.jsxs(Lz,{className:"space-y-4",children:[r&&E.jsxs("div",{className:"text-xs text-muted-foreground rounded-md bg-muted/50 px-3 py-2 space-y-2",children:[E.jsxs("p",{children:["Engine, Model, Max Turns & Thinking apply to"," ",E.jsx("strong",{children:O?"every conversation":"this conversation"}),". Other settings are always global defaults."]}),E.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[E.jsx("input",{type:"checkbox",checked:O,onChange:I=>k(I.target.checked)}),E.jsx("span",{children:"Apply globally — also the default for Slack, email & scheduled runs"})]})]}),b&&E.jsxs("div",{children:[E.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Engine"}),E.jsx("select",{value:c.engine??"",onChange:I=>{const U=I.target.value||void 0;u(G=>({...G,engine:U,model:void 0}))},className:P,children:v.map(I=>E.jsx("option",{value:I.name,children:I.name==="claude-code"?"Claude Code (default)":I.name},I.name))})]}),E.jsxs("div",{children:[E.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Model"}),E.jsx("select",{value:c.model??"",onChange:I=>u(U=>({...U,model:I.target.value||void 0})),className:P,children:D?D.map(([I,U])=>E.jsx("optgroup",{label:I.charAt(0).toUpperCase()+I.slice(1),children:U.map(G=>E.jsx("option",{value:G.value,children:G.label},G.value))},I)):R.map(I=>E.jsx("option",{value:I.value,children:I.label},I.value))})]}),(F=s.settingsSections)==null?void 0:F.call(s,{getToken:e,sessionId:r}),E.jsxs("div",{children:[E.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Permission Mode"}),E.jsx("select",{value:c.permissionMode??"acceptEdits",onChange:I=>u(U=>({...U,permissionMode:I.target.value})),className:P,children:Oke.map(I=>E.jsx("option",{value:I.value,children:I.label},I.value))})]}),E.jsxs("div",{children:[E.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Max Turns"}),E.jsx(In,{type:"number",min:1,max:200,value:c.maxTurns??50,onChange:I=>u(U=>({...U,maxTurns:Number(I.target.value)||50}))})]}),E.jsxs("div",{children:[E.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Thinking"}),E.jsxs("select",{value:c.thinking??"",onChange:I=>u(U=>({...U,thinking:I.target.value||void 0})),className:P,children:[E.jsx("option",{value:"",children:"Default (off)"}),E.jsx("option",{value:"adaptive",children:"Adaptive (Claude decides)"}),E.jsx("option",{value:"enabled",children:"Enabled (always think)"}),E.jsx("option",{value:"disabled",children:"Disabled"})]})]}),E.jsxs("div",{children:[E.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Effort"}),E.jsxs("select",{value:c.effort??"",onChange:I=>u(U=>({...U,effort:I.target.value||void 0})),className:P,children:[E.jsx("option",{value:"",children:"Default"}),E.jsx("option",{value:"low",children:"Low — fast"}),E.jsx("option",{value:"medium",children:"Medium"}),E.jsx("option",{value:"high",children:"High"}),E.jsx("option",{value:"max",children:"Max"})]})]}),E.jsxs("div",{children:[E.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Allowed Tools"}),E.jsx(In,{placeholder:"Read, Edit, Bash, WebSearch, Glob, LS",value:(c.allowedTools??[]).join(", "),onChange:I=>u(U=>({...U,allowedTools:I.target.value.split(",").map(G=>G.trim()).filter(Boolean)}))}),E.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Comma-separated list of tools Claude can use"})]}),E.jsxs("div",{className:"flex items-center justify-between",children:[E.jsxs("div",{children:[E.jsx("label",{className:"text-sm font-medium",children:"Skill Discovery"}),E.jsx("p",{className:"text-xs text-muted-foreground",children:"Index all skills + auto-inject on trigger match"})]}),E.jsx("button",{type:"button",role:"switch","aria-checked":c.skillDiscovery!==!1,onClick:()=>u(I=>({...I,skillDiscovery:I.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:E.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"}`})})]}),E.jsxs("div",{children:[E.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"System Prompt (optional)"}),E.jsx(by,{placeholder:"Additional instructions appended to Claude's system prompt…",value:c.systemPrompt??"",onChange:I=>u(U=>({...U,systemPrompt:I.target.value||void 0})),rows:4})]})]}),E.jsx(zz,{children:E.jsx(Re,{onClick:C,disabled:p,children:p?"Saving…":"Save Configuration"})})]})]})}function Tke(e){const t=e.requestedEngine||"claude-code",n=e.actualEngine||t,r=e.actualEngine&&e.actualEngine!==t?t:void 0,i=n==="claude-code"||n==="cursor",a=(e.actualEngine?e.actualModel:void 0)||e.requestedModel||(n==="cursor"?"cursor/composer-2.5":"sonnet-4-6"),s=a.includes("/")?a.split("/")[0]:n==="claude-code"?"anthropic":n;return{engine:n,engineIsNative:i,engineMismatch:r,rawModel:a,billingProvider:s}}function Nke({sessionId:e,config:t,sessionDirectives:n,actualModel:r,actualEngine:i,scheduleId:a,onScheduleClick:s}){const[c,u]=y.useState(!1),{engine:f,engineIsNative:h,engineMismatch:p,rawModel:m,billingProvider:v}=Tke({requestedEngine:(n==null?void 0:n.engine)||t.engine,requestedModel:(n==null?void 0:n.model)||t.model,actualEngine:i,actualModel:r}),x=h?m.replace("claude-",""):`${f} · ${m.replace("claude-","")}`,b=f==="claude-code"&&t.claudeAuthSource==="subscription",S=b?"sub":v==="cursor"?"plan":"metered",_=S==="sub"?"bg-emerald-50 text-emerald-700 ring-emerald-600/20 dark:bg-emerald-950/50 dark:text-emerald-300 dark:ring-emerald-400/30":S==="plan"?"bg-amber-50 text-amber-700 ring-amber-600/20 dark:bg-amber-950/50 dark:text-amber-300 dark:ring-amber-400/30":"bg-rose-50 text-rose-700 ring-rose-600/20 dark:bg-rose-950/50 dark:text-rose-300 dark:ring-rose-400/30",O=S==="sub"?"Claude.ai subscription (OAuth login) — no API key in use":S==="plan"?`Runs on your ${v} API key — usage may draw on your ${v} plan/subscription`:`Runs on your ${v} API key — metered per-token billing`,k=t.permissionMode||"acceptEdits",C=k==="bypassPermissions"?"bypass":k==="plan"?"plan":k==="default"?"prompt":"edits",N=(n==null?void 0:n.thinking)||t.thinking,T=()=>{e&&(navigator.clipboard.writeText(e),u(!0),setTimeout(()=>u(!1),1500))};return E.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[E.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:x}),E.jsx("span",{title:O,className:`inline-flex items-center rounded-md px-1.5 py-0.5 text-[10px] font-medium ring-1 ring-inset ${_}`,children:b?"sub":`API·${v}`}),p&&E.jsxs("span",{title:`This session requests the "${p}" engine, but the last turn actually ran on "${f}" — so the chips above report ${f}, and that provider was billed.`,className:"inline-flex items-center rounded-md bg-rose-50 px-1.5 py-0.5 text-[10px] font-medium text-rose-700 ring-1 ring-inset ring-rose-600/20 dark:bg-rose-950/50 dark:text-rose-300 dark:ring-rose-400/30",children:["≠ ",p]}),E.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:C}),E.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"]}),N&&N!=="disabled"&&E.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&&E.jsxs("button",{onClick:T,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}
|
|
1945
|
+
`?1:0),kind:"command"}),O(0)):G?(S({query:G[1],start:G.index,kind:"mention"}),O(0)):S(null)};return y.useEffect(()=>{const L=()=>S(null);return b&&document.addEventListener("mousedown",L),()=>document.removeEventListener("mousedown",L)},[b]),E.jsxs("div",{className:"relative flex-1 min-w-0",children:[b&&k.length>0&&E.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:k.map((L,D)=>E.jsxs("button",{onMouseDown:P=>{P.preventDefault(),N(L.value)},className:`w-full text-left px-3 py-1.5 text-sm hover:bg-accent transition-colors flex items-center gap-2 ${D===_?"bg-accent":""}`,children:[E.jsx("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground shrink-0 w-14",children:(b==null?void 0:b.kind)==="command"?"cmd":L.kind==="skill"?"skill":"file"}),E.jsxs("span",{className:"truncate",children:[E.jsx("span",{className:"text-muted-foreground",children:(b==null?void 0:b.kind)==="command"?"/":"@"}),L.value]})]},`${L.kind}:${L.value}`))}),E.jsx("textarea",{ref:x,value:t,onChange:R,onKeyDown:T,onPaste:i,placeholder:c,disabled:h,rows:f,dir:"auto",className:u})]})}),mA="shraga:draft:";function ew(e,t){const n=mA+(e??"new");t.trim()?localStorage.setItem(n,t):localStorage.removeItem(n)}function V2(e){return localStorage.getItem(mA+(e??"new"))??""}function Y2(e){localStorage.removeItem(mA+(e??"new"))}const Ske=y.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:m,inputCtx:v},x){var $,W;const b=Sa(),[S,_]=y.useState(()=>V2(m)),[O,k]=y.useState([]),[C,N]=y.useState(!1),T=y.useRef(null),R=y.useRef(null),L=y.useRef(m);y.useEffect(()=>{var j;if(L.current===m)return;const K=L.current;if(L.current=m,!m){Y2(K),ew(void 0,S);return}ew(K,S);const X=V2(m);_(X),(j=R.current)==null||j.setValue(X)},[m]);const D=y.useCallback(K=>{_(K),ew(L.current,K)},[]);y.useImperativeHandle(x,()=>({prefill(K){var X,j;D(K),(X=R.current)==null||X.setValue(K),(j=R.current)==null||j.focus()},setText(K){var X;D(K),(X=R.current)==null||X.setValue(K)},focus(){var K;(K=R.current)==null||K.focus()}}));const P=(K="send")=>{var j;const X=S.trim();!X&&O.length===0||(K==="steer"?n(X):K==="queue"?r(X):t(X,O.length>0?O:void 0),_(""),Y2(L.current),k([]),(j=R.current)==null||j.setValue(""))},F=typeof window<"u"&&(($=window.matchMedia)==null?void 0:$.call(window,"(pointer: coarse)").matches),I=K=>{if(K.key==="Enter"&&!K.shiftKey&&(!F||K.metaKey||K.ctrlKey)){K.preventDefault(),P(f?"steer":"send");return}if(K.key==="Tab"&&f&&S.trim()){K.preventDefault(),P("queue");return}},U=y.useCallback(async K=>{N(!0);try{const X=await s(K);X&&k(j=>[...j,X])}finally{N(!1)}},[s]),G=y.useCallback(K=>{const X=Array.from(K.clipboardData.items);for(const j of X)if(j.type.startsWith("image/")||j.type==="application/pdf"){const H=j.getAsFile();H&&U(H)}},[U]),q=K=>{var j;const X=(j=K.target.files)==null?void 0:j[0];X&&(U(X),K.target.value="")};return E.jsx("div",{className:"border-t bg-background",style:{paddingBottom:"env(safe-area-inset-bottom)"},children:E.jsxs("div",{className:"max-w-3xl mx-auto px-2 sm:px-4 py-3",children:[(O.length>0||C)&&E.jsxs("div",{className:"flex gap-2 mb-2 flex-wrap items-center",children:[O.map((K,X)=>E.jsxs("div",{className:"relative group",children:[K.mimeType.startsWith("image/")?E.jsx(pA,{src:K.url,alt:K.name,className:"h-16 w-16 object-cover rounded-lg border"}):E.jsxs("div",{className:"h-16 px-3 flex items-center gap-2 rounded-lg border bg-muted/50 text-xs text-muted-foreground",children:[E.jsx(sE,{className:"w-4 h-4 shrink-0"}),E.jsx("span",{className:"truncate max-w-[120px]",children:K.name})]}),E.jsx("button",{onClick:()=>k(j=>j.filter((H,Q)=>Q!==X)),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:E.jsx(Rl,{className:"w-3 h-3"})})]},X)),C&&E.jsx("span",{className:"text-xs text-muted-foreground animate-pulse",children:"Uploading…"})]}),E.jsxs("div",{className:"flex items-center gap-2 bg-muted/50 rounded-xl border px-3 py-2",children:[E.jsx(Re,{variant:"ghost",size:"icon",className:"h-9 w-9 sm:h-8 sm:w-8 shrink-0",onClick:()=>{var K;return(K=T.current)==null?void 0:K.click()},disabled:u,title:"Attach file or image",children:E.jsx(Xq,{className:"w-4 h-4"})}),E.jsx("input",{ref:T,type:"file",className:"hidden",onChange:q}),E.jsx(k6,{ref:R,value:S,onChange:D,onKeyDown:I,onPaste:G,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]"}),(W=b.inputAdornments)==null?void 0:W.call(b,v),f?E.jsxs("div",{className:"flex items-center gap-2",children:[S.trim()&&E.jsx(Re,{size:"icon",className:"h-9 w-9 sm:h-8 sm:w-8 shrink-0 rounded-lg",onClick:()=>P("steer"),title:"Steer (inject into current turn)",children:E.jsx(tg,{className:"w-4 h-4"})}),E.jsx(Re,{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:E.jsx(xj,{className:"w-3.5 h-3.5"})})]}):E.jsx(Re,{size:"icon",className:"h-9 w-9 sm:h-8 sm:w-8 shrink-0 rounded-lg",onClick:()=>P(),disabled:u||C||!S.trim()&&O.length===0,children:E.jsx(tg,{className:"w-4 h-4"})})]}),a.length>0&&E.jsx("div",{className:"flex gap-1.5 flex-wrap mt-2",children:a.map((K,X)=>E.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:[E.jsx("span",{className:"truncate max-w-[200px]",children:K}),E.jsx("button",{onClick:()=>i(X),className:"hover:text-blue-900 dark:hover:text-blue-100",children:E.jsx(Rl,{className:"w-3 h-3"})})]},X))}),E.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"})]})})}),_ke={"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 Ake({artifacts:e,selectedId:t,sessionId:n,getToken:r,onSelect:i,onClose:a}){var R;const[s,c]=y.useState(!1),[u,f]=y.useState(!1),[h,p]=y.useState(!1),[m,v]=y.useState(1),x=y.useRef(null),b=e.find(L=>L.id===t),S=y.useCallback(()=>{if(!x.current||!b)return;const{clientWidth:L,clientHeight:D}=x.current,P=32,F=L-P,I=D-P,[U,G]=b.dimensions;v(Math.min(F/U,I/G,1))},[b]);y.useEffect(()=>{let L=!0;return r().then(D=>fetch("/api/features",{headers:D?{Authorization:`Bearer ${D}`}:{}})).then(D=>D.json()).then(D=>{L&&p(!!D.artifactPngExport)}).catch(D=>console.error("[artifact] features fetch failed:",D)),()=>{L=!1}},[r]),y.useEffect(()=>{S();const L=x.current;if(!L)return;const D=new ResizeObserver(S);return D.observe(L),()=>D.disconnect()},[S]);const _=async()=>{if(b){f(!0);try{const L=await r(),D=await fetch(`/api/artifacts/${n}/${b.id}/export`,{method:"POST",headers:{"Content-Type":"application/json",...L?{Authorization:`Bearer ${L}`}:{}},body:JSON.stringify({dimensions:b.dimensions})});if(!D.ok)throw new Error(await D.text());const P=await D.blob(),F=URL.createObjectURL(P),I=document.createElement("a");I.href=F,I.download=`${b.title.replace(/\s+/g,"-").toLowerCase()}.png`,I.click(),URL.revokeObjectURL(F)}catch(L){console.error("[artifact] export failed:",L)}finally{f(!1)}}},O=b?(R=Object.entries(_ke).find(([,L])=>L[0]===b.dimensions[0]&&L[1]===b.dimensions[1]))==null?void 0:R[0]:null,[k,C]=(b==null?void 0:b.dimensions)??[0,0],N=k*m,T=C*m;return E.jsxs("div",{className:He("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:[E.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1.5 border-b bg-muted/30",children:[E.jsx(Re,{variant:"ghost",size:"icon",className:"h-7 w-7 sm:hidden shrink-0",onClick:a,title:"Back to chat",children:E.jsx(mj,{className:"w-4 h-4"})}),e.length>1&&E.jsx("select",{className:"text-xs bg-transparent border rounded px-1 py-0.5 max-w-[160px] truncate",value:t??"",onChange:L=>i(L.target.value),children:e.map(L=>E.jsx("option",{value:L.id,children:L.title},L.id))}),e.length<=1&&b&&E.jsx("span",{className:"text-xs font-medium truncate max-w-[160px]",children:b.title}),b&&E.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[O??`${k}×${C}`,m<1&&` · ${Math.round(m*100)}%`]}),E.jsx("div",{className:"flex-1"}),h&&E.jsx(Re,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:_,disabled:!b||u,title:"Export PNG",children:u?E.jsx("span",{className:"w-3 h-3 border-2 border-current border-t-transparent rounded-full animate-spin"}):E.jsx(Kq,{className:"w-3.5 h-3.5"})}),E.jsx(Re,{variant:"ghost",size:"icon",className:"h-6 w-6 hidden sm:inline-flex",onClick:()=>c(!s),title:s?"Minimize":"Maximize",children:s?E.jsx(cE,{className:"w-3.5 h-3.5"}):E.jsx(lE,{className:"w-3.5 h-3.5"})}),E.jsx(Re,{variant:"ghost",size:"icon",className:"h-6 w-6 hidden sm:inline-flex",onClick:a,title:"Close",children:E.jsx(Rl,{className:"w-3.5 h-3.5"})})]}),E.jsx("div",{ref:x,className:"flex-1 overflow-hidden flex items-center justify-center bg-muted/10",children:b?E.jsx("div",{style:{width:N,height:T},children:E.jsx("iframe",{src:`/api/artifacts/${n}/${b.id}`,sandbox:"allow-scripts",className:"border shadow-sm bg-white origin-top-left",style:{width:k,height:C,transform:`scale(${m})`},title:b.title})}):E.jsx("p",{className:"text-sm text-muted-foreground",children:"No artifact selected"})})]})}const by=y.forwardRef(({className:e,...t},n)=>E.jsx("textarea",{className:He("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}));by.displayName="Textarea";const kke=[{value:"",label:"Default (claude-sonnet-5)"},{value:"claude-fable-5",label:"Fable 5 — frontier, most capable"},{value:"claude-opus-5",label:"Opus 5 — most capable, best for complex/agentic tasks"},{value:"claude-opus-4-8",label:"Opus 4.8"},{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"}],Oke=[{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 Cke({getToken:e,onSaved:t,trigger:n,sessionId:r,sessionDirectives:i,onDirectivesSaved:a}){var F;const s=Sa(),[c,u]=y.useState({}),[f,h]=y.useState(!1),[p,m]=y.useState(!1),[v,x]=y.useState([]),[b,S]=y.useState(!1),_=y.useRef({}),[O,k]=y.useState(!1);y.useEffect(()=>{f&&(k(!1),e().then(I=>{I&&(fetch("/api/config",{headers:{Authorization:`Bearer ${I}`}}).then(U=>U.json()).then(U=>{_.current=U;const G=r?i:void 0;u({...U,...(G==null?void 0:G.engine)!==void 0?{engine:G.engine}:{},...(G==null?void 0:G.model)!==void 0?{model:G.model}:{},...(G==null?void 0:G.turns)!==void 0?{maxTurns:G.turns}:{},...(G==null?void 0:G.thinking)!==void 0?{thinking:G.thinking}:{}})}).catch(()=>{}),fetch("/api/engines",{headers:{Authorization:`Bearer ${I}`}}).then(U=>U.json()).then(U=>{x(U.engines??[]),S(U.multiEngine??!1)}).catch(()=>{}))}))},[f,e,r,i]);const C=async()=>{m(!0);const U={Authorization:`Bearer ${await e()??""}`,"Content-Type":"application/json"};try{if(r){const G=O?{engine:"",model:"",turns:null,thinking:""}:{engine:c.engine,model:c.model,turns:c.maxTurns,thinking:c.thinking},q=await fetch(`/api/sessions/${r}/directives`,{method:"PUT",headers:U,body:JSON.stringify(G)}).then(W=>W.json()).catch(W=>(console.warn("[config] directives save failed",W),null));q!=null&&q.directives&&(a==null||a(q.directives));const $=O?c:{...c,engine:_.current.engine,model:_.current.model,maxTurns:_.current.maxTurns,thinking:_.current.thinking};await fetch("/api/config",{method:"PUT",headers:U,body:JSON.stringify($)}),t==null||t($)}else await fetch("/api/config",{method:"PUT",headers:U,body:JSON.stringify(c)}),t==null||t(c);h(!1)}finally{m(!1)}},N=c.engine||"claude-code",T=v.find(I=>I.name===N),R=(T==null?void 0:T.models)??kke;y.useEffect(()=>{!T||!R.length||R.some(I=>(I.value||"")===(c.model??""))||u(I=>({...I,model:R[0].value||void 0}))},[T,R,c.model]);const D=R.some(I=>I.provider)?Array.from(R.reduce((I,U)=>{const G=U.provider||"default";return I.has(G)||I.set(G,[]),I.get(G).push(U),I},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 E.jsxs(Es,{open:f,onOpenChange:h,children:[E.jsx(oh,{asChild:!0,children:n||E.jsx(Re,{variant:"ghost",size:"icon",title:"Agent Config",children:E.jsx(tG,{className:"w-4 h-4"})})}),E.jsxs(uo,{className:"max-w-lg",children:[E.jsx(Dl,{children:E.jsx(Ss,{children:"Agent Configuration"})}),E.jsxs(Lz,{className:"space-y-4",children:[r&&E.jsxs("div",{className:"text-xs text-muted-foreground rounded-md bg-muted/50 px-3 py-2 space-y-2",children:[E.jsxs("p",{children:["Engine, Model, Max Turns & Thinking apply to"," ",E.jsx("strong",{children:O?"every conversation":"this conversation"}),". Other settings are always global defaults."]}),E.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[E.jsx("input",{type:"checkbox",checked:O,onChange:I=>k(I.target.checked)}),E.jsx("span",{children:"Apply globally — also the default for Slack, email & scheduled runs"})]})]}),b&&E.jsxs("div",{children:[E.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Engine"}),E.jsx("select",{value:c.engine??"",onChange:I=>{const U=I.target.value||void 0;u(G=>({...G,engine:U,model:void 0}))},className:P,children:v.map(I=>E.jsx("option",{value:I.name,children:I.name==="claude-code"?"Claude Code (default)":I.name},I.name))})]}),E.jsxs("div",{children:[E.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Model"}),E.jsx("select",{value:c.model??"",onChange:I=>u(U=>({...U,model:I.target.value||void 0})),className:P,children:D?D.map(([I,U])=>E.jsx("optgroup",{label:I.charAt(0).toUpperCase()+I.slice(1),children:U.map(G=>E.jsx("option",{value:G.value,children:G.label},G.value))},I)):R.map(I=>E.jsx("option",{value:I.value,children:I.label},I.value))})]}),(F=s.settingsSections)==null?void 0:F.call(s,{getToken:e,sessionId:r}),E.jsxs("div",{children:[E.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Permission Mode"}),E.jsx("select",{value:c.permissionMode??"acceptEdits",onChange:I=>u(U=>({...U,permissionMode:I.target.value})),className:P,children:Oke.map(I=>E.jsx("option",{value:I.value,children:I.label},I.value))})]}),E.jsxs("div",{children:[E.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Max Turns"}),E.jsx(In,{type:"number",min:1,max:200,value:c.maxTurns??50,onChange:I=>u(U=>({...U,maxTurns:Number(I.target.value)||50}))})]}),E.jsxs("div",{children:[E.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Thinking"}),E.jsxs("select",{value:c.thinking??"",onChange:I=>u(U=>({...U,thinking:I.target.value||void 0})),className:P,children:[E.jsx("option",{value:"",children:"Default (off)"}),E.jsx("option",{value:"adaptive",children:"Adaptive (Claude decides)"}),E.jsx("option",{value:"enabled",children:"Enabled (always think)"}),E.jsx("option",{value:"disabled",children:"Disabled"})]})]}),E.jsxs("div",{children:[E.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Effort"}),E.jsxs("select",{value:c.effort??"",onChange:I=>u(U=>({...U,effort:I.target.value||void 0})),className:P,children:[E.jsx("option",{value:"",children:"Default"}),E.jsx("option",{value:"low",children:"Low — fast"}),E.jsx("option",{value:"medium",children:"Medium"}),E.jsx("option",{value:"high",children:"High"}),E.jsx("option",{value:"max",children:"Max"})]})]}),E.jsxs("div",{children:[E.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Allowed Tools"}),E.jsx(In,{placeholder:"Read, Edit, Bash, WebSearch, Glob, LS",value:(c.allowedTools??[]).join(", "),onChange:I=>u(U=>({...U,allowedTools:I.target.value.split(",").map(G=>G.trim()).filter(Boolean)}))}),E.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Comma-separated list of tools Claude can use"})]}),E.jsxs("div",{className:"flex items-center justify-between",children:[E.jsxs("div",{children:[E.jsx("label",{className:"text-sm font-medium",children:"Skill Discovery"}),E.jsx("p",{className:"text-xs text-muted-foreground",children:"Index all skills + auto-inject on trigger match"})]}),E.jsx("button",{type:"button",role:"switch","aria-checked":c.skillDiscovery!==!1,onClick:()=>u(I=>({...I,skillDiscovery:I.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:E.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"}`})})]}),E.jsxs("div",{children:[E.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"System Prompt (optional)"}),E.jsx(by,{placeholder:"Additional instructions appended to Claude's system prompt…",value:c.systemPrompt??"",onChange:I=>u(U=>({...U,systemPrompt:I.target.value||void 0})),rows:4})]})]}),E.jsx(zz,{children:E.jsx(Re,{onClick:C,disabled:p,children:p?"Saving…":"Save Configuration"})})]})]})}function Tke(e){var u;const t=e.requestedEngine||"claude-code",n=e.actualEngine||t,r=e.actualEngine&&e.actualEngine!==t?t:void 0,i=n==="claude-code"||n==="cursor",s=(e.actualEngine||(u=e.actualModel)!=null&&u.includes("/")?e.actualModel:void 0)||e.requestedModel||(n==="cursor"?"cursor/composer-2.5":"sonnet-4-6"),c=s.includes("/")?s.split("/")[0]:n==="claude-code"?"anthropic":n;return{engine:n,engineIsNative:i,engineMismatch:r,rawModel:s,billingProvider:c}}function Nke({sessionId:e,config:t,sessionDirectives:n,actualModel:r,actualEngine:i,scheduleId:a,onScheduleClick:s}){const[c,u]=y.useState(!1),{engine:f,engineIsNative:h,engineMismatch:p,rawModel:m,billingProvider:v}=Tke({requestedEngine:(n==null?void 0:n.engine)||t.engine,requestedModel:(n==null?void 0:n.model)||t.model,actualEngine:i,actualModel:r}),x=h?m.replace("claude-",""):`${f} · ${m.replace("claude-","")}`,b=f==="claude-code"&&t.claudeAuthSource==="subscription",S=b?"sub":v==="cursor"?"plan":"metered",_=S==="sub"?"bg-emerald-50 text-emerald-700 ring-emerald-600/20 dark:bg-emerald-950/50 dark:text-emerald-300 dark:ring-emerald-400/30":S==="plan"?"bg-amber-50 text-amber-700 ring-amber-600/20 dark:bg-amber-950/50 dark:text-amber-300 dark:ring-amber-400/30":"bg-rose-50 text-rose-700 ring-rose-600/20 dark:bg-rose-950/50 dark:text-rose-300 dark:ring-rose-400/30",O=S==="sub"?"Claude.ai subscription (OAuth login) — no API key in use":S==="plan"?`Runs on your ${v} API key — usage may draw on your ${v} plan/subscription`:`Runs on your ${v} API key — metered per-token billing`,k=t.permissionMode||"acceptEdits",C=k==="bypassPermissions"?"bypass":k==="plan"?"plan":k==="default"?"prompt":"edits",N=(n==null?void 0:n.thinking)||t.thinking,T=()=>{e&&(navigator.clipboard.writeText(e),u(!0),setTimeout(()=>u(!1),1500))};return E.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[E.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:x}),E.jsx("span",{title:O,className:`inline-flex items-center rounded-md px-1.5 py-0.5 text-[10px] font-medium ring-1 ring-inset ${_}`,children:b?"sub":`API·${v}`}),p&&E.jsxs("span",{title:`This session requests the "${p}" engine, but the last turn actually ran on "${f}" — so the chips above report ${f}, and that provider was billed.`,className:"inline-flex items-center rounded-md bg-rose-50 px-1.5 py-0.5 text-[10px] font-medium text-rose-700 ring-1 ring-inset ring-rose-600/20 dark:bg-rose-950/50 dark:text-rose-300 dark:ring-rose-400/30",children:["≠ ",p]}),E.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:C}),E.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"]}),N&&N!=="disabled"&&E.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&&E.jsxs("button",{onClick:T,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}
|
|
1946
1946
|
Click to copy`,children:[e.slice(0,8),c?E.jsx(ha,{className:"w-2.5 h-2.5"}):E.jsx(oE,{className:"w-2.5 h-2.5"})]}),a&&E.jsxs("button",{onClick:s,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:[E.jsx(aE,{className:"w-2.5 h-2.5"}),a.slice(0,8)]})]})}function Mke({sessionId:e,agentConfig:t,sessionDirectives:n,sessionLastModel:r,sessionLastEngine:i,sessionScheduleId:a,artifactCount:s,getToken:c,onConfigSaved:u,onDirectivesSaved:f,onFork:h,onToggleArtifacts:p,onScheduleClick:m}){return E.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:[E.jsx(Nke,{sessionId:e,config:t,sessionDirectives:n,actualModel:r,actualEngine:i,scheduleId:a,onScheduleClick:m}),E.jsx("div",{className:"flex-1"}),e&&E.jsx(Re,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:h,title:"Fork conversation",children:E.jsx(vj,{className:"w-3.5 h-3.5"})}),E.jsx(Cke,{getToken:c,onSaved:u,sessionId:e,sessionDirectives:n,onDirectivesSaved:f}),s>0&&E.jsx(Re,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:p,title:"Toggle artifacts panel",children:E.jsx(Gq,{className:"w-3.5 h-3.5"})})]})}function Ike({nodeId:e,sessionId:t}){var K;const n=iE(),r=Sa(),i=y.useRef(null),[a,s]=y.useState(),[c,u]=y.useState([]),f=y.useRef(void 0),[h,p]=y.useState(t),m=y.useRef(h);m.current=h;const v=y.useRef(t).current,[x,b]=y.useState(),[S,_]=y.useState(),[O,k]=y.useState(),[C,N]=y.useState(),[T,R]=y.useState(!1),L=Rae(h,n.getToken,n.token),D=y.useRef(!1),P=y.useCallback(X=>{n.bumpSidebar(),X!==m.current&&(p(X),n.assignSession(e,X))},[n,e]),F=y.useCallback(X=>{X.type==="artifact"?X.sessionId===m.current&&L.handleArtifactEvent(X):X.type==="directives"?D.current&&(k(void 0),N(void 0)):X.type==="model_resolved"&&X.sessionId===m.current&&(k(X.model),N(X.engine))},[n,e,L]),I=Nae(n.socket,{getToken:n.getToken,initialSessionId:t,onNewSession:P,onDirectivesChanged:b,onParticipantsChanged:R,onEvent:F});D.current=I.busy,y.useEffect(()=>{if(!v)return;let X=!1;return(async()=>{try{const H=await(await bl(`/api/sessions/${v}/messages`,n.getToken)).json();if(X)return;I.setMessages(fj(H)),R(Array.isArray(H.participants)&&H.participants.length>1),H.busy&&I.setBusy(!0)}catch(j){X||console.error("[pane] history load failed:",j)}})(),()=>{X=!0}},[v]),y.useEffect(()=>{if(!h){b(void 0),_(void 0),k(void 0),N(void 0);return}bl(`/api/sessions/${h}/meta`,n.getToken).then(X=>X.json()).then(X=>{b(X.directives),_(X.scheduleId),k(X.lastModel),N(X.lastEngine),X.runStatus==="running"&&I.setBusy(!0)}).catch(()=>{})},[h,n.getToken]);const U=y.useCallback((X,j,H)=>{var Q;I.sendMessage(X,m.current,H,j,(Q=f.current)==null?void 0:Q.call(f))},[I]),G={sessionId:h,busy:I.busy,socket:n.socket,getToken:n.getToken,setInputCtx:s,setSendOptions:X=>{f.current=X},setInputText:X=>{var j;return(j=i.current)==null?void 0:j.setText(X)},send:(X,j,H)=>I.sendMessage(X,m.current,void 0,void 0,j,(H==null?void 0:H.echo)!==!1),appendAssistant:X=>I.setMessages(j=>j.concat({id:ms(),role:"assistant",blocks:X})),setStatusItems:u},q=y.useCallback(async X=>{const j=await n.getToken();if(!j)return null;try{return await(await fetch("/api/upload",{method:"POST",headers:{Authorization:`Bearer ${j}`,"x-filename":encodeURIComponent(X.name),"Content-Type":X.type||"application/octet-stream","x-session-id":m.current||""},body:X})).json()}catch(H){return console.error("[upload] Failed:",H),null}},[n]),$=y.useCallback(async X=>{const j=m.current;if(!j)return;const H=await n.getToken();if(H)try{const Q=await fetch(`/api/sessions/${j}/fork`,{method:"POST",headers:{Authorization:`Bearer ${H}`,"Content-Type":"application/json"},body:JSON.stringify(X!=null?{truncateAtIndex:X}:{})});if(!Q.ok){console.error("[fork] server error:",(await Q.json().catch(()=>({}))).error||Q.status);return}const{sessionId:B}=await Q.json();n.bumpSidebar(),n.openSession(B)}catch(Q){console.error("[fork] failed:",Q)}},[n]),W=y.useCallback((X,j,H)=>{if(I.busy)return;const Q=I.messages.findIndex(B=>B.id===X);Q>=0&&I.setMessages(I.messages.slice(0,Q)),U(j,Q>=0?Q:void 0,H)},[I,U]);return E.jsxs("div",{className:"flex flex-col h-full min-h-0",children:[(K=r.conversationController)==null?void 0:K.call(r,G),E.jsx(Mke,{sessionId:h,agentConfig:n.agentConfig,sessionDirectives:x,sessionLastModel:O,sessionLastEngine:C,sessionScheduleId:S,artifactCount:L.artifacts.length,getToken:n.getToken,onConfigSaved:n.setAgentConfig,onDirectivesSaved:b,onFork:()=>$(),onToggleArtifacts:L.togglePanel,onScheduleClick:n.openSchedules}),E.jsxs("div",{className:"flex-1 flex min-h-0",children:[E.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[E.jsx(ske,{messages:I.messages,busy:I.busy,multiParticipant:T,connectionStatus:n.connectionStatus??void 0,onPermissionRespond:I.respondPermission,onQuestionRespond:I.respondQuestion,onReplay:W,onEdit:W,onFork:X=>$(X),statusItems:c}),E.jsx(Ske,{ref:i,onSend:(X,j)=>U(X,void 0,j),onSteer:I.steer,onQueue:I.addToQueue,onRemoveQueued:I.removeFromQueue,queue:I.queue,onUpload:q,onCancel:I.cancel,disabled:!1,busy:I.busy,skills:n.skills,workspaceFiles:n.workspaceFiles,sessionId:h,inputCtx:a})]}),L.panelOpen&&L.artifacts.length>0&&h&&E.jsx(Ake,{artifacts:L.artifacts,selectedId:L.selectedId,sessionId:h,getToken:n.getToken,onSelect:L.selectArtifact,onClose:L.closePanel})]})]})}const Rke=()=>({command:"",args:[],env:{}});function X2({getToken:e,trigger:t}){const[n,r]=y.useState({}),[i,a]=y.useState(!1),[s,c]=y.useState(!1),[u,f]=y.useState(new Set),h=k=>f(C=>{const N=new Set(C);return N.has(k)?N.delete(k):N.add(k),N});y.useEffect(()=>{i&&e().then(k=>{k&&fetch("/api/mcps",{headers:{Authorization:`Bearer ${k}`}}).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 k=await e();try{await fetch("/api/mcps",{method:"PUT",headers:{Authorization:`Bearer ${k??""}`,"Content-Type":"application/json"},body:JSON.stringify(n)}),a(!1)}finally{c(!1)}},m=()=>{const k=`server-${Date.now()}`;r(C=>({...C,[k]:Rke()}))},v=k=>{r(C=>{const N={...C};return delete N[k],N})},x=(k,C,N)=>{r(T=>({...T,[k]:{...T[k],[C]:C==="args"?N.split(" "):N}}))},b=(k,C,N)=>{r(T=>{const R={...T[k].env},L=R[C]??"";return delete R[C],N.trim()&&(R[N.trim()]=L),{...T,[k]:{...T[k],env:R}}})},S=(k,C,N)=>{r(T=>({...T,[k]:{...T[k],env:{...T[k].env,[C]:N}}}))},_=(k,C)=>{r(N=>{const T={...N[k].env};return delete T[C],{...N,[k]:{...N[k],env:T}}})},O=k=>{const C=`KEY_${Date.now()}`;r(N=>({...N,[k]:{...N[k],env:{...N[k].env,[C]:""}}}))};return E.jsxs(Es,{open:i,onOpenChange:a,children:[E.jsx(oh,{asChild:!0,children:t||E.jsx(Re,{variant:"ghost",size:"icon",title:"MCP Servers",children:E.jsx(yj,{className:"w-4 h-4"})})}),E.jsxs(uo,{className:"max-w-[95vw] sm:max-w-2xl",children:[E.jsx(Dl,{children:E.jsx(Ss,{children:"MCP Servers"})}),E.jsxs(Lz,{className:"space-y-4",children:[Object.entries(n).map(([k,C])=>{const N=!!C.readonly;return E.jsxs("div",{className:`border rounded-lg p-4 space-y-3 ${N?"opacity-70":""}`,children:[E.jsxs("div",{className:"flex items-center justify-between",children:[E.jsxs("span",{className:"font-medium text-sm flex items-center gap-1.5",children:[N&&E.jsx(Pm,{className:"w-3 h-3 text-muted-foreground"}),k]}),!N&&E.jsx(Re,{variant:"ghost",size:"icon",onClick:()=>v(k),children:E.jsx(Md,{className:"w-4 h-4 text-destructive"})})]}),N?E.jsx("p",{className:"text-xs text-muted-foreground",children:"Configured in shraga.config.ts"}):E.jsxs("div",{className:"grid gap-2",children:[E.jsx(In,{placeholder:"Command (e.g. npx)",value:C.command,onChange:T=>x(k,"command",T.target.value)}),E.jsx(In,{placeholder:"Args (space-separated)",value:(C.args||[]).join(" "),onChange:T=>x(k,"args",T.target.value)}),Object.entries(C.env||{}).length>0&&E.jsxs("div",{className:"space-y-2",children:[E.jsx("span",{className:"text-xs text-muted-foreground",children:"Environment variables"}),Object.entries(C.env||{}).map(([T,R])=>E.jsxs("div",{className:"flex gap-2 items-center",children:[E.jsx(In,{className:"w-1/3 font-mono text-xs",value:T,onChange:L=>b(k,T,L.target.value),placeholder:"KEY"}),u.has(`${k}:${T}`)?E.jsx(In,{className:"flex-1 font-mono text-xs",placeholder:"paste new value",autoFocus:!0,onChange:L=>S(k,T,L.target.value),onBlur:()=>h(`${k}:${T}`)}):E.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(`${k}:${T}`),title:"Click to change",children:R||"(empty — click to set)"}),E.jsx(Re,{variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0",onClick:()=>_(k,T),children:E.jsx(Md,{className:"w-3 h-3 text-muted-foreground"})})]},T))]}),E.jsx(Re,{variant:"ghost",size:"sm",className:"text-xs text-muted-foreground",onClick:()=>O(k),children:"+ Add env var"})]})]},k)}),Object.keys(n).length===0&&E.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No MCP servers configured"})]}),E.jsxs(zz,{className:"flex gap-2",children:[E.jsxs(Re,{variant:"outline",onClick:m,className:"gap-2",children:[E.jsx(dv,{className:"w-4 h-4"})," Add Server"]}),E.jsx(Re,{onClick:p,disabled:s,children:s?"Saving…":"Save"})]})]})]})}function gA(e){return typeof e=="string"?e:e.name}function Z2(e){return typeof e=="string"?!1:e.capped===!0||typeof e.capped=="number"&&e.capped>0}function md(e,t){return e.some(n=>gA(n)===t)}function Q2(e,t){return e.find(n=>gA(n)===t)}async function Va(e,t,n){return fetch(e,{...n,headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json",...(n==null?void 0:n.headers)??{}}})}function J2({getToken:e,onSkillsChange:t,trigger:n}){const[r,i]=y.useState(!1),[a,s]=y.useState([]),[c,u]=y.useState([]),[f,h]=y.useState([]),[p,m]=y.useState(null),[v,x]=y.useState(""),[b,S]=y.useState(!1),[_,O]=y.useState(null),[k,C]=y.useState(""),N=p?c.includes(p):!1,T=async()=>{const q=await e();if(!q)return;const[$,W]=await Promise.all([Va("/api/skills",q),Va("/api/skills-defaults",q)]),K=await $.json(),X=await W.json();s(K.skills),u(K.builtins),h(X),t==null||t(K.skills)},R=async q=>{const $=await e();if(!$)return;const K=await(await Va(`/api/skills/${q}`,$)).json();x(K.content),m(q),S(!1)},L=async()=>{if(!p||N)return;const q=await e();q&&(await Va(`/api/skills/${p}`,q,{method:"PUT",body:JSON.stringify({content:v})}),S(!1))},D=async()=>{const q=k.trim().replace(/\s+/g,"-");if(!q)return;const $=await e();if($){if(_==="create")await Va(`/api/skills/${q}`,$,{method:"PUT",body:JSON.stringify({content:""})}),await T(),await R(q);else if(_==="duplicate"&&p){if(!(await Va(`/api/skills/${p}/duplicate`,$,{method:"POST",body:JSON.stringify({newName:q})})).ok)return;await T(),await R(q)}else if(_==="rename"&&p){if(!(await Va(`/api/skills/${p}/rename`,$,{method:"POST",body:JSON.stringify({newName:q})})).ok)return;await T(),await R(q)}O(null),C("")}},P=async q=>{const $=await e();!$||!(await Va(`/api/skills/${q}`,$,{method:"DELETE"})).ok||(p===q&&(m(null),x("")),await T())},F=async q=>{const $=await e();if(!$)return;const W=md(f,q)?f.filter(K=>gA(K)!==q):[...f,q];await Va("/api/skills-defaults",$,{method:"PUT",body:JSON.stringify(W)}),h(W)},I=q=>{O(q),C(q==="rename"&&p?p:q==="duplicate"&&p?`${p}-copy`:"")},U=()=>{O(null),C("")};y.useEffect(()=>{r&&T()},[r]);const G=_==="create"?"skill-name":_==="rename"?"new-name":"copy-name";return E.jsxs(Es,{open:r,onOpenChange:i,children:[E.jsx(oh,{asChild:!0,children:n||E.jsx(Re,{variant:"ghost",size:"icon",title:"Skills",className:"h-8 w-8",children:E.jsx(hw,{className:"w-4 h-4"})})}),E.jsxs(uo,{className:"max-w-[95vw] sm:max-w-2xl h-[70dvh] sm:h-[520px] flex flex-col gap-0 p-0",children:[E.jsx(Dl,{className:"px-4 pt-4 pb-2 border-b shrink-0",children:E.jsxs(Ss,{className:"flex items-center gap-2",children:[E.jsx(hw,{className:"w-4 h-4"})," Skills"]})}),E.jsxs("div",{className:"flex flex-col sm:flex-row flex-1 overflow-hidden",children:[E.jsxs("div",{className:`sm:w-52 border-r flex flex-col shrink-0 ${p?"hidden sm:flex":"flex"}`,children:[E.jsx("div",{className:"flex-1 overflow-y-auto py-1",children:a.map(q=>E.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===q?"bg-accent font-medium":""}`,onClick:()=>R(q),children:[E.jsx("button",{className:`shrink-0 transition-colors ${md(f,q)?"text-amber-500":"text-muted-foreground/30 hover:text-amber-400"}`,onClick:$=>{$.stopPropagation(),F(q)},title:md(f,q)?"Remove from defaults":"Set as default (always active)",children:E.jsx(jT,{className:`w-3 h-3 ${md(f,q)?"fill-current":""}`})}),E.jsxs("span",{className:"truncate flex-1",children:["@",q]}),c.includes(q)&&E.jsx("span",{title:"Built-in (read-only)",children:E.jsx(Pm,{className:"w-2.5 h-2.5 text-muted-foreground/40 shrink-0"})}),!c.includes(q)&&E.jsx("button",{className:"opacity-0 group-hover:opacity-100 text-muted-foreground hover:text-destructive transition-opacity shrink-0",onClick:$=>{$.stopPropagation(),P(q)},title:"Delete",children:E.jsx(Md,{className:"w-3 h-3"})})]},q))}),E.jsx("div",{className:"border-t p-2",children:_?E.jsxs("div",{className:"flex gap-1",children:[E.jsx(In,{value:k,onChange:q=>C(q.target.value),onKeyDown:q=>{q.key==="Enter"&&D(),q.key==="Escape"&&U()},placeholder:G,className:"h-7 text-xs",autoFocus:!0}),E.jsx(Re,{size:"icon",className:"h-7 w-7 shrink-0",onClick:D,children:E.jsx(ha,{className:"w-3 h-3"})}),E.jsx(Re,{size:"icon",variant:"ghost",className:"h-7 w-7 shrink-0",onClick:U,children:E.jsx(Rl,{className:"w-3 h-3"})})]}):E.jsxs(Re,{variant:"outline",size:"sm",className:"w-full h-7 text-xs",onClick:()=>I("create"),children:[E.jsx(dv,{className:"w-3 h-3 mr-1"})," New skill"]})})]}),E.jsx("div",{className:`flex-1 flex flex-col overflow-hidden ${p?"":"hidden sm:flex"}`,children:p?E.jsxs(E.Fragment,{children:[E.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b text-sm shrink-0",children:[E.jsxs("div",{className:"flex items-center gap-0.5 font-medium",children:[E.jsx("button",{className:"sm:hidden mr-1.5 text-muted-foreground",onClick:()=>{m(null),x(""),S(!1)},children:E.jsx(mj,{className:"w-4 h-4"})}),E.jsx("span",{className:"text-muted-foreground",children:"@"}),E.jsx("span",{children:p})]}),E.jsxs("div",{className:"flex items-center gap-1.5",children:[N&&E.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:[E.jsx(Pm,{className:"w-2.5 h-2.5"})," read-only"]}),md(f,p)&&E.jsxs(E.Fragment,{children:[E.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"}),E.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded font-medium ${Z2(Q2(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:Z2(Q2(f,p))?"capped":"full"})]}),E.jsx(Re,{variant:"ghost",size:"sm",className:"h-6 text-xs px-1.5",onClick:()=>I("duplicate"),title:"Duplicate",children:E.jsx(oE,{className:"w-3 h-3"})}),!N&&E.jsx(Re,{variant:"ghost",size:"sm",className:"h-6 text-xs px-1.5",onClick:()=>I("rename"),title:"Rename",children:E.jsx(uE,{className:"w-3 h-3"})}),b&&!N&&E.jsxs(Re,{size:"sm",className:"h-6 text-xs",onClick:L,children:[E.jsx(ha,{className:"w-3 h-3 mr-1"})," Save"]})]})]}),E.jsx(by,{value:v,onChange:q=>{N||(x(q.target.value),S(!0))},readOnly:N,className:`flex-1 resize-none rounded-none border-0 font-mono text-xs focus-visible:ring-0 ${N?"opacity-70 cursor-default":""}`,placeholder:"Write the skill instructions here…"})]}):E.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center text-muted-foreground text-sm gap-1",children:[E.jsx("p",{children:"Select or create a skill"}),E.jsxs("p",{className:"text-xs",children:[E.jsx(jT,{className:"w-3 h-3 inline fill-amber-500 text-amber-500"})," = injected in every conversation"]}),E.jsxs("p",{className:"text-xs",children:[E.jsx(Pm,{className:"w-3 h-3 inline"})," = built-in, duplicate to customize"]})]})})]})]})]})}async function gd(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 Pke(e,t,n=0){const[r,i]=y.useState([]),[a,s]=y.useState([]),[c,u]=y.useState(!1),[f,h]=y.useState(!1),[p,m]=y.useState(null),v=y.useCallback(async()=>{h(!0),m(null);try{const O=await gd("/api/modules",e);i(O.installed??[]),s(O.available??[]),u(!1)}catch(O){/^404\b/.test(O.message)?u(!0):m(O.message)}finally{h(!1)}},[e]);y.useEffect(()=>{t&&v()},[t,v,n]);const x=y.useCallback(async O=>{await gd("/api/modules/install",e,{method:"POST",body:JSON.stringify(O)}),await v()},[e,v]),b=y.useCallback(async(O,k)=>{await gd(`/api/modules/${O}/${k?"enable":"disable"}`,e,{method:"POST"}),await v()},[e,v]),S=y.useCallback(async(O,k)=>{await gd(`/api/modules/${O}/config`,e,{method:"PUT",body:JSON.stringify({config:k})}),await v()},[e,v]),_=y.useCallback(async O=>{await gd(`/api/modules/${O}`,e,{method:"DELETE"}),await v()},[e,v]);return{installed:r,available:a,unsupported:c,loading:f,error:p,refresh:v,install:x,toggle:b,updateConfig:S,uninstall:_}}function O6({checked:e,onChange:t,title:n,disabled:r}){return E.jsx("button",{type:"button",role:"switch","aria-checked":e,title:n,disabled:r,onClick:()=>t(!e),className:`relative inline-flex h-6 w-11 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${e?"bg-primary":"bg-muted"}`,children:E.jsx("span",{className:`pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform ${e?"translate-x-5":"translate-x-0"}`})})}function eD(e){const t=Object.keys(e.config??{});return t.length===0?"":t.slice(0,3).map(n=>`${n}: ${String(e.config[n])}`).join(" · ")+(t.length>3?` · +${t.length-3}`:"")}function Dke({schema:e,config:t,onSave:n,saving:r}){const[i,a]=y.useState(()=>{const h={};for(const[p,m]of Object.entries(e)){const v=t[p]??m.default;h[p]=m.type==="boolean"?!!v:v==null?"":String(v)}return h}),[s,c]=y.useState({}),u=(h,p)=>{a(m=>({...m,[h]:p})),c(m=>m[h]?{...m,[h]:""}:m)},f=()=>{const h={},p={};for(const[m,v]of Object.entries(e)){const x=i[m];if(v.type==="boolean"){const S=!!x;if(!S&&t[m]===void 0&&typeof v.default!="boolean")continue;h[m]=S;continue}const b=String(x??"").trim();if(b===""){(v.type==="number"&&typeof v.default=="number"&&Number.isFinite(v.default)||v.type==="string"&&typeof v.default=="string"&&v.default!=="")&&(h[m]=v.default);continue}if(v.type==="number"){const S=Number(b);if(!Number.isFinite(S)){p[m]="Not a number";continue}h[m]=S}else h[m]=b}if(Object.values(p).some(Boolean)){c(p);return}c({}),n(h)};return E.jsxs("div",{className:"space-y-2 pt-2",children:[Object.entries(e).map(([h,p])=>E.jsxs("div",{className:"flex items-center gap-2",children:[E.jsx("label",{className:"text-xs w-36 shrink-0 truncate",title:p.description||h,children:h}),p.type==="boolean"?E.jsx(O6,{checked:!!i[h],onChange:m=>u(h,m)}):E.jsxs("div",{className:"flex-1 min-w-0",children:[E.jsx(In,{type:"text",inputMode:p.type==="number"?"decimal":void 0,value:String(i[h]??""),onChange:m=>u(h,m.target.value),className:`h-7 text-xs w-full ${s[h]?"border-destructive":""}`,placeholder:p.description}),s[h]&&E.jsx("p",{className:"text-[10px] text-destructive mt-0.5",children:s[h]})]})]},h)),E.jsxs(Re,{size:"sm",className:"h-6 text-xs",disabled:r,onClick:f,children:[r?E.jsx(Nd,{className:"w-3 h-3 mr-1 animate-spin"}):E.jsx(ha,{className:"w-3 h-3 mr-1"})," Save config"]})]})}function tD({getToken:e,trigger:t}){const[n,r]=y.useState(!1),{installed:i,available:a,unsupported:s,loading:c,error:u,install:f,toggle:h,updateConfig:p,uninstall:m}=Pke(e,n),[v,x]=y.useState(null),[b,S]=y.useState(null),[_,O]=y.useState(null),k=async(N,T)=>{if(!b){S(N),O(null);try{await T()}catch(R){O(R.message)}finally{S(null)}}},C=a.filter(N=>!N.installed);return E.jsxs(Es,{open:n,onOpenChange:r,children:[E.jsx(oh,{asChild:!0,children:t||E.jsx(Re,{variant:"ghost",size:"icon",title:"Modules",className:"h-8 w-8",children:E.jsx(dw,{className:"w-4 h-4"})})}),E.jsxs(uo,{className:"max-w-[95vw] sm:max-w-2xl h-[70dvh] sm:h-[520px] flex flex-col gap-0 p-0",children:[E.jsx(Dl,{className:"px-4 pt-4 pb-2 border-b shrink-0",children:E.jsxs(Ss,{className:"flex items-center gap-2",children:[E.jsx(dw,{className:"w-4 h-4"})," Modules"]})}),E.jsxs("div",{className:"flex-1 overflow-y-auto p-3 space-y-4",children:[s&&E.jsx("p",{className:"text-sm text-muted-foreground text-center py-8",children:"This server does not support modules yet."}),(u||_)&&E.jsx("p",{className:"text-xs text-destructive",children:_||u}),c&&i.length===0&&!s&&E.jsx("p",{className:"text-sm text-muted-foreground text-center py-8",children:"Loading…"}),!s&&!c&&i.length===0&&C.length===0&&!u&&E.jsx("p",{className:"text-sm text-muted-foreground text-center py-8",children:"No modules available."}),i.length>0&&E.jsxs("div",{className:"space-y-2",children:[E.jsx("h3",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Installed"}),i.map(N=>{const T=v===N.name,R=N.configSchema&&Object.keys(N.configSchema).length>0,L=[N.skillCount?`provides ${N.skillCount} skill${N.skillCount===1?"":"s"}`:"",N.scheduleCount?`${N.scheduleCount} schedule${N.scheduleCount===1?"":"s"}`:""].filter(Boolean).join(", ");return E.jsxs("div",{className:"border rounded-lg p-3 space-y-1",children:[E.jsxs("div",{className:"flex items-center gap-2",children:[E.jsx(O6,{checked:N.enabled,onChange:D=>k(`toggle-${N.name}`,()=>h(N.name,D)),title:N.enabled?"Disable":"Enable",disabled:b===`toggle-${N.name}`}),E.jsx("span",{className:"font-medium text-sm truncate",children:N.name}),E.jsxs("span",{className:"text-[10px] font-mono px-1.5 py-0.5 rounded bg-muted text-muted-foreground shrink-0",children:["v",N.version]}),!N.enabled&&E.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground shrink-0",children:"disabled"}),E.jsx("div",{className:"flex-1"}),b===`toggle-${N.name}`&&E.jsx(Nd,{className:"w-3 h-3 animate-spin text-muted-foreground"}),(R||N.readme)&&E.jsx("button",{className:"text-muted-foreground hover:text-foreground transition-colors",onClick:()=>x(T?null:N.name),title:"Details",children:T?E.jsx(Lq,{className:"w-3.5 h-3.5"}):E.jsx(Is,{className:"w-3.5 h-3.5"})}),E.jsx("button",{className:"text-muted-foreground hover:text-destructive transition-colors",onClick:()=>{confirm(`Uninstall module "${N.name}"? Its skills and schedules will be removed (seeds/data stay).`)&&k(`rm-${N.name}`,()=>m(N.name))},title:"Uninstall",children:E.jsx(Md,{className:"w-3.5 h-3.5"})})]}),N.description&&E.jsx("p",{className:"text-xs text-muted-foreground",children:N.description}),L&&E.jsx("p",{className:"text-[10px] text-muted-foreground",children:L}),!T&&eD(N)&&E.jsx("p",{className:"text-[10px] font-mono text-muted-foreground truncate",children:eD(N)}),T&&N.readme&&E.jsx("pre",{className:"text-[11px] text-muted-foreground whitespace-pre-wrap font-sans bg-muted/40 rounded p-2 max-h-48 overflow-y-auto",children:N.readme}),T&&R&&E.jsx(Dke,{schema:N.configSchema,config:N.config,saving:b===`cfg-${N.name}`,onSave:D=>k(`cfg-${N.name}`,()=>p(N.name,D))},JSON.stringify(N.config))]},N.name)})]}),C.length>0&&E.jsxs("div",{className:"space-y-2",children:[E.jsx("h3",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Available"}),C.map(N=>E.jsxs("div",{className:"border rounded-lg p-3 flex items-center gap-2",children:[E.jsxs("div",{className:"min-w-0 flex-1",children:[E.jsxs("div",{className:"flex items-center gap-2",children:[E.jsx("span",{className:"font-medium text-sm truncate",children:N.name}),E.jsxs("span",{className:"text-[10px] font-mono px-1.5 py-0.5 rounded bg-muted text-muted-foreground shrink-0",children:["v",N.version]})]}),N.description&&E.jsx("p",{className:"text-xs text-muted-foreground",children:N.description})]}),E.jsxs(Re,{size:"sm",variant:"outline",className:"h-7 text-xs shrink-0",disabled:b===`install-${N.name}`,onClick:()=>k(`install-${N.name}`,()=>f({name:N.name})),children:[b===`install-${N.name}`?E.jsx(Nd,{className:"w-3 h-3 mr-1 animate-spin"}):E.jsx(gj,{className:"w-3 h-3 mr-1"}),"Install"]})]},N.name))]})]})]})]})}async function hl(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 jke(e,t,n=0){const[r,i]=y.useState([]),[a,s]=y.useState(new Set),[c,u]=y.useState(!1),[f,h]=y.useState(null),p=y.useCallback(async()=>{u(!0),h(null);try{const O=await hl("/api/schedules",e);i(O.schedules),s(new Set(O.runningIds))}catch(O){h(O.message)}finally{u(!1)}},[e]);y.useEffect(()=>{t&&p()},[t,p,n]);const m=y.useCallback(async O=>{const k=await hl("/api/schedules",e,{method:"POST",body:JSON.stringify(O)});return await p(),k},[e,p]),v=y.useCallback(async(O,k)=>{const C=await hl(`/api/schedules/${O}`,e,{method:"PUT",body:JSON.stringify(k)});return await p(),C},[e,p]),x=y.useCallback(async O=>{await hl(`/api/schedules/${O}`,e,{method:"DELETE"}),await p()},[e,p]),b=y.useCallback(async(O,k)=>{await hl(`/api/schedules/${O}/toggle`,e,{method:"POST",body:JSON.stringify({enabled:k})}),await p()},[e,p]),S=y.useCallback(async(O,k)=>{const C=await hl(`/api/schedules/${O}/run`,e,{method:"POST",body:JSON.stringify(k?{override:k}:{})});return await p(),C.sessionId},[e,p]),_=y.useCallback(async O=>{await hl(`/api/schedules/${O}/cancel`,e,{method:"POST"}),await p()},[e,p]);return{schedules:r,serverRunningIds:a,loading:c,error:f,refresh:p,create:m,update:v,remove:x,toggle:b,runNow:S,cancelRun:_}}var tw={exports:{}},nD;function Lke(){return nD||(nD=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(m,v,x){v===void 0&&(v=!0),x===void 0&&(x=!1),this.expression=m,this.dayOfWeekStartIndexZero=v,this.monthStartIndexZero=x}return p.prototype.parse=function(){var m,v,x=(m=this.expression)!==null&&m!==void 0?m:"";if(x==="@reboot")return v=["@reboot","","","","","",""],v;if(x.startsWith("@")){var b=this.parseSpecial(this.expression);v=this.extractParts(b)}else v=this.extractParts(this.expression);return this.normalize(v),this.validate(v),v},p.prototype.parseSpecial=function(m){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"},x=v[m];if(!x)throw new Error("Unknown special expression.");return x},p.prototype.extractParts=function(m){if(!this.expression)throw new Error("cron expression is empty");for(var v=m.trim().split(/[ ]+/),x=0;x<v.length;x++)if(v[x].includes(",")){var b=v[x].split(",").map(function(_){return _.trim()}).filter(function(_){return _!==""}).map(function(_){return isNaN(Number(_))?_:Number(_)}).filter(function(_){return _!==null&&_!==""});b.length===0&&b.push("*"),b.sort(function(_,O){return _!==null&&O!==null?_-O:0}),v[x]=b.map(function(_){return _!==null?_.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 S=/\d{4}$/.test(v[5])||v[4]=="?"||v[2]=="?";S?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(m){var v=this;if(m[3]=m[3].replace("?","*"),m[5]=m[5].replace("?","*"),m[2]=m[2].replace("?","*"),m[0].indexOf("0/")==0&&(m[0]=m[0].replace("0/","*/")),m[1].indexOf("0/")==0&&(m[1]=m[1].replace("0/","*/")),m[2].indexOf("0/")==0&&(m[2]=m[2].replace("0/","*/")),m[3].indexOf("1/")==0&&(m[3]=m[3].replace("1/","*/")),m[4].indexOf("1/")==0&&(m[4]=m[4].replace("1/","*/")),m[6].indexOf("1/")==0&&(m[6]=m[6].replace("1/","*/")),m[5]=m[5].replace(/(^\d)|([^#/\s]\d)/g,function(N){var T=N.replace(/\D/,""),R=T;return v.dayOfWeekStartIndexZero?T=="7"&&(R="0"):R=(parseInt(T)-1).toString(),N.replace(T,R)}),m[5]=="L"&&(m[5]="6"),m[3]=="?"&&(m[3]="*"),m[3].indexOf("W")>-1&&(m[3].indexOf(",")>-1||m[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 x={SUN:0,MON:1,TUE:2,WED:3,THU:4,FRI:5,SAT:6};for(var b in x)m[5]=m[5].replace(new RegExp(b,"gi"),x[b].toString());m[4]=m[4].replace(/(^\d{1,2})|([^#/\s]\d{1,2})/g,function(N){var T=N.replace(/\D/,""),R=T;return v.monthStartIndexZero&&(R=(parseInt(T)+1).toString()),N.replace(T,R)});var S={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 _ in S)m[4]=m[4].replace(new RegExp(_,"gi"),S[_].toString());m[0]=="0"&&(m[0]=""),!/\*|\-|\,|\//.test(m[2])&&(/\*|\//.test(m[1])||/\*|\//.test(m[0]))&&(m[2]+="-".concat(m[2]));for(var O=0;O<m.length;O++)if(m[O].indexOf(",")!=-1&&(m[O]=m[O].split(",").filter(function(N){return N!==""}).join(",")||"*"),m[O]=="*/1"&&(m[O]="*"),m[O].indexOf("/")>-1&&!/^\*|\-|\,/.test(m[O])){var k=null;switch(O){case 4:k="12";break;case 5:k="6";break;case 6:k="9999";break;default:k=null;break}if(k!==null){var C=m[O].split("/");m[O]="".concat(C[0],"-").concat(k,"/").concat(C[1])}}},p.prototype.validate=function(m){var v="0-9,\\-*/";this.validateOnlyExpectedCharactersFound(m[0],v),this.validateOnlyExpectedCharactersFound(m[1],v),this.validateOnlyExpectedCharactersFound(m[2],v),this.validateOnlyExpectedCharactersFound(m[3],"0-9,\\-*/LW"),this.validateOnlyExpectedCharactersFound(m[4],v),this.validateOnlyExpectedCharactersFound(m[5],"0-9,\\-*/L#"),this.validateOnlyExpectedCharactersFound(m[6],v),this.validateAnyRanges(m)},p.prototype.validateAnyRanges=function(m){f.default.secondRange(m[0]),f.default.minuteRange(m[1]),f.default.hourRange(m[2]),f.default.dayOfMonthRange(m[3]),f.default.monthRange(m[4],this.monthStartIndexZero),f.default.dayOfWeekRange(m[5],this.dayOfWeekStartIndexZero)},p.prototype.validateOnlyExpectedCharactersFound=function(m,v){var x=m.match(new RegExp("[^".concat(v,"]+"),"gi"));if(x&&x.length)throw new Error("Expression contains invalid values: '".concat(x.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 m(v,x){if(this.expression=v,this.options=x,this.expressionParts=new Array(5),!this.options.locale&&m.defaultLocale&&(this.options.locale=m.defaultLocale),!m.locales[this.options.locale]){var b=Object.keys(m.locales)[0];console.warn("Locale '".concat(this.options.locale,"' could not be found; falling back to '").concat(b,"'.")),this.options.locale=b}this.i18n=m.locales[this.options.locale],x.use24HourTimeFormat===void 0&&(x.use24HourTimeFormat=this.i18n.use24HourTimeFormatByDefault())}return m.toString=function(v,x){var b=x===void 0?{}:x,S=b.throwExceptionOnParseError,_=S===void 0?!0:S,O=b.verbose,k=O===void 0?!1:O,C=b.dayOfWeekStartIndexZero,N=C===void 0?!0:C,T=b.monthStartIndexZero,R=T===void 0?!1:T,L=b.use24HourTimeFormat,D=b.trimHoursLeadingZero,P=D===void 0?!1:D,F=b.locale,I=F===void 0?null:F,U=b.logicalAndDayFields,G=U===void 0?!1:U,q={throwExceptionOnParseError:_,verbose:k,dayOfWeekStartIndexZero:N,monthStartIndexZero:R,use24HourTimeFormat:L,trimHoursLeadingZero:P,locale:I,logicalAndDayFields:G};q.tzOffset&&console.warn("'tzOffset' option has been deprecated and is no longer supported.");var $=new m(v,q);return $.getFullDescription()},m.initialize=function(v,x){x===void 0&&(x="en"),m.specialCharacters=["/","-",",","*"],m.defaultLocale=x,v.load(m.locales)},m.prototype.getFullDescription=function(){var v,x,b="";try{var S=new h.CronParser(this.expression,this.options.dayOfWeekStartIndexZero,this.options.monthStartIndexZero);if(this.expressionParts=S.parse(),this.expressionParts[0]==="@reboot")return((x=(v=this.i18n).atReboot)===null||x===void 0?void 0:x.call(v))||"Run once, at startup";var _=this.getTimeOfDayDescription(),O=this.getDayOfMonthDescription(),k=this.getMonthDescription(),C=this.getDayOfWeekDescription(),N=this.getYearDescription();b+=_+O+C+k+N,b=this.transformVerbosity(b,!!this.options.verbose),b=b.charAt(0).toLocaleUpperCase()+b.substr(1)}catch(T){if(!this.options.throwExceptionOnParseError)b=this.i18n.anErrorOccuredWhenGeneratingTheExpressionD();else throw"".concat(T)}return b},m.prototype.getTimeOfDayDescription=function(){var v=this.expressionParts[0],x=this.expressionParts[1],b=this.expressionParts[2],S="";if(!f.StringUtilities.containsAny(x,m.specialCharacters)&&!f.StringUtilities.containsAny(b,m.specialCharacters)&&!f.StringUtilities.containsAny(v,m.specialCharacters))S+=this.i18n.atSpace()+this.formatTime(b,x,v);else if(!v&&x.indexOf("-")>-1&&!(x.indexOf(",")>-1)&&!(x.indexOf("/")>-1)&&!f.StringUtilities.containsAny(b,m.specialCharacters)){var _=x.split("-");S+=f.StringUtilities.format(this.i18n.everyMinuteBetweenX0AndX1(),this.formatTime(b,_[0],""),this.formatTime(b,_[1],""))}else if(!v&&b.indexOf(",")>-1&&b.indexOf("-")==-1&&b.indexOf("/")==-1&&!f.StringUtilities.containsAny(x,m.specialCharacters)){var O=b.split(",");S+=this.i18n.at();for(var k=0;k<O.length;k++)S&&(S+=" "),S+=this.formatTime(O[k],x,""),k<O.length-2&&(S+=","),k==O.length-2&&(S+=this.i18n.spaceAnd())}else{var C=this.getSecondsDescription(),N=this.getMinutesDescription(),T=this.getHoursDescription();if(S+=C,S&&N&&(S+=", "),S+=N,N===T)return S;S&&T&&(S+=", "),S+=T}return S},m.prototype.getSecondsDescription=function(){var v=this,x=this.getSegmentDescription(this.expressionParts[0],this.i18n.everySecond(),function(b){return b},function(b){return f.StringUtilities.format(v.i18n.everyX0Seconds(b),b)},function(b){return v.i18n.secondsX0ThroughX1PastTheMinute()},function(b){return b=="0"?"":parseInt(b)<20?v.i18n.atX0SecondsPastTheMinute(b):v.i18n.atX0SecondsPastTheMinuteGt20()||v.i18n.atX0SecondsPastTheMinute(b)});return x},m.prototype.getMinutesDescription=function(){var v=this,x=this.expressionParts[0],b=this.expressionParts[2],S=this.getSegmentDescription(this.expressionParts[1],this.i18n.everyMinute(),function(_){return _},function(_){return f.StringUtilities.format(v.i18n.everyX0Minutes(_),_)},function(_){return v.i18n.minutesX0ThroughX1PastTheHour()},function(_){var O,k;try{return _=="0"&&b.indexOf("/")==-1&&x==""?v.i18n.everyHour():_=="0"?((k=(O=v.i18n).onTheHour)===null||k===void 0?void 0:k.call(O))||v.i18n.atX0MinutesPastTheHour(_):parseInt(_)<20?v.i18n.atX0MinutesPastTheHour(_):v.i18n.atX0MinutesPastTheHourGt20()||v.i18n.atX0MinutesPastTheHour(_)}catch{return v.i18n.atX0MinutesPastTheHour(_)}});return S},m.prototype.getHoursDescription=function(){var v=this,x=this.expressionParts[2],b=0,S=[];x.split("/")[0].split(",").forEach(function(k){var C=k.split("-");C.length===2&&S.push({value:C[1],index:b+1}),b+=C.length});var _=0,O=this.getSegmentDescription(x,this.i18n.everyHour(),function(k){var C=S.find(function(T){return T.value===k&&T.index===_}),N=C&&v.expressionParts[1]!=="0";return _++,N?v.formatTime(k,"59",""):v.formatTime(k,"0","")},function(k){return f.StringUtilities.format(v.i18n.everyX0Hours(k),k)},function(k){return v.i18n.betweenX0AndX1()},function(k){return v.i18n.atX0()});return O},m.prototype.getDayOfWeekDescription=function(){var v=this,x=this.i18n.daysOfTheWeek(),b=null;return this.expressionParts[5]=="*"?b="":b=this.getSegmentDescription(this.expressionParts[5],this.i18n.commaEveryDay(),function(S,_){var O=S;S.indexOf("#")>-1?O=S.substring(0,S.indexOf("#")):S.indexOf("L")>-1&&(O=O.replace("L",""));var k=parseInt(O),C=v.i18n.daysOfTheWeekInCase?v.i18n.daysOfTheWeekInCase(_)[k]:x[k];if(S.indexOf("#")>-1){var N=null,T=S.substring(S.indexOf("#")+1),R=S.substring(0,S.indexOf("#"));switch(T){case"1":N=v.i18n.first(R);break;case"2":N=v.i18n.second(R);break;case"3":N=v.i18n.third(R);break;case"4":N=v.i18n.fourth(R);break;case"5":N=v.i18n.fifth(R);break}C=N+" "+C}return C},function(S){return parseInt(S)==1?"":f.StringUtilities.format(v.i18n.commaEveryX0DaysOfTheWeek(S),S)},function(S){var _=S.substring(0,S.indexOf("-")),O=v.expressionParts[3]!="*";return O?v.i18n.commaAndX0ThroughX1(_):v.i18n.commaX0ThroughX1(_)},function(S){var _=null;if(S.indexOf("#")>-1){var O=S.substring(S.indexOf("#")+1),k=S.substring(0,S.indexOf("#"));_=v.i18n.commaOnThe(O,k).trim()+v.i18n.spaceX0OfTheMonth()}else if(S.indexOf("L")>-1)_=v.i18n.commaOnTheLastX0OfTheMonth(S.replace("L",""));else{var C=v.expressionParts[3]!="*";C?v.options.logicalAndDayFields?_=v.i18n.commaOnlyOnX0(S):_=v.i18n.commaAndOnX0():_=v.i18n.commaOnlyOnX0(S)}return _}),b},m.prototype.getMonthDescription=function(){var v=this,x=this.i18n.monthsOfTheYear(),b=this.getSegmentDescription(this.expressionParts[4],"",function(S,_){return _&&v.i18n.monthsOfTheYearInCase?v.i18n.monthsOfTheYearInCase(_)[parseInt(S)-1]:x[parseInt(S)-1]},function(S){return parseInt(S)==1?"":f.StringUtilities.format(v.i18n.commaEveryX0Months(S),S)},function(S){return v.i18n.commaMonthX0ThroughMonthX1()||v.i18n.commaX0ThroughX1()},function(S){return v.i18n.commaOnlyInMonthX0?v.i18n.commaOnlyInMonthX0():v.i18n.commaOnlyInX0()});return b},m.prototype.getDayOfMonthDescription=function(){var v=this,x=null,b=this.expressionParts[3];switch(b){case"L":x=this.i18n.commaOnTheLastDayOfTheMonth();break;case"WL":case"LW":x=this.i18n.commaOnTheLastWeekdayOfTheMonth();break;default:var S=b.match(/(\d{1,2}W)|(W\d{1,2})/);if(S){var _=parseInt(S[0].replace("W","")),O=_==1?this.i18n.firstWeekday():f.StringUtilities.format(this.i18n.weekdayNearestDayX0(),_.toString());x=f.StringUtilities.format(this.i18n.commaOnTheX0OfTheMonth(),O);break}else{var k=b.match(/L-(\d{1,2})/);if(k){var C=k[1];x=f.StringUtilities.format(this.i18n.commaDaysBeforeTheLastDayOfTheMonth(C),C);break}else{if(b=="*"&&this.expressionParts[5]!="*")return"";x=this.getSegmentDescription(b,this.i18n.commaEveryDay(),function(N){return N=="L"?v.i18n.lastDay():v.i18n.dayX0?f.StringUtilities.format(v.i18n.dayX0(),N):N},function(N){return N=="1"?v.i18n.commaEveryDay():v.i18n.commaEveryX0Days(N)},function(N){return v.i18n.commaBetweenDayX0AndX1OfTheMonth(N)},function(N){return v.i18n.commaOnDayX0OfTheMonth(N)})}break}}return x},m.prototype.getYearDescription=function(){var v=this,x=this.getSegmentDescription(this.expressionParts[6],"",function(b){return/^\d+$/.test(b)?new Date(parseInt(b),1).getFullYear().toString():b},function(b){return f.StringUtilities.format(v.i18n.commaEveryX0Years(b),b)},function(b){return v.i18n.commaYearX0ThroughYearX1()||v.i18n.commaX0ThroughX1()},function(b){return v.i18n.commaOnlyInYearX0?v.i18n.commaOnlyInYearX0():v.i18n.commaOnlyInX0()});return x},m.prototype.getSegmentDescription=function(v,x,b,S,_,O){var k=null,C=v.indexOf("/")>-1,N=v.indexOf("-")>-1,T=v.indexOf(",")>-1;if(!v)k="";else if(v==="*")k=x;else if(!C&&!N&&!T)k=f.StringUtilities.format(O(v),b(v));else if(T){for(var R=v.split(","),L="",D=this.i18n.spaceAnd(),P=0;P<R.length;P++)if(P>0&&R.length>2&&(L+=",",P<R.length-1&&(L+=" ")),P>0&&R.length>1&&(P==R.length-1||R.length==2)&&(L+=D==","&&R.length>2?" ":"".concat(D," ")),R[P].indexOf("/")>-1||R[P].indexOf("-")>-1){var F=R[P].indexOf("-")>-1&&R[P].indexOf("/")==-1,I=this.getSegmentDescription(R[P],x,b,S,F?this.i18n.commaX0ThroughX1:_,O);F&&(I=I.replace(", ","")),L+=I}else if(!C)L+=b(R[P]);else{var U=this.getSegmentDescription(R[P],x,b,S,_,O);U&&U.startsWith(", ")&&(U=U.substring(2)),L+=U}C?k=L:k=f.StringUtilities.format(O(v),L)}else if(C){var R=v.split("/");if(k=f.StringUtilities.format(S(R[1]),R[1]),R[0].indexOf("-")>-1){var G=this.generateRangeSegmentDescription(R[0],_,b);G.indexOf(", ")!=0&&(k+=", "),k+=G}else if(R[0].indexOf("*")==-1){var q=f.StringUtilities.format(O(R[0]),b(R[0]));q=q.replace(", ",""),k+=f.StringUtilities.format(this.i18n.commaStartingX0(),q)}}else N&&(k=this.generateRangeSegmentDescription(v,_,b));return k},m.prototype.generateRangeSegmentDescription=function(v,x,b){var S="",_=v.split("-"),O=b(_[0],1),k=b(_[1],2),C=x(v);return S+=f.StringUtilities.format(C,O,k),S},m.prototype.formatTime=function(v,x,b){var S=0,_=0,O=parseInt(v)+S,k=parseInt(x)+_;k>=60?(k-=60,O+=1):k<0&&(k+=60,O-=1),O>=24?O=O-24:O<0&&(O=24+O);var C="",N=!1;this.options.use24HourTimeFormat||(N=!!(this.i18n.setPeriodBeforeTime&&this.i18n.setPeriodBeforeTime()),C=N?"".concat(this.getPeriod(O)," "):" ".concat(this.getPeriod(O)),O>12&&(O-=12),O===0&&(O=12));var T="";b&&(T=":".concat(("00"+b).substring(b.length)));var R=O.toString(),L=("00"+R).substring(R.length),D=k.toString(),P=("00"+D).substring(D.length),F=this.options.trimHoursLeadingZero?R:L;return"".concat(N?C:"").concat(F,":").concat(P).concat(T).concat(N?"":C)},m.prototype.transformVerbosity=function(v,x){if(!x&&(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 b=0,S=Object.entries(this.i18n.conciseVerbosityReplacements());b<S.length;b++){var _=S[b],O=_[0],k=_[1];v=v.replace(new RegExp(O,"g"),k)}return v},m.prototype.getPeriod=function(v){return v>=12?this.i18n.pm&&this.i18n.pm()||"PM":this.i18n.am&&this.i18n.am()||"AM"},m.locales={},m})();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(m){m.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 m=p.split(","),v=0;v<m.length;v++)if(!isNaN(parseInt(m[v],10))){var x=parseInt(m[v],10);u(x>=0&&x<=59,"seconds part must be >= 0 and <= 59")}},h.minuteRange=function(p){for(var m=p.split(","),v=0;v<m.length;v++)if(!isNaN(parseInt(m[v],10))){var x=parseInt(m[v],10);u(x>=0&&x<=59,"minutes part must be >= 0 and <= 59")}},h.hourRange=function(p){for(var m=p.split(","),v=0;v<m.length;v++)if(!isNaN(parseInt(m[v],10))){var x=parseInt(m[v],10);u(x>=0&&x<=23,"hours part must be >= 0 and <= 23")}},h.dayOfMonthRange=function(p){for(var m=p.split(","),v=0;v<m.length;v++)if(!isNaN(parseInt(m[v],10))){var x=parseInt(m[v],10);u(x>=1&&x<=31,"DOM part must be >= 1 and <= 31")}},h.monthRange=function(p,m){for(var v=p.split(","),x=0;x<v.length;x++)if(!isNaN(parseInt(v[x],10))){var b=parseInt(v[x],10);u(b>=1&&b<=12,m?"month part must be >= 0 and <= 11":"month part must be >= 1 and <= 12")}},h.dayOfWeekRange=function(p,m){for(var v=p.split(","),x=0;x<v.length;x++)if(!isNaN(parseInt(v[x],10))){var b=parseInt(v[x],10);u(b>=0&&b<=6,m?"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=[],m=1;m<arguments.length;m++)p[m-1]=arguments[m];return h.replace(/%s/g,function(v){return p.shift()})},f.containsAny=function(h,p){return p.some(function(m){return h.indexOf(m)>-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})())})(tw)),tw.exports}var zke=Lke();const C6=Nu(zke);function $ke(e){return e.trigger.kind}function Bke(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=Uke(t.expr,r),a=C6.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 Uke(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 rD(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 Fke={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 Hke(e){return e.scope==="system"}function Kke(e){return e==="prompt"?"Additional instructions (appended to prompt)":e==="bash"?"Override command":"Override args"}function qke(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 Gke(e,t){var n;return e.scope==="system"?"system":((n=e.createdBy)==null?void 0:n.uid)===t?"mine":"others"}function Wke({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]=y.useState(null),[m,v]=y.useState(""),[x,b]=y.useState({mine:!0,others:!0,system:!0}),[S,_]=y.useState({once:!0,interval:!0,cron:!0,event:!0}),[O,k]=y.useState(!1),C=D=>b(P=>{if(Object.values(P).every(Boolean))return{mine:!1,others:!1,system:!1,[D]:!0};const I={...P,[D]:!P[D]};return Object.values(I).some(Boolean)?I:{mine:!0,others:!0,system:!0}}),N=D=>_(P=>{if(Object.values(P).every(Boolean))return{once:!1,interval:!1,cron:!1,event:!1,[D]:!0};const I={...P,[D]:!P[D]};return Object.values(I).some(Boolean)?I:{once:!0,interval:!0,cron:!0,event:!0}}),T=e.filter(D=>x[Gke(D,t)]&&S[$ke(D)]),R=D=>{const P=localStorage.getItem(`schedule-override-${D.id}`);v(P??""),p(D.id)},L=async()=>{if(h){k(!0);try{const D=m.trim()||void 0;D&&localStorage.setItem(`schedule-override-${h}`,D);const P=await s(h,D);p(null),v(""),P&&u(P)}finally{k(!1)}}};return E.jsxs("div",{className:"space-y-3",children:[E.jsxs("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[E.jsxs("div",{className:"flex gap-1 flex-wrap",children:[["mine","others","system"].map(D=>E.jsx("button",{onClick:()=>C(D),className:`text-[11px] px-2 py-0.5 rounded-full border transition-colors ${x[D]?"bg-primary text-primary-foreground border-primary":"bg-transparent text-muted-foreground border-border hover:border-muted-foreground"}`,children:D},D)),E.jsx("span",{className:"w-px h-4 bg-border mx-1"}),["once","interval","cron","event"].map(D=>E.jsx("button",{onClick:()=>N(D),className:`text-[11px] px-2 py-0.5 rounded-full border transition-colors ${S[D]?"bg-primary text-primary-foreground border-primary":"bg-transparent text-muted-foreground border-border hover:border-muted-foreground"}`,children:D},D))]}),E.jsxs(Re,{size:"sm",onClick:n,className:"gap-1",children:[E.jsx(dv,{className:"w-4 h-4"})," New schedule"]})]}),T.length===0&&E.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(D=>{var P,F;return E.jsxs("div",{className:"border rounded-lg p-3 space-y-2 overflow-hidden",children:[E.jsxs("div",{className:"flex items-start justify-between gap-2 flex-wrap",children:[E.jsxs("div",{className:"min-w-0 flex-1",children:[E.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-wrap",children:[E.jsx("input",{type:"checkbox",checked:D.enabled,onChange:I=>a(D.id,I.target.checked),title:D.enabled?"Disable":"Enable",className:"shrink-0"}),E.jsx("span",{className:"font-medium text-sm truncate max-w-[280px]",title:D.name,children:D.name}),E.jsx("span",{className:"shrink-0 text-[10px] font-mono px-1.5 py-0.5 rounded bg-muted text-muted-foreground",children:D.task.kind}),E.jsx("span",{className:"shrink-0 text-[10px] font-mono px-1.5 py-0.5 rounded bg-muted text-muted-foreground",children:D.trigger.kind}),f.has(D.id)&&E.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:[E.jsx(Nd,{className:"w-3 h-3 animate-spin"}),"running"]}),E.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:Hke(D)?"system":((F=(P=D.createdBy)==null?void 0:P.email)==null?void 0:F.split("@")[0])??"unknown"})]}),E.jsx("div",{className:"mt-1 text-xs text-muted-foreground truncate",children:Bke(D)}),E.jsxs("div",{className:"mt-1 flex items-center gap-3 text-xs text-muted-foreground",children:[E.jsxs("span",{children:["Next: ",D.enabled?rD(D.nextRun):"disabled"]}),D.lastRun&&E.jsxs("button",{className:`px-1.5 py-0.5 rounded text-[10px] ${Fke[D.lastRun.status]??""}`,onClick:()=>u(D.lastRun.sessionId),title:"Open last run",children:["last: ",D.lastRun.status," ",rD(D.lastRun.at)]}),E.jsxs("span",{children:["runs: ",D.runCount??0]})]})]}),E.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[f.has(D.id)?E.jsx(Re,{variant:"ghost",size:"icon",title:"Stop run",onClick:()=>c(D.id),children:E.jsx(xj,{className:"w-4 h-4 text-destructive"})}):E.jsx(Re,{variant:"ghost",size:"icon",title:"Run now",onClick:()=>R(D),children:E.jsx(Zq,{className:"w-4 h-4"})}),E.jsx(Re,{variant:"ghost",size:"icon",title:"Edit",onClick:()=>r(D),children:E.jsx(uE,{className:"w-4 h-4"})}),E.jsx(Re,{variant:"ghost",size:"icon",title:"Delete",onClick:()=>i(D.id),children:E.jsx(Md,{className:"w-4 h-4 text-destructive"})})]})]}),h===D.id&&E.jsxs("div",{className:"border-t pt-2 mt-2 space-y-2",children:[E.jsx("label",{className:"text-xs text-muted-foreground",children:Kke(D.task.kind)}),E.jsx("input",{type:"text",className:"w-full text-sm border rounded px-2 py-1.5 bg-background",placeholder:qke(D.task.kind),value:m,onChange:I=>v(I.target.value),onKeyDown:I=>{I.key==="Enter"&&!O&&L(),I.key==="Escape"&&p(null)},disabled:O,autoFocus:!0}),E.jsxs("div",{className:"flex gap-2 justify-end",children:[E.jsx(Re,{size:"sm",variant:"ghost",onClick:()=>p(null),disabled:O,children:"Cancel"}),E.jsx(Re,{size:"sm",onClick:L,disabled:O,children:O?"Running...":"Run"})]})]})]},D.id)})]})}function Vke(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 Yke=[{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}],Xke=[{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 Zke({match:e,onChange:t}){const n=Object.entries(e),r=(s,c,u)=>{const f={};n.forEach(([h,p],m)=>{f[m===s?c:h]=m===s?u:p}),t(f)},i=s=>t(Object.fromEntries(n.filter((c,u)=>u!==s))),a=()=>t({...e,"":""});return E.jsxs("div",{className:"space-y-1",children:[E.jsx("label",{className:"text-xs text-muted-foreground",children:"Match filter (optional — all must match)"}),n.map(([s,c],u)=>E.jsxs("div",{className:"flex gap-1",children:[E.jsx(In,{className:"text-xs font-mono",value:s,onChange:f=>r(u,f.target.value,c),placeholder:"payload.path (e.g. type)"}),E.jsx(In,{className:"text-xs font-mono",value:c,onChange:f=>r(u,s,f.target.value),placeholder:"value (e.g. invoice.paid)"}),E.jsx(Re,{type:"button",variant:"ghost",size:"sm",onClick:()=>i(u),children:"×"})]},u)),E.jsx(Re,{type:"button",variant:"outline",size:"sm",onClick:a,children:"+ Add filter"})]})}function iD({initial:e,onSave:t,onCancel:n,skills:r=[],workspaceFiles:i=[]}){const a=y.useMemo(()=>Intl.DateTimeFormat().resolvedOptions().timeZone,[]),[s,c]=y.useState((e==null?void 0:e.name)??"New schedule"),[u,f]=y.useState((e==null?void 0:e.enabled)??!0),[h,p]=y.useState((e==null?void 0:e.trigger)??{kind:"cron",expr:"0 9 * * *",tz:a}),[m,v]=y.useState((e==null?void 0:e.task)??{kind:"prompt",prompt:""}),[x,b]=y.useState(!1),[S,_]=y.useState(null),O=y.useMemo(()=>{if(h.kind!=="cron")return"";try{return C6.toString(h.expr)}catch{return"Invalid cron"}},[h]),k=async()=>{b(!0),_(null);try{await t({name:s,enabled:u,trigger:h,task:m})}catch(C){_(C.message)}finally{b(!1)}};return E.jsxs("div",{className:"space-y-4",children:[E.jsxs("div",{className:"space-y-1",children:[E.jsx("label",{className:"text-xs text-muted-foreground",children:"Name"}),E.jsx(In,{value:s,onChange:C=>c(C.target.value),placeholder:"e.g. Daily standup summary"})]}),E.jsxs("div",{className:"space-y-2",children:[E.jsx("label",{className:"text-xs text-muted-foreground",children:"Trigger"}),E.jsx("div",{className:"flex gap-1",children:["once","interval","cron","event"].map(C=>E.jsx(Re,{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"&&E.jsx(In,{type:"datetime-local",value:Vke(h.at),onChange:C=>{const N=new Date(C.target.value);isNaN(N.getTime())||p({kind:"once",at:N.getTime()})}}),h.kind==="interval"&&E.jsxs("div",{className:"space-y-2",children:[E.jsx("div",{className:"flex gap-1 flex-wrap",children:Yke.map(C=>E.jsx(Re,{type:"button",variant:h.everyMs===C.ms?"default":"outline",size:"sm",onClick:()=>p({kind:"interval",everyMs:C.ms}),children:C.label},C.ms))}),E.jsx(In,{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"}),E.jsxs("p",{className:"text-xs text-muted-foreground",children:["Every ",Math.round(h.everyMs/1e3),"s"]})]}),h.kind==="cron"&&E.jsxs("div",{className:"space-y-2",children:[E.jsx("div",{className:"flex gap-1 flex-wrap",children:Xke.map(C=>E.jsx(Re,{type:"button",variant:"outline",size:"sm",onClick:()=>p({kind:"cron",expr:C.expr,tz:a}),children:C.label},C.expr))}),E.jsx(In,{className:"font-mono text-xs",value:h.expr,onChange:C=>p({...h,expr:C.target.value}),placeholder:"0 9 * * *"}),E.jsx(In,{className:"text-xs",value:h.tz,onChange:C=>p({...h,tz:C.target.value}),placeholder:"IANA timezone"}),E.jsxs("p",{className:"text-xs text-muted-foreground",children:[O," (",h.tz,")"]})]}),h.kind==="event"&&E.jsxs("div",{className:"space-y-2",children:[E.jsx(In,{value:h.source,onChange:C=>p({...h,source:C.target.value}),placeholder:"Event source (e.g. stripe, github, deploy)"}),E.jsxs("p",{className:"text-xs text-muted-foreground",children:["Fires when an event with this source arrives via ",E.jsxs("code",{children:["POST /api/events/",h.source||":source"]})," or ",E.jsx("code",{children:"ctx.emitEvent()"}),"."]}),E.jsx(Zke,{match:h.match??{},onChange:C=>p({...h,match:C})})]})]}),E.jsxs("div",{className:"space-y-2",children:[E.jsx("label",{className:"text-xs text-muted-foreground",children:"Task"}),E.jsx("div",{className:"flex gap-1",children:["prompt","bash"].map(C=>E.jsx(Re,{type:"button",variant:m.kind===C?"default":"outline",size:"sm",onClick:()=>v(C==="prompt"?{kind:"prompt",prompt:""}:{kind:"bash",command:""}),children:C==="prompt"?"Prompt":"Bash command"},C))}),m.kind==="prompt"?E.jsx(k6,{rows:5,value:m.prompt,onChange:C=>v({...m,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"}):m.kind==="bash"?E.jsx(by,{rows:3,className:"font-mono text-xs",value:m.command,onChange:C=>v({...m,command:C.target.value}),placeholder:"ls -la ~/"}):E.jsxs("p",{className:"text-xs text-muted-foreground",children:["Command: ",m.command]})]}),E.jsxs("div",{className:"flex items-center gap-2",children:[E.jsx("input",{id:"sched-enabled",type:"checkbox",checked:u,onChange:C=>f(C.target.checked)}),E.jsx("label",{htmlFor:"sched-enabled",className:"text-sm",children:"Enabled"})]}),S&&E.jsx("p",{className:"text-xs text-destructive",children:S}),E.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[E.jsx(Re,{variant:"outline",onClick:n,disabled:x,children:"Cancel"}),E.jsx(Re,{onClick:k,disabled:x,children:x?"Saving…":"Save"})]})]})}const aD=y.forwardRef(function({getToken:t,onOpenSession:n,refreshKey:r=0,runningIds:i=new Set,skills:a=[],workspaceFiles:s=[],trigger:c},u){const[f,h]=y.useState(!1),{user:p}=ij(),{schedules:m,serverRunningIds:v,create:x,update:b,remove:S,toggle:_,runNow:O,cancelRun:k}=jke(t,f,r);y.useImperativeHandle(u,()=>({open:()=>h(!0)}),[]);const[C,N]=y.useState(null),[T,R]=y.useState(!1),[L,D]=y.useState(new Set),P=()=>{N(null),R(!1)},F=async(I,U)=>{D(G=>new Set(G).add(I));try{return await O(I,U)}finally{setTimeout(()=>{D(G=>{const q=new Set(G);return q.delete(I),q})},1500)}};return E.jsxs(Es,{open:f,onOpenChange:I=>{h(I),I||P()},children:[E.jsx(oh,{asChild:!0,children:c||E.jsx(Re,{variant:"ghost",size:"icon",className:"h-8 w-8",title:"Scheduled Tasks",children:E.jsx(aE,{className:"w-4 h-4"})})}),E.jsxs(uo,{className:"max-w-[95vw] sm:max-w-2xl",children:[E.jsx(Dl,{children:E.jsx(Ss,{children:T?"New Schedule":C?`Edit: ${C.name}`:"Scheduled Tasks"})}),T?E.jsx(iD,{onSave:async I=>{await x(I),P()},onCancel:P,skills:a,workspaceFiles:s},"__new__"):C?E.jsx(iD,{initial:C,onSave:async I=>{await b(C.id,I),P()},onCancel:P,skills:a,workspaceFiles:s},C.id):E.jsx(Wke,{schedules:m,currentUserUid:p==null?void 0:p.uid,onCreate:()=>R(!0),onEdit:I=>N(I),onDelete:I=>{confirm("Delete this schedule?")&&S(I)},onToggle:_,onRunNow:F,onCancel:k,runningIds:new Set([...i,...v,...L]),onOpenRun:I=>{h(!1),n(I)}})]})]})});function T6(){const e=localStorage.getItem("dark-mode");return e!==null?e==="true":window.matchMedia("(prefers-color-scheme: dark)").matches}let Ml=typeof window<"u"?T6():!0;const K1=new Set;function N6(){document.documentElement.classList.toggle("dark",Ml),localStorage.setItem("dark-mode",String(Ml)),K1.forEach(e=>e())}typeof window<"u"&&N6();function M6(e){e!==Ml&&(Ml=e,N6())}function Qke(e){K1.add(e);const t=n=>{n.key==="dark-mode"&&M6(T6())};return window.addEventListener("storage",t),()=>{K1.delete(e),window.removeEventListener("storage",t)}}function Jke(){return{dark:y.useSyncExternalStore(Qke,()=>Ml,()=>Ml),toggle:()=>M6(!Ml)}}const oD=4;function eOe(e,t){const[n,r]=y.useState({}),[i,a]=y.useState([]),s=y.useRef(t);s.current=t;const c=y.useRef(!document.hidden),u=y.useRef(e);u.current=e,y.useEffect(()=>{const b=()=>{var O;c.current=!document.hidden,(O=u.current)==null||O.sendPresence(s.current,c.current),c.current&&s.current&&h(s.current)},S=()=>{var O;c.current=!0,(O=u.current)==null||O.sendPresence(s.current,!0),s.current&&h(s.current)},_=()=>{var O;c.current=!1,(O=u.current)==null||O.sendPresence(s.current,!1)};return document.addEventListener("visibilitychange",b),window.addEventListener("focus",S),window.addEventListener("blur",_),()=>{document.removeEventListener("visibilitychange",b),window.removeEventListener("focus",S),window.removeEventListener("blur",_)}},[]),y.useEffect(()=>{e==null||e.sendPresence(t,c.current),t&&c.current&&h(t)},[t,e]),y.useEffect(()=>{},[i.length]);const f=y.useCallback(b=>{var S,_;if(b.type==="unread"){if(s.current===b.sessionId&&c.current){(S=u.current)==null||S.markRead(b.sessionId);return}r(k=>({...k,[b.sessionId]:{count:b.count,preview:b.preview,source:b.source,title:b.title}})),a(k=>{const C=k.filter(T=>T.sessionId!==b.sessionId);return[{id:`${b.sessionId}-${Date.now()}`,sessionId:b.sessionId,preview:b.preview,title:b.title,ts:Date.now()},...C].slice(0,oD)})}if(b.type==="unread_sync"){const O={};for(const[k,C]of Object.entries(b.sessions)){if(k===s.current&&c.current){(_=u.current)==null||_.markRead(k);continue}O[k]={count:C.count,preview:C.preview,source:C.source,title:C.title}}r(O)}b.type==="unread_cleared"&&r(O=>{const k={...O};return delete k[b.sessionId],k})},[]),h=y.useCallback(b=>{var S;r(_=>{if(!_[b])return _;const O={..._};return delete O[b],O}),a(_=>_.filter(O=>O.sessionId!==b)),(S=u.current)==null||S.markRead(b)},[]),p=y.useCallback(b=>{a(S=>S.filter(_=>_.id!==b))},[]),m=y.useCallback(b=>{s.current===b.sessionId&&c.current||a(S=>{const _=S.filter(k=>k.sessionId!==b.sessionId);return[{id:`${b.sessionId}-${Date.now()}`,sessionId:b.sessionId,preview:b.preview,title:b.title,ts:Date.now()},..._].slice(0,oD)})},[]),v=Object.keys(n).length;y.useEffect(()=>{const b="Shraga";document.title=v>0?`(${v}) ${b}`:b,tOe(v)},[v]);const x=y.useRef(0);return y.useEffect(()=>{v>x.current,x.current=v},[v]),{unreads:n,toasts:i,totalUnread:v,markRead:h,dismissToast:p,addToast:m,handleUnreadEvent:f}}let Xc=null,nw=null;function tOe(e){if(typeof document>"u")return;if(!nw){const n=document.querySelector('link[rel="icon"]');nw=(n==null?void 0:n.href)??""}if(e===0){sD(nw||"");return}Xc||(Xc=document.createElement("canvas"),Xc.width=32,Xc.height=32);const t=Xc.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),sD(Xc.toDataURL()))}function sD(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 nOe({toasts:e,onDismiss:t,onOpen:n}){return e.length===0?null:E.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)=>E.jsxs("div",{className:He("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:[E.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:E.jsx(Rl,{className:"w-3 h-3 text-muted-foreground"})}),E.jsxs("div",{className:"flex items-start gap-2.5",children:[E.jsx(pw,{className:"w-4 h-4 mt-0.5 shrink-0 text-blue-500"}),E.jsxs("div",{className:"flex-1 min-w-0",children:[E.jsx("div",{className:"text-xs font-medium text-foreground truncate",children:r.title||`Session ${r.sessionId.slice(0,8)}`}),E.jsx("div",{className:"text-xs text-muted-foreground mt-0.5 line-clamp-2",children:r.preview})]})]})]},r.id))})}function lD(){return new URLSearchParams(window.location.search).get("session")||void 0}function rOe(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 iOe(){return E.jsx(Mq,{value:{},children:E.jsx(aOe,{})})}function aOe(){var $n,xr;const e=Sa(),{dark:t,toggle:n}=Jke(),{user:r,token:i,getToken:a,loading:s,mode:c,needsSetup:u,loginLocal:f,registerLocal:h,logout:p}=ij(),[m,v]=y.useState(()=>localStorage.getItem("shraga:sidebarOpen")!=="false"),x=y.useCallback(he=>{v(Ue=>{const ot=typeof he=="function"?he(Ue):he;return localStorage.setItem("shraga:sidebarOpen",String(ot)),ot})},[]),[b,S]=y.useState(!1),[_,O]=y.useState({top:52,right:8}),k=y.useRef(null),C=y.useCallback(()=>{var Ue;const he=(Ue=k.current)==null?void 0:Ue.getBoundingClientRect();he&&O({top:he.bottom+4,right:Math.max(4,window.innerWidth-he.right)}),S(ot=>!ot)},[]),[N,T]=y.useState({}),R=y.useRef(null),[L,D]=y.useState(0),[P,F]=y.useState(0),[I,U]=y.useState(new Set),[G,q]=y.useState([]),[$,W]=y.useState([]),[K,X]=y.useState(0),[j,H]=y.useState(new Set),[Q,B]=y.useState(!1),[de,be]=y.useState(()=>localStorage.getItem("shraga:authorized")==="1"?!0:null),[ge,Ie]=y.useState(()=>lD()),Ve=y.useCallback((he,Ue)=>Ie(he),[]),fe=y.useCallback((he,Ue)=>Ie(Ue),[]),ke=y.useCallback((he,Ue)=>{},[]),we=y.useCallback(()=>D(he=>he+1),[]),ue=y.useRef(!1);y.useEffect(()=>{if(!i){!ue.current&&localStorage.getItem("shraga:authorized")!=="1"&&be(null);return}a().then(async he=>{var Ue,ot,mt;if(!he)return be(!1);try{const un=await fetch("/api/config",{headers:{Authorization:`Bearer ${he}`}});if(un.ok)return ue.current=!0,localStorage.setItem("shraga:authorized","1"),be(!0);const On=await un.json().catch(()=>({}));if(un.status===401&&((Ue=On.error)!=null&&Ue.includes("audience")||(ot=On.error)!=null&&ot.includes("aud"))){console.warn("[auth] Token audience mismatch — signing out stale session"),p();return}if(un.status===403&&((mt=On.error)!=null&&mt.toLowerCase().includes("whitelist")))return localStorage.removeItem("shraga:authorized"),be(!1);if(ue.current)return;be(un.status!==401&&un.status!==403)}catch{if(ue.current)return;be(!0)}})},[i,a]);const ht=y.useCallback(()=>{i&&(X(he=>he+1),bl("/api/workspace",a).then(he=>he.json()).then(he=>W(he.entries??[])).catch(he=>console.warn("[workspace] refresh failed",he)))},[i,a]),qe=y.useCallback(he=>{F(Ue=>Ue+1),he.type==="schedule:run_started"?(U(Ue=>new Set(Ue).add(he.scheduleId)),we()):he.type==="schedule:run_finished"?(U(Ue=>{const ot=new Set(Ue);return ot.delete(he.scheduleId),ot}),we()):he.type==="schedule:deleted"&&U(Ue=>{const ot=new Set(Ue);return ot.delete(he.id),ot})},[we]),_e=y.useRef(null),De=y.useRef(null),Kt=y.useRef(ge);Kt.current=ge;const kn=y.useCallback(he=>{var Ue,ot;if((Ue=De.current)==null||Ue.call(De,he),he.type.startsWith("schedule:")){qe(he);return}switch(he.type,he.type){case"workspace_change":ht();break;case"session_title_updated":we();break;case"session_messages_changed":we(),he.sessionId===Kt.current&&((ot=_e.current)==null||ot.call(_e,he.sessionId));break;case"session_busy":H(mt=>{const un=new Set(mt);return he.busy?un.add(he.sessionId):un.delete(he.sessionId),un}),he.busy||we();break}},[qe,ht,we]),{socket:zn,connectionStatus:ur,authError:Oi}=KK(i,a,kn),{unreads:ti,toasts:Oo,markRead:St,dismissToast:Co,addToast:ae,handleUnreadEvent:ve}=eOe(zn,ge);De.current=ve,_e.current=St,Oq({socket:zn,getToken:a,pushEnabled:Q,activeSessionId:ge,switchTo:()=>{},openSession:Ve,onForegroundMessage:he=>{var ot;const Ue=typeof((ot=he.data)==null?void 0:ot.session)=="string"?he.data.session:void 0;Ue&&ae({sessionId:Ue,preview:he.body||"New message",title:he.title})}}),y.useEffect(()=>{Cq()},[]),y.useEffect(()=>{rOe(ge),ge&&St(ge)},[ge,St]),y.useEffect(()=>{const he=()=>Ie(lD());return window.addEventListener("popstate",he),()=>window.removeEventListener("popstate",he)},[]),y.useEffect(()=>{i&&(bl("/api/config",a).then(he=>he.json()).then(T).catch(()=>{}),bl("/api/skills",a).then(he=>he.json()).then(he=>q(he.skills)).catch(()=>{}),bl("/api/features",a).then(he=>he.json()).then(he=>B(!!he.push)).catch(()=>{}))},[i,a]),y.useEffect(()=>{ht()},[ht]);const ze=y.useCallback(()=>{Ie(void 0),window.innerWidth<640&&x(!1)},[x]),Xe=y.useMemo(()=>$.filter(he=>he.type==="file").map(he=>he.path),[$]),pt=y.useMemo(()=>({socket:zn,connectionStatus:ur,getToken:a,token:i,agentConfig:N,setAgentConfig:T,activeSessionId:ge,skills:G,workspaceFiles:Xe,openSchedules:()=>{var he;return(he=R.current)==null?void 0:he.open()},markRead:St,bumpSidebar:we,assignSession:fe,renameTab:ke,openSession:Ve}),[zn,ur,a,i,N,ge,G,Xe,St,we,fe,ke,Ve]);return s?E.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground text-sm",children:"Loading…"}):!r||!i?E.jsx(wG,{mode:c,needsSetup:u,onLoginLocal:f,onRegisterLocal:h}):de===null?E.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground text-sm",children:"Verifying access…"}):!de||Oi?E.jsx("div",{className:"flex h-full items-center justify-center bg-background",children:E.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:[E.jsx("div",{className:"flex items-center justify-center w-12 h-12 rounded-full bg-destructive/10 text-destructive",children:E.jsx(j0,{className:"w-6 h-6"})}),E.jsx("h2",{className:"text-lg font-semibold",children:"Access Denied"}),E.jsx("p",{className:"text-sm text-muted-foreground",children:"Your account is not authorized to use this app."}),E.jsxs("p",{className:"text-xs text-muted-foreground",children:["Signed in as ",r.email]}),E.jsx(Re,{variant:"outline",onClick:()=>p(),children:"Sign out"})]})}):window.location.pathname==="/oauth/authorize"?E.jsx(EG,{getToken:a,userEmail:r.email??""}):window.location.pathname==="/cli-auth"?E.jsx(SG,{getToken:a,userEmail:r.email??""}):E.jsxs("div",{className:"flex h-full",children:[m&&E.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:[E.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:[E.jsx("span",{className:"text-sm font-medium",children:"Sessions"}),E.jsx(Re,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>x(!1),children:E.jsx(DT,{className:"w-4 h-4"})})]}),E.jsx("div",{className:"flex-1 min-h-0",children:E.jsx(Tae,{getToken:a,activeSessionId:ge,onSelect:(he,Ue)=>{Ve(he,Ue),St(he),window.innerWidth<640&&x(!1)},onNew:ze,refreshKey:L,workspaceRefreshKey:K,onRefreshWorkspace:ht,userUid:r.uid,userEmail:r.email||"",unreads:ti,busySessions:j,socket:zn})})]}),E.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[E.jsx("header",{className:"border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60",style:{paddingTop:"env(safe-area-inset-top)"},children:E.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2 px-2 sm:px-3 py-1.5",children:[E.jsx(Re,{variant:"ghost",size:"icon",className:"h-9 w-9 sm:h-8 sm:w-8 shrink-0",onClick:()=>x(!m),title:"Toggle sidebar",children:m?E.jsx(DT,{className:"w-4 h-4"}):E.jsx(Yq,{className:"w-4 h-4"})}),E.jsx(Re,{variant:"ghost",size:"icon",className:"h-9 w-9 sm:h-8 sm:w-8 shrink-0",onClick:ze,title:"New chat (⌘N)",children:E.jsx(nG,{className:"w-4 h-4"})}),E.jsx("div",{className:"flex-1"}),E.jsxs("div",{className:"hidden sm:flex items-center gap-0.5 shrink-0",children:[E.jsx(Re,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:n,title:t?"Light mode":"Dark mode",children:t?E.jsx(LT,{className:"w-4 h-4"}):E.jsx(PT,{className:"w-4 h-4"})}),($n=e.headerActions)==null?void 0:$n.call(e),E.jsx(X2,{getToken:a}),E.jsx(J2,{getToken:a,onSkillsChange:q}),E.jsx(tD,{getToken:a}),E.jsx(aD,{ref:R,getToken:a,refreshKey:P,runningIds:I,onOpenSession:he=>Ve(he),skills:G,workspaceFiles:Xe}),E.jsx(Re,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>p(),title:"Sign out",children:E.jsx(j0,{className:"w-4 h-4"})})]}),E.jsxs("div",{className:"relative sm:hidden shrink-0",children:[E.jsx(Re,{ref:k,variant:"ghost",size:"icon",className:"h-9 w-9",onClick:C,children:E.jsx(zq,{className:"w-4 h-4"})}),b&&Ea.createPortal(E.jsxs(E.Fragment,{children:[E.jsx("div",{className:"fixed inset-0 z-[1090] cursor-pointer",onClick:()=>S(!1)}),E.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:_.top,right:_.right},children:[(xr=e.headerActions)==null?void 0:xr.call(e),E.jsx(X2,{getToken:a,trigger:E.jsxs("button",{className:"flex w-full items-center gap-2.5 rounded-md px-3 py-2.5 text-sm hover:bg-accent",children:[E.jsx(yj,{className:"w-3.5 h-3.5"})," MCPs"]})}),E.jsx(J2,{getToken:a,onSkillsChange:q,trigger:E.jsxs("button",{className:"flex w-full items-center gap-2.5 rounded-md px-3 py-2.5 text-sm hover:bg-accent",children:[E.jsx(hw,{className:"w-3.5 h-3.5"})," Skills"]})}),E.jsx(tD,{getToken:a,trigger:E.jsxs("button",{className:"flex w-full items-center gap-2.5 rounded-md px-3 py-2.5 text-sm hover:bg-accent",children:[E.jsx(dw,{className:"w-3.5 h-3.5"})," Modules"]})}),E.jsx(aD,{getToken:a,refreshKey:P,runningIds:I,onOpenSession:he=>Ve(he),skills:G,workspaceFiles:Xe,trigger:E.jsxs("button",{className:"flex w-full items-center gap-2.5 rounded-md px-3 py-2.5 text-sm hover:bg-accent",children:[E.jsx(aE,{className:"w-3.5 h-3.5"})," Schedules"]})}),E.jsx("div",{className:"border-t my-1"}),E.jsxs("button",{className:"flex w-full items-center gap-2.5 rounded-md px-3 py-2.5 text-sm hover:bg-accent",onClick:()=>{S(!1),n()},children:[t?E.jsx(LT,{className:"w-3.5 h-3.5"}):E.jsx(PT,{className:"w-3.5 h-3.5"}),t?"Light mode":"Dark mode"]}),E.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:[E.jsx(j0,{className:"w-3.5 h-3.5"})," Sign out"]})]})]}),document.body)]})]})}),ur==="update_available"&&E.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:[E.jsx("span",{children:"A new version is available"}),E.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"})]}),E.jsx(Nq,{value:pt,children:E.jsx("div",{className:"flex-1 min-h-0",children:E.jsx(Ike,{nodeId:"main",sessionId:ge},ge??"new")})})]}),E.jsx(nOe,{toasts:Oo,onDismiss:Co,onOpen:he=>{Ve(he),St(he)}})]})}const cD="unclaw:",oOe="shraga:";function sOe(){try{const e=Object.keys(localStorage).filter(t=>t.startsWith(cD));for(const t of e){const n=oOe+t.slice(cD.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))}}sOe();G8.createRoot(document.getElementById("root")).render(E.jsx(y.StrictMode,{children:E.jsx(iOe,{})}));
|
package/dist/client/index.html
CHANGED
|
@@ -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-
|
|
16
|
+
<script type="module" crossorigin src="/assets/index-BmGzUolm.js"></script>
|
|
17
17
|
<link rel="stylesheet" crossorigin href="/assets/index-J2NH6FvE.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.
|
|
3
|
+
"version": "0.1.90",
|
|
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",
|
|
@@ -33,11 +33,14 @@ export function deriveRuntimeBadges(input: {
|
|
|
33
33
|
// other than where this session currently asks to run.
|
|
34
34
|
const engineMismatch = input.actualEngine && input.actualEngine !== requestedEngine ? requestedEngine : undefined;
|
|
35
35
|
const engineIsNative = engine === 'claude-code' || engine === 'cursor';
|
|
36
|
-
//
|
|
36
|
+
// "The pair, or neither" is right for the ENGINE, not for the provider: a `provider/` prefix on the
|
|
37
|
+
// recorded model is direct evidence of what actually ran and was billed, and needs no engine to read.
|
|
38
|
+
// Only a BARE recorded id is unreadable alone (it belongs to whichever engine recorded it), so only
|
|
39
|
+
// that one is dropped. Sessions written before lastEngine existed carry a prefixed model and nothing
|
|
40
|
+
// else — dropping it made the UI report the requested provider, the very claim this must never make.
|
|
41
|
+
const recordedModel = input.actualEngine || input.actualModel?.includes('/') ? input.actualModel : undefined;
|
|
37
42
|
const rawModel =
|
|
38
|
-
|
|
39
|
-
input.requestedModel ||
|
|
40
|
-
(engine === 'cursor' ? 'cursor/composer-2.5' : 'sonnet-4-6');
|
|
43
|
+
recordedModel || input.requestedModel || (engine === 'cursor' ? 'cursor/composer-2.5' : 'sonnet-4-6');
|
|
41
44
|
// Provider = the model's prefix; a bare id belongs to the engine that ran it (claude-code ⇒ anthropic,
|
|
42
45
|
// an add-on engine ⇒ that engine's own provider) — never assume anthropic just because a prefix is absent.
|
|
43
46
|
const billingProvider = rawModel.includes('/') ? rawModel.split('/')[0] : engine === 'claude-code' ? 'anthropic' : engine;
|