@pi-chamber/web 1.0.4 → 1.0.5-rc.2
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/README.md +1 -1
- package/bin/cli.js +21 -2
- package/bin/cli.test.js +164 -4
- package/bin/lib/DOCUMENTATION.md +3 -3
- package/bin/lib/cli-args.js +96 -13
- package/bin/lib/commands-connect-url-tailscale.test.js +136 -0
- package/bin/lib/commands-connect-url.js +146 -39
- package/bin/lib/commands-connect-url.test.js +126 -0
- package/bin/lib/commands-serve.js +45 -2
- package/bin/lib/commands-status.js +28 -5
- package/bin/lib/commands-status.test.js +107 -0
- package/bin/lib/commands-tunnel.js +36 -10
- package/dist/assets/{DiagramView-BpG1c3Hi.js → DiagramView-BWG8peHt.js} +1 -1
- package/dist/assets/DiffView-C_uRNQMT.js +18 -0
- package/dist/assets/{FileSaveConflictDialog-DP7k9a-i.js → FileSaveConflictDialog-DlH8IWDL.js} +2 -2
- package/dist/assets/FilesView-RnF9JBPu.js +6 -0
- package/dist/assets/{GitHubDetailScaffold-UxLAMAOl.js → GitHubDetailScaffold-BTRvUnwh.js} +2 -2
- package/dist/assets/{GitHubLinkPicker-Bh9RO1yK.js → GitHubLinkPicker-CGi8p2zF.js} +1 -1
- package/dist/assets/{GitHubListPrimitives-DQyhT5wG.js → GitHubListPrimitives-XckcmdeA.js} +1 -1
- package/dist/assets/{GitView-XBBheKRM.js → GitView-DyPJ8Oay.js} +4 -4
- package/dist/assets/{IssuesSurface-BA1kpvAJ.js → IssuesSurface-rQ78ziEu.js} +3 -3
- package/dist/assets/{JsonTreeView-BAaEPL4O.js → JsonTreeView-Cy5NKUzx.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-DzgDmUsL.js → MarkdownRendererImpl-C5AlnAbG.js} +1 -1
- package/dist/assets/{PatchDiff-BMEUsgXH.js → PatchDiff-D6048My1.js} +1 -1
- package/dist/assets/PierreDiffViewer-_000TWrM.js +135 -0
- package/dist/assets/PullRequestsSurface-eACi4Yxm.js +2 -0
- package/dist/assets/SessionSwitcherContent-CFMjBIfH.js +1 -0
- package/dist/assets/SessionSwitcherDropdown-CINW_ydZ.js +2 -0
- package/dist/assets/SessionUnreadDot-YZJi4IFP.js +1 -0
- package/dist/assets/SettingsView-DBiQXIji.js +6 -0
- package/dist/assets/{SettingsWindow-j0e99YI0.js → SettingsWindow-Wvd56oG1.js} +1 -1
- package/dist/assets/StickyHorizontalScrollbar-BMITjK4e.js +8 -0
- package/dist/assets/{ToolOutputDialog-VlS12Xyq.js → ToolOutputDialog-DeDXQNWw.js} +4 -4
- package/dist/assets/{ToolPartDiffPreview-DdSneZws.js → ToolPartDiffPreview-DuN8fldE.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-BqiXjvP6.js → VirtualizedFileDiff-BYVjUxk9.js} +4 -4
- package/dist/assets/{Virtualizer-Cp_cJWbI.js → Virtualizer-DP6HbEeC.js} +1 -1
- package/dist/assets/{collapsible-C7oyikVm.js → collapsible-BOcd0lzY.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-BJjC-tXV.js → computeVirtualFileMetrics-E4gJTgVF.js} +1 -1
- package/dist/assets/{contextFileOpenGuard-BBzqKGei.js → contextFileOpenGuard-CcGZtZsz.js} +1 -1
- package/dist/assets/{gitStatusPredicates-Dq-E5DaH.js → gitStatusPredicates-C2H7tf7t.js} +1 -1
- package/dist/assets/{githubLink-Cryd7GkG.js → githubLink-DTEEkgAl.js} +5 -5
- package/dist/assets/{index-BbhXFTId.js → index-BKc_DF05.js} +1 -1
- package/dist/assets/index-DWSrsQWl.js +11 -0
- package/dist/assets/index-DsQIBAWK.css +1 -0
- package/dist/assets/main-BNoO2jRw.js +136 -0
- package/dist/assets/main-DnCR4Jva.js +2 -0
- package/dist/assets/{markdownCore-B9AuEyYi.js → markdownCore-CP1hsIRw.js} +2 -2
- package/dist/assets/{miniChat-CgOaJfD8.js → miniChat-BBI_B4OS.js} +2 -2
- package/dist/assets/mobile-dRWyYBgl.js +2 -0
- package/dist/assets/{nativeFileSave-BzhtrDoD.js → nativeFileSave-CFuugNKV.js} +1 -1
- package/dist/assets/pi-session-focus-preference-Cw78V7mw.js +9 -0
- package/dist/assets/{renderDiffWithHighlighter-CVLsdtQ5.js → renderDiffWithHighlighter-kdzNWs8-.js} +1 -1
- package/dist/assets/renderElectronMiniChatApp-uVOQvccp.js +2 -0
- package/dist/assets/{renderFileWithHighlighter-DJ9mk2bZ.js → renderFileWithHighlighter-BdeYSXwS.js} +1 -1
- package/dist/assets/renderMobileApp-Cdg1IAhJ.js +11 -0
- package/dist/assets/runtimeEndpointReset-thviM404.js +62 -0
- package/dist/assets/{runtimeSurface-DBiUWYK2.js → runtimeSurface-Der4qUnI.js} +1 -1
- package/dist/assets/useAppFontEffects-Bd0btzjJ.js +212 -0
- package/dist/assets/{useFilesViewSearch-D2Au5Xgt.js → useFilesViewSearch-Yvk43YOy.js} +3 -3
- package/dist/assets/useGitHubRemoteSearch-BUjSEnXC.js +1 -0
- package/dist/assets/{useSwitcherItems-Dej8BzXI.js → useSwitcherItems-D2opwbRZ.js} +1 -1
- package/dist/assets/{vendor-aparajita-capacitor-secure-storage-BYohCVY0.js → vendor-aparajita-capacitor-secure-storage-BDrMx_CE.js} +1 -1
- package/dist/assets/{vendor-base-ui-BscvGUFt.js → vendor-base-ui-CKRUCG-f.js} +1 -1
- package/dist/assets/{vendor-boot-Dgb9NVFe.js → vendor-boot-EC6IyLt1.js} +13 -13
- package/dist/assets/{vendor-capacitor-app-BjdQVib9.js → vendor-capacitor-app-BaupizkW.js} +1 -1
- package/dist/assets/{vendor-capacitor-keyboard-eTtI5go3.js → vendor-capacitor-keyboard-9BVxykO7.js} +1 -1
- package/dist/assets/{vendor-capacitor-status-bar-9rNIGxlO.js → vendor-capacitor-status-bar-BsrUwiaA.js} +1 -1
- package/dist/assets/{vendor-codemirror-autocomplete-DxS3jwvE.js → vendor-codemirror-autocomplete-CGpAsPWp.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-angular-DdjXl9e2.js → vendor-codemirror-lang-angular-CDJoHJSY.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-cpp--aMr7NVt.js → vendor-codemirror-lang-cpp-BmHofQls.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-css-CZ_qxZY9.js → vendor-codemirror-lang-css-RM2HqXZ0.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-go-Ca-y2Alu.js → vendor-codemirror-lang-go-Crwca_X7.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-html-COZ0L5wT.js → vendor-codemirror-lang-html-CHSHUpwq.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-java-D3Rf3QNJ.js → vendor-codemirror-lang-java-lhQXgWu0.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-javascript-DwJ-IvCs.js → vendor-codemirror-lang-javascript-Dw4kFO4e.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-jinja-D_5lod6k.js → vendor-codemirror-lang-jinja-_pAC3UTN.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-json-BG8C7OpC.js → vendor-codemirror-lang-json-B-b1vAv-.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-less-CVEkoaTw.js → vendor-codemirror-lang-less-xIgOi1ze.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-liquid-U9vj0m8w.js → vendor-codemirror-lang-liquid-CP49m5dB.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-markdown-DqlYH9gY.js → vendor-codemirror-lang-markdown-BTht2ATe.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-php-BFEiEVA1.js → vendor-codemirror-lang-php-BguZDhaO.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-python-Cz1dQXQd.js → vendor-codemirror-lang-python-CH6_em9L.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-rust-C_CoD9mj.js → vendor-codemirror-lang-rust-EG_DtGyi.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sass-BuR0aKh5.js → vendor-codemirror-lang-sass-BknY5Qpo.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sql-DggNUjdM.js → vendor-codemirror-lang-sql-B0f-qCZo.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-vue-DFZHi2J3.js → vendor-codemirror-lang-vue-CyGn9snv.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-wast-zuTN3SHT.js → vendor-codemirror-lang-wast-CsFfSyyB.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-xml-CrcvhI-k.js → vendor-codemirror-lang-xml-Cdan_Jp1.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-yaml-DcVWsakb.js → vendor-codemirror-lang-yaml-COI5hck8.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-CCLITgCF.js → vendor-codemirror-language-data-CqU7kHmg.js} +2 -2
- package/dist/assets/{vendor-codemirror-search-H7NOEdbX.js → vendor-codemirror-search-DUfSCF9S.js} +1 -1
- package/dist/assets/{vendor-lezer-cpp-C8aD2KAr.js → vendor-lezer-cpp-DMZOJzBa.js} +1 -1
- package/dist/assets/{vendor-lezer-css-2lbTJF-Y.js → vendor-lezer-css-DUkkbMp7.js} +1 -1
- package/dist/assets/{vendor-lezer-go-Bw6LFTrZ.js → vendor-lezer-go-CHIhCNY6.js} +1 -1
- package/dist/assets/{vendor-lezer-html-D7ym2z7S.js → vendor-lezer-html-B3h0MOrG.js} +1 -1
- package/dist/assets/{vendor-lezer-java-CZhK7w21.js → vendor-lezer-java-tMazV_6X.js} +1 -1
- package/dist/assets/{vendor-lezer-javascript-rpKeTHZp.js → vendor-lezer-javascript-ctwLWf4v.js} +1 -1
- package/dist/assets/{vendor-lezer-json-C7jwsd2G.js → vendor-lezer-json-BP_UAzLL.js} +1 -1
- package/dist/assets/{vendor-lezer-lr-DR-ylqNN.js → vendor-lezer-lr-B8TQctNw.js} +1 -1
- package/dist/assets/{vendor-lezer-markdown-Bir0m5nB.js → vendor-lezer-markdown-aGLZf_3h.js} +1 -1
- package/dist/assets/{vendor-lezer-php-y0hIEfo1.js → vendor-lezer-php-D5zCNzlt.js} +1 -1
- package/dist/assets/{vendor-lezer-python-D64A9lNV.js → vendor-lezer-python-EJ4Im4y2.js} +1 -1
- package/dist/assets/{vendor-lezer-rust-E3ZA9T2L.js → vendor-lezer-rust-DO5c7OtA.js} +1 -1
- package/dist/assets/{vendor-lezer-sass-C5UFI9SP.js → vendor-lezer-sass-CMi6zfXI.js} +1 -1
- package/dist/assets/{vendor-lezer-xml-DOy7FzCR.js → vendor-lezer-xml-0MHMeZDp.js} +1 -1
- package/dist/assets/{vendor-lezer-yaml-kEjaSCvZ.js → vendor-lezer-yaml-BE2EFjpA.js} +1 -1
- package/dist/assets/{vendor-replit-codemirror-vim-BLfh0LPy.js → vendor-replit-codemirror-vim-AnOuN8yJ.js} +1 -1
- package/dist/assets/{web-components-C7CmoFxi.js → web-components-BeROQeen.js} +3 -3
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/dist/sw.js +1 -1
- package/package.json +1 -2
- package/server/index.js +72 -30
- package/server/lib/client-auth/DOCUMENTATION.md +15 -1
- package/server/lib/client-auth/pairing.js +2 -12
- package/server/lib/client-auth/remote-clients.js +2 -12
- package/server/lib/cloudflare-tunnel.js +0 -132
- package/server/lib/fs/DOCUMENTATION.md +8 -0
- package/server/lib/fs/atomic-write.js +111 -0
- package/server/lib/fs/atomic-write.test.js +133 -0
- package/server/lib/notifications/DOCUMENTATION.md +43 -32
- package/server/lib/notifications/pi-notification-watcher.js +8 -7
- package/server/lib/notifications/pi-notification-watcher.test.js +88 -2
- package/server/lib/pi/routes-extension-events.test.js +231 -0
- package/server/lib/pi/routes.js +137 -4
- package/server/lib/pi/routes.test.js +248 -2
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +17 -4
- package/server/lib/pi/session-daemon/daemon-process.js +2 -0
- package/server/lib/pi/session-daemon/engines/index.js +6 -0
- package/server/lib/pi/session-daemon/extension-bridge-draft.test.js +1 -1
- package/server/lib/pi/session-daemon/extension-bridge.js +24 -0
- package/server/lib/pi/session-daemon/extension-message-render.js +74 -0
- package/server/lib/pi/session-daemon/extension-message-render.test.js +164 -0
- package/server/lib/pi/session-daemon/extension-tool-render.js +13 -6
- package/server/lib/pi/session-daemon/pending-input.js +188 -0
- package/server/lib/pi/session-daemon/pending-input.test.js +202 -0
- package/server/lib/pi/session-daemon/session-daemon-engines.test.js +828 -0
- package/server/lib/pi/session-daemon/session-daemon-extensions.test.js +296 -6
- package/server/lib/pi/session-daemon/session-daemon-turn.e2e.test.js +9 -0
- package/server/lib/pi/session-daemon/session-daemon.js +219 -19
- package/server/lib/pi/session-daemon/session-daemon.test.js +30 -2
- package/server/lib/pi/session-daemon/session-engine-router.js +390 -0
- package/server/lib/pi/session-daemon/session-engine-router.test.js +515 -0
- package/server/lib/pi/session-daemon/session-engines.js +467 -0
- package/server/lib/pi/session-daemon/session-engines.test.js +383 -0
- package/server/lib/pi/snippets-store.js +8 -17
- package/server/lib/pi/ui-settings-store.js +6 -10
- package/server/lib/pi/ui-settings-store.test.js +37 -1
- package/server/lib/relay/DOCUMENTATION.md +6 -4
- package/server/lib/relay/identity-store.js +116 -0
- package/server/lib/relay/identity-store.test.js +169 -0
- package/server/lib/relay/identity.js +6 -4
- package/server/lib/relay/server-id.js +63 -0
- package/server/lib/relay/server-id.test.js +132 -0
- package/server/lib/relay/signing-key.js +14 -11
- package/server/lib/security/bind-host.js +6 -2
- package/server/lib/security/bind-host.test.js +17 -0
- package/server/lib/server/core-routes.js +27 -1
- package/server/lib/server/lan-addresses.js +18 -6
- package/server/lib/server/lan-addresses.test.js +28 -0
- package/server/lib/server/tunnel-auth.js +47 -7
- package/server/lib/server/tunnel-auth.rate-limit.test.js +164 -0
- package/server/lib/server/tunnel-service.DOCUMENTATION.md +3 -4
- package/server/lib/server/tunnel-service.js +23 -20
- package/server/lib/server/tunnel-service.test.js +19 -2
- package/server/lib/stt/config-store.js +5 -15
- package/server/lib/tailscale/DOCUMENTATION.md +285 -0
- package/server/lib/tailscale/nc-probe.js +220 -0
- package/server/lib/tailscale/routes.js +45 -0
- package/server/lib/tailscale/service.js +1012 -0
- package/server/lib/tailscale/tailscale.js +302 -0
- package/server/lib/tailscale/tailscale.test.js +2080 -0
- package/server/lib/tunnels/DOCUMENTATION.md +3 -4
- package/server/lib/tunnels/providers/cloudflare.js +1 -22
- package/server/lib/tunnels/types.js +0 -2
- package/server/lib/ui-auth/DOCUMENTATION.md +31 -0
- package/server/lib/ui-auth/ui-auth.js +80 -6
- package/server/lib/ui-auth/ui-auth.test.js +136 -0
- package/server/lib/ui-auth/ui-passkeys.js +2 -13
- package/server/lib/update-job-store.js +4 -6
- package/dist/assets/DiffView-BxwoRCYx.js +0 -18
- package/dist/assets/FilesView-D_2QcdUt.js +0 -6
- package/dist/assets/PierreDiffViewer-BW8MO-O6.js +0 -134
- package/dist/assets/PullRequestsSurface-B3ictm4I.js +0 -2
- package/dist/assets/SessionSwitcherContent-rLoyVqgs.js +0 -1
- package/dist/assets/SessionSwitcherDropdown-CfySKnUu.js +0 -2
- package/dist/assets/SessionUnreadDot-CmEF9sxM.js +0 -1
- package/dist/assets/SettingsView-BiwlwnTK.js +0 -6
- package/dist/assets/index-BnZVqcki.js +0 -11
- package/dist/assets/index-BnieExes.css +0 -1
- package/dist/assets/main-9O5IAtT_.js +0 -136
- package/dist/assets/main-DWGwALIw.js +0 -2
- package/dist/assets/mobile-BbJcYVym.js +0 -2
- package/dist/assets/pi-session-focus-preference-Bmk1iOvn.js +0 -10
- package/dist/assets/renderElectronMiniChatApp-R5o9NwFC.js +0 -2
- package/dist/assets/renderMobileApp-CQ9tWYIj.js +0 -11
- package/dist/assets/runtimeEndpointReset-CtK4C_5h.js +0 -62
- package/dist/assets/useAppFontEffects-DviRbaCJ.js +0 -212
- package/dist/assets/useGitHubRemoteSearch-D-K7aolk.js +0 -1
- package/dist/assets/vendor-capacitor-push-notifications-CBKq2Arn.js +0 -1
- package/server/lib/notifications/delivery-runtime.js +0 -314
- package/server/lib/notifications/delivery-runtime.test.js +0 -85
- package/server/lib/notifications/routes.js +0 -74
- package/server/lib/relay/service.js +0 -9
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{k as e,bV as Ne,bW as Ce,bX as ke,bY as Se,bZ as Re,aL as Ge}from"./vendor-boot-Dgb9NVFe.js";import{R as d}from"./vendor-react-DASdDPIk.js";import{o as L,v as He,A as Le}from"./index-BnZVqcki.js";import{B as N,I as G,ae as Pe,t as U,cw as Me,cx as Ee,cy as De,cz as Fe,cA as Te,q as ze,s as A,bo as $e,a as Ie,bz as Be,by as te,cI as Ae,a8 as le,ab as ce,ad as ue,ag as _e,cJ as Q,ai as Ke,cu as de,cv as me,cK as Oe,cL as qe,cM as We}from"./useAppFontEffects-DviRbaCJ.js";import{am as ne,_ as Ve,an as Ye,ao as Ue}from"./runtimeEndpointReset-CtK4C_5h.js";import{a as Qe,G as he,c as Xe,d as Ze,e as Je,f as es,b as ss,g as ts,h as ns,i as rs}from"./GitHubListPrimitives-DQyhT5wG.js";import{c as as}from"./vendor-zustand-CUi8eEds.js";import{K as fe,C as is,D as os}from"./GitHubDetailScaffold-UxLAMAOl.js";const pe=s=>s?s.kind==="rate-limited"?{reason:"rate-limited",retryAt:s.retryAt??null}:s.kind==="failed"?{reason:"failed",message:s.message}:{reason:s.reason,scopes:s.scopes??[]}:{reason:"failed",message:"GitHub request failed"},_=({command:s,label:t})=>{const i=d.useCallback(()=>{Pe(s).then(a=>{U[a.ok?"success":"error"](a.ok?"Command copied":"Failed to copy command")}).catch(()=>U.error("Failed to copy command"))},[s]);return e.jsxs("span",{className:"inline-flex max-w-full items-center gap-1.5",children:[e.jsx("code",{className:"min-w-0 truncate rounded bg-[var(--surface-muted)] px-1.5 py-0.5 font-mono typography-micro text-foreground",children:s}),e.jsx("button",{type:"button",onClick:i,className:"shrink-0 rounded p-1 text-muted-foreground hover:bg-interactive-hover hover:text-foreground",title:t??`Copy ${s}`,"aria-label":t??`Copy ${s}`,children:e.jsx(G,{name:"file-copy",className:"size-3.5"})})]})},k=({icon:s,title:t,description:i,children:a})=>e.jsx(Qe,{icon:s,title:t,description:i,action:a?e.jsx("div",{className:"mt-1 flex flex-wrap items-center justify-center gap-2",children:a}):void 0}),D=({info:s,onRetry:t,isRetrying:i})=>{const a=t?e.jsxs(N,{type:"button",variant:"outline",size:"sm",onClick:t,disabled:i,children:[e.jsx(G,{name:"refresh",className:"size-3.5"}),i?"Checking…":"Check again"]}):null;switch(s.reason){case"gh-missing":return e.jsxs(k,{icon:"github-fill",title:"GitHub CLI not found",description:"Install the GitHub CLI on the machine running PiChamber to browse pull requests and issues.",children:[e.jsx(_,{command:"gh --version",label:"Copy gh version check"}),a]});case"gh-outdated":return e.jsxs(k,{icon:"github-fill",title:"GitHub CLI too old",description:"Update gh on the machine running PiChamber, then check again.",children:[e.jsx(_,{command:"gh upgrade",label:"Copy gh upgrade command"}),a]});case"gh-unauthenticated":return e.jsxs(k,{icon:"github-fill",title:"Not signed in",description:"Run gh auth login on the machine running PiChamber, then check again.",children:[e.jsx(_,{command:"gh auth login",label:"Copy gh auth login command"}),a]});case"not-github":return e.jsx(k,{icon:"git-repository",title:"Not a GitHub repository",description:"This directory is a git repository, but none of its remotes point at GitHub."});case"no-repository":return e.jsx(k,{icon:"git-repository",title:"No repository here",description:"Open a directory inside a git repository to browse pull requests and issues."});case"no-access":return e.jsx(k,{icon:"lock",title:"No access",description:"The signed-in GitHub account cannot access this repository. Check the remote and the account in Settings.",children:a});case"scope-missing":{const r=(s.scopes??[]).filter(Boolean),n=r.length>0?`gh auth refresh -s ${r.join(" ")}`:"gh auth refresh -s repo";return e.jsxs(k,{icon:"shield-keyhole",title:"Missing token scope",description:`The GitHub token needs ${r.length>0?r.join(", "):"more scope"}. Run this on the machine running PiChamber, then check again.`,children:[e.jsx(_,{command:n,label:"Copy gh auth refresh command"}),a]})}case"rate-limited":{const r=s.retryAt?new Date(s.retryAt).toLocaleTimeString():null;return e.jsx(k,{icon:"hourglass",title:"Rate limited",description:r?`GitHub rate limit reached. Try again after ${r}.`:"GitHub rate limit reached. Try again shortly.",children:a})}default:return e.jsx(k,{icon:"error-warning",title:"Something went wrong",description:s.message||"GitHub request failed",children:a})}},ls=s=>s.map(t=>({host:t.host,owner:t.owner,repo:t.repo,relativePath:t.relativePath,kind:t.kind,submodule:t.submodule,disabledReason:t.disabledReason??null,ref:t.host&&t.owner&&t.repo?`${t.host}/${t.owner}/${t.repo}`:""})),cs=s=>s.kind==="enclosing"?"enclosing":s.kind==="nested"?"nested":s.submodule?"submodule":null,re=({entries:s,value:t,onChange:i,ariaLabel:a})=>{const r=s.find(n=>n.ref===t)??null;return e.jsxs(Me,{value:t??"",onValueChange:i,children:[e.jsx(Ee,{size:"sm",className:"min-w-0 max-w-56","aria-label":a??"Select repository",children:e.jsx(De,{placeholder:"Select repository",children:n=>{const o=s.find(l=>l.ref===n)??r;return!o||!o.ref?"Select repository":e.jsxs("span",{className:"block truncate",children:[o.relativePath," · ",o.owner,"/",o.repo]})}})}),e.jsx(Fe,{children:s.map(n=>{const o=!n.ref||!!n.disabledReason,l=cs(n);return e.jsx(Te,{value:n.ref,disabled:o,children:e.jsxs("span",{className:L("flex min-w-0 items-center gap-1.5",o&&"opacity-60"),children:[e.jsx(G,{name:"git-repository",className:"size-3.5 shrink-0"}),e.jsxs("span",{className:"min-w-0 truncate",children:[n.relativePath," · ",n.owner&&n.repo?`${n.owner}/${n.repo}`:"not on GitHub"]}),l?e.jsx("span",{className:"shrink-0 rounded bg-[var(--surface-muted)] px-1 typography-micro text-muted-foreground",children:l}):null,n.disabledReason?e.jsxs("span",{className:"shrink-0 typography-micro text-muted-foreground",children:["· ",n.disabledReason]}):null]})},`${n.ref||n.relativePath}:${n.relativePath}`)})})]})},Hs=({directory:s,isRefreshing:t,onRefresh:i,children:a})=>{const n=ze().github??null,o=A(p=>p.entriesByDirectory[He(s.trim())]??null),l=A(p=>p.ensureScope),c=A(p=>p.refreshScope),u=A(p=>p.setSelectedRepo),m=$e(s||null),h=ne(p=>p.status),g=ne(p=>p.refresh);d.useEffect(()=>{!s||!n||(l(s,n),g(n))},[s,n,l,g]);const C=d.useCallback(()=>{if(i){i();return}n&&(c(s,n,{force:!0}),g(n,{force:!0}))},[i,n,c,g,s]);if(!n)return e.jsx("div",{className:"flex h-full flex-col",children:e.jsx(D,{info:{reason:"failed",message:"GitHub is not available in this runtime."}})});if(o?.isLoading&&!o.scope&&!o.error)return e.jsx("div",{className:"flex h-full min-h-0 flex-col",children:e.jsx(he,{label:"Finding GitHub repositories"})});if(o?.error&&!o.scope)return e.jsx("div",{className:"flex h-full flex-col",children:e.jsx(D,{info:pe(o.error),onRetry:C,isRetrying:t||o.isLoading})});const j=o?.scope??null;if(j&&!h?.installed)return e.jsx("div",{className:"flex h-full flex-col",children:e.jsx(D,{info:{reason:"gh-missing"},onRetry:C,isRetrying:t})});const x=j?ls(j.repositories):[],f=x.filter(p=>!!(p.ref&&!p.disabledReason));if(j&&f.length===0){const p=j.topLevel?"not-github":"no-repository";return e.jsx("div",{className:"flex h-full flex-col",children:e.jsx(D,{info:{reason:p}})})}if(!m)return e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsx("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-3 py-2",children:e.jsx(re,{entries:x,value:m,onChange:p=>u(s,p)})}),e.jsxs("div",{className:"flex flex-col items-start gap-2 p-4",children:[e.jsx("div",{className:"typography-ui-header text-foreground",children:"Select a repository"}),e.jsx("p",{className:"typography-ui text-muted-foreground",children:"Several repositories are in scope. Pick one to browse."})]})]});const b=f.length>1;return e.jsxs("div",{className:"flex h-full flex-col",children:[b?e.jsx("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-3 py-2",children:e.jsx(re,{entries:x,value:m,onChange:p=>u(s,p)})}):null,e.jsx("div",{className:"min-h-0 flex-1",children:a({repo:m,directory:s})})]})},Ls=({copy:s,busy:t,destructive:i,disabled:a,disabledReason:r,label:n,variant:o="default",icon:l,onConfirm:c})=>{const[u,m]=d.useState(!1);return e.jsxs(Ne,{open:u,onOpenChange:h=>{t||m(h)},children:[e.jsxs(Ce,{render:e.jsx(N,{type:"button",variant:o,size:"xs",className:"shrink-0",disabled:a||t,title:r??n,"aria-label":n}),children:[l,n]}),e.jsx(ke,{children:e.jsx(Se,{side:"bottom",align:"start",sideOffset:6,collisionPadding:8,className:"z-50",children:e.jsxs(Re,{"aria-label":s.title,className:"w-64 rounded-lg border border-border/60 bg-[var(--surface-elevated)] p-3 shadow-lg",children:[e.jsx("p",{className:"typography-ui-label text-foreground",children:s.title}),e.jsx("p",{className:"mt-1 typography-micro text-muted-foreground",children:s.detail}),e.jsxs("div",{className:"mt-3 flex justify-end gap-1.5",children:[e.jsx(N,{type:"button",variant:"outline",size:"xs",disabled:t,onClick:()=>m(!1),children:"Cancel"}),e.jsx(N,{type:"button",variant:i?"destructive":"default",size:"xs",disabled:t,onClick:()=>{Promise.resolve(c()).finally(()=>m(!1))},"aria-label":s.confirm,children:t?s.progress:s.confirm})]})]})})})]})},Ps=async(s,t)=>{if(!t?.listGitWorktrees)return;const i=Ie.getState().projects,a=Be(i,te.getState()),n=Ae(i,a,s)?.path??s;try{await te.getState().refreshProject(n,t,{force:!0})}catch{}},y=(s,t)=>`${s}#${t}`,xe=Object.freeze([]),us=Object.freeze({comments:xe,summary:"",verdict:"comment",commentDraft:""});let ae=0;const ds=()=>(ae+=1,`pending-review-comment-${ae}`),R=(s,t)=>s.entries[t]??us,S=(s,t,i)=>({...s.entries,[t]:{...R(s,t),...i}}),P=as()((s,t)=>({entries:{},addComment:(i,a,r)=>{const n=r.id??ds(),o=y(i,a);return s(l=>({entries:S(l,o,{comments:[...R(l,o).comments,{...r,id:n}]})})),n},removeComment:(i,a,r)=>{const n=y(i,a);s(o=>{const l=R(o,n).comments,c=l.filter(u=>u.id!==r);if(c.length===l.length)return o;if(c.length===0&&R(o,n).summary===""&&R(o,n).commentDraft===""){const u={...o.entries};return delete u[n],{entries:u}}return{entries:S(o,n,{comments:c})}})},removeComments:(i,a,r)=>{if(r.length===0)return;const n=y(i,a),o=new Set(r);s(l=>{const c=R(l,n).comments,u=c.filter(m=>!o.has(m.id));return u.length===c.length?l:{entries:S(l,n,{comments:u})}})},clearComments:(i,a)=>{const r=y(i,a);s(n=>(n.entries[r]?.comments.length??0)===0?n:{entries:S(n,r,{comments:[]})})},setSummary:(i,a,r)=>{const n=y(i,a);t().entries[n]?.summary!==r&&s(o=>({entries:S(o,n,{summary:r})}))},clearSummary:(i,a,r)=>{const n=y(i,a);s(o=>R(o,n).summary!==r?o:{entries:S(o,n,{summary:""})})},setVerdict:(i,a,r)=>{const n=y(i,a);t().entries[n]?.verdict!==r&&s(o=>({entries:S(o,n,{verdict:r})}))},setCommentDraft:(i,a,r)=>{const n=y(i,a);t().entries[n]?.commentDraft!==r&&s(o=>({entries:S(o,n,{commentDraft:r})}))},clearCommentDraft:(i,a)=>{const r=y(i,a);s(n=>R(n,r).commentDraft===""?n:{entries:S(n,r,{commentDraft:""})})},resetForRuntimeSwitch:()=>s({entries:{}})}));typeof window<"u"&&Le(()=>{P.getState().resetForRuntimeSwitch()});const Ms=(s,t)=>P(i=>i.entries[y(s,t)]?.comments??xe),Es=(s,t)=>P(i=>i.entries[y(s,t)]?.summary??""),Ds=(s,t)=>P(i=>i.entries[y(s,t)]?.verdict??"comment"),Fs=(s,t)=>P(i=>i.entries[y(s,t)]?.comments.length??0),ms=300,Ts=(s,t)=>{const i=y(s,t),a=P(h=>h.entries[i]?.commentDraft??""),[r,n]=d.useState(a),o=d.useRef(r);o.current=r;const l=d.useRef(a);l.current=a;const c=d.useRef(a);d.useEffect(()=>{o.current===c.current&&a!==c.current&&(c.current=a,n(a))},[a]);const u=d.useCallback(()=>{const h=o.current;h!==c.current&&(c.current=h,P.getState().setCommentDraft(s,t,h))},[s,t]),m=d.useCallback(h=>{n(h)},[]);return d.useEffect(()=>{if(r===c.current)return;const h=setTimeout(u,ms);return()=>clearTimeout(h)},[r,u]),d.useEffect(()=>()=>u(),[u]),{draft:r,onDraftChange:m,flushDraft:u}},hs=240,zs=({draft:s,onDraftChange:t,placeholder:i="Leave a comment",ariaLabel:a="Leave a comment",busy:r,error:n,disabledReason:o,followUp:l,onSubmitComment:c,onDraftBlur:u})=>{const m=d.useRef(null),[h,g]=d.useState(!1),C=d.useRef(null);d.useLayoutEffect(()=>{const f=m.current;if(!f)return;f.style.height="0px",f.style.height=`${Math.min(f.scrollHeight,hs)}px`;let b=C.current;if(!b){const v=getComputedStyle(f);b={lineHeight:Number.parseFloat(v.lineHeight)||20,padding:Number.parseFloat(v.paddingTop)+Number.parseFloat(v.paddingBottom)||0},C.current=b}const p=f.scrollHeight-b.padding>b.lineHeight*1.5;g(v=>v===p?v:p)},[s]);const j=s.trim().length===0,x=r!==null;return e.jsxs("form",{className:"flex flex-col gap-2 border-t border-border/60 pt-5","aria-label":a,onSubmit:f=>{f.preventDefault(),c()},children:[e.jsxs("div",{className:`flex ${h?"items-end":"items-center"} gap-1.5 rounded-md border border-border bg-[var(--surface-elevated)] py-1 pr-1 focus-within:border-[var(--interactive-focus-ring)]`,children:[e.jsx(Ve,{simple:!0,ref:m,rows:1,value:s,placeholder:`${i} (⌘↩)`,"aria-label":a,disabled:x,onChange:f=>t(f.target.value),onBlur:()=>u?.(),outerClassName:"min-w-0 flex-1",className:"min-h-0 w-full resize-none overflow-y-auto border-0 bg-transparent px-2.5 py-1 typography-ui text-foreground shadow-none outline-none placeholder:text-muted-foreground focus-visible:ring-0",onKeyDown:f=>{f.nativeEvent.isComposing||f.key==="Enter"&&(f.metaKey||f.ctrlKey)&&!f.shiftKey&&!f.altKey&&!f.repeat&&(f.preventDefault(),f.stopPropagation(),!j&&!x&&c())}}),!j&&l&&l.allowed?e.jsx(N,{type:"button",variant:"ghost",size:"xs",disabled:x,title:l.reason??l.label,onClick:l.onRun,children:r===l.id?l.busyLabel:l.label}):null,e.jsx(N,{type:"button",variant:"default",size:"xs",disabled:j||x,title:o??"Post comment",onClick:c,children:r==="comment"?"Posting…":"Comment"})]}),n?e.jsx("p",{className:"typography-micro text-[var(--status-error)]",role:"alert",children:n}):null]})},fs=async s=>{const t=s.notify??((r,n)=>U[r](n)),i=await s.postComment(s.trimmed);if(!i.ok){const r=i.error?.kind==="failed"&&i.error.message?i.error.message:"Failed to post comment";throw t("error",r),new Error(r)}if(s.afterPost(),s.action==="comment"){t("success","Comment posted");return}const a=await s.runFollowUp(s.action);if(!a.ok){const r=s.verbs[s.action],n=a.error?.kind==="failed"&&a.error.message?a.error.message:`Failed to ${r}`;throw t("error",n),new Error(n)}t("success",s.doneLabels[s.action])},$s=s=>{const[t,i]=d.useState(null),[a,r]=d.useState(null),n=d.useRef(s);n.current=s;const o=d.useCallback(async(l,c)=>{const u=c.trim(),m=n.current;if(!(u.length===0||t!==null)){i(l),r(null);try{await fs({trimmed:u,action:l,postComment:m.postComment,runFollowUp:m.runFollowUp,verbs:m.verbs,doneLabels:m.doneLabels,afterPost:m.afterPost})}catch(h){r(h instanceof Error?h.message:"Failed to post comment")}finally{i(null)}}},[t]);return{busy:t,error:a,submit:o}},ie=({label:s,value:t,options:i,currentLabel:a,onChange:r})=>e.jsxs(Oe,{children:[e.jsxs(qe,{children:[e.jsx("span",{className:"flex-1",children:s}),e.jsx("span",{className:"min-w-0 max-w-32 truncate typography-micro text-muted-foreground",children:a})]}),e.jsx(We,{className:"min-w-48",children:e.jsxs(de,{value:t,onValueChange:n=>{typeof n=="string"&&n!==t&&r(n)},children:[e.jsx(Q,{children:s}),i.map(n=>e.jsx(me,{value:n.id,closeOnClick:!1,children:n.label},n.id))]})})]}),ps=({stateValue:s,stateOptions:t,onStateChange:i,involvementValue:a,involvementOptions:r,onInvolvementChange:n,labelsValue:o,onLabelsChange:l})=>{const c=t.find(g=>g.id===s)?.label??s,u=r.find(g=>g.id===a)?.label??a,m=(o??"").trim().length>0,h=(s!==t[0]?.id?1:0)+(a!==r[0]?.id?1:0)+(m?1:0);return e.jsxs(le,{modal:!1,children:[e.jsx(ce,{asChild:!0,children:e.jsxs(N,{type:"button",variant:"ghost",size:"sm","aria-label":"Filters",title:"Filters",className:"h-8 shrink-0 gap-1.5 px-2 normal-case",children:[e.jsx(G,{name:"equalizer",className:"size-4","aria-hidden":"true"}),e.jsx("span",{children:"Filters"}),h>0?e.jsx("span",{className:"rounded-full bg-[var(--surface-muted)] px-1.5 typography-micro tabular-nums text-muted-foreground",children:h}):null]})}),e.jsxs(ue,{align:"end",className:"w-64",children:[e.jsx(ie,{label:"State",value:s,options:t,currentLabel:c,onChange:i}),e.jsx(ie,{label:"Involvement",value:a,options:r,currentLabel:u,onChange:n}),l?e.jsxs(e.Fragment,{children:[e.jsx(_e,{}),e.jsx(Q,{children:"Labels"}),e.jsxs("div",{className:"px-2 pb-2",children:[e.jsx(Ke,{value:o??"",onChange:g=>l(g.target.value),placeholder:"bug, enhancement","aria-label":"Filter by labels",className:"h-7"}),e.jsx("p",{className:"mt-1 typography-micro text-muted-foreground",children:"Comma-separated. Or type label:bug in search."})]})]}):null]})]})},xs=({value:s,options:t,onChange:i,ariaLabel:a})=>e.jsxs(le,{modal:!1,children:[e.jsx(ce,{asChild:!0,children:e.jsx(N,{type:"button",variant:"ghost",size:"sm","aria-label":a,title:a,className:"h-8 w-8 shrink-0 p-0",children:e.jsx(G,{name:"expand-up-down",className:"size-4","aria-hidden":"true"})})}),e.jsx(ue,{align:"end",className:"w-52",children:e.jsxs(de,{value:s,onValueChange:r=>{typeof r=="string"&&r!==s&&i(r)},children:[e.jsx(Q,{children:"Sort"}),t.map(r=>e.jsx(me,{value:r.id,children:r.label},r.id))]})})]}),oe=({isRefreshing:s,onRefresh:t,label:i,presentation:a="toolbar"})=>a==="desktop"?e.jsx(N,{type:"button",variant:"ghost",size:"sm",onClick:t,disabled:s,title:i??"Refresh","aria-label":i??"Refresh GitHub data",className:"h-8 w-8 shrink-0 p-0",children:e.jsx(G,{name:"refresh",className:L("size-4",s&&"animate-spin"),"aria-hidden":"true"})}):a==="drawer"?e.jsx(N,{type:"button",variant:"ghost",size:"icon",onClick:t,disabled:s,title:i??"Refresh","aria-label":i??"Refresh GitHub data",className:"shrink-0",children:e.jsx(G,{name:"refresh",className:L("size-4",s&&"animate-spin"),"aria-hidden":"true"})}):e.jsx(N,{type:"button",variant:"ghost",size:"sm",onClick:t,disabled:s,title:i??"Refresh","aria-label":i??"Refresh GitHub data",className:"h-8 w-8 shrink-0 p-0",children:e.jsx(G,{name:"refresh",className:L("size-4",s&&"animate-spin"),"aria-hidden":"true"})}),Is=({items:s,renderRow:t,hasMore:i,isLoadingMore:a,isLoading:r,isRefreshing:n,stale:o,error:l,searchValue:c,onSearchChange:u,searchPlaceholder:m,searchAriaLabel:h,toolbarControls:g,primaryAction:C,headerActionsSlot:j=null,headerActionsPresentation:x="drawer",isDefaultFilters:f,stateLabel:b,kindSingular:p,kindPlural:v,noItemsTitle:F,noItemsBody:M,noItemsIcon:K,noItemsAction:X,listAriaLabel:E,skeletonLabel:ge,updatedAtOf:O,countComplete:q=!0,incompleteNotice:T=null,remote:w=null,numberJump:z=null,numberJumpKind:be,onClearFilters:je,onLoadMore:ye,onRetry:$,onOpen:ve})=>{const Z=d.useMemo(()=>{if(s.length===0)return null;const H=s.length===1&&q?`1 ${p}`:`${s.length}${q?"":"+"} ${v}`;let B=0;for(const se of s){const Y=O(se)?Date.parse(O(se)):NaN;Number.isFinite(Y)&&Y>B&&(B=Y)}const ee=B>0?fe(new Date(B).toISOString()):"";return`${H} · ${b.toLowerCase()}${ee?` · updated ${ee}`:""}`},[s,b,p,v,q,O]),I=!!l&&s.length===0,W=!I&&r&&s.length===0,V=j??null,we=x??"drawer",J=n||r;return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[o?e.jsx(Xe,{onRetry:$}):null,e.jsxs("div",{className:"flex shrink-0 flex-wrap items-center gap-1.5 border-b border-border px-3 py-2",children:[e.jsx(Ze,{value:c,onChange:u,placeholder:m,ariaLabel:h}),g,V?null:e.jsxs(e.Fragment,{children:[C,e.jsx(oe,{isRefreshing:J,onRefresh:$,presentation:"toolbar"})]})]}),V?Ge.createPortal(e.jsxs(e.Fragment,{children:[C,e.jsx(oe,{isRefreshing:J,onRefresh:$,presentation:we})]}),V):null,I?e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:e.jsx(D,{info:pe(l),onRetry:$,isRetrying:r})}):W?e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(he,{label:ge})}):e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto",role:"list","aria-label":E,children:[s.length===0&&z==null?e.jsx(Je,{kind:f?"no-items":"no-match",noItemsTitle:F,noItemsBody:f?M:void 0,noItemsIcon:K,noItemsAction:f?X:void 0,onClearFilters:f?void 0:je}):e.jsxs(e.Fragment,{children:[s.length>0?e.jsx("ul",{className:"flex flex-col p-1",children:s.map(H=>e.jsx(d.Fragment,{children:t(H)},H.number))}):null,z!=null?e.jsx(es,{number:z,kindLabel:be,onOpen:()=>ve(z)}):null]}),e.jsx(ss,{hasMore:i,isLoading:a||r,onLoadMore:ye}),w&&(w.isSearching||w.error||w.items.length>0)?e.jsx(ts,{title:"More results from GitHub",isSearching:w.isSearching,error:w.error,hasResults:w.items.length>0,hasMore:w.hasMore,isLoadingMore:w.isLoadingMore,onRetry:w.onRetry,onLoadMore:w.onLoadMore,children:e.jsx("ul",{className:"flex flex-col",children:w.items.map(H=>e.jsx(d.Fragment,{children:t(H)},H.number))})}):null]}),!I&&!W&&T?e.jsx(ns,{matchSummary:T.summary,searching:T.searching,onSearchAll:T.onSearchAll}):null,!I&&!W&&Z?e.jsx(rs,{summary:Z}):null]})},Bs=({stateValue:s,stateOptions:t,onStateChange:i,involvementValue:a,involvementOptions:r,onInvolvementChange:n,labelsValue:o,onLabelsChange:l,sortValue:c,sortOptions:u,onSortChange:m,sortAriaLabel:h})=>e.jsxs(e.Fragment,{children:[e.jsx(ps,{stateValue:s,stateOptions:t,onStateChange:i,involvementValue:a,involvementOptions:r,onInvolvementChange:n,labelsValue:o,onLabelsChange:l}),e.jsx(xs,{value:c,options:u,onChange:m,ariaLabel:h})]}),gs="shrink-0 font-mono typography-micro tabular-nums text-muted-foreground",bs=({glyph:s,below:t})=>e.jsxs("span",{className:"flex w-4 shrink-0 flex-col items-center gap-0.5",children:[e.jsx("span",{className:"inline-flex",children:s}),t?e.jsx("span",{className:"inline-flex",children:t}):null]}),As=({login:s,avatarUrl:t})=>e.jsxs("span",{className:"inline-flex min-w-0 shrink-0 items-center gap-1",title:s??"ghost",children:[e.jsx(is,{login:s,avatarUrl:t,size:"xs"}),e.jsx("span",{className:"truncate",children:s??"ghost"})]}),_s=({head:s,base:t})=>e.jsxs("span",{className:"flex min-w-0 items-center gap-1 font-mono",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate",title:s,children:s}),e.jsx("span",{className:"shrink-0",children:"→"}),e.jsx("span",{className:"max-w-[45%] shrink-0 truncate",title:t,children:t})]}),js=[{show:""},{show:"hidden @xl/github-row:inline-flex"},{show:"hidden @3xl/github-row:inline-flex"}],ys=["hidden @xl/github-row:hidden","hidden @xl/github-row:inline-flex @3xl/github-row:hidden",""],Ks=({labels:s})=>s.length===0?null:e.jsx("span",{className:"flex min-w-0 shrink-0 items-center gap-1",children:js.map((t,i)=>{const a=s[i];if(!a)return null;const r=s.length-i-1;return e.jsxs("span",{className:L("min-w-0",t.show),children:[e.jsx(os,{name:a.name,color:a.color}),r>0?e.jsxs("span",{className:L("ml-0.5 shrink-0",ys[i]),"aria-label":`${r} more labels`,children:["+",r]}):null]},a.name)})}),Os=({glyph:s,glyphBelow:t,number:i,title:a,signals:r,status:n,meta:o,updatedAt:l,selected:c,onOpen:u,ariaLabel:m})=>e.jsxs("button",{type:"button",onClick:u,"aria-label":m,"aria-current":c?"true":void 0,className:L("@container/github-row group/github-row flex w-full items-center gap-2 rounded-md px-2 py-1 text-left",c?"bg-interactive-selection text-interactive-selection-foreground":"hover:bg-interactive-hover"),children:[e.jsx(bs,{glyph:s,below:t}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[e.jsx("span",{className:gs,children:i}),e.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",title:a,children:a}),r?e.jsx("span",{className:"flex shrink-0 items-center gap-1",children:r}):null,n?e.jsx("span",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:n}):null]}),e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 overflow-hidden typography-micro text-muted-foreground",children:[o,l?e.jsx("span",{className:"ml-auto shrink-0 whitespace-nowrap tabular-nums",children:fe(l)}):null]})]})]}),qs=s=>{const{repo:t,query:i,queryKey:a,autoRemote:r,indexNumbers:n,visibleItems:o,searchText:l,useRemoteEntry:c,runSearch:u,runLoadMore:m}=s,[h,g]=d.useState(!1),[C,j]=d.useState(null);d.useEffect(()=>j(null),[t]);const x=c(t,i),f=r||C===a||x!=null,b=d.useCallback(()=>{g(!0),u(i).catch(()=>null).finally(()=>g(!1))},[i,u]);d.useEffect(()=>{if(!r||x?.data||x?.isLoading||x?.error||h)return;const E=setTimeout(b,400);return()=>clearTimeout(E)},[r,a,x?.data,x?.isLoading,x?.error,h,b]);const p=d.useCallback(()=>{j(a),b()},[a,b]),v=d.useCallback(()=>{g(!0),m(i).catch(()=>null).finally(()=>g(!1))},[i,m]),F=d.useMemo(()=>Ye(x?.data?.items??[],n),[x?.data?.items,n]),M=Ue(l),K=M!=null&&!o.some(E=>E.number===M)?M:null;return{remoteView:d.useMemo(()=>f?{items:F,isSearching:h||(x?.isLoading??!1),isLoadingMore:h,hasMore:x?.data?.nextCursor!=null,error:x?.error??null,onSearchAll:p,onLoadMore:v,onRetry:b}:null,[f,F,h,x?.isLoading,x?.data?.nextCursor,x?.error,p,v,b]),numberJump:K,remotePending:h,handleSearchAll:p}};export{zs as G,Ms as a,Ts as b,$s as c,Es as d,Ds as e,Fs as f,D as g,Ls as h,Os as i,As as j,_s as k,Is as l,Bs as m,Hs as n,qs as o,Ks as p,Ps as r,pe as t,P as u};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as i}from"./vendor-boot-Dgb9NVFe.js";import"./vendor-react-DASdDPIk.js";import"./vendor-clsx-B-dksMZM.js";const s=i("PushNotifications",{});export{s as PushNotifications};
|
|
@@ -1,314 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import { chmod, mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
3
|
-
import { dirname, join } from 'node:path';
|
|
4
|
-
|
|
5
|
-
import { withCrossProcessLock } from '../server/cross-process-lock.js';
|
|
6
|
-
import { signRelayMessage } from '../relay/signing-key.js';
|
|
7
|
-
|
|
8
|
-
const STORE_VERSION = 1;
|
|
9
|
-
const MAX_ENTRIES_PER_CLIENT = 10;
|
|
10
|
-
const MAX_STORED_ENTRIES = 1_000;
|
|
11
|
-
const VISIBILITY_TTL_MS = 30_000;
|
|
12
|
-
const DEFAULT_RELAY_URL = 'https://api.pichamber.dev/v1/push/send';
|
|
13
|
-
|
|
14
|
-
const emptyStore = () => ({
|
|
15
|
-
version: STORE_VERSION,
|
|
16
|
-
subscriptionsByClient: {},
|
|
17
|
-
nativeTokensByClient: {},
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
const isRecord = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
21
|
-
|
|
22
|
-
const boundEntriesByClient = (entriesByClient) => {
|
|
23
|
-
const newest = Object.entries(entriesByClient)
|
|
24
|
-
.flatMap(([clientId, entries]) => (Array.isArray(entries)
|
|
25
|
-
? entries.map((entry) => ({ clientId, entry }))
|
|
26
|
-
: []))
|
|
27
|
-
.filter(({ entry }) => isRecord(entry))
|
|
28
|
-
.sort((left, right) => (right.entry.updatedAt ?? 0) - (left.entry.updatedAt ?? 0))
|
|
29
|
-
.slice(0, MAX_STORED_ENTRIES);
|
|
30
|
-
const bounded = {};
|
|
31
|
-
for (const { clientId, entry } of newest) {
|
|
32
|
-
(bounded[clientId] ??= []).push(entry);
|
|
33
|
-
}
|
|
34
|
-
return bounded;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export const createNotificationDeliveryRuntime = ({
|
|
38
|
-
dataDir,
|
|
39
|
-
webPush,
|
|
40
|
-
crypto,
|
|
41
|
-
fetch: fetchImpl = globalThis.fetch,
|
|
42
|
-
storeFile = join(dataDir, 'notifications.json'),
|
|
43
|
-
relayUrl = process.env.PICHAMBER_PUSH_RELAY_URL || DEFAULT_RELAY_URL,
|
|
44
|
-
onDesktopNotification,
|
|
45
|
-
}) => {
|
|
46
|
-
const visibilityByClient = new Map();
|
|
47
|
-
let initializedWebPush = false;
|
|
48
|
-
|
|
49
|
-
const readStore = async () => {
|
|
50
|
-
try {
|
|
51
|
-
const parsed = JSON.parse(await readFile(storeFile, 'utf8'));
|
|
52
|
-
if (!isRecord(parsed) || parsed.version !== STORE_VERSION) return emptyStore();
|
|
53
|
-
return {
|
|
54
|
-
version: STORE_VERSION,
|
|
55
|
-
subscriptionsByClient: isRecord(parsed.subscriptionsByClient) ? parsed.subscriptionsByClient : {},
|
|
56
|
-
nativeTokensByClient: isRecord(parsed.nativeTokensByClient) ? parsed.nativeTokensByClient : {},
|
|
57
|
-
...(isRecord(parsed.vapidKeys) ? { vapidKeys: parsed.vapidKeys } : {}),
|
|
58
|
-
...(isRecord(parsed.relaySigningKey) ? { relaySigningKey: parsed.relaySigningKey } : {}),
|
|
59
|
-
};
|
|
60
|
-
} catch (error) {
|
|
61
|
-
if (error?.code === 'ENOENT') return emptyStore();
|
|
62
|
-
throw error;
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const writeStore = async (store) => {
|
|
67
|
-
await mkdir(dirname(storeFile), { recursive: true, mode: 0o700 });
|
|
68
|
-
const temporary = `${storeFile}.tmp-${process.pid}-${randomUUID()}`;
|
|
69
|
-
await writeFile(temporary, `${JSON.stringify(store, null, 2)}\n`, { mode: 0o600 });
|
|
70
|
-
await rename(temporary, storeFile);
|
|
71
|
-
if (process.platform !== 'win32') await chmod(storeFile, 0o600);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const mutateStore = (mutate) => withCrossProcessLock(`${storeFile}.lock`, async () => {
|
|
75
|
-
const next = await mutate(await readStore());
|
|
76
|
-
await writeStore(next);
|
|
77
|
-
return next;
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
const getOrCreateVapidKeys = async () => {
|
|
81
|
-
const current = await readStore();
|
|
82
|
-
if (typeof current.vapidKeys?.publicKey === 'string' && typeof current.vapidKeys?.privateKey === 'string') {
|
|
83
|
-
return current.vapidKeys;
|
|
84
|
-
}
|
|
85
|
-
const generated = webPush.generateVAPIDKeys();
|
|
86
|
-
const next = await mutateStore((store) => ({ ...store, vapidKeys: store.vapidKeys ?? generated }));
|
|
87
|
-
return next.vapidKeys;
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const ensureWebPush = async () => {
|
|
91
|
-
if (initializedWebPush) return;
|
|
92
|
-
const keys = await getOrCreateVapidKeys();
|
|
93
|
-
webPush.setVapidDetails('mailto:pichamber@localhost', keys.publicKey, keys.privateKey);
|
|
94
|
-
initializedWebPush = true;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const addWebSubscription = async (clientId, input) => {
|
|
98
|
-
await ensureWebPush();
|
|
99
|
-
await mutateStore((store) => {
|
|
100
|
-
const existing = Array.isArray(store.subscriptionsByClient[clientId])
|
|
101
|
-
? store.subscriptionsByClient[clientId]
|
|
102
|
-
: [];
|
|
103
|
-
const entries = existing.filter((entry) => entry?.endpoint !== input.endpoint);
|
|
104
|
-
entries.unshift({ ...input, updatedAt: Date.now() });
|
|
105
|
-
return {
|
|
106
|
-
...store,
|
|
107
|
-
subscriptionsByClient: boundEntriesByClient({
|
|
108
|
-
...store.subscriptionsByClient,
|
|
109
|
-
[clientId]: entries.slice(0, MAX_ENTRIES_PER_CLIENT),
|
|
110
|
-
}),
|
|
111
|
-
};
|
|
112
|
-
});
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const removeWebSubscription = async (clientId, endpoint) => {
|
|
116
|
-
await mutateStore((store) => {
|
|
117
|
-
const existing = Array.isArray(store.subscriptionsByClient[clientId])
|
|
118
|
-
? store.subscriptionsByClient[clientId]
|
|
119
|
-
: [];
|
|
120
|
-
const entries = existing.filter((entry) => entry?.endpoint !== endpoint);
|
|
121
|
-
const subscriptionsByClient = { ...store.subscriptionsByClient };
|
|
122
|
-
if (entries.length > 0) subscriptionsByClient[clientId] = entries;
|
|
123
|
-
else delete subscriptionsByClient[clientId];
|
|
124
|
-
return { ...store, subscriptionsByClient };
|
|
125
|
-
});
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
const getOrCreateRelayKey = async () => {
|
|
129
|
-
const current = await readStore();
|
|
130
|
-
if (isRecord(current.relaySigningKey?.privateJwk) && isRecord(current.relaySigningKey?.publicJwk)) {
|
|
131
|
-
return {
|
|
132
|
-
privateKey: crypto.createPrivateKey({ key: current.relaySigningKey.privateJwk, format: 'jwk' }),
|
|
133
|
-
publicJwk: current.relaySigningKey.publicJwk,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
const pair = crypto.generateKeyPairSync('ec', { namedCurve: 'P-256' });
|
|
137
|
-
const generated = {
|
|
138
|
-
privateJwk: pair.privateKey.export({ format: 'jwk' }),
|
|
139
|
-
publicJwk: pair.publicKey.export({ format: 'jwk' }),
|
|
140
|
-
};
|
|
141
|
-
const next = await mutateStore((store) => ({ ...store, relaySigningKey: store.relaySigningKey ?? generated }));
|
|
142
|
-
return {
|
|
143
|
-
privateKey: crypto.createPrivateKey({ key: next.relaySigningKey.privateJwk, format: 'jwk' }),
|
|
144
|
-
publicJwk: next.relaySigningKey.publicJwk,
|
|
145
|
-
};
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
const relayPublicJwk = (jwk) => ({ kty: jwk.kty, crv: jwk.crv, x: jwk.x, y: jwk.y });
|
|
149
|
-
|
|
150
|
-
const registerNativeTokenWithRelay = async (token, platform) => {
|
|
151
|
-
if (!relayUrl || process.env.PICHAMBER_PUSH_RELAY_DISABLED === 'true') return;
|
|
152
|
-
const { privateKey, publicJwk } = await getOrCreateRelayKey();
|
|
153
|
-
const ts = Date.now();
|
|
154
|
-
const sig = signRelayMessage({ crypto }, privateKey, `${ts}.${token}.${platform}`);
|
|
155
|
-
const response = await fetchImpl(relayUrl.replace(/\/send$/, '/register-token'), {
|
|
156
|
-
method: 'POST',
|
|
157
|
-
headers: { 'content-type': 'application/json' },
|
|
158
|
-
body: JSON.stringify({ token, platform, publicKeyJwk: relayPublicJwk(publicJwk), ts, sig }),
|
|
159
|
-
});
|
|
160
|
-
if (!response.ok) throw new Error(`PUSH_RELAY_REGISTRATION_FAILED_${response.status}`);
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
const addNativeToken = async (clientId, input) => {
|
|
164
|
-
await mutateStore((store) => {
|
|
165
|
-
const existing = Array.isArray(store.nativeTokensByClient[clientId])
|
|
166
|
-
? store.nativeTokensByClient[clientId]
|
|
167
|
-
: [];
|
|
168
|
-
const entries = existing.filter((entry) => entry?.token !== input.token);
|
|
169
|
-
entries.unshift({ ...input, updatedAt: Date.now() });
|
|
170
|
-
return {
|
|
171
|
-
...store,
|
|
172
|
-
nativeTokensByClient: boundEntriesByClient({
|
|
173
|
-
...store.nativeTokensByClient,
|
|
174
|
-
[clientId]: entries.slice(0, MAX_ENTRIES_PER_CLIENT),
|
|
175
|
-
}),
|
|
176
|
-
};
|
|
177
|
-
});
|
|
178
|
-
await registerNativeTokenWithRelay(input.token, input.platform);
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
const removeNativeToken = async (clientId, token) => {
|
|
182
|
-
await mutateStore((store) => {
|
|
183
|
-
const existing = Array.isArray(store.nativeTokensByClient[clientId])
|
|
184
|
-
? store.nativeTokensByClient[clientId]
|
|
185
|
-
: [];
|
|
186
|
-
const entries = existing.filter((entry) => entry?.token !== token);
|
|
187
|
-
const nativeTokensByClient = { ...store.nativeTokensByClient };
|
|
188
|
-
if (entries.length > 0) nativeTokensByClient[clientId] = entries;
|
|
189
|
-
else delete nativeTokensByClient[clientId];
|
|
190
|
-
return { ...store, nativeTokensByClient };
|
|
191
|
-
});
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
const removeNativeTokenFromAllClients = async (token) => {
|
|
195
|
-
await mutateStore((store) => {
|
|
196
|
-
const nativeTokensByClient = {};
|
|
197
|
-
for (const [clientId, entries] of Object.entries(store.nativeTokensByClient)) {
|
|
198
|
-
const kept = Array.isArray(entries) ? entries.filter((entry) => entry?.token !== token) : [];
|
|
199
|
-
if (kept.length > 0) nativeTokensByClient[clientId] = kept;
|
|
200
|
-
}
|
|
201
|
-
return { ...store, nativeTokensByClient };
|
|
202
|
-
});
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
const updateVisibility = (clientId, visible, platform) => {
|
|
206
|
-
visibilityByClient.set(clientId, { visible, platform, updatedAt: Date.now() });
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
const isAnyInteractiveClientVisible = () => {
|
|
210
|
-
const now = Date.now();
|
|
211
|
-
for (const [clientId, state] of visibilityByClient) {
|
|
212
|
-
if (now - state.updatedAt > VISIBILITY_TTL_MS) {
|
|
213
|
-
visibilityByClient.delete(clientId);
|
|
214
|
-
continue;
|
|
215
|
-
}
|
|
216
|
-
if (state.visible && state.platform !== 'ios' && state.platform !== 'android') return true;
|
|
217
|
-
}
|
|
218
|
-
return false;
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
const removeDeadWebEndpoint = async (endpoint) => {
|
|
222
|
-
await mutateStore((store) => {
|
|
223
|
-
const subscriptionsByClient = {};
|
|
224
|
-
for (const [clientId, entries] of Object.entries(store.subscriptionsByClient)) {
|
|
225
|
-
const kept = Array.isArray(entries) ? entries.filter((entry) => entry?.endpoint !== endpoint) : [];
|
|
226
|
-
if (kept.length > 0) subscriptionsByClient[clientId] = kept;
|
|
227
|
-
}
|
|
228
|
-
return { ...store, subscriptionsByClient };
|
|
229
|
-
});
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
const sendWebPush = async (payload) => {
|
|
233
|
-
await ensureWebPush();
|
|
234
|
-
const store = await readStore();
|
|
235
|
-
const byEndpoint = new Map();
|
|
236
|
-
for (const entries of Object.values(store.subscriptionsByClient)) {
|
|
237
|
-
for (const entry of Array.isArray(entries) ? entries : []) {
|
|
238
|
-
if (typeof entry?.endpoint === 'string') byEndpoint.set(entry.endpoint, entry);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
await Promise.all([...byEndpoint.values()].map(async (entry) => {
|
|
242
|
-
try {
|
|
243
|
-
await webPush.sendNotification({
|
|
244
|
-
endpoint: entry.endpoint,
|
|
245
|
-
keys: { p256dh: entry.p256dh, auth: entry.auth },
|
|
246
|
-
}, JSON.stringify(payload));
|
|
247
|
-
} catch (error) {
|
|
248
|
-
if (error?.statusCode === 404 || error?.statusCode === 410) {
|
|
249
|
-
await removeDeadWebEndpoint(entry.endpoint);
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
console.warn(`[Push] delivery failed with status ${error?.statusCode ?? 'unknown'}`);
|
|
253
|
-
}
|
|
254
|
-
}));
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
const sendNativePush = async (payload) => {
|
|
258
|
-
if (!relayUrl || process.env.PICHAMBER_PUSH_RELAY_DISABLED === 'true') return;
|
|
259
|
-
if (isAnyInteractiveClientVisible()) return;
|
|
260
|
-
const store = await readStore();
|
|
261
|
-
const tokens = new Set();
|
|
262
|
-
for (const entries of Object.values(store.nativeTokensByClient)) {
|
|
263
|
-
for (const entry of Array.isArray(entries) ? entries : []) {
|
|
264
|
-
if (typeof entry?.token === 'string') tokens.add(entry.token);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
if (tokens.size === 0) return;
|
|
268
|
-
const list = [...tokens].slice(0, 100);
|
|
269
|
-
const { privateKey, publicJwk } = await getOrCreateRelayKey();
|
|
270
|
-
const ts = Date.now();
|
|
271
|
-
const sig = signRelayMessage({ crypto }, privateKey, `${ts}.${[...list].sort().join(',')}.${payload.title}`);
|
|
272
|
-
const response = await fetchImpl(relayUrl, {
|
|
273
|
-
method: 'POST',
|
|
274
|
-
headers: { 'content-type': 'application/json' },
|
|
275
|
-
body: JSON.stringify({
|
|
276
|
-
tokens: list,
|
|
277
|
-
title: payload.title,
|
|
278
|
-
body: payload.body,
|
|
279
|
-
collapseId: payload.tag?.slice(0, 64),
|
|
280
|
-
data: payload.data,
|
|
281
|
-
publicKeyJwk: relayPublicJwk(publicJwk),
|
|
282
|
-
ts,
|
|
283
|
-
sig,
|
|
284
|
-
}),
|
|
285
|
-
});
|
|
286
|
-
if (!response.ok) {
|
|
287
|
-
console.warn(`[Push relay] delivery failed with status ${response.status}`);
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
const result = await response.json().catch(() => null);
|
|
291
|
-
for (const entry of Array.isArray(result?.results) ? result.results : []) {
|
|
292
|
-
if (entry?.drop === true && typeof entry.token === 'string') {
|
|
293
|
-
await removeNativeTokenFromAllClients(entry.token);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
const send = async (payload) => {
|
|
299
|
-
const desktop = typeof onDesktopNotification === 'function'
|
|
300
|
-
? Promise.resolve().then(() => onDesktopNotification(payload))
|
|
301
|
-
: Promise.resolve();
|
|
302
|
-
await Promise.allSettled([desktop, sendWebPush(payload), sendNativePush(payload)]);
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
return {
|
|
306
|
-
getOrCreateVapidKeys,
|
|
307
|
-
addWebSubscription,
|
|
308
|
-
removeWebSubscription,
|
|
309
|
-
addNativeToken,
|
|
310
|
-
removeNativeToken,
|
|
311
|
-
updateVisibility,
|
|
312
|
-
send,
|
|
313
|
-
};
|
|
314
|
-
};
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { mkdtemp, readFile, rm, stat } from 'node:fs/promises';
|
|
2
|
-
import { tmpdir } from 'node:os';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import crypto from 'node:crypto';
|
|
5
|
-
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
6
|
-
|
|
7
|
-
import { createNotificationDeliveryRuntime } from './delivery-runtime.js';
|
|
8
|
-
|
|
9
|
-
const directories = [];
|
|
10
|
-
afterEach(async () => {
|
|
11
|
-
await Promise.all(directories.splice(0).map((directory) => rm(directory, { recursive: true, force: true })));
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
const setup = async () => {
|
|
15
|
-
const dataDir = await mkdtemp(join(tmpdir(), 'pichamber-notifications-'));
|
|
16
|
-
directories.push(dataDir);
|
|
17
|
-
const sendNotification = vi.fn(async () => undefined);
|
|
18
|
-
const fetch = vi.fn(async () => new Response(JSON.stringify({ results: [] }), { status: 200 }));
|
|
19
|
-
const webPush = {
|
|
20
|
-
generateVAPIDKeys: vi.fn(() => ({ publicKey: 'public-key', privateKey: 'private-key' })),
|
|
21
|
-
setVapidDetails: vi.fn(),
|
|
22
|
-
sendNotification,
|
|
23
|
-
};
|
|
24
|
-
return {
|
|
25
|
-
dataDir,
|
|
26
|
-
fetch,
|
|
27
|
-
sendNotification,
|
|
28
|
-
runtime: createNotificationDeliveryRuntime({ dataDir, webPush, crypto, fetch }),
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
describe('notification delivery runtime', () => {
|
|
33
|
-
it('persists subscriptions privately and fans out one terminal event', async () => {
|
|
34
|
-
const { dataDir, fetch, runtime, sendNotification } = await setup();
|
|
35
|
-
await runtime.addWebSubscription('client-1', {
|
|
36
|
-
endpoint: 'https://push.example/subscription',
|
|
37
|
-
p256dh: 'p256dh',
|
|
38
|
-
auth: 'auth',
|
|
39
|
-
platform: 'web',
|
|
40
|
-
});
|
|
41
|
-
await runtime.addNativeToken('client-1', {
|
|
42
|
-
token: 'native-token',
|
|
43
|
-
platform: 'ios',
|
|
44
|
-
environment: 'production',
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
await runtime.send({
|
|
48
|
-
title: 'Work completed',
|
|
49
|
-
body: 'Session',
|
|
50
|
-
tag: 'pichamber:completion:s1:7',
|
|
51
|
-
data: { type: 'completion', sessionId: 's1' },
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
expect(sendNotification).toHaveBeenCalledTimes(1);
|
|
55
|
-
expect(fetch).toHaveBeenCalledTimes(2);
|
|
56
|
-
expect(fetch.mock.calls[0][0]).toMatch(/register-token$/);
|
|
57
|
-
expect(fetch.mock.calls[1][0]).toMatch(/\/send$/);
|
|
58
|
-
const stored = JSON.parse(await readFile(join(dataDir, 'notifications.json'), 'utf8'));
|
|
59
|
-
expect(stored.subscriptionsByClient['client-1']).toHaveLength(1);
|
|
60
|
-
expect(stored.nativeTokensByClient['client-1']).toHaveLength(1);
|
|
61
|
-
if (process.platform !== 'win32') {
|
|
62
|
-
expect((await stat(join(dataDir, 'notifications.json'))).mode & 0o777).toBe(0o600);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('suppresses native fanout while an interactive client is visible', async () => {
|
|
67
|
-
const { fetch, runtime } = await setup();
|
|
68
|
-
await runtime.addNativeToken('mobile', {
|
|
69
|
-
token: 'native-token',
|
|
70
|
-
platform: 'ios',
|
|
71
|
-
environment: 'production',
|
|
72
|
-
});
|
|
73
|
-
runtime.updateVisibility('desktop', true, 'desktop');
|
|
74
|
-
|
|
75
|
-
await runtime.send({
|
|
76
|
-
title: 'Work failed',
|
|
77
|
-
body: 'Session',
|
|
78
|
-
tag: 'pichamber:error:s1:9',
|
|
79
|
-
data: { type: 'error', sessionId: 's1' },
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
expect(fetch).toHaveBeenCalledTimes(1);
|
|
83
|
-
expect(fetch.mock.calls[0][0]).toMatch(/register-token$/);
|
|
84
|
-
});
|
|
85
|
-
});
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
const text = (value, maxLength) => {
|
|
2
|
-
if (typeof value !== 'string') return '';
|
|
3
|
-
const trimmed = value.trim();
|
|
4
|
-
return trimmed.length > 0 && trimmed.length <= maxLength ? trimmed : '';
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export const registerNotificationRoutes = (app, { uiAuthController, delivery }) => {
|
|
8
|
-
const clientId = (req, res) => uiAuthController.ensureSessionToken(req, res);
|
|
9
|
-
|
|
10
|
-
app.get('/api/push/vapid-public-key', async (_req, res) => {
|
|
11
|
-
try {
|
|
12
|
-
const keys = await delivery.getOrCreateVapidKeys();
|
|
13
|
-
res.json({ publicKey: keys.publicKey });
|
|
14
|
-
} catch {
|
|
15
|
-
res.status(500).json({ error: 'Push notifications are unavailable' });
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
app.post('/api/push/subscribe', async (req, res) => {
|
|
20
|
-
const id = await clientId(req, res);
|
|
21
|
-
if (!id) return;
|
|
22
|
-
const endpoint = text(req.body?.endpoint, 4096);
|
|
23
|
-
const p256dh = text(req.body?.keys?.p256dh, 1024);
|
|
24
|
-
const auth = text(req.body?.keys?.auth, 1024);
|
|
25
|
-
if (!endpoint || !p256dh || !auth) return res.status(400).json({ error: 'Invalid push subscription' });
|
|
26
|
-
await delivery.addWebSubscription(id, {
|
|
27
|
-
endpoint,
|
|
28
|
-
p256dh,
|
|
29
|
-
auth,
|
|
30
|
-
platform: text(req.body?.platform, 32) || undefined,
|
|
31
|
-
});
|
|
32
|
-
res.json({ ok: true });
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
app.delete('/api/push/subscribe', async (req, res) => {
|
|
36
|
-
const id = await clientId(req, res);
|
|
37
|
-
if (!id) return;
|
|
38
|
-
const endpoint = text(req.body?.endpoint, 4096);
|
|
39
|
-
if (!endpoint) return res.status(400).json({ error: 'Invalid push subscription' });
|
|
40
|
-
await delivery.removeWebSubscription(id, endpoint);
|
|
41
|
-
res.json({ ok: true });
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
app.post('/api/push/apns-token', async (req, res) => {
|
|
45
|
-
const id = await clientId(req, res);
|
|
46
|
-
if (!id) return;
|
|
47
|
-
const token = text(req.body?.token, 4096);
|
|
48
|
-
const platform = req.body?.platform === 'android' ? 'android' : 'ios';
|
|
49
|
-
const environment = req.body?.environment === 'sandbox' ? 'sandbox' : 'production';
|
|
50
|
-
if (!token) return res.status(400).json({ error: 'Invalid native push token' });
|
|
51
|
-
try {
|
|
52
|
-
await delivery.addNativeToken(id, { token, platform, environment });
|
|
53
|
-
res.json({ ok: true });
|
|
54
|
-
} catch {
|
|
55
|
-
res.status(502).json({ error: 'Native push registration failed' });
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
app.delete('/api/push/apns-token', async (req, res) => {
|
|
60
|
-
const id = await clientId(req, res);
|
|
61
|
-
if (!id) return;
|
|
62
|
-
const token = text(req.body?.token, 4096);
|
|
63
|
-
if (!token) return res.status(400).json({ error: 'Invalid native push token' });
|
|
64
|
-
await delivery.removeNativeToken(id, token);
|
|
65
|
-
res.json({ ok: true });
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
app.post('/api/push/visibility', async (req, res) => {
|
|
69
|
-
const id = await clientId(req, res);
|
|
70
|
-
if (!id) return;
|
|
71
|
-
delivery.updateVisibility(id, req.body?.visible === true, text(req.body?.platform, 32) || undefined);
|
|
72
|
-
res.json({ ok: true });
|
|
73
|
-
});
|
|
74
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// Private relay service: shared relay endpoint configuration.
|
|
2
|
-
//
|
|
3
|
-
// The relay host entrypoint (createRelayService: settings persistence, the
|
|
4
|
-
// /api/pichamber/relay/* management routes, and host lifecycle wiring) was
|
|
5
|
-
// removed as dead code — no runtime wired it in. What remains is the relay
|
|
6
|
-
// endpoint constant, which the CLI connect-url command uses so the pairing
|
|
7
|
-
// link points at the same relay a host would dial out to.
|
|
8
|
-
|
|
9
|
-
export const DEFAULT_RELAY_URL = 'wss://relay.pichamber.dev/ws';
|