@xopcai/xopc 0.0.96 → 0.0.97
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/dist/browser-ext/manifest.json +1 -1
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/gateway/static/root/assets/{agents-DmIuSaOE.js → agents-B_YUvNi6.js} +1 -1
- package/dist/gateway/static/root/assets/{apps-page-DFcHBxLw.js → apps-page-BmwG5aur.js} +1 -1
- package/dist/gateway/static/root/assets/{channels-settings-DDUf55C5.js → channels-settings-BiwkeKPb.js} +1 -1
- package/dist/gateway/static/root/assets/{channels-status-swr-BxF-_nzD.js → channels-status-swr-ChyN473C.js} +1 -1
- package/dist/gateway/static/root/assets/{cron-api-DylQtnb_.js → cron-api-CvSifIfJ.js} +1 -1
- package/dist/gateway/static/root/assets/{cron-page-BO0d9Pf-.js → cron-page-BDqTDFy6.js} +1 -1
- package/dist/gateway/static/root/assets/{dist-BskF0qDS.js → dist-DxsUrjpy.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-BcZdTdjJ.js → extension-debug-page-DV_Av5Jq.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-D2iuDa1D.js → extension-page-CwZwRhWw.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-BKpQCgLc.js → extension-settings-page-Bb7TR1Se.js} +1 -1
- package/dist/gateway/static/root/assets/{fetch-CtNDpjij.js → fetch-BLLOP2CM.js} +1 -1
- package/dist/gateway/static/root/assets/{field-primitives-2PekrGZF.js → field-primitives-CyqVu1QR.js} +1 -1
- package/dist/gateway/static/root/assets/{heartbeat-config-api-D3D7SW8A.js → heartbeat-config-api-Cd4M1eHt.js} +1 -1
- package/dist/gateway/static/root/assets/{index-Db9fd_X4.js → index-0tS9lV85.js} +5 -5
- package/dist/gateway/static/root/assets/index-BJDmBCSl.css +1 -0
- package/dist/gateway/static/root/assets/{logs-page-B3I1a26m.js → logs-page-BsAOSowN.js} +1 -1
- package/dist/gateway/static/root/assets/{note-detail-page-BOizhtJ8.js → note-detail-page-Dlxoy6Ap.js} +1 -1
- package/dist/gateway/static/root/assets/{note-time-CjUGtqKr.js → note-time-B-r8yTpQ.js} +1 -1
- package/dist/gateway/static/root/assets/{notes-page-BB8-I0Of.js → notes-page-CHFcyqYW.js} +1 -1
- package/dist/gateway/static/root/assets/{sessions-page-BcH-1K9i.js → sessions-page-Ctu0kgt7.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-advanced-gate-Czn8nnjN.js → settings-advanced-gate-Dh0TyOOg.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-form-section-ZZWDwgVe.js → settings-form-section-DXMCEW1d.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-BX8c_zrN.js → settings-page-CIkZ7233.js} +1 -1
- package/dist/gateway/static/root/assets/{share-preview-page-Ch3_6Qah.js → share-preview-page-7RV65xhJ.js} +1 -1
- package/dist/gateway/static/root/assets/{skills-page-WO0bbJ54.js → skills-page-D_Az1SlU.js} +1 -1
- package/dist/gateway/static/root/assets/{theme-store-XxRFRZDX.js → theme-store-e2q2yjs4.js} +1 -1
- package/dist/gateway/static/root/assets/{url-6zpynn1R.js → url-DpFBIyN9.js} +2 -2
- package/dist/gateway/static/root/assets/{utils-uTYKh54l.js → utils-OA_b1q0Q.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-api-key-field-BIAYHRs-.js → voice-api-key-field-SJml1hAt.js} +1 -1
- package/dist/gateway/static/root/assets/{workflow-page.utils-BbWhqD36.js → workflow-page.utils-D90VVCzC.js} +1 -1
- package/dist/gateway/static/root/assets/{workflows-page-D4RIF7E1.js → workflows-page-y7Btji0J.js} +1 -1
- package/dist/gateway/static/root/index.html +5 -5
- package/dist/package.js +1 -1
- package/dist/src/agent/agent-manager.js +1 -3
- package/dist/src/agent/agent-manager.js.map +1 -1
- package/dist/src/agent/bootstrap/bootstrap-cache.d.ts +0 -1
- package/dist/src/agent/bootstrap/bootstrap-cache.js +2 -3
- package/dist/src/agent/bootstrap/bootstrap-cache.js.map +1 -1
- package/dist/src/agent/bootstrap/bootstrap-files.d.ts +0 -5
- package/dist/src/agent/bootstrap/bootstrap-files.js +4 -5
- package/dist/src/agent/bootstrap/bootstrap-files.js.map +1 -1
- package/dist/src/agent/bootstrap/load-bootstrap-files.d.ts +2 -6
- package/dist/src/agent/bootstrap/load-bootstrap-files.js +6 -21
- package/dist/src/agent/bootstrap/load-bootstrap-files.js.map +1 -1
- package/dist/src/agent/bootstrap/types.d.ts +5 -5
- package/dist/src/agent/context/workspace-seed.js +5 -9
- package/dist/src/agent/context/workspace-seed.js.map +1 -1
- package/dist/src/agent/context/workspace-state.d.ts +3 -35
- package/dist/src/agent/context/workspace-state.js +9 -53
- package/dist/src/agent/context/workspace-state.js.map +1 -1
- package/dist/src/agent/context/workspace-templates/AGENTS.md +0 -4
- package/dist/src/agent/prompt/system-prompt.js +0 -1
- package/dist/src/agent/prompt/system-prompt.js.map +1 -1
- package/dist/src/agent/tools/tool-paths.js +1 -3
- package/dist/src/agent/tools/tool-paths.js.map +1 -1
- package/dist/src/chat-commands/agent-edit.js +1 -2
- package/dist/src/chat-commands/agent-edit.js.map +1 -1
- package/dist/src/cli/commands/onboard.js +0 -8
- package/dist/src/cli/commands/onboard.js.map +1 -1
- package/dist/src/cli/templates.d.ts +3 -10
- package/dist/src/cli/templates.js +4 -32
- package/dist/src/cli/templates.js.map +1 -1
- package/dist/src/config/paths.d.ts +0 -1
- package/dist/src/config/paths.js +1 -2
- package/dist/src/config/paths.js.map +1 -1
- package/dist/src/config/schema.js +1 -1
- package/dist/src/config/schema.js.map +1 -1
- package/dist/src/gateway/agents-admin.js +1 -6
- package/dist/src/gateway/agents-admin.js.map +1 -1
- package/dist/src/gateway/heartbeat/service.js +1 -1
- package/dist/src/heartbeat/index.js +1 -1
- package/package.json +1 -1
- package/dist/gateway/static/root/assets/index-BvEhL9RQ.css +0 -1
- package/dist/src/agent/context/workspace-templates/BOOTSTRAP.md +0 -61
package/dist/gateway/static/root/assets/{sessions-page-BcH-1K9i.js → sessions-page-Ctu0kgt7.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{i,o as a,t as o}from"./url-6zpynn1R.js";import{i as s}from"./vendor-swr-BIWyz7Rc.js";import{a as c,n as l}from"./fetch-CtNDpjij.js";import{$n as u,$o as d,Ba as f,Bn as p,Ca as m,Cr as h,Dr as ee,Er as g,Go as _,M as v,N as y,Oa as b,Or as te,Ra as x,So as S,Vn as C,Wo as w,Yi as T,ar as E,bn as D,cr as O,da as k,di as A,dr as j,er as M,fa as N,fi as P,fo as F,hr as I,io as L,ir as R,j as z,kr as B,li as V,mr as ne,ni as H,nr as re,or as ie,pi as U,po as W,rr as G,sr as ae,ti as K,tr as oe,ui as q,ur as J,wi as se,wr as ce,yn as le,za as ue,zn as de}from"./index-Db9fd_X4.js";import{n as fe,t as Y}from"./settings-form-section-ZZWDwgVe.js";var X=e(t(),1),pe=n(),Z=r();function me(e){let t=new Date(e),n=Math.floor((new Date().getTime()-t.getTime())/(1e3*60*60*24));return n===0?t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}):n===1?`Yesterday`:n<7?t.toLocaleDateString([],{weekday:`short`}):t.toLocaleDateString([],{month:`short`,day:`numeric`})}function he(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function ge(e){let t=(0,pe.c)(105),{session:n,variant:r,labels:i,sessionAgentId:a,sessionAgentAvatar:o,onOpen:s,onAction:c}=e,l;t[0]!==i.unnamedSession||t[1]!==n.name?(l=n.name?.trim()||i.unnamedSession,t[0]=i.unnamedSession,t[1]=n.name,t[2]=l):l=t[2];let u=l,d;t[3]===n.name?d=t[4]:(d=n.name?.trim(),t[3]=n.name,t[4]=d);let f=!!d,p=n.status===`archived`,h=n.status===`pinned`,ee=r===`list`&&`sm:flex-row sm:items-center sm:gap-4`,g;t[5]===ee?g=t[6]:(g=A(`group flex min-w-0 w-full max-w-full cursor-pointer flex-col rounded-xl bg-surface-base text-left transition-colors duration-150 ease-out`,`hover:bg-surface-hover active:scale-[0.99]`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-surface-panel`,ee),t[5]=ee,t[6]=g);let v;t[7]===s?v=t[8]:(v=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),s())},t[7]=s,t[8]=v);let y=r===`list`&&`sm:py-3`,b;t[9]===y?b=t[10]:(b=A(`flex min-w-0 items-start justify-between gap-2 bg-surface-hover/35 px-3 py-2 dark:bg-surface-hover/25`,y),t[9]=y,t[10]=b);let te;t[11]===n.sourceChannel?te=t[12]:(te=(0,Z.jsx)(`div`,{className:`flex min-w-0 items-center gap-2`,children:(0,Z.jsx)(`span`,{className:`truncate text-[11px] font-medium uppercase tracking-wide text-fg-subtle`,children:n.sourceChannel})}),t[11]=n.sourceChannel,t[12]=te);let x;t[13]===h?x=t[14]:(x=h?(0,Z.jsx)(N,{className:`size-3.5 text-accent-fg`,strokeWidth:1.75,"aria-hidden":!0}):null,t[13]=h,t[14]=x);let S;t[15]===n.updatedAt?S=t[16]:(S=me(n.updatedAt),t[15]=n.updatedAt,t[16]=S);let T;t[17]===S?T=t[18]:(T=(0,Z.jsx)(`span`,{children:S}),t[17]=S,t[18]=T);let E;t[19]!==T||t[20]!==x?(E=(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5 text-xs text-fg-muted`,children:[x,T]}),t[19]=T,t[20]=x,t[21]=E):E=t[21];let D;t[22]!==E||t[23]!==b||t[24]!==te?(D=(0,Z.jsxs)(`div`,{className:b,children:[te,E]}),t[22]=E,t[23]=b,t[24]=te,t[25]=D):D=t[25];let O=r===`list`&&`sm:py-3`,j;t[26]===O?j=t[27]:(j=A(`min-w-0 flex-1 px-3 py-2`,O),t[26]=O,t[27]=j);let M=r===`list`&&`sm:items-start`,I;t[28]===M?I=t[29]:(I=A(`flex gap-3`,M),t[28]=M,t[29]=I);let L;t[30]!==o||t[31]!==a?(L=(0,Z.jsx)(C,{agentId:a,avatar:o,size:40,className:`size-10 shrink-0 ring-1 ring-edge/60 dark:ring-edge`}),t[30]=o,t[31]=a,t[32]=L):L=t[32];let R;t[33]===u?R=t[34]:(R=(0,Z.jsx)(`div`,{className:`min-w-0 max-w-full truncate text-sm font-semibold text-fg`,title:u,children:u}),t[33]=u,t[34]=R);let z;t[35]!==n.key||t[36]!==f?(z=f?(0,Z.jsx)(`div`,{className:`mt-0.5 min-w-0 max-w-full truncate font-mono text-[11px] text-fg-subtle`,title:n.key,children:n.key}):null,t[35]=n.key,t[36]=f,t[37]=z):z=t[37];let B;t[38]!==R||t[39]!==z?(B=(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[R,z]}),t[38]=R,t[39]=z,t[40]=B):B=t[40];let V;t[41]!==I||t[42]!==L||t[43]!==B?(V=(0,Z.jsxs)(`div`,{className:I,children:[L,B]}),t[41]=I,t[42]=L,t[43]=B,t[44]=V):V=t[44];let ne;t[45]===Symbol.for(`react.memo_cache_sentinel`)?(ne=(0,Z.jsx)(m,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0}),t[45]=ne):ne=t[45];let H;t[46]===n.messageCount?H=t[47]:(H=(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[ne,n.messageCount]}),t[46]=n.messageCount,t[47]=H);let re;t[48]===Symbol.for(`react.memo_cache_sentinel`)?(re=(0,Z.jsx)(P,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0}),t[48]=re):re=t[48];let ie;t[49]===n.estimatedTokens?ie=t[50]:(ie=he(n.estimatedTokens),t[49]=n.estimatedTokens,t[50]=ie);let U;t[51]===ie?U=t[52]:(U=(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[re,ie]}),t[51]=ie,t[52]=U);let W;t[53]!==H||t[54]!==U?(W=(0,Z.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-3 text-xs text-fg-muted`,children:[H,U]}),t[53]=H,t[54]=U,t[55]=W):W=t[55];let G;t[56]===n.tags?G=t[57]:(G=n.tags.length>0?(0,Z.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-1`,children:[n.tags.slice(0,3).map(ye),n.tags.length>3?(0,Z.jsxs)(`span`,{className:`text-[11px] text-fg-disabled`,children:[`+`,n.tags.length-3]}):null]}):null,t[56]=n.tags,t[57]=G);let ae;t[58]!==j||t[59]!==V||t[60]!==W||t[61]!==G?(ae=(0,Z.jsxs)(`div`,{className:j,children:[V,W,G]}),t[58]=j,t[59]=V,t[60]=W,t[61]=G,t[62]=ae):ae=t[62];let oe;t[63]===c?oe=t[64]:(oe=()=>c(`continue`),t[63]=c,t[64]=oe);let q;t[65]===Symbol.for(`react.memo_cache_sentinel`)?(q=(0,Z.jsx)(m,{className:`size-4`,strokeWidth:1.75}),t[65]=q):q=t[65];let J;t[66]!==i.continueChat||t[67]!==oe?(J=(0,Z.jsx)(`button`,{type:`button`,className:K,title:i.continueChat,"aria-label":i.continueChat,onClick:oe,children:q}),t[66]=i.continueChat,t[67]=oe,t[68]=J):J=t[68];let ce;t[69]!==p||t[70]!==i.archive||t[71]!==i.unarchive||t[72]!==c?(ce=p?(0,Z.jsx)(`button`,{type:`button`,className:K,title:i.unarchive,"aria-label":i.unarchive,onClick:()=>c(`unarchive`),children:(0,Z.jsx)(_,{className:`size-4`,strokeWidth:1.75})}):(0,Z.jsx)(`button`,{type:`button`,className:K,title:i.archive,"aria-label":i.archive,onClick:()=>c(`archive`),children:(0,Z.jsx)(w,{className:`size-4`,strokeWidth:1.75})}),t[69]=p,t[70]=i.archive,t[71]=i.unarchive,t[72]=c,t[73]=ce):ce=t[73];let le;t[74]!==h||t[75]!==i.pin||t[76]!==i.unpin||t[77]!==c?(le=h?(0,Z.jsx)(`button`,{type:`button`,className:K,title:i.unpin,"aria-label":i.unpin,onClick:()=>c(`unpin`),children:(0,Z.jsx)(k,{className:`size-4`,strokeWidth:1.75})}):(0,Z.jsx)(`button`,{type:`button`,className:K,title:i.pin,"aria-label":i.pin,onClick:()=>c(`pin`),children:(0,Z.jsx)(N,{className:`size-4`,strokeWidth:1.75})}),t[74]=h,t[75]=i.pin,t[76]=i.unpin,t[77]=c,t[78]=le):le=t[78];let ue;t[79]===c?ue=t[80]:(ue=()=>c(`export`),t[79]=c,t[80]=ue);let de;t[81]===Symbol.for(`react.memo_cache_sentinel`)?(de=(0,Z.jsx)(F,{className:`size-4`,strokeWidth:1.75}),t[81]=de):de=t[81];let fe;t[82]!==i.export||t[83]!==ue?(fe=(0,Z.jsx)(`button`,{type:`button`,className:K,title:i.export,"aria-label":i.export,onClick:ue,children:de}),t[82]=i.export,t[83]=ue,t[84]=fe):fe=t[84];let Y;t[85]===Symbol.for(`react.memo_cache_sentinel`)?(Y=A(K,`text-red-600 hover:bg-red-50 dark:text-red-400 dark:hover:bg-red-950/40`),t[85]=Y):Y=t[85];let X;t[86]===c?X=t[87]:(X=()=>c(`delete`),t[86]=c,t[87]=X);let ge;t[88]===Symbol.for(`react.memo_cache_sentinel`)?(ge=(0,Z.jsx)(se,{className:`size-4`,strokeWidth:1.75}),t[88]=ge):ge=t[88];let Q;t[89]!==i.delete||t[90]!==X?(Q=(0,Z.jsx)(`button`,{type:`button`,className:Y,title:i.delete,"aria-label":i.delete,onClick:X,children:ge}),t[89]=i.delete,t[90]=X,t[91]=Q):Q=t[91];let be;t[92]!==J||t[93]!==ce||t[94]!==le||t[95]!==fe||t[96]!==Q?(be=(0,Z.jsxs)(`div`,{role:`group`,className:`flex flex-wrap items-center gap-0.5 border-t border-edge-subtle/80 bg-surface-hover/25 p-2 dark:border-edge-subtle`,onClick:ve,onKeyDown:_e,children:[J,ce,le,fe,Q]}),t[92]=J,t[93]=ce,t[94]=le,t[95]=fe,t[96]=Q,t[97]=be):be=t[97];let $;return t[98]!==s||t[99]!==D||t[100]!==ae||t[101]!==g||t[102]!==be||t[103]!==v?($=(0,Z.jsxs)(`div`,{role:`button`,tabIndex:0,className:g,onClick:s,onKeyDown:v,children:[D,ae,be]}),t[98]=s,t[99]=D,t[100]=ae,t[101]=g,t[102]=be,t[103]=v,t[104]=$):$=t[104],$}function _e(e){return e.stopPropagation()}function ve(e){return e.stopPropagation()}function ye(e){return(0,Z.jsx)(`span`,{className:`max-w-full break-words rounded-md bg-surface-hover px-1.5 py-0.5 text-[11px] text-fg-muted`,children:e},e)}function Q(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function be(e){return e===`main`||e===`per-peer`||e===`per-channel-peer`||e===`per-account-channel-peer`?e:`main`}function $(e){let t=Q(e)?e:{},n=Q(t.session)?t.session:{},r=Q(n.storage)?n.storage:{},i=typeof r.pruneAfterDays==`number`&&Number.isFinite(r.pruneAfterDays)?Math.max(0,Math.floor(r.pruneAfterDays)):typeof r.pruneAfterMs==`number`&&Number.isFinite(r.pruneAfterMs)?Math.max(0,Math.round(r.pruneAfterMs/864e5)):null,a=typeof r.maxEntries==`number`&&Number.isFinite(r.maxEntries)?Math.max(1,Math.floor(r.maxEntries)):null;return{dmScope:be(n.dmScope),pruneAfterDays:i,maxEntries:a}}async function xe(e){await l(o(`/api/config`),{method:`PATCH`,body:JSON.stringify({session:{dmScope:e.dmScope,storage:{pruneAfterMs:e.pruneAfterDays===null?null:e.pruneAfterDays*864e5,maxEntries:e.maxEntries}}})}),J()}function Se(){return A(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,V,`dark:border-edge`)}var Ce=z();function we({hasToken:e}){let t=a(i(e=>e.language)).sessions.config,{data:n,isLoading:r}=j(e),o=(0,X.useMemo)(()=>n?.payload?.config===void 0?null:$(n.payload.config),[n]),[s,c]=(0,X.useReducer)(Ce,{form:null,baseline:null}),l=s.form,u=s.baseline,[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(null),h=(0,X.useRef)(!1),ee=(0,X.useRef)(null);v({enabled:e,parsed:o,dirty:h.current,trackedParsedRef:ee,dispatch:c,onResetDirty:()=>{h.current=!1}});let g=l&&u&&JSON.stringify(l)!==JSON.stringify(u),_=(0,X.useCallback)(e=>{h.current=!0,c({type:`patch`,patch:e})},[]);return!e||!l?r?(0,Z.jsx)(Y,{children:(0,Z.jsx)(b,{className:`size-4 animate-spin text-fg-muted`})}):null:(0,Z.jsxs)(Y,{children:[(0,Z.jsx)(fe,{icon:W,title:t.title,subtitle:t.hint}),(0,Z.jsxs)(`div`,{className:`mb-4 flex justify-end gap-2`,children:[(0,Z.jsx)(q,{type:`button`,variant:`secondary`,disabled:!g||d,onClick:()=>c({type:`discard`}),children:t.discard}),(0,Z.jsx)(q,{type:`button`,variant:`primary`,disabled:!g||d,onClick:()=>{(async()=>{f(!0),m(null);try{await xe(l),h.current=!1,c({type:`saved`,value:l})}catch(e){m(e instanceof Error?e.message:t.saveError)}finally{f(!1)}})()},children:d?t.saving:t.save})]}),p?(0,Z.jsx)(`p`,{className:`mb-3 text-sm text-red-600 dark:text-red-400`,children:p}):null,(0,Z.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,Z.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,children:t.dmScope}),(0,Z.jsxs)(`select`,{className:Se(),value:l.dmScope,onChange:e=>_({dmScope:e.target.value}),children:[(0,Z.jsx)(`option`,{value:`main`,children:t.dmScopeMain}),(0,Z.jsx)(`option`,{value:`per-peer`,children:t.dmScopePerPeer}),(0,Z.jsx)(`option`,{value:`per-channel-peer`,children:t.dmScopePerChannelPeer}),(0,Z.jsx)(`option`,{value:`per-account-channel-peer`,children:t.dmScopePerAccountChannelPeer})]}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:t.dmScopeHint})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,children:t.pruneAfterDays}),(0,Z.jsx)(`input`,{type:`number`,min:0,className:Se(),value:l.pruneAfterDays??``,placeholder:t.unsetPlaceholder,onChange:e=>{let t=e.target.value.trim();_({pruneAfterDays:t===``?null:Math.max(0,Math.floor(Number(t)||0))})}})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,children:t.maxEntries}),(0,Z.jsx)(`input`,{type:`number`,min:1,className:Se(),value:l.maxEntries??``,placeholder:t.unsetPlaceholder,onChange:e=>{let t=e.target.value.trim();_({maxEntries:t===``?null:Math.max(1,Math.floor(Number(t)||1))})}})]})]})]})}function Te(e){if(typeof e==`string`)return e.length>2e3?`${e.slice(0,2e3)}…`:e;try{let t=JSON.stringify(e,null,2);return t.length>2e3?`${t.slice(0,2e3)}…`:t}catch{return String(e)}}function Ee(e){let t=(0,pe.c)(60),{open:n,loading:r,session:i,sessionAgentId:a,sessionAgentAvatar:o,labels:s,onClose:c,onArchive:l,onUnarchive:u,onPin:d,onUnpin:f,onExport:p,onDelete:m}=e,_=i?.status===`archived`,v=i?.status===`pinned`,y;t[0]===c?y=t[1]:(y=e=>!e&&c(),t[0]=c,t[1]=y);let b;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,Z.jsx)(g,{className:A(`xopc-dialog-overlay fixed inset-0 bg-scrim`,D)}),t[2]=b):b=t[2];let x;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(x=A(`xopc-drawer-right fixed right-0 top-0 flex size-full max-w-lg flex-col border-l border-edge bg-surface-panel shadow-popover outline-none`,le,`dark:border-edge`),t[3]=x):x=t[3];let S;t[4]!==i||t[5]!==o||t[6]!==a?(S=i&&a?(0,Z.jsx)(C,{agentId:a,avatar:o,size:40,className:`size-10 shrink-0 ring-1 ring-edge/60 dark:ring-edge`}):null,t[4]=i,t[5]=o,t[6]=a,t[7]=S):S=t[7];let w;t[8]!==s.unnamedSession||t[9]!==i?.name?(w=i?.name?.trim()||s.unnamedSession,t[8]=s.unnamedSession,t[9]=i?.name,t[10]=w):w=t[10];let T;t[11]===w?T=t[12]:(T=(0,Z.jsx)(B,{className:`min-w-0 flex-1 truncate text-base font-semibold tracking-tight text-fg`,children:w}),t[11]=w,t[12]=T);let E;t[13]!==S||t[14]!==T?(E=(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-3`,children:[S,T]}),t[13]=S,t[14]=T,t[15]=E):E=t[15];let O;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,Z.jsx)(U,{className:`size-5`,strokeWidth:1.75}),t[16]=O):O=t[16];let k;t[17]===s.close?k=t[18]:(k=(0,Z.jsx)(h,{asChild:!0,children:(0,Z.jsx)(q,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 p-0`,"aria-label":s.close,children:O})}),t[17]=s.close,t[18]=k);let j;t[19]!==E||t[20]!==k?(j=(0,Z.jsxs)(`div`,{className:`flex min-w-0 shrink-0 items-center justify-between gap-2 border-b border-edge px-4 py-3 dark:border-edge`,children:[E,k]}),t[19]=E,t[20]=k,t[21]=j):j=t[21];let M;t[22]!==s.detailLoading||t[23]!==s.detailMessages||t[24]!==r||t[25]!==i?(M=r?(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:s.detailLoading}):i?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`dl`,{className:`mb-4 grid gap-2 text-xs text-fg-muted`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`dt`,{className:`text-fg-disabled`,children:`Key`}),(0,Z.jsx)(`dd`,{className:`mt-0.5 break-all font-mono text-fg`,children:i.key})]}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-4`,children:(0,Z.jsxs)(`span`,{children:[i.messageCount,` msgs · `,i.estimatedTokens,` tok`]})})]}),(0,Z.jsx)(`h3`,{className:`mb-2 text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:s.detailMessages}),(0,Z.jsx)(`ul`,{className:`space-y-3`,children:i.messages.map(De)})]}):null,t[22]=s.detailLoading,t[23]=s.detailMessages,t[24]=r,t[25]=i,t[26]=M):M=t[26];let N;t[27]===M?N=t[28]:(N=(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-4 py-3`,children:M}),t[27]=M,t[28]=N);let P;t[29]!==s.detailExport||t[30]!==p?(P=(0,Z.jsx)(q,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:p,children:s.detailExport}),t[29]=s.detailExport,t[30]=p,t[31]=P):P=t[31];let F;t[32]!==_||t[33]!==s.archive||t[34]!==s.unarchive||t[35]!==l||t[36]!==u?(F=_?(0,Z.jsx)(q,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:u,children:s.unarchive}):(0,Z.jsx)(q,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:l,children:s.archive}),t[32]=_,t[33]=s.archive,t[34]=s.unarchive,t[35]=l,t[36]=u,t[37]=F):F=t[37];let I;t[38]!==v||t[39]!==s.pin||t[40]!==s.unpin||t[41]!==d||t[42]!==f?(I=v?(0,Z.jsx)(q,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:f,children:s.unpin}):(0,Z.jsx)(q,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:d,children:s.pin}),t[38]=v,t[39]=s.pin,t[40]=s.unpin,t[41]=d,t[42]=f,t[43]=I):I=t[43];let L;t[44]!==s.delete||t[45]!==m?(L=(0,Z.jsx)(q,{type:`button`,variant:`secondary`,className:`text-sm text-red-600 hover:bg-red-50 dark:text-red-400 dark:hover:bg-red-950/40`,onClick:m,children:s.delete}),t[44]=s.delete,t[45]=m,t[46]=L):L=t[46];let R;t[47]!==P||t[48]!==F||t[49]!==I||t[50]!==L?(R=(0,Z.jsx)(`div`,{className:`shrink-0 border-t border-edge px-4 py-3 dark:border-edge`,children:(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[P,F,I,L]})}),t[47]=P,t[48]=F,t[49]=I,t[50]=L,t[51]=R):R=t[51];let z;t[52]!==j||t[53]!==N||t[54]!==R?(z=(0,Z.jsxs)(ee,{children:[b,(0,Z.jsxs)(ce,{className:x,"aria-describedby":void 0,children:[j,N,R]})]}),t[52]=j,t[53]=N,t[54]=R,t[55]=z):z=t[55];let V;return t[56]!==n||t[57]!==y||t[58]!==z?(V=(0,Z.jsx)(te,{open:n,onOpenChange:y,children:z}),t[56]=n,t[57]=y,t[58]=z,t[59]=V):V=t[59],V}function De(e){return(0,Z.jsxs)(`li`,{className:`rounded-lg border border-edge-subtle bg-surface-hover/50 p-2 dark:border-edge`,children:[(0,Z.jsx)(`div`,{className:`mb-1 text-[10px] font-medium uppercase text-fg-subtle`,children:e.role}),(0,Z.jsx)(`pre`,{className:`max-h-40 overflow-auto whitespace-pre-wrap break-words font-mono text-[11px] leading-relaxed text-fg-muted`,children:Te(e.content)})]},`${e.timestamp??``}-${e.role}-${Te(e.content).slice(0,24)}`)}var Oe=20;function ke(e,t){return e.replace(/\{\{(\w+)\}\}/g,(e,n)=>String(t[n]??``))}var Ae=new Set([`all`,`active`,`pinned`,`archived`]),je=new Set([`grid`,`list`]);function Me(e){let t=e.get(`status`),n=e.get(`view`);return{searchInput:e.get(`q`)??``,debouncedSearch:(e.get(`q`)??``).trim(),statusFilter:Ae.has(t)?t:`all`,viewMode:je.has(n)?n:`grid`,channelFilter:(e.get(`channel`)??``).trim(),sessions:[],loading:!1,error:null,hasMore:!1,stats:null,detailOpen:!1,detailLoading:!1,detailSession:null,confirmOpen:!1,confirmKey:null}}function Ne(){let e=a(i(e=>e.language)),t=e.sessions,n=c(e=>e.token),r=!!n,{data:o,mutate:l}=s(r?[`gateway-chat-agents`,n]:null,O,{revalidateOnFocus:!1}),m=o?.defaultId??`main`,h=o?.items??[],[_,v]=d(),[b,C]=(0,X.useReducer)(y,_,Me),{searchInput:k,debouncedSearch:j,statusFilter:P,viewMode:F,channelFilter:z,sessions:V,loading:U,error:W,hasMore:K,stats:J,detailOpen:se,detailLoading:fe,detailSession:Y,confirmOpen:pe,confirmKey:me}=b;(0,X.useEffect)(()=>{let e=setTimeout(()=>{let e=k.trim();j!==e&&C({type:`patch`,patch:{debouncedSearch:e}})},300);return()=>clearTimeout(e)},[k,j]);let he=_.toString(),_e=(0,X.useRef)(he);if(_e.current!==he){_e.current=he;let e=_.get(`q`)??``,t=_.get(`status`),n=_.get(`view`),r=(_.get(`channel`)??``).trim(),i=Ae.has(t)?t:`all`,a=je.has(n)?n:`grid`,o=e.trim();C({type:`patch`,patch:{...k===e?{}:{searchInput:e},...j===o?{}:{debouncedSearch:o},...P===i?{}:{statusFilter:i},...F===a?{}:{viewMode:a},...z===r?{}:{channelFilter:r}}})}(0,X.useEffect)(()=>{let e=new URLSearchParams(_),t=j.trim();t?e.set(`q`,t):e.delete(`q`),P===`all`?e.delete(`status`):e.set(`status`,P),F===`grid`?e.delete(`view`):e.set(`view`,F),z?e.set(`channel`,z):e.delete(`channel`),e.toString()!==_.toString()&&v(e,{replace:!0})},[j,_,v,P,F,z]),(0,X.useEffect)(()=>{if(!r)return;let e=!1;return(async()=>{C({type:`patch`,patch:{loading:!0,error:null}});try{let t=await R({limit:Oe,offset:0,...j?{search:j}:{},...P===`all`?{}:{status:P},...z?{channel:z}:{}});if(e)return;C({type:`patch`,patch:{sessions:t.items,hasMore:t.hasMore}})}catch(n){e||C({type:`patch`,patch:{error:n instanceof Error?n.message:t.loadError}})}finally{e||C({type:`patch`,patch:{loading:!1}})}})(),()=>{e=!0}},[r,j,P,z,t.loadError]),(0,X.useEffect)(()=>{r&&G().then(e=>C({type:`patch`,patch:{stats:e}})).catch(()=>{})},[r]),(0,X.useEffect)(()=>{if(!r)return;let e=()=>void l();return window.addEventListener(`config-reload`,e),()=>window.removeEventListener(`config-reload`,e)},[r,l]),(0,X.useEffect)(()=>{if(!r)return;let e=e=>{let t=e.detail;!t?.key||t.name===void 0||C({type:`patch`,patch:{sessions:V.map(e=>e.key===t.key?{...e,name:t.name}:e),detailSession:Y&&Y.key===t.key?{...Y,name:t.name}:Y}})};return window.addEventListener(`session-updated`,e),()=>{window.removeEventListener(`session-updated`,e)}},[r,V,Y]);let ve=(0,X.useCallback)(async()=>{if(!(!r||U||!K)){C({type:`patch`,patch:{loading:!0,error:null}});try{let e=await R({limit:Oe,offset:V.length,...j?{search:j}:{},...P===`all`?{}:{status:P},...z?{channel:z}:{}});C({type:`patch`,patch:{sessions:[...V,...e.items],hasMore:e.hasMore}})}catch(e){C({type:`patch`,patch:{error:e instanceof Error?e.message:t.loadError}})}finally{C({type:`patch`,patch:{loading:!1}})}}},[r,U,K,V.length,j,P,z,t.loadError]),ye=(0,X.useCallback)((e,t)=>{C({type:`patch`,patch:{sessions:V.map(n=>n.key===e?{...n,status:t}:n),detailSession:Y&&Y.key===e?{...Y,status:t}:Y}})},[V,Y]),Q=(0,X.useCallback)(async e=>{C({type:`patch`,patch:{detailOpen:!0,detailLoading:!0,detailSession:null}});try{C({type:`patch`,patch:{detailSession:await re(e)}})}catch{C({type:`patch`,patch:{detailOpen:!1}})}finally{C({type:`patch`,patch:{detailLoading:!1}})}},[]),be=e=>{Q(e)},$=async(e,t)=>{if(t===`continue`){window.dispatchEvent(new CustomEvent(`navigate-to-chat`,{detail:{sessionKey:e},bubbles:!0}));return}if(t===`delete`){C({type:`patch`,patch:{confirmKey:e,confirmOpen:!0}});return}try{switch(t){case`archive`:await u(e),ye(e,`archived`);break;case`unarchive`:await ie(e),ye(e,`active`);break;case`pin`:await E(e),ye(e,`pinned`);break;case`unpin`:await ae(e),ye(e,`active`);break;case`export`:{let t=await oe(e),n=new Blob([t],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`session-${e.replace(/[^a-z0-9]/gi,`_`)}.json`,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r);break}default:break}G().then(e=>C({type:`patch`,patch:{stats:e}})).catch(()=>{})}catch{}},xe=async e=>{try{await M(e),C({type:`patch`,patch:{sessions:V.filter(t=>t.key!==e),detailSession:Y?.key===e?null:Y,...Y?.key===e?{detailOpen:!1}:{}}}),G().then(e=>C({type:`patch`,patch:{stats:e}})).catch(()=>{})}catch{}},Se={continueChat:t.continueChat,archive:t.archive,unarchive:t.unarchive,pin:t.pin,unpin:t.unpin,export:t.export,delete:t.delete,unnamedSession:e.chat.newSession},Ce={close:t.close,detailLoading:t.detailLoading,detailMessages:t.detailMessages,detailExport:t.detailExport,archive:t.archive,unarchive:t.unarchive,pin:t.pin,unpin:t.unpin,delete:t.delete,unnamedSession:e.chat.newSession},Te=[{key:`all`,label:t.filterAll,icon:f},{key:`active`,label:t.filterActive,icon:S},{key:`pinned`,label:t.filterPinned,icon:N},{key:`archived`,label:t.filterArchived,icon:w}],De=(()=>{let e=Object.entries(J?.byChannel??{}).sort((e,t)=>t[1]-e[1]).slice(0,6).map(([e])=>e),t=new Set(e);for(let n of[`telegram`,`weixin`,`feishu`])t.has(n)||(e.push(n),t.add(n));return e.slice(0,8)})();return r?(0,Z.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-x-hidden bg-surface-panel`,children:[(0,Z.jsxs)(`div`,{className:`mx-auto flex w-full min-w-0 max-w-2xl flex-col gap-4 px-4 py-6 sm:px-6 lg:max-w-app-main lg:px-8`,children:[(0,Z.jsx)(we,{hasToken:r}),(0,Z.jsxs)(`header`,{className:`flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Z.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight text-fg`,children:t.title}),(0,Z.jsxs)(`div`,{className:`flex w-full min-w-0 items-center gap-2 rounded-xl bg-surface-base px-3 py-2 transition-colors sm:max-w-md dark:bg-surface-hover/40`,children:[(0,Z.jsx)(T,{className:`size-4 shrink-0 text-fg-disabled`,strokeWidth:1.75,"aria-hidden":!0}),(0,Z.jsx)(`input`,{type:`search`,value:k,onChange:e=>C({type:`patch`,patch:{searchInput:e.target.value}}),placeholder:t.searchPlaceholder,"data-debounced-query":j||void 0,className:`min-w-0 flex-1 border-0 bg-transparent text-sm text-fg placeholder:text-fg-disabled focus:outline-none focus:ring-0`})]})]}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:Te.map(({key:e,label:t,icon:n})=>(0,Z.jsxs)(`button`,{type:`button`,"aria-pressed":P===e,onClick:()=>C({type:`patch`,patch:{statusFilter:e}}),className:A(`inline-flex items-center gap-1.5 rounded-xl px-3 py-2 text-sm font-medium`,H.transition,H.focusRingPanel,P===e?`bg-accent-soft text-accent-fg`:`bg-surface-base text-fg-muted hover:bg-surface-hover hover:text-fg dark:bg-surface-hover/35`),children:[(0,Z.jsx)(n,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),t]},e))}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-medium text-fg-subtle`,children:t.filterChannelLabel}),(0,Z.jsx)(`button`,{type:`button`,"aria-pressed":!z,onClick:()=>C({type:`patch`,patch:{channelFilter:``}}),className:A(`inline-flex items-center rounded-xl px-3 py-2 text-sm font-medium`,H.transition,H.focusRingPanel,z?`bg-surface-base text-fg-muted hover:bg-surface-hover hover:text-fg dark:bg-surface-hover/35`:`bg-accent-soft text-accent-fg`),children:t.filterChannelAll}),De.map(e=>(0,Z.jsxs)(`button`,{type:`button`,"aria-pressed":z===e,onClick:()=>C({type:`patch`,patch:{channelFilter:e}}),className:A(`inline-flex items-center rounded-xl px-3 py-2 text-sm font-medium`,H.transition,H.focusRingPanel,z===e?`bg-accent-soft text-accent-fg`:`bg-surface-base text-fg-muted hover:bg-surface-hover hover:text-fg dark:bg-surface-hover/35`),children:[e,J?.byChannel?.[e]==null?null:(0,Z.jsx)(`span`,{className:`ml-2 rounded-full bg-surface-hover px-2 py-0.5 text-[11px] text-fg-subtle`,children:J.byChannel[e]})]},e))]}),J?(0,Z.jsx)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-4`,children:[[J.totalSessions,t.totalSessions],[J.activeSessions,t.activeSessions],[J.pinnedSessions,t.pinnedSessions],[J.archivedSessions,t.archivedSessions]].map(([e,t])=>(0,Z.jsxs)(`div`,{className:`rounded-xl bg-surface-base p-3 dark:bg-surface-hover/30`,children:[(0,Z.jsx)(`div`,{className:`text-lg font-semibold tabular-nums text-fg`,children:e}),(0,Z.jsx)(`div`,{className:`text-xs text-fg-muted`,children:t})]},t))}):null,W?(0,Z.jsx)(`div`,{className:`rounded-lg border border-edge bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-edge dark:bg-red-950/40 dark:text-red-300`,children:W}):null,(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Z.jsx)(`p`,{className:`text-xs text-fg-muted`,children:ke(t.sessionCount,{count:V.length})}),(0,Z.jsxs)(`div`,{className:I,role:`group`,"aria-label":t.layoutToggleGroup,children:[(0,Z.jsx)(q,{type:`button`,variant:`segmented`,title:t.gridView,"aria-pressed":F===`grid`,onClick:()=>C({type:`patch`,patch:{viewMode:`grid`}}),className:A(ne,`size-7 p-0`,F===`grid`&&`bg-surface-panel shadow-sm dark:bg-surface-panel dark:shadow-sm dark:ring-1 dark:ring-edge-strong/40`,F===`grid`&&`text-accent-fg`),children:(0,Z.jsx)(ue,{className:`size-3.5`,strokeWidth:1.5})}),(0,Z.jsx)(q,{type:`button`,variant:`segmented`,title:t.listView,"aria-pressed":F===`list`,onClick:()=>C({type:`patch`,patch:{viewMode:`list`}}),className:A(ne,`size-9 p-0`,F===`list`&&`bg-surface-panel shadow-sm dark:bg-surface-panel dark:shadow-sm dark:ring-1 dark:ring-edge-strong/40`,F===`list`&&`text-accent-fg`),children:(0,Z.jsx)(x,{className:`size-3.5`,strokeWidth:1.5})})]})]}),U&&V.length===0?(0,Z.jsx)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:Array.from({length:6}).map((e,t)=>(0,Z.jsx)(`div`,{className:`h-40 animate-pulse rounded-xl bg-surface-hover/60 dark:bg-surface-hover/40`},t))}):V.length===0?(0,Z.jsxs)(`div`,{className:`flex flex-col items-center justify-center rounded-2xl bg-surface-base py-16 text-center dark:bg-surface-hover/25`,children:[(0,Z.jsx)(L,{className:`mb-3 size-12 text-fg-disabled`,strokeWidth:1.25,"aria-hidden":!0}),(0,Z.jsx)(`p`,{className:`text-base font-semibold text-fg`,children:t.noSessions}),(0,Z.jsx)(`p`,{className:`mt-1 max-w-sm text-sm text-fg-muted`,children:t.noSessionsDescription}),(0,Z.jsx)(q,{variant:`primary`,className:`mt-6`,onClick:()=>{window.dispatchEvent(new CustomEvent(`navigate-to-chat`,{detail:{sessionKey:``},bubbles:!0}))},children:t.startNewChat})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:A(`grid min-w-0 gap-3`,F===`grid`?`sm:grid-cols-2 lg:grid-cols-3`:`grid-cols-1`),"data-debounced-query":j||void 0,children:V.map(e=>{let t=p(e,m);return(0,Z.jsx)(ge,{session:e,variant:F,labels:Se,sessionAgentId:t,sessionAgentAvatar:de(t,h),onOpen:()=>be(e.key),onAction:t=>void $(e.key,t)},e.key)})}),K?(0,Z.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,Z.jsx)(q,{type:`button`,variant:`secondary`,disabled:U,onClick:()=>void ve(),children:t.loadMore})}):null]})]}),(0,Z.jsx)(Ee,{open:se,loading:fe,session:Y,sessionAgentId:Y?p(Y,m):void 0,sessionAgentAvatar:Y?de(p(Y,m),h):void 0,labels:Ce,onClose:()=>{C({type:`patch`,patch:{detailOpen:!1,detailSession:null}})},onArchive:()=>Y&&void $(Y.key,`archive`),onUnarchive:()=>Y&&void $(Y.key,`unarchive`),onPin:()=>Y&&void $(Y.key,`pin`),onUnpin:()=>Y&&void $(Y.key,`unpin`),onExport:()=>Y&&void $(Y.key,`export`),onDelete:()=>Y&&C({type:`patch`,patch:{confirmKey:Y.key,confirmOpen:!0}})}),(0,Z.jsx)(te,{open:pe,onOpenChange:e=>C({type:`patch`,patch:{confirmOpen:e}}),children:(0,Z.jsxs)(ee,{children:[(0,Z.jsx)(g,{className:A(`xopc-dialog-overlay fixed inset-0 bg-scrim`,D)}),(0,Z.jsxs)(ce,{className:A(`xopc-dialog-content fixed left-1/2 top-1/2 w-[min(100%-2rem,24rem)] -translate-x-1/2 -translate-y-1/2 rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`,le),children:[(0,Z.jsx)(B,{className:`text-base font-semibold text-fg`,children:t.deleteSessionTitle}),(0,Z.jsx)(`p`,{className:`mt-2 text-sm text-fg-muted`,children:me?ke(t.deleteSessionMessage,{name:V.find(e=>e.key===me)?.name?.trim()||e.chat.newSession}):``}),(0,Z.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,Z.jsx)(q,{type:`button`,variant:`secondary`,onClick:()=>C({type:`patch`,patch:{confirmOpen:!1}}),children:t.cancel}),(0,Z.jsx)(q,{type:`button`,variant:`primary`,className:`bg-red-600 hover:bg-red-700`,onClick:()=>{me&&xe(me),C({type:`patch`,patch:{confirmOpen:!1,confirmKey:null}})},children:t.delete})]})]})]})})]}):(0,Z.jsx)(`div`,{className:`mx-auto w-full max-w-2xl px-4 py-16 text-center text-sm text-fg-muted sm:px-8 lg:max-w-app-main`,children:t.needToken})}export{Ne as SessionsPage};
|
|
1
|
+
import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{i,o as a,t as o}from"./url-DpFBIyN9.js";import{i as s}from"./vendor-swr-BIWyz7Rc.js";import{a as c,n as l}from"./fetch-BLLOP2CM.js";import{$n as u,$o as d,Ba as f,Bn as p,Ca as m,Cr as h,Dr as ee,Er as g,Go as _,M as v,N as y,Oa as b,Or as te,Ra as x,So as S,Vn as C,Wo as w,Yi as T,ar as E,bn as D,cr as O,da as k,di as A,dr as j,er as M,fa as N,fi as P,fo as F,hr as I,io as L,ir as R,j as z,kr as B,li as V,mr as ne,ni as H,nr as re,or as ie,pi as U,po as W,rr as G,sr as ae,ti as K,tr as oe,ui as q,ur as J,wi as se,wr as ce,yn as le,za as ue,zn as de}from"./index-0tS9lV85.js";import{n as fe,t as Y}from"./settings-form-section-DXMCEW1d.js";var X=e(t(),1),pe=n(),Z=r();function me(e){let t=new Date(e),n=Math.floor((new Date().getTime()-t.getTime())/(1e3*60*60*24));return n===0?t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}):n===1?`Yesterday`:n<7?t.toLocaleDateString([],{weekday:`short`}):t.toLocaleDateString([],{month:`short`,day:`numeric`})}function he(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function ge(e){let t=(0,pe.c)(105),{session:n,variant:r,labels:i,sessionAgentId:a,sessionAgentAvatar:o,onOpen:s,onAction:c}=e,l;t[0]!==i.unnamedSession||t[1]!==n.name?(l=n.name?.trim()||i.unnamedSession,t[0]=i.unnamedSession,t[1]=n.name,t[2]=l):l=t[2];let u=l,d;t[3]===n.name?d=t[4]:(d=n.name?.trim(),t[3]=n.name,t[4]=d);let f=!!d,p=n.status===`archived`,h=n.status===`pinned`,ee=r===`list`&&`sm:flex-row sm:items-center sm:gap-4`,g;t[5]===ee?g=t[6]:(g=A(`group flex min-w-0 w-full max-w-full cursor-pointer flex-col rounded-xl bg-surface-base text-left transition-colors duration-150 ease-out`,`hover:bg-surface-hover active:scale-[0.99]`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-surface-panel`,ee),t[5]=ee,t[6]=g);let v;t[7]===s?v=t[8]:(v=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),s())},t[7]=s,t[8]=v);let y=r===`list`&&`sm:py-3`,b;t[9]===y?b=t[10]:(b=A(`flex min-w-0 items-start justify-between gap-2 bg-surface-hover/35 px-3 py-2 dark:bg-surface-hover/25`,y),t[9]=y,t[10]=b);let te;t[11]===n.sourceChannel?te=t[12]:(te=(0,Z.jsx)(`div`,{className:`flex min-w-0 items-center gap-2`,children:(0,Z.jsx)(`span`,{className:`truncate text-[11px] font-medium uppercase tracking-wide text-fg-subtle`,children:n.sourceChannel})}),t[11]=n.sourceChannel,t[12]=te);let x;t[13]===h?x=t[14]:(x=h?(0,Z.jsx)(N,{className:`size-3.5 text-accent-fg`,strokeWidth:1.75,"aria-hidden":!0}):null,t[13]=h,t[14]=x);let S;t[15]===n.updatedAt?S=t[16]:(S=me(n.updatedAt),t[15]=n.updatedAt,t[16]=S);let T;t[17]===S?T=t[18]:(T=(0,Z.jsx)(`span`,{children:S}),t[17]=S,t[18]=T);let E;t[19]!==T||t[20]!==x?(E=(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5 text-xs text-fg-muted`,children:[x,T]}),t[19]=T,t[20]=x,t[21]=E):E=t[21];let D;t[22]!==E||t[23]!==b||t[24]!==te?(D=(0,Z.jsxs)(`div`,{className:b,children:[te,E]}),t[22]=E,t[23]=b,t[24]=te,t[25]=D):D=t[25];let O=r===`list`&&`sm:py-3`,j;t[26]===O?j=t[27]:(j=A(`min-w-0 flex-1 px-3 py-2`,O),t[26]=O,t[27]=j);let M=r===`list`&&`sm:items-start`,I;t[28]===M?I=t[29]:(I=A(`flex gap-3`,M),t[28]=M,t[29]=I);let L;t[30]!==o||t[31]!==a?(L=(0,Z.jsx)(C,{agentId:a,avatar:o,size:40,className:`size-10 shrink-0 ring-1 ring-edge/60 dark:ring-edge`}),t[30]=o,t[31]=a,t[32]=L):L=t[32];let R;t[33]===u?R=t[34]:(R=(0,Z.jsx)(`div`,{className:`min-w-0 max-w-full truncate text-sm font-semibold text-fg`,title:u,children:u}),t[33]=u,t[34]=R);let z;t[35]!==n.key||t[36]!==f?(z=f?(0,Z.jsx)(`div`,{className:`mt-0.5 min-w-0 max-w-full truncate font-mono text-[11px] text-fg-subtle`,title:n.key,children:n.key}):null,t[35]=n.key,t[36]=f,t[37]=z):z=t[37];let B;t[38]!==R||t[39]!==z?(B=(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[R,z]}),t[38]=R,t[39]=z,t[40]=B):B=t[40];let V;t[41]!==I||t[42]!==L||t[43]!==B?(V=(0,Z.jsxs)(`div`,{className:I,children:[L,B]}),t[41]=I,t[42]=L,t[43]=B,t[44]=V):V=t[44];let ne;t[45]===Symbol.for(`react.memo_cache_sentinel`)?(ne=(0,Z.jsx)(m,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0}),t[45]=ne):ne=t[45];let H;t[46]===n.messageCount?H=t[47]:(H=(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[ne,n.messageCount]}),t[46]=n.messageCount,t[47]=H);let re;t[48]===Symbol.for(`react.memo_cache_sentinel`)?(re=(0,Z.jsx)(P,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0}),t[48]=re):re=t[48];let ie;t[49]===n.estimatedTokens?ie=t[50]:(ie=he(n.estimatedTokens),t[49]=n.estimatedTokens,t[50]=ie);let U;t[51]===ie?U=t[52]:(U=(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[re,ie]}),t[51]=ie,t[52]=U);let W;t[53]!==H||t[54]!==U?(W=(0,Z.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-3 text-xs text-fg-muted`,children:[H,U]}),t[53]=H,t[54]=U,t[55]=W):W=t[55];let G;t[56]===n.tags?G=t[57]:(G=n.tags.length>0?(0,Z.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-1`,children:[n.tags.slice(0,3).map(ye),n.tags.length>3?(0,Z.jsxs)(`span`,{className:`text-[11px] text-fg-disabled`,children:[`+`,n.tags.length-3]}):null]}):null,t[56]=n.tags,t[57]=G);let ae;t[58]!==j||t[59]!==V||t[60]!==W||t[61]!==G?(ae=(0,Z.jsxs)(`div`,{className:j,children:[V,W,G]}),t[58]=j,t[59]=V,t[60]=W,t[61]=G,t[62]=ae):ae=t[62];let oe;t[63]===c?oe=t[64]:(oe=()=>c(`continue`),t[63]=c,t[64]=oe);let q;t[65]===Symbol.for(`react.memo_cache_sentinel`)?(q=(0,Z.jsx)(m,{className:`size-4`,strokeWidth:1.75}),t[65]=q):q=t[65];let J;t[66]!==i.continueChat||t[67]!==oe?(J=(0,Z.jsx)(`button`,{type:`button`,className:K,title:i.continueChat,"aria-label":i.continueChat,onClick:oe,children:q}),t[66]=i.continueChat,t[67]=oe,t[68]=J):J=t[68];let ce;t[69]!==p||t[70]!==i.archive||t[71]!==i.unarchive||t[72]!==c?(ce=p?(0,Z.jsx)(`button`,{type:`button`,className:K,title:i.unarchive,"aria-label":i.unarchive,onClick:()=>c(`unarchive`),children:(0,Z.jsx)(_,{className:`size-4`,strokeWidth:1.75})}):(0,Z.jsx)(`button`,{type:`button`,className:K,title:i.archive,"aria-label":i.archive,onClick:()=>c(`archive`),children:(0,Z.jsx)(w,{className:`size-4`,strokeWidth:1.75})}),t[69]=p,t[70]=i.archive,t[71]=i.unarchive,t[72]=c,t[73]=ce):ce=t[73];let le;t[74]!==h||t[75]!==i.pin||t[76]!==i.unpin||t[77]!==c?(le=h?(0,Z.jsx)(`button`,{type:`button`,className:K,title:i.unpin,"aria-label":i.unpin,onClick:()=>c(`unpin`),children:(0,Z.jsx)(k,{className:`size-4`,strokeWidth:1.75})}):(0,Z.jsx)(`button`,{type:`button`,className:K,title:i.pin,"aria-label":i.pin,onClick:()=>c(`pin`),children:(0,Z.jsx)(N,{className:`size-4`,strokeWidth:1.75})}),t[74]=h,t[75]=i.pin,t[76]=i.unpin,t[77]=c,t[78]=le):le=t[78];let ue;t[79]===c?ue=t[80]:(ue=()=>c(`export`),t[79]=c,t[80]=ue);let de;t[81]===Symbol.for(`react.memo_cache_sentinel`)?(de=(0,Z.jsx)(F,{className:`size-4`,strokeWidth:1.75}),t[81]=de):de=t[81];let fe;t[82]!==i.export||t[83]!==ue?(fe=(0,Z.jsx)(`button`,{type:`button`,className:K,title:i.export,"aria-label":i.export,onClick:ue,children:de}),t[82]=i.export,t[83]=ue,t[84]=fe):fe=t[84];let Y;t[85]===Symbol.for(`react.memo_cache_sentinel`)?(Y=A(K,`text-red-600 hover:bg-red-50 dark:text-red-400 dark:hover:bg-red-950/40`),t[85]=Y):Y=t[85];let X;t[86]===c?X=t[87]:(X=()=>c(`delete`),t[86]=c,t[87]=X);let ge;t[88]===Symbol.for(`react.memo_cache_sentinel`)?(ge=(0,Z.jsx)(se,{className:`size-4`,strokeWidth:1.75}),t[88]=ge):ge=t[88];let Q;t[89]!==i.delete||t[90]!==X?(Q=(0,Z.jsx)(`button`,{type:`button`,className:Y,title:i.delete,"aria-label":i.delete,onClick:X,children:ge}),t[89]=i.delete,t[90]=X,t[91]=Q):Q=t[91];let be;t[92]!==J||t[93]!==ce||t[94]!==le||t[95]!==fe||t[96]!==Q?(be=(0,Z.jsxs)(`div`,{role:`group`,className:`flex flex-wrap items-center gap-0.5 border-t border-edge-subtle/80 bg-surface-hover/25 p-2 dark:border-edge-subtle`,onClick:ve,onKeyDown:_e,children:[J,ce,le,fe,Q]}),t[92]=J,t[93]=ce,t[94]=le,t[95]=fe,t[96]=Q,t[97]=be):be=t[97];let $;return t[98]!==s||t[99]!==D||t[100]!==ae||t[101]!==g||t[102]!==be||t[103]!==v?($=(0,Z.jsxs)(`div`,{role:`button`,tabIndex:0,className:g,onClick:s,onKeyDown:v,children:[D,ae,be]}),t[98]=s,t[99]=D,t[100]=ae,t[101]=g,t[102]=be,t[103]=v,t[104]=$):$=t[104],$}function _e(e){return e.stopPropagation()}function ve(e){return e.stopPropagation()}function ye(e){return(0,Z.jsx)(`span`,{className:`max-w-full break-words rounded-md bg-surface-hover px-1.5 py-0.5 text-[11px] text-fg-muted`,children:e},e)}function Q(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function be(e){return e===`main`||e===`per-peer`||e===`per-channel-peer`||e===`per-account-channel-peer`?e:`main`}function $(e){let t=Q(e)?e:{},n=Q(t.session)?t.session:{},r=Q(n.storage)?n.storage:{},i=typeof r.pruneAfterDays==`number`&&Number.isFinite(r.pruneAfterDays)?Math.max(0,Math.floor(r.pruneAfterDays)):typeof r.pruneAfterMs==`number`&&Number.isFinite(r.pruneAfterMs)?Math.max(0,Math.round(r.pruneAfterMs/864e5)):null,a=typeof r.maxEntries==`number`&&Number.isFinite(r.maxEntries)?Math.max(1,Math.floor(r.maxEntries)):null;return{dmScope:be(n.dmScope),pruneAfterDays:i,maxEntries:a}}async function xe(e){await l(o(`/api/config`),{method:`PATCH`,body:JSON.stringify({session:{dmScope:e.dmScope,storage:{pruneAfterMs:e.pruneAfterDays===null?null:e.pruneAfterDays*864e5,maxEntries:e.maxEntries}}})}),J()}function Se(){return A(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,V,`dark:border-edge`)}var Ce=z();function we({hasToken:e}){let t=a(i(e=>e.language)).sessions.config,{data:n,isLoading:r}=j(e),o=(0,X.useMemo)(()=>n?.payload?.config===void 0?null:$(n.payload.config),[n]),[s,c]=(0,X.useReducer)(Ce,{form:null,baseline:null}),l=s.form,u=s.baseline,[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(null),h=(0,X.useRef)(!1),ee=(0,X.useRef)(null);v({enabled:e,parsed:o,dirty:h.current,trackedParsedRef:ee,dispatch:c,onResetDirty:()=>{h.current=!1}});let g=l&&u&&JSON.stringify(l)!==JSON.stringify(u),_=(0,X.useCallback)(e=>{h.current=!0,c({type:`patch`,patch:e})},[]);return!e||!l?r?(0,Z.jsx)(Y,{children:(0,Z.jsx)(b,{className:`size-4 animate-spin text-fg-muted`})}):null:(0,Z.jsxs)(Y,{children:[(0,Z.jsx)(fe,{icon:W,title:t.title,subtitle:t.hint}),(0,Z.jsxs)(`div`,{className:`mb-4 flex justify-end gap-2`,children:[(0,Z.jsx)(q,{type:`button`,variant:`secondary`,disabled:!g||d,onClick:()=>c({type:`discard`}),children:t.discard}),(0,Z.jsx)(q,{type:`button`,variant:`primary`,disabled:!g||d,onClick:()=>{(async()=>{f(!0),m(null);try{await xe(l),h.current=!1,c({type:`saved`,value:l})}catch(e){m(e instanceof Error?e.message:t.saveError)}finally{f(!1)}})()},children:d?t.saving:t.save})]}),p?(0,Z.jsx)(`p`,{className:`mb-3 text-sm text-red-600 dark:text-red-400`,children:p}):null,(0,Z.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,Z.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,children:t.dmScope}),(0,Z.jsxs)(`select`,{className:Se(),value:l.dmScope,onChange:e=>_({dmScope:e.target.value}),children:[(0,Z.jsx)(`option`,{value:`main`,children:t.dmScopeMain}),(0,Z.jsx)(`option`,{value:`per-peer`,children:t.dmScopePerPeer}),(0,Z.jsx)(`option`,{value:`per-channel-peer`,children:t.dmScopePerChannelPeer}),(0,Z.jsx)(`option`,{value:`per-account-channel-peer`,children:t.dmScopePerAccountChannelPeer})]}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:t.dmScopeHint})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,children:t.pruneAfterDays}),(0,Z.jsx)(`input`,{type:`number`,min:0,className:Se(),value:l.pruneAfterDays??``,placeholder:t.unsetPlaceholder,onChange:e=>{let t=e.target.value.trim();_({pruneAfterDays:t===``?null:Math.max(0,Math.floor(Number(t)||0))})}})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,children:t.maxEntries}),(0,Z.jsx)(`input`,{type:`number`,min:1,className:Se(),value:l.maxEntries??``,placeholder:t.unsetPlaceholder,onChange:e=>{let t=e.target.value.trim();_({maxEntries:t===``?null:Math.max(1,Math.floor(Number(t)||1))})}})]})]})]})}function Te(e){if(typeof e==`string`)return e.length>2e3?`${e.slice(0,2e3)}…`:e;try{let t=JSON.stringify(e,null,2);return t.length>2e3?`${t.slice(0,2e3)}…`:t}catch{return String(e)}}function Ee(e){let t=(0,pe.c)(60),{open:n,loading:r,session:i,sessionAgentId:a,sessionAgentAvatar:o,labels:s,onClose:c,onArchive:l,onUnarchive:u,onPin:d,onUnpin:f,onExport:p,onDelete:m}=e,_=i?.status===`archived`,v=i?.status===`pinned`,y;t[0]===c?y=t[1]:(y=e=>!e&&c(),t[0]=c,t[1]=y);let b;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,Z.jsx)(g,{className:A(`xopc-dialog-overlay fixed inset-0 bg-scrim`,D)}),t[2]=b):b=t[2];let x;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(x=A(`xopc-drawer-right fixed right-0 top-0 flex size-full max-w-lg flex-col border-l border-edge bg-surface-panel shadow-popover outline-none`,le,`dark:border-edge`),t[3]=x):x=t[3];let S;t[4]!==i||t[5]!==o||t[6]!==a?(S=i&&a?(0,Z.jsx)(C,{agentId:a,avatar:o,size:40,className:`size-10 shrink-0 ring-1 ring-edge/60 dark:ring-edge`}):null,t[4]=i,t[5]=o,t[6]=a,t[7]=S):S=t[7];let w;t[8]!==s.unnamedSession||t[9]!==i?.name?(w=i?.name?.trim()||s.unnamedSession,t[8]=s.unnamedSession,t[9]=i?.name,t[10]=w):w=t[10];let T;t[11]===w?T=t[12]:(T=(0,Z.jsx)(B,{className:`min-w-0 flex-1 truncate text-base font-semibold tracking-tight text-fg`,children:w}),t[11]=w,t[12]=T);let E;t[13]!==S||t[14]!==T?(E=(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-3`,children:[S,T]}),t[13]=S,t[14]=T,t[15]=E):E=t[15];let O;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,Z.jsx)(U,{className:`size-5`,strokeWidth:1.75}),t[16]=O):O=t[16];let k;t[17]===s.close?k=t[18]:(k=(0,Z.jsx)(h,{asChild:!0,children:(0,Z.jsx)(q,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 p-0`,"aria-label":s.close,children:O})}),t[17]=s.close,t[18]=k);let j;t[19]!==E||t[20]!==k?(j=(0,Z.jsxs)(`div`,{className:`flex min-w-0 shrink-0 items-center justify-between gap-2 border-b border-edge px-4 py-3 dark:border-edge`,children:[E,k]}),t[19]=E,t[20]=k,t[21]=j):j=t[21];let M;t[22]!==s.detailLoading||t[23]!==s.detailMessages||t[24]!==r||t[25]!==i?(M=r?(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:s.detailLoading}):i?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`dl`,{className:`mb-4 grid gap-2 text-xs text-fg-muted`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`dt`,{className:`text-fg-disabled`,children:`Key`}),(0,Z.jsx)(`dd`,{className:`mt-0.5 break-all font-mono text-fg`,children:i.key})]}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-4`,children:(0,Z.jsxs)(`span`,{children:[i.messageCount,` msgs · `,i.estimatedTokens,` tok`]})})]}),(0,Z.jsx)(`h3`,{className:`mb-2 text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:s.detailMessages}),(0,Z.jsx)(`ul`,{className:`space-y-3`,children:i.messages.map(De)})]}):null,t[22]=s.detailLoading,t[23]=s.detailMessages,t[24]=r,t[25]=i,t[26]=M):M=t[26];let N;t[27]===M?N=t[28]:(N=(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-4 py-3`,children:M}),t[27]=M,t[28]=N);let P;t[29]!==s.detailExport||t[30]!==p?(P=(0,Z.jsx)(q,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:p,children:s.detailExport}),t[29]=s.detailExport,t[30]=p,t[31]=P):P=t[31];let F;t[32]!==_||t[33]!==s.archive||t[34]!==s.unarchive||t[35]!==l||t[36]!==u?(F=_?(0,Z.jsx)(q,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:u,children:s.unarchive}):(0,Z.jsx)(q,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:l,children:s.archive}),t[32]=_,t[33]=s.archive,t[34]=s.unarchive,t[35]=l,t[36]=u,t[37]=F):F=t[37];let I;t[38]!==v||t[39]!==s.pin||t[40]!==s.unpin||t[41]!==d||t[42]!==f?(I=v?(0,Z.jsx)(q,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:f,children:s.unpin}):(0,Z.jsx)(q,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:d,children:s.pin}),t[38]=v,t[39]=s.pin,t[40]=s.unpin,t[41]=d,t[42]=f,t[43]=I):I=t[43];let L;t[44]!==s.delete||t[45]!==m?(L=(0,Z.jsx)(q,{type:`button`,variant:`secondary`,className:`text-sm text-red-600 hover:bg-red-50 dark:text-red-400 dark:hover:bg-red-950/40`,onClick:m,children:s.delete}),t[44]=s.delete,t[45]=m,t[46]=L):L=t[46];let R;t[47]!==P||t[48]!==F||t[49]!==I||t[50]!==L?(R=(0,Z.jsx)(`div`,{className:`shrink-0 border-t border-edge px-4 py-3 dark:border-edge`,children:(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[P,F,I,L]})}),t[47]=P,t[48]=F,t[49]=I,t[50]=L,t[51]=R):R=t[51];let z;t[52]!==j||t[53]!==N||t[54]!==R?(z=(0,Z.jsxs)(ee,{children:[b,(0,Z.jsxs)(ce,{className:x,"aria-describedby":void 0,children:[j,N,R]})]}),t[52]=j,t[53]=N,t[54]=R,t[55]=z):z=t[55];let V;return t[56]!==n||t[57]!==y||t[58]!==z?(V=(0,Z.jsx)(te,{open:n,onOpenChange:y,children:z}),t[56]=n,t[57]=y,t[58]=z,t[59]=V):V=t[59],V}function De(e){return(0,Z.jsxs)(`li`,{className:`rounded-lg border border-edge-subtle bg-surface-hover/50 p-2 dark:border-edge`,children:[(0,Z.jsx)(`div`,{className:`mb-1 text-[10px] font-medium uppercase text-fg-subtle`,children:e.role}),(0,Z.jsx)(`pre`,{className:`max-h-40 overflow-auto whitespace-pre-wrap break-words font-mono text-[11px] leading-relaxed text-fg-muted`,children:Te(e.content)})]},`${e.timestamp??``}-${e.role}-${Te(e.content).slice(0,24)}`)}var Oe=20;function ke(e,t){return e.replace(/\{\{(\w+)\}\}/g,(e,n)=>String(t[n]??``))}var Ae=new Set([`all`,`active`,`pinned`,`archived`]),je=new Set([`grid`,`list`]);function Me(e){let t=e.get(`status`),n=e.get(`view`);return{searchInput:e.get(`q`)??``,debouncedSearch:(e.get(`q`)??``).trim(),statusFilter:Ae.has(t)?t:`all`,viewMode:je.has(n)?n:`grid`,channelFilter:(e.get(`channel`)??``).trim(),sessions:[],loading:!1,error:null,hasMore:!1,stats:null,detailOpen:!1,detailLoading:!1,detailSession:null,confirmOpen:!1,confirmKey:null}}function Ne(){let e=a(i(e=>e.language)),t=e.sessions,n=c(e=>e.token),r=!!n,{data:o,mutate:l}=s(r?[`gateway-chat-agents`,n]:null,O,{revalidateOnFocus:!1}),m=o?.defaultId??`main`,h=o?.items??[],[_,v]=d(),[b,C]=(0,X.useReducer)(y,_,Me),{searchInput:k,debouncedSearch:j,statusFilter:P,viewMode:F,channelFilter:z,sessions:V,loading:U,error:W,hasMore:K,stats:J,detailOpen:se,detailLoading:fe,detailSession:Y,confirmOpen:pe,confirmKey:me}=b;(0,X.useEffect)(()=>{let e=setTimeout(()=>{let e=k.trim();j!==e&&C({type:`patch`,patch:{debouncedSearch:e}})},300);return()=>clearTimeout(e)},[k,j]);let he=_.toString(),_e=(0,X.useRef)(he);if(_e.current!==he){_e.current=he;let e=_.get(`q`)??``,t=_.get(`status`),n=_.get(`view`),r=(_.get(`channel`)??``).trim(),i=Ae.has(t)?t:`all`,a=je.has(n)?n:`grid`,o=e.trim();C({type:`patch`,patch:{...k===e?{}:{searchInput:e},...j===o?{}:{debouncedSearch:o},...P===i?{}:{statusFilter:i},...F===a?{}:{viewMode:a},...z===r?{}:{channelFilter:r}}})}(0,X.useEffect)(()=>{let e=new URLSearchParams(_),t=j.trim();t?e.set(`q`,t):e.delete(`q`),P===`all`?e.delete(`status`):e.set(`status`,P),F===`grid`?e.delete(`view`):e.set(`view`,F),z?e.set(`channel`,z):e.delete(`channel`),e.toString()!==_.toString()&&v(e,{replace:!0})},[j,_,v,P,F,z]),(0,X.useEffect)(()=>{if(!r)return;let e=!1;return(async()=>{C({type:`patch`,patch:{loading:!0,error:null}});try{let t=await R({limit:Oe,offset:0,...j?{search:j}:{},...P===`all`?{}:{status:P},...z?{channel:z}:{}});if(e)return;C({type:`patch`,patch:{sessions:t.items,hasMore:t.hasMore}})}catch(n){e||C({type:`patch`,patch:{error:n instanceof Error?n.message:t.loadError}})}finally{e||C({type:`patch`,patch:{loading:!1}})}})(),()=>{e=!0}},[r,j,P,z,t.loadError]),(0,X.useEffect)(()=>{r&&G().then(e=>C({type:`patch`,patch:{stats:e}})).catch(()=>{})},[r]),(0,X.useEffect)(()=>{if(!r)return;let e=()=>void l();return window.addEventListener(`config-reload`,e),()=>window.removeEventListener(`config-reload`,e)},[r,l]),(0,X.useEffect)(()=>{if(!r)return;let e=e=>{let t=e.detail;!t?.key||t.name===void 0||C({type:`patch`,patch:{sessions:V.map(e=>e.key===t.key?{...e,name:t.name}:e),detailSession:Y&&Y.key===t.key?{...Y,name:t.name}:Y}})};return window.addEventListener(`session-updated`,e),()=>{window.removeEventListener(`session-updated`,e)}},[r,V,Y]);let ve=(0,X.useCallback)(async()=>{if(!(!r||U||!K)){C({type:`patch`,patch:{loading:!0,error:null}});try{let e=await R({limit:Oe,offset:V.length,...j?{search:j}:{},...P===`all`?{}:{status:P},...z?{channel:z}:{}});C({type:`patch`,patch:{sessions:[...V,...e.items],hasMore:e.hasMore}})}catch(e){C({type:`patch`,patch:{error:e instanceof Error?e.message:t.loadError}})}finally{C({type:`patch`,patch:{loading:!1}})}}},[r,U,K,V.length,j,P,z,t.loadError]),ye=(0,X.useCallback)((e,t)=>{C({type:`patch`,patch:{sessions:V.map(n=>n.key===e?{...n,status:t}:n),detailSession:Y&&Y.key===e?{...Y,status:t}:Y}})},[V,Y]),Q=(0,X.useCallback)(async e=>{C({type:`patch`,patch:{detailOpen:!0,detailLoading:!0,detailSession:null}});try{C({type:`patch`,patch:{detailSession:await re(e)}})}catch{C({type:`patch`,patch:{detailOpen:!1}})}finally{C({type:`patch`,patch:{detailLoading:!1}})}},[]),be=e=>{Q(e)},$=async(e,t)=>{if(t===`continue`){window.dispatchEvent(new CustomEvent(`navigate-to-chat`,{detail:{sessionKey:e},bubbles:!0}));return}if(t===`delete`){C({type:`patch`,patch:{confirmKey:e,confirmOpen:!0}});return}try{switch(t){case`archive`:await u(e),ye(e,`archived`);break;case`unarchive`:await ie(e),ye(e,`active`);break;case`pin`:await E(e),ye(e,`pinned`);break;case`unpin`:await ae(e),ye(e,`active`);break;case`export`:{let t=await oe(e),n=new Blob([t],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`session-${e.replace(/[^a-z0-9]/gi,`_`)}.json`,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r);break}default:break}G().then(e=>C({type:`patch`,patch:{stats:e}})).catch(()=>{})}catch{}},xe=async e=>{try{await M(e),C({type:`patch`,patch:{sessions:V.filter(t=>t.key!==e),detailSession:Y?.key===e?null:Y,...Y?.key===e?{detailOpen:!1}:{}}}),G().then(e=>C({type:`patch`,patch:{stats:e}})).catch(()=>{})}catch{}},Se={continueChat:t.continueChat,archive:t.archive,unarchive:t.unarchive,pin:t.pin,unpin:t.unpin,export:t.export,delete:t.delete,unnamedSession:e.chat.newSession},Ce={close:t.close,detailLoading:t.detailLoading,detailMessages:t.detailMessages,detailExport:t.detailExport,archive:t.archive,unarchive:t.unarchive,pin:t.pin,unpin:t.unpin,delete:t.delete,unnamedSession:e.chat.newSession},Te=[{key:`all`,label:t.filterAll,icon:f},{key:`active`,label:t.filterActive,icon:S},{key:`pinned`,label:t.filterPinned,icon:N},{key:`archived`,label:t.filterArchived,icon:w}],De=(()=>{let e=Object.entries(J?.byChannel??{}).sort((e,t)=>t[1]-e[1]).slice(0,6).map(([e])=>e),t=new Set(e);for(let n of[`telegram`,`weixin`,`feishu`])t.has(n)||(e.push(n),t.add(n));return e.slice(0,8)})();return r?(0,Z.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-x-hidden bg-surface-panel`,children:[(0,Z.jsxs)(`div`,{className:`mx-auto flex w-full min-w-0 max-w-2xl flex-col gap-4 px-4 py-6 sm:px-6 lg:max-w-app-main lg:px-8`,children:[(0,Z.jsx)(we,{hasToken:r}),(0,Z.jsxs)(`header`,{className:`flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Z.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight text-fg`,children:t.title}),(0,Z.jsxs)(`div`,{className:`flex w-full min-w-0 items-center gap-2 rounded-xl bg-surface-base px-3 py-2 transition-colors sm:max-w-md dark:bg-surface-hover/40`,children:[(0,Z.jsx)(T,{className:`size-4 shrink-0 text-fg-disabled`,strokeWidth:1.75,"aria-hidden":!0}),(0,Z.jsx)(`input`,{type:`search`,value:k,onChange:e=>C({type:`patch`,patch:{searchInput:e.target.value}}),placeholder:t.searchPlaceholder,"data-debounced-query":j||void 0,className:`min-w-0 flex-1 border-0 bg-transparent text-sm text-fg placeholder:text-fg-disabled focus:outline-none focus:ring-0`})]})]}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:Te.map(({key:e,label:t,icon:n})=>(0,Z.jsxs)(`button`,{type:`button`,"aria-pressed":P===e,onClick:()=>C({type:`patch`,patch:{statusFilter:e}}),className:A(`inline-flex items-center gap-1.5 rounded-xl px-3 py-2 text-sm font-medium`,H.transition,H.focusRingPanel,P===e?`bg-accent-soft text-accent-fg`:`bg-surface-base text-fg-muted hover:bg-surface-hover hover:text-fg dark:bg-surface-hover/35`),children:[(0,Z.jsx)(n,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),t]},e))}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-medium text-fg-subtle`,children:t.filterChannelLabel}),(0,Z.jsx)(`button`,{type:`button`,"aria-pressed":!z,onClick:()=>C({type:`patch`,patch:{channelFilter:``}}),className:A(`inline-flex items-center rounded-xl px-3 py-2 text-sm font-medium`,H.transition,H.focusRingPanel,z?`bg-surface-base text-fg-muted hover:bg-surface-hover hover:text-fg dark:bg-surface-hover/35`:`bg-accent-soft text-accent-fg`),children:t.filterChannelAll}),De.map(e=>(0,Z.jsxs)(`button`,{type:`button`,"aria-pressed":z===e,onClick:()=>C({type:`patch`,patch:{channelFilter:e}}),className:A(`inline-flex items-center rounded-xl px-3 py-2 text-sm font-medium`,H.transition,H.focusRingPanel,z===e?`bg-accent-soft text-accent-fg`:`bg-surface-base text-fg-muted hover:bg-surface-hover hover:text-fg dark:bg-surface-hover/35`),children:[e,J?.byChannel?.[e]==null?null:(0,Z.jsx)(`span`,{className:`ml-2 rounded-full bg-surface-hover px-2 py-0.5 text-[11px] text-fg-subtle`,children:J.byChannel[e]})]},e))]}),J?(0,Z.jsx)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-4`,children:[[J.totalSessions,t.totalSessions],[J.activeSessions,t.activeSessions],[J.pinnedSessions,t.pinnedSessions],[J.archivedSessions,t.archivedSessions]].map(([e,t])=>(0,Z.jsxs)(`div`,{className:`rounded-xl bg-surface-base p-3 dark:bg-surface-hover/30`,children:[(0,Z.jsx)(`div`,{className:`text-lg font-semibold tabular-nums text-fg`,children:e}),(0,Z.jsx)(`div`,{className:`text-xs text-fg-muted`,children:t})]},t))}):null,W?(0,Z.jsx)(`div`,{className:`rounded-lg border border-edge bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-edge dark:bg-red-950/40 dark:text-red-300`,children:W}):null,(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Z.jsx)(`p`,{className:`text-xs text-fg-muted`,children:ke(t.sessionCount,{count:V.length})}),(0,Z.jsxs)(`div`,{className:I,role:`group`,"aria-label":t.layoutToggleGroup,children:[(0,Z.jsx)(q,{type:`button`,variant:`segmented`,title:t.gridView,"aria-pressed":F===`grid`,onClick:()=>C({type:`patch`,patch:{viewMode:`grid`}}),className:A(ne,`size-7 p-0`,F===`grid`&&`bg-surface-panel shadow-sm dark:bg-surface-panel dark:shadow-sm dark:ring-1 dark:ring-edge-strong/40`,F===`grid`&&`text-accent-fg`),children:(0,Z.jsx)(ue,{className:`size-3.5`,strokeWidth:1.5})}),(0,Z.jsx)(q,{type:`button`,variant:`segmented`,title:t.listView,"aria-pressed":F===`list`,onClick:()=>C({type:`patch`,patch:{viewMode:`list`}}),className:A(ne,`size-9 p-0`,F===`list`&&`bg-surface-panel shadow-sm dark:bg-surface-panel dark:shadow-sm dark:ring-1 dark:ring-edge-strong/40`,F===`list`&&`text-accent-fg`),children:(0,Z.jsx)(x,{className:`size-3.5`,strokeWidth:1.5})})]})]}),U&&V.length===0?(0,Z.jsx)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:Array.from({length:6}).map((e,t)=>(0,Z.jsx)(`div`,{className:`h-40 animate-pulse rounded-xl bg-surface-hover/60 dark:bg-surface-hover/40`},t))}):V.length===0?(0,Z.jsxs)(`div`,{className:`flex flex-col items-center justify-center rounded-2xl bg-surface-base py-16 text-center dark:bg-surface-hover/25`,children:[(0,Z.jsx)(L,{className:`mb-3 size-12 text-fg-disabled`,strokeWidth:1.25,"aria-hidden":!0}),(0,Z.jsx)(`p`,{className:`text-base font-semibold text-fg`,children:t.noSessions}),(0,Z.jsx)(`p`,{className:`mt-1 max-w-sm text-sm text-fg-muted`,children:t.noSessionsDescription}),(0,Z.jsx)(q,{variant:`primary`,className:`mt-6`,onClick:()=>{window.dispatchEvent(new CustomEvent(`navigate-to-chat`,{detail:{sessionKey:``},bubbles:!0}))},children:t.startNewChat})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:A(`grid min-w-0 gap-3`,F===`grid`?`sm:grid-cols-2 lg:grid-cols-3`:`grid-cols-1`),"data-debounced-query":j||void 0,children:V.map(e=>{let t=p(e,m);return(0,Z.jsx)(ge,{session:e,variant:F,labels:Se,sessionAgentId:t,sessionAgentAvatar:de(t,h),onOpen:()=>be(e.key),onAction:t=>void $(e.key,t)},e.key)})}),K?(0,Z.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,Z.jsx)(q,{type:`button`,variant:`secondary`,disabled:U,onClick:()=>void ve(),children:t.loadMore})}):null]})]}),(0,Z.jsx)(Ee,{open:se,loading:fe,session:Y,sessionAgentId:Y?p(Y,m):void 0,sessionAgentAvatar:Y?de(p(Y,m),h):void 0,labels:Ce,onClose:()=>{C({type:`patch`,patch:{detailOpen:!1,detailSession:null}})},onArchive:()=>Y&&void $(Y.key,`archive`),onUnarchive:()=>Y&&void $(Y.key,`unarchive`),onPin:()=>Y&&void $(Y.key,`pin`),onUnpin:()=>Y&&void $(Y.key,`unpin`),onExport:()=>Y&&void $(Y.key,`export`),onDelete:()=>Y&&C({type:`patch`,patch:{confirmKey:Y.key,confirmOpen:!0}})}),(0,Z.jsx)(te,{open:pe,onOpenChange:e=>C({type:`patch`,patch:{confirmOpen:e}}),children:(0,Z.jsxs)(ee,{children:[(0,Z.jsx)(g,{className:A(`xopc-dialog-overlay fixed inset-0 bg-scrim`,D)}),(0,Z.jsxs)(ce,{className:A(`xopc-dialog-content fixed left-1/2 top-1/2 w-[min(100%-2rem,24rem)] -translate-x-1/2 -translate-y-1/2 rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`,le),children:[(0,Z.jsx)(B,{className:`text-base font-semibold text-fg`,children:t.deleteSessionTitle}),(0,Z.jsx)(`p`,{className:`mt-2 text-sm text-fg-muted`,children:me?ke(t.deleteSessionMessage,{name:V.find(e=>e.key===me)?.name?.trim()||e.chat.newSession}):``}),(0,Z.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,Z.jsx)(q,{type:`button`,variant:`secondary`,onClick:()=>C({type:`patch`,patch:{confirmOpen:!1}}),children:t.cancel}),(0,Z.jsx)(q,{type:`button`,variant:`primary`,className:`bg-red-600 hover:bg-red-700`,onClick:()=>{me&&xe(me),C({type:`patch`,patch:{confirmOpen:!1,confirmKey:null}})},children:t.delete})]})]})]})})]}):(0,Z.jsx)(`div`,{className:`mx-auto w-full max-w-2xl px-4 py-16 text-center text-sm text-fg-muted sm:px-8 lg:max-w-app-main`,children:t.needToken})}export{Ne as SessionsPage};
|