@alook/app 0.0.139 → 0.0.141
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundled/email-worker/index.js +50 -33
- package/bundled/web/.open-next/.build/durable-objects/queue.js +5 -5
- package/bundled/web/.open-next/assets/BUILD_ID +1 -1
- package/bundled/web/.open-next/assets/_next/static/chunks/0eayyb8dzeuqj.js +1 -0
- package/bundled/web/.open-next/assets/_next/static/chunks/0hujq4gn1km2d.css +1 -0
- package/bundled/web/.open-next/assets/_next/static/chunks/{3a4lcn1k6my37.js → 0u1g621cl6cpa.js} +1 -1
- package/bundled/web/.open-next/assets/_next/static/chunks/{0gadq1gaq7l2d.js → 0v8_t40u7sj2s.js} +3 -3
- package/bundled/web/.open-next/assets/_next/static/chunks/{0pqa0bk3fnq2q.js → 15gpqusfs36cs.js} +2 -2
- package/bundled/web/.open-next/assets/_next/static/chunks/{0rmmmmqzr5q8u.js → 1vdalq9vvychb.js} +1 -1
- package/bundled/web/.open-next/assets/_next/static/chunks/1wk6udc50axdg.js +1 -0
- package/bundled/web/.open-next/assets/_next/static/chunks/{1l3nq6kc3fbh-.js → 2aicu2qufs82c.js} +1 -1
- package/bundled/web/.open-next/assets/_next/static/chunks/2c9n34tpjgbko.js +1 -0
- package/bundled/web/.open-next/assets/_next/static/chunks/{2h7oy-ljwoem9.js → 2jgr6hdohnj5b.js} +1 -1
- package/bundled/web/.open-next/assets/_next/static/chunks/{2qc57pol1-1f3.js → 348z6y6iea4gl.js} +3 -3
- package/bundled/web/.open-next/assets/_next/static/chunks/447gx8byleobi.js +1 -0
- package/bundled/web/.open-next/cache/{0z9UpPLBZKa_jgTjfoBR5 → n67RZ-dHYbiPuCBj-CPEs}/_global-error.cache +1 -1
- package/bundled/web/.open-next/cache/{0z9UpPLBZKa_jgTjfoBR5 → n67RZ-dHYbiPuCBj-CPEs}/_not-found.cache +1 -1
- package/bundled/web/.open-next/cache/{0z9UpPLBZKa_jgTjfoBR5 → n67RZ-dHYbiPuCBj-CPEs}/device.cache +1 -1
- package/bundled/web/.open-next/cache/{0z9UpPLBZKa_jgTjfoBR5 → n67RZ-dHYbiPuCBj-CPEs}/privacy.cache +1 -1
- package/bundled/web/.open-next/cache/{0z9UpPLBZKa_jgTjfoBR5 → n67RZ-dHYbiPuCBj-CPEs}/sitemap.xml.cache +1 -1
- package/bundled/web/.open-next/cloudflare/cache-assets-manifest.sql +1 -1
- package/bundled/web/.open-next/cloudflare/init.js +1 -1
- package/bundled/web/.open-next/dynamodb-provider/dynamodb-cache.json +1 -1
- package/bundled/web/.open-next/middleware/handler.mjs +5 -5
- package/bundled/web/.open-next/server-functions/default/src/web/.next/BUILD_ID +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/build-manifest.json +3 -3
- package/bundled/web/.open-next/server-functions/default/src/web/.next/prerender-manifest.json +3 -3
- package/bundled/web/.open-next/server-functions/default/src/web/.next/required-server-files.json +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/invite/[token]/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/studio/new/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/agents/[id]/activity/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/agents/[id]/chat/[convId]/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/agents/[id]/chat/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/agents/[id]/email/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/agents/[id]/files/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/agents/[id]/meetings/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/agents/[id]/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/agents/new/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/agents/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/calendar/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/flags/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/help/email-setup/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/home/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/issues/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/runtimes/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/settings/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/traces/[traceId]/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/traces/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/w/[slug]/unread/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(app)/workspaces/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/(auth)/sign-in/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/api/daemon/tasks/[taskId]/complete/route.js +2 -2
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/api/daemon/tasks/[taskId]/fail/route.js +2 -2
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/api/daemon/tasks/[taskId]/start/route.js +2 -2
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/api/daemon/tasks/[taskId]/supersede/route.js +2 -2
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/device/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/page/react-loadable-manifest.json +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/privacy/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/templates/[id]/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/app/templates/page_client-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__0aacn1t._.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__0aj228b._.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__0dvn7u2._.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__0pn6awg._.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__12fz1lr._.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/{[root-of-the-server]__11-5cy7._.js → [root-of-the-server]__134-7z_._.js} +2 -2
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__155l597._.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__1diut0w._.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__1e9t6i6._.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/{[root-of-the-server]__1lcw_r4._.js → [root-of-the-server]__1jq8zws._.js} +2 -2
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/{[root-of-the-server]__0dnslqa._.js → [root-of-the-server]__1w9__7q._.js} +2 -2
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[root-of-the-server]__1xpwaca._.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/{[root-of-the-server]__0j4ezcj._.js → [root-of-the-server]__20s9whj._.js} +2 -2
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/[turbopack]_runtime.js +16 -16
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_0d2x7fl._.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_0guhu0i._.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_0n8pg0d._.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_0v95a0y._.js +11 -10
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_139j3zh._.js +11 -10
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_13jq647._.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_1a2lyoh._.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_1aztsqf._.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_1i4egv6._.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_1kt_xdj._.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/_1nfaney._.js +11 -10
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/ssr/[root-of-the-server]__13aweo1._.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/ssr/{[root-of-the-server]__1e237f4._.js → [root-of-the-server]__1x1ppqv._.js} +2 -2
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/ssr/[turbopack]_runtime.js +16 -16
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/ssr/_04ht2b1._.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/ssr/{_19hsbaa._.js → _09dj89g._.js} +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/ssr/_09v4-yk._.js +6 -5
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/ssr/_0qgcnj5._.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/ssr/{_0g_x3qh._.js → _16456wu._.js} +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/ssr/{_10-8eci._.js → _1twnk18._.js} +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/ssr/{node_modules__pnpm_0os8mdu._.js → node_modules__pnpm_00joh18._.js} +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/ssr/{node_modules__pnpm_03t1_eh._.js → node_modules__pnpm_06u5s5x._.js} +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/ssr/{node_modules__pnpm_0pd1a42._.js → node_modules__pnpm_0_eee0q._.js} +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/ssr/{node_modules__pnpm_0b_f_5l._.js → node_modules__pnpm_0_muan4._.js} +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/ssr/{node_modules__pnpm_0-sy0jc._.js → node_modules__pnpm_0t9vloz._.js} +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/ssr/{node_modules__pnpm_1tajvfi._.js → node_modules__pnpm_121t594._.js} +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/ssr/{node_modules__pnpm_0lmr_qu._.js → node_modules__pnpm_12zyy1_._.js} +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/ssr/{node_modules__pnpm_0z21f3h._.js → node_modules__pnpm_1m55ws1._.js} +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/ssr/src_web_src_0pwl5s4._.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/ssr/src_web_src_1kzi5ju._.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/ssr/src_web_src_app_(app)_w_[slug]_runtimes_page_tsx_11-1juy._.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/chunks/ssr/src_web_src_lib_api_ts_1ffelwp._.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/middleware-build-manifest.js +3 -3
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/middleware-manifest.json +5 -5
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/server-reference-manifest.js +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/.next/server/server-reference-manifest.json +1 -1
- package/bundled/web/.open-next/server-functions/default/src/web/handler.mjs +180 -176
- package/bundled/web/.open-next/server-functions/default/src/web/handler.mjs.meta.json +264 -264
- package/bundled/web/.open-next/server-functions/default/src/web/index.mjs +4 -4
- package/bundled/web/migrations/0043_machine_owner_id.sql +26 -0
- package/bundled/web/wrangler.toml +1 -1
- package/bundled/ws-do/index.js +50 -33
- package/dist/cli/index.js +13 -11
- package/dist/cli/session-runner.js +2 -1
- package/dist/index.js +39 -12
- package/package.json +1 -1
- package/bundled/web/.open-next/assets/_next/static/chunks/0pydx20mmtmb-.js +0 -1
- package/bundled/web/.open-next/assets/_next/static/chunks/11jejnuxkw5-s.js +0 -1
- package/bundled/web/.open-next/assets/_next/static/chunks/29j2dlmefldk5.js +0 -1
- package/bundled/web/.open-next/assets/_next/static/chunks/2usqt49xbpqd2.css +0 -1
- package/bundled/web/.open-next/assets/_next/static/chunks/3pmxar-ugtky1.js +0 -1
- /package/bundled/web/.open-next/assets/_next/static/{0z9UpPLBZKa_jgTjfoBR5 → n67RZ-dHYbiPuCBj-CPEs}/_buildManifest.js +0 -0
- /package/bundled/web/.open-next/assets/_next/static/{0z9UpPLBZKa_jgTjfoBR5 → n67RZ-dHYbiPuCBj-CPEs}/_clientMiddlewareManifest.js +0 -0
- /package/bundled/web/.open-next/assets/_next/static/{0z9UpPLBZKa_jgTjfoBR5 → n67RZ-dHYbiPuCBj-CPEs}/_ssgManifest.js +0 -0
- /package/bundled/web/.open-next/cache/{0z9UpPLBZKa_jgTjfoBR5 → n67RZ-dHYbiPuCBj-CPEs}/robots.txt.cache +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,74348,e=>{"use strict";var t=e.i(653772),a=e.i(511043),s=e.i(222862),r=e.i(500324);let n=(0,a.createContext)(null);e.s(["FlagCountProvider",0,function({children:e}){let{workspaceId:l}=(0,r.useWorkspace)(),[i,o]=(0,a.useState)(0),c=(0,a.useCallback)(()=>{(0,s.getFlaggedCount)(l).then(e=>o(e.count)).catch(()=>{})},[l]),d=(0,a.useCallback)(()=>{o(e=>e+1)},[]),u=(0,a.useCallback)(()=>{o(e=>Math.max(0,e-1))},[]);return(0,a.useEffect)(()=>{c()},[c]),(0,t.jsx)(n.Provider,{value:{count:i,refresh:c,increment:d,decrement:u},children:e})},"useFlagCount",0,function(){let e=(0,a.useContext)(n);if(!e)throw Error("useFlagCount must be used within FlagCountProvider");return e}])},817988,144516,865145,350780,158571,802634,431884,184526,773652,505175,684565,648365,360315,544346,204799,594518,378830,e=>{"use strict";var t=e.i(653772),a=e.i(511043),s=e.i(82970),r=e.i(896315),n=e.i(945074);let l={claude:"Claude Code",codex:"Codex",opencode:"OpenCode"},i="the agent runtime";function o({provider:e,message:c,onRetry:d,retrying:u}){let[m,f]=(0,a.useState)(!1),h=u??m,p=async()=>{if(d){f(!0);try{await d()}finally{f(!1)}}};return(0,t.jsxs)("div",{className:"rounded-md border border-destructive/30 bg-destructive/5 p-2 max-w-full overflow-hidden",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsxs)("p",{className:"flex items-center gap-1.5 text-sm font-semibold text-destructive min-w-0",children:[(0,t.jsx)(s.AlertCircle,{className:"size-3.5 shrink-0"}),(0,t.jsxs)("span",{children:["Error from ",e?l[e]??i:i]})]}),d&&(0,t.jsxs)("button",{type:"button",onClick:p,disabled:h,className:"ml-auto shrink-0 text-xs text-muted-foreground hover:text-foreground transition-colors cursor-pointer disabled:opacity-50 flex items-center gap-1",children:[h?(0,t.jsx)(n.Loader2,{className:"size-3 animate-spin"}):(0,t.jsx)(r.RotateCw,{className:"size-3"}),"Retry"]})]}),(0,t.jsx)("p",{className:"mt-1.5 text-sm text-destructive/90 wrap-anywhere whitespace-pre-wrap",children:c}),(0,t.jsx)("p",{className:"mt-1.5 text-xs text-muted-foreground",children:"This came from the agent runtime on your machine, not from Alook."})]})}function c({task:e,messages:s,connectionLost:r,onRetry:n,provider:l}){let i=(0,a.useMemo)(()=>(function(e){let t=[];for(let a of e)"error"===a.type&&t.push({kind:"error",id:a.id||`seq-${a.seq}`,content:a.content||a.output});return t})(s),[s]);return 0!==i.length||"failed"===e.status&&e.error||r?(0,t.jsxs)("div",{className:"space-y-3 min-w-0 max-w-full",children:[i.length>0&&(0,t.jsx)("div",{className:"space-y-1 mt-1",children:i.map(e=>(0,t.jsx)(o,{provider:l,message:e.content},e.id))}),"failed"===e.status&&e.error&&(0,t.jsx)("div",{className:"mt-2",children:(0,t.jsx)(o,{provider:l,message:e.error,onRetry:n})}),r&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground animate-pulse mt-1",children:"Connection lost — retrying..."})]}):null}function d(e,t,a){if(e?.issueId)return"issue";if(e?.emailId)return"email";if(e?.calendarEventId)return"calendar";if("issue_event"===a)return"issue";if("email_notification"===a)return"email";if("calendar_event"===a)return"calendar";let s=t.toLowerCase();return s.startsWith("issue ")||s.startsWith("issue:")?"issue":s.includes("email")?"email":"calendar"}function u(e){return e.slice().sort((e,t)=>{let a=e.created_at.localeCompare(t.created_at);return 0!==a?a:e.id.localeCompare(t.id)})}function m(e,t){let a=new Map;for(let t of e)a.set(t.id,t);for(let e of t)a.set(e.id,e);return u([...a.values()])}function f(e){if("artifact"===e.kind)return"agent";if("message"!==e.kind)return null;let t=e.data.role;return"user"===t?"user":"assistant"===t||"event"===t?"agent":null}function h(e){return e.data.created_at}function p(e){let t=Array(e.length).fill(null),a=(e,t)=>{if(!e||!t)return!1;let a=f(e),s=f(t);if(null===a||a!==s)return!1;let r=h(e),n=h(t);return!r||!n||6e4>Math.abs(new Date(r).getTime()-new Date(n).getTime())};for(let s=0;s<e.length;s++){let r=e[s];if(null===f(r))continue;let n=s>0?e[s-1]:null,l=s<e.length-1?e[s+1]:null,i=a(n,r),o=a(r,l);i&&o?t[s]="middle":i&&!o?t[s]="last":!i&&o?t[s]="first":t[s]="solo"}return t}function g(e,t,a,s){if(!s||0===a.length){let s=[...e.map(e=>({kind:"message",data:e})),...t.map(e=>({kind:"artifact",data:e})),...a.map(e=>({kind:"nap",data:e}))];return s.sort((e,t)=>{let a=e.data.created_at.localeCompare(t.data.created_at);if(0!==a)return a;if("nap"===e.kind||"nap"===t.kind){if("nap"===e.kind&&"nap"!==t.kind)return 1;if("nap"!==e.kind&&"nap"===t.kind)return -1}return e.kind!==t.kind?"message"===e.kind?-1:1:e.data.id.localeCompare(t.data.id)}),s}let r=new Set(a.map(e=>e.id.replace(/^nap-/,""))),n=[...a].sort((e,t)=>e.created_at.localeCompare(t.created_at)),l=a=>[...e.filter(e=>e.conversation_id===a).map(e=>({kind:"message",data:e})),...t.filter(e=>e.conversation_id===a).map(e=>({kind:"artifact",data:e}))].sort((e,t)=>{let a=e.data.created_at.localeCompare(t.data.created_at);return 0!==a?a:e.kind!==t.kind?"message"===e.kind?-1:1:e.data.id.localeCompare(t.data.id)}),i=[];for(let e of n){let t=e.id.replace(/^nap-/,"");i.push(...l(t)),i.push({kind:"nap",data:e})}i.push(...l(s));let o=new Set([...r,s]),c=e.filter(e=>!o.has(e.conversation_id)),d=t.filter(e=>!o.has(e.conversation_id));if(c.length>0||d.length>0){let e=[...c.map(e=>({kind:"message",data:e})),...d.map(e=>({kind:"artifact",data:e}))];e.sort((e,t)=>{let a=e.data.created_at.localeCompare(t.data.created_at);return 0!==a?a:e.kind!==t.kind?"message"===e.kind?-1:1:e.data.id.localeCompare(t.data.id)});let t=i.findIndex(e=>"nap"===e.kind);t>=0?i.splice(t,0,...e):i.push(...e)}return i}function x(e){return!e}function v(e){let{task:t,agentId:a,activeChannel:s,currentPointerConvId:r}=e;return t.agent_id!==a||(t.channel??"default")!==s||t.conversation_id===r?null:t.conversation_id}function b(e){let t=(0,a.useRef)(e);return(0,a.useEffect)(()=>{t.current=e},[e]),t}e.s(["TaskStream",0,c],817988),e.s(["buildTimeline",0,g,"computeGroupPositions",0,p,"eventTypeFromMessage",0,d,"mergeMessages",0,m,"pointerRefreshTargetForTaskCreated",0,v,"shouldPersistPointerForLoad",0,x,"sortMessages",0,u,"useLatest",0,b],144516);var k=e.i(419412);let y=(0,k.default)("bed-double",[["path",{d:"M2 20v-8a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v8",key:"1k78r4"}],["path",{d:"M4 10V6a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v4",key:"fb3tl2"}],["path",{d:"M12 4v6",key:"1dcgq2"}],["path",{d:"M2 18h20",key:"ajqnye"}]]);e.s(["BedDouble",0,y],865145);let j=(0,k.default)("message-square-quote",[["path",{d:"M14 14a2 2 0 0 0 2-2V8h-2",key:"1r06pg"}],["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}],["path",{d:"M8 14a2 2 0 0 0 2-2V8H8",key:"1jzu5j"}]]);e.s(["MessageSquareQuote",0,j],350780);var w=e.i(280115),N=e.i(222862),_=e.i(275351),C=e.i(516266),S=e.i(364079),I=e.i(205189);e.s(["useAgentChat",0,function(e,t){let{agentId:s,targetConvId:r,scrollToTaskId:n,scrollToMessageId:l,propTargetConvId:i,workspaceId:o,agents:c,activeChannel:d,channelLoading:f,subscribeWs:h,subscribeReconnect:k,refreshInboxCount:y}=e,{setFlaggedIds:j,setPendingFiles:M,setInput:T,setQuotedMessage:A,setActiveSkill:E,clearActiveSkill:R,inputRef:z,quotedMessageRef:L,pendingFilesRef:P,activeSkillRef:U,draftMetaRestoredRef:$}=t,[D,F]=(0,a.useState)(null),[O,q]=(0,a.useState)([]),B=(0,a.useRef)([]);B.current=O;let[W,H]=(0,a.useState)(!1),[V,K]=(0,a.useState)(null),[Q,X]=(0,a.useState)([]),[G,Y]=(0,a.useState)(!0),[J,Z]=(0,a.useState)(!1),[ee,et]=(0,a.useState)(!1),[ea,es]=(0,a.useState)(!1),[er,en]=(0,a.useState)([]);(0,a.useRef)(er).current=er;let el=(0,a.useCallback)(e=>{en(t=>{let a="function"==typeof e?e(t):e;return a===t||a.length===t.length&&a.every((e,a)=>e.id===t[a].id&&e.has_thumbnail===t[a].has_thumbnail)?t:a})},[]),[ei,eo]=(0,a.useState)([]),[ec,ed]=(0,a.useState)(!1),[eu,em]=(0,a.useState)([]),[ef,eh]=(0,a.useState)(()=>new Map),[ep,eg]=(0,a.useState)(()=>new Map),[ex,ev]=(0,a.useState)(()=>new Map),{writeToCache:eb}=function(e,t){let[s,r]=(0,a.useState)(null),[n,l]=(0,a.useState)(!1),i=(0,a.useRef)(e);return(0,a.useEffect)(()=>{if(i.current=e,!e||!t){r(null),l(!1);return}(0,_.openCacheDB)(t);let a=!1;return(0,_.getCachedMessages)(e,t).then(t=>{a||i.current!==e||(t&&t.length>0?(r(t),l(!0)):(r(null),l(!1)))}),()=>{a=!0}},[e,t]),{cachedMessages:s,isFromCache:n,writeToCache:(0,a.useCallback)(async(e,a,s)=>{i.current&&t&&await (0,_.mergeCachedMessages)(i.current,e,a,t,s)},[t])}}(r??null,o),ek=(0,a.useRef)(eb);(0,a.useEffect)(()=>{ek.current=eb},[eb]);let ey=(0,a.useRef)(!1);(0,a.useEffect)(()=>{D&&!ey.current&&(ey.current=!0,(0,I.trackAgentChatOpened)({agent_id:s,is_first_chat:0===O.length}))},[D,s]);let ej=(0,a.useMemo)(()=>er.filter(e=>"agent"===e.source),[er]),ew=(0,a.useMemo)(()=>g(O,ej,eu,D?.id),[O,ej,eu,D?.id]),eN=(0,a.useMemo)(()=>p(ew),[ew]),e_=(0,a.useMemo)(()=>{if(!V)return null;for(let e=O.length-1;e>=0;e--){let t=O[e];if("assistant"===t.role&&t.task_id===V.id)return t.id}return null},[O,V]),eC=(0,a.useRef)(null),eS=(0,a.useRef)(null),eI=(0,a.useRef)(null),eM=(0,a.useRef)(null),eT=(0,a.useRef)(0),eA=(0,a.useRef)(0),eE=(0,a.useRef)(!1),eR=(0,a.useRef)(!1),ez=(0,a.useRef)(!0),eL=(0,a.useRef)(!1),eP=(0,a.useRef)(null),eU=(0,a.useRef)(null),e$=(0,a.useRef)(0),eD=(0,a.useRef)(void 0),eF=(0,a.useRef)(null),eO=(0,a.useRef)({completedKey:null}),eq=(0,a.useRef)(null),eB=(0,a.useCallback)((e,t)=>{eF.current===e&&(0,_.getConvExtras)(e,o).then(a=>{if(a&&eF.current===e)return(0,_.setConvExtras)(e,{artifacts:t,conversation_type:a.conversation_type,conversation_title:a.conversation_title,conversation_channel:a.conversation_channel,conversation_created_at:a.conversation_created_at,hasMoreArtifacts:a.hasMoreArtifacts},o)}).catch(()=>{})},[o]),eW=(0,a.useCallback)(()=>{ez.current=!0,setTimeout(()=>{eC.current?.scrollTo({top:eC.current.scrollHeight,behavior:"smooth"})},50)},[]),eH=(0,a.useCallback)((e,t)=>{let a=e.filter(e=>e.content_type.startsWith("image/")&&e.has_thumbnail).map(e=>(0,S.getArtifactThumbnailUrl)(e.id,o)),s=new Set(e.map(e=>e.id));Promise.all(a.map(function(e){return new Promise(t=>{let a=new window.Image;a.onload=()=>t(),a.onerror=()=>t(),a.src=e})})).then(()=>{eh(e=>{if(0===e.size)return e;let t=B.current,a=new Map(e),r=!1;for(let[n,l]of e){let e=t.find(e=>e.id===n),i=e?.attachment_ids;if(i&&i.length>0&&i.every(e=>s.has(e))){for(let e of l)e.thumbnailUrl&&URL.revokeObjectURL(e.thumbnailUrl);a.delete(n),r=!0}}return r?a:e})})},[o]);(0,a.useEffect)(()=>{var e,t;if(!r&&f)return;let a=(e={workspaceId:o,agentId:s,targetConvId:r,scrollToTaskId:n}).targetConvId?`${e.workspaceId}::${e.agentId}::${e.targetConvId}::${e.scrollToTaskId??""}`:null;if(t=eO.current,a&&t.completedKey===a||(t.completedKey=null,0))return;eS.current&&clearInterval(eS.current),eS.current=null,eM.current=null,eF.current=null;let l=!1;Y(!0),eE.current=!1,K(null),X([]),eh(e=>{for(let t of e.values())for(let e of t)e.thumbnailUrl&&URL.revokeObjectURL(e.thumbnailUrl);return new Map}),eg(new Map),ev(new Map),em([]),eo([]),ed(!1),eU.current=null,T(localStorage.getItem(`chat-draft:${s}:${r??"default"}`)??"");let i=localStorage.getItem(`chat-draft-meta:${s}:${r??"default"}`);if(i)try{let e=JSON.parse(i),t=e.quote;A(t&&"object"==typeof t&&t.id?t:null),E(e.skill?e.skill:null)}catch{A(null),E(null)}else A(null),E(null);async function c(e){let t=await (0,_.getCacheMeta)(e,o);if(t?.newestMessageId){let a=await (0,_.getCachedMessages)(e,o);if(l)return{painted:!1,cacheMeta:t};if(a&&a.length>0)return q(a),et(t.hasMore),Y(!1),await u(e,a),{painted:!0,cacheMeta:t}}return{painted:!1,cacheMeta:t}}async function u(e,t){let a=await (0,_.getConvExtras)(e,o);if(l||!a)return;el(a.artifacts);let r=a.conversation_created_at||t[0]?.created_at||t[t.length-1]?.created_at||"";F(t=>t&&t.id===e?t:{id:e,agent_id:s,title:a.conversation_title,type:a.conversation_type,channel:a.conversation_channel,created_at:r})}return $.current=!0,q([]),async function(){let e=!1;try{let t=null,a=null,i=null;if(r){t=r;let s=await c(t);if(l)return;a=s.cacheMeta,e=s.painted}else{let r=await (0,_.getLastOpenConversation)(s,d,o);if(l)return;if(r?.conversation_id&&r.serverMessageCount>0){let t=await c(r.conversation_id);if(l)return;t.painted&&(e=!0,i=r.conversation_id,a=t.cacheMeta)}try{let r=await (0,N.checkFreshness)({agentId:s,channel:d},o);if(l)return;if(t=r.conversation_id,i&&t!==i){eE.current=!1,ez.current=!0;let s=await c(t);if(l)return;a=s.cacheMeta,e=s.painted,s.painted||(q([]),Y(!0),el([]))}else if(!i){let s=await c(t);if(l)return;a=s.cacheMeta,e=s.painted}}catch{}}if(t){eF.current=t;let i=await (0,N.conversationInit)(t,o,{newestMessageId:a?.newestMessageId??void 0,messageCount:a?.serverMessageCount||void 0});if(l)return;if(F(i.conversation),ed(i.has_more_conversations),!i.cache_valid&&i.messages){let a=ez.current;q(e=>m(e,i.messages)),eF.current===t&&(0,_.mergeCachedMessages)(t,i.messages,i.has_more_messages,o,i.message_count).catch(()=>{}),et(i.has_more_messages),e&&eE.current&&a&&eW()}else a&&et(a.hasMore);if(eF.current===t&&x(r)){let e=await (0,_.getCacheMeta)(t,o);if(l)return;(0,_.setLastOpenConversation)(s,d,{conversation_id:t,newestMessageId:e?.newestMessageId??a?.newestMessageId??null,serverMessageCount:i.message_count},o).catch(()=>{})}if(el(i.artifacts),eF.current===t&&(0,_.setConvExtras)(t,{artifacts:i.artifacts,conversation_type:i.conversation.type,conversation_title:i.conversation.title,conversation_channel:i.conversation.channel,conversation_created_at:i.conversation.created_at,hasMoreArtifacts:i.has_more_artifacts},o).catch(()=>{}),j(new Set(i.flagged_message_ids)),i.active_task&&(K(i.active_task),X(i.task_messages),i.task_messages.length>0&&(eT.current=Math.max(...i.task_messages.map(e=>e.seq))),eP.current?.(i.active_task.id,t,eT.current)),n){let e=await (0,N.getTask)(n,o).catch(()=>null);if(l)return;if(e&&!["completed","failed","cancelled","superseded"].includes(e.status)){K(e);let a=await (0,N.getTaskMessages)(n,o).catch(()=>[]);if(l)return;let s=a.filter(e=>"error"===e.type);X(s),a.length>0&&(eT.current=Math.max(...a.map(e=>e.seq))),eP.current?.(e.id,t,eT.current)}}}else{let t=await (0,N.chatInit)(s,o,d);if(l)return;eF.current=t.conversation.id,F(t.conversation);let a=ez.current;q(e=>e.length>0?m(e,t.messages):t.messages),et(t.has_more_messages),el(t.artifacts),ed(t.has_more_conversations),(0,_.mergeCachedMessages)(t.conversation.id,t.messages,t.has_more_messages,o).catch(()=>{}),eF.current===t.conversation.id&&(0,_.setConvExtras)(t.conversation.id,{artifacts:t.artifacts,conversation_type:t.conversation.type,conversation_title:t.conversation.title,conversation_channel:t.conversation.channel,conversation_created_at:t.conversation.created_at,hasMoreArtifacts:t.has_more_artifacts},o).catch(()=>{}),(0,_.setLastOpenConversation)(s,d,{conversation_id:t.conversation.id,newestMessageId:t.messages.length>0?t.messages[t.messages.length-1].id:null,serverMessageCount:t.has_more_messages?0:t.messages.length},o).catch(()=>{}),e&&eE.current&&a&&eW(),(0,N.listFlaggedMessageIds)(o,t.conversation.id).then(e=>{l||j(new Set(e.message_ids))}).catch(()=>{}),t.active_task&&(K(t.active_task),t.task_messages.length>0&&(X(t.task_messages),eT.current=Math.max(...t.task_messages.map(e=>e.seq))),["completed","failed","cancelled","superseded"].includes(t.active_task.status)||eP.current?.(t.active_task.id,t.conversation.id,eT.current))}}catch{e?C.toast.error("Couldn't refresh conversation"):C.toast.error("Failed to load conversation")}finally{if(!l){var t;Y(!1),t=eO.current,a&&(t.completedKey=a)}}}(),()=>{l=!0}},[s,o,r,n,d,f]);let eV=(0,a.useRef)(y);(0,a.useEffect)(()=>{eV.current=y},[y]);let eK=(0,a.useRef)(null);(0,a.useEffect)(()=>{if(!D?.id||!o||eK.current===D.id)return;eK.current=D.id;let e=setTimeout(()=>{(0,N.markInboxRead)(D.id,o).then(()=>eV.current()).catch(()=>{})},1e3);return()=>{eK.current=null,clearTimeout(e)}},[D?.id,o]),(0,a.useEffect)(()=>{G||!(O.length>0)||eE.current||(eE.current=!0,n||l?(ez.current=!1,eC.current?.scrollTo({top:eC.current.scrollHeight})):i?setTimeout(()=>{let e=eC.current?.querySelectorAll("[data-quote-source]");e&&e.length>0?e[e.length-1].scrollIntoView({behavior:"instant",block:"start"}):eC.current?.scrollTo({top:eC.current.scrollHeight})},50):setTimeout(()=>{eC.current?.scrollTo({top:eC.current.scrollHeight})},50))},[G,O.length,n,l,i]),(0,a.useEffect)(()=>{let e;if(!n||G||!D)return;ez.current=!1,eL.current=!0;let t=!1,a=()=>{if(t)return!1;let a=document.querySelector(`[data-task-id="${CSS.escape(n)}"]`);return!!a&&(a.scrollIntoView({behavior:"smooth",block:"center"}),a.classList.add("task-highlight"),e=setTimeout(()=>{a.classList.remove("task-highlight"),t||(eL.current=!1)},1500),!0)},s=setTimeout(async()=>{if(!t&&!a())try{let e=await (0,N.listMessagesAroundTask)(D.id,o,n);if(t)return;e.length>0?(q(t=>m(t,e)),requestAnimationFrame(()=>{setTimeout(()=>{a()||(eL.current=!1)},100)})):eL.current=!1}catch{t||(eL.current=!1)}},100);return()=>{t=!0,clearTimeout(s),e&&clearTimeout(e)}},[n,G,D,o]),(0,a.useEffect)(()=>{let e;if(!l||n||G||!D)return;ez.current=!1,eL.current=!0;let t=!1,a=setTimeout(()=>{!t&&((()=>{if(t)return!1;let a=document.querySelector(`[data-message-id="${CSS.escape(l)}"]`);return!!a&&(a.scrollIntoView({behavior:"smooth",block:"center"}),a.classList.add("task-highlight"),e=setTimeout(()=>{a.classList.remove("task-highlight"),t||(eL.current=!1)},1500),!0)})()||(eC.current?.scrollTo({top:eC.current.scrollHeight}),eL.current=!1))},100);return()=>{t=!0,clearTimeout(a),e&&clearTimeout(e)}},[l,n,G,D]);let eQ=V?.status;(0,a.useEffect)(()=>{eL.current||("running"===eQ||"queued"===eQ)&&ez.current&&eW()},[Q.length,eQ,eW]),(0,a.useEffect)(()=>{eL.current||eE.current&&ez.current&&eW()},[er.length,O.length,eW]);let eX=(0,a.useMemo)(()=>c.find(e=>e.id===s)?.name??"Agent",[c,s]),eG=b(O),eY=b(ee),eJ=b(ei),eZ=b(ec),e0=b(eX),e1=b(d),e2=(0,a.useCallback)(async(e=!1)=>{if(!D||eR.current)return;eR.current=!0;let t=eG.current,a=eY.current,n=eZ.current,l=e0.current,i=e1.current,c=!!r,d=t[0],u=eU.current?.id??D.id,m=a&&d,f=eJ.current;if(!c&&!m&&0===f.length&&n){let e=eU.current??{id:D.id,created_at:D.created_at};try{let t=await (0,N.listPreviousConversations)(s,o,{exclude:D.id,before:e.created_at,channel:i});f=t.conversations,eo(t.conversations),ed(t.has_more)}catch{ed(!1)}}let h=!c&&f.length>0;if(!m&&!h){eR.current=!1;return}es(!0);let p=eC.current;p&&(p.style.overflowAnchor="none");let g=p?.scrollHeight??0;try{let t=[],a=[],r=20,h=!1,x=[],v=!1;if(m){let e=u===D.id?await (0,_.getCachedMessagesBefore)(u,d.created_at,d.id,20,o):null;if(e)t=e.messages,r-=e.messages.length,h=e.hasMore;else{let e=await (0,N.listMessages)(u,o,{limit:20,before:d.created_at,beforeId:d.id});t=e.messages,r-=e.messages.length,h=e.has_more}v=h}if(!c&&!h&&r>0){if(0===f.length&&n){let e=eU.current??{id:D.id,created_at:D.created_at};try{let t=await (0,N.listPreviousConversations)(s,o,{exclude:D.id,before:e.created_at,channel:i});f=t.conversations,eo(t.conversations),ed(t.has_more)}catch{ed(!1)}}let e=0,t=0;for(;e<f.length&&r>0&&t<5;){let s=f[e];e++,t++;let n=await (0,N.listMessages)(s.id,o,{limit:r});if(0===n.messages.length){eU.current=s;continue}let i=eU.current?.created_at??D.created_at;x.push({agentName:l,created_at:i,id:`nap-${s.id}`}),a=[...n.messages,...a],r-=n.messages.length,h=n.has_more,eU.current=s}e>0&&eo(t=>t.slice(e))}let b=[...a,...t];if((0,w.flushSync)(()=>{b.length>0?(x.length>0&&em(e=>{let t=new Set(e.map(e=>e.id)),a=x.filter(e=>!t.has(e.id));return[...e,...a]}),et(h),q(e=>{let t=new Set(e.map(e=>e.id));return[...b.filter(e=>!t.has(e.id)),...e]})):et(!1)}),b.length>0&&D){let e=b.filter(e=>e.conversation_id===D.id);e.length>0&&(0,_.mergeCachedMessages)(D.id,e,v,o).catch(()=>{})}if(eR.current=!1,(0,w.flushSync)(()=>es(!1)),p)if(e)p.scrollTop=p.scrollHeight;else{let e=p.scrollHeight;p.scrollTop=e-g}}catch{C.toast.error("Failed to load older messages")}finally{eR.current=!1,es(!1),eC.current&&(eC.current.style.overflowAnchor="")}},[D,o,s,r,eG,eY,eZ,e0,e1,eJ]),e5=r?ee:ee||ei.length>0||ec;(0,a.useEffect)(()=>{D?.id!==eD.current&&(eD.current=D?.id,e$.current=0)},[D?.id]),(0,a.useEffect)(()=>{G||!D||n||r||O.length>=10||!e5||ea||e$.current>=3||(e$.current+=1,e2(!0))},[G,O.length,e5,ea,D,e2,n,r]);let e3=(0,a.useCallback)(()=>{let e=eC.current;e&&(ez.current=e.scrollHeight-e.scrollTop-e.clientHeight<100)},[]),e4=(0,a.useCallback)((e,t,a)=>{eS.current&&clearInterval(eS.current),eT.current=a??0,eA.current=0,Z(!1),eM.current=e,eS.current=setInterval(async()=>{if(eM.current===e)try{let a=await (0,N.getTask)(e,o),s=eM.current!==e;if(eA.current=0,Z(!1),"completed"===a.status||"failed"===a.status||"cancelled"===a.status||"superseded"===a.status){if(s)return void(0,N.listMessages)(t,o).then(({messages:e})=>{q(t=>m(t,e)),(0,_.mergeCachedMessages)(t,e,null,o).catch(()=>{})}).catch(()=>{});eS.current&&clearInterval(eS.current),eS.current=null,eI.current&&clearTimeout(eI.current),eI.current=setTimeout(()=>{(0,N.markInboxRead)(t,o).then(()=>eV.current()).catch(()=>{})},1e3);let r=!eL.current&&ez.current;try{let[e,s]=await Promise.all([(0,N.listMessages)(t,o),(0,N.listArtifacts)(t,o).catch(()=>null)]);q(t=>m(t,e.messages)),(0,_.mergeCachedMessages)(t,e.messages,null,o).catch(()=>{}),s&&(el(s),eB(t,s),eH(s,t)),K(a)}catch{K(a),C.toast.error("Failed to refresh messages")}r&&requestAnimationFrame(()=>{eC.current?.scrollTo({top:eC.current.scrollHeight,behavior:"smooth"})}),setTimeout(async()=>{if(!eS.current)try{let a=await (0,N.getActiveTask)(t,o);if(a&&a.id!==e){let{messages:e}=await (0,N.listMessages)(t,o);q(t=>m(t,e)),(0,_.mergeCachedMessages)(t,e,null,o).catch(()=>{}),K(a),X([]),eP.current?.(a.id,t)}}catch{}},1e3)}else s||K(a)}catch{if(eM.current!==e)return;eA.current+=1,eA.current>=3&&Z(!0),eA.current>=10&&(eS.current&&clearInterval(eS.current),eS.current=null,C.toast.error("Lost connection to agent"))}},3e3)},[o]);(0,a.useEffect)(()=>{eP.current=e4},[e4]),(0,a.useEffect)(()=>()=>{eS.current&&clearInterval(eS.current),eI.current&&clearTimeout(eI.current)},[]);let e8=(0,a.useRef)(null);(0,a.useEffect)(()=>{e8.current=V?.id??null},[V]),(0,a.useEffect)(()=>h(e=>{if("task.messages"===e.type&&e.taskId===e8.current){let t=e.messages.filter(e=>e.seq>eT.current);if(t.length>0){let e=t.filter(e=>"error"===e.type);e.length>0&&X(t=>{let a=new Set(t.map(e=>e.seq)),s=e.filter(e=>!a.has(e.seq));return s.length>0?[...t,...s]:t}),eT.current=Math.max(...t.map(e=>e.seq),eT.current)}}if("task.created"===e.type&&e.conversationId===D?.id){(0,N.listMessages)(e.conversationId,o).then(({messages:t})=>{q(e=>m(e,t)),(0,_.mergeCachedMessages)(e.conversationId,t,null,o).catch(()=>{})}).catch(()=>{});let t=e.task;e8.current=t.id,K(t),X([]),eT.current=0,eP.current?.(t.id,e.conversationId)}if("task.created"===e.type){let t=e.task,a=e1.current;(0,_.getLastOpenConversation)(s,a,o).then(e=>{let r=v({task:t,agentId:s,activeChannel:a,currentPointerConvId:e?.conversation_id??null});if(r)return(0,_.getCacheMeta)(r,o).then(e=>(0,_.setLastOpenConversation)(s,a,{conversation_id:r,newestMessageId:e?.newestMessageId??null,serverMessageCount:e?.messageCount??0},o))}).catch(()=>{})}if("conversation.message"===e.type&&(e.conversationId===eF.current&&(0,_.appendCachedMessage)(e.conversationId,e.message,o).catch(()=>{}),e.conversationId===D?.id)){let t=new Date(e.message.created_at).getTime(),a=eG.current.find(a=>a.id.startsWith("temp-")&&a.role===e.message.role&&a.content===e.message.content&&2e3>Math.abs(new Date(a.created_at).getTime()-t));a&&(eh(t=>{if(!t.has(a.id))return t;let s=t.get(a.id),r=new Map(t);return r.delete(a.id),r.set(e.message.id,s),r}),ev(t=>{if(t.has(e.message.id))return t;let s=new Map(t);return s.set(e.message.id,a.id),s})),q(t=>{if(a){let s=t.findIndex(e=>e.id===a.id);if(-1!==s){let a=[...t];return a[s]=e.message,a}}return m(t,[e.message])})}"task.updated"===e.type&&e.taskId===e8.current&&K(t=>t?{...t,status:e.status}:t),"artifact.uploaded"===e.type&&e.conversationId===D?.id&&el(t=>{if(t.some(t=>t.id===e.artifact.id))return t;let a=[...t,e.artifact];return eB(e.conversationId,a),a})}),[h,D?.id,o,s,eB]),(0,a.useEffect)(()=>k(()=>{D?.id&&(0,_.getCacheMeta)(D.id,o).then(e=>{(0,N.conversationInit)(D.id,o,{newestMessageId:e?.newestMessageId??void 0,messageCount:e?.serverMessageCount??void 0}).then(e=>{!e.cache_valid&&e.messages&&(q(t=>m(t,e.messages)),ek.current(e.messages,e.has_more_messages,e.message_count).catch(()=>{}))}).catch(()=>{})})}),[k,D?.id,o]);let e6=async()=>{let e=z.current.trim();if(!e&&0===P.current.length||W||!D)return;if(!e)return void C.toast.error("Please type a message");let t=e,a=L.current;U.current&&(t=`/${U.current.name} ${t}`);let r=[...P.current],n=r.map(e=>({...e,thumbnailUrl:e.thumbnailBlob?URL.createObjectURL(e.thumbnailBlob):null}));(0,I.trackMessageSent)({agent_id:s,message_length:t.length}),T(""),M([]),A(null),R(),H(!0);let l=`temp-${Date.now()}`,i={id:l,conversation_id:D.id,role:"user",content:t,task_id:null,attachment_ids:null,...a?{metadata:{quote:{messageId:a.id,excerpt:a.excerpt}}}:{},created_at:new Date().toISOString()};n.length>0&&eh(e=>{let t=new Map(e);return t.set(l,n),t}),q(e=>[...e,i]),eW();try{let{message:e,task:s}=await (0,N.sendMessage)(D.id,t,o,r.length>0?r:void 0,a?{quote:{messageId:a.id,excerpt:a.excerpt}}:void 0);eh(t=>{if(!t.has(l))return t;let a=t.get(l),s=new Map(t);return s.delete(l),s.set(e.id,a),s}),ev(t=>{let a=new Map(t);return a.set(e.id,l),a}),q(t=>{if(!t.some(e=>e.id===i.id))return t.some(t=>t.id===e.id)?t:u([...t,e]);let a=t.filter(t=>t.id!==i.id&&t.id!==e.id);return u([...a,e])}),(0,_.appendCachedMessage)(D.id,e,o).catch(()=>{}),e.attachment_ids&&e.attachment_ids.length>0&&(0,N.listArtifacts)(D.id,o).then(e=>{el(e),eB(D.id,e),eH(e,D.id)}).catch(()=>{}),K(s),X([]),e4(s.id,D.id)}catch{eg(e=>{let a=new Map(e);return a.set(l,{content:t,files:n}),a})}finally{H(!1),eq.current?.focus()}},e7=(0,a.useCallback)(e=>{let t=ep.get(e);if(!t||!D||W)return;eg(t=>{let a=new Map(t);return a.delete(e),a}),q(t=>t.filter(t=>t.id!==e)),eh(t=>{if(!t.has(e))return t;let a=new Map(t);return a.delete(e),a}),H(!0);let a=`temp-${Date.now()}`,s={id:a,conversation_id:D.id,role:"user",content:t.content,task_id:null,attachment_ids:null,created_at:new Date().toISOString()};t.files.length>0&&eh(e=>{let s=new Map(e);return s.set(a,t.files),s}),q(e=>[...e,s]),(0,N.sendMessage)(D.id,t.content,o,t.files.length>0?t.files:void 0).then(({message:e,task:t})=>{eh(t=>{if(!t.has(a))return t;let s=t.get(a),r=new Map(t);return r.delete(a),r.set(e.id,s),r}),ev(t=>{let s=new Map(t);return s.set(e.id,a),s}),q(t=>u([...t.filter(t=>t.id!==a&&t.id!==e.id),e])),(0,_.appendCachedMessage)(D.id,e,o).catch(()=>{}),e.attachment_ids&&e.attachment_ids.length>0&&(0,N.listArtifacts)(D.id,o).then(e=>{el(e),eB(D.id,e),eH(e,D.id)}).catch(()=>{}),K(t),X([]),e4(t.id,D.id)}).catch(()=>{eg(e=>{let s=new Map(e);return s.set(a,t),s})}).finally(()=>{H(!1)})},[ep,D,W,o,e4]),e9=(0,a.useCallback)(async()=>{if(!V||!D)return;let e=await (0,N.retryTask)(V.id,o);K(e),X([]),e4(e.id,D.id)},[V,D,o,e4]),[te,tt]=(0,a.useState)(!1),ta=(0,a.useMemo)(()=>!!D&&O.some(e=>e.conversation_id===D.id),[D,O]),ts=async()=>{if(D&&ta&&!te){tt(!0);try{eS.current&&(clearInterval(eS.current),eS.current=null);let e=await (0,N.createConversation)(s,o,d);em(t=>[...t,{agentName:eX,created_at:e.created_at,id:`nap-${D.id}`}]),eo(e=>[{id:D.id,created_at:D.created_at},...e]),F(e),K(null),X([]),el([]),M([]),eh(e=>{for(let t of e.values())for(let e of t)e.thumbnailUrl&&URL.revokeObjectURL(e.thumbnailUrl);return new Map}),eg(new Map),ev(new Map),eT.current=0,Z(!1),et(!1),eU.current=null,eW()}catch{C.toast.error("Failed to start new conversation")}finally{tt(!1)}}};return{conversation:D,messages:O,sending:W,activeTask:V,taskMessages:Q,messagesLoading:G,connectionLost:J,hasMore:ee,loadingMore:ea,artifacts:er,previousConversations:ei,hasMoreConversations:ec,napMarkers:eu,napping:te,pendingFilesByMessage:ef,failedSends:ep,stableKeyMap:ex,agentArtifacts:ej,agentName:eX,timeline:ew,groupPositions:eN,activeTaskStreamMsgId:e_,canLoadMore:e5,currentConvHasMessages:ta,scrollRef:eC,composerRef:eq,loadOlderMessages:e2,handleScroll:e3,handleSend:e6,handleRetrySend:e7,handleRetryTask:e9,handleNap:ts,scrollToBottom:eW}}],158571);var M=e.i(74348);async function T(e){let t;if(!e.type.startsWith("image/")||"image/svg+xml"===e.type)return null;try{var a,s,r;t=URL.createObjectURL(e);let n=await (a=t,new Promise((e,t)=>{let s=new Image;s.onload=()=>e(s),s.onerror=t,s.src=a})),{w:l,h:i}=function(e,t){if(e<=200&&t<=200)return{w:e,h:t};let a=Math.min(200/e,200/t);return{w:Math.round(e*a),h:Math.round(t*a)}}(n.naturalWidth,n.naturalHeight),o=document.createElement("canvas");o.width=l,o.height=i;let c=o.getContext("2d");if(!c)return null;return c.drawImage(n,0,0,l,i),await (s=o,r="image/jpeg",new Promise(e=>s.toBlob(e,r,.7)))}catch{return null}finally{t&&URL.revokeObjectURL(t)}}function A(e){for(let t of e)t.thumbnailUrl&&URL.revokeObjectURL(t.thumbnailUrl)}e.s(["useMessageFlags",0,function(e){let[t,s]=(0,a.useState)(new Set),r=(0,a.useRef)(t);(0,a.useEffect)(()=>{r.current=t});let{increment:n,decrement:l,refresh:i}=(0,M.useFlagCount)(),o=(0,a.useCallback)(async t=>{let a=r.current.has(t);s(e=>{let s=new Set(e);return a?s.delete(t):s.add(t),s}),a?(l(),(0,N.unflagMessage)(e,t).then(()=>{i()}).catch(()=>{s(e=>new Set(e).add(t)),n()})):(n(),(0,N.flagMessage)(e,t).then(()=>{i()}).catch(()=>{s(e=>{let a=new Set(e);return a.delete(t),a}),l()}))},[e,n,l,i]);return{flaggedIds:t,setFlaggedIds:s,handleToggleFlag:o}}],802634),e.s(["useChatSheets",0,function(e){let[t,s]=(0,a.useState)(!1),[r,n]=(0,a.useState)(null),[l,i]=(0,a.useState)(!1),[o,c]=(0,a.useState)(null),[d,u]=(0,a.useState)(!1),[m,f]=(0,a.useState)(null),[h,p]=(0,a.useState)(!1),[g,x]=(0,a.useState)(null),[v,b]=(0,a.useState)(null),[k,y]=(0,a.useState)(!1),[j,w]=(0,a.useState)(null),[_,S]=(0,a.useState)(null),I=(0,a.useCallback)(async t=>{x(t),p(!0),y(!0),w(null),S(null);try{let a=await (0,N.getIssue)(e,t);b(a),a.issue.latest_task_id&&(0,N.getTask)(a.issue.latest_task_id,e).then(e=>S(e)).catch(()=>S(null)),a.issue.trace_id&&(0,N.getTrace)(a.issue.trace_id,e).then(e=>w(e.tasks)).catch(()=>w(null))}catch(e){C.toast.error(e instanceof Error?e.message:"Failed to load issue"),p(!1)}finally{y(!1)}},[e]),M=v?.issue?.conversation_id??null,T=v?.issue?.latest_task_id??null;return{artifactSheetOpen:t,setArtifactSheetOpen:s,selectedArtifact:r,setSelectedArtifact:n,emailSheetOpen:l,setEmailSheetOpen:i,selectedEmailId:o,setSelectedEmailId:c,calendarEventSheetOpen:d,setCalendarEventSheetOpen:u,selectedCalendarEventId:m,setSelectedCalendarEventId:f,issueSheetOpen:h,setIssueSheetOpen:p,selectedIssueId:g,setSelectedIssueId:x,issueDetail:v,setIssueDetail:b,issueDetailLoading:k,issueTraceTasks:j,issueActiveTask:_,setIssueActiveTask:S,openIssue:I,issueConvId:M,issueTaskId:T}}],431884),e.s(["useFileAttachments",0,function(){let[e,t]=(0,a.useState)([]),s=(0,a.useRef)(e);s.current=e;let r=(0,a.useCallback)(e=>{t(t=>{let a="function"==typeof e?e(t):e;return 0===a.length&&t.length>0&&A(t),a})},[]);(0,a.useEffect)(()=>()=>A(s.current),[]);let n=(0,a.useRef)(null),l=(0,a.useCallback)(async e=>{let a=[];for(let t of e)t.size>0xa00000?C.toast.error(`"${t.name}" exceeds 10 MB limit`):a.push(t);if(0===a.length)return;let s=await Promise.all(a.map(async e=>{let t=await T(e);return{file:e,thumbnailUrl:t?URL.createObjectURL(t):null,thumbnailBlob:t}}));t(e=>[...e,...s])},[]),i=(0,a.useCallback)(e=>{let t=e.target.files;t&&(l(Array.from(t)),e.target.value="")},[l]),o=(0,a.useCallback)(e=>{t(t=>{let a=t[e];return a?.thumbnailUrl&&URL.revokeObjectURL(a.thumbnailUrl),t.filter((t,a)=>a!==e)})},[]),[c,d]=(0,a.useState)(!1),u=(0,a.useRef)(0),m=(0,a.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),u.current++,e.dataTransfer.types.includes("Files")&&d(!0)},[]),f=(0,a.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),u.current--,0===u.current&&d(!1)},[]),h=(0,a.useCallback)(e=>{e.preventDefault(),e.stopPropagation()},[]),p=(0,a.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),d(!1),u.current=0,l(Array.from(e.dataTransfer.files))},[l]);return{pendingFiles:e,setPendingFiles:r,fileInputRef:n,addPendingFiles:l,handleFileSelect:i,removePendingFile:o,dragging:c,handleDragEnter:m,handleDragLeave:f,handleDragOver:h,handleDrop:p}}],184526),e.s(["useTextSelectionQuote",0,function(){let[e,t]=(0,a.useState)(null),s=(0,a.useCallback)(()=>{let e=window.getSelection();if(!e||e.isCollapsed||!e.rangeCount)return void t(null);let a=e.toString().trim();if(!a)return void t(null);let s=e.getRangeAt(0),r=s.commonAncestorContainer instanceof HTMLElement?s.commonAncestorContainer:s.commonAncestorContainer.parentElement,n=r?.closest("[data-quote-source]");if(!n)return void t(null);let l=n.closest("[data-message-id]"),i=l?.getAttribute("data-message-id")??null,o=s.getClientRects(),c=o[o.length-1]||s.getBoundingClientRect();t({text:a,messageId:i,x:c.right,y:c.top-4})},[]);return(0,a.useEffect)(()=>(document.addEventListener("selectionchange",s),()=>document.removeEventListener("selectionchange",s)),[s]),{selectionPopup:e,setSelectionPopup:t}}],773652),e.s(["useSlashCommand",0,function({input:e,caretIndex:t,skills:s,onInputChange:r,initialActiveSkill:n,getAnchorPos:l,onAfterSelect:i}){let[o,c]=(0,a.useState)(!1),[d,u]=(0,a.useState)(""),[m,f]=(0,a.useState)(0),[h,p]=(0,a.useState)({top:0,left:0}),g=(0,a.useRef)(null),x=(0,a.useMemo)(()=>{if(!o)return[];if(!d)return s;let e=d.toLowerCase(),t=[],a=[];for(let r of s){let s=r.name.toLowerCase();s.startsWith(e)?t.push(r):s.includes(e)&&a.push(r)}return[...t,...a]},[o,d,s]);(0,a.useEffect)(()=>{f(0)},[x.length,d]);let[v,b]=(0,a.useState)(n??null);(0,a.useEffect)(()=>{if(v||null===t)return void c(!1);let a=function(e,t){if(!e.startsWith("/")||0===t)return null;let a=t-1;for(;a>=0&&t-a<=30;){let s=e.charCodeAt(a);if(47===s&&0===a)return{start:0,query:e.slice(1,t)};if(10===s||13===s||32===s)break;a--}return null}(e,t);if(a){g.current=a.start,u(a.query),c(!0);let e=l(a.start);e&&p(e)}else c(!1),g.current=null},[e,t,l,v]);let k=(0,a.useCallback)(e=>{b(e),r(""),c(!1),i?.()},[r,i]),y=(0,a.useCallback)(()=>{b(null)},[]),j=(0,a.useCallback)(e=>!!o&&0!==x.length&&!e.isComposing&&("ArrowDown"===e.key?(e.preventDefault(),f(e=>(e+1)%x.length),!0):"ArrowUp"===e.key?(e.preventDefault(),f(e=>(e-1+x.length)%x.length),!0):"Enter"===e.key||"Tab"===e.key?(e.preventDefault(),k(x[m]),!0):"Escape"===e.key&&(e.preventDefault(),c(!1),!0)),[o,x,m,k]);return{isOpen:o,query:d,selectedIndex:m,anchorPos:h,skills:x,activeSkill:v,handleSlashKeyDown:j,selectSkill:k,clearActiveSkill:y,setActiveSkill:b}}],505175);var E=e.i(613349);function R({skill:e,isSelected:a,onSelect:s}){return(0,t.jsxs)("button",{type:"button","data-slash-item":!0,className:(0,E.cn)("flex w-full flex-col gap-0.5 px-3 py-1.5 text-left text-sm transition-colors",a?"bg-accent text-accent-foreground":"hover:bg-accent/50"),onMouseDown:t=>{t.preventDefault(),s(e)},children:[(0,t.jsxs)("span",{className:"flex w-full items-center gap-2",children:[(0,t.jsxs)("span",{className:"min-w-0 flex-1 truncate font-medium",children:["/",e.name]}),e.isGlobal&&(0,t.jsx)("span",{className:"shrink-0 rounded px-1 py-0.5 text-[10px] font-medium bg-muted text-muted-foreground",children:"Global"})]}),e.description&&(0,t.jsx)("span",{className:"truncate text-xs text-muted-foreground",children:e.description.slice(0,80)})]})}e.s(["SlashCommandPopup",0,function({isOpen:e,skills:s,selectedIndex:r,onSelect:n,anchorPos:l}){let i=(0,a.useRef)(null);if((0,a.useEffect)(()=>{if(!i.current)return;let e=i.current.querySelectorAll("[data-slash-item]")[r];e?.scrollIntoView({block:"nearest"})},[r]),!e||0===s.length)return null;let o=Math.max(8,window.innerWidth-280-8),c=Math.min(l.left,o);return(0,w.createPortal)((0,t.jsx)("div",{className:"fixed z-100 w-70 rounded-lg border border-border bg-popover text-popover-foreground shadow-md transition-opacity duration-150",style:{top:l.top-4,left:c,transform:"translateY(-100%)"},children:(0,t.jsx)("div",{ref:i,className:"max-h-60 overflow-y-auto py-1 thin-scrollbar",children:s.map((e,a)=>(0,t.jsx)(R,{skill:e,isSelected:a===r,onSelect:n},e.name))})}),document.body)}],684565);var z=e.i(720115),L=e.i(941693),P=e.i(37476),U=e.i(251383);function $(e,t){if(!t)return e;let a=t.toLowerCase(),s=[],r=[];for(let t of e){let e=t.name.toLowerCase();e.startsWith(a)?s.push(t):e.includes(a)&&r.push(t)}return[...s,...r]}var D=e.i(8973);function F(e){return e.replaceAll("<","<").replaceAll(">",">").replaceAll("&","&")}e.i(954194);var O=e.i(439769);let q={items:[],selectedIndex:0,command:null,rect:null};function B({state:e}){let s=(0,a.useRef)(null),{items:r,selectedIndex:n,command:l,rect:i}=e;if((0,a.useEffect)(()=>{if(!s.current)return;let e=s.current.children[n];e?.scrollIntoView({block:"nearest"})},[n]),!i||0===r.length||!l)return null;let o=Math.max(8,window.innerWidth-256-8),c=Math.min(i.left,o);return(0,w.createPortal)((0,t.jsx)("div",{className:"fixed z-100 w-64 rounded-lg border border-border bg-popover text-popover-foreground shadow-md",style:{top:i.top-4,left:c,transform:"translateY(-100%)"},children:(0,t.jsx)("div",{ref:s,className:"max-h-50 overflow-y-auto py-1 thin-scrollbar",children:r.map((e,a)=>(0,t.jsxs)("button",{type:"button",className:(0,E.cn)("flex w-full items-center gap-2 px-3 py-1.5 text-left text-sm transition-colors",a===n?"bg-accent text-accent-foreground":"hover:bg-accent/50"),onMouseDown:t=>{t.preventDefault(),l({id:e.id,label:e.name})},children:[(0,t.jsx)("span",{className:"truncate font-medium",children:e.name}),e.email_handle&&(0,t.jsx)("span",{className:"truncate text-xs text-muted-foreground",children:(0,O.toAlookAddress)(e.email_handle)})]},e.id))})}),document.body)}let W=(0,a.forwardRef)(function({value:e,onChange:s,onEditorState:r,onSend:n,onFocus:l,onBlur:i,overlay:o,disabled:c,onMultiLineChange:d,onFiles:u,agents:m,agentLinks:f,currentAgentId:h,slashIsOpen:p,onSlashKeyDown:g},x){let[v,b]=(0,a.useState)(!1),[k,y]=(0,a.useState)(q),j=(0,a.useRef)(k);(0,a.useEffect)(()=>{j.current=k},[k]);let w=(0,a.useRef)(m),N=(0,a.useRef)(f),_=(0,a.useRef)(h),C=(0,a.useRef)(n),S=(0,a.useRef)(r),I=(0,a.useRef)(s),M=(0,a.useRef)(u),T=(0,a.useRef)(l),A=(0,a.useRef)(i),E=(0,a.useRef)(p),R=(0,a.useRef)(g);(0,a.useEffect)(()=>{w.current=m},[m]),(0,a.useEffect)(()=>{N.current=f},[f]),(0,a.useEffect)(()=>{_.current=h},[h]),(0,a.useEffect)(()=>{C.current=n},[n]),(0,a.useEffect)(()=>{S.current=r},[r]),(0,a.useEffect)(()=>{I.current=s},[s]),(0,a.useEffect)(()=>{M.current=u},[u]),(0,a.useEffect)(()=>{T.current=l},[l]),(0,a.useEffect)(()=>{A.current=i},[i]),(0,a.useEffect)(()=>{E.current=p},[p]),(0,a.useEffect)(()=>{R.current=g},[g]);let O=e=>{S.current(e.getText(),e.state.selection.from-1)},[W]=(0,a.useState)(()=>D.default.extend({markdownName:"mention",renderMarkdown:e=>`@${e.attrs.label??e.attrs.id}`}).configure({HTMLAttributes:{class:"mention-highlight"},renderText:({node:e})=>`@${e.attrs.label??e.attrs.id}`,suggestion:{char:"@",items:({query:e})=>(function(e,t,a,s,r=20){let n=function(e,t){let a=new Set;for(let s of e)s.source_agent_id===t&&a.add(s.target_agent_id),s.target_agent_id===t&&a.add(s.source_agent_id);return a}(t,a),l=[],i=[];for(let t of e)n.has(t.id)?l.push(t):i.push(t);return[...$(l,s),...$(i,s)].slice(0,r)})(w.current,N.current,_.current,e),render:()=>({onStart:e=>{y({items:e.items??[],selectedIndex:0,command:e.command,rect:e.clientRect?.()??null})},onUpdate:e=>{y(t=>({items:e.items??[],selectedIndex:t.selectedIndex<(e.items?.length??0)?t.selectedIndex:0,command:e.command,rect:e.clientRect?.()??null}))},onKeyDown:({event:e})=>{if(e.isComposing)return!1;let t=j.current;if(0===t.items.length)return!1;if("ArrowDown"===e.key)return e.preventDefault(),y(e=>({...e,selectedIndex:(e.selectedIndex+1)%e.items.length})),!0;if("ArrowUp"===e.key)return e.preventDefault(),y(e=>({...e,selectedIndex:(e.selectedIndex-1+e.items.length)%e.items.length})),!0;if("Enter"===e.key){e.preventDefault();let a=t.items[t.selectedIndex];return a&&t.command&&t.command({id:a.id,label:a.name}),y(q),!0}return"Escape"===e.key&&(y(q),!0)},onExit:()=>y(q)})}})),H=(0,z.useEditor)({immediatelyRender:!1,content:e?e.replaceAll("\n","<br>"):void 0,editable:!c,extensions:[L.default.configure({heading:!1,blockquote:!1,codeBlock:!1,horizontalRule:!1,bold:!1,italic:!1,strike:!1,code:!1,link:!1,bulletList:!1,orderedList:!1,listItem:!1,listKeymap:!1}),P.default.configure({placeholder:""}),U.Markdown,W],editorProps:{attributes:{class:"outline-none",enterkeyhint:"send"},handleKeyDown:(e,t)=>(!(j.current.items.length>0)||null===j.current.command)&&(!!(E.current&&R.current({key:t.key,isComposing:t.isComposing,preventDefault:()=>t.preventDefault()}))||"Enter"===t.key&&!t.shiftKey&&!t.isComposing&&!E.current&&(t.preventDefault(),C.current(),!0)),handlePaste:(e,t)=>{let a=t.clipboardData?.items;if(!a)return!1;let s=[];for(let e=0;e<a.length;e++)if("file"===a[e].kind){let t=a[e].getAsFile();t&&s.push(t)}if(s.length>0)return t.preventDefault(),M.current?.(s),!0;let r=t.clipboardData?.getData("text/plain");return!!r&&(t.preventDefault(),e.dispatch(e.state.tr.insertText(r)),!0)},handleDrop:()=>!1},onFocus:()=>{b(!0),T.current?.()},onBlur:()=>{b(!1),A.current?.()},onUpdate:({editor:e})=>{I.current(F(e.getMarkdown())),O(e)},onSelectionUpdate:({editor:e})=>{O(e)}});(0,a.useEffect)(()=>{H?.setEditable(!c)},[H,c]),(0,a.useEffect)(()=>{if(!H)return;let t=(e||"").trim();t!==F(H.getMarkdown()||"").trim()&&(t?H.commands.setContent((e||"").replaceAll("\n","<br>"),{emitUpdate:!1}):H.commands.clearContent(),S.current(H.getText(),H.state.selection.from-1))},[e,H]);let V=(0,a.useRef)(null);return(0,a.useEffect)(()=>{if(!H||!d)return;let e=V.current?.querySelector(".ProseMirror");if(!e)return;let t=()=>d(e.scrollHeight>32);t();let a=new ResizeObserver(t);return a.observe(e),()=>a.disconnect()},[H,d]),(0,a.useEffect)(()=>{let e=function(e,t){let a=navigator.virtualKeyboard;if(!a)return null;a.overlaysContent=!0;let s=e()?.closest("[data-keyboard-offset]");if(!s)return null;let r=()=>{if(!t){s.style.transform="",s.removeAttribute("data-keyboard-active");return}let{height:e}=a.boundingRect;e>0?(s.style.transform=`translateY(-${e}px)`,s.setAttribute("data-keyboard-active","")):(s.style.transform="",s.removeAttribute("data-keyboard-active"))};return a.addEventListener("geometrychange",r),()=>{a.removeEventListener("geometrychange",r),s.style.transform="",s.removeAttribute("data-keyboard-active"),a.overlaysContent=!1}}(()=>V.current,v);return e||(function(e,t){let a,s=window.visualViewport;if(!s)return null;let{handler:r,cleanup:n}={handler:()=>{t&&(clearTimeout(a),a=setTimeout(()=>{let t=e();if(!t)return;let a=window.visualViewport;if(!a)return void t.scrollIntoView({block:"end",behavior:"smooth"});let s=window.innerHeight-a.height,r=t.closest("[data-keyboard-offset]");if(r&&s>0){let e=r.getBoundingClientRect().bottom-a.height-a.offsetTop;e>0?(r.style.transform=`translateY(-${e}px)`,r.setAttribute("data-keyboard-active","")):(r.style.transform="",r.removeAttribute("data-keyboard-active"))}else r?(r.style.transform="",r.removeAttribute("data-keyboard-active")):t.scrollIntoView({block:"end",behavior:"smooth"})},150))},cleanup:()=>{clearTimeout(a);let t=e();if(!t)return;let s=t.closest("[data-keyboard-offset]");s&&(s.style.transform="",s.removeAttribute("data-keyboard-active"))}};return s.addEventListener("resize",r),s.addEventListener("scroll",r),()=>{s.removeEventListener("resize",r),s.removeEventListener("scroll",r),n()}}(()=>V.current,v)??void 0)},[V,v]),(0,a.useImperativeHandle)(x,()=>({focus:()=>H?.commands.focus(),clear:()=>H?.commands.clearContent(),isEmpty:()=>H?.isEmpty??!0,coordsAtTextIndex:e=>{if(!H)return null;try{let t=H.view.coordsAtPos(e+1);return{top:t.top,left:t.left}}catch{return null}}}),[H]),(0,t.jsxs)("div",{ref:V,className:"chat-composer relative",children:[(0,t.jsx)(z.EditorContent,{editor:H,className:"max-h-44 overflow-y-auto thin-scrollbar pr-2 text-base chat-input-line-height"}),o,(0,t.jsx)(B,{state:k})]})});e.s(["ChatComposer",0,W,"RotatingPlaceholderOverlay",0,function({hint:e,animate:s}){let[r,n]=(0,a.useState)(e),[l,i]=(0,a.useState)(!0);return(0,a.useEffect)(()=>{if(!s){n(e),i(!0);return}if(e===r)return;i(!1);let t=setTimeout(()=>{n(e),i(!0)},200);return()=>clearTimeout(t)},[e,r,s]),(0,t.jsx)("div",{className:"chat-placeholder-overlay","aria-hidden":"true",children:(0,t.jsx)("span",{className:s?"chat-placeholder-fade":void 0,style:s?{opacity:+!!l}:void 0,children:r})})}],648365);let H=["Email the team this week's launch update","Recruit a QA agent to review my PRs","Remind me to follow up with Acme on Thursday","What did we ship last week?","Fix the failing test in the checkout flow"];e.s(["useRotatingPlaceholder",0,function(e){var t;let s=function(){let[e,t]=(0,a.useState)(!1);return(0,a.useEffect)(()=>{if(!window.matchMedia)return;let e=window.matchMedia("(prefers-reduced-motion: reduce)");t(e.matches);let a=e=>t(e.matches);return e.addEventListener("change",a),()=>e.removeEventListener("change",a)},[]),e}(),[r,n]=(0,a.useState)(()=>(function(e,t=Math.random){return e<=0?0:Math.floor(t()*e)%e})(H.length)),l=(t={...e,reducedMotion:s}).isEmpty&&!t.isFocused&&!t.isTaskActive&&!t.reducedMotion,i=(0,a.useRef)(r);return i.current=r,(0,a.useEffect)(()=>{if(!l)return;let e=setInterval(()=>{var e,t;n((e=i.current,(t=H.length)<=0?0:(e+1)%t))},6e3);return()=>clearInterval(e)},[l]),{hint:H[r]??H[0],isRotating:l}}],360315);var V=e.i(288329),K=e.i(332680),Q=e.i(186339),X=e.i(692670),G=e.i(896210),Y=e.i(966662),J=e.i(492451),Z=e.i(940931);e.s(["EmailEventSheet",0,function({open:e,onOpenChange:s,emailId:r,workspaceId:l}){let[i,o]=(0,a.useState)(null),[c,d]=(0,a.useState)(null),[u,m]=(0,a.useState)(!1),{width:f,onPointerDown:h,onPointerMove:p,onPointerUp:g}=(0,V.useSheetResize)({defaultWidth:500,minWidth:320,maxWidthRatio:.8}),x=(0,a.useRef)(s);(0,a.useEffect)(()=>{x.current=s}),(0,a.useEffect)(()=>{e&&r&&(m(!0),o(null),d(null),Promise.all([(0,N.getEmail)(r,l),(0,N.getEmailBody)(r,l)]).then(([e,t])=>{o(e),d(t)}).catch(()=>{C.toast.error("Email not found"),x.current(!1)}).finally(()=>m(!1)))},[e,r,l]);let v=e=>{s(e),e||setTimeout(()=>{o(null),d(null)},300)};return(0,t.jsx)(K.Sheet,{open:e,onOpenChange:v,children:(0,t.jsxs)(K.SheetContent,{side:"right",showCloseButton:!1,style:{width:`min(${f}px, 100vw)`,maxWidth:"none"},className:"data-[side=right]:sm:inset-y-2 data-[side=right]:sm:right-2 data-[side=right]:sm:h-auto data-[side=right]:sm:rounded-xl data-[side=right]:sm:border",children:[(0,t.jsx)(V.SheetResizeHandle,{onPointerDown:h,onPointerMove:p,onPointerUp:g}),(0,t.jsx)(K.SheetHeader,{children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(G.Mail,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),(0,t.jsx)(K.SheetTitle,{className:"truncate flex-1",children:u?"Loading...":i?.subject||"Email"}),(0,t.jsx)(Q.Button,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>v(!1),children:(0,t.jsx)(X.X,{className:"h-4 w-4"})})]})}),(0,t.jsx)(K.SheetBody,{className:"flex-1 overflow-y-auto thin-scrollbar",children:u?(0,t.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,t.jsx)(n.Loader2,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):i?(0,t.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,t.jsxs)("div",{className:"text-sm space-y-1 border-b pb-3",children:[(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)("span",{className:"text-muted-foreground shrink-0",children:"From:"}),(0,t.jsx)("span",{className:"truncate",children:i.from_email})]}),(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)("span",{className:"text-muted-foreground shrink-0",children:"To:"}),(0,t.jsx)("span",{className:"truncate",children:i.to_email})]}),(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)("span",{className:"text-muted-foreground shrink-0",children:"Date:"}),(0,t.jsx)("span",{children:new Date(i.created_at).toLocaleString()})]})]}),c?.isHtml?(0,t.jsx)(Z.EmailBodyFrame,{html:c.content,className:"max-w-full"}):(0,t.jsx)("pre",{className:"whitespace-pre-wrap text-sm font-mono",children:c?.content}),i.attachments&&i.attachments.length>0&&(0,t.jsxs)("div",{className:"border-t pt-3",children:[(0,t.jsxs)("div",{className:"flex items-center gap-1.5 mb-2 text-xs text-muted-foreground",children:[(0,t.jsx)(Y.Paperclip,{className:"size-3"}),i.attachments.length," attachment",i.attachments.length>1?"s":""]}),(0,t.jsx)("div",{className:"flex flex-wrap gap-1.5",children:i.attachments.map((e,a)=>(0,t.jsxs)("a",{href:`/api/email/${i.id}/attachment/${a}?workspace_id=${l}`,target:"_blank",rel:"noopener noreferrer",download:e.filename,className:"flex items-center gap-1.5 rounded-md border border-border/50 bg-muted/50 px-2.5 py-1.5 text-xs hover:bg-muted transition-colors cursor-pointer",children:[(0,t.jsx)(J.File,{className:"size-3 text-muted-foreground shrink-0"}),(0,t.jsx)("span",{className:"truncate max-w-45",children:e.filename}),(0,t.jsx)("span",{className:"text-muted-foreground shrink-0",children:e.size<1024?`${e.size} B`:e.size<1048576?`${(e.size/1024).toFixed(1)} KB`:`${(e.size/1048576).toFixed(1)} MB`})]},e.key))})]})]}):null})]})})}],544346);var ee=e.i(933253);e.s(["ImageLightbox",0,function(e){let s,r,n,{open:l,onClose:i}=e,o=(0,a.useCallback)(e=>{"Escape"===e.key&&i()},[i]);if((0,a.useEffect)(()=>{if(l)return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[l,o]),e.imageUrl){if(!l)return null;s=e.imageUrl,r=e.filename}else{if(!l||!e.artifact)return null;s=(0,S.getArtifactUrl)(e.artifact.id,e.workspaceId),r=e.artifact.filename,n=(0,S.getArtifactUrl)(e.artifact.id,e.workspaceId,!0)}return(0,w.createPortal)((0,t.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-md animate-in fade-in duration-150",onClick:i,children:[(0,t.jsxs)("div",{className:"absolute top-4 right-4 flex items-center gap-2",children:[n&&(0,t.jsx)("a",{href:n,download:r,onClick:e=>e.stopPropagation(),className:"rounded-full p-2 text-white/70 hover:text-white hover:bg-white/10 transition-colors",children:(0,t.jsx)(ee.Download,{className:"size-5"})}),(0,t.jsx)("button",{type:"button",onClick:i,className:"rounded-full p-2 text-white/70 hover:text-white hover:bg-white/10 transition-colors",children:(0,t.jsx)(X.X,{className:"size-5"})})]}),(0,t.jsx)("img",{src:s,alt:r,onClick:e=>e.stopPropagation(),className:"max-w-[90vw] max-h-[90vh] object-contain rounded-lg"})]}),document.body)}],204799);var et=e.i(329686);e.i(68322);var ea=e.i(522281),es=e.i(418277),er=e.i(742204);function en(e,t){if(t>=e.length)return!0;let a=e.charCodeAt(t);return(!(a>=48)||!(a<=57))&&(!(a>=65)||!(a<=90))&&(!(a>=97)||!(a<=122))&&95!==a}function el(e,t){if(!e||0===t.length||!e.includes("@"))return e;let a=t.slice().sort((e,t)=>t.name.length-e.name.length),s=[];for(let t=0;t<e.length;t++){if("@"!==e[t]||!function(e,t){if(0===t)return!0;let a=e.charCodeAt(t-1);return(!(a>=48)||!(a<=57))&&(!(a>=65)||!(a<=90))&&(!(a>=97)||!(a<=122))&&95!==a}(e,t))continue;let r=t+1;for(let n of a){let a=r+n.name.length;if(a>e.length||e.slice(r,a).toLowerCase()!==n.name.toLowerCase())continue;let l=a,i=e.slice(a).match(/^ \([a-zA-Z0-9-]+@alook\.ai\)/);if(i&&(l=a+i[0].length),(i||en(e,a))&&(!i||en(e,l))){if(s.some(e=>t>=e.start&&t<e.end))break;s.push({start:t,end:a,name:n.name,agentId:n.id});break}}}let r=e;for(let e=s.length-1;e>=0;e--){let t=s[e],a=r.slice(t.start,t.end);r=r.slice(0,t.start)+`<mention data-agent-id="${t.agentId}">${a}</mention>`+r.slice(t.end)}return r}e.i(400175);var ei=e.i(819748),eo=e.i(80137);let ec=(0,k.default)("flag",[["path",{d:"M4 22V4a1 1 0 0 1 .4-.8A6 6 0 0 1 8 2c3 0 5 2 7.333 2q2 0 3.067-.8A1 1 0 0 1 20 4v10a1 1 0 0 1-.4.8A6 6 0 0 1 16 16c-3 0-5-2-8-2a6 6 0 0 0-4 1.528",key:"1jaruq"}]]);e.s(["Flag",0,ec],594518);var ed=e.i(330746),eu=e.i(353155),em=e.i(758956),ef=e.i(355753),ef=ef,eh=e.i(465368);let ep={"1day":"Daily","1week":"Weekly","1month":"Monthly"};function eg({title:e,scheduledAt:a,repeatInterval:s,onClick:r}){let n=a?new Date(a):null,l=n?n.toLocaleDateString("en-US",{weekday:"short"}):null,i=n?n.toLocaleDateString("en-US",{month:"short"}):null,o=n?n.getDate():null,c=n?n.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit"}):null;return(0,t.jsxs)("button",{type:"button",onClick:r,disabled:!r,className:"card-grain w-104 max-w-full overflow-hidden rounded-(--radius) border border-(--border) text-left cursor-pointer [transition:translate_.2s_cubic-bezier(.2,.8,.2,1),box-shadow_.2s_ease] hover:-translate-y-0.5 [box-shadow:var(--e1)] hover:[box-shadow:var(--e2)]",children:[(0,t.jsxs)("span",{className:"h-6 bg-(--tc) flex items-center px-3",children:[n?(0,t.jsxs)("span",{className:"text-[0.62rem] font-semibold uppercase tracking-[0.06em] text-white/85",children:[l," ",i," ",o]}):(0,t.jsx)("span",{className:"text-[0.62rem] font-semibold uppercase tracking-[0.06em] text-white/85",children:"Calendar"}),s&&(0,t.jsx)("span",{className:"ml-auto text-[0.52rem] font-semibold uppercase tracking-[0.04em] px-1 py-px rounded-full bg-white/20 text-white/90",children:function(e){if(ep[e])return ep[e];let t=/^(\d+)(hour|day|week|month)s?$/.exec(e);return t?`Every ${t[1]} ${t[2]}${Number(t[1])>1?"s":""}`:e}(s)})]}),(0,t.jsxs)("span",{className:"bg-(--paper) p-3 flex gap-3 items-start",children:[null!=o&&(0,t.jsx)("span",{className:"text-[1.8rem] font-bold leading-none tracking-[-0.02em] opacity-80 min-w-8 text-center shrink-0",children:o}),(0,t.jsxs)("span",{className:"min-w-0 flex-1 flex flex-col",children:[(0,t.jsx)("span",{className:"text-[0.92rem] font-semibold tracking-[-0.01em] leading-[1.3]",children:e}),c&&(0,t.jsx)("span",{className:"text-[0.72rem] text-(--muted-foreground) mt-1 font-mono",children:c})]})]})]})}let ex={created:"Issue created",status_changed:"Issue updated",dispatch_failed:"Dispatch failed"};function ev({title:e,event:a,fromStatus:s,toStatus:r,assigneeName:n,onClick:l}){let i="created"===a?"New":"status_changed"===a?r??"Done":null,o="created"===a&&n?`assigned to ${n}`:"status_changed"===a&&s&&r?`${s} → ${r}`:null;return(0,t.jsxs)("button",{type:"button",onClick:l,disabled:!l,className:"card-grain w-104 max-w-full overflow-hidden rounded-(--radius) border border-(--border) bg-(--paper) text-left flex cursor-pointer [transition:translate_.2s_cubic-bezier(.2,.8,.2,1),box-shadow_.2s_ease] hover:-translate-y-0.5 [box-shadow:var(--e1)] hover:[box-shadow:var(--e2)]",children:[(0,t.jsx)("span",{className:"w-1 bg-(--ti) shrink-0 self-stretch"}),(0,t.jsxs)("span",{className:"flex-1 p-3 min-w-0 flex flex-col gap-1 relative",children:[(0,t.jsx)("span",{className:"text-[0.62rem] font-semibold uppercase tracking-wider text-(--ti) leading-none",children:ex[a]??a}),(0,t.jsx)("span",{className:"text-[0.92rem] font-semibold tracking-[-0.01em] leading-[1.3] line-clamp-2 pr-8",children:e}),o&&(0,t.jsx)("span",{className:"text-[0.75rem] text-(--muted-foreground) leading-[1.2]",children:o}),i&&(0,t.jsx)("span",{className:"absolute top-3 right-3 text-[0.5rem] font-bold uppercase tracking-wider text-(--ti) border-[1.5px] border-(--ti) opacity-45 rotate-[4deg] rounded-[3px] px-1 py-0.5",children:i})]})]})}var eb=e.i(754902),ek=e.i(855351),ey=e.i(648632);let ej={mention:["data-agent-id"]},ew=["mention"];function eN(e){return"solo"===e?"single":e}function e_({attachmentIds:e,artifacts:a,onArtifactClick:s}){let r=e.map(e=>a.find(t=>t.id===e)).filter(e=>!!e).filter(e=>!e.content_type.startsWith("image/"));return 0===r.length?null:(0,t.jsx)("div",{className:"flex flex-wrap gap-1.5 mt-1.5",children:r.map(e=>(0,t.jsxs)("button",{type:"button",onClick:t=>{t.stopPropagation(),s(e)},className:"inline-flex items-center gap-1 rounded-md bg-primary-foreground/10 border border-primary-foreground/20 px-2 py-0.5 text-xs text-primary-foreground/80 hover:bg-primary-foreground/20 transition-colors cursor-pointer",children:[(0,t.jsx)(eo.FileText,{className:"size-3 shrink-0"}),(0,t.jsx)("span",{className:"truncate max-w-37.5",children:e.filename})]},e.id))})}function eC({attachmentIds:e,artifacts:a,workspaceId:s,onArtifactClick:r}){let n=e.map(e=>a.find(t=>t.id===e)).filter(e=>!!e&&e.content_type.startsWith("image/"));return 0===n.length?null:(0,t.jsx)("div",{className:"flex flex-wrap gap-1.5 mt-1.5",children:n.map(e=>{let a=e.has_thumbnail?(0,S.getArtifactThumbnailUrl)(e.id,s):void 0;return a?(0,t.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),r(e)},className:"max-w-48 overflow-hidden rounded-(--radius) border border-(--border) cursor-pointer [transition:translate_.2s_cubic-bezier(.2,.8,.2,1),box-shadow_.2s_ease] hover:-translate-y-0.5 [box-shadow:var(--e1)] hover:[box-shadow:var(--e2)]",children:(0,t.jsx)("img",{src:a,alt:e.filename,loading:"lazy",className:"block w-full h-auto"})},e.id):(0,t.jsxs)("button",{type:"button",onClick:t=>{t.stopPropagation(),r(e)},className:"inline-flex items-center gap-1 rounded-md bg-primary-foreground/10 border border-primary-foreground/20 px-2 py-0.5 text-xs text-primary-foreground/80 hover:bg-primary-foreground/20 transition-colors cursor-pointer",children:[(0,t.jsx)(ef.default,{className:"size-3 shrink-0"}),(0,t.jsx)("span",{className:"truncate max-w-37.5",children:e.filename})]},e.id)})})}function eS({groupPosition:e,agentName:a,config:s,forceSpacer:r=!1,children:n}){return(0,t.jsx)(ek.MessageCluster,{avatar:s?(0,t.jsx)(ei.AnimatedAvatar,{config:s,size:ek.AVATAR_SIZE,className:"rounded-md",isHovered:!1}):null,name:a,position:r?"middle":e,children:n})}function eI({actions:e}){return 0===e.length?null:(0,t.jsx)("div",{className:(0,E.cn)("absolute -top-3 right-0 z-10 flex items-center gap-0.5 rounded-lg border bg-card p-0.5 shadow-sm","opacity-0 transition-opacity duration-150 group-hover/msg:opacity-100 focus-within:opacity-100"),children:e.map(e=>(0,t.jsxs)(et.Tooltip,{children:[(0,t.jsx)(et.TooltipTrigger,{render:(0,t.jsx)(Q.Button,{variant:"ghost",size:"icon-xs","aria-label":e.label,onClick:t=>{t.stopPropagation(),e.onClick()},className:(0,E.cn)(e.active?"text-foreground":"text-muted-foreground")}),children:e.icon}),(0,t.jsx)(et.TooltipContent,{children:e.label})]},e.key))})}function eM({open:e,onOpenChange:a,actions:s}){return(0,t.jsx)(K.Sheet,{open:e,onOpenChange:a,children:(0,t.jsx)(K.SheetContent,{side:"bottom",showCloseButton:!1,className:"rounded-t-2xl p-2",children:(0,t.jsx)("div",{className:"flex flex-col",children:s.map(e=>(0,t.jsxs)("button",{type:"button",onClick:()=>{e.onClick(),a(!1)},className:(0,E.cn)("flex items-center gap-3 rounded-lg px-3 py-3 text-left text-[0.95rem] active:bg-muted",(e.active,"text-foreground")),children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:e.icon}),e.label]},e.key))})})})}function eT(){return(0,t.jsx)("span",{"aria-hidden":!0,className:"absolute -left-1.5 -top-1.5 z-10 flex size-3.5 items-center justify-center rounded-full border-2 border-background bg-foreground text-background",children:(0,t.jsx)(ec,{className:"size-2 fill-current"})})}function eA(){return(0,t.jsx)("span",{"aria-hidden":!0,className:"absolute -left-1.5 -top-1.5 z-10 flex size-3.5 items-center justify-center rounded-full border-2 border-background bg-foreground text-background",children:(0,t.jsx)(em.MessageSquare,{className:"size-2"})})}let eE=(0,a.memo)(function({msg:e,agents:s,artifacts:r,activeTask:n,activeTaskStreamMsgId:l,taskMessages:i,connectionLost:u,conversationType:m,pendingFilesByMessage:f,workspaceId:h,onArtifactClick:p,onEmailClick:g,onIssueClick:x,onCalendarEventClick:v,onRetry:b,mentionComponents:k,isFlagged:y,onToggleFlag:w,groupPosition:N="solo",provider:_,agentName:S,agentAvatarConfig:I,isSendFailed:M,onPendingImageClick:T,onRetrySend:A,onQuote:R,onReplyInThread:z,threadSummary:L,isThreadRoot:P,onAgentChatOpen:U}){var $;let D,F,q,B,W,{copy:H,copied:V}=function(e=2e3){let[t,s]=(0,a.useState)(!1),r=(0,a.useRef)(void 0),n=(0,a.useCallback)(async t=>{try{return await navigator.clipboard.writeText(t),s(!0),clearTimeout(r.current),r.current=setTimeout(()=>s(!1),e),!0}catch{return!1}},[e]);return(0,a.useEffect)(()=>()=>clearTimeout(r.current),[]),{copy:n,copied:t}}(),K=!!n&&"assistant"===e.role&&e.task_id===n.id&&e.conversation_id===n.conversation_id&&(null==l||e.id===l)&&i.length>0&&!["completed","cancelled","superseded"].includes(n.status),Q=K&&(i.some(e=>"error"===e.type)||"failed"===n.status&&!!n.error||u),X=K&&n?.status==="failed",G="assistant"===e.role&&(e.metadata?.kind==="lifecycle"||"Task cancelled by you"===e.content||"Task cancelled by user"===e.content),Y=function(){let[e,t]=a.useState(!0);return a.useEffect(()=>{if(!window.matchMedia)return;let e=window.matchMedia("(hover: hover) and (pointer: fine)"),a=()=>t(e.matches);return a(),e.addEventListener("change",a),()=>e.removeEventListener("change",a)},[]),e}(),[J,Z]=a.default.useState(!1),ee=a.default.useCallback(async()=>{await H(e.content)?C.toast.success("Copied to clipboard"):C.toast.error("Failed to copy")},[H,e.content]),et="assistant"===e.role||"user"===e.role,en=[];et&&en.push({key:"copy",label:V?"Copied":"Copy",icon:V?(0,t.jsx)(eu.Check,{className:"size-3.5"}):(0,t.jsx)(ed.Copy,{className:"size-3.5"}),onClick:ee}),R&&("assistant"===e.role||"user"===e.role)&&en.push({key:"quote",label:"Quote",icon:(0,t.jsx)(j,{className:"size-3.5"}),onClick:()=>R(e.id,e.content.slice(0,50))}),z&&("assistant"===e.role||"user"===e.role)&&en.push({key:"thread",label:"Reply in thread",icon:(0,t.jsx)(em.MessageSquare,{className:"size-3.5"}),onClick:()=>z(e.id)}),"assistant"===e.role&&w&&en.push({key:"flag",label:y?"Unflag":"Flag",icon:(0,t.jsx)(ec,{className:(0,E.cn)("size-3.5",y&&"fill-current")}),onClick:()=>w(e.id),active:y});let ei=(0,ey.useLongPress)(()=>{en.length>0&&Z(!0)}),ef=!Y&&en.length>0?ei:{},ep=!Y&&en.length>0?(0,t.jsx)(eM,{open:J,onOpenChange:Z,actions:en}):null,ex=Y&&en.length>0?(0,t.jsx)(eI,{actions:en}):null;return(0,t.jsxs)(a.default.Fragment,{children:[K&&Q&&(0,t.jsx)("div",{className:(0,E.cn)("group/msg",y&&"bg-muted/30 rounded-lg px-2 -mx-2"),...X?{"data-quote-source":!0}:{},children:(0,t.jsx)(eS,{groupPosition:N,agentName:S,config:I,children:(0,t.jsxs)("div",{className:"relative min-w-0 w-fit max-w-full",...X?ef:{},children:[(0,t.jsx)(c,{task:n,messages:i,connectionLost:u,onRetry:b,provider:_}),X&&ex,X&&ep]})})}),"user"===e.role?(D=e.content.match(/^\/(\S+)\s?([\s\S]*)$/),F=D?.[1]??null,q=D?D[2]||"":e.content,(0,t.jsxs)("div",{className:"group/msg flex flex-col items-end","data-message-id":e.id,...e.task_id?{"data-task-id":e.task_id}:{},children:[(B=e.metadata?.quote,(W=B?.messageId)?(0,t.jsxs)("button",{type:"button",onClick:()=>{let e=document.querySelector(`[data-message-id="${CSS.escape(W)}"]`);e?.scrollIntoView({behavior:"smooth",block:"center"})},className:"max-w-[50%] mb-0.5 flex items-center gap-1.5 rounded-lg bg-muted/60 px-2.5 py-1 text-left",children:[(0,t.jsx)(j,{className:"size-3 shrink-0 text-muted-foreground"}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground truncate",children:B.excerpt})]}):null),(0,t.jsxs)(eb.MessageBubble,{variant:"user",position:eN(N),className:(0,E.cn)("max-w-[80%] relative",M&&"opacity-60"),...ef,children:[F&&(0,t.jsxs)("span",{className:"inline-flex items-center rounded px-1.5 py-0.5 text-xs font-medium bg-primary-foreground/15 text-primary-foreground mb-1",children:["/",F]}),q&&(0,t.jsx)("div",{className:"markdown markdown-user",children:(0,t.jsx)(ea.Streamdown,{plugins:{mermaid:es.mermaid,cjk:er.cjk,math:es.math},controls:{code:{copy:!0,download:!1},table:{copy:!1,download:!1,fullscreen:!1}},linkSafety:{enabled:!1},allowedTags:ej,literalTagContent:ew,components:k,children:el(q,s)})}),(()=>{let a=f.get(e.id),s=a?.filter(e=>!e.thumbnailUrl);if(s&&s.length>0)return(0,t.jsx)("div",{className:"flex flex-wrap gap-1.5 mt-1.5",children:s.map((e,a)=>(0,t.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-md bg-primary-foreground/10 border border-primary-foreground/20 px-2 py-0.5 text-xs text-primary-foreground/80",children:[(0,t.jsx)(eo.FileText,{className:"size-3 shrink-0"}),(0,t.jsx)("span",{className:"truncate max-w-37.5",children:e.file.name})]},a))});let n=e.attachment_ids;if(n&&n.length>0){let e=n.map(e=>r.find(t=>t.id===e)).filter(e=>!!e).filter(e=>!e.content_type.startsWith("image/"));if(e.length>0)return(0,t.jsx)(e_,{attachmentIds:e.map(e=>e.id),artifacts:r,onArtifactClick:p})}return null})(),ex]}),(()=>{let a=f.get(e.id),s=a?.filter(e=>e.thumbnailUrl);if(s&&s.length>0)return(0,t.jsx)("div",{className:"flex flex-wrap gap-1.5 mt-1.5",children:s.map((e,a)=>(0,t.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),T?.(e.file)},className:"max-w-48 overflow-hidden rounded-(--radius) border border-(--border) cursor-pointer [transition:translate_.2s_cubic-bezier(.2,.8,.2,1),box-shadow_.2s_ease] hover:-translate-y-0.5 [box-shadow:var(--e1)] hover:[box-shadow:var(--e2)]",children:(0,t.jsx)("img",{src:e.thumbnailUrl,alt:e.file.name,className:"block w-full h-auto"})},a))});let n=e.attachment_ids;if(n&&n.length>0){let e=n.map(e=>r.find(t=>t.id===e)).filter(e=>!!e).filter(e=>e.content_type.startsWith("image/"));if(e.length>0)return(0,t.jsx)(eC,{attachmentIds:e.map(e=>e.id),artifacts:r,workspaceId:h,onArtifactClick:p})}return null})(),ep,M&&(0,t.jsx)("button",{type:"button",onClick:()=>A?.(e.id),className:"mt-1 px-1 text-xs text-destructive hover:underline",children:"Not delivered · tap to retry"}),L&&L.reply_count>0&&(0,t.jsxs)("button",{type:"button",onClick:()=>z?.(e.id),className:"flex items-center gap-1.5 pt-1 cursor-pointer hover:opacity-75 transition-opacity",children:[(0,t.jsxs)("span",{className:"text-[11px] font-semibold text-[oklch(0.72_0.19_145)]",children:[L.reply_count," ",1===L.reply_count?"reply":"replies"]}),L.last_reply_at&&(0,t.jsxs)("span",{className:"text-[10px] text-muted-foreground",children:["last reply ",new Date(L.last_reply_at).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]})]})]})):"event"===e.role?(()=>{let a,r=e.metadata?.emailId,n=e.metadata?.issueId,l=e.metadata?.calendarEventId,i=r?()=>g(r):n?()=>x(n):l?()=>v(l):void 0,o=function(e,t,a){let s=d(e,t,a);if("email"===s){if(e?.subject)return{type:"email",subject:e.subject,address:"inbound"===e.direction?e.from:e.to,direction:e.direction};let a=/^Email sent to (.+?): ([\s\S]+)$/.exec(t);if(a)return{type:"email",subject:a[2],address:a[1],direction:"outbound"};let s=/^New email from (.+?): ([\s\S]+)$/.exec(t);if(s)return{type:"email",subject:s[2],address:s[1],direction:"inbound"};let r=t.indexOf(": ");return{type:"email",subject:r>-1?t.slice(r+2):t,address:"",direction:"inbound"}}if("issue"===s){if(e?.event)return{type:"issue",title:e.title??t.replace(/^Issue (?:created|opened|status changed):?\s*/i,""),event:e.event,fromStatus:e.fromStatus,toStatus:e.toStatus,agentId:e.agentId};let a=/^Issue status changed: ([\s\S]+?) -> ([\s\S]+)$/.exec(t);if(a)return{type:"issue",title:`${a[1]} → ${a[2]}`,event:"status_changed",fromStatus:a[1],toStatus:a[2]};let s=/^Issue (?:created|opened): ([\s\S]+)$/.exec(t);return s?{type:"issue",title:s[1],event:"created"}:/dispatch failed/i.test(t)?{type:"issue",title:t.replace(/^Issue dispatch failed:?\s*/i,""),event:"dispatch_failed"}:{type:"issue",title:t.replace(/^Issue:?\s*/i,""),event:"created"}}return e?.title?{type:"calendar",title:e.title,scheduledAt:e.scheduledAt,repeatInterval:e.repeatInterval}:{type:"calendar",title:t.replace(/^Calendar event:\s*/i,"")}}(e.metadata,e.content,m);if("email"===o.type){let r=(0,O.parseEmailHandle)(o.address),n=e.metadata?.targetConversationId,l=e.metadata?.targetAgentId,c=!!r,d=null;if(c&&!Y&&n&&l&&U){let e=s.find(e=>e.email_handle===r)?.name;e&&(d={label:`View ${e}'s conversation`,onClick:()=>U(l,n)})}a=(0,t.jsx)(eh.EmailCard,{subject:o.subject,address:o.address,direction:o.direction,onClick:i,timestamp:e.created_at,...Y&&c?{isInternal:!0,internalHandle:r||void 0,targetConvId:n,targetAgentId:l,agents:s,onAgentChatOpen:U}:{},touchAction:d})}else a="calendar"===o.type?(0,t.jsx)(eg,{title:o.title,scheduledAt:o.scheduledAt,repeatInterval:o.repeatInterval,onClick:i}):(0,t.jsx)(ev,{title:o.title,event:o.event,fromStatus:o.fromStatus,toStatus:o.toStatus,assigneeName:o.agentId?s.find(e=>e.id===o.agentId)?.name:void 0,onClick:i});return(0,t.jsx)("div",{"data-message-id":e.id,...e.task_id?{"data-task-id":e.task_id}:{},children:(0,t.jsx)(eS,{groupPosition:N,agentName:S,config:I,children:a})})})():G&&e.metadata?.error_source!=="runtime"?(0,t.jsx)("div",{className:"flex justify-center","data-message-id":e.id,...e.task_id?{"data-task-id":e.task_id}:{},children:(0,t.jsx)("span",{className:"text-xs text-muted-foreground/70 text-center px-2 py-1",children:e.content})}):($={hasTaskStream:K,isRuntimeError:e.metadata?.error_source==="runtime"}).hasTaskStream&&$.isRuntimeError?null:(0,t.jsx)("div",{className:(0,E.cn)("group/msg overflow-x-clip",y&&e.metadata?.error_source==="runtime"&&"bg-muted/30 rounded-lg px-2 -mx-2"),"data-message-id":e.id,"data-quote-source":!0,...e.task_id?{"data-task-id":e.task_id}:{},children:(0,t.jsxs)(eS,{groupPosition:N,agentName:S,config:I,children:[e.metadata?.error_source==="runtime"?(0,t.jsxs)("div",{className:"relative min-w-0 w-fit max-w-full",...ef,children:[(0,t.jsx)(o,{provider:e.metadata.provider??_,message:e.content}),ex,ep]}):(0,t.jsxs)("div",{className:"relative min-w-0 w-fit max-w-full",...ef,children:[(0,t.jsx)(eb.MessageBubble,{variant:"agent",position:eN(N),className:(0,E.cn)("markdown min-w-0 max-w-full",(y||P)&&"shadow-[inset_2px_0_0_var(--foreground)]"),children:(0,t.jsx)(ea.Streamdown,{plugins:{mermaid:es.mermaid,cjk:er.cjk,math:es.math},controls:{code:{copy:!0,download:!1},table:{copy:!0,download:!1,fullscreen:!0}},linkSafety:{enabled:!1},allowedTags:ej,literalTagContent:ew,components:k,children:el(e.content,s)})}),y&&!P&&(0,t.jsx)(eT,{}),P&&(0,t.jsx)(eA,{}),ex,ep]}),L&&L.reply_count>0&&(0,t.jsxs)("button",{type:"button",onClick:()=>z?.(e.id),className:"flex items-center gap-1.5 pt-1 cursor-pointer hover:opacity-75 transition-opacity",children:[(0,t.jsxs)("span",{className:"text-[11px] font-semibold text-[oklch(0.72_0.19_145)]",children:[L.reply_count," ",1===L.reply_count?"reply":"replies"]}),L.last_reply_at&&(0,t.jsxs)("span",{className:"text-[10px] text-muted-foreground",children:["last reply ",new Date(L.last_reply_at).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]})]})]})})]})});e.s(["AgentRow",0,eS,"MessageItem",0,eE],378830)},49879,844010,e=>{"use strict";e.s(["AgentChatView",()=>er],49879);var t=e.i(653772),a=e.i(511043),s=e.i(126942),r=e.i(500324),n=e.i(186339),l=e.i(817988),i=e.i(222862),o=e.i(144516),c=e.i(355578),d=e.i(875494),u=e.i(872937),m=e.i(516266),f=e.i(613349),h=e.i(728886),p=e.i(329686),g=e.i(131890),x=e.i(865145),v=e.i(80137),b=e.i(945074),k=e.i(896210),y=e.i(350780),j=e.i(966662),w=e.i(267007),N=e.i(692670),_=e.i(158571),C=e.i(802634),S=e.i(431884),I=e.i(184526),M=e.i(773652),T=e.i(505175),A=e.i(684565),E=e.i(648365),R=e.i(360315),z=e.i(721387),L=e.i(544346),P=e.i(204799),U=e.i(781360),$=e.i(169678),D=e.i(364079),F=e.i(219658),O=e.i(378830),q=e.i(252304),B=e.i(157349);let W=(0,e.i(419412).default)("menu",[["path",{d:"M4 5h16",key:"1tepv9"}],["path",{d:"M4 12h16",key:"1lakjw"}],["path",{d:"M4 19h16",key:"1djgab"}]]);function H({open:e}){return(0,t.jsxs)("span",{className:"relative size-4",children:[(0,t.jsx)(W,{className:(0,f.cn)("size-4 absolute transition-all duration-200",e?"opacity-0 rotate-90 scale-75":"opacity-100 rotate-0 scale-100")}),(0,t.jsx)(N.X,{className:(0,f.cn)("size-4 absolute transition-all duration-200",e?"opacity-100 rotate-0 scale-100":"opacity-0 -rotate-90 scale-75")})]})}e.i(400175);var V=e.i(126366);e.i(954194);var K=e.i(439769),Q=e.i(353155),X=e.i(330746),G=e.i(819748),Y=e.i(309475);function J({agent:e,isOnline:s,activeTaskCount:r,variant:n="default",isHovered:l}){let[i,o]=(0,a.useState)(!1),c=e.email_handle?(0,K.toAlookAddress)(e.email_handle):null,d=(0,a.useCallback)(async()=>{if(c)try{await navigator.clipboard.writeText(c),o(!0),m.toast.success("Email copied to clipboard"),setTimeout(()=>o(!1),2e3)}catch{m.toast.error("Failed to copy email")}},[c]);if("compact"===n){let a;return(0,t.jsxs)("div",{className:"flex items-center gap-2 p-0",children:[(a=(0,V.parseAvatarUrl)(e.avatar_url))?(0,t.jsx)(G.AnimatedAvatar,{config:a,size:32,className:"shrink-0 rounded-xl",isHovered:l??!1,isWorking:!!s&&(r??0)>0}):(0,t.jsx)("div",{className:"flex items-center justify-center size-8 rounded-xl bg-secondary text-secondary-foreground text-xs font-medium shrink-0",children:e.name.charAt(0).toUpperCase()}),(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,t.jsx)("p",{className:"text-sm font-medium truncate max-w-35",children:e.name}),c&&(0,t.jsx)("span",{className:"text-xs text-muted-foreground truncate",children:c})]}),void 0!==s&&(0,t.jsx)("div",{className:"pointer-events-none mt-0.5",children:(0,t.jsx)(Y.AgentStatusBadge,{isOnline:s,taskCount:r??0,agentId:e.id})})]})]})}return(0,t.jsxs)("div",{className:"flex flex-col gap-1.5 p-1",children:[(0,t.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,t.jsx)("p",{className:"text-sm font-medium truncate",children:e.name}),(0,t.jsx)("span",{className:"flex-1"}),void 0!==s&&(0,t.jsxs)("span",{className:"inline-flex items-center gap-1 text-[11px] text-muted-foreground",children:[(0,t.jsx)("span",{className:(0,f.cn)("size-1.5 rounded-full",s?"bg-status-online":"bg-status-offline")}),s?(r??0)>0?"Working":null:"Offline"]})]}),c&&(0,t.jsxs)("div",{className:"flex items-center gap-1",children:[(0,t.jsx)("span",{className:"text-xs text-muted-foreground truncate",children:c}),(0,t.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),d()},className:"shrink-0 p-0.5 rounded-sm text-muted-foreground/60 hover:text-foreground transition-colors cursor-pointer",children:i?(0,t.jsx)(Q.Check,{className:"size-3 text-green-500"}):(0,t.jsx)(X.Copy,{className:"size-3"})})]}),e.description&&(0,t.jsx)("p",{className:"text-xs text-muted-foreground line-clamp-2",children:e.description})]})}e.s(["AgentPreviewCard",0,J],844010);var Z=e.i(224950);function ee({filename:e,size:a,contentType:s,version:r,hasDuplicates:n,onClick:l}){let i=function(e,t){let a=e.lastIndexOf(".");if(a>-1)return e.slice(a+1).toUpperCase();if(t){let e=t.split("/")[1];if(e)return e.split(";")[0].toUpperCase()}return"FILE"}(e,s);return(0,t.jsxs)("button",{type:"button",onClick:l,disabled:!l,className:"card-grain w-104 max-w-full overflow-hidden rounded-(--radius) border border-(--border) bg-(--paper) text-left grid grid-cols-[44px_1fr] cursor-pointer [transition:translate_.2s_cubic-bezier(.2,.8,.2,1),box-shadow_.2s_ease] hover:-translate-y-0.5 [box-shadow:var(--e1)] hover:[box-shadow:var(--e2)]",children:[(0,t.jsxs)("span",{className:"flex flex-col items-center justify-center border-r border-(--border) bg-[oklch(from_var(--tf)_l_c_h/0.08)] gap-0.5 p-2",children:[(0,t.jsxs)("span",{className:"flex flex-col gap-0.5 w-4.5",children:[(0,t.jsx)("i",{className:"h-[1.5px] rounded-sm bg-(--tf) opacity-[0.28] w-full"}),(0,t.jsx)("i",{className:"h-[1.5px] rounded-sm bg-(--tf) opacity-[0.28] w-[78%]"}),(0,t.jsx)("i",{className:"h-[1.5px] rounded-sm bg-(--tf) opacity-[0.28] w-[55%]"})]}),(0,t.jsx)("span",{className:"font-mono text-[0.44rem] font-semibold uppercase text-(--tf) mt-px tracking-[0.02em]",children:i})]}),(0,t.jsxs)("span",{className:"p-3 min-w-0 flex flex-col justify-center gap-0.5",children:[(0,t.jsxs)("span",{className:"flex items-center gap-1.5 min-w-0",children:[(0,t.jsx)("span",{className:"text-[0.9rem] font-semibold tracking-[-0.01em] truncate",children:e}),n&&null!=r&&(0,t.jsxs)("span",{className:"shrink-0 text-xs text-(--muted-foreground) bg-(--muted) rounded-full px-1.5 py-0.5 font-normal",children:["v",r]})]}),(0,t.jsx)("span",{className:"text-[0.7rem] text-(--muted-foreground) font-mono",children:(0,z.formatSize)(a)})]})]})}let et={mention:function(e){let{children:a,...s}=e,{agents:r}=(0,c.useAgentContext)(),n=s["data-agent-id"]??s.dataAgentId,l=n?r.find(e=>e.id===n):void 0;if(!l&&"string"==typeof a){let e=a.startsWith("@")?a.slice(1):a;l=r.find(t=>t.name.toLowerCase()===e.toLowerCase())}return l?(0,t.jsxs)(Z.Popover,{children:[(0,t.jsx)(Z.PopoverTrigger,{openOnHover:!0,delay:300,nativeButton:!1,render:(0,t.jsx)("span",{className:"mention-highlight cursor-pointer"}),children:a}),(0,t.jsx)(Z.PopoverContent,{side:"top",className:"w-fit max-w-80",children:(0,t.jsx)(J,{agent:l})})]}):(0,t.jsx)("span",{className:"mention-highlight",children:a})},p:({children:e,node:a,...s})=>(0,t.jsx)("div",{"data-md-p":"",...s,children:e})};function ea({agentName:e}){return(0,t.jsxs)("div",{className:"flex items-center gap-3 py-4 select-none","aria-hidden":!0,children:[(0,t.jsx)("div",{className:"flex-1 border-t border-border/40"}),(0,t.jsxs)("span",{className:"text-xs text-muted-foreground/60 whitespace-nowrap",children:[e," took a nap 💤"]}),(0,t.jsx)("div",{className:"flex-1 border-t border-border/40"})]})}function es({artifact:e,version:s,hasDuplicates:r,onClick:n,workspaceId:l}){let[i,o]=(0,a.useState)(!1),c=e.has_thumbnail?(0,D.getArtifactThumbnailUrl)(e.id,l):void 0;return c&&!i?(0,t.jsx)("button",{type:"button",onClick:()=>n(e),className:"max-w-64 overflow-hidden rounded-(--radius) border border-(--border) cursor-pointer [transition:translate_.2s_cubic-bezier(.2,.8,.2,1),box-shadow_.2s_ease] hover:-translate-y-0.5 [box-shadow:var(--e1)] hover:[box-shadow:var(--e2)]",children:(0,t.jsx)("img",{src:c,alt:e.filename,loading:"lazy",onError:()=>o(!0),className:"block w-full h-auto"})}):(0,t.jsx)(ee,{filename:e.filename,size:e.size,contentType:e.content_type??void 0,version:s,hasDuplicates:r,onClick:()=>n(e)})}function er({agentId:e,targetConvId:W,scrollToTaskId:K,scrollToMessageId:Q}){let X,G,Y,J,ee,en=(0,s.useParams)(),el=(0,s.useSearchParams)(),{workspaceId:ei,slug:eo}=(0,r.useWorkspace)(),{agents:ec,runtimes:ed,agentLinks:eu,activeTaskCounts:em,subscribeWs:ef,subscribeReconnect:eh}=(0,c.useAgentContext)(),{refresh:ep}=(0,d.useInboxCount)(),{activeChannel:eg,loading:ex,setAgentId:ev}=(0,u.useChannel)(),eb=e??en.id,ek=ec.find(e=>e.id===eb),ey=ek?.runtime_id?ed.find(e=>e.id===ek.runtime_id):null,ej=ey?.provider??null,ew=void 0!==K?K:el.get("task"),eN=void 0!==Q?Q:el.get("msg"),e_=void 0!==W?W:el.get("conv"),[eC,eS]=(0,a.useState)(()=>localStorage.getItem(`chat-draft:${eb}:${e_??"default"}`)??""),[eI,eM]=(0,a.useState)(!1),{artifactSheetOpen:eT,setArtifactSheetOpen:eA,selectedArtifact:eE,setSelectedArtifact:eR,emailSheetOpen:ez,setEmailSheetOpen:eL,selectedEmailId:eP,setSelectedEmailId:eU,calendarEventSheetOpen:e$,setCalendarEventSheetOpen:eD,selectedCalendarEventId:eF,setSelectedCalendarEventId:eO,issueSheetOpen:eq,setIssueSheetOpen:eB,selectedIssueId:eW,setSelectedIssueId:eH,issueDetail:eV,setIssueDetail:eK,issueDetailLoading:eQ,issueTraceTasks:eX,issueActiveTask:eG,setIssueActiveTask:eY,openIssue:eJ,issueConvId:eZ,issueTaskId:e0}=(0,S.useChatSheets)(ei),[e1,e2]=(0,a.useState)(null),[e5,e3]=(0,a.useState)(null),{pendingFiles:e4,setPendingFiles:e8,fileInputRef:e6,addPendingFiles:e7,handleFileSelect:e9,removePendingFile:te,dragging:tt,handleDragEnter:ta,handleDragLeave:ts,handleDragOver:tr,handleDrop:tn}=(0,I.useFileAttachments)(),[tl,ti]=(0,a.useState)(null),[to]=(0,a.useState)(()=>Date.now()),[tc,td]=(0,a.useState)(()=>{try{let e=JSON.parse(localStorage.getItem(`chat-draft-meta:${eb}:${e_??"default"}`)??"null"),t=e?.quote;return t&&"object"==typeof t&&t.id?t:null}catch{return null}}),[tu,tm]=(0,a.useState)(!1),{flaggedIds:tf,setFlaggedIds:th,handleToggleFlag:tp}=(0,C.useMessageFlags)(ei),{openAgentChat:tg}=(0,q.useAgentChatSheet)(),[tx,tv]=(0,a.useState)(new Map),[tb,tk]=(0,a.useState)(null);(0,a.useEffect)(()=>{ev(eb)},[eb,ev]);let ty=(0,a.useRef)(!1),tj=(0,o.useLatest)(eC),tw=(0,o.useLatest)(tc),tN=(0,o.useLatest)(e4),t_=(0,a.useRef)(null),tC=(0,a.useRef)(null),{conversation:tS,messages:tI,sending:tM,activeTask:tT,taskMessages:tA,messagesLoading:tE,connectionLost:tR,loadingMore:tz,artifacts:tL,napping:tP,pendingFilesByMessage:tU,failedSends:t$,stableKeyMap:tD,agentArtifacts:tF,agentName:tO,timeline:tq,groupPositions:tB,activeTaskStreamMsgId:tW,canLoadMore:tH,currentConvHasMessages:tV,scrollRef:tK,composerRef:tQ,loadOlderMessages:tX,handleScroll:tG,handleSend:tY,handleRetrySend:tJ,handleRetryTask:tZ,handleNap:t0}=(0,_.useAgentChat)({agentId:eb,targetConvId:e_,scrollToTaskId:ew,scrollToMessageId:eN,propTargetConvId:W,workspaceId:ei,agents:ec,activeChannel:eg,channelLoading:ex,subscribeWs:ef,subscribeReconnect:eh,refreshInboxCount:ep},{setFlaggedIds:th,setPendingFiles:e8,setInput:eS,setQuotedMessage:td,setActiveSkill:e=>tC.current?.setActiveSkill(e),clearActiveSkill:()=>tC.current?.clearActiveSkill(),inputRef:tj,quotedMessageRef:tw,pendingFilesRef:tN,activeSkillRef:t_,draftMetaRestoredRef:ty}),{versionMap:t1,duplicateFilenames:t2}=(0,a.useMemo)(()=>(0,D.computeArtifactVersions)(tF),[tF]);(0,a.useEffect)(()=>{tS?.parent_message_id&&ei?(0,i.conversationInit)(tS.id,ei).then(e=>{e.root_message&&tk(e.root_message)}).catch(()=>{}):tk(null)},[tS?.id,tS?.parent_message_id,ei]);let t5=(0,a.useCallback)(()=>{tS?.id&&ei&&(0,i.getThreadSummaries)(tS.id,ei).then(e=>{let t=new Map;for(let a of e.thread_summaries)t.set(a.parent_message_id,{thread_id:a.thread_id,reply_count:a.reply_count,last_reply_at:a.last_reply_at,thread_title:a.thread_title});tv(t)}).catch(()=>{})},[tS?.id,ei]);(0,a.useEffect)(()=>{t5()},[t5]),(0,a.useEffect)(()=>ef(e=>{("thread.created"===e.type||"thread.reply"===e.type)&&t5()}),[ef,t5]);let t3=(0,a.useMemo)(()=>(0,V.parseAvatarUrl)(ec.find(e=>e.id===eb)?.avatar_url??null),[ec,eb]),t4=(0,a.useMemo)(()=>tO.split(/\s+/)[0]||tO,[tO]),t8=(0,a.useCallback)(e=>{e3({url:URL.createObjectURL(e),filename:e.name})},[]),t6=(0,a.useCallback)(e=>{e.content_type.startsWith("image/")?e2(e):(0,D.isPreviewable)(e)?(eR(e),eA(!0)):window.open((0,D.getArtifactUrl)(e.id,ei,!0),"_blank")},[ei]),t7=(0,a.useCallback)(e=>{e.content_type.startsWith("image/")?e2(e):(0,D.isPreviewable)(e)?(eR(e),eA(!0)):window.open((0,D.getArtifactUrl)(e.id,ei,!0),"_blank")},[ei]),[t9,ae]=(0,a.useState)(""),at=(0,a.useMemo)(()=>ec.filter(e=>e.id!==eb),[ec,eb]),[aa,as]=(0,a.useState)([]),ar=(0,a.useRef)(!1);(0,a.useEffect)(()=>{ar.current||(ar.current=!0,(0,i.getAgentSkills)(eb,ei).then(e=>as(e.skills)).catch(()=>{}))},[eb,ei]);let[an]=(0,a.useState)(()=>{try{let e=JSON.parse(localStorage.getItem(`chat-draft-meta:${eb}:${e_??"default"}`)??"null");return e?.skill??null}catch{return null}}),al=(0,T.useSlashCommand)({input:t9,caretIndex:tl,skills:aa,onInputChange:()=>tQ.current?.clear(),initialActiveSkill:an,getAnchorPos:(0,a.useCallback)(e=>tQ.current?.coordsAtTextIndex(e)??null,[]),onAfterSelect:(0,a.useCallback)(()=>{requestAnimationFrame(()=>tQ.current?.focus())},[])});(0,a.useLayoutEffect)(()=>{tC.current=al,t_.current=al.activeSkill}),(0,a.useEffect)(()=>{0===aa.length||!al.activeSkill||aa.some(e=>e.name===al.activeSkill.name)||al.setActiveSkill(null)},[aa]),(0,a.useEffect)(()=>{let e=`chat-draft:${eb}:${e_??"default"}`;eC?localStorage.setItem(e,eC):localStorage.removeItem(e)},[eC,eb,e_]),(0,a.useEffect)(()=>{if(!ty.current)return;let e=`chat-draft-meta:${eb}:${e_??"default"}`,t={};al.activeSkill&&(t.skill={name:al.activeSkill.name,description:al.activeSkill.description}),tc&&(t.quote=tc),t.skill||t.quote?localStorage.setItem(e,JSON.stringify(t)):localStorage.removeItem(e)},[al.activeSkill,tc,eb,e_]),(0,a.useEffect)(()=>{tM||tQ.current?.focus()},[tM]);let{selectionPopup:ai,setSelectionPopup:ao}=(0,M.useTextSelectionQuote)(),ac=(0,a.useCallback)(()=>{if(ai){let e=ai.text.slice(0,100);td(ai.messageId?{id:ai.messageId,excerpt:e}:null),ao(null),window.getSelection()?.removeAllRanges(),tQ.current?.focus()}},[ai]),ad=(0,a.useCallback)((e,t)=>{td({id:e,excerpt:t}),tQ.current?.focus()},[]),au=(0,a.useCallback)(e=>{eU(e),eL(!0)},[]),am=(0,a.useCallback)(e=>{eO(e),eD(!0)},[]),af=(0,a.useCallback)(e=>{eJ(e)},[eJ]),ah=(0,a.useCallback)((e,t)=>{tg(e,{conversationId:t})},[tg]),ap=(0,o.useLatest)(tx),ag=(0,o.useLatest)(tS),ax=(0,o.useLatest)(t5),av=(0,a.useCallback)(async e=>{let t=ap.current.get(e);if(t?.thread_id)tg(eb,{conversationId:t.thread_id});else if(ag.current)try{let t=await (0,i.createThread)(ag.current.id,e,"",ei);tg(eb,{conversationId:t.conversation.id}),ax.current()}catch{}},[tg,eb,ei]);(0,a.useEffect)(()=>{if(eq&&eW)return ef(e=>{if("task.updated"===e.type&&e0&&e.taskId===e0&&(0,i.getTask)(e0,ei).then(e=>eY(e)).catch(()=>{}),"conversation.message"===e.type&&eZ&&e.conversationId===eZ&&(eK(t=>!t||t.messages.some(t=>t.id===e.message.id)?t:{...t,messages:[...t.messages,e.message]}),"event"===e.message.role&&e.message.content.startsWith("Issue status changed:"))){let t=e.message.content.match(/-> (\w+)/);t&&eK(e=>e?{...e,issue:{...e.issue,status:t[1]}}:e)}"issue.comment"===e.type&&e.issueId===eW&&eK(t=>!t||t.comments.some(t=>t.id===e.comment.id)?t:{...t,comments:[...t.comments,e.comment]})})},[eq,eW,eZ,e0,ei,ef]);let[ab,ak]=(0,a.useState)(!1),[ay,aj]=(0,a.useState)(!1),aw=!!tT&&!["completed","failed","cancelled","superseded"].includes(tT.status),aN=(0,a.useCallback)(async()=>{if(tS?.id&&!ay){aj(!0);try{await (0,i.cancelActiveTask)(tS.id,ei)}catch{m.toast.error("Failed to stop the task")}finally{aj(!1)}}},[tS?.id,ei,ay]),a_=(0,R.useRotatingPlaceholder)({isEmpty:""===eC.trim(),isFocused:eI,isTaskActive:aw});return tE?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"flex-1 overflow-y-auto px-3 md:px-5",children:(0,t.jsxs)("div",{className:"mx-auto max-w-3xl py-6 space-y-6 motion-safe:animate-[fade-up_200ms_ease-out_both]",children:[(0,t.jsxs)("div",{className:"flex justify-start items-start gap-2",children:[(0,t.jsx)(h.Skeleton,{className:"size-7.5 shrink-0 rounded-md"}),(0,t.jsxs)("div",{className:"flex flex-col items-start gap-1 max-w-[86%]",children:[(0,t.jsx)(h.Skeleton,{className:"h-3 w-20 rounded mb-0.5"}),(0,t.jsx)(h.Skeleton,{className:"h-9 w-64 rounded-[1.05rem]"}),(0,t.jsx)(h.Skeleton,{className:"h-9 w-48 rounded-[1.05rem]"})]})]}),(0,t.jsxs)("div",{className:"flex flex-col items-end gap-1",children:[(0,t.jsx)(h.Skeleton,{className:"h-9 w-44 rounded-[1.05rem]"}),(0,t.jsx)(h.Skeleton,{className:"h-9 w-32 rounded-[1.05rem]"})]}),(0,t.jsxs)("div",{className:"flex justify-start items-start gap-2",children:[(0,t.jsx)(h.Skeleton,{className:"size-7.5 shrink-0 rounded-md"}),(0,t.jsxs)("div",{className:"flex flex-col items-start gap-1 max-w-[86%]",children:[(0,t.jsx)(h.Skeleton,{className:"h-3 w-20 rounded mb-0.5"}),(0,t.jsx)(h.Skeleton,{className:"h-9 w-56 rounded-[1.05rem]"})]})]})]})}),(0,t.jsx)("div",{"data-keyboard-offset":!0,className:"relative z-10 px-3 md:px-5 pt-3 pb-[max(1.25rem,env(safe-area-inset-bottom))] md:pb-6",children:(0,t.jsxs)("div",{className:"mx-auto max-w-3xl",children:[(0,t.jsx)("div",{className:"h-5 px-1 mb-2 flex items-center",children:(0,t.jsx)(h.Skeleton,{className:"h-3.5 w-28 rounded"})}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(h.Skeleton,{className:"size-8 shrink-0 rounded-full"}),(0,t.jsx)(h.Skeleton,{className:"h-10 flex-1 rounded-3xl"})]})]})})]}):tE||tS||0!==tI.length?(0,t.jsxs)(t.Fragment,{children:[ai&&(0,t.jsxs)("button",{type:"button",className:"fixed z-50 flex items-center gap-1 px-2 py-1 rounded-md bg-popover border shadow-md text-xs text-popover-foreground hover:bg-accent transition-colors",style:{left:ai.x,top:ai.y,transform:"translate(-100%, -100%)"},onMouseDown:e=>e.preventDefault(),onClick:ac,children:[(0,t.jsx)(y.MessageSquareQuote,{className:"size-3"}),"Quote"]}),(0,t.jsxs)("div",{className:"relative flex-1 min-h-0",children:[(0,t.jsx)("div",{className:"h-full overflow-y-auto overflow-x-hidden px-3 md:px-5 thin-scrollbar",ref:tK,onScroll:tG,onClick:e=>{e.target.closest('[data-streamdown="code-block-actions"] button')&&m.toast.success("Copied to clipboard")},children:(0,t.jsxs)("div",{className:"mx-auto max-w-3xl pt-6 pb-15 min-w-0",children:[tb&&(0,t.jsx)("div",{className:"mb-2",children:(0,t.jsx)(O.MessageItem,{msg:tb,agents:ec,artifacts:[],activeTask:null,taskMessages:[],connectionLost:!1,pendingFilesByMessage:new Map,workspaceId:ei,onArtifactClick:()=>{},onEmailClick:()=>{},onIssueClick:()=>{},onCalendarEventClick:()=>{},mentionComponents:et,groupPosition:"solo",agentName:tO,agentAvatarConfig:t3,isThreadRoot:!0})}),tS&&tH&&!tz&&(0,t.jsx)("div",{className:"flex justify-center py-2",children:(0,t.jsx)("button",{onClick:()=>tX(),className:"text-xs text-muted-foreground hover:text-foreground transition-colors",children:"Load earlier messages"})}),tz&&(0,t.jsx)("div",{className:"flex justify-center py-2",children:(0,t.jsx)(b.Loader2,{className:"size-4 animate-spin text-muted-foreground"})}),0===tI.length&&!tT&&(X=ec.find(e=>e.id===eb),G=X?.created_at&&to-new Date(X.created_at).getTime()<3e5,Y=(em[eb]??0)>0,G&&Y&&"default"===eg?(0,t.jsxs)("div",{className:"flex flex-col items-center justify-center py-20 gap-3 animate-[fade-up_400ms_ease-out_both]",children:[(0,t.jsxs)("div",{className:"relative animate-bounce",children:[(0,t.jsx)(k.Mail,{className:"size-8 text-primary"}),(0,t.jsxs)("span",{className:"absolute -top-1 -right-1 flex size-3",children:[(0,t.jsx)("span",{className:"animate-ping absolute inline-flex size-full rounded-full bg-primary/60"}),(0,t.jsx)("span",{className:"relative inline-flex size-3 rounded-full bg-primary"})]})]}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground text-center max-w-xs",children:"Your agent is sending you a welcome email."}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground/60 text-center max-w-xs",children:"Wait for the email task in the top-left to complete, then check your inbox. Or send a message below to start chatting."})]}):(0,t.jsxs)("p",{className:"text-center text-muted-foreground py-20 text-base animate-[fade-up_400ms_ease-out_both]",children:["Say hi to ",t4,"."]})),tq.map((e,a)=>{let s=tB[a],r="first"===s||"solo"===s||null===s,n=0===a?"":r?"mt-6":"mt-1.5";if("nap"===e.kind)return(0,t.jsx)("div",{className:n,children:(0,t.jsx)(ea,{agentName:tO})},e.data.id);if("artifact"===e.kind){let a=s??"solo",r="first"===a||"solo"===a;return(0,t.jsx)("div",{className:n,children:(0,t.jsx)(O.AgentRow,{groupPosition:a,agentName:tO,config:t3,forceSpacer:!r,children:(0,t.jsx)(es,{artifact:e.data,version:t1.get(e.data.id)??1,hasDuplicates:t2.has(e.data.filename),onClick:t6,workspaceId:ei})})},`artifact-${e.data.id}`)}let l=e.data,i=tD.get(l.id)??l.id;return(0,t.jsx)("div",{className:n,children:(0,t.jsx)(O.MessageItem,{msg:l,agents:ec,artifacts:tL,activeTask:tT,activeTaskStreamMsgId:tW,taskMessages:tA,connectionLost:tR,conversationType:tS?.type,pendingFilesByMessage:tU,workspaceId:ei,onArtifactClick:t6,onPendingImageClick:t8,onEmailClick:au,onCalendarEventClick:am,onIssueClick:af,onRetry:tZ,mentionComponents:et,isFlagged:tf.has(l.id),onToggleFlag:"assistant"===l.role?tp:void 0,groupPosition:s??"solo",provider:ej,agentName:tO,agentAvatarConfig:t3,isSendFailed:t$.has(l.id),onRetrySend:tJ,onQuote:ad,onReplyInThread:tS?.parent_message_id?void 0:av,threadSummary:tS?.parent_message_id?null:tx.get(l.id)??null,onAgentChatOpen:ah})},i)}),tT&&tT.conversation_id===tS?.id&&null==tW&&!["completed","failed","cancelled","superseded"].includes(tT.status)&&(0,t.jsx)("div",{className:"mt-4",children:(0,t.jsx)(l.TaskStream,{task:tT,messages:tA,connectionLost:tR,provider:ej})})]})}),(0,t.jsx)(F.ScrollToBottomButton,{scrollRef:tK})]}),(0,t.jsx)("div",{"data-keyboard-offset":!0,className:"relative z-10 px-3 md:px-5 pt-3 pb-[max(1.25rem,env(safe-area-inset-bottom))] md:pb-6",children:(0,t.jsxs)("div",{className:"mx-auto max-w-3xl relative",children:[tS&&(0,t.jsx)(B.PresenceLine,{agentFirstName:t4,taskStatus:aw?tT?.status:null}),(0,t.jsxs)("div",{className:"flex items-end gap-2",children:[!e_&&(0,t.jsxs)(Z.Popover,{open:ab,onOpenChange:ak,children:[(0,t.jsx)(Z.PopoverTrigger,{render:(0,t.jsx)(n.Button,{variant:"ghost",size:"icon-sm",className:"shrink-0 self-end mb-2.5 size-8 rounded-full text-muted-foreground/60 hover:text-foreground transition-colors duration-200"}),children:(0,t.jsx)(H,{open:ab})}),(0,t.jsxs)(Z.PopoverContent,{side:"top",align:"start",className:"w-auto p-1.5 flex flex-col gap-0.5",children:[(0,t.jsxs)(p.Tooltip,{children:[(0,t.jsx)(p.TooltipTrigger,{render:e=>(0,t.jsx)("span",{...e,className:(0,f.cn)("inline-flex",e.className),children:(0,t.jsxs)(n.Button,{variant:"ghost",size:"sm",onClick:()=>{ak(!1),t0()},disabled:tP||!tS||!tV||aw,className:"w-full justify-start gap-2 rounded-md text-muted-foreground hover:text-foreground",children:[tP?(0,t.jsx)(b.Loader2,{className:"size-3.5 animate-spin"}):(0,t.jsx)(x.BedDouble,{className:"size-3.5"}),(0,t.jsx)("span",{className:"text-xs",children:"Nap"})]})})}),(0,t.jsx)(p.TooltipContent,{side:"right",children:aw?"Wait for the task to finish":tV?"Take a nap and reset the current session":`${tO} is well-rested and ready to go`})]}),(0,t.jsxs)(p.Tooltip,{children:[(0,t.jsx)(p.TooltipTrigger,{render:e=>(0,t.jsx)("span",{...e,className:(0,f.cn)("inline-flex",e.className),children:(0,t.jsxs)(n.Button,{variant:"ghost",size:"sm",onClick:()=>{ak(!1),aN()},disabled:ay||!aw,className:"w-full justify-start gap-2 rounded-md text-muted-foreground hover:text-foreground",children:[ay?(0,t.jsx)(b.Loader2,{className:"size-3.5 animate-spin"}):(0,t.jsx)(w.Square,{className:"size-3.5"}),(0,t.jsx)("span",{className:"text-xs",children:"Stop"})]})})}),(0,t.jsx)(p.TooltipContent,{side:"right",children:aw?"Stop the running task":"No task running"})]})]})]}),(0,t.jsxs)("div",{className:(0,f.cn)("relative flex-1 min-w-0 flex flex-col rounded-3xl border border-border/50 bg-background/90 transition-[border-radius] duration-200","focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50",(tu||tc||al.activeSkill)&&"rounded-2xl",tM&&"opacity-50",tt&&"border-ring ring-3 ring-ring/50"),onDragEnter:ta,onDragLeave:ts,onDragOver:tr,onDrop:tn,children:[tt&&(0,t.jsx)("div",{className:(0,f.cn)("absolute inset-0 z-10 flex items-center justify-center bg-background/80 border-2 border-dashed border-ring pointer-events-none",tu||tc||al.activeSkill?"rounded-2xl":"rounded-3xl"),children:(0,t.jsx)("p",{className:"text-sm text-muted-foreground font-medium",children:"Drop files here"})}),al.activeSkill&&(0,t.jsxs)("div",{className:"flex items-center gap-2 px-3.5 pt-2.5 pb-1 border-b border-border/50",children:[(0,t.jsxs)("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[(0,t.jsxs)("span",{className:"shrink-0 text-xs font-medium text-primary",children:["/",al.activeSkill.name]}),al.activeSkill.isGlobal&&(0,t.jsx)("span",{className:"text-[10px] font-medium text-muted-foreground bg-muted rounded px-1 py-0.5",children:"Global"}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground truncate",children:al.activeSkill.description})]}),(0,t.jsx)("button",{type:"button",onClick:al.clearActiveSkill,className:"shrink-0 p-0.5 rounded-sm hover:bg-muted-foreground/20 transition-colors text-muted-foreground",children:(0,t.jsx)(N.X,{className:"size-3.5"})})]}),tc&&(0,t.jsxs)("div",{className:"flex items-center gap-2 px-3.5 pt-2.5 pb-1 border-b border-border/50",children:[(0,t.jsxs)("div",{className:"flex-1 min-w-0 flex items-start gap-2",children:[(0,t.jsx)(y.MessageSquareQuote,{className:"size-3.5 shrink-0 mt-0.5 text-muted-foreground"}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground truncate max-w-50",children:tc.excerpt})]}),(0,t.jsx)("button",{type:"button",onClick:()=>td(null),className:"shrink-0 p-0.5 rounded-sm hover:bg-muted-foreground/20 transition-colors text-muted-foreground",children:(0,t.jsx)(N.X,{className:"size-3.5"})})]}),(0,t.jsx)(A.SlashCommandPopup,{isOpen:al.isOpen,skills:al.skills,selectedIndex:al.selectedIndex,onSelect:al.selectSkill,anchorPos:al.anchorPos}),e4.length>0&&(J=e4.map((e,t)=>({pf:e,i:t})).filter(({pf:e})=>e.thumbnailUrl),ee=e4.map((e,t)=>({pf:e,i:t})).filter(({pf:e})=>!e.thumbnailUrl),(0,t.jsxs)("div",{className:"px-3.5 pt-3 pb-0.5 space-y-1.5",children:[J.length>0&&(0,t.jsx)("div",{className:"flex flex-wrap gap-1.5",children:J.map(({pf:e,i:a})=>(0,t.jsxs)("div",{className:"relative group",children:[(0,t.jsx)("button",{type:"button",onClick:()=>{e3({url:URL.createObjectURL(e.file),filename:e.file.name})},className:"cursor-pointer",children:(0,t.jsx)("img",{src:e.thumbnailUrl,alt:e.file.name,className:"h-12 w-auto rounded-md object-cover"})}),(0,t.jsx)("button",{type:"button",onClick:()=>te(a),className:"absolute -top-1.5 -right-1.5 size-4 rounded-full bg-muted-foreground text-background flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:(0,t.jsx)(N.X,{className:"size-2.5"})})]},`${e.file.name}-${a}`))}),ee.length>0&&(0,t.jsx)("div",{className:"flex flex-wrap gap-1.5",children:ee.map(({pf:e,i:a})=>(0,t.jsxs)("span",{className:"inline-flex items-center gap-1.5 rounded-md bg-muted px-2 py-1 text-xs text-muted-foreground",children:[(0,t.jsx)(v.FileText,{className:"size-3 shrink-0"}),(0,t.jsx)("span",{className:"truncate max-w-30",children:e.file.name}),(0,t.jsx)("span",{className:"text-muted-foreground/60",children:(0,z.formatSize)(e.file.size)}),(0,t.jsx)("button",{type:"button",onClick:()=>te(a),className:"ml-0.5 rounded-sm p-0.5 hover:bg-muted-foreground/20 transition-colors",children:(0,t.jsx)(N.X,{className:"size-3"})})]},`${e.file.name}-${a}`))})]})),(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)("input",{ref:e6,type:"file",multiple:!0,className:"hidden",onChange:e9}),(0,t.jsx)("div",{className:"px-13 py-3",children:(0,t.jsx)(E.ChatComposer,{ref:tQ,value:eC,onChange:eS,onEditorState:(e,t)=>{ae(e),ti(t)},onSend:tY,onFocus:()=>eM(!0),onBlur:()=>eM(!1),overlay:""===eC.trim()?aw?(0,t.jsx)(E.RotatingPlaceholderOverlay,{hint:`Message ${t4}`,animate:!1}):(0,t.jsx)(E.RotatingPlaceholderOverlay,{hint:a_.hint,animate:a_.isRotating}):void 0,disabled:tM,onMultiLineChange:tm,onFiles:e7,agents:at,agentLinks:eu,currentAgentId:eb,slashIsOpen:al.isOpen,onSlashKeyDown:al.handleSlashKeyDown})}),(0,t.jsxs)(p.Tooltip,{children:[(0,t.jsx)(p.TooltipTrigger,{render:(0,t.jsx)(n.Button,{variant:"ghost",size:"icon-sm",onPointerDown:e=>e.preventDefault(),onClick:()=>e6.current?.click(),disabled:tM,className:"absolute left-2 bottom-2 size-8 rounded-full text-muted-foreground/60 hover:text-foreground transition-colors duration-200"}),children:(0,t.jsx)(j.Paperclip,{className:"size-3.5"})}),(0,t.jsx)(p.TooltipContent,{side:"top",children:"Attach files"})]}),(0,t.jsxs)(p.Tooltip,{children:[(0,t.jsx)(p.TooltipTrigger,{render:(0,t.jsx)(n.Button,{size:"icon-sm",onClick:tY,disabled:!eC.trim()||tM,className:(0,f.cn)("absolute right-2 bottom-2 size-8 rounded-full bg-primary text-primary-foreground transition-opacity duration-200",!eC.trim()&&"opacity-30")}),children:tM?(0,t.jsx)(b.Loader2,{className:"size-3.5 animate-spin"}):(0,t.jsx)(g.ArrowUp,{className:"size-3.5"})}),(0,t.jsx)(p.TooltipContent,{side:"top",children:"Send"})]})]})]})]})]})}),(0,t.jsx)(P.ImageLightbox,{open:null!=e1,onClose:()=>e2(null),artifact:e1,workspaceId:ei}),e5&&(0,t.jsx)(P.ImageLightbox,{open:!0,onClose:()=>{URL.revokeObjectURL(e5.url),e3(null)},imageUrl:e5.url,filename:e5.filename}),(0,t.jsx)(z.ArtifactSheet,{open:eT,onOpenChange:e=>{eA(e),e||setTimeout(()=>{eR(null)},300)},artifacts:eE?[eE]:tF,workspaceId:ei,initialArtifact:eE,versionMap:t1,duplicateFilenames:t2}),(0,t.jsx)(L.EmailEventSheet,{open:ez,onOpenChange:e=>{eL(e),e||setTimeout(()=>eU(null),300)},emailId:eP,workspaceId:ei}),(0,t.jsx)(U.CalendarEventSheet,{readonly:!0,open:e$,onOpenChange:e=>{eD(e),e||setTimeout(()=>eO(null),300)},calendarEventId:eF,workspaceId:ei}),(0,t.jsx)($.IssueSheet,{open:eq,onOpenChange:e=>{eB(e),e||setTimeout(()=>{eH(null),eK(null),eY(null)},300)},agents:ec,issue:eV?.issue??null,detail:eV?{messages:eV.messages,comments:eV.comments,artifacts:eV.artifacts,traceId:eV.issue.trace_id}:null,detailLoading:eQ,activeTask:eG,traceTasks:eX,slug:eo,workspaceId:ei,onUpdate:async(e,t)=>{try{let a=await (0,i.updateIssue)(ei,e,t);eK(s=>s&&s.issue.id===e?{...s,issue:{...s.issue,...t,updated_at:a.updated_at}}:s)}catch(e){m.toast.error(e instanceof Error?e.message:"Failed to update issue")}},onStatusChange:async(e,t)=>{try{await (0,i.updateIssue)(ei,e,{status:t}),eK(a=>a&&a.issue.id===e?{...a,issue:{...a.issue,status:t}}:a)}catch(e){m.toast.error(e instanceof Error?e.message:"Failed to update status")}},onCommented:()=>{eW&&eJ(eW)},onArtifactClick:t7})]}):(0,t.jsx)("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:"Failed to load conversation"})}},252304,e=>{"use strict";e.s(["AgentChatSheetProvider",()=>k,"useAgentChatSheet",()=>b],252304);var t=e.i(653772),a=e.i(511043),s=e.i(126942),r=e.i(355578),n=e.i(500324),l=e.i(288329),i=e.i(332680);e.i(954194);var o=e.i(439769);e.i(400175);var c=e.i(819748),d=e.i(126366),u=e.i(988232),m=e.i(49879),f=e.i(345262),h=e.i(887972),p=e.i(186339),g=e.i(329686);function x({open:e,onOpenChange:a,agentId:v,agent:b,targetConvId:k,scrollToTaskId:y,scrollToMessageId:j}){let w,N,_,C,S,I,{runtimes:M,activeTaskCounts:T}=(0,r.useAgentContext)(),{slug:A}=(0,n.useWorkspace)(),E=(0,s.useRouter)(),{width:R,onPointerDown:z,onPointerMove:L,onPointerUp:P}=(0,l.useSheetResize)({defaultWidth:480,minWidth:320,maxWidthRatio:.8});return(0,t.jsx)(i.Sheet,{open:e,onOpenChange:a,children:(0,t.jsxs)(i.SheetContent,{side:"right",showCloseButton:!1,style:{width:`min(${R}px, 100vw)`,maxWidth:"none"},className:"data-[side=right]:sm:inset-y-2 data-[side=right]:sm:right-2 data-[side=right]:sm:h-auto data-[side=right]:sm:rounded-xl data-[side=right]:sm:border flex flex-col",children:[(0,t.jsx)(l.SheetResizeHandle,{onPointerDown:z,onPointerMove:L,onPointerUp:P}),(0,t.jsxs)("div",{className:"absolute top-3 right-3 z-10 flex items-center gap-1",children:[v&&(w=new URLSearchParams,y&&w.set("task",y),j&&w.set("msg",j),k&&w.set("conv",k),N=w.toString(),_=`/w/${A}/agents/${v}${N?`?${N}`:""}`,(0,t.jsxs)(g.Tooltip,{children:[(0,t.jsx)(g.TooltipTrigger,{render:(0,t.jsx)("a",{href:_,onClick:e=>{e.metaKey||e.ctrlKey||e.shiftKey||(e.preventDefault(),a(!1),E.push(_))},className:(0,p.buttonVariants)({variant:"ghost",size:"icon-sm"})}),children:(0,t.jsx)(f.ArrowUpRight,{})}),(0,t.jsx)(g.TooltipContent,{children:"Open full page"})]})),(0,t.jsxs)(i.SheetClose,{render:(0,t.jsx)(p.Button,{variant:"ghost",size:"icon-sm"}),children:[(0,t.jsx)(h.XIcon,{}),(0,t.jsx)("span",{className:"sr-only",children:"Close"})]})]}),(0,t.jsx)(i.SheetHeader,{children:(0,t.jsxs)("div",{className:"flex items-center gap-3 pr-16",children:[b&&(C=(0,d.parseAvatarUrl)(b.avatar_url),S=M.find(e=>e.id===b.runtime_id),I=S?.status==="online"&&(T[b.id]??0)>0,C?(0,t.jsx)(c.AnimatedAvatar,{config:C,size:28,className:"shrink-0 rounded-lg",isHovered:!1,isWorking:I}):null),(0,t.jsxs)("div",{className:"flex items-baseline gap-2 min-w-0",children:[(0,t.jsx)(i.SheetTitle,{className:"truncate shrink-0",children:b?.name??"Chat"}),b?.email_handle&&(0,t.jsx)("span",{className:"text-xs text-muted-foreground truncate",children:(0,o.toAlookAddress)(b.email_handle)})]})]})}),!k&&(0,t.jsx)("div",{className:"px-4 pb-2",children:(0,t.jsx)(u.ChannelBar,{})}),v&&(0,t.jsx)("div",{className:"flex-1 overflow-hidden flex flex-col",children:(0,t.jsx)(m.AgentChatView,{agentId:v,targetConvId:k,scrollToTaskId:y,scrollToMessageId:j},`${v}-${k??""}`)})]})})}let v=(0,a.createContext)(null);function b(){let e=(0,a.useContext)(v);if(!e)throw Error("useAgentChatSheet must be used within AgentChatSheetProvider");return e}function k({children:e}){let l=(0,s.useRouter)(),{agents:i}=(0,r.useAgentContext)(),{slug:o}=(0,n.useWorkspace)(),[c,d]=(0,a.useState)(!1),[u,m]=(0,a.useState)(null),[f,h]=(0,a.useState)(null),[p,g]=(0,a.useState)(null),[b,y]=(0,a.useState)(null),j=u?i.find(e=>e.id===u)??null:null,w=(0,a.useRef)(i);(0,a.useEffect)(()=>{w.current=i});let N=(0,a.useCallback)((e,t)=>{w.current.find(t=>t.id===e)?(m(e),h(t?.conversationId??null),g(t?.taskId??null),y(t?.messageId??null),d(!0)):l.push(`/w/${o}/agents/${e}`)},[l,o]),_=(0,a.useCallback)(e=>{d(e),e||(h(null),g(null),y(null))},[]);return(0,t.jsxs)(v.Provider,{value:{openAgentChat:N},children:[e,(0,t.jsx)(x,{open:c,onOpenChange:_,agentId:u,agent:j,targetConvId:f,scrollToTaskId:p,scrollToMessageId:b})]})}}]);
|