@preventive/triage 1.0.0-alpha.79 → 1.0.0-alpha.80

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.
Files changed (60) hide show
  1. package/common/line-diff.d.ts +4 -0
  2. package/common/line-diff.js +72 -14
  3. package/common/managed/npm-packages.d.ts +2 -0
  4. package/common/managed/npm-packages.js +12 -0
  5. package/common/pretty-json.js +3 -0
  6. package/common/pretty-kinds.js +20 -0
  7. package/common/pretty-sourcemap.js +70 -0
  8. package/common/sourcemap-listing.js +78 -0
  9. package/common/sourcemap-mappings.js +136 -0
  10. package/common/sourcemap-unlist.js +85 -0
  11. package/out/activity.js +2 -2
  12. package/out/brotli-fallback.js +2 -2
  13. package/out/chunk-2XUEZHIP.js +1 -1
  14. package/out/{chunk-PLF4LBLE.js → chunk-5AVGKFMR.js} +1 -1
  15. package/out/{chunk-WB3NRZL7.js → chunk-5CJKUV53.js} +1 -1
  16. package/out/{chunk-6VXEPL32.js → chunk-5EAVJAD2.js} +1 -1
  17. package/out/{chunk-OWIBDEJJ.js → chunk-5M2X3QPK.js} +1 -1
  18. package/out/{chunk-26W3E5JE.js → chunk-5QWPKTCE.js} +1 -1
  19. package/out/chunk-74JZTGTO.js +1 -1
  20. package/out/{chunk-MKX6JODK.js → chunk-7YO4QV5P.js} +1 -1
  21. package/out/{chunk-EMNIV37E.js → chunk-DUS5ARE2.js} +1 -1
  22. package/out/{chunk-Z54AXVCK.js → chunk-GBMAXAYK.js} +2 -2
  23. package/out/chunk-GO7FT4OD.js +1 -1
  24. package/out/{chunk-V43XH2JQ.js → chunk-JXBRWLMA.js} +1 -1
  25. package/out/chunk-LBD3M3J6.js +1 -0
  26. package/out/chunk-MV66NL3G.js +3 -0
  27. package/out/chunk-N57OWFKY.js +15 -0
  28. package/out/{chunk-IIJK4F4U.js → chunk-OWSEQOL5.js} +1 -1
  29. package/out/chunk-PLGH63UC.js +2 -0
  30. package/out/{chunk-3S4YWYOM.js → chunk-PTFYDJUP.js} +1 -1
  31. package/out/chunk-QD3IBSF4.js +1 -1
  32. package/out/{chunk-ATT2QA77.js → chunk-VZPPX6MV.js} +1 -1
  33. package/out/chunk-YKCRCNYZ.js +266 -0
  34. package/out/client-managed-import.js +1 -1
  35. package/out/client-managed.js +1 -1
  36. package/out/client-sync.js +2 -2
  37. package/out/compare.js +13 -18
  38. package/out/dialogs.js +38 -38
  39. package/out/graph.js +3 -3
  40. package/out/index.html +11 -11
  41. package/out/prism.js +1 -1
  42. package/out/scan.js +2 -2
  43. package/out/terminal.js +167 -167
  44. package/out/view.js +8 -8
  45. package/package.json +14 -9
  46. package/risk/index.d.ts +3 -0
  47. package/risk/index.js +1 -1
  48. package/risk/npm/tarball.js +4 -4
  49. package/server-managed/http.ts +36 -80
  50. package/server-managed/npm-delta-worker.js +117 -44
  51. package/server-managed/npm-delta.ts +101 -22
  52. package/server-managed/npm-kept.ts +5 -0
  53. package/server-managed/npm-patch-paths.ts +29 -0
  54. package/server-managed/npm-patch.ts +11 -3
  55. package/out/chunk-4YZOXAXR.js +0 -2
  56. package/out/chunk-NTJJIEHS.js +0 -259
  57. package/out/chunk-PQPKHAI5.js +0 -15
  58. package/out/chunk-QBIUW5EF.js +0 -2
  59. package/out/chunk-XLX6XXJF.js +0 -1
  60. /package/out/{chunk-S5HSDGTP.js → chunk-DUASGS2O.js} +0 -0
@@ -1,4 +1,4 @@
1
- import{a as e}from"./chunk-6VOB5WXX.js";import{g as t,n,r,s as i,t as a,u as o,v as s,w as c,x as l}from"./chunk-MKX6JODK.js";import{a as u}from"./chunk-NRPC74AM.js";import{e as d,i as f}from"./chunk-7C7DWL7I.js";import"./chunk-PNHBZGDD.js";import"./chunk-6VXEPL32.js";import"./chunk-XLX6XXJF.js";import{D as p}from"./chunk-QRKFPLA4.js";import{a as m,c as h,g}from"./chunk-2XUEZHIP.js";import"./chunk-TUII34K2.js";import"./chunk-OOJM4CTU.js";var _=`h1{font-size:1.35rem;margin-bottom:.5rem}h2{font-size:1.1rem;margin-bottom:.5rem}.triage-import{display:flex;gap:1rem;align-items:center;margin:1.5rem 0 2rem}.triage-import .btn{flex-shrink:0}.triage-import p{margin:0}.workspace-drop{display:grid;gap:.8rem;padding:2rem;margin:1.5rem 0;border:1px dashed var(--border);border-radius:var(--ui-radius, 8px)}.workspace-drop.dragging{border-color:var(--accent);background:rgb(from var(--accent) r g b / .08)}.workspace-drop span,p,li span{color:var(--muted);line-height:1.5}.actions,.local-choice{display:flex;gap:.8rem;flex-wrap:wrap;align-items:center}.local-choice{margin-bottom:1.5rem}.import-preview{display:grid;gap:.8rem}input:not([type=radio]),select{padding:.55rem;border:1px solid var(--border);border-radius:var(--ui-radius, 5px);color:var(--text);background:var(--bg);font:inherit}.import-preview input:not([type=radio]),.import-preview select{width:100%;box-sizing:border-box}fieldset{display:grid;gap:.8rem;padding:1rem;border:1px solid var(--border);border-radius:var(--ui-radius, 5px)}fieldset label{display:flex;gap:.5rem;align-items:center}li{padding:.4rem 0;overflow-wrap:anywhere}li span{display:block;font-size:.8rem}ul{padding-left:1.2rem}.primary{justify-self:start;color:var(--accent)}.error{color:var(--critical)}button:disabled{opacity:.5}input:focus-visible,select:focus-visible,button:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
1
+ import{a as e}from"./chunk-6VOB5WXX.js";import{g as t,n,r,s as i,t as a,u as o,v as s,w as c,x as l}from"./chunk-7YO4QV5P.js";import{a as u}from"./chunk-NRPC74AM.js";import{e as d,i as f}from"./chunk-7C7DWL7I.js";import"./chunk-PNHBZGDD.js";import"./chunk-5EAVJAD2.js";import"./chunk-LBD3M3J6.js";import{D as p}from"./chunk-QRKFPLA4.js";import{a as m,c as h,g}from"./chunk-2XUEZHIP.js";import"./chunk-TUII34K2.js";import"./chunk-OOJM4CTU.js";var _=`h1{font-size:1.35rem;margin-bottom:.5rem}h2{font-size:1.1rem;margin-bottom:.5rem}.triage-import{display:flex;gap:1rem;align-items:center;margin:1.5rem 0 2rem}.triage-import .btn{flex-shrink:0}.triage-import p{margin:0}.workspace-drop{display:grid;gap:.8rem;padding:2rem;margin:1.5rem 0;border:1px dashed var(--border);border-radius:var(--ui-radius, 8px)}.workspace-drop.dragging{border-color:var(--accent);background:rgb(from var(--accent) r g b / .08)}.workspace-drop span,p,li span{color:var(--muted);line-height:1.5}.actions,.local-choice{display:flex;gap:.8rem;flex-wrap:wrap;align-items:center}.local-choice{margin-bottom:1.5rem}.import-preview{display:grid;gap:.8rem}input:not([type=radio]),select{padding:.55rem;border:1px solid var(--border);border-radius:var(--ui-radius, 5px);color:var(--text);background:var(--bg);font:inherit}.import-preview input:not([type=radio]),.import-preview select{width:100%;box-sizing:border-box}fieldset{display:grid;gap:.8rem;padding:1rem;border:1px solid var(--border);border-radius:var(--ui-radius, 5px)}fieldset label{display:flex;gap:.5rem;align-items:center}li{padding:.4rem 0;overflow-wrap:anywhere}li span{display:block;font-size:.8rem}ul{padding-left:1.2rem}.primary{justify-self:start;color:var(--accent)}.error{color:var(--critical)}button:disabled{opacity:.5}input:focus-visible,select:focus-visible,button:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
2
2
  `;async function v(e,{session:t,confirmImport:n,...r}){if(t?.role!==`admin`||!t.csrfToken)throw Error(`An administrator session is required.`);if(e!=null&&(typeof e!=`object`||Array.isArray(e)))throw Error(`Invalid local triage.`);let i=Object.create(null);for(let[t,n]of Object.entries(e??{})){let{ignoredReports:e,scopedIgnoredReports:r,...a}=d(n)??{};Object.keys(a).length!==0&&(i[t]=a)}let a=Object.keys(i).length,o=new Set,s=[],c;if(a>0)do{r.signal?.throwIfAborted();let e=`/api/admin/reports/finding-ids`+(c?`?after=${encodeURIComponent(c)}`:``),{reports:t,nextCursor:n}=await r.api.send(e);r.signal?.throwIfAborted();for(let e of t){let t=e.findingIds.filter(e=>Object.hasOwn(i,e)&&!o.has(e));t.length>0&&s.push({id:e.id,ids:t});for(let e of t)o.add(e)}c=n}while(c);for(let e of o){if(!e||e.length>100)throw Error(`Triage finding IDs must be between 1 and 100 characters.`);if(l(i[e])===`invalid`)throw Error(`Triage for ${e} exceeds the managed server limits.`)}if(r.signal?.throwIfAborted(),n){let e=await n({matched:o.size,available:a});if(r.signal?.throwIfAborted(),!e)return null}let u=r.importedIds??new Set;for(let e of s)await S(i,{...r,importedIds:u,ids:e.ids,path:`/api/admin/reports/${encodeURIComponent(e.id)}/import-triage`});return o.size}function y(e,t){let n=[],r=Object.create(null);for(let[i,a]of Object.entries(e)){let e=t[i];if(!e)throw Error(`The server did not return the requested triage snapshot.`);let o=e.entry??{},s=r[i]={...o};delete s.comment;for(let[t,r]of Object.entries(a))if(t===`comment`){if(e.comments.some(e=>e.body===r))continue;e.comments.length>0?n.push({id:i,property:t,local:e.comments.map(e=>e.body).join(`
3
3
 
4
4
  `),imported:r}):s.comment=r}else if(o[t]!==void 0&&o[t]!==r){let e=e=>t===`flagged`?e?`flagged`:`not flagged`:e;n.push({id:i,property:t,local:e(o[t]),imported:e(r)})}else s[t]=r}return{entries:r,conflicts:n}}async function b(e,t,n,r,i){i?.throwIfAborted();let{entries:a,conflicts:o}=y(e,t);if(o.length===0)return a;let s=await r(o,n,{title:`Triage conflicts on import`,intro:`disagree with stored triage on`,trailingNote:`Imported comments are added alongside existing comments. Other choices apply to these finding IDs across all teams.`,importedSideLabel:`Apply imported`});if(i?.throwIfAborted(),!s)throw Object.assign(Error(`Triage conflict resolution was cancelled.`),{cancelled:!0});for(let t of o){let n=s[`${t.id}:${t.property}`];if(![`local`,`imported`].includes(n))throw Error(`Resolve every triage conflict before importing.`);n===`imported`&&(a[t.id][t.property]=e[t.id][t.property])}return a}function x(e,t){let n=[],r={entries:{},expected:{}};for(let[i,a]of Object.entries(e)){let e={entries:{...r.entries,[i]:a},expected:{...r.expected,[i]:t[i].version}};if(new TextEncoder().encode(JSON.stringify(e)).length<=262144)r=e;else{if(Object.keys(r.entries).length===0)throw Error(`This triage entry is too large to import.`);n.push(r),r={entries:{[i]:a},expected:{[i]:t[i].version}}}}return Object.keys(r.entries).length>0&&n.push(r),n}async function S(e,{api:t,path:n,ids:r=Object.keys(e),importedIds:i=new Set,lookup:a=new Map,resolveConflicts:o,signal:s}){r=r.filter(t=>Object.hasOwn(e,t)&&!i.has(t));for(let c=0;c<r.length;c+=200){let l=r.slice(c,c+200);for(let r=0;r<5&&l.length>0;r++){s?.throwIfAborted();let{snapshots:r}=await t.send(n,{findingIds:l}),c=await b(Object.fromEntries(l.map(t=>[t,e[t]])),r,a,o,s);for(let e of x(c,r)){if(s?.throwIfAborted(),(await t.send(n,e)).conflict)break;Object.keys(e.entries).forEach(e=>i.add(e))}l=l.filter(e=>!i.has(e))}if(l.length>0)throw Error(`Stored triage keeps changing. Retry to resolve it against the latest values.`)}}var C=`You can retry the remaining steps.`;function w(e){return String(e?.detail??e?.message??e).replace(/\.$/u,``)}function T(e,t){return t?.aborted===!0||e?.name===`AbortError`||e?.cancelled===!0}function E(e){if(typeof e!=`string`)return{ok:!0,path:null};if(/\p{Cc}/u.test(e)||e.includes(`\\`)||e!==e.trim())return{ok:!1};let t=[];for(let n of e.split(`/`))if(n!==``&&n!==`.`){if(n===`..`||n!==n.trim())return{ok:!1};t.push(n)}let n=t.join(`/`);return n.length>500?{ok:!1}:{ok:!0,path:n===``?null:n}}async function D(e,t){let a=new Uint8Array(await e.arrayBuffer());return n(a)?t({tryPassword:e=>r(a,e)}):a[0]===31&&a[1]===139?r(a):i(new TextDecoder(`utf-8`,{fatal:!0}).decode(a))}function O(e,t,n,r,i=``){let a=e?u(e,t,r,i):null,o=n.find(t=>a?t.repoId===a.repoId:t.fullName.toLowerCase()===e?.toLowerCase());return{repoId:o?.repoId??null,directory:a?.directory??t,github:o?.fullName??e}}async function k(e,n,r=[]){let i=new Map,l=[];for(let t of e.reports){if(typeof t?.name!=`string`||!t.name||typeof t.content!=`string`)throw Error(`Every report must have a name and content.`);let u=a(t.content,t.name);if(!u.data)throw Error(`${t.name}: ${u.reason??`Unsupported report`}`);let d=p(u.data),f=d??p(t)??p({repo:{github:e.repoUrls?.[t.name]}})??s(u.data),m=d?``:c(u.data),h=E(u.data.repo?.directory);if(!h.ok)throw Error(`${t.name}: invalid repository directory`);let g=u.format===`links`?[]:(await o(t.content,t.name))?.findings??[];for(let e of g)e.id&&i.set(e.id,e);let _=h.path??``;l.push({...t,links:u.format===`links`,...O(f,_,n,r,m),declaredGithub:f,declaredDirectory:_,filePrefix:m,embedded:d,ids:[...new Set(g.map(e=>e.id).filter(Boolean))],uploaded:null})}let u=Object.create(null);if(e.triage!=null&&(typeof e.triage!=`object`||Array.isArray(e.triage)))throw Error(`Invalid workspace triage.`);let f=await t(e.triage,t=>e.reports.find(e=>e.name===t)?.content);for(let[e,t]of Object.entries(f.entries)){if(!i.has(e))continue;let n=d(t);if(!n)continue;let{ignoredReports:r,scopedIgnoredReports:a,...o}=n;Object.keys(o).length!==0&&(u[e]=o)}let m=[];for(let t of e.bundleBlobs??[]){let e=Uint8Array.fromBase64(t.data),n=`sha512-${new Uint8Array(await crypto.subtle.digest(`SHA-512`,e)).toBase64()}`;if(n!==t.integrity)throw Error(`${t.name}: bundle integrity mismatch`);m.push({name:t.name,integrity:n,bytes:e,uploaded:null})}return{name:e.workspace.name.slice(0,100),reports:l,bundles:m,triage:u,lookup:i,references:e.bundles??[],team:null,completed:new Set,importedIds:new Set}}function A(e,t,n){async function r(r,i,a={}){n?.throwIfAborted();let o=await e(r,{credentials:`same-origin`,signal:n,...i===void 0?{}:{method:`POST`,body:i instanceof File?i:JSON.stringify(i)},headers:{...i instanceof File?{}:{"content-type":`application/json`},"x-csrf-token":t.csrfToken,...a}});if(n?.throwIfAborted(),o.status===409)return{conflict:!0};if(!o.ok){let e=await o.json().then(e=>typeof e?.error==`string`?e.error:``,()=>``);n?.throwIfAborted();let t=`Import request failed (HTTP ${o.status}${e?`: ${e}`:``}).`;throw Object.assign(Error(`${t} ${C}`),{detail:t})}let s=await o.json();return n?.throwIfAborted(),s}return{send:r}}async function j(e,t,n,r,i,a){if(e.bundles.length===0&&e.references.length===0)return;let o=i??(await n.send(`/api/admin/bundles`)).bundles,s=new Set(e.bundles.map(e=>e.uploaded.id));if([...s].some(e=>!o.some(t=>t.id===e)))throw Error(`Could not verify the uploaded source bundles. Retry the import.`);let c=new Set(e.references);for(let i of o){if(!s.has(i.id)&&!c.has(i.integrity))continue;let o=!a.has(i.repoId),l=o?t:i.repoId;o&&await r(`bundle-repo:${i.id}:${l}`,()=>n.send(`/api/admin/bundles/set-repo`,{bundleId:i.id,repoId:l}));let u=o?``:i.repoDirectory??``;await r(`repo:${l}:${u}`,()=>n.send(`/api/admin/teams/set-repo`,{teamId:e.team.id,repoId:l,path:u}))}}async function M(e,t){e.uploaded||=await t.send(`/api/admin/deduplication`,new File([e.content],e.name),{"x-report-filename":encodeURIComponent(e.name)})}async function N(e,t){let n=(await t.send(`/api/admin/repositories/browsable`)).repos,r=e.reports.filter(e=>!e.links&&e.declaredGithub&&!e.uploaded);if(r.length>0){let{aliases:e=[]}=await t.send(`/api/admin/repositories/aliases`);for(let t of r)Object.assign(t,O(t.declaredGithub,t.declaredDirectory,n,e,t.filePrefix))}return new Set(n.map(e=>e.repoId))}async function P(e,{plan:t,api:n,step:r,activeRepos:i,defaultRepo:a,includeTriage:o,resolveConflicts:s,signal:c}){if(e.links){await M(e,n);return}let l=i.has(e.repoId)?e.repoId:a;if(!e.uploaded){let t=await n.send(`/api/admin/reports`,new File([e.content],e.name),{"x-report-filename":encodeURIComponent(e.name),"x-repo-id":String(l),"x-repo-directory":encodeURIComponent(e.directory)});if(t.conflict)throw Error(`Could not reuse the stored report ${e.name}. Retry the import.`);e.uploaded=t}let u=e.uploaded;i.has(u.repoId)||await r(`report-repo:${u.id}:${l}:${e.directory}`,async()=>{if((await n.send(`/api/admin/reports/set-repo`,{reportId:u.id,repoId:l,directory:e.directory})).conflict)throw Error(`Could not assign the stored report ${e.name} to its repository.`);u.repoId=l,u.repoDirectory=e.directory});let d=u.repoDirectory??``;await r(`repo:${u.repoId}:${d}`,()=>n.send(`/api/admin/teams/set-repo`,{teamId:t.team.id,repoId:u.repoId,path:d})),o&&await S(t.triage,{api:n,resolveConflicts:s,signal:c,ids:e.ids,importedIds:t.importedIds,lookup:t.lookup,path:`/api/admin/reports/${encodeURIComponent(e.uploaded.id)}/import-triage`}),await r(`publish:${e.uploaded.id}`,()=>n.send(`/api/admin/reports/set-visible`,{reportId:e.uploaded.id,visible:!0}))}async function F(e,{api:t,session:n,defaultRepo:r,includeTriage:i,resolveConflicts:a,signal:o,progress:s=()=>{}}){if(n?.role!==`admin`||!n.csrfToken)throw Error(`An administrator session is required.`);if(!e.name.trim()||e.name.trim().length>100)throw Error(`Enter a team name of up to 100 characters.`);if(i)for(let[t,n]of Object.entries(e.triage)){if(!t||t.length>100)throw Error(`Triage finding IDs must be between 1 and 100 characters. Choose Skip triage to import the files without it.`);if(l(n)===`invalid`)throw Error(`Triage for ${t} exceeds the managed server limits. Choose Skip triage to import the files without it.`)}o?.throwIfAborted();let c=null;if(e.bundles.length===0){let n=new Set(e.references);c=n.size>0?(await t.send(`/api/admin/bundles`)).bundles.filter(e=>n.has(e.integrity)):[]}if(e.reports.length===0&&e.bundles.length===0&&c.length===0)throw Error(e.references.length>0?`None of the referenced source bundles are available on the server. Export with bundle bytes included and try again.`:`This workspace contains no report or bundle files.`);let u=await N(e,t);for(let t of e.reports.filter(e=>!e.links)){if(t.embedded&&!u.has(t.repoId))throw Error(`Connect ${t.embedded} in Repositories before importing ${t.name}.`);if(!u.has(t.repoId)&&!u.has(r))throw Error(`Choose an active repository for ${t.name}.`)}if((e.bundles.length>0||c.some(e=>!u.has(e.repoId)))&&!u.has(r))throw Error(`Choose an active repository for the source bundles.`);let d=()=>o?.throwIfAborted(),f=async(t,n)=>{d(),e.completed.has(t)||(await n(),e.completed.add(t))};if(d(),!e.team){let n=await t.send(`/api/admin/teams`,{name:e.name.trim()});if(n.conflict)throw Error(`A team already has this name. Choose another name.`);e.team=n}await f(`member`,()=>t.send(`/api/admin/teams/set-member`,{teamId:e.team.id,userId:n.id,security:!0,dependencies:!0}));for(let n of e.bundles)d(),s(`Importing ${n.name}\u2026`),n.uploaded||=await t.send(`/api/admin/bundles`,new File([n.bytes],n.name),{"x-bundle-filename":encodeURIComponent(n.name)});await j(e,r,t,f,c,u);let p=[];for(let n of e.reports){d(),s(`Importing ${n.name}\u2026`);try{await P(n,{plan:e,api:t,step:f,activeRepos:u,defaultRepo:r,includeTriage:i,resolveConflicts:a,signal:o})}catch(e){if(T(e,o))throw e;p.push(`${n.name}: ${w(e)}`)}}if(p.length>0)throw Error(`Could not import ${p.length} of ${e.reports.length} files: ${p.join(`; `)}. ${C}`);return e.team}function I(e){let t=()=>e.isEncryptionEnabled()&&!e.isUnlocked();return{get locked(){return t()},unlock:t=>e.unlockEncryption(t),async read({signal:n}={}){let r=!1,i=e.onVaultStateChange(()=>{r=!0}),a=()=>{if(n?.throwIfAborted(),t()||r)throw Error(`Local data was locked or changed. Unlock it and import triage again.`)};try{a();let t=await e.readTriageBlob();return a(),t}finally{i()}}}}function L(e){let t=()=>e.isEncryptionEnabled()&&!e.isUnlocked();async function n(){let t=JSON.parse(await e.hydrateKey(`deepview.workspaces`)||`[]`);return(Array.isArray(t)?t:t.workspaces??[]).filter(e=>typeof e.id==`string`&&typeof e.name==`string`)}async function r(n,r){let i=!1,a=[e.onVaultStateChange,e.onFileMutated,e.onBundleMutated].map(e=>e(()=>{i=!0})),o=()=>{if(r?.throwIfAborted(),t()||i)throw Error(`Local data was locked or changed. Unlock it and select the workspace again.`)};try{o();let e=await n(o);return o(),e}finally{a.forEach(e=>e())}}return{get locked(){return t()},unlock:t=>e.unlockEncryption(t),list:({signal:e}={})=>r(async()=>(await n()).map(e=>({id:e.id,name:e.name})),e),read:(t,{signal:i}={})=>r(async r=>{let i=(await n()).find(e=>e.id===t);if(!i)throw Error(`This local workspace no longer exists.`);let a=JSON.stringify(i),o=JSON.parse(await e.hydrateKey(`deepview.repoUrls`)||`{}`),s=[];for(let t of i.reports??[]){r();let n=await e.withStoredItem(`report`,t,()=>e.readFile(t));r(),s.push({name:t,content:n,...o[t]?{repo:{github:o[t]}}:{}})}let c=await e.listBundles(),l=[];for(let t of i.bundles??[]){r();let n=c.find(e=>e.integrity===t);if(!n)continue;let i=await e.withStoredItem(`bundle`,t,()=>e.readBundle(t));r(),l.push({integrity:t,name:n.name,data:i.toBase64()})}let u=await e.readTriageBlob()??{};if(JSON.stringify((await n()).find(e=>e.id===t))!==a)throw Error(`The local workspace changed. Select it again.`);return{version:1,workspace:{id:t,name:i.name,privateKey:``},reports:s,bundles:i.bundles??[],bundleBlobs:l,triage:u,repoUrls:o}},i)}}var R=e=>e===`bundle`?`bundles`:`reports`,z=(e,t)=>JSON.stringify([e,t||``]),B=(e,t)=>new Set(t.map(t=>e===`bundle`?t.integrity:z(t.sha256,t.analyzer)));async function V(e){let t=new Uint8Array(await e.arrayBuffer()),n=a(new TextDecoder().decode(t),e.name);if(!n.data)throw Error(n.reason??`Not a recognized report`);let r=new Uint8Array(await crypto.subtle.digest(`SHA-256`,t)).toBase64({alphabet:`base64url`,omitPadding:!0});return{hash:r,key:z(r,typeof n.data.source==`string`?n.data.source:null)}}async function H(e,{source:t,deps:n,api:r,signal:i}){let a=JSON.parse(await n.hydrateKey(`deepview.workspaces`)||`[]`),o=(Array.isArray(a)?a:a.workspaces??[]).filter(e=>typeof e.id==`string`&&typeof e.name==`string`);i.throwIfAborted();let s=await t.list(e),c=B(e,(await r.send(`/api/admin/${R(e)}`))[R(e)]),l=o.map(e=>({id:e.id,name:e.name,items:[]})),u={id:null,name:`Not in a workspace`,items:[]},d=[];for(let r of s){i.throwIfAborted();let a={value:r.value,name:r.label,key:r.value,synced:!1,present:!1,error:``};if(e===`report`)try{Object.assign(a,await t.importItem(e,a.value,V,{signal:i})),a.syncHash=await n.reportSyncHash(a.value)}catch(e){i.throwIfAborted(),a.error=String(e?.message??e)}i.throwIfAborted(),a.present=c.has(a.key);let s=!1;o.forEach((t,r)=>{if(!t[R(e)]?.includes(a.value))return;let i=n.localContentSyncStatus(t.id,e,a.value,a.syncHash);a.synced||=i.synced,l[r].items.push({item:a,...i}),s=!0}),s||u.items.push({item:a,synced:!1,cached:!1}),d.push(a)}return{kind:e,items:d,groups:[...l,u].filter(e=>e.items.length>0)}}async function U(e,t,{source:n,api:r,signal:i,progress:a=()=>{},imported:o=new Set}){let{kind:s}=e,c=B(s,(await r.send(`/api/admin/${R(s)}`))[R(s)]),l=new Set(t),u=[],d=0;for(let t of e.items)if(i.throwIfAborted(),!(!l.has(t.value)||t.error||t.present)){if(c.has(t.key)){t.present=!0;continue}a(`Importing ${t.name}\u2026`),d++;try{await n.importItem(s,t.value,async e=>{let n=s===`report`?(await V(e)).key:await f(new Uint8Array(await e.arrayBuffer()));if(i.throwIfAborted(),n!==t.key)throw Error(`${t.name} changed. Choose files again before importing.`);if((await r.send(`/api/admin/${R(s)}`,e,{[`x-${s}-filename`]:encodeURIComponent(e.name)})).conflict)throw Error(`Could not import ${t.name}. Try again.`)},{signal:i})}catch(e){if(T(e,i))throw e;u.push(`${t.name}: ${w(e)}`);continue}c.add(t.key),t.present=!0,o.add(t.value)}if(u.length>0)throw Error(`Imported ${d-u.length} of ${d} ${s}s. Could not import ${u.join(`; `)}. Import again to retry them.`);return o.size}var W=(e,t)=>e===void 0?`managed-only`:t===void 0?`local-only`:`mismatch`;function G(e,t){let n=t.slice(),r=e.map(e=>{let t=n.indexOf(e);return t!==-1&&n.splice(t,1),{text:e,different:t===-1}}),i=e.slice(),a=t.map(e=>{let t=i.indexOf(e);return t!==-1&&i.splice(t,1),{text:e,different:t===-1}});return!r.some(e=>e.different)&&!a.some(e=>e.different)?null:{property:`comment`,local:r,managed:a,kind:r.some(e=>e.different)?a.some(e=>e.different)?`mismatch`:`local-only`:`managed-only`}}function K(e,t){let n=d(e)??{},r=d(t.entry)??{},i=[];for(let e of[`triage`,`color`,`fix`,`flagged`])n[e]!==r[e]&&i.push({property:e,local:n[e],managed:r[e],kind:W(n[e],r[e])});let a=G(n.comment?[n.comment]:[],t.comments.map(e=>e.body));return a&&i.push(a),n.ignoredReports?.length&&i.push({property:`ignoredReports`,local:[...new Set(n.ignoredReports)],managed:void 0,kind:`local-only`}),i}async function q(e,{lookup:t,triage:n,matched:r,findings:i,api:a,signal:o}){let s=[...new Set(e.findingIds)].filter(e=>t.has(e)&&!r.has(e));for(let c=0;c<s.length;c+=200){let l=s.slice(c,c+200);if(l.some(e=>e.length>100))throw Error(`A shared finding ID exceeds the managed triage limit.`);o.throwIfAborted();let{snapshots:u}=await a.send(`/api/admin/reports/${encodeURIComponent(e.id)}/import-triage`,{findingIds:l});o.throwIfAborted();for(let e of l){if(!u?.[e])throw Error(`The server did not return the requested triage snapshot.`);let a=K(n[e],u[e]);a.length>0&&i.push({id:e,finding:t.get(e),differences:a}),r.add(e)}}}async function J({source:e,readTriage:t,api:n,signal:r,progress:i=()=>{}}){let s=new Map,c=[];for(let t of await e.list(`report`)){r.throwIfAborted(),i(`Reading ${t.label}\u2026`);try{let n=await e.importItem(`report`,t.value,async e=>{let t=await e.text(),n=a(t,e.name);if(!n.data)throw Error(n.reason??`Not a recognized report`);return n.format===`links`?[]:(await o(t,e.name))?.findings??[]},{signal:r});r.throwIfAborted();for(let e of n)typeof e.id!=`string`||!e.id||(s.has(e.id)||s.set(e.id,{...e,reports:[]}),s.get(e.id).reports.push(t.label))}catch(e){r.throwIfAborted(),c.push({name:t.label,reason:String(e?.message??e)})}}let l=await t()??{};if(r.throwIfAborted(),typeof l!=`object`||Array.isArray(l))throw TypeError(`Invalid local triage.`);let u=[],d=new Set;if(s.size===0)return{matched:0,localFindings:0,findings:u,skipped:c};let f;do{r.throwIfAborted(),i(`Comparing local and managed triage…`);let e=await n.send(`/api/admin/reports/finding-ids`+(f?`?after=${encodeURIComponent(f)}`:``));r.throwIfAborted();for(let t of e.reports)await q(t,{lookup:s,triage:l,matched:d,findings:u,api:n,signal:r});f=e.nextCursor}while(f);return r.throwIfAborted(),{matched:d.size,localFindings:s.size,findings:u,skipped:c}}function Y(t,n){if(customElements.get(`managed-admin-import`))return;class r extends t{static view=`manage-import`;static styles=[m(e),m(_)];static properties={localDeps:{attribute:!1},_busy:{state:!0},_error:{state:!0},_message:{state:!0},_plan:{state:!0},_catalog:{state:!0},_localOpen:{state:!0},_workspaces:{state:!0},_localId:{state:!0},_triage:{state:!0},_repo:{state:!0},_drag:{state:!0}};constructor(){super(),this._busy=!1,this._error=``,this._message=``,this._plan=null,this._catalog=null,this._workspaces=[],this._localOpen=!1,this._localId=``,this._triage=``,this._repo=null,this._files=[],this._drag=!1,this._local=!1,this._over=e=>{e.dataTransfer?.types?.includes(`Files`)&&(e.preventDefault(),this._drag=!0)},this._drop=e=>{e.dataTransfer?.types?.includes(`Files`)&&(e.preventDefault(),e.stopPropagation(),this._drag=!1,this._busy||(this._files.push(...e.dataTransfer.files),this._nextFile()))},this._localChanged=()=>{this._workspaces=[],this._localId=``,!this._unlocking&&(this._local&&(this._plan=null),(this._local||this._importingTriage||this._importingContent||this._comparingTriage)&&(this._operation?.abort(),this._message=``,this._error=this._comparingTriage?`Local data changed or was locked. Compare triage again to continue.`:this._importingContent?`Local data changed or was locked. Choose files again to continue.`:this._importingTriage?`Local data changed or was locked. Import triage again to continue.`:`Local data changed or was locked. Choose the workspace again.`))},this._blur=()=>{this._readingLocal&&this._localChanged()}}connectedCallback(){super.connectedCallback(),this.addEventListener(`dragover`,this._over),this.addEventListener(`drop`,this._drop),globalThis.addEventListener(`blur`,this._blur),globalThis.addEventListener(`storage`,this._localChanged),this._offVault=this.localDeps?.onVaultStateChange(this._localChanged),this._loadCatalog()}disconnectedCallback(){this._operation?.abort(),this._offVault?.(),this._plan=null,this._files=[],this.removeEventListener(`dragover`,this._over),this.removeEventListener(`drop`,this._drop),globalThis.removeEventListener(`blur`,this._blur),globalThis.removeEventListener(`storage`,this._localChanged),super.disconnectedCallback()}updated(e){e.has(`session`)&&(this._role!==`admin`||e.get(`session`)?.id!==this.session?.id)&&(this._operation?.abort(),this._plan=null,this._files=[])}async _action(e){if(this._busy||this._role!==`admin`)return;let t=this._operation=new AbortController,n=AbortSignal.any([t.signal,this.appState.sessionController.signal]);this._busy=!0,this._error=``;try{await e(n),n.throwIfAborted()}catch(e){n.aborted||(this._error=String(e?.message??e))}finally{this._operation===t&&(this._busy=!1)}}async _loadCatalog(){if(this._role===`admin`)try{await this._loadCollection(`workspace-import:catalog`,`import options`,async e=>{let t=A(n,this.session,e),[r,i,a,o]=await Promise.all([t.send(`/api/admin/reports`),t.send(`/api/admin/teams`),t.send(`/api/admin/bundles`),t.send(`/api/admin/repositories/aliases`)]);return{repos:r.repos,teams:i.teams,bundles:a.bundles,aliases:o.aliases}},e=>{this._catalog=e})}catch(e){this._error=String(e?.message??e)}}_browse(){let e=document.createElement(`input`);e.type=`file`,e.multiple=!0,e.accept=`.enc,.gz,.json`,e.addEventListener(`change`,()=>{this._files.push(...e.files),this._nextFile()},{once:!0}),e.click()}async _prepare(e,t){if(!e)return;if(this._catalog||await this._loadCatalog(),t.throwIfAborted(),!this._catalog)throw Error(`Could not load repositories. Try again.`);let n=await k(e,this._catalog.repos,this._catalog.aliases);t.throwIfAborted();let r=new Set(this._catalog.teams.map(e=>e.name)),i=n.name||`Imported workspace`,a=2;for(;r.has(n.name);){let e=` (${a++})`;n.name=i.slice(0,100-e.length)+e}let o=new Set(n.reports.map(e=>e.repoId).filter(e=>e!=null));this._repo=o.size===1?[...o][0]:null,this._triage=Object.keys(n.triage).length>0?``:`skip`,this._plan=n,this._message=``}async _nextFile(){if(this._files.length===0||this._busy)return;let e=this._files.shift();this._local=!1,this._plan=null,await this._action(async t=>{let n=await D(e,this.promptPassword);t.throwIfAborted(),await this._prepare(n,t)})}async _unlock(e,t){this._unlocking=!0;try{return!e.locked||await e.unlock({signal:t})}finally{this._unlocking=!1}}async _chooseLocal(){this._localOpen=!0,await this._action(async e=>{let t=L(this.localDeps);await this._unlock(t,e)&&(e.throwIfAborted(),this._workspaces=await t.list({signal:e}))})}async _readLocal(){if(!this._localId)return;let e=this._localId;this._local=!0,this._plan=null,await this._action(async t=>{let n=L(this.localDeps);if(await this._unlock(n,t)){this._readingLocal=!0;try{await this._prepare(await n.read(e,{signal:t}),t)}finally{this._readingLocal=!1}}})}async _import(){this._plan&&this._triage&&this._csrf&&(await this._action(async e=>{if(this._local&&L(this.localDeps).locked)throw Error(`Unlock local data and choose the workspace again.`);let t=this._plan,r=[`teams`,`reports`,`bundles`,`history`,`workspace-import`,`scan-sources`,`repo-impact`];try{let i=await this.appState.mutate(()=>F(t,{api:A(n,this.session,e),session:this.session,defaultRepo:this._repo,includeTriage:this._triage===`include`,resolveConflicts:this.resolveConflicts,signal:e,progress:e=>{this._message=e}}),r);this._catalog.teams.push(i),this._message=`Imported into ${i.name}.`,this._plan=null}finally{this.appState.invalidate(r),t.team&&this._emit(`managed-import-complete`)}}),!this._plan&&!this._error&&await this._nextFile())}async _importLocalTriage(){this._csrf&&await this._action(async e=>{this._importingTriage=!0,this._message=``;let t=new Set,r=[`reports`,`history`];try{let r=I(this.localDeps);if(!await this._unlock(r,e))return;this._readingLocal=!0;let i;try{i=await r.read({signal:e})}finally{this._readingLocal=!1}let a=await v(i,{api:A(n,this.session,e),session:this.session,resolveConflicts:this.resolveConflicts,signal:e,importedIds:t,confirmImport:async t=>(await this.confirmTriageImport({...t,signal:e}))?.confirmed===!0});if(e.throwIfAborted(),a===null)return;this._message=a?`Imported triage for ${a} finding${a===1?``:`s`}.`:`No local triage matches findings in managed reports.`}finally{this._importingTriage=!1,this.appState.invalidate(r),t.size>0&&this._emit(`managed-import-complete`)}})}async _compareLocalTriage(){this._csrf&&await this._action(async e=>{this._comparingTriage=!0,this._message=``;let t=this.localImportSource,r=t.subscribe(this._localChanged);try{if(!await this._unlock(t,e))return;e.throwIfAborted(),this._readingLocal=!0;let r=I(this.localDeps),i=await J({source:t,signal:e,readTriage:()=>r.read({signal:e}),api:A(n,this.session,e),progress:e=>{this._message=e}});e.throwIfAborted(),this._message=``,await this.showTriageComparison({comparison:i,signal:e})}finally{r(),this._readingLocal=!1,this._comparingTriage=!1,this._message=``}})}async _importLocalContent(e){this._csrf&&await this._action(async t=>{this._importingContent=!0,this._message=``;let r=this.localImportSource,i=[`reports`,`bundles`,`bundle-metadata`,`history`,`workspace-import`,`scan-sources`,`repo-impact`],a=new Set,o=r.subscribe(this._localChanged);try{if(!await this._unlock(r,t))return;t.throwIfAborted(),this._readingLocal=!0;let i=A(n,this.session,t),o=await H(e,{source:r,deps:this.localDeps,api:i,signal:t}),s=await this.confirmContentImport({plan:o,signal:t});if(t.throwIfAborted(),!s?.confirmed)return;let c=await U(o,s.selected,{source:r,api:i,signal:t,imported:a,progress:e=>{this._message=e}});this._message=`Imported ${c} ${e}${c===1?``:`s`}.`}finally{o(),this._readingLocal=!1,this._importingContent=!1,this.appState.invalidate(i),a.size>0&&this._emit(`managed-import-complete`)}})}render(){if(this._role!==`admin`)return g;let e=this._plan,t=e?Object.keys(e.triage).length:0,n=new Set([...e?.references??[],...e?.bundles.map(e=>e.integrity)??[]]),r=(this._catalog?.bundles??[]).filter(e=>n.has(e.integrity)),i=e?.references.filter(t=>!e.bundles.some(e=>e.integrity===t)).length??0;return h`<div class="wrap" @dragleave="${()=>{this._drag=!1}}">${this._nav()}<h1>Import</h1><section class="triage-import" aria-label="Import local files"><div class="actions"><button type="button" class="btn" ?disabled="${this._busy||!this._csrf}" @click="${()=>this._importLocalContent(`bundle`)}">Import bundles</button> <button type="button" class="btn" ?disabled="${this._busy||!this._csrf}" @click="${()=>this._importLocalContent(`report`)}">Import reports</button></div><p>Choose files from this browser, grouped by workspace. Import files without teams or triage.</p></section><section class="triage-import" aria-label="Local triage"><div class="actions"><button type="button" class="btn" ?disabled="${this._busy||!this._csrf}" @click="${()=>this._importLocalTriage()}">Import triage</button> <button type="button" class="btn" ?disabled="${this._busy||!this._csrf}" @click="${()=>this._compareLocalTriage()}">Compare triage</button></div><p>Import saved triage and comments for findings already in managed reports.<br>Unmatched data stays in this browser.<br>Conflicting values prompt for resolution; per-report ignores are skipped.</p></section><h2>Import workspace</h2><p class="intro ui-hint">Create a new team from a workspace export or a workspace stored in this browser.</p><section class="${`workspace-drop ${this._drag?`dragging`:``}`}" aria-label="Workspace files"><strong>Drop workspace files here</strong><span>Encrypted exports, JSON, or compressed JSON. Encrypted files prompt for a password.</span><div class="actions"><button type="button" class="btn" ?disabled="${this._busy||!this._catalog}" @click="${()=>this._browse()}">Choose files</button> <button type="button" class="btn" ?disabled="${this._busy}" @click="${()=>this._chooseLocal()}">Choose local workspace</button></div></section>${this._localOpen?h`<section class="local-choice"><label for="local-workspace">Local workspace</label> <select id="local-workspace" .value="${this._localId}" ?disabled="${this._busy}" @change="${e=>{this._localId=e.target.value}}"><option value="">Choose a workspace…</option>${this._workspaces.map(e=>h`<option value="${e.id}">${e.name}</option>`)}</select> <button type="button" class="btn" ?disabled="${this._busy||!this._localId}" @click="${()=>this._readLocal()}">Select workspace</button> ${!this._busy&&this._workspaces.length===0?h`<p class="ui-hint">No unlocked local workspaces. Choose local workspace to unlock or refresh.</p>`:g}</section>`:g} ${e?h`<section class="import-preview" aria-label="Import options">${e.team?h`<p>Team ${e.team.name} has been created. Retry continues its remaining import steps.</p>`:g} <label for="import-team">New team name</label><input id="import-team" maxlength="100" .value="${e.name}" ?disabled="${this._busy||!!e.team}" @input="${t=>{e.name=t.target.value,this.requestUpdate()}}"><p>${e.reports.length} reports / links · ${n.size} source bundles · ${t} triaged findings</p><label for="import-repo">Repository for files and source bundles without an active repository</label> <select id="import-repo" .value="${String(this._repo??``)}" ?disabled="${this._busy||!!e.team}" @change="${e=>{this._repo=e.target.value?Number(e.target.value):null}}"><option value="" ?selected="${this._repo==null}">Choose a repository…</option>${(this._catalog?.repos??[]).map(e=>h`<option value="${String(e.repoId)}" ?selected="${this._repo===e.repoId}">${e.fullName}</option>`)}</select><p>Declared report repositories and directories are preserved. Stored reports without an active repository use the selected repository. The new team receives those repository paths; other published reports in the same paths are also visible to that team.</p><ul>${e.reports.map(e=>h`<li>${e.name}<span>${e.links?`Global deduplication — enabled for all teams`:e.github??`Uses selected repository`}${e.links||e.github==null||e.repoId!=null?``:e.embedded?` — connect this repository first`:` — not connected; uses selected repository`}</span></li>`)}</ul>${r.length>0?h`<p>Existing source bundles in active repositories keep their locations. The new team also receives access to those directories. Unassigned bundles and bundles in inactive repositories use the selected repository.</p><ul>${r.map(e=>h`<li>${e.filename}<span>${e.repoFullName?`${e.repoFullName}${e.repoDirectory?`/${e.repoDirectory}`:``}`:`Uses selected repository`}</span></li>`)}</ul>`:g} ${i?h`<p>${i} referenced source bundles have no bytes in this export. Reports can use matching bundles already on the server.</p>`:g} ${t?h`<fieldset ?disabled="${this._busy||!!e.team}"><legend>Import triage?</legend><label><input type="radio" name="import-triage" value="include" ?checked="${this._triage===`include`}" @change="${()=>{this._triage=`include`}}"> Include triage and comments</label> <label><input type="radio" name="import-triage" value="skip" ?checked="${this._triage===`skip`}" @change="${()=>{this._triage=`skip`}}"> Skip triage</label><p>Conflicting values prompt for resolution. Triage stays shared by finding ID across teams. Per-report local ignores are not imported.</p></fieldset>`:g} <button type="button" class="btn primary" ?disabled="${this._busy||!this._triage||!this._csrf}" @click="${()=>this._import()}">${this._busy?`Importing…`:e.team?`Retry remaining import`:`Import workspace`}</button></section>`:g} ${this._message?h`<p role="status">${this._message}</p>`:g} ${this._error?h`<p class="error" role="alert">${this._error}${this._catalog?g:h`<button class="btn" @click="${()=>this._loadCatalog()}">Retry</button>`}</p>`:g} ${this._files.length>0&&!this._busy?h`<button class="btn" @click="${()=>this._nextFile()}">Next workspace file (${this._files.length} waiting)</button>`:g}</div>`}}customElements.define(`managed-admin-import`,r)}export{Y as registerWorkspaceImport};
@@ -1,4 +1,4 @@
1
- import{b as e,d as t,i as n}from"./chunk-WB3NRZL7.js";import{a as r}from"./chunk-6VOB5WXX.js";import{A as i,B as a,a as o,b as s,c,d as l,e as u,f as d,g as ee,h as te,i as ne,j as re,k as ie,l as ae,m as oe,n as se,o as ce,p as le,q as ue,r as de,s as fe,t as pe,u as me,v as he,w as ge,x as _e,y as ve,z as ye}from"./chunk-Z54AXVCK.js";import"./chunk-6CCSTJWB.js";import{$a as be,H as xe,I as Se,Ka as Ce,Sa as we,Ta as Te,X as Ee,Ya as De,Za as Oe,a as ke,ab as Ae,bb as je,cb as Me,db as Ne,eb as f,fb as Pe,g as Fe,gb as p,hb as Ie,i as Le,ja as Re,ka as ze,m as Be,ma as Ve,n as m,z as He}from"./chunk-EMNIV37E.js";import{y as Ue}from"./chunk-OWIBDEJJ.js";import"./chunk-S5HSDGTP.js";import{b as We}from"./chunk-NRPC74AM.js";import"./chunk-PNHBZGDD.js";import{a as h,e as Ge}from"./chunk-74JZTGTO.js";import"./chunk-IYPY47MC.js";import{C as Ke,D as qe,d as g,h as Je,i as Ye,j as Xe,x as _,y as Ze}from"./chunk-ITUKKCCK.js";import{a as Qe,d as $e}from"./chunk-PWFUOLZK.js";import"./chunk-C4Z6ZBXV.js";import{m as et,r as tt}from"./chunk-XLX6XXJF.js";import{B as nt,D as rt,J as it}from"./chunk-QRKFPLA4.js";import{a as v,b as at,c as y,d as ot,g as b,j as st}from"./chunk-2XUEZHIP.js";import"./chunk-TUII34K2.js";import"./chunk-OOJM4CTU.js";function ct(e){let t=document.createElement(`input`);t.type=`file`,t.multiple=!0,t.addEventListener(`change`,()=>{e([...t.files])},{once:!0}),t.click()}function lt(e,t,n){let r=0,i=e=>Array.from(e.dataTransfer?.types??[]).includes(`Files`),a=e=>{i(e)&&(e.preventDefault(),r+=1,n(!0))},o=e=>{i(e)&&e.preventDefault()},s=e=>{i(e)&&(r=Math.max(0,r-1),r===0&&n(!1))},c=e=>{i(e)&&(e.preventDefault(),e.stopPropagation(),r=0,n(!1),t([...e.dataTransfer.files]))};return e.addEventListener(`dragenter`,a),e.addEventListener(`dragover`,o),e.addEventListener(`dragleave`,s),e.addEventListener(`drop`,c),()=>{e.removeEventListener(`dragenter`,a),e.removeEventListener(`dragover`,o),e.removeEventListener(`dragleave`,s),e.removeEventListener(`drop`,c)}}async function ut(e,t,n,r){let i=e.appState.generation;try{return await e.appState.mutate(()=>n(t),r)}catch(t){throw i===e.appState.generation&&e.appState.invalidate(r),t}}async function dt(e,t,n,r){if(e._busy||!e._csrf)throw Error(`Wait for the current operation to finish, then try again.`);e._busy=!0;try{await ut(e,t,n,r)}finally{await e._load(),e._busy=!1;let t=e._queue.splice(0);t.length>0&&e._upload(t)}}async function ft(e,t,n,r){if(t.length===0||(e._queue.push(...t),e._busy))return;e._busy=!0,e._error=null;let i=e.appState.generation,a=[],o=0;try{for(;e._queue.length>0;){if(e.appState.generation!==i){e._queue=[];break}let t=e._queue.shift();try{await ut(e,t,n,r)}catch(n){if(n?.name===`AbortError`||e.appState.generation!==i){e._queue=[];break}a.push(`${t.name}: ${String(n?.message??n)}`)}o++}}finally{a.length>0&&(e._error=o===1?`Upload failed: ${a[0]}`:`Upload failed for ${a.length} of ${o} files: ${a.join(`; `)}`),e._busy=!1,await e._load({preserveError:!0})}}var x=class extends st{static properties={session:{attribute:!1},allowShare:{attribute:!1},_loading:{state:!0},_data:{state:!0},_error:{state:!0}};constructor(){super(),this.session=null,this.allowShare=!1,this.appState=u,this._loading=!1,this._loadRequest=null,this._data=null,this._error=null}get _role(){return this.session?.role??null}get _csrf(){return this.session?.csrfToken??null}get _me(){return this.session?.id??null}connectedCallback(){super.connectedCallback(),this._load()}disconnectedCallback(){this._loadRequest?.abort(),super.disconnectedCallback()}async _load({preserveError:e=!1}={}){let{collection:t}=this.constructor;if(!t)return;e||(this._error=null);let[n,r,i]=t;await this._loadCollection(n,r,i,e=>this._show(e))}_show(e){this._data=e}async _loadCollection(e,t,n,r){this._loading=!0,await this._read(`_loadRequest`,e,t,n,{apply:r,settled:()=>{this._loading=!1},failed:t=>{this.appState.read(e)===void 0&&(this._error=String(t?.message??t))}})}async _read(e,t,n,r,{apply:i,answered:a,failed:o,settled:s}){this[e]?.abort();let c=this[e]=new AbortController;try{await this.appState.load(t,n,r,{signal:c.signal,apply:i}),c.signal.aborted||a?.()}catch(e){!c.signal.aborted&&e?.name!==`AbortError`&&o(e)}finally{this[e]===c&&s()}}_nav(){return Pe(this.constructor.view,this._role,this.allowShare)}_emit(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}_list(e,t,n){return y`<div class="manage-list" aria-busy="${this._loading}">${e==null?this._error?b:S(t):n()}</div>`}},pt=class{constructor(e,t=()=>!0){this.host=e,this.accepts=t,this.active=!1,e.addController(this)}hostConnected(){this.teardown=lt(this.host,e=>{this.accepts()&&this.host._upload(e)},e=>{this.active=this.accepts()&&e,this.host.requestUpdate()})}hostDisconnected(){this.teardown?.()}overlay(e){return this.active?y`<div class="dropzone">${e}</div>`:b}card(e,t,n,r=`Uploading…`){return y`<span class="drop-icon" aria-hidden="true">${p(`upload`)}</span><span class="drop-copy"><strong>${e}</strong><span>${t}</span></span><button type="button" class="drop-browse" ?disabled="${n}" @click="${()=>ct(e=>{this.host._upload(e)})}">${this.host._busy?r:`Browse files`}</button>`}};function S(e){return y`<div class="loading-rows" role="status"><span class="sr-only">${e}</span><div aria-hidden="true">${[0,1,2,3].map(()=>y`<div class="loading-row"><span></span><span></span></div>`)}</div></div>`}var C=e=>e?y`<p class="msg error" role="alert">${e}</p>`:b,w=(e,t)=>y`<div class="empty"><strong>${e}</strong><p>${t}</p></div>`;function mt(e){let t=e.split(`/`);return t.at(-1)===`stasis.config.json`&&!t.includes(`node_modules`)}var ht=class extends Te{get changeEvent(){return`local-item-change`}get searchLabel(){return`Search local files`}get optionsLabel(){return`Local files`}get noMatchesLabel(){return`No matching files.`}get emptyLabel(){return`No local files available.`}choices(){let e=this._query.trim().toLocaleLowerCase(),t=this.options.filter(t=>`${t.label} ${t.secondary??``}`.toLocaleLowerCase().includes(e));return{pinned:[],sections:[{options:t}],count:t.length,total:this.options.length,showFacets:!1}}};customElements.define(`managed-local-item-selector`,ht);var gt=class{constructor(e,t,n){this.host=e,this.kind=t,this.upload=n,this.source=null,this.hasData=!1,this.open=!1,this.options=[],this.value=null,this.busy=!1,this.loading=!1,this.error=``,this.success=``,this.generation=0,this.readAbort=null,this.onChange=e=>{if(e?.kind){if(e.kind!==this.kind)return;if(e.value!==this.value){this.refresh();return}}this.readAbort&&!this.readAbort.signal.aborted&&(this.readAbort.abort(),this.error=`The local ${this.kind} changed or the list was refreshed. Select it again before importing.`),this.options=[],this.value=null,this.success=``,this.refresh()},this.onBlur=()=>{this.readAbort&&!this.readAbort.signal.aborted&&this.onChange()},this.onVisibilityChange=()=>{globalThis.document?.visibilityState===`hidden`&&this.onBlur()},e.addController(this)}listeners(){return[[globalThis,`focus`,this.onChange],[globalThis,`blur`,this.onBlur],[globalThis,`storage`,this.onChange],[globalThis.document,`visibilitychange`,this.onVisibilityChange]]}hostConnected(){for(let[e,t,n]of this.listeners())e?.addEventListener(t,n);this.connectSource()}hostUpdated(){this.connectSource()}connectSource(){this.source!==this.host.localImportSource&&(this.unsubscribe?.(),this.abort?.abort(),this.source=this.host.localImportSource,this.unsubscribe=this.source?.subscribe(this.onChange),this.onChange())}hostDisconnected(){++this.generation,this.abort?.abort(),this.unsubscribe?.(),this.source=null;for(let[e,t,n]of this.listeners())e?.removeEventListener(t,n)}async refresh(){let e=++this.generation,t=this.source;this.loading=!0,this.host.requestUpdate();try{let n=t?await t.hasData(this.kind):!1;if(e!==this.generation)return;this.hasData=n;let r=this.open&&!t?.locked?await t?.list(this.kind)??[]:[];if(e!==this.generation)return;this.options=r,r.some(e=>e.value===this.value)||(this.value=null)}catch(t){e===this.generation&&(this.error=String(t?.message??t))}finally{e===this.generation&&(this.loading=!1,this.host.requestUpdate())}}toggle(){this.busy||(this.open=!this.open,this.error=``,this.success=``,this.options=[],this.value=null,this.refresh())}async busyWith(e){let t=this.abort=new AbortController;this.busy=!0,this.error=``,this.host.requestUpdate();try{await e(t)}catch(e){t.signal.aborted||(this.error=String(e?.message??e))}finally{this.readAbort===t&&(this.readAbort=null),this.busy=!1,this.host.requestUpdate()}}async unlock(){this.busy||await this.busyWith(async e=>{await this.source.unlock({signal:e.signal})&&!e.signal.aborted&&await this.refresh()})}async importSelected(){if(this.busy||this.loading||!this.value||this.source?.locked)return;this.success=``;let e=this.options.find(e=>e.value===this.value)?.label;await this.busyWith(async t=>{this.readAbort=t,await this.source.importItem(this.kind,this.value,e=>(this.readAbort=null,this.upload(e)),{signal:t.signal}),!t.signal.aborted&&!this.source?.locked&&(this.success=`Imported ${e}.`,this.value=null)})}renderAction(){return this.hasData||this.open?y`<button type="button" class="local-import-toggle" aria-expanded="${this.open}" aria-controls="local-import-panel" ?disabled="${this.busy}" @click="${()=>this.toggle()}">Import</button>`:b}renderPanel(e){if(!this.open)return b;let t=this.source?.locked;return y`<section class="local-import-panel" id="local-import-panel" aria-label="${`Import local ${this.kind}`}"><div class="local-import-copy"><strong>Import local ${this.kind}</strong><p>${t?`Unlock local data with your passkey to choose a file.`:`Copy a file from this browser to the managed workspace. The local copy stays on this device.`}</p></div><div class="local-import-controls">${t?y`<button type="button" class="local-import-submit" ?disabled="${this.busy}" @click="${()=>this.unlock()}">${this.busy?`Waiting for passkey…`:`Unlock with passkey`}</button>`:y`<managed-local-item-selector label="${`Choose local ${this.kind}`}" placeholder="${this.loading?`Loading local files…`:`Choose local ${this.kind}\u2026`}" .options="${this.options}" .value="${this.value}" ?disabled="${this.busy||this.loading}" @local-item-change="${e=>{this.value=e.detail.value,this.success=``,this.host.requestUpdate()}}"></managed-local-item-selector><button type="button" class="local-import-submit" ?disabled="${e||this.busy||this.loading||!this.value}" @click="${()=>this.importSelected()}">${this.busy?`Importing…`:`Import ${this.kind}`}</button>`} <button type="button" class="local-import-close" ?disabled="${this.busy}" @click="${()=>this.toggle()}">Close</button></div>${!t&&!this.loading&&this.options.length===0?y`<p class="local-import-message">No local ${this.kind}s available.</p>`:b} ${this.error?y`<p class="local-import-message error" role="alert">${this.error} <button type="button" ?disabled="${this.busy}" @click="${()=>{this.error=``,this.refresh()}}">Retry</button></p>`:b} ${this.success?y`<p class="local-import-message" role="status">${this.success}</p>`:b}</section>`}},T=e=>e?AbortSignal.any([e,u.sessionController.signal]):u.sessionController.signal,_t=()=>new DOMException(`Managed session changed`,`AbortError`),E=e=>e.json();async function vt({signal:e}={}){e=T(e),e.throwIfAborted();let t=await l(`/api/admin/bundles`,{credentials:`same-origin`,signal:e});if(e.throwIfAborted(),!t.ok)throw Object.assign(Error(`Bundle catalogue request failed (${t.status})`),{status:t.status});let n=await t.json();return e.throwIfAborted(),n.bundles??[]}async function D(e,t,n){let r=u.generation,i=await l(`/api/bundles/${encodeURIComponent(e)}/${t}`,{credentials:`same-origin`,signal:n});if(n?.throwIfAborted(),!i.ok)throw Object.assign(Error(`Bundle ${t} request failed (${i.status})`),{status:i.status});let a=t===`contents`?await i.text():await i.json();if(n?.throwIfAborted(),r!==u.generation)throw _t();return a}function yt(e,{signal:t}={}){return u.load(`bundle-metadata:${e}`,`bundle metadata`,t=>D(e,`metadata`,t),{signal:t,retryInvalidated:!0})}async function bt(e,{signal:t}={}){t=T(t);let n=await D(e,`metadata`,t),r=n?.bundle?.repo??null,i=rt({repo:r});if(!i)return r;let a=new URLSearchParams({repo:i,directory:r.directory??``}),o=new Set(n.unsized??[]),s=We((n.files??[]).filter(([e,t])=>t!=null||o.has(e)).map(([e])=>e));s&&a.set(`filePrefix`,s);let c=await l(`/api/admin/repositories/resolve?${a}`,{credentials:`same-origin`,cache:`no-store`,signal:t});if(t.throwIfAborted(),!c.ok)throw Error(`Repository suggestion request failed (${c.status})`);let{location:u}=await c.json();return t.throwIfAborted(),u?{...r,github:u.github,...u.mapped?{directory:u.directory}:{},repoId:u.repoId}:r}async function xt(e,{signal:t}={}){t=T(t);try{return await D(e,`contents`,t)}catch(e){throw e.name!==`AbortError`&&u.notify(`Couldn't load bundle contents: ${e.message}`),e}}function St(e,t,n=``,r=!1,i=!1){let a=n?`${n.startsWith(`entry:`)?`entry`:`reason`}=${encodeURIComponent(n.slice(n.indexOf(`:`)+1))}`:``,o=[t?`team=${encodeURIComponent(t)}`:``,a,r?`repoAdvisories=true`:``,i?`details=true`:``].filter(Boolean).join(`&`);return D(e,`advisories${o?`?${o}`:``}`,u.sessionController.signal)}var Ct={"patch-not-found":`The patch isn’t at the commit it was looked for at.`,"patch-mismatch":`The file at the commit the patch was read at isn’t the patch its lockfile names.`,"patch-unreadable":`The patch isn’t written as git writes one, so pnpm versions may apply it differently.`,"patch-unsupported":`The patch changes a file’s bytes, or gives it a mode other than 644 or 755, which isn’t reviewed here.`,"patch-does-not-apply":`The patch doesn’t apply to this version, though pnpm may still install part of it.`,"patch-too-large":`The patch is too large to read here.`,"no-repository":`The repository the patch is in isn’t available to you.`,"no-directory":`Only some of the repository the patch is in is available to you.`,"github-token-required":`Reading the patch needs your GitHub sign-in.`,"patch-not-kept":`The patch isn’t kept here: a review of a version it patches keeps it, as does a team’s Dependencies tab of its repository’s default branch.`},wt=e=>e?{patchHash:e.hash,...e.repoId==null?{}:{patchRepoId:String(e.repoId),patchCommit:e.commit},...e.path==null?{}:{patchPath:e.path}}:{},O={...Ct,"bad-tarball":`This package's tarball couldn't be read.`,"tarball-conflict":`This package's tarball isn't shown, as it doesn't install as one set of files: it holds two different files at one path, or at paths that are one on macOS or Windows, or a file within another, which installers each install their own way.`,"upstream-invalid":`The npm registry's answer for this package couldn't be read.`,"upstream-too-large":`The npm registry's answer for this package is too large to read here.`,400:`Not an npm package name and version.`,404:`No such package version, or it is not available to you.`,413:`This package is too large to open here.`,429:`Too many packages are loading. Try again shortly.`,502:`The npm registry couldn't be reached.`},Tt=15e3,k=new Map;function Et(e){if(k.has(e))return;let t=new AbortController,n=l(e,{credentials:`same-origin`,signal:AbortSignal.any([t.signal,u.sessionController.signal])});n.catch(()=>{});let r={reading:n,until:Date.now()+Tt,generation:u.generation};k.set(e,r),setTimeout(()=>{k.get(e)===r&&(k.delete(e),t.abort())},Tt)}function Dt(e,t){let n=k.get(e);return n?(k.delete(e),n.until>Date.now()&&n.generation===t?n.reading:null):null}var Ot=(e,t)=>new Promise((n,r)=>{let i=()=>r(t.reason);t.aborted?i():(t.addEventListener(`abort`,i,{once:!0}),e.then(n,r).finally(()=>t.removeEventListener(`abort`,i)))});async function A(e,t,n,r,i={}){r=T(r);let a=u.generation,o=()=>l(e,{credentials:`same-origin`,...i,signal:r}),s=i.method?null:Dt(e,a),c=s&&await Ot(s,r).then(e=>e.ok?e:null,e=>{if(r.aborted)throw e;return null})||await o();if(r.throwIfAborted(),!c.ok){let e=await c.json().catch(()=>null),n=e?.error??null;throw Object.assign(Error(t[n]??t[c.status]??`Request failed (${c.status})`),{status:c.status,code:n,...typeof e?.commit==`string`?{commit:e.commit}:{}})}let d=await n(c);if(r.throwIfAborted(),a!==u.generation)throw _t();return d}var j=(e,t,n)=>A(`/api/npm/${e}?${new URLSearchParams(t)}`,O,E,n),kt={"no-repository":`This repository is not available to you.`,"no-directory":`This directory is not at that commit, or not available to you.`,"directory-too-large":`This directory is too large to open here. Open one of its directories instead.`,"directory-unreadable":`GitHub’s archive of this directory couldn’t be read here, as when a symlink in it points outside the repository.`,"repository-busy":`Too many directories and packages are loading. Try again shortly.`,"repository-changed":`The repository changed while it was read. Try again.`,"github-rate-limited":`GitHub’s API rate limit has been reached. Try again later.`,"github-unauthorized":`GitHub authentication has expired or was revoked. Sign in again.`,"github-status-403":`GitHub denied this request. Check repository access and the GitHub App’s read permissions.`,"github-malformed":`GitHub’s archive of this directory could not be verified against its commit.`,"github-unreachable":`Could not connect to GitHub. Try again shortly.`,"github-moved":`GitHub moved this repository, as when it is renamed. Try again shortly.`,"github-timeout":`GitHub took too long to answer. Try again shortly.`,400:`Not a repository directory and commit.`,403:`Repository access is required to read its files.`,404:`This repository, commit or directory is unavailable.`,413:`This directory is too large to open here.`,429:`Too many directories and packages are loading. Try again shortly.`,502:`GitHub couldn’t be reached.`},M=(e,t,n,r=kt)=>A(`/api/admin/repositories/${e}?${new URLSearchParams(t)}`,r,E,n);function At(e,t,n,{signal:r}={}){return M(`code`,{repoId:e,ref:t,path:n},r)}async function jt({signal:e}={}){return(await M(`browsable`,{},e)).repos??[]}function Mt(e,{signal:t}={}){return M(`refs`,{repoId:e},t)}function Nt(e,t,n,{signal:r,commitOnly:i=!1}={}){return M(`contents`,{repoId:e,ref:t,path:n,...i?{listing:`none`}:{}},r)}var Pt={...kt,"no-directory":`This directory’s history is not available to you.`,"github-malformed":`GitHub answered with a history that couldn’t be read.`,"github-token-required":`Reading every branch needs your GitHub sign-in.`,400:`Not a repository’s history.`};function Ft(e,t,n,{page:r=1,all:i=!1,fresh:a=!1,from:o=null,signal:s}={}){return M(`history`,{repoId:e,ref:t,path:n,page:r,...i?{all:`true`}:{},...a?{fresh:`true`}:{},...o?{from:o.join(`,`)}:{}},s,Pt)}var It={...Pt,"no-directory":`This directory’s changes are not available to you.`,"github-malformed":`GitHub answered with a commit’s files that couldn’t be read.`,400:`Not a repository’s commits.`};function Lt(e,t,n,{signal:r}={}){return M(`changes`,{repoId:e,path:t,shas:n.join(`,`)},r,It)}function Rt(e,t,n,{signal:r}={}){return M(`tree`,{repoId:e,path:t,commit:n},r,It)}var N={...kt,"no-directory":`Issues and pull requests show only with access to the whole repository.`,"github-malformed":`GitHub answered with a list that couldn’t be read.`,"github-token-required":`Reading issues and pull requests needs your GitHub sign-in.`,"github-status-403":`GitHub refused to list these. The GitHub App reading this repository needs Issues: read and Pull requests: read, which an owner of its installation approves.`,400:`Not a repository’s issues or pull requests.`},zt=(e,t,n,r)=>`/api/admin/repositories/issues?${new URLSearchParams({repoId:e,kind:t,state:n,...r?{after:r}:{}})}`;function Bt(e,t,{state:n=`open`,after:r=null,signal:i}={}){return A(zt(e,t,n,r),N,E,i)}var Vt={...N,"no-directory":`Agents show only with access to the whole repository.`,"github-token-required":`Reading what the agents did needs your GitHub sign-in.`,400:`Not a repository’s agents.`},Ht=(e,t,n)=>`/api/admin/repositories/agents?${new URLSearchParams({repoId:e,...t?{pulls:t}:{},...n?{commits:n}:{}})}`;function Ut(e,{pulls:t=null,commits:n=null,signal:r}={}){return A(Ht(e,t,n),Vt,E,r)}var Wt={...N,"github-not-found":`GitHub has no issue or pull request of that number here.`,400:`Not an issue or pull request of a repository.`};function Gt(e,t,{signal:n}={}){return M(`item`,{repoId:e,number:t},n,Wt)}var Kt={...Wt,"github-not-found":`GitHub has no pull request of that number here.`,"github-malformed":`GitHub answered with a pull request or lockfile that couldn’t be read.`,"github-status-403":`GitHub refused to read its lockfiles. The GitHub App reading this repository needs Contents: read and Pull requests: read, which an owner of its installation approves.`,400:`Not a pull request of a repository.`},qt=({review:e,listed:t})=>({...e?{review:`1`}:{},...t?{listed:`1`}:{}});function Jt(e,t,{review:n=!1,listed:r=!1,signal:i}={}){return M(`pull-dependencies`,{repoId:e,number:t,...qt({review:n,listed:r})},i,Kt)}async function Yt(e,t,{review:n=!1,listed:r=!1,signal:i}={}){let{pulls:a,users:o,deltas:s}=await M(`pull-dependencies`,{repoId:e,numbers:t.join(`,`),...qt({review:n,listed:r})},i,Kt);return Xt(a,o,s)}var Xt=(e,t,n)=>new Map((Array.isArray(e)?e:[]).filter(e=>Number.isSafeInteger(e?.number)).map(e=>[e.number,typeof e.error==`string`?Object.assign(Error(Kt[e.error]??`It couldn\u2019t be read (${e.error}).`),{code:e.error}):{...e,...t?{users:t}:{},...Array.isArray(n)&&n.length>0?{deltas:n}:{}}])),Zt={...Wt,"github-not-found":`GitHub has none of a lockfile it lists on the default branch.`,"github-malformed":`GitHub answered with a lockfile that couldn’t be read.`,"github-status-403":`GitHub refused to read its lockfiles. The GitHub App reading this repository needs Contents: read, which an owner of its installation approves.`,400:`Not a repository.`},Qt={...Zt,"no-bundle":`This bundle is not available to you.`,"bundle-unavailable":`This bundle’s packages couldn’t be read.`,"directory-package-malformed":`This bundle records a package installed from a directory with an integrity, or naming no directory.`,"payload-too-large":`This bundle holds too many packages to check here.`,"repository-changed":`The bundle or its repository changed while it was read. Try again.`,"github-not-found":`GitHub has none of the commit this bundle was built from, or of a lockfile it lists there.`,400:`Not a bundle.`};function $t(e,{signal:t}={}){return A(`/api/bundles/${encodeURIComponent(e)}/dependency-review`,Qt,E,t)}var en={...Qt,"unsupported-bundle":`Only Stasis bundles are validated.`,"validation-busy":`Other bundles are being validated. Try again shortly.`,"validation-failed":`The validation failed. Try again.`,"csrf-missing":`Your session is missing its request token. Reload the page.`,"csrf-mismatch":`Your session changed. Reload the page.`,429:`Other bundles are being validated. Try again shortly.`},tn=e=>`/api/bundles/${encodeURIComponent(e)}/validation`;function nn(e,{signal:t}={}){return A(tn(e),en,E,t)}function rn(e,t,{signal:n}={}){return A(tn(e),en,e=>e.json().catch(()=>null),n,{method:`POST`,headers:{"x-csrf-token":t}})}var an={"no-team":`This team is not available to you.`,400:`Not a team’s repositories.`},on=`GitHub failed to answer. Try again shortly.`,sn={...N,"github-status-502":on,"github-status-504":on,"time-up":`Reading them took too long.`},cn=e=>`Not all its open pull requests were read. ${sn[e]??`(${e})`}`;function ln(e,t,{repoIds:n=null,kept:r=!1,signal:i}={}){let a=new URLSearchParams({...n?{repoIds:n.join(`,`)}:{},...r?{kept:`1`}:{}}),o=a.size>0?`?${a}`:``;return A(`/api/teams/${encodeURIComponent(e)}/dependencies${o}`,an,async e=>{for await(let n of On(e))typeof n.error==`string`?t({...n,error:Zt[n.error]??Zt[n.status]??`It couldn\u2019t be read (${n.error}).`,code:n.error}):t({...n,...Array.isArray(n.dependencies)?{dependencies:Xt(n.dependencies,n.users)}:{},...typeof n.pulls?.error==`string`?{pulls:{...n.pulls,error:cn(n.pulls.error)}}:{}})},i)}function un(e,t,n,r,{signal:i}={}){let a=JSON.stringify({since:t,versions:n.map(({name:e,version:t})=>[e,t])});return A(`/api/teams/${encodeURIComponent(e)}/dependency-reviews/changed`,an,e=>e.json().then(e=>({now:Number.isSafeInteger(e?.now)?e.now:null,versions:Array.isArray(e?.versions)?e.versions.flatMap(e=>Array.isArray(e)&&typeof e[0]==`string`&&typeof e[1]==`string`?[{name:e[0],version:e[1]}]:[]):[]})),i,{method:`POST`,headers:{"content-type":`application/json`,"x-csrf-token":r},body:a})}var dn={...N,"no-directory":`Pulse shows only with access to the whole repository.`,"github-malformed":`GitHub answered with statistics that couldn’t be read.`,"github-token-required":`Reading a repository’s pulse needs your GitHub sign-in.`,"github-status-403":`GitHub refused to read these. The GitHub App reading this repository needs Contents, Issues and Pull requests: read, which an owner of its installation approves.`,400:`Not a repository’s pulse.`},fn=(e,t)=>`/api/admin/repositories/pulse?${new URLSearchParams({repoId:e,weeks:t})}`;function pn(e,t,{signal:n}={}){return A(fn(e,t),dn,E,n)}function mn(e,t,{state:n=`open`,weeks:r=4}={}){t===`issues`||t===`pulls`?Et(zt(e,t,n,null)):t===`agents`?Et(Ht(e,null,null)):t===`pulse`&&Et(fn(e,r))}function hn(e,t,{from:n,to:r=null,authors:i=[]},{signal:a}={}){return M(`pulse/items`,{repoId:e,weeks:t,from:n,...r===null?{}:{to:r},...i.length>0?{authors:i.join(`,`)}:{}},a,dn)}function gn(e,t,{signal:n,patch:r=null}={}){return j(`package`,{name:e,version:t,...wt(r)},n)}function _n(e,{signal:t}={}){return j(`versions`,{name:e},t)}function vn(e,{signal:t}={}){return j(`stats`,{name:e},t)}function yn(e,{signal:t}={}){return j(`advisories`,{name:e},t)}function bn(e,t,{signal:n}={}){return j(`tags`,{name:e,version:t},n)}function xn(e,t,{signal:n}={}){return j(`socket`,{name:e,version:t},n)}function Sn(e,t,n=null,{signal:r}={}){return j(`risk`,{name:e,version:t,...n===null?{}:{otherVersion:n}},r)}function Cn(e,t,{signal:n}={}){return j(`provenance`,{name:e,version:t},n)}var P={404:`This file is no longer available.`,409:`This file has changed since it was opened.`,413:`This file is too large to pretty-print.`,422:`This file couldn't be read as code.`,"pretty-mismatch":`Pretty-printing would change more than its layout, so it is shown as published.`,unsupported:`This kind of file can't be checked once pretty-printed, so it is shown as published.`,429:`Too many files are being pretty-printed. Try again shortly.`,502:`The npm registry couldn't be reached.`};function wn(e,t,n,{signal:r}={}){return A(`/api/bundles/${encodeURIComponent(e)}/pretty?${new URLSearchParams({path:t,hash:n})}`,P,En,r)}function Tn(e,t,n,r,{signal:i}={}){return A(`/api/npm/pretty?${new URLSearchParams({name:e,version:t,path:n,hash:r})}`,{...O,...P},En,i)}var En=async e=>({...await e.json(),source:e.headers.get(`x-source-hash`)});async function*Dn(e){let t=e.body.pipeThrough(new TextDecoderStream).getReader(),n=[];for(;;){let{done:e,value:r}=await t.read();if(e)return;let i=0;for(let e=r.indexOf(`
1
+ import{b as e,d as t,i as n}from"./chunk-5CJKUV53.js";import{a as r}from"./chunk-6VOB5WXX.js";import{A as i,B as a,a as o,b as s,c,d as l,e as u,f as d,g as ee,h as te,i as ne,j as re,k as ie,l as ae,m as oe,n as se,o as ce,p as le,q as ue,r as de,s as fe,t as pe,u as me,v as he,w as ge,x as _e,y as ve,z as ye}from"./chunk-GBMAXAYK.js";import"./chunk-6CCSTJWB.js";import{$a as be,H as xe,I as Se,Ka as Ce,Sa as we,Ta as Te,X as Ee,Ya as De,Za as Oe,a as ke,ab as Ae,bb as je,cb as Me,db as Ne,eb as f,fb as Pe,g as Fe,gb as p,hb as Ie,i as Le,ja as Re,ka as ze,m as Be,ma as Ve,n as m,z as He}from"./chunk-DUS5ARE2.js";import{y as Ue}from"./chunk-5M2X3QPK.js";import"./chunk-DUASGS2O.js";import{b as We}from"./chunk-NRPC74AM.js";import"./chunk-PNHBZGDD.js";import{a as h,e as Ge}from"./chunk-74JZTGTO.js";import"./chunk-IYPY47MC.js";import{C as Ke,D as qe,d as g,h as Je,i as Ye,j as Xe,x as _,y as Ze}from"./chunk-ITUKKCCK.js";import{a as Qe,d as $e}from"./chunk-PWFUOLZK.js";import"./chunk-C4Z6ZBXV.js";import{m as et,s as tt}from"./chunk-LBD3M3J6.js";import{B as nt,D as rt,J as it}from"./chunk-QRKFPLA4.js";import{a as v,b as at,c as y,d as ot,g as b,j as st}from"./chunk-2XUEZHIP.js";import"./chunk-TUII34K2.js";import"./chunk-OOJM4CTU.js";function ct(e){let t=document.createElement(`input`);t.type=`file`,t.multiple=!0,t.addEventListener(`change`,()=>{e([...t.files])},{once:!0}),t.click()}function lt(e,t,n){let r=0,i=e=>Array.from(e.dataTransfer?.types??[]).includes(`Files`),a=e=>{i(e)&&(e.preventDefault(),r+=1,n(!0))},o=e=>{i(e)&&e.preventDefault()},s=e=>{i(e)&&(r=Math.max(0,r-1),r===0&&n(!1))},c=e=>{i(e)&&(e.preventDefault(),e.stopPropagation(),r=0,n(!1),t([...e.dataTransfer.files]))};return e.addEventListener(`dragenter`,a),e.addEventListener(`dragover`,o),e.addEventListener(`dragleave`,s),e.addEventListener(`drop`,c),()=>{e.removeEventListener(`dragenter`,a),e.removeEventListener(`dragover`,o),e.removeEventListener(`dragleave`,s),e.removeEventListener(`drop`,c)}}async function ut(e,t,n,r){let i=e.appState.generation;try{return await e.appState.mutate(()=>n(t),r)}catch(t){throw i===e.appState.generation&&e.appState.invalidate(r),t}}async function dt(e,t,n,r){if(e._busy||!e._csrf)throw Error(`Wait for the current operation to finish, then try again.`);e._busy=!0;try{await ut(e,t,n,r)}finally{await e._load(),e._busy=!1;let t=e._queue.splice(0);t.length>0&&e._upload(t)}}async function ft(e,t,n,r){if(t.length===0||(e._queue.push(...t),e._busy))return;e._busy=!0,e._error=null;let i=e.appState.generation,a=[],o=0;try{for(;e._queue.length>0;){if(e.appState.generation!==i){e._queue=[];break}let t=e._queue.shift();try{await ut(e,t,n,r)}catch(n){if(n?.name===`AbortError`||e.appState.generation!==i){e._queue=[];break}a.push(`${t.name}: ${String(n?.message??n)}`)}o++}}finally{a.length>0&&(e._error=o===1?`Upload failed: ${a[0]}`:`Upload failed for ${a.length} of ${o} files: ${a.join(`; `)}`),e._busy=!1,await e._load({preserveError:!0})}}var x=class extends st{static properties={session:{attribute:!1},allowShare:{attribute:!1},_loading:{state:!0},_data:{state:!0},_error:{state:!0}};constructor(){super(),this.session=null,this.allowShare=!1,this.appState=u,this._loading=!1,this._loadRequest=null,this._data=null,this._error=null}get _role(){return this.session?.role??null}get _csrf(){return this.session?.csrfToken??null}get _me(){return this.session?.id??null}connectedCallback(){super.connectedCallback(),this._load()}disconnectedCallback(){this._loadRequest?.abort(),super.disconnectedCallback()}async _load({preserveError:e=!1}={}){let{collection:t}=this.constructor;if(!t)return;e||(this._error=null);let[n,r,i]=t;await this._loadCollection(n,r,i,e=>this._show(e))}_show(e){this._data=e}async _loadCollection(e,t,n,r){this._loading=!0,await this._read(`_loadRequest`,e,t,n,{apply:r,settled:()=>{this._loading=!1},failed:t=>{this.appState.read(e)===void 0&&(this._error=String(t?.message??t))}})}async _read(e,t,n,r,{apply:i,answered:a,failed:o,settled:s}){this[e]?.abort();let c=this[e]=new AbortController;try{await this.appState.load(t,n,r,{signal:c.signal,apply:i}),c.signal.aborted||a?.()}catch(e){!c.signal.aborted&&e?.name!==`AbortError`&&o(e)}finally{this[e]===c&&s()}}_nav(){return Pe(this.constructor.view,this._role,this.allowShare)}_emit(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}_list(e,t,n){return y`<div class="manage-list" aria-busy="${this._loading}">${e==null?this._error?b:S(t):n()}</div>`}},pt=class{constructor(e,t=()=>!0){this.host=e,this.accepts=t,this.active=!1,e.addController(this)}hostConnected(){this.teardown=lt(this.host,e=>{this.accepts()&&this.host._upload(e)},e=>{this.active=this.accepts()&&e,this.host.requestUpdate()})}hostDisconnected(){this.teardown?.()}overlay(e){return this.active?y`<div class="dropzone">${e}</div>`:b}card(e,t,n,r=`Uploading…`){return y`<span class="drop-icon" aria-hidden="true">${p(`upload`)}</span><span class="drop-copy"><strong>${e}</strong><span>${t}</span></span><button type="button" class="drop-browse" ?disabled="${n}" @click="${()=>ct(e=>{this.host._upload(e)})}">${this.host._busy?r:`Browse files`}</button>`}};function S(e){return y`<div class="loading-rows" role="status"><span class="sr-only">${e}</span><div aria-hidden="true">${[0,1,2,3].map(()=>y`<div class="loading-row"><span></span><span></span></div>`)}</div></div>`}var C=e=>e?y`<p class="msg error" role="alert">${e}</p>`:b,w=(e,t)=>y`<div class="empty"><strong>${e}</strong><p>${t}</p></div>`;function mt(e){let t=e.split(`/`);return t.at(-1)===`stasis.config.json`&&!t.includes(`node_modules`)}var ht=class extends Te{get changeEvent(){return`local-item-change`}get searchLabel(){return`Search local files`}get optionsLabel(){return`Local files`}get noMatchesLabel(){return`No matching files.`}get emptyLabel(){return`No local files available.`}choices(){let e=this._query.trim().toLocaleLowerCase(),t=this.options.filter(t=>`${t.label} ${t.secondary??``}`.toLocaleLowerCase().includes(e));return{pinned:[],sections:[{options:t}],count:t.length,total:this.options.length,showFacets:!1}}};customElements.define(`managed-local-item-selector`,ht);var gt=class{constructor(e,t,n){this.host=e,this.kind=t,this.upload=n,this.source=null,this.hasData=!1,this.open=!1,this.options=[],this.value=null,this.busy=!1,this.loading=!1,this.error=``,this.success=``,this.generation=0,this.readAbort=null,this.onChange=e=>{if(e?.kind){if(e.kind!==this.kind)return;if(e.value!==this.value){this.refresh();return}}this.readAbort&&!this.readAbort.signal.aborted&&(this.readAbort.abort(),this.error=`The local ${this.kind} changed or the list was refreshed. Select it again before importing.`),this.options=[],this.value=null,this.success=``,this.refresh()},this.onBlur=()=>{this.readAbort&&!this.readAbort.signal.aborted&&this.onChange()},this.onVisibilityChange=()=>{globalThis.document?.visibilityState===`hidden`&&this.onBlur()},e.addController(this)}listeners(){return[[globalThis,`focus`,this.onChange],[globalThis,`blur`,this.onBlur],[globalThis,`storage`,this.onChange],[globalThis.document,`visibilitychange`,this.onVisibilityChange]]}hostConnected(){for(let[e,t,n]of this.listeners())e?.addEventListener(t,n);this.connectSource()}hostUpdated(){this.connectSource()}connectSource(){this.source!==this.host.localImportSource&&(this.unsubscribe?.(),this.abort?.abort(),this.source=this.host.localImportSource,this.unsubscribe=this.source?.subscribe(this.onChange),this.onChange())}hostDisconnected(){++this.generation,this.abort?.abort(),this.unsubscribe?.(),this.source=null;for(let[e,t,n]of this.listeners())e?.removeEventListener(t,n)}async refresh(){let e=++this.generation,t=this.source;this.loading=!0,this.host.requestUpdate();try{let n=t?await t.hasData(this.kind):!1;if(e!==this.generation)return;this.hasData=n;let r=this.open&&!t?.locked?await t?.list(this.kind)??[]:[];if(e!==this.generation)return;this.options=r,r.some(e=>e.value===this.value)||(this.value=null)}catch(t){e===this.generation&&(this.error=String(t?.message??t))}finally{e===this.generation&&(this.loading=!1,this.host.requestUpdate())}}toggle(){this.busy||(this.open=!this.open,this.error=``,this.success=``,this.options=[],this.value=null,this.refresh())}async busyWith(e){let t=this.abort=new AbortController;this.busy=!0,this.error=``,this.host.requestUpdate();try{await e(t)}catch(e){t.signal.aborted||(this.error=String(e?.message??e))}finally{this.readAbort===t&&(this.readAbort=null),this.busy=!1,this.host.requestUpdate()}}async unlock(){this.busy||await this.busyWith(async e=>{await this.source.unlock({signal:e.signal})&&!e.signal.aborted&&await this.refresh()})}async importSelected(){if(this.busy||this.loading||!this.value||this.source?.locked)return;this.success=``;let e=this.options.find(e=>e.value===this.value)?.label;await this.busyWith(async t=>{this.readAbort=t,await this.source.importItem(this.kind,this.value,e=>(this.readAbort=null,this.upload(e)),{signal:t.signal}),!t.signal.aborted&&!this.source?.locked&&(this.success=`Imported ${e}.`,this.value=null)})}renderAction(){return this.hasData||this.open?y`<button type="button" class="local-import-toggle" aria-expanded="${this.open}" aria-controls="local-import-panel" ?disabled="${this.busy}" @click="${()=>this.toggle()}">Import</button>`:b}renderPanel(e){if(!this.open)return b;let t=this.source?.locked;return y`<section class="local-import-panel" id="local-import-panel" aria-label="${`Import local ${this.kind}`}"><div class="local-import-copy"><strong>Import local ${this.kind}</strong><p>${t?`Unlock local data with your passkey to choose a file.`:`Copy a file from this browser to the managed workspace. The local copy stays on this device.`}</p></div><div class="local-import-controls">${t?y`<button type="button" class="local-import-submit" ?disabled="${this.busy}" @click="${()=>this.unlock()}">${this.busy?`Waiting for passkey…`:`Unlock with passkey`}</button>`:y`<managed-local-item-selector label="${`Choose local ${this.kind}`}" placeholder="${this.loading?`Loading local files…`:`Choose local ${this.kind}\u2026`}" .options="${this.options}" .value="${this.value}" ?disabled="${this.busy||this.loading}" @local-item-change="${e=>{this.value=e.detail.value,this.success=``,this.host.requestUpdate()}}"></managed-local-item-selector><button type="button" class="local-import-submit" ?disabled="${e||this.busy||this.loading||!this.value}" @click="${()=>this.importSelected()}">${this.busy?`Importing…`:`Import ${this.kind}`}</button>`} <button type="button" class="local-import-close" ?disabled="${this.busy}" @click="${()=>this.toggle()}">Close</button></div>${!t&&!this.loading&&this.options.length===0?y`<p class="local-import-message">No local ${this.kind}s available.</p>`:b} ${this.error?y`<p class="local-import-message error" role="alert">${this.error} <button type="button" ?disabled="${this.busy}" @click="${()=>{this.error=``,this.refresh()}}">Retry</button></p>`:b} ${this.success?y`<p class="local-import-message" role="status">${this.success}</p>`:b}</section>`}},T=e=>e?AbortSignal.any([e,u.sessionController.signal]):u.sessionController.signal,_t=()=>new DOMException(`Managed session changed`,`AbortError`),E=e=>e.json();async function vt({signal:e}={}){e=T(e),e.throwIfAborted();let t=await l(`/api/admin/bundles`,{credentials:`same-origin`,signal:e});if(e.throwIfAborted(),!t.ok)throw Object.assign(Error(`Bundle catalogue request failed (${t.status})`),{status:t.status});let n=await t.json();return e.throwIfAborted(),n.bundles??[]}async function D(e,t,n){let r=u.generation,i=await l(`/api/bundles/${encodeURIComponent(e)}/${t}`,{credentials:`same-origin`,signal:n});if(n?.throwIfAborted(),!i.ok)throw Object.assign(Error(`Bundle ${t} request failed (${i.status})`),{status:i.status});let a=t===`contents`?await i.text():await i.json();if(n?.throwIfAborted(),r!==u.generation)throw _t();return a}function yt(e,{signal:t}={}){return u.load(`bundle-metadata:${e}`,`bundle metadata`,t=>D(e,`metadata`,t),{signal:t,retryInvalidated:!0})}async function bt(e,{signal:t}={}){t=T(t);let n=await D(e,`metadata`,t),r=n?.bundle?.repo??null,i=rt({repo:r});if(!i)return r;let a=new URLSearchParams({repo:i,directory:r.directory??``}),o=new Set(n.unsized??[]),s=We((n.files??[]).filter(([e,t])=>t!=null||o.has(e)).map(([e])=>e));s&&a.set(`filePrefix`,s);let c=await l(`/api/admin/repositories/resolve?${a}`,{credentials:`same-origin`,cache:`no-store`,signal:t});if(t.throwIfAborted(),!c.ok)throw Error(`Repository suggestion request failed (${c.status})`);let{location:u}=await c.json();return t.throwIfAborted(),u?{...r,github:u.github,...u.mapped?{directory:u.directory}:{},repoId:u.repoId}:r}async function xt(e,{signal:t}={}){t=T(t);try{return await D(e,`contents`,t)}catch(e){throw e.name!==`AbortError`&&u.notify(`Couldn't load bundle contents: ${e.message}`),e}}function St(e,t,n=``,r=!1,i=!1){let a=n?`${n.startsWith(`entry:`)?`entry`:`reason`}=${encodeURIComponent(n.slice(n.indexOf(`:`)+1))}`:``,o=[t?`team=${encodeURIComponent(t)}`:``,a,r?`repoAdvisories=true`:``,i?`details=true`:``].filter(Boolean).join(`&`);return D(e,`advisories${o?`?${o}`:``}`,u.sessionController.signal)}var Ct={"patch-not-found":`The patch isn’t at the commit it was looked for at.`,"patch-mismatch":`The file at the commit the patch was read at isn’t the patch its lockfile names.`,"patch-unreadable":`The patch is written so that pnpm versions, or macOS and Windows, may apply it differently.`,"patch-unsupported":`The patch changes a file’s bytes, or gives it a mode other than 644 or 755, which isn’t reviewed here.`,"patch-does-not-apply":`The patch doesn’t apply to this version, though pnpm may still install part of it.`,"patch-too-large":`The patch is too large to read here.`,"no-repository":`The repository the patch is in isn’t available to you.`,"no-directory":`Only some of the repository the patch is in is available to you.`,"github-token-required":`Reading the patch needs your GitHub sign-in.`,"patch-not-kept":`The patch isn’t kept here: a review of a version it patches keeps it, as does a team’s Dependencies tab of its repository’s default branch.`},wt=e=>e?{patchHash:e.hash,...e.repoId==null?{}:{patchRepoId:String(e.repoId),patchCommit:e.commit},...e.path==null?{}:{patchPath:e.path}}:{},O={...Ct,"bad-tarball":`This package's tarball couldn't be read.`,"tarball-conflict":`This package's tarball isn't shown, as it doesn't install as one set of files: it holds two different files at one path, or at paths that are one on macOS or Windows, or a file within another, which installers each install their own way.`,"upstream-invalid":`The npm registry's answer for this package couldn't be read.`,"upstream-too-large":`The npm registry's answer for this package is too large to read here.`,400:`Not an npm package name and version.`,404:`No such package version, or it is not available to you.`,413:`This package is too large to open here.`,429:`Too many packages are loading. Try again shortly.`,502:`The npm registry couldn't be reached.`},Tt=15e3,k=new Map;function Et(e){if(k.has(e))return;let t=new AbortController,n=l(e,{credentials:`same-origin`,signal:AbortSignal.any([t.signal,u.sessionController.signal])});n.catch(()=>{});let r={reading:n,until:Date.now()+Tt,generation:u.generation};k.set(e,r),setTimeout(()=>{k.get(e)===r&&(k.delete(e),t.abort())},Tt)}function Dt(e,t){let n=k.get(e);return n?(k.delete(e),n.until>Date.now()&&n.generation===t?n.reading:null):null}var Ot=(e,t)=>new Promise((n,r)=>{let i=()=>r(t.reason);t.aborted?i():(t.addEventListener(`abort`,i,{once:!0}),e.then(n,r).finally(()=>t.removeEventListener(`abort`,i)))});async function A(e,t,n,r,i={}){r=T(r);let a=u.generation,o=()=>l(e,{credentials:`same-origin`,...i,signal:r}),s=i.method?null:Dt(e,a),c=s&&await Ot(s,r).then(e=>e.ok?e:null,e=>{if(r.aborted)throw e;return null})||await o();if(r.throwIfAborted(),!c.ok){let e=await c.json().catch(()=>null),n=e?.error??null;throw Object.assign(Error(t[n]??t[c.status]??`Request failed (${c.status})`),{status:c.status,code:n,...typeof e?.commit==`string`?{commit:e.commit}:{}})}let d=await n(c);if(r.throwIfAborted(),a!==u.generation)throw _t();return d}var j=(e,t,n)=>A(`/api/npm/${e}?${new URLSearchParams(t)}`,O,E,n),kt={"no-repository":`This repository is not available to you.`,"no-directory":`This directory is not at that commit, or not available to you.`,"directory-too-large":`This directory is too large to open here. Open one of its directories instead.`,"directory-unreadable":`GitHub’s archive of this directory couldn’t be read here, as when a symlink in it points outside the repository.`,"repository-busy":`Too many directories and packages are loading. Try again shortly.`,"repository-changed":`The repository changed while it was read. Try again.`,"github-rate-limited":`GitHub’s API rate limit has been reached. Try again later.`,"github-unauthorized":`GitHub authentication has expired or was revoked. Sign in again.`,"github-status-403":`GitHub denied this request. Check repository access and the GitHub App’s read permissions.`,"github-malformed":`GitHub’s archive of this directory could not be verified against its commit.`,"github-unreachable":`Could not connect to GitHub. Try again shortly.`,"github-moved":`GitHub moved this repository, as when it is renamed. Try again shortly.`,"github-timeout":`GitHub took too long to answer. Try again shortly.`,400:`Not a repository directory and commit.`,403:`Repository access is required to read its files.`,404:`This repository, commit or directory is unavailable.`,413:`This directory is too large to open here.`,429:`Too many directories and packages are loading. Try again shortly.`,502:`GitHub couldn’t be reached.`},M=(e,t,n,r=kt)=>A(`/api/admin/repositories/${e}?${new URLSearchParams(t)}`,r,E,n);function At(e,t,n,{signal:r}={}){return M(`code`,{repoId:e,ref:t,path:n},r)}async function jt({signal:e}={}){return(await M(`browsable`,{},e)).repos??[]}function Mt(e,{signal:t}={}){return M(`refs`,{repoId:e},t)}function Nt(e,t,n,{signal:r,commitOnly:i=!1}={}){return M(`contents`,{repoId:e,ref:t,path:n,...i?{listing:`none`}:{}},r)}var Pt={...kt,"no-directory":`This directory’s history is not available to you.`,"github-malformed":`GitHub answered with a history that couldn’t be read.`,"github-token-required":`Reading every branch needs your GitHub sign-in.`,400:`Not a repository’s history.`};function Ft(e,t,n,{page:r=1,all:i=!1,fresh:a=!1,from:o=null,signal:s}={}){return M(`history`,{repoId:e,ref:t,path:n,page:r,...i?{all:`true`}:{},...a?{fresh:`true`}:{},...o?{from:o.join(`,`)}:{}},s,Pt)}var It={...Pt,"no-directory":`This directory’s changes are not available to you.`,"github-malformed":`GitHub answered with a commit’s files that couldn’t be read.`,400:`Not a repository’s commits.`};function Lt(e,t,n,{signal:r}={}){return M(`changes`,{repoId:e,path:t,shas:n.join(`,`)},r,It)}function Rt(e,t,n,{signal:r}={}){return M(`tree`,{repoId:e,path:t,commit:n},r,It)}var N={...kt,"no-directory":`Issues and pull requests show only with access to the whole repository.`,"github-malformed":`GitHub answered with a list that couldn’t be read.`,"github-token-required":`Reading issues and pull requests needs your GitHub sign-in.`,"github-status-403":`GitHub refused to list these. The GitHub App reading this repository needs Issues: read and Pull requests: read, which an owner of its installation approves.`,400:`Not a repository’s issues or pull requests.`},zt=(e,t,n,r)=>`/api/admin/repositories/issues?${new URLSearchParams({repoId:e,kind:t,state:n,...r?{after:r}:{}})}`;function Bt(e,t,{state:n=`open`,after:r=null,signal:i}={}){return A(zt(e,t,n,r),N,E,i)}var Vt={...N,"no-directory":`Agents show only with access to the whole repository.`,"github-token-required":`Reading what the agents did needs your GitHub sign-in.`,400:`Not a repository’s agents.`},Ht=(e,t,n)=>`/api/admin/repositories/agents?${new URLSearchParams({repoId:e,...t?{pulls:t}:{},...n?{commits:n}:{}})}`;function Ut(e,{pulls:t=null,commits:n=null,signal:r}={}){return A(Ht(e,t,n),Vt,E,r)}var Wt={...N,"github-not-found":`GitHub has no issue or pull request of that number here.`,400:`Not an issue or pull request of a repository.`};function Gt(e,t,{signal:n}={}){return M(`item`,{repoId:e,number:t},n,Wt)}var Kt={...Wt,"github-not-found":`GitHub has no pull request of that number here.`,"github-malformed":`GitHub answered with a pull request or lockfile that couldn’t be read.`,"github-status-403":`GitHub refused to read its lockfiles. The GitHub App reading this repository needs Contents: read and Pull requests: read, which an owner of its installation approves.`,400:`Not a pull request of a repository.`},qt=({review:e,listed:t})=>({...e?{review:`1`}:{},...t?{listed:`1`}:{}});function Jt(e,t,{review:n=!1,listed:r=!1,signal:i}={}){return M(`pull-dependencies`,{repoId:e,number:t,...qt({review:n,listed:r})},i,Kt)}async function Yt(e,t,{review:n=!1,listed:r=!1,signal:i}={}){let{pulls:a,users:o,deltas:s}=await M(`pull-dependencies`,{repoId:e,numbers:t.join(`,`),...qt({review:n,listed:r})},i,Kt);return Xt(a,o,s)}var Xt=(e,t,n)=>new Map((Array.isArray(e)?e:[]).filter(e=>Number.isSafeInteger(e?.number)).map(e=>[e.number,typeof e.error==`string`?Object.assign(Error(Kt[e.error]??`It couldn\u2019t be read (${e.error}).`),{code:e.error}):{...e,...t?{users:t}:{},...Array.isArray(n)&&n.length>0?{deltas:n}:{}}])),Zt={...Wt,"github-not-found":`GitHub has none of a lockfile it lists on the default branch.`,"github-malformed":`GitHub answered with a lockfile that couldn’t be read.`,"github-status-403":`GitHub refused to read its lockfiles. The GitHub App reading this repository needs Contents: read, which an owner of its installation approves.`,400:`Not a repository.`},Qt={...Zt,"no-bundle":`This bundle is not available to you.`,"bundle-unavailable":`This bundle’s packages couldn’t be read.`,"directory-package-malformed":`This bundle records a package installed from a directory with an integrity, or naming no directory.`,"payload-too-large":`This bundle holds too many packages to check here.`,"repository-changed":`The bundle or its repository changed while it was read. Try again.`,"github-not-found":`GitHub has none of the commit this bundle was built from, or of a lockfile it lists there.`,400:`Not a bundle.`};function $t(e,{signal:t}={}){return A(`/api/bundles/${encodeURIComponent(e)}/dependency-review`,Qt,E,t)}var en={...Qt,"unsupported-bundle":`Only Stasis bundles are validated.`,"validation-busy":`Other bundles are being validated. Try again shortly.`,"validation-failed":`The validation failed. Try again.`,"csrf-missing":`Your session is missing its request token. Reload the page.`,"csrf-mismatch":`Your session changed. Reload the page.`,429:`Other bundles are being validated. Try again shortly.`},tn=e=>`/api/bundles/${encodeURIComponent(e)}/validation`;function nn(e,{signal:t}={}){return A(tn(e),en,E,t)}function rn(e,t,{signal:n}={}){return A(tn(e),en,e=>e.json().catch(()=>null),n,{method:`POST`,headers:{"x-csrf-token":t}})}var an={"no-team":`This team is not available to you.`,400:`Not a team’s repositories.`},on=`GitHub failed to answer. Try again shortly.`,sn={...N,"github-status-502":on,"github-status-504":on,"time-up":`Reading them took too long.`},cn=e=>`Not all its open pull requests were read. ${sn[e]??`(${e})`}`;function ln(e,t,{repoIds:n=null,kept:r=!1,signal:i}={}){let a=new URLSearchParams({...n?{repoIds:n.join(`,`)}:{},...r?{kept:`1`}:{}}),o=a.size>0?`?${a}`:``;return A(`/api/teams/${encodeURIComponent(e)}/dependencies${o}`,an,async e=>{for await(let n of On(e))typeof n.error==`string`?t({...n,error:Zt[n.error]??Zt[n.status]??`It couldn\u2019t be read (${n.error}).`,code:n.error}):t({...n,...Array.isArray(n.dependencies)?{dependencies:Xt(n.dependencies,n.users)}:{},...typeof n.pulls?.error==`string`?{pulls:{...n.pulls,error:cn(n.pulls.error)}}:{}})},i)}function un(e,t,n,r,{signal:i}={}){let a=JSON.stringify({since:t,versions:n.map(({name:e,version:t})=>[e,t])});return A(`/api/teams/${encodeURIComponent(e)}/dependency-reviews/changed`,an,e=>e.json().then(e=>({now:Number.isSafeInteger(e?.now)?e.now:null,versions:Array.isArray(e?.versions)?e.versions.flatMap(e=>Array.isArray(e)&&typeof e[0]==`string`&&typeof e[1]==`string`?[{name:e[0],version:e[1]}]:[]):[]})),i,{method:`POST`,headers:{"content-type":`application/json`,"x-csrf-token":r},body:a})}var dn={...N,"no-directory":`Pulse shows only with access to the whole repository.`,"github-malformed":`GitHub answered with statistics that couldn’t be read.`,"github-token-required":`Reading a repository’s pulse needs your GitHub sign-in.`,"github-status-403":`GitHub refused to read these. The GitHub App reading this repository needs Contents, Issues and Pull requests: read, which an owner of its installation approves.`,400:`Not a repository’s pulse.`},fn=(e,t)=>`/api/admin/repositories/pulse?${new URLSearchParams({repoId:e,weeks:t})}`;function pn(e,t,{signal:n}={}){return A(fn(e,t),dn,E,n)}function mn(e,t,{state:n=`open`,weeks:r=4}={}){t===`issues`||t===`pulls`?Et(zt(e,t,n,null)):t===`agents`?Et(Ht(e,null,null)):t===`pulse`&&Et(fn(e,r))}function hn(e,t,{from:n,to:r=null,authors:i=[]},{signal:a}={}){return M(`pulse/items`,{repoId:e,weeks:t,from:n,...r===null?{}:{to:r},...i.length>0?{authors:i.join(`,`)}:{}},a,dn)}function gn(e,t,{signal:n,patch:r=null}={}){return j(`package`,{name:e,version:t,...wt(r)},n)}function _n(e,{signal:t}={}){return j(`versions`,{name:e},t)}function vn(e,{signal:t}={}){return j(`stats`,{name:e},t)}function yn(e,{signal:t}={}){return j(`advisories`,{name:e},t)}function bn(e,t,{signal:n}={}){return j(`tags`,{name:e,version:t},n)}function xn(e,t,{signal:n}={}){return j(`socket`,{name:e,version:t},n)}function Sn(e,t,n=null,{signal:r}={}){return j(`risk`,{name:e,version:t,...n===null?{}:{otherVersion:n}},r)}function Cn(e,t,{signal:n}={}){return j(`provenance`,{name:e,version:t},n)}var P={404:`This file is no longer available.`,409:`This file has changed since it was opened.`,413:`This file is too large to pretty-print.`,422:`This file couldn't be read as code.`,"pretty-mismatch":`Pretty-printing would change more than its layout, so it is shown as published.`,unsupported:`This kind of file can't be checked once pretty-printed, so it is shown as published.`,429:`Too many files are being pretty-printed. Try again shortly.`,502:`The npm registry couldn't be reached.`};function wn(e,t,n,{signal:r}={}){return A(`/api/bundles/${encodeURIComponent(e)}/pretty?${new URLSearchParams({path:t,hash:n})}`,P,En,r)}function Tn(e,t,n,r,{signal:i}={}){return A(`/api/npm/pretty?${new URLSearchParams({name:e,version:t,path:n,hash:r})}`,{...O,...P},En,i)}var En=async e=>({...await e.json(),source:e.headers.get(`x-source-hash`)});async function*Dn(e){let t=e.body.pipeThrough(new TextDecoderStream).getReader(),n=[];for(;;){let{done:e,value:r}=await t.read();if(e)return;let i=0;for(let e=r.indexOf(`
2
2
  `);e!==-1;i=e+1,e=r.indexOf(`
3
3
  `,i))n.push(r.slice(i,e)),yield JSON.parse(n.join(``)),n=[];n.push(r.slice(i))}}async function*On(e){let t=u.generation;for await(let n of Dn(e)){if(t!==u.generation)throw _t();yield n}}function kn(e,t,n,{signal:r}={}){return F(`/api/npm/pretty?${new URLSearchParams({name:e,version:t})}`,O,n,r)}function An(e,t,n,{signal:r}={}){return F(`/api/bundles/${encodeURIComponent(e)}/pretty?${new URLSearchParams({other:t})}`,P,n,r)}function jn(e,t,n,r,{signal:i}={}){return F(`/api/npm/pretty?${new URLSearchParams({name:e,version:t,otherVersion:n})}`,O,r,i)}function F(e,t,n,r,i=P){return A(e,t,async e=>{for await(let{error:t,status:r,...a}of On(e))await n(t?{...a,status:r,message:i[t]??i[r]??`Request failed (${r})`}:a)},r)}var Mn={...P,413:`This file is too large to compare with renamed names hidden.`,422:`This file couldn't be compared as code.`,"diff-busy":`Too many files are being compared. Try again shortly.`,504:`Comparing this file took too long.`},Nn=(e,t)=>A(e,Mn,E,t);function Pn(e,t,{path:n,hash:r,otherPath:i,otherHash:a},{signal:o}={}){return Nn(`/api/bundles/${encodeURIComponent(e)}/rename-diff?${new URLSearchParams({path:n,hash:r,other:t,otherPath:i,otherHash:a})}`,o)}function Fn(e,t,n,{path:r,hash:i,otherPath:a,otherHash:o},{signal:s}={}){return Nn(`/api/npm/rename-diff?${new URLSearchParams({name:e,version:t,path:r,hash:i,otherVersion:n,otherPath:a,otherHash:o})}`,s)}var In=(e,t)=>new URLSearchParams({other:e,...t?{scope:t}:{}});function Ln(e,t,n,{signal:r,scope:i=``}={}){return F(`/api/bundles/${encodeURIComponent(e)}/rename-diff?${In(t,i)}`,P,n,r,Mn)}function Rn(e,t,n,r,{signal:i}={}){return F(`/api/npm/rename-diff?${new URLSearchParams({name:e,version:t,otherVersion:n})}`,O,r,i,Mn)}function zn(e,t,n,{signal:r,scope:i=``}={}){return F(`/api/bundles/${encodeURIComponent(e)}/type-only?${In(t,i)}&runs=1`,P,n,r)}function Bn(e,t,n,r,{signal:i}={}){return F(`/api/npm/type-only?${new URLSearchParams({name:e,version:t,otherVersion:n,runs:`1`})}`,O,r,i)}var Vn={...O,"delta-busy":`Too many packages are being counted. Try again shortly.`,"delta-timeout":`Counting its lines took too long.`,"delta-failed":`Its lines couldn’t be counted.`};function Hn(e,t,{signal:n}={}){return A(`/api/npm/deltas?${new URLSearchParams({versions:JSON.stringify(e)})}`,Vn,async e=>{for await(let{error:n,status:r,...i}of On(e))t(n?{...i,error:Vn[n]??Vn[r]??`Request failed (${r})`}:i)},n)}var Un={404:`This bundle is no longer available.`,422:`This bundle couldn't be read.`,429:`Too many bundles are being compared. Try again shortly.`},Wn=async e=>{let t=await e.json();return t.files.basePaths=new Map(t.files.basePaths),t};function Gn(e,t,{signal:n,scope:r=``}={}){return A(`/api/bundles/${encodeURIComponent(e)}/comparison?${In(t,r)}`,Un,Wn,n)}function Kn(e,t,n,{signal:r,otherName:i=e,patch:a=null,otherPatch:o=null}={}){return A(`/api/npm/comparison?${new URLSearchParams({name:e,version:t,otherVersion:n,...i===e?{}:{otherName:i},...wt(a),...o?{otherPatchHash:o.hash}:{}})}`,O,Wn,r)}async function I(e,t){let n=await l(e,{signal:t,credentials:`same-origin`,headers:{accept:`application/json`}});if(!n.ok)throw Error(`HTTP ${n.status}`);return n.json()}function L(e,t,n,{signal:r,token:i=!!t}={}){let a={"content-type":`application/json`};return i&&(a[`x-csrf-token`]=t),l(e,{method:`POST`,credentials:`same-origin`,...r?{signal:r}:{},headers:a,body:JSON.stringify(n)})}async function R(e,t,n){let r=await L(e,t,n);if(!r.ok)throw Error(`HTTP ${r.status}`);return r}function qn(e,t){return async(n=``,r={})=>{let i=await l(`${e}${n}`,{credentials:`same-origin`,...r}),a=await i.json();if(!i.ok)throw Error(t[a?.error]??`HTTP ${i.status}`);return a}}async function Jn(e){let t=await e.json().then(e=>typeof e?.error==`string`?e.error:``,()=>``);return[`repo-forbidden`,`forbidden`].includes(t)?`choose a repository and directory within your team access`:`HTTP 403${t?`: ${t}`:``}`}async function Yn(e,t,n){let r=n?{"x-csrf-token":n}:{},i=await l(`/api/admin/${e}/${encodeURIComponent(t)}`,{method:`DELETE`,credentials:`same-origin`,headers:r});if(!i.ok)throw Error(`HTTP ${i.status}`)}function Xn(e,t,n,r){let i={"content-type":r,[`x-${e}-filename`]:encodeURIComponent(t.name)};return n&&(i[`x-csrf-token`]=n),l(`/api/admin/${e}s`,{method:`POST`,credentials:`same-origin`,headers:i,body:t})}async function Zn(e,t,n,r,i,a){let o=new URLSearchParams({page:String(t),limit:`100`,kind:n,q:r.trim()});i&&o.set(`repo`,i),a&&o.set(`actor`,a);let s=await I(`/api/admin/history?${o}`,e);if(!Array.isArray(s?.history)||!Number.isSafeInteger(s.total)||s.total<0||!Number.isSafeInteger(s.page)||s.page<1)throw Error(`No history returned`);return s}async function Qn(e){let t=await I(`/api/admin/users`,e);return Array.isArray(t?.users)?t.users:[]}async function $n(e,t,n){await R(`/api/admin/set-role`,n,{userId:e,role:t})}function er(e,t,n,r){let i=new URLSearchParams({scope:e});return e===`installed`&&i.set(`showAll`,String(t)),n&&i.set(`refresh`,`true`),I(`/api/admin/repositories?${i}`,r)}async function tr(e,t,n){await R(`/api/admin/repositories/select`,n,{repoId:e,selected:t})}async function nr(e,{enabled:t,required:n,since:r,lockfiles:i},a){let o=await L(`/api/admin/repositories/dependency-review`,a,{repoId:e,enabled:t,required:n,since:r,...i?{lockfiles:i}:{}});if(!o.ok)throw Error(o.status===400?`Enter 1 to 10 required reviews, the commit as its full 40-character id, and at most 100 lockfiles by their paths in the repository; a stasis.config.json only among those reviewed alone.`:`HTTP ${o.status}`);return(await o.json()).dependencyReview}async function rr(e,t){let n=await I(`/api/admin/repositories/lockfiles?repoId=${encodeURIComponent(e)}`,t);return{paths:Array.isArray(n?.lockfiles)?n.lockfiles.flatMap(e=>typeof e?.path==`string`?[e.path]:[]):[],configs:Array.isArray(n?.configs)?n.configs.filter(e=>typeof e==`string`):[]}}var ir={400:`Enter a repository as owner/repo or a GitHub repository URL.`,403:`You do not have permission to add arbitrary public repositories.`,404:`No public repository was found at that address.`,409:`Choose a public, non-archived repository.`};async function ar(e,t){let n=await L(`/api/admin/repositories/add-public`,t,{repository:e},{token:!0});if(!n.ok)throw Error(ir[n.status]??`GitHub lookup failed (HTTP ${n.status}). Try again.`)}async function or(e,t){let n=await I(`/api/admin/repositories/impact?repoId=${encodeURIComponent(e)}`,t);if(n?.repoId!==e||!Array.isArray(n.reports)||!Array.isArray(n.bundles)||!Number.isSafeInteger(n.triageCount)||n.triageCount<0)throw Error(`Invalid repository data`);return n}var sr={"github-app-not-configured":`The GitHub App is not configured on this server.`,"repo-identity-changed":`The repository has changed on GitHub. Refresh and check its connection.`,"repo-connection-changed":`The connection or your permissions changed. Refresh and try again.`,"repo-not-connected":`This repository is no longer connected.`,forbidden:`Administrator access is required to connect the GitHub App.`};async function cr(e,t){let n=await L(`/api/admin/repositories/connect-app`,t,{repoId:e},{token:!0}),r=await n.json();if(!n.ok)throw Error(sr[r.error]??`Could not connect the GitHub App (HTTP ${n.status}). Try again.`);if(r.connected===!0)return r;if(r.connected!==!1||typeof r.installUrl!=`string`||!/^https:\/\/github\.com\/apps\/[^/?#]+\/installations\/new$/u.test(r.installUrl))throw Error(`Invalid GitHub installation response.`);return r}async function lr(e,t,n,r){return(await R(`/api/admin/repositories/remove`,r,{repoId:e,fullName:t,acknowledge:!0,deleteTriage:n})).json()}function ur(e){return I(`/api/admin/reports`,e)}var dr={"unsupported-entries":`Select JavaScript/TypeScript files (including JSX/TSX) or Solidity files. Stasis cannot mix languages or use JSON or Rust as remote entry points.`,"bad-conditions":`Check the export conditions and selected platforms.`,"metro-conditions":`Stasis’s Metro preset requires the react-native condition without manual changes.`,"config-invalid":`Stasis can’t read the stasis.config.json these entry points are under, build them with the options it sets, or lay out the lockfiles it names. Check it at this revision.`,"config-mixed":`Entry points listed in a stasis.config.json are built with its options, alone. Select only those it lists, or only other files.`,"config-conditions":`These entry points are listed in stasis.config.json, which sets their options, so they take no conditions. Reload the directory and try again.`,"config-runs-code":`stasis.config.json sets an option for these entry points that runs the repository’s code, such as babel. Bundles built here never run it.`,"config-policy":`The bundle holds a path or package that stasis.config.json’s allowedPaths, disallowedPaths, allowedModules or disallowedModules refuses, or that its excludeModules excludes.`,"stasis-lock":`The build doesn’t agree with the repository’s stasis.lock.json, or stasis.config.json’s lock = frozen needs one that isn’t there. Update it at this revision.`,"commit-not-own":`Stasis can’t find this commit in the history of the repository’s branches or tags: it may be a fork’s, which GitHub serves through the repository too. Pick a commit of its default branch, a branch or a tag.`,"build-lockfile":`Stasis needs a supported lockfile: pnpm-lock.yaml, yarn.lock (Yarn 1), package-lock.json, or soldeer.lock.`,"build-scope":`Your team needs access to the bundle’s project root, including its lockfile and dependencies.`,"build-busy":`A bundle is already being built, or the server is busy. Try again shortly.`,"build-timeout":`The bundle build timed out. Try a smaller selection or retry.`,"too-large":`This bundle exceeds the server’s size limit.`,"build-memory":`Building this selection needs more memory than the server gives a build. Select fewer entry points, or build it with stasis github-bundle and upload the bundle.`,"github-rate-limited":`GitHub’s API rate limit has been reached. Retry after the limit resets.`,"github-build-failed":`Could not fetch the repository from GitHub. Check access and retry.`,"repository-changed":`The repository connection changed during the build. Reload and try again.`,"bundle-conflict":`This bundle already exists but is outside your current access.`,"build-failed":`Stasis could not build this selection. Check that its lockfile is supported and all entry points and imports exist at this commit.`};async function fr(e,t,n){let r=await L(`/api/admin/bundles/create`,t,e,{signal:n,token:!0}),i=await r.json();if(!r.ok)throw Error(dr[i.error]??(r.status===401?`Sign in again to create a bundle.`:r.status===403||r.status===404?`Repository access is required to create this bundle.`:`Could not create the bundle. Try again.`));return i}async function pr(e,t){let n=(await I(`/api/config`)).managed?.uploadMaxBytes?.reports;if(Number.isSafeInteger(n)&&n>0){if(e.size>n)throw Error(`too large`)}else if(e.size>3145728)return mr(e,t);let r=je(await e.text(),e.name);if(!r)return mr(e,t);let i=[],a=[];for(let{name:e,content:n}of r)try{a.push(await mr(new File([n],e,{type:`application/json`}),t))}catch(t){i.push(`${e}: ${String(t?.message??t)}`)}if(i.length>0)throw Error(`${i.length} of ${r.length} products failed (${i.join(`; `)})`);return a.at(-1)}async function mr(e,t){let n=await Xn(`report`,e,t,e.type||`application/json`);if(!n.ok){if(n.status===413)throw Error(`too large`);if(n.status===403)throw Error(await Jn(n));let e=await n.json().catch(()=>null);if(e?.error===`storage-encryption-required`)throw Error(`Link reports require managed storage encryption. Configure MANAGED_STORAGE_ENCRYPTION_KEY.`);if(e?.error===`invalid-report`)throw Error(typeof e.reason==`string`&&e.reason?`This file is not a report: ${e.reason}`:`This file is not a recognized report.`);let t=e?.error===`repo-not-connected`&&typeof e.repo==`string`?`: ${e.repo} is not connected`:``;throw Error(`HTTP ${n.status}${t}`)}return n.json()}async function hr(e,t,n){await R(`/api/admin/reports/set-visible`,n,{reportId:e,visible:t})}async function gr(e,t,n){let r=await L(`/api/admin/reports/set-opening`,n,{reportId:e,confirmedDefault:t});if(!r.ok)throw Error(r.status===409?`this report already opens as an App view, or has no Confirmed findings`:`HTTP ${r.status}`)}async function _r(e,t,n,r){let i=await L(`/api/admin/reports/set-repo`,r,{reportId:e,repoId:t,directory:n});if(!i.ok)throw i.status===409?Error(`this report already defines its repository`):i.status===403?Error(await Jn(i)):Error(i.status===400?`invalid repository or directory`:`HTTP ${i.status}`);return i.json()}async function vr(e,t){let n=await l(`/api/admin/reports/${encodeURIComponent(e)}/location`,{signal:t,credentials:`same-origin`});if(!n.ok)throw Error(`Report location suggestion request failed (${n.status})`);return(await n.json())?.location??null}function yr(e,t){return Yn(`reports`,e,t)}function br(e){return I(`/api/admin/bundles`,e)}async function xr(e,t){let n=await Xn(`bundle`,e,t,`application/octet-stream`);if(!n.ok)throw Error(n.status===413?`too large`:n.status===403?await Jn(n):`HTTP ${n.status}`);return n.json()}async function Sr(e,t){let n=await I(`/api/admin/bundles/${encodeURIComponent(e)}/usage`,t);if(n?.bundleId!==e||!Array.isArray(n.reports)||!n.reports.every(e=>typeof e?.filename==`string`)||!Number.isSafeInteger(n.otherReports)||n.otherReports<0)throw Error(`Invalid bundle usage`);return n}function Cr(e,t){return Yn(`bundles`,e,t)}async function wr(e,t,n){await R(`/api/admin/bundles/set-visible`,n,{bundleId:e,visible:t})}async function Tr(e,t,n,r){let i=await L(`/api/admin/bundles/set-repo`,r,{bundleId:e,repoId:t,directory:n});if(!i.ok)throw Error(i.status===403?await Jn(i):i.status===400?`invalid repository or directory`:`HTTP ${i.status}`)}function Er(e){return I(`/api/admin/teams`,e)}async function Dr(e,t,n){let r=await L(`/api/admin/teams${e}`,t,n);if(!r.ok)throw Error(r.status===409?`name already taken`:`HTTP ${r.status}`)}var Or=`.local-import-toggle{flex-shrink:0;margin-block:calc(-.25rem - 1px);margin-left:auto;padding:.25rem .6rem;border:1px solid var(--border);border-radius:var(--ui-radius, 6px);background:transparent;color:var(--muted);font:inherit;font-size:.75rem;line-height:1.5}.local-import-toggle:hover,.local-import-toggle[aria-expanded=true]{color:var(--text);background:rgb(from var(--text) r g b / .06)}.local-import-panel{display:grid;gap:.8rem;padding:1rem;margin-bottom:1.25rem;border:1px solid var(--border);border-radius:var(--ui-radius, 8px);background:rgb(from var(--accent) r g b / .025)}.local-import-copy strong{font-size:.82rem;font-weight:600}.local-import-copy p,.local-import-message{margin:.3rem 0 0;color:var(--muted);font-size:.75rem;line-height:1.5}.local-import-controls{display:flex;align-items:center;flex-wrap:wrap;gap:.5rem}managed-local-item-selector{flex:1 1 16rem;min-width:0}.local-import-controls button,.local-import-message button{padding:.35rem .7rem;border:1px solid var(--border);border-radius:var(--ui-radius, 5px);background:transparent;color:var(--text);font:inherit;font-size:.75rem;line-height:1.5}.local-import-controls .local-import-submit{border-color:rgb(from var(--accent) r g b / .4);background:rgb(from var(--accent) r g b / .1);color:var(--accent)}.local-import-controls .local-import-close{color:var(--muted)}.local-import-panel button:disabled,.local-import-toggle:disabled{opacity:.5}.local-import-panel button:focus-visible,.local-import-toggle:focus-visible{outline:2px solid var(--accent);outline-offset:2px}.local-import-message.error{color:var(--critical)}
4
4
  `,kr=`.home-section{margin-block:1.1rem 2rem}.section-heading{display:flex;align-items:baseline;gap:1rem;margin-bottom:.85rem}.section-heading h2{margin:0;font-size:.86rem;font-weight:600}.section-heading>span{color:var(--muted);font-size:.75rem}.pages{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:.9rem}.page{display:flex;flex-direction:column;gap:.85rem;padding:1.35rem;border:1px solid var(--border);border-radius:var(--ui-radius, 12px);color:var(--text);background:var(--panel);text-align:left;font:inherit}.page:hover{background:var(--panel-hover);border-color:color-mix(in srgb,var(--muted) 60%,var(--border))}.page-top{display:flex;align-items:center;gap:.75rem;width:100%}.page-icon{display:grid;place-items:center;flex-shrink:0;width:2.5rem;height:2.5rem;border:1px solid color-mix(in srgb,var(--accent) 16%,var(--border));border-radius:var(--ui-radius, 9px);background:color-mix(in srgb,var(--accent) 7%,var(--panel));color:var(--accent)}.page-bundle .page-icon{color:var(--green);border-color:color-mix(in srgb,var(--green) 18%,var(--border));background:color-mix(in srgb,var(--green) 6%,var(--panel))}.page-scan .page-icon{color:var(--scan-icon-color, var(--yellow));border-color:color-mix(in srgb,var(--scan-icon-color, var(--yellow)) 18%,var(--border));background:color-mix(in srgb,var(--scan-icon-color, var(--yellow)) 6%,var(--panel))}:host-context(body.theme-light) .page-scan .page-icon{--scan-icon-color: #bf8700}:host-context(body.theme-green) :is(.page-bundle,.page-scan) .page-icon,:host-context(body.theme-pink) :is(.page-bundle,.page-scan) .page-icon{color:var(--accent);border-color:color-mix(in srgb,var(--accent) 16%,var(--border));background:color-mix(in srgb,var(--accent) 7%,var(--panel))}.page-icon svg{width:1.2rem;height:1.2rem}.arrow{display:flex;margin-left:auto;flex-shrink:0;color:var(--muted)}.arrow svg{width:1rem;height:1rem}.page:hover .arrow{color:var(--text)}.page-copy{display:grid;gap:.45rem}.page>.page-copy{margin-inline-start:3.25rem}.page-copy strong,.page-title{font-size:1rem;font-weight:600;letter-spacing:-.015em}.page-copy>span{color:var(--muted);font-size:.8rem;line-height:1.65}.workspace-pages .page{padding:1.2rem 1.35rem}.workspace-pages .page-icon{width:2rem;height:2rem;color:var(--muted);background:transparent;border-color:var(--border)}.workspace-pages .page-title{font-size:.9rem}.workspace-pages .page-copy{margin-inline-start:2.75rem}.history-link{display:flex;align-items:center;gap:1rem;width:100%;padding:1.25rem 0;border:0;border-top:1px solid var(--border);text-align:left;color:var(--text);background:transparent}.history-link>.page-icon{color:var(--muted);background:transparent;border-color:var(--border)}.history-link .page-copy strong{font-size:.85rem}.history-cta{display:flex;align-items:center;gap:.6rem;flex-shrink:0;margin-left:auto;color:var(--muted);font-size:.78rem}.history-cta svg{width:1rem;height:1rem}.history-link:hover .history-cta{color:var(--accent)}@container (max-width: 48rem){.pages{grid-template-columns:1fr;gap:.65rem}.page,.workspace-pages .page{gap:.65rem;padding:1.15rem}.page-top .arrow{display:none}.workspace-pages .page-icon{width:2.5rem;height:2.5rem}.workspace-pages .page-copy{margin-inline-start:3.25rem}.page-copy{gap:.2rem}.page-copy strong,.page-title{font-size:.95rem}.section-heading>span{display:none}.history-cta{font-size:0}}
@@ -1,6 +1,6 @@
1
- import{i as e,n as t,o as n,q as r,r as i,s as a,t as o,u as s,v as c,w as l}from"./chunk-7BKKYVWR.js";import{a as u,b as d,d as f,e as p,f as m,g as h,h as g,i as _}from"./chunk-7C7DWL7I.js";import{a as v,b as y}from"./chunk-PNHBZGDD.js";import{a as b,c as x}from"./chunk-TUII34K2.js";import"./chunk-OOJM4CTU.js";function S(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`&&`BYTES_PER_ELEMENT`in e&&e.BYTES_PER_ELEMENT===1}var C=e=>e?`"${e}" `:``;function w(e,t=``){if(typeof e!=`boolean`)throw TypeError(C(t)+`expected boolean, got type=`+typeof e);return e}function T(e,t=``){if(typeof e!=`number`)throw TypeError(C(t)+`expected number, got `+typeof e);if(!Number.isSafeInteger(e)||e<0)throw RangeError(C(t)+`expected integer >= 0, got `+e);return e}function E(e,t,n=``){if(S(e)&&(t===void 0||e.length===t))return e;t!==void 0&&T(t,`length`);let r=S(e),i=t===void 0?``:` of length ${t}`,a=r?`length=${e.length}`:`type=${typeof e}`,o=C(n)+`expected Uint8Array`+i+`, got `+a;throw r?RangeError(o):TypeError(o)}var D=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError(t===`object`?`expected valid options object`:`"${t}" expected object, got type=${typeof e}`)};function O(e,t=!0){if(e.destroyed)throw Error(`hash was destroyed`);if(t&&e.finished)throw Error(`digest() was already called`)}function k(e,t){E(e,void 0,`output`);let n=t.outputLen;if(!(e.length>=n))throw RangeError(`"output" expected length >= `+n)}function A(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function j(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function M(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}var N=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function P(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function F(e){for(let t=0;t<e.length;t++)e[t]=P(e[t]);return e}var I=N?e=>e:F;function L(e,t){return!e.byteLength||!t.byteLength?!1:e.buffer===t.buffer&&e.byteOffset<t.byteOffset+t.byteLength&&t.byteOffset<e.byteOffset+e.byteLength}function R(e,t){if(L(e,t)&&e.byteOffset<t.byteOffset)throw Error(`complex overlap of input and output is not supported`)}function z(e,t){return D(e,`defaults`),D(t,`opts`),Object.assign(e,t)}function ee(e,t){if(e=E(e),t=E(t),e.length!==t.length)return!1;let n=0;for(let r=0;r<e.length;r++)n|=e[r]^t[r];return n===0}function te(e,t,n){let r=t,i=n||(()=>[]),a=(e,t)=>r(t,...i(e)).update(e).digest(),o=r(new Uint8Array(e),...i(new Uint8Array));return a.outputLen=o.outputLen,a.blockLen=o.blockLen,a.create=(e,...t)=>r(e,...t),a}var ne=(e,t)=>{function n(n,...r){if(E(n,void 0,`key`),e.nonceLength!==void 0){let t=r[0];E(t,e.varSizeNonce?void 0:e.nonceLength,`nonce`)}let i=e.tagLength,a=e.nonceLength===void 0?0:1;if(!e.withAAD){for(let e=a;e<r.length;e++)if(S(r[e]))throw Error(`AAD not supported`)}e.withAAD&&r[a]!==void 0&&E(r[a],void 0,`AAD`);let o=t(n,...r),s=(e,t)=>{if(t!==void 0){if(e!==2)throw Error(`cipher output not supported`);E(t,void 0,`output`)}},c=!1;return{encrypt(e,t){if(c)throw Error(`cannot encrypt() twice with same key + nonce`);return c=!0,E(e,void 0,`data`),s(o.encrypt.length,t),o.encrypt(e,t)},decrypt(e,t){if(E(e,void 0,`data`),i&&e.length<i)throw Error(`"ciphertext" expected length >= tagLength=`+i);return s(o.decrypt.length,t),o.decrypt(e,t)}}}return Object.assign(n,e),n};function B(e,t,n=!0){if(t===void 0)return new Uint8Array(e);if(E(t,e,`output`),n&&!ie(t))throw Error(`invalid output, must be aligned`);return t}function re(e,t,n){T(e),T(t),w(n);let r=new Uint8Array(16),i=M(r);return i.setBigUint64(0,BigInt(t),n),i.setBigUint64(8,BigInt(e),n),r}function ie(e){return e.byteOffset%4==0}function ae(e){return Uint8Array.from(E(e))}var oe=e=>Uint8Array.from(e.split(``),e=>e.charCodeAt(0)),se=I(A(oe(`expand 16-byte k`))),ce=I(A(oe(`expand 32-byte k`)));function V(e,t){return e<<t|e>>>32-t}var le=64,ue=16,de=2**32-1,fe=Uint32Array.of();function pe(e,t,n,r,i,a,o,s){let c=i.length,l=new Uint8Array(le),u=A(l),d=N&&ie(i)&&ie(a),f=d?A(i):fe,p=d?A(a):fe;if(N)for(let m=0;m<c;o++){if(e(t,n,r,u,o,s),o>=de)throw Error(`arx: counter overflow`);let h=Math.min(le,c-m);if(d&&h===le){let e=m/4;if(m%4!=0)throw Error(`arx: invalid block position`);for(let t=0,n;t<ue;t++)n=e+t,p[n]=f[n]^u[t];m+=le}else{for(let e=0,t;e<h;e++)t=m+e,a[t]=i[t]^l[e];m+=h}}else for(let d=0;d<c;o++){if(e(t,n,r,u,o,s),I(u),o>=de)throw Error(`arx: counter overflow`);let f=Math.min(le,c-d);for(let e=0,t;e<f;e++)t=d+e,a[t]=i[t]^l[e];d+=f}}function me(e,t){let{allowShortKeys:n,extendNonceFn:r,counterLength:i,counterRight:a,rounds:o}=z({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof e!=`function`)throw Error(`core must be a function`);return T(i),T(o),w(a),w(n),(t,s,c,l,u=0)=>{E(t,void 0,`key`),E(s,void 0,`nonce`),E(c,void 0,`data`);let d=c.length,f=l!==void 0;if(l=B(d,l,!1),f&&R(c,l),T(u),u<0||u>=de)throw Error(`arx: counter overflow`);let p=[],m=t.length,h,g;if(m===32)p.push(h=ae(t)),g=ce;else if(m===16&&n)h=new Uint8Array(32),h.set(t),h.set(t,16),g=se,p.push(h);else throw E(t,32,`arx key`),Error(`invalid key size`);N&&ie(s)||p.push(s=ae(s));let _=A(h);if(r){if(s.length!==24)throw Error(`arx: extended nonce must be 24 bytes`);let e=s.subarray(0,16);if(N)r(g,_,A(e),_);else{let t=I(Uint32Array.from(g));r(t,_,A(e),_),j(t),I(_)}s=s.subarray(16)}else N||I(_);let v=16-i;if(v!==s.length)throw Error(`arx: nonce must be ${v} or 16 bytes`);if(v!==12){let e=new Uint8Array(12);e.set(s,a?0:12-s.length),s=e,p.push(s)}let y=I(A(s));try{return pe(e,g,_,y,c,l,u,o),l}finally{j(...p)}}}function H(e,t){return e[t++]&255|(e[t++]&255)<<8}var he=class{blockLen=16;outputLen=16;buffer=new Uint8Array(16);r=new Uint16Array(10);h=new Uint16Array(10);pad=new Uint16Array(8);pos=0;finished=!1;destroyed=!1;constructor(e){e=ae(E(e,32,`key`));let t=H(e,0),n=H(e,2),r=H(e,4),i=H(e,6),a=H(e,8),o=H(e,10),s=H(e,12),c=H(e,14);this.r[0]=t&8191,this.r[1]=(t>>>13|n<<3)&8191,this.r[2]=(n>>>10|r<<6)&7939,this.r[3]=(r>>>7|i<<9)&8191,this.r[4]=(i>>>4|a<<12)&255,this.r[5]=a>>>1&8190,this.r[6]=(a>>>14|o<<2)&8191,this.r[7]=(o>>>11|s<<5)&8065,this.r[8]=(s>>>8|c<<8)&8191,this.r[9]=c>>>5&127;for(let t=0;t<8;t++)this.pad[t]=H(e,16+2*t)}process(e,t,n=!1){let r=n?0:2048,{h:i,r:a}=this,o=a[0],s=a[1],c=a[2],l=a[3],u=a[4],d=a[5],f=a[6],p=a[7],m=a[8],h=a[9],g=H(e,t+0),_=H(e,t+2),v=H(e,t+4),y=H(e,t+6),b=H(e,t+8),x=H(e,t+10),S=H(e,t+12),C=H(e,t+14),w=i[0]+(g&8191),T=i[1]+((g>>>13|_<<3)&8191),E=i[2]+((_>>>10|v<<6)&8191),D=i[3]+((v>>>7|y<<9)&8191),O=i[4]+((y>>>4|b<<12)&8191),k=i[5]+(b>>>1&8191),A=i[6]+((b>>>14|x<<2)&8191),j=i[7]+((x>>>11|S<<5)&8191),M=i[8]+((S>>>8|C<<8)&8191),N=i[9]+(C>>>5|r),P=0,F=P+w*o+5*h*T+5*m*E+5*p*D+5*f*O;P=F>>>13,F&=8191,F+=5*d*k+5*u*A+5*l*j+5*c*M+5*s*N,P+=F>>>13,F&=8191;let I=P+w*s+T*o+5*h*E+5*m*D+5*p*O;P=I>>>13,I&=8191,I+=5*f*k+5*d*A+5*u*j+5*l*M+5*c*N,P+=I>>>13,I&=8191;let L=P+w*c+T*s+E*o+5*h*D+5*m*O;P=L>>>13,L&=8191,L+=5*p*k+5*f*A+5*d*j+5*u*M+5*l*N,P+=L>>>13,L&=8191;let R=P+w*l+T*c+E*s+D*o+5*h*O;P=R>>>13,R&=8191,R+=5*m*k+5*p*A+5*f*j+5*d*M+5*u*N,P+=R>>>13,R&=8191;let z=P+w*u+T*l+E*c+D*s+O*o;P=z>>>13,z&=8191,z+=5*h*k+5*m*A+5*p*j+5*f*M+5*d*N,P+=z>>>13,z&=8191;let ee=P+w*d+T*u+E*l+D*c+O*s;P=ee>>>13,ee&=8191,ee+=k*o+5*h*A+5*m*j+5*p*M+5*f*N,P+=ee>>>13,ee&=8191;let te=P+w*f+T*d+E*u+D*l+O*c;P=te>>>13,te&=8191,te+=k*s+A*o+5*h*j+5*m*M+5*p*N,P+=te>>>13,te&=8191;let ne=P+w*p+T*f+E*d+D*u+O*l;P=ne>>>13,ne&=8191,ne+=k*c+A*s+j*o+5*h*M+5*m*N,P+=ne>>>13,ne&=8191;let B=P+w*m+T*p+E*f+D*d+O*u;P=B>>>13,B&=8191,B+=k*l+A*c+j*s+M*o+5*h*N,P+=B>>>13,B&=8191;let re=P+w*h+T*m+E*p+D*f+O*d;P=re>>>13,re&=8191,re+=k*u+A*l+j*c+M*s+N*o,P+=re>>>13,re&=8191,P=(P<<2)+P|0,P=P+F|0,F=P&8191,P>>>=13,I+=P,i[0]=F,i[1]=I,i[2]=L,i[3]=R,i[4]=z,i[5]=ee,i[6]=te,i[7]=ne,i[8]=B,i[9]=re}finalize(){let{h:e,pad:t}=this,n=new Uint16Array(10),r=e[1]>>>13;e[1]&=8191;for(let t=2;t<10;t++)e[t]+=r,r=e[t]>>>13,e[t]&=8191;e[0]+=r*5,r=e[0]>>>13,e[0]&=8191,e[1]+=r,r=e[1]>>>13,e[1]&=8191,e[2]+=r,n[0]=e[0]+5,r=n[0]>>>13,n[0]&=8191;for(let t=1;t<10;t++)n[t]=e[t]+r,r=n[t]>>>13,n[t]&=8191;n[9]-=8192;let i=(r^1)-1;for(let e=0;e<10;e++)n[e]&=i;i=~i;for(let t=0;t<10;t++)e[t]=e[t]&i|n[t];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let a=e[0]+t[0];e[0]=a&65535;for(let n=1;n<8;n++)a=(e[n]+t[n]|0)+(a>>>16)|0,e[n]=a&65535;j(n)}update(e){O(this),E(e),e=ae(e);let{buffer:t,blockLen:n}=this,r=e.length;for(let i=0;i<r;){let a=Math.min(n-this.pos,r-i);if(a===n)for(;n<=r-i;i+=n)this.process(e,i);else t.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===n&&(this.process(t,0,!1),this.pos=0)}return this}destroy(){this.destroyed=!0,j(this.h,this.r,this.buffer,this.pad)}digestInto(e){O(this),k(e,this),this.finished=!0;let{buffer:t,h:n}=this,{pos:r}=this;if(r){for(t[r++]=1;r<16;r++)t[r]=0;this.process(t,0,!0)}this.finalize();let i=0;for(let t=0;t<8;t++)e[i++]=n[t]>>>0,e[i++]=n[t]>>>8}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}},ge=te(32,e=>new he(e));function _e(e,t,n,r,i,a=20){let o=e[0],s=e[1],c=e[2],l=e[3],u=t[0],d=t[1],f=t[2],p=t[3],m=t[4],h=t[5],g=t[6],_=t[7],v=i,y=n[0],b=n[1],x=n[2],S=o,C=s,w=c,T=l,E=u,D=d,O=f,k=p,A=m,j=h,M=g,N=_,P=v,F=y,I=b,L=x;for(let e=0;e<a;e+=2)S=S+E|0,P=V(P^S,16),A=A+P|0,E=V(E^A,12),S=S+E|0,P=V(P^S,8),A=A+P|0,E=V(E^A,7),C=C+D|0,F=V(F^C,16),j=j+F|0,D=V(D^j,12),C=C+D|0,F=V(F^C,8),j=j+F|0,D=V(D^j,7),w=w+O|0,I=V(I^w,16),M=M+I|0,O=V(O^M,12),w=w+O|0,I=V(I^w,8),M=M+I|0,O=V(O^M,7),T=T+k|0,L=V(L^T,16),N=N+L|0,k=V(k^N,12),T=T+k|0,L=V(L^T,8),N=N+L|0,k=V(k^N,7),S=S+D|0,L=V(L^S,16),M=M+L|0,D=V(D^M,12),S=S+D|0,L=V(L^S,8),M=M+L|0,D=V(D^M,7),C=C+O|0,P=V(P^C,16),N=N+P|0,O=V(O^N,12),C=C+O|0,P=V(P^C,8),N=N+P|0,O=V(O^N,7),w=w+k|0,F=V(F^w,16),A=A+F|0,k=V(k^A,12),w=w+k|0,F=V(F^w,8),A=A+F|0,k=V(k^A,7),T=T+E|0,I=V(I^T,16),j=j+I|0,E=V(E^j,12),T=T+E|0,I=V(I^T,8),j=j+I|0,E=V(E^j,7);let R=0;r[R++]=o+S|0,r[R++]=s+C|0,r[R++]=c+w|0,r[R++]=l+T|0,r[R++]=u+E|0,r[R++]=d+D|0,r[R++]=f+O|0,r[R++]=p+k|0,r[R++]=m+A|0,r[R++]=h+j|0,r[R++]=g+M|0,r[R++]=_+N|0,r[R++]=v+P|0,r[R++]=y+F|0,r[R++]=b+I|0,r[R++]=x+L|0}var ve=me(_e,{counterRight:!1,counterLength:4,allowShortKeys:!1}),ye=new Uint8Array(16),be=(e,t)=>{e.update(t);let n=t.length%16;n&&e.update(ye.subarray(n))},xe=new Uint8Array(32);function Se(e,t,n,r,i){i!==void 0&&E(i,void 0,`AAD`);let a=e(t,n,xe),o=re(r.length,i?i.length:0,!0),s=ge.create(a);i&&be(s,i),be(s,r),s.update(o);let c=s.digest();return j(a,o),c}var Ce=ne({blockSize:64,nonceLength:12,tagLength:16,withAAD:!0},(e=>(t,n,r)=>({encrypt(i,a){let o=i.length;a=B(o+16,a,!1),a.set(i);let s=a.subarray(0,-16);e(t,n,s,s,1);let c=Se(e,t,n,s,r);return a.set(c,o),j(c),a},decrypt(i,a){a=B(i.length-16,a,!1);let o=i.subarray(0,-16),s=i.subarray(-16),c=Se(e,t,n,o,r);if(!ee(s,c))throw j(c),Error(`invalid tag`);return a.set(i.subarray(0,-16)),e(t,n,a,a,1),j(c),a}}))(ve)),we=`deepview-triage-sync.v1.content-key`,Te=`deepview-triage-sync.v1.sign-key`,Ee=`deepview-triage-sync.v1.save`,De=`deepview-triage-sync.v1.subscribe`,Oe=12,ke=new Uint8Array([48,46,2,1,0,48,5,6,3,43,101,112,4,34,4,32]),Ae=null;function je(){return Ae||(Ae=(async()=>{try{return await crypto.subtle.importKey(`raw`,new Uint8Array(32),{name:`ChaCha20-Poly1305`},!1,[`encrypt`,`decrypt`]),!0}catch{return!1}})(),Ae)}async function Me(e,t){let n=Uint8Array.fromBase64(e);if(n.length!==32)throw Error(`workspace private key must be 32 bytes (got ${n.length})`);let r=await crypto.subtle.importKey(`raw`,n,`HKDF`,!1,[`deriveBits`]),i=await crypto.subtle.deriveBits({name:`HKDF`,hash:`SHA-256`,salt:new Uint8Array,info:b(t)},r,256);return new Uint8Array(i)}async function Ne(e){return await Me(e,we)}async function Pe(e,t){let n=await Me(e,`${Te}|${t}`),r=new Uint8Array(ke.length+32);r.set(ke,0),r.set(n,ke.length);let i=await crypto.subtle.importKey(`pkcs8`,r,{name:`Ed25519`},!0,[`sign`]),a=await crypto.subtle.exportKey(`jwk`,i),o=a.x;if(delete a.d,o==null)throw Error(`Ed25519 JWK export returned no public key`);let s=Uint8Array.fromBase64(o,{alphabet:`base64url`}),c=await crypto.subtle.importKey(`pkcs8`,r,{name:`Ed25519`},!1,[`sign`]);return n.fill(0),r.fill(0),{privateKey:c,publicKey:s,publicKeyB64:o}}function Fe({publicKeyB64:e,base:t,keyframe:n,nonceB64:r,ciphertextB64:i}){return b([Ee,e,t==null?``:String(t),n===!0?`1`:``,r,i].join(`
1
+ import{i as e,n as t,o as n,q as r,r as i,s as a,t as o,u as s,v as c,w as l}from"./chunk-7BKKYVWR.js";import{a as u,b as d,d as f,e as p,f as m,g as h,h as g,i as _}from"./chunk-7C7DWL7I.js";import{a as v,b as y}from"./chunk-PNHBZGDD.js";import{a as b,c as x}from"./chunk-TUII34K2.js";import"./chunk-OOJM4CTU.js";function S(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`&&`BYTES_PER_ELEMENT`in e&&e.BYTES_PER_ELEMENT===1}var C=e=>e?`"${e}" `:``;function w(e,t=``){if(typeof e!=`boolean`)throw TypeError(C(t)+`expected boolean, got type=`+typeof e);return e}function T(e,t=``){if(typeof e!=`number`)throw TypeError(C(t)+`expected number, got `+typeof e);if(!Number.isSafeInteger(e)||e<0)throw RangeError(C(t)+`expected integer >= 0, got `+e);return e}function E(e,t,n=``){if(S(e)&&(t===void 0||e.length===t))return e;t!==void 0&&T(t,`length`);let r=S(e),i=t===void 0?``:` of length ${t}`,a=r?`length=${e.length}`:`type=${typeof e}`,o=C(n)+`expected Uint8Array`+i+`, got `+a;throw r?RangeError(o):TypeError(o)}var D=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError(t===`object`?`expected valid options object`:`"${t}" expected object, got type=${typeof e}`)};function O(e,t=!0){if(e.destroyed)throw Error(`hash was destroyed`);if(t&&e.finished)throw Error(`digest() was already called`)}function k(e,t){E(e,void 0,`output`);let n=t.outputLen;if(!(e.length>=n))throw RangeError(`"output" expected length >= `+n)}function A(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function j(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function M(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}var N=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function P(e){return e<<24&0xff000000|e<<8&0xff0000|e>>>8&65280|e>>>24&255}function F(e){for(let t=0;t<e.length;t++)e[t]=P(e[t]);return e}var I=N?e=>e:F;function L(e,t){return!e.byteLength||!t.byteLength?!1:e.buffer===t.buffer&&e.byteOffset<t.byteOffset+t.byteLength&&t.byteOffset<e.byteOffset+e.byteLength}function R(e,t){if(L(e,t)&&e.byteOffset<t.byteOffset)throw Error(`complex overlap of input and output is not supported`)}function z(e,t){return D(e,`defaults`),D(t,`opts`),Object.assign(e,t)}function ee(e,t){if(e=E(e),t=E(t),e.length!==t.length)return!1;let n=0;for(let r=0;r<e.length;r++)n|=e[r]^t[r];return n===0}function te(e,t,n){let r=t,i=n||(()=>[]),a=(e,t)=>r(t,...i(e)).update(e).digest(),o=r(new Uint8Array(e),...i(new Uint8Array));return a.outputLen=o.outputLen,a.blockLen=o.blockLen,a.create=(e,...t)=>r(e,...t),a}var ne=(e,t)=>{function n(n,...r){E(n,void 0,`key`),e.nonceLength!==void 0&&E(r[0],e.varSizeNonce?void 0:e.nonceLength,`nonce`);let i=e.tagLength,a=e.nonceLength===void 0?0:1;if(!e.withAAD){for(let e=a;e<r.length;e++)if(S(r[e]))throw Error(`AAD not supported`)}e.withAAD&&r[a]!==void 0&&E(r[a],void 0,`AAD`);let o=t(n,...r),s=(e,t)=>{if(t!==void 0){if(e!==2)throw Error(`cipher output not supported`);E(t,void 0,`output`)}},c=!1;return{encrypt(e,t){if(c)throw Error(`cannot encrypt() twice with same key + nonce`);return c=!0,E(e,void 0,`data`),s(o.encrypt.length,t),o.encrypt(e,t)},decrypt(e,t){if(E(e,void 0,`data`),i&&e.length<i)throw Error(`"ciphertext" expected length >= tagLength=`+i);return s(o.decrypt.length,t),o.decrypt(e,t)}}}return Object.assign(n,e),n};function B(e,t,n=!0){if(t===void 0)return new Uint8Array(e);if(E(t,e,`output`),n&&!ie(t))throw Error(`invalid output, must be aligned`);return t}function re(e,t,n){T(e),T(t),w(n);let r=new Uint8Array(16),i=M(r);return i.setBigUint64(0,BigInt(t),n),i.setBigUint64(8,BigInt(e),n),r}function ie(e){return e.byteOffset%4==0}function ae(e){return Uint8Array.from(E(e))}var oe=e=>Uint8Array.from(e.split(``),e=>e.charCodeAt(0)),se=I(A(oe(`expand 16-byte k`))),ce=I(A(oe(`expand 32-byte k`)));function V(e,t){return e<<t|e>>>32-t}var le=64,ue=16,de=2**32-1,fe=Uint32Array.of();function pe(e,t,n,r,i,a,o,s){let c=i.length,l=new Uint8Array(le),u=A(l),d=N&&ie(i)&&ie(a),f=d?A(i):fe,p=d?A(a):fe;if(N)for(let m=0;m<c;o++){if(e(t,n,r,u,o,s),o>=de)throw Error(`arx: counter overflow`);let h=Math.min(le,c-m);if(d&&h===le){let e=m/4;if(m%4!=0)throw Error(`arx: invalid block position`);for(let t=0,n;t<ue;t++)n=e+t,p[n]=f[n]^u[t];m+=le}else{for(let e=0,t;e<h;e++)t=m+e,a[t]=i[t]^l[e];m+=h}}else for(let d=0;d<c;o++){if(e(t,n,r,u,o,s),I(u),o>=de)throw Error(`arx: counter overflow`);let f=Math.min(le,c-d);for(let e=0,t;e<f;e++)t=d+e,a[t]=i[t]^l[e];d+=f}}function me(e,t){let{allowShortKeys:n,extendNonceFn:r,counterLength:i,counterRight:a,rounds:o}=z({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof e!=`function`)throw Error(`core must be a function`);return T(i),T(o),w(a),w(n),(t,s,c,l,u=0)=>{E(t,void 0,`key`),E(s,void 0,`nonce`),E(c,void 0,`data`);let d=c.length,f=l!==void 0;if(l=B(d,l,!1),f&&R(c,l),T(u),u<0||u>=de)throw Error(`arx: counter overflow`);let p=[],m=t.length,h,g;if(m===32)p.push(h=ae(t)),g=ce;else if(m===16&&n)h=new Uint8Array(32),h.set(t),h.set(t,16),g=se,p.push(h);else throw E(t,32,`arx key`),Error(`invalid key size`);N&&ie(s)||p.push(s=ae(s));let _=A(h);if(r){if(s.length!==24)throw Error(`arx: extended nonce must be 24 bytes`);let e=s.subarray(0,16);if(N)r(g,_,A(e),_);else{let t=I(Uint32Array.from(g));r(t,_,A(e),_),j(t),I(_)}s=s.subarray(16)}else N||I(_);let v=16-i;if(v!==s.length)throw Error(`arx: nonce must be ${v} or 16 bytes`);if(v!==12){let e=new Uint8Array(12);e.set(s,a?0:12-s.length),s=e,p.push(s)}let y=I(A(s));try{return pe(e,g,_,y,c,l,u,o),l}finally{j(...p)}}}function H(e,t){return e[t++]&255|(e[t++]&255)<<8}var he=class{blockLen=16;outputLen=16;buffer=new Uint8Array(16);r=new Uint16Array(10);h=new Uint16Array(10);pad=new Uint16Array(8);pos=0;finished=!1;destroyed=!1;constructor(e){e=ae(E(e,32,`key`));let t=H(e,0),n=H(e,2),r=H(e,4),i=H(e,6),a=H(e,8),o=H(e,10),s=H(e,12),c=H(e,14);this.r[0]=t&8191,this.r[1]=(t>>>13|n<<3)&8191,this.r[2]=(n>>>10|r<<6)&7939,this.r[3]=(r>>>7|i<<9)&8191,this.r[4]=(i>>>4|a<<12)&255,this.r[5]=a>>>1&8190,this.r[6]=(a>>>14|o<<2)&8191,this.r[7]=(o>>>11|s<<5)&8065,this.r[8]=(s>>>8|c<<8)&8191,this.r[9]=c>>>5&127;for(let t=0;t<8;t++)this.pad[t]=H(e,16+2*t)}process(e,t,n=!1){let r=n?0:2048,{h:i,r:a}=this,o=a[0],s=a[1],c=a[2],l=a[3],u=a[4],d=a[5],f=a[6],p=a[7],m=a[8],h=a[9],g=H(e,t+0),_=H(e,t+2),v=H(e,t+4),y=H(e,t+6),b=H(e,t+8),x=H(e,t+10),S=H(e,t+12),C=H(e,t+14),w=i[0]+(g&8191),T=i[1]+((g>>>13|_<<3)&8191),E=i[2]+((_>>>10|v<<6)&8191),D=i[3]+((v>>>7|y<<9)&8191),O=i[4]+((y>>>4|b<<12)&8191),k=i[5]+(b>>>1&8191),A=i[6]+((b>>>14|x<<2)&8191),j=i[7]+((x>>>11|S<<5)&8191),M=i[8]+((S>>>8|C<<8)&8191),N=i[9]+(C>>>5|r),P=0,F=P+w*o+5*h*T+5*m*E+5*p*D+5*f*O;P=F>>>13,F&=8191,F+=5*d*k+5*u*A+5*l*j+5*c*M+5*s*N,P+=F>>>13,F&=8191;let I=P+w*s+T*o+5*h*E+5*m*D+5*p*O;P=I>>>13,I&=8191,I+=5*f*k+5*d*A+5*u*j+5*l*M+5*c*N,P+=I>>>13,I&=8191;let L=P+w*c+T*s+E*o+5*h*D+5*m*O;P=L>>>13,L&=8191,L+=5*p*k+5*f*A+5*d*j+5*u*M+5*l*N,P+=L>>>13,L&=8191;let R=P+w*l+T*c+E*s+D*o+5*h*O;P=R>>>13,R&=8191,R+=5*m*k+5*p*A+5*f*j+5*d*M+5*u*N,P+=R>>>13,R&=8191;let z=P+w*u+T*l+E*c+D*s+O*o;P=z>>>13,z&=8191,z+=5*h*k+5*m*A+5*p*j+5*f*M+5*d*N,P+=z>>>13,z&=8191;let ee=P+w*d+T*u+E*l+D*c+O*s;P=ee>>>13,ee&=8191,ee+=k*o+5*h*A+5*m*j+5*p*M+5*f*N,P+=ee>>>13,ee&=8191;let te=P+w*f+T*d+E*u+D*l+O*c;P=te>>>13,te&=8191,te+=k*s+A*o+5*h*j+5*m*M+5*p*N,P+=te>>>13,te&=8191;let ne=P+w*p+T*f+E*d+D*u+O*l;P=ne>>>13,ne&=8191,ne+=k*c+A*s+j*o+5*h*M+5*m*N,P+=ne>>>13,ne&=8191;let B=P+w*m+T*p+E*f+D*d+O*u;P=B>>>13,B&=8191,B+=k*l+A*c+j*s+M*o+5*h*N,P+=B>>>13,B&=8191;let re=P+w*h+T*m+E*p+D*f+O*d;P=re>>>13,re&=8191,re+=k*u+A*l+j*c+M*s+N*o,P+=re>>>13,re&=8191,P=(P<<2)+P|0,P=P+F|0,F=P&8191,P>>>=13,I+=P,i[0]=F,i[1]=I,i[2]=L,i[3]=R,i[4]=z,i[5]=ee,i[6]=te,i[7]=ne,i[8]=B,i[9]=re}finalize(){let{h:e,pad:t}=this,n=new Uint16Array(10),r=e[1]>>>13;e[1]&=8191;for(let t=2;t<10;t++)e[t]+=r,r=e[t]>>>13,e[t]&=8191;e[0]+=r*5,r=e[0]>>>13,e[0]&=8191,e[1]+=r,r=e[1]>>>13,e[1]&=8191,e[2]+=r,n[0]=e[0]+5,r=n[0]>>>13,n[0]&=8191;for(let t=1;t<10;t++)n[t]=e[t]+r,r=n[t]>>>13,n[t]&=8191;n[9]-=8192;let i=(r^1)-1;for(let e=0;e<10;e++)n[e]&=i;i=~i;for(let t=0;t<10;t++)e[t]=e[t]&i|n[t];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let a=e[0]+t[0];e[0]=a&65535;for(let n=1;n<8;n++)a=(e[n]+t[n]|0)+(a>>>16)|0,e[n]=a&65535;j(n)}update(e){O(this),E(e),e=ae(e);let{buffer:t,blockLen:n}=this,r=e.length;for(let i=0;i<r;){let a=Math.min(n-this.pos,r-i);if(a===n)for(;n<=r-i;i+=n)this.process(e,i);else t.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===n&&(this.process(t,0,!1),this.pos=0)}return this}destroy(){this.destroyed=!0,j(this.h,this.r,this.buffer,this.pad)}digestInto(e){O(this),k(e,this),this.finished=!0;let{buffer:t,h:n}=this,{pos:r}=this;if(r){for(t[r++]=1;r<16;r++)t[r]=0;this.process(t,0,!0)}this.finalize();let i=0;for(let t=0;t<8;t++)e[i++]=n[t]>>>0,e[i++]=n[t]>>>8}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}},ge=te(32,e=>new he(e));function _e(e,t,n,r,i,a=20){let o=e[0],s=e[1],c=e[2],l=e[3],u=t[0],d=t[1],f=t[2],p=t[3],m=t[4],h=t[5],g=t[6],_=t[7],v=i,y=n[0],b=n[1],x=n[2],S=o,C=s,w=c,T=l,E=u,D=d,O=f,k=p,A=m,j=h,M=g,N=_,P=v,F=y,I=b,L=x;for(let e=0;e<a;e+=2)S=S+E|0,P=V(P^S,16),A=A+P|0,E=V(E^A,12),S=S+E|0,P=V(P^S,8),A=A+P|0,E=V(E^A,7),C=C+D|0,F=V(F^C,16),j=j+F|0,D=V(D^j,12),C=C+D|0,F=V(F^C,8),j=j+F|0,D=V(D^j,7),w=w+O|0,I=V(I^w,16),M=M+I|0,O=V(O^M,12),w=w+O|0,I=V(I^w,8),M=M+I|0,O=V(O^M,7),T=T+k|0,L=V(L^T,16),N=N+L|0,k=V(k^N,12),T=T+k|0,L=V(L^T,8),N=N+L|0,k=V(k^N,7),S=S+D|0,L=V(L^S,16),M=M+L|0,D=V(D^M,12),S=S+D|0,L=V(L^S,8),M=M+L|0,D=V(D^M,7),C=C+O|0,P=V(P^C,16),N=N+P|0,O=V(O^N,12),C=C+O|0,P=V(P^C,8),N=N+P|0,O=V(O^N,7),w=w+k|0,F=V(F^w,16),A=A+F|0,k=V(k^A,12),w=w+k|0,F=V(F^w,8),A=A+F|0,k=V(k^A,7),T=T+E|0,I=V(I^T,16),j=j+I|0,E=V(E^j,12),T=T+E|0,I=V(I^T,8),j=j+I|0,E=V(E^j,7);let R=0;r[R++]=o+S|0,r[R++]=s+C|0,r[R++]=c+w|0,r[R++]=l+T|0,r[R++]=u+E|0,r[R++]=d+D|0,r[R++]=f+O|0,r[R++]=p+k|0,r[R++]=m+A|0,r[R++]=h+j|0,r[R++]=g+M|0,r[R++]=_+N|0,r[R++]=v+P|0,r[R++]=y+F|0,r[R++]=b+I|0,r[R++]=x+L|0}var ve=me(_e,{counterRight:!1,counterLength:4,allowShortKeys:!1}),ye=new Uint8Array(16),be=(e,t)=>{e.update(t);let n=t.length%16;n&&e.update(ye.subarray(n))},xe=new Uint8Array(32);function Se(e,t,n,r,i){i!==void 0&&E(i,void 0,`AAD`);let a=e(t,n,xe),o=re(r.length,i?i.length:0,!0),s=ge.create(a);i&&be(s,i),be(s,r),s.update(o);let c=s.digest();return j(a,o),c}var Ce=ne({blockSize:64,nonceLength:12,tagLength:16,withAAD:!0},(e=>(t,n,r)=>({encrypt(i,a){let o=i.length;a=B(o+16,a,!1),a.set(i);let s=a.subarray(0,-16);e(t,n,s,s,1);let c=Se(e,t,n,s,r);return a.set(c,o),j(c),a},decrypt(i,a){a=B(i.length-16,a,!1);let o=i.subarray(0,-16),s=i.subarray(-16),c=Se(e,t,n,o,r);if(!ee(s,c))throw j(c),Error(`invalid tag`);return a.set(i.subarray(0,-16)),e(t,n,a,a,1),j(c),a}}))(ve)),we=`deepview-triage-sync.v1.content-key`,Te=`deepview-triage-sync.v1.sign-key`,Ee=`deepview-triage-sync.v1.save`,De=`deepview-triage-sync.v1.subscribe`,Oe=12,ke=new Uint8Array([48,46,2,1,0,48,5,6,3,43,101,112,4,34,4,32]),Ae=null;function je(){return Ae||(Ae=(async()=>{try{return await crypto.subtle.importKey(`raw`,new Uint8Array(32),{name:`ChaCha20-Poly1305`},!1,[`encrypt`,`decrypt`]),!0}catch{return!1}})(),Ae)}async function Me(e,t){let n=Uint8Array.fromBase64(e);if(n.length!==32)throw Error(`workspace private key must be 32 bytes (got ${n.length})`);let r=await crypto.subtle.importKey(`raw`,n,`HKDF`,!1,[`deriveBits`]),i=await crypto.subtle.deriveBits({name:`HKDF`,hash:`SHA-256`,salt:new Uint8Array,info:b(t)},r,256);return new Uint8Array(i)}async function Ne(e){return await Me(e,we)}async function Pe(e,t){let n=await Me(e,`${Te}|${t}`),r=new Uint8Array(ke.length+32);r.set(ke,0),r.set(n,ke.length);let i=await crypto.subtle.importKey(`pkcs8`,r,{name:`Ed25519`},!0,[`sign`]),a=await crypto.subtle.exportKey(`jwk`,i),o=a.x;if(delete a.d,o==null)throw Error(`Ed25519 JWK export returned no public key`);let s=Uint8Array.fromBase64(o,{alphabet:`base64url`}),c=await crypto.subtle.importKey(`pkcs8`,r,{name:`Ed25519`},!1,[`sign`]);return n.fill(0),r.fill(0),{privateKey:c,publicKey:s,publicKeyB64:o}}function Fe({publicKeyB64:e,base:t,keyframe:n,nonceB64:r,ciphertextB64:i}){return b([Ee,e,t==null?``:String(t),n===!0?`1`:``,r,i].join(`
2
2
  `))}async function Ie(e,t){let n=await crypto.subtle.sign({name:`Ed25519`},e,t);return new Uint8Array(n).toBase64({alphabet:`base64url`,omitPadding:!0})}async function Le(e,t){return await Ie(e,Fe(t))}async function Re(e){let t=Fe(e),n=await crypto.subtle.digest(`SHA-256`,t);return new Uint8Array(n).toBase64({alphabet:`base64url`,omitPadding:!0})}function ze(e,t,n){return b([De,e,t==null?``:String(t),n].join(`
3
- `))}async function Be(e,t,n,r){return await Ie(e,ze(t,n,r))}async function Ve(e,t,n){try{let r=await crypto.subtle.importKey(`raw`,e,{name:`Ed25519`},!1,[`verify`]),i=Uint8Array.fromBase64(n,{alphabet:`base64url`}),a=Fe(t);return await crypto.subtle.verify({name:`Ed25519`},r,i,a)}catch{return!1}}function He(){let e=new Uint8Array(Oe);return crypto.getRandomValues(e),e}function Ue(e,t){return b(`${e}|${t==null?``:String(t)}`)}async function We(e,t,n){let r=He();if(await je()){let i=await crypto.subtle.importKey(`raw`,e,{name:`ChaCha20-Poly1305`},!1,[`encrypt`]);return{nonce:r,ciphertext:new Uint8Array(await crypto.subtle.encrypt({name:`ChaCha20-Poly1305`,iv:r,additionalData:n},i,t))}}return{nonce:r,ciphertext:Ce(e,r,n).encrypt(t)}}async function Ge(e,t,n,r){if(await je()){let i=await crypto.subtle.importKey(`raw`,e,{name:`ChaCha20-Poly1305`},!1,[`decrypt`]);return new Uint8Array(await crypto.subtle.decrypt({name:`ChaCha20-Poly1305`,iv:t,additionalData:r},i,n))}return Ce(e,t,r).decrypt(n)}var Ke=64;function qe(e,t){return e<=t?t:2**(32-Math.clz32(e-1))}async function Je(e){let t=b(JSON.stringify(e)),n=await v(t);if(n.length>1073741820)throw Error(`payload too large`);let r=qe(4+n.length,Ke),i=new Uint8Array(r);return new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,n.length,!1),i.set(n,4),i}var Ye=67108864;async function Xe(e){if(e.length<4)throw Error(`plaintext too short`);let t=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(0,!1);if(t+4>e.length)throw Error(`length prefix exceeds buffer`);let n=e.subarray(4,4+t),r=await y(n,{maxBytes:Ye});return JSON.parse(x(r))}async function Ze(e,t,n){let{nonce:r,ciphertext:i}=await We(e,await Je(t),n);return{nonce:r.toBase64(),ciphertext:i.toBase64()}}async function Qe(e,t,n,r){return Xe(await Ge(e,Uint8Array.fromBase64(t),Uint8Array.fromBase64(n),r))}var $e=`deepview-objstore.v1.content`,et=`deepview-objstore.v1.tag`,tt=`objstore-tag
3
+ `))}async function Be(e,t,n,r){return await Ie(e,ze(t,n,r))}async function Ve(e,t,n){try{let r=await crypto.subtle.importKey(`raw`,e,{name:`Ed25519`},!1,[`verify`]),i=Uint8Array.fromBase64(n,{alphabet:`base64url`}),a=Fe(t);return await crypto.subtle.verify({name:`Ed25519`},r,i,a)}catch{return!1}}function He(){let e=new Uint8Array(Oe);return crypto.getRandomValues(e),e}function Ue(e,t){return b(`${e}|${t==null?``:String(t)}`)}async function We(e,t,n){let r=He();if(await je()){let i=await crypto.subtle.importKey(`raw`,e,{name:`ChaCha20-Poly1305`},!1,[`encrypt`]);return{nonce:r,ciphertext:new Uint8Array(await crypto.subtle.encrypt({name:`ChaCha20-Poly1305`,iv:r,additionalData:n},i,t))}}return{nonce:r,ciphertext:Ce(e,r,n).encrypt(t)}}async function Ge(e,t,n,r){if(await je()){let i=await crypto.subtle.importKey(`raw`,e,{name:`ChaCha20-Poly1305`},!1,[`decrypt`]);return new Uint8Array(await crypto.subtle.decrypt({name:`ChaCha20-Poly1305`,iv:t,additionalData:r},i,n))}return Ce(e,t,r).decrypt(n)}var Ke=64;function qe(e,t){return e<=t?t:2**(32-Math.clz32(e-1))}async function Je(e){let t=b(JSON.stringify(e)),n=await v(t);if(n.length>0x3ffffffc)throw Error(`payload too large`);let r=qe(4+n.length,Ke),i=new Uint8Array(r);return new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,n.length,!1),i.set(n,4),i}var Ye=67108864;async function Xe(e){if(e.length<4)throw Error(`plaintext too short`);let t=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(0,!1);if(t+4>e.length)throw Error(`length prefix exceeds buffer`);let n=e.subarray(4,4+t),r=await y(n,{maxBytes:Ye});return JSON.parse(x(r))}async function Ze(e,t,n){let{nonce:r,ciphertext:i}=await We(e,await Je(t),n);return{nonce:r.toBase64(),ciphertext:i.toBase64()}}async function Qe(e,t,n,r){return Xe(await Ge(e,Uint8Array.fromBase64(t),Uint8Array.fromBase64(n),r))}var $e=`deepview-objstore.v1.content`,et=`deepview-objstore.v1.tag`,tt=`objstore-tag
4
4
  `,nt=`objstore-bundle-tag
5
5
  `,rt=12,it=16;async function at(e,t){let n=Uint8Array.fromBase64(e);if(n.length!==32)throw Error(`workspace private key must be 32 bytes (got ${n.length})`);let r=await ot(n,$e,32),i=await ot(n,et,32);n.fill(0);let{privateKey:a,publicKeyB64:o}=await Pe(e,t);return{signingKey:a,contentKey:r,tagKey:i,workspaceTag:o}}async function ot(e,t,n){let r=await crypto.subtle.importKey(`raw`,e,`HKDF`,!1,[`deriveBits`]),i=await crypto.subtle.deriveBits({name:`HKDF`,hash:`SHA-256`,salt:new Uint8Array,info:b(t)},r,n*8);return new Uint8Array(i)}async function U(e,t){let n=await crypto.subtle.importKey(`raw`,e,{name:`HMAC`,hash:`SHA-256`},!1,[`sign`]);return new Uint8Array(await crypto.subtle.sign(`HMAC`,n,b(tt+t))).toBase64({alphabet:`base64url`,omitPadding:!0})}async function st(e,t){let n=await crypto.subtle.importKey(`raw`,e,{name:`HMAC`,hash:`SHA-256`},!1,[`sign`]);return new Uint8Array(await crypto.subtle.sign(`HMAC`,n,b(nt+t))).toBase64({alphabet:`base64url`,omitPadding:!0})}function ct(e,t,n,r,i){let a=b(t);if(a.length>65535)throw Error(`fileName too long: ${a.length} bytes (max 65535)`);let o=new Uint8Array(2+a.length+n.length);new DataView(o.buffer).setUint16(0,a.length,!1),o.set(a,2),o.set(n,2+a.length);let s=new Uint8Array(rt);crypto.getRandomValues(s);let c=Ce(e,s,b(`${r}
6
6
  ${i}`)).encrypt(o),l=new Uint8Array(rt+c.length);return l.set(s,0),l.set(c,rt),l}function lt(e,t){return rt+2+b(e).length+t+it}function ut(e,t){let n=b(e);if(n.length>65535)throw Error(`bundle name too long: ${n.length} bytes (max 65535)`);let r=new Uint8Array(2+n.length+t.length);return new DataView(r.buffer).setUint16(0,n.length,!1),r.set(n,2),r.set(t,2+n.length),r}function dt(e){if(e.length<2)throw Error(`bundle wrapped content truncated: ${e.length} bytes`);let t=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint16(0,!1);if(2+t>e.length)throw Error(`bundle wrapped nameLen ${t} overflows ${e.length}`);return{name:new TextDecoder(`utf-8`,{fatal:!0}).decode(e.subarray(2,2+t)),content:new Uint8Array(e.subarray(2+t))}}function ft(e,t,n,r){if(t.length<rt+16)throw Error(`objstore payload too short: ${t.length} bytes`);let i=t.subarray(0,rt),a=t.subarray(rt),o=Ce(e,i,b(`${n}