jinn-cli 0.7.2 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/dist/src/engines/claude.d.ts.map +1 -1
  2. package/dist/src/engines/claude.js +9 -0
  3. package/dist/src/engines/claude.js.map +1 -1
  4. package/dist/src/gateway/__tests__/api-last-n.test.d.ts +2 -0
  5. package/dist/src/gateway/__tests__/api-last-n.test.d.ts.map +1 -0
  6. package/dist/src/gateway/__tests__/api-last-n.test.js +32 -0
  7. package/dist/src/gateway/__tests__/api-last-n.test.js.map +1 -0
  8. package/dist/src/gateway/api.d.ts.map +1 -1
  9. package/dist/src/gateway/api.js +30 -0
  10. package/dist/src/gateway/api.js.map +1 -1
  11. package/dist/src/gateway/lifecycle.d.ts.map +1 -1
  12. package/dist/src/gateway/lifecycle.js +1 -0
  13. package/dist/src/gateway/lifecycle.js.map +1 -1
  14. package/dist/src/sessions/__tests__/callbacks.test.d.ts +2 -0
  15. package/dist/src/sessions/__tests__/callbacks.test.d.ts.map +1 -0
  16. package/dist/src/sessions/__tests__/callbacks.test.js +118 -0
  17. package/dist/src/sessions/__tests__/callbacks.test.js.map +1 -0
  18. package/dist/src/sessions/callbacks.d.ts +1 -1
  19. package/dist/src/sessions/callbacks.js +4 -4
  20. package/dist/src/sessions/callbacks.js.map +1 -1
  21. package/dist/src/sessions/manager.d.ts.map +1 -1
  22. package/dist/src/sessions/manager.js +21 -3
  23. package/dist/src/sessions/manager.js.map +1 -1
  24. package/dist/src/shared/__tests__/rateLimit.test.d.ts +2 -0
  25. package/dist/src/shared/__tests__/rateLimit.test.d.ts.map +1 -0
  26. package/dist/src/shared/__tests__/rateLimit.test.js +108 -0
  27. package/dist/src/shared/__tests__/rateLimit.test.js.map +1 -0
  28. package/dist/src/shared/__tests__/usageAwareness.test.d.ts +2 -0
  29. package/dist/src/shared/__tests__/usageAwareness.test.d.ts.map +1 -0
  30. package/dist/src/shared/__tests__/usageAwareness.test.js +58 -0
  31. package/dist/src/shared/__tests__/usageAwareness.test.js.map +1 -0
  32. package/dist/src/shared/rateLimit.d.ts +7 -0
  33. package/dist/src/shared/rateLimit.d.ts.map +1 -1
  34. package/dist/src/shared/rateLimit.js +31 -0
  35. package/dist/src/shared/rateLimit.js.map +1 -1
  36. package/dist/src/shared/usageAwareness.d.ts.map +1 -1
  37. package/dist/src/shared/usageAwareness.js +7 -0
  38. package/dist/src/shared/usageAwareness.js.map +1 -1
  39. package/dist/web/404.html +1 -1
  40. package/dist/web/_next/static/chunks/{155-592ad81a5c00a38a.js → 155-277bf3022d16e74f.js} +1 -1
  41. package/dist/web/_next/static/chunks/{192-bd69b67fd03b9f3d.js → 192-3064c98adfeef88c.js} +1 -1
  42. package/dist/web/_next/static/chunks/{51-ea7256657692ba90.js → 51-43ce350b707e6b06.js} +1 -1
  43. package/dist/web/_next/static/chunks/app/_not-found/page-1a2952195ec2c3fa.js +1 -0
  44. package/dist/web/_next/static/chunks/app/chat/{page-83a714baeb382ffb.js → page-d9b12d7effe66c59.js} +1 -1
  45. package/dist/web/_next/static/chunks/app/cron/page-03f6c20a2336f185.js +1 -0
  46. package/dist/web/_next/static/chunks/app/kanban/{page-0e1b2a66378b8a6b.js → page-0aa74ece5109e58f.js} +1 -1
  47. package/dist/web/_next/static/chunks/app/{layout-ab9ba2b24a88513d.js → layout-45d8b9cc84f9443f.js} +1 -1
  48. package/dist/web/_next/static/chunks/app/logs/{page-b2ea0e6b92c54706.js → page-0f2b58794d9a97ce.js} +1 -1
  49. package/dist/web/_next/static/chunks/app/org/{page-05c8d33b3bf07d3d.js → page-e51ef93389a23de8.js} +1 -1
  50. package/dist/web/_next/static/chunks/app/{page-57dcf41f8ef011a7.js → page-16b78d2823b60898.js} +1 -1
  51. package/dist/web/_next/static/chunks/app/settings/{page-2903a5e9b8b0fc4a.js → page-8d1048b944663524.js} +1 -1
  52. package/dist/web/_next/static/chunks/app/skills/page-6d9c1d5b03aa86bb.js +1 -0
  53. package/dist/web/_next/static/chunks/{main-app-72a2d12a170701ef.js → main-app-637478e5d2259005.js} +1 -1
  54. package/dist/web/chat.html +1 -1
  55. package/dist/web/chat.txt +3 -3
  56. package/dist/web/cron.html +1 -1
  57. package/dist/web/cron.txt +3 -3
  58. package/dist/web/index.html +1 -1
  59. package/dist/web/index.txt +3 -3
  60. package/dist/web/kanban.html +1 -1
  61. package/dist/web/kanban.txt +3 -3
  62. package/dist/web/logs.html +2 -2
  63. package/dist/web/logs.txt +3 -3
  64. package/dist/web/org.html +1 -1
  65. package/dist/web/org.txt +3 -3
  66. package/dist/web/sessions.html +1 -1
  67. package/dist/web/sessions.txt +2 -2
  68. package/dist/web/settings.html +1 -1
  69. package/dist/web/settings.txt +3 -3
  70. package/dist/web/skills.html +1 -1
  71. package/dist/web/skills.txt +3 -3
  72. package/package.json +1 -1
  73. package/template/AGENTS.md +21 -0
  74. package/template/CLAUDE.md +21 -0
  75. package/dist/web/_next/static/chunks/app/_not-found/page-22b69e9fb96ef3fc.js +0 -1
  76. package/dist/web/_next/static/chunks/app/cron/page-4ede68bcdb3e76ca.js +0 -1
  77. package/dist/web/_next/static/chunks/app/skills/page-971feac69b3a1383.js +0 -1
  78. /package/dist/web/_next/static/{4OBIVkP7CCBmCjhg6p9Id → astVwZfaNwQEC0C3qtVHe}/_buildManifest.js +0 -0
  79. /package/dist/web/_next/static/{4OBIVkP7CCBmCjhg6p9Id → astVwZfaNwQEC0C3qtVHe}/_ssgManifest.js +0 -0
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[492],{3315:(e,t,l)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),Object.defineProperty(t,"default",{enumerable:!0,get:function(){return o}});let r=l(4130),n=l(7791),o=function(){return(0,r.jsx)("html",{children:(0,r.jsx)("body",{children:(0,r.jsx)(n.HTTPAccessErrorFallback,{status:404,message:"This page could not be found."})})})};("function"==typeof t.default||"object"==typeof t.default&&null!==t.default)&&void 0===t.default.__esModule&&(Object.defineProperty(t.default,"__esModule",{value:!0}),Object.assign(t.default,t),e.exports=t.default)},6026:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),Object.defineProperty(t,"styles",{enumerable:!0,get:function(){return l}});let l={error:{fontFamily:'system-ui,"Segoe UI",Roboto,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji"',height:"100vh",textAlign:"center",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},desc:{display:"inline-block"},h1:{display:"inline-block",margin:"0 20px 0 0",padding:"0 23px 0 0",fontSize:24,fontWeight:500,verticalAlign:"top",lineHeight:"49px"},h2:{fontSize:14,fontWeight:400,lineHeight:"49px",margin:0}};("function"==typeof t.default||"object"==typeof t.default&&null!==t.default)&&void 0===t.default.__esModule&&(Object.defineProperty(t.default,"__esModule",{value:!0}),Object.assign(t.default,t),e.exports=t.default)},7791:(e,t,l)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),Object.defineProperty(t,"HTTPAccessErrorFallback",{enumerable:!0,get:function(){return o}});let r=l(4130),n=l(6026);function o(e){let{status:t,message:l}=e;return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("title",{children:t+": "+l}),(0,r.jsx)("div",{style:n.styles.error,children:(0,r.jsxs)("div",{children:[(0,r.jsx)("style",{dangerouslySetInnerHTML:{__html:"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}),(0,r.jsx)("h1",{className:"next-error-h1",style:n.styles.h1,children:t}),(0,r.jsx)("div",{style:n.styles.desc,children:(0,r.jsx)("h2",{style:n.styles.h2,children:l})})]})})]})}("function"==typeof t.default||"object"==typeof t.default&&null!==t.default)&&void 0===t.default.__esModule&&(Object.defineProperty(t.default,"__esModule",{value:!0}),Object.assign(t.default,t),e.exports=t.default)},9617:(e,t,l)=>{(window.__NEXT_P=window.__NEXT_P||[]).push(["/_not-found/page",function(){return l(3315)}])}},e=>{e.O(0,[344,144,358],()=>e(e.s=9617)),_N_E=e.O()}]);
@@ -1 +1 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[457],{4527:(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>eL});var a=r(4130),n=r(7946),s=r(2467),l=r(6654),i=r(2845),o=r(7192),c=r(7053),d=r.n(c),u=r(2784),x=r(263),p=r(8574),m=r(841),h=r(6429),g=r(4535),v=r(937),f=r(4607),b=r(4722),y=r(3160),j=r(8689),w=r(6063);function k(e){let{...t}=e;return(0,a.jsx)(j.bL,{"data-slot":"context-menu",...t})}function N(e){let{...t}=e;return(0,a.jsx)(j.l9,{"data-slot":"context-menu-trigger",...t})}function S(e){let{className:t,...r}=e;return(0,a.jsx)(j.ZL,{children:(0,a.jsx)(j.UC,{"data-slot":"context-menu-content",className:(0,w.cn)("z-50 max-h-(--radix-context-menu-content-available-height) min-w-[8rem] origin-(--radix-context-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",t),...r})})}function C(e){let{className:t,inset:r,variant:n="default",...s}=e;return(0,a.jsx)(j.q7,{"data-slot":"context-menu-item","data-inset":r,"data-variant":n,className:(0,w.cn)("relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!",t),...s})}function I(e){let{className:t,...r}=e;return(0,a.jsx)(j.wv,{"data-slot":"context-menu-separator",className:(0,w.cn)("-mx-1 my-1 h-px bg-border",t),...r})}var D=r(6960);let M="jinn-sidebar-collapsed",L="jinn-sidebar-expanded",E="jinn-pinned-sessions";function A(e){if(!e)return"";let t=new Date(e),r=Date.now()-t.getTime();return r<6e4?"now":r<36e5?"".concat(Math.floor(r/6e4),"m"):r<864e5?new Date(e).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):r<1728e5?"yesterday":new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric"})}function z(){try{let e=localStorage.getItem("jinn-read-sessions");return e?new Set(JSON.parse(e)):new Set}catch(e){return new Set}}function _(e){try{localStorage.setItem(E,JSON.stringify(Array.from(e)))}catch(e){}}function T(e){return"cron"===e.source||(e.sourceRef||"").startsWith("cron:")}function R(e){return e.lastActivity||e.createdAt||""}function F(e){return[...e].sort((e,t)=>R(t).localeCompare(R(e)))}function U(e,t){return"running"===e.status?"var(--system-blue)":"error"===e.status?"var(--system-red)":t.has(e.id)?"var(--text-quaternary)":"var(--system-green)"}function W(e){let{color:t,pulse:r=!1,className:n}=e;return(0,a.jsx)("span",{className:(0,w.cn)("shrink-0 rounded-full",n),style:{background:t,animation:r?"sidebar-pulse 2s ease-in-out infinite":"none",boxShadow:r?"0 0 8px ".concat(t):"none"}})}function B(e){let{icon:t,label:r,count:n}=e;return(0,a.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2",children:[(0,a.jsx)("span",{className:"text-xs",children:t}),(0,a.jsx)("span",{className:"text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:r}),"number"==typeof n&&(0,a.jsx)("span",{className:"ml-auto rounded bg-[var(--fill-tertiary)] px-1.5 py-0.5 text-[10px] text-[var(--text-secondary)]",children:n})]})}function K(e){var t;let{selectedId:r,onSelect:s,onNewChat:l,onDelete:i,onSessionsLoaded:o,onEmployeeSessionsAvailable:c}=e,{settings:j}=(0,b.t0)(),K=null!=(t=j.portalName)?t:"Jinn",P=K.toLowerCase(),{data:q,isLoading:O}=(0,y.te)(),V=(0,y.tS)(),J=(0,y.Q6)(),H=(0,n.useMemo)(()=>{if(!q)return[];let e=q.filter(e=>"web"===e.source||"cron"===e.source||"whatsapp"===e.source||"discord"===e.source||!e.source);return e.sort((e,t)=>{let r=e.lastActivity||e.createdAt||"";return(t.lastActivity||t.createdAt||"").localeCompare(r)}),e},[q]),[Q,$]=(0,n.useState)(""),[G,Y]=(0,n.useState)(null),[X,Z]=(0,n.useState)(new Set),[ee,et]=(0,n.useState)(new Set),[er,ea]=(0,n.useState)(new Set),[en,es]=(0,n.useState)({}),[el,ei]=(0,n.useState)({}),[eo,ec]=(0,n.useState)(new Map),ed=(0,n.useRef)(o);(0,n.useEffect)(()=>{ed.current=o},[o]),(0,n.useEffect)(()=>{H.length>0&&(0,n.startTransition)(()=>{var e;null==(e=ed.current)||e.call(ed,H)})},[H]),(0,n.useEffect)(()=>{Z(z()),et(function(){try{let e=localStorage.getItem(E);return e?new Set(JSON.parse(e)):new Set}catch(e){return new Set}}()),ea(function(){try{let e=localStorage.getItem(M);return e?new Set(JSON.parse(e)):new Set}catch(e){return new Set}}()),es(function(){try{let e=localStorage.getItem(L);return e?JSON.parse(e):{}}catch(e){return{}}}())},[]),(0,n.useEffect)(()=>{if(r){let e=z();e.add(r);let t=Array.from(e);t.length>500&&t.splice(0,t.length-500),localStorage.setItem("jinn-read-sessions",JSON.stringify(t)),Z(e=>{let t=new Set(e);return t.add(r),t})}},[r]);let eu=(0,n.useCallback)(()=>{ea(e=>{let t=new Set(e);t.has("cron")?t.delete("cron"):t.add("cron");try{localStorage.setItem(M,JSON.stringify(Array.from(t)))}catch(e){}return t})},[]),ex=(0,n.useCallback)(e=>{es(t=>{let r={...t,[e]:!t[e]};try{localStorage.setItem(L,JSON.stringify(r))}catch(e){}return r[e]||ei(t=>{if(!t[e])return t;let{[e]:r,...a}=t;return a}),r})},[]),ep=(0,n.useCallback)(e=>{et(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),_(r),r})},[]),em=(0,n.useCallback)(e=>{let t=z();for(let r of e)t.add(r.id);let r=Array.from(t);r.length>500&&r.splice(0,r.length-500),localStorage.setItem("jinn-read-sessions",JSON.stringify(r)),Z(t=>{let r=new Set(t);for(let t of e)r.add(t.id);return r})},[]);async function eh(e,t){let a=t.map(e=>e.id);try{await J.mutateAsync(a),et(t=>{let r=new Set(t);for(let t of(r.delete("emp:".concat(e)),a))r.delete(t);return _(r),r}),(0,n.startTransition)(()=>{r&&a.includes(r)&&l()})}catch(e){}}async function eg(e){try{await V.mutateAsync(e),et(t=>{if(!t.has(e))return t;let r=new Set(t);return r.delete(e),_(r),r}),(0,n.startTransition)(()=>{i?i(e):r===e&&l()})}catch(e){}}let ev=Q.trim()?H.filter(e=>{let t=Q.toLowerCase(),r=e.employee?eo.get(e.employee):void 0;return e.id.toLowerCase().includes(t)||e.employee&&e.employee.toLowerCase().includes(t)||(null==r?void 0:r.displayName)&&r.displayName.toLowerCase().includes(t)||e.title&&e.title.toLowerCase().includes(t)}):H,ef=[],eb=[],ey=new Map;for(let e of ev)if(T(e))ef.push(e);else if(T(e)||e.employee&&e.employee!==P){let t=e.employee;ey.has(t)||ey.set(t,[]),ey.get(t).push(e)}else eb.push(e);let ej=[];for(let[e,t]of ey){let r=F(t);ej.push({type:"employee",employeeName:e,employeeData:eo.get(e),sessions:r,sortKey:R(r[0]),pinKey:"emp:".concat(e)})}if(eb.length>0){let e=F(eb);ej.push({type:"employee",employeeName:P,employeeData:{name:P,displayName:K,emoji:"\uD83D\uDCAC",department:"direct",role:"",rank:"manager",engine:"",model:"",persona:""},sessions:e,sortKey:R(e[0]),pinKey:"emp:".concat(P)})}let ew=ej.filter(e=>ee.has(e.pinKey)).sort((e,t)=>t.sortKey.localeCompare(e.sortKey)),ek=ej.filter(e=>!ee.has(e.pinKey)).sort((e,t)=>t.sortKey.localeCompare(e.sortKey)),eN=er.has("cron"),eS=F(ef);function eC(e,t){var n,l;let i=e.id===r,o=U(e,X),d="running"===e.status,m=(n=e.title,l=e.employee,n?"Jinn"!==K&&n.startsWith("Jinn - ")?K+n.slice(4):n:l||K),h=A(R(e)),g=ee.has(e.id),v=G===e.id;return(0,a.jsxs)(k,{children:[(0,a.jsx)(N,{asChild:!0,children:(0,a.jsxs)("button",{onClick:()=>{s(e.id),null==c||c(null!=t?t:[e])},onMouseEnter:()=>Y(e.id),onMouseLeave:()=>{G!=="menu:".concat(e.id)&&Y(null)},className:(0,w.cn)("group relative flex w-full items-center gap-2.5 border-l-2 px-4 py-2 text-left transition-colors",t?"pl-[67px]":"pl-6",i?"border-l-[var(--accent)] bg-[var(--fill-secondary)]":"border-l-transparent hover:bg-accent"),children:[(0,a.jsx)(W,{color:o,pulse:d,className:"size-1.5"}),(0,a.jsx)("span",{className:(0,w.cn)("min-w-0 flex-1 truncate text-xs",i?"font-semibold text-foreground":"text-[var(--text-secondary)]"),children:m||"Untitled"}),g?(0,a.jsx)(u.A,{className:(0,w.cn)("size-3 shrink-0 text-[var(--accent)]",v&&"hidden lg:hidden")}):null,(0,a.jsx)("span",{className:(0,w.cn)("shrink-0 text-[10px] text-[var(--text-quaternary)]",v&&"lg:hidden"),children:h}),(0,a.jsx)("button",{onClick:t=>{t.stopPropagation(),Y("menu:".concat(e.id))},className:(0,w.cn)("hidden shrink-0 text-muted-foreground transition-colors hover:text-foreground",v&&"lg:block"),children:(0,a.jsx)(x.A,{className:"size-3.5"})}),G==="menu:".concat(e.id)?(0,a.jsxs)("div",{className:"absolute right-2 top-full z-50 min-w-[140px] overflow-hidden rounded-lg border border-border bg-[var(--material-thick)] py-1 shadow-[var(--shadow-overlay)] backdrop-blur-xl",onMouseLeave:()=>Y(null),children:[(0,a.jsxs)("button",{onClick:t=>{t.stopPropagation(),ep(e.id),Y(null)},className:"flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs text-foreground transition-colors hover:bg-accent",children:[(0,a.jsx)(u.A,{className:"size-3"})," ",g?"Unpin":"Pin"]}),(0,a.jsx)("div",{className:"my-0.5 border-t border-border"}),(0,a.jsxs)("button",{onClick:t=>{t.stopPropagation(),Y(null),window.confirm("Delete this session?")&&eg(e.id)},className:"flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs text-[var(--system-red)] transition-colors hover:bg-accent",children:[(0,a.jsx)(p.A,{className:"size-3"})," Delete"]})]}):null]})}),(0,a.jsxs)(S,{children:[(0,a.jsx)(C,{onClick:()=>ep(e.id),children:g?"Unpin":"Pin"}),(0,a.jsx)(I,{}),(0,a.jsx)(C,{variant:"destructive",onClick:()=>{window.confirm("Delete this session?")&&eg(e.id)},children:"Delete session"})]})]},e.id)}function eI(e){let t=e.employeeName,n=e.sessions,l=n[0],i=e.employeeData,o=(null==i?void 0:i.displayName)||t,d=(null==i?void 0:i.emoji)||"\uD83E\uDD16",m=(null==i?void 0:i.department)||"",h=A(R(l)),g=U(l,X),v="running"===l.status,f=n.some(e=>e.id===r),b=ee.has(e.pinKey),y=G===e.pinKey,j=n.length,I=en[t]||!1,D=n.some(e=>!X.has(e.id)&&"running"!==e.status&&"error"!==e.status);return(0,a.jsxs)("div",{children:[(0,a.jsxs)(k,{children:[(0,a.jsx)(N,{asChild:!0,children:(0,a.jsxs)("button",{onClick:()=>(function(e){let t=e.employeeName,r=e.sessions;if(r.length>1){let e=en[t]||!1;ex(t),e||(s(r[0].id),null==c||c(r))}else s(r[0].id),null==c||c(r)})(e),onMouseEnter:()=>Y(e.pinKey),onMouseLeave:()=>{G!=="menu:".concat(e.pinKey)&&Y(null)},className:(0,w.cn)("group relative flex w-full items-center gap-3 border-l-2 px-4 py-3 text-left transition-colors",f?"border-l-[var(--accent)] bg-[var(--fill-secondary)]":"border-l-transparent hover:bg-accent"),children:[(0,a.jsxs)("div",{className:"relative flex size-9 shrink-0 items-center justify-center rounded-full bg-[var(--fill-secondary)] text-lg",children:[d,(0,a.jsx)(W,{color:g,pulse:v,className:"absolute -bottom-0.5 -right-0.5 size-2.5 border-2 border-[var(--sidebar-bg)]"})]}),(0,a.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,a.jsxs)("div",{className:"mb-0.5 flex items-baseline gap-2",children:[(0,a.jsx)("span",{className:(0,w.cn)("min-w-0 flex-1 truncate text-[13px] tracking-[-0.2px] text-foreground",D||f?"font-semibold":"font-medium"),children:o}),(0,a.jsx)("span",{className:(0,w.cn)("shrink-0 text-[10px] text-[var(--text-tertiary)]",y&&"lg:hidden"),children:h}),(0,a.jsx)("button",{onClick:t=>{t.stopPropagation(),Y("menu:".concat(e.pinKey))},className:(0,w.cn)("hidden shrink-0 text-muted-foreground transition-colors hover:text-foreground",y&&"lg:block"),children:(0,a.jsx)(x.A,{className:"size-3.5"})})]}),(0,a.jsxs)("div",{className:"flex items-center gap-1.5 overflow-hidden text-[11px] text-[var(--text-tertiary)]",children:[m?(0,a.jsx)("span",{className:"truncate",children:m}):null,j>1?(0,a.jsxs)("span",{className:"shrink-0 rounded bg-[var(--fill-tertiary)] px-1.5 py-0.5 text-[10px]",children:[j," chats"]}):null,b?(0,a.jsx)(u.A,{className:"size-3 shrink-0 text-[var(--accent)]"}):null]})]}),G==="menu:".concat(e.pinKey)?(0,a.jsxs)("div",{className:"absolute right-2 top-full z-50 min-w-[160px] overflow-hidden rounded-lg border border-border bg-[var(--material-thick)] py-1 shadow-[var(--shadow-overlay)] backdrop-blur-xl",onMouseLeave:()=>Y(null),children:[(0,a.jsxs)("button",{onClick:t=>{t.stopPropagation(),ep(e.pinKey),Y(null)},className:"flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs text-foreground transition-colors hover:bg-accent",children:[(0,a.jsx)(u.A,{className:"size-3"})," ",b?"Unpin":"Pin"]}),(0,a.jsx)("button",{onClick:e=>{e.stopPropagation(),em(n),Y(null)},className:"flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs text-foreground transition-colors hover:bg-accent",children:"Mark all as read"}),(0,a.jsx)("div",{className:"my-0.5 border-t border-border"}),(0,a.jsxs)("button",{onClick:e=>{e.stopPropagation(),Y(null),window.confirm("Delete all ".concat(n.length,' chats with "').concat(o,'"?'))&&eh(t,n)},className:"flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs text-[var(--system-red)] transition-colors hover:bg-accent",children:[(0,a.jsx)(p.A,{className:"size-3"})," Delete all chats"]})]}):null]})}),(0,a.jsxs)(S,{children:[(0,a.jsx)(C,{onClick:()=>ep(e.pinKey),children:b?"Unpin":"Pin"}),(0,a.jsx)(C,{onClick:()=>em(n),children:"Mark all as read"})]})]}),I&&j>1?el[t]?n.map(e=>eC(e,n)):n.slice(0,5).map(e=>eC(e,n)):null,I&&j>5&&!el[t]?(0,a.jsxs)("button",{onClick:()=>ei(e=>({...e,[t]:!0})),className:"w-full cursor-pointer px-4 pb-2 pl-[67px] text-left text-[10px] text-[var(--text-quaternary)] transition-colors hover:text-[var(--text-secondary)]",children:["+",j-5," more"]}):null]},e.pinKey)}let eD=ew.length>0;return(0,a.jsxs)("div",{className:"jsx-fb767975a1bed37e flex h-full flex-col border-r border-border bg-[var(--sidebar-bg)]",children:[(0,a.jsxs)("div",{className:"jsx-fb767975a1bed37e shrink-0 border-b border-border bg-[var(--material-thick)] px-4 pb-3 pt-4",children:[(0,a.jsxs)("div",{className:"jsx-fb767975a1bed37e mb-3 flex items-center justify-between gap-3",children:[(0,a.jsxs)("div",{className:"jsx-fb767975a1bed37e",children:[(0,a.jsx)("h2",{className:"jsx-fb767975a1bed37e text-xl font-bold tracking-[-0.03em] text-foreground",children:"Chats"}),(0,a.jsx)("p",{className:"jsx-fb767975a1bed37e text-xs text-muted-foreground",children:"Sessions, employees, and cron runs"})]}),(0,a.jsxs)(D.$,{size:"sm",className:"gap-1.5",onClick:l,children:[(0,a.jsx)(m.A,{className:"size-3.5"}),"New"]})]}),(0,a.jsxs)("div",{className:"jsx-fb767975a1bed37e flex items-center gap-2 rounded-[var(--radius-md)] bg-[var(--fill-tertiary)] px-3 py-2",children:[(0,a.jsx)(h.A,{className:"size-3.5 shrink-0 text-[var(--text-tertiary)]"}),(0,a.jsx)("input",{type:"text",value:Q,onChange:e=>$(e.target.value),placeholder:"Search chats...","aria-label":"Search chats",className:"jsx-fb767975a1bed37e min-w-0 flex-1 bg-transparent text-sm text-foreground outline-none placeholder:text-[var(--text-tertiary)]"}),Q.trim()?(0,a.jsx)("button",{onClick:()=>$(""),"aria-label":"Clear search",className:"jsx-fb767975a1bed37e rounded-full p-0.5 text-[var(--text-tertiary)] transition-colors hover:bg-[var(--fill-secondary)] hover:text-foreground",children:(0,a.jsx)(g.A,{className:"size-3"})}):null]})]}),(0,a.jsx)("div",{className:"jsx-fb767975a1bed37e flex-1 overflow-y-auto py-1",children:O?(0,a.jsx)("div",{className:"jsx-fb767975a1bed37e px-4 py-8 text-center text-xs text-[var(--text-quaternary)]",children:"Loading sessions..."}):0===ew.length&&0===ek.length&&0===ef.length?(0,a.jsx)("div",{className:"jsx-fb767975a1bed37e px-4 py-8 text-center text-xs text-[var(--text-quaternary)]",children:Q.trim()?"No matching chats":"No conversations yet"}):(0,a.jsxs)(a.Fragment,{children:[eD?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(B,{icon:"\uD83D\uDCCC",label:"Pinned"}),ew.map(e=>eI(e)),ek.length>0?(0,a.jsx)("div",{className:"jsx-fb767975a1bed37e mx-4 my-2 border-t border-border"}):null]}):null,ek.map(e=>eI(e)),ef.length>0?(0,a.jsxs)("div",{className:"jsx-fb767975a1bed37e "+((0,w.cn)("mt-2",0===ew.length&&0===ek.length&&"mt-0")||""),children:[(0,a.jsxs)("button",{onClick:eu,onMouseEnter:()=>Y("cron-header"),onMouseLeave:()=>Y(null),className:"jsx-fb767975a1bed37e flex w-full items-center gap-2 px-4 py-2 text-left transition-colors hover:bg-accent",children:[(0,a.jsx)(v.A,{className:"size-3.5 text-muted-foreground"}),(0,a.jsx)("span",{className:"jsx-fb767975a1bed37e text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:"Scheduled"}),(0,a.jsx)("span",{className:"jsx-fb767975a1bed37e ml-auto rounded bg-[var(--fill-tertiary)] px-1.5 py-0.5 text-[10px] text-[var(--text-secondary)]",children:ef.length}),(0,a.jsx)(f.A,{className:(0,w.cn)("size-3.5 text-muted-foreground transition-transform",eN&&"-rotate-90")})]}),eN?null:eS.map(e=>eC(e))]}):null]})}),(0,a.jsx)(d(),{id:"fb767975a1bed37e",children:"@keyframes sidebar-pulse{0%,100%{opacity:1;transform:scale(1)}50%{opacity:.55;transform:scale(.85)}}"})]})}var P=r(129);let q={running:"bg-blue-500 animate-pulse",error:"bg-red-500",idle:"bg-zinc-500"};function O(e){let{tabs:t,activeIndex:r,onSwitch:s,onClose:l,onNew:i,toolbarActions:o}=e,c=(0,n.useRef)(null);return(0,a.jsxs)("div",{className:"relative z-[100] flex h-10 shrink-0 items-center border-b border-border bg-[var(--bg-secondary)]",children:[t.length>0&&(0,a.jsx)("div",{ref:c,className:"flex min-w-0 flex-1 items-center overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:t.map((e,t)=>(0,a.jsxs)("button",{onClick:()=>s(t),onMouseDown:e=>{1===e.button&&(e.preventDefault(),l(t))},className:(0,w.cn)("group flex h-10 max-w-[180px] shrink-0 items-center gap-1.5 border-r border-border px-3 text-xs font-medium whitespace-nowrap transition-colors",t===r?"border-b-2 border-b-[var(--accent)] bg-background text-foreground":"text-muted-foreground hover:bg-[var(--fill-quaternary)] hover:text-foreground",e.unread&&t!==r&&"font-bold"),children:[(0,a.jsx)("span",{className:"w-1.5 h-1.5 rounded-full shrink-0 ".concat(q[e.status]||q.idle)}),e.emoji&&(0,a.jsx)("span",{className:"text-sm",children:e.emoji}),(0,a.jsx)("span",{className:"truncate",children:e.label}),(0,a.jsx)("span",{onClick:e=>{e.stopPropagation(),l(t)},className:"ml-auto rounded-sm p-0.5 opacity-0 transition-all hover:bg-accent hover:text-foreground group-hover:opacity-100",children:(0,a.jsx)(g.A,{size:12})})]},e.sessionId))}),0===t.length&&(0,a.jsx)("div",{className:"flex-1"}),(0,a.jsx)("button",{onClick:i,className:"flex size-10 shrink-0 items-center justify-center text-[var(--text-tertiary)] transition-colors hover:bg-[var(--fill-quaternary)] hover:text-foreground",title:"New Chat",children:(0,a.jsx)(m.A,{size:14})}),o&&(0,a.jsxs)("div",{className:"hidden shrink-0 items-center gap-2 border-l border-border px-3 lg:flex",children:[o,(0,a.jsx)(P.r,{})]})]})}let V="jinn-intermediate-";function J(e){try{localStorage.removeItem("".concat(V).concat(e))}catch(e){}}function H(e){let{name:t,size:r,mimeType:n,url:s,isUser:l}=e;return(0,a.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-3)",padding:"var(--space-3) var(--space-4)",borderRadius:"var(--radius-lg)",background:l?"var(--accent)":"var(--material-thin)",border:l?"none":"1px solid var(--separator)",maxWidth:280,minWidth:180},children:[(0,a.jsx)("div",{style:{width:36,height:36,borderRadius:"var(--radius-sm)",background:l?"rgba(0,0,0,0.15)":"var(--fill-tertiary)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,color:l?"#000":"var(--text-secondary)"},children:function(e,t){var r;let n=(null==t||null==(r=t.split(".").pop())?void 0:r.toLowerCase())||"",s="application/pdf"===e||"pdf"===n,l=["doc","docx"].includes(n)||(null==e?void 0:e.includes("wordprocessingml")),i=["txt","csv","json","md"].includes(n)||(null==e?void 0:e.startsWith("text/")),o=["zip","tar","gz","rar","7z"].includes(n);return s?(0,a.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,a.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,a.jsx)("polyline",{points:"14 2 14 8 20 8"}),(0,a.jsx)("line",{x1:"9",y1:"15",x2:"15",y2:"15"})]}):l?(0,a.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,a.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,a.jsx)("polyline",{points:"14 2 14 8 20 8"}),(0,a.jsx)("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),(0,a.jsx)("line",{x1:"16",y1:"17",x2:"8",y2:"17"}),(0,a.jsx)("polyline",{points:"10 9 9 9 8 9"})]}):i?(0,a.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,a.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,a.jsx)("polyline",{points:"14 2 14 8 20 8"})]}):o?(0,a.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,a.jsx)("path",{d:"M21 8v13H3V8"}),(0,a.jsx)("path",{d:"M1 3h22v5H1z"}),(0,a.jsx)("path",{d:"M10 12h4"})]}):(0,a.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,a.jsx)("path",{d:"M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"}),(0,a.jsx)("polyline",{points:"13 2 13 9 20 9"})]})}(n,t)}),(0,a.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,a.jsx)("div",{style:{fontSize:"var(--text-footnote)",fontWeight:"var(--weight-medium)",color:l?"#000":"var(--text-primary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t}),null!=r&&(0,a.jsx)("div",{style:{fontSize:"var(--text-caption2)",color:l?"rgba(0,0,0,0.5)":"var(--text-tertiary)",marginTop:1},children:r<1024?"".concat(r," B"):r<1048576?"".concat((r/1024).toFixed(0)," KB"):"".concat((r/1048576).toFixed(1)," MB")})]}),(0,a.jsx)("a",{href:s,download:t,"aria-label":"Download ".concat(t),style:{width:28,height:28,borderRadius:"50%",background:l?"rgba(0,0,0,0.15)":"var(--fill-secondary)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,color:l?"#000":"var(--text-secondary)",textDecoration:"none"},children:(0,a.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,a.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,a.jsx)("polyline",{points:"7 10 12 15 17 10"}),(0,a.jsx)("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})})]})}function Q(e){let{src:t,duration:r,waveform:s,isUser:l}=e,i=(0,n.useRef)(null),[o,c]=(0,n.useState)(!1),[d,u]=(0,n.useState)(0),[x,p]=(0,n.useState)(0);(0,n.useEffect)(()=>{let e=new Audio(t);return i.current=e,e.addEventListener("timeupdate",()=>{e.duration&&isFinite(e.duration)&&(u(e.currentTime/e.duration),p(e.currentTime))}),e.addEventListener("ended",()=>{c(!1),u(0),p(0)}),e.addEventListener("pause",()=>c(!1)),e.addEventListener("play",()=>c(!0)),()=>{e.pause(),e.src=""}},[t]);let m=(0,n.useCallback)(()=>{let e=i.current;e&&(o?e.pause():e.play().catch(()=>{}))},[o]),h=s.length>0?s:Array(50).fill(.1),g=o?x:r;return(0,a.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-3)",padding:"var(--space-3) var(--space-4)",borderRadius:"var(--radius-lg)",background:l?"var(--accent)":"var(--material-thin)",border:l?"none":"1px solid var(--separator)",maxWidth:280,minWidth:200},children:[(0,a.jsx)("button",{onClick:m,"aria-label":o?"Pause":"Play",style:{width:28,height:28,borderRadius:"50%",background:l?"rgba(0,0,0,0.2)":"var(--fill-secondary)",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,color:l?"#000":"var(--text-primary)"},children:o?(0,a.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,a.jsx)("rect",{x:"6",y:"4",width:"4",height:"16",rx:"1"}),(0,a.jsx)("rect",{x:"14",y:"4",width:"4",height:"16",rx:"1"})]}):(0,a.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:(0,a.jsx)("polygon",{points:"6,4 20,12 6,20"})})}),(0,a.jsx)("div",{style:{flex:1,display:"flex",alignItems:"center",gap:2,height:28},children:h.map((e,t)=>{let r=t/h.length<=d;return(0,a.jsx)("div",{style:{width:3,borderRadius:1.5,height:"".concat(Math.max(4,24*e),"px"),background:l?r?"rgba(0,0,0,0.7)":"rgba(0,0,0,0.25)":r?"var(--accent)":"var(--fill-primary)",transition:"background 100ms ease",flexShrink:0}},t)})}),(0,a.jsx)("span",{style:{fontSize:"var(--text-caption2)",color:l?"rgba(0,0,0,0.6)":"var(--text-tertiary)",fontVariantNumeric:"tabular-nums",flexShrink:0,minWidth:28,textAlign:"right"},children:function(e){let t=Math.floor(e/60),r=Math.floor(e%60);return"".concat(t,":").concat(r.toString().padStart(2,"0"))}(g)})]})}function $(e){let{msgs:t,isActive:r}=e,[s,l]=(0,n.useState)(!1),i=t.every(e=>e.content.startsWith("Used ")),o=r&&!i?"".concat(t.length," tool").concat(1!==t.length?"s":""," running…"):"".concat(t.length," tool").concat(1!==t.length?"s":""," used");return(0,a.jsxs)("div",{className:"px-[var(--space-4)] mb-[var(--space-1)]",children:[(0,a.jsxs)("button",{onClick:()=>l(e=>!e),className:"flex items-center gap-[var(--space-2)] py-[5px] px-[var(--space-3)] rounded-full bg-[var(--fill-secondary)] border border-[var(--separator)] text-[length:var(--text-caption1)] text-[var(--text-secondary)] cursor-pointer transition-[background] duration-150 ease-in-out hover:bg-[var(--fill-tertiary)]",children:[(0,a.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"opacity-60",children:(0,a.jsx)("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"})}),o,r&&!i&&(0,a.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[var(--system-blue)] animate-[jinn-pulse_1.4s_infinite]"}),(0,a.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"transition-transform duration-150 ease-in-out opacity-50 ".concat(s?"rotate-180":"rotate-0"),children:(0,a.jsx)("polyline",{points:"6 9 12 15 18 9"})})]}),s&&(0,a.jsx)("div",{className:"flex flex-wrap gap-[var(--space-1)] mt-[var(--space-1)] pl-[var(--space-1)]",children:t.map(e=>(0,a.jsx)("span",{className:"inline-flex items-center gap-1 py-0.5 px-2 rounded-full bg-[var(--fill-tertiary)] border border-[var(--separator)] text-[length:var(--text-caption2)] text-[var(--text-tertiary)]",children:e.toolCall},e.id))})]})}function G(e){let t,r=[],n=/(https?:\/\/[^\s<]+[^\s<.,;:!?)}\]'"])|(\*\*(.+?)\*\*)|(`([^`]+)`)|\*([^*]+)\*/g,s=0;for(;null!==(t=n.exec(e));)t.index>s&&r.push(e.slice(s,t.index)),t[1]?r.push((0,a.jsx)("a",{href:t[1],target:"_blank",rel:"noopener noreferrer",className:"text-[var(--system-blue)] underline underline-offset-2",children:t[1]},t.index)):t[2]?r.push((0,a.jsx)("strong",{className:"font-[var(--weight-bold)]",children:t[3]},t.index)):t[4]?r.push((0,a.jsx)("code",{className:"bg-[var(--fill-secondary)] border border-[var(--separator)] rounded-[5px] py-px px-[5px] text-[0.88em] font-['SF_Mono',Menlo,monospace] text-[var(--accent)]",children:t[5]},t.index)):t[6]&&r.push((0,a.jsx)("em",{className:"italic opacity-[0.85]",children:t[6]},t.index)),s=t.index+t[0].length;return s<e.length&&r.push(e.slice(s)),1===r.length?r[0]:(0,a.jsx)(a.Fragment,{children:r})}function Y(e){let{code:t,keyProp:r}=e,[s,l]=(0,n.useState)(!1);return(0,a.jsxs)("div",{className:"relative my-2",children:[(0,a.jsx)("button",{onClick:function(){navigator.clipboard.writeText(t).then(()=>{l(!0),setTimeout(()=>l(!1),1500)})},"aria-label":"Copy code",className:"absolute top-2 right-2 py-0.5 px-2 text-[11px] rounded-[var(--radius-sm)] bg-[var(--fill-secondary)] text-[var(--text-secondary)] border border-[var(--separator)] cursor-pointer",children:s?"Copied!":"Copy"}),(0,a.jsx)("pre",{className:"code-block bg-[var(--fill-tertiary)] border border-[var(--separator)] rounded-[var(--radius-md)] py-[var(--space-3)] px-[var(--space-4)] overflow-x-auto text-[13px] leading-normal font-['SF_Mono',Menlo,monospace] text-[var(--text-primary)]",children:(0,a.jsx)("code",{children:t})})]},r)}function X(e){return/^\|[\s:|-]+\|$/.test(e.trim())}function Z(e){return e.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(e=>e.trim())}function ee(e){let{headerLine:t,rows:r,keyProp:n}=e,s=Z(t),l=r.map(Z);return(0,a.jsx)("div",{className:"my-2.5 rounded-[10px] border border-[var(--separator)] overflow-hidden",children:(0,a.jsx)("div",{className:"overflow-x-auto [WebkitOverflowScrolling:touch]",children:(0,a.jsxs)("table",{className:"border-collapse text-[length:var(--text-footnote)] leading-[1.6] w-full min-w-max",children:[(0,a.jsx)("thead",{children:(0,a.jsx)("tr",{className:"bg-[var(--fill-tertiary)]",children:s.map((e,t)=>(0,a.jsx)("th",{className:"text-left py-2.5 px-4 font-semibold text-[var(--text-primary)] border-b border-[var(--separator)] max-w-[280px] break-words",children:G(e)},t))})}),(0,a.jsx)("tbody",{children:l.map((e,t)=>(0,a.jsx)("tr",{className:t%2==1?"bg-[var(--fill-quaternary,transparent)]":"bg-transparent",children:e.map((e,r)=>(0,a.jsx)("td",{className:"py-2.5 px-4 text-[var(--text-primary)] max-w-[280px] break-words ".concat(t<l.length-1?"border-b border-[var(--separator)]":""),children:G(e)},r))},t))})]})})},n)}function et(e){if(!e)return null;let t=e.split("\n"),r=[],n=!1,s=[];for(let e=0;e<t.length;e++){let i=t[e];if(i.startsWith("```")){n?(n=!1,r.push((0,a.jsx)(Y,{keyProp:e,code:s.join("\n")},e))):n=!0,s=[];continue}if(n){s.push(i);continue}if(i.trim().startsWith("|")&&i.trim().endsWith("|")&&e+1<t.length&&X(t[e+1])){e++;let n=[];for(;e+1<t.length&&t[e+1].trim().startsWith("|")&&t[e+1].trim().endsWith("|")&&!X(t[e+1]);)e++,n.push(t[e]);r.push((0,a.jsx)(ee,{keyProp:e,headerLine:i,rows:n},"table-".concat(e)));continue}if(""===i.trim()){r.push((0,a.jsx)("div",{className:"h-1.5"},"space-".concat(e)));continue}if(i.match(/^[-*] /)){r.push((0,a.jsxs)("div",{className:"flex gap-[var(--space-2)] mb-0.5",children:[(0,a.jsx)("span",{className:"text-[var(--accent)] shrink-0 mt-px",children:"•"}),(0,a.jsx)("span",{children:G(i.slice(2))})]},e));continue}if(i.match(/^\d+\. /)){var l;let t=null==(l=i.match(/^(\d+)\. /))?void 0:l[1];r.push((0,a.jsxs)("div",{className:"flex gap-[var(--space-2)] mb-0.5",children:[(0,a.jsxs)("span",{className:"text-[var(--accent)] shrink-0 font-[var(--weight-semibold)] min-w-4",children:[t,"."]}),(0,a.jsx)("span",{children:G(i.replace(/^\d+\. /,""))})]},e));continue}if(i.startsWith("### ")){r.push((0,a.jsx)("div",{className:"font-[var(--weight-semibold)] text-[length:var(--text-footnote)] mt-[var(--space-2)] mb-0.5",children:G(i.slice(4))},e));continue}if(i.startsWith("## ")){r.push((0,a.jsx)("div",{className:"font-[var(--weight-bold)] text-[length:var(--text-subheadline)] mt-[var(--space-3)] mb-[3px]",children:G(i.slice(3))},e));continue}if(i.startsWith("# ")){r.push((0,a.jsx)("div",{className:"font-[var(--weight-bold)] text-[length:var(--text-body)] mt-[var(--space-3)] mb-[var(--space-1)]",children:G(i.slice(2))},e));continue}r.push((0,a.jsx)("div",{className:"mb-px",children:G(i)},e))}return n&&s.length>0&&r.push((0,a.jsx)(Y,{keyProp:999,code:s.join("\n")},"trailing-code")),(0,a.jsx)(a.Fragment,{children:r})}function er(e){let t=new Date,r=new Date(e),a=t.toDateString()===r.toDateString(),n=new Date(t);n.setDate(n.getDate()-1);let s=n.toDateString()===r.toDateString(),l=r.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0});return a?"Today ".concat(l):s?"Yesterday ".concat(l):r.toLocaleDateString("en-US",{month:"short",day:"numeric"})+" ".concat(l)}function ea(e,t){return 0===t||e[t].timestamp-e[t-1].timestamp>3e5}function en(e,t){let r=e.filter(e=>"image"===e.type),n=e.filter(e=>"audio"===e.type),s=e.filter(e=>"file"===e.type);return(0,a.jsxs)(a.Fragment,{children:[r.map((e,t)=>(0,a.jsx)("div",{className:"mt-[var(--space-2)] rounded-[var(--radius-lg)] overflow-hidden max-w-[280px]",children:(0,a.jsx)("img",{src:e.url,alt:e.name||"Image",className:"w-full block rounded-[var(--radius-lg)] cursor-pointer",onClick:()=>window.open(e.url,"_blank")})},"img-".concat(t))),n.map((e,r)=>(0,a.jsx)("div",{className:"mt-[var(--space-2)]",children:(0,a.jsx)(Q,{src:e.url,duration:e.duration||0,waveform:e.waveform||[],isUser:t})},"audio-".concat(r))),s.map((e,r)=>(0,a.jsx)("div",{className:"mt-[var(--space-2)]",children:(0,a.jsx)(H,{name:e.name||"File",size:e.size,mimeType:e.mimeType,url:e.url,isUser:t})},"file-".concat(r)))]})}function es(e){let{messages:t,loading:r,streamingText:s}=e,l=(0,n.useRef)(null),i=(0,n.useRef)(null),o=(0,n.useRef)(0),c=(0,n.useRef)(null);return((0,n.useLayoutEffect)(()=>{var e,r;if(0===t.length){o.current=0,c.current=null;return}let a=(null==(e=t[0])?void 0:e.id)||null,n=null!==c.current&&a!==c.current;0===o.current&&t.length>0||n?i.current&&(i.current.scrollTop=i.current.scrollHeight):null==(r=l.current)||r.scrollIntoView({behavior:"smooth"}),o.current=t.length,c.current=a},[t]),(0,n.useEffect)(()=>{if(r&&t.length>0){var e;null==(e=l.current)||e.scrollIntoView({behavior:"smooth"})}},[r,t.length]),0!==t.length||r)?(0,a.jsxs)("div",{ref:i,className:"chat-messages-scroll flex-1 overflow-y-auto overflow-x-hidden py-[var(--space-3)] pb-[var(--space-6)] bg-[var(--bg)] min-h-0",children:[(function(e){let t=[],r=0;for(;r<e.length;)if("assistant"===e[r].role&&e[r].toolCall){let a=[],n=r;for(;r<e.length&&"assistant"===e[r].role&&e[r].toolCall;)a.push(e[r]),r++;t.push({kind:"tool-group",msgs:a,startIndex:n})}else t.push({kind:"message",msg:e[r],index:r}),r++;return t})(t).map(e=>{if("tool-group"===e.kind){let n=e.msgs[0],s=ea(t,e.startIndex),l=e.startIndex>0?t[e.startIndex-1]:null,i=r&&e.startIndex+e.msgs.length===t.length;return(0,a.jsxs)("div",{children:[s&&(0,a.jsx)("div",{className:"text-center py-[var(--space-3)] text-[length:var(--text-caption2)] text-[var(--text-tertiary)]",children:er(n.timestamp)}),!s&&l&&(0,a.jsx)("div",{className:"assistant"!==l.role?"h-[var(--space-4)]":"h-[var(--space-1)]"}),(0,a.jsx)($,{msgs:e.msgs,isActive:i})]},"tg-".concat(e.startIndex))}let{msg:n,index:s}=e,l="user"===n.role,i="notification"===n.role,o=ea(t,s),c=n.media||function(e){let t,r=[],a=/!\[([^\]]*)\]\((https?:\/\/[^)]+\.(jpg|jpeg|png|gif|webp|svg)(\?[^)]*)?)\)/gi;for(;null!==(t=a.exec(e));)r.push({type:"image",url:t[2],name:t[1]||"Image"});let n=RegExp("(?<!\\]\\()https?:\\/\\/\\S+\\.(jpg|jpeg|png|gif|webp)(\\?\\S*)?\\b","gi");for(;null!==(t=n.exec(e));){let e=t[0];r.find(t=>t.url===e)||r.push({type:"image",url:e})}let s=/https?:\/\/\S+\.(mp3|wav|ogg|m4a|aac)(\?\S*)?\b/gi;for(;null!==(t=s.exec(e));)r.push({type:"audio",url:t[0],name:t[0].split("/").pop()});return r}(n.content),d=n.content;return c.length>0&&!n.media&&(c.forEach(e=>{d=(d=d.replace(e.url,"")).replace(/!\[[^\]]*\]\([^)]+\)/g,"")}),d=d.trim()),n.media&&n.media.length>0&&d.startsWith("[")&&d.endsWith("]")&&(d=""),(0,a.jsxs)("div",{children:[o&&(0,a.jsx)("div",{className:"text-center py-[var(--space-3)] text-[length:var(--text-caption2)] text-[var(--text-tertiary)]",children:er(n.timestamp)}),!o&&s>0&&(0,a.jsx)("div",{className:t[s-1].role!==n.role?"h-[var(--space-4)]":"h-[var(--space-1)]"}),i&&(0,a.jsx)("div",{className:"flex justify-center px-[var(--space-4)] mb-[var(--space-1)]",children:(0,a.jsxs)("div",{className:"notification-msg-bubble flex items-start gap-[var(--space-2)] py-[var(--space-3)] px-[var(--space-4)] rounded-[var(--radius-md)] bg-[var(--fill-secondary)] border border-dashed border-[var(--separator)] text-[var(--text-secondary)] text-[length:var(--text-caption1)] leading-[var(--leading-relaxed)] max-w-[85%]",children:[(0,a.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0 mt-0.5 opacity-60",children:[(0,a.jsx)("path",{d:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"}),(0,a.jsx)("path",{d:"M13.73 21a2 2 0 0 1-3.46 0"})]}),(0,a.jsx)("span",{children:et(d)})]})}),l&&(0,a.jsxs)("div",{className:"flex flex-col items-end px-[var(--space-4)] mb-[var(--space-1)]",children:[d&&(0,a.jsx)("div",{className:"user-msg-bubble py-[var(--space-3)] px-[var(--space-4)] rounded-[var(--radius-lg)_var(--radius-lg)_var(--radius-sm)_var(--radius-lg)] bg-[var(--accent)] text-[var(--accent-contrast)] text-[length:var(--text-subheadline)] leading-[var(--leading-relaxed)] font-[var(--weight-medium)] shadow-[var(--shadow-subtle)]",children:et(d)}),c.length>0&&(0,a.jsx)("div",{className:"user-msg-bubble",children:en(c,!0)})]}),!l&&!i&&(0,a.jsx)("div",{className:"assistant-msg-row flex justify-start px-[var(--space-4)] mb-[var(--space-1)]",children:(0,a.jsxs)("div",{className:"assistant-msg-bubble flex flex-col",children:[d&&(0,a.jsx)("div",{className:"py-[var(--space-3)] px-[var(--space-4)] rounded-[var(--radius-sm)_var(--radius-lg)_var(--radius-lg)_var(--radius-lg)] bg-[var(--material-thin)] border border-[var(--separator)] text-[var(--text-primary)] text-[length:var(--text-subheadline)] leading-[var(--leading-relaxed)]",children:et(d)}),c.length>0&&en(c,!1)]})})]},n.id||s)}),s&&(0,a.jsx)("div",{className:"assistant-msg-row flex justify-start px-[var(--space-4)] mb-[var(--space-1)]",children:(0,a.jsx)("div",{className:"assistant-msg-bubble flex flex-col",children:(0,a.jsx)("div",{className:"py-[var(--space-3)] px-[var(--space-4)] rounded-[var(--radius-sm)_var(--radius-lg)_var(--radius-lg)_var(--radius-lg)] bg-[var(--material-thin)] border border-[var(--separator)] text-[var(--text-primary)] text-[length:var(--text-subheadline)] leading-[var(--leading-relaxed)]",children:et(function(e){let t=e,r=(t.match(/```/g)||[]).length;if(r%2!=0&&(t+="\n```"),r%2==0){let e=t.replace(/```[\s\S]*?```/g,"");(e.match(/`/g)||[]).length%2!=0&&(t+="`"),(e.match(/\*\*/g)||[]).length%2!=0&&(t+="**")}return t}(s))})})}),r&&!s&&t.length>0&&(0,a.jsxs)("div",{className:"flex items-center gap-1.5 py-1.5 px-[var(--space-4)] mt-[var(--space-1)]",children:[(0,a.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[var(--accent)] animate-[jinn-pulse_1.4s_infinite] shrink-0"}),(0,a.jsx)("span",{className:"text-[length:var(--text-caption1)] text-[var(--text-tertiary)] font-[var(--weight-medium)]",children:"Thinking"})]}),(0,a.jsx)("div",{ref:l}),(0,a.jsx)("style",{children:"\n @keyframes jinn-pulse {\n 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }\n 40% { opacity: 1; transform: scale(1); }\n }\n .assistant-msg-bubble { max-width: 100%; overflow-wrap: break-word; word-break: break-word; }\n .user-msg-bubble { max-width: 90%; overflow-wrap: break-word; word-break: break-word; }\n .notification-msg-bubble { overflow-wrap: break-word; word-break: break-word; }\n .assistant-msg-row { padding: 0 var(--space-2) !important; }\n @media (min-width: 1024px) {\n .assistant-msg-bubble { max-width: 75%; }\n .user-msg-bubble { max-width: 75%; }\n .assistant-msg-row { padding: 0 var(--space-4) !important; }\n }\n /* User message contrast fixes — ensure all child elements are visible on accent background */\n .user-msg-bubble code {\n background: rgba(255,255,255,0.2) !important;\n border-color: rgba(255,255,255,0.3) !important;\n color: inherit !important;\n }\n .user-msg-bubble .code-block,\n .user-msg-bubble pre {\n background: rgba(0,0,0,0.2) !important;\n border-color: rgba(255,255,255,0.15) !important;\n color: rgba(255,255,255,0.95) !important;\n }\n .user-msg-bubble a {\n color: inherit !important;\n text-decoration-color: rgba(255,255,255,0.6) !important;\n }\n .user-msg-bubble strong { color: inherit !important; }\n .user-msg-bubble em { color: inherit !important; opacity: 0.9; }\n .user-msg-bubble span { color: inherit !important; }\n .user-msg-bubble div { color: inherit !important; }\n .user-msg-bubble th, .user-msg-bubble td { color: inherit !important; }\n .user-msg-bubble table { border-color: rgba(255,255,255,0.2) !important; }\n .user-msg-bubble th { border-color: rgba(255,255,255,0.2) !important; }\n .user-msg-bubble td { border-color: rgba(255,255,255,0.15) !important; }\n .user-msg-bubble tr { background: transparent !important; }\n .user-msg-bubble thead tr { background: rgba(255,255,255,0.1) !important; }\n /* Selection visibility for user messages */\n .user-msg-bubble ::selection {\n background: rgba(255,255,255,0.35);\n color: inherit;\n }\n .user-msg-bubble ::-moz-selection {\n background: rgba(255,255,255,0.35);\n color: inherit;\n }\n "})]}):(0,a.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,a.jsxs)("div",{className:"text-center",children:[(0,a.jsx)("div",{className:"text-[length:var(--text-title3)] font-[var(--weight-semibold)] text-[var(--text-tertiary)]",children:"Start a conversation"}),(0,a.jsx)("div",{className:"text-[length:var(--text-footnote)] text-[var(--text-quaternary)] mt-[var(--space-2)]",children:"Send a message or use /new to begin"})]})})}function el(e){let{attachments:t,onRemove:r}=e;return 0===t.length?null:(0,a.jsx)("div",{style:{display:"flex",gap:"var(--space-2)",padding:"var(--space-2) var(--space-3)",overflowX:"auto",overflowY:"hidden"},children:t.map((e,t)=>{var n,s;return(0,a.jsxs)("div",{style:{position:"relative",width:56,height:56,flexShrink:0,borderRadius:"var(--radius-sm)",overflow:"hidden",background:"var(--fill-tertiary)",border:"1px solid var(--separator)"},children:["image"===e.type?(0,a.jsx)("img",{src:e.url,alt:e.name||"Preview",style:{width:"100%",height:"100%",objectFit:"cover"}}):(0,a.jsxs)("div",{style:{width:"100%",height:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2,padding:4},children:["audio"===e.type?(0,a.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-tertiary)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,a.jsx)("path",{d:"M9 18V5l12-2v13"}),(0,a.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,a.jsx)("circle",{cx:"18",cy:"16",r:"3"})]}):(0,a.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-tertiary)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,a.jsx)("path",{d:"M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"}),(0,a.jsx)("polyline",{points:"13 2 13 9 20 9"})]}),(0,a.jsx)("span",{style:{fontSize:8,color:"var(--text-quaternary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"100%",textAlign:"center"},children:(null==(s=e.name)||null==(n=s.split(".").pop())?void 0:n.toUpperCase())||e.type.toUpperCase()})]}),(0,a.jsx)("button",{onClick:()=>r(t),"aria-label":"Remove attachment",style:{position:"absolute",top:2,right:2,width:18,height:18,borderRadius:"50%",background:"rgba(0,0,0,0.6)",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:"#fff",fontSize:11,lineHeight:1,padding:0},children:(0,a.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:[(0,a.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,a.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},t)})})}function ei(e){let{open:t,progress:r,onDownload:n,onCancel:s}=e;if(!t)return null;let l=null!==r;return(0,a.jsx)("div",{className:"fixed inset-0 bg-black/50 z-[60] flex items-center justify-center",onClick:l?void 0:s,children:(0,a.jsxs)("div",{className:"bg-[var(--bg)] rounded-[var(--radius-lg)] p-[var(--space-6)] max-w-[400px] w-[90%] shadow-[var(--shadow-overlay)]",onClick:e=>e.stopPropagation(),children:[(0,a.jsx)("div",{className:"w-12 h-12 rounded-[var(--radius-md)] bg-[var(--fill-secondary)] flex items-center justify-center mb-[var(--space-4)]",children:(0,a.jsxs)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-secondary)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,a.jsx)("path",{d:"M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"}),(0,a.jsx)("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),(0,a.jsx)("line",{x1:"12",y1:"19",x2:"12",y2:"23"}),(0,a.jsx)("line",{x1:"8",y1:"23",x2:"16",y2:"23"})]})}),(0,a.jsx)("h3",{className:"text-[length:var(--text-headline)] font-[var(--weight-bold)] text-[var(--text-primary)] mb-[var(--space-2)]",children:"Enable voice input?"}),(0,a.jsx)("p",{className:"text-[length:var(--text-body)] text-[var(--text-secondary)] mb-[var(--space-5)] leading-[var(--leading-relaxed)]",children:"This will download a speech recognition model (~500MB). Transcription runs locally on your server — no data leaves your network."}),l&&(0,a.jsxs)("div",{className:"mb-[var(--space-5)]",children:[(0,a.jsxs)("div",{className:"flex justify-between mb-[var(--space-2)] text-[length:var(--text-footnote)] text-[var(--text-tertiary)]",children:[(0,a.jsx)("span",{children:"Downloading model…"}),(0,a.jsxs)("span",{children:[r,"%"]})]}),(0,a.jsx)("div",{className:"h-1.5 rounded-[3px] bg-[var(--fill-tertiary)] overflow-hidden",children:(0,a.jsx)("div",{className:"h-full rounded-[3px] bg-[var(--accent)] transition-[width] duration-300 ease-in-out",style:{width:"".concat(r,"%")}})})]}),(0,a.jsxs)("div",{className:"flex gap-[var(--space-3)] justify-end",children:[!l&&(0,a.jsx)("button",{onClick:s,className:"px-[var(--space-4)] py-[var(--space-2)] rounded-[var(--radius-md)] bg-[var(--fill-tertiary)] text-[var(--text-primary)] border-none cursor-pointer text-[length:var(--text-body)]",children:"Cancel"}),(0,a.jsx)("button",{onClick:n,disabled:l,className:"px-[var(--space-4)] py-[var(--space-2)] rounded-[var(--radius-md)] border-none text-[length:var(--text-body)] font-[var(--weight-semibold)] ".concat(l?"bg-[var(--fill-tertiary)] text-[var(--text-tertiary)] cursor-default":"bg-[var(--accent)] text-black cursor-pointer"),children:l?"Downloading…":"Download"})]})]})})}function eo(e){let{analyser:t,width:r=64,height:s=32,color:l="var(--system-red)"}=e,i=(0,n.useRef)(null),o=(0,n.useRef)(0);return(0,n.useEffect)(()=>{let e=i.current;if(!e||!t)return;let a=e.getContext("2d");if(!a)return;let n=t.frequencyBinCount,c=new Uint8Array(n),d=(r-22)/12;return!function e(){o.current=requestAnimationFrame(e),t.getByteFrequencyData(c),a.clearRect(0,0,r,s);for(let e=0;e<12;e++){let t=Math.max(3,c[Math.floor(e/12*(.6*n))]/255*s),r=e*(d+2),i=(s-t)/2;a.fillStyle=l,a.beginPath(),a.roundRect(r,i,d,t,1.5),a.fill()}}(),()=>{cancelAnimationFrame(o.current)}},[t,r,s,l]),(0,a.jsx)("canvas",{ref:i,width:r,height:s,style:{width:r,height:s,display:"block"}})}let ec=[{name:"new",description:"Start a new chat session"},{name:"status",description:"Show current session info"}];async function ed(e){let t,r=e.type.startsWith("image/"),a=e.type.startsWith("audio/");if(r)t=await new Promise((t,r)=>{let a=new Image,n=URL.createObjectURL(e);a.onload=()=>{URL.revokeObjectURL(n);let{width:s,height:l}=a;if(s>1200||l>1200){let e=1200/Math.max(s,l);s=Math.round(s*e),l=Math.round(l*e)}let i=document.createElement("canvas");i.width=s,i.height=l;let o=i.getContext("2d");if(!o)return void r(Error("no canvas context"));o.drawImage(a,0,0,s,l);let c=e.size>5e4?"image/jpeg":"image/png";t(i.toDataURL(c,"image/jpeg"===c?.85:void 0))},a.onerror=()=>{URL.revokeObjectURL(n),r(Error("image load failed"))},a.src=n});else t=await new Promise((t,r)=>{let a=new FileReader;a.onloadend=()=>t(a.result),a.onerror=r,a.readAsDataURL(e)});return{type:r?"image":a?"audio":"file",url:t,name:e.name,mimeType:e.type,size:t.length}}function eu(e){let{disabled:t,loading:r,onSend:s,onInterrupt:i,onNewSession:o,onStatusRequest:c,skillsVersion:d,events:u}=e,[x,p]=(0,n.useState)(""),[m,h]=(0,n.useState)([]),[g,v]=(0,n.useState)(!1),[f,b]=(0,n.useState)(""),[y,j]=(0,n.useState)(0),[w,k]=(0,n.useState)(ec),[N,S]=(0,n.useState)(!1),[C,I]=(0,n.useState)(""),[D,M]=(0,n.useState)(0),[L,E]=(0,n.useState)([]),A=(0,n.useRef)(null),z=(0,n.useRef)(null),_=(0,n.useRef)(new Map),T=function(e,t){let[r,a]=(0,n.useState)("idle"),[s,i]=(0,n.useState)(null),[o,c]=(0,n.useState)(null),[d,u]=(0,n.useState)(null),[x,p]=(0,n.useState)(["en"]),[m,h]=(0,n.useState)(null),[g,v]=(0,n.useState)(()=>localStorage.getItem("stt-language")||"en"),f=(0,n.useRef)(g);f.current=g;let b=(0,n.useRef)(null),y=(0,n.useRef)(null),j=(0,n.useRef)(null),w=(0,n.useRef)([]),k=(0,n.useRef)(null),N=(0,n.useRef)(null),S=(0,n.useRef)(t);S.current=t,(0,n.useEffect)(()=>{if(!e||0===e.length)return;let t=e[e.length-1];if(!t.event.startsWith("stt:"))return;let r=t.payload;"stt:download:progress"===t.event&&c(Number(r.progress)||0),"stt:download:complete"===t.event&&(c(null),i(!0),a("idle")),"stt:download:error"===t.event&&(c(null),a("idle"))},[e]);let C=(0,n.useCallback)(()=>{var e,t;null==(e=j.current)||e.getTracks().forEach(e=>e.stop()),j.current=null,null==(t=y.current)||t.close().catch(()=>{}),y.current=null,u(null),b.current=null},[]);(0,n.useEffect)(()=>()=>{var e,t,r;k.current&&clearTimeout(k.current),(null==(e=b.current)?void 0:e.state)==="recording"&&b.current.stop(),null==(t=j.current)||t.getTracks().forEach(e=>e.stop()),null==(r=y.current)||r.close().catch(()=>{})},[]);let I=(0,n.useCallback)(async()=>{try{var e;let t=await l.F.sttStatus();return i(t.available),t.downloading&&c(t.progress),(null==(e=t.languages)?void 0:e.length)>0&&(p(t.languages),v(e=>{if(!t.languages.includes(e)){let e=t.languages[0];return localStorage.setItem("stt-language",e),e}return e})),t.available}catch(e){return i(!1),!1}},[]),D=(0,n.useCallback)(async()=>{try{let e=await navigator.mediaDevices.getUserMedia({audio:!0});j.current=e;let t=new AudioContext;y.current=t;let r=t.createMediaStreamSource(e),n=t.createAnalyser();n.fftSize=128,r.connect(n),u(n);let s=MediaRecorder.isTypeSupported("audio/webm;codecs=opus")?"audio/webm;codecs=opus":MediaRecorder.isTypeSupported("audio/mp4")?"audio/mp4":"",i=new MediaRecorder(e,s?{mimeType:s}:void 0);b.current=i,w.current=[],i.ondataavailable=e=>{e.data.size>0&&w.current.push(e.data)},i.onstop=async()=>{C(),a("transcribing");let e=new Blob(w.current,{type:i.mimeType||"audio/webm"});if(w.current=[],0===e.size){var t;a("idle"),null==(t=N.current)||t.call(N,null),N.current=null;return}try{let t=(await l.F.sttTranscribe(e,f.current)).text||null;a("idle"),h(null),N.current?(N.current(t),N.current=null):t&&S.current&&S.current(t)}catch(t){let e=t instanceof Error?t.message:"Transcription failed";h(e),a("error"),N.current&&(N.current(null),N.current=null)}},i.start(5e3),a("recording"),k.current=setTimeout(()=>{var e;(null==(e=b.current)?void 0:e.state)==="recording"&&b.current.stop()},18e5)}catch(e){C(),a("idle")}},[C]),M=(0,n.useCallback)(async()=>{"recording"!==r&&"transcribing"!==r&&("error"===r&&(h(null),a("idle")),await I()?await D():a("no-model"))},[r,I,D]),L=(0,n.useCallback)(async()=>{await D()},[D]),E=(0,n.useCallback)(async()=>b.current&&"inactive"!==b.current.state?(k.current&&(clearTimeout(k.current),k.current=null),new Promise(e=>{var t;N.current=e,(null==(t=b.current)?void 0:t.state)==="recording"?b.current.stop():(C(),a("idle"),N.current=null,e(null))})):(a("idle"),null),[C]),A=(0,n.useCallback)(()=>{var e;k.current&&(clearTimeout(k.current),k.current=null),(null==(e=b.current)?void 0:e.state)==="recording"&&b.current.stop(),C(),w.current=[],a("idle")},[C]),z=(0,n.useCallback)(()=>{c(0),l.F.sttDownload().catch(()=>{c(null)})},[]),_=(0,n.useCallback)(()=>{a("idle"),c(null)},[]),T=(0,n.useCallback)(()=>{a("idle"),h(null)},[]),R=(0,n.useCallback)(()=>{v(e=>{let t=x.indexOf(e),r=x[(t+1)%x.length];return localStorage.setItem("stt-language",r),r})},[x]);return{state:r,available:s,downloadProgress:o,analyser:d,languages:x,selectedLanguage:g,error:m,cycleLanguage:R,handleMicClick:M,startRecording:L,stopRecording:E,cancelRecording:A,startDownload:z,dismissDownload:_,dismissError:T}}(u,e=>{e&&p(t=>t?t+" "+e:e)});(0,n.useEffect)(()=>{l.F.getOrg().then(async e=>{let t=e.employees;Array.isArray(t)&&h(await Promise.all(t.map(async e=>{try{let t=await l.F.getEmployee(e);return{name:t.name,displayName:t.displayName,department:t.department,rank:t.rank,engine:t.engine}}catch(t){return{name:e}}})))}).catch(()=>{})},[]),(0,n.useEffect)(()=>{l.F.getSkills().then(e=>{if(!Array.isArray(e))return;let t=e.filter(e=>!ec.some(t=>t.name===e.name)).map(e=>({name:e.name,description:e.description||"",needsEmployee:"sync"===e.name}));k([...ec,...t])}).catch(()=>{})},[d]);let R=(0,n.useCallback)(e=>{var t;let r=x.lastIndexOf("@");-1!==r&&p(x.slice(0,r)+"@"+e+" "),v(!1),null==(t=A.current)||t.focus()},[x]),F=(0,n.useCallback)(e=>{var t;e.needsEmployee?(p("/"+e.name+" @"),S(!1),b(""),j(0),v(!0)):(p("/"+e.name),S(!1)),null==(t=A.current)||t.focus()},[]);function U(){let e=x.trim(),r=L.length>0;if(!e&&!r||t)return;if("/new"===e){p(""),o();return}if("/status"===e){p(""),c();return}let a=r?[...L]:void 0;p(""),E([]),v(!1),S(!1),A.current&&(A.current.style.height="auto"),s(e,a,!1)}async function W(e){let t=e.target.files;if(!t||0===t.length)return;let r=[];for(let e=0;e<t.length;e++)r.push(await ed(t[e]));E(e=>[...e,...r]),e.target.value=""}async function B(e){var t;let r=null==(t=e.clipboardData)?void 0:t.items;if(r){for(let t=0;t<r.length;t++)if(r[t].type.startsWith("image/")){e.preventDefault();let a=r[t].getAsFile();if(a){let e=await ed(a);E(t=>[...t,e])}return}}}let K=(0,n.useCallback)(e=>{e&&p(t=>t?t+" "+e:e)},[]);async function P(){if("recording"===T.state){var e;let t=await T.stopRecording();K(null!=t?t:""),null==(e=A.current)||e.focus()}else"transcribing"===T.state||T.handleMicClick()}(0,n.useEffect)(()=>{A.current&&(A.current.style.height="auto",A.current.style.height=Math.min(A.current.scrollHeight,120)+"px")},[x]);let q=w.filter(e=>e.name.toLowerCase().startsWith(C)),O=m.filter(e=>e.name.toLowerCase().includes(f)),V=x.trim().length>0||L.length>0;return(0,a.jsxs)("div",{className:"px-3 sm:px-4 pt-[var(--space-3)] pb-[var(--space-3)] border-t border-t-[var(--separator)] bg-[var(--material-regular)] shrink-0 relative",children:[N&&q.length>0&&(0,a.jsx)("div",{className:"absolute bottom-full left-[var(--space-4)] right-[var(--space-4)] mb-1 bg-[var(--bg)] border border-[var(--separator)] rounded-[var(--radius-md)] shadow-[var(--shadow-lg)] max-h-60 overflow-y-auto z-10",children:q.map((e,t)=>{let r=t===D;return(0,a.jsxs)("button",{ref:e=>{r&&e&&e.scrollIntoView({block:"nearest"})},onClick:()=>F(e),className:"w-full text-left py-[var(--space-2)] px-[var(--space-3)] text-[length:var(--text-footnote)] ".concat(r?"bg-[var(--fill-secondary)]":"bg-transparent"," border-none cursor-pointer flex items-center gap-[var(--space-2)] text-[var(--text-primary)]"),children:[(0,a.jsxs)("span",{className:"font-[family-name:var(--font-mono)] font-[var(--weight-semibold)] text-[var(--accent)] text-[length:var(--text-footnote)]",children:["/",e.name]}),(0,a.jsx)("span",{className:"text-[var(--text-tertiary)] text-[length:var(--text-caption1)]",children:e.description})]},e.name)})}),g&&O.length>0&&(0,a.jsx)("div",{className:"absolute bottom-full left-[var(--space-4)] right-[var(--space-4)] mb-1 bg-[var(--bg)] border border-[var(--separator)] rounded-[var(--radius-md)] shadow-[var(--shadow-lg)] max-h-40 overflow-y-auto z-10",children:O.slice(0,8).map((e,t)=>{let r=t===y;return(0,a.jsxs)("button",{ref:e=>{e?_.current.set(t,e):_.current.delete(t),r&&e&&e.scrollIntoView({block:"nearest"})},onClick:()=>R(e.name),className:"w-full text-left py-[var(--space-2)] px-[var(--space-3)] text-[length:var(--text-footnote)] ".concat(r?"bg-[var(--fill-secondary)]":"bg-transparent"," border-none cursor-pointer flex items-center gap-[var(--space-2)] text-[var(--text-primary)]"),children:[(0,a.jsx)("span",{className:"text-base leading-none",children:{executive:"\uD83C\uDFAF",manager:"\uD83D\uDCCB",senior:"⭐",employee:"\uD83D\uDC64"}[e.rank||"employee"]||"\uD83D\uDC64"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-[var(--space-2)]",children:[(0,a.jsx)("span",{className:"font-[var(--weight-semibold)]",children:e.displayName||e.name}),(0,a.jsxs)("span",{className:"font-[family-name:var(--font-mono)] text-[length:var(--text-caption2)] text-[var(--text-tertiary)]",children:["@",e.name]})]}),e.department&&(0,a.jsxs)("div",{className:"text-[length:var(--text-caption2)] text-[var(--text-quaternary)] flex gap-[var(--space-2)] mt-px",children:[(0,a.jsx)("span",{children:e.department}),e.engine&&(0,a.jsx)("span",{className:"text-[var(--accent)] font-[var(--weight-medium)]",children:e.engine})]})]})]},e.name)})}),L.length>0&&(0,a.jsx)("div",{className:"mb-[var(--space-2)]",children:(0,a.jsx)(el,{attachments:L,onRemove:function(e){E(t=>t.filter((t,r)=>r!==e))}})}),(0,a.jsxs)("div",{className:"flex items-center gap-[var(--space-2)] bg-[var(--fill-secondary)] rounded-[var(--radius-lg)] py-1.5 px-[var(--space-3)] min-h-11 transition-[border-color] duration-200 ease-in-out border ".concat(r?"border-[var(--accent)]":"border-[var(--separator)]"),children:[(0,a.jsx)("button",{"aria-label":"Attach file",onClick:()=>{var e;return null==(e=z.current)?void 0:e.click()},className:"w-8 h-8 shrink-0 rounded-[var(--radius-sm)] flex items-center justify-center bg-transparent border-none cursor-pointer text-[var(--text-secondary)] mb-0",children:(0,a.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,a.jsx)("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}),(0,a.jsx)("input",{ref:z,type:"file",accept:"image/*,audio/*,.pdf,.doc,.docx,.txt,.csv,.json,.zip",multiple:!0,className:"hidden",onChange:W}),(0,a.jsx)("textarea",{ref:A,value:x,onChange:function(e){let t=e.target.value;if(p(t),t.startsWith("/")&&!t.includes(" ")){I(t.slice(1).toLowerCase()),M(0),S(!0),v(!1);return}S(!1);let r=t.lastIndexOf("@");if(-1!==r){let e=t.slice(r+1);if(!e.includes(" ")&&!e.includes("\n")){b(e.toLowerCase()),j(0),v(!0);return}}v(!1)},onKeyDown:function(e){if(N&&q.length>0){let t=q.length;if("ArrowDown"===e.key){e.preventDefault(),M(e=>(e+1)%t);return}if("ArrowUp"===e.key){e.preventDefault(),M(e=>(e-1+t)%t);return}if("Tab"===e.key||"Enter"===e.key){e.preventDefault(),F(q[D]);return}if("Escape"===e.key){e.preventDefault(),S(!1);return}}if(g&&O.length>0){let t=Math.min(O.length,8);if("ArrowDown"===e.key){e.preventDefault(),j(e=>(e+1)%t);return}if("ArrowUp"===e.key){e.preventDefault(),j(e=>(e-1+t)%t);return}if("Tab"===e.key||"Enter"===e.key){e.preventDefault(),R(O[y].name);return}if("Escape"===e.key){e.preventDefault(),v(!1);return}}"Enter"!==e.key||e.shiftKey||(e.preventDefault(),U())},onPaste:B,placeholder:t?"Waiting for response...":"Type a message...",rows:1,disabled:t,className:"flex-1 bg-transparent border-none outline-none resize-none text-[var(--text-primary)] text-[length:var(--text-subheadline)] leading-5 max-h-30 min-h-5 h-5 p-0 m-0 ".concat(t?"opacity-50":"opacity-100"),onInput:e=>{let t=e.target;t.style.height="auto",t.style.height=Math.min(t.scrollHeight,120)+"px"}}),T.languages.length>1&&(0,a.jsx)("button",{"aria-label":"STT language: ".concat(T.selectedLanguage.toUpperCase(),". Click to switch."),onClick:T.cycleLanguage,className:"h-6 px-1.5 shrink-0 rounded-[var(--radius-sm)] flex items-center justify-center bg-[var(--fill-tertiary)] border-none cursor-pointer text-[var(--text-secondary)] text-[11px] font-semibold font-[family-name:var(--font-mono)] tracking-[0.5px] uppercase transition-all duration-150 ease-in-out",title:"Transcription language: ".concat(T.selectedLanguage.toUpperCase(),". Click to cycle."),children:T.selectedLanguage}),(0,a.jsx)("button",{"aria-label":"recording"===T.state?"Stop recording":"transcribing"===T.state?"Transcribing…":"Voice input",onClick:P,disabled:"transcribing"===T.state,className:"w-8 h-8 shrink-0 flex items-center justify-center border-none transition-all duration-150 ease-in-out ".concat("recording"===T.state?"rounded-full bg-[var(--system-red)] text-white cursor-pointer":"rounded-[var(--radius-sm)] bg-transparent text-[var(--text-secondary)] ".concat("transcribing"===T.state?"cursor-wait":"cursor-pointer")),title:"recording"===T.state?"Stop recording":"transcribing"===T.state?"Transcribing…":"Voice input",children:"transcribing"===T.state?(0,a.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"animate-[stt-spin_1s_linear_infinite]",children:(0,a.jsx)("path",{d:"M12 2a10 10 0 0 1 10 10"})}):(0,a.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,a.jsx)("path",{d:"M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"}),(0,a.jsx)("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),(0,a.jsx)("line",{x1:"12",y1:"19",x2:"12",y2:"23"}),(0,a.jsx)("line",{x1:"8",y1:"23",x2:"16",y2:"23"})]})}),"recording"===T.state&&T.analyser&&(0,a.jsx)(eo,{analyser:T.analyser,width:64,height:28}),r&&i&&(0,a.jsx)("button",{onClick:i,"aria-label":"Stop",className:"w-8 h-8 rounded-full bg-[var(--system-red)] text-white border-none cursor-pointer flex items-center justify-center shrink-0 transition-all duration-150 ease-in-out",children:(0,a.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:(0,a.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"})})}),(0,a.jsx)("button",{onClick:U,disabled:!V||t,"aria-label":"Send message",className:"w-8 h-8 rounded-full border-none flex items-center justify-center shrink-0 transition-all duration-150 ease-in-out ".concat(V?"bg-[var(--accent)] text-[var(--accent-contrast)] cursor-pointer":"bg-[var(--fill-tertiary)] text-[var(--text-quaternary)] cursor-default"),children:(0,a.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,a.jsx)("line",{x1:"12",y1:"19",x2:"12",y2:"5"}),(0,a.jsx)("polyline",{points:"5 12 12 5 19 12"})]})})]}),(0,a.jsxs)("div",{className:"hidden sm:flex text-[length:var(--text-caption2)] text-[var(--text-quaternary)] text-center mt-[var(--space-1)] justify-center gap-[var(--space-3)]",children:[(0,a.jsx)("span",{children:"Enter to send"}),(0,a.jsx)("span",{children:"/ - commands"}),(0,a.jsx)("span",{children:"@name - mention"})]}),"error"===T.state&&T.error&&(0,a.jsxs)("div",{className:"flex items-center gap-[var(--space-2)] mt-[var(--space-2)] py-[var(--space-2)] px-[var(--space-3)] rounded-[var(--radius-sm)] text-[length:var(--text-caption1)] text-[var(--system-red)]",style:{background:"color-mix(in srgb, var(--system-red) 12%, transparent)"},children:[(0,a.jsxs)("span",{className:"flex-1",children:["Voice input error: ",T.error]}),(0,a.jsx)("button",{onClick:T.dismissError,className:"bg-none border-none cursor-pointer text-[var(--system-red)] text-[length:var(--text-caption1)] font-semibold py-0.5 px-1.5",children:"Dismiss"})]}),(0,a.jsx)(ei,{open:"no-model"===T.state,progress:T.downloadProgress,onDownload:T.startDownload,onCancel:T.dismissDownload}),(0,a.jsx)("style",{children:"\n @keyframes stt-spin {\n from { transform: rotate(0deg); }\n to { transform: rotate(360deg); }\n }\n "})]})}var ex=r(687),ep=r(7181);function em(e){let{sessionId:t,events:r,paused:s=!1}=e,[i,o]=(0,n.useState)([]),[c,d]=(0,n.useState)(s),u=(0,n.useCallback)(async()=>{if(t)try{let e=await l.F.getSessionQueue(t);o(e)}catch(e){}},[t]);(0,n.useEffect)(()=>{u()},[u]),(0,n.useEffect)(()=>{if(!r.length)return;let e=r[r.length-1];if("queue:updated"===e.event){u();let t=e.payload;"boolean"==typeof(null==t?void 0:t.paused)&&d(t.paused)}},[r,u]);let x=i.filter(e=>"pending"===e.status);if(!t||0===x.length)return null;async function m(e){if(t)try{await l.F.cancelQueueItem(t,e),await u()}catch(e){}}async function h(){if(t)try{await l.F.clearSessionQueue(t),o([])}catch(e){}}async function v(){if(t)try{c?(await l.F.resumeSessionQueue(t),d(!1)):(await l.F.pauseSessionQueue(t),d(!0))}catch(e){}}return(0,a.jsxs)("div",{className:"border-t border-[var(--separator)] px-[var(--space-4)] py-[var(--space-2)] bg-[var(--fill-quaternary)] shrink-0",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between mb-[var(--space-1)]",children:[(0,a.jsxs)("span",{className:"text-[length:var(--text-caption2)] font-semibold text-[var(--text-secondary)] uppercase tracking-[0.5px]",children:[x.length," queued ",c&&"\xb7 Paused"]}),(0,a.jsxs)("div",{className:"flex gap-[var(--space-1)]",children:[(0,a.jsx)("button",{onClick:v,title:c?"Resume queue":"Pause queue",className:"bg-transparent border-none cursor-pointer text-[var(--text-secondary)] p-0.5 flex items-center",children:c?(0,a.jsx)(ex.A,{size:13}):(0,a.jsx)(ep.A,{size:13})}),(0,a.jsx)("button",{onClick:h,title:"Clear all queued messages",className:"bg-transparent border-none cursor-pointer text-[var(--text-secondary)] p-0.5 flex items-center",children:(0,a.jsx)(p.A,{size:13})})]})]}),(0,a.jsx)("div",{className:"flex flex-col gap-0.5",children:x.map(e=>(0,a.jsxs)("div",{className:"flex items-center gap-[var(--space-2)] px-[var(--space-2)] py-[3px] rounded-[var(--radius-sm)] bg-[var(--fill-tertiary)]",children:[(0,a.jsxs)("span",{className:"text-[length:var(--text-caption2)] text-[var(--text-tertiary)] min-w-4",children:[e.position,"."]}),(0,a.jsx)("span",{className:"flex-1 text-[length:var(--text-caption1)] text-[var(--text-secondary)] overflow-hidden text-ellipsis whitespace-nowrap",children:e.prompt.length>60?e.prompt.slice(0,57)+"...":e.prompt}),(0,a.jsx)("button",{onClick:()=>m(e.id),title:"Cancel this message",className:"bg-transparent border-none cursor-pointer text-[var(--text-tertiary)] p-px flex items-center shrink-0",children:(0,a.jsx)(g.A,{size:11})})]},e.id))})]})}function eh(e){let{input:t}=e,[r,s]=(0,n.useState)(!1),l=JSON.stringify(t,null,2);return l.length>300?(0,a.jsxs)("div",{children:[(0,a.jsx)("button",{onClick:()=>s(e=>!e),className:"mt-1 px-2 py-0.5 text-[11px] rounded bg-white/[0.08] border border-white/[0.12] text-[var(--text-tertiary)] cursor-pointer font-[SF_Mono,Menlo,Cascadia_Code,monospace]",children:r?"collapse input":"show input (".concat(l.length," chars)")}),r&&(0,a.jsx)("pre",{className:"mt-1 px-2.5 py-1.5 bg-white/5 rounded text-xs leading-normal whitespace-pre-wrap break-all text-[var(--text-secondary)] font-[SF_Mono,Menlo,Cascadia_Code,monospace] overflow-x-auto max-h-[400px] overflow-y-auto",children:l})]}):(0,a.jsx)("pre",{className:"mt-1 px-2.5 py-1.5 bg-white/5 rounded text-xs leading-normal whitespace-pre-wrap break-all text-[var(--text-secondary)] font-[SF_Mono,Menlo,Cascadia_Code,monospace] overflow-x-auto",children:l})}function eg(e){let{text:t}=e,[r,s]=(0,n.useState)(!1);return(0,a.jsxs)("div",{className:"mb-1.5",children:[(0,a.jsx)("button",{onClick:()=>s(e=>!e),className:"px-2 py-0.5 text-[11px] rounded bg-white/[0.06] border border-white/10 text-[var(--text-quaternary,var(--text-tertiary))] cursor-pointer font-[SF_Mono,Menlo,Cascadia_Code,monospace] italic",children:r?"hide thinking":"show thinking"}),r&&(0,a.jsx)("div",{className:"mt-1 px-3 py-2 bg-white/[0.04] border-l-2 border-white/10 text-xs leading-relaxed text-[var(--text-quaternary,var(--text-tertiary))] italic whitespace-pre-wrap break-words font-[SF_Mono,Menlo,Cascadia_Code,monospace]",children:t})]})}function ev(e){let{text:t}=e,[r,s]=(0,n.useState)(!1);return t.length>500?(0,a.jsxs)("div",{children:[(0,a.jsx)("button",{onClick:()=>s(e=>!e),className:"mt-1 px-2 py-0.5 text-[11px] rounded bg-white/[0.08] border border-white/[0.12] text-[var(--text-tertiary)] cursor-pointer font-[SF_Mono,Menlo,Cascadia_Code,monospace]",children:r?"collapse output":"show output (".concat(t.length," chars)")}),r&&(0,a.jsx)("pre",{className:"mt-1 px-2.5 py-1.5 bg-white/[0.04] rounded text-xs leading-normal whitespace-pre-wrap break-all text-[var(--text-tertiary)] font-[SF_Mono,Menlo,Cascadia_Code,monospace] overflow-x-auto max-h-[400px] overflow-y-auto",children:t})]}):(0,a.jsx)("pre",{className:"mt-1 px-2.5 py-1.5 bg-white/[0.04] rounded text-xs leading-normal whitespace-pre-wrap break-all text-[var(--text-tertiary)] font-[SF_Mono,Menlo,Cascadia_Code,monospace] overflow-x-auto max-h-[300px] overflow-y-auto",children:t||"(empty)"})}function ef(e){let{block:t}=e;return"thinking"===t.type?(0,a.jsx)(eg,{text:t.text||""}):"tool_use"===t.type?(0,a.jsxs)("div",{className:"mb-2 px-2.5 py-1.5 bg-[rgba(99,179,237,0.08)] border border-[rgba(99,179,237,0.2)] rounded-md",children:[(0,a.jsxs)("div",{className:"text-[11px] font-semibold text-[rgba(99,179,237,0.9)] font-[SF_Mono,Menlo,Cascadia_Code,monospace] mb-0.5 uppercase tracking-wide",children:["tool: ",t.name]}),t.input&&Object.keys(t.input).length>0&&(0,a.jsx)(eh,{input:t.input})]}):"tool_result"===t.type?(0,a.jsxs)("div",{className:"mb-2 px-2.5 py-1.5 bg-white/[0.03] border border-white/[0.08] rounded-md",children:[(0,a.jsx)("div",{className:"text-[11px] font-semibold text-[rgba(160,160,160,0.7)] font-[SF_Mono,Menlo,Cascadia_Code,monospace] mb-0.5 uppercase tracking-wide",children:"result"}),(0,a.jsx)(ev,{text:t.text||""})]}):(0,a.jsx)("div",{className:"whitespace-pre-wrap break-words leading-relaxed text-[var(--text-primary)] mb-1",children:t.text})}function eb(e){let{entry:t}=e,r="user"===t.role;return(0,a.jsxs)("div",{className:"flex gap-2.5 py-2.5 border-b border-white/[0.04]",children:[(0,a.jsx)("div",{className:"shrink-0 w-4 text-[13px] font-bold font-[SF_Mono,Menlo,Cascadia_Code,monospace] pt-px",style:{color:r?"var(--accent)":"rgba(110, 231, 183, 0.8)"},children:r?">":"$"}),(0,a.jsx)("div",{className:"flex-1 min-w-0",children:t.content.map((e,t)=>(0,a.jsx)(ef,{block:e},t))})]})}function ey(e){let{sessionId:t}=e,[r,s]=(0,n.useState)([]),[i,o]=(0,n.useState)(!0),[c,d]=(0,n.useState)(null),u=(0,n.useRef)(null);return((0,n.useEffect)(()=>{t&&(o(!0),d(null),l.F.getSessionTranscript(t).then(e=>{s(e),o(!1)}).catch(e=>{d(e instanceof Error?e.message:"Failed to load transcript"),o(!1)}))},[t]),(0,n.useEffect)(()=>{var e;null==(e=u.current)||e.scrollIntoView({behavior:"instant"})},[r]),i)?(0,a.jsx)("div",{className:"flex-1 flex items-center justify-center bg-[var(--bg-primary,var(--bg))] text-[var(--text-tertiary)] font-[SF_Mono,Menlo,Cascadia_Code,monospace] text-[13px]",children:"loading transcript..."}):c?(0,a.jsxs)("div",{className:"flex-1 flex items-center justify-center bg-[var(--bg-primary,var(--bg))] text-[var(--system-red)] font-[SF_Mono,Menlo,Cascadia_Code,monospace] text-[13px]",children:["error: ",c]}):0===r.length?(0,a.jsx)("div",{className:"flex-1 flex items-center justify-center bg-[var(--bg-primary,var(--bg))] text-[var(--text-tertiary)] font-[SF_Mono,Menlo,Cascadia_Code,monospace] text-[13px]",children:"no transcript available"}):(0,a.jsxs)("div",{className:"flex-1 overflow-y-auto overflow-x-hidden bg-[var(--bg-primary,var(--bg))] p-[var(--space-4)] font-[SF_Mono,Menlo,Cascadia_Code,monospace] text-[13px] leading-normal min-h-0",children:[r.map((e,t)=>(0,a.jsx)(eb,{entry:e},t)),(0,a.jsx)("div",{ref:u})]})}function ej(e){var t;let{sessionId:r,isActive:s,onFocus:i,onSessionCreated:o,onSessionMetaChange:c,onRefresh:d,portalName:u="Jinn",subscribe:x,connectionSeq:p,skillsVersion:m,events:h,viewMode:g="chat",getOnboardingPrompt:v,isStubSession:f,onStubCleared:b}=e,[y,j]=(0,n.useState)([]),[w,k]=(0,n.useState)(!1),N=(0,n.useRef)(""),[S,C]=(0,n.useState)(""),I=(0,n.useRef)(-1),[D,M]=(0,n.useState)(null),L=(0,n.useRef)(r);(0,n.useEffect)(()=>{L.current=r},[r]);let E=(0,n.useCallback)((e,t)=>{if(!t)return;let r=I.current;if(r<0)return;let a=e.slice(r);a.length>0&&function(e,t){try{localStorage.setItem("".concat(V).concat(e),JSON.stringify(t))}catch(e){}}(t,a)},[]);(0,n.useEffect)(()=>x((e,t)=>{let r=L.current;if(r&&t.sessionId===r){if("session:delta"===e){let e=String(t.type||"text");if("text"===e){let e=String(t.content||"");N.current+=e,C(N.current)}else if("text_snapshot"===e){let e=String(t.content||"");e.length>=N.current.length&&(N.current=e,C(e))}else if("tool_use"===e){if(N.current){let e=N.current;N.current="",C(""),j(t=>{I.current<0&&(I.current=t.length);let a=[...t,{id:crypto.randomUUID(),role:"assistant",content:e,timestamp:Date.now()}];return E(a,r),a})}let e=String(t.toolName||"tool");j(t=>{I.current<0&&(I.current=t.length);let a=[...t,{id:crypto.randomUUID(),role:"assistant",content:"Using ".concat(e),timestamp:Date.now(),toolCall:e}];return E(a,r),a})}else"tool_result"===e&&j(e=>{let t=[...e],a=t[t.length-1];return a&&"assistant"===a.role&&a.toolCall&&(t[t.length-1]={...a,content:"Used ".concat(a.toolCall)}),E(t,r),t})}if("session:notification"===e){let e=String(t.message||"");e&&j(t=>[...t,{id:crypto.randomUUID(),role:"notification",content:e,timestamp:Date.now()}])}if("session:interrupted"===e&&(N.current="",C("")),"session:stopped"===e&&(k(!1),C("")),"session:completed"===e){N.current="",C(""),k(!1),I.current=-1;let e=r||(t.sessionId?String(t.sessionId):null);e&&J(e),t.result&&j(e=>{let r=[...e],a=r[r.length-1];return a&&"assistant"===a.role&&!a.toolCall&&r.pop(),[...r,{id:crypto.randomUUID(),role:"assistant",content:String(t.result),timestamp:Date.now()}]}),t.error&&!t.result&&j(e=>[...e,{id:crypto.randomUUID(),role:"assistant",content:"Error: ".concat(t.error),timestamp:Date.now()}]),null==d||d()}}}),[x,E,d]);let A=(0,n.useCallback)(async e=>{try{let t=await l.F.getSession(e);M(t);let r={engine:t.engine?String(t.engine):void 0,engineSessionId:t.engineSessionId?String(t.engineSessionId):void 0,model:t.model?String(t.model):void 0,title:t.title?String(t.title):void 0,employee:t.employee?String(t.employee):void 0};null==c||c(r);let a=t.messages||t.history||[],n=Array.isArray(a)?a.map(e=>({id:crypto.randomUUID(),role:e.role||"assistant",content:String(e.content||e.text||""),timestamp:e.timestamp?Number(e.timestamp):Date.now()})):[];if("error"===t.status&&t.lastError){let e=n[n.length-1],r="Error: ".concat(String(t.lastError));e&&"assistant"===e.role&&e.content===r||n.push({id:crypto.randomUUID(),role:"assistant",content:r,timestamp:Date.now()})}if("running"===t.status){let t=function(e){try{let t=localStorage.getItem("".concat(V).concat(e));return t?JSON.parse(t):[]}catch(e){return[]}}(e);t.length>0?(I.current=n.length,j([...n,...t])):(I.current=n.length,j(n)),k(!0)}else J(e),I.current=-1,j(n)}catch(e){j([]),M(null),I.current=-1}},[c]);(0,n.useEffect)(()=>{if(!r){j([]),k(!1),M(null),N.current="",C(""),I.current=-1;return}A(r)},[r,A]),(0,n.useEffect)(()=>{p&&r&&A(r)},[p,r,A]),(0,n.useEffect)(()=>{if(!r||!w)return;let e=setInterval(async()=>{try{let e=await l.F.getSession(r);"running"!==e.status&&(await A(r),k(!1))}catch(e){}},5e3);return()=>clearInterval(e)},[r,w,A]);let z=(0,n.useCallback)(async()=>{if(r)try{await l.F.stopSession(r)}catch(e){}},[r]),_=(0,n.useCallback)(async(e,t,a)=>{let n={id:crypto.randomUUID(),role:"user",content:e,timestamp:Date.now(),media:t};j(e=>(I.current=e.length+1,[...e,n])),k(!0);try{let t=r;if(t&&f&&v){null==b||b();let r=v(e);await l.F.sendMessage(t,{message:r}),null==d||d()}else if(t)await l.F.sendMessage(t,{message:e,interrupt:a||void 0}),null==d||d();else{let r=await l.F.createSession({source:"web",prompt:e});t=String(r.id),null==o||o(t),null==d||d()}}catch(e){k(!1),j(t=>[...t,{id:crypto.randomUUID(),role:"assistant",content:"Error: ".concat(e instanceof Error?e.message:"Failed to send message"),timestamp:Date.now()}])}},[r,f,v,b,o,d]),T=(0,n.useCallback)(async()=>{if(!r)return void j(e=>[...e,{id:crypto.randomUUID(),role:"assistant",content:"No active session. Send a message to start one.",timestamp:Date.now()}]);try{let e=await l.F.getSession(r),t=["**Session Info**","ID: `".concat(e.id,"`"),"Status: ".concat(e.status||"unknown"),e.employee?"Employee: ".concat(e.employee):null,e.engine?"Engine: ".concat(e.engine):null,e.model?"Model: ".concat(e.model):null,e.createdAt?"Created: ".concat(e.createdAt):null].filter(Boolean).join("\n");j(e=>[...e,{id:crypto.randomUUID(),role:"assistant",content:t,timestamp:Date.now()}])}catch(e){j(e=>[...e,{id:crypto.randomUUID(),role:"assistant",content:"Failed to fetch session status.",timestamp:Date.now()}])}},[r]),R=(0,n.useCallback)(()=>{j([]),k(!1),M(null),N.current="",C(""),I.current=-1},[]);return(0,a.jsxs)("div",{style:{display:"flex",flexDirection:"column",flex:1,overflow:"hidden",background:"var(--bg)"},onClick:i,children:["cli"===g&&r?(0,a.jsx)(ey,{sessionId:r}):(0,a.jsx)(es,{messages:y,loading:w,streamingText:S}),"chat"===g&&(0,a.jsx)(em,{sessionId:r,events:h,paused:null!=(t=null==D?void 0:D.paused)&&t}),"chat"===g&&(0,a.jsx)(eu,{disabled:!1,loading:w,onSend:_,onInterrupt:z,onNewSession:R,onStatusRequest:T,skillsVersion:m,events:h})]})}let ew="jinn-chat-tabs",ek="jinn-chat-draft-";var eN=r(7122),eS=r(5465),eC=r(7632),eI=r(6790),eD=r(4139);class eM extends n.Component{static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error("[ChatErrorBoundary]",e.message,"\nComponent stack:",t.componentStack)}render(){if(this.state.error){var e;return(0,a.jsx)(o.M,{children:(0,a.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-4 p-8 text-center",children:[(0,a.jsx)("p",{className:"text-lg font-semibold text-[var(--system-red)]",children:"Chat crashed"}),(0,a.jsxs)("pre",{className:"max-w-lg overflow-auto rounded-lg bg-[var(--bg-tertiary)] p-4 text-left text-xs text-muted-foreground",children:[this.state.error.message,"\n",null==(e=this.state.error.stack)?void 0:e.split("\n").slice(0,5).join("\n")]}),(0,a.jsx)("button",{onClick:()=>{this.setState({error:null}),window.location.reload()},className:"rounded-md bg-[var(--accent)] px-4 py-2 text-sm font-medium text-white",children:"Reload"})]})})}return this.props.children}constructor(...e){super(...e),this.state={error:null}}}function eL(){return(0,a.jsx)(eM,{children:(0,a.jsx)(n.Suspense,{fallback:(0,a.jsx)(o.M,{children:(0,a.jsx)("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:"Loading..."})}),children:(0,a.jsx)(eE,{})})})}function eE(){var e;let{settings:t}=(0,b.t0)(),r=null!=(e=t.portalName)?e:"Jinn",[c,d]=(0,n.useState)(null),[u,m]=(0,n.useState)("sidebar"),[h,g]=(0,n.useState)(null),[v,f]=(0,n.useState)([]),j=(0,n.useRef)(!1),[k,N]=(0,n.useState)("chat"),[S,C]=(0,n.useState)(!1),[I,M]=(0,n.useState)(!1),[L,E]=(0,n.useState)(null),[A,z]=(0,n.useState)(!1),_=(0,n.useRef)(null),T=(0,n.useRef)(null),{events:R,connectionSeq:F,skillsVersion:U,subscribe:W}=(0,i.G)(),B=function(){let[{tabs:e,activeIndex:t},r]=(0,n.useState)({tabs:[],activeIndex:-1});(0,n.useEffect)(()=>{r(function(){try{let t=localStorage.getItem(ew);if(t){var e;return e=JSON.parse(t),0===e.tabs.length?{tabs:[],activeIndex:-1}:e.activeIndex<0||e.activeIndex>=e.tabs.length?{tabs:e.tabs,activeIndex:0}:e}}catch(e){}return{tabs:[],activeIndex:-1}}())},[]),(0,n.useEffect)(()=>{localStorage.setItem(ew,JSON.stringify({tabs:e,activeIndex:t}))},[e,t]);let a=t>=0?e[t]:null,s=(0,n.useCallback)(e=>{r(t=>{let r=t.tabs.findIndex(t=>t.sessionId===e.sessionId);if(r>=0)return{tabs:t.tabs.map((t,a)=>a===r?{...t,...e}:t),activeIndex:r};if(t.tabs.length>=12){let r=t.tabs.findIndex((e,r)=>r!==t.activeIndex);if(r>=0){let a=[...t.tabs];return a[r]=e,{tabs:a,activeIndex:r}}}return{tabs:[...t.tabs,e],activeIndex:t.tabs.length}})},[]),l=(0,n.useCallback)(e=>{r(t=>{var r;let a=null==(r=t.tabs[e])?void 0:r.sessionId;a&&localStorage.removeItem(ek+a);let n=t.tabs.filter((t,r)=>r!==e);if(0===n.length)return{tabs:[],activeIndex:-1};let s=t.activeIndex;return t.activeIndex===e?s=Math.min(e,n.length-1):t.activeIndex>e&&(s=t.activeIndex-1),{tabs:n,activeIndex:s}})},[]),i=(0,n.useCallback)(e=>{r(t=>e<0||e>=t.tabs.length?t:{...t,activeIndex:e})},[e.length]),o=(0,n.useCallback)(()=>{r(e=>0===e.tabs.length?e:{...e,activeIndex:(e.activeIndex+1+e.tabs.length)%e.tabs.length})},[e.length]),c=(0,n.useCallback)(()=>{r(e=>0===e.tabs.length?e:{...e,activeIndex:(e.activeIndex-1+e.tabs.length)%e.tabs.length})},[e.length]),d=(0,n.useCallback)(()=>{r(e=>({...e,activeIndex:-1}))},[]),u=(0,n.useCallback)((e,t)=>{t.trim()?localStorage.setItem(ek+e,t):localStorage.removeItem(ek+e)},[]);return{tabs:e,activeTab:a,activeIndex:t,openTab:s,closeTab:l,switchTab:i,nextTab:o,prevTab:c,clearActiveTab:d,saveDraft:u,loadDraft:(0,n.useCallback)(e=>localStorage.getItem(ek+e)||"",[]),updateTabStatus:(0,n.useCallback)((e,t)=>{r(r=>({...r,tabs:r.tabs.map(r=>r.sessionId===e?{...r,...t}:r)}))},[])}}(),P=(0,s.useSearchParams)(),q=(0,n.useRef)(!1),V=(0,n.useRef)(!1);(0,y.tS)();let H=(0,eN.jE)();(0,n.useEffect)(()=>{if(S||I)return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e);function e(e){S&&_.current&&!_.current.contains(e.target)&&C(!1),I&&T.current&&!T.current.contains(e.target)&&M(!1)}},[S,I]);let Q=(0,n.useCallback)((e,t)=>{navigator.clipboard.writeText(e),E(t),C(!1),setTimeout(()=>E(null),1500)},[]);function $(){l.F.createStubSession({greeting:"Hey! \uD83D\uDC4B Say hi when you're ready to get started.",title:"Welcome"}).then(e=>{let t=String(e.id);V.current=!0,d(t),H.invalidateQueries({queryKey:eS.l.sessions.all})}).catch(()=>{})}(0,n.useEffect)(()=>{q.current||("1"===P.get("onboarding")?(q.current=!0,$()):l.F.getOnboarding().then(e=>{e.needed&&!q.current&&(q.current=!0,$())}).catch(()=>{}))},[P]),(0,n.useEffect)(()=>{c&&h&&B.updateTabStatus(c,{label:h.title||h.employee||r})},[c,h,r,B]);let G=(0,n.useCallback)(e=>{f(e.length>1?e:[])},[]),Y=(0,n.useCallback)(e=>{j.current=!1,V.current=!1,d(e),m("chat"),N("chat"),B.openTab({sessionId:e,label:"Loading...",status:"idle",unread:!1})},[B]),X=(0,n.useCallback)(()=>{j.current=!0,d(null),g(null),m("chat"),f([]),B.clearActiveTab()},[B]),Z=(0,n.useCallback)(e=>{c||q.current||j.current||!(e.length>0)||Y(e[0].id)},[c,Y]),ee=(0,n.useCallback)(e=>{c===e&&(d(null),g(null)),J(e),B.closeTab(B.tabs.findIndex(t=>t.sessionId===e)),z(!1),C(!1)},[c,B]),et=(0,n.useCallback)(e=>{d(e),B.openTab({sessionId:e,label:"New Chat",status:"running",unread:!1}),H.invalidateQueries({queryKey:eS.l.sessions.all})},[B,H]),er=(0,n.useCallback)(e=>{g(e)},[]),ea=(0,n.useCallback)(()=>{H.invalidateQueries({queryKey:eS.l.sessions.all})},[H]),en=(0,n.useCallback)(e=>"This is your first time being activated. The user just set up ".concat(r," and opened the web dashboard for the first time.\n\nRead your CLAUDE.md instructions and the onboarding skill at ~/.jinn/skills/onboarding/SKILL.md, then follow the onboarding flow:\n- Greet the user warmly and introduce yourself as ").concat(r,"\n- Briefly explain what you can do (manage cron jobs, hire AI employees, connect to Slack, etc.)\n- Ask the user what they'd like to set up first\n\nThe user said: \"").concat(e,'"'),[r]),es=(0,n.useCallback)(()=>{V.current=!1},[]);(0,n.useEffect)(()=>{function e(e){e.metaKey&&"w"===e.key&&(e.preventDefault(),B.activeIndex>=0&&B.closeTab(B.activeIndex)),e.metaKey&&e.shiftKey&&"["===e.key&&(e.preventDefault(),B.prevTab()),e.metaKey&&e.shiftKey&&"]"===e.key&&(e.preventDefault(),B.nextTab()),e.metaKey&&e.altKey&&e.key>="1"&&e.key<="9"&&(e.preventDefault(),B.switchTab(parseInt(e.key)-1))}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[B]),(0,n.useEffect)(()=>{if(B.activeTab&&B.activeTab.sessionId!==c){d(B.activeTab.sessionId),N("chat");return}B.activeTab||!c||j.current||(d(null),g(null),f([]))},[B.activeTab,c]);let el=c?(0,a.jsxs)("div",{ref:_,className:"relative",children:[(0,a.jsx)("button",{onClick:()=>C(e=>!e),"aria-label":"More options",className:"flex items-center rounded-md p-1 text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",children:(0,a.jsx)(x.A,{className:"size-[18px]"})}),S&&(0,a.jsxs)("div",{className:"absolute right-0 top-full z-[200] mt-1 min-w-[220px] overflow-hidden rounded-[var(--radius-md)] border border-border bg-[var(--material-thick)] shadow-[var(--shadow-overlay)] backdrop-blur-xl",children:[(0,a.jsx)("button",{onClick:()=>Q(c,"id"),className:"block w-full px-3 py-2 text-left text-sm text-foreground transition-colors hover:bg-accent",children:"Copy Session ID"}),(null==h?void 0:h.engineSessionId)&&(0,a.jsx)("button",{onClick:()=>{let e="codex"===h.engine?"codex":"claude";Q("".concat(e," --resume ").concat(h.engineSessionId),"cli")},className:"block w-full px-3 py-2 text-left text-sm text-foreground transition-colors hover:bg-accent",children:"Copy CLI Resume Command"}),(0,a.jsx)("div",{className:"my-0.5 border-t border-border"}),(0,a.jsxs)("button",{onClick:()=>{C(!1),z(!0)},className:"flex w-full items-center gap-2 px-3 py-2 text-left text-sm text-[var(--system-red)] transition-colors hover:bg-accent",children:[(0,a.jsx)(p.A,{className:"size-3.5"}),"Delete Session"]})]})]}):null,ei=(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("button",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-sm font-medium text-[var(--accent)] transition-colors hover:bg-accent lg:hidden",onClick:()=>m("sidebar"),"aria-label":"Back to sessions",children:[(0,a.jsx)(eI.A,{className:"size-4"}),"Back"]}),c&&(0,a.jsxs)("div",{className:"flex items-center gap-0.5 rounded-full bg-[var(--fill-tertiary)] p-0.5",children:[(0,a.jsx)("button",{onClick:()=>N("chat"),className:(0,w.cn)("rounded-full px-2.5 py-1 text-[11px] font-medium transition-all","chat"===k?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:"Chat"}),(0,a.jsx)("button",{onClick:()=>N("cli"),className:(0,w.cn)("rounded-full px-2.5 py-1 font-mono text-[11px] font-medium transition-all","cli"===k?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:"CLI"})]}),(0,a.jsx)("div",{className:"hidden lg:block",children:el}),L&&(0,a.jsxs)("div",{className:"flex items-center gap-1 whitespace-nowrap text-xs font-medium text-[var(--accent)]",children:[(0,a.jsx)(eD.A,{className:"size-3"}),"Copied!"]})]});return(0,a.jsxs)(o.M,{mobileHeaderActions:el,children:[(0,a.jsxs)("div",{className:"flex h-[calc(100%-48px)] overflow-hidden lg:h-full",children:[(0,a.jsx)("div",{className:"hidden h-full w-[280px] shrink-0 lg:block",children:(0,a.jsx)(K,{selectedId:c,onSelect:Y,onNewChat:X,onDelete:ee,onSessionsLoaded:Z,onEmployeeSessionsAvailable:G})}),(0,a.jsx)("div",{className:"sidebar"===u?"block lg:hidden":"hidden",style:{width:"100%",height:"100%"},children:(0,a.jsx)(K,{selectedId:c,onSelect:Y,onNewChat:X,onDelete:ee,onSessionsLoaded:Z,onEmployeeSessionsAvailable:G})}),(0,a.jsxs)("div",{className:(0,w.cn)("min-w-0 flex-1 flex-col overflow-hidden bg-background","sidebar"===u?"hidden lg:flex":"flex"),children:[(0,a.jsx)(O,{tabs:B.tabs,activeIndex:B.activeIndex,onSwitch:B.switchTab,onClose:B.closeTab,onNew:X,toolbarActions:ei}),(0,a.jsx)(ej,{sessionId:c,isActive:!0,onFocus:()=>{},onSessionCreated:et,onSessionMetaChange:er,onRefresh:ea,portalName:r,subscribe:W,connectionSeq:F,skillsVersion:U,events:R,viewMode:k,getOnboardingPrompt:V.current?en:void 0,isStubSession:V.current,onStubCleared:es})]})]}),(0,a.jsx)(eC.lG,{open:A&&!!c,onOpenChange:z,children:(0,a.jsxs)(eC.Cf,{showCloseButton:!1,className:"max-w-sm",children:[(0,a.jsxs)(eC.c7,{children:[(0,a.jsx)(eC.L3,{children:"Delete Session?"}),(0,a.jsx)(eC.rr,{children:"This will permanently delete the session and all its messages."})]}),(0,a.jsxs)(eC.Es,{children:[(0,a.jsx)(D.$,{variant:"outline",onClick:()=>z(!1),children:"Cancel"}),(0,a.jsx)(D.$,{variant:"destructive",onClick:()=>c&&ee(c),children:"Delete"})]})]})})]})}},7e3:(e,t,r)=>{Promise.resolve().then(r.bind(r,4527))}},e=>{e.O(0,[625,51,458,865,155,192,344,144,358],()=>e(e.s=7e3)),_N_E=e.O()}]);
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[457],{4527:(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>eL});var a=r(4130),n=r(7946),s=r(2467),l=r(6654),i=r(2845),o=r(7192),c=r(7053),d=r.n(c),u=r(2784),x=r(263),p=r(8574),m=r(841),h=r(6429),g=r(4535),v=r(937),f=r(4607),b=r(4722),y=r(3160),j=r(8689),w=r(6063);function k(e){let{...t}=e;return(0,a.jsx)(j.bL,{"data-slot":"context-menu",...t})}function N(e){let{...t}=e;return(0,a.jsx)(j.l9,{"data-slot":"context-menu-trigger",...t})}function S(e){let{className:t,...r}=e;return(0,a.jsx)(j.ZL,{children:(0,a.jsx)(j.UC,{"data-slot":"context-menu-content",className:(0,w.cn)("z-50 max-h-(--radix-context-menu-content-available-height) min-w-[8rem] origin-(--radix-context-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",t),...r})})}function C(e){let{className:t,inset:r,variant:n="default",...s}=e;return(0,a.jsx)(j.q7,{"data-slot":"context-menu-item","data-inset":r,"data-variant":n,className:(0,w.cn)("relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!",t),...s})}function I(e){let{className:t,...r}=e;return(0,a.jsx)(j.wv,{"data-slot":"context-menu-separator",className:(0,w.cn)("-mx-1 my-1 h-px bg-border",t),...r})}var D=r(6960);let M="jinn-sidebar-collapsed",L="jinn-sidebar-expanded",E="jinn-pinned-sessions";function A(e){if(!e)return"";let t=new Date(e),r=Date.now()-t.getTime();return r<6e4?"now":r<36e5?"".concat(Math.floor(r/6e4),"m"):r<864e5?new Date(e).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):r<1728e5?"yesterday":new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric"})}function z(){try{let e=localStorage.getItem("jinn-read-sessions");return e?new Set(JSON.parse(e)):new Set}catch(e){return new Set}}function _(e){try{localStorage.setItem(E,JSON.stringify(Array.from(e)))}catch(e){}}function T(e){return"cron"===e.source||(e.sourceRef||"").startsWith("cron:")}function R(e){return e.lastActivity||e.createdAt||""}function F(e){return[...e].sort((e,t)=>R(t).localeCompare(R(e)))}function U(e,t){return"running"===e.status?"var(--system-blue)":"error"===e.status?"var(--system-red)":t.has(e.id)?"var(--text-quaternary)":"var(--system-green)"}function W(e){let{color:t,pulse:r=!1,className:n}=e;return(0,a.jsx)("span",{className:(0,w.cn)("shrink-0 rounded-full",n),style:{background:t,animation:r?"sidebar-pulse 2s ease-in-out infinite":"none",boxShadow:r?"0 0 8px ".concat(t):"none"}})}function B(e){let{icon:t,label:r,count:n}=e;return(0,a.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2",children:[(0,a.jsx)("span",{className:"text-xs",children:t}),(0,a.jsx)("span",{className:"text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:r}),"number"==typeof n&&(0,a.jsx)("span",{className:"ml-auto rounded bg-[var(--fill-tertiary)] px-1.5 py-0.5 text-[10px] text-[var(--text-secondary)]",children:n})]})}function K(e){var t;let{selectedId:r,onSelect:s,onNewChat:l,onDelete:i,onSessionsLoaded:o,onEmployeeSessionsAvailable:c}=e,{settings:j}=(0,b.t0)(),K=null!=(t=j.portalName)?t:"Jinn",P=K.toLowerCase(),{data:q,isLoading:O}=(0,y.te)(),V=(0,y.tS)(),J=(0,y.Q6)(),H=(0,n.useMemo)(()=>{if(!q)return[];let e=q.filter(e=>"web"===e.source||"cron"===e.source||"whatsapp"===e.source||"discord"===e.source||!e.source);return e.sort((e,t)=>{let r=e.lastActivity||e.createdAt||"";return(t.lastActivity||t.createdAt||"").localeCompare(r)}),e},[q]),[Q,$]=(0,n.useState)(""),[G,Y]=(0,n.useState)(null),[X,Z]=(0,n.useState)(new Set),[ee,et]=(0,n.useState)(new Set),[er,ea]=(0,n.useState)(new Set),[en,es]=(0,n.useState)({}),[el,ei]=(0,n.useState)({}),[eo,ec]=(0,n.useState)(new Map),ed=(0,n.useRef)(o);(0,n.useEffect)(()=>{ed.current=o},[o]),(0,n.useEffect)(()=>{H.length>0&&(0,n.startTransition)(()=>{var e;null==(e=ed.current)||e.call(ed,H)})},[H]),(0,n.useEffect)(()=>{Z(z()),et(function(){try{let e=localStorage.getItem(E);return e?new Set(JSON.parse(e)):new Set}catch(e){return new Set}}()),ea(function(){try{let e=localStorage.getItem(M);return e?new Set(JSON.parse(e)):new Set}catch(e){return new Set}}()),es(function(){try{let e=localStorage.getItem(L);return e?JSON.parse(e):{}}catch(e){return{}}}())},[]),(0,n.useEffect)(()=>{if(r){let e=z();e.add(r);let t=Array.from(e);t.length>500&&t.splice(0,t.length-500),localStorage.setItem("jinn-read-sessions",JSON.stringify(t)),Z(e=>{let t=new Set(e);return t.add(r),t})}},[r]);let eu=(0,n.useCallback)(()=>{ea(e=>{let t=new Set(e);t.has("cron")?t.delete("cron"):t.add("cron");try{localStorage.setItem(M,JSON.stringify(Array.from(t)))}catch(e){}return t})},[]),ex=(0,n.useCallback)(e=>{es(t=>{let r={...t,[e]:!t[e]};try{localStorage.setItem(L,JSON.stringify(r))}catch(e){}return r[e]||ei(t=>{if(!t[e])return t;let{[e]:r,...a}=t;return a}),r})},[]),ep=(0,n.useCallback)(e=>{et(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),_(r),r})},[]),em=(0,n.useCallback)(e=>{let t=z();for(let r of e)t.add(r.id);let r=Array.from(t);r.length>500&&r.splice(0,r.length-500),localStorage.setItem("jinn-read-sessions",JSON.stringify(r)),Z(t=>{let r=new Set(t);for(let t of e)r.add(t.id);return r})},[]);async function eh(e,t){let a=t.map(e=>e.id);try{await J.mutateAsync(a),et(t=>{let r=new Set(t);for(let t of(r.delete("emp:".concat(e)),a))r.delete(t);return _(r),r}),(0,n.startTransition)(()=>{r&&a.includes(r)&&l()})}catch(e){}}async function eg(e){try{await V.mutateAsync(e),et(t=>{if(!t.has(e))return t;let r=new Set(t);return r.delete(e),_(r),r}),(0,n.startTransition)(()=>{i?i(e):r===e&&l()})}catch(e){}}let ev=Q.trim()?H.filter(e=>{let t=Q.toLowerCase(),r=e.employee?eo.get(e.employee):void 0;return e.id.toLowerCase().includes(t)||e.employee&&e.employee.toLowerCase().includes(t)||(null==r?void 0:r.displayName)&&r.displayName.toLowerCase().includes(t)||e.title&&e.title.toLowerCase().includes(t)}):H,ef=[],eb=[],ey=new Map;for(let e of ev)if(T(e))ef.push(e);else if(T(e)||e.employee&&e.employee!==P){let t=e.employee;ey.has(t)||ey.set(t,[]),ey.get(t).push(e)}else eb.push(e);let ej=[];for(let[e,t]of ey){let r=F(t);ej.push({type:"employee",employeeName:e,employeeData:eo.get(e),sessions:r,sortKey:R(r[0]),pinKey:"emp:".concat(e)})}if(eb.length>0){let e=F(eb);ej.push({type:"employee",employeeName:P,employeeData:{name:P,displayName:K,emoji:"\uD83D\uDCAC",department:"direct",role:"",rank:"manager",engine:"",model:"",persona:""},sessions:e,sortKey:R(e[0]),pinKey:"emp:".concat(P)})}let ew=ej.filter(e=>ee.has(e.pinKey)).sort((e,t)=>t.sortKey.localeCompare(e.sortKey)),ek=ej.filter(e=>!ee.has(e.pinKey)).sort((e,t)=>t.sortKey.localeCompare(e.sortKey)),eN=er.has("cron"),eS=F(ef);function eC(e,t){var n,l;let i=e.id===r,o=U(e,X),d="running"===e.status,m=(n=e.title,l=e.employee,n?"Jinn"!==K&&n.startsWith("Jinn - ")?K+n.slice(4):n:l||K),h=A(R(e)),g=ee.has(e.id),v=G===e.id;return(0,a.jsxs)(k,{children:[(0,a.jsx)(N,{asChild:!0,children:(0,a.jsxs)("button",{onClick:()=>{s(e.id),null==c||c(null!=t?t:[e])},onMouseEnter:()=>Y(e.id),onMouseLeave:()=>{G!=="menu:".concat(e.id)&&Y(null)},className:(0,w.cn)("group relative flex w-full items-center gap-2.5 border-l-2 px-4 py-2 text-left transition-colors",t?"pl-[67px]":"pl-6",i?"border-l-[var(--accent)] bg-[var(--fill-secondary)]":"border-l-transparent hover:bg-accent"),children:[(0,a.jsx)(W,{color:o,pulse:d,className:"size-1.5"}),(0,a.jsx)("span",{className:(0,w.cn)("min-w-0 flex-1 truncate text-xs",i?"font-semibold text-foreground":"text-[var(--text-secondary)]"),children:m||"Untitled"}),g?(0,a.jsx)(u.A,{className:(0,w.cn)("size-3 shrink-0 text-[var(--accent)]",v&&"hidden lg:hidden")}):null,(0,a.jsx)("span",{className:(0,w.cn)("shrink-0 text-[10px] text-[var(--text-quaternary)]",v&&"lg:hidden"),children:h}),(0,a.jsx)("button",{onClick:t=>{t.stopPropagation(),Y("menu:".concat(e.id))},className:(0,w.cn)("hidden shrink-0 text-muted-foreground transition-colors hover:text-foreground",v&&"lg:block"),children:(0,a.jsx)(x.A,{className:"size-3.5"})}),G==="menu:".concat(e.id)?(0,a.jsxs)("div",{className:"absolute right-2 top-full z-50 min-w-[140px] overflow-hidden rounded-lg border border-border bg-[var(--material-thick)] py-1 shadow-[var(--shadow-overlay)] backdrop-blur-xl",onMouseLeave:()=>Y(null),children:[(0,a.jsxs)("button",{onClick:t=>{t.stopPropagation(),ep(e.id),Y(null)},className:"flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs text-foreground transition-colors hover:bg-accent",children:[(0,a.jsx)(u.A,{className:"size-3"})," ",g?"Unpin":"Pin"]}),(0,a.jsx)("div",{className:"my-0.5 border-t border-border"}),(0,a.jsxs)("button",{onClick:t=>{t.stopPropagation(),Y(null),window.confirm("Delete this session?")&&eg(e.id)},className:"flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs text-[var(--system-red)] transition-colors hover:bg-accent",children:[(0,a.jsx)(p.A,{className:"size-3"})," Delete"]})]}):null]})}),(0,a.jsxs)(S,{children:[(0,a.jsx)(C,{onClick:()=>ep(e.id),children:g?"Unpin":"Pin"}),(0,a.jsx)(I,{}),(0,a.jsx)(C,{variant:"destructive",onClick:()=>{window.confirm("Delete this session?")&&eg(e.id)},children:"Delete session"})]})]},e.id)}function eI(e){let t=e.employeeName,n=e.sessions,l=n[0],i=e.employeeData,o=(null==i?void 0:i.displayName)||t,d=(null==i?void 0:i.emoji)||"\uD83E\uDD16",m=(null==i?void 0:i.department)||"",h=A(R(l)),g=U(l,X),v="running"===l.status,f=n.some(e=>e.id===r),b=ee.has(e.pinKey),y=G===e.pinKey,j=n.length,I=en[t]||!1,D=n.some(e=>!X.has(e.id)&&"running"!==e.status&&"error"!==e.status);return(0,a.jsxs)("div",{children:[(0,a.jsxs)(k,{children:[(0,a.jsx)(N,{asChild:!0,children:(0,a.jsxs)("button",{onClick:()=>(function(e){let t=e.employeeName,r=e.sessions;if(r.length>1){let e=en[t]||!1;ex(t),e||(s(r[0].id),null==c||c(r))}else s(r[0].id),null==c||c(r)})(e),onMouseEnter:()=>Y(e.pinKey),onMouseLeave:()=>{G!=="menu:".concat(e.pinKey)&&Y(null)},className:(0,w.cn)("group relative flex w-full items-center gap-3 border-l-2 px-4 py-3 text-left transition-colors",f?"border-l-[var(--accent)] bg-[var(--fill-secondary)]":"border-l-transparent hover:bg-accent"),children:[(0,a.jsxs)("div",{className:"relative flex size-9 shrink-0 items-center justify-center rounded-full bg-[var(--fill-secondary)] text-lg",children:[d,(0,a.jsx)(W,{color:g,pulse:v,className:"absolute -bottom-0.5 -right-0.5 size-2.5 border-2 border-[var(--sidebar-bg)]"})]}),(0,a.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,a.jsxs)("div",{className:"mb-0.5 flex items-baseline gap-2",children:[(0,a.jsx)("span",{className:(0,w.cn)("min-w-0 flex-1 truncate text-[13px] tracking-[-0.2px] text-foreground",D||f?"font-semibold":"font-medium"),children:o}),(0,a.jsx)("span",{className:(0,w.cn)("shrink-0 text-[10px] text-[var(--text-tertiary)]",y&&"lg:hidden"),children:h}),(0,a.jsx)("button",{onClick:t=>{t.stopPropagation(),Y("menu:".concat(e.pinKey))},className:(0,w.cn)("hidden shrink-0 text-muted-foreground transition-colors hover:text-foreground",y&&"lg:block"),children:(0,a.jsx)(x.A,{className:"size-3.5"})})]}),(0,a.jsxs)("div",{className:"flex items-center gap-1.5 overflow-hidden text-[11px] text-[var(--text-tertiary)]",children:[m?(0,a.jsx)("span",{className:"truncate",children:m}):null,j>1?(0,a.jsxs)("span",{className:"shrink-0 rounded bg-[var(--fill-tertiary)] px-1.5 py-0.5 text-[10px]",children:[j," chats"]}):null,b?(0,a.jsx)(u.A,{className:"size-3 shrink-0 text-[var(--accent)]"}):null]})]}),G==="menu:".concat(e.pinKey)?(0,a.jsxs)("div",{className:"absolute right-2 top-full z-50 min-w-[160px] overflow-hidden rounded-lg border border-border bg-[var(--material-thick)] py-1 shadow-[var(--shadow-overlay)] backdrop-blur-xl",onMouseLeave:()=>Y(null),children:[(0,a.jsxs)("button",{onClick:t=>{t.stopPropagation(),ep(e.pinKey),Y(null)},className:"flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs text-foreground transition-colors hover:bg-accent",children:[(0,a.jsx)(u.A,{className:"size-3"})," ",b?"Unpin":"Pin"]}),(0,a.jsx)("button",{onClick:e=>{e.stopPropagation(),em(n),Y(null)},className:"flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs text-foreground transition-colors hover:bg-accent",children:"Mark all as read"}),(0,a.jsx)("div",{className:"my-0.5 border-t border-border"}),(0,a.jsxs)("button",{onClick:e=>{e.stopPropagation(),Y(null),window.confirm("Delete all ".concat(n.length,' chats with "').concat(o,'"?'))&&eh(t,n)},className:"flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs text-[var(--system-red)] transition-colors hover:bg-accent",children:[(0,a.jsx)(p.A,{className:"size-3"})," Delete all chats"]})]}):null]})}),(0,a.jsxs)(S,{children:[(0,a.jsx)(C,{onClick:()=>ep(e.pinKey),children:b?"Unpin":"Pin"}),(0,a.jsx)(C,{onClick:()=>em(n),children:"Mark all as read"})]})]}),I&&j>1?el[t]?n.map(e=>eC(e,n)):n.slice(0,5).map(e=>eC(e,n)):null,I&&j>5&&!el[t]?(0,a.jsxs)("button",{onClick:()=>ei(e=>({...e,[t]:!0})),className:"w-full cursor-pointer px-4 pb-2 pl-[67px] text-left text-[10px] text-[var(--text-quaternary)] transition-colors hover:text-[var(--text-secondary)]",children:["+",j-5," more"]}):null]},e.pinKey)}let eD=ew.length>0;return(0,a.jsxs)("div",{className:"jsx-fb767975a1bed37e flex h-full flex-col border-r border-border bg-[var(--sidebar-bg)]",children:[(0,a.jsxs)("div",{className:"jsx-fb767975a1bed37e shrink-0 border-b border-border bg-[var(--material-thick)] px-4 pb-3 pt-4",children:[(0,a.jsxs)("div",{className:"jsx-fb767975a1bed37e mb-3 flex items-center justify-between gap-3",children:[(0,a.jsxs)("div",{className:"jsx-fb767975a1bed37e",children:[(0,a.jsx)("h2",{className:"jsx-fb767975a1bed37e text-xl font-bold tracking-[-0.03em] text-foreground",children:"Chats"}),(0,a.jsx)("p",{className:"jsx-fb767975a1bed37e text-xs text-muted-foreground",children:"Sessions, employees, and cron runs"})]}),(0,a.jsxs)(D.$,{size:"sm",className:"gap-1.5",onClick:l,children:[(0,a.jsx)(m.A,{className:"size-3.5"}),"New"]})]}),(0,a.jsxs)("div",{className:"jsx-fb767975a1bed37e flex items-center gap-2 rounded-[var(--radius-md)] bg-[var(--fill-tertiary)] px-3 py-2",children:[(0,a.jsx)(h.A,{className:"size-3.5 shrink-0 text-[var(--text-tertiary)]"}),(0,a.jsx)("input",{type:"text",value:Q,onChange:e=>$(e.target.value),placeholder:"Search chats...","aria-label":"Search chats",className:"jsx-fb767975a1bed37e min-w-0 flex-1 bg-transparent text-sm text-foreground outline-none placeholder:text-[var(--text-tertiary)]"}),Q.trim()?(0,a.jsx)("button",{onClick:()=>$(""),"aria-label":"Clear search",className:"jsx-fb767975a1bed37e rounded-full p-0.5 text-[var(--text-tertiary)] transition-colors hover:bg-[var(--fill-secondary)] hover:text-foreground",children:(0,a.jsx)(g.A,{className:"size-3"})}):null]})]}),(0,a.jsx)("div",{className:"jsx-fb767975a1bed37e flex-1 overflow-y-auto py-1",children:O?(0,a.jsx)("div",{className:"jsx-fb767975a1bed37e px-4 py-8 text-center text-xs text-[var(--text-quaternary)]",children:"Loading sessions..."}):0===ew.length&&0===ek.length&&0===ef.length?(0,a.jsx)("div",{className:"jsx-fb767975a1bed37e px-4 py-8 text-center text-xs text-[var(--text-quaternary)]",children:Q.trim()?"No matching chats":"No conversations yet"}):(0,a.jsxs)(a.Fragment,{children:[eD?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(B,{icon:"\uD83D\uDCCC",label:"Pinned"}),ew.map(e=>eI(e)),ek.length>0?(0,a.jsx)("div",{className:"jsx-fb767975a1bed37e mx-4 my-2 border-t border-border"}):null]}):null,ek.map(e=>eI(e)),ef.length>0?(0,a.jsxs)("div",{className:"jsx-fb767975a1bed37e "+((0,w.cn)("mt-2",0===ew.length&&0===ek.length&&"mt-0")||""),children:[(0,a.jsxs)("button",{onClick:eu,onMouseEnter:()=>Y("cron-header"),onMouseLeave:()=>Y(null),className:"jsx-fb767975a1bed37e flex w-full items-center gap-2 px-4 py-2 text-left transition-colors hover:bg-accent",children:[(0,a.jsx)(v.A,{className:"size-3.5 text-muted-foreground"}),(0,a.jsx)("span",{className:"jsx-fb767975a1bed37e text-[11px] font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:"Scheduled"}),(0,a.jsx)("span",{className:"jsx-fb767975a1bed37e ml-auto rounded bg-[var(--fill-tertiary)] px-1.5 py-0.5 text-[10px] text-[var(--text-secondary)]",children:ef.length}),(0,a.jsx)(f.A,{className:(0,w.cn)("size-3.5 text-muted-foreground transition-transform",eN&&"-rotate-90")})]}),eN?null:eS.map(e=>eC(e))]}):null]})}),(0,a.jsx)(d(),{id:"fb767975a1bed37e",children:"@keyframes sidebar-pulse{0%,100%{opacity:1;transform:scale(1)}50%{opacity:.55;transform:scale(.85)}}"})]})}var P=r(129);let q={running:"bg-blue-500 animate-pulse",error:"bg-red-500",idle:"bg-zinc-500"};function O(e){let{tabs:t,activeIndex:r,onSwitch:s,onClose:l,onNew:i,toolbarActions:o}=e,c=(0,n.useRef)(null);return(0,a.jsxs)("div",{className:"relative z-[100] flex h-10 shrink-0 items-center border-b border-border bg-[var(--bg-secondary)]",children:[t.length>0&&(0,a.jsx)("div",{ref:c,className:"flex min-w-0 flex-1 items-center overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:t.map((e,t)=>(0,a.jsxs)("button",{onClick:()=>s(t),onMouseDown:e=>{1===e.button&&(e.preventDefault(),l(t))},className:(0,w.cn)("group flex h-10 max-w-[180px] shrink-0 items-center gap-1.5 border-r border-border px-3 text-xs font-medium whitespace-nowrap transition-colors",t===r?"border-b-2 border-b-[var(--accent)] bg-background text-foreground":"text-muted-foreground hover:bg-[var(--fill-quaternary)] hover:text-foreground",e.unread&&t!==r&&"font-bold"),children:[(0,a.jsx)("span",{className:"w-1.5 h-1.5 rounded-full shrink-0 ".concat(q[e.status]||q.idle)}),e.emoji&&(0,a.jsx)("span",{className:"text-sm",children:e.emoji}),(0,a.jsx)("span",{className:"truncate",children:e.label}),(0,a.jsx)("span",{onClick:e=>{e.stopPropagation(),l(t)},className:"ml-auto rounded-sm p-0.5 opacity-0 transition-all hover:bg-accent hover:text-foreground group-hover:opacity-100",children:(0,a.jsx)(g.A,{size:12})})]},e.sessionId))}),0===t.length&&(0,a.jsx)("div",{className:"flex-1"}),(0,a.jsx)("button",{onClick:i,className:"flex size-10 shrink-0 items-center justify-center text-[var(--text-tertiary)] transition-colors hover:bg-[var(--fill-quaternary)] hover:text-foreground",title:"New Chat",children:(0,a.jsx)(m.A,{size:14})}),o&&(0,a.jsxs)("div",{className:"hidden shrink-0 items-center gap-2 border-l border-border px-3 lg:flex",children:[o,(0,a.jsx)(P.r,{})]})]})}let V="jinn-intermediate-";function J(e){try{localStorage.removeItem("".concat(V).concat(e))}catch(e){}}function H(e){let{name:t,size:r,mimeType:n,url:s,isUser:l}=e;return(0,a.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-3)",padding:"var(--space-3) var(--space-4)",borderRadius:"var(--radius-lg)",background:l?"var(--accent)":"var(--material-thin)",border:l?"none":"1px solid var(--separator)",maxWidth:280,minWidth:180},children:[(0,a.jsx)("div",{style:{width:36,height:36,borderRadius:"var(--radius-sm)",background:l?"rgba(0,0,0,0.15)":"var(--fill-tertiary)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,color:l?"#000":"var(--text-secondary)"},children:function(e,t){var r;let n=(null==t||null==(r=t.split(".").pop())?void 0:r.toLowerCase())||"",s="application/pdf"===e||"pdf"===n,l=["doc","docx"].includes(n)||(null==e?void 0:e.includes("wordprocessingml")),i=["txt","csv","json","md"].includes(n)||(null==e?void 0:e.startsWith("text/")),o=["zip","tar","gz","rar","7z"].includes(n);return s?(0,a.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,a.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,a.jsx)("polyline",{points:"14 2 14 8 20 8"}),(0,a.jsx)("line",{x1:"9",y1:"15",x2:"15",y2:"15"})]}):l?(0,a.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,a.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,a.jsx)("polyline",{points:"14 2 14 8 20 8"}),(0,a.jsx)("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),(0,a.jsx)("line",{x1:"16",y1:"17",x2:"8",y2:"17"}),(0,a.jsx)("polyline",{points:"10 9 9 9 8 9"})]}):i?(0,a.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,a.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,a.jsx)("polyline",{points:"14 2 14 8 20 8"})]}):o?(0,a.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,a.jsx)("path",{d:"M21 8v13H3V8"}),(0,a.jsx)("path",{d:"M1 3h22v5H1z"}),(0,a.jsx)("path",{d:"M10 12h4"})]}):(0,a.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,a.jsx)("path",{d:"M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"}),(0,a.jsx)("polyline",{points:"13 2 13 9 20 9"})]})}(n,t)}),(0,a.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,a.jsx)("div",{style:{fontSize:"var(--text-footnote)",fontWeight:"var(--weight-medium)",color:l?"#000":"var(--text-primary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t}),null!=r&&(0,a.jsx)("div",{style:{fontSize:"var(--text-caption2)",color:l?"rgba(0,0,0,0.5)":"var(--text-tertiary)",marginTop:1},children:r<1024?"".concat(r," B"):r<1048576?"".concat((r/1024).toFixed(0)," KB"):"".concat((r/1048576).toFixed(1)," MB")})]}),(0,a.jsx)("a",{href:s,download:t,"aria-label":"Download ".concat(t),style:{width:28,height:28,borderRadius:"50%",background:l?"rgba(0,0,0,0.15)":"var(--fill-secondary)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,color:l?"#000":"var(--text-secondary)",textDecoration:"none"},children:(0,a.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,a.jsx)("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),(0,a.jsx)("polyline",{points:"7 10 12 15 17 10"}),(0,a.jsx)("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})})]})}function Q(e){let{src:t,duration:r,waveform:s,isUser:l}=e,i=(0,n.useRef)(null),[o,c]=(0,n.useState)(!1),[d,u]=(0,n.useState)(0),[x,p]=(0,n.useState)(0);(0,n.useEffect)(()=>{let e=new Audio(t);return i.current=e,e.addEventListener("timeupdate",()=>{e.duration&&isFinite(e.duration)&&(u(e.currentTime/e.duration),p(e.currentTime))}),e.addEventListener("ended",()=>{c(!1),u(0),p(0)}),e.addEventListener("pause",()=>c(!1)),e.addEventListener("play",()=>c(!0)),()=>{e.pause(),e.src=""}},[t]);let m=(0,n.useCallback)(()=>{let e=i.current;e&&(o?e.pause():e.play().catch(()=>{}))},[o]),h=s.length>0?s:Array(50).fill(.1),g=o?x:r;return(0,a.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-3)",padding:"var(--space-3) var(--space-4)",borderRadius:"var(--radius-lg)",background:l?"var(--accent)":"var(--material-thin)",border:l?"none":"1px solid var(--separator)",maxWidth:280,minWidth:200},children:[(0,a.jsx)("button",{onClick:m,"aria-label":o?"Pause":"Play",style:{width:28,height:28,borderRadius:"50%",background:l?"rgba(0,0,0,0.2)":"var(--fill-secondary)",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,color:l?"#000":"var(--text-primary)"},children:o?(0,a.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,a.jsx)("rect",{x:"6",y:"4",width:"4",height:"16",rx:"1"}),(0,a.jsx)("rect",{x:"14",y:"4",width:"4",height:"16",rx:"1"})]}):(0,a.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:(0,a.jsx)("polygon",{points:"6,4 20,12 6,20"})})}),(0,a.jsx)("div",{style:{flex:1,display:"flex",alignItems:"center",gap:2,height:28},children:h.map((e,t)=>{let r=t/h.length<=d;return(0,a.jsx)("div",{style:{width:3,borderRadius:1.5,height:"".concat(Math.max(4,24*e),"px"),background:l?r?"rgba(0,0,0,0.7)":"rgba(0,0,0,0.25)":r?"var(--accent)":"var(--fill-primary)",transition:"background 100ms ease",flexShrink:0}},t)})}),(0,a.jsx)("span",{style:{fontSize:"var(--text-caption2)",color:l?"rgba(0,0,0,0.6)":"var(--text-tertiary)",fontVariantNumeric:"tabular-nums",flexShrink:0,minWidth:28,textAlign:"right"},children:function(e){let t=Math.floor(e/60),r=Math.floor(e%60);return"".concat(t,":").concat(r.toString().padStart(2,"0"))}(g)})]})}function $(e){let{msgs:t,isActive:r}=e,[s,l]=(0,n.useState)(!1),i=t.every(e=>e.content.startsWith("Used ")),o=r&&!i?"".concat(t.length," tool").concat(1!==t.length?"s":""," running…"):"".concat(t.length," tool").concat(1!==t.length?"s":""," used");return(0,a.jsxs)("div",{className:"px-[var(--space-4)] mb-[var(--space-1)]",children:[(0,a.jsxs)("button",{onClick:()=>l(e=>!e),className:"flex items-center gap-[var(--space-2)] py-[5px] px-[var(--space-3)] rounded-full bg-[var(--fill-secondary)] border border-[var(--separator)] text-[length:var(--text-caption1)] text-[var(--text-secondary)] cursor-pointer transition-[background] duration-150 ease-in-out hover:bg-[var(--fill-tertiary)]",children:[(0,a.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"opacity-60",children:(0,a.jsx)("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"})}),o,r&&!i&&(0,a.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[var(--system-blue)] animate-[jinn-pulse_1.4s_infinite]"}),(0,a.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"transition-transform duration-150 ease-in-out opacity-50 ".concat(s?"rotate-180":"rotate-0"),children:(0,a.jsx)("polyline",{points:"6 9 12 15 18 9"})})]}),s&&(0,a.jsx)("div",{className:"flex flex-wrap gap-[var(--space-1)] mt-[var(--space-1)] pl-[var(--space-1)]",children:t.map(e=>(0,a.jsx)("span",{className:"inline-flex items-center gap-1 py-0.5 px-2 rounded-full bg-[var(--fill-tertiary)] border border-[var(--separator)] text-[length:var(--text-caption2)] text-[var(--text-tertiary)]",children:e.toolCall},e.id))})]})}function G(e){let t,r=[],n=/(https?:\/\/[^\s<]+[^\s<.,;:!?)}\]'"])|(\*\*(.+?)\*\*)|(`([^`]+)`)|\*([^*]+)\*/g,s=0;for(;null!==(t=n.exec(e));)t.index>s&&r.push(e.slice(s,t.index)),t[1]?r.push((0,a.jsx)("a",{href:t[1],target:"_blank",rel:"noopener noreferrer",className:"text-[var(--system-blue)] underline underline-offset-2",children:t[1]},t.index)):t[2]?r.push((0,a.jsx)("strong",{className:"font-[var(--weight-bold)]",children:t[3]},t.index)):t[4]?r.push((0,a.jsx)("code",{className:"bg-[var(--fill-secondary)] border border-[var(--separator)] rounded-[5px] py-px px-[5px] text-[0.88em] font-['SF_Mono',Menlo,monospace] text-[var(--accent)]",children:t[5]},t.index)):t[6]&&r.push((0,a.jsx)("em",{className:"italic opacity-[0.85]",children:t[6]},t.index)),s=t.index+t[0].length;return s<e.length&&r.push(e.slice(s)),1===r.length?r[0]:(0,a.jsx)(a.Fragment,{children:r})}function Y(e){let{code:t,keyProp:r}=e,[s,l]=(0,n.useState)(!1);return(0,a.jsxs)("div",{className:"relative my-2",children:[(0,a.jsx)("button",{onClick:function(){navigator.clipboard.writeText(t).then(()=>{l(!0),setTimeout(()=>l(!1),1500)})},"aria-label":"Copy code",className:"absolute top-2 right-2 py-0.5 px-2 text-[11px] rounded-[var(--radius-sm)] bg-[var(--fill-secondary)] text-[var(--text-secondary)] border border-[var(--separator)] cursor-pointer",children:s?"Copied!":"Copy"}),(0,a.jsx)("pre",{className:"code-block bg-[var(--fill-tertiary)] border border-[var(--separator)] rounded-[var(--radius-md)] py-[var(--space-3)] px-[var(--space-4)] overflow-x-auto text-[13px] leading-normal font-['SF_Mono',Menlo,monospace] text-[var(--text-primary)]",children:(0,a.jsx)("code",{children:t})})]},r)}function X(e){return/^\|[\s:|-]+\|$/.test(e.trim())}function Z(e){return e.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(e=>e.trim())}function ee(e){let{headerLine:t,rows:r,keyProp:n}=e,s=Z(t),l=r.map(Z);return(0,a.jsx)("div",{className:"my-2.5 rounded-[10px] border border-[var(--separator)] overflow-hidden",children:(0,a.jsx)("div",{className:"overflow-x-auto [WebkitOverflowScrolling:touch]",children:(0,a.jsxs)("table",{className:"border-collapse text-[length:var(--text-footnote)] leading-[1.6] w-full min-w-max",children:[(0,a.jsx)("thead",{children:(0,a.jsx)("tr",{className:"bg-[var(--fill-tertiary)]",children:s.map((e,t)=>(0,a.jsx)("th",{className:"text-left py-2.5 px-4 font-semibold text-[var(--text-primary)] border-b border-[var(--separator)] max-w-[280px] break-words",children:G(e)},t))})}),(0,a.jsx)("tbody",{children:l.map((e,t)=>(0,a.jsx)("tr",{className:t%2==1?"bg-[var(--fill-quaternary,transparent)]":"bg-transparent",children:e.map((e,r)=>(0,a.jsx)("td",{className:"py-2.5 px-4 text-[var(--text-primary)] max-w-[280px] break-words ".concat(t<l.length-1?"border-b border-[var(--separator)]":""),children:G(e)},r))},t))})]})})},n)}function et(e){if(!e)return null;let t=e.split("\n"),r=[],n=!1,s=[];for(let e=0;e<t.length;e++){let i=t[e];if(i.startsWith("```")){n?(n=!1,r.push((0,a.jsx)(Y,{keyProp:e,code:s.join("\n")},e))):n=!0,s=[];continue}if(n){s.push(i);continue}if(i.trim().startsWith("|")&&i.trim().endsWith("|")&&e+1<t.length&&X(t[e+1])){e++;let n=[];for(;e+1<t.length&&t[e+1].trim().startsWith("|")&&t[e+1].trim().endsWith("|")&&!X(t[e+1]);)e++,n.push(t[e]);r.push((0,a.jsx)(ee,{keyProp:e,headerLine:i,rows:n},"table-".concat(e)));continue}if(""===i.trim()){r.push((0,a.jsx)("div",{className:"h-1.5"},"space-".concat(e)));continue}if(i.match(/^[-*] /)){r.push((0,a.jsxs)("div",{className:"flex gap-[var(--space-2)] mb-0.5",children:[(0,a.jsx)("span",{className:"text-[var(--accent)] shrink-0 mt-px",children:"•"}),(0,a.jsx)("span",{children:G(i.slice(2))})]},e));continue}if(i.match(/^\d+\. /)){var l;let t=null==(l=i.match(/^(\d+)\. /))?void 0:l[1];r.push((0,a.jsxs)("div",{className:"flex gap-[var(--space-2)] mb-0.5",children:[(0,a.jsxs)("span",{className:"text-[var(--accent)] shrink-0 font-[var(--weight-semibold)] min-w-4",children:[t,"."]}),(0,a.jsx)("span",{children:G(i.replace(/^\d+\. /,""))})]},e));continue}if(i.startsWith("### ")){r.push((0,a.jsx)("div",{className:"font-[var(--weight-semibold)] text-[length:var(--text-footnote)] mt-[var(--space-2)] mb-0.5",children:G(i.slice(4))},e));continue}if(i.startsWith("## ")){r.push((0,a.jsx)("div",{className:"font-[var(--weight-bold)] text-[length:var(--text-subheadline)] mt-[var(--space-3)] mb-[3px]",children:G(i.slice(3))},e));continue}if(i.startsWith("# ")){r.push((0,a.jsx)("div",{className:"font-[var(--weight-bold)] text-[length:var(--text-body)] mt-[var(--space-3)] mb-[var(--space-1)]",children:G(i.slice(2))},e));continue}r.push((0,a.jsx)("div",{className:"mb-px",children:G(i)},e))}return n&&s.length>0&&r.push((0,a.jsx)(Y,{keyProp:999,code:s.join("\n")},"trailing-code")),(0,a.jsx)(a.Fragment,{children:r})}function er(e){let t=new Date,r=new Date(e),a=t.toDateString()===r.toDateString(),n=new Date(t);n.setDate(n.getDate()-1);let s=n.toDateString()===r.toDateString(),l=r.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0});return a?"Today ".concat(l):s?"Yesterday ".concat(l):r.toLocaleDateString("en-US",{month:"short",day:"numeric"})+" ".concat(l)}function ea(e,t){return 0===t||e[t].timestamp-e[t-1].timestamp>3e5}function en(e,t){let r=e.filter(e=>"image"===e.type),n=e.filter(e=>"audio"===e.type),s=e.filter(e=>"file"===e.type);return(0,a.jsxs)(a.Fragment,{children:[r.map((e,t)=>(0,a.jsx)("div",{className:"mt-[var(--space-2)] rounded-[var(--radius-lg)] overflow-hidden max-w-[280px]",children:(0,a.jsx)("img",{src:e.url,alt:e.name||"Image",className:"w-full block rounded-[var(--radius-lg)] cursor-pointer",onClick:()=>window.open(e.url,"_blank")})},"img-".concat(t))),n.map((e,r)=>(0,a.jsx)("div",{className:"mt-[var(--space-2)]",children:(0,a.jsx)(Q,{src:e.url,duration:e.duration||0,waveform:e.waveform||[],isUser:t})},"audio-".concat(r))),s.map((e,r)=>(0,a.jsx)("div",{className:"mt-[var(--space-2)]",children:(0,a.jsx)(H,{name:e.name||"File",size:e.size,mimeType:e.mimeType,url:e.url,isUser:t})},"file-".concat(r)))]})}function es(e){let{messages:t,loading:r,streamingText:s}=e,l=(0,n.useRef)(null),i=(0,n.useRef)(null),o=(0,n.useRef)(0),c=(0,n.useRef)(null);return((0,n.useLayoutEffect)(()=>{var e,r;if(0===t.length){o.current=0,c.current=null;return}let a=(null==(e=t[0])?void 0:e.id)||null,n=null!==c.current&&a!==c.current;0===o.current&&t.length>0||n?i.current&&(i.current.scrollTop=i.current.scrollHeight):null==(r=l.current)||r.scrollIntoView({behavior:"smooth"}),o.current=t.length,c.current=a},[t]),(0,n.useEffect)(()=>{if(r&&t.length>0){var e;null==(e=l.current)||e.scrollIntoView({behavior:"smooth"})}},[r,t.length]),0!==t.length||r)?(0,a.jsxs)("div",{ref:i,className:"chat-messages-scroll flex-1 overflow-y-auto overflow-x-hidden py-[var(--space-3)] pb-[var(--space-6)] bg-[var(--bg)] min-h-0",children:[(function(e){let t=[],r=0;for(;r<e.length;)if("assistant"===e[r].role&&e[r].toolCall){let a=[],n=r;for(;r<e.length&&"assistant"===e[r].role&&e[r].toolCall;)a.push(e[r]),r++;t.push({kind:"tool-group",msgs:a,startIndex:n})}else t.push({kind:"message",msg:e[r],index:r}),r++;return t})(t).map(e=>{if("tool-group"===e.kind){let n=e.msgs[0],s=ea(t,e.startIndex),l=e.startIndex>0?t[e.startIndex-1]:null,i=r&&e.startIndex+e.msgs.length===t.length;return(0,a.jsxs)("div",{children:[s&&(0,a.jsx)("div",{className:"text-center py-[var(--space-3)] text-[length:var(--text-caption2)] text-[var(--text-tertiary)]",children:er(n.timestamp)}),!s&&l&&(0,a.jsx)("div",{className:"assistant"!==l.role?"h-[var(--space-4)]":"h-[var(--space-1)]"}),(0,a.jsx)($,{msgs:e.msgs,isActive:i})]},"tg-".concat(e.startIndex))}let{msg:n,index:s}=e,l="user"===n.role,i="notification"===n.role,o=ea(t,s),c=n.media||function(e){let t,r=[],a=/!\[([^\]]*)\]\((https?:\/\/[^)]+\.(jpg|jpeg|png|gif|webp|svg)(\?[^)]*)?)\)/gi;for(;null!==(t=a.exec(e));)r.push({type:"image",url:t[2],name:t[1]||"Image"});let n=RegExp("(?<!\\]\\()https?:\\/\\/\\S+\\.(jpg|jpeg|png|gif|webp)(\\?\\S*)?\\b","gi");for(;null!==(t=n.exec(e));){let e=t[0];r.find(t=>t.url===e)||r.push({type:"image",url:e})}let s=/https?:\/\/\S+\.(mp3|wav|ogg|m4a|aac)(\?\S*)?\b/gi;for(;null!==(t=s.exec(e));)r.push({type:"audio",url:t[0],name:t[0].split("/").pop()});return r}(n.content),d=n.content;return c.length>0&&!n.media&&(c.forEach(e=>{d=(d=d.replace(e.url,"")).replace(/!\[[^\]]*\]\([^)]+\)/g,"")}),d=d.trim()),n.media&&n.media.length>0&&d.startsWith("[")&&d.endsWith("]")&&(d=""),(0,a.jsxs)("div",{children:[o&&(0,a.jsx)("div",{className:"text-center py-[var(--space-3)] text-[length:var(--text-caption2)] text-[var(--text-tertiary)]",children:er(n.timestamp)}),!o&&s>0&&(0,a.jsx)("div",{className:t[s-1].role!==n.role?"h-[var(--space-4)]":"h-[var(--space-1)]"}),i&&(0,a.jsx)("div",{className:"flex justify-center px-[var(--space-4)] mb-[var(--space-1)]",children:(0,a.jsxs)("div",{className:"notification-msg-bubble flex items-start gap-[var(--space-2)] py-[var(--space-3)] px-[var(--space-4)] rounded-[var(--radius-md)] bg-[var(--fill-secondary)] border border-dashed border-[var(--separator)] text-[var(--text-secondary)] text-[length:var(--text-caption1)] leading-[var(--leading-relaxed)] max-w-[85%]",children:[(0,a.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0 mt-0.5 opacity-60",children:[(0,a.jsx)("path",{d:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"}),(0,a.jsx)("path",{d:"M13.73 21a2 2 0 0 1-3.46 0"})]}),(0,a.jsx)("span",{children:et(d)})]})}),l&&(0,a.jsxs)("div",{className:"flex flex-col items-end px-[var(--space-4)] mb-[var(--space-1)]",children:[d&&(0,a.jsx)("div",{className:"user-msg-bubble py-[var(--space-3)] px-[var(--space-4)] rounded-[var(--radius-lg)_var(--radius-lg)_var(--radius-sm)_var(--radius-lg)] bg-[var(--accent)] text-[var(--accent-contrast)] text-[length:var(--text-subheadline)] leading-[var(--leading-relaxed)] font-[var(--weight-medium)] shadow-[var(--shadow-subtle)]",children:et(d)}),c.length>0&&(0,a.jsx)("div",{className:"user-msg-bubble",children:en(c,!0)})]}),!l&&!i&&(0,a.jsx)("div",{className:"assistant-msg-row flex justify-start px-[var(--space-4)] mb-[var(--space-1)]",children:(0,a.jsxs)("div",{className:"assistant-msg-bubble flex flex-col",children:[d&&(0,a.jsx)("div",{className:"py-[var(--space-3)] px-[var(--space-4)] rounded-[var(--radius-sm)_var(--radius-lg)_var(--radius-lg)_var(--radius-lg)] bg-[var(--material-thin)] border border-[var(--separator)] text-[var(--text-primary)] text-[length:var(--text-subheadline)] leading-[var(--leading-relaxed)]",children:et(d)}),c.length>0&&en(c,!1)]})})]},n.id||s)}),s&&(0,a.jsx)("div",{className:"assistant-msg-row flex justify-start px-[var(--space-4)] mb-[var(--space-1)]",children:(0,a.jsx)("div",{className:"assistant-msg-bubble flex flex-col",children:(0,a.jsx)("div",{className:"py-[var(--space-3)] px-[var(--space-4)] rounded-[var(--radius-sm)_var(--radius-lg)_var(--radius-lg)_var(--radius-lg)] bg-[var(--material-thin)] border border-[var(--separator)] text-[var(--text-primary)] text-[length:var(--text-subheadline)] leading-[var(--leading-relaxed)]",children:et(function(e){let t=e,r=(t.match(/```/g)||[]).length;if(r%2!=0&&(t+="\n```"),r%2==0){let e=t.replace(/```[\s\S]*?```/g,"");(e.match(/`/g)||[]).length%2!=0&&(t+="`"),(e.match(/\*\*/g)||[]).length%2!=0&&(t+="**")}return t}(s))})})}),r&&!s&&t.length>0&&(0,a.jsxs)("div",{className:"flex items-center gap-1.5 py-1.5 px-[var(--space-4)] mt-[var(--space-1)]",children:[(0,a.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[var(--accent)] animate-[jinn-pulse_1.4s_infinite] shrink-0"}),(0,a.jsx)("span",{className:"text-[length:var(--text-caption1)] text-[var(--text-tertiary)] font-[var(--weight-medium)]",children:"Thinking"})]}),(0,a.jsx)("div",{ref:l}),(0,a.jsx)("style",{children:"\n @keyframes jinn-pulse {\n 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }\n 40% { opacity: 1; transform: scale(1); }\n }\n .assistant-msg-bubble { max-width: 100%; overflow-wrap: break-word; word-break: break-word; }\n .user-msg-bubble { max-width: 90%; overflow-wrap: break-word; word-break: break-word; }\n .notification-msg-bubble { overflow-wrap: break-word; word-break: break-word; }\n .assistant-msg-row { padding: 0 var(--space-2) !important; }\n @media (min-width: 1024px) {\n .assistant-msg-bubble { max-width: 75%; }\n .user-msg-bubble { max-width: 75%; }\n .assistant-msg-row { padding: 0 var(--space-4) !important; }\n }\n /* User message contrast fixes — ensure all child elements are visible on accent background */\n .user-msg-bubble code {\n background: rgba(255,255,255,0.2) !important;\n border-color: rgba(255,255,255,0.3) !important;\n color: inherit !important;\n }\n .user-msg-bubble .code-block,\n .user-msg-bubble pre {\n background: rgba(0,0,0,0.2) !important;\n border-color: rgba(255,255,255,0.15) !important;\n color: rgba(255,255,255,0.95) !important;\n }\n .user-msg-bubble a {\n color: inherit !important;\n text-decoration-color: rgba(255,255,255,0.6) !important;\n }\n .user-msg-bubble strong { color: inherit !important; }\n .user-msg-bubble em { color: inherit !important; opacity: 0.9; }\n .user-msg-bubble span { color: inherit !important; }\n .user-msg-bubble div { color: inherit !important; }\n .user-msg-bubble th, .user-msg-bubble td { color: inherit !important; }\n .user-msg-bubble table { border-color: rgba(255,255,255,0.2) !important; }\n .user-msg-bubble th { border-color: rgba(255,255,255,0.2) !important; }\n .user-msg-bubble td { border-color: rgba(255,255,255,0.15) !important; }\n .user-msg-bubble tr { background: transparent !important; }\n .user-msg-bubble thead tr { background: rgba(255,255,255,0.1) !important; }\n /* Selection visibility for user messages */\n .user-msg-bubble ::selection {\n background: rgba(255,255,255,0.35);\n color: inherit;\n }\n .user-msg-bubble ::-moz-selection {\n background: rgba(255,255,255,0.35);\n color: inherit;\n }\n "})]}):(0,a.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,a.jsxs)("div",{className:"text-center",children:[(0,a.jsx)("div",{className:"text-[length:var(--text-title3)] font-[var(--weight-semibold)] text-[var(--text-tertiary)]",children:"Start a conversation"}),(0,a.jsx)("div",{className:"text-[length:var(--text-footnote)] text-[var(--text-quaternary)] mt-[var(--space-2)]",children:"Send a message or use /new to begin"})]})})}function el(e){let{attachments:t,onRemove:r}=e;return 0===t.length?null:(0,a.jsx)("div",{style:{display:"flex",gap:"var(--space-2)",padding:"var(--space-2) var(--space-3)",overflowX:"auto",overflowY:"hidden"},children:t.map((e,t)=>{var n,s;return(0,a.jsxs)("div",{style:{position:"relative",width:56,height:56,flexShrink:0,borderRadius:"var(--radius-sm)",overflow:"hidden",background:"var(--fill-tertiary)",border:"1px solid var(--separator)"},children:["image"===e.type?(0,a.jsx)("img",{src:e.url,alt:e.name||"Preview",style:{width:"100%",height:"100%",objectFit:"cover"}}):(0,a.jsxs)("div",{style:{width:"100%",height:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2,padding:4},children:["audio"===e.type?(0,a.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-tertiary)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,a.jsx)("path",{d:"M9 18V5l12-2v13"}),(0,a.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,a.jsx)("circle",{cx:"18",cy:"16",r:"3"})]}):(0,a.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-tertiary)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,a.jsx)("path",{d:"M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"}),(0,a.jsx)("polyline",{points:"13 2 13 9 20 9"})]}),(0,a.jsx)("span",{style:{fontSize:8,color:"var(--text-quaternary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"100%",textAlign:"center"},children:(null==(s=e.name)||null==(n=s.split(".").pop())?void 0:n.toUpperCase())||e.type.toUpperCase()})]}),(0,a.jsx)("button",{onClick:()=>r(t),"aria-label":"Remove attachment",style:{position:"absolute",top:2,right:2,width:18,height:18,borderRadius:"50%",background:"rgba(0,0,0,0.6)",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:"#fff",fontSize:11,lineHeight:1,padding:0},children:(0,a.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:[(0,a.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,a.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},t)})})}function ei(e){let{open:t,progress:r,onDownload:n,onCancel:s}=e;if(!t)return null;let l=null!==r;return(0,a.jsx)("div",{className:"fixed inset-0 bg-black/50 z-[60] flex items-center justify-center",onClick:l?void 0:s,children:(0,a.jsxs)("div",{className:"bg-[var(--bg)] rounded-[var(--radius-lg)] p-[var(--space-6)] max-w-[400px] w-[90%] shadow-[var(--shadow-overlay)]",onClick:e=>e.stopPropagation(),children:[(0,a.jsx)("div",{className:"w-12 h-12 rounded-[var(--radius-md)] bg-[var(--fill-secondary)] flex items-center justify-center mb-[var(--space-4)]",children:(0,a.jsxs)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-secondary)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,a.jsx)("path",{d:"M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"}),(0,a.jsx)("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),(0,a.jsx)("line",{x1:"12",y1:"19",x2:"12",y2:"23"}),(0,a.jsx)("line",{x1:"8",y1:"23",x2:"16",y2:"23"})]})}),(0,a.jsx)("h3",{className:"text-[length:var(--text-headline)] font-[var(--weight-bold)] text-[var(--text-primary)] mb-[var(--space-2)]",children:"Enable voice input?"}),(0,a.jsx)("p",{className:"text-[length:var(--text-body)] text-[var(--text-secondary)] mb-[var(--space-5)] leading-[var(--leading-relaxed)]",children:"This will download a speech recognition model (~500MB). Transcription runs locally on your server — no data leaves your network."}),l&&(0,a.jsxs)("div",{className:"mb-[var(--space-5)]",children:[(0,a.jsxs)("div",{className:"flex justify-between mb-[var(--space-2)] text-[length:var(--text-footnote)] text-[var(--text-tertiary)]",children:[(0,a.jsx)("span",{children:"Downloading model…"}),(0,a.jsxs)("span",{children:[r,"%"]})]}),(0,a.jsx)("div",{className:"h-1.5 rounded-[3px] bg-[var(--fill-tertiary)] overflow-hidden",children:(0,a.jsx)("div",{className:"h-full rounded-[3px] bg-[var(--accent)] transition-[width] duration-300 ease-in-out",style:{width:"".concat(r,"%")}})})]}),(0,a.jsxs)("div",{className:"flex gap-[var(--space-3)] justify-end",children:[!l&&(0,a.jsx)("button",{onClick:s,className:"px-[var(--space-4)] py-[var(--space-2)] rounded-[var(--radius-md)] bg-[var(--fill-tertiary)] text-[var(--text-primary)] border-none cursor-pointer text-[length:var(--text-body)]",children:"Cancel"}),(0,a.jsx)("button",{onClick:n,disabled:l,className:"px-[var(--space-4)] py-[var(--space-2)] rounded-[var(--radius-md)] border-none text-[length:var(--text-body)] font-[var(--weight-semibold)] ".concat(l?"bg-[var(--fill-tertiary)] text-[var(--text-tertiary)] cursor-default":"bg-[var(--accent)] text-black cursor-pointer"),children:l?"Downloading…":"Download"})]})]})})}function eo(e){let{analyser:t,width:r=64,height:s=32,color:l="var(--system-red)"}=e,i=(0,n.useRef)(null),o=(0,n.useRef)(0);return(0,n.useEffect)(()=>{let e=i.current;if(!e||!t)return;let a=e.getContext("2d");if(!a)return;let n=t.frequencyBinCount,c=new Uint8Array(n),d=(r-22)/12;return!function e(){o.current=requestAnimationFrame(e),t.getByteFrequencyData(c),a.clearRect(0,0,r,s);for(let e=0;e<12;e++){let t=Math.max(3,c[Math.floor(e/12*(.6*n))]/255*s),r=e*(d+2),i=(s-t)/2;a.fillStyle=l,a.beginPath(),a.roundRect(r,i,d,t,1.5),a.fill()}}(),()=>{cancelAnimationFrame(o.current)}},[t,r,s,l]),(0,a.jsx)("canvas",{ref:i,width:r,height:s,style:{width:r,height:s,display:"block"}})}let ec=[{name:"new",description:"Start a new chat session"},{name:"status",description:"Show current session info"}];async function ed(e){let t,r=e.type.startsWith("image/"),a=e.type.startsWith("audio/");if(r)t=await new Promise((t,r)=>{let a=new Image,n=URL.createObjectURL(e);a.onload=()=>{URL.revokeObjectURL(n);let{width:s,height:l}=a;if(s>1200||l>1200){let e=1200/Math.max(s,l);s=Math.round(s*e),l=Math.round(l*e)}let i=document.createElement("canvas");i.width=s,i.height=l;let o=i.getContext("2d");if(!o)return void r(Error("no canvas context"));o.drawImage(a,0,0,s,l);let c=e.size>5e4?"image/jpeg":"image/png";t(i.toDataURL(c,"image/jpeg"===c?.85:void 0))},a.onerror=()=>{URL.revokeObjectURL(n),r(Error("image load failed"))},a.src=n});else t=await new Promise((t,r)=>{let a=new FileReader;a.onloadend=()=>t(a.result),a.onerror=r,a.readAsDataURL(e)});return{type:r?"image":a?"audio":"file",url:t,name:e.name,mimeType:e.type,size:t.length}}function eu(e){let{disabled:t,loading:r,onSend:s,onInterrupt:i,onNewSession:o,onStatusRequest:c,skillsVersion:d,events:u}=e,[x,p]=(0,n.useState)(""),[m,h]=(0,n.useState)([]),[g,v]=(0,n.useState)(!1),[f,b]=(0,n.useState)(""),[y,j]=(0,n.useState)(0),[w,k]=(0,n.useState)(ec),[N,S]=(0,n.useState)(!1),[C,I]=(0,n.useState)(""),[D,M]=(0,n.useState)(0),[L,E]=(0,n.useState)([]),A=(0,n.useRef)(null),z=(0,n.useRef)(null),_=(0,n.useRef)(new Map),T=function(e,t){let[r,a]=(0,n.useState)("idle"),[s,i]=(0,n.useState)(null),[o,c]=(0,n.useState)(null),[d,u]=(0,n.useState)(null),[x,p]=(0,n.useState)(["en"]),[m,h]=(0,n.useState)(null),[g,v]=(0,n.useState)(()=>localStorage.getItem("stt-language")||"en"),f=(0,n.useRef)(g);f.current=g;let b=(0,n.useRef)(null),y=(0,n.useRef)(null),j=(0,n.useRef)(null),w=(0,n.useRef)([]),k=(0,n.useRef)(null),N=(0,n.useRef)(null),S=(0,n.useRef)(t);S.current=t,(0,n.useEffect)(()=>{if(!e||0===e.length)return;let t=e[e.length-1];if(!t.event.startsWith("stt:"))return;let r=t.payload;"stt:download:progress"===t.event&&c(Number(r.progress)||0),"stt:download:complete"===t.event&&(c(null),i(!0),a("idle")),"stt:download:error"===t.event&&(c(null),a("idle"))},[e]);let C=(0,n.useCallback)(()=>{var e,t;null==(e=j.current)||e.getTracks().forEach(e=>e.stop()),j.current=null,null==(t=y.current)||t.close().catch(()=>{}),y.current=null,u(null),b.current=null},[]);(0,n.useEffect)(()=>()=>{var e,t,r;k.current&&clearTimeout(k.current),(null==(e=b.current)?void 0:e.state)==="recording"&&b.current.stop(),null==(t=j.current)||t.getTracks().forEach(e=>e.stop()),null==(r=y.current)||r.close().catch(()=>{})},[]);let I=(0,n.useCallback)(async()=>{try{var e;let t=await l.F.sttStatus();return i(t.available),t.downloading&&c(t.progress),(null==(e=t.languages)?void 0:e.length)>0&&(p(t.languages),v(e=>{if(!t.languages.includes(e)){let e=t.languages[0];return localStorage.setItem("stt-language",e),e}return e})),t.available}catch(e){return i(!1),!1}},[]),D=(0,n.useCallback)(async()=>{try{let e=await navigator.mediaDevices.getUserMedia({audio:!0});j.current=e;let t=new AudioContext;y.current=t;let r=t.createMediaStreamSource(e),n=t.createAnalyser();n.fftSize=128,r.connect(n),u(n);let s=MediaRecorder.isTypeSupported("audio/webm;codecs=opus")?"audio/webm;codecs=opus":MediaRecorder.isTypeSupported("audio/mp4")?"audio/mp4":"",i=new MediaRecorder(e,s?{mimeType:s}:void 0);b.current=i,w.current=[],i.ondataavailable=e=>{e.data.size>0&&w.current.push(e.data)},i.onstop=async()=>{C(),a("transcribing");let e=new Blob(w.current,{type:i.mimeType||"audio/webm"});if(w.current=[],0===e.size){var t;a("idle"),null==(t=N.current)||t.call(N,null),N.current=null;return}try{let t=(await l.F.sttTranscribe(e,f.current)).text||null;a("idle"),h(null),N.current?(N.current(t),N.current=null):t&&S.current&&S.current(t)}catch(t){let e=t instanceof Error?t.message:"Transcription failed";h(e),a("error"),N.current&&(N.current(null),N.current=null)}},i.start(5e3),a("recording"),k.current=setTimeout(()=>{var e;(null==(e=b.current)?void 0:e.state)==="recording"&&b.current.stop()},18e5)}catch(e){C(),a("idle")}},[C]),M=(0,n.useCallback)(async()=>{"recording"!==r&&"transcribing"!==r&&("error"===r&&(h(null),a("idle")),await I()?await D():a("no-model"))},[r,I,D]),L=(0,n.useCallback)(async()=>{await D()},[D]),E=(0,n.useCallback)(async()=>b.current&&"inactive"!==b.current.state?(k.current&&(clearTimeout(k.current),k.current=null),new Promise(e=>{var t;N.current=e,(null==(t=b.current)?void 0:t.state)==="recording"?b.current.stop():(C(),a("idle"),N.current=null,e(null))})):(a("idle"),null),[C]),A=(0,n.useCallback)(()=>{var e;k.current&&(clearTimeout(k.current),k.current=null),(null==(e=b.current)?void 0:e.state)==="recording"&&b.current.stop(),C(),w.current=[],a("idle")},[C]),z=(0,n.useCallback)(()=>{c(0),l.F.sttDownload().catch(()=>{c(null)})},[]),_=(0,n.useCallback)(()=>{a("idle"),c(null)},[]),T=(0,n.useCallback)(()=>{a("idle"),h(null)},[]),R=(0,n.useCallback)(()=>{v(e=>{let t=x.indexOf(e),r=x[(t+1)%x.length];return localStorage.setItem("stt-language",r),r})},[x]);return{state:r,available:s,downloadProgress:o,analyser:d,languages:x,selectedLanguage:g,error:m,cycleLanguage:R,handleMicClick:M,startRecording:L,stopRecording:E,cancelRecording:A,startDownload:z,dismissDownload:_,dismissError:T}}(u,e=>{e&&p(t=>t?t+" "+e:e)});(0,n.useEffect)(()=>{l.F.getOrg().then(async e=>{let t=e.employees;Array.isArray(t)&&h(await Promise.all(t.map(async e=>{try{let t=await l.F.getEmployee(e);return{name:t.name,displayName:t.displayName,department:t.department,rank:t.rank,engine:t.engine}}catch(t){return{name:e}}})))}).catch(()=>{})},[]),(0,n.useEffect)(()=>{l.F.getSkills().then(e=>{if(!Array.isArray(e))return;let t=e.filter(e=>!ec.some(t=>t.name===e.name)).map(e=>({name:e.name,description:e.description||"",needsEmployee:"sync"===e.name}));k([...ec,...t])}).catch(()=>{})},[d]);let R=(0,n.useCallback)(e=>{var t;let r=x.lastIndexOf("@");-1!==r&&p(x.slice(0,r)+"@"+e+" "),v(!1),null==(t=A.current)||t.focus()},[x]),F=(0,n.useCallback)(e=>{var t;e.needsEmployee?(p("/"+e.name+" @"),S(!1),b(""),j(0),v(!0)):(p("/"+e.name),S(!1)),null==(t=A.current)||t.focus()},[]);function U(){let e=x.trim(),r=L.length>0;if(!e&&!r||t)return;if("/new"===e){p(""),o();return}if("/status"===e){p(""),c();return}let a=r?[...L]:void 0;p(""),E([]),v(!1),S(!1),A.current&&(A.current.style.height="auto"),s(e,a,!1)}async function W(e){let t=e.target.files;if(!t||0===t.length)return;let r=[];for(let e=0;e<t.length;e++)r.push(await ed(t[e]));E(e=>[...e,...r]),e.target.value=""}async function B(e){var t;let r=null==(t=e.clipboardData)?void 0:t.items;if(r){for(let t=0;t<r.length;t++)if(r[t].type.startsWith("image/")){e.preventDefault();let a=r[t].getAsFile();if(a){let e=await ed(a);E(t=>[...t,e])}return}}}let K=(0,n.useCallback)(e=>{e&&p(t=>t?t+" "+e:e)},[]);async function P(){if("recording"===T.state){var e;let t=await T.stopRecording();K(null!=t?t:""),null==(e=A.current)||e.focus()}else"transcribing"===T.state||T.handleMicClick()}(0,n.useEffect)(()=>{A.current&&(A.current.style.height="auto",A.current.style.height=Math.min(A.current.scrollHeight,120)+"px")},[x]);let q=w.filter(e=>e.name.toLowerCase().startsWith(C)),O=m.filter(e=>e.name.toLowerCase().includes(f)),V=x.trim().length>0||L.length>0;return(0,a.jsxs)("div",{className:"px-3 sm:px-4 pt-[var(--space-3)] pb-[var(--space-3)] border-t border-t-[var(--separator)] bg-[var(--material-regular)] shrink-0 relative",children:[N&&q.length>0&&(0,a.jsx)("div",{className:"absolute bottom-full left-[var(--space-4)] right-[var(--space-4)] mb-1 bg-[var(--bg)] border border-[var(--separator)] rounded-[var(--radius-md)] shadow-[var(--shadow-lg)] max-h-60 overflow-y-auto z-10",children:q.map((e,t)=>{let r=t===D;return(0,a.jsxs)("button",{ref:e=>{r&&e&&e.scrollIntoView({block:"nearest"})},onClick:()=>F(e),className:"w-full text-left py-[var(--space-2)] px-[var(--space-3)] text-[length:var(--text-footnote)] ".concat(r?"bg-[var(--fill-secondary)]":"bg-transparent"," border-none cursor-pointer flex items-center gap-[var(--space-2)] text-[var(--text-primary)]"),children:[(0,a.jsxs)("span",{className:"font-[family-name:var(--font-mono)] font-[var(--weight-semibold)] text-[var(--accent)] text-[length:var(--text-footnote)]",children:["/",e.name]}),(0,a.jsx)("span",{className:"text-[var(--text-tertiary)] text-[length:var(--text-caption1)]",children:e.description})]},e.name)})}),g&&O.length>0&&(0,a.jsx)("div",{className:"absolute bottom-full left-[var(--space-4)] right-[var(--space-4)] mb-1 bg-[var(--bg)] border border-[var(--separator)] rounded-[var(--radius-md)] shadow-[var(--shadow-lg)] max-h-40 overflow-y-auto z-10",children:O.slice(0,8).map((e,t)=>{let r=t===y;return(0,a.jsxs)("button",{ref:e=>{e?_.current.set(t,e):_.current.delete(t),r&&e&&e.scrollIntoView({block:"nearest"})},onClick:()=>R(e.name),className:"w-full text-left py-[var(--space-2)] px-[var(--space-3)] text-[length:var(--text-footnote)] ".concat(r?"bg-[var(--fill-secondary)]":"bg-transparent"," border-none cursor-pointer flex items-center gap-[var(--space-2)] text-[var(--text-primary)]"),children:[(0,a.jsx)("span",{className:"text-base leading-none",children:{executive:"\uD83C\uDFAF",manager:"\uD83D\uDCCB",senior:"⭐",employee:"\uD83D\uDC64"}[e.rank||"employee"]||"\uD83D\uDC64"}),(0,a.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,a.jsxs)("div",{className:"flex items-center gap-[var(--space-2)]",children:[(0,a.jsx)("span",{className:"font-[var(--weight-semibold)]",children:e.displayName||e.name}),(0,a.jsxs)("span",{className:"font-[family-name:var(--font-mono)] text-[length:var(--text-caption2)] text-[var(--text-tertiary)]",children:["@",e.name]})]}),e.department&&(0,a.jsxs)("div",{className:"text-[length:var(--text-caption2)] text-[var(--text-quaternary)] flex gap-[var(--space-2)] mt-px",children:[(0,a.jsx)("span",{children:e.department}),e.engine&&(0,a.jsx)("span",{className:"text-[var(--accent)] font-[var(--weight-medium)]",children:e.engine})]})]})]},e.name)})}),L.length>0&&(0,a.jsx)("div",{className:"mb-[var(--space-2)]",children:(0,a.jsx)(el,{attachments:L,onRemove:function(e){E(t=>t.filter((t,r)=>r!==e))}})}),(0,a.jsxs)("div",{className:"flex items-center gap-[var(--space-2)] bg-[var(--fill-secondary)] rounded-[var(--radius-lg)] py-1.5 px-[var(--space-3)] min-h-11 transition-[border-color] duration-200 ease-in-out border ".concat(r?"border-[var(--accent)]":"border-[var(--separator)]"),children:[(0,a.jsx)("button",{"aria-label":"Attach file",onClick:()=>{var e;return null==(e=z.current)?void 0:e.click()},className:"w-8 h-8 shrink-0 rounded-[var(--radius-sm)] flex items-center justify-center bg-transparent border-none cursor-pointer text-[var(--text-secondary)] mb-0",children:(0,a.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,a.jsx)("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}),(0,a.jsx)("input",{ref:z,type:"file",accept:"image/*,audio/*,.pdf,.doc,.docx,.txt,.csv,.json,.zip",multiple:!0,className:"hidden",onChange:W}),(0,a.jsx)("textarea",{ref:A,value:x,onChange:function(e){let t=e.target.value;if(p(t),t.startsWith("/")&&!t.includes(" ")){I(t.slice(1).toLowerCase()),M(0),S(!0),v(!1);return}S(!1);let r=t.lastIndexOf("@");if(-1!==r){let e=t.slice(r+1);if(!e.includes(" ")&&!e.includes("\n")){b(e.toLowerCase()),j(0),v(!0);return}}v(!1)},onKeyDown:function(e){if(N&&q.length>0){let t=q.length;if("ArrowDown"===e.key){e.preventDefault(),M(e=>(e+1)%t);return}if("ArrowUp"===e.key){e.preventDefault(),M(e=>(e-1+t)%t);return}if("Tab"===e.key||"Enter"===e.key){e.preventDefault(),F(q[D]);return}if("Escape"===e.key){e.preventDefault(),S(!1);return}}if(g&&O.length>0){let t=Math.min(O.length,8);if("ArrowDown"===e.key){e.preventDefault(),j(e=>(e+1)%t);return}if("ArrowUp"===e.key){e.preventDefault(),j(e=>(e-1+t)%t);return}if("Tab"===e.key||"Enter"===e.key){e.preventDefault(),R(O[y].name);return}if("Escape"===e.key){e.preventDefault(),v(!1);return}}"Enter"!==e.key||e.shiftKey||(e.preventDefault(),U())},onPaste:B,placeholder:t?"Waiting for response...":"Type a message...",rows:1,disabled:t,className:"flex-1 bg-transparent border-none outline-none resize-none text-[var(--text-primary)] text-[length:var(--text-subheadline)] leading-5 max-h-30 min-h-5 h-5 p-0 m-0 ".concat(t?"opacity-50":"opacity-100"),onInput:e=>{let t=e.target;t.style.height="auto",t.style.height=Math.min(t.scrollHeight,120)+"px"}}),T.languages.length>1&&(0,a.jsx)("button",{"aria-label":"STT language: ".concat(T.selectedLanguage.toUpperCase(),". Click to switch."),onClick:T.cycleLanguage,className:"h-6 px-1.5 shrink-0 rounded-[var(--radius-sm)] flex items-center justify-center bg-[var(--fill-tertiary)] border-none cursor-pointer text-[var(--text-secondary)] text-[11px] font-semibold font-[family-name:var(--font-mono)] tracking-[0.5px] uppercase transition-all duration-150 ease-in-out",title:"Transcription language: ".concat(T.selectedLanguage.toUpperCase(),". Click to cycle."),children:T.selectedLanguage}),(0,a.jsx)("button",{"aria-label":"recording"===T.state?"Stop recording":"transcribing"===T.state?"Transcribing…":"Voice input",onClick:P,disabled:"transcribing"===T.state,className:"w-8 h-8 shrink-0 flex items-center justify-center border-none transition-all duration-150 ease-in-out ".concat("recording"===T.state?"rounded-full bg-[var(--system-red)] text-white cursor-pointer":"rounded-[var(--radius-sm)] bg-transparent text-[var(--text-secondary)] ".concat("transcribing"===T.state?"cursor-wait":"cursor-pointer")),title:"recording"===T.state?"Stop recording":"transcribing"===T.state?"Transcribing…":"Voice input",children:"transcribing"===T.state?(0,a.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"animate-[stt-spin_1s_linear_infinite]",children:(0,a.jsx)("path",{d:"M12 2a10 10 0 0 1 10 10"})}):(0,a.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,a.jsx)("path",{d:"M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"}),(0,a.jsx)("path",{d:"M19 10v2a7 7 0 0 1-14 0v-2"}),(0,a.jsx)("line",{x1:"12",y1:"19",x2:"12",y2:"23"}),(0,a.jsx)("line",{x1:"8",y1:"23",x2:"16",y2:"23"})]})}),"recording"===T.state&&T.analyser&&(0,a.jsx)(eo,{analyser:T.analyser,width:64,height:28}),r&&i&&(0,a.jsx)("button",{onClick:i,"aria-label":"Stop",className:"w-8 h-8 rounded-full bg-[var(--system-red)] text-white border-none cursor-pointer flex items-center justify-center shrink-0 transition-all duration-150 ease-in-out",children:(0,a.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:(0,a.jsx)("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"})})}),(0,a.jsx)("button",{onClick:U,disabled:!V||t,"aria-label":"Send message",className:"w-8 h-8 rounded-full border-none flex items-center justify-center shrink-0 transition-all duration-150 ease-in-out ".concat(V?"bg-[var(--accent)] text-[var(--accent-contrast)] cursor-pointer":"bg-[var(--fill-tertiary)] text-[var(--text-quaternary)] cursor-default"),children:(0,a.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,a.jsx)("line",{x1:"12",y1:"19",x2:"12",y2:"5"}),(0,a.jsx)("polyline",{points:"5 12 12 5 19 12"})]})})]}),(0,a.jsxs)("div",{className:"hidden sm:flex text-[length:var(--text-caption2)] text-[var(--text-quaternary)] text-center mt-[var(--space-1)] justify-center gap-[var(--space-3)]",children:[(0,a.jsx)("span",{children:"Enter to send"}),(0,a.jsx)("span",{children:"/ - commands"}),(0,a.jsx)("span",{children:"@name - mention"})]}),"error"===T.state&&T.error&&(0,a.jsxs)("div",{className:"flex items-center gap-[var(--space-2)] mt-[var(--space-2)] py-[var(--space-2)] px-[var(--space-3)] rounded-[var(--radius-sm)] text-[length:var(--text-caption1)] text-[var(--system-red)]",style:{background:"color-mix(in srgb, var(--system-red) 12%, transparent)"},children:[(0,a.jsxs)("span",{className:"flex-1",children:["Voice input error: ",T.error]}),(0,a.jsx)("button",{onClick:T.dismissError,className:"bg-none border-none cursor-pointer text-[var(--system-red)] text-[length:var(--text-caption1)] font-semibold py-0.5 px-1.5",children:"Dismiss"})]}),(0,a.jsx)(ei,{open:"no-model"===T.state,progress:T.downloadProgress,onDownload:T.startDownload,onCancel:T.dismissDownload}),(0,a.jsx)("style",{children:"\n @keyframes stt-spin {\n from { transform: rotate(0deg); }\n to { transform: rotate(360deg); }\n }\n "})]})}var ex=r(687),ep=r(7181);function em(e){let{sessionId:t,events:r,paused:s=!1}=e,[i,o]=(0,n.useState)([]),[c,d]=(0,n.useState)(s),u=(0,n.useCallback)(async()=>{if(t)try{let e=await l.F.getSessionQueue(t);o(e)}catch(e){}},[t]);(0,n.useEffect)(()=>{u()},[u]),(0,n.useEffect)(()=>{if(!r.length)return;let e=r[r.length-1];if("queue:updated"===e.event){u();let t=e.payload;"boolean"==typeof(null==t?void 0:t.paused)&&d(t.paused)}},[r,u]);let x=i.filter(e=>"pending"===e.status);if(!t||0===x.length)return null;async function m(e){if(t)try{await l.F.cancelQueueItem(t,e),await u()}catch(e){}}async function h(){if(t)try{await l.F.clearSessionQueue(t),o([])}catch(e){}}async function v(){if(t)try{c?(await l.F.resumeSessionQueue(t),d(!1)):(await l.F.pauseSessionQueue(t),d(!0))}catch(e){}}return(0,a.jsxs)("div",{className:"border-t border-[var(--separator)] px-[var(--space-4)] py-[var(--space-2)] bg-[var(--fill-quaternary)] shrink-0",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between mb-[var(--space-1)]",children:[(0,a.jsxs)("span",{className:"text-[length:var(--text-caption2)] font-semibold text-[var(--text-secondary)] uppercase tracking-[0.5px]",children:[x.length," queued ",c&&"\xb7 Paused"]}),(0,a.jsxs)("div",{className:"flex gap-[var(--space-1)]",children:[(0,a.jsx)("button",{onClick:v,title:c?"Resume queue":"Pause queue",className:"bg-transparent border-none cursor-pointer text-[var(--text-secondary)] p-0.5 flex items-center",children:c?(0,a.jsx)(ex.A,{size:13}):(0,a.jsx)(ep.A,{size:13})}),(0,a.jsx)("button",{onClick:h,title:"Clear all queued messages",className:"bg-transparent border-none cursor-pointer text-[var(--text-secondary)] p-0.5 flex items-center",children:(0,a.jsx)(p.A,{size:13})})]})]}),(0,a.jsx)("div",{className:"flex flex-col gap-0.5",children:x.map(e=>(0,a.jsxs)("div",{className:"flex items-center gap-[var(--space-2)] px-[var(--space-2)] py-[3px] rounded-[var(--radius-sm)] bg-[var(--fill-tertiary)]",children:[(0,a.jsxs)("span",{className:"text-[length:var(--text-caption2)] text-[var(--text-tertiary)] min-w-4",children:[e.position,"."]}),(0,a.jsx)("span",{className:"flex-1 text-[length:var(--text-caption1)] text-[var(--text-secondary)] overflow-hidden text-ellipsis whitespace-nowrap",children:e.prompt.length>60?e.prompt.slice(0,57)+"...":e.prompt}),(0,a.jsx)("button",{onClick:()=>m(e.id),title:"Cancel this message",className:"bg-transparent border-none cursor-pointer text-[var(--text-tertiary)] p-px flex items-center shrink-0",children:(0,a.jsx)(g.A,{size:11})})]},e.id))})]})}function eh(e){let{input:t}=e,[r,s]=(0,n.useState)(!1),l=JSON.stringify(t,null,2);return l.length>300?(0,a.jsxs)("div",{children:[(0,a.jsx)("button",{onClick:()=>s(e=>!e),className:"mt-1 px-2 py-0.5 text-[11px] rounded bg-white/[0.08] border border-white/[0.12] text-[var(--text-tertiary)] cursor-pointer font-[SF_Mono,Menlo,Cascadia_Code,monospace]",children:r?"collapse input":"show input (".concat(l.length," chars)")}),r&&(0,a.jsx)("pre",{className:"mt-1 px-2.5 py-1.5 bg-white/5 rounded text-xs leading-normal whitespace-pre-wrap break-all text-[var(--text-secondary)] font-[SF_Mono,Menlo,Cascadia_Code,monospace] overflow-x-auto max-h-[400px] overflow-y-auto",children:l})]}):(0,a.jsx)("pre",{className:"mt-1 px-2.5 py-1.5 bg-white/5 rounded text-xs leading-normal whitespace-pre-wrap break-all text-[var(--text-secondary)] font-[SF_Mono,Menlo,Cascadia_Code,monospace] overflow-x-auto",children:l})}function eg(e){let{text:t}=e,[r,s]=(0,n.useState)(!1);return(0,a.jsxs)("div",{className:"mb-1.5",children:[(0,a.jsx)("button",{onClick:()=>s(e=>!e),className:"px-2 py-0.5 text-[11px] rounded bg-white/[0.06] border border-white/10 text-[var(--text-quaternary,var(--text-tertiary))] cursor-pointer font-[SF_Mono,Menlo,Cascadia_Code,monospace] italic",children:r?"hide thinking":"show thinking"}),r&&(0,a.jsx)("div",{className:"mt-1 px-3 py-2 bg-white/[0.04] border-l-2 border-white/10 text-xs leading-relaxed text-[var(--text-quaternary,var(--text-tertiary))] italic whitespace-pre-wrap break-words font-[SF_Mono,Menlo,Cascadia_Code,monospace]",children:t})]})}function ev(e){let{text:t}=e,[r,s]=(0,n.useState)(!1);return t.length>500?(0,a.jsxs)("div",{children:[(0,a.jsx)("button",{onClick:()=>s(e=>!e),className:"mt-1 px-2 py-0.5 text-[11px] rounded bg-white/[0.08] border border-white/[0.12] text-[var(--text-tertiary)] cursor-pointer font-[SF_Mono,Menlo,Cascadia_Code,monospace]",children:r?"collapse output":"show output (".concat(t.length," chars)")}),r&&(0,a.jsx)("pre",{className:"mt-1 px-2.5 py-1.5 bg-white/[0.04] rounded text-xs leading-normal whitespace-pre-wrap break-all text-[var(--text-tertiary)] font-[SF_Mono,Menlo,Cascadia_Code,monospace] overflow-x-auto max-h-[400px] overflow-y-auto",children:t})]}):(0,a.jsx)("pre",{className:"mt-1 px-2.5 py-1.5 bg-white/[0.04] rounded text-xs leading-normal whitespace-pre-wrap break-all text-[var(--text-tertiary)] font-[SF_Mono,Menlo,Cascadia_Code,monospace] overflow-x-auto max-h-[300px] overflow-y-auto",children:t||"(empty)"})}function ef(e){let{block:t}=e;return"thinking"===t.type?(0,a.jsx)(eg,{text:t.text||""}):"tool_use"===t.type?(0,a.jsxs)("div",{className:"mb-2 px-2.5 py-1.5 bg-[rgba(99,179,237,0.08)] border border-[rgba(99,179,237,0.2)] rounded-md",children:[(0,a.jsxs)("div",{className:"text-[11px] font-semibold text-[rgba(99,179,237,0.9)] font-[SF_Mono,Menlo,Cascadia_Code,monospace] mb-0.5 uppercase tracking-wide",children:["tool: ",t.name]}),t.input&&Object.keys(t.input).length>0&&(0,a.jsx)(eh,{input:t.input})]}):"tool_result"===t.type?(0,a.jsxs)("div",{className:"mb-2 px-2.5 py-1.5 bg-white/[0.03] border border-white/[0.08] rounded-md",children:[(0,a.jsx)("div",{className:"text-[11px] font-semibold text-[rgba(160,160,160,0.7)] font-[SF_Mono,Menlo,Cascadia_Code,monospace] mb-0.5 uppercase tracking-wide",children:"result"}),(0,a.jsx)(ev,{text:t.text||""})]}):(0,a.jsx)("div",{className:"whitespace-pre-wrap break-words leading-relaxed text-[var(--text-primary)] mb-1",children:t.text})}function eb(e){let{entry:t}=e,r="user"===t.role;return(0,a.jsxs)("div",{className:"flex gap-2.5 py-2.5 border-b border-white/[0.04]",children:[(0,a.jsx)("div",{className:"shrink-0 w-4 text-[13px] font-bold font-[SF_Mono,Menlo,Cascadia_Code,monospace] pt-px",style:{color:r?"var(--accent)":"rgba(110, 231, 183, 0.8)"},children:r?">":"$"}),(0,a.jsx)("div",{className:"flex-1 min-w-0",children:t.content.map((e,t)=>(0,a.jsx)(ef,{block:e},t))})]})}function ey(e){let{sessionId:t}=e,[r,s]=(0,n.useState)([]),[i,o]=(0,n.useState)(!0),[c,d]=(0,n.useState)(null),u=(0,n.useRef)(null);return((0,n.useEffect)(()=>{t&&(o(!0),d(null),l.F.getSessionTranscript(t).then(e=>{s(e),o(!1)}).catch(e=>{d(e instanceof Error?e.message:"Failed to load transcript"),o(!1)}))},[t]),(0,n.useEffect)(()=>{var e;null==(e=u.current)||e.scrollIntoView({behavior:"instant"})},[r]),i)?(0,a.jsx)("div",{className:"flex-1 flex items-center justify-center bg-[var(--bg-primary,var(--bg))] text-[var(--text-tertiary)] font-[SF_Mono,Menlo,Cascadia_Code,monospace] text-[13px]",children:"loading transcript..."}):c?(0,a.jsxs)("div",{className:"flex-1 flex items-center justify-center bg-[var(--bg-primary,var(--bg))] text-[var(--system-red)] font-[SF_Mono,Menlo,Cascadia_Code,monospace] text-[13px]",children:["error: ",c]}):0===r.length?(0,a.jsx)("div",{className:"flex-1 flex items-center justify-center bg-[var(--bg-primary,var(--bg))] text-[var(--text-tertiary)] font-[SF_Mono,Menlo,Cascadia_Code,monospace] text-[13px]",children:"no transcript available"}):(0,a.jsxs)("div",{className:"flex-1 overflow-y-auto overflow-x-hidden bg-[var(--bg-primary,var(--bg))] p-[var(--space-4)] font-[SF_Mono,Menlo,Cascadia_Code,monospace] text-[13px] leading-normal min-h-0",children:[r.map((e,t)=>(0,a.jsx)(eb,{entry:e},t)),(0,a.jsx)("div",{ref:u})]})}function ej(e){var t;let{sessionId:r,isActive:s,onFocus:i,onSessionCreated:o,onSessionMetaChange:c,onRefresh:d,portalName:u="Jinn",subscribe:x,connectionSeq:p,skillsVersion:m,events:h,viewMode:g="chat",getOnboardingPrompt:v,isStubSession:f,onStubCleared:b}=e,[y,j]=(0,n.useState)([]),[w,k]=(0,n.useState)(!1),N=(0,n.useRef)(""),[S,C]=(0,n.useState)(""),I=(0,n.useRef)(-1),[D,M]=(0,n.useState)(null),L=(0,n.useRef)(r);(0,n.useEffect)(()=>{L.current=r},[r]);let E=(0,n.useCallback)((e,t)=>{if(!t)return;let r=I.current;if(r<0)return;let a=e.slice(r);a.length>0&&function(e,t){try{localStorage.setItem("".concat(V).concat(e),JSON.stringify(t))}catch(e){}}(t,a)},[]);(0,n.useEffect)(()=>x((e,t)=>{let r=L.current;if(r&&t.sessionId===r){if("session:delta"===e){let e=String(t.type||"text");if("text"===e){let e=String(t.content||"");N.current+=e,C(N.current)}else if("text_snapshot"===e){let e=String(t.content||"");e.length>=N.current.length&&(N.current=e,C(e))}else if("tool_use"===e){if(N.current){let e=N.current;N.current="",C(""),j(t=>{I.current<0&&(I.current=t.length);let a=[...t,{id:crypto.randomUUID(),role:"assistant",content:e,timestamp:Date.now()}];return E(a,r),a})}let e=String(t.toolName||"tool");j(t=>{I.current<0&&(I.current=t.length);let a=[...t,{id:crypto.randomUUID(),role:"assistant",content:"Using ".concat(e),timestamp:Date.now(),toolCall:e}];return E(a,r),a})}else"tool_result"===e&&j(e=>{let t=[...e],a=t[t.length-1];return a&&"assistant"===a.role&&a.toolCall&&(t[t.length-1]={...a,content:"Used ".concat(a.toolCall)}),E(t,r),t})}if("session:notification"===e){let e=String(t.message||"");e&&j(t=>[...t,{id:crypto.randomUUID(),role:"notification",content:e,timestamp:Date.now()}])}if("session:interrupted"===e&&(N.current="",C("")),"session:stopped"===e&&(k(!1),C("")),"session:completed"===e){N.current="",C(""),k(!1),I.current=-1;let e=r||(t.sessionId?String(t.sessionId):null);e&&J(e),t.result&&j(e=>{let r=[...e],a=r[r.length-1];return a&&"assistant"===a.role&&!a.toolCall&&r.pop(),[...r,{id:crypto.randomUUID(),role:"assistant",content:String(t.result),timestamp:Date.now()}]}),t.error&&!t.result&&j(e=>[...e,{id:crypto.randomUUID(),role:"assistant",content:"Error: ".concat(t.error),timestamp:Date.now()}]),null==d||d()}}}),[x,E,d]);let A=(0,n.useCallback)(async e=>{try{let t=await l.F.getSession(e);M(t);let r={engine:t.engine?String(t.engine):void 0,engineSessionId:t.engineSessionId?String(t.engineSessionId):void 0,model:t.model?String(t.model):void 0,title:t.title?String(t.title):void 0,employee:t.employee?String(t.employee):void 0};null==c||c(r);let a=t.messages||t.history||[],n=Array.isArray(a)?a.map(e=>({id:crypto.randomUUID(),role:e.role||"assistant",content:String(e.content||e.text||""),timestamp:e.timestamp?Number(e.timestamp):Date.now()})):[];if("error"===t.status&&t.lastError){let e=n[n.length-1],r="Error: ".concat(String(t.lastError));e&&"assistant"===e.role&&e.content===r||n.push({id:crypto.randomUUID(),role:"assistant",content:r,timestamp:Date.now()})}if("running"===t.status){let t=function(e){try{let t=localStorage.getItem("".concat(V).concat(e));return t?JSON.parse(t):[]}catch(e){return[]}}(e);t.length>0?(I.current=n.length,j([...n,...t])):(I.current=n.length,j(n)),k(!0)}else J(e),I.current=-1,j(n)}catch(e){j([]),M(null),I.current=-1}},[c]);(0,n.useEffect)(()=>{if(!r){j([]),k(!1),M(null),N.current="",C(""),I.current=-1;return}A(r)},[r,A]),(0,n.useEffect)(()=>{p&&r&&A(r)},[p,r,A]),(0,n.useEffect)(()=>{if(!r||!w)return;let e=setInterval(async()=>{try{let e=await l.F.getSession(r);"running"!==e.status&&(await A(r),k(!1))}catch(e){}},5e3);return()=>clearInterval(e)},[r,w,A]);let z=(0,n.useCallback)(async()=>{if(r)try{await l.F.stopSession(r)}catch(e){}},[r]),_=(0,n.useCallback)(async(e,t,a)=>{let n={id:crypto.randomUUID(),role:"user",content:e,timestamp:Date.now(),media:t};j(e=>(I.current=e.length+1,[...e,n])),k(!0);try{let t=r;if(t&&f&&v){null==b||b();let r=v(e);await l.F.sendMessage(t,{message:r}),null==d||d()}else if(t)await l.F.sendMessage(t,{message:e,interrupt:a||void 0}),null==d||d();else{let r=await l.F.createSession({source:"web",prompt:e});t=String(r.id),null==o||o(t),null==d||d()}}catch(e){k(!1),j(t=>[...t,{id:crypto.randomUUID(),role:"assistant",content:"Error: ".concat(e instanceof Error?e.message:"Failed to send message"),timestamp:Date.now()}])}},[r,f,v,b,o,d]),T=(0,n.useCallback)(async()=>{if(!r)return void j(e=>[...e,{id:crypto.randomUUID(),role:"assistant",content:"No active session. Send a message to start one.",timestamp:Date.now()}]);try{let e=await l.F.getSession(r),t=["**Session Info**","ID: `".concat(e.id,"`"),"Status: ".concat(e.status||"unknown"),e.employee?"Employee: ".concat(e.employee):null,e.engine?"Engine: ".concat(e.engine):null,e.model?"Model: ".concat(e.model):null,e.createdAt?"Created: ".concat(e.createdAt):null].filter(Boolean).join("\n");j(e=>[...e,{id:crypto.randomUUID(),role:"assistant",content:t,timestamp:Date.now()}])}catch(e){j(e=>[...e,{id:crypto.randomUUID(),role:"assistant",content:"Failed to fetch session status.",timestamp:Date.now()}])}},[r]),R=(0,n.useCallback)(()=>{j([]),k(!1),M(null),N.current="",C(""),I.current=-1},[]);return(0,a.jsxs)("div",{style:{display:"flex",flexDirection:"column",flex:1,overflow:"hidden",background:"var(--bg)"},onClick:i,children:["cli"===g&&r?(0,a.jsx)(ey,{sessionId:r}):(0,a.jsx)(es,{messages:y,loading:w,streamingText:S}),"chat"===g&&(0,a.jsx)(em,{sessionId:r,events:h,paused:null!=(t=null==D?void 0:D.paused)&&t}),"chat"===g&&(0,a.jsx)(eu,{disabled:!1,loading:w,onSend:_,onInterrupt:z,onNewSession:R,onStatusRequest:T,skillsVersion:m,events:h})]})}let ew="jinn-chat-tabs",ek="jinn-chat-draft-";var eN=r(7122),eS=r(5465),eC=r(7632),eI=r(6790),eD=r(4139);class eM extends n.Component{static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error("[ChatErrorBoundary]",e.message,"\nComponent stack:",t.componentStack)}render(){if(this.state.error){var e;return(0,a.jsx)(o.M,{children:(0,a.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-4 p-8 text-center",children:[(0,a.jsx)("p",{className:"text-lg font-semibold text-[var(--system-red)]",children:"Chat crashed"}),(0,a.jsxs)("pre",{className:"max-w-lg overflow-auto rounded-lg bg-[var(--bg-tertiary)] p-4 text-left text-xs text-muted-foreground",children:[this.state.error.message,"\n",null==(e=this.state.error.stack)?void 0:e.split("\n").slice(0,5).join("\n")]}),(0,a.jsx)("button",{onClick:()=>{this.setState({error:null}),window.location.reload()},className:"rounded-md bg-[var(--accent)] px-4 py-2 text-sm font-medium text-white",children:"Reload"})]})})}return this.props.children}constructor(...e){super(...e),this.state={error:null}}}function eL(){return(0,a.jsx)(eM,{children:(0,a.jsx)(n.Suspense,{fallback:(0,a.jsx)(o.M,{children:(0,a.jsx)("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:"Loading..."})}),children:(0,a.jsx)(eE,{})})})}function eE(){var e;let{settings:t}=(0,b.t0)(),r=null!=(e=t.portalName)?e:"Jinn",[c,d]=(0,n.useState)(null),[u,m]=(0,n.useState)("sidebar"),[h,g]=(0,n.useState)(null),[v,f]=(0,n.useState)([]),j=(0,n.useRef)(!1),[k,N]=(0,n.useState)("chat"),[S,C]=(0,n.useState)(!1),[I,M]=(0,n.useState)(!1),[L,E]=(0,n.useState)(null),[A,z]=(0,n.useState)(!1),_=(0,n.useRef)(null),T=(0,n.useRef)(null),{events:R,connectionSeq:F,skillsVersion:U,subscribe:W}=(0,i.G)(),B=function(){let[{tabs:e,activeIndex:t},r]=(0,n.useState)({tabs:[],activeIndex:-1});(0,n.useEffect)(()=>{r(function(){try{let t=localStorage.getItem(ew);if(t){var e;return e=JSON.parse(t),0===e.tabs.length?{tabs:[],activeIndex:-1}:e.activeIndex<0||e.activeIndex>=e.tabs.length?{tabs:e.tabs,activeIndex:0}:e}}catch(e){}return{tabs:[],activeIndex:-1}}())},[]),(0,n.useEffect)(()=>{localStorage.setItem(ew,JSON.stringify({tabs:e,activeIndex:t}))},[e,t]);let a=t>=0?e[t]:null,s=(0,n.useCallback)(e=>{r(t=>{let r=t.tabs.findIndex(t=>t.sessionId===e.sessionId);if(r>=0)return{tabs:t.tabs.map((t,a)=>a===r?{...t,...e}:t),activeIndex:r};if(t.tabs.length>=12){let r=t.tabs.findIndex((e,r)=>r!==t.activeIndex);if(r>=0){let a=[...t.tabs];return a[r]=e,{tabs:a,activeIndex:r}}}return{tabs:[...t.tabs,e],activeIndex:t.tabs.length}})},[]),l=(0,n.useCallback)(e=>{r(t=>{var r;let a=null==(r=t.tabs[e])?void 0:r.sessionId;a&&localStorage.removeItem(ek+a);let n=t.tabs.filter((t,r)=>r!==e);if(0===n.length)return{tabs:[],activeIndex:-1};let s=t.activeIndex;return t.activeIndex===e?s=Math.min(e,n.length-1):t.activeIndex>e&&(s=t.activeIndex-1),{tabs:n,activeIndex:s}})},[]),i=(0,n.useCallback)(e=>{r(t=>e<0||e>=t.tabs.length?t:{...t,activeIndex:e})},[e.length]),o=(0,n.useCallback)(()=>{r(e=>0===e.tabs.length?e:{...e,activeIndex:(e.activeIndex+1+e.tabs.length)%e.tabs.length})},[e.length]),c=(0,n.useCallback)(()=>{r(e=>0===e.tabs.length?e:{...e,activeIndex:(e.activeIndex-1+e.tabs.length)%e.tabs.length})},[e.length]),d=(0,n.useCallback)(()=>{r(e=>({...e,activeIndex:-1}))},[]),u=(0,n.useCallback)((e,t)=>{t.trim()?localStorage.setItem(ek+e,t):localStorage.removeItem(ek+e)},[]);return{tabs:e,activeTab:a,activeIndex:t,openTab:s,closeTab:l,switchTab:i,nextTab:o,prevTab:c,clearActiveTab:d,saveDraft:u,loadDraft:(0,n.useCallback)(e=>localStorage.getItem(ek+e)||"",[]),updateTabStatus:(0,n.useCallback)((e,t)=>{r(r=>({...r,tabs:r.tabs.map(r=>r.sessionId===e?{...r,...t}:r)}))},[])}}(),P=(0,s.useSearchParams)(),q=(0,n.useRef)(!1),V=(0,n.useRef)(!1);(0,y.tS)();let H=(0,eN.jE)();(0,n.useEffect)(()=>{if(S||I)return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e);function e(e){S&&_.current&&!_.current.contains(e.target)&&C(!1),I&&T.current&&!T.current.contains(e.target)&&M(!1)}},[S,I]);let Q=(0,n.useCallback)((e,t)=>{navigator.clipboard.writeText(e),E(t),C(!1),setTimeout(()=>E(null),1500)},[]);function $(){l.F.createStubSession({greeting:"Hey! \uD83D\uDC4B Say hi when you're ready to get started.",title:"Welcome"}).then(e=>{let t=String(e.id);V.current=!0,d(t),H.invalidateQueries({queryKey:eS.l.sessions.all})}).catch(()=>{})}(0,n.useEffect)(()=>{q.current||("1"===P.get("onboarding")?(q.current=!0,$()):l.F.getOnboarding().then(e=>{e.needed&&!q.current&&(q.current=!0,$())}).catch(()=>{}))},[P]),(0,n.useEffect)(()=>{c&&h&&B.updateTabStatus(c,{label:h.title||h.employee||r})},[c,h,r,B]);let G=(0,n.useCallback)(e=>{f(e.length>1?e:[])},[]),Y=(0,n.useCallback)(e=>{j.current=!1,V.current=!1,d(e),m("chat"),N("chat"),B.openTab({sessionId:e,label:"Loading...",status:"idle",unread:!1})},[B]),X=(0,n.useCallback)(()=>{j.current=!0,d(null),g(null),m("chat"),f([]),B.clearActiveTab()},[B]),Z=(0,n.useCallback)(e=>{c||q.current||j.current||!(e.length>0)||Y(e[0].id)},[c,Y]),ee=(0,n.useCallback)(e=>{c===e&&(d(null),g(null)),J(e),B.closeTab(B.tabs.findIndex(t=>t.sessionId===e)),z(!1),C(!1)},[c,B]),et=(0,n.useCallback)(e=>{d(e),B.openTab({sessionId:e,label:"New Chat",status:"running",unread:!1}),H.invalidateQueries({queryKey:eS.l.sessions.all})},[B,H]),er=(0,n.useCallback)(e=>{g(e)},[]),ea=(0,n.useCallback)(()=>{H.invalidateQueries({queryKey:eS.l.sessions.all})},[H]),en=(0,n.useCallback)(e=>"This is your first time being activated. The user just set up ".concat(r," and opened the web dashboard for the first time.\n\nRead your CLAUDE.md instructions and the onboarding skill at ~/.jinn/skills/onboarding/SKILL.md, then follow the onboarding flow:\n- Greet the user warmly and introduce yourself as ").concat(r,"\n- Briefly explain what you can do (manage cron jobs, hire AI employees, connect to Slack, etc.)\n- Ask the user what they'd like to set up first\n\nThe user said: \"").concat(e,'"'),[r]),es=(0,n.useCallback)(()=>{V.current=!1},[]);(0,n.useEffect)(()=>{function e(e){e.metaKey&&"w"===e.key&&(e.preventDefault(),B.activeIndex>=0&&B.closeTab(B.activeIndex)),e.metaKey&&e.shiftKey&&"["===e.key&&(e.preventDefault(),B.prevTab()),e.metaKey&&e.shiftKey&&"]"===e.key&&(e.preventDefault(),B.nextTab()),e.metaKey&&e.altKey&&e.key>="1"&&e.key<="9"&&(e.preventDefault(),B.switchTab(parseInt(e.key)-1))}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[B]),(0,n.useEffect)(()=>{if(B.activeTab&&B.activeTab.sessionId!==c){d(B.activeTab.sessionId),N("chat");return}B.activeTab||!c||j.current||(d(null),g(null),f([]))},[B.activeTab,c]);let el=c?(0,a.jsxs)("div",{ref:_,className:"relative",children:[(0,a.jsx)("button",{onClick:()=>C(e=>!e),"aria-label":"More options",className:"flex items-center rounded-md p-1 text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",children:(0,a.jsx)(x.A,{className:"size-[18px]"})}),S&&(0,a.jsxs)("div",{className:"absolute right-0 top-full z-[200] mt-1 min-w-[220px] overflow-hidden rounded-[var(--radius-md)] border border-border bg-[var(--material-thick)] shadow-[var(--shadow-overlay)] backdrop-blur-xl",children:[(0,a.jsx)("button",{onClick:()=>Q(c,"id"),className:"block w-full px-3 py-2 text-left text-sm text-foreground transition-colors hover:bg-accent",children:"Copy Session ID"}),(null==h?void 0:h.engineSessionId)&&(0,a.jsx)("button",{onClick:()=>{let e="codex"===h.engine?"codex":"claude";Q("".concat(e," --resume ").concat(h.engineSessionId),"cli")},className:"block w-full px-3 py-2 text-left text-sm text-foreground transition-colors hover:bg-accent",children:"Copy CLI Resume Command"}),(0,a.jsx)("div",{className:"my-0.5 border-t border-border"}),(0,a.jsxs)("button",{onClick:()=>{C(!1),z(!0)},className:"flex w-full items-center gap-2 px-3 py-2 text-left text-sm text-[var(--system-red)] transition-colors hover:bg-accent",children:[(0,a.jsx)(p.A,{className:"size-3.5"}),"Delete Session"]})]})]}):null,ei=(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("button",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-sm font-medium text-[var(--accent)] transition-colors hover:bg-accent lg:hidden",onClick:()=>m("sidebar"),"aria-label":"Back to sessions",children:[(0,a.jsx)(eI.A,{className:"size-4"}),"Back"]}),c&&(0,a.jsxs)("div",{className:"flex items-center gap-0.5 rounded-full bg-[var(--fill-tertiary)] p-0.5",children:[(0,a.jsx)("button",{onClick:()=>N("chat"),className:(0,w.cn)("rounded-full px-2.5 py-1 text-[11px] font-medium transition-all","chat"===k?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:"Chat"}),(0,a.jsx)("button",{onClick:()=>N("cli"),className:(0,w.cn)("rounded-full px-2.5 py-1 font-mono text-[11px] font-medium transition-all","cli"===k?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:"CLI"})]}),(0,a.jsx)("div",{className:"hidden lg:block",children:el}),L&&(0,a.jsxs)("div",{className:"flex items-center gap-1 whitespace-nowrap text-xs font-medium text-[var(--accent)]",children:[(0,a.jsx)(eD.A,{className:"size-3"}),"Copied!"]})]});return(0,a.jsxs)(o.M,{mobileHeaderActions:el,children:[(0,a.jsxs)("div",{className:"flex h-[calc(100%-48px)] overflow-hidden lg:h-full",children:[(0,a.jsx)("div",{className:"hidden h-full w-[280px] shrink-0 lg:block",children:(0,a.jsx)(K,{selectedId:c,onSelect:Y,onNewChat:X,onDelete:ee,onSessionsLoaded:Z,onEmployeeSessionsAvailable:G})}),(0,a.jsx)("div",{className:"sidebar"===u?"block lg:hidden":"hidden",style:{width:"100%",height:"100%"},children:(0,a.jsx)(K,{selectedId:c,onSelect:Y,onNewChat:X,onDelete:ee,onSessionsLoaded:Z,onEmployeeSessionsAvailable:G})}),(0,a.jsxs)("div",{className:(0,w.cn)("min-w-0 flex-1 flex-col overflow-hidden bg-background","sidebar"===u?"hidden lg:flex":"flex"),children:[(0,a.jsx)(O,{tabs:B.tabs,activeIndex:B.activeIndex,onSwitch:B.switchTab,onClose:B.closeTab,onNew:X,toolbarActions:ei}),(0,a.jsx)(ej,{sessionId:c,isActive:!0,onFocus:()=>{},onSessionCreated:et,onSessionMetaChange:er,onRefresh:ea,portalName:r,subscribe:W,connectionSeq:F,skillsVersion:U,events:R,viewMode:k,getOnboardingPrompt:V.current?en:void 0,isStubSession:V.current,onStubCleared:es})]})]}),(0,a.jsx)(eC.lG,{open:A&&!!c,onOpenChange:z,children:(0,a.jsxs)(eC.Cf,{showCloseButton:!1,className:"max-w-sm",children:[(0,a.jsxs)(eC.c7,{children:[(0,a.jsx)(eC.L3,{children:"Delete Session?"}),(0,a.jsx)(eC.rr,{children:"This will permanently delete the session and all its messages."})]}),(0,a.jsxs)(eC.Es,{children:[(0,a.jsx)(D.$,{variant:"outline",onClick:()=>z(!1),children:"Cancel"}),(0,a.jsx)(D.$,{variant:"destructive",onClick:()=>c&&ee(c),children:"Delete"})]})]})})]})}},7983:(e,t,r)=>{Promise.resolve().then(r.bind(r,4527))}},e=>{e.O(0,[625,51,458,865,155,192,344,144,358],()=>e(e.s=7983)),_N_E=e.O()}]);