workoffdesk 1.0.0 → 1.0.1
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/CHANGELOG.md +6 -0
- package/dist/build.json +1 -1
- package/dist/server/http/sessionSocket.js +12 -11
- package/dist/web/assets/{Setup-DinzDcF1.js → Setup-C27bNf5I.js} +1 -1
- package/dist/web/assets/{main-w7i8PvU7.js → main-DQFM4yJU.js} +2 -2
- package/dist/web/index.html +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/build.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"1.0.
|
|
1
|
+
{"version":"1.0.1","commit":"0c91daa8df475d40277aa688bddd0ed166ec32db","dirty":false}
|
|
@@ -21,15 +21,23 @@ export async function serveSession(socket, id, machine, onVisibility, journal) {
|
|
|
21
21
|
let closed = false;
|
|
22
22
|
let cleanup = () => { };
|
|
23
23
|
socket.on('message', (data, isBinary) => (handle ? handle(data, isBinary) : early.push([data, isBinary])));
|
|
24
|
+
const ended = () => {
|
|
25
|
+
if (socket.readyState === socket.OPEN)
|
|
26
|
+
socket.send(JSON.stringify({ type: 'exit' }));
|
|
27
|
+
};
|
|
28
|
+
// Watched before it is first looked for, so a session that ends while it is being found is not missed.
|
|
29
|
+
const unwatch = machine.onChange(async () => {
|
|
30
|
+
if (closed || (await machine.exists(id).catch(() => true)))
|
|
31
|
+
return;
|
|
32
|
+
ended();
|
|
33
|
+
socket.close(1000);
|
|
34
|
+
});
|
|
24
35
|
socket.on('close', () => {
|
|
25
36
|
closed = true;
|
|
26
37
|
onVisibility?.(id, connId, false);
|
|
38
|
+
unwatch();
|
|
27
39
|
cleanup();
|
|
28
40
|
});
|
|
29
|
-
const ended = () => {
|
|
30
|
-
if (socket.readyState === socket.OPEN)
|
|
31
|
-
socket.send(JSON.stringify({ type: 'exit' }));
|
|
32
|
-
};
|
|
33
41
|
if (!(await machine.exists(id))) {
|
|
34
42
|
ended();
|
|
35
43
|
socket.close(4404, 'no such session');
|
|
@@ -48,12 +56,6 @@ export async function serveSession(socket, id, machine, onVisibility, journal) {
|
|
|
48
56
|
lastSent = Date.now();
|
|
49
57
|
};
|
|
50
58
|
const ping = setInterval(() => socket.ping(), 25_000);
|
|
51
|
-
const unwatch = machine.onChange(async () => {
|
|
52
|
-
if (closed || (await machine.exists(id).catch(() => true)))
|
|
53
|
-
return;
|
|
54
|
-
ended();
|
|
55
|
-
socket.close(1000);
|
|
56
|
-
});
|
|
57
59
|
// Where the page's copy of the journal is, once it has said and been caught up; a page behind a change
|
|
58
60
|
// is sent nothing until it says where it is again.
|
|
59
61
|
let journalAt = null;
|
|
@@ -151,7 +153,6 @@ export async function serveSession(socket, id, machine, onVisibility, journal) {
|
|
|
151
153
|
clearInterval(ping);
|
|
152
154
|
clearTimeout(screenTimer);
|
|
153
155
|
clearTimeout(textTimer);
|
|
154
|
-
unwatch();
|
|
155
156
|
unwatchJournal();
|
|
156
157
|
};
|
|
157
158
|
let input = Promise.resolve();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as _,t,A as z,e as $,j as e,r as i,C as q,I as G}from"./main-
|
|
1
|
+
import{c as _,t,A as z,e as $,j as e,r as i,C as q,I as G}from"./main-DQFM4yJU.js";const k=["checks","account","address","service","phone"],O=["macos","node","tmux","claude"],R=s=>s.checks.filter(n=>O.includes(n.id)&&!n.ok);function L(s){return R(s).length?"checks":s.user?s.origin?s.checks.some(n=>n.id==="service"&&n.ok)?"phone":"service":"address":"account"}const P="setup-token";function M(s,n){const u=s.replace(/^#/,"");try{return u&&n.setItem(P,u),u||n.getItem(P)}catch{return u||null}}const F=12,W={getItem:s=>sessionStorage.getItem(s),setItem:(s,n)=>sessionStorage.setItem(s,n),removeItem:s=>sessionStorage.removeItem(s)},S=M(location.hash,W);location.hash&&history.replaceState(null,"",location.pathname);const{api:D}=_({base:()=>location.origin,headers:()=>S?{"x-setup-token":S}:{},onUnauthorized:()=>{}}),w=(s,n)=>D(s,{method:"POST",json:n}),v=s=>s instanceof z&&s.status===403?t.setupNoToken:$(s,t.failed,t.setupGone);function C({busy:s,children:n}){return s?e.jsx("span",{className:"spinner small"}):e.jsx(e.Fragment,{children:n})}function Y({state:s,reload:n,next:u}){const[a,r]=i.useState(!1),l=R(s),d=s.checks.filter(o=>O.includes(o.id)),x=async()=>{r(!0),await n(),r(!1)};return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"setup-note",children:l.length?t.setupChecksFix:t.setupChecksNote}),e.jsx("div",{className:"group",children:[...l,...d.filter(o=>o.ok)].map(o=>e.jsx(q,{check:o},o.id))}),e.jsx("div",{className:"setup-actions",children:l.length?e.jsx("button",{className:"btn primary",onClick:x,disabled:a,children:e.jsx(C,{busy:a,children:t.setupCheckAgain})}):e.jsx("button",{className:"btn primary",onClick:u,children:t.setupContinue})})]})}function J({state:s,reload:n,next:u}){const[a,r]=i.useState(!s.user),[l,d]=i.useState(""),[x,o]=i.useState(""),[b,N]=i.useState(""),[g,f]=i.useState(null),[c,p]=i.useState(!1);if(!a&&s.user)return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"setup-note",children:t.setupAccountHave(s.user)}),e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{className:"btn primary",onClick:u,children:t.setupKeep}),e.jsx("button",{className:"btn",onClick:()=>r(!0),children:t.setupReplace})]})]});const j=async h=>{if(h.preventDefault(),x!==b)return f(t.setupPasswordsDiffer);p(!0),f(null);try{await w("/api/setup/account",{username:l,password:x}),await n(),u()}catch(y){f(v(y))}finally{p(!1)}};return e.jsxs("form",{className:"setup-form",onSubmit:j,children:[e.jsx("p",{className:"setup-note",children:t.setupAccountNote}),s.user&&e.jsx("p",{className:"setup-warn",children:t.setupReplaceNote}),e.jsxs("label",{className:"field",children:[t.username,e.jsx("input",{value:l,onChange:h=>d(h.target.value),autoComplete:"username",autoCapitalize:"none",spellCheck:!1,required:!0})]}),e.jsxs("label",{className:"field",children:[t.password,e.jsx("input",{type:"password",value:x,onChange:h=>o(h.target.value),autoComplete:"new-password",minLength:F,required:!0}),e.jsx("small",{children:t.setupPasswordRule(F)})]}),e.jsxs("label",{className:"field",children:[t.setupPasswordAgain,e.jsx("input",{type:"password",value:b,onChange:h=>N(h.target.value),autoComplete:"new-password",required:!0})]}),g&&e.jsx("div",{className:"alert",role:"alert",children:g}),e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{className:"btn primary",type:"submit",disabled:c,children:e.jsx(C,{busy:c,children:t.setupSaveAccount})}),s.user&&e.jsx("button",{className:"btn",type:"button",onClick:()=>r(!1),children:t.cancel})]})]})}function Q({state:s,reload:n,next:u}){const{tailscale:a,cloudflared:r}=s.remote,l=(r==null?void 0:r.tunnels)??[],[d,x]=i.useState(a!=null&&a.running?"tailscale":l.length?"cloudflare":"other"),[o,b]=i.useState(l[0]??""),[N,g]=i.useState(""),[f,c]=i.useState("https://"),[p,j]=i.useState(null),[h,y]=i.useState(null),H=async m=>{m.preventDefault();const E=d==="tailscale"?{kind:d}:d==="cloudflare"?{kind:d,tunnel:o,hostname:N.trim()}:{kind:d,origin:f.trim()};y("save"),j(null);try{await w("/api/setup/address",E),await n(),u()}catch(T){j(v(T))}finally{y(null)}},K=async()=>{y("check"),await n(),y(null)},A=(m,E,T,I,U)=>e.jsxs("label",{className:`setup-choice${d===m?" chosen":""}${I?"":" off"}`,children:[e.jsx("input",{type:"radio",name:"kind",checked:d===m,disabled:!I,onChange:()=>x(m)}),e.jsxs("span",{className:"setup-choice-text",children:[e.jsx("strong",{children:E}),e.jsx("span",{children:T}),d===m&&U]})]});return e.jsxs("form",{className:"setup-form",onSubmit:H,children:[e.jsx("p",{className:"setup-note",children:t.setupAddressNote}),s.origin&&e.jsxs("div",{className:"setup-now",children:[e.jsx("span",{children:t.setupAddressNow(s.origin)}),e.jsx("button",{className:"btn small",type:"button",onClick:u,children:t.setupKeep})]}),e.jsxs("div",{className:"setup-choices",children:[a&&A("tailscale",t.setupTailscale,a.running?t.setupTailscaleUse(a.dnsName):t.setupTailscaleDown,a.running),l.length>0&&A("cloudflare",t.setupCloudflare,t.setupCloudflareNote,!0,e.jsxs("span",{className:"setup-choice-fields",children:[e.jsxs("label",{className:"field",children:[t.setupTunnel,e.jsx("select",{value:o,onChange:m=>b(m.target.value),children:l.map(m=>e.jsx("option",{children:m},m))})]}),e.jsxs("label",{className:"field",children:[t.setupHostname,e.jsx("input",{value:N,onChange:m=>g(m.target.value),placeholder:"workoffdesk.example.com",autoCapitalize:"none",spellCheck:!1,required:!0})]})]})),A("other",t.setupOther,t.setupOtherNote(s.port),!0,e.jsx("span",{className:"setup-choice-fields",children:e.jsx("label",{className:"field",children:e.jsx("input",{value:f,onChange:m=>c(m.target.value),type:"url",autoCapitalize:"none",spellCheck:!1,required:!0,"aria-label":t.setupOther})})}))]}),!(a!=null&&a.running)&&!l.length&&e.jsx("p",{className:"setup-note",children:t.setupNoWayIn}),p&&e.jsx("div",{className:"alert",role:"alert",children:p}),e.jsxs("div",{className:"setup-actions",children:[e.jsx("button",{className:"btn primary",type:"submit",disabled:h!==null,children:e.jsx(C,{busy:h==="save",children:t.setupUseAddress})}),e.jsx("button",{className:"btn",type:"button",onClick:K,disabled:h!==null,children:e.jsx(C,{busy:h==="check",children:t.setupCheckAgain})})]})]})}function V({reload:s,next:n}){const[u,a]=i.useState(!1),[r,l]=i.useState(null),d=async()=>{a(!0),l(null);try{const x=await w("/api/setup/service",{});await s(),x.ok?n():l(x.message)}catch(x){l(v(x))}finally{a(!1)}};return e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"setup-note",children:t.setupServiceNote}),u&&e.jsxs("div",{className:"setup-busy",role:"status",children:[e.jsx("span",{className:"spinner small"}),t.setupInstalling]}),r&&e.jsx("div",{className:"alert setup-pre",role:"alert",children:r}),e.jsx("div",{className:"setup-actions",children:e.jsx("button",{className:"btn primary",onClick:d,disabled:u,children:r?t.tryAgain:t.setupInstall})})]})}function B({state:s}){return e.jsxs(e.Fragment,{children:[s.qr&&e.jsx("div",{className:"setup-qr",dangerouslySetInnerHTML:{__html:s.qr}}),e.jsx("p",{className:"setup-origin",children:s.origin}),s.user&&e.jsx("p",{className:"setup-note centered",children:t.setupPhoneNote(s.user)})]})}function X({state:s,finish:n}){const[u,a]=i.useState(!1),r=s.checks.filter(l=>!l.ok);return e.jsxs(e.Fragment,{children:[e.jsx(B,{state:s}),e.jsx("div",{className:`mac-summary ${r.length?"bad":"ok"}`,children:r.length?t.macProblemCount(r.length):t.macAllGood}),r.length>0&&e.jsx("div",{className:"group",children:r.map(l=>e.jsx(q,{check:l},l.id))}),e.jsx("div",{className:"setup-actions",children:e.jsx("button",{className:"btn primary",disabled:u,onClick:async()=>{a(!0),await n(),a(!1)},children:t.setupFinish})})]})}const Z=(s,n)=>s==="account"?n.user:s==="address"?n.origin:s==="service"?t.macRunning:null,ee=["account","address"];function te(){const[s,n]=i.useState(null),[u,a]=i.useState(null),[r,l]=i.useState(S?null:t.setupNoToken),[d,x]=i.useState(!1),o=i.useCallback(async()=>{try{const c=await D("/api/setup/state");n(c),l(null),a(p=>p??L(c))}catch(c){l(v(c))}},[]);i.useEffect(()=>{document.title=t.setupTitle,S&&o()},[o]);const b=async()=>{try{await w("/api/setup/done",{}),x(!0)}catch(c){l(v(c))}},N=u?k.indexOf(u):-1,g=()=>a(k[Math.min(N+1,k.length-1)]),f=(c,p)=>c==="checks"?e.jsx(Y,{state:p,reload:o,next:g}):c==="account"?e.jsx(J,{state:p,reload:o,next:g}):c==="address"?e.jsx(Q,{state:p,reload:o,next:g}):c==="service"?e.jsx(V,{reload:o,next:g}):e.jsx(X,{state:p,finish:b});return e.jsxs("main",{className:"setup",children:[e.jsxs("header",{className:"brand setup-brand",children:[e.jsx("img",{src:"/icon.svg",alt:""}),e.jsx("h1",{children:t.setupTitle}),e.jsx("p",{children:t.setupSub})]}),d?e.jsxs("div",{className:"setup-done",children:[e.jsx("div",{className:"mac-summary ok",role:"status",children:t.setupFinished}),s&&e.jsx(B,{state:s})]}):e.jsxs(e.Fragment,{children:[r&&e.jsx("div",{className:"alert setup-gap",role:"alert",children:r}),!s&&!r&&e.jsx("div",{className:"mac-loading",children:e.jsx("span",{className:"spinner"})}),s&&u&&e.jsx("ol",{className:"setup-steps",children:k.map((c,p)=>{const j=p<N?"done":p===N?"now":"later",h=j==="done"?Z(c,s):null;return e.jsxs("li",{className:`setup-step ${j}`,"aria-current":j==="now"?"step":void 0,children:[e.jsxs("div",{className:"setup-step-head",children:[e.jsx("span",{className:"setup-num",children:j==="done"?e.jsx(G,{}):p+1}),e.jsx("strong",{children:t.setupSteps[c]}),h&&e.jsx("span",{className:"setup-summary",children:h}),j==="done"&&ee.includes(c)&&e.jsx("button",{className:"setup-change",onClick:()=>a(c),children:t.setupChange})]}),j==="now"&&e.jsx("div",{className:"setup-body",children:f(c,s)})]},c)})})]})]})}export{te as Setup};
|
|
@@ -56,7 +56,7 @@ Commit the changes`,snippetsNote:"They come first when you type / in the box; a
|
|
|
56
56
|
把改动提交了`,snippetsNote:"输入框里打 / 时排在最前面,点一下整句放进去。只存在这台设备上。",pushInsecure:"推送需要通过 https 打开这个网站(例如你的正式域名)。",pushUnsupported:"这个浏览器不支持推送。iPhone 上要先在 Safari 里「分享 → 添加到主屏幕」,再从主屏幕打开。",pushDenied:"通知权限被拒绝了,要到系统设置里给这个网站打开通知。",failed:"没成功",passkeyNone:"还没有 Passkey。添加后可以用 Face ID 直接登录。",passkeyNoneOnPhone:"还没有 Passkey。在网页版的「设置」里添加后,就能在网页上用 Face ID 登录。",pushAppUnready:"这台 Mac 还推送不到 iPhone App:服务器需要一把 Apple 推送密钥(~/.workoffdesk 里的 apns.json)。",pushAppDenied:"WorkOffDesk 的通知被关掉了,要到 iPhone「设置」→ WorkOffDesk →「通知」里打开。",addedAgo:n=>`添加于 ${n}`,lastUsedAgo:n=>` · 上次使用 ${n}`,passkeysTitle:"通行密钥(Passkey)",addPasskey:"添加这台设备的 Passkey",loggedIn:"已登录的设备",thisDevice:"这台设备",loginBy:(n,l)=>`${n?"Passkey":"密码"}登录 · 最近活动 ${l}`,revoke:"吊销",confirmDelete:"确认删除",confirmRevoke:"确认吊销",pushTitle:"推送通知",pushRemind:"Claude 需要你时提醒我",pushRemindSub:"等你确认、或一轮做完时推送到这台设备",logOut:"退出登录",addAccount:"添加账号",addAccountTagline:"登录另一个账号或服务器",signInAgainTagline:"这个账号在它的 Mac 上已失效,请重新登录",removeAccount:"移除",confirmRemoveAccount:"从这台手机移除",account:"账号",appRelease:n=>n?`App 当前版本 ${n}`:"App 当前版本:随安装包",thisMac:"这台 Mac",thisMacSub:"检查、版本、重启",macAllGood:"一切正常",macProblemCount:n=>`有 ${n} 个问题`,macChecks:"检查",checkNames:{macos:"macOS",node:"Node.js",tmux:"tmux",claude:"Claude Code",codex:"Codex",setup:"账号",service:"服务",origin:"地址",sleep:"防休眠",apns:"iPhone 通知"},macFixTap:"点一下复制",macCheckPassed:"通过",macCheckFailed:"没通过",macVersion:"版本",macBuiltFrom:(n,l)=>`构建自 ${n}${l?"(含未提交的改动)":""}`,macServingSince:n=>`${n}开始上线`,macReleases:"保留的版本",macRunning:"运行中",macActions:"服务",macRestart:"重启服务",macRestartNote:"会话不会断;页面会自己连回来。",macRestartConfirm:"现在重启",macRestartShort:"重启",macRollbackShort:"回退",macRollbackSure:"确定?",macPassed:n=>`另外 ${n} 项正常`,macAllPassed:n=>`${n} 项检查全部通过`,macRollback:n=>`回退到 ${n}`,macNoRollback:"没有保留更早的版本可以回退。",macNotManaged:"这个服务是手动起的(workoffdesk serve),不是作为后台服务运行的,所以这里不能重启它。",macRestarting:"正在重启…",macRollingBack:"正在回退…",macRestarted:"已重启",macRolledBack:"已回退",macNoReturn:"一分钟了 Mac 还没回来。去 Mac 上看看,或者在那里运行 workoffdesk doctor。",macProblems:"最近的警告和错误",macNoProblems:"最近没出过问题。",macLogNote:"完整日志在 Mac 上 ~/.workoffdesk 的 logs 文件夹里。",macClaudeAccounts:"Claude 账号",macAccountNote:"新会话用打勾的账号开;开着的会话不变,除非搬过去。",macElsewhere:n=>`${n} 个开着的会话还在别的账号上`,macMoveTo:n=>`搬到 ${n},从停下的地方接着跑。`,macMoveButton:"搬过去",macMovingSessions:n=>`正在搬 ${n} 个会话`,macMovingTo:n=>`正在搬到 ${n}:空闲的马上搬,正在回复的等这轮完了再搬。`,accountSignedOut:"已退出登录",accountNotReady:"先在终端里用它打开一次 Claude Code",accountApart:"它的对话没有和这台 Mac 的共用",accountNotSeen:"还没看到它的用量",limitReset:"已重置",claudeAccountLine:"账号"},hx={setupTitle:"设置 WorkOffDesk",setupSub:"在这台 Mac 上设一次,之后就用手机。",setupSteps:{checks:"这台 Mac",account:"账号",address:"地址",service:"服务",phone:"手机"},setupChange:"修改",setupContinue:"继续",setupCheckAgain:"再检查一次",setupChecksNote:"WorkOffDesk 在这台 Mac 上需要的东西。",setupChecksFix:"在终端里运行这些命令,然后再检查一次。",setupChecksOk:"这台 Mac 需要的都有了。",setupAccountNote:"手机登录用的用户名和密码。",setupAccountHave:n=>`已有账号:${n}`,setupKeep:"保留",setupReplace:"换一个",setupReplaceNote:"换账号会让所有设备退出登录。",setupPasswordRule:n=>`至少 ${n} 个字符`,setupPasswordAgain:"再输一次密码",setupPasswordsDiffer:"两次输入的密码不一样",setupSaveAccount:"保存账号",setupAddressNote:"手机打开的 HTTPS 地址,手机在哪儿都能连上。",setupAddressNow:n=>`当前:${n}`,setupTailscale:"Tailscale",setupTailscaleUse:n=>`https://${n},只有你自己的设备能访问`,setupTailscaleDown:"Tailscale 装了但没在运行。打开它并登录,然后再检查一次。",setupCloudflare:"Cloudflare 隧道",setupCloudflareNote:"用你域名下的一个主机名,走你建好的隧道。",setupTunnel:"隧道",setupHostname:"主机名",setupOther:"其他地址",setupOtherNote:n=>`任何能连到这台 Mac ${n} 端口的 HTTPS 地址。`,setupNoWayIn:"最省事的连法:这台 Mac 和手机都装上 Tailscale。装好后再检查一次。",setupUseAddress:"用这个地址",setupServiceNote:"WorkOffDesk 作为服务运行,登录这台 Mac 时自动启动。",setupInstall:"安装并启动",setupInstalling:"正在启动,可能要半分钟。",setupPhoneNote:n=>`用手机相机对准这个码,然后用 ${n} 登录。`,setupFinish:"完成",setupFinished:"都设好了。可以关掉这个页面了。",setupNoToken:"请从终端里 workoffdesk setup --web 打印的地址打开这个页面。再运行一次会打印新地址。",setupGone:"设置已经结束了。再运行一次 workoffdesk setup --web。"},mx={...ox,...cx,...rx,...ux,...dx,...fx,...hx};function gx(n){for(const l of n){if(/^zh\b/i.test(l))return"zh";if(/^en\b/i.test(l))return"en"}return"en"}var pb;const Ab=((pb=globalThis.navigator)==null?void 0:pb.languages)??[Intl.DateTimeFormat().resolvedOptions().locale],Qu=globalThis.workoffdeskLanguage,Xi=Qu==="zh"||Qu==="en"?Qu:gx(Ab),Nb=Ab[0]??(Xi==="zh"?"zh-CN":"en-US"),p=Xi==="zh"?mx:ix;let _b=0;function px(n,l,i){const o=n?Date.parse(n):NaN;Number.isNaN(o)||(_b=o+500-(l+i)/2)}const kb=n=>n-_b,bx=[300,1e3,2e3],yx=[300,1e3,2e3,4e3],Ob=n=>n==="network"||n===502||n===503||n===504,vx=n=>{if(n instanceof TypeError)return"network";const l=n==null?void 0:n.status;return typeof l=="number"||l==="network"?l:null};async function Wg(n,l={}){const i=l.delays??bx,o=l.sleep??(u=>new Promise(f=>setTimeout(f,u)));for(let u=0;;u++)try{return await n()}catch(f){const m=vx(f);if(u>=i.length||m===null||!Ob(m))throw f;await o(i[u])}}function Rb(n=Math.random){return 250+n()*500}class Sn extends Error{constructor(l,i,o,u){super(i),this.status=l,this.retryAfter=o,this.code=u}}class zd extends TypeError{}class Mb extends Error{}function At(n,l,i=p.noServer){return n instanceof Mb?p.noAnswer:n instanceof zd?i:n instanceof Sn?n.code&&p.serverErrors[n.code]?p.serverErrors[n.code]:n.status===404&&n.message?p.goneOnMac:n.message?n.message:Ob(n.status)?i:l:l}const Cb=2e3,Sx=8e3,xx=15e3,Ex=25,wx=new Set(["POST","PUT","PATCH"]),Tx=n=>n instanceof Blob?n.size:typeof n=="string"?n.length:n instanceof ArrayBuffer||ArrayBuffer.isView(n)?n.byteLength:0;async function Vu(n,l,i=()=>new zd("timed out")){const o=new AbortController,u=setTimeout(()=>o.abort(),n);try{return await l(o.signal)}catch(f){throw o.signal.aborted?i():f}finally{clearTimeout(u)}}function Ax(n){const l=()=>{var u;return((u=n.headers)==null?void 0:u.call(n))??{}};async function i(u,f){var y;const m=Date.now();let h="network";try{return await o(u,f,g=>h=g)}finally{const g=Date.now()-m;g>=Cb&&((y=n.onSlow)==null||y.call(n,{method:f.method??"GET",path:u.split("?")[0],ms:g,outcome:h}))}}async function o(u,f,m){var T;const{json:h,...y}=f,g=h===void 0&&y.body==null&&wx.has(y.method??"GET")?{}:h,v=new Headers(y.headers);for(const[C,P]of Object.entries(l()))v.has(C)||v.set(C,P);g!==void 0&&v.set("content-type","application/json");let E;const _=Date.now();try{E=await fetch(n.base()+u,{...y,headers:v,body:g!==void 0?JSON.stringify(g):y.body})}catch(C){throw new zd((C==null?void 0:C.message)??"fetch failed",{cause:C})}m(E.status),px(E.headers.get("date"),_,Date.now());const x=E.headers.get("x-workoffdesk-version");if(x&&((T=n.onVersion)==null||T.call(n,x)),E.status===401&&!u.startsWith("/api/auth/")&&n.onUnauthorized(v),!E.ok){let C="",P;try{const z=await E.json();C=z.error??C,P=typeof z.code=="string"?z.code:void 0}catch{}throw new Sn(E.status,C,Number(E.headers.get("retry-after"))||void 0,P)}return E.status===204?void 0:(E.headers.get("content-type")??"").includes("json")?E.json():E.text()}return{api(u,{idempotent:f,...m}={}){const h=m.method??"GET";if(h==="GET"||h==="DELETE")return Wg(()=>Vu(Sx,g=>i(u,{signal:g,...m})));const y=xx+Tx(m.body)/Ex;return f?Wg(()=>Vu(y,g=>i(u,{signal:g,...m})),{delays:yx}):Vu(y,g=>i(u,{signal:g,...m}),()=>new Mb("no answer"))},wsUrl:u=>n.base().replace(/^http/,"ws")+u,signIn:l}}const wa=n=>n==="claude"||n==="codex",vc=n=>n==="codex"?"Codex":"Claude",ls=n=>n.agent??"claude",Bt="local";function Nx(){let n=null;const l=new Set;return{saw(i){if(i===n)return;const o=n===null;if(n=i,!o)for(const u of l)u(i)},subscribe(i){return l.add(i),()=>void l.delete(i)}}}const jb=Nx(),{api:at,wsUrl:_x}=Ax({base:()=>location.origin,onVersion:jb.saw,onUnauthorized:()=>{location.pathname!=="/login"&&location.assign(`/login?next=${encodeURIComponent(location.pathname)}`)}});class kx extends Error{}function Jg(n){return n instanceof kx?p.loginNotKept:n instanceof Sn&&n.status===401?p.wrongPassword:n instanceof Sn&&n.status===429?p.tooManyTries(Math.ceil((n.retryAfter??900)/60)):At(n,n instanceof Sn?p.loginFailed(n.status):p.loginFailedOther)}function Ua(n,l=Date.now()){const i=Math.max(0,Math.round((l-n)/1e3));if(i<60)return p.justNow;const o=Math.round(i/60);if(o<60)return p.minutesAgo(o);const u=Math.round(o/60);if(u<24)return p.hoursAgo(u);const f=Math.round(u/24);return f<30?p.daysAgo(f):new Date(n).toLocaleDateString(Mc)}function Ba(n){var i;if(!n)return"";const l=(i=n.match(/^\/Users\/[^/]+/))==null?void 0:i[0];return l?`~${n.slice(l.length)}`:n}function Zi(n){return n.split("/").filter(Boolean).pop()??n}function Db(n){return n.title===Zi(n.cwd)?"":n.title}const vd=p.status;function Ox(n){return n.status==="ended"?vd.ended:wa(n.kind)?n.status?vd[n.status]:n.kind==="codex"?"Codex":"Claude":"Shell"}const Mc=Xi==="zh"?"zh-CN":"en-US",Rx=new Intl.DateTimeFormat(Mc,{weekday:"long"}),Mx=new Intl.DateTimeFormat(Mc,{month:"short",day:"numeric"}),Cx=new Intl.DateTimeFormat(Mc,{year:"numeric",month:"numeric",day:"numeric"}),jx=1440*60*1e3;function Lb(n,l=Date.now()){const i=new Date(n),o=f=>new Date(f.getFullYear(),f.getMonth(),f.getDate()).getTime(),u=Math.round((o(new Date(l))-o(i))/jx);return u<=0?`${String(i.getHours()).padStart(2,"0")}:${String(i.getMinutes()).padStart(2,"0")}`:u===1?p.yesterday:u<7?Rx.format(i):i.getFullYear()===new Date(l).getFullYear()?Mx.format(i):Cx.format(i)}function Dx(n){const l=wa(n.kind);return l&&n.status==="starting"?p.previewStarting:l&&n.status==="working"?p.previewWorking:l&&n.status==="compacting"?p.compactingContext:l&&(n.status==="waiting"||n.status==="ended")?vd[n.status]:n.lastReply||Ba(n.cwd)}function zb(n){const l=Math.max(0,Math.floor(n/1e3));return l<60?p.seconds(l):p.minutesSeconds(Math.floor(l/60),l%60)}function Ub(n){const l=n?new Date(n):null;return!l||Number.isNaN(l.getTime())?"":`${String(l.getHours()).padStart(2,"0")}:${String(l.getMinutes()).padStart(2,"0")}`}function ep(n){const l=/iPhone/.test(n)?"iPhone":/iPad/.test(n)?"iPad":/Android/.test(n)?"Android":/Mac OS X/.test(n)?"Mac":/Windows/.test(n)?"Windows":p.device,i=/^WorkOffDesk\//.test(n)?"WorkOffDesk":/Edg\//.test(n)?"Edge":/CriOS|Chrome\//.test(n)?"Chrome":/FxiOS|Firefox\//.test(n)?"Firefox":/Safari\//.test(n)?"Safari":"";return i?`${l} · ${i}`:l}function Wu(n){if("text"in n)return n.text;const l=n.event;return l.e==="task"?p.noteTask(l.status,l.what):l.e==="peer"?p.notePeer(l.from):l.e==="failed"?l.limit?p.noteLimit:p.noteFailed:l.e==="compacted"?p.noteCompacted:p.noteInterrupted}const Bb=n=>{var l;return n.k==="note"&&((l=n.event)==null?void 0:l.e)==="failed"&&!!n.event.limit},Hb=n=>n.title?p.panelNamed(p.panelTitles[n.title]??n.title.replace(/\s+/g," ")):p.aPanel,Yl=n=>p.effortLevels[n]??n,Lx=["low","medium","high","xhigh","max"],zx=[{alias:"opus",name:"Opus"},{alias:"fable",name:"Fable"},{alias:"sonnet",name:"Sonnet"},{alias:"haiku",name:"Haiku"}];function Ux(n,l){return n!=null&&n.length?n.map(i=>({label:i.name,sub:i.about||void 0,current:i.name===l,command:`/model ${i.value}`})):[...zx.map(i=>({label:i.name,current:!1,command:`/model ${i.alias}`})),{label:p.otherModels,current:!1,command:"/model"}]}const Bx=(n,l)=>{var o;const i=(o=n==null?void 0:n.find(u=>u.name===l))==null?void 0:o.efforts;return i!=null&&i.length?i:Lx},Hx=n=>[...n.mode?[p.alwaysMode(n.mode)]:[],...n.rules.length?[p.alwaysRules]:[],...n.dirs.length?[p.alwaysDirs(n.dirs.map(l=>Ba(l)).join(p.listSeparator))]:[]].join(p.alwaysJoin),$x=n=>[{label:p.allowYes,answer:{allow:!0}},...n.always?[{label:p.allowAlways(Hx(n.always)),...n.always.rules.length>0&&{code:n.always.rules.join(`
|
|
57
57
|
`)},answer:{allow:!0,always:!0}}]:[],{label:p.allowNo,detail:p.allowNoDetail,answer:{allow:!1}}],$b=n=>{var l;return!!n.panel||!!((l=n.choices)!=null&&l.opened)&&!n.choices.submit},tp={sid:null,items:[],next:0,base:0,pages:[]},Ix=n=>{var l;return(((l=n.pages[0])==null?void 0:l.start)??0)>0};function Gx(n,l){if(l.sid!==n.sid||l.from!==n.next||!n.pages.length)return{sid:l.sid,items:l.items,next:l.next,base:0,pages:[{start:l.from,count:l.items.length}]};const i=n.pages.at(-1);return{...n,items:[...n.items,...l.items],next:l.next,pages:[...n.pages.slice(0,-1),{...i,count:i.count+l.items.length}]}}function qx(n,l){return l.sid!==n.sid||!n.pages.length||l.next!==n.pages[0].start?null:{...n,items:[...l.items,...n.items],base:n.base-l.items.length,pages:[{start:l.from,count:l.items.length},...n.pages]}}function Yx(n,l){let i=0,o=0;for(;i<n.pages.length-1&&n.items.length-o>l;)o+=n.pages[i++].count;return{...n,items:n.items.slice(o),base:n.base+o,pages:n.pages.slice(i)}}const Ju=n=>Number.isSafeInteger(n)&&n>=0;function Kx(n){const l=n;return!l||typeof l!="object"||!(l.sid===null||typeof l.sid=="string")||!Array.isArray(l.items)||!Ju(l.next)||!Number.isSafeInteger(l.base)||!Array.isArray(l.pages)||!l.pages.every(i=>i&&Ju(i.start)&&Ju(i.count))||l.pages.reduce((i,o)=>i+o.count,0)!==l.items.length?null:l}const Fx=new Set(["TaskCreate","TaskUpdate","TaskList","TaskGet","TodoWrite"]);function Px(n){const l=n.map((o,u)=>({i:o,n:u})),i=o=>"at"in o&&o.at?Date.parse(o.at):NaN;for(let o=0;o<l.length;o++){const u=i(l[o].i);if(l[o].i.k!=="user"||Number.isNaN(u))continue;let f=o;for(let m=o-1;m>=0&&l[m].i.k!=="user";m--){const h=i(l[m].i);if(!Number.isNaN(h)){if(h<=u)break;f=m}}f<o&&l.splice(f,0,...l.splice(o,1))}return l}function Ud(n,l){const i=new Map;for(const m of n)m.k==="result"&&i.set(m.id,{text:m.text,error:m.error,stopped:m.stopped,image:m.image,diff:m.diff});const o=[];let u=new Map;const f=()=>{const m=o.at(-1);u.size&&(m==null?void 0:m.k)==="text"&&o.push({k:"changes",files:[...u.values()],key:`changes-${m.key}`}),u=new Map};for(const{i:m,n:h}of Px(n)){if(m.k==="result"||m.k==="task"||m.k==="todos"||m.k==="bg")continue;if(m.k==="user"&&f(),m.k!=="tool"){o.push({...m,key:String(l+h)});continue}if(Fx.has(m.name))continue;const y=i.get(m.id);o.push({...m,result:y,key:m.id});const g=y==null?void 0:y.diff;if(!g)continue;const v=u.get(g.file);u.set(g.file,{file:g.file,added:((v==null?void 0:v.added)??0)+g.added,removed:((v==null?void 0:v.removed)??0)+g.removed,...v!=null&&v.created||g.created?{created:!0}:{},tool:m.id})}return f(),o}const Xx=n=>{var l;return n.k==="tool"&&!n.plan&&!(n.name==="Read"&&((l=n.result)!=null&&l.image))};function Ib(n,l=!1){const i=[];let o=[];const u=(f=!1)=>{o.length>1?i.push({k:"tools",key:o[0].key,tools:o,going:l&&f}):o.length&&i.push({k:"one",t:o[0]}),o=[]};for(const f of n)Xx(f)?o.push(f):(u(),i.push({k:"one",t:f}));return u(!0),i}function Gb(n){const l=n.lastIndexOf("/");return!n.startsWith("/")||l===n.length-1?null:{name:n.slice(l+1),dir:Ba(n.slice(0,l))||"/"}}const qb="workoffdesk",Fi="chats",Zx=1500,Qx=500;let Yi=null;function Yb(){return Yi??(Yi=new Promise((n,l)=>{const i=indexedDB.open(qb,1);i.onupgradeneeded=()=>i.result.createObjectStore(Fi),i.onsuccess=()=>n(i.result),i.onerror=()=>l(i.error),i.onblocked=()=>l(new Error("blocked"))}).catch(n=>{throw Yi=null,n})),Yi}function Vx(n){return new Promise((l,i)=>{n.onsuccess=()=>l(n.result),n.onerror=()=>i(n.error)})}async function Wx(n){const l=async()=>Kx(await Vx((await Yb()).transaction(Fi).objectStore(Fi).get(n))),i=new Promise(o=>setTimeout(()=>o(null),Qx));try{return await Promise.race([l(),i])}catch{return null}}async function Jx(n,l){try{(await Yb()).transaction(Fi,"readwrite").objectStore(Fi).put(Yx(l,Zx),n)}catch{}}async function eE(){var n;try{const l=Yi;Yi=null,(n=await(l==null?void 0:l.catch(()=>null)))==null||n.close(),indexedDB.deleteDatabase(qb)}catch{}}const _t={fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"},Bd=()=>r.jsx("svg",{viewBox:"0 0 24 24",..._t,"aria-hidden":!0,children:r.jsx("path",{d:"M15 18l-6-6 6-6"})}),Cc=()=>r.jsx("svg",{viewBox:"0 0 24 24",..._t,"aria-hidden":!0,children:r.jsx("path",{d:"M9 18l6-6-6-6"})}),tE=()=>r.jsxs("svg",{viewBox:"0 0 24 24",..._t,"aria-hidden":!0,children:[r.jsx("circle",{cx:"12",cy:"12",r:"3"}),r.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 1 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 1 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 1 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9c.26.6.85 1 1.51 1H21a2 2 0 1 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]}),Kb=()=>r.jsxs("svg",{viewBox:"0 0 24 24",..._t,"aria-hidden":!0,children:[r.jsx("path",{d:"M4 17l6-5-6-5"}),r.jsx("path",{d:"M12 19h8"})]}),Fb=()=>r.jsx("svg",{viewBox:"0 0 24 24",..._t,"aria-hidden":!0,children:r.jsx("path",{d:"M8 7l-5 5 5 5M16 7l5 5-5 5M14 4l-4 16"})}),Pb=()=>r.jsx("svg",{viewBox:"0 0 24 24",..._t,"aria-hidden":!0,children:r.jsx("path",{d:"M4 5h16v11H9l-5 4z"})}),nE=()=>r.jsx("svg",{viewBox:"0 0 24 24",..._t,"aria-hidden":!0,children:r.jsx("path",{d:"M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"})}),aE=()=>r.jsx("svg",{viewBox:"0 0 24 24",..._t,"aria-hidden":!0,children:r.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H8l-5 4V6a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})}),sE=()=>r.jsxs("svg",{viewBox:"0 0 24 24",..._t,"aria-hidden":!0,children:[r.jsx("path",{d:"M3 12a9 9 0 1 0 2.64-6.36L3 8.3"}),r.jsx("path",{d:"M3 3.5v4.8h4.8"}),r.jsx("path",{d:"M12 7.5V12l3.5 2"})]}),lE=()=>r.jsxs("svg",{viewBox:"0 0 24 24",..._t,"aria-hidden":!0,children:[r.jsx("rect",{x:"2.5",y:"4.5",width:"19",height:"15",rx:"3"}),r.jsx("path",{d:"M6.5 9.5l2.5 2.5-2.5 2.5M11.5 15h5"})]}),Xb=()=>r.jsx("svg",{viewBox:"0 0 24 24",..._t,"aria-hidden":!0,children:r.jsx("path",{d:"M5 12.5l4.5 4.5L19 7.5"})}),Qi=()=>r.jsx("svg",{viewBox:"0 0 24 24",..._t,"aria-hidden":!0,children:r.jsx("path",{d:"M18 6L6 18M6 6l12 12"})}),iE=()=>r.jsxs("svg",{viewBox:"0 0 24 24",..._t,"aria-hidden":!0,children:[r.jsx("path",{d:"M7 3H5a2 2 0 0 0-2 2v2M17 3h2a2 2 0 0 1 2 2v2M7 21H5a2 2 0 0 1-2-2v-2M17 21h2a2 2 0 0 0 2-2v-2"}),r.jsx("path",{d:"M9 9v1M15 9v1M12 9v4h-1M9 16c1.6 1.3 4.4 1.3 6 0"})]}),oE=()=>r.jsxs("svg",{viewBox:"0 0 24 24",..._t,"aria-hidden":!0,children:[r.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),r.jsx("circle",{cx:"9",cy:"10",r:"1.5"}),r.jsx("path",{d:"M21 16l-5-5-9 9"})]}),cE=()=>r.jsxs("svg",{viewBox:"0 0 24 24",..._t,"aria-hidden":!0,children:[r.jsx("path",{d:"M4 8h3l2-3h6l2 3h3a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V9a1 1 0 0 1 1-1z"}),r.jsx("circle",{cx:"12",cy:"13.5",r:"3.5"})]}),Hd=()=>r.jsxs("svg",{viewBox:"0 0 24 24",..._t,"aria-hidden":!0,children:[r.jsx("path",{d:"M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"}),r.jsx("path",{d:"M14 3v5h5"})]}),Zb=()=>r.jsx("svg",{viewBox:"0 0 24 24","aria-hidden":!0,children:r.jsx("path",{d:"M8 5.5v13l10.5-6.5z",fill:"currentColor"})}),rE=()=>r.jsx("svg",{viewBox:"0 0 24 24",..._t,"aria-hidden":!0,children:r.jsx("path",{d:"M12 5v14M6 13l6 6 6-6"})}),uE=()=>r.jsx("svg",{viewBox:"0 0 24 24",..._t,"aria-hidden":!0,children:r.jsx("path",{d:"M12 19V5M6 11l6-6 6 6"})}),Qb=()=>r.jsx("svg",{viewBox:"0 0 24 24",..._t,"aria-hidden":!0,children:r.jsx("path",{d:"M12 5v14M5 12h14"})}),dE=()=>r.jsx("svg",{viewBox:"0 0 24 24",..._t,strokeWidth:2.6,"aria-hidden":!0,children:r.jsx("path",{d:"M5 12h.01M12 12h.01M19 12h.01"})}),fE=()=>r.jsxs("svg",{viewBox:"0 0 24 24",..._t,"aria-hidden":!0,children:[r.jsx("circle",{cx:"11",cy:"11",r:"6.5"}),r.jsx("path",{d:"M16 16l4 4"})]}),hE=()=>r.jsx("svg",{viewBox:"0 0 24 24",..._t,"aria-hidden":!0,children:r.jsx("path",{d:"M5 7h14M5 12h14M5 17h9"})}),mE=()=>r.jsxs("svg",{viewBox:"0 0 24 24",..._t,"aria-hidden":!0,children:[r.jsx("rect",{x:"2",y:"6",width:"20",height:"12",rx:"2"}),r.jsx("path",{d:"M6 10h.01M10 10h.01M14 10h.01M18 10h.01M7 14h10"})]});function Zt(n,l=!1){l?history.replaceState(null,"",n):history.pushState(null,"",n),window.dispatchEvent(new PopStateEvent("popstate"))}function gE(){const[n,l]=H.useState(location.pathname);return H.useEffect(()=>{const i=()=>l(location.pathname);return window.addEventListener("popstate",i),()=>window.removeEventListener("popstate",i)},[]),n}const np="workoffdesk.answered.",pE=50;function bE(n,l){const i=u=>{try{return JSON.parse(n.getItem(np+u)??"[]")}catch{return[]}},o=u=>{var y,g;const{conv:f,items:m}=l.view(u),h=(g=Ud(m,((y=m[0])==null?void 0:y.pos)??0).at(-1))==null?void 0:g.key;return f&&h?{conv:f,turn:h}:void 0};return{answersOf:i,async give(u,f,m,h,y){var _;const g=Date.now(),v=o(u);await f();const E={said:m,...y&&{code:y},question:((_=h.split(`
|
|
58
58
|
`).find(x=>x.trim()))==null?void 0:_.trim())??"",at:g,...v&&{after:v}};try{n.setItem(np+u,JSON.stringify([...i(u),E].slice(-pE)))}catch{}}}}function yE(n,l,i){const o=new Map,u=new Set(l.map(y=>y.key));let f=-1/0;const m=l.map(y=>y.at?f=Math.max(f,kb(Date.parse(y.at))||f):f),h=y=>{var v;let g=l.length-1;for(;g>=0&&m[g]>y.at;)g--;return(v=l[g])==null?void 0:v.key};for(const y of n){const g=y.after?y.after.conv===i&&u.has(y.after.turn)?y.after.turn:void 0:h(y);g!==void 0&&o.set(g,[...o.get(g)??[],y])}return o}const vE=1200,SE=1e4;function xE(n){const{api:l,visibility:i,store:o}=n,u=new Map;return{remembered:f=>u.get(f)??null,forget:()=>u.clear(),follow(f,m,h){let y=u.get(f)??null,g=!1,v,E=null,_=!1;const x=(z,L=!0)=>{y=z,u.set(f,z),h.show(z),L&&(o==null||o.keep(f,z))},N=async()=>{if(v=void 0,i.visible()){const z=y??tp;try{const L=await l(`${m}?from=${z.next}&sid=${z.sid??""}`),le=y??tp,ne=le.pages.length>0&&L.sid===le.sid&&L.from===le.next&&L.next===le.next;if(g)return;ne||x(Gx(le,L)),E=null,h.failed(!1)}catch(L){if(g)return;if(L instanceof Sn&&L.status===404){h.failed(!1);return}E??(E=Date.now()),Date.now()-E>=SE&&h.failed(!0)}}g||(v=setTimeout(N,T?0:vE)),T=!1};let T=!1;const C=()=>{if(!v){T=!0;return}clearTimeout(v),N()},P=i.onChange(()=>{i.visible()&&C()});return(async()=>{if(!y&&o){const z=await o.kept(f);z&&!g&&!y&&x(z,!1)}g||N()})(),{stop(){g=!0,clearTimeout(v),P()},async older(z){const L=y;if(!(!L||!Ix(L)||_)){_=!0,h.loadingOlder(!0);try{const le=await l(`${m}?sid=${L.sid??""}&before=${L.pages[0].start}`),ne=y&&qx(y,le);ne&&!g&&(z(),x(ne))}catch{}finally{_=!1,h.loadingOlder(!1)}}}}}}}const ed="workoffdesk.draft.";function EE(n){return{draftOf(l){try{return n.getItem(ed+l)??""}catch{return""}},keepDraft(l,i){try{i?n.setItem(ed+l,i):n.removeItem(ed+l)}catch{}}}}const Vb=1e4,Wb=3e4,$d=new Map,pc=new Map,Jb=new Map;function wE(n,l){$d.set(n,Date.now()),ey(n,l)}const ap=(n,l)=>ey(n,{type:"screen",screen:l});function ey(n,l){l.type==="screen"&&Jb.set(n,l.screen);for(const i of pc.get(n)??[])i(l)}const Sc=n=>Date.now()-($d.get(n)??0)<Vb,TE=n=>Sc(n)?Jb.get(n):void 0;function ty(n,l){const i=pc.get(n)??new Set;return i.add(l),pc.set(n,i),()=>{i.delete(l),i.size||pc.delete(n)}}function AE(n,l){const i=($d.get(n)??0)+Vb-Date.now();return i>0?Math.min(Wb,i+l):l}const NE=(n,l)=>!Sc(n)||Date.now()-l>=Wb;function ny(){const n=new Map;return{ask:(l,i)=>[...n.get(l)??[]].map(o=>o(i)).some(Boolean),on(l,i){const o=n.get(l)??new Set;return o.add(i),n.set(l,o),()=>{o.delete(i),o.size||n.delete(l)}}}}const _E=ny(),kE=(n,l)=>_E.on(n,l),Kl=new Map,Sd=ny();function OE(n){const l=Kl.get(n)??0;Kl.set(n,l+1),l||Sd.ask(n,!0);let i=!1;return()=>{if(i)return;i=!0;const o=(Kl.get(n)??1)-1;if(o)return void Kl.set(n,o);Kl.delete(n),Sd.ask(n,!1)}}const RE=n=>(Kl.get(n)??0)>0,ME=(n,l)=>Sd.on(n,l),Id=new Map,bc=new Map;function sp(n,l){Id.set(n,l);for(const i of bc.get(n)??[])i(l)}function CE(n){Id.delete(n)}function jE(n,l){const i=bc.get(n)??new Set;i.add(l),bc.set(n,i);const o=Id.get(n);return o&&l(o),()=>{i.delete(l),i.size||bc.delete(n)}}let Ls=null;const xd=new Set;function td(n){Ls=n&&{epoch:n.epoch,v:new Map(Object.entries(n.heads))};for(const l of xd)l()}function DE(n){return xd.add(n),()=>void xd.delete(n)}const nd=(n,l)=>!!Ls&&l.epoch===Ls.epoch&&Ls.v.get(n)===l.v;function ay(n,l){const i=Ls==null?void 0:Ls.v.get(n);return i!==void 0&&(l.epoch!==Ls.epoch||i>l.v)}const Ed={choices:null,panel:null},lp=()=>({epoch:null,v:0,items:new Map,messages:new Map,states:new Map,older:null}),LE={synced:!1,failed:!1,behind:!1,gone:!1,conv:null,items:[],older:!1,loadingOlder:!1,messages:[],status:null,workingSince:null,screen:Ed,screenStale:!1,live:null,tasks:[],background:[],onMac:0};function ad(n,l,i=!1){if(i){n.items.clear(),n.states.clear();for(const[o,u]of n.messages)u.body.state!=="sending"&&n.messages.delete(o)}for(const o of l)if(o.t==="item")n.items.has(o.key)||n.items.set(o.key,{...o.body,itemId:o.key});else{const u=o.t==="message"?n.messages:n.states,f=u.get(o.key);(!f||o.v>f.v)&&u.set(o.key,{v:o.v,body:o.body})}}function zE(n,l,{screenHidden:i,...o}){const u=(h,y)=>{var g;return((g=l.states.get(h))==null?void 0:g.body)??y},f=u("conv",{conv:null}).conv,m=[...l.items.values()].filter(h=>h.conv===f).sort((h,y)=>h.pos-y.pos);return{...o,behind:ay(n,l),conv:f,items:m,older:l.older!==null,messages:[...l.messages.values()].map(h=>h.body),status:u("status",null),workingSince:u("workingSince",null),screen:i?Ed:{...u("screen",Ed),asks:u("asks",[])},screenStale:i,live:u("live",{text:null}).text,tasks:u("tasks",[]),background:u("background",[]),onMac:u("onMac",0)}}const UE=new Set(["sending","delivering","delivered"]),BE=new Set(["starting","waiting","compacting","ended"]),sy=n=>n.status!==null&&BE.has(n.status)||n.messages.some(l=>l.state==="queued");function ly(n,l,i){return l.state==="queued"?"mac":l.state==="enqueued"?"claude":l.state==="sending"&&(i||n.status==="working")?"sending":null}function HE(n,l){const i=sy(n),o={claude:0,mac:1,sending:2};return n.messages.flatMap(u=>{const f=ly(n,u,i);return f&&!l.has(u.id)?[{m:u,w:f}]:[]}).sort((u,f)=>o[u.w]-o[f.w]||(u.w==="mac"?(u.m.ord??0)-(f.m.ord??0):u.m.sentAt-f.m.sentAt)).map(({m:u,w:f})=>({id:u.id,text:u.text,at:u.sentAt,waits:f}))}function $E(n,l){const i=l.at(-1),o=new Map(n.items.map(g=>[g.itemId,String(g.pos)])),u=new Set;(i==null?void 0:i.k)==="user"&&n.messages.some(g=>g.state==="landed"&&g.item&&o.get(g.item)===i.key)&&u.add(i.key);const f=l.findLast(g=>g.k==="user"),m=(f==null?void 0:f.k)==="user"&&f.at?Date.parse(f.at):-1/0,h=sy(n),y=n.messages.filter(g=>UE.has(g.state)&&!ly(n,g,h)||g.state==="unconfirmed"&&!(m>g.sentAt)).sort((g,v)=>g.sentAt-v.sentAt);return{sent:u,bubbles:y}}const IE=1200,GE=1e4;function qE(n){const{api:l,visibility:i,store:o}=n,u=new Map,f=x=>`/api/m/${Bt}/sessions/${x}`,m=x=>{let N=u.get(x);return N||(N={id:x,copy:lp(),view:LE,synced:!1,failed:!1,gone:!1,loadingOlder:!1,screenHidden:!1,listeners:new Set,read:null,lastSend:Promise.resolve(),arrived:new Map,posting:new Set},u.set(x,N)),N},h=x=>{x.view=zE(x.id,x.copy,x);for(const N of x.listeners)N()},y=(x,N,T=!1)=>{var le;const C=m(x);ad(C.copy,N,T);for(const ne of N)ne.t==="state"&&(ne.key==="screen"||ne.key==="asks")&&(C.screenHidden=!1),!(ne.t!=="message"||!ne.v)&&((le=C.arrived.get(ne.key))==null||le(),C.arrived.delete(ne.key));const{epoch:P,v:z,older:L}=C.copy;o==null||o.write(x,{epoch:P,v:z,older:L},N,T),h(C)},g=(x,N)=>{const T=m(x);N.reset&&(T.copy.older=N.older??null),T.copy.epoch=N.epoch,T.copy.v=N.v,y(x,N.rows,!!N.reset)},v=(x,N)=>{const T=m(x);T.posting.add(N.id);const C=T.lastSend.then(()=>l(`${f(x)}/messages`,{method:"POST",json:{text:N.text,id:N.id},idempotent:!0})),P=new Promise(z=>T.arrived.set(N.id,z));return T.lastSend=Promise.race([C.catch(()=>{}),P]),C.then(z=>{z.message&&y(x,[z.message])},z=>{throw T.arrived.delete(N.id),z}).finally(()=>T.posting.delete(N.id))},E=(x,N)=>{var C;const T=m(x);return((C=T.copy.messages.get(N))==null?void 0:C.v)!==0?!1:(T.copy.messages.delete(N),o==null||o.remove(x,N),h(T),!0)},_=async x=>{const N=m(x);for(;;){const T=await l(`${f(x)}/journal?epoch=${encodeURIComponent(N.copy.epoch??"")}&v=${N.copy.v}`);if(g(x,T),!T.more)break}sp(x,{epoch:N.copy.epoch??"",v:N.copy.v})};return{view:x=>m(x).view,subscribe(x,N){const T=m(x);return T.listeners.add(N),()=>T.listeners.delete(N)},follow(x){const N=m(x);let T=!1,C,P=0,z=null,L=!1,le=!1,ne=!1;const W=()=>{ne=!0;for(const j of N.copy.messages.values())j.v===0&&!N.posting.has(j.body.id)&&v(x,j.body).catch(fe=>{fe instanceof Sn&&fe.status>=400&&fe.status<500&&E(x,j.body.id)})},oe=j=>{Object.entries(j).every(([fe,Ce])=>N[fe]===Ce)||(Object.assign(N,j),h(N))},he=async(j=!0)=>{if(clearTimeout(C),L){le=!0;return}if(i.visible()&&(j||NE(x,P))){L=!0,P=Date.now();const fe=N.screenHidden;try{await _(x),!ne&&!T&&W(),z=null,oe({synced:!0,failed:!1,...fe&&{screenHidden:!1}})}catch(Ce){Ce instanceof Sn&&Ce.status===404?oe({gone:!0,failed:!1}):(z??(z=Date.now()),Date.now()-z>=GE&&oe({failed:!0}))}finally{L=!1}}if(!(T||N.gone)){if(le)return le=!1,void he();C=setTimeout(()=>void he(!1),AE(x,IE))}};oe({synced:nd(x,N.copy),failed:!1});const ge=()=>void(nd(x,N.copy)&&oe({synced:!0})),_e=DE(()=>{N.view.behind!==ay(x,N.copy)&&h(N),ge()}),Y=ty(x,j=>{j.type!=="journal"||T||(j.reset&&j.epoch?(g(x,{epoch:j.epoch,v:j.v,rows:j.rows,more:!!j.more,reset:!0,older:j.older}),oe({synced:!0})):(!j.epoch||j.epoch===N.copy.epoch)&&j.from===N.copy.v?(N.copy.v=j.v,y(x,j.rows),j.epoch&&!j.more?oe({synced:!0}):ge()):he())}),ee=i.onChange(()=>i.visible()&&void he());return N.read=()=>void he(),(async()=>{if(o&&!N.copy.epoch){const j=await o.load(x).catch(()=>null);j&&!T&&!N.copy.epoch&&(N.copy={...lp(),epoch:j.epoch,v:j.v,older:j.older},ad(N.copy,j.rows),N.synced=nd(x,N.copy),h(N))}T||(N.copy.epoch&&sp(x,{epoch:N.copy.epoch,v:N.copy.v}),he())})(),()=>{T=!0,clearTimeout(C),_e(),Y(),ee(),N.read=null,CE(x)}},refresh(x){var N,T;(T=(N=m(x)).read)==null||T.call(N)},rereadScreen(x){var T;const N=m(x);N.screenHidden=!0,h(N),(T=N.read)==null||T.call(N)},async older(x,N){const T=m(x),C=T.view.conv;if(!(T.copy.older===null||T.loadingOlder||!C)){T.loadingOlder=!0,h(T);try{const P=await l(`${f(x)}/journal/items?conv=${C}&before=${T.copy.older}`);T.view.conv===C&&(N==null||N(),T.copy.older=P.older,ad(T.copy,P.rows),o==null||o.write(x,{epoch:T.copy.epoch,v:T.copy.v,older:P.older},P.rows,!1))}catch{}finally{T.loadingOlder=!1,h(T)}}},apply:y,send(x,N){const T={id:n.newId(),text:N,sentAt:Date.now(),state:"sending",ord:null,item:null};return y(x,[{t:"message",key:T.id,v:0,body:T}]),v(x,T).catch(C=>{if(E(x,T.id))throw C})},async forget(){u.clear(),await(o==null?void 0:o.forget())}}}const ip="workoffdesk.keysShown";function YE(n){return{shown(){try{return n.getItem(ip)==="1"}catch{return!1}},show(l){try{n.setItem(ip,l?"1":"0")}catch{}}}}const KE=8,FE=n=>Array.from(n,l=>l.toString(16).padStart(2,"0")).join(""),PE=1;function XE(n,l){const i=n;return i.onopen=()=>l.open(),i.onmessage=o=>l.message(o.data),i.onclose=o=>l.close(o.code),{isOpen:()=>n.readyState===PE,send:o=>n.send(o),close:()=>n.close()}}const iy=[4401,4403],oy=4012,ZE=4404,op="workoffdesk.seen";function QE(n){const l=()=>{try{return JSON.parse(n.getItem(op)??"{}")}catch{return{}}},i=o=>{try{n.setItem(op,JSON.stringify(o))}catch{}};return{markSeen(o){i({...l(),[o]:Date.now()})},unreadOf(o){const u=l(),f=new Set;let m=!1;for(const h of o)u[h.id]===void 0?(u[h.id]=h.lastActivity,m=!0):h.lastActivity>u[h.id]&&f.add(h.id);return m&&i(u),f}}}function VE(n){if(n===" ")return"\0";if(n==="?")return"";const l=n.toUpperCase().charCodeAt(0);return l>=64&&l<=95?String.fromCharCode(l&31):null}const WE=[{label:"Esc",seq:"\x1B"},{label:"↑",seq:"\x1B[A"},{label:"↓",seq:"\x1B[B"},{label:"⏎",seq:"\r"},{label:"Tab",seq:" "},{label:"^C",seq:""},{label:"←",seq:"\x1B[D"},{label:"→",seq:"\x1B[C"},{label:"^X^S",seq:""},{label:"Ctrl",seq:null}],JE="\r";function ew(n,l,i){return(!n||i?n:`\x1B[200~${n.replaceAll("\x1B[201~","")}\x1B[201~`)+(l?"\r":"")}const Gd=[{mode:null,name:p.modes.default},{mode:"accept edits",name:p.modes["accept edits"]},{mode:"plan mode",name:p.modes["plan mode"]},{mode:"auto mode",name:p.modes["auto mode"]},{mode:"bypass permissions",name:p.modes["bypass permissions"]}],cp=n=>{var l;return((l=Gd.find(i=>i.mode===n))==null?void 0:l.name)??n??""},tw="\x1B[Z",nw=Gd.length+1,aw=5e3,rp=150;async function sw(n,l){let i=await l.modeNow();for(let o=0;o<nw&&i!==n;o++){if(!l.press())return i;const u=i;for(let f=0;f<aw&&i===u;f+=rp)await l.sleep(rp),i=await l.modeNow()}return i}function lw(n,l,i){return i?{kind:n.kind,status:"ended"}:l?"reconnecting":n}const iw=3e4,ow=8e3,cw=new TextEncoder;function rw(n){return{open(l,i){let o=null,u=1e3,f,m,h=!1;const y=W=>o!=null&&o.isOpen()?(o.send(W),!0):!1,g=()=>y(JSON.stringify({type:"visible",visible:n.visibility.visible()}));let v=null;const E=()=>v&&y(JSON.stringify({type:"journal",...v})),_=W=>y(JSON.stringify({type:"screenText",on:W})),x=()=>{clearTimeout(f),clearTimeout(m),m=void 0},N=()=>{h=!0,x(),i("ended")},T=()=>{m??(m=setTimeout(()=>i("reconnecting"),ow))},C=()=>{clearTimeout(f);const W=`/api/m/${Bt}/sessions/${l}/ws`,oe=Date.now();let he=!1;const ge=Y=>{var j;if(he)return;he=!0;const ee=Date.now()-oe;ee>=Cb&&((j=n.onSlow)==null||j.call(n,{method:"WS",path:W,ms:ee,outcome:Y}))},_e=n.open(W,{open:()=>{ge(101),o===_e&&(u=1e3,clearTimeout(m),m=void 0,g(),E(),RE(l)&&_(!0),i("live"))},message:Y=>{if(o!==_e||typeof Y!="string")return;const ee=JSON.parse(Y);ee.type==="exit"?N():wE(l,ee)},close:Y=>{if(ge("network"),!(o!==_e||h)){if(iy.includes(Y))return n.onSignedOut();if(Y===ZE)return N();if(T(),Y===oy){u=500,f=setTimeout(C,Rb());return}f=setTimeout(C,u),u=Math.min(u*2,iw)}}});o=_e},P=()=>{if(g(),n.visibility.visible()&&!h){u=1e3;const W=o;o=null,W==null||W.close(),C()}},z=n.visibility.onChange(P),L=jE(l,W=>{v=W,E()}),le=ME(l,_),ne=kE(l,()=>y(JSON.stringify({type:"screen"})));return i("connecting"),C(),{send:W=>y(cw.encode(W)),close:()=>{x(),z(),L(),le(),ne();const W=o;o=null,W==null||W.close()}}}}}const uw=()=>({ctrl:!1,toast:null,switching:!1,commanding:null,settling:null,refill:null,nudge:0,models:null,ending:!1,dismissed:null,taking:new Set,lastMode:void 0});function dw(n,l){return n==="starting"?p.queueWhenStarted(l):n==="ended"?p.queueWhenContinued(l):n==="compacting"?p.queueAfterCompact:n==="waiting"?p.queueAfterWaiting(l):n==="working"?p.queueAfterTurn(l):p.queueNow}function up(n,l){const{known:i,link:o}=n,f=n.view.behind&&!!(i!=null&&i.status)&&i.status!==n.view.status?{...n.view,status:i.status,workingSince:null,live:null}:n.view,{screen:m}=f,h=o==="ended"||f.gone||n.endedBefore,y=h?"ended":f.status??(i==null?void 0:i.status),g=!!(m.choices||m.panel)||y==="waiting",v=$b(m);return{view:f,kind:(i==null?void 0:i.kind)??null,ended:h,quit:!h&&wa(i==null?void 0:i.kind)&&y==="ended",status:y,header:i&&lw(i,wa(i.kind)?f.failed:o==="reconnecting",h),covered:g,mode:g?l.lastMode:m.mode,queued:HE(f,l.taking),queueWhy:dw(y,vc(i==null?void 0:i.kind)),canSendNow:y==="working"&&!g,suggestion:wa(i==null?void 0:i.kind)&&y==="idle"&&m.suggestion&&m.suggestion!==l.dismissed?m.suggestion:null,dialog:v?m:l.settling,dialogBusy:!v&&!!l.settling}}const fw=2500,hw=1e4;function mw(n){const l=new Map;return{get(i){let o=l.get(i);return o||(o=gw(i,n,()=>l.delete(i)),l.set(i,o)),o}}}function gw(n,l,i){const{api:o,journals:u,list:f,seen:m}=l,h=`/api/m/${Bt}/sessions/${n}`,y=new Set,g=new Map,v=()=>{var se;return(se=f.current())==null?void 0:se.find(pe=>pe.id===n)};let E=v();const _=E?null:f.ended(n);let x=uw(),N="connecting",T=null,C=0,P,z=!1,L=!1;const le=[];let ne=null,W=!1,oe=null;const he=()=>{const se=E??_??void 0;return{view:u.view(n),known:se,endedBefore:!!_&&!E,link:N}},ge=se=>{for(const pe of["toast","commanding","settling"])x[pe]!==se[pe]&&(clearTimeout(g.get(pe)),g.delete(pe),x[pe]!==null&&g.set(pe,setTimeout(()=>fe({[pe]:null}),pe==="toast"?fw:hw)))},_e=(se,pe)=>{const{screen:De}=se.view;let Se=x;return!pe.covered&&De.mode!==void 0&&De.mode!==Se.lastMode&&(Se={...Se,lastMode:De.mode}),Se.commanding&&$b(De)&&(Se={...Se,commanding:null}),Se.settling&&!se.view.screenStale&&De!==Se.settling&&(Se={...Se,settling:null}),Se},Y=()=>{const se=he();let pe=up(se,x);const De=_e(se,pe);if(De!==x){const Se=x;x=De,ge(Se),pe=up(se,x)}return{...x,...pe,id:n,known:se.known,link:N}};let ee=Y();const j=()=>{ee=Y();for(const se of[...y])se()};function fe(se){if(L)return;const pe=x;x={...x,...se},ge(pe),j()}const Ce=()=>{var De;if(j(),L||!z)return;const se=ee;wa(se.kind)&&!ne&&(ne=u.follow(n)),wa(se.kind)&&!W&&(W=!0,o(`${h}/models`).then(Se=>fe({models:Se.models}),()=>{}));const pe=(De=se.known)==null?void 0:De.lastActivity;pe!==oe&&(oe=pe,m.markSeen(n))},G=()=>{z=!0,T=l.links.open(n,se=>{N=se,j()}),le.push(()=>T==null?void 0:T.close()),le.push(f.subscribe(()=>{const se=v();se&&(E=se),Ce()})),le.push(u.subscribe(n,Ce)),Ce()},ie=()=>{if(!C){m.markSeen(n),L=!0,ne==null||ne(),ne=null;for(const se of le.splice(0))se();for(const se of g.values())clearTimeout(se);g.clear(),i()}},X=se=>fe({toast:se}),ve=()=>u.rereadScreen(n),we=se=>{var pe;return fe({refill:{text:se,n:(((pe=x.refill)==null?void 0:pe.n)??0)+1}})},R=(se,pe)=>{const De=se.cursor;l.answers.give(n,()=>o(`${h}/choices`,{method:"POST",json:{index:De,label:se.options[De].label,text:pe}}),pe,se.context).then(ve,Se=>{X(Se instanceof Sn&&Se.status===409?p.optionsChanged:At(Se,p.notSentGiveBack,p.notSentGiveBack)),we(pe),ve()})},F=se=>{let pe=se;if(x.ctrl&&se){fe({ctrl:!1});const Se=VE(se[0]);Se&&(pe=Se+se.slice(1))}const De=(T==null?void 0:T.send(pe))??!1;return!De&&N!=="ended"&&X(p.notConnectedSend),De},I=(se,pe)=>F(ew(se,pe,x.ctrl)),Q=se=>{se.message&&u.apply(n,[se.message])},ye=(se,pe)=>{const De=se instanceof Sn&&se.status===404;De&&u.refresh(n),X(De?p.alreadySent:At(se,pe,pe))},Te=se=>`${h}/messages/${se.id}`,Ue=(se,pe)=>{const De=new Set(x.taking);pe?De.add(se):De.delete(se),fe({taking:De})},st=(se,pe,De)=>o(Te(se),{method:"POST",...pe}).then(Se=>(Q(Se),!0),Se=>(ye(Se,De),!1)),Ge=(se,pe)=>(o(se,{method:"POST",json:pe}).then(De=>{ap(n,De.screen),u.refresh(n)},De=>{fe({settling:null}),X(At(De,p.notPressed,p.notConnectedTap))}),!0),Kt=async se=>{let pe=!0;const De=await sw(se,{modeNow:async()=>{const Se=TE(n);return Se?Se.mode:o(`${h}/choices`).then(xn=>xn.mode,()=>{})},press:()=>pe=F(tw),sleep:Se=>new Promise(xn=>setTimeout(xn,Se))});pe&&(ve(),De!==se&&X(p.modeNotSwitched))};return{id:n,subscribe(se){return y.add(se),()=>void y.delete(se)},getSnapshot:()=>ee,hold(){C++,clearTimeout(P),!z&&!L&&G();let se=!1;return()=>{se||(se=!0,!--C&&(P=setTimeout(ie,0)))}},send:F,sendText:I,armCtrl:se=>fe({ctrl:se}),async paste(){try{const se=await l.readClipboard();se&&I(se,!1)}catch{X(p.clipboardUnreadable)}},sendMessage(se){var De;if(u.view(n).screen.panel)return fe({nudge:x.nudge+1}),!1;if(!se||x.ctrl)return I(se,!0);const pe=u.view(n).screen.choices;return pe&&!pe.submit&&((De=pe.options[pe.cursor])!=null&&De.typed)?(R(pe,se),!0):(u.send(n,se).catch(()=>{X(p.notSentGiveBack),we(se)}),!0)},press:se=>Ge(`${h}/keys`,{keys:se}),closeDialog:()=>Ge(`${h}/close`,{}),settle(){fe({settling:u.view(n).screen}),ve()},reread:ve,runCommand(se){x.commanding||(fe({commanding:se}),o(`${h}/command`,{method:"POST",json:{command:se}}).then(pe=>{pe.screen&&ap(n,pe.screen),u.refresh(n),!(pe.ran&&!se.includes(" "))&&(fe({commanding:null}),pe.ran||X(p.serverErrors["dialog-open"]))},pe=>{fe({commanding:null}),X(At(pe,p.notRun,p.notConnectedTap))}))},async switchMode(se){if(!x.switching){fe({switching:!0});try{await Kt(se)}finally{fe({switching:!1})}}},sendNow:se=>st(se,{json:{},idempotent:!0},p.notSentRetry),move:(se,pe)=>st(se,{json:{move:pe}},p.notMoved),unsend(se,pe){return Ue(se.id,!0),o(Te(se),{method:"DELETE"}).then(De=>(Q(De),pe&&we(De.text),!0),De=>(ye(De,pe?p.takeBackFailed:p.deleteFailed),!1)).finally(()=>Ue(se.id,!1))},giveBack:we,dismissSuggestion:()=>fe({dismissed:u.view(n).screen.suggestion??null}),loadCommands:async()=>(await o(`${h}/commands`)).commands,loadFiles:async()=>(await o(`${h}/files`)).files,async end(){if(x.ending)return!1;fe({ending:!0});try{await o(h,{method:"DELETE"})}catch(se){return fe({ending:!1}),X(At(se,p.notEnded,p.endFailed)),!1}return f.drop(n),!0},sayToast:X}}const dp="workoffdesk.snippets";function pw(n){const l=()=>{try{return n.getItem(dp)??""}catch{return""}};return{text:l,lines:()=>l().split(`
|
|
59
|
-
`).map(i=>i.trim()).filter(Boolean),set(i){try{n.setItem(dp,i)}catch{}}}}function bw(n,l){const i=l.toLowerCase();return n.filter(o=>o.toLowerCase().includes(i))}const sd="workoffdesk.sessions",rc="workoffdesk.ended",yw=50,vw=5e3,Sw=3e4,xw=3e3,Ew=5e3;function ww(n){const{storage:l}=n,i=()=>{try{const ee=JSON.parse(l.getItem(sd)??"null");return Array.isArray(ee)?ee:null}catch{return null}},o=ee=>{try{l.setItem(sd,JSON.stringify(ee))}catch{}},u=ee=>{try{const j=JSON.parse(l.getItem(ee)??"[]");return Array.isArray(j)?j:[]}catch{return[]}},f=(ee,j)=>{try{l.setItem(ee,JSON.stringify(j))}catch{}};let m=i(),h=null;const y=new Set;let g=null,v,E,_=null,x=1e3,N=!1,T=!1,C;const P=ee=>{m=ee;for(const j of y)j()},z=ee=>{const j=new Set(ee.map(G=>G.id)),fe=(m??[]).filter(G=>!j.has(G.id)),Ce=u(rc);if(fe.length||Ce.some(G=>j.has(G.id))){const G=new Set(fe.map(ie=>ie.id));f(rc,[...fe,...Ce.filter(ie=>!j.has(ie.id)&&!G.has(ie.id))].slice(0,yw))}P(ee),o(ee)},L=ee=>{if(ee.type==="heads"&&ee.machine===Bt&&typeof ee.epoch=="string"&&ee.heads&&typeof ee.heads=="object")return td({epoch:ee.epoch,heads:ee.heads});if(ee.type!=="sessions"||ee.machine!==Bt||!Array.isArray(ee.sessions))return;const j=typeof ee.asOf=="number"?ee.asOf:null;j!==null&&h!==null&&j<h||(h=j,z(ee.sessions))},le=()=>_!==null,ne=()=>le()&&!!n.ask&&!(N&&(g!=null&&g.isOpen())),W=async()=>{clearTimeout(C),C=void 0;const ee=n.ask;if(!(!ee||!ne())){if(!T){T=!0;try{L(await ee())}catch{}finally{T=!1}}ne()&&C===void 0&&(C=setTimeout(W,Ew))}},oe=()=>{n.ask&&C===void 0&&!T&&(C=setTimeout(W,xw))},he=()=>{clearTimeout(v),N=!1,td(null),oe();const ee=n.open("/api/events",{open:()=>{},message:j=>{g===ee&&(x=1e3,N=!0,L(JSON.parse(String(j))))},close:j=>{if(g===ee){if(g=null,N=!1,td(null),oe(),iy.includes(j))return n.onSignedOut();if(j===oy){x=500,v=setTimeout(he,Rb());return}v=setTimeout(he,x),x=Math.min(x*2,Sw)}}});g=ee},ge=()=>{if(!n.visibility.visible())return;const ee=g;g=null,ee==null||ee.close(),x=1e3,he()},_e=()=>{clearTimeout(E),E=void 0,!_&&(_=n.visibility.onChange(ge),he())},Y=()=>{_==null||_(),_=null,clearTimeout(v),clearTimeout(C),C=void 0;const ee=g;g=null,ee==null||ee.close()};return{current:()=>m,ended:ee=>u(rc).find(j=>j.id===ee)??null,subscribe(ee){return y.add(ee),y.size===1&&_e(),()=>{!y.delete(ee)||y.size||(E=setTimeout(()=>{E=void 0,Y()},vw))}},drop(ee){m&&z(m.filter(j=>j.id!==ee))},forget(){clearTimeout(E),E=void 0,Y(),P(null);try{l.removeItem(sd),l.removeItem(rc)}catch{}},reopen(){y.size&&_e()}}}const fp="workoffdesk.textSize",cy=80,ry=150,hp=10,mp=100;function Tw(n){return{get(){try{const l=Number(n.getItem(fp)??mp);if(Number.isInteger(l)&&l>=cy&&l<=ry)return l}catch{}return mp},keep(l){try{n.setItem(fp,String(l))}catch{}}}}const Vi={visible:()=>document.visibilityState==="visible",onChange:n=>(document.addEventListener("visibilitychange",n),()=>document.removeEventListener("visibilitychange",n))},uy=(n,l)=>XE(new WebSocket(_x(n)),l),dy=()=>Zt(`/login?next=${encodeURIComponent(location.pathname)}`,!0),xc=ww({open:uy,storage:ma,visibility:Vi,onSignedOut:dy,ask:()=>at("/api/events/now")}),Aw=rw({open:uy,visibility:Vi,onSignedOut:dy}),wd=xE({api:at,visibility:Vi,store:{kept:Wx,keep:(n,l)=>void Jx(n,l)}}),jc=qE({api:at,visibility:Vi,newId:()=>FE(crypto.getRandomValues(new Uint8Array(KE)))}),qd=bE(ma,jc),fy=QE(ma),Nw=EE(ma),hy=Tw(ma),Td=pw(ma),_w=mw({api:at,journals:jc,links:Aw,list:xc,seen:fy,answers:qd,readClipboard:()=>navigator.clipboard.readText()}),gp=YE(ma),Dc=(n,l)=>n(`/api/m/${Bt}/sessions`,{method:"POST",json:l}),kw=n=>n(`/api/m/${Bt}/agents`);async function Ow(n,l,i){const o=l.kind==="codex"?l.codexThreadId:l.claudeSessionId;try{return{session:i?await n(`/api/m/${Bt}/sessions/${l.id}/continue`,{method:"POST"}):await Dc(n,{kind:l.kind,cwd:l.cwd,resumeId:o})}}catch(u){if(o&&u instanceof Sn&&u.code==="open-on-mac")return{onMac:{agent:l.kind,sid:o}};throw u}}const pp=n=>!!(n.kind==="codex"?n.codexThreadId:n.claudeSessionId),Yd=n=>n("/api/recent").catch(l=>{if(l instanceof Sn&&l.status===404)return n("/api/claude/recent");throw l}),Rw=(n,l)=>n==="codex"?`/api/codex/threads/${l}/chat`:`/api/claude/sessions/${l}/chat`;function Mw(n,l){const i=l.trim().toLowerCase(),o=n.filter(u=>u.cwd&&(!i||`${u.title} ${u.cwd}`.toLowerCase().includes(i)));return{people:o.filter(u=>!u.automated),programs:o.filter(u=>u.automated)}}function Cw(n){const l=ls(n)==="codex";return`${l?"Codex · ":""}${n.openIn?p.alreadyOpen:n.folderGone?p.folderGoneShort:n.background?l?p.openElsewhere:p.inBackground:""}`}const jw=n=>!!n.openIn||!n.background&&!n.folderGone;function Dw(n){return n.openIn?{do:"open",id:n.openIn}:n.folderGone?{do:"gone"}:n.background?{do:"none"}:n.onMac?{do:"takeOver",status:n.onMac.status,terminals:n.onMac.terminals,waiting:!!n.takingOver}:{do:"resume"}}async function bp(n,l,i){const o=await n(`/api/m/${Bt}/sessions`,{method:"POST",json:{kind:ls(l),cwd:l.cwd,resumeId:l.sessionId,takeOver:i}});return"waiting"in o?null:o}const Lw=(n,l)=>n(ls(l)==="codex"?`/api/codex/threads/${l.sessionId}/take-over`:`/api/claude/sessions/${l.sessionId}/take-over`,{method:"DELETE"}),zw=n=>`workoffdesk attach ${n}`,Kd="workoffdesk.mac-sessions",Uw=24*36e5,Bw=20,yp=1e3,Hw=3e4,$w=15e3,Iw=(n,l)=>n.filter(i=>!i.automated&&!i.openIn&&i.cwd&&i.lastActivity>l-Uw).slice(0,Bw);function my(n){try{const l=JSON.parse(n.getItem(Kd)??"null");return Array.isArray(l)?l:[]}catch{return[]}}const Gw=(n,l)=>{const i=new Map(n.map((o,u)=>[o.sessionId,u]));return[...l.filter(o=>!i.has(o.sessionId)),...l.filter(o=>i.has(o.sessionId)).sort((o,u)=>i.get(o.sessionId)-i.get(u.sessionId))]};function qw(n,l){let i=!0,o,u=yp,f=0,m=null;const h=g=>{if(clearTimeout(o),!n.visibility.visible())return;const v=++f;Yd(n.api).then(E=>{if(!(!i||v!==f)){u=yp,o=setTimeout(()=>h(!1),$w),m=g||!m?E:Gw(m,E),l(m);try{n.storage.setItem(Kd,JSON.stringify(E))}catch{}}},()=>{!i||v!==f||(o=setTimeout(()=>h(g),u),u=Math.min(u*2,Hw))})};l(my(n.storage)),h(!0);const y=n.visibility.onChange(()=>{i&&n.visibility.visible()&&h(!0)});return()=>{i=!1,clearTimeout(o),y()}}function Yw(){xc.forget();try{ma.removeItem(Kd)}catch{}}function Kw(){return H.useSyncExternalStore(xc.subscribe,xc.current)}function vp(){const n=new URLSearchParams(location.search).get("next");Zt(n&&n.startsWith("/")&&!n.startsWith("//")?n:"/",!0)}function Fw(){const[n,l]=H.useState(""),[i,o]=H.useState(""),[u,f]=H.useState(null),[m,h]=H.useState(!1);H.useEffect(()=>{Yw(),wd.forget(),eE(),jc.forget()},[]);const y=async v=>{v.preventDefault(),h(!0),f(null);try{await at("/api/auth/password",{method:"POST",json:{username:n,password:i}}),vp()}catch(E){f(Jg(E)),h(!1)}},g=async()=>{h(!0),f(null);try{const v=await at("/api/auth/passkey/login/options",{method:"POST",json:{}}),E=await W0({optionsJSON:v});await at("/api/auth/passkey/login/verify",{method:"POST",json:{response:E}}),vp()}catch(v){const E=v==null?void 0:v.name;E==="NotAllowedError"||E==="AbortError"?f(null):v instanceof Sn&&v.status===401?f(p.unknownPasskey):f(Jg(v)),h(!1)}};return r.jsx("main",{className:"login",children:r.jsxs("div",{className:"login-card",children:[r.jsxs("div",{className:"brand",children:[r.jsx("img",{src:"/icon.svg",alt:""}),r.jsx("h1",{children:"WorkOffDesk"}),r.jsx("p",{children:p.tagline})]}),Pi()&&r.jsxs(r.Fragment,{children:[r.jsxs("button",{className:"btn primary block",onClick:g,disabled:m,children:[r.jsx(iE,{}),p.faceId]}),r.jsx("div",{className:"divider",children:p.orPassword})]}),r.jsxs("form",{onSubmit:y,style:{display:"contents"},children:[r.jsxs("label",{className:"field",children:[p.username,r.jsx("input",{value:n,onChange:v=>l(v.target.value),autoComplete:"username webauthn",autoCapitalize:"none",autoCorrect:"off",spellCheck:!1,required:!0})]}),r.jsxs("label",{className:"field",children:[p.password,r.jsx("input",{type:"password",value:i,onChange:v=>o(v.target.value),autoComplete:"current-password",required:!0})]}),u&&r.jsx("div",{className:"alert",role:"alert",children:u}),r.jsx("button",{className:"btn primary block",type:"submit",disabled:m||!n||!i,children:p.login})]})]})})}const Pw=150,Sp=n=>n==="~"||n.startsWith("~/")||n.startsWith("/"),gy=n=>n.slice(n.lastIndexOf("/")+1),Xw=(n,l)=>{let i=0;for(const o of l)if(i=n.indexOf(o,i)+1,!i)return!1;return!0};function Zw(n,l){const i=l.toLowerCase(),o=u=>{const f=gy(u).toLowerCase();return f.startsWith(i)?0:f.includes(i)?1:Xw(u.toLowerCase(),i)?2:null};return n.map(u=>({dir:u,rank:o(u)})).filter(u=>u.rank!==null).sort((u,f)=>u.rank-f.rank).map(u=>u.dir)}function Qw(n,l){return`${n==="~"?"~/":n.slice(0,n.lastIndexOf("/")+1)}${gy(l)}/`}function Vw(n){const l=new Set;let i=null,o="",u=null,f,m=!1;const h=()=>{const E=Sp(o);return E?{text:o,path:E,rows:(u==null?void 0:u.rows)??null,error:(u==null?void 0:u.error)??null}:{text:o,path:E,rows:i&&Zw(i,o),error:null}};let y=h();const g=()=>{y=h();for(const E of l)E()},v=E=>{const _=(x,N)=>{E!==o||!m||(u={rows:x,error:N},g())};n(`/api/m/${Bt}/dirs?path=${encodeURIComponent(E)}`).then(x=>_(x,null),x=>_([],At(x,p.loadFailed)))};return{subscribe(E){return l.add(E),()=>void l.delete(E)},getSnapshot:()=>y,type(E){m&&(o=E.trim(),clearTimeout(f),Sp(o)?f=setTimeout(()=>v(o),Pw):u=null,g())},setKnown(E){i=E,g()},hold(){return m=!0,()=>{m=!1,clearTimeout(f)}}}}var Fd=Sb();function Lc(n){const l=H.useId(),{onClose:i}=n;H.useEffect(()=>{const u=f=>f.key==="Escape"&&i();return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[i]);const o=n.onBack&&r.jsx("button",{className:"icon-btn",onClick:n.onBack,"aria-label":p.back,children:r.jsx(Bd,{})});return Fd.createPortal(r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"scrim",onClick:n.onClose}),r.jsxs("div",{className:["sheet",n.bar&&"bar",n.className].filter(Boolean).join(" "),role:"dialog","aria-modal":"true","aria-labelledby":l,children:[r.jsxs("div",{className:"sheet-head",children:[n.bar?r.jsx("span",{className:"sheet-side",children:o}):o,r.jsx("h2",{id:l,children:n.title}),n.head,r.jsx("button",{className:"sheet-close",onClick:n.onClose,"aria-label":p.close,children:r.jsx(Qi,{})})]}),r.jsx("div",{className:"sheet-body",children:n.children})]})]}),document.body)}function Pd(n){const[l,i]=H.useState({data:null,error:null});return H.useEffect(()=>{let o=!1;return n().then(u=>!o&&i({data:u,error:null}),u=>!o&&i({data:null,error:At(u,p.loadFailed)})),()=>{o=!0}},[n]),l}function Ww(n,l){var T;const[i,o]=H.useState("menu"),[u,f]=H.useState(!1),[m,h]=H.useState(null),[y,g]=H.useState("claude"),v=H.useMemo(()=>()=>kw(n),[n]),E=(T=Pd(v).data)==null?void 0:T.codex,_=C=>{g(C),o("project")},x=async C=>{f(!0),h(null);try{l(await Dc(n,C))}catch(P){h(At(P,p.openFailed)),f(!1)}},N=i==="menu"?p.newSession:i==="project"?p.pickProject:p.resumeRecent;return{step:i,setStep:o,busy:u,error:m,agent:y,codex:E,pick:_,run:x,title:N}}const Wi=n=>H.useSyncExternalStore(n.subscribe,n.getSnapshot);function Jw(n){return{useSession(l){const i=n.get(l);return H.useEffect(()=>i.hold(),[i]),[i,Wi(i)]}}}const eT=n=>n("/api/claude/projects");function tT(n){var v;const l=H.useMemo(()=>()=>eT(n),[n]),{data:i,error:o}=Pd(l),u=H.useMemo(()=>Vw(n),[n]);H.useEffect(()=>u.hold(),[u]),H.useEffect(()=>u.setKnown(i),[u,i]);const f=Wi(u),[m,h]=H.useState(""),y=E=>{h(E),u.type(E)},g=f.path?f.text:(v=f.rows)==null?void 0:v[0];return{data:i,error:o,found:f,box:m,type:y,chosen:g}}const py=n=>Zt(`/m/${Bt}/s/${n.id}`);async function xp(n){py(await Dc(at,n))}function nT({onClose:n}){const{step:l,setStep:i,busy:o,error:u,agent:f,codex:m,pick:h,run:y,title:g}=Ww(at,py);return r.jsxs(Lc,{bar:!0,title:g,onClose:n,onBack:l==="menu"?void 0:()=>i("menu"),children:[u&&r.jsx("div",{className:"alert",role:"alert",children:u}),l==="menu"&&r.jsxs(r.Fragment,{children:[r.jsxs("button",{className:"option",disabled:o,onClick:()=>h("claude"),children:[r.jsx("span",{className:"opt-icon",children:r.jsx(aE,{})}),r.jsxs("span",{className:"opt-text",children:[r.jsx("span",{className:"opt-title",children:p.newInProject}),r.jsx("span",{className:"opt-sub",children:p.newInProjectSub})]})]}),r.jsxs("button",{className:"option",disabled:o,onClick:()=>i("recent"),children:[r.jsx("span",{className:"opt-icon",children:r.jsx(sE,{})}),r.jsxs("span",{className:"opt-text",children:[r.jsx("span",{className:"opt-title",children:p.resumeRecent}),r.jsx("span",{className:"opt-sub",children:p.resumeRecentSub})]})]}),m&&r.jsxs(r.Fragment,{children:[r.jsx("hr",{className:"opt-rule"}),r.jsxs("button",{className:"option",disabled:o,onClick:()=>h("codex"),children:[r.jsx("span",{className:"opt-icon",children:r.jsx(lE,{})}),r.jsxs("span",{className:"opt-text",children:[r.jsx("span",{className:"opt-title",children:p.newCodexInProject}),r.jsx("span",{className:"opt-sub",children:p.newCodexInProjectSub})]})]})]})]}),l==="project"&&r.jsx(sT,{busy:o,onPick:(v,E)=>y({kind:f,cwd:v,title:E||void 0})}),l==="recent"&&r.jsx(lT,{busy:o,onPick:v=>Zt(v.openIn?`/m/${Bt}/s/${v.openIn}`:`/${ls(v)}/${v.sessionId}`)})]})}const aT=()=>Yd(at);function sT({busy:n,onPick:l}){var v,E;const{error:i,found:o,box:u,type:f,chosen:m}=tT(at),[h,y]=H.useState(""),g=H.useRef(null);return r.jsxs(r.Fragment,{children:[r.jsx("input",{className:"search","aria-label":p.nameOptional,placeholder:p.nameOptionalHint,value:h,onChange:_=>y(_.target.value)}),r.jsxs("form",{onSubmit:_=>{_.preventDefault(),m&&l(m,h)},style:{display:"flex",gap:8},children:[r.jsx("input",{ref:g,className:"search","aria-label":p.findProject,placeholder:p.findProject,value:u,onChange:_=>f(_.target.value),autoCapitalize:"none",autoCorrect:"off",spellCheck:!1}),r.jsx("button",{className:"btn small",type:"submit",disabled:n||!m,children:p.open})]}),o.path?o.error&&r.jsx("div",{className:"alert",children:o.error}):i&&r.jsx("div",{className:"alert",children:i}),!o.rows&&!(i&&!o.path)&&r.jsx("p",{className:"muted center",children:p.loading}),((v=o.rows)==null?void 0:v.length)===0&&r.jsx("p",{className:"note",children:o.path?p.noFolders:o.text?p.notFound(o.text):p.noProjects}),(E=o.rows)==null?void 0:E.map(_=>r.jsxs("div",{className:"option-row",children:[r.jsxs("button",{className:"option",disabled:n,onClick:()=>l(_,h),children:[r.jsx("span",{className:"opt-icon",children:r.jsx(nE,{})}),r.jsxs("span",{className:"opt-text",children:[r.jsx("span",{className:"opt-title",children:_.split("/").pop()||_}),r.jsx("span",{className:"opt-sub",children:Ba(_)})]})]}),o.path&&r.jsx("button",{className:"option-in","aria-label":p.lookInside(_.split("/").pop()||_),onClick:()=>{var x;f(Qw(o.text,_)),(x=g.current)==null||x.focus()},children:r.jsx(Cc,{})})]},_))]})}function lT({busy:n,onPick:l}){const{data:i,error:o}=Pd(aT),[u,f]=H.useState(""),[m,h]=H.useState(!1),{people:y,programs:g}=H.useMemo(()=>Mw(i??[],u),[i,u]),v=y.length+g.length,E=u.trim()!=="",_=x=>r.jsx("button",{className:"option",disabled:n||!jw(x),onClick:()=>l(x),children:r.jsxs("span",{className:"opt-text",children:[r.jsx("span",{className:"opt-title",children:x.title}),r.jsxs("span",{className:"opt-sub",children:[Cw(x),Ua(x.lastActivity)," · ",Ba(x.cwd)]})]})},x.sessionId);return r.jsxs(r.Fragment,{children:[r.jsx("input",{className:"search",placeholder:p.searchTitlePath,value:u,onChange:x=>f(x.target.value),autoCorrect:"off",spellCheck:!1}),o&&r.jsx("div",{className:"alert",children:o}),!i&&!o&&r.jsx("p",{className:"muted center",children:p.loading}),i&&v===0&&r.jsx("p",{className:"note",children:u?p.noMatch:p.noConversations}),y.map(_),g.length>0&&!E&&r.jsxs("button",{className:"fold","aria-expanded":m,onClick:()=>h(!m),children:[r.jsx(Bd,{}),p.automated(g.length)]}),(E||m)&&g.map(_)]})}function iT(n,l,i){const[o,u]=H.useState(Db(l)),[f,m]=H.useState(!1),[h,y]=H.useState(null);return{name:o,setName:u,busy:f,error:h,save:async()=>{m(!0),y(null);try{await n(`/api/m/${Bt}/sessions/${l.id}`,{method:"PATCH",json:{title:o},idempotent:!0}),i()}catch(v){y(At(v,p.renameFailed)),m(!1)}}}}function by({session:n,onClose:l}){const{name:i,setName:o,busy:u,error:f,save:m}=iT(at,n,l);return r.jsxs(Lc,{title:p.rename,onClose:l,children:[f&&r.jsx("div",{className:"alert",role:"alert",children:f}),r.jsxs("form",{className:"rename-form",onSubmit:h=>{h.preventDefault(),m()},children:[r.jsx("input",{className:"search","aria-label":p.name,placeholder:Zi(n.cwd),value:i,onChange:h=>o(h.target.value),enterKeyHint:"done",autoFocus:!0}),r.jsx("button",{className:"btn small primary",type:"submit",disabled:u,children:p.save})]}),r.jsx("p",{className:"sheet-note",children:p.renameNote})]})}const oT=(n,l)=>{const i=l.trim().toLowerCase();return!i||[n.title,n.cwd,Ba(n.cwd)].some(o=>o.toLowerCase().includes(i))};function cT(n,l){const i=n&&[...n].sort((f,m)=>m.lastActivity-f.lastActivity),o=(i==null?void 0:i.filter(f=>oT(f,l)))??[],u=[];for(const f of o){const m=u.find(h=>h.cwd===f.cwd);m?m.sessions.push(f):u.push({cwd:f.cwd,title:Zi(f.cwd),sessions:[f]})}return u.length===1&&(u[0].title=null),{sorted:i,shown:o,groups:u}}function rT(n,l){return l||!Db(n)?null:Zi(n.cwd)}const Ad=n=>l=>{l.metaKey||l.ctrlKey||l.shiftKey||(l.preventDefault(),Zt(n))};function uT(n){const[l,i]=H.useState(()=>my(ma)),o=(n??[]).flatMap(u=>u.claudeSessionId??u.codexThreadId??[]).sort().join(" ");return H.useEffect(()=>qw({api:at,storage:ma,visibility:Vi},i),[o]),Iw(l,Date.now())}const Ep=10;function dT({s:n,folder:l,open:i,current:o,unread:u,onOpen:f,onRename:m}){const h=`/m/${Bt}/s/${n.id}`,y=wa(n.kind)?n.status:null,g=H.useRef(null),[v,E]=H.useState(null),_=i?-88:0,x=v??_,N=z=>{z.button===0&&(g.current={x:z.clientX,y:z.clientY,swiping:!1,moved:!1})},T=z=>{const L=g.current;if(!L)return;const le=z.clientX-L.x,ne=z.clientY-L.y;if(!L.swiping&&!L.moved){if(Math.abs(le)<Ep&&Math.abs(ne)<Ep||(L.moved=!0,Math.abs(le)<=Math.abs(ne)))return;L.swiping=!0,z.currentTarget.setPointerCapture(z.pointerId)}L.swiping&&E(Math.min(0,Math.max(-88,_+le)))},C=()=>{var z;(z=g.current)!=null&&z.swiping&&v!==null&&f(v<-88/2),E(null)},P=z=>{const L=g.current;if(g.current=null,L!=null&&L.moved||i){z.preventDefault(),i&&!(L!=null&&L.moved)&&f(!1);return}Ad(h)(z)};return r.jsxs("div",{className:`sess-row${v!==null?" dragging":""}`,children:[x<0&&r.jsx("button",{className:"sess-action",onClick:m,children:p.renameAction}),r.jsxs("a",{className:o?"sess-item current":"sess-item","aria-current":o?"page":void 0,"data-testid":"session-card",href:h,style:x?{transform:`translateX(${x}px)`}:void 0,onPointerDown:N,onPointerMove:T,onPointerUp:C,onPointerCancel:()=>{g.current=null,E(null)},onClick:P,draggable:!1,children:[r.jsxs("span",{className:`avatar ${n.kind}`,"aria-hidden":!0,children:[n.kind==="codex"?r.jsx(Fb,{}):wa(n.kind)?r.jsx(Pb,{}):r.jsx(Kb,{}),y==="waiting"&&r.jsx("span",{className:"needs-you"}),y==="working"&&r.jsx("span",{className:"busy"})]}),r.jsxs("span",{className:"sess-main",children:[r.jsxs("span",{className:"sess-top",children:[y==="working"&&r.jsx("span",{className:"sess-badge working",children:p.busy}),y==="waiting"&&r.jsx("span",{className:"sess-badge waiting",children:p.needsYou}),u&&y!=="working"&&y!=="waiting"&&r.jsx("span",{className:"sess-badge unread",children:p.unread}),r.jsx("span",{className:"sess-name",children:n.title}),l&&r.jsx("span",{className:"sess-dir",children:l}),r.jsx("span",{className:"sess-time",children:Lb(n.lastActivity)})]}),r.jsx("span",{className:"sess-preview",children:Dx(n)})]})]})]})}function wp({current:n}={}){const l=Kw(),i=uT(l),[o,u]=H.useState(!1),[f,m]=H.useState(""),[h,y]=H.useState(null),[g,v]=H.useState(null),{sorted:E,shown:_,groups:x}=cT(l,f),N=E?fy.unreadOf(E):new Set;return r.jsxs("main",{className:"list-page",children:[r.jsxs("header",{className:"list-top",children:[r.jsx("a",{className:"icon-btn",href:"/settings","aria-label":p.settings,onClick:Ad("/settings"),children:r.jsx(tE,{})}),r.jsx("h1",{children:p.sessions}),r.jsx("button",{className:"icon-btn","aria-label":p.newSession,onClick:()=>u(!0),children:r.jsx(Qb,{})})]}),!E&&r.jsx("p",{className:"muted center",children:p.loading}),(E==null?void 0:E.length)===0&&r.jsxs("div",{className:"empty",children:[r.jsx(Kb,{}),r.jsx("strong",{children:p.noSessions}),r.jsx("span",{children:p.noSessionsSub})]}),!!(E!=null&&E.length)&&_.length===0&&r.jsx("p",{className:"muted center",children:p.notFound(f.trim())}),_.length>0&&r.jsx("div",{className:"sess-list",children:x.map(T=>[T.title&&r.jsxs("h2",{className:"sess-group",children:[T.title,r.jsx("small",{children:T.sessions.length})]},`g-${T.cwd}`),...T.sessions.map(C=>r.jsx(dT,{s:C,folder:rT(C,T.title),unread:N.has(C.id),open:h===C.id,current:C.id===n,onOpen:P=>y(P?C.id:null),onRename:()=>{y(null),v(C)}},C.id))])}),i.length>0&&!f.trim()&&r.jsxs("div",{className:"sess-list",children:[r.jsxs("h2",{className:"sess-group",children:[p.otherMacSessions,r.jsx("small",{children:i.length})]}),i.map(T=>{var C,P,z,L,le;return r.jsxs("a",{className:T.sessionId===n?"sess-item mac current":"sess-item mac","aria-current":T.sessionId===n?"page":void 0,href:`/${ls(T)}/${T.sessionId}`,onClick:Ad(`/${ls(T)}/${T.sessionId}`),children:[r.jsxs("span",{className:`avatar ${ls(T)}${T.onMac?"":" mac"}`,"aria-hidden":!0,children:[ls(T)==="codex"?r.jsx(Fb,{}):r.jsx(Pb,{}),((C=T.onMac)==null?void 0:C.status)==="waiting"&&r.jsx("span",{className:"needs-you"}),((P=T.onMac)==null?void 0:P.status)==="busy"&&r.jsx("span",{className:"busy"})]}),r.jsxs("span",{className:"sess-main",children:[r.jsxs("span",{className:"sess-top",children:[((z=T.onMac)==null?void 0:z.status)==="busy"&&r.jsx("span",{className:"sess-badge working",children:p.busy}),((L=T.onMac)==null?void 0:L.status)==="waiting"&&r.jsx("span",{className:"sess-badge waiting",children:p.needsYou}),(((le=T.onMac)==null?void 0:le.terminals)??0)>1&&r.jsx("span",{className:"sess-badge waiting",children:p.openInTerminals(T.onMac.terminals)}),r.jsx("span",{className:"sess-name",children:T.title}),T.cwd&&r.jsx("span",{className:"sess-dir",children:Zi(T.cwd)}),r.jsx("span",{className:"sess-time",children:Lb(T.lastActivity)})]}),r.jsx("span",{className:"sess-preview",children:T.lastPrompt??Ba(T.cwd??"")})]})]},T.sessionId)}),r.jsx("p",{className:"muted sess-hint",children:p.startInTmuxHint})]}),!!(E!=null&&E.length)&&r.jsxs("label",{className:"list-search",children:[r.jsx(fE,{}),r.jsx("input",{type:"search","aria-label":p.search,placeholder:p.search,value:f,onChange:T=>m(T.target.value),enterKeyHint:"search"})]}),o&&r.jsx(nT,{onClose:()=>u(!1)}),g&&r.jsx(by,{session:g,onClose:()=>v(null)})]})}function zc(n){const{onClose:l}=n;H.useEffect(()=>{const u=f=>f.key==="Escape"&&l();return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[l]);const i=r.jsx("button",{className:"action",onClick:l,autoFocus:!0,children:n.cancel??p.cancel}),o=n.actions.map(u=>r.jsx("button",{className:u.destructive?"action danger":"action",onClick:()=>{l(),u.run()},children:u.label},u.label));return Fd.createPortal(r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"scrim soft",onClick:l}),r.jsx("div",{className:"action-sheet",children:r.jsxs("div",{className:n.side?"action-card alert":"action-card",role:"dialog","aria-modal":"true","aria-label":n.title,children:[(n.title||n.message)&&r.jsxs("div",{className:"action-head",children:[n.title&&r.jsx("div",{className:"action-title",children:n.title}),n.message&&r.jsx("div",{className:"action-message",children:n.message})]}),n.side?r.jsxs("div",{className:"action-row",children:[i,o]}):r.jsxs(r.Fragment,{children:[o,i]})]})})]}),document.body)}function Ec(n){const[l,i]=H.useState(!1);return r.jsxs(r.Fragment,{children:[r.jsx("button",{className:n.className??"btn small danger",disabled:n.disabled,onClick:()=>i(!0),children:n.label}),l&&r.jsx(zc,{title:n.title,message:n.what,side:!0,actions:[{label:n.action,run:n.onConfirm,destructive:n.destructive}],onClose:()=>i(!1)})]})}function Uc({title:n,onBack:l,right:i}){return r.jsxs("header",{className:"pagebar",children:[r.jsx("button",{className:"pagebar-back","aria-label":p.back,onClick:l,children:r.jsx(Bd,{})}),r.jsx("h1",{children:n}),r.jsx("div",{className:"pagebar-right",children:i})]})}function fT(){"serviceWorker"in navigator&&window.isSecureContext&&(navigator.serviceWorker.register("/sw.js").catch(()=>{}),navigator.serviceWorker.addEventListener("message",n=>{var l;((l=n.data)==null?void 0:l.type)==="open"&&typeof n.data.url=="string"&&(history.pushState(null,"",n.data.url),window.dispatchEvent(new PopStateEvent("popstate")))}))}async function hT(){return location.protocol!=="https:"?"insecure":!("serviceWorker"in navigator)||!("PushManager"in window)||!("Notification"in window)?"unsupported":Notification.permission==="denied"?"denied":await(await navigator.serviceWorker.ready).pushManager.getSubscription()?"on":"off"}function mT(n){const l=n.replace(/-/g,"+").replace(/_/g,"/"),i=atob(l+"=".repeat((4-l.length%4)%4));return Uint8Array.from(i,o=>o.charCodeAt(0))}async function gT(){if(await Notification.requestPermission()!=="granted")return"denied";const{publicKey:n}=await at("/api/push/key"),i=await(await navigator.serviceWorker.ready).pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:mT(n)});return await at("/api/push/subscribe",{method:"POST",json:i.toJSON()}),"on"}async function pT(){const l=await(await navigator.serviceWorker.ready).pushManager.getSubscription();return l&&(await at("/api/push/subscribe",{method:"DELETE",json:{endpoint:l.endpoint}}),await l.unsubscribe()),"off"}const yy=hy.get;function vy(n=yy()){document.documentElement.style.setProperty("--text-scale",String(n/100))}function bT(n){vy(n),hy.keep(n)}const uc={state:"loading"},Sy=n=>n.then(l=>({state:"loaded",rows:l}),l=>({state:"failed",error:At(l,p.loadFailed)})),Tp=n=>Sy(n("/api/auth/passkeys")),Ap=n=>Sy(n("/api/auth/logins").then(l=>l.sort((i,o)=>Number(o.current)-Number(i.current)||o.lastSeen-i.lastSeen)));function yT(n){const[l,i]=H.useState(n.themeChoice.get()),o={system:p.followSystem,light:p.themeLight,dark:p.themeDark,eye:p.themeEye},u=y=>{n.setTheme(y),i(y)},f=n.languageChoice.get(),m={system:p.followSystem,zh:"中文",en:"English"};return{colours:l,themes:o,pickTheme:u,language:f,languages:m,pickLanguage:y=>{y!==f&&(n.languageChoice.keep(y),n.restart())}}}function vT(n){const[l,i]=H.useState(uc),[o,u]=H.useState(uc),f=()=>Tp(n).then(i),m=()=>Ap(n).then(u),h=()=>Promise.all([f(),m()]);H.useEffect(()=>{Tp(n).then(i),Ap(n).then(u)},[n]);const y=l.state==="loaded"?l.rows:null,g=o.state==="loaded"?o.rows:null;return{passkeyList:l,loginList:o,passkeys:y,logins:g,load:h,retryPasskeys:()=>{i(uc),f()},retryLogins:()=>{u(uc),m()}}}function ST(){const[n,l]=H.useState(yy),i=o=>{l(o),bT(o)};return r.jsxs("section",{className:"section",children:[r.jsx("h2",{children:p.textSize}),r.jsxs("div",{className:"group",children:[r.jsxs("div",{className:"row",children:[r.jsxs("div",{className:"row-main",children:[r.jsx("strong",{children:p.wholeApp}),r.jsx("span",{children:p.thisDeviceOnly})]}),r.jsxs("div",{className:"stepper",children:[r.jsx("button",{className:"btn small","aria-label":p.smaller,disabled:n<=cy,onClick:()=>i(n-hp),children:"A−"}),r.jsxs("output",{role:"status","aria-label":p.textSize,children:[n,"%"]}),r.jsx("button",{className:"btn small","aria-label":p.larger,disabled:n>=ry,onClick:()=>i(n+hp),children:"A+"})]})]}),r.jsx("div",{className:"row text-preview",children:p.textPreview})]})]})}function xT(){const{colours:n,themes:l,pickTheme:i,language:o,languages:u,pickLanguage:f}=yT({themeChoice:jd,setTheme:U0,languageChoice:yb,restart:()=>location.reload()});return r.jsxs("section",{className:"section",children:[r.jsx("h2",{children:p.appearance}),r.jsxs("div",{className:"group",children:[r.jsx(Np,{label:p.theme,names:l,value:n,onPick:i}),r.jsx(Np,{label:p.language,note:p.languageRestarts,names:u,value:o,onPick:f})]})]})}function Np(n){const[l,i]=H.useState(!1),o=Object.keys(n.names);return r.jsxs(r.Fragment,{children:[r.jsxs("button",{className:"row row-link",onClick:()=>i(!0),children:[r.jsx("div",{className:"row-main",children:r.jsx("strong",{children:n.label})}),r.jsx("span",{className:"row-value",children:n.names[n.value]}),r.jsx(Cc,{})]}),l&&r.jsx(zc,{title:n.label,message:n.note,actions:o.map(u=>({label:n.names[u],run:()=>n.onPick(u)})),onClose:()=>i(!1)})]})}function _p({list:n,retry:l}){return n.state==="loading"?r.jsx("div",{className:"row empty-row",children:p.loading}):n.state==="loaded"?null:r.jsxs("div",{className:"row",children:[r.jsx("div",{className:"row-main",role:"alert",children:r.jsx("span",{children:n.error})}),r.jsx("button",{className:"btn small",onClick:l,children:p.tryAgain})]})}function ET(){const[n,l]=H.useState(Td.text);return r.jsxs("section",{className:"section",children:[r.jsx("h2",{children:p.snippets}),r.jsxs("div",{className:"group",children:[r.jsx("textarea",{className:"snippets-input","aria-label":p.snippetsLines,rows:5,placeholder:p.snippetsPlaceholder,value:n,onChange:i=>{l(i.target.value),Td.set(i.target.value)}}),r.jsx("div",{className:"row empty-row",children:p.snippetsNote})]})]})}function wT(){const[n,l]=H.useState(null);return H.useEffect(()=>{at("/api/me").then(i=>l(i.username??null),()=>{})},[]),r.jsxs("section",{className:"section",children:[r.jsx("h2",{children:p.account}),r.jsx("div",{className:"group",children:r.jsxs("div",{className:"row",children:[r.jsxs("div",{className:"row-main",children:[n&&r.jsx("strong",{children:n}),n?r.jsx("span",{children:location.origin}):r.jsx("strong",{children:location.origin}),r.jsx("span",{children:p.appRelease("1.0.0")})]}),r.jsx("span",{className:"row-check",children:r.jsx(Xb,{})})]})})]})}const kp={insecure:p.pushInsecure,unsupported:p.pushUnsupported,denied:p.pushDenied};function TT(){const{passkeyList:n,loginList:l,passkeys:i,logins:o,load:u,retryPasskeys:f,retryLogins:m}=vT(at),[h,y]=H.useState(null),[g,v]=H.useState(null),[E,_]=H.useState(!1);H.useEffect(()=>{hT().then(y,()=>y("unsupported"))},[]);const x=async L=>{_(!0),v(null);try{await L()}catch(le){const ne=le==null?void 0:le.name;ne!=="NotAllowedError"&&ne!=="AbortError"&&v(At(le,p.failed))}finally{_(!1)}},N=()=>x(async()=>{const L=await at("/api/auth/passkey/register/options",{method:"POST",json:{}}),le=await Z0({optionsJSON:L});await at("/api/auth/passkey/register/verify",{method:"POST",json:{response:le}}),u()}),T=L=>x(async()=>{await at(`/api/auth/passkeys/${encodeURIComponent(L)}`,{method:"DELETE"}),u()}),C=L=>x(async()=>{await at(`/api/auth/logins/${L}`,{method:"DELETE"}),u()}),P=()=>x(async()=>y(h==="on"?await pT():await gT())),z=()=>x(async()=>{await at("/api/auth/logout",{method:"POST"}),Zt("/login",!0)});return r.jsxs(r.Fragment,{children:[r.jsx(Uc,{title:p.settings,onBack:()=>Zt("/")}),r.jsxs("main",{className:"page",children:[g&&r.jsx("div",{className:"alert",role:"alert",children:g}),r.jsx("section",{className:"section",children:r.jsx("div",{className:"group",children:r.jsxs("button",{className:"row row-link",onClick:()=>Zt("/mac"),children:[r.jsxs("div",{className:"row-main",children:[r.jsx("strong",{children:p.thisMac}),r.jsx("span",{children:p.thisMacSub})]}),r.jsx(Cc,{})]})})}),r.jsx(ST,{}),r.jsx(xT,{}),r.jsxs("section",{className:"section",children:[r.jsx("h2",{children:p.pushTitle}),r.jsxs("div",{className:"group",children:[r.jsxs("div",{className:"row",children:[r.jsxs("div",{className:"row-main",children:[r.jsx("strong",{children:p.pushRemind}),r.jsx("span",{children:p.pushRemindSub})]}),r.jsxs("label",{className:"switch",children:[r.jsx("input",{type:"checkbox","aria-label":p.pushTitle,checked:h==="on",disabled:E||h!=="on"&&h!=="off",onChange:P}),r.jsx("span",{})]})]}),h&&kp[h]&&r.jsx("div",{className:"row empty-row",children:kp[h]})]})]}),r.jsx(ET,{}),r.jsx(wT,{}),r.jsxs("section",{className:"section",children:[r.jsx("h2",{children:p.passkeysTitle}),r.jsxs("div",{className:"group",children:[r.jsx(_p,{list:n,retry:f}),(i==null?void 0:i.length)===0&&r.jsx("div",{className:"row empty-row",children:p.passkeyNone}),i==null?void 0:i.map(L=>r.jsxs("div",{className:"row","data-testid":"passkey-row",children:[r.jsxs("div",{className:"row-main",children:[r.jsx("strong",{children:L.name}),r.jsxs("span",{children:[p.addedAgo(Ua(L.createdAt)),L.lastUsedAt?p.lastUsedAgo(Ua(L.lastUsedAt)):""]})]}),r.jsx(Ec,{label:p.delete,title:p.confirmDelete,what:L.name,action:p.confirmDelete,destructive:!0,disabled:E,onConfirm:()=>T(L.id)})]},L.id)),Pi()&&r.jsx("button",{className:"row row-link row-add",disabled:E,onClick:N,children:p.addPasskey})]})]}),r.jsxs("section",{className:"section",children:[r.jsx("h2",{children:p.loggedIn}),r.jsxs("div",{className:"group",children:[r.jsx(_p,{list:l,retry:m}),o==null?void 0:o.map(L=>r.jsxs("div",{className:"row","data-testid":"login-row",children:[r.jsxs("div",{className:"row-main",children:[r.jsxs("strong",{children:[ep(L.ua),L.current&&r.jsx("span",{className:"chip idle",children:p.thisDevice})]}),r.jsx("span",{children:p.loginBy(L.method==="passkey",Ua(L.lastSeen))})]}),!L.current&&r.jsx(Ec,{label:p.revoke,title:p.confirmRevoke,what:`${ep(L.ua)}
|
|
59
|
+
`).map(i=>i.trim()).filter(Boolean),set(i){try{n.setItem(dp,i)}catch{}}}}function bw(n,l){const i=l.toLowerCase();return n.filter(o=>o.toLowerCase().includes(i))}const sd="workoffdesk.sessions",rc="workoffdesk.ended",yw=50,vw=5e3,Sw=3e4,xw=3e3,Ew=5e3;function ww(n){const{storage:l}=n,i=()=>{try{const ee=JSON.parse(l.getItem(sd)??"null");return Array.isArray(ee)?ee:null}catch{return null}},o=ee=>{try{l.setItem(sd,JSON.stringify(ee))}catch{}},u=ee=>{try{const j=JSON.parse(l.getItem(ee)??"[]");return Array.isArray(j)?j:[]}catch{return[]}},f=(ee,j)=>{try{l.setItem(ee,JSON.stringify(j))}catch{}};let m=i(),h=null;const y=new Set;let g=null,v,E,_=null,x=1e3,N=!1,T=!1,C;const P=ee=>{m=ee;for(const j of y)j()},z=ee=>{const j=new Set(ee.map(G=>G.id)),fe=(m??[]).filter(G=>!j.has(G.id)),Ce=u(rc);if(fe.length||Ce.some(G=>j.has(G.id))){const G=new Set(fe.map(ie=>ie.id));f(rc,[...fe,...Ce.filter(ie=>!j.has(ie.id)&&!G.has(ie.id))].slice(0,yw))}P(ee),o(ee)},L=ee=>{if(ee.type==="heads"&&ee.machine===Bt&&typeof ee.epoch=="string"&&ee.heads&&typeof ee.heads=="object")return td({epoch:ee.epoch,heads:ee.heads});if(ee.type!=="sessions"||ee.machine!==Bt||!Array.isArray(ee.sessions))return;const j=typeof ee.asOf=="number"?ee.asOf:null;j!==null&&h!==null&&j<h||(h=j,z(ee.sessions))},le=()=>_!==null,ne=()=>le()&&!!n.ask&&!(N&&(g!=null&&g.isOpen())),W=async()=>{clearTimeout(C),C=void 0;const ee=n.ask;if(!(!ee||!ne())){if(!T){T=!0;try{L(await ee())}catch{}finally{T=!1}}ne()&&C===void 0&&(C=setTimeout(W,Ew))}},oe=()=>{n.ask&&C===void 0&&!T&&(C=setTimeout(W,xw))},he=()=>{clearTimeout(v),N=!1,td(null),oe();const ee=n.open("/api/events",{open:()=>{},message:j=>{g===ee&&(x=1e3,N=!0,L(JSON.parse(String(j))))},close:j=>{if(g===ee){if(g=null,N=!1,td(null),oe(),iy.includes(j))return n.onSignedOut();if(j===oy){x=500,v=setTimeout(he,Rb());return}v=setTimeout(he,x),x=Math.min(x*2,Sw)}}});g=ee},ge=()=>{if(!n.visibility.visible())return;const ee=g;g=null,ee==null||ee.close(),x=1e3,he()},_e=()=>{clearTimeout(E),E=void 0,!_&&(_=n.visibility.onChange(ge),he())},Y=()=>{_==null||_(),_=null,clearTimeout(v),clearTimeout(C),C=void 0;const ee=g;g=null,ee==null||ee.close()};return{current:()=>m,ended:ee=>u(rc).find(j=>j.id===ee)??null,subscribe(ee){return y.add(ee),y.size===1&&_e(),()=>{!y.delete(ee)||y.size||(E=setTimeout(()=>{E=void 0,Y()},vw))}},drop(ee){m&&z(m.filter(j=>j.id!==ee))},forget(){clearTimeout(E),E=void 0,Y(),P(null);try{l.removeItem(sd),l.removeItem(rc)}catch{}},reopen(){y.size&&_e()}}}const fp="workoffdesk.textSize",cy=80,ry=150,hp=10,mp=100;function Tw(n){return{get(){try{const l=Number(n.getItem(fp)??mp);if(Number.isInteger(l)&&l>=cy&&l<=ry)return l}catch{}return mp},keep(l){try{n.setItem(fp,String(l))}catch{}}}}const Vi={visible:()=>document.visibilityState==="visible",onChange:n=>(document.addEventListener("visibilitychange",n),()=>document.removeEventListener("visibilitychange",n))},uy=(n,l)=>XE(new WebSocket(_x(n)),l),dy=()=>Zt(`/login?next=${encodeURIComponent(location.pathname)}`,!0),xc=ww({open:uy,storage:ma,visibility:Vi,onSignedOut:dy,ask:()=>at("/api/events/now")}),Aw=rw({open:uy,visibility:Vi,onSignedOut:dy}),wd=xE({api:at,visibility:Vi,store:{kept:Wx,keep:(n,l)=>void Jx(n,l)}}),jc=qE({api:at,visibility:Vi,newId:()=>FE(crypto.getRandomValues(new Uint8Array(KE)))}),qd=bE(ma,jc),fy=QE(ma),Nw=EE(ma),hy=Tw(ma),Td=pw(ma),_w=mw({api:at,journals:jc,links:Aw,list:xc,seen:fy,answers:qd,readClipboard:()=>navigator.clipboard.readText()}),gp=YE(ma),Dc=(n,l)=>n(`/api/m/${Bt}/sessions`,{method:"POST",json:l}),kw=n=>n(`/api/m/${Bt}/agents`);async function Ow(n,l,i){const o=l.kind==="codex"?l.codexThreadId:l.claudeSessionId;try{return{session:i?await n(`/api/m/${Bt}/sessions/${l.id}/continue`,{method:"POST"}):await Dc(n,{kind:l.kind,cwd:l.cwd,resumeId:o})}}catch(u){if(o&&u instanceof Sn&&u.code==="open-on-mac")return{onMac:{agent:l.kind,sid:o}};throw u}}const pp=n=>!!(n.kind==="codex"?n.codexThreadId:n.claudeSessionId),Yd=n=>n("/api/recent").catch(l=>{if(l instanceof Sn&&l.status===404)return n("/api/claude/recent");throw l}),Rw=(n,l)=>n==="codex"?`/api/codex/threads/${l}/chat`:`/api/claude/sessions/${l}/chat`;function Mw(n,l){const i=l.trim().toLowerCase(),o=n.filter(u=>u.cwd&&(!i||`${u.title} ${u.cwd}`.toLowerCase().includes(i)));return{people:o.filter(u=>!u.automated),programs:o.filter(u=>u.automated)}}function Cw(n){const l=ls(n)==="codex";return`${l?"Codex · ":""}${n.openIn?p.alreadyOpen:n.folderGone?p.folderGoneShort:n.background?l?p.openElsewhere:p.inBackground:""}`}const jw=n=>!!n.openIn||!n.background&&!n.folderGone;function Dw(n){return n.openIn?{do:"open",id:n.openIn}:n.folderGone?{do:"gone"}:n.background?{do:"none"}:n.onMac?{do:"takeOver",status:n.onMac.status,terminals:n.onMac.terminals,waiting:!!n.takingOver}:{do:"resume"}}async function bp(n,l,i){const o=await n(`/api/m/${Bt}/sessions`,{method:"POST",json:{kind:ls(l),cwd:l.cwd,resumeId:l.sessionId,takeOver:i}});return"waiting"in o?null:o}const Lw=(n,l)=>n(ls(l)==="codex"?`/api/codex/threads/${l.sessionId}/take-over`:`/api/claude/sessions/${l.sessionId}/take-over`,{method:"DELETE"}),zw=n=>`workoffdesk attach ${n}`,Kd="workoffdesk.mac-sessions",Uw=24*36e5,Bw=20,yp=1e3,Hw=3e4,$w=15e3,Iw=(n,l)=>n.filter(i=>!i.automated&&!i.openIn&&i.cwd&&i.lastActivity>l-Uw).slice(0,Bw);function my(n){try{const l=JSON.parse(n.getItem(Kd)??"null");return Array.isArray(l)?l:[]}catch{return[]}}const Gw=(n,l)=>{const i=new Map(n.map((o,u)=>[o.sessionId,u]));return[...l.filter(o=>!i.has(o.sessionId)),...l.filter(o=>i.has(o.sessionId)).sort((o,u)=>i.get(o.sessionId)-i.get(u.sessionId))]};function qw(n,l){let i=!0,o,u=yp,f=0,m=null;const h=g=>{if(clearTimeout(o),!n.visibility.visible())return;const v=++f;Yd(n.api).then(E=>{if(!(!i||v!==f)){u=yp,o=setTimeout(()=>h(!1),$w),m=g||!m?E:Gw(m,E),l(m);try{n.storage.setItem(Kd,JSON.stringify(E))}catch{}}},()=>{!i||v!==f||(o=setTimeout(()=>h(g),u),u=Math.min(u*2,Hw))})};l(my(n.storage)),h(!0);const y=n.visibility.onChange(()=>{i&&n.visibility.visible()&&h(!0)});return()=>{i=!1,clearTimeout(o),y()}}function Yw(){xc.forget();try{ma.removeItem(Kd)}catch{}}function Kw(){return H.useSyncExternalStore(xc.subscribe,xc.current)}function vp(){const n=new URLSearchParams(location.search).get("next");Zt(n&&n.startsWith("/")&&!n.startsWith("//")?n:"/",!0)}function Fw(){const[n,l]=H.useState(""),[i,o]=H.useState(""),[u,f]=H.useState(null),[m,h]=H.useState(!1);H.useEffect(()=>{Yw(),wd.forget(),eE(),jc.forget()},[]);const y=async v=>{v.preventDefault(),h(!0),f(null);try{await at("/api/auth/password",{method:"POST",json:{username:n,password:i}}),vp()}catch(E){f(Jg(E)),h(!1)}},g=async()=>{h(!0),f(null);try{const v=await at("/api/auth/passkey/login/options",{method:"POST",json:{}}),E=await W0({optionsJSON:v});await at("/api/auth/passkey/login/verify",{method:"POST",json:{response:E}}),vp()}catch(v){const E=v==null?void 0:v.name;E==="NotAllowedError"||E==="AbortError"?f(null):v instanceof Sn&&v.status===401?f(p.unknownPasskey):f(Jg(v)),h(!1)}};return r.jsx("main",{className:"login",children:r.jsxs("div",{className:"login-card",children:[r.jsxs("div",{className:"brand",children:[r.jsx("img",{src:"/icon.svg",alt:""}),r.jsx("h1",{children:"WorkOffDesk"}),r.jsx("p",{children:p.tagline})]}),Pi()&&r.jsxs(r.Fragment,{children:[r.jsxs("button",{className:"btn primary block",onClick:g,disabled:m,children:[r.jsx(iE,{}),p.faceId]}),r.jsx("div",{className:"divider",children:p.orPassword})]}),r.jsxs("form",{onSubmit:y,style:{display:"contents"},children:[r.jsxs("label",{className:"field",children:[p.username,r.jsx("input",{value:n,onChange:v=>l(v.target.value),autoComplete:"username webauthn",autoCapitalize:"none",autoCorrect:"off",spellCheck:!1,required:!0})]}),r.jsxs("label",{className:"field",children:[p.password,r.jsx("input",{type:"password",value:i,onChange:v=>o(v.target.value),autoComplete:"current-password",required:!0})]}),u&&r.jsx("div",{className:"alert",role:"alert",children:u}),r.jsx("button",{className:"btn primary block",type:"submit",disabled:m||!n||!i,children:p.login})]})]})})}const Pw=150,Sp=n=>n==="~"||n.startsWith("~/")||n.startsWith("/"),gy=n=>n.slice(n.lastIndexOf("/")+1),Xw=(n,l)=>{let i=0;for(const o of l)if(i=n.indexOf(o,i)+1,!i)return!1;return!0};function Zw(n,l){const i=l.toLowerCase(),o=u=>{const f=gy(u).toLowerCase();return f.startsWith(i)?0:f.includes(i)?1:Xw(u.toLowerCase(),i)?2:null};return n.map(u=>({dir:u,rank:o(u)})).filter(u=>u.rank!==null).sort((u,f)=>u.rank-f.rank).map(u=>u.dir)}function Qw(n,l){return`${n==="~"?"~/":n.slice(0,n.lastIndexOf("/")+1)}${gy(l)}/`}function Vw(n){const l=new Set;let i=null,o="",u=null,f,m=!1;const h=()=>{const E=Sp(o);return E?{text:o,path:E,rows:(u==null?void 0:u.rows)??null,error:(u==null?void 0:u.error)??null}:{text:o,path:E,rows:i&&Zw(i,o),error:null}};let y=h();const g=()=>{y=h();for(const E of l)E()},v=E=>{const _=(x,N)=>{E!==o||!m||(u={rows:x,error:N},g())};n(`/api/m/${Bt}/dirs?path=${encodeURIComponent(E)}`).then(x=>_(x,null),x=>_([],At(x,p.loadFailed)))};return{subscribe(E){return l.add(E),()=>void l.delete(E)},getSnapshot:()=>y,type(E){m&&(o=E.trim(),clearTimeout(f),Sp(o)?f=setTimeout(()=>v(o),Pw):u=null,g())},setKnown(E){i=E,g()},hold(){return m=!0,()=>{m=!1,clearTimeout(f)}}}}var Fd=Sb();function Lc(n){const l=H.useId(),{onClose:i}=n;H.useEffect(()=>{const u=f=>f.key==="Escape"&&i();return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[i]);const o=n.onBack&&r.jsx("button",{className:"icon-btn",onClick:n.onBack,"aria-label":p.back,children:r.jsx(Bd,{})});return Fd.createPortal(r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"scrim",onClick:n.onClose}),r.jsxs("div",{className:["sheet",n.bar&&"bar",n.className].filter(Boolean).join(" "),role:"dialog","aria-modal":"true","aria-labelledby":l,children:[r.jsxs("div",{className:"sheet-head",children:[n.bar?r.jsx("span",{className:"sheet-side",children:o}):o,r.jsx("h2",{id:l,children:n.title}),n.head,r.jsx("button",{className:"sheet-close",onClick:n.onClose,"aria-label":p.close,children:r.jsx(Qi,{})})]}),r.jsx("div",{className:"sheet-body",children:n.children})]})]}),document.body)}function Pd(n){const[l,i]=H.useState({data:null,error:null});return H.useEffect(()=>{let o=!1;return n().then(u=>!o&&i({data:u,error:null}),u=>!o&&i({data:null,error:At(u,p.loadFailed)})),()=>{o=!0}},[n]),l}function Ww(n,l){var T;const[i,o]=H.useState("menu"),[u,f]=H.useState(!1),[m,h]=H.useState(null),[y,g]=H.useState("claude"),v=H.useMemo(()=>()=>kw(n),[n]),E=(T=Pd(v).data)==null?void 0:T.codex,_=C=>{g(C),o("project")},x=async C=>{f(!0),h(null);try{l(await Dc(n,C))}catch(P){h(At(P,p.openFailed)),f(!1)}},N=i==="menu"?p.newSession:i==="project"?p.pickProject:p.resumeRecent;return{step:i,setStep:o,busy:u,error:m,agent:y,codex:E,pick:_,run:x,title:N}}const Wi=n=>H.useSyncExternalStore(n.subscribe,n.getSnapshot);function Jw(n){return{useSession(l){const i=n.get(l);return H.useEffect(()=>i.hold(),[i]),[i,Wi(i)]}}}const eT=n=>n("/api/claude/projects");function tT(n){var v;const l=H.useMemo(()=>()=>eT(n),[n]),{data:i,error:o}=Pd(l),u=H.useMemo(()=>Vw(n),[n]);H.useEffect(()=>u.hold(),[u]),H.useEffect(()=>u.setKnown(i),[u,i]);const f=Wi(u),[m,h]=H.useState(""),y=E=>{h(E),u.type(E)},g=f.path?f.text:(v=f.rows)==null?void 0:v[0];return{data:i,error:o,found:f,box:m,type:y,chosen:g}}const py=n=>Zt(`/m/${Bt}/s/${n.id}`);async function xp(n){py(await Dc(at,n))}function nT({onClose:n}){const{step:l,setStep:i,busy:o,error:u,agent:f,codex:m,pick:h,run:y,title:g}=Ww(at,py);return r.jsxs(Lc,{bar:!0,title:g,onClose:n,onBack:l==="menu"?void 0:()=>i("menu"),children:[u&&r.jsx("div",{className:"alert",role:"alert",children:u}),l==="menu"&&r.jsxs(r.Fragment,{children:[r.jsxs("button",{className:"option",disabled:o,onClick:()=>h("claude"),children:[r.jsx("span",{className:"opt-icon",children:r.jsx(aE,{})}),r.jsxs("span",{className:"opt-text",children:[r.jsx("span",{className:"opt-title",children:p.newInProject}),r.jsx("span",{className:"opt-sub",children:p.newInProjectSub})]})]}),r.jsxs("button",{className:"option",disabled:o,onClick:()=>i("recent"),children:[r.jsx("span",{className:"opt-icon",children:r.jsx(sE,{})}),r.jsxs("span",{className:"opt-text",children:[r.jsx("span",{className:"opt-title",children:p.resumeRecent}),r.jsx("span",{className:"opt-sub",children:p.resumeRecentSub})]})]}),m&&r.jsxs(r.Fragment,{children:[r.jsx("hr",{className:"opt-rule"}),r.jsxs("button",{className:"option",disabled:o,onClick:()=>h("codex"),children:[r.jsx("span",{className:"opt-icon",children:r.jsx(lE,{})}),r.jsxs("span",{className:"opt-text",children:[r.jsx("span",{className:"opt-title",children:p.newCodexInProject}),r.jsx("span",{className:"opt-sub",children:p.newCodexInProjectSub})]})]})]})]}),l==="project"&&r.jsx(sT,{busy:o,onPick:(v,E)=>y({kind:f,cwd:v,title:E||void 0})}),l==="recent"&&r.jsx(lT,{busy:o,onPick:v=>Zt(v.openIn?`/m/${Bt}/s/${v.openIn}`:`/${ls(v)}/${v.sessionId}`)})]})}const aT=()=>Yd(at);function sT({busy:n,onPick:l}){var v,E;const{error:i,found:o,box:u,type:f,chosen:m}=tT(at),[h,y]=H.useState(""),g=H.useRef(null);return r.jsxs(r.Fragment,{children:[r.jsx("input",{className:"search","aria-label":p.nameOptional,placeholder:p.nameOptionalHint,value:h,onChange:_=>y(_.target.value)}),r.jsxs("form",{onSubmit:_=>{_.preventDefault(),m&&l(m,h)},style:{display:"flex",gap:8},children:[r.jsx("input",{ref:g,className:"search","aria-label":p.findProject,placeholder:p.findProject,value:u,onChange:_=>f(_.target.value),autoCapitalize:"none",autoCorrect:"off",spellCheck:!1}),r.jsx("button",{className:"btn small",type:"submit",disabled:n||!m,children:p.open})]}),o.path?o.error&&r.jsx("div",{className:"alert",children:o.error}):i&&r.jsx("div",{className:"alert",children:i}),!o.rows&&!(i&&!o.path)&&r.jsx("p",{className:"muted center",children:p.loading}),((v=o.rows)==null?void 0:v.length)===0&&r.jsx("p",{className:"note",children:o.path?p.noFolders:o.text?p.notFound(o.text):p.noProjects}),(E=o.rows)==null?void 0:E.map(_=>r.jsxs("div",{className:"option-row",children:[r.jsxs("button",{className:"option",disabled:n,onClick:()=>l(_,h),children:[r.jsx("span",{className:"opt-icon",children:r.jsx(nE,{})}),r.jsxs("span",{className:"opt-text",children:[r.jsx("span",{className:"opt-title",children:_.split("/").pop()||_}),r.jsx("span",{className:"opt-sub",children:Ba(_)})]})]}),o.path&&r.jsx("button",{className:"option-in","aria-label":p.lookInside(_.split("/").pop()||_),onClick:()=>{var x;f(Qw(o.text,_)),(x=g.current)==null||x.focus()},children:r.jsx(Cc,{})})]},_))]})}function lT({busy:n,onPick:l}){const{data:i,error:o}=Pd(aT),[u,f]=H.useState(""),[m,h]=H.useState(!1),{people:y,programs:g}=H.useMemo(()=>Mw(i??[],u),[i,u]),v=y.length+g.length,E=u.trim()!=="",_=x=>r.jsx("button",{className:"option",disabled:n||!jw(x),onClick:()=>l(x),children:r.jsxs("span",{className:"opt-text",children:[r.jsx("span",{className:"opt-title",children:x.title}),r.jsxs("span",{className:"opt-sub",children:[Cw(x),Ua(x.lastActivity)," · ",Ba(x.cwd)]})]})},x.sessionId);return r.jsxs(r.Fragment,{children:[r.jsx("input",{className:"search",placeholder:p.searchTitlePath,value:u,onChange:x=>f(x.target.value),autoCorrect:"off",spellCheck:!1}),o&&r.jsx("div",{className:"alert",children:o}),!i&&!o&&r.jsx("p",{className:"muted center",children:p.loading}),i&&v===0&&r.jsx("p",{className:"note",children:u?p.noMatch:p.noConversations}),y.map(_),g.length>0&&!E&&r.jsxs("button",{className:"fold","aria-expanded":m,onClick:()=>h(!m),children:[r.jsx(Bd,{}),p.automated(g.length)]}),(E||m)&&g.map(_)]})}function iT(n,l,i){const[o,u]=H.useState(Db(l)),[f,m]=H.useState(!1),[h,y]=H.useState(null);return{name:o,setName:u,busy:f,error:h,save:async()=>{m(!0),y(null);try{await n(`/api/m/${Bt}/sessions/${l.id}`,{method:"PATCH",json:{title:o},idempotent:!0}),i()}catch(v){y(At(v,p.renameFailed)),m(!1)}}}}function by({session:n,onClose:l}){const{name:i,setName:o,busy:u,error:f,save:m}=iT(at,n,l);return r.jsxs(Lc,{title:p.rename,onClose:l,children:[f&&r.jsx("div",{className:"alert",role:"alert",children:f}),r.jsxs("form",{className:"rename-form",onSubmit:h=>{h.preventDefault(),m()},children:[r.jsx("input",{className:"search","aria-label":p.name,placeholder:Zi(n.cwd),value:i,onChange:h=>o(h.target.value),enterKeyHint:"done",autoFocus:!0}),r.jsx("button",{className:"btn small primary",type:"submit",disabled:u,children:p.save})]}),r.jsx("p",{className:"sheet-note",children:p.renameNote})]})}const oT=(n,l)=>{const i=l.trim().toLowerCase();return!i||[n.title,n.cwd,Ba(n.cwd)].some(o=>o.toLowerCase().includes(i))};function cT(n,l){const i=n&&[...n].sort((f,m)=>m.lastActivity-f.lastActivity),o=(i==null?void 0:i.filter(f=>oT(f,l)))??[],u=[];for(const f of o){const m=u.find(h=>h.cwd===f.cwd);m?m.sessions.push(f):u.push({cwd:f.cwd,title:Zi(f.cwd),sessions:[f]})}return u.length===1&&(u[0].title=null),{sorted:i,shown:o,groups:u}}function rT(n,l){return l||!Db(n)?null:Zi(n.cwd)}const Ad=n=>l=>{l.metaKey||l.ctrlKey||l.shiftKey||(l.preventDefault(),Zt(n))};function uT(n){const[l,i]=H.useState(()=>my(ma)),o=(n??[]).flatMap(u=>u.claudeSessionId??u.codexThreadId??[]).sort().join(" ");return H.useEffect(()=>qw({api:at,storage:ma,visibility:Vi},i),[o]),Iw(l,Date.now())}const Ep=10;function dT({s:n,folder:l,open:i,current:o,unread:u,onOpen:f,onRename:m}){const h=`/m/${Bt}/s/${n.id}`,y=wa(n.kind)?n.status:null,g=H.useRef(null),[v,E]=H.useState(null),_=i?-88:0,x=v??_,N=z=>{z.button===0&&(g.current={x:z.clientX,y:z.clientY,swiping:!1,moved:!1})},T=z=>{const L=g.current;if(!L)return;const le=z.clientX-L.x,ne=z.clientY-L.y;if(!L.swiping&&!L.moved){if(Math.abs(le)<Ep&&Math.abs(ne)<Ep||(L.moved=!0,Math.abs(le)<=Math.abs(ne)))return;L.swiping=!0,z.currentTarget.setPointerCapture(z.pointerId)}L.swiping&&E(Math.min(0,Math.max(-88,_+le)))},C=()=>{var z;(z=g.current)!=null&&z.swiping&&v!==null&&f(v<-88/2),E(null)},P=z=>{const L=g.current;if(g.current=null,L!=null&&L.moved||i){z.preventDefault(),i&&!(L!=null&&L.moved)&&f(!1);return}Ad(h)(z)};return r.jsxs("div",{className:`sess-row${v!==null?" dragging":""}`,children:[x<0&&r.jsx("button",{className:"sess-action",onClick:m,children:p.renameAction}),r.jsxs("a",{className:o?"sess-item current":"sess-item","aria-current":o?"page":void 0,"data-testid":"session-card",href:h,style:x?{transform:`translateX(${x}px)`}:void 0,onPointerDown:N,onPointerMove:T,onPointerUp:C,onPointerCancel:()=>{g.current=null,E(null)},onClick:P,draggable:!1,children:[r.jsxs("span",{className:`avatar ${n.kind}`,"aria-hidden":!0,children:[n.kind==="codex"?r.jsx(Fb,{}):wa(n.kind)?r.jsx(Pb,{}):r.jsx(Kb,{}),y==="waiting"&&r.jsx("span",{className:"needs-you"}),y==="working"&&r.jsx("span",{className:"busy"})]}),r.jsxs("span",{className:"sess-main",children:[r.jsxs("span",{className:"sess-top",children:[y==="working"&&r.jsx("span",{className:"sess-badge working",children:p.busy}),y==="waiting"&&r.jsx("span",{className:"sess-badge waiting",children:p.needsYou}),u&&y!=="working"&&y!=="waiting"&&r.jsx("span",{className:"sess-badge unread",children:p.unread}),r.jsx("span",{className:"sess-name",children:n.title}),l&&r.jsx("span",{className:"sess-dir",children:l}),r.jsx("span",{className:"sess-time",children:Lb(n.lastActivity)})]}),r.jsx("span",{className:"sess-preview",children:Dx(n)})]})]})]})}function wp({current:n}={}){const l=Kw(),i=uT(l),[o,u]=H.useState(!1),[f,m]=H.useState(""),[h,y]=H.useState(null),[g,v]=H.useState(null),{sorted:E,shown:_,groups:x}=cT(l,f),N=E?fy.unreadOf(E):new Set;return r.jsxs("main",{className:"list-page",children:[r.jsxs("header",{className:"list-top",children:[r.jsx("a",{className:"icon-btn",href:"/settings","aria-label":p.settings,onClick:Ad("/settings"),children:r.jsx(tE,{})}),r.jsx("h1",{children:p.sessions}),r.jsx("button",{className:"icon-btn","aria-label":p.newSession,onClick:()=>u(!0),children:r.jsx(Qb,{})})]}),!E&&r.jsx("p",{className:"muted center",children:p.loading}),(E==null?void 0:E.length)===0&&r.jsxs("div",{className:"empty",children:[r.jsx(Kb,{}),r.jsx("strong",{children:p.noSessions}),r.jsx("span",{children:p.noSessionsSub})]}),!!(E!=null&&E.length)&&_.length===0&&r.jsx("p",{className:"muted center",children:p.notFound(f.trim())}),_.length>0&&r.jsx("div",{className:"sess-list",children:x.map(T=>[T.title&&r.jsxs("h2",{className:"sess-group",children:[T.title,r.jsx("small",{children:T.sessions.length})]},`g-${T.cwd}`),...T.sessions.map(C=>r.jsx(dT,{s:C,folder:rT(C,T.title),unread:N.has(C.id),open:h===C.id,current:C.id===n,onOpen:P=>y(P?C.id:null),onRename:()=>{y(null),v(C)}},C.id))])}),i.length>0&&!f.trim()&&r.jsxs("div",{className:"sess-list",children:[r.jsxs("h2",{className:"sess-group",children:[p.otherMacSessions,r.jsx("small",{children:i.length})]}),i.map(T=>{var C,P,z,L,le;return r.jsxs("a",{className:T.sessionId===n?"sess-item mac current":"sess-item mac","aria-current":T.sessionId===n?"page":void 0,href:`/${ls(T)}/${T.sessionId}`,onClick:Ad(`/${ls(T)}/${T.sessionId}`),children:[r.jsxs("span",{className:`avatar ${ls(T)}${T.onMac?"":" mac"}`,"aria-hidden":!0,children:[ls(T)==="codex"?r.jsx(Fb,{}):r.jsx(Pb,{}),((C=T.onMac)==null?void 0:C.status)==="waiting"&&r.jsx("span",{className:"needs-you"}),((P=T.onMac)==null?void 0:P.status)==="busy"&&r.jsx("span",{className:"busy"})]}),r.jsxs("span",{className:"sess-main",children:[r.jsxs("span",{className:"sess-top",children:[((z=T.onMac)==null?void 0:z.status)==="busy"&&r.jsx("span",{className:"sess-badge working",children:p.busy}),((L=T.onMac)==null?void 0:L.status)==="waiting"&&r.jsx("span",{className:"sess-badge waiting",children:p.needsYou}),(((le=T.onMac)==null?void 0:le.terminals)??0)>1&&r.jsx("span",{className:"sess-badge waiting",children:p.openInTerminals(T.onMac.terminals)}),r.jsx("span",{className:"sess-name",children:T.title}),T.cwd&&r.jsx("span",{className:"sess-dir",children:Zi(T.cwd)}),r.jsx("span",{className:"sess-time",children:Lb(T.lastActivity)})]}),r.jsx("span",{className:"sess-preview",children:T.lastPrompt??Ba(T.cwd??"")})]})]},T.sessionId)}),r.jsx("p",{className:"muted sess-hint",children:p.startInTmuxHint})]}),!!(E!=null&&E.length)&&r.jsxs("label",{className:"list-search",children:[r.jsx(fE,{}),r.jsx("input",{type:"search","aria-label":p.search,placeholder:p.search,value:f,onChange:T=>m(T.target.value),enterKeyHint:"search"})]}),o&&r.jsx(nT,{onClose:()=>u(!1)}),g&&r.jsx(by,{session:g,onClose:()=>v(null)})]})}function zc(n){const{onClose:l}=n;H.useEffect(()=>{const u=f=>f.key==="Escape"&&l();return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[l]);const i=r.jsx("button",{className:"action",onClick:l,autoFocus:!0,children:n.cancel??p.cancel}),o=n.actions.map(u=>r.jsx("button",{className:u.destructive?"action danger":"action",onClick:()=>{l(),u.run()},children:u.label},u.label));return Fd.createPortal(r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"scrim soft",onClick:l}),r.jsx("div",{className:"action-sheet",children:r.jsxs("div",{className:n.side?"action-card alert":"action-card",role:"dialog","aria-modal":"true","aria-label":n.title,children:[(n.title||n.message)&&r.jsxs("div",{className:"action-head",children:[n.title&&r.jsx("div",{className:"action-title",children:n.title}),n.message&&r.jsx("div",{className:"action-message",children:n.message})]}),n.side?r.jsxs("div",{className:"action-row",children:[i,o]}):r.jsxs(r.Fragment,{children:[o,i]})]})})]}),document.body)}function Ec(n){const[l,i]=H.useState(!1);return r.jsxs(r.Fragment,{children:[r.jsx("button",{className:n.className??"btn small danger",disabled:n.disabled,onClick:()=>i(!0),children:n.label}),l&&r.jsx(zc,{title:n.title,message:n.what,side:!0,actions:[{label:n.action,run:n.onConfirm,destructive:n.destructive}],onClose:()=>i(!1)})]})}function Uc({title:n,onBack:l,right:i}){return r.jsxs("header",{className:"pagebar",children:[r.jsx("button",{className:"pagebar-back","aria-label":p.back,onClick:l,children:r.jsx(Bd,{})}),r.jsx("h1",{children:n}),r.jsx("div",{className:"pagebar-right",children:i})]})}function fT(){"serviceWorker"in navigator&&window.isSecureContext&&(navigator.serviceWorker.register("/sw.js").catch(()=>{}),navigator.serviceWorker.addEventListener("message",n=>{var l;((l=n.data)==null?void 0:l.type)==="open"&&typeof n.data.url=="string"&&(history.pushState(null,"",n.data.url),window.dispatchEvent(new PopStateEvent("popstate")))}))}async function hT(){return location.protocol!=="https:"?"insecure":!("serviceWorker"in navigator)||!("PushManager"in window)||!("Notification"in window)?"unsupported":Notification.permission==="denied"?"denied":await(await navigator.serviceWorker.ready).pushManager.getSubscription()?"on":"off"}function mT(n){const l=n.replace(/-/g,"+").replace(/_/g,"/"),i=atob(l+"=".repeat((4-l.length%4)%4));return Uint8Array.from(i,o=>o.charCodeAt(0))}async function gT(){if(await Notification.requestPermission()!=="granted")return"denied";const{publicKey:n}=await at("/api/push/key"),i=await(await navigator.serviceWorker.ready).pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:mT(n)});return await at("/api/push/subscribe",{method:"POST",json:i.toJSON()}),"on"}async function pT(){const l=await(await navigator.serviceWorker.ready).pushManager.getSubscription();return l&&(await at("/api/push/subscribe",{method:"DELETE",json:{endpoint:l.endpoint}}),await l.unsubscribe()),"off"}const yy=hy.get;function vy(n=yy()){document.documentElement.style.setProperty("--text-scale",String(n/100))}function bT(n){vy(n),hy.keep(n)}const uc={state:"loading"},Sy=n=>n.then(l=>({state:"loaded",rows:l}),l=>({state:"failed",error:At(l,p.loadFailed)})),Tp=n=>Sy(n("/api/auth/passkeys")),Ap=n=>Sy(n("/api/auth/logins").then(l=>l.sort((i,o)=>Number(o.current)-Number(i.current)||o.lastSeen-i.lastSeen)));function yT(n){const[l,i]=H.useState(n.themeChoice.get()),o={system:p.followSystem,light:p.themeLight,dark:p.themeDark,eye:p.themeEye},u=y=>{n.setTheme(y),i(y)},f=n.languageChoice.get(),m={system:p.followSystem,zh:"中文",en:"English"};return{colours:l,themes:o,pickTheme:u,language:f,languages:m,pickLanguage:y=>{y!==f&&(n.languageChoice.keep(y),n.restart())}}}function vT(n){const[l,i]=H.useState(uc),[o,u]=H.useState(uc),f=()=>Tp(n).then(i),m=()=>Ap(n).then(u),h=()=>Promise.all([f(),m()]);H.useEffect(()=>{Tp(n).then(i),Ap(n).then(u)},[n]);const y=l.state==="loaded"?l.rows:null,g=o.state==="loaded"?o.rows:null;return{passkeyList:l,loginList:o,passkeys:y,logins:g,load:h,retryPasskeys:()=>{i(uc),f()},retryLogins:()=>{u(uc),m()}}}function ST(){const[n,l]=H.useState(yy),i=o=>{l(o),bT(o)};return r.jsxs("section",{className:"section",children:[r.jsx("h2",{children:p.textSize}),r.jsxs("div",{className:"group",children:[r.jsxs("div",{className:"row",children:[r.jsxs("div",{className:"row-main",children:[r.jsx("strong",{children:p.wholeApp}),r.jsx("span",{children:p.thisDeviceOnly})]}),r.jsxs("div",{className:"stepper",children:[r.jsx("button",{className:"btn small","aria-label":p.smaller,disabled:n<=cy,onClick:()=>i(n-hp),children:"A−"}),r.jsxs("output",{role:"status","aria-label":p.textSize,children:[n,"%"]}),r.jsx("button",{className:"btn small","aria-label":p.larger,disabled:n>=ry,onClick:()=>i(n+hp),children:"A+"})]})]}),r.jsx("div",{className:"row text-preview",children:p.textPreview})]})]})}function xT(){const{colours:n,themes:l,pickTheme:i,language:o,languages:u,pickLanguage:f}=yT({themeChoice:jd,setTheme:U0,languageChoice:yb,restart:()=>location.reload()});return r.jsxs("section",{className:"section",children:[r.jsx("h2",{children:p.appearance}),r.jsxs("div",{className:"group",children:[r.jsx(Np,{label:p.theme,names:l,value:n,onPick:i}),r.jsx(Np,{label:p.language,note:p.languageRestarts,names:u,value:o,onPick:f})]})]})}function Np(n){const[l,i]=H.useState(!1),o=Object.keys(n.names);return r.jsxs(r.Fragment,{children:[r.jsxs("button",{className:"row row-link",onClick:()=>i(!0),children:[r.jsx("div",{className:"row-main",children:r.jsx("strong",{children:n.label})}),r.jsx("span",{className:"row-value",children:n.names[n.value]}),r.jsx(Cc,{})]}),l&&r.jsx(zc,{title:n.label,message:n.note,actions:o.map(u=>({label:n.names[u],run:()=>n.onPick(u)})),onClose:()=>i(!1)})]})}function _p({list:n,retry:l}){return n.state==="loading"?r.jsx("div",{className:"row empty-row",children:p.loading}):n.state==="loaded"?null:r.jsxs("div",{className:"row",children:[r.jsx("div",{className:"row-main",role:"alert",children:r.jsx("span",{children:n.error})}),r.jsx("button",{className:"btn small",onClick:l,children:p.tryAgain})]})}function ET(){const[n,l]=H.useState(Td.text);return r.jsxs("section",{className:"section",children:[r.jsx("h2",{children:p.snippets}),r.jsxs("div",{className:"group",children:[r.jsx("textarea",{className:"snippets-input","aria-label":p.snippetsLines,rows:5,placeholder:p.snippetsPlaceholder,value:n,onChange:i=>{l(i.target.value),Td.set(i.target.value)}}),r.jsx("div",{className:"row empty-row",children:p.snippetsNote})]})]})}function wT(){const[n,l]=H.useState(null);return H.useEffect(()=>{at("/api/me").then(i=>l(i.username??null),()=>{})},[]),r.jsxs("section",{className:"section",children:[r.jsx("h2",{children:p.account}),r.jsx("div",{className:"group",children:r.jsxs("div",{className:"row",children:[r.jsxs("div",{className:"row-main",children:[n&&r.jsx("strong",{children:n}),n?r.jsx("span",{children:location.origin}):r.jsx("strong",{children:location.origin}),r.jsx("span",{children:p.appRelease("1.0.1")})]}),r.jsx("span",{className:"row-check",children:r.jsx(Xb,{})})]})})]})}const kp={insecure:p.pushInsecure,unsupported:p.pushUnsupported,denied:p.pushDenied};function TT(){const{passkeyList:n,loginList:l,passkeys:i,logins:o,load:u,retryPasskeys:f,retryLogins:m}=vT(at),[h,y]=H.useState(null),[g,v]=H.useState(null),[E,_]=H.useState(!1);H.useEffect(()=>{hT().then(y,()=>y("unsupported"))},[]);const x=async L=>{_(!0),v(null);try{await L()}catch(le){const ne=le==null?void 0:le.name;ne!=="NotAllowedError"&&ne!=="AbortError"&&v(At(le,p.failed))}finally{_(!1)}},N=()=>x(async()=>{const L=await at("/api/auth/passkey/register/options",{method:"POST",json:{}}),le=await Z0({optionsJSON:L});await at("/api/auth/passkey/register/verify",{method:"POST",json:{response:le}}),u()}),T=L=>x(async()=>{await at(`/api/auth/passkeys/${encodeURIComponent(L)}`,{method:"DELETE"}),u()}),C=L=>x(async()=>{await at(`/api/auth/logins/${L}`,{method:"DELETE"}),u()}),P=()=>x(async()=>y(h==="on"?await pT():await gT())),z=()=>x(async()=>{await at("/api/auth/logout",{method:"POST"}),Zt("/login",!0)});return r.jsxs(r.Fragment,{children:[r.jsx(Uc,{title:p.settings,onBack:()=>Zt("/")}),r.jsxs("main",{className:"page",children:[g&&r.jsx("div",{className:"alert",role:"alert",children:g}),r.jsx("section",{className:"section",children:r.jsx("div",{className:"group",children:r.jsxs("button",{className:"row row-link",onClick:()=>Zt("/mac"),children:[r.jsxs("div",{className:"row-main",children:[r.jsx("strong",{children:p.thisMac}),r.jsx("span",{children:p.thisMacSub})]}),r.jsx(Cc,{})]})})}),r.jsx(ST,{}),r.jsx(xT,{}),r.jsxs("section",{className:"section",children:[r.jsx("h2",{children:p.pushTitle}),r.jsxs("div",{className:"group",children:[r.jsxs("div",{className:"row",children:[r.jsxs("div",{className:"row-main",children:[r.jsx("strong",{children:p.pushRemind}),r.jsx("span",{children:p.pushRemindSub})]}),r.jsxs("label",{className:"switch",children:[r.jsx("input",{type:"checkbox","aria-label":p.pushTitle,checked:h==="on",disabled:E||h!=="on"&&h!=="off",onChange:P}),r.jsx("span",{})]})]}),h&&kp[h]&&r.jsx("div",{className:"row empty-row",children:kp[h]})]})]}),r.jsx(ET,{}),r.jsx(wT,{}),r.jsxs("section",{className:"section",children:[r.jsx("h2",{children:p.passkeysTitle}),r.jsxs("div",{className:"group",children:[r.jsx(_p,{list:n,retry:f}),(i==null?void 0:i.length)===0&&r.jsx("div",{className:"row empty-row",children:p.passkeyNone}),i==null?void 0:i.map(L=>r.jsxs("div",{className:"row","data-testid":"passkey-row",children:[r.jsxs("div",{className:"row-main",children:[r.jsx("strong",{children:L.name}),r.jsxs("span",{children:[p.addedAgo(Ua(L.createdAt)),L.lastUsedAt?p.lastUsedAgo(Ua(L.lastUsedAt)):""]})]}),r.jsx(Ec,{label:p.delete,title:p.confirmDelete,what:L.name,action:p.confirmDelete,destructive:!0,disabled:E,onConfirm:()=>T(L.id)})]},L.id)),Pi()&&r.jsx("button",{className:"row row-link row-add",disabled:E,onClick:N,children:p.addPasskey})]})]}),r.jsxs("section",{className:"section",children:[r.jsx("h2",{children:p.loggedIn}),r.jsxs("div",{className:"group",children:[r.jsx(_p,{list:l,retry:m}),o==null?void 0:o.map(L=>r.jsxs("div",{className:"row","data-testid":"login-row",children:[r.jsxs("div",{className:"row-main",children:[r.jsxs("strong",{children:[ep(L.ua),L.current&&r.jsx("span",{className:"chip idle",children:p.thisDevice})]}),r.jsx("span",{children:p.loginBy(L.method==="passkey",Ua(L.lastSeen))})]}),!L.current&&r.jsx(Ec,{label:p.revoke,title:p.confirmRevoke,what:`${ep(L.ua)}
|
|
60
60
|
${p.loginBy(L.method==="passkey",Ua(L.lastSeen))}`,action:p.confirmRevoke,destructive:!0,disabled:E,onConfirm:()=>C(L.handle)})]},L.handle))]})]}),r.jsx("section",{className:"section",children:r.jsx("button",{className:"btn block danger",disabled:E,onClick:z,children:p.logOut})})]})]})}const AT=n=>n.phase==="asking"||n.phase==="waiting"?n.kind==="restart"?p.macRestarting:p.macRollingBack:n.phase==="done"?n.kind==="restart"?p.macRestarted:p.macRolledBack:n.message??p.failed,NT=1e3,_T=6e4,kT=3e3;function OT(n,l){const i=new Set;let o={report:null,problems:null,error:null,op:null,accounts:null,picking:null,moveAsked:!1},u=!1,f,m;const h=C=>{if(u){o={...o,...C};for(const P of i)P()}},y=()=>n(`/api/mac?lang=${l}`),g=()=>n("/api/mac/problems").then(C=>h({problems:C}),()=>h({problems:o.problems??[]})),v=()=>{y().then(C=>h({report:C,error:null}),C=>h({error:At(C,p.loadFailed)})),g(),x()},E=C=>{h({accounts:C}),_()},_=()=>{var C;clearTimeout(m),u&&((C=o.accounts)!=null&&C.moving)&&(m=setTimeout(x,kT))},x=()=>{n("/api/claude/accounts").then(E,_)},N=(C,P)=>{const z=Date.now(),L=()=>{f=setTimeout(()=>{y().then(ne=>{const W=ne.lastOp;if(!W||W.startedAt===P||W.finishedAt===void 0)return le();h({report:ne,op:{kind:C,phase:W.ok?"done":"failed",message:W.ok?null:W.message??p.failed}}),g()},()=>le())},NT)},le=()=>{u&&(Date.now()-z>=_T?h({op:{kind:C,phase:"failed",message:p.macNoReturn}}):L())};L()},T=(C,P,z)=>{var ne,W,oe,he;const L=((ne=o.op)==null?void 0:ne.phase)==="asking"||((W=o.op)==null?void 0:W.phase)==="waiting";if(!u||L)return;const le=(he=(oe=o.report)==null?void 0:oe.lastOp)==null?void 0:he.startedAt;h({op:{kind:C,phase:"asking",message:null}}),n(P,{method:"POST",json:z}).then(()=>{h({op:{kind:C,phase:"waiting",message:null}}),u&&N(C,le)},ge=>h({op:{kind:C,phase:"failed",message:At(ge,p.failed)}}))};return{subscribe(C){return i.add(C),()=>void i.delete(C)},getSnapshot:()=>o,load:v,restart:()=>T("restart","/api/mac/restart",{}),rollback:C=>T("rollback","/api/mac/rollback",{to:C}),pick(C){!u||o.picking!==null||(h({picking:C}),n("/api/claude/account",{method:"PUT",json:{id:C},idempotent:!0}).then(P=>(h({picking:null}),E(P)),P=>h({picking:null,error:At(P,p.failed)})))},move(){!u||o.moveAsked||(h({moveAsked:!0}),n("/api/claude/account/move",{method:"POST",idempotent:!0}).then(C=>(h({moveAsked:!1}),E(C)),C=>h({moveAsked:!1,error:At(C,p.failed)})))},hold(){return u=!0,v(),()=>{u=!1,clearTimeout(f),clearTimeout(m)}}}}const wc=80,ol=n=>`${Math.round(n)}%`;function RT(n,l=Date.now()){const i=Math.max(0,Math.round((n*1e3-l)/6e4));if(i<60)return p.resetsInMinutes(i);const o=Math.floor(i/60);return o<24?p.resetsInHours(o,i%60):p.resetsInDays(Math.floor(o/24),o%24)}function MT(n,l=Date.now(),i){const o=i?[{label:p.claudeAccountLine,value:i}]:[];n.context!==void 0&&o.push({label:p.context,value:ol(n.context),high:n.context>=wc});for(const[u,f]of[[p.fiveHourLimit,n.fiveHour],[p.sevenDayLimit,n.sevenDay]])f&&o.push({label:u,value:ol(f.used),sub:f.resetsAt?RT(f.resetsAt,l):void 0,high:f.used>=wc});return n.cost!==void 0&&o.push({label:p.sessionCost,value:`$${n.cost.toFixed(2)}`}),(n.added||n.removed)&&o.push({label:p.linesChanged,value:p.lines(n.added??0,n.removed??0)}),o}const CT=(n,l)=>[n.model,...l.map(i=>`${i.label} ${i.value}${i.sub?` (${i.sub})`:""}`)].filter(Boolean).join(`
|
|
61
61
|
`);function jT(n){const l=n.context!==void 0&&{label:p.contextLabel(ol(n.context)),accessibilityLabel:p.contextIs(ol(n.context)),high:n.context>=wc};if(l&&l.high)return l;for(const[i,o,u]of[[n.fiveHour,p.fiveHourLimit,p.fiveHourLabel],[n.sevenDay,p.sevenDayLimit,p.sevenDayLabel]])if(i&&i.used>=wc)return{label:u(ol(i.used)),accessibilityLabel:p.limitIs(o,ol(i.used)),high:!0};return l||null}const Xd=n=>n.signedIn?n.ready?n.shared?null:p.accountApart:p.accountNotReady:p.accountSignedOut;function DT(n,l=Date.now()){if(!n.limits)return p.accountNotSeen;const i=(u,f)=>u&&f(u.resetsAt!==void 0&&u.resetsAt*1e3<=l?p.limitReset:ol(u.used)),o=[i(n.limits.fiveHour,p.fiveHourLabel),i(n.limits.sevenDay,p.sevenDayLabel)].filter(Boolean);return o.length?`${o.join(" · ")} · ${Ua(n.limits.at,l)}`:p.accountNotSeen}const xy=(n,l=Date.now())=>`${n.folder} · ${Xd(n)??DT(n,l)}`;function LT(n){var u;const l=H.useMemo(()=>OT(n,Xi),[n]);H.useEffect(()=>l.hold(),[l]);const i=Wi(l),o=((u=i.report)==null?void 0:u.checks.filter(f=>!f.ok).length)??0;return{page:l,...i,failed:o}}function zT(){const[n,l]=H.useState(!1);return H.useEffect(()=>{if(!n)return;const i=setTimeout(()=>l(!1),1500);return()=>clearTimeout(i)},[n]),[n,l]}function Op({check:n}){const[l,i]=zT(),o=()=>{var u;return(u=navigator.clipboard)==null?void 0:u.writeText(n.fix).then(()=>i(!0),()=>{})};return r.jsxs("div",{className:"row mac-check","data-testid":"mac-check",children:[r.jsx("span",{className:`mac-dot ${n.ok?"ok":"bad"}`,"aria-label":n.ok?p.macCheckPassed:p.macCheckFailed}),r.jsxs("div",{className:"row-main",children:[r.jsx("strong",{children:p.checkNames[n.id]??n.id}),r.jsx("span",{children:n.detail}),n.fix&&r.jsxs("button",{className:"mac-fix",onClick:o,title:p.macFixTap,children:[r.jsx("code",{children:n.fix}),r.jsx("em",{children:l?p.copied:p.macFixTap})]})]})]})}function UT({accounts:n,picking:l,pick:i,moveAsked:o,move:u}){return r.jsxs("section",{className:"section",children:[r.jsx("h2",{children:p.macClaudeAccounts}),r.jsx("div",{className:"group",children:n.accounts.map(f=>{const m=Xd(f),h=f.id===n.inUse;return r.jsxs("button",{className:m?"row row-link barred":"row row-link","aria-pressed":h,disabled:!!m||h||l!==null,onClick:()=>i(f.id),children:[r.jsxs("div",{className:"row-main",children:[r.jsx("strong",{children:f.email}),r.jsx("span",{children:xy(f)})]}),l===f.id?r.jsx("span",{className:"spinner"}):h&&r.jsx("span",{className:"row-check",children:r.jsx(Xb,{})})]},f.id)})}),r.jsx(BT,{accounts:n,moveAsked:o,disabled:l!==null,move:u}),!n.elsewhere&&!n.moving&&r.jsx("p",{className:"muted mac-note",children:p.macAccountNote})]})}function BT({accounts:n,moveAsked:l,disabled:i,move:o}){var f;const u=((f=n.accounts.find(m=>m.id===n.inUse))==null?void 0:f.email)??"";return n.moving>0?r.jsxs("div",{className:"mac-move moving",role:"status",children:[r.jsx("span",{className:"spinner small","aria-hidden":!0}),r.jsxs("div",{className:"mac-move-text",children:[r.jsx("strong",{children:p.macMovingSessions(n.moving)}),r.jsx("span",{children:p.macMovingTo(u)})]})]}):n.elsewhere?r.jsxs("div",{className:"mac-move",children:[r.jsxs("div",{className:"mac-move-text",children:[r.jsx("strong",{children:p.macElsewhere(n.elsewhere)}),r.jsx("span",{children:p.macMoveTo(u)})]}),r.jsx("button",{className:"btn primary",disabled:l||i,"aria-busy":l,onClick:o,children:l?r.jsx("span",{className:"spinner small","aria-hidden":!0}):p.macMoveButton})]}):null}function HT({report:n}){var o;const l=n.releases.find(u=>u.name===n.release),i=l!=null&&l.activatedAt?Date.parse(l.activatedAt):NaN;return r.jsxs("section",{className:"section",children:[r.jsx("h2",{children:p.macVersion}),r.jsx("div",{className:"group",children:r.jsx("div",{className:"row",children:r.jsxs("div",{className:"row-main",children:[r.jsx("strong",{children:n.version}),((o=n.build)==null?void 0:o.commit)&&r.jsx("span",{children:p.macBuiltFrom(n.build.commit.slice(0,12),n.build.dirty)}),!Number.isNaN(i)&&r.jsx("span",{children:p.macServingSince(Ua(i))})]})})}),n.releases.length>0&&r.jsxs(r.Fragment,{children:[r.jsx("h2",{className:"mac-sub",children:p.macReleases}),r.jsx("div",{className:"group",children:n.releases.map(u=>r.jsx("div",{className:"row",children:r.jsxs("div",{className:"row-main",children:[r.jsxs("strong",{children:[u.version||u.name,u.name===n.release&&r.jsx("span",{className:"chip idle",children:p.macRunning})]}),r.jsxs("span",{children:[u.name,u.activatedAt?` · ${Ua(Date.parse(u.activatedAt))}`:""]})]})},u.name))})]})]})}function $T({report:n,op:l,restart:i,rollback:o}){const u=(l==null?void 0:l.phase)==="asking"||(l==null?void 0:l.phase)==="waiting",f=n.releases.find(h=>h.name===n.rollbackTo),m=f?f.version||f.name:null;return r.jsxs("section",{className:"section",children:[r.jsx("h2",{children:p.macActions}),r.jsxs("div",{className:"group",children:[l&&r.jsxs("div",{className:`row mac-op ${l.phase}`,role:"status",children:[u&&r.jsx("span",{className:"spinner small"}),r.jsx("span",{children:AT(l)})]}),n.managed?r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"row",children:[r.jsxs("div",{className:"row-main",children:[r.jsx("strong",{children:p.macRestart}),r.jsx("span",{children:p.macRestartNote})]}),r.jsx(Ec,{className:"btn small",label:p.macRestartShort,title:p.macRestart,what:p.macRestartNote,action:p.macRestartConfirm,disabled:u,onConfirm:i})]}),r.jsx("div",{className:"row",children:m&&n.rollbackTo?r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"row-main",children:[r.jsx("strong",{children:p.macRollback(m)}),r.jsx("span",{children:n.rollbackTo})]}),r.jsx(Ec,{label:p.macRollbackShort,title:p.macRollback(m),what:n.rollbackTo,action:p.macRollbackShort,destructive:!0,disabled:u,onConfirm:()=>o(n.rollbackTo)})]}):r.jsx("div",{className:"row-main",children:r.jsx("span",{children:p.macNoRollback})})})]}):r.jsx("div",{className:"row empty-row",children:p.macNotManaged})]})]})}function IT(){const{page:n,report:l,problems:i,error:o,op:u,accounts:f,picking:m,moveAsked:h,failed:y}=LT(at);return r.jsxs(r.Fragment,{children:[r.jsx(Uc,{title:p.thisMac,onBack:()=>Zt("/settings")}),r.jsxs("main",{className:"page",children:[o&&r.jsxs("div",{className:"alert",role:"alert",children:[o," ",r.jsx("button",{className:"btn small",onClick:n.load,children:p.tryAgain})]}),!l&&!o&&r.jsx("div",{className:"mac-loading",children:r.jsx("span",{className:"spinner"})}),l&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:`mac-summary ${y?"bad":"ok"}`,"data-testid":"mac-summary",children:y?p.macProblemCount(y):p.macAllGood}),f&&f.accounts.length>=2&&r.jsx(UT,{accounts:f,picking:m,pick:n.pick,moveAsked:h,move:n.move}),r.jsxs("section",{className:"section",children:[r.jsx("h2",{children:p.macChecks}),r.jsxs("div",{className:"group",children:[l.checks.filter(g=>!g.ok).map(g=>r.jsx(Op,{check:g},g.id)),r.jsxs("details",{className:"mac-passed",children:[r.jsxs("summary",{children:[r.jsx("span",{className:"mac-dot ok"}),r.jsx("span",{children:y?p.macPassed(l.checks.length-y):p.macAllPassed(l.checks.length)}),r.jsx(Cc,{})]}),l.checks.filter(g=>g.ok).map(g=>r.jsx(Op,{check:g},g.id))]})]})]}),r.jsx($T,{report:l,op:u,restart:n.restart,rollback:n.rollback}),r.jsx(HT,{report:l})]}),i&&r.jsxs("section",{className:"section",children:[r.jsx("h2",{children:p.macProblems}),r.jsxs("div",{className:"group",children:[i.length===0&&r.jsx("div",{className:"row empty-row",children:p.macNoProblems}),i.map((g,v)=>r.jsxs("details",{className:"mac-problem",children:[r.jsxs("summary",{children:[r.jsx("span",{className:`mac-level ${g.level}`,children:g.level}),r.jsx("span",{className:"mac-problem-msg",children:g.msg||"—"}),r.jsx("time",{children:Ua(Date.parse(g.at))})]}),r.jsx("pre",{children:g.detail})]},`${g.at}-${v}`))]}),r.jsx("p",{className:"muted mac-note",children:p.macLogNote})]})]})]})}const Ey=H.createContext("Claude"),zs=()=>H.useContext(Ey),Zd=String.raw`\.(?:png|jpe?g|gif|webp)`,ld=String.raw`\s\x60'"<>()()「」『』【】\[\],。、;:!?`,GT=new RegExp(String.raw`(?<=^|[\s\x60'"((「『【\[\]::,,])(~?\/(?!\/)[^${ld}]*?${Zd})(?=$|[${ld}]|[.,;:!?](?:$|[${ld}]))`,"giu"),qT=new RegExp(String.raw`\x60(~?\/[^\x60\n]*?${Zd})\x60`,"giu"),YT=/!\[[^\]\n]*\]\(\s*<?([^)\s>]+)>?(?:\s+(?:"[^"\n]*"|'[^'\n]*'))?\s*\)/g,KT=new RegExp(String.raw`^~?\/(?!\/).*${Zd}$`,"iu"),Bc=/\/uploads\/\d{4}-\d{2}-\d{2}-\d{6}-[0-9a-f]{6}\.(?:png|jpg|gif|webp)$/,FT=/\[Image #\d+\]/g,Rp=/\[image\]/g,Nd=n=>[...new Set(n)],wy=String.raw`"(~?\/[^"\n]*\/uploads\/\d{4}-\d{2}-\d{2}-\d{6}-[0-9a-f]{6}\/([^"/\n]+))"(?: \(video: \d+ stills, one every \d+ s, in "[^"\n]+"\))?`,Ty=new RegExp(wy,"g"),PT=new RegExp(String.raw`^${wy}(?: |$)`),Ay=n=>({piece:n[0].trimEnd(),path:n[1],name:n[2],video:n[0].includes("(video: ")}),XT=({path:n,frames:l})=>l?`"${n}" (video: ${l.count} stills, one every ${l.every} s, in "${l.dir}/")`:`"${n}"`;function Ny(n){const l=[];for(const i of n.matchAll(qT))l.push({at:i.index,path:i[1]});for(const i of n.matchAll(GT))l.push({at:i.index,path:i[1]});return Nd(l.sort((i,o)=>i.at-o.at).map(i=>i.path))}const ZT=n=>n.replace(/[ \t]{2,}/g," ").trim();function Hc(n){var h;const l=Oy(n),i=l.length?n.replace(Ty," "):n,o=Ny(i),u=((h=n.match(Rp))==null?void 0:h.length)??0,f=o.filter(y=>Bc.test(y));let m=i.replace(FT,"").replace(Rp," ");for(const y of f)m=m.split(`"${y}"`).join(" ").split(y).join(" ");return{images:o,files:l,text:m===n?n:ZT(m),unseen:Math.max(0,u-o.length)}}function QT(n){const l=Hc(n),i=l.images.length+l.unseen,o=[i&&p.imageCount(i),l.files.length&&p.fileCount(l.files.length)].filter(Boolean).join(" · ");return o?l.text?`${l.text} · ${o}`:o:l.text}function _y(n){const l=[],i=[],o=n.replace(YT,(u,f)=>{if(/^https?:\/\//i.test(f))i.push(f);else if(KT.test(f))l.push(f);else return u;return""});return{text:o,local:Nd([...l,...Ny(o)]),remote:Nd(i)}}function VT(n,l){return Bc.test(n)?p.imageExpired:l?p.imageGone:null}const WT=(n,l)=>[...n,l].filter(Boolean).join(" "),JT=/^("?)(\S+?)\1(?: |$)/;function eA(n){const l=[],i=[];let o=n;for(;;){const u=PT.exec(o),f=u?null:JT.exec(o);if(u)i.push(Ay(u));else if(f&&Bc.test(f[2]))l.push(f[2]);else break;o=o.slice((u??f)[0].length)}return{pictures:l,files:i,text:o}}const ky=n=>`/api/uploads/${n.slice(n.lastIndexOf("/")+1)}`,tA=n=>n.split("/").at(-2)??"",nA=n=>`/api/uploads/${tA(n)}/cover`,Oy=n=>[...n.matchAll(Ty)].map(Ay),aA=(n,l)=>Bc.test(l)?ky(l):`/api/m/${Bt}/sessions/${n}/image?path=${encodeURIComponent(l)}`,Tc=n=>n.replace(/\/{2,}/g,"/").replace(/\/(?:\.\/)+/g,"/");function sA(n){var l;return n.k==="user"?Hc(n.text).images:n.k==="text"?_y(n.text).local:n.k==="tool"&&n.name==="Read"&&((l=n.result)!=null&&l.image)?[n.summary]:[]}function lA(n){const l=new Set,i=new Map;for(const o of n)for(const u of sA(o)){const f=Tc(u);l.has(f)?i.set(o.key,(i.get(o.key)??new Set).add(u)):l.add(f)}return i}function Ry(n){var L,le,ne;const{view:l,status:i}=n,{screen:o}=l,u=Ud(l.items,((L=l.items[0])==null?void 0:L.pos)??0),f=lA(u),{sent:m,bubbles:h}=$E(l,u),y=yE(n.answers,u,l.conv),g=Ib(u,i==="working"),v=new Map(u.map((W,oe)=>[W.key,oe])),E=(le=u.findLast(W=>W.k==="user"&&!m.has(W.key)))==null?void 0:le.key,_=i==="idle"&&!o.choices&&!o.panel,x=[],N=new Map,T=W=>{for(const oe of y.get(W)??[])x.push({kind:"answer",key:`answer-${oe.at}`,answer:oe})};g.forEach((W,oe)=>{if(W.k==="tools"){const _e=g[oe+1];x.push({kind:"tools",key:W.key,tools:W.tools,going:W.going,end:(_e==null?void 0:_e.k)==="one"&&"at"in _e.t?_e.t.at:void 0});for(const Y of W.tools)N.set(Y.key,W.key),T(Y.key);return}const he=W.t,ge=v.get(he.key);N.set(he.key,he.key),x.push({kind:"turn",key:he.key,turn:he,repeated:f.get(he.key),sent:m.has(he.key),last:he.k==="text"&&(ge===u.length-1?i!=="working":["user","changes"].includes(u[ge+1].k)),rewind:n.kind==="claude"&&he.key===E&&_,retry:oe===g.length-1&&_&&!n.queued}),T(he.key)}),l.synced&&!u.length&&!n.queued&&!h.length&&x.push({kind:"empty",key:"empty"}),l.live&&x.push({kind:"live",key:"live",text:l.live});for(const W of h)x.push({kind:"bubble",key:`message-${W.id}`,message:W});l.failed&&x.push({kind:"failed",key:"failed"}),l.background.length&&x.push({kind:"background",key:"background",running:l.background}),i==="working"&&x.push({kind:"working",key:"working",since:l.workingSince===null?null:kb(l.workingSince)});const C=i==="waiting"||i==="working",P=(ne=o.asks)==null?void 0:ne[0],{choices:z}=o;return n.dialog?{entries:x,shown:u,inEntry:N}:(P?x.push({kind:"ask",key:`ask-${P.id}`,ask:P}):C&&z&&!z.submit?x.push({kind:"choice",key:"choice",choices:z}):C&&(z!=null&&z.submit)?x.push({kind:"tick",key:["tick",z.context,...z.options.map(W=>W.label)].join(`
|
|
62
62
|
`),choices:z}):i==="waiting"&&x.push({kind:"waiting",key:"waiting"}),{entries:x,shown:u,inEntry:N})}const Nt=n=>({onPointerDown:l=>l.preventDefault(),onClick:n});function My(n){return r.jsxs("div",{className:"keybar",role:"toolbar","aria-label":p.keys,children:[WE.map(l=>l.seq===null?r.jsx("button",{className:`key ${n.ctrlArmed?"armed":""}`,"aria-pressed":n.ctrlArmed,...Nt(n.onCtrl),children:"Ctrl"},l.label):r.jsx("button",{className:"key","aria-label":l.seq===JE?p.enter:l.label,...Nt(()=>n.onKey(l.seq)),children:l.label},l.label)),r.jsx("button",{className:"key",...Nt(n.onPaste),children:p.paste})]})}/*! @license DOMPurify 3.4.16 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.16/LICENSE */function Mp(n,l){(l==null||l>n.length)&&(l=n.length);for(var i=0,o=Array(l);i<l;i++)o[i]=n[i];return o}function iA(n){if(Array.isArray(n))return n}function oA(n,l){var i=n==null?null:typeof Symbol<"u"&&n[Symbol.iterator]||n["@@iterator"];if(i!=null){var o,u,f,m,h=[],y=!0,g=!1;try{if(f=(i=i.call(n)).next,l!==0)for(;!(y=(o=f.call(i)).done)&&(h.push(o.value),h.length!==l);y=!0);}catch(v){g=!0,u=v}finally{try{if(!y&&i.return!=null&&(m=i.return(),Object(m)!==m))return}finally{if(g)throw u}}return h}}function cA(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
@@ -129,4 +129,4 @@ ${i.title}`]}),i.detail&&r.jsx("pre",{className:"panel-body",children:i.detail})
|
|
|
129
129
|
`).length>L_||n.length>z_;return r.jsxs(r.Fragment,{children:[r.jsx("div",{className:`bubble mine ${o&&!l?"folded":""}`,children:n}),o&&r.jsx("button",{className:"mine-more",onClick:()=>i(!l),children:l?p.collapse:p.expandAll})]})}function U_({text:n,onRewind:l}){const[i,o]=H.useState(!1),u=()=>{var f;return void((f=navigator.clipboard)==null?void 0:f.writeText(n).then(()=>{o(!0),setTimeout(()=>o(!1),dv)}))};return r.jsxs(r.Fragment,{children:[n&&r.jsx("button",{onClick:u,children:i?p.copied:p.copy}),r.jsx("button",{onClick:l,children:p.rewind})]})}function B_({count:n}){return r.jsx("div",{className:"send-held compacting",role:"status","aria-label":p.compactingContext,children:r.jsxs("span",{children:[r.jsx("b",{children:p.compactingContext}),r.jsx("small",{children:n?p.compactingQueued(n):p.compactingWillQueue})]})})}function H_({terminals:n,sessionId:l}){return r.jsx("div",{className:"send-held",role:"status","aria-label":p.alsoOnMac(n),children:r.jsxs("span",{children:[r.jsx("b",{children:p.alsoOnMac(n)}),r.jsx("small",{children:p.alsoOnMacSub(l)})]})})}function $_(n){return n.messages.length?r.jsx("ul",{className:"outbox",children:n.messages.map(l=>l.state==="sending"?r.jsxs("li",{className:"outbox-item held","aria-label":p.sendingMessage,children:[r.jsx(ob,{sessionId:n.sessionId,text:l.text,onOpen:n.onOpen}),r.jsx("small",{children:p.sending})]},l.id):r.jsxs("li",{className:"outbox-item","aria-label":p.sentMessage,children:[r.jsx(ob,{sessionId:n.sessionId,text:l.text,onOpen:n.onOpen}),r.jsx("small",{children:p.sent})]},l.id))}):null}const gd=2e3,I_=300;function G_(n,l,i){const[o,u]=H.useState(null),[f,m]=H.useState(!1),h=H.useRef(()=>{});return H.useEffect(()=>{let v=!1,E=!1,_=!1,x;const N=z=>{v||(u(z),m(!1))},T=z=>{clearTimeout(x),v||(x=setTimeout(()=>h.current(),z))};h.current=async(z=!1)=>{const L=E&&Sc(l);if(_||!z&&(L||!i()))return T(gd);_=!0;try{N((await n(`/api/m/${Bt}/sessions/${l}/screen`)).text)}catch{v||m(!0)}finally{_=!1}T(gd)};const C=ty(l,z=>{z.type==="screenText"&&(E=!0,N(z.text))}),P=OE(l);return T(Sc(l)?gd:0),()=>{v=!0,clearTimeout(x),C(),P()}},[l]),{text:o,failed:f,refresh:()=>{m(!1),h.current(!0)},keyed:()=>setTimeout(()=>h.current(),I_)}}function gv({sessionId:n,onClose:l,keys:i}){const{text:o,failed:u,refresh:f,keyed:m}=G_(at,n,()=>document.visibilityState==="visible"),h=H.useRef(null),y=H.useRef(!1);return H.useLayoutEffect(()=>{y.current||!h.current||(y.current=!0,h.current.scrollTop=h.current.scrollHeight)},[o]),r.jsxs(Lc,{title:p.screenTitle,onClose:l,className:"screen-sheet",head:r.jsx("button",{className:"btn small",onClick:f,children:p.refresh}),children:[u&&r.jsx("div",{className:"alert",role:"alert",children:p.screenUnread}),o===null?r.jsx("div",{className:"screen-text",children:!u&&r.jsx("p",{className:"muted center",children:p.reading})}):r.jsx("pre",{ref:h,className:"screen-text","aria-label":p.screenContent,children:o||p.screenEmpty}),i&&r.jsx(My,{ctrlArmed:i.ctrlArmed,onCtrl:i.onCtrl,onPaste:()=>{i.onPaste(),m()},onKey:g=>{i.onKey(g),m()}})]})}function q_({running:n,onManage:l}){return n.length?r.jsxs("details",{className:"chat-bg",children:[r.jsxs("summary",{children:[r.jsx("b",{children:p.backgroundCommands})," ",p.backgroundRunning(n.length)]}),r.jsx("ul",{children:n.map(i=>r.jsxs("li",{children:[r.jsx("span",{children:i.label}),r.jsxs("small",{children:["#",i.id]})]},i.id))}),r.jsx("button",{className:"btn small",...Nt(l),children:p.backgroundOpen})]}):null}const Y_=new Set(["Read","Edit","MultiEdit","Write","NotebookEdit"]);function pv({name:n,summary:l}){const i=Y_.has(n)?Gb(l):null;return i?r.jsxs("span",{className:"tool-summary",children:[r.jsx("span",{className:"tool-file",children:i.name})," ",i.dir]}):r.jsx("span",{className:"tool-summary",children:l})}function cf({d:n}){return r.jsxs("span",{className:"diff-count",children:[n.added>0&&r.jsxs("ins",{children:["+",n.added]}),n.removed>0&&r.jsxs("del",{children:["−",n.removed]})]})}function K_({d:n}){return r.jsxs("div",{className:"diff",role:"group","aria-label":p.changes,children:[n.created&&r.jsx("div",{className:"diff-head",children:p.newFile}),n.hunks.map((l,i)=>r.jsxs("div",{className:"diff-hunk",children:[!n.created&&r.jsx("div",{className:"diff-head",children:p.atLine(l.newStart)}),l.lines.map((o,u)=>r.jsx("div",{className:`diff-line ${o[0]==="+"?"add":o[0]==="-"?"del":""}`,children:o||" "},u))]},i)),n.cut&&r.jsx("div",{className:"diff-head",children:p.diffCut})]})}function F_(n,l){var o,u;const i=(o=n.currentTarget.closest(".chat"))==null?void 0:o.querySelector(`[data-tool="${CSS.escape(l)}"]`);if(i){for(let f=i;f;f=((u=f.parentElement)==null?void 0:u.closest("details"))??null)f.open=!0;i.scrollIntoView({behavior:"smooth",block:"center"})}}function P_({files:n}){return r.jsxs("div",{className:"chat-changes",role:"group","aria-label":p.changedFiles,children:[r.jsx("div",{className:"changes-title",children:p.filesChanged(n.length)}),n.map(l=>{const i=Gb(l.file);return r.jsxs("button",{className:"changes-file",onClick:o=>F_(o,l.tool),children:[r.jsxs("span",{className:"changes-name",children:[r.jsx("span",{className:"tool-file",children:(i==null?void 0:i.name)??l.file})," ",i==null?void 0:i.dir,l.created&&r.jsx("span",{className:"changes-new",children:p.newMark})]}),r.jsx(cf,{d:l})]},l.file)})]})}function bv(n){const{tools:l}=n,i=n.going||l.some(v=>!v.result),o=l.at(-1),u=Date.parse(l[0].at??""),f=n.end??o.at,m=Date.parse(f??"")-u,h=l.reduce((v,E)=>{var _,x;return v+(((x=(_=E.result)==null?void 0:_.diff)==null?void 0:x.added)??0)},0),y=l.reduce((v,E)=>{var _,x;return v+(((x=(_=E.result)==null?void 0:_.diff)==null?void 0:x.removed)??0)},0),g=l.filter(v=>{var E;return(E=v.result)==null?void 0:E.error}).length;return r.jsxs("details",{className:`chat-tools ${i?"live":""}`,children:[r.jsx("summary",{children:i?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"tools-state",children:p.toolsCalled(l.length)}),r.jsx("span",{className:"tool-name",children:o.name}),r.jsx(pv,{name:o.name,summary:o.summary})]}):r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"tools-state",children:p.toolsDone(l.length)}),r.jsx("span",{className:"tools-meta",children:[Ub(f),m>=1e3?p.took(zb(m)):"",g?p.toolErrors(g):""].filter(Boolean).join(" · ")}),(h>0||y>0)&&r.jsx(cf,{d:{added:h,removed:y}})]})}),r.jsx("div",{className:"chat-tools-list",children:l.map(v=>r.jsx(rf,{sessionId:n.sessionId,t:v,onOpen:n.onOpen},v.key))})]})}function rf(n){var m,h,y;const l=zs(),{sessionId:i,t:o,repeated:u,onOpen:f}=n;switch(o.k){case"user":return n.sent?r.jsxs("div",{className:"outbox-item",role:"group","aria-label":p.sentMessage,children:[r.jsx(ib,{sessionId:i,text:o.text,onOpen:f}),r.jsx("small",{children:p.sent})]}):r.jsx(ib,{sessionId:i,text:o.text,at:o.at,onOpen:f,onRewind:n.onRewind});case"text":return r.jsx(p_,{sessionId:i,text:o.text,repeated:u,onOpen:f,last:n.last});case"note":return o.retry?r.jsxs("div",{className:`chat-stopped ${o.detail?"failed":""}`,role:"status",children:[r.jsxs("span",{children:[o.detail?"⊗":"×"," ",Wu(o),o.detail&&r.jsxs("small",{children:[" · ",o.detail]})]}),n.onRetry&&r.jsx("button",{className:"btn small",onClick:n.onRetry,children:p.tryAgain}),n.onRetry&&n.retryActions]}):o.detail?r.jsxs("details",{className:"chat-note",children:[r.jsx("summary",{children:Wu(o)}),r.jsx("div",{className:"chat-note-detail",children:o.detail})]}):r.jsx("div",{className:"chat-note",children:Wu(o)});case"changes":return r.jsx(P_,{files:o.files});case"tool":{if(o.plan)return r.jsxs("div",{className:"chat-plan","data-tool":o.id,children:[r.jsx("div",{className:"chat-plan-head",children:p.plan}),r.jsx(of,{text:o.plan})]});const g=(m=o.result)==null?void 0:m.diff,v=r.jsxs("details",{className:`chat-tool ${(h=o.result)!=null&&h.error?"error":""}`,"data-tool":o.id,children:[r.jsxs("summary",{children:[r.jsx("span",{className:"tool-name",children:o.name}),r.jsx(pv,{name:o.name,summary:o.summary}),g&&r.jsx(cf,{d:g}),!o.result&&r.jsx("span",{className:"tool-running",children:p.running})]}),g?r.jsx(K_,{d:g}):r.jsx("pre",{children:o.result?o.result.stopped?p.toolStopped(l):o.result.text||p.noOutput:p.noResultYet})]});return!((y=o.result)!=null&&y.image)||o.name!=="Read"?v:r.jsxs(r.Fragment,{children:[v,u!=null&&u.has(o.summary)?r.jsx(y_,{path:o.summary}):r.jsx(Gc,{sessionId:i,side:"theirs",paths:[o.summary],read:!0,onOpen:f})]})}}}function X_(n){const[l,i]=H.useState(()=>Date.now());return H.useEffect(()=>{if(!n)return;const o=setInterval(()=>i(Date.now()),1e3);return()=>clearInterval(o)},[n]),l}const Z_=40,Q_=300;function V_(n,l){const[i,o]=H.useState(()=>wd.remembered(n)),[u,f]=H.useState(!1),[m,h]=H.useState(!1),y=H.useRef(null);H.useEffect(()=>{const v=wd.follow(n,l,{show:o,failed:f,loadingOlder:h});return y.current=v,()=>{v.stop(),y.current=null}},[n,l]);const g=H.useCallback(async v=>{var E;return(E=y.current)==null?void 0:E.older(v)},[]);return{chat:i,failed:u,loadingOlder:m,loadOlder:g}}function W_(n){const l=zs();return r.jsxs("div",{className:`send-held${n.nudge?" nudged":""}`,role:"status","aria-label":p.sendPaused,children:[r.jsxs("span",{children:[r.jsx("b",{children:p.agentHasOpen(l,Hb(n.panel))}),r.jsx("small",{children:p.heldWhilePanel})]}),r.jsx("button",{className:"btn small",...Nt(()=>n.onKey("\x1B")&&n.onDone()),children:p.close})]},n.nudge)}function J_({session:n,s:l,limitActions:i}){var Y,ee;const{view:o,status:u,id:f}=l,m=zs(),h=!!l.dialog,{entries:y}=H.useMemo(()=>Ry({kind:l.kind,view:o,status:u,answers:qd.answersOf(f),queued:l.queued.length,dialog:h}),[l.kind,o,u,f,l.queued.length,h]),g=X_(u==="working"),v=H.useRef(null),E=H.useRef(!0),_=H.useRef(0),x=H.useRef(!1),N=H.useRef(new Set),[T,C]=H.useState(!1),[P,z]=H.useState(null),[L,le]=H.useState(!1),ne=()=>le(!0),W=H.useRef(null),oe=H.useCallback(()=>jc.older(f,()=>{const j=v.current;j&&(W.current={height:j.scrollHeight,top:j.scrollTop})}),[f]);H.useLayoutEffect(()=>{const j=v.current;if(!j)return;const fe=o.messages.filter(ie=>ie.state==="sending"),Ce=fe.some(ie=>!N.current.has(ie.id));N.current=new Set(fe.map(ie=>ie.id)),Ce&&(E.current=!0);const G=W.current;W.current=null,G?j.scrollTop=G.top+j.scrollHeight-G.height:E.current&&!x.current&&(j.scrollTop=j.scrollHeight),o.older&&j.clientHeight&&j.scrollHeight<=j.clientHeight&&oe()},[o,u,oe]),H.useEffect(()=>{const j=v.current;if(!j)return;const fe=()=>{E.current&&!x.current&&(j.scrollTop=j.scrollHeight)},Ce=new ResizeObserver(fe);Ce.observe(j);for(const ie of j.children)Ce.observe(ie);const G=new MutationObserver(ie=>{for(const X of ie)for(const ve of X.addedNodes)ve instanceof Element&&Ce.observe(ve)});return G.observe(j,{childList:!0}),()=>{Ce.disconnect(),G.disconnect()}},[]);const he=()=>{const j=v.current;if(!j)return;const fe=j.scrollHeight-j.scrollTop-j.clientHeight<Z_,Ce=j.scrollTop<_.current;_.current=j.scrollTop,E.current=fe||E.current&&!Ce,C(!fe),j.scrollTop<Q_&&oe()},ge=()=>{const j=v.current;j&&j.scrollTo({top:j.scrollHeight,behavior:"smooth"})},_e=j=>{switch(j.kind){case"tools":return r.jsx(bv,{sessionId:f,tools:j.tools,going:j.going,end:j.end,onOpen:z});case"turn":return r.jsx(rf,{sessionId:f,t:j.turn,repeated:j.repeated,sent:j.sent,last:j.last,onOpen:z,onRewind:j.rewind?()=>n.send("/rewind\r"):void 0,onRetry:j.retry?()=>n.send(`${p.continueWord}\r`):void 0,retryActions:Bb(j.turn)&&i});case"answer":return r.jsxs("div",{className:"chat-answered",title:j.answer.question,children:[r.jsxs("span",{children:[p.youChose,j.answer.said]}),j.answer.code&&r.jsx("code",{children:j.answer.code})]});case"empty":return r.jsxs("div",{className:"chat-empty",children:[r.jsx("strong",{children:p.noConversation}),r.jsx("span",{className:"muted",children:p.typeBelow})]});case"live":return r.jsxs("div",{className:"reply chat-live","aria-live":"polite",children:[r.jsx("div",{className:"chat-live-head",children:p.agentWriting(m)}),j.text]});case"bubble":return r.jsx($_,{sessionId:f,messages:[j.message],onOpen:z});case"failed":return r.jsx("div",{className:"chat-note",children:p.chatUnreadable});case"background":return r.jsx(q_,{running:j.running,onManage:()=>n.send("/tasks\r")});case"working":return r.jsx("div",{className:"chat-working",children:r.jsxs("span",{className:"chat-working-now",children:[r.jsx("span",{className:"spinner","aria-hidden":!0}),p.claudeWorking,j.since!==null&&` · ${ek(j.since,g)}`]})});case"ask":return r.jsx(w_,{sessionId:f,ask:j.ask,onScreen:ne,onDone:n.reread},j.ask.id);case"choice":return r.jsx(lb,{sessionId:f,choices:j.choices,onKey:n.press,onScreen:ne,onDone:n.reread});case"tick":return r.jsx(D_,{sessionId:f,choices:j.choices,onKey:n.press,onScreen:ne,onDone:n.reread});case"waiting":return r.jsxs("div",{className:"chat-waiting",role:"status",children:[r.jsx("span",{children:p.agentWaiting(m)}),r.jsx("button",{className:"btn small",onClick:ne,children:p.showScreen})]})}};return r.jsxs("div",{className:"chat-layer",children:[r.jsxs("div",{className:"chat","data-testid":"chat",ref:v,onScroll:he,onTouchStart:()=>x.current=!0,onTouchEnd:()=>x.current=!1,onTouchCancel:()=>x.current=!1,children:[o.loadingOlder&&r.jsx("div",{className:"chat-older",role:"status","aria-label":p.loadingEarlier,children:r.jsx("span",{className:"spinner"})}),y.map(j=>r.jsx(H.Fragment,{children:_e(j)},j.key)),!o.synced&&!o.failed&&r.jsx("div",{className:"chat-empty muted",children:u==="ended"?p.endedNoChat:p.reading}),((Y=l.dialog)==null?void 0:Y.panel)&&r.jsx(j_,{panel:l.dialog.panel,onKey:n.press,onScreen:ne,onDone:n.settle}),((ee=l.dialog)==null?void 0:ee.choices)&&!l.dialog.panel&&r.jsx(lb,{sessionId:f,choices:l.dialog.choices,onKey:n.press,onScreen:ne,onDone:n.settle})]}),T&&r.jsx("button",{className:"to-bottom","aria-label":p.toBottom,onClick:ge,children:r.jsx(rE,{})}),P&&r.jsx(h_,{src:P,onClose:()=>z(null)}),L&&r.jsx(gv,{sessionId:f,onClose:()=>le(!1),keys:l.ended?void 0:{ctrlArmed:l.ctrl,onCtrl:()=>n.armCtrl(!l.ctrl),onKey:n.send,onPaste:()=>void n.paste()}})]})}const ek=(n,l)=>zb(Math.max(0,l-n)),tk=300;function nk(n){let l=!1;const i=setTimeout(()=>{l=!0,n()},tk);return{held:()=>l,end:()=>(clearTimeout(i),l?"held":"tap")}}const cb=n=>n.source==="builtin"&&p.builtinCommands[n.name]||n.description;function rb(n){const l=/^\/([^\s/]*)$/.exec(n);return l?l[1]:null}function ak(n,l){const i=l.toLowerCase(),o=f=>{const m=f.toLowerCase();return m.startsWith(i)?0:m.split(":").slice(1).some(h=>h.startsWith(i))?1:m.includes(i)?2:-1},u=n.map(f=>({c:f,r:o(f.name)})).filter(f=>f.r>=0);return[0,1,2].flatMap(f=>u.filter(m=>m.r===f).map(m=>m.c))}function sk(n,l){const i=/(^|\s)@([^\s@]*)$/.exec(n.slice(0,l));return i?{start:l-i[2].length-1,query:i[2]}:null}const lk=30;function ik(n,l){const i=l.toLowerCase(),o=f=>{const m=f.toLowerCase(),h=m.slice(m.lastIndexOf("/")+1);return h.startsWith(i)?0:h.includes(i)?1:m.includes(i)?2:-1},u=n.map(f=>({path:f,r:o(f)})).filter(f=>f.r>=0);return u.sort((f,m)=>f.r-m.r||f.path.length-m.path.length),u.slice(0,lk).map(f=>f.path)}function ok(n,l,i,o){const u=n.slice(l).replace(/^\S*/,"").replace(/^ /,""),f=`${n.slice(0,i.start)}@${o} `;return{text:f+u,caret:f.length}}const ck=1500;function rk(n,l){let i="",o="message",u="held",f=!1,m=!1,h,y={listening:!1,heard:"",zone:"send",finishing:!1};const g=x=>{y=x,o==="message"&&l.show(y)},v=()=>{u="over",clearTimeout(h),l.show(null)},E=()=>{if(u!=="over"){if(v(),f||_.abort(),!i.trim())return l.say(m?p.notHeard:p.micJustOn);o==="message"&&l.send(i)}};l.show(y);let _;try{_=n(x=>{u!=="over"&&(i=x,o==="composer"?l.write(x):g({...y,heard:x}))},x=>{if(f=!0,u!=="over"){if(x&&x!=="no-speech"&&x!=="aborted")return v(),l.failed(x);if(u==="finishing")return E();m||(v(),l.say(p.speechUnavailable))}},()=>{m=!0,g({...y,listening:!0})})}catch(x){return l.show(null),l.say(At(x,p.speechUnavailable)),null}return{move:x=>{u==="held"&&y.zone!==x&&g({...y,zone:x})},release:x=>{if(u==="held"){if(x==="cancel")return v(),_.abort();if(u="finishing",x==="text"?(l.show(null),o="composer",l.write(i)):g({...y,finishing:!0}),f)return E();_.stop(),h=setTimeout(E,ck)}},drop:()=>{u!=="over"&&(v(),_.abort())}}}function uk(n){return n==="language-not-supported"?p.speechLanguage:p.speechErrors[n]??p.speechStopped}const dk=500,fk=3e4,hk=n=>n.replace(/^"(.*)"$/,"$1");function mk(n){var F;const{draftKey:l,drafts:i}=n,o=n.snippets.lines();let u=l?i.draftOf(l):"",f=0,m=!1,h=[],y=null,g=n.speech,v=0,E=((F=n.refill)==null?void 0:F.n)??null,_=null,x=!1,N=null,T=!1,C=!1,P=0,z=null,L=null,le,ne=!1;const W=new Set,oe=()=>m?sk(u,f):null,he=()=>h.some(I=>I.piece===null),ge=()=>{clearTimeout(le),l&&i.keepDraft(l,u)},_e=()=>{rb(u)!==null&&!_&&!x&&n.loadCommands&&(x=!0,n.loadCommands().then(Q=>{x=!1,_=Q,j()},()=>x=!1)),oe()?n.loadFiles&&!T&&!C&&!(N&&Date.now()-N.at<fk)&&(T=!0,n.loadFiles().then(Q=>{T=!1,N={at:Date.now(),list:Q},j()},()=>{T=!1,C=!0})):C=!1},Y=()=>{const I=rb(u),Q=oe();return{text:u,caret:f,focused:m,attached:h,uploading:he(),sending:ne,empty:!u&&!h.length,offered:I!==null&&_?ak(_,I):[],said:I!==null?bw(o,I):[],mentioned:Q&&N?ik(N.list,Q.query):[],hold:y,speech:g,sent:v}};let ee=Y();const j=()=>{ee=Y();for(const I of[...W])I()},fe=I=>{I!==u&&l&&(clearTimeout(le),le=setTimeout(ge,dk)),u=I},Ce=(I,Q)=>{h=h.map(ye=>ye.key===I?Q(ye):ye)},G=(I,Q)=>{var Te;if(I.kind==="file")return I.source;if(I.kind==="picture")return I.source??n.sourceOf("picture",hk(Q));const ye=(Te=Oy(Q)[0])==null?void 0:Te.path;return ye?n.sourceOf("video",ye):I.source},ie=I=>{h=h.filter(Q=>!I.includes(Q.key))},X=()=>he()?(ne=!0,!1):(ne=!1,n.onSend(WT(h.map(I=>I.piece),u))?(u="",h=[],v++,ge(),!0):!1),ve=I=>{fe(I),f=I.length,X(),j()},we=()=>{L=rk(n.recognize,{show:I=>{y=I,j()},write:I=>{n.focusField(),fe(I),f=I.length,j()},send:ve,failed:I=>{n.speechFailed(I)&&(g=!1,j())},say:n.onError})},R=()=>{z==null||z.end(),z=null,L==null||L.drop(),L=null};return{subscribe(I){return W.add(I),()=>void W.delete(I)},getSnapshot:()=>ee,type(I,Q){fe(I),Q!==void 0&&(f=Q),_e(),j()},setCaret(I){f=I,_e(),j()},focus(){m=!0,_e(),j()},blur(){m=!1,_e(),j()},refill(I){if(!I||I.n===E)return;E=I.n;const Q=eA(I.text);fe(u&&Q.text?`${Q.text}
|
|
130
130
|
${u}`:Q.text||u);const ye=()=>`attached-${++P}`;h=[...Q.pictures.map(Te=>({key:ye(),kind:"picture",name:Te,piece:`"${Te}"`,source:n.sourceOf("picture",Te)})),...Q.files.map(Te=>({key:ye(),kind:Te.video?"video":"file",name:Te.name,piece:Te.piece,source:Te.video?n.sourceOf("video",Te.path):void 0})),...h],_e(),j()},attach(I,Q,ye,Te){const Ue=`attached-${++P}`;return h=[...h,{key:Ue,kind:I,name:Q,piece:null,source:Te}],(async()=>ye(Ue))().then(st=>{Ce(Ue,Ge=>({...Ge,piece:st,source:G(Ge,st)})),ne&&X(),j()},st=>{ie([Ue]),ne=!1;const Ge=I==="picture"?p.uploadFailed:p.fileUploadFailed(Q),Kt=At(st,Ge);n.onError(Kt===Ge?Ge:p.whatAndWhy(Ge,Kt)),j()}),j(),Ue},progress(I,Q){Ce(I,ye=>({...ye,sent:Q})),j()},remove(I){ie([I]),ne=!1,j()},send(){const I=X();return j(),I},pickCommand(I){n.focusField(),fe(`/${I.name} `),j()},pickSnippet(I){n.focusField(),fe(I),j()},pickFile(I){const Q=oe();if(!Q)return null;const ye=ok(u,f,Q,I);return fe(ye.text),f=ye.caret,_e(),j(),ye.caret},pressIn(){g&&(R(),z=nk(we))},move(I){z!=null&&z.held()&&(L==null||L.move(I))},letGo(I){const Q=z;return z=null,!Q||Q.end()==="tap"?I===null?"none":"tap":(I?L==null||L.release(I):L==null||L.drop(),L=null,"held")},dropTalk:R,leave(){ge(),R()}}}const gk=2*1024*1024,pk=8,ub=[1e3,2e3,4e3,8e3,15e3],db="abcdefghijklmnopqrstuvwxyz0123456789",bk=()=>Array.from({length:24},()=>db[Math.floor(Math.random()*db.length)]).join(""),yk=n=>new Promise(l=>setTimeout(l,n));async function vk(n,l,i){const o=`/api/uploads/parts/${l.id}`,u=async()=>(await n(o)).size;let f=await u().catch(()=>0),m=0;for(;f<l.size;)try{const h=await l.read(f,Math.min(gk,l.size-f));f=(await n(o,{method:"PUT",headers:{"content-type":"application/octet-stream","upload-offset":String(f)},body:h})).size,m=0,i(f)}catch(h){if(h instanceof Sn&&h.status<500&&h.status!==409&&h.status!==408&&h.status!==429||++m>=pk)throw h;await yk(ub[Math.min(m,ub.length)-1]),f=await u().catch(()=>f),i(f)}return n(`${o}/done`,{method:"POST",json:{name:l.name,size:l.size},idempotent:!0})}const{useSession:Sk}=Jw(_w);class xk extends Error{}const yv=()=>{const n=window;return n.SpeechRecognition??n.webkitSpeechRecognition},Ek=()=>yv()!==void 0;function wk(n,l,i){const o=yv();if(!o)throw new xk(p.noLiveSpeech);const u=new o;u.lang=Nb,u.continuous=!0,u.interimResults=!0;let f;return u.onresult=m=>n(Array.from(m.results,h=>h[0].transcript).join("")),u.onerror=m=>f=m.error,u.onstart=()=>i==null?void 0:i(),u.onend=()=>l(f),u.start(),{stop:()=>u.stop(),abort:()=>u.abort()}}function Tk({a:n,onRemove:l}){const i=n.piece===null,o=`${Math.round((n.sent??0)*100)}%`;return r.jsxs("span",{className:`attachment ${n.kind}`,"aria-label":i?`${n.name}, ${p.uploading}`:n.name,children:[n.kind==="file"?r.jsxs(r.Fragment,{children:[r.jsx(Hd,{}),r.jsxs("span",{className:"attachment-text",children:[r.jsx(rv,{className:"attachment-name",name:n.name,lines:2}),i&&r.jsx("span",{className:"attachment-sent",children:`${p.uploading} ${o}`})]})]}):n.kind==="video"?r.jsx("span",{className:"attachment-cover",children:i?o:r.jsx(Zb,{})}):r.jsxs(r.Fragment,{children:[n.source&&r.jsx("img",{src:n.source,alt:""}),i&&r.jsx("span",{className:"attachment-cover",children:r.jsx("span",{className:"spinner"})})]}),r.jsx("button",{className:"remove","aria-label":n.kind==="picture"?p.removeImage:p.removeFile,onClick:l,children:r.jsx(Qi,{})})]})}const Ak=54,Nk={send:p.holdSend,cancel:p.holdCancel,text:p.holdText};function _k({hold:n}){const l=H.useRef(null);H.useLayoutEffect(()=>{const o=document.documentElement;return o.classList.add("voice-held"),()=>o.classList.remove("voice-held")},[]),H.useLayoutEffect(()=>{const o=l.current;o&&(o.scrollTop=o.scrollHeight)},[n.heard]);const i=(o,u,f)=>r.jsxs("div",{className:n.zone===o?`voice-target ${o} active`:`voice-target ${o}`,children:[r.jsx("span",{className:"voice-target-dot","data-zone":o,"aria-hidden":!0,children:f}),u]});return r.jsxs("div",{className:`voice-panel zone-${n.zone}`,role:"status",children:[n.heard&&r.jsx("div",{className:"voice-heard",ref:l,children:n.heard}),!n.finishing&&r.jsxs("div",{className:"voice-targets",children:[i("cancel",p.cancel,r.jsx(Qi,{})),i("text",p.toText,r.jsx(hE,{}))]}),r.jsx("div",{className:"voice-hint",children:n.finishing?p.recognizing:Nk[n.zone]}),n.listening?r.jsx("div",{className:"wave","aria-hidden":!0,children:Array.from({length:Ak},(o,u)=>r.jsx("i",{style:{animationDelay:`${-(u*137%900)}ms`}},u))}):r.jsx("div",{className:"spinner","aria-label":p.openingMic})]})}const kk=16;function fb(n){for(const l of document.querySelectorAll(".voice-target-dot[data-zone]")){const i=l.getBoundingClientRect();if(Math.hypot(n.clientX-(i.left+i.width/2),n.clientY-(i.top+i.height/2))<=i.width/2+kk)return l.dataset.zone}return"send"}function Ok(n){const{onStop:l,footer:i,keys:o}=n,u=H.useRef(n);H.useLayoutEffect(()=>{u.current=n});const f=H.useRef(null),m=H.useRef(null),h=H.useRef(null),y=H.useRef(null),g=H.useRef(!1),[v]=H.useState(()=>mk({draftKey:n.draftKey,drafts:Nw,snippets:Td,loadCommands:n.loadCommands&&(()=>u.current.loadCommands()),loadFiles:n.loadFiles&&(()=>u.current.loadFiles()),onSend:Y=>u.current.onSend(Y),onError:Y=>u.current.onError(Y),sourceOf:(Y,ee)=>Y==="picture"?ky(ee):nA(ee),recognize:wk,speech:Ek(),speechFailed:Y=>(Y==="service-not-allowed"?u.current.onError(p.speechBlocked):u.current.onError(Y==="not-allowed"?p.speechDenied:uk(Y)),Y==="service-not-allowed"),focusField:()=>{var Y;return(Y=f.current)==null?void 0:Y.focus()},refill:n.refill})),E=Wi(v);H.useEffect(()=>{v.refill(n.refill??null)},[v,n.refill]),H.useEffect(()=>()=>v.leave(),[v]),H.useLayoutEffect(()=>{const Y=f.current;Y.style.height="",E.text&&(Y.style.height=`${Math.min(Y.scrollHeight,120)}px`)},[E.text]);const _=()=>{var Y;!g.current&&v.send()&&((Y=f.current)==null||Y.blur())},x=Y=>{Y.key!=="Enter"||Y.shiftKey||g.current||Y.nativeEvent.keyCode===229||(Y.preventDefault(),_())},N=Y=>ee=>v.progress(Y,ee),T=Y=>{const ee=[...Y.files??[]];Y.value="";for(const j of ee)j.type.startsWith("image/")?v.attach("picture",j.name,async()=>`"${await u.current.onUpload(j)}"`):v.attach(j.type.startsWith("video/")?"video":"file",j.name,fe=>Rk(j,N(fe)))},[C,P]=H.useState(!1),z=Y=>{P(!1),Y==null||Y.click()},L=()=>{var Y;(Y=f.current)==null||Y.blur(),P(!0)},le=Y=>{const ee=v.pickFile(Y);ee!==null&&requestAnimationFrame(()=>{var j,fe;(j=f.current)==null||j.focus(),(fe=f.current)==null||fe.setSelectionRange(ee,ee)})},ne=H.useRef("tap"),W=Y=>{E.speech&&(Y.currentTarget.setPointerCapture(Y.pointerId),v.pressIn())},oe=Y=>{E.hold&&v.move(fb(Y))},he=Y=>{ne.current=v.letGo(Y.type==="pointercancel"?null:fb(Y))},ge=()=>{var ee;const Y=ne.current;ne.current="tap",Y==="tap"&&((ee=f.current)==null||ee.focus())},_e=!E.text&&!E.focused;return r.jsxs("div",{className:E.attached.length||E.offered.length||E.said.length||E.mentioned.length?"composer with-pictures":"composer",children:[E.offered.length+E.said.length>0&&r.jsxs("div",{className:"slash-menu",role:"listbox","aria-label":p.commands,children:[E.said.map(Y=>r.jsxs("button",{role:"option","aria-selected":!1,"aria-label":p.snippet(Y),className:"snippet",onPointerDown:ee=>ee.preventDefault(),onClick:()=>v.pickSnippet(Y),children:[r.jsx("b",{children:Y}),r.jsx("span",{children:p.snippets})]},`said-${Y}`)),E.offered.map(Y=>r.jsxs("button",{role:"option","aria-selected":!1,"aria-label":`/${Y.name} ${cb(Y)}`,onPointerDown:ee=>ee.preventDefault(),onClick:()=>v.pickCommand(Y),children:[r.jsxs("b",{children:["/",Y.name]}),r.jsx("span",{children:cb(Y)})]},Y.name))]}),E.mentioned.length>0&&r.jsx("div",{className:"slash-menu",role:"listbox","aria-label":p.files,children:E.mentioned.map(Y=>{const ee=Y.lastIndexOf("/")+1;return r.jsxs("button",{role:"option","aria-selected":!1,"aria-label":`@${Y}`,onPointerDown:j=>j.preventDefault(),onClick:()=>le(Y),children:[r.jsx("b",{children:Y.slice(ee)}),ee>0&&r.jsx("span",{children:Y.slice(0,ee)})]},Y)})}),E.attached.length>0&&r.jsx("div",{className:"attachments",children:E.attached.map(Y=>r.jsx(Tk,{a:Y,onRemove:()=>v.remove(Y.key)},Y.key))}),r.jsxs("div",{className:"composer-row",children:[r.jsx("button",{className:"tool attach","aria-label":p.attach,"aria-expanded":C,onClick:L,children:r.jsx(Qb,{})}),C&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"sources-catcher",onClick:()=>P(!1)}),r.jsxs("div",{className:"sources",role:"menu",children:[r.jsxs("button",{role:"menuitem",onClick:()=>z(m.current),children:[r.jsx(oE,{}),p.photosAndVideos]}),Mk()&&r.jsxs("button",{role:"menuitem",onClick:()=>z(h.current),children:[r.jsx(cE,{}),p.takePhoto]}),r.jsxs("button",{role:"menuitem",onClick:()=>z(y.current),children:[r.jsx(Hd,{}),p.pickFile]})]})]}),r.jsx("input",{ref:m,type:"file",accept:"image/*,video/*",multiple:!0,hidden:!0,onChange:Y=>T(Y.currentTarget)}),r.jsx("input",{ref:h,type:"file",accept:"image/*",capture:"environment",hidden:!0,onChange:Y=>T(Y.currentTarget)}),r.jsx("input",{ref:y,type:"file",multiple:!0,hidden:!0,onChange:Y=>T(Y.currentTarget)}),r.jsxs("div",{className:"composer-field",children:[r.jsx("textarea",{ref:f,"aria-label":p.input,rows:1,value:E.text,enterKeyHint:"send",autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,onChange:Y=>v.type(Y.target.value,Y.target.selectionStart),onSelect:Y=>v.setCaret(Y.currentTarget.selectionStart),onFocus:()=>v.focus(),onBlur:()=>v.blur(),onCompositionStart:()=>g.current=!0,onCompositionEnd:()=>g.current=!1,onKeyDown:x}),_e&&r.jsx("button",{className:"hold-bar",onPointerDown:W,onPointerMove:oe,onPointerUp:he,onPointerCancel:he,onClick:ge,onContextMenu:Y=>Y.preventDefault(),children:E.speech?p.placeholderSpeech:p.placeholder})]}),l&&E.empty&&r.jsx("button",{className:"send stop","aria-label":p.stop,onPointerDown:Y=>Y.preventDefault(),onClick:l,children:r.jsx("span",{className:"send-dot",children:r.jsx("span",{className:"stop-square"})})}),!E.empty&&r.jsx("button",{className:"send","aria-label":E.sending?p.sending:p.send,disabled:E.sending,onPointerDown:Y=>Y.preventDefault(),onClick:_,children:r.jsx("span",{className:"send-dot",children:E.sending?r.jsx("span",{className:"spinner"}):r.jsx(uE,{})})})]}),(i||o)&&r.jsxs("div",{className:"composer-foot",children:[r.jsx("div",{className:"composer-foot-main",children:i}),o&&r.jsx("button",{className:o.shown?"keys-toggle shown":"keys-toggle","aria-label":o.shown?p.hideKeys:p.showKeys,"aria-pressed":o.shown,onPointerDown:Y=>Y.preventDefault(),onClick:o.onToggle,children:r.jsx(mE,{})})]}),E.hold&&r.jsx(_k,{hold:E.hold})]})}async function Rk(n,l){const i=async(o,u)=>new Uint8Array(await n.slice(o,o+u).arrayBuffer());return XT(await vk(at,{id:bk(),name:n.name,size:n.size,read:i},o=>l(n.size?o/n.size:1)))}const Mk=()=>matchMedia("(pointer: coarse)").matches;function Ck({s:n}){if(n==="reconnecting")return r.jsxs("span",{className:"status-word",children:["● ",p.reconnecting]});const l=wa(n.kind)?n.status:null;return r.jsxs("span",{className:l?`status-word ${l}`:"status-word",children:["● ",Ox(n)]})}function hb(n){const l=zs(),[i,o]=H.useState(null);if(!n.queued.length)return null;const u=n.queued.filter(f=>f.waits==="mac");return r.jsxs("section",{className:"queue","aria-label":p.queuedMessages,children:[r.jsxs("header",{className:"queue-head",children:[r.jsx("b",{children:p.queued(n.queued.length)}),r.jsx("small",{children:n.why})]}),r.jsx("ol",{children:n.queued.map((f,m)=>{var h,y;return r.jsxs("li",{className:i===f.id?"queue-item open":"queue-item",children:[r.jsxs("div",{className:"queue-row",children:[r.jsx("span",{className:"queue-n",children:m+1}),r.jsx("button",{className:"queue-text","aria-expanded":i===f.id,onClick:()=>o(i===f.id?null:f.id),children:QT(f.text)}),f.waits!=="mac"?r.jsx("small",{children:f.waits==="sending"?p.sending:p.inAgentsQueue(l)}):r.jsxs(r.Fragment,{children:[r.jsx("button",{className:"btn small",...Nt(()=>n.onEdit(f)),children:p.edit}),n.onSendNow&&r.jsx("button",{className:"btn small",...Nt(()=>{var g;return(g=n.onSendNow)==null?void 0:g.call(n,f)}),children:p.sendNow})]})]}),i===f.id&&f.waits==="mac"&&r.jsxs("div",{className:"queue-actions",children:[r.jsx("button",{className:"btn small",disabled:f.id===((h=u[0])==null?void 0:h.id),...Nt(()=>n.onMove(f,-1)),children:p.moveUp}),r.jsx("button",{className:"btn small",disabled:f.id===((y=u.at(-1))==null?void 0:y.id),...Nt(()=>n.onMove(f,1)),children:p.moveDown}),r.jsx("button",{className:"btn small danger",...Nt(()=>n.onDrop(f)),children:p.delete})]})]},f.id)})})]})}const mc=6;function Rc(n){var m,h;const l=H.useRef(null),[i,o]=H.useState(null),u=()=>o(null),f=()=>{var E;const y=(E=l.current)==null?void 0:E.getBoundingClientRect();if(i||!y)return u();const g=window.innerHeight-y.top+mc,v=y.top-2*mc;o(y.left<window.innerWidth/2?{left:Math.max(mc,y.left),bottom:g,maxHeight:v}:{right:Math.max(mc,window.innerWidth-y.right),bottom:g,maxHeight:v})};return r.jsxs(r.Fragment,{children:[r.jsx("button",{ref:l,className:`pill-part ${n.className??""}`,"aria-label":n.ariaLabel,"aria-haspopup":"menu","aria-expanded":!!i,...Nt(f),children:n.label}),i&&Fd.createPortal(r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"menu-scrim",onPointerDown:y=>(y.preventDefault(),u())}),r.jsxs("div",{className:"key-menu",role:"menu",style:i,children:[(m=n.children)==null?void 0:m.call(n,u),(h=n.items)==null?void 0:h.map(y=>r.jsxs("button",{role:"menuitemradio","aria-checked":!!y.current,className:y.current?"key-menu-item current":"key-menu-item",...Nt(()=>{u(),y.current||y.pick()}),children:[r.jsxs("span",{className:"key-menu-body",children:[r.jsx("span",{children:y.label}),y.sub&&r.jsx("span",{className:"key-menu-sub",children:y.sub})]}),y.current&&r.jsx("span",{className:"key-menu-check",children:"✓"})]},y.label))]})]}),document.body)]})}function jk(n){const{mode:l}=n;return r.jsx(Rc,{label:n.switching?p.switchingMode:l===void 0?p.permissions:cp(l),ariaLabel:p.permissionsIs(l===void 0?p.unknown:cp(l)),className:l==="bypass permissions"?"bypass":void 0,items:Gd.map(i=>({label:i.name,current:i.mode===l,pick:()=>n.onMode(i.mode)}))})}function Dk(){return r.jsx("div",{className:"pill pill-skeleton",role:"status","aria-label":p.reading})}function Lk(n){const l=n.usage??{},i=jT(l);return n.fixed?r.jsxs("div",{className:"pill",children:[r.jsx("span",{className:"pill-part","aria-label":p.modelIs(l.model??p.unknown),children:l.model??p.model}),l.effort&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"pill-sep","aria-hidden":!0,children:"·"}),r.jsx("span",{className:"pill-part","aria-label":p.effortIs(Yl(l.effort)),children:Yl(l.effort)})]}),i&&r.jsx(mb,{usage:l,figure:i,account:n.account})]}):r.jsxs("div",{className:"pill",children:[r.jsx(Rc,{label:l.model??p.model,ariaLabel:p.modelIs(l.model??p.unknown),items:Ux(n.models,l.model).map(o=>({...o,pick:()=>n.onCommand(o.command)}))}),r.jsx("span",{className:"pill-sep","aria-hidden":!0,children:"·"}),r.jsx(jk,{mode:n.mode,switching:n.switching,onMode:n.onMode}),l.effort&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"pill-sep","aria-hidden":!0,children:"·"}),r.jsx(Rc,{label:Yl(l.effort),ariaLabel:p.effortIs(Yl(l.effort)),items:Bx(n.models,l.model).map(o=>({label:Yl(o),current:o===l.effort,pick:()=>n.onCommand(`/effort ${o}`)}))})]}),i&&r.jsx(mb,{usage:l,figure:i,account:n.account})]})}const zk=1500;function mb({usage:n,figure:l,account:i}){const[o,u]=H.useState(!1),f=MT(n,void 0,i),m=()=>{var h;return void((h=navigator.clipboard)==null?void 0:h.writeText(CT(n,f)).then(()=>{u(!0),setTimeout(()=>u(!1),zk)}))};return r.jsx(Rc,{label:l.label,ariaLabel:l.accessibilityLabel,className:l.high?"pill-ctx high":"pill-ctx",children:()=>r.jsxs("div",{className:"usage-menu",children:[f.map(h=>r.jsxs("div",{className:"usage-menu-row",children:[r.jsx("span",{children:h.label}),r.jsxs("span",{className:h.high?"usage-menu-value high":"usage-menu-value",children:[h.value,h.sub&&r.jsx("small",{children:h.sub})]})]},h.label)),r.jsx("button",{className:"key-menu-item",...Nt(m),children:r.jsx("span",{children:o?p.copied:p.copyUsage})})]})})}const Uk={completed:"✓",in_progress:"●"};function Bk({tasks:n}){const l=n.filter(o=>o.status==="completed").length;if(!n.length||l===n.length)return null;const i=n.find(o=>o.status==="in_progress");return r.jsxs("details",{className:"chat-tasks",children:[r.jsxs("summary",{children:[r.jsx("span",{className:"tasks-count",children:p.tasks(l,n.length)}),r.jsx("span",{className:"tasks-now",children:i?p.taskNow(i.subject):p.taskNotStarted})]}),r.jsx("ul",{children:n.map((o,u)=>r.jsxs("li",{className:o.status,children:[r.jsx("span",{className:"tasks-mark",children:Uk[o.status]??"○"}),o.subject]},u))})]})}function Hk(n,l){var o;const i=l??((o=n.accounts.find(u=>u.id===n.inUse))==null?void 0:o.email);return n.accounts.filter(u=>u.email!==i&&Xd(u)===null)}const $k=n=>n.limits?xy(n):n.folder;function Ik(n){const{entries:l}=Ry({kind:"claude",view:n.view,status:n.status,answers:[],queued:n.queued,dialog:!1});return l.some(i=>i.kind==="turn"&&i.retry&&Bb(i.turn))}function Gk(n,l){const i=new Set;let o={accounts:null,asking:null,moving:null,waiting:null,error:null};const u=f=>{o={...o,...f},i.forEach(m=>m())};return{subscribe(f){return i.add(f),()=>void i.delete(f)},getSnapshot:()=>o,load:f=>n("/api/claude/accounts").then(m=>u({accounts:Hk(m,f)}),()=>{}),offer:(f,m)=>u({asking:{text:f,typed:m},error:null}),dismiss(){var m;const f=(m=o.asking)!=null&&m.typed?o.asking.text:null;return u({asking:null,error:null}),f},async move(f){var y;const m=o.asking,h=(y=o.accounts)==null?void 0:y.find(g=>g.id===f);if(!(!m||!h||o.moving!==null)){u({moving:f,error:null});try{await n("/api/claude/account",{method:"PUT",json:{id:f},idempotent:!0}),await n("/api/claude/account/move",{method:"POST",idempotent:!0}),u({asking:null,moving:null,waiting:{email:h.email,text:m.text}})}catch(g){u({moving:null,error:At(g,p.failed)})}}},seen(f){const m=o.waiting;!m||f!==m.email||(u({waiting:null}),l(m.text))}}}function qk(n,l,i){const o=H.useRef(i);H.useLayoutEffect(()=>{o.current=i});const u=H.useMemo(()=>Gk(n,f=>o.current(f)),[n]);return H.useEffect(()=>{u.load(l),u.seen(l)},[u,l]),{move:u,...Wi(u)}}function Yk({move:n,state:l}){return l.waiting?r.jsxs("small",{className:"chat-limit-how",role:"status",children:[r.jsx("span",{className:"spinner small","aria-hidden":!0})," ",p.movingAccount(l.waiting.email)]}):l.accounts?l.accounts.length?r.jsx("button",{className:"btn small primary",onClick:()=>n.offer(p.continueWord,!1),children:p.moveAccount}):r.jsx("small",{className:"chat-limit-how",children:p.moveAccountHow}):null}function Kk({move:n,state:l,onGiveBack:i}){const{asking:o,accounts:u,moving:f,error:m}=l;if(!o||!u)return null;const h=()=>{const y=n.dismiss();y&&i(y)};return r.jsxs(Lc,{title:p.moveAccountTitle,onClose:h,children:[m&&r.jsx("div",{className:"alert",role:"alert",children:m}),o.typed&&r.jsx("p",{className:"sheet-lead",children:p.moveAccountThen(o.text)}),u.map(y=>r.jsxs("button",{className:"option",disabled:f!==null,"aria-busy":f===y.id,onClick:()=>void n.move(y.id),children:[r.jsxs("span",{className:"opt-text",children:[r.jsx("span",{className:"opt-title",children:y.email}),r.jsx("span",{className:"opt-sub",children:$k(y)})]}),f===y.id&&r.jsx("span",{className:"spinner small","aria-hidden":!0})]},y.id)),r.jsx("p",{className:"sheet-note",children:p.moveAccountNote})]})}function Fk({id:n,onClose:l}){const i=zw(n),o=()=>navigator.clipboard.writeText(i).catch(()=>window.prompt(p.continueOnMacSub,i));return r.jsx(zc,{title:p.continueOnMac,message:`${p.continueOnMacSub}
|
|
131
131
|
|
|
132
|
-
${i}`,side:!0,cancel:p.close,actions:[{label:p.copy,run:()=>void o()}],onClose:l})}const Pk=150,Xk=20;function Zk(){return window.matchMedia("(display-mode: standalone)").matches?(window.innerHeight>=window.innerWidth?Math.max(screen.width,screen.height):Math.min(screen.width,screen.height))-window.innerHeight>=Xk:!1}const Qk=n=>n instanceof HTMLTextAreaElement||n instanceof HTMLInputElement&&!["button","checkbox","radio","range","submit","file"].includes(n.type)||n instanceof HTMLElement&&n.isContentEditable;function Vk(){H.useEffect(()=>{const n=window.visualViewport;if(!n)return;const l=document.documentElement,i=()=>{const f=Qk(document.activeElement);f?l.style.setProperty("--vvh",`${n.height}px`):l.style.removeProperty("--vvh");const m=f&&n.height<window.innerHeight-Pk;l.toggleAttribute("data-no-home-indicator",m||Zk()),window.scrollTo(0,0)};let o=0;const u=()=>{cancelAnimationFrame(o),o=requestAnimationFrame(i)};return i(),n.addEventListener("resize",i),n.addEventListener("scroll",i),document.addEventListener("focusout",u),()=>{cancelAnimationFrame(o),n.removeEventListener("resize",i),n.removeEventListener("scroll",i),document.removeEventListener("focusout",u),l.style.removeProperty("--vvh"),l.removeAttribute("data-no-home-indicator")}},[])}function Wk({id:n}){Vk();const[l,i]=Sk(n),[o,u]=H.useState(gp.shown),f=()=>{gp.show(!o),u(!o)},{known:m,kind:h,ended:y,status:g,header:v,link:E,view:_}=i,{screen:x}=_,N=wa(h)?h:null,T=!!N,[C,P]=H.useState(!1),[z,L]=H.useState(!1),[le,ne]=H.useState(!1),[W,oe]=H.useState(!1),[he,ge]=H.useState(!1),{move:_e,...Y}=qk(at,m==null?void 0:m.claudeAccount,X=>void l.sendMessage(X)),ee=X=>{var we;return h==="claude"&&!!((we=Y.accounts)!=null&&we.length)&&!Y.waiting&&!X.startsWith("/")&&Ik({view:_,status:g,queued:i.queued.length})?(_e.offer(X,!0),!0):l.sendMessage(X)},j=(X,ve)=>{ge(!0),Ow(at,{...ve,kind:X},i.quit).then(we=>{"onMac"in we?Zt(`/${we.onMac.agent}/${we.onMac.sid}`):we.session.id!==n&&Zt(`/m/${Bt}/s/${we.session.id}`)},we=>l.sayToast(At(we,p.continueFailed))).finally(()=>ge(!1))},fe={method:"POST",headers:{"content-type":"application/octet-stream"},idempotent:!0},Ce=async X=>(await at("/api/uploads",{...fe,body:X})).path,G=async()=>{await l.end()&&Zt("/")},ie=[{label:p.showScreen,run:()=>ne(!0)},{label:p.continueOnMac,run:()=>L(!0)},...m?[{label:p.rename,run:()=>oe(!0)}]:[],...i.ending?[]:[{label:p.endSession,run:()=>void G(),destructive:!0}]];return r.jsx(Ey.Provider,{value:vc(h),children:r.jsxs("div",{className:"term-page","data-link":E,children:[r.jsx(Uc,{onBack:()=>Zt("/"),title:r.jsxs("button",{className:"term-title","aria-label":p.renameSession((m==null?void 0:m.title)??p.session),disabled:!m||y,onClick:()=>oe(!0),children:[r.jsx("strong",{children:(m==null?void 0:m.title)??p.session}),r.jsxs("span",{children:[v&&r.jsx(Ck,{s:v}),Ba((m==null?void 0:m.cwd)??"")]})]}),right:!y&&r.jsx("button",{className:"icon-btn","aria-label":p.sessionMenu,onClick:()=>P(!0),children:r.jsx(dE,{})})}),r.jsxs("div",{className:"term-wrap",children:[T&&r.jsx(J_,{session:l,s:i,limitActions:r.jsx(Yk,{move:_e,state:Y})}),h==="shell"&&!y&&r.jsxs("div",{className:"overlay",children:[r.jsx("strong",{children:p.shellSession}),r.jsx("span",{className:"muted",children:p.shellSessionSub}),r.jsxs("div",{className:"actions",children:[r.jsx("button",{className:"btn",onClick:()=>Zt("/"),children:p.back}),r.jsx("button",{className:"btn primary",onClick:()=>ne(!0),children:p.showScreen})]})]}),E==="reconnecting"&&!y&&!N&&r.jsxs("div",{className:"overlay",children:[r.jsx("div",{className:"spinner"}),r.jsx("strong",{children:p.reconnecting}),r.jsx("span",{className:"muted",children:p.reconnectingSub})]}),y&&!N&&r.jsxs("div",{className:"overlay",children:[r.jsx("strong",{children:p.sessionEnded}),r.jsx("span",{className:"muted",children:p.sessionEndedSub}),r.jsx("div",{className:"actions",children:r.jsx("button",{className:"btn",onClick:()=>Zt("/"),children:p.back})})]})]}),(y||i.quit)&&m&&N&&r.jsxs("footer",{className:"term-bottom ended-bar",children:[i.quit&&r.jsx(hb,{queued:i.queued,why:i.queueWhy,onMove:(X,ve)=>void l.move(X,ve),onEdit:X=>void l.unsend(X,!0),onDrop:X=>void l.unsend(X,!1)}),r.jsx("strong",{children:i.quit?p.agentQuit(vc(N)):p.sessionEnded}),r.jsx("span",{className:"muted",children:i.quit?p.agentQuitSub:pp(m)?p.endedGoOnSub:p.sessionEndedSub}),pp(m)?r.jsxs("div",{className:"actions",children:[r.jsx("button",{className:"btn",disabled:he,onClick:()=>void xp({kind:N,cwd:m.cwd}),children:p.startAnother}),r.jsx("button",{className:"btn primary",disabled:he,onClick:()=>j(N,m),children:p.continueConversation})]}):r.jsxs("div",{className:"actions",children:[r.jsx("button",{className:"btn",onClick:()=>Zt("/"),children:p.back}),r.jsx("button",{className:"btn primary",onClick:()=>void xp({kind:N,cwd:m.cwd}),children:p.startAnother})]})]}),h!=="shell"&&!y&&!i.quit&&r.jsxs("footer",{className:"term-bottom",children:[x.panel&&r.jsx(W_,{panel:x.panel,nudge:i.nudge,onKey:l.press,onDone:l.reread}),_.onMac>0&&r.jsx(H_,{terminals:_.onMac,sessionId:n}),g==="compacting"&&r.jsx(B_,{count:i.queued.length}),T&&r.jsx(Bk,{tasks:_.tasks}),r.jsx(hb,{queued:i.queued,why:i.queueWhy,onSendNow:i.canSendNow?X=>void l.sendNow(X):void 0,onMove:(X,ve)=>void l.move(X,ve),onEdit:X=>void l.unsend(X,!0),onDrop:X=>void l.unsend(X,!1)}),i.suggestion&&r.jsxs("div",{className:"suggest",children:[r.jsxs("button",{className:"suggest-take",onClick:()=>l.giveBack(i.suggestion),children:[r.jsx("small",{children:p.suggestion}),r.jsx("span",{children:i.suggestion})]}),r.jsx("button",{className:"icon-btn","aria-label":p.dismissSuggestion,onClick:l.dismissSuggestion,children:r.jsx(Qi,{})})]}),(o||i.ctrl)&&r.jsx(My,{ctrlArmed:i.ctrl,onCtrl:()=>l.armCtrl(!i.ctrl),onKey:l.send,onPaste:()=>void l.paste()}),r.jsx(Ok,{draftKey:n,keys:{shown:o,onToggle:f},onSend:ee,onUpload:Ce,onError:l.sayToast,loadCommands:l.loadCommands,loadFiles:l.loadFiles,refill:i.refill,onStop:g==="working"?()=>l.send("\x1B"):void 0,footer:h===null?r.jsx(Dk,{}):T&&r.jsx(Lk,{usage:m==null?void 0:m.usage,account:m==null?void 0:m.claudeAccount,mode:i.mode,models:i.models,switching:i.switching,fixed:h==="codex",onCommand:l.runCommand,onMode:X=>void l.switchMode(X)})})]}),i.toast&&r.jsx("div",{className:"toast",children:i.toast}),W&&m&&r.jsx(by,{session:m,onClose:()=>oe(!1)}),le&&r.jsx(gv,{sessionId:n,onClose:()=>ne(!1),keys:y?void 0:{ctrlArmed:i.ctrl,onCtrl:()=>l.armCtrl(!i.ctrl),onKey:l.send,onPaste:()=>void l.paste()}}),C&&r.jsx(zc,{title:m==null?void 0:m.title,actions:ie,onClose:()=>P(!1)}),z&&r.jsx(Fk,{id:n,onClose:()=>L(!1)}),r.jsx(Kk,{move:_e,state:Y,onGiveBack:l.giveBack})]})})}const Jk=3e3;function e1(n,l,i,o){const[u,f]=H.useState(null),[m,h]=H.useState(!1),[y,g]=H.useState(null),[v,E]=H.useState(0),[_,x]=H.useState(!1);H.useEffect(()=>{let L=!1;return Yd(n).then(le=>{if(L)return;const ne=le.find(W=>W.sessionId===i&&ls(W)===l)??null;f(ne),ne!=null&&ne.takingOver&&x(!0)},()=>{}),()=>{L=!0}},[n,l,i,v]);const N=u?Dw(u):null,T=(N==null?void 0:N.do)==="takeOver"&&N.waiting,C=(N==null?void 0:N.do)==="takeOver";H.useEffect(()=>{if(!C)return;const L=setInterval(()=>E(le=>le+1),Jk);return()=>clearInterval(L)},[C]),H.useEffect(()=>{(N==null?void 0:N.do)==="open"&&_&&o(N.id)});const P=_&&!T&&(N==null?void 0:N.do)!=="open",z=async L=>{if(u!=null&&u.cwd){h(!0),g(null),x(!1);try{const le=await L(u.cwd);if(le)return o(le.id);E(ne=>ne+1)}catch(le){g(At(le,p.openFailed))}h(!1)}};return{info:u,busy:m,error:y,pick:N,waiting:T,missed:P,resume:()=>z(L=>Dc(n,{kind:l,cwd:L,resumeId:i})),takeOverNow:()=>z(L=>bp(n,{...u,cwd:L},"now")),takeOverWhenDone:()=>z(L=>bp(n,{...u,cwd:L},"whenIdle")),cancel:()=>z(()=>Lw(n,u).then(()=>null))}}function t1({agent:n,sid:l}){const{chat:i,failed:o}=V_(`${n}:${l}`,Rw(n,l)),{info:u,busy:f,error:m,pick:h,waiting:y,missed:g,resume:v,takeOverNow:E,takeOverWhenDone:_,cancel:x}=e1(at,n,l,z=>Zt(`/m/${Bt}/s/${z}`)),N=H.useRef(null),T=i?Ud(i.items,i.base):[],C=H.useRef(!0);H.useLayoutEffect(()=>{const z=N.current;if(!z)return;const L=()=>{C.current&&(z.scrollTop=z.scrollHeight)};L();const le=new ResizeObserver(L);le.observe(z);for(const ne of z.children)le.observe(ne);return()=>le.disconnect()},[T.length]);const P=()=>{const z=N.current;z&&(C.current=z.scrollHeight-z.scrollTop-z.clientHeight<40)};return r.jsxs("div",{className:"term-page",children:[r.jsx(Uc,{onBack:()=>Zt("/"),title:r.jsxs("div",{className:"term-title",children:[r.jsx("strong",{children:(u==null?void 0:u.title)??p.macSession}),u&&r.jsx("span",{children:`${Ba(u.cwd??"")} · ${Ua(u.lastActivity)}`})]}),right:r.jsx("span",{className:"chip",children:p.readOnly})}),r.jsx("div",{className:"term-wrap",children:r.jsxs("div",{className:"chat",ref:N,onScroll:P,children:[Ib(T).map(z=>z.k==="tools"?r.jsx(bv,{sessionId:l,tools:z.tools,going:z.going,onOpen:()=>{}},z.key):r.jsx(rf,{sessionId:l,t:z.t,onOpen:()=>{}},z.t.key)),!i&&!o&&r.jsx("div",{className:"chat-empty muted",children:p.reading}),o&&r.jsx("div",{className:"chat-note",children:p.cannotRead})]})}),r.jsxs("div",{className:"claude-view-foot",children:[m&&r.jsx("div",{className:"alert",children:m}),g&&!m&&r.jsx("div",{className:"alert",children:p.takeOverMissed}),(h==null?void 0:h.do)==="takeOver"&&r.jsx("strong",{children:[h.status==="busy"?p.onMacBusy:h.status==="waiting"?p.onMacWaiting:p.onMacIdle,h.terminals>1&&p.openInTerminals(h.terminals)].filter(Boolean).join(" · ")}),(h==null?void 0:h.do)==="takeOver"&&y?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"muted",children:p.takingOverWait}),r.jsx("button",{className:"btn primary",disabled:f,onClick:E,children:p.takeOverInterrupt}),r.jsx("button",{className:"btn",disabled:f,onClick:x,children:p.takeOverCancel})]}):(h==null?void 0:h.do)==="takeOver"?r.jsxs(r.Fragment,{children:[h.status==="idle"&&r.jsx("button",{className:"btn primary",disabled:f,onClick:E,children:p.takeOverNow}),h.status==="busy"&&r.jsxs(r.Fragment,{children:[r.jsx("button",{className:"btn primary",disabled:f,onClick:_,children:p.takeOverWhenDone}),r.jsx("button",{className:"btn",disabled:f,onClick:E,children:p.takeOverInterrupt})]}),h.status==="waiting"&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"muted",children:p.takeOverDropsQuestion}),r.jsx("button",{className:"btn primary",disabled:f,onClick:E,children:p.takeOverNow})]}),r.jsx("span",{className:"claude-view-note",children:p.takeOverNote(vc(n))})]}):(h==null?void 0:h.do)==="gone"?r.jsxs(r.Fragment,{children:[r.jsx("button",{className:"btn primary",disabled:!0,children:p.folderGoneNoResume}),r.jsx("span",{className:"claude-view-note",children:p.folderGoneSub(Ba((u==null?void 0:u.cwd)??""))})]}):r.jsx("button",{className:"btn primary",disabled:f||!(u!=null&&u.cwd)||!h||h.do==="none",onClick:()=>(h==null?void 0:h.do)==="open"?Zt(`/m/${Bt}/s/${h.id}`):void v(),children:(h==null?void 0:h.do)==="open"?p.openAlreadyOnPhone:(h==null?void 0:h.do)==="none"?n==="codex"?p.openElsewhereNoResume:p.inBackgroundNoResume:p.continueOnPhone})]})]})}const vv=n=>{var l;return((l=n.querySelector('script[type="module"][src]'))==null?void 0:l.getAttribute("src"))??null},gb=vv(document);let pd=!1,Sv=!1;const Cd=new Set;async function n1(){const n=await fetch("/",{cache:"no-store",credentials:"same-origin"});return n.ok?vv(new DOMParser().parseFromString(await n.text(),"text/html")):null}async function bd(n){if(!(pd||!gb)){pd=!0;try{const l=await n1();if(!l||l===gb)return;if(n)return location.reload();Sv=!0;for(const i of Cd)i()}catch{}finally{pd=!1}}}function a1(){document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&bd(!0)}),window.addEventListener("popstate",()=>void bd(!0)),jb.subscribe(()=>void bd(!1))}const s1=()=>H.useSyncExternalStore(n=>(Cd.add(n),()=>void Cd.delete(n)),()=>Sv);function l1(){return s1()?r.jsx("button",{className:"update-offer",onClick:()=>location.reload(),children:p.updateReady}):null}const xv="(min-width: 900px)",i1=n=>{const l=matchMedia(xv);return l.addEventListener("change",n),()=>l.removeEventListener("change",n)},o1=()=>H.useSyncExternalStore(i1,()=>matchMedia(xv).matches);function c1(){var m;const n=gE(),l=o1();if(n==="/login")return r.jsx(Fw,{});if(n==="/settings")return r.jsx(TT,{});if(n==="/mac")return r.jsx(IT,{});const i=(m=n.match(/^\/m\/[^/]+\/s\/([a-z0-9]+)$/))==null?void 0:m[1],o=n.match(/^\/(claude|codex)\/([0-9a-f-]{36})$/),u=o?{agent:o[1],sid:o[2]}:null,f=i?r.jsx(Wk,{id:i},i):u?r.jsx(t1,{...u},n):null;return l?r.jsxs("div",{className:"split",children:[r.jsx("div",{className:"split-list",children:r.jsx(wp,{current:i??(u==null?void 0:u.sid)})}),r.jsx("div",{className:"split-pane",children:f??r.jsx("p",{className:"split-empty muted",children:p.chooseSession})})]}):f??r.jsx(wp,{})}document.documentElement.lang=Xi==="zh"?"zh-CN":"en";vy();const Ev=location.pathname==="/setup",r1=H.lazy(()=>O0(()=>import("./Setup-DinzDcF1.js"),[]).then(n=>({default:n.Setup})));Ev||(fT(),a1());Y0.createRoot(document.getElementById("root")).render(r.jsx(H.StrictMode,{children:Ev?r.jsx(H.Suspense,{children:r.jsx(r1,{})}):r.jsxs(r.Fragment,{children:[r.jsx(c1,{}),r.jsx(l1,{})]})}));export{Sn as A,Op as C,Xb as I,Ax as c,At as e,r as j,H as r,p as t};
|
|
132
|
+
${i}`,side:!0,cancel:p.close,actions:[{label:p.copy,run:()=>void o()}],onClose:l})}const Pk=150,Xk=20;function Zk(){return window.matchMedia("(display-mode: standalone)").matches?(window.innerHeight>=window.innerWidth?Math.max(screen.width,screen.height):Math.min(screen.width,screen.height))-window.innerHeight>=Xk:!1}const Qk=n=>n instanceof HTMLTextAreaElement||n instanceof HTMLInputElement&&!["button","checkbox","radio","range","submit","file"].includes(n.type)||n instanceof HTMLElement&&n.isContentEditable;function Vk(){H.useEffect(()=>{const n=window.visualViewport;if(!n)return;const l=document.documentElement,i=()=>{const f=Qk(document.activeElement);f?l.style.setProperty("--vvh",`${n.height}px`):l.style.removeProperty("--vvh");const m=f&&n.height<window.innerHeight-Pk;l.toggleAttribute("data-no-home-indicator",m||Zk()),window.scrollTo(0,0)};let o=0;const u=()=>{cancelAnimationFrame(o),o=requestAnimationFrame(i)};return i(),n.addEventListener("resize",i),n.addEventListener("scroll",i),document.addEventListener("focusout",u),()=>{cancelAnimationFrame(o),n.removeEventListener("resize",i),n.removeEventListener("scroll",i),document.removeEventListener("focusout",u),l.style.removeProperty("--vvh"),l.removeAttribute("data-no-home-indicator")}},[])}function Wk({id:n}){Vk();const[l,i]=Sk(n),[o,u]=H.useState(gp.shown),f=()=>{gp.show(!o),u(!o)},{known:m,kind:h,ended:y,status:g,header:v,link:E,view:_}=i,{screen:x}=_,N=wa(h)?h:null,T=!!N,[C,P]=H.useState(!1),[z,L]=H.useState(!1),[le,ne]=H.useState(!1),[W,oe]=H.useState(!1),[he,ge]=H.useState(!1),{move:_e,...Y}=qk(at,m==null?void 0:m.claudeAccount,X=>void l.sendMessage(X)),ee=X=>{var we;return h==="claude"&&!!((we=Y.accounts)!=null&&we.length)&&!Y.waiting&&!X.startsWith("/")&&Ik({view:_,status:g,queued:i.queued.length})?(_e.offer(X,!0),!0):l.sendMessage(X)},j=(X,ve)=>{ge(!0),Ow(at,{...ve,kind:X},i.quit).then(we=>{"onMac"in we?Zt(`/${we.onMac.agent}/${we.onMac.sid}`):we.session.id!==n&&Zt(`/m/${Bt}/s/${we.session.id}`)},we=>l.sayToast(At(we,p.continueFailed))).finally(()=>ge(!1))},fe={method:"POST",headers:{"content-type":"application/octet-stream"},idempotent:!0},Ce=async X=>(await at("/api/uploads",{...fe,body:X})).path,G=async()=>{await l.end()&&Zt("/")},ie=[{label:p.showScreen,run:()=>ne(!0)},{label:p.continueOnMac,run:()=>L(!0)},...m?[{label:p.rename,run:()=>oe(!0)}]:[],...i.ending?[]:[{label:p.endSession,run:()=>void G(),destructive:!0}]];return r.jsx(Ey.Provider,{value:vc(h),children:r.jsxs("div",{className:"term-page","data-link":E,children:[r.jsx(Uc,{onBack:()=>Zt("/"),title:r.jsxs("button",{className:"term-title","aria-label":p.renameSession((m==null?void 0:m.title)??p.session),disabled:!m||y,onClick:()=>oe(!0),children:[r.jsx("strong",{children:(m==null?void 0:m.title)??p.session}),r.jsxs("span",{children:[v&&r.jsx(Ck,{s:v}),Ba((m==null?void 0:m.cwd)??"")]})]}),right:!y&&r.jsx("button",{className:"icon-btn","aria-label":p.sessionMenu,onClick:()=>P(!0),children:r.jsx(dE,{})})}),r.jsxs("div",{className:"term-wrap",children:[T&&r.jsx(J_,{session:l,s:i,limitActions:r.jsx(Yk,{move:_e,state:Y})}),h==="shell"&&!y&&r.jsxs("div",{className:"overlay",children:[r.jsx("strong",{children:p.shellSession}),r.jsx("span",{className:"muted",children:p.shellSessionSub}),r.jsxs("div",{className:"actions",children:[r.jsx("button",{className:"btn",onClick:()=>Zt("/"),children:p.back}),r.jsx("button",{className:"btn primary",onClick:()=>ne(!0),children:p.showScreen})]})]}),E==="reconnecting"&&!y&&!N&&r.jsxs("div",{className:"overlay",children:[r.jsx("div",{className:"spinner"}),r.jsx("strong",{children:p.reconnecting}),r.jsx("span",{className:"muted",children:p.reconnectingSub})]}),y&&!N&&r.jsxs("div",{className:"overlay",children:[r.jsx("strong",{children:p.sessionEnded}),r.jsx("span",{className:"muted",children:p.sessionEndedSub}),r.jsx("div",{className:"actions",children:r.jsx("button",{className:"btn",onClick:()=>Zt("/"),children:p.back})})]})]}),(y||i.quit)&&m&&N&&r.jsxs("footer",{className:"term-bottom ended-bar",children:[i.quit&&r.jsx(hb,{queued:i.queued,why:i.queueWhy,onMove:(X,ve)=>void l.move(X,ve),onEdit:X=>void l.unsend(X,!0),onDrop:X=>void l.unsend(X,!1)}),r.jsx("strong",{children:i.quit?p.agentQuit(vc(N)):p.sessionEnded}),r.jsx("span",{className:"muted",children:i.quit?p.agentQuitSub:pp(m)?p.endedGoOnSub:p.sessionEndedSub}),pp(m)?r.jsxs("div",{className:"actions",children:[r.jsx("button",{className:"btn",disabled:he,onClick:()=>void xp({kind:N,cwd:m.cwd}),children:p.startAnother}),r.jsx("button",{className:"btn primary",disabled:he,onClick:()=>j(N,m),children:p.continueConversation})]}):r.jsxs("div",{className:"actions",children:[r.jsx("button",{className:"btn",onClick:()=>Zt("/"),children:p.back}),r.jsx("button",{className:"btn primary",onClick:()=>void xp({kind:N,cwd:m.cwd}),children:p.startAnother})]})]}),h!=="shell"&&!y&&!i.quit&&r.jsxs("footer",{className:"term-bottom",children:[x.panel&&r.jsx(W_,{panel:x.panel,nudge:i.nudge,onKey:l.press,onDone:l.reread}),_.onMac>0&&r.jsx(H_,{terminals:_.onMac,sessionId:n}),g==="compacting"&&r.jsx(B_,{count:i.queued.length}),T&&r.jsx(Bk,{tasks:_.tasks}),r.jsx(hb,{queued:i.queued,why:i.queueWhy,onSendNow:i.canSendNow?X=>void l.sendNow(X):void 0,onMove:(X,ve)=>void l.move(X,ve),onEdit:X=>void l.unsend(X,!0),onDrop:X=>void l.unsend(X,!1)}),i.suggestion&&r.jsxs("div",{className:"suggest",children:[r.jsxs("button",{className:"suggest-take",onClick:()=>l.giveBack(i.suggestion),children:[r.jsx("small",{children:p.suggestion}),r.jsx("span",{children:i.suggestion})]}),r.jsx("button",{className:"icon-btn","aria-label":p.dismissSuggestion,onClick:l.dismissSuggestion,children:r.jsx(Qi,{})})]}),(o||i.ctrl)&&r.jsx(My,{ctrlArmed:i.ctrl,onCtrl:()=>l.armCtrl(!i.ctrl),onKey:l.send,onPaste:()=>void l.paste()}),r.jsx(Ok,{draftKey:n,keys:{shown:o,onToggle:f},onSend:ee,onUpload:Ce,onError:l.sayToast,loadCommands:l.loadCommands,loadFiles:l.loadFiles,refill:i.refill,onStop:g==="working"?()=>l.send("\x1B"):void 0,footer:h===null?r.jsx(Dk,{}):T&&r.jsx(Lk,{usage:m==null?void 0:m.usage,account:m==null?void 0:m.claudeAccount,mode:i.mode,models:i.models,switching:i.switching,fixed:h==="codex",onCommand:l.runCommand,onMode:X=>void l.switchMode(X)})})]}),i.toast&&r.jsx("div",{className:"toast",children:i.toast}),W&&m&&r.jsx(by,{session:m,onClose:()=>oe(!1)}),le&&r.jsx(gv,{sessionId:n,onClose:()=>ne(!1),keys:y?void 0:{ctrlArmed:i.ctrl,onCtrl:()=>l.armCtrl(!i.ctrl),onKey:l.send,onPaste:()=>void l.paste()}}),C&&r.jsx(zc,{title:m==null?void 0:m.title,actions:ie,onClose:()=>P(!1)}),z&&r.jsx(Fk,{id:n,onClose:()=>L(!1)}),r.jsx(Kk,{move:_e,state:Y,onGiveBack:l.giveBack})]})})}const Jk=3e3;function e1(n,l,i,o){const[u,f]=H.useState(null),[m,h]=H.useState(!1),[y,g]=H.useState(null),[v,E]=H.useState(0),[_,x]=H.useState(!1);H.useEffect(()=>{let L=!1;return Yd(n).then(le=>{if(L)return;const ne=le.find(W=>W.sessionId===i&&ls(W)===l)??null;f(ne),ne!=null&&ne.takingOver&&x(!0)},()=>{}),()=>{L=!0}},[n,l,i,v]);const N=u?Dw(u):null,T=(N==null?void 0:N.do)==="takeOver"&&N.waiting,C=(N==null?void 0:N.do)==="takeOver";H.useEffect(()=>{if(!C)return;const L=setInterval(()=>E(le=>le+1),Jk);return()=>clearInterval(L)},[C]),H.useEffect(()=>{(N==null?void 0:N.do)==="open"&&_&&o(N.id)});const P=_&&!T&&(N==null?void 0:N.do)!=="open",z=async L=>{if(u!=null&&u.cwd){h(!0),g(null),x(!1);try{const le=await L(u.cwd);if(le)return o(le.id);E(ne=>ne+1)}catch(le){g(At(le,p.openFailed))}h(!1)}};return{info:u,busy:m,error:y,pick:N,waiting:T,missed:P,resume:()=>z(L=>Dc(n,{kind:l,cwd:L,resumeId:i})),takeOverNow:()=>z(L=>bp(n,{...u,cwd:L},"now")),takeOverWhenDone:()=>z(L=>bp(n,{...u,cwd:L},"whenIdle")),cancel:()=>z(()=>Lw(n,u).then(()=>null))}}function t1({agent:n,sid:l}){const{chat:i,failed:o}=V_(`${n}:${l}`,Rw(n,l)),{info:u,busy:f,error:m,pick:h,waiting:y,missed:g,resume:v,takeOverNow:E,takeOverWhenDone:_,cancel:x}=e1(at,n,l,z=>Zt(`/m/${Bt}/s/${z}`)),N=H.useRef(null),T=i?Ud(i.items,i.base):[],C=H.useRef(!0);H.useLayoutEffect(()=>{const z=N.current;if(!z)return;const L=()=>{C.current&&(z.scrollTop=z.scrollHeight)};L();const le=new ResizeObserver(L);le.observe(z);for(const ne of z.children)le.observe(ne);return()=>le.disconnect()},[T.length]);const P=()=>{const z=N.current;z&&(C.current=z.scrollHeight-z.scrollTop-z.clientHeight<40)};return r.jsxs("div",{className:"term-page",children:[r.jsx(Uc,{onBack:()=>Zt("/"),title:r.jsxs("div",{className:"term-title",children:[r.jsx("strong",{children:(u==null?void 0:u.title)??p.macSession}),u&&r.jsx("span",{children:`${Ba(u.cwd??"")} · ${Ua(u.lastActivity)}`})]}),right:r.jsx("span",{className:"chip",children:p.readOnly})}),r.jsx("div",{className:"term-wrap",children:r.jsxs("div",{className:"chat",ref:N,onScroll:P,children:[Ib(T).map(z=>z.k==="tools"?r.jsx(bv,{sessionId:l,tools:z.tools,going:z.going,onOpen:()=>{}},z.key):r.jsx(rf,{sessionId:l,t:z.t,onOpen:()=>{}},z.t.key)),!i&&!o&&r.jsx("div",{className:"chat-empty muted",children:p.reading}),o&&r.jsx("div",{className:"chat-note",children:p.cannotRead})]})}),r.jsxs("div",{className:"claude-view-foot",children:[m&&r.jsx("div",{className:"alert",children:m}),g&&!m&&r.jsx("div",{className:"alert",children:p.takeOverMissed}),(h==null?void 0:h.do)==="takeOver"&&r.jsx("strong",{children:[h.status==="busy"?p.onMacBusy:h.status==="waiting"?p.onMacWaiting:p.onMacIdle,h.terminals>1&&p.openInTerminals(h.terminals)].filter(Boolean).join(" · ")}),(h==null?void 0:h.do)==="takeOver"&&y?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"muted",children:p.takingOverWait}),r.jsx("button",{className:"btn primary",disabled:f,onClick:E,children:p.takeOverInterrupt}),r.jsx("button",{className:"btn",disabled:f,onClick:x,children:p.takeOverCancel})]}):(h==null?void 0:h.do)==="takeOver"?r.jsxs(r.Fragment,{children:[h.status==="idle"&&r.jsx("button",{className:"btn primary",disabled:f,onClick:E,children:p.takeOverNow}),h.status==="busy"&&r.jsxs(r.Fragment,{children:[r.jsx("button",{className:"btn primary",disabled:f,onClick:_,children:p.takeOverWhenDone}),r.jsx("button",{className:"btn",disabled:f,onClick:E,children:p.takeOverInterrupt})]}),h.status==="waiting"&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"muted",children:p.takeOverDropsQuestion}),r.jsx("button",{className:"btn primary",disabled:f,onClick:E,children:p.takeOverNow})]}),r.jsx("span",{className:"claude-view-note",children:p.takeOverNote(vc(n))})]}):(h==null?void 0:h.do)==="gone"?r.jsxs(r.Fragment,{children:[r.jsx("button",{className:"btn primary",disabled:!0,children:p.folderGoneNoResume}),r.jsx("span",{className:"claude-view-note",children:p.folderGoneSub(Ba((u==null?void 0:u.cwd)??""))})]}):r.jsx("button",{className:"btn primary",disabled:f||!(u!=null&&u.cwd)||!h||h.do==="none",onClick:()=>(h==null?void 0:h.do)==="open"?Zt(`/m/${Bt}/s/${h.id}`):void v(),children:(h==null?void 0:h.do)==="open"?p.openAlreadyOnPhone:(h==null?void 0:h.do)==="none"?n==="codex"?p.openElsewhereNoResume:p.inBackgroundNoResume:p.continueOnPhone})]})]})}const vv=n=>{var l;return((l=n.querySelector('script[type="module"][src]'))==null?void 0:l.getAttribute("src"))??null},gb=vv(document);let pd=!1,Sv=!1;const Cd=new Set;async function n1(){const n=await fetch("/",{cache:"no-store",credentials:"same-origin"});return n.ok?vv(new DOMParser().parseFromString(await n.text(),"text/html")):null}async function bd(n){if(!(pd||!gb)){pd=!0;try{const l=await n1();if(!l||l===gb)return;if(n)return location.reload();Sv=!0;for(const i of Cd)i()}catch{}finally{pd=!1}}}function a1(){document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&bd(!0)}),window.addEventListener("popstate",()=>void bd(!0)),jb.subscribe(()=>void bd(!1))}const s1=()=>H.useSyncExternalStore(n=>(Cd.add(n),()=>void Cd.delete(n)),()=>Sv);function l1(){return s1()?r.jsx("button",{className:"update-offer",onClick:()=>location.reload(),children:p.updateReady}):null}const xv="(min-width: 900px)",i1=n=>{const l=matchMedia(xv);return l.addEventListener("change",n),()=>l.removeEventListener("change",n)},o1=()=>H.useSyncExternalStore(i1,()=>matchMedia(xv).matches);function c1(){var m;const n=gE(),l=o1();if(n==="/login")return r.jsx(Fw,{});if(n==="/settings")return r.jsx(TT,{});if(n==="/mac")return r.jsx(IT,{});const i=(m=n.match(/^\/m\/[^/]+\/s\/([a-z0-9]+)$/))==null?void 0:m[1],o=n.match(/^\/(claude|codex)\/([0-9a-f-]{36})$/),u=o?{agent:o[1],sid:o[2]}:null,f=i?r.jsx(Wk,{id:i},i):u?r.jsx(t1,{...u},n):null;return l?r.jsxs("div",{className:"split",children:[r.jsx("div",{className:"split-list",children:r.jsx(wp,{current:i??(u==null?void 0:u.sid)})}),r.jsx("div",{className:"split-pane",children:f??r.jsx("p",{className:"split-empty muted",children:p.chooseSession})})]}):f??r.jsx(wp,{})}document.documentElement.lang=Xi==="zh"?"zh-CN":"en";vy();const Ev=location.pathname==="/setup",r1=H.lazy(()=>O0(()=>import("./Setup-C27bNf5I.js"),[]).then(n=>({default:n.Setup})));Ev||(fT(),a1());Y0.createRoot(document.getElementById("root")).render(r.jsx(H.StrictMode,{children:Ev?r.jsx(H.Suspense,{children:r.jsx(r1,{})}):r.jsxs(r.Fragment,{children:[r.jsx(c1,{}),r.jsx(l1,{})]})}));export{Sn as A,Op as C,Xb as I,Ax as c,At as e,r as j,H as r,p as t};
|
package/dist/web/index.html
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
<link rel="icon" href="/icon.svg" type="image/svg+xml" />
|
|
17
17
|
<link rel="apple-touch-icon" href="/icon-180.png" />
|
|
18
18
|
<title>WorkOffDesk</title>
|
|
19
|
-
<script type="module" crossorigin src="/assets/main-
|
|
19
|
+
<script type="module" crossorigin src="/assets/main-DQFM4yJU.js"></script>
|
|
20
20
|
<link rel="stylesheet" crossorigin href="/assets/main-C8GiLoJy.css">
|
|
21
21
|
</head>
|
|
22
22
|
<body>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "workoffdesk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Your Mac's Claude Code and Codex sessions, on your phone: chat, answer prompts, pick up where the terminal left off. Self-hosted, no account.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|