shraga 0.1.95 → 0.1.96
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/defaults/skills/platform.md +1 -1
- package/dist/client/assets/{index-D2xviJL0.js → index-519evGGj.js} +1 -1
- package/dist/client/index.html +1 -1
- package/package.json +1 -1
- package/src/client/components/ConfigPanel.tsx +2 -1
- package/src/server/engine/claude-code.ts +2 -1
- package/src/server/model-aliases.ts +2 -1
|
@@ -30,7 +30,7 @@ Users can prefix any message with `[directives]` to override settings. Parsed se
|
|
|
30
30
|
|
|
31
31
|
| Position | What | Examples |
|
|
32
32
|
|----------|------|----------|
|
|
33
|
-
| 1st | Model alias | `fable`, `opus`, `sonnet`, `haiku`, `fable-5`, `opus-5`, `opus-4-8`, `opus-4-7` |
|
|
33
|
+
| 1st | Model alias | `fable`, `opus`, `sonnet`, `haiku`, `fable-5-1`, `fable-5`, `opus-5`, `opus-4-8`, `opus-4-7` |
|
|
34
34
|
| 2nd | Max turns (integer) | `5`, `20`, `100` |
|
|
35
35
|
|
|
36
36
|
### Named directives
|
|
@@ -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 xAe(e,t){if(e){if(typeof e=="string")return G2(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)?G2(e,t):void 0}}function G2(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 wAe(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 EAe(e){if(Array.isArray(e))return e}var SAe=()=>(vbe(),null);function uv(e){if(typeof e=="number")return e;if(typeof e=="string"){var t=parseFloat(e);if(!Number.isNaN(t))return t}return 0}var _Ae=y.forwardRef((e,t)=>{var n,r,i=y.useRef(null),a=y.useState({containerWidth:uv((n=e.style)===null||n===void 0?void 0:n.width),containerHeight:uv((r=e.style)===null||r===void 0?void 0:r.height)}),s=cv(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,T=k.width,C=k.height;f(T,C)}},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(mh,{width:c.containerWidth,height:c.containerHeight}),y.createElement("div",ws({ref:h},e)))}),AAe=y.forwardRef((e,t)=>{var n=e.width,r=e.height,i=y.useState({containerWidth:uv(n),containerHeight:uv(r)}),a=cv(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(mh,{width:s.containerWidth,height:s.containerHeight}),y.createElement("div",ws({ref:f},e)))}),kAe=y.forwardRef((e,t)=>{var n=e.width,r=e.height;return y.createElement(y.Fragment,null,y.createElement(mh,{width:n,height:r}),y.createElement("div",ws({ref:t},e)))}),OAe=y.forwardRef((e,t)=>{var n=e.width,r=e.height;return typeof n=="string"||typeof r=="string"?y.createElement(AAe,ws({},e,{ref:t})):typeof n=="number"&&typeof r=="number"?y.createElement(kAe,ws({},e,{width:n,height:r,ref:t})):y.createElement(y.Fragment,null,y.createElement(mh,{width:n,height:r}),y.createElement("div",ws({ref:t},e)))});function CAe(e){return e?_Ae:OAe}var TAe=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,T=k===void 0?!0:k,C=y.useRef(null),N=Dt(),P=y.useState(null),D=cv(P,2),L=D[0],R=D[1],F=y.useState(null),I=cv(F,2),q=I[0],G=I[1],K=pAe(),z=CS(),V=(z==null?void 0:z.width)>0?z.width:_,H=(z==null?void 0:z.height)>0?z.height:i,Y=y.useCallback(_e=>{K(_e),typeof t=="function"&&t(_e),R(_e),G(_e),_e!=null&&(C.current=_e)},[K,t,R,G]),j=y.useCallback(_e=>{N(f6(_e)),N(pi({handler:a,reactEvent:_e}))},[N,a]),U=y.useCallback(_e=>{N(F1(_e)),N(pi({handler:f,reactEvent:_e}))},[N,f]),Z=y.useCallback(_e=>{N(F4()),N(pi({handler:h,reactEvent:_e}))},[N,h]),B=y.useCallback(_e=>{N(F1(_e)),N(pi({handler:p,reactEvent:_e}))},[N,p]),fe=y.useCallback(()=>{N(v6())},[N]),be=y.useCallback(()=>{N(y6())},[N]),ge=y.useCallback(_e=>{N(g6(_e.key))},[N]),Ie=y.useCallback(_e=>{N(pi({handler:s,reactEvent:_e}))},[N,s]),We=y.useCallback(_e=>{N(pi({handler:c,reactEvent:_e}))},[N,c]),de=y.useCallback(_e=>{N(pi({handler:u,reactEvent:_e}))},[N,u]),ke=y.useCallback(_e=>{N(pi({handler:m,reactEvent:_e}))},[N,m]),we=y.useCallback(_e=>{N(pi({handler:b,reactEvent:_e}))},[N,b]),ue=y.useCallback(_e=>{T&&N(w6(_e)),N(pi({handler:x,reactEvent:_e}))},[N,T,x]),ht=y.useCallback(_e=>{N(pi({handler:v,reactEvent:_e}))},[N,v]),qe=CAe(O);return y.createElement(uU.Provider,{value:L},y.createElement(d$.Provider,{value:q},y.createElement(qe,{width:V??(S==null?void 0:S.width),height:H??(S==null?void 0:S.height),className:vt("recharts-wrapper",r),style:mAe({position:"relative",cursor:"default",width:V,height:H},S),onClick:j,onContextMenu:Ie,onDoubleClick:We,onFocus:fe,onBlur:be,onKeyDown:ge,onMouseDown:de,onMouseEnter:U,onMouseLeave:Z,onMouseMove:B,onMouseUp:ke,onTouchEnd:ht,onTouchMove:ue,onTouchStart:we,ref:Y},y.createElement(SAe,null),n)))}),NAe=["width","height","responsive","children","className","style","compact","title","desc"];function MAe(e,t){if(e==null)return{};var n,r,i=IAe(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 IAe(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 C6=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=MAe(e,NAe),m=Zr(p);return u?y.createElement(y.Fragment,null,y.createElement(mh,{width:n,height:r}),y.createElement(H2,{otherAttributes:m,title:f,desc:h},a)):y.createElement(TAe,{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(H2,{otherAttributes:m,title:f,desc:h,ref:t},y.createElement(A1e,null,a)))});function H1(){return H1=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},H1.apply(null,arguments)}function V2(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 RAe(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?V2(Object(n),!0).forEach(function(r){PAe(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):V2(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function PAe(e,t,n){return(t=DAe(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function DAe(e){var t=jAe(e,"string");return typeof t=="symbol"?t:t+""}function jAe(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 LAe={top:5,right:5,bottom:5,left:5},zAe=RAe({accessibilityLayer:!0,barCategoryGap:"10%",barGap:4,layout:"horizontal",margin:LAe,responsive:!1,reverseStackOrder:!1,stackOffset:"none",syncMethod:"index"},bA),T6=y.forwardRef(function(t,n){var r,i=Pn(t.categoricalChartProps,zAe),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(_6,{preloadedState:{options:h},reduxStoreName:(r=f.id)!==null&&r!==void 0?r:a},y.createElement(HU,{chartData:f.data}),y.createElement(A6,{layout:i.layout,margin:i.margin}),y.createElement(O6,{throttleDelay:i.throttleDelay,throttledEvents:i.throttledEvents}),y.createElement(k6,{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(C6,H1({},i,{ref:n})))}),$Ae=["axis"],BAe=y.forwardRef((e,t)=>y.createElement(T6,{chartName:"LineChart",defaultTooltipEventType:"axis",validateTooltipEventTypes:$Ae,tooltipPayloadSearcher:K_,categoricalChartProps:e,ref:t})),UAe=["axis","item"],FAe=y.forwardRef((e,t)=>y.createElement(T6,{chartName:"BarChart",defaultTooltipEventType:"axis",validateTooltipEventTypes:UAe,tooltipPayloadSearcher:K_,categoricalChartProps:e,ref:t}));function HAe(e){var t=Dt();return y.useEffect(()=>{t(V_e(e))},[t,e]),null}var KAe=["layout"];function K1(){return K1=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},K1.apply(null,arguments)}function qAe(e,t){if(e==null)return{};var n,r,i=GAe(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 GAe(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 W2(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 VAe(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?W2(Object(n),!0).forEach(function(r){WAe(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):W2(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function WAe(e,t,n){return(t=YAe(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function YAe(e){var t=XAe(e,"string");return typeof t=="symbol"?t:t+""}function XAe(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 ZAe={top:5,right:5,bottom:5,left:5},N6=VAe({accessibilityLayer:!0,stackOffset:"none",barCategoryGap:"10%",barGap:4,margin:ZAe,reverseStackOrder:!1,syncMethod:"index",layout:"radial",responsive:!1,cx:"50%",cy:"50%",innerRadius:0,outerRadius:"80%"},bA),QAe=y.forwardRef(function(t,n){var r,i=Pn(t.categoricalChartProps,N6),a=i.layout,s=qAe(i,KAe),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(_6,{preloadedState:{options:p},reduxStoreName:(r=i.id)!==null&&r!==void 0?r:c},y.createElement(HU,{chartData:i.data}),y.createElement(A6,{layout:a,margin:i.margin}),y.createElement(O6,{throttleDelay:i.throttleDelay,throttledEvents:i.throttledEvents}),y.createElement(k6,{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(HAe,{cx:i.cx,cy:i.cy,startAngle:i.startAngle,endAngle:i.endAngle,innerRadius:i.innerRadius,outerRadius:i.outerRadius}),y.createElement(C6,K1({},s,{ref:n})))});function Y2(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 X2(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?Y2(Object(n),!0).forEach(function(r){JAe(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Y2(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function JAe(e,t,n){return(t=eke(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function eke(e){var t=tke(e,"string");return typeof t=="symbol"?t:t+""}function tke(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 nke=["item"],rke=X2(X2({},N6),{},{layout:"centric",startAngle:0,endAngle:360}),ike=y.forwardRef((e,t)=>{var n=Pn(e,rke);return y.createElement(QAe,{chartName:"PieChart",defaultTooltipEventType:"item",validateTooltipEventTypes:nke,tooltipPayloadSearcher:K_,categoricalChartProps:n,ref:t})});const Xc=["#6366f1","#f59e0b","#10b981","#ef4444","#8b5cf6","#ec4899","#14b8a6","#f97316"];function ake(e){const t=e.trim();if(!t.startsWith("{")&&!t.startsWith("["))return null;try{return JSON.parse(t)}catch{return null}}function oke(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 ske(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;const t=e;return"file"in t&&"sizeBytes"in t}function lke(e){if(ske(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=oke(e);if(t)return t}return null}function cke(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 uke(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 fke({data:e}){const{rows:t,labelKey:n,numericKeys:r,chartType:i}=y.useMemo(()=>{const a=lke(e);if(!a||a.length===0)return{rows:null,labelKey:"",numericKeys:[],chartType:"table"};const{labelKey:s,numericKeys:c}=uke(a),u=cke(a,s,c);return{rows:a,labelKey:s,numericKeys:c,chartType:u}},[e]);return t?i==="table"?E.jsx(Z2,{rows:t}):E.jsxs("div",{className:"space-y-2",children:[E.jsx("div",{className:"h-64 w-full",children:E.jsx(Eue,{width:"100%",height:"100%",children:i==="pie"?E.jsxs(ike,{children:[E.jsx(BU,{data:t,dataKey:r[0],nameKey:n,cx:"50%",cy:"50%",outerRadius:80,label:!0,children:t.map((a,s)=>E.jsx(Mh,{fill:Xc[s%Xc.length]},s))}),E.jsx(Wx,{}),E.jsx(Gm,{})]}):i==="line"?E.jsxs(BAe,{data:t,children:[E.jsx(R1,{strokeDasharray:"3 3",className:"opacity-30"}),E.jsx(z1,{dataKey:n,tick:{fontSize:11}}),E.jsx(U1,{tick:{fontSize:11}}),E.jsx(Wx,{}),r.length>1&&E.jsx(Gm,{}),r.map((a,s)=>E.jsx(i6,{type:"monotone",dataKey:a,stroke:Xc[s%Xc.length],strokeWidth:2,dot:!1},a))]}):E.jsxs(FAe,{data:t,children:[E.jsx(R1,{strokeDasharray:"3 3",className:"opacity-30"}),E.jsx(z1,{dataKey:n,tick:{fontSize:11}}),E.jsx(U1,{tick:{fontSize:11}}),E.jsx(Wx,{}),r.length>1&&E.jsx(Gm,{}),r.map((a,s)=>E.jsx(c6,{dataKey:a,fill:Xc[s%Xc.length],radius:[3,3,0,0]},a))]})})}),E.jsx(Z2,{rows:t})]}):E.jsx("pre",{className:"text-xs whitespace-pre-wrap break-words",children:JSON.stringify(e,null,2)})}function Z2({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 q1=/^\/uploads\//;function xA({src:e,alt:t,className:n,onClick:r}){const{getToken:i}=uE(),[a,s]=y.useState(q1.test(e)?null:e);return y.useEffect(()=>{if(!q1.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 dke({src:e,name:t,className:n}){const{getToken:r}=uE(),i=async a=>{if(q1.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(hE,{className:"w-4 h-4 shrink-0"}),E.jsx("span",{className:"truncate max-w-[200px]",children:t})]})}const G1=1,M6=10,gd={scale:1,tx:0,ty:0},Q2=e=>Math.min(M6,Math.max(G1,e));function hke({src:e,alt:t=""}){const n=y.useRef(null),r=y.useRef(null),[i,a]=y.useState(gd),[s,c]=y.useState(!1),u=(_,O)=>{var T;const k=(T=n.current)==null?void 0:T.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(T=>{const C=Q2(_);if(C===T.scale)return T;if(C<=G1)return gd;const N=C/T.scale;return{scale:C,tx:O-N*(O-T.tx),ty:k-N*(k-T.ty)}})},[]),h=_=>{_.preventDefault();const{cx:O,cy:k}=u(_.clientX,_.clientY),T=_.deltaY<0?1.15:1/1.15;a(C=>{const N=Q2(C.scale*T);if(N===C.scale)return C;if(N<=G1)return gd;const P=N/C.scale;return{scale:N,tx:O-P*(O-C.tx),ty:k-P*(k-C.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(gd):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(vG,{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>=M6,children:E.jsx(gG,{className:"w-4 h-4"})}),E.jsx("button",{type:"button",onClick:()=>a(gd),title:"Reset",className:"p-1.5 rounded-full hover:bg-muted transition-colors disabled:opacity-40",disabled:!S,children:E.jsx(pE,{className:"w-4 h-4"})})]})]})}const pke=new Set(["p","li","h1","h2","h3","h4","h5","h6","blockquote","td","th"]),mke=()=>e=>{const t=n=>{for(const r of n.children??[])r.type==="element"&&(pke.has(r.tagName)&&(r.properties??(r.properties={}),r.properties.dir="auto"),t(r))};t(e)};var vD,yD;const gke=typeof window<"u"&&!!((yD=(vD=window.webkit)==null?void 0:vD.messageHandlers)!=null&&yD.appwrap);function vke({text:e,onImageClick:t}){const n=e.replace(/\[Image #\d+\]\s*/g,"").trim();return gke?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(kL,{remarkPlugins:[XL],rehypePlugins:[yz,mke],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(Rke,{...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(xA,{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 J2(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 eD="shraga:showDetails",yke=150;function bke({messages:e,busy:t,connectionStatus:n,onPermissionRespond:r,onQuestionRespond:i,onReplay:a,onEdit:s,onFork:c,multiParticipant:u,statusItems:f}){var Y;const h=Sa(),p=y.useRef(null),m=y.useRef(null),v=y.useRef(!0),[x,b]=y.useState(()=>localStorage.getItem(eD)==="true"),[S,_]=y.useState(null),O=y.useRef({onPermissionRespond:r,onQuestionRespond:i,onReplay:a,onEdit:s,onFork:c});O.current={onPermissionRespond:r,onQuestionRespond:i,onReplay:a,onEdit:s,onFork:c};const k=y.useCallback((j,U,Z)=>{var B,fe;return(fe=(B=O.current).onPermissionRespond)==null?void 0:fe.call(B,j,U,Z)},[]),T=y.useCallback((j,U)=>{var Z,B;return(B=(Z=O.current).onQuestionRespond)==null?void 0:B.call(Z,j,U)},[]),C=y.useCallback((j,U,Z)=>{var B,fe;return(fe=(B=O.current).onReplay)==null?void 0:fe.call(B,j,U,Z)},[]),N=y.useCallback((j,U,Z)=>{var B,fe;return(fe=(B=O.current).onEdit)==null?void 0:fe.call(B,j,U,Z)},[]),P=y.useCallback(j=>{var U,Z;return(Z=(U=O.current).onFork)==null?void 0:Z.call(U,j)},[]),D=()=>{const j=m.current;j&&(v.current=j.scrollHeight-j.scrollTop-j.clientHeight<80)},L=y.useRef(new Map),R=y.useRef(new WeakSet),F=y.useRef(0),I=y.useMemo(()=>(kke(L.current,R.current,e)&&F.current++,F.current),[e]),q=L.current,[G,K]=y.useState(!1),z=G?0:Math.max(0,e.length-yke),V=z>0?e.slice(z):e;if(y.useEffect(()=>{var j;v.current&&((j=p.current)==null||j.scrollIntoView({behavior:t?"auto":"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(uu,{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 H=()=>{b(j=>(localStorage.setItem(eD,String(!j)),!j))};return E.jsxs("div",{ref:m,onScroll:D,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:H,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(Xq,{className:"w-3.5 h-3.5"}):E.jsx(Yq,{className:"w-3.5 h-3.5"}),"Details"]})}),z>0&&E.jsx("div",{className:"flex justify-center pb-2",children:E.jsxs("button",{onClick:()=>K(!0),className:"text-xs px-3 py-1 rounded-full border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors",children:["Show ",z," earlier message",z===1?"":"s"]})}),V.map((j,U)=>{const Z=z+U;return E.jsx(xke,{message:j,messageIndex:Z,isLast:Z===e.length-1,showDetails:x,onPermissionRespond:k,onQuestionRespond:T,onReplay:C,onEdit:N,onFork:P,onImageClick:_,busy:t&&Z===e.length-1,screenMap:q,screenVersion:I,multiParticipant:u},j.id)}),t&&((Y=e[e.length-1])==null?void 0:Y.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(uu,{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(uu,{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:j=>{j||_(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(hke,{src:S})})})]})}const xke=y.memo(function({message:t,messageIndex:n,isLast:r,showDetails:i,onPermissionRespond:a,onQuestionRespond:s,onReplay:c,onEdit:u,onFork:f,onImageClick:h,busy:p,screenMap:m,multiParticipant:v}){var F;const x=t.blocks.find(I=>I.type==="compact_marker");if(x&&x.type==="compact_marker")return E.jsx(wke,{summary:x.summary,compactedCount:x.compactedCount});const b=t.role==="user",S=b?((F=t.blocks.find(I=>I.type==="text"))==null?void 0:F.text)??"":"",_=b?t.blocks.filter(I=>I.type==="image"||I.type==="file").map(I=>I.type==="image"?{url:I.src,name:I.src.split("/").pop()??"image",mimeType:"image/png",path:I.src}:{url:I.src,name:I.name,mimeType:I.mimeType,path:I.src}):void 0,[O,k]=y.useState(!1),[T,C]=y.useState(""),[N,P]=y.useState(!1),D=y.useRef(null),L=()=>{C(S),k(!0),setTimeout(()=>{const I=D.current;I&&(I.style.height="auto",I.style.height=I.scrollHeight+"px",I.focus(),I.setSelectionRange(I.value.length,I.value.length))},0)},R=()=>{const I=T.trim();I&&(k(!1),u==null||u(t.id,I,_!=null&&_.length?_:void 0))};return E.jsxs("div",{className:He("flex gap-3 py-4 group/row",b&&"flex-row-reverse"),onTouchStart:I=>{I.target.closest("button")||P(q=>!q)},children:[!b&&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(uu,{className:"w-4 h-4 text-primary"})}),b&&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(pG,{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:[v&&b&&t.senderName&&E.jsx("div",{className:"text-[11px] font-medium text-muted-foreground text-right px-1",children:t.senderName}),O?E.jsxs("div",{className:"inline-block text-left w-full",children:[E.jsx("textarea",{ref:D,value:T,onChange:I=>{C(I.target.value),I.target.style.height="auto",I.target.style.height=I.target.scrollHeight+"px"},onKeyDown:I=>{I.key==="Enter"&&!I.shiftKey&&(I.preventDefault(),R()),I.key==="Escape"&&k(!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:()=>k(!1),className:"p-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted transition-colors",title:"Cancel",children:E.jsx(Pl,{className:"w-3.5 h-3.5"})}),E.jsx("button",{onClick:R,className:"p-1 rounded-md text-primary hover:bg-primary/10 transition-colors",title:"Send",children:E.jsx(ig,{className:"w-3.5 h-3.5"})})]})]}):E.jsxs(E.Fragment,{children:[t.blocks.filter(I=>i?!0:I.type==="tool_use"&&I.tool==="AskUserQuestion"?t.blocks.some(q=>q.type==="tool_result"&&q.toolUseId===I.toolUseId):I.type!=="tool_use"&&I.type!=="tool_result"&&I.type!=="thinking").filter(I=>I.type!=="tool_result"?!0:!t.blocks.some(q=>q.type==="tool_use"&&q.toolUseId===I.toolUseId)).map((I,q,G)=>{const K=I.type==="tool_use"?t.blocks.find(z=>z.type==="tool_result"&&z.toolUseId===I.toolUseId):void 0;return E.jsx(Eke,{block:I,isUser:b,ts:t.ts,onPermissionRespond:a,onQuestionRespond:s,pairedResult:K,onImageClick:h,busy:p,screenMap:m},q)}),b&&S&&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:[t.ts&&E.jsx("span",{className:"text-[10px] text-muted-foreground/50 select-none mr-1",children:J2(t.ts)}),E.jsx("button",{onClick:()=>c==null?void 0:c(t.id,S,_!=null&&_.length?_:void 0),className:"p-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted transition-colors",title:"Replay",children:E.jsx(cG,{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(gE,{className:"w-3.5 h-3.5"})})]}),!b&&!(p&&r)&&E.jsxs("div",{className:He("flex gap-1 items-center transition-opacity",N?"opacity-100":"opacity-0 group-hover/row:opacity-100"),children:[t.ts&&E.jsx("span",{className:"text-[10px] text-muted-foreground/40 select-none mr-1",children:J2(t.ts)}),E.jsx("button",{onClick:()=>f==null?void 0:f(n),className:"p-1 rounded-md text-muted-foreground hover:text-foreground hover:bg-muted transition-colors",title:"Fork from here",children:E.jsx(_j,{className:"w-3.5 h-3.5"})})]})]})]})]})});function wke({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(mE,{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 Eke({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(xA,{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(dke,{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(_ke,{label:e.label,text:e.text}):e.type==="thinking"?E.jsx(Ake,{text:e.text}):e.type==="error"?E.jsx(Ske,{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(vke,{text:e.text,onImageClick:s})}):e.type==="tool_use"?e.tool==="AskUserQuestion"&&(a!=null&&a.output)?E.jsx(Cke,{input:e.input,result:a.output}):E.jsx(Tke,{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(Nke,{output:e.output}):e.type==="permission_request"?E.jsx(Mke,{id:e.id,tool:e.tool,input:e.input,onRespond:r}):e.type==="question_request"?E.jsx(Ike,{id:e.id,questions:e.questions,onRespond:i}):((h=f.extensionBlocks)==null?void 0:h.call(f,{block:e,onImageClick:s}))??null}function Ske({text:e,ts:t}){const n=jne(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 _ke({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(tG,{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 Ake({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(Gq,{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 kke(e,t,n){let r=!1;for(const i of n)for(const a of i.blocks)if(!(a.type!=="tool_result"||!a.output)&&!t.has(a)&&(t.add(a),!!a.output.includes('"screen"')))try{const s=JSON.parse(a.output);typeof(s==null?void 0:s.sessionId)=="string"&&Array.isArray(s==null?void 0:s.screen)&&(e.set(s.sessionId,s.screen),r=!0)}catch{}return r}function Oke(e){const t={},n=/"([^"]+)"="([^"]+)"/g;let r;for(;(r=n.exec(e))!==null;)t[r[1]]=r[2];return t}function Cke({input:e,result:t}){const n=e,r=(n==null?void 0:n.questions)??[],i=Oke(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(vE,{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 Tke({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?I6(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(rg,{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(mG,{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(Id,{className:"w-3 h-3 text-muted-foreground animate-spin shrink-0"}):E.jsx("span",{title:"Interrupted",children:E.jsx(rg,{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 I6(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 Nke({output:e}){const[t,n]=y.useState(!1),{trimmed:r,isError:i,chartData:a,isLong:s,preview:c}=y.useMemo(()=>{const m=e.trim().replace(/\[Image #\d+\]\s*/g,"").trim(),v=I6(m),x=/^(Error|ERROR)|"status"\s*:\s*[45]\d\d|ENOENT|EACCES|Permission denied|command not found|No such file/i.test(v);return{trimmed:v,isError:x,chartData:x?null:ake(v),isLong:v.length>200,preview:v.slice(0,120).replace(/\n/g," ")}},[e]);if(!r)return null;const u=i?rg:ha,f=i?"border-red-200 dark:border-red-900":"border-green-200 dark:border-green-900",h=i?"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",p=i?"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",f),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",h),children:[E.jsx(u,{className:He("w-3.5 h-3.5 shrink-0",p)}),E.jsx("span",{className:"text-muted-foreground truncate flex-1 min-w-0",children:s?c+"…":c}),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:a?E.jsx(fke,{data:a}):E.jsx("pre",{className:"overflow-auto max-h-96 text-xs whitespace-pre-wrap break-words",children:r})})]})}function Mke({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(vE,{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(BT,{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(BT,{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(rg,{className:"w-3.5 h-3.5"}),"Deny"]})]})]})}function Ike({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 T=S[O.question];T!=null&&(_[k]=new Set(Array.isArray(T)?T:[T]))}),_})}})},[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(vE,{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(T=>({...T,[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(ig,{className:"w-3.5 h-3.5"}),c?"Sent":"Submit"]}),E.jsxs("span",{className:"text-muted-foreground",children:[m,"/",t.length," answered"]})]})]})}function Rke({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(Pke,{getText:()=>{var r;return((r=n.current)==null?void 0:r.textContent)||""}})]})}function Pke({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(dE,{className:"w-3 h-3"})})}const R6=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 D;return(D=x.current)==null?void 0:D.focus()},setValue:D=>{n(D),p&&T()}}));const k=b?[...a.filter(D=>D.toLowerCase().includes(b.query.toLowerCase())).map(D=>({kind:"skill",value:D})),...b.kind==="mention"?s.filter(D=>D.toLowerCase().includes(b.query.toLowerCase())).map(D=>({kind:"workspace",value:D})):[]]:[];function T(){setTimeout(()=>{const D=x.current;D&&(D.style.height="auto",D.style.height=Math.min(D.scrollHeight,m)+"px")},0)}const C=D=>{if(!b)return;const L=b.kind==="command"?"/":"@",R=t.slice(0,b.start),F=t.slice(b.start+b.query.length+1),I=`${R}${L}${D} ${F}`;n(I),S(null),setTimeout(()=>{const q=x.current;if(!q)return;p&&(q.style.height="auto",q.style.height=Math.min(q.scrollHeight,m)+"px");const G=R.length+D.length+2;q.setSelectionRange(G,G),q.focus()},0)},N=D=>{if(b&&k.length>0){if(D.key==="ArrowDown"){D.preventDefault(),O(L=>(L+1)%k.length);return}if(D.key==="ArrowUp"){D.preventDefault(),O(L=>(L-1+k.length)%k.length);return}if(D.key==="Enter"||D.key==="Tab"){D.preventDefault(),C(k[_].value);return}if(D.key==="Escape"){S(null);return}}r==null||r(D)},P=D=>{const L=D.target.value;n(L);const R=D.target;p&&(R.style.height="auto",R.style.height=Math.min(R.scrollHeight,m)+"px");const F=R.selectionStart??L.length,I=L.slice(0,F),q=I.match(/(?:^|\n)\/([\w-]*)$/),G=I.match(/@([\w\-./]*)$/);q?(S({query:q[1],start:q.index+(I[q.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 D=()=>S(null);return b&&document.addEventListener("mousedown",D),()=>document.removeEventListener("mousedown",D)},[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((D,L)=>E.jsxs("button",{onMouseDown:R=>{R.preventDefault(),C(D.value)},className:`w-full text-left px-3 py-1.5 text-sm hover:bg-accent transition-colors flex items-center gap-2 ${L===_?"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":D.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"?"/":"@"}),D.value]})]},`${D.kind}:${D.value}`))}),E.jsx("textarea",{ref:x,value:t,onChange:P,onKeyDown:N,onPaste:i,placeholder:c,disabled:h,rows:f,dir:"auto",className:u})]})}),wA="shraga:draft:";function rw(e,t){const n=wA+(e??"new");t.trim()?localStorage.setItem(n,t):localStorage.removeItem(n)}function tD(e){return localStorage.getItem(wA+(e??"new"))??""}function nD(e){localStorage.removeItem(wA+(e??"new"))}const Dke=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 z,V;const b=Sa(),[S,_]=y.useState(()=>tD(m)),[O,k]=y.useState([]),[T,C]=y.useState(!1),N=y.useRef(null),P=y.useRef(null),D=y.useRef(m);y.useEffect(()=>{var j;if(D.current===m)return;const H=D.current;if(D.current=m,!m){nD(H),rw(void 0,S);return}rw(H,S);const Y=tD(m);_(Y),(j=P.current)==null||j.setValue(Y)},[m]);const L=y.useCallback(H=>{_(H),rw(D.current,H)},[]);y.useImperativeHandle(x,()=>({prefill(H){var Y,j;L(H),(Y=P.current)==null||Y.setValue(H),(j=P.current)==null||j.focus()},setText(H){var Y;L(H),(Y=P.current)==null||Y.setValue(H)},focus(){var H;(H=P.current)==null||H.focus()}}));const R=(H="send")=>{var j;const Y=S.trim();!Y&&O.length===0||(H==="steer"?n(Y):H==="queue"?r(Y):t(Y,O.length>0?O:void 0),_(""),nD(D.current),k([]),(j=P.current)==null||j.setValue(""))},F=typeof window<"u"&&((z=window.matchMedia)==null?void 0:z.call(window,"(pointer: coarse)").matches),I=H=>{if(H.key==="Enter"&&!H.shiftKey&&(!F||H.metaKey||H.ctrlKey)){H.preventDefault(),R(f?"steer":"send");return}if(H.key==="Tab"&&f&&S.trim()){H.preventDefault(),R("queue");return}},q=y.useCallback(async H=>{C(!0);try{const Y=await s(H);Y&&k(j=>[...j,Y])}finally{C(!1)}},[s]),G=y.useCallback(H=>{const Y=Array.from(H.clipboardData.items);for(const j of Y)if(j.type.startsWith("image/")||j.type==="application/pdf"){const U=j.getAsFile();U&&q(U)}},[q]),K=H=>{var j;const Y=(j=H.target.files)==null?void 0:j[0];Y&&(q(Y),H.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||T)&&E.jsxs("div",{className:"flex gap-2 mb-2 flex-wrap items-center",children:[O.map((H,Y)=>E.jsxs("div",{className:"relative group",children:[H.mimeType.startsWith("image/")?E.jsx(xA,{src:H.url,alt:H.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(hE,{className:"w-4 h-4 shrink-0"}),E.jsx("span",{className:"truncate max-w-[120px]",children:H.name})]}),E.jsx("button",{onClick:()=>k(j=>j.filter((U,Z)=>Z!==Y)),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(Pl,{className:"w-3 h-3"})})]},Y)),T&&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 H;return(H=N.current)==null?void 0:H.click()},disabled:u,title:"Attach file or image",children:E.jsx(oG,{className:"w-4 h-4"})}),E.jsx("input",{ref:N,type:"file",className:"hidden",onChange:K}),E.jsx(R6,{ref:P,value:S,onChange:L,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]"}),(V=b.inputAdornments)==null?void 0:V.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:()=>R("steer"),title:"Steer (inject into current turn)",children:E.jsx(ig,{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(Oj,{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:()=>R(),disabled:u||T||!S.trim()&&O.length===0,children:E.jsx(ig,{className:"w-4 h-4"})})]}),a.length>0&&E.jsx("div",{className:"flex gap-1.5 flex-wrap mt-2",children:a.map((H,Y)=>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:H}),E.jsx("button",{onClick:()=>i(Y),className:"hover:text-blue-900 dark:hover:text-blue-100",children:E.jsx(Pl,{className:"w-3 h-3"})})]},Y))}),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"})]})})}),jke={"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 Lke({artifacts:e,selectedId:t,sessionId:n,getToken:r,onSelect:i,onClose:a}){var P;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(D=>D.id===t),S=y.useCallback(()=>{if(!x.current||!b)return;const{clientWidth:D,clientHeight:L}=x.current,R=32,F=D-R,I=L-R,[q,G]=b.dimensions;v(Math.min(F/q,I/G,1))},[b]);y.useEffect(()=>{let D=!0;return r().then(L=>fetch("/api/features",{headers:L?{Authorization:`Bearer ${L}`}:{}})).then(L=>L.json()).then(L=>{D&&p(!!L.artifactPngExport)}).catch(L=>console.error("[artifact] features fetch failed:",L)),()=>{D=!1}},[r]),y.useEffect(()=>{S();const D=x.current;if(!D)return;const L=new ResizeObserver(S);return L.observe(D),()=>L.disconnect()},[S]);const _=async()=>{if(b){f(!0);try{const D=await r(),L=await fetch(`/api/artifacts/${n}/${b.id}/export`,{method:"POST",headers:{"Content-Type":"application/json",...D?{Authorization:`Bearer ${D}`}:{}},body:JSON.stringify({dimensions:b.dimensions})});if(!L.ok)throw new Error(await L.text());const R=await L.blob(),F=URL.createObjectURL(R),I=document.createElement("a");I.href=F,I.download=`${b.title.replace(/\s+/g,"-").toLowerCase()}.png`,I.click(),URL.revokeObjectURL(F)}catch(D){console.error("[artifact] export failed:",D)}finally{f(!1)}}},O=b?(P=Object.entries(jke).find(([,D])=>D[0]===b.dimensions[0]&&D[1]===b.dimensions[1]))==null?void 0:P[0]:null,[k,T]=(b==null?void 0:b.dimensions)??[0,0],C=k*m,N=T*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(Ej,{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:D=>i(D.target.value),children:e.map(D=>E.jsx("option",{value:D.id,children:D.title},D.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}×${T}`,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(eG,{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(mE,{className:"w-3.5 h-3.5"}):E.jsx(pE,{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(Pl,{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:C,height:N},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:T,transform:`scale(${m})`},title:b.title})}):E.jsx("p",{className:"text-sm text-muted-foreground",children:"No artifact selected"})})]})}const Ey=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}));Ey.displayName="Textarea";const V1={fable:"claude-fable-5","fable-5":"claude-fable-5",opus:"claude-opus-5","opus-5":"claude-opus-5","opus-4-8":"claude-opus-4-8","opus-4-7":"claude-opus-4-7","opus-4-6":"claude-opus-4-6",sonnet:"claude-sonnet-5","sonnet-5":"claude-sonnet-5","sonnet-4-6":"claude-sonnet-4-6",haiku:"claude-haiku-4-5-20251001"},zke=/^\s*\[([^\]]*)\]\s*([\s\S]*)/,P6=["model","turns","thinking","think","effort","engine"],W1=e=>/^[a-z0-9._-]+\/[a-z0-9./_-]+$/.test(e);let Ml=null;function $ke(e){Ml=e}function Y1(e){const t=e.trim().toLowerCase();return V1[t]?{model:V1[t]}:(Ml==null?void 0:Ml(t))??null}function D6(e,t){const n=Y1(t);return n?(e.model=n.model,n.engine&&!e.engine&&(e.engine=n.engine),!0):!1}function Bke(e){const t=e.split(",").map(n=>n.trim()).filter(Boolean);return t.length?t.every(n=>{const r=n.indexOf(":");if(r!==-1)return P6.includes(n.slice(0,r).trim().toLowerCase());const i=n.toLowerCase();return!!V1[i]||!!(Ml!=null&&Ml(i))||/^\d+$/.test(i)||["think","adaptive","nothink","nothinking"].includes(i)}):!1}function EA(e,t){let n=e;const r=[];for(;;){const i=n.match(zke);if(!i)break;const a=i[1].trim();if((r.length||t!=null&&t.strict)&&a&&!Bke(a))break;r.push(a),n=i[2]}return{groups:r,body:n}}function Uke(e){const{groups:t,body:n}=EA(e);if(!t.length)return{prompt:e,directives:{}};const r=t.filter(Boolean).join(","),i=n.trim();if(!r)return{prompt:i,directives:{}};const a={};let s=0,c;const u=r.split(","),f=u.some(h=>{const p=h.indexOf(":");return p!==-1&&P6.includes(h.slice(0,p).trim().toLowerCase())});for(const h of u){const p=h.trim();if(!p)continue;const m=p.indexOf(":");if(m!==-1){const v=p.slice(0,m).trim().toLowerCase(),x=p.slice(m+1).trim().toLowerCase();c=Fke(a,v,x)??c}else{const v=p.toLowerCase();s===0&&D6(a,v)||(s<=1&&/^\d+$/.test(v)?a.turns=parseInt(v,10):["think","adaptive"].includes(v)?a.thinking="adaptive":["nothink","nothinking"].includes(v)?a.thinking="disabled":s===0&&(f&&!W1(v)&&(c??(c=p)),console.warn(W1(v)?`[directives] Provider-qualified model needs key form: "[model:${p}]"`:`[directives] Unknown model alias: "${p}"`))),s++}}return{prompt:i,directives:a,unresolvedModel:c}}function Fke(e,t,n){switch(t){case"model":if(D6(e,n))break;if(W1(n)){e.model=n;break}return n;case"turns":/^\d+$/.test(n)?e.turns=parseInt(n,10):console.warn(`[directives] Invalid turns value: "${n}"`);break;case"thinking":case"think":["adaptive","enabled","disabled"].includes(n)?e.thinking=n:console.warn(`[directives] Invalid thinking value: "${n}"`);break;case"effort":["low","medium","high","max"].includes(n)?e.effort=n:console.warn(`[directives] Invalid effort value: "${n}"`);break;case"engine":e.engine=n;break;default:console.warn(`[directives] Unknown directive key: "${t}"`)}}function Hke(e){return t=>{const n=t.toLowerCase(),r=[];for(const{name:i,models:a}of e())for(const s of a){if(!s.value)continue;const c=s.value.toLowerCase();if(c===n)return{model:s.value,engine:i};c.slice(c.lastIndexOf("/")+1)===n&&r.push({model:s.value,engine:i})}return r.length===1?r[0]:(r.length>1&&console.warn(`[directives] Ambiguous model "${t}" (${r.map(i=>`${i.engine}:${i.model}`).join(", ")}) — use the full id`),null)}}let Ym=[];$ke(Hke(()=>Ym));function j6(e,t=!0){const[n,r]=y.useState(Ym),[i,a]=y.useState(!1);return y.useEffect(()=>{if(!t)return;let s=!0;return e().then(c=>{!c||!s||fetch("/api/engines",{headers:{Authorization:`Bearer ${c}`}}).then(u=>u.json()).then(u=>{s&&(Ym=u.engines??[],r(Ym),a(u.multiEngine??!1))}).catch(u=>console.warn("[engines] load failed",u))}),()=>{s=!1}},[t,e]),{engines:n,multiEngine:i}}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"}],qke=[{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 Gke({getToken:e,onSaved:t,trigger:n,sessionId:r,sessionDirectives:i,onDirectivesSaved:a}){var L;const s=Sa(),[c,u]=y.useState({}),[f,h]=y.useState(!1),[p,m]=y.useState(!1),{engines:v,multiEngine:x}=j6(e,f),b=y.useRef({}),[S,_]=y.useState(!1);y.useEffect(()=>{f&&(_(!1),e().then(R=>{R&&fetch("/api/config",{headers:{Authorization:`Bearer ${R}`}}).then(F=>F.json()).then(F=>{b.current=F;const I=r?i:void 0;u({...F,...(I==null?void 0:I.engine)!==void 0?{engine:I.engine}:{},...(I==null?void 0:I.model)!==void 0?{model:I.model}:{},...(I==null?void 0:I.turns)!==void 0?{maxTurns:I.turns}:{},...(I==null?void 0:I.thinking)!==void 0?{thinking:I.thinking}:{}})}).catch(()=>{})}))},[f,e,r,i]);const O=async()=>{m(!0);const F={Authorization:`Bearer ${await e()??""}`,"Content-Type":"application/json"};try{if(r){const I=S?{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:F,body:JSON.stringify(I)}).then(K=>K.json()).catch(K=>(console.warn("[config] directives save failed",K),null));q!=null&&q.directives&&(a==null||a(q.directives));const G=S?c:{...c,engine:b.current.engine,model:b.current.model,maxTurns:b.current.maxTurns,thinking:b.current.thinking};await fetch("/api/config",{method:"PUT",headers:F,body:JSON.stringify(G)}),t==null||t(G)}else await fetch("/api/config",{method:"PUT",headers:F,body:JSON.stringify(c)}),t==null||t(c);h(!1)}finally{m(!1)}},k=c.engine||"claude-code",T=v.find(R=>R.name===k),C=(T==null?void 0:T.models)??Kke;y.useEffect(()=>{!T||!C.length||C.some(R=>(R.value||"")===(c.model??""))||u(R=>({...R,model:C[0].value||void 0}))},[T,C,c.model]);const P=C.some(R=>R.provider)?Array.from(C.reduce((R,F)=>{const I=F.provider||"default";return R.has(I)||R.set(I,[]),R.get(I).push(F),R},new Map)):null,D="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(lh,{asChild:!0,children:n||E.jsx(Re,{variant:"ghost",size:"icon",title:"Agent Config",children:E.jsx(fG,{className:"w-4 h-4"})})}),E.jsxs(uo,{className:"max-w-lg",children:[E.jsx(jl,{children:E.jsx(Ss,{children:"Agent Configuration"})}),E.jsxs(Kz,{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:S?"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:S,onChange:R=>_(R.target.checked)}),E.jsx("span",{children:"Apply globally — also the default for Slack, email & scheduled runs"})]})]}),x&&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:R=>{const F=R.target.value||void 0;u(I=>({...I,engine:F,model:void 0}))},className:D,children:v.map(R=>E.jsx("option",{value:R.name,children:R.name==="claude-code"?"Claude Code (default)":R.name},R.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:R=>u(F=>({...F,model:R.target.value||void 0})),className:D,children:P?P.map(([R,F])=>E.jsx("optgroup",{label:R.charAt(0).toUpperCase()+R.slice(1),children:F.map(I=>E.jsx("option",{value:I.value,children:I.label},I.value))},R)):C.map(R=>E.jsx("option",{value:R.value,children:R.label},R.value))})]}),(L=s.settingsSections)==null?void 0:L.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:R=>u(F=>({...F,permissionMode:R.target.value})),className:D,children:qke.map(R=>E.jsx("option",{value:R.value,children:R.label},R.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:R=>u(F=>({...F,maxTurns:Number(R.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:R=>u(F=>({...F,thinking:R.target.value||void 0})),className:D,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:R=>u(F=>({...F,effort:R.target.value||void 0})),className:D,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:R=>u(F=>({...F,allowedTools:R.target.value.split(",").map(I=>I.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(R=>({...R,skillDiscovery:R.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(Ey,{placeholder:"Additional instructions appended to Claude's system prompt…",value:c.systemPrompt??"",onChange:R=>u(F=>({...F,systemPrompt:R.target.value||void 0})),rows:4})]})]}),E.jsx(qz,{children:E.jsx(Re,{onClick:O,disabled:p,children:p?"Saving…":"Save Configuration"})})]})]})}function Vke(e){const t=e.requestedEngine||"claude-code",n=e.actualEngine?"ran":e.actualModel?"ran-model":"pending",r=n==="ran"?e.actualEngine:n==="pending"?t:void 0,i=e.actualModel||e.requestedModel||(t==="cursor"?"cursor/composer-2.5":"sonnet-4-6"),a=n==="ran"&&r!==t?t:void 0,s=r==="claude-code"||r==="cursor",c=i.includes("/")?i.split("/")[0]:r==="claude-code"?"anthropic":r;return{provenance:n,engine:r,engineIsNative:s,engineMismatch:a,rawModel:i,billingProvider:c}}function Wke({sessionId:e,config:t,sessionDirectives:n,actualModel:r,actualEngine:i,scheduleId:a,onScheduleClick:s}){const[c,u]=y.useState(!1),{provenance:f,engine:h,engineIsNative:p,engineMismatch:m,rawModel:v,billingProvider:x}=Vke({requestedEngine:(n==null?void 0:n.engine)||t.engine,requestedModel:(n==null?void 0:n.model)||t.model,actualEngine:i,actualModel:r}),b=v.replace("claude-",""),S=h&&!p?`${h} · ${b}`:b,_=f==="pending",O=_?" border border-dashed border-current/40 opacity-80":"",k=_?"Nothing has run in this conversation yet — this is what the next turn is set to use.":f==="ran-model"?"Model recorded from the last turn. The engine that ran it was not recorded (this conversation predates engine tracking), so it is not named here.":"Engine and model that actually ran the last turn.",T=h==="claude-code"&&t.claudeAuthSource==="subscription",C=x?T?"sub":x==="cursor"?"plan":"metered":"unknown",N=C==="unknown"?"bg-muted text-muted-foreground ring-border":C==="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":C==="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",P=C==="unknown"?"The engine that ran this turn was not recorded and the model id carries no provider prefix — the billed provider cannot be named from what was stored.":C==="sub"?"Claude.ai subscription (OAuth login) — no API key in use":C==="plan"?`Runs on your ${x} API key — usage may draw on your ${x} plan/subscription`:`Runs on your ${x} API key — metered per-token billing`,D=t.permissionMode||"acceptEdits",L=D==="bypassPermissions"?"bypass":D==="plan"?"plan":D==="default"?"prompt":"edits",R=(n==null?void 0:n.thinking)||t.thinking,F=()=>{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",{title:k,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${O}`,children:_?`→ ${S}`:S}),E.jsx("span",{title:_?`${k} ${P}`:P,className:`inline-flex items-center rounded-md px-1.5 py-0.5 text-[10px] font-medium ring-1 ring-inset ${N}${O}`,children:C==="unknown"?"API·?":T?"sub":`API·${x}`}),m&&E.jsxs("span",{title:`This session requests the "${m}" engine, but the last turn actually ran on "${h}" — so the chips above report ${h}, 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:["≠ ",m]}),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:L}),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"]}),R&&R!=="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:F,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 D=()=>S(null);return b&&document.addEventListener("mousedown",D),()=>document.removeEventListener("mousedown",D)},[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((D,L)=>E.jsxs("button",{onMouseDown:R=>{R.preventDefault(),C(D.value)},className:`w-full text-left px-3 py-1.5 text-sm hover:bg-accent transition-colors flex items-center gap-2 ${L===_?"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":D.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"?"/":"@"}),D.value]})]},`${D.kind}:${D.value}`))}),E.jsx("textarea",{ref:x,value:t,onChange:P,onKeyDown:N,onPaste:i,placeholder:c,disabled:h,rows:f,dir:"auto",className:u})]})}),wA="shraga:draft:";function rw(e,t){const n=wA+(e??"new");t.trim()?localStorage.setItem(n,t):localStorage.removeItem(n)}function tD(e){return localStorage.getItem(wA+(e??"new"))??""}function nD(e){localStorage.removeItem(wA+(e??"new"))}const Dke=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 z,V;const b=Sa(),[S,_]=y.useState(()=>tD(m)),[O,k]=y.useState([]),[T,C]=y.useState(!1),N=y.useRef(null),P=y.useRef(null),D=y.useRef(m);y.useEffect(()=>{var j;if(D.current===m)return;const H=D.current;if(D.current=m,!m){nD(H),rw(void 0,S);return}rw(H,S);const Y=tD(m);_(Y),(j=P.current)==null||j.setValue(Y)},[m]);const L=y.useCallback(H=>{_(H),rw(D.current,H)},[]);y.useImperativeHandle(x,()=>({prefill(H){var Y,j;L(H),(Y=P.current)==null||Y.setValue(H),(j=P.current)==null||j.focus()},setText(H){var Y;L(H),(Y=P.current)==null||Y.setValue(H)},focus(){var H;(H=P.current)==null||H.focus()}}));const R=(H="send")=>{var j;const Y=S.trim();!Y&&O.length===0||(H==="steer"?n(Y):H==="queue"?r(Y):t(Y,O.length>0?O:void 0),_(""),nD(D.current),k([]),(j=P.current)==null||j.setValue(""))},F=typeof window<"u"&&((z=window.matchMedia)==null?void 0:z.call(window,"(pointer: coarse)").matches),I=H=>{if(H.key==="Enter"&&!H.shiftKey&&(!F||H.metaKey||H.ctrlKey)){H.preventDefault(),R(f?"steer":"send");return}if(H.key==="Tab"&&f&&S.trim()){H.preventDefault(),R("queue");return}},q=y.useCallback(async H=>{C(!0);try{const Y=await s(H);Y&&k(j=>[...j,Y])}finally{C(!1)}},[s]),G=y.useCallback(H=>{const Y=Array.from(H.clipboardData.items);for(const j of Y)if(j.type.startsWith("image/")||j.type==="application/pdf"){const U=j.getAsFile();U&&q(U)}},[q]),K=H=>{var j;const Y=(j=H.target.files)==null?void 0:j[0];Y&&(q(Y),H.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||T)&&E.jsxs("div",{className:"flex gap-2 mb-2 flex-wrap items-center",children:[O.map((H,Y)=>E.jsxs("div",{className:"relative group",children:[H.mimeType.startsWith("image/")?E.jsx(xA,{src:H.url,alt:H.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(hE,{className:"w-4 h-4 shrink-0"}),E.jsx("span",{className:"truncate max-w-[120px]",children:H.name})]}),E.jsx("button",{onClick:()=>k(j=>j.filter((U,Z)=>Z!==Y)),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(Pl,{className:"w-3 h-3"})})]},Y)),T&&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 H;return(H=N.current)==null?void 0:H.click()},disabled:u,title:"Attach file or image",children:E.jsx(oG,{className:"w-4 h-4"})}),E.jsx("input",{ref:N,type:"file",className:"hidden",onChange:K}),E.jsx(R6,{ref:P,value:S,onChange:L,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]"}),(V=b.inputAdornments)==null?void 0:V.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:()=>R("steer"),title:"Steer (inject into current turn)",children:E.jsx(ig,{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(Oj,{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:()=>R(),disabled:u||T||!S.trim()&&O.length===0,children:E.jsx(ig,{className:"w-4 h-4"})})]}),a.length>0&&E.jsx("div",{className:"flex gap-1.5 flex-wrap mt-2",children:a.map((H,Y)=>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:H}),E.jsx("button",{onClick:()=>i(Y),className:"hover:text-blue-900 dark:hover:text-blue-100",children:E.jsx(Pl,{className:"w-3 h-3"})})]},Y))}),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"})]})})}),jke={"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 Lke({artifacts:e,selectedId:t,sessionId:n,getToken:r,onSelect:i,onClose:a}){var P;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(D=>D.id===t),S=y.useCallback(()=>{if(!x.current||!b)return;const{clientWidth:D,clientHeight:L}=x.current,R=32,F=D-R,I=L-R,[q,G]=b.dimensions;v(Math.min(F/q,I/G,1))},[b]);y.useEffect(()=>{let D=!0;return r().then(L=>fetch("/api/features",{headers:L?{Authorization:`Bearer ${L}`}:{}})).then(L=>L.json()).then(L=>{D&&p(!!L.artifactPngExport)}).catch(L=>console.error("[artifact] features fetch failed:",L)),()=>{D=!1}},[r]),y.useEffect(()=>{S();const D=x.current;if(!D)return;const L=new ResizeObserver(S);return L.observe(D),()=>L.disconnect()},[S]);const _=async()=>{if(b){f(!0);try{const D=await r(),L=await fetch(`/api/artifacts/${n}/${b.id}/export`,{method:"POST",headers:{"Content-Type":"application/json",...D?{Authorization:`Bearer ${D}`}:{}},body:JSON.stringify({dimensions:b.dimensions})});if(!L.ok)throw new Error(await L.text());const R=await L.blob(),F=URL.createObjectURL(R),I=document.createElement("a");I.href=F,I.download=`${b.title.replace(/\s+/g,"-").toLowerCase()}.png`,I.click(),URL.revokeObjectURL(F)}catch(D){console.error("[artifact] export failed:",D)}finally{f(!1)}}},O=b?(P=Object.entries(jke).find(([,D])=>D[0]===b.dimensions[0]&&D[1]===b.dimensions[1]))==null?void 0:P[0]:null,[k,T]=(b==null?void 0:b.dimensions)??[0,0],C=k*m,N=T*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(Ej,{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:D=>i(D.target.value),children:e.map(D=>E.jsx("option",{value:D.id,children:D.title},D.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}×${T}`,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(eG,{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(mE,{className:"w-3.5 h-3.5"}):E.jsx(pE,{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(Pl,{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:C,height:N},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:T,transform:`scale(${m})`},title:b.title})}):E.jsx("p",{className:"text-sm text-muted-foreground",children:"No artifact selected"})})]})}const Ey=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}));Ey.displayName="Textarea";const V1={fable:"claude-fable-5-1","fable-5-1":"claude-fable-5-1","fable-5":"claude-fable-5",opus:"claude-opus-5","opus-5":"claude-opus-5","opus-4-8":"claude-opus-4-8","opus-4-7":"claude-opus-4-7","opus-4-6":"claude-opus-4-6",sonnet:"claude-sonnet-5","sonnet-5":"claude-sonnet-5","sonnet-4-6":"claude-sonnet-4-6",haiku:"claude-haiku-4-5-20251001"},zke=/^\s*\[([^\]]*)\]\s*([\s\S]*)/,P6=["model","turns","thinking","think","effort","engine"],W1=e=>/^[a-z0-9._-]+\/[a-z0-9./_-]+$/.test(e);let Ml=null;function $ke(e){Ml=e}function Y1(e){const t=e.trim().toLowerCase();return V1[t]?{model:V1[t]}:(Ml==null?void 0:Ml(t))??null}function D6(e,t){const n=Y1(t);return n?(e.model=n.model,n.engine&&!e.engine&&(e.engine=n.engine),!0):!1}function Bke(e){const t=e.split(",").map(n=>n.trim()).filter(Boolean);return t.length?t.every(n=>{const r=n.indexOf(":");if(r!==-1)return P6.includes(n.slice(0,r).trim().toLowerCase());const i=n.toLowerCase();return!!V1[i]||!!(Ml!=null&&Ml(i))||/^\d+$/.test(i)||["think","adaptive","nothink","nothinking"].includes(i)}):!1}function EA(e,t){let n=e;const r=[];for(;;){const i=n.match(zke);if(!i)break;const a=i[1].trim();if((r.length||t!=null&&t.strict)&&a&&!Bke(a))break;r.push(a),n=i[2]}return{groups:r,body:n}}function Uke(e){const{groups:t,body:n}=EA(e);if(!t.length)return{prompt:e,directives:{}};const r=t.filter(Boolean).join(","),i=n.trim();if(!r)return{prompt:i,directives:{}};const a={};let s=0,c;const u=r.split(","),f=u.some(h=>{const p=h.indexOf(":");return p!==-1&&P6.includes(h.slice(0,p).trim().toLowerCase())});for(const h of u){const p=h.trim();if(!p)continue;const m=p.indexOf(":");if(m!==-1){const v=p.slice(0,m).trim().toLowerCase(),x=p.slice(m+1).trim().toLowerCase();c=Fke(a,v,x)??c}else{const v=p.toLowerCase();s===0&&D6(a,v)||(s<=1&&/^\d+$/.test(v)?a.turns=parseInt(v,10):["think","adaptive"].includes(v)?a.thinking="adaptive":["nothink","nothinking"].includes(v)?a.thinking="disabled":s===0&&(f&&!W1(v)&&(c??(c=p)),console.warn(W1(v)?`[directives] Provider-qualified model needs key form: "[model:${p}]"`:`[directives] Unknown model alias: "${p}"`))),s++}}return{prompt:i,directives:a,unresolvedModel:c}}function Fke(e,t,n){switch(t){case"model":if(D6(e,n))break;if(W1(n)){e.model=n;break}return n;case"turns":/^\d+$/.test(n)?e.turns=parseInt(n,10):console.warn(`[directives] Invalid turns value: "${n}"`);break;case"thinking":case"think":["adaptive","enabled","disabled"].includes(n)?e.thinking=n:console.warn(`[directives] Invalid thinking value: "${n}"`);break;case"effort":["low","medium","high","max"].includes(n)?e.effort=n:console.warn(`[directives] Invalid effort value: "${n}"`);break;case"engine":e.engine=n;break;default:console.warn(`[directives] Unknown directive key: "${t}"`)}}function Hke(e){return t=>{const n=t.toLowerCase(),r=[];for(const{name:i,models:a}of e())for(const s of a){if(!s.value)continue;const c=s.value.toLowerCase();if(c===n)return{model:s.value,engine:i};c.slice(c.lastIndexOf("/")+1)===n&&r.push({model:s.value,engine:i})}return r.length===1?r[0]:(r.length>1&&console.warn(`[directives] Ambiguous model "${t}" (${r.map(i=>`${i.engine}:${i.model}`).join(", ")}) — use the full id`),null)}}let Ym=[];$ke(Hke(()=>Ym));function j6(e,t=!0){const[n,r]=y.useState(Ym),[i,a]=y.useState(!1);return y.useEffect(()=>{if(!t)return;let s=!0;return e().then(c=>{!c||!s||fetch("/api/engines",{headers:{Authorization:`Bearer ${c}`}}).then(u=>u.json()).then(u=>{s&&(Ym=u.engines??[],r(Ym),a(u.multiEngine??!1))}).catch(u=>console.warn("[engines] load failed",u))}),()=>{s=!1}},[t,e]),{engines:n,multiEngine:i}}const Kke=[{value:"",label:"Default (claude-sonnet-5)"},{value:"claude-fable-5-1",label:"Fable 5.1 — frontier, most capable"},{value:"claude-fable-5",label:"Fable 5"},{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"}],qke=[{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 Gke({getToken:e,onSaved:t,trigger:n,sessionId:r,sessionDirectives:i,onDirectivesSaved:a}){var L;const s=Sa(),[c,u]=y.useState({}),[f,h]=y.useState(!1),[p,m]=y.useState(!1),{engines:v,multiEngine:x}=j6(e,f),b=y.useRef({}),[S,_]=y.useState(!1);y.useEffect(()=>{f&&(_(!1),e().then(R=>{R&&fetch("/api/config",{headers:{Authorization:`Bearer ${R}`}}).then(F=>F.json()).then(F=>{b.current=F;const I=r?i:void 0;u({...F,...(I==null?void 0:I.engine)!==void 0?{engine:I.engine}:{},...(I==null?void 0:I.model)!==void 0?{model:I.model}:{},...(I==null?void 0:I.turns)!==void 0?{maxTurns:I.turns}:{},...(I==null?void 0:I.thinking)!==void 0?{thinking:I.thinking}:{}})}).catch(()=>{})}))},[f,e,r,i]);const O=async()=>{m(!0);const F={Authorization:`Bearer ${await e()??""}`,"Content-Type":"application/json"};try{if(r){const I=S?{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:F,body:JSON.stringify(I)}).then(K=>K.json()).catch(K=>(console.warn("[config] directives save failed",K),null));q!=null&&q.directives&&(a==null||a(q.directives));const G=S?c:{...c,engine:b.current.engine,model:b.current.model,maxTurns:b.current.maxTurns,thinking:b.current.thinking};await fetch("/api/config",{method:"PUT",headers:F,body:JSON.stringify(G)}),t==null||t(G)}else await fetch("/api/config",{method:"PUT",headers:F,body:JSON.stringify(c)}),t==null||t(c);h(!1)}finally{m(!1)}},k=c.engine||"claude-code",T=v.find(R=>R.name===k),C=(T==null?void 0:T.models)??Kke;y.useEffect(()=>{!T||!C.length||C.some(R=>(R.value||"")===(c.model??""))||u(R=>({...R,model:C[0].value||void 0}))},[T,C,c.model]);const P=C.some(R=>R.provider)?Array.from(C.reduce((R,F)=>{const I=F.provider||"default";return R.has(I)||R.set(I,[]),R.get(I).push(F),R},new Map)):null,D="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(lh,{asChild:!0,children:n||E.jsx(Re,{variant:"ghost",size:"icon",title:"Agent Config",children:E.jsx(fG,{className:"w-4 h-4"})})}),E.jsxs(uo,{className:"max-w-lg",children:[E.jsx(jl,{children:E.jsx(Ss,{children:"Agent Configuration"})}),E.jsxs(Kz,{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:S?"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:S,onChange:R=>_(R.target.checked)}),E.jsx("span",{children:"Apply globally — also the default for Slack, email & scheduled runs"})]})]}),x&&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:R=>{const F=R.target.value||void 0;u(I=>({...I,engine:F,model:void 0}))},className:D,children:v.map(R=>E.jsx("option",{value:R.name,children:R.name==="claude-code"?"Claude Code (default)":R.name},R.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:R=>u(F=>({...F,model:R.target.value||void 0})),className:D,children:P?P.map(([R,F])=>E.jsx("optgroup",{label:R.charAt(0).toUpperCase()+R.slice(1),children:F.map(I=>E.jsx("option",{value:I.value,children:I.label},I.value))},R)):C.map(R=>E.jsx("option",{value:R.value,children:R.label},R.value))})]}),(L=s.settingsSections)==null?void 0:L.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:R=>u(F=>({...F,permissionMode:R.target.value})),className:D,children:qke.map(R=>E.jsx("option",{value:R.value,children:R.label},R.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:R=>u(F=>({...F,maxTurns:Number(R.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:R=>u(F=>({...F,thinking:R.target.value||void 0})),className:D,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:R=>u(F=>({...F,effort:R.target.value||void 0})),className:D,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:R=>u(F=>({...F,allowedTools:R.target.value.split(",").map(I=>I.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(R=>({...R,skillDiscovery:R.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(Ey,{placeholder:"Additional instructions appended to Claude's system prompt…",value:c.systemPrompt??"",onChange:R=>u(F=>({...F,systemPrompt:R.target.value||void 0})),rows:4})]})]}),E.jsx(qz,{children:E.jsx(Re,{onClick:O,disabled:p,children:p?"Saving…":"Save Configuration"})})]})]})}function Vke(e){const t=e.requestedEngine||"claude-code",n=e.actualEngine?"ran":e.actualModel?"ran-model":"pending",r=n==="ran"?e.actualEngine:n==="pending"?t:void 0,i=e.actualModel||e.requestedModel||(t==="cursor"?"cursor/composer-2.5":"sonnet-4-6"),a=n==="ran"&&r!==t?t:void 0,s=r==="claude-code"||r==="cursor",c=i.includes("/")?i.split("/")[0]:r==="claude-code"?"anthropic":r;return{provenance:n,engine:r,engineIsNative:s,engineMismatch:a,rawModel:i,billingProvider:c}}function Wke({sessionId:e,config:t,sessionDirectives:n,actualModel:r,actualEngine:i,scheduleId:a,onScheduleClick:s}){const[c,u]=y.useState(!1),{provenance:f,engine:h,engineIsNative:p,engineMismatch:m,rawModel:v,billingProvider:x}=Vke({requestedEngine:(n==null?void 0:n.engine)||t.engine,requestedModel:(n==null?void 0:n.model)||t.model,actualEngine:i,actualModel:r}),b=v.replace("claude-",""),S=h&&!p?`${h} · ${b}`:b,_=f==="pending",O=_?" border border-dashed border-current/40 opacity-80":"",k=_?"Nothing has run in this conversation yet — this is what the next turn is set to use.":f==="ran-model"?"Model recorded from the last turn. The engine that ran it was not recorded (this conversation predates engine tracking), so it is not named here.":"Engine and model that actually ran the last turn.",T=h==="claude-code"&&t.claudeAuthSource==="subscription",C=x?T?"sub":x==="cursor"?"plan":"metered":"unknown",N=C==="unknown"?"bg-muted text-muted-foreground ring-border":C==="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":C==="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",P=C==="unknown"?"The engine that ran this turn was not recorded and the model id carries no provider prefix — the billed provider cannot be named from what was stored.":C==="sub"?"Claude.ai subscription (OAuth login) — no API key in use":C==="plan"?`Runs on your ${x} API key — usage may draw on your ${x} plan/subscription`:`Runs on your ${x} API key — metered per-token billing`,D=t.permissionMode||"acceptEdits",L=D==="bypassPermissions"?"bypass":D==="plan"?"plan":D==="default"?"prompt":"edits",R=(n==null?void 0:n.thinking)||t.thinking,F=()=>{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",{title:k,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${O}`,children:_?`→ ${S}`:S}),E.jsx("span",{title:_?`${k} ${P}`:P,className:`inline-flex items-center rounded-md px-1.5 py-0.5 text-[10px] font-medium ring-1 ring-inset ${N}${O}`,children:C==="unknown"?"API·?":T?"sub":`API·${x}`}),m&&E.jsxs("span",{title:`This session requests the "${m}" engine, but the last turn actually ran on "${h}" — so the chips above report ${h}, 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:["≠ ",m]}),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:L}),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"]}),R&&R!=="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:F,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(dE,{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(fE,{className:"w-2.5 h-2.5"}),a.slice(0,8)]})]})}function Yke({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(Wke,{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(_j,{className:"w-3.5 h-3.5"})}),E.jsx(Gke,{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(nG,{className:"w-3.5 h-3.5"})})]})}function Xke({nodeId:e,sessionId:t}){var H;const n=uE(),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(),[T,C]=y.useState(),[N,P]=y.useState(!1),D=Kae(h,n.getToken,n.token),L=y.useRef(!1),R=y.useCallback(Y=>{n.bumpSidebar(),Y!==m.current&&(p(Y),n.assignSession(e,Y))},[n,e]),F=y.useCallback(Y=>{Y.type==="artifact"?Y.sessionId===m.current&&D.handleArtifactEvent(Y):Y.type==="directives"?L.current&&(k(void 0),C(void 0)):Y.type==="model_resolved"&&Y.sessionId===m.current&&(k(Y.model),C(Y.engine))},[n,e,D]),I=Uae(n.socket,{getToken:n.getToken,initialSessionId:t,onNewSession:R,onDirectivesChanged:b,onParticipantsChanged:P,onEvent:F});L.current=I.busy,y.useEffect(()=>{if(!v)return;let Y=!1;return(async()=>{try{const U=await(await bl(`/api/sessions/${v}/messages`,n.getToken)).json();if(Y)return;I.setMessages(yj(U)),P(Array.isArray(U.participants)&&U.participants.length>1),U.busy&&I.setBusy(!0)}catch(j){Y||console.error("[pane] history load failed:",j)}})(),()=>{Y=!0}},[v]),y.useEffect(()=>{if(!h){b(void 0),_(void 0),k(void 0),C(void 0);return}bl(`/api/sessions/${h}/meta`,n.getToken).then(Y=>Y.json()).then(Y=>{b(Y.directives),_(Y.scheduleId),k(Y.lastModel),C(Y.lastEngine),Y.runStatus==="running"&&I.setBusy(!0)}).catch(()=>{})},[h,n.getToken]);const q=y.useCallback((Y,j,U)=>{var Z;I.sendMessage(Y,m.current,U,j,(Z=f.current)==null?void 0:Z.call(f))},[I]),G={sessionId:h,busy:I.busy,socket:n.socket,getToken:n.getToken,setInputCtx:s,setSendOptions:Y=>{f.current=Y},setInputText:Y=>{var j;return(j=i.current)==null?void 0:j.setText(Y)},send:(Y,j,U)=>I.sendMessage(Y,m.current,void 0,void 0,j,(U==null?void 0:U.echo)!==!1),appendAssistant:Y=>I.setMessages(j=>j.concat({id:ms(),role:"assistant",blocks:Y})),setStatusItems:u},K=y.useCallback(async Y=>{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(Y.name),"Content-Type":Y.type||"application/octet-stream","x-session-id":m.current||""},body:Y})).json()}catch(U){return console.error("[upload] Failed:",U),null}},[n]),z=y.useCallback(async Y=>{const j=m.current;if(!j)return;const U=await n.getToken();if(U)try{const Z=await fetch(`/api/sessions/${j}/fork`,{method:"POST",headers:{Authorization:`Bearer ${U}`,"Content-Type":"application/json"},body:JSON.stringify(Y!=null?{truncateAtIndex:Y}:{})});if(!Z.ok){console.error("[fork] server error:",(await Z.json().catch(()=>({}))).error||Z.status);return}const{sessionId:B}=await Z.json();n.bumpSidebar(),n.openSession(B)}catch(Z){console.error("[fork] failed:",Z)}},[n]),V=y.useCallback((Y,j,U)=>{if(I.busy)return;const Z=I.messages.findIndex(B=>B.id===Y);Z>=0&&I.setMessages(I.messages.slice(0,Z)),q(j,Z>=0?Z:void 0,U)},[I,q]);return E.jsxs("div",{className:"flex flex-col h-full min-h-0",children:[(H=r.conversationController)==null?void 0:H.call(r,G),E.jsx(Yke,{sessionId:h,agentConfig:n.agentConfig,sessionDirectives:x,sessionLastModel:O,sessionLastEngine:T,sessionScheduleId:S,artifactCount:D.artifacts.length,getToken:n.getToken,onConfigSaved:n.setAgentConfig,onDirectivesSaved:b,onFork:()=>z(),onToggleArtifacts:D.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(bke,{messages:I.messages,busy:I.busy,multiParticipant:N,connectionStatus:n.connectionStatus??void 0,onPermissionRespond:I.respondPermission,onQuestionRespond:I.respondQuestion,onReplay:V,onEdit:V,onFork:Y=>z(Y),statusItems:c}),E.jsx(Dke,{ref:i,onSend:(Y,j)=>q(Y,void 0,j),onSteer:I.steer,onQueue:I.addToQueue,onRemoveQueued:I.removeFromQueue,queue:I.queue,onUpload:K,onCancel:I.cancel,disabled:!1,busy:I.busy,skills:n.skills,workspaceFiles:n.workspaceFiles,sessionId:h,inputCtx:a})]}),D.panelOpen&&D.artifacts.length>0&&h&&E.jsx(Lke,{artifacts:D.artifacts,selectedId:D.selectedId,sessionId:h,getToken:n.getToken,onSelect:D.selectArtifact,onClose:D.closePanel})]})]})}const Zke=()=>({command:"",args:[],env:{}});function rD({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(T=>{const C=new Set(T);return C.has(k)?C.delete(k):C.add(k),C});y.useEffect(()=>{i&&e().then(k=>{k&&fetch("/api/mcps",{headers:{Authorization:`Bearer ${k}`}}).then(T=>{if(!T.ok)throw new Error(`HTTP ${T.status}`);return T.json()}).then(r).catch(T=>console.error("[McpManager] fetch failed",T))})},[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(T=>({...T,[k]:Zke()}))},v=k=>{r(T=>{const C={...T};return delete C[k],C})},x=(k,T,C)=>{r(N=>({...N,[k]:{...N[k],[T]:T==="args"?C.split(" "):C}}))},b=(k,T,C)=>{r(N=>{const P={...N[k].env},D=P[T]??"";return delete P[T],C.trim()&&(P[C.trim()]=D),{...N,[k]:{...N[k],env:P}}})},S=(k,T,C)=>{r(N=>({...N,[k]:{...N[k],env:{...N[k].env,[T]:C}}}))},_=(k,T)=>{r(C=>{const N={...C[k].env};return delete N[T],{...C,[k]:{...C[k],env:N}}})},O=k=>{const T=`KEY_${Date.now()}`;r(C=>({...C,[k]:{...C[k],env:{...C[k].env,[T]:""}}}))};return E.jsxs(Es,{open:i,onOpenChange:a,children:[E.jsx(lh,{asChild:!0,children:t||E.jsx(Re,{variant:"ghost",size:"icon",title:"MCP Servers",children:E.jsx(Aj,{className:"w-4 h-4"})})}),E.jsxs(uo,{className:"max-w-[95vw] sm:max-w-2xl",children:[E.jsx(jl,{children:E.jsx(Ss,{children:"MCP Servers"})}),E.jsxs(Kz,{className:"space-y-4",children:[Object.entries(n).map(([k,T])=>{const C=!!T.readonly;return E.jsxs("div",{className:`border rounded-lg p-4 space-y-3 ${C?"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:[C&&E.jsx(jm,{className:"w-3 h-3 text-muted-foreground"}),k]}),!C&&E.jsx(Re,{variant:"ghost",size:"icon",onClick:()=>v(k),children:E.jsx(Rd,{className:"w-4 h-4 text-destructive"})})]}),C?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:T.command,onChange:N=>x(k,"command",N.target.value)}),E.jsx(In,{placeholder:"Args (space-separated)",value:(T.args||[]).join(" "),onChange:N=>x(k,"args",N.target.value)}),Object.entries(T.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(T.env||{}).map(([N,P])=>E.jsxs("div",{className:"flex gap-2 items-center",children:[E.jsx(In,{className:"w-1/3 font-mono text-xs",value:N,onChange:D=>b(k,N,D.target.value),placeholder:"KEY"}),u.has(`${k}:${N}`)?E.jsx(In,{className:"flex-1 font-mono text-xs",placeholder:"paste new value",autoFocus:!0,onChange:D=>S(k,N,D.target.value),onBlur:()=>h(`${k}:${N}`)}):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}:${N}`),title:"Click to change",children:P||"(empty — click to set)"}),E.jsx(Re,{variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0",onClick:()=>_(k,N),children:E.jsx(Rd,{className:"w-3 h-3 text-muted-foreground"})})]},N))]}),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(qz,{className:"flex gap-2",children:[E.jsxs(Re,{variant:"outline",onClick:m,className:"gap-2",children:[E.jsx(mv,{className:"w-4 h-4"})," Add Server"]}),E.jsx(Re,{onClick:p,disabled:s,children:s?"Saving…":"Save"})]})]})]})}function SA(e){return typeof e=="string"?e:e.name}function iD(e){return typeof e=="string"?!1:e.capped===!0||typeof e.capped=="number"&&e.capped>0}function vd(e,t){return e.some(n=>SA(n)===t)}function aD(e,t){return e.find(n=>SA(n)===t)}async function Wa(e,t,n){return fetch(e,{...n,headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json",...(n==null?void 0:n.headers)??{}}})}function oD({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,T]=y.useState(""),C=p?c.includes(p):!1,N=async()=>{const K=await e();if(!K)return;const[z,V]=await Promise.all([Wa("/api/skills",K),Wa("/api/skills-defaults",K)]),H=await z.json(),Y=await V.json();s(H.skills),u(H.builtins),h(Y),t==null||t(H.skills)},P=async K=>{const z=await e();if(!z)return;const H=await(await Wa(`/api/skills/${K}`,z)).json();x(H.content),m(K),S(!1)},D=async()=>{if(!p||C)return;const K=await e();K&&(await Wa(`/api/skills/${p}`,K,{method:"PUT",body:JSON.stringify({content:v})}),S(!1))},L=async()=>{const K=k.trim().replace(/\s+/g,"-");if(!K)return;const z=await e();if(z){if(_==="create")await Wa(`/api/skills/${K}`,z,{method:"PUT",body:JSON.stringify({content:""})}),await N(),await P(K);else if(_==="duplicate"&&p){if(!(await Wa(`/api/skills/${p}/duplicate`,z,{method:"POST",body:JSON.stringify({newName:K})})).ok)return;await N(),await P(K)}else if(_==="rename"&&p){if(!(await Wa(`/api/skills/${p}/rename`,z,{method:"POST",body:JSON.stringify({newName:K})})).ok)return;await N(),await P(K)}O(null),T("")}},R=async K=>{const z=await e();!z||!(await Wa(`/api/skills/${K}`,z,{method:"DELETE"})).ok||(p===K&&(m(null),x("")),await N())},F=async K=>{const z=await e();if(!z)return;const V=vd(f,K)?f.filter(H=>SA(H)!==K):[...f,K];await Wa("/api/skills-defaults",z,{method:"PUT",body:JSON.stringify(V)}),h(V)},I=K=>{O(K),T(K==="rename"&&p?p:K==="duplicate"&&p?`${p}-copy`:"")},q=()=>{O(null),T("")};y.useEffect(()=>{r&&N()},[r]);const G=_==="create"?"skill-name":_==="rename"?"new-name":"copy-name";return E.jsxs(Es,{open:r,onOpenChange:i,children:[E.jsx(lh,{asChild:!0,children:n||E.jsx(Re,{variant:"ghost",size:"icon",title:"Skills",className:"h-8 w-8",children:E.jsx(gw,{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(jl,{className:"px-4 pt-4 pb-2 border-b shrink-0",children:E.jsxs(Ss,{className:"flex items-center gap-2",children:[E.jsx(gw,{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(K=>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===K?"bg-accent font-medium":""}`,onClick:()=>P(K),children:[E.jsx("button",{className:`shrink-0 transition-colors ${vd(f,K)?"text-amber-500":"text-muted-foreground/30 hover:text-amber-400"}`,onClick:z=>{z.stopPropagation(),F(K)},title:vd(f,K)?"Remove from defaults":"Set as default (always active)",children:E.jsx(HT,{className:`w-3 h-3 ${vd(f,K)?"fill-current":""}`})}),E.jsxs("span",{className:"truncate flex-1",children:["@",K]}),c.includes(K)&&E.jsx("span",{title:"Built-in (read-only)",children:E.jsx(jm,{className:"w-2.5 h-2.5 text-muted-foreground/40 shrink-0"})}),!c.includes(K)&&E.jsx("button",{className:"opacity-0 group-hover:opacity-100 text-muted-foreground hover:text-destructive transition-opacity shrink-0",onClick:z=>{z.stopPropagation(),R(K)},title:"Delete",children:E.jsx(Rd,{className:"w-3 h-3"})})]},K))}),E.jsx("div",{className:"border-t p-2",children:_?E.jsxs("div",{className:"flex gap-1",children:[E.jsx(In,{value:k,onChange:K=>T(K.target.value),onKeyDown:K=>{K.key==="Enter"&&L(),K.key==="Escape"&&q()},placeholder:G,className:"h-7 text-xs",autoFocus:!0}),E.jsx(Re,{size:"icon",className:"h-7 w-7 shrink-0",onClick:L,children:E.jsx(ha,{className:"w-3 h-3"})}),E.jsx(Re,{size:"icon",variant:"ghost",className:"h-7 w-7 shrink-0",onClick:q,children:E.jsx(Pl,{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(mv,{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(Ej,{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:[C&&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(jm,{className:"w-2.5 h-2.5"})," read-only"]}),vd(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 ${iD(aD(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:iD(aD(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(dE,{className:"w-3 h-3"})}),!C&&E.jsx(Re,{variant:"ghost",size:"sm",className:"h-6 text-xs px-1.5",onClick:()=>I("rename"),title:"Rename",children:E.jsx(gE,{className:"w-3 h-3"})}),b&&!C&&E.jsxs(Re,{size:"sm",className:"h-6 text-xs",onClick:D,children:[E.jsx(ha,{className:"w-3 h-3 mr-1"})," Save"]})]})]}),E.jsx(Ey,{value:v,onChange:K=>{C||(x(K.target.value),S(!0))},readOnly:C,className:`flex-1 resize-none rounded-none border-0 font-mono text-xs focus-visible:ring-0 ${C?"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(HT,{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(jm,{className:"w-3 h-3 inline"})," = built-in, duplicate to customize"]})]})})]})]})]})}async function yd(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 Qke(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 yd("/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 yd("/api/modules/install",e,{method:"POST",body:JSON.stringify(O)}),await v()},[e,v]),b=y.useCallback(async(O,k)=>{await yd(`/api/modules/${O}/${k?"enable":"disable"}`,e,{method:"POST"}),await v()},[e,v]),S=y.useCallback(async(O,k)=>{await yd(`/api/modules/${O}/config`,e,{method:"PUT",body:JSON.stringify({config:k})}),await v()},[e,v]),_=y.useCallback(async O=>{await yd(`/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 L6({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 sD(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 Jke({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(L6,{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(Id,{className:"w-3 h-3 mr-1 animate-spin"}):E.jsx(ha,{className:"w-3 h-3 mr-1"})," Save config"]})]})}function lD({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}=Qke(e,n),[v,x]=y.useState(null),[b,S]=y.useState(null),[_,O]=y.useState(null),k=async(C,N)=>{if(!b){S(C),O(null);try{await N()}catch(P){O(P.message)}finally{S(null)}}},T=a.filter(C=>!C.installed);return E.jsxs(Es,{open:n,onOpenChange:r,children:[E.jsx(lh,{asChild:!0,children:t||E.jsx(Re,{variant:"ghost",size:"icon",title:"Modules",className:"h-8 w-8",children:E.jsx(mw,{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(jl,{className:"px-4 pt-4 pb-2 border-b shrink-0",children:E.jsxs(Ss,{className:"flex items-center gap-2",children:[E.jsx(mw,{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&&T.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(C=>{const N=v===C.name,P=C.configSchema&&Object.keys(C.configSchema).length>0,D=[C.skillCount?`provides ${C.skillCount} skill${C.skillCount===1?"":"s"}`:"",C.scheduleCount?`${C.scheduleCount} schedule${C.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(L6,{checked:C.enabled,onChange:L=>k(`toggle-${C.name}`,()=>h(C.name,L)),title:C.enabled?"Disable":"Enable",disabled:b===`toggle-${C.name}`}),E.jsx("span",{className:"font-medium text-sm truncate",children:C.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",C.version]}),!C.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-${C.name}`&&E.jsx(Id,{className:"w-3 h-3 animate-spin text-muted-foreground"}),(P||C.readme)&&E.jsx("button",{className:"text-muted-foreground hover:text-foreground transition-colors",onClick:()=>x(N?null:C.name),title:"Details",children:N?E.jsx(Vq,{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 "${C.name}"? Its skills and schedules will be removed (seeds/data stay).`)&&k(`rm-${C.name}`,()=>m(C.name))},title:"Uninstall",children:E.jsx(Rd,{className:"w-3.5 h-3.5"})})]}),C.description&&E.jsx("p",{className:"text-xs text-muted-foreground",children:C.description}),D&&E.jsx("p",{className:"text-[10px] text-muted-foreground",children:D}),!N&&sD(C)&&E.jsx("p",{className:"text-[10px] font-mono text-muted-foreground truncate",children:sD(C)}),N&&C.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:C.readme}),N&&P&&E.jsx(Jke,{schema:C.configSchema,config:C.config,saving:b===`cfg-${C.name}`,onSave:L=>k(`cfg-${C.name}`,()=>p(C.name,L))},JSON.stringify(C.config))]},C.name)})]}),T.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"}),T.map(C=>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:C.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",C.version]})]}),C.description&&E.jsx("p",{className:"text-xs text-muted-foreground",children:C.description})]}),E.jsxs(Re,{size:"sm",variant:"outline",className:"h-7 text-xs shrink-0",disabled:b===`install-${C.name}`,onClick:()=>k(`install-${C.name}`,()=>f({name:C.name})),children:[b===`install-${C.name}`?E.jsx(Id,{className:"w-3 h-3 mr-1 animate-spin"}):E.jsx(Sj,{className:"w-3 h-3 mr-1"}),"Install"]})]},C.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 eOe(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 T=await hl(`/api/schedules/${O}`,e,{method:"PUT",body:JSON.stringify(k)});return await p(),T},[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 T=await hl(`/api/schedules/${O}/run`,e,{method:"POST",body:JSON.stringify(k?{override:k}:{})});return await p(),T.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 iw={exports:{}},cD;function tOe(){return cD||(cD=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(C){var N=C.replace(/\D/,""),P=N;return v.dayOfWeekStartIndexZero?N=="7"&&(P="0"):P=(parseInt(N)-1).toString(),C.replace(N,P)}),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(C){var N=C.replace(/\D/,""),P=N;return v.monthStartIndexZero&&(P=(parseInt(N)+1).toString()),C.replace(N,P)});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(C){return C!==""}).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 T=m[O].split("/");m[O]="".concat(T[0],"-").concat(k,"/").concat(T[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,T=b.dayOfWeekStartIndexZero,C=T===void 0?!0:T,N=b.monthStartIndexZero,P=N===void 0?!1:N,D=b.use24HourTimeFormat,L=b.trimHoursLeadingZero,R=L===void 0?!1:L,F=b.locale,I=F===void 0?null:F,q=b.logicalAndDayFields,G=q===void 0?!1:q,K={throwExceptionOnParseError:_,verbose:k,dayOfWeekStartIndexZero:C,monthStartIndexZero:P,use24HourTimeFormat:D,trimHoursLeadingZero:R,locale:I,logicalAndDayFields:G};K.tzOffset&&console.warn("'tzOffset' option has been deprecated and is no longer supported.");var z=new m(v,K);return z.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(),T=this.getDayOfWeekDescription(),C=this.getYearDescription();b+=_+O+T+k+C,b=this.transformVerbosity(b,!!this.options.verbose),b=b.charAt(0).toLocaleUpperCase()+b.substr(1)}catch(N){if(!this.options.throwExceptionOnParseError)b=this.i18n.anErrorOccuredWhenGeneratingTheExpressionD();else throw"".concat(N)}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 T=this.getSecondsDescription(),C=this.getMinutesDescription(),N=this.getHoursDescription();if(S+=T,S&&C&&(S+=", "),S+=C,C===N)return S;S&&N&&(S+=", "),S+=N}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 T=k.split("-");T.length===2&&S.push({value:T[1],index:b+1}),b+=T.length});var _=0,O=this.getSegmentDescription(x,this.i18n.everyHour(),function(k){var T=S.find(function(N){return N.value===k&&N.index===_}),C=T&&v.expressionParts[1]!=="0";return _++,C?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),T=v.i18n.daysOfTheWeekInCase?v.i18n.daysOfTheWeekInCase(_)[k]:x[k];if(S.indexOf("#")>-1){var C=null,N=S.substring(S.indexOf("#")+1),P=S.substring(0,S.indexOf("#"));switch(N){case"1":C=v.i18n.first(P);break;case"2":C=v.i18n.second(P);break;case"3":C=v.i18n.third(P);break;case"4":C=v.i18n.fourth(P);break;case"5":C=v.i18n.fifth(P);break}T=C+" "+T}return T},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 T=v.expressionParts[3]!="*";T?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 T=k[1];x=f.StringUtilities.format(this.i18n.commaDaysBeforeTheLastDayOfTheMonth(T),T);break}else{if(b=="*"&&this.expressionParts[5]!="*")return"";x=this.getSegmentDescription(b,this.i18n.commaEveryDay(),function(C){return C=="L"?v.i18n.lastDay():v.i18n.dayX0?f.StringUtilities.format(v.i18n.dayX0(),C):C},function(C){return C=="1"?v.i18n.commaEveryDay():v.i18n.commaEveryX0Days(C)},function(C){return v.i18n.commaBetweenDayX0AndX1OfTheMonth(C)},function(C){return v.i18n.commaOnDayX0OfTheMonth(C)})}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,T=v.indexOf("/")>-1,C=v.indexOf("-")>-1,N=v.indexOf(",")>-1;if(!v)k="";else if(v==="*")k=x;else if(!T&&!C&&!N)k=f.StringUtilities.format(O(v),b(v));else if(N){for(var P=v.split(","),D="",L=this.i18n.spaceAnd(),R=0;R<P.length;R++)if(R>0&&P.length>2&&(D+=",",R<P.length-1&&(D+=" ")),R>0&&P.length>1&&(R==P.length-1||P.length==2)&&(D+=L==","&&P.length>2?" ":"".concat(L," ")),P[R].indexOf("/")>-1||P[R].indexOf("-")>-1){var F=P[R].indexOf("-")>-1&&P[R].indexOf("/")==-1,I=this.getSegmentDescription(P[R],x,b,S,F?this.i18n.commaX0ThroughX1:_,O);F&&(I=I.replace(", ","")),D+=I}else if(!T)D+=b(P[R]);else{var q=this.getSegmentDescription(P[R],x,b,S,_,O);q&&q.startsWith(", ")&&(q=q.substring(2)),D+=q}T?k=D:k=f.StringUtilities.format(O(v),D)}else if(T){var P=v.split("/");if(k=f.StringUtilities.format(S(P[1]),P[1]),P[0].indexOf("-")>-1){var G=this.generateRangeSegmentDescription(P[0],_,b);G.indexOf(", ")!=0&&(k+=", "),k+=G}else if(P[0].indexOf("*")==-1){var K=f.StringUtilities.format(O(P[0]),b(P[0]));K=K.replace(", ",""),k+=f.StringUtilities.format(this.i18n.commaStartingX0(),K)}}else C&&(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),T=x(v);return S+=f.StringUtilities.format(T,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 T="",C=!1;this.options.use24HourTimeFormat||(C=!!(this.i18n.setPeriodBeforeTime&&this.i18n.setPeriodBeforeTime()),T=C?"".concat(this.getPeriod(O)," "):" ".concat(this.getPeriod(O)),O>12&&(O-=12),O===0&&(O=12));var N="";b&&(N=":".concat(("00"+b).substring(b.length)));var P=O.toString(),D=("00"+P).substring(P.length),L=k.toString(),R=("00"+L).substring(L.length),F=this.options.trimHoursLeadingZero?P:D;return"".concat(C?T:"").concat(F,":").concat(R).concat(N).concat(C?"":T)},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})())})(iw)),iw.exports}var nOe=tOe();const z6=Mu(nOe);function rOe(e){return e.trigger.kind}function iOe(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=aOe(t.expr,r),a=z6.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 aOe(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 uD(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 oOe={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 sOe(e){return e.scope==="system"}function lOe(e){return e==="prompt"?"Additional instructions (appended to prompt)":e==="bash"?"Override command":"Override args"}function cOe(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 uOe(e,t){var n;return e.scope==="system"?"system":((n=e.createdBy)==null?void 0:n.uid)===t?"mine":"others"}function fOe({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),T=L=>b(R=>{if(Object.values(R).every(Boolean))return{mine:!1,others:!1,system:!1,[L]:!0};const I={...R,[L]:!R[L]};return Object.values(I).some(Boolean)?I:{mine:!0,others:!0,system:!0}}),C=L=>_(R=>{if(Object.values(R).every(Boolean))return{once:!1,interval:!1,cron:!1,event:!1,[L]:!0};const I={...R,[L]:!R[L]};return Object.values(I).some(Boolean)?I:{once:!0,interval:!0,cron:!0,event:!0}}),N=e.filter(L=>x[uOe(L,t)]&&S[rOe(L)]),P=L=>{const R=localStorage.getItem(`schedule-override-${L.id}`);v(R??""),p(L.id)},D=async()=>{if(h){k(!0);try{const L=m.trim()||void 0;L&&localStorage.setItem(`schedule-override-${h}`,L);const R=await s(h,L);p(null),v(""),R&&u(R)}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(L=>E.jsx("button",{onClick:()=>T(L),className:`text-[11px] px-2 py-0.5 rounded-full border transition-colors ${x[L]?"bg-primary text-primary-foreground border-primary":"bg-transparent text-muted-foreground border-border hover:border-muted-foreground"}`,children:L},L)),E.jsx("span",{className:"w-px h-4 bg-border mx-1"}),["once","interval","cron","event"].map(L=>E.jsx("button",{onClick:()=>C(L),className:`text-[11px] px-2 py-0.5 rounded-full border transition-colors ${S[L]?"bg-primary text-primary-foreground border-primary":"bg-transparent text-muted-foreground border-border hover:border-muted-foreground"}`,children:L},L))]}),E.jsxs(Re,{size:"sm",onClick:n,className:"gap-1",children:[E.jsx(mv,{className:"w-4 h-4"})," New schedule"]})]}),N.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."}),N.map(L=>{var R,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:L.enabled,onChange:I=>a(L.id,I.target.checked),title:L.enabled?"Disable":"Enable",className:"shrink-0"}),E.jsx("span",{className:"font-medium text-sm truncate max-w-[280px]",title:L.name,children:L.name}),E.jsx("span",{className:"shrink-0 text-[10px] font-mono px-1.5 py-0.5 rounded bg-muted text-muted-foreground",children:L.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:L.trigger.kind}),f.has(L.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(Id,{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:sOe(L)?"system":((F=(R=L.createdBy)==null?void 0:R.email)==null?void 0:F.split("@")[0])??"unknown"})]}),E.jsx("div",{className:"mt-1 text-xs text-muted-foreground truncate",children:iOe(L)}),E.jsxs("div",{className:"mt-1 flex items-center gap-3 text-xs text-muted-foreground",children:[E.jsxs("span",{children:["Next: ",L.enabled?uD(L.nextRun):"disabled"]}),L.lastRun&&E.jsxs("button",{className:`px-1.5 py-0.5 rounded text-[10px] ${oOe[L.lastRun.status]??""}`,onClick:()=>u(L.lastRun.sessionId),title:"Open last run",children:["last: ",L.lastRun.status," ",uD(L.lastRun.at)]}),E.jsxs("span",{children:["runs: ",L.runCount??0]})]})]}),E.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[f.has(L.id)?E.jsx(Re,{variant:"ghost",size:"icon",title:"Stop run",onClick:()=>c(L.id),children:E.jsx(Oj,{className:"w-4 h-4 text-destructive"})}):E.jsx(Re,{variant:"ghost",size:"icon",title:"Run now",onClick:()=>P(L),children:E.jsx(sG,{className:"w-4 h-4"})}),E.jsx(Re,{variant:"ghost",size:"icon",title:"Edit",onClick:()=>r(L),children:E.jsx(gE,{className:"w-4 h-4"})}),E.jsx(Re,{variant:"ghost",size:"icon",title:"Delete",onClick:()=>i(L.id),children:E.jsx(Rd,{className:"w-4 h-4 text-destructive"})})]})]}),h===L.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:lOe(L.task.kind)}),E.jsx("input",{type:"text",className:"w-full text-sm border rounded px-2 py-1.5 bg-background",placeholder:cOe(L.task.kind),value:m,onChange:I=>v(I.target.value),onKeyDown:I=>{I.key==="Enter"&&!O&&D(),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:D,disabled:O,children:O?"Running...":"Run"})]})]})]},L.id)})]})}function dOe(e){const{directives:t}=Uke(e),n=EA(e,{strict:!0}).groups.some(r=>r.split(",").some(i=>/^\s*engine\s*:/i.test(i)));return{engine:t.engine,model:t.model,engineExplicit:n}}const hOe=/^(engine|model)\s*:/i;function pOe(e,t){var h;const{groups:n,body:r}=EA(e,{strict:!0}),i=[];let a=!1;for(const p of n)for(const m of p.split(",").map(v=>v.trim()).filter(Boolean)){if(hOe.test(m))continue;if(m.includes(":")){i.push(m);continue}const v=!a&&!!Y1(m);a=!0,v||i.push(m)}const s=t.model?(h=Y1(t.model))==null?void 0:h.engine:void 0,c=t.engine&&t.engine!==s?t.engine:void 0,f=[...[c&&`engine:${c}`,t.model&&`model:${t.model}`].filter(Boolean),...i];return f.length?`[${f.join(",")}] ${r}`:r}function mOe(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 gOe=[{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}],vOe=[{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 yOe({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 bOe({prompt:e,onChange:t,getToken:n}){const{engines:r}=j6(n),i=r.length>0,a=y.useMemo(()=>dOe(e),[e,i]),s=a.engineExplicit?r.find(v=>v.name===a.engine):void 0,c=s?[{engine:s.name,models:s.models}]:r.map(v=>({engine:v.name,models:v.models})),u=(v,x)=>!v||x.includes(v),f=u(a.model,c.flatMap(v=>v.models.map(x=>x.value))),h=u(a.engine,r.map(v=>v.name)),p=v=>t(pOe(e,{engine:a.engineExplicit?a.engine:void 0,model:a.model,...v})),m="h-8 rounded-md border border-input bg-background px-2 text-xs";return E.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[E.jsx("label",{className:"text-xs text-muted-foreground",children:"Runtime"}),E.jsxs("select",{className:m,disabled:!i,value:a.engine??"",onChange:v=>p({engine:v.target.value||void 0,model:void 0}),children:[E.jsx("option",{value:"",children:"Default engine (agent config)"}),!h&&E.jsxs("option",{value:a.engine,children:[a.engine," — not registered on this server"]}),r.map(v=>E.jsx("option",{value:v.name,children:v.name},v.name))]}),E.jsxs("select",{className:m,disabled:!i,value:a.model??"",onChange:v=>p({model:v.target.value||void 0}),children:[E.jsx("option",{value:"",children:"Default model (agent config)"}),!f&&E.jsxs("option",{value:a.model,children:[a.model," — not offered by this engine"]}),c.map(({engine:v,models:x})=>E.jsx("optgroup",{label:v,children:x.filter(b=>b.value).map(b=>E.jsx("option",{value:b.value,children:b.label||b.value},`${v}:${b.value}`))},v))]}),!i&&E.jsx("span",{className:"text-[10px] text-muted-foreground",children:"loading engines…"})]})}function fD({getToken:e,initial:t,onSave:n,onCancel:r,skills:i=[],workspaceFiles:a=[]}){const s=y.useMemo(()=>Intl.DateTimeFormat().resolvedOptions().timeZone,[]),[c,u]=y.useState((t==null?void 0:t.name)??"New schedule"),[f,h]=y.useState((t==null?void 0:t.enabled)??!0),[p,m]=y.useState((t==null?void 0:t.trigger)??{kind:"cron",expr:"0 9 * * *",tz:s}),[v,x]=y.useState((t==null?void 0:t.task)??{kind:"prompt",prompt:""}),[b,S]=y.useState(!1),[_,O]=y.useState(null),k=y.useMemo(()=>{if(p.kind!=="cron")return"";try{return z6.toString(p.expr)}catch{return"Invalid cron"}},[p]),T=async()=>{S(!0),O(null);try{await n({name:c,enabled:f,trigger:p,task:v})}catch(C){O(C.message)}finally{S(!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:c,onChange:C=>u(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:p.kind===C?"default":"outline",size:"sm",onClick:()=>{m(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:s})},children:C},C))}),p.kind==="once"&&E.jsx(In,{type:"datetime-local",value:mOe(p.at),onChange:C=>{const N=new Date(C.target.value);isNaN(N.getTime())||m({kind:"once",at:N.getTime()})}}),p.kind==="interval"&&E.jsxs("div",{className:"space-y-2",children:[E.jsx("div",{className:"flex gap-1 flex-wrap",children:gOe.map(C=>E.jsx(Re,{type:"button",variant:p.everyMs===C.ms?"default":"outline",size:"sm",onClick:()=>m({kind:"interval",everyMs:C.ms}),children:C.label},C.ms))}),E.jsx(In,{type:"number",min:1,value:Math.round(p.everyMs/1e3),onChange:C=>m({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(p.everyMs/1e3),"s"]})]}),p.kind==="cron"&&E.jsxs("div",{className:"space-y-2",children:[E.jsx("div",{className:"flex gap-1 flex-wrap",children:vOe.map(C=>E.jsx(Re,{type:"button",variant:"outline",size:"sm",onClick:()=>m({kind:"cron",expr:C.expr,tz:s}),children:C.label},C.expr))}),E.jsx(In,{className:"font-mono text-xs",value:p.expr,onChange:C=>m({...p,expr:C.target.value}),placeholder:"0 9 * * *"}),E.jsx(In,{className:"text-xs",value:p.tz,onChange:C=>m({...p,tz:C.target.value}),placeholder:"IANA timezone"}),E.jsxs("p",{className:"text-xs text-muted-foreground",children:[k," (",p.tz,")"]})]}),p.kind==="event"&&E.jsxs("div",{className:"space-y-2",children:[E.jsx(In,{value:p.source,onChange:C=>m({...p,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/",p.source||":source"]})," or ",E.jsx("code",{children:"ctx.emitEvent()"}),"."]}),E.jsx(yOe,{match:p.match??{},onChange:C=>m({...p,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:v.kind===C?"default":"outline",size:"sm",onClick:()=>x(C==="prompt"?{kind:"prompt",prompt:""}:{kind:"bash",command:""}),children:C==="prompt"?"Prompt":"Bash command"},C))}),v.kind==="prompt"?E.jsxs(E.Fragment,{children:[E.jsx(bOe,{prompt:v.prompt,getToken:e,onChange:C=>x({...v,prompt:C})}),E.jsx(R6,{rows:5,value:v.prompt,onChange:C=>x({...v,prompt:C}),placeholder:"What should the agent do? (@ for skills, / for commands)",skills:i,workspaceFiles:a,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"})]}):v.kind==="bash"?E.jsx(Ey,{rows:3,className:"font-mono text-xs",value:v.command,onChange:C=>x({...v,command:C.target.value}),placeholder:"ls -la ~/"}):E.jsxs("p",{className:"text-xs text-muted-foreground",children:["Command: ",v.command]})]}),E.jsxs("div",{className:"flex items-center gap-2",children:[E.jsx("input",{id:"sched-enabled",type:"checkbox",checked:f,onChange:C=>h(C.target.checked)}),E.jsx("label",{htmlFor:"sched-enabled",className:"text-sm",children:"Enabled"})]}),_&&E.jsx("p",{className:"text-xs text-destructive",children:_}),E.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[E.jsx(Re,{variant:"outline",onClick:r,disabled:b,children:"Cancel"}),E.jsx(Re,{onClick:T,disabled:b,children:b?"Saving…":"Save"})]})]})}const dD=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}=fj(),{schedules:m,serverRunningIds:v,create:x,update:b,remove:S,toggle:_,runNow:O,cancelRun:k}=eOe(t,f,r);y.useImperativeHandle(u,()=>({open:()=>h(!0)}),[]);const[T,C]=y.useState(null),[N,P]=y.useState(!1),[D,L]=y.useState(new Set),R=()=>{C(null),P(!1)},F=async(I,q)=>{L(G=>new Set(G).add(I));try{return await O(I,q)}finally{setTimeout(()=>{L(G=>{const K=new Set(G);return K.delete(I),K})},1500)}};return E.jsxs(Es,{open:f,onOpenChange:I=>{h(I),I||R()},children:[E.jsx(lh,{asChild:!0,children:c||E.jsx(Re,{variant:"ghost",size:"icon",className:"h-8 w-8",title:"Scheduled Tasks",children:E.jsx(fE,{className:"w-4 h-4"})})}),E.jsxs(uo,{className:"max-w-[95vw] sm:max-w-2xl",children:[E.jsx(jl,{children:E.jsx(Ss,{children:N?"New Schedule":T?`Edit: ${T.name}`:"Scheduled Tasks"})}),N?E.jsx(fD,{getToken:t,onSave:async I=>{await x(I),R()},onCancel:R,skills:a,workspaceFiles:s},"__new__"):T?E.jsx(fD,{getToken:t,initial:T,onSave:async I=>{await b(T.id,I),R()},onCancel:R,skills:a,workspaceFiles:s},T.id):E.jsx(fOe,{schedules:m,currentUserUid:p==null?void 0:p.uid,onCreate:()=>P(!0),onEdit:I=>C(I),onDelete:I=>{confirm("Delete this schedule?")&&S(I)},onToggle:_,onRunNow:F,onCancel:k,runningIds:new Set([...i,...v,...D]),onOpenRun:I=>{h(!1),n(I)}})]})]})});function $6(){const e=localStorage.getItem("dark-mode");return e!==null?e==="true":window.matchMedia("(prefers-color-scheme: dark)").matches}let Il=typeof window<"u"?$6():!0;const X1=new Set;function B6(){document.documentElement.classList.toggle("dark",Il),localStorage.setItem("dark-mode",String(Il)),X1.forEach(e=>e())}typeof window<"u"&&B6();function U6(e){e!==Il&&(Il=e,B6())}function xOe(e){X1.add(e);const t=n=>{n.key==="dark-mode"&&U6($6())};return window.addEventListener("storage",t),()=>{X1.delete(e),window.removeEventListener("storage",t)}}function wOe(){return{dark:y.useSyncExternalStore(xOe,()=>Il,()=>Il),toggle:()=>U6(!Il)}}const hD=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 T=k.filter(N=>N.sessionId!==b.sessionId);return[{id:`${b.sessionId}-${Date.now()}`,sessionId:b.sessionId,preview:b.preview,title:b.title,ts:Date.now()},...T].slice(0,hD)})}if(b.type==="unread_sync"){const O={};for(const[k,T]of Object.entries(b.sessions)){if(k===s.current&&c.current){(_=u.current)==null||_.markRead(k);continue}O[k]={count:T.count,preview:T.preview,source:T.source,title:T.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,hD)})},[]),v=Object.keys(n).length;y.useEffect(()=>{const b="Shraga";document.title=v>0?`(${v}) ${b}`:b,SOe(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 Zc=null,aw=null;function SOe(e){if(typeof document>"u")return;if(!aw){const n=document.querySelector('link[rel="icon"]');aw=(n==null?void 0:n.href)??""}if(e===0){pD(aw||"");return}Zc||(Zc=document.createElement("canvas"),Zc.width=32,Zc.height=32);const t=Zc.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),pD(Zc.toDataURL()))}function pD(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 _Oe({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(Pl,{className:"w-3 h-3 text-muted-foreground"})}),E.jsxs("div",{className:"flex items-start gap-2.5",children:[E.jsx(vw,{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 mD(){return new URLSearchParams(window.location.search).get("session")||void 0}function AOe(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 kOe(){return E.jsx(Uq,{value:{},children:E.jsx(OOe,{})})}function OOe(){var $n,xr;const e=Sa(),{dark:t,toggle:n}=wOe(),{user:r,token:i,getToken:a,loading:s,mode:c,needsSetup:u,loginLocal:f,registerLocal:h,logout:p}=fj(),[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),T=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)},[]),[C,N]=y.useState({}),P=y.useRef(null),[D,L]=y.useState(0),[R,F]=y.useState(0),[I,q]=y.useState(new Set),[G,K]=y.useState([]),[z,V]=y.useState([]),[H,Y]=y.useState(0),[j,U]=y.useState(new Set),[Z,B]=y.useState(!1),[fe,be]=y.useState(()=>localStorage.getItem("shraga:authorized")==="1"?!0:null),[ge,Ie]=y.useState(()=>mD()),We=y.useCallback((he,Ue)=>Ie(he),[]),de=y.useCallback((he,Ue)=>Ie(Ue),[]),ke=y.useCallback((he,Ue)=>{},[]),we=y.useCallback(()=>L(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&&(Y(he=>he+1),bl("/api/workspace",a).then(he=>he.json()).then(he=>V(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"?(q(Ue=>new Set(Ue).add(he.scheduleId)),we()):he.type==="schedule:run_finished"?(q(Ue=>{const ot=new Set(Ue);return ot.delete(he.scheduleId),ot}),we()):he.type==="schedule:deleted"&&q(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":U(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}=eq(i,a,kn),{unreads:ti,toasts:Oo,markRead:St,dismissToast:Co,addToast:ae,handleUnreadEvent:ve}=EOe(zn,ge);De.current=ve,_e.current=St,Lq({socket:zn,getToken:a,pushEnabled:Z,activeSessionId:ge,switchTo:()=>{},openSession:We,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(()=>{zq()},[]),y.useEffect(()=>{AOe(ge),ge&&St(ge)},[ge,St]),y.useEffect(()=>{const he=()=>Ie(mD());return window.addEventListener("popstate",he),()=>window.removeEventListener("popstate",he)},[]),y.useEffect(()=>{i&&(bl("/api/config",a).then(he=>he.json()).then(N).catch(()=>{}),bl("/api/skills",a).then(he=>he.json()).then(he=>K(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(()=>z.filter(he=>he.type==="file").map(he=>he.path),[z]),pt=y.useMemo(()=>({socket:zn,connectionStatus:ur,getToken:a,token:i,agentConfig:C,setAgentConfig:N,activeSessionId:ge,skills:G,workspaceFiles:Xe,openSchedules:()=>{var he;return(he=P.current)==null?void 0:he.open()},markRead:St,bumpSidebar:we,assignSession:de,renameTab:ke,openSession:We}),[zn,ur,a,i,C,ge,G,Xe,St,we,de,ke,We]);return s?E.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground text-sm",children:"Loading…"}):!r||!i?E.jsx(MG,{mode:c,needsSetup:u,onLoginLocal:f,onRegisterLocal:h}):fe===null?E.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground text-sm",children:"Verifying access…"}):!fe||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($0,{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(IG,{getToken:a,userEmail:r.email??""}):window.location.pathname==="/cli-auth"?E.jsx(RG,{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(FT,{className:"w-4 h-4"})})]}),E.jsx("div",{className:"flex-1 min-h-0",children:E.jsx(Bae,{getToken:a,activeSessionId:ge,onSelect:(he,Ue)=>{We(he,Ue),St(he),window.innerWidth<640&&x(!1)},onNew:ze,refreshKey:D,workspaceRefreshKey:H,onRefreshWorkspace:ht,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(FT,{className:"w-4 h-4"}):E.jsx(aG,{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(dG,{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(KT,{className:"w-4 h-4"}):E.jsx(UT,{className:"w-4 h-4"})}),($n=e.headerActions)==null?void 0:$n.call(e),E.jsx(rD,{getToken:a}),E.jsx(oD,{getToken:a,onSkillsChange:K}),E.jsx(lD,{getToken:a}),E.jsx(dD,{ref:P,getToken:a,refreshKey:R,runningIds:I,onOpenSession:he=>We(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($0,{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:T,children:E.jsx(Wq,{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(rD,{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(Aj,{className:"w-3.5 h-3.5"})," MCPs"]})}),E.jsx(oD,{getToken:a,onSkillsChange:K,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(gw,{className:"w-3.5 h-3.5"})," Skills"]})}),E.jsx(lD,{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(mw,{className:"w-3.5 h-3.5"})," Modules"]})}),E.jsx(dD,{getToken:a,refreshKey:R,runningIds:I,onOpenSession:he=>We(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(fE,{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(KT,{className:"w-3.5 h-3.5"}):E.jsx(UT,{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($0,{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(Bq,{value:pt,children:E.jsx("div",{className:"flex-1 min-h-0",children:E.jsx(Xke,{nodeId:"main",sessionId:ge},ge??"new")})})]}),E.jsx(_Oe,{toasts:Oo,onDismiss:Co,onOpen:he=>{We(he),St(he)}})]})}const gD="unclaw:",COe="shraga:";function TOe(){try{const e=Object.keys(localStorage).filter(t=>t.startsWith(gD));for(const t of e){const n=COe+t.slice(gD.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))}}TOe();n9.createRoot(document.getElementById("root")).render(E.jsx(y.StrictMode,{children:E.jsx(kOe,{})}));
|
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-519evGGj.js"></script>
|
|
17
17
|
<link rel="stylesheet" crossorigin href="/assets/index-CJDfTuzn.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.96",
|
|
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",
|
|
@@ -21,7 +21,8 @@ interface AgentConfig {
|
|
|
21
21
|
|
|
22
22
|
const FALLBACK_MODELS: EngineModel[] = [
|
|
23
23
|
{ value: '', label: 'Default (claude-sonnet-5)' },
|
|
24
|
-
{ value: 'claude-fable-5', label: 'Fable 5 — frontier, most capable' },
|
|
24
|
+
{ value: 'claude-fable-5-1', label: 'Fable 5.1 — frontier, most capable' },
|
|
25
|
+
{ value: 'claude-fable-5', label: 'Fable 5' },
|
|
25
26
|
{ value: 'claude-opus-5', label: 'Opus 5 — most capable, best for complex/agentic tasks' },
|
|
26
27
|
{ value: 'claude-opus-4-8', label: 'Opus 4.8' },
|
|
27
28
|
{ value: 'claude-opus-4-7', label: 'Opus 4.7' },
|
|
@@ -207,7 +207,8 @@ export class ClaudeCodeEngine implements AgentEngine {
|
|
|
207
207
|
getModels(): EngineModel[] {
|
|
208
208
|
return [
|
|
209
209
|
{ value: '', label: `Default (${DEFAULT_MODEL})` },
|
|
210
|
-
{ value: 'claude-fable-5', label: 'Fable 5 — frontier, most capable' },
|
|
210
|
+
{ value: 'claude-fable-5-1', label: 'Fable 5.1 — frontier, most capable' },
|
|
211
|
+
{ value: 'claude-fable-5', label: 'Fable 5' },
|
|
211
212
|
{ value: 'claude-opus-5', label: 'Opus 5 — most capable' },
|
|
212
213
|
{ value: 'claude-opus-4-8', label: 'Opus 4.8' },
|
|
213
214
|
{ value: 'claude-opus-4-7', label: 'Opus 4.7' },
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
/** Canonical short aliases → concrete Anthropic model ids. */
|
|
10
10
|
export const MODEL_ALIASES: Record<string, string> = {
|
|
11
|
-
fable: 'claude-fable-5',
|
|
11
|
+
fable: 'claude-fable-5-1',
|
|
12
|
+
'fable-5-1': 'claude-fable-5-1',
|
|
12
13
|
'fable-5': 'claude-fable-5',
|
|
13
14
|
opus: 'claude-opus-5',
|
|
14
15
|
'opus-5': 'claude-opus-5',
|