@fleox-agent-crm/agentcrm 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -16
- package/changelog.json +19 -0
- package/dist/admin/admin-files.json +8 -8
- package/dist/admin/assets/{chartsImpl-CE2akJat.js → chartsImpl-B45AAqnr.js} +30 -30
- package/dist/admin/assets/{firebase-BHSUggRo.js → firebase-C1x_l9P9.js} +2 -2
- package/dist/admin/assets/{gitJson-BulGh2KV.js → gitJson-CAUSxl8d.js} +1 -1
- package/dist/admin/assets/{index-DidVVK7L.js → index-ChFauO8y.js} +265 -265
- package/dist/admin/assets/{index-hMXwHSvN.css → index-TcjySLVg.css} +1 -1
- package/dist/admin/assets/{lucide-react.min-DEDlHCPj.js → lucide-react.min--rznIkmQ.js} +1 -1
- package/dist/admin/assets/{sdk-CnrLnlRo.js → sdk-DgzLACmL.js} +1 -1
- package/dist/admin/index.html +2 -2
- package/dist/agent/agentcrm.mjs +267 -142
- package/dist/agent/chunks/{api-B6OqNVWp.mjs → api-Cz0Ubj-B.mjs} +4 -3
- package/dist/agent/chunks/{appearance-BaShelzt.mjs → appearance-BloHbiLA.mjs} +1 -1
- package/dist/agent/chunks/{automations-BWrvLqP6.mjs → automations-DwWruxmu.mjs} +3 -3
- package/dist/agent/chunks/{backup-ClSmxmFZ.mjs → backup-W3CjgkAJ.mjs} +16 -3
- package/dist/agent/chunks/{compact-CsFPaAAq.mjs → compact-BGHI92tm.mjs} +2 -2
- package/dist/agent/chunks/{exportCsv-B5hRvkNm.mjs → exportCsv-C6e6XEmB.mjs} +38 -3
- package/dist/agent/chunks/{extCheck--7lmVvl7.mjs → extCheck-GgHG1dYB.mjs} +16 -9
- package/dist/agent/chunks/{extPackage-BGl5Oqs8.mjs → extPackage-DuZ6GZhp.mjs} +2 -2
- package/dist/agent/chunks/{extScaffold-DqxI7R1e.mjs → extScaffold-Aqyjf1nr.mjs} +3 -3
- package/dist/agent/chunks/{extensions-BP1k60md.mjs → extensions-Bp72uZ9a.mjs} +19 -6
- package/dist/agent/chunks/{featureRegistry-C9nbVShp.mjs → featureRegistry-DSsZbhrh.mjs} +3 -3
- package/dist/agent/chunks/{files-q8Xu5bft.mjs → files-D1daDgY0.mjs} +1 -1
- package/dist/agent/chunks/{forms-BKU5F9WF.mjs → forms-BfuWaQjA.mjs} +1 -1
- package/dist/agent/chunks/{importCsv-DmE_sBch.mjs → importCsv-LVmMTaWU.mjs} +2 -2
- package/dist/agent/chunks/{install-CpHoUFtL.mjs → install-CbpD_7gd.mjs} +3 -3
- package/dist/agent/chunks/{loader-C9nm3iwx.mjs → loader-MPD9iAvh.mjs} +20 -20
- package/dist/agent/chunks/{modules-CqdVQVJb.mjs → modules-clWdE-K2.mjs} +27 -2
- package/dist/agent/chunks/{nodeImport-BPCt5uMu.mjs → nodeImport-ylfRDvqt.mjs} +2 -2
- package/dist/agent/chunks/{package-DWbn3t2R.mjs → package-B7mI6HGi.mjs} +1 -1
- package/dist/agent/chunks/{papaparse-DjBYnQM2.mjs → papaparse-Df7i1dHr.mjs} +31 -7
- package/dist/agent/chunks/{pipelines-DCdRBNBV.mjs → pipelines-BAKpPk1w.mjs} +1 -1
- package/dist/agent/chunks/{plan-C0TBrU92.mjs → plan-BmTat6-T.mjs} +1 -1
- package/dist/agent/chunks/{records-DoqiT9xR.mjs → records-DcHFelq5.mjs} +5 -1
- package/dist/agent/chunks/{registry-Ceexawxl.mjs → registry-COfJrSmg.mjs} +18 -18
- package/dist/agent/chunks/{reports-BB59N6ke.mjs → reports-BACHGccj.mjs} +3 -3
- package/dist/agent/chunks/{runtime-DHo7ZEEO.mjs → runtime-C0Xf0Axi.mjs} +53 -32
- package/dist/agent/chunks/{schema-DlHt2PxI.mjs → schema-C4lSslXv.mjs} +10 -4
- package/dist/agent/chunks/{schema-7-4-qtSS.mjs → schema-DnLj8dUO.mjs} +10 -0
- package/dist/agent/chunks/{seed-CugPGYZL.mjs → seed-6MRmQQBR.mjs} +26 -8
- package/dist/agent/chunks/{server-ISwlDRCN.mjs → server-DC3t8r30.mjs} +5 -5
- package/dist/agent/chunks/{settings-BtvR_jdm.mjs → settings-Di8nzNEL.mjs} +35 -0
- package/dist/agent/chunks/{stats-CfeJssSS.mjs → stats-BfuLWhVV.mjs} +2 -2
- package/dist/agent/chunks/{tools-Bew8lxKx.mjs → tools-iSH-yMpl.mjs} +59 -19
- package/dist/agent/chunks/{views-fO_BM5U_.mjs → views-DH1n9Lrt.mjs} +1 -1
- package/dist/version.json +1 -1
- package/package.json +1 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/skills/agentcrm-admin/SKILL.md +67 -67
- package/plugin/skills/agentcrm-admin/references/appearance.md +1 -1
- package/plugin/skills/agentcrm-admin/references/records.md +5 -5
- package/plugin/skills/agentcrm-admin/references/schema.md +20 -20
- package/plugin/skills/agentcrm-extensions/SKILL.md +9 -9
- package/plugin/skills/agentcrm-extensions/references/module-recipes.md +2 -2
- package/plugin/skills/agentcrm-extensions/references/testing.md +16 -14
- package/plugin/skills/agentcrm-extensions/references/theme-recipes.md +3 -3
- package/plugin/skills/agentcrm-install/SKILL.md +13 -13
- package/plugin/skills/agentcrm-install/references/firebase.md +1 -1
- package/plugin/skills/agentcrm-install/references/github.md +1 -1
- package/plugin/skills/agentcrm-install/references/mcp.md +3 -3
- package/plugin/skills/agentcrm-install/references/plans.md +1 -1
- package/plugin/skills/agentcrm-install/references/s3.md +1 -1
- package/plugin/skills/agentcrm-manage/SKILL.md +15 -15
- package/plugin/skills/agentcrm-sales/SKILL.md +18 -18
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./sdk-
|
|
2
|
-
import{c as Y,w as Z,_ as ee,C as L,e as te,p as z,n as ie,r as ne,F as K,a as se}from"./index-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./sdk-DgzLACmL.js","./index-ChFauO8y.js","./index-TcjySLVg.css","./index.esm-Dum0J07z.js","./index.esm2017-EOzKbpUS.js","./index.esm-CtEQZRb1.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{c as Y,w as Z,_ as ee,C as L,e as te,p as z,n as ie,r as ne,F as K,a as se}from"./index-ChFauO8y.js";const oe=Symbol("deleteField");function G(e){return(e==null?void 0:e.code)??""}function _(e){const n=G(e);return n==="permission-denied"||n==="firestore/permission-denied"}const re=500;function ce(e,n){const s=[];for(let t=0;t<e.length;t+=n)s.push(e.slice(t,t+n));return s}const j="invites",F="extensionChunks",x=3e5,ae=["admin","member","viewer"];class N extends Error{constructor(n,s,t){super(s),this.reason=n,this.email=t,this.name="FirebaseAccessError"}}function be(e){return e.kind==="firebase"&&typeof e.accessError=="function"}function W(e){const{id:n,...s}=z(e);return s}function le(e){return ie({...e.data,id:e.id})}function T(e){return typeof e=="string"&&ae.includes(e)}function E(e){return typeof e=="string"?e.trim().toLowerCase():""}function H(e){return!!e&&!e.authUid&&!!E(e.email)}function ue(e,n,s){const t=new Map;for(const i of e){if(i.collection!=="users")continue;const c=i.op==="set"?i.doc.id:i.id,a=n(c),p=s.users.get(c),h=H(a)?E(a.email):"",m=H(p)?E(p.email):"";h&&h!==m&&t.set(h,{type:"delete",collection:j,id:h}),m&&p&&(p.disabled?t.set(m,{type:"delete",collection:j,id:m}):t.set(m,{type:"set",collection:j,id:m,data:{role:T(p.role)?p.role:"member",userId:c,email:m}}))}return[...t.values()]}const B=(e,n,s)=>`${e}__${n}__${s}`;function X(e){const n=(e==null?void 0:e.files)??{},s={};for(const[t,i]of Object.entries(n))typeof i=="string"&&(s[t]=Math.ceil(i.length/x));return s}function fe(e,n){const s=e.files??{},t=Object.values(s).reduce((p,h)=>p+(typeof h=="string"?h.length:0),0),i=[],c={},a=W(e);if(t>x){for(const[p,h]of Object.entries(s)){if(typeof h!="string")continue;const m=Math.ceil(h.length/x);c[p]=m;for(let y=0;y<m;y++)i.push({type:"set",collection:F,id:B(e.id,p,y),data:{ext:e.id,file:p,index:y,data:h.slice(y*x,(y+1)*x)}})}a.files={},a.chunks=c}for(const[p,h]of Object.entries(X(n)))for(let m=c[p]??0;m<h;m++)i.push({type:"delete",collection:F,id:B(e.id,p,m)});return i.unshift({type:"set",collection:"extensions",id:e.id,data:a}),i}function de(e,n){const s=new Map;for(const t of n){const i=String(t.data.ext??"");s.set(i,[...s.get(i)??[],t])}return e.map(t=>{const i=t.data.chunks;if(!i||typeof i!="object")return t;const c={},a=s.get(t.id)??[];for(const[m,y]of Object.entries(i)){const C=a.filter(O=>O.data.file===m).sort((O,D)=>Number(O.data.index)-Number(D.data.index));C.length===y&&(c[m]=C.map(O=>String(O.data.data??"")).join(""))}const{chunks:p,...h}=t.data;return{id:t.id,data:{...h,files:c}}})}function pe(e,n){const s=[];for(const t of e)if(t.op==="set"&&t.collection==="extensions")s.push(...fe(t.doc,n.extensions.get(t.doc.id)));else if(t.op==="set")s.push({type:"set",collection:t.collection,id:t.doc.id,data:W(t.doc)});else if(t.op==="delete"){if(s.push({type:"delete",collection:t.collection,id:t.id}),t.collection==="extensions")for(const[i,c]of Object.entries(X(n.extensions.get(t.id))))for(let a=0;a<c;a++)s.push({type:"delete",collection:F,id:B(t.id,i,a)})}else{if(!n[t.collection].has(t.id))continue;const i={};for(const[c,a]of Object.entries(t.fields))c==="id"||c.startsWith("id.")||(i[c]=a===void 0?oe:z(a));Object.keys(i).length&&s.push({type:"update",collection:t.collection,id:t.id,data:i})}return s}const he="files",q="Firebase Storage isn't enabled for this project: enable it in the Firebase console (Build → Storage), add `storageBucket` to the web config and deploy the storage rules (docs/files.md).";function me(e){const n=()=>{if(!e.storage)throw new K(q);return e.storage},s=i=>(se(i),`${he}/${i}`),t=async i=>{try{return await i()}catch(c){const a=G(c);throw a==="storage/unknown"||a==="storage/bucket-not-found"||a==="storage/no-default-bucket"?new K(q):c}};return{kind:"firebase",put:(i,c,a)=>t(()=>n().put(s(i),c,a==null?void 0:a.mime)),async putMany(i){for(const c of i)await t(()=>{var a;return n().put(s(c.id),c.bytes,(a=c.meta)==null?void 0:a.mime)})},get:i=>t(()=>n().get(s(i))),delete:i=>t(()=>n().delete(s(i)))}}function ge(e){const n=e.api,s=e.requireVerifiedEmail!==!1,t=e.now??Date.now;let i=null,c=null,a=null,p=new Map,h=!1;const m=n.auth.onChange(o=>{(!o||o.uid!==(c==null?void 0:c.uid))&&(i=null,c=null)});function y(o,r){const f=te();for(const d of L){const g=d==="extensions"?de(o.get(d)??[],r):o.get(d)??[];for(const l of g)f[d].set(l.id,le(l))}p=new Map(f.users);for(const d of[...f.users.values()])typeof d.replaces=="string"&&d.replaces!==d.id&&f.users.delete(d.replaces);return f}async function C(o){try{return await n.listCollection(o)}catch(r){if(_(r))return[];throw r}}async function O(o){const r=E(o.email);let f=null;try{f=await n.getDoc("users",o.uid)}catch(u){if(!_(u))throw u}if(f)return T(f.role)?f.role:"viewer";if(s&&!o.emailVerified)throw new N("unverified","Verify your email address to continue.",r);const d={email:r,name:o.displayName||r.split("@")[0]||"User",authUid:o.uid,createdAt:t(),updatedAt:t(),...o.photoURL?{avatarUrl:o.photoURL}:{}},g=(u,b={})=>n.commit([{type:"set",collection:"users",id:o.uid,data:{...d,...b,role:u}}]);try{return await g("admin"),"admin"}catch(u){if(!_(u))throw u}let l=null;try{l=r?await n.getDoc(j,r):null}catch(u){if(!_(u))throw u}const w=l&&T(l.role)?l.role:"member";try{return await g(w,l&&typeof l.userId=="string"?{replaces:l.userId}:{}),w}catch(u){if(!_(u))throw u}throw new N("notInvited","This account has not been invited to this CRM. Ask an admin to add your email in Settings → Users.",r)}async function D(){const o=await n.auth.currentUser();if(!o)return a=null,null;try{const r=await O(o);return a=null,{uid:o.uid,email:E(o.email),displayName:o.displayName||E(o.email),role:r}}catch(r){return a=r instanceof N?r:new N("error",r.message,E(o.email)),null}}async function J(o,r,f){const d=pe(o,r);(c==null?void 0:c.role)==="admin"&&d.push(...ue(o,g=>r.users.get(g)??p.get(g),f));for(const g of ce(d,re))await n.commit(g);for(const g of o){if(g.collection!=="users")continue;const l=g.op==="set"?g.doc.id:g.id,w=f.users.get(l);w?p.set(l,w):p.delete(l)}}const S=Y({kind:"firebase",async load(){const o=new Map;let r=[];await Promise.all([...L.map(async d=>o.set(d,await C(d))),C(F).then(d=>r=d)]);const f=y(o,r);return P(),f},persist:(o,r,f)=>J(o,r,f),watch(o){const r=new Map;let f=null;const d=()=>{r.size<L.length||f===null||(o(y(r,f)),P())},g=L.map(l=>n.watchCollection(l,w=>{r.set(l,w),d()},w=>{_(w)?r.set(l,[]):console.warn(`[firebase] live updates of ${l} stopped:`,w)}));return g.push(n.watchCollection(F,l=>{f=l,d()},l=>{_(l)?f=[]:console.warn("[firebase] live updates of extension chunks stopped:",l)})),()=>g.forEach(l=>l())},identity(){return i||(i=D().then(o=>(c=o,o||(i=null),o))),i},close(){m()}});function P(){if((c==null?void 0:c.role)!=="admin"||h)return;const o=[...p.values()].filter(r=>typeof r.replaces=="string");o.length&&(h=!0,setTimeout(()=>{Q(o).finally(()=>h=!1)},0))}async function Q(o){var l;const r=[],f=[],d=S.list("objects"),g=new Map(d.map(w=>[w.id,(w.fields??[]).filter(u=>u.type==="user").map(u=>u.id)]));for(const w of o){const u=w.replaces,b=w.id,k=p.get(u);for(const v of S.list("records")){const I={};v.ownerId===u&&(I.ownerId=b),v.createdBy===u&&(I.createdBy=b);for(const M of g.get(v.object)??[]){const A=(l=v.fields)==null?void 0:l[M];A===u?I[`fields.${M}`]=b:Array.isArray(A)&&A.includes(u)&&(I[`fields.${M}`]=A.map(V=>V===u?b:V))}Object.keys(I).length&&r.push({op:"patch",collection:"records",id:v.id,fields:I})}for(const v of S.list("activities"))v.assigneeId===u&&r.push({op:"patch",collection:"activities",id:v.id,fields:{assigneeId:b}});const R=S.get("settings","general");(R==null?void 0:R.ownerUserId)===u&&r.push({op:"patch",collection:"settings",id:"general",fields:{ownerUserId:b}}),k&&(r.push({op:"delete",collection:"users",id:u}),E(k.email)&&f.push({type:"delete",collection:j,id:E(k.email)})),r.push({op:"patch",collection:"users",id:b,fields:{replaces:void 0,...k&&k.role!==w.role&&T(k.role)?{role:k.role}:{}}})}try{await S.write(r,{message:"Link invited users"}),f.length&&await n.commit(f)}catch(w){console.warn("[firebase] could not link invited users:",w)}}return Z(S,me(n)),Object.assign(S,{api:n,accessError:()=>a,resetSession(){i=null,c=null,a=null}})}const $=new Map;function we(e){const n=e.firebase.projectId??"default";let s=$.get(n);return s||(s=ee(()=>import("./sdk-DgzLACmL.js"),__vite__mapDeps([0,1,2,3,4,5]),import.meta.url).then(t=>t.createSdkFirebaseApi(e.firebase)),$.set(n,s),s.catch(()=>$.delete(n))),s}let U=null;ne("firebase",{async signOut(){await(U==null?void 0:U.auth.signOut())}});async function Ee(e,n={}){var i;const s=e;if(!((i=s.firebase)!=null&&i.apiKey)||!s.firebase.projectId)throw new Error("The Firebase web config (apiKey, projectId) is missing.");const t=await we(s);return U=t,ge({api:t})}export{oe as DELETE_FIELD,F as EXTENSION_CHUNKS_COLLECTION,x as EXTENSION_CHUNK_CHARS,re as FIRESTORE_BATCH_LIMIT,N as FirebaseAccessError,j as INVITES_COLLECTION,he as STORAGE_FILES_DIR,q as STORAGE_NOT_ENABLED,de as assembleExtensionDocs,ce as chunk,Ee as createFirebaseStore,ge as createFirebaseStoreWith,E as emailKey,G as errorCode,we as firebaseApiFor,me as firebaseFileStore,ue as inviteOps,be as isFirebaseStore,_ as isPermissionDenied,pe as mutationOps};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{i as V,e as X,n as Q,s as U,d as G,f as Z,S as tt,C as et,j as O,c as nt,w as st,h as ot,G as J,a as L,k as rt,D as C,l as it,m as at,o as ct,q as lt,t as ft,u as B,v as ut,x as P,y as ht,z as dt,A as pt}from"./index-
|
|
1
|
+
import{i as V,e as X,n as Q,s as U,d as G,f as Z,S as tt,C as et,j as O,c as nt,w as st,h as ot,G as J,a as L,k as rt,D as C,l as it,m as at,o as ct,q as lt,t as ft,u as B,v as ut,x as P,y as ht,z as dt,A as pt}from"./index-ChFauO8y.js";import{B as Dt}from"./index-ChFauO8y.js";const gt="agentcrm-git-json",yt=1,v="agentcrm.json";function D(t,e){return`${t}/${e}`}function A(t){return encodeURIComponent(t).replace(/\./g,"%2E")}function mt(t){try{return decodeURIComponent(t)}catch{return t}}function wt(t,e){if(t==="records"){const s=typeof e.object=="string"&&e.object?e.object:"_";return`records/${A(s)}/${A(e.id)}.json`}return`${t}/${A(e.id)}.json`}function H(t){const e=t.split("/"),[s]=e;if(!V(s))return null;const a=e[e.length-1];if(!a.endsWith(".json")||(s==="records"?e.length!==3:e.length!==2))return null;const i=mt(a.slice(0,-5));return i?{collection:s,id:i}:null}function K(t){return t===v||H(t)!==null}function bt(t){return JSON.stringify(t,null,2)+`
|
|
2
2
|
`}function R(t,e,s){if(Array.isArray(t))return t.map((i,o)=>R(i,[...e,String(o)],s));if(!t||typeof t!="object")return t;const a={};for(const[i,o]of Object.entries(t)){if(tt.has(i)&&typeof o=="string"){o&&(s[[...e,i].join(".")]=o);continue}a[i]=R(o,[...e,i],s)}return a}function St(t){const e={};return{doc:R(t,[],e),secrets:e}}function Tt(t,e){if(!e)return t;let s={...t};for(const[a,i]of Object.entries(e)){const o=U(a);G(s,o.slice(0,-1))===void 0&&o.length>1||(s=Z(s,o,i))}return s}function jt(t,e={}){const s=X(),a=new Map,i=[];for(const[o,f]of t){const l=H(o);if(!l)continue;let n;try{const c=JSON.parse(f);if(!c||typeof c!="object"||Array.isArray(c))throw new Error("not an object");n={...c,id:l.id}}catch(c){i.push(`${o}: ${c.message}`);continue}l.collection==="config"&&(n=Tt(n,e[l.id])),s[l.collection].set(l.id,Q(n)),a.set(D(l.collection,l.id),o)}return{snapshot:s,index:a,errors:i}}function $t(t,e,s,a,i){const o=new Map(s),f=new Map(a),l={...i},n=new Map,c=new Set;for(const[T,d]of t){const b=D(T,d);if(c.has(b))continue;c.add(b);const w=f.get(b),j=e[T].get(d);if(!j){w&&(n.set(w,{type:"delete",path:w}),o.delete(w),f.delete(b)),T==="config"&&delete l[d];continue}let M=j;if(T==="config"){const I=St(j);M=I.doc,Object.keys(I.secrets).length?l[d]=I.secrets:delete l[d]}const $=wt(T,M),_=bt(M);w&&w!==$&&(n.set(w,{type:"delete",path:w}),o.delete(w)),o.get($)!==_&&n.set($,{type:"put",path:$,content:_}),o.set($,_),f.set(b,$)}return{changes:[...n.values()],files:o,index:f,secrets:l}}function W(){return JSON.stringify({format:gt,version:yt},null,2)+`
|
|
3
3
|
`}function Lt(t){return et.includes(t)}const z=3e4,xt=1e4,kt=3;function At(t){return t.kind==="git-json"&&typeof t.resetSession=="function"}function Et(t){return t.isAdmin?"admin":t.canWrite?"member":"viewer"}function Y(t,e,s){const a=e.kind==="github"?`${t.login}@users.noreply.github.com`:e.kind==="gitlab"?`${t.login}@users.noreply.gitlab.com`:"local@localhost";return{uid:e.kind==="local"?"local":`${e.kind}:${t.login}`,email:(s==null?void 0:s.trim().toLowerCase())||a,displayName:t.login,role:e.kind==="local"?"admin":Et(t)}}const F="files",Mt=5*1024*1024;function q(t){return[t.collection,t.op==="set"?t.doc.id:t.id]}const N=(t,e)=>JSON.stringify(t??null)===JSON.stringify(e??null);function Ot(t,e,s,a="Someone else changed this document — reload to see their version."){for(const i of t){const[o,f]=q(i),l=e[o].get(f),n=s[o].get(f);if(!N(l,n)){if(i.op==="patch"){if(!n)throw new C(a,o,f);for(const[c,T]of Object.entries(i.fields)){const d=U(c),b=G(l,d),w=G(n,d);if(!N(b,w)&&!N(w,T))throw new C(a,o,f);for(let j=1;j<d.length;j++){const M=G(l,d.slice(0,j)),$=G(n,d.slice(0,j));if(M===void 0!=($===void 0))throw new C(a,o,f)}}continue}if(!(i.op==="set"&&N(n,i.doc))&&!(i.op==="delete"&&!n))throw new C(a,o,f)}}}function _t(t){const e=t.dir.replace(/^\/+|\/+$/g,""),s=r=>e?r.slice(e.length+1):r,a=r=>!e||r.startsWith(e+"/"),i=t.messageSuffix??" — AgentCRM [skip ci]",o=t.secrets??{read:()=>({}),write:()=>{}};let f=null,l=null,n=null,c=!1;async function T(){return f||(f=await t.openTransport()),f}async function d(){const r=await T();if(!r)throw new Error("Not connected to the data repository on this browser (missing token or folder access).");return r}async function b(){const r=await d(),u=await r.listTree(),p=u.entries.filter(E=>a(E.path)&&K(s(E.path))),h=await r.readTexts(p),S=new Map;for(const[E,m]of h)S.set(s(E),m);const{snapshot:y,index:g,errors:x}=jt(S,o.read());x.length&&console.warn("[git-json] unreadable files:",x);const k=new Map;for(const E of u.entries){if(!a(E.path))continue;const m=s(E.path);m.startsWith(`${F}/`)&&m.endsWith(".bin")&&k.set(m,E)}return{head:u.headSha,blobs:k,files:S,index:g,snapshot:y,errors:x}}async function w(r,u,p,h){const S=await d();n||(n=await b());for(let y=0;;y++){const g=n;Ot(r,u,g.snapshot);const{next:x}=ot(g.snapshot,r),k=$t(r.map(q),x,g.files,g.index,o.read());if(g.files.has(v)||(k.changes.push({type:"put",path:v,content:W()}),k.files.set(v,W())),k.changes.length===0)return;const E=k.changes.map(m=>m.type==="put"?{type:"put",path:O(e,m.path),content:m.content??""}:{type:"delete",path:O(e,m.path)});try{const m=await S.commit(E,{message:`${h}${i}`,expectedHeadSha:g.head});o.write(k.secrets),n={head:m,blobs:g.blobs,files:k.files,index:k.index,snapshot:x,errors:g.errors},g.snapshot!==u&&y>0&&(c=!0);return}catch(m){if(!(m instanceof J)||y>=kt)throw m}n=await b(),c=!0}}const j=nt({kind:"git-json",pollIntervalMs:t.pollIntervalMs??z,async load(){return n=await b(),c=!1,n.snapshot},persist:w,async poll(){const r=await T();return!r||!n||await r.headSha()===n.head&&!c?null:(n=await b(),c=!1,n.snapshot)},identity(){return l||(l=(async()=>{const r=await T();if(!r)return null;try{const u=await r.permissions();return t.identityFor?t.identityFor(u,r):Y(u,r)}catch(u){return console.warn("[git-json] permission check failed:",u),null}})(),l.then(r=>{r||(l=null,f=null)})),l}}),M=r=>`${F}/${r}.bin`;async function $(r,u){const p=await d(),h=r.map(y=>({...y,path:O(e,y.path)})),S=`${u}${i}`;if(n)try{const y=await p.commit(h,{message:S,expectedHeadSha:n.head}),g=new Map(n.blobs);for(const x of r)x.type==="put"?g.set(x.path,{path:O(e,x.path),sha:""}):g.delete(x.path);n={...n,head:y,blobs:g};return}catch(y){if(!(y instanceof J))throw y}await p.commit(h,{message:S}),c=!0}async function _(r){const u=M(r);let p=n==null?void 0:n.blobs.get(u);if(!p||!p.sha){const S=await(await d()).listTree(),y=O(e,u);p=S.entries.find(g=>g.path===y),p&&n&&n.blobs.set(u,p)}return p??null}const I={kind:"git-json",async put(r,u){await I.putMany([{id:r,bytes:u}])},async putMany(r){var p;if(!r.length)return;for(const h of r)L(h.id);const u=r.reduce((h,S)=>h+S.bytes.length,0);u>Mt&&console.warn(`[git-json] committing ${Math.round(u/1024)} KB of files: git history keeps them forever and large repos get slow.`),await $(r.map(h=>({type:"put",path:M(h.id),content:rt(h.bytes),encoding:"base64"})),`Upload ${r.length===1?((p=r[0].meta)==null?void 0:p.name)??"a file":`${r.length} files`}`)},async get(r){L(r);const u=await _(r);return u?(await d()).readBytes(u):null},async delete(r){L(r),await _(r)&&await $([{type:"delete",path:M(r)}],"Purge a file")},async list(){const u=await(await d()).listTree(),p=O(e,`${F}/`);return u.entries.filter(h=>h.path.startsWith(p)&&h.path.endsWith(".bin")).map(h=>h.path.slice(p.length,-4)).filter(h=>!h.includes("/")).sort()}};return st(j,I),Object.assign(j,{resetSession(){f=null,l=null,n=null,c=!1},loadErrors:()=>(n==null?void 0:n.errors)??[],headSha:()=>(n==null?void 0:n.head)??null})}async function Ft(t,e){const s=e.replace(/^\/+|\/+$/g,""),a=await t.listTree(),i=a.entries.map(c=>s?c.path.startsWith(s+"/")?c.path.slice(s.length+1):null:c.path).filter(c=>c!==null),o=i.filter(c=>c!==v&&K(c)),f=i.includes(v)||o.some(c=>c.startsWith("objects/"));let l;const n=a.entries.find(c=>c.path===O(s,"settings/general.json"));if(n){const c=(await t.readTexts([n])).get(n.path);try{l=c?JSON.parse(c).name:void 0}catch{}}return{exists:f,documents:o.length,hasUsers:o.some(c=>c.startsWith("users/")),name:l}}function Jt(t={}){return{head:"c0",files:new Map(Object.entries(t)),commits:[]}}function It(t){let e=2166136261;for(let s=0;s<t.length;s++)e^=t.charCodeAt(s),e=Math.imul(e,16777619);return`b${(e>>>0).toString(16)}-${t.length}`}function Rt(t,e={}){const s={kind:e.kind??"github",label:"memory/repo@main",reads:0,async headSha(){return t.head},async listTree(){const a=[...t.files.entries()].map(([i,o])=>({path:i,sha:It(o),size:o.length})).sort((i,o)=>i.path.localeCompare(o.path));return{headSha:t.head,entries:a}},async readTexts(a){s.reads++;const i=new Map;for(const o of a){const f=t.files.get(o.path);f!==void 0&&i.set(o.path,f)}return i},async readBytes(a){return new TextEncoder().encode(t.files.get(a.path)??"")},async commit(a,i){var f;if((f=e.beforeCommit)==null||f.call(e,t),i.expectedHeadSha&&i.expectedHeadSha!==t.head)throw new J("Branch moved",t.head);for(const l of a)l.type==="delete"?t.files.delete(l.path):t.files.set(l.path,l.encoding==="base64"?it(l.content):l.content);const o=`c${t.commits.length+1}`;return t.commits.push({sha:o,message:i.message,changes:a}),t.head=o,o},async permissions(){return{login:"octocat",canWrite:!0,isAdmin:!0,visibility:"private",...e.permissions}}};return s}const vt="git-json-folder";async function Gt(t,e){if(t.provider==="local"){const a=await at(vt);return!a||!await ct(a,!1)?null:lt(a)}const s=e??ft(t);return s?t.provider==="github"?B({provider:"github",owner:t.owner??"",repo:t.repo??"",branch:t.branch,token:s,apiBaseUrl:t.apiBaseUrl}):B({provider:"gitlab",project:t.project??"",branch:t.branch,token:s,apiBaseUrl:t.apiBaseUrl}):null}function Ct(t){return ht(`gitEmail:${P(t)}`)}function Pt(t,e){ut(`gitEmail:${P(t)}`,(e==null?void 0:e.trim().toLowerCase())||null)}function Bt(t,e={}){var f,l;const s=t.git,a=typeof((f=e.secrets)==null?void 0:f.token)=="string"?e.secrets.token:null,i=typeof((l=e.secrets)==null?void 0:l.email)=="string"?e.secrets.email:null,o=`gitSecrets:${P(t)}`;return _t({dir:s.dir,openTransport:()=>Gt(s,a),identityFor:(n,c)=>Y(n,c,i??Ct(t)),secrets:{read:()=>pt(o)??{},write:n=>dt(o,n)},pollIntervalMs:e.pollIntervalMs??(s.provider==="local"?xt:z)})}export{gt as GIT_JSON_FORMAT,yt as GIT_JSON_VERSION,vt as LOCAL_GIT_HANDLE_KEY,v as MARKER_FILE,Ot as checkRebase,Bt as createGitJsonStore,_t as createGitJsonStoreWith,Rt as createMemoryGitTransport,Jt as createMemoryRepo,D as docKey,wt as docPath,jt as filesToSnapshot,ft as getGitToken,Ct as getGitUserEmail,Ft as inspectGitJsonFolder,Lt as isCollectionFolder,At as isGitJsonStore,K as isLayoutFile,W as markerContent,Tt as mergeDocSecrets,Gt as openGitJsonTransport,H as parseDocPath,$t as planChanges,Et as roleFromPermissions,bt as serializeDoc,Dt as setGitToken,Pt as setGitUserEmail,St as stripDocSecrets};
|