PageSourceSearch

https://phasoric.com/assets/workspace-bootstrap-BlZDnksD.js

js phasoric.com collected 2026-09-24 14:52:26 UTC 12,638 bytes, 1 lines download raw bytes

1import{r as F}from"./rolldown-runtime-BNNRdYrd.js";import{G as V,J as W,U as J,X as Q,at as b,nt as R,rt as z,tt as P}from"./index-BQuIkJiK.js";import{m as O,o as B,s as ee}from"./db-Dgd9zlNH.js";import{s as $}from"./desktop-vault-binding-CVzuZYam.js";import{a as G}from"./permanent-memory-BEUfT4yj.js";import{_ as te}from"./metadata-sync-BmUSMven.js";import{b as q,l as H,s as j,x as re,y as oe}from"./cloud-sources-0yR8nunz.js";async function ae(e=null){const t=V();if(!e||e.localOnly){const o=R();return{workspaceId:o,source:o?"local":"none",isNew:!o}}try{const o=await fetch("/api/workspace/identity",{credentials:"include"});if(o.ok){const n=await o.json();if(t(),n.primaryWorkspaceId)return P(n.primaryWorkspaceId,e.id),b(n.primaryWorkspaceId,{label:n.tenantName||"Hosted workspace",linkedAccountId:e.id}),{workspaceId:n.primaryWorkspaceId,source:"server_account",isNew:!1,metadata:n}}}catch(o){if(o.code==="ACCOUNT_CONTEXT_CHANGED")throw o}try{t();const o=await fetch("/api/connections",{credentials:"include"});if(o.ok){const{connections:n}=await o.json();t();for(const r of n||[])if(r.status==="connected"&&r.workspaceManifest?.workspaceId){const c=r.workspaceManifest.workspaceId;return P(c,e.id),b(c,{label:`${r.provider} vault`,linkedAccountId:e.id,providerLabels:[r.provider]}),{workspaceId:c,source:`provider_manifest:${r.provider}`,isNew:!1,metadata:r.workspaceManifest}}}}catch(o){if(o.code==="ACCOUNT_CONTEXT_CHANGED")throw o}return t(),{workspaceId:null,source:"none",isNew:!0}}var ne="recovery_checkpoint";async function ie(e){try{return(await e.metadata.get("recovery_checkpoint"))?.value||null}catch{return null}}async function U(e,{notes:t=[],attachments:o=[],noteHeaders:n=[],objectMetadata:r=[],checkpoint:c}){await e.transaction("rw",[e.notes,e.attachments,e.metadata,e.objectMetadata],async()=>{t.length>0&&await e.notes.bulkPut(t),r.length>0&&await e.objectMetadata.bulkPut(r),o.length>0&&await e.attachments.bulkPut(o),c&&await e.metadata.put({key:ne,value:{...c,updatedAt:Date.now()}})})}var T=class extends Error{constructor(e,t="INVARIANT_VIOLATION"){super(e),this.name="InvariantViolationError",this.code=t}};function ce(e,t={}){if(e==="UNRESOLVED"||e==="RECOVERING"||e==="ADOPTING"||e==="AMBIGUOUS")throw new T(`Illegal provider DELETE attempted while workspace bootstrap state is ${e}. Operation: ${JSON.stringify(t)}`,"RECOVERY_DELETE_PROHIBITED")}function se(e,t={}){if(e==="UNRESOLVED"||e==="RECOVERING"||e==="ADOPTING"||e==="AMBIGUOUS")throw new T(`Illegal provider WRITE caused solely by local absence attempted while workspace bootstrap state is ${e}. Operation: ${JSON.stringify(t)}`,"RECOVERY_ABSENCE_WRITE_PROHIBITED")}function de(e=[],t,o){const n=e.find(r=>r.providerIdentity===t&&r.noteIdentity!==o);if(n)throw new T(`Provider identity '${t}' is already bound to note ID '${n.noteIdentity}', cannot rebind to '${o}'.`,"DUPLICATE_PROVIDER_IDENTITY_BINDING")}async function le({db:e,workspaceId:t,providerAdapters:o=[],bootstrapCoordinator:n=null,isAdoption:r=!1,onProgress:c=()=>{}}){const E=r?"adopt":"rec",u=await ie(e)||{phase:"METADATA",cursor:"",processedCount:0,totalCount:0,generation:`${E}_${Date.now()}`},p=await e.notes.toArray(),h=new Map(p.map(a=>[a.path,a])),I=[],N=[],v=[],w=[],A=[];let l=u.processedCount;for(const a of o){let i=u.cursor||null,g=!0;for(;g;){const k=await a.listRemoteMetadata({cursor:i,limit:100}),X=k.entries||[];for(const s of X){l++;try{s.providerIdentity&&s.noteIdentity&&(de(I,s.providerIdentity,s.noteIdentity),I.push({providerIdentity:s.providerIdentity,noteIdentity:s.noteIdentity}))}catch(m){A.push({id:`ambig_${Date.now()}_${l}`,path:s.path,sourceId:s.providerIdentity,status:"AMBIGUOUS",reason:m.message,createdAt:Date.now()});continue}const C=s.path,D=h.get(C),M={id:s.noteIdentity||D?.id||crypto.randomUUID(),path:C,title:s.title||C.split("/").pop().replace(/\.md$/,""),content:s.content||D?.content||"",updatedAt:s.updatedAt||Date.now(),createdAt:s.createdAt||Date.now(),synced:!0,favorite:!!D?.favorite,archived:!!D?.archived,status:"reconstructed"};N.push(M);for(const m of s.attachments||[])m?.id&&v.push({...m,id:String(m.id),notePath:C,sourceId:m.sourceId||a.sourceId||a.provider||"",updatedAt:Number(m.updatedAt||s.updatedAt||Date.now())});s.objectMetadata&&w.push({id:`om_${M.id}`,targetType:"note",targetPath:C,updatedAt:s.updatedAt||Date.now(),...s.objectMetadata})}i=k.cursor,g=!!(k.hasMore&&i),await U(e,{notes:N,attachments:v,objectMetadata:w,checkpoint:{ph
1ase:"METADATA",cursor:i||"",processedCount:l,totalCount:l,generation:u.generation}}),c({processed:l,phase:"METADATA"})}}return A.length>0&&(await e.syncConflicts.bulkPut(A),n)?(n.transition("AMBIGUOUS",{conflicts:A,message:"Reconstruction halted due to ambiguous provider identities."}),{success:!1,state:"AMBIGUOUS",processed:l}):(await U(e,{checkpoint:{phase:"COMPLETE",cursor:"",processedCount:l,totalCount:l,generation:u.generation}}),await O(t,"INITIALIZED",{recoveryGeneration:u.generation}),{success:!0,state:"INITIALIZED",processed:l})}var ue=class extends T{constructor(e){super(e,"WRITE_BARRIER_VIOLATION"),this.name="WriteBarrierViolationError"}};function x(e){return e==="READY"||e==="INITIALIZED"}function pe(e,t,o={}){if(x(e))return!0;throw t==="DELETE"&&ce(e,o),(t==="WRITE"||t==="FLUSH_QUEUE"||t==="UPLOAD_VAULT")&&(o.causedByLocalAbsence||t==="UPLOAD_VAULT"||t==="FLUSH_QUEUE")&&se(e,o),new ue(`Recovery write barrier blocked remote mutation '${t}' while workspace is in state '${e}'.`)}var ke=F({assertCanMutateRemote:()=>Ie,bootstrapWorkspace:()=>Oe,canMutateRemote:()=>Z,canOpenWorkspaceBeforeReconciliation:()=>he,completeWorkspaceContentRecovery:()=>K,getBootstrapContext:()=>Ee,getBootstrapState:()=>ye,recheckWorkspaceContentRecovery:()=>ve,subscribeBootstrapState:()=>fe,transitionState:()=>d}),f="UNRESOLVED",y={},_=new Set,S=Promise.resolve(),L=0;function ye(){return f}function Ee(){return y}function fe(e){return _.add(e),()=>_.delete(e)}function Re(){for(const e of _)try{e(f,y)}catch{}}function d(e,t={}){return e==="UNRESOLVED"&&(L+=1),(e==="UNRESOLVED"||t.workspaceId&&t.workspaceId!==y.workspaceId)&&(y={}),e==="RECOVERING"&&f!=="RECOVERING"&&!t.recovery&&delete y.recovery,f=e,y={...y,...t,updatedAt:Date.now()},Re(),f}function Ie(e,t={}){if($())throw Object.assign(new Error("This desktop vault is local. Use its filesystem sync application to sync the folder."),{code:"DESKTOP_VAULT_LOCAL_ONLY"});if(Z(t))return!0;pe(f,e,t)}function Z(e={}){if($())return!1;if(x(f))return!0;if(f!=="RECOVERING"||!e.recoveryBinding||y.workspaceId!==R()||y.durability?.state!=="PROTECTED")return!1;try{if(JSON.parse(localStorage.getItem("basalt_session")||"null")?.id!==y.recoveryAccountId)return!1}catch{return!1}return!!(y.recovery?.vaults?.some(o=>o.state==="ready"&&o.localVault===e.localVault&&o.readyBindings.includes(e.recoveryBinding))&&H().some(o=>(o.mappings||[]).some(n=>j(o,n)&&q(o,n).recoveryBinding===e.recoveryBinding)))}function he(e={}){return!e.contentRecoveryRequired||e.localFirstReady===!0}async function Y(e,t){if(!e||e.localOnly)return{ready:!0,durability:{state:"LOCAL_ONLY"}};d("RECONCILING_MEMORY",{workspaceId:t});const o=await te({hosted:!0}),n=await G({hosted:!0}),r=o.mode==="cloud"&&n.state==="PROTECTED";return r||d("RECOVERING",{workspaceId:t,reason:"Permanent semantic memory is not reconciled.",durability:n}),{ready:r,durability:n}}function K(e,t={}){const o=V(),n=t.workspaceId||R(),r=L,c=()=>{if(o(),r!==L||n!==R())throw Object.assign(new Error("The active workspace changed."),{code:"WORKSPACE_CONTEXT_CHANGED"})},E=S.catch(()=>{}).then(()=>(c(),me(e,{...t,workspaceId:n},c)));return S=E,E}async function ve(e){if(f!=="RECOVERING"||!y.contentRecoveryRequired)return null;let t;try{t=JSON.parse(localStorage.getItem("basalt_session")||"null")}catch{return null}return!t?.id||t.localOnly?null:K(t,{syncResult:e})}async function me(e,{workspaceId:t=R(),syncResult:o=null}={},n=()=>{}){if(!e||e.localOnly)return d("READY",{workspaceId:t,durability:{state:"LOCAL_ONLY"}}),{workspaceId:t,state:"READY",durability:{state:"LOCAL_ONLY"}};const r=B(t),c=[],E={},[u,p]=await Promise.all([G({database:r,hosted:!0}),r.noteHeaders.toArray(),r.notes.each(a=>c.push({id:a.id,noteId:a.noteId,path:a.path,hasBody:typeof a.content=="string"})),r.attachments.each(a=>{const i=re(a.notePath||a.logicalPath);E[i]=(E[i]||0)+1})]);if(n(),t!==R())throw Object.assign(new Error("The active workspace changed."),{code:"WORKSPACE_CONTEXT_CHANGED"});const h=H().flatMap(a=>(a.mappings||[]).filter(i=>j(a,i)).map(i=>({source:a,mapping:i,scope:q(a,i)}))),I=new Set(y.recovery?.verifiedBindings||[]);for(const a of[...o?.results||[],...o?.failures||[]]){for(const i of h.filter(g=>
1g.source.id===a.sourceId))I.delete(i.scope.recoveryBinding);for(const i of a.summary?.mappingResults||[]){const g=i.recoveryErrors??i.errors;i.reconciled&&!g?.length&&!i.cancelled&&I.add(i.recoveryBinding)}}const N=new Set(h.map(a=>a.scope.recoveryBinding));for(const a of I)N.has(a)||I.delete(a);const v=oe({headers:p,notes:c,attachmentCounts:E,bindings:h,verifiedBindings:I,protectedMemory:u.state==="PROTECTED"}),w=[...(o?.results||[]).flatMap(a=>a.summary?.errors||[]),...(o?.failures||[]).map(a=>a.message)],A=u.state==="PROTECTED"&&!w.length&&v.every(a=>a.state==="ready"),l={expectedNotes:p.length,restoredNotes:c.filter(a=>a.hasBody).length,missingNoteIds:v.flatMap(a=>a.missingNoteIds).slice(0,20),expectedAttachments:v.reduce((a,i)=>a+i.expectedAttachments,0),restoredAttachments:Object.values(E).reduce((a,i)=>a+i,0),hasRecoveryBinding:h.some(a=>a.mapping.direction!=="push"),verifiedBindings:[...I],vaults:v,syncErrors:w};if(!A){if(await O(t,"RECOVERING",{contentRecoveryRequired:!0,recovery:l}),n(),t!==R())throw Object.assign(new Error("The active workspace changed."),{code:"WORKSPACE_CONTEXT_CHANGED"});return d("RECOVERING",{workspaceId:t,recoveryAccountId:e.id,reason:"Canonical content recovery has not converged.",durability:u,recovery:l,contentRecoveryRequired:!0}),{workspaceId:t,state:"RECOVERING",durability:u,recovery:l,contentRecoveryRequired:!0}}if(await O(t,"INITIALIZED",{contentRecoveryRequired:!1,contentRecoveredAt:Date.now(),recovery:l}),n(),t!==R())throw Object.assign(new Error("The active workspace changed."),{code:"WORKSPACE_CONTEXT_CHANGED"});return d("READY",{workspaceId:t,recoveryAccountId:e.id,durability:u,recovery:l,contentRecoveryRequired:!1}),{workspaceId:t,state:"READY",durability:u,recovery:l}}async function Oe(e=null,{providerAdapters:t=[]}={}){const o=V();d("UNRESOLVED",{user:e});try{z(e),Q()?.deviceOnly&&(e={...e,localOnly:!0});const n=await ae(e);o();let r=n.workspaceId||R();if(!r&&n.isNew){r=W(),b(r,{label:"Personal Workspace"}),B(r),await O(r,"INITIALIZED"),d("INITIALIZED",{workspaceId:r,mode:"NEW_LOCAL"});const p=await Y(e,r);return p.ready?(d("READY",{workspaceId:r,durability:p.durability}),{workspaceId:r,state:"READY"}):{workspaceId:r,state:f,durability:p.durability}}r!==R()?J(r,{reload:!1,accountId:e?.localOnly?"":e?.id||""}):W(r);const c=await ee(r),E=B(r);if(c.state==="RECOVERING"&&c.localContentAvailable)return d("RECOVERING",{workspaceId:r,reason:"Canonical content recovery is continuing in the background.",contentRecoveryRequired:!0,localFirstReady:!0,localNoteCount:c.localNoteCount}),{workspaceId:r,state:"RECOVERING",contentRecoveryRequired:!0,localFirstReady:!0,localNoteCount:c.localNoteCount};if(c.state==="ABSENT"||c.state==="RECOVERING"){if(d("RECOVERING",{workspaceId:r,reason:"Local database absent"}),await O(r,"RECOVERING"),t.length>0){if(!(await le({db:E,workspaceId:r,providerAdapters:t,bootstrapCoordinator:{transition:d},onProgress:h=>d("RECOVERING",{progress:h})})).success)return{workspaceId:r,state:f}}else await O(r,"RECOVERING",{contentRecoveryRequired:!0});d("INITIALIZED",{workspaceId:r});const p=await Y(e,r);return p.ready?!e?.localOnly&&t.length===0?(await O(r,"RECOVERING",{contentRecoveryRequired:!0}),d("RECOVERING",{workspaceId:r,reason:"Waiting for connected storage bindings to restore canonical content.",durability:p.durability,contentRecoveryRequired:!0}),{workspaceId:r,state:"RECOVERING",durability:p.durability,contentRecoveryRequired:!0}):(d("READY",{workspaceId:r,durability:p.durability}),{workspaceId:r,state:"READY"}):{workspaceId:r,state:f,durability:p.durability}}d("INITIALIZED",{workspaceId:r});const u=await G({database:E,hosted:!!(e&&!e.localOnly)});return d("READY",{workspaceId:r,durability:u,routineReconciliationRequired:!!(e&&!e.localOnly)}),{workspaceId:r,state:"READY",durability:u,routineReconciliationRequired:!!(e&&!e.localOnly)}}catch(n){throw d("ERROR",{error:n.message}),n}}export{fe as a,ve as i,Z as n,ke as o,ye as r,Ie as t};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.