1import{o as e,t}from"./react-B8HINTYZ.js";import{l as n}from"./chunk-OE4NN4TA-yuhGJTpF.js";import{_ as r}from"./removable-WH_Agnx_.js";import{t as i}from"./useQuery-eUuiyF0g.js";import{t as a}from"./useMutation-BxaOQ-QX.js";import{i as o}from"./bundle-mjs-C77yRssA.js";import{n as s}from"./QueryClientProvider-CL16TmWP.js";import{t as c}from"./queryOptions-C6eUkPeV.js";import{a as l,o as u}from"./i18n-BWNmymKJ.js";import{t as d}from"./Button-DTYgvPVQ.js";import{t as ee}from"./chevron-right-CYPuYBVv.js";import{t as te}from"./info-B6-auYX3.js";import{t as f}from"./trash-2-B7r-FLWj.js";import{t as p}from"./Sheet-D3tLYicl.js";import{c as m,d as h,i as g,l as _,p as v,r as y,t as b}from"./schemas-yJwYz_QM.js";import{t as x}from"./client-BP9RQxQS.js";import{t as S}from"./queryKeys-DQZ5qimK.js";import{i as C,n as w,r as T,t as E}from"./ActionMenu-ChvBSppT.js";import{t as D}from"./Loader-Cqe9DCTS.js";import{n as O}from"./routes-BpbnlVJL.js";import{n as k}from"./conversations-CzKEpVKh.js";import{l as A}from"./requests-DC9VGFOj.js";var j=u(`message-circle`,[[`path`,{d:`M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719`,key:`1sd12s`}]]),ne=u(`pause`,[[`rect`,{x:`14`,y:`3`,width:`5`,height:`18`,rx:`1`,key:`kaeet6`}],[`rect`,{x:`5`,y:`3`,width:`5`,height:`18`,rx:`1`,key:`1wsw3u`}]]),re=u(`play`,[[`path`,{d:`M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z`,key:`10ikf1`}]]),ie=e(t(),1),M=_({freq:b([`daily`,`weekly`,`monthly`,`yearly`]),time:h(),weekday:m().nullable(),day_of_month:m().nullable(),month:m().nullable()}),N=_({type:b([`once`,`recurring`]),run_at:m().nullable(),recurrence:M.nullable(),timezone:h().nullable(),next_run_at:m().nullable()}),P=_({id:h(),title:h(),notes:h().nullable(),instructions:h().nullable(),status:b([`active`,`running`,`stopped`,`completed`,`failed`]),conversation_id:h(),needs_clarification:g(),schedule:N.nullable(),last_run:_({ran_at:m(),status:b([`completed`,`failed`])}).nullable(),created_at:m(),updated_at:m()}),F=y(v()).transform(e=>e.flatMap(e=>{let t=P.safeParse(e);return t.success?[t.data]:(console.warn(`Skipping malformed errand`,{issues:t.error.issues,item:e}),[])})),I=_({errands:F,next_cursor:h().nullable(),has_more:g()}),L=_({errands:F}),R=_({errand:P});async function z(e,t){let n=new URLSearchParams({filter:e});return t&&n.set(`cursor`,t),x(`/api/errands?${n.toString()}`,{},I)}async function B(e,t){let{errands:n}=await x(`/api/conversations/${e}/errands?${new URLSearchParams({filter:t}).toString()}`,{},L);return n}async function V(e,t){return{errands:await B(e,t),next_cursor:null,has_more:!1}}async function H(e){let{errand:t}=await x(`/api/errands/${e}`,{},R);return t}async function U(e){let{errand:t}=await x(`/api/errands/${e}/stop`,{method:`POST`,body:JSON.stringify({})},R);return t}async function W(e){await x(`/api/errands/${e}`,{method:`DELETE`},_({ok:g()}))}var G={getErrandsQueryOptions:(e,t)=>c({queryKey:t?S.errands.conversationList(t,e):S.errands.list(e),queryFn:()=>t?V(t,e):z(e),placeholderData:r}),getErrandQueryOptions:e=>c({queryKey:S.errands.detail(e),queryFn:()=>H(e),enabled:!!e}),getConversationErrandsCountQueryOptions:e=>c({queryKey:S.errands.conversationCount(e??``),queryFn:async()=>(await B(e,`upcoming`)).length,enabled:!!e})};function K(e){return String(e).padStart(2,`0`)}function q(e){return`${K(e.getHours())}:${K(e.getMinutes())}`}function J(e){return`${K(e.getDate())}.${K(e.getMonth()+1)}.${e.getFullYear()}`}function Y(e){let t=new Date(e);return t.setHours(0,0,0,0),t}function ae(e,t){let n=Y(t).getTime()-Y(e).getTime();return Math.round(n/864e5)}function X(e){let t=e.schedule?.next_run_at??e.schedule?.run_at??e.last_run?.ran_at??null;if(t==null)return null;let n=new Date(t*1e3);return Number.isNaN(n.getTime())?null:n}var oe={daily:`errandsRecurrenceDaily`,weekly:`errandsRecurrenceWeekly`,monthly:`errandsRecurrenceMonthly`,yearly:`errandsRecurrenceYearly`};function se(e,t){let n=X(e);return n?e.status===`running`?q(n):e.schedule?.type===`recurring`&&e.schedule.recurrence?`${t(oe[e.schedule.recurrence.freq])}, ${e.schedule.recurrence.time}`:ae(new Date,n)===0?q(n):`${J(n)}, ${q(n)}`:``}function ce(e){return e.status===`running`?{name:`sidebar-spinner`,spin:!0}:e.schedule?e.schedule.type===`recurring`?{name:`errand-recurring`,spin:!1}:{name:`calendar`,spin:!1}:{name:`artifact-doc`,spin:!1}}
1var le={daily:`errandsWhenDaily`,weekly:`errandsWhenWeekly`,monthly:`errandsWhenMonthly`,yearly:`errandsWhenYearly`};function ue(e,t){if(e.schedule?.type===`recurring`&&e.schedule.recurrence)return`${t(le[e.schedule.recurrence.freq])}, ${e.schedule.recurrence.time}`;let n=X(e);return n?`${J(n)}, ${q(n)}`:`â`}var de={active:`errandsStatusActive`,running:`errandsStatusRunning`,stopped:`errandsStatusStopped`,completed:`errandsStatusCompleted`,failed:`errandsStatusFailed`};function Z(e,t){return t(de[e.status])}var Q=o();function $({label:e,children:t}){return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Q.jsx)(`p`,{className:`text-body font-medium text-text-dim`,children:e}),(0,Q.jsx)(`div`,{className:`whitespace-pre-line text-body font-medium text-foreground`,children:t})]})}function fe({errandId:e,open:t,onClose:r}){let o=l(),c=n(),u=s(),{data:m,isLoading:h}=i(G.getErrandQueryOptions(e)),{data:g}=i(k.getConversationsQueryOptions()),_=g?.find(e=>e.id===m?.conversation_id)?.title?.trim()||o(`chatNewLabel`),v=e=>{let t=e.status===`active`||e.status===`running`?`upcoming`:`completed`;[`upcoming`,`completed`].forEach(n=>{u.setQueryData(S.errands.list(n),r=>{if(!r)return r;let i=r.errands.filter(t=>t.id!==e.id);return n===t?{...r,errands:[e,...i]}:i.length===r.errands.length?r:{...r,errands:i}})})},y=t=>{u.setQueryData(S.errands.detail(e),t),v(t)},b=a({mutationFn:()=>U(e),onSuccess:e=>{y(e),u.invalidateQueries({queryKey:S.errands.lists})}}),x=a({mutationFn:()=>A(o(`errandsResumeMessage`,{id:e}),m.conversation_id,[]),onSuccess:()=>y({...m,status:`active`})}),M=a({mutationFn:()=>W(e),onSuccess:()=>{u.removeQueries({queryKey:S.errands.detail(e)}
1),u.invalidateQueries({queryKey:S.errands.lists}),r()}}),[N,P]=(0,ie.useState)(!1),F=()=>{m&&(r(),c(O.chatConversation(m.conversation_id)))},I=m?.status===`active`||m?.status===`running`,L=m?.status===`stopped`,R=b.isPending||x.isPending,z=(0,Q.jsxs)(Q.Fragment,{children:[o(`errandsDetailNumber`),` `,(0,Q.jsxs)(`span`,{className:`text-text-dim`,children:[`#`,e]})]});return(0,Q.jsx)(p,{mode:`modal`,open:t,onOpenChange:e=>{e||r()},title:z,contentClassName:`flex flex-1 flex-col overflow-hidden px-0 pt-0 pb-0`,children:h||!m?(0,Q.jsx)(`div`,{className:`flex flex-1 items-center justify-center`,children:h?(0,Q.jsx)(D,{}):(0,Q.jsx)(`p`,{className:`text-body font-medium text-text-dim`,children:o(`errandsNotFound`)})}):(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col bg-background`,children:(0,Q.jsxs)(`div`,{className:`mx-auto flex min-h-0 w-full max-w-[700px] flex-1 flex-col max-xl:px-4 pb-[calc(var(--sa-bottom)+16px)] pt-2 lg:pb-10 lg:pt-4`,children:[(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-8 overflow-y-auto overflow-x-clip`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,Q.jsx)(`h1`,{className:`text-title font-bold leading-none text-foreground max-lg:hidden`,children:z}),(0,Q.jsxs)(E,{open:N,onOpenChange:P,children:[(0,Q.jsx)(C,{"aria-label":o(`errandsMenuLabel`),className:`ml-auto size-7 rounded-[6px] bg-surface-bee text-text-dim hover:bg-surface-muted hover:text-text-dim data-[state=open]:bg-surface-bee`}),(0,Q.jsxs)(w,{align:`end`,sideOffset:8,className:`flex flex-col gap-[5px]`,children:[I?(0,Q.jsx)(T,{icon:(0,Q.jsx)(ne,{className:`size-[18px] shrink-0`,strokeWidth:1.5}),label:o(`errandsStop`),disabled:R,onClick:()=>{P(!1),b.mutate()}}):L?(0,Q.jsx)(T,{icon:(0,Q.jsx)(re,{className:`size-[18px] shrink-0`,strokeWidth:1.5}),label:o(`errandsResume`),disabled:R,onClick:()=>{P(!1),x.mutate()}}):null,(0,Q.jsx)(T,{icon:(0,Q.jsx)(f,{className:`size-[18px] shrink-0`,strokeWidth:1.5}),label:o(`errandsDelete`),destructive:!0,disabled:M.isPending,onClick:()=>{P(!1),M.mutate()}})]})]})]}),m.needs_clarification?(0,Q.jsxs)(`div`,{className:`flex w-full items-start gap-2 rounded-[10px] bg-surface-bee py-[10px] pl-[10px] pr-[14px]`,children:[(0,Q.jsx)(te,{className:`size-[19px] shrink-0 text-foreground`,strokeWidth:1.5,"aria-hidden":`true`}),(0,Q.jsx)(`p`,{className:`text-body font-medium text-foreground`,children:o(`errandsNeedsClarification`)})]}):null,(0,Q.jsx)($,{label:o(`errandsDetailStatus`),children:Z(m,o)}),(0,Q.jsx)($,{label:o(`errandsDetailName`),children:m.title}),m.notes?(0,Q.jsx)($,{label:o(`errandsDetailNotes`),children:m.notes}):null,m.instructions?(0,Q.jsx)($,{label:o(`errandsDetailInstructions`),children:m.instructions}):null,(0,Q.jsx)($,{label:o(`errandsDetailWhen`),children:ue(m,o)}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Q.jsx)(`p`,{className:`text-body font-medium text-text-dim`,children:o(`errandsDetailDialog`)}),(0,Q.jsxs)(`button`,{type:`button`,onClick:F,className:`flex w-full cursor-pointer items-center gap-2 rounded-xl p-control text-left transition-colors hover:bg-surface-bee`,children:[(0,Q.jsx)(j,{className:`size-[18px] shrink-0 text-foreground`,strokeWidth:1.5,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-body font-medium text-foreground`,children:_}),(0,Q.jsx)(ee,{className:`size-[18px] shrink-0 text-text-dim`,strokeWidth:1.5,"aria-hidden":`true`})]})]})]}),(0,Q.jsx)(`div`,{className:`mt-auto shrink-0 pt-6 lg:hidden`,children:(0,Q.jsx)(d,{type:`button`,onClick:F,className:`w-full rounded-card!`,children:o(`errandsGoToChat`)})})]})})})}export{j as a,G as i,se as n,ce as r,fe as t};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.