@ibgib/space-gib 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/Dockerfile +14 -0
- package/IMPLEMENTATION.md +484 -0
- package/README.md +46 -0
- package/dist/client/bootstrap.mjs +58 -0
- package/dist/client/bootstrap.mjs.map +7 -0
- package/dist/client/chunk-CT47Z5WU.mjs +21 -0
- package/dist/client/chunk-CT47Z5WU.mjs.map +7 -0
- package/dist/client/chunk-RHEDTRKF.mjs +235 -0
- package/dist/client/chunk-RHEDTRKF.mjs.map +7 -0
- package/dist/client/index.html +147 -0
- package/dist/client/index.mjs +2 -0
- package/dist/client/index.mjs.map +7 -0
- package/dist/client/script.mjs +2 -0
- package/dist/client/script.mjs.map +7 -0
- package/dist/client/style.css +605 -0
- package/dist/respec-gib.node.mjs +5 -0
- package/dist/server/server.mjs +20157 -0
- package/dist/server/server.mjs.map +7 -0
- package/generate-version-file.js +35 -0
- package/package.json +27 -0
- package/src/client/AUTO-GENERATED-version.mts +11 -0
- package/src/client/README.md +19 -0
- package/src/client/api/function-infos.web.mts +38 -0
- package/src/client/api/space-gib-api-bridge.mts +85 -0
- package/src/client/bootstrap.mts +49 -0
- package/src/client/components/keystone-creator/keystone-creator.css +139 -0
- package/src/client/components/keystone-creator/keystone-creator.html +26 -0
- package/src/client/components/keystone-creator/keystone-creator.mts +229 -0
- package/src/client/constants.mts +76 -0
- package/src/client/custom.d.ts +11 -0
- package/src/client/dev-tools.mts +540 -0
- package/src/client/helpers.web.mts +178 -0
- package/src/client/index.html +147 -0
- package/src/client/index.mts +59 -0
- package/src/client/script.mts +13 -0
- package/src/client/style.css +605 -0
- package/src/client/types.mts +85 -0
- package/src/client/ui/shell/space-gib-shell-constants.mts +24 -0
- package/src/client/ui/shell/space-gib-shell-service.mts +233 -0
- package/src/client/ui/shell/space-gib-shell-types.mts +5 -0
- package/src/client/witness/app/space-gib/space-gib-app-v1.mts +160 -0
- package/src/client/witness/app/space-gib/space-gib-constants.mts +38 -0
- package/src/client/witness/app/space-gib/space-gib-helper.mts +72 -0
- package/src/client/witness/app/space-gib/space-gib-types.mts +47 -0
- package/src/common/keystone-policies.mts +159 -0
- package/src/respec-gib.node.mts +6 -0
- package/src/server/README.md +18 -0
- package/src/server/bootstrap-helper.mts +141 -0
- package/src/server/bootstrap-helper.respec.mts +100 -0
- package/src/server/metaspace-nodeindexedspace/metaspace-nodeindexedspace.mts +85 -0
- package/src/server/path-constants.mts +89 -0
- package/src/server/path-helper.mts +101 -0
- package/src/server/path-helper.respec.mts +94 -0
- package/src/server/serve-gib/CHANGELOG.md +29 -0
- package/src/server/serve-gib/README.md +34 -0
- package/src/server/serve-gib/constants.mts +1 -0
- package/src/server/serve-gib/handlers/api/debug/ws-echo.handler.mts +104 -0
- package/src/server/serve-gib/handlers/api/health.handler.mts +23 -0
- package/src/server/serve-gib/handlers/api/health.respec.mts +51 -0
- package/src/server/serve-gib/handlers/api/ibgib/ibgib-handler-types.mts +49 -0
- package/src/server/serve-gib/handlers/api/ibgib/ibgib.handler.mts +176 -0
- package/src/server/serve-gib/handlers/api/keystone/keystone-evolve.handler.mts +261 -0
- package/src/server/serve-gib/handlers/api/keystone/keystone-genesis.handler.mts +146 -0
- package/src/server/serve-gib/handlers/api/keystone/keystone-get.handler.mts +198 -0
- package/src/server/serve-gib/handlers/api/keystone/keystone-get.respec.mts +107 -0
- package/src/server/serve-gib/handlers/api/keystone/keystone-handler-types.mts +29 -0
- package/src/server/serve-gib/handlers/api/keystone/keystone-post.handler.mts +70 -0
- package/src/server/serve-gib/handlers/api/keystone/keystone-post.respec.mts +130 -0
- package/src/server/serve-gib/handlers/error-handler.mts +36 -0
- package/src/server/serve-gib/handlers/handler-base.mts +383 -0
- package/src/server/serve-gib/handlers/static-handler.mts +82 -0
- package/src/server/serve-gib/handlers/ws/sync-upgrade.handler.mts +498 -0
- package/src/server/serve-gib/handlers/ws/ws-helper.mts +111 -0
- package/src/server/serve-gib/handlers/ws/ws-types.mts +53 -0
- package/src/server/serve-gib/serve-gib-helpers.mts +32 -0
- package/src/server/serve-gib/serve-gib-v1.mts +172 -0
- package/src/server/serve-gib/serve-gib.respec.mts +90 -0
- package/src/server/serve-gib/types.mts +102 -0
- package/src/server/server-constants.mts +2 -0
- package/src/server/server.mts +96 -0
- package/tsconfig.json +29 -0
- package/tsconfig.server.json +29 -0
- package/tsconfig.test.json +27 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import{a as Mr,b as Et,c as ia,d as We,e as vr,f as Rr,g as na,h as Ve,i as Ur,j as sa,k as Te,l as yt,m as Br,n as Je,o as kr,p as $t,q as Fr,r as jr,s as Pe,t as Ye,u as zr,v as qr,w as Hr,x as Xr,y as Wr}from"./chunk-RHEDTRKF.mjs";import{$ as Ie,$a as Er,Aa as Jt,Ab as Ge,B as y,Ba as sr,Bb as Tr,C,Ca as cr,Da as lr,E as qt,Ea as lt,Fa as Fe,Fb as Pr,G as J,Gb as W,H as q,I as H,Ia as dr,Ib as aa,Ja as dt,Jb as mt,Ka as Yt,Kb as Xe,L as X,La as fr,Lb as Nr,M as ot,Ma as Se,Mb as ra,Na as Qt,Oa as br,P as ce,Pa as hr,Q as Ht,Qa as pr,Qb as fe,R as Me,Ra as ur,S as ve,Sa as mr,Sb as oa,T as Re,Ta as ft,Tb as Cr,U as Ue,Ua as bt,Ub as gt,V as it,Va as gr,Vb as xr,W as $e,Wa as wr,Wb as Lr,X as Xa,Xa as je,Xb as Dr,Y as Wa,Ya as ze,Z as Xt,Za as Kt,_ as Be,_a as ht,_b as Or,a as b,aa as Va,ab as yr,b as Ut,ba as Ja,bb as pt,da as _e,db as qe,dc as wt,eb as He,fb as $r,ga as ke,gb as Ir,h as O,ha as Ya,hb as Zt,i as re,ia as Ae,ib as _r,j as Bt,ja as Qa,jb as ea,k as M,ka as Ka,kb as Ar,l as $,la as Wt,lb as de,m as ne,ma as Vt,n as m,na as Za,o as Ha,oa as er,ob as Sr,p as rt,pa as tr,pb as Gr,q as kt,qa as ar,ra as nt,rb as ut,sa as st,t as Ft,ta as le,tb as T,u as jt,ua as rr,ub as ta,w as se,wa as or,x as Ee,xa as ir,y as zt,ya as nr,z as ye,za as ct}from"./chunk-CT47Z5WU.mjs";var Vr={src:["source","from","in","input"],dest:["destination","to","out","output"]};function Ho({paramName:c,noBare:e,argTypeName:a,description:t}){let r={name:`src-${c}`,argTypeName:a??"string",synonyms:[...Vr.src.map(o=>`${o}-${c}`)],description:t};return e||r.synonyms.push(c),r}b(Ho,"getParam_src");function Xo({paramName:c,argTypeName:e="string",description:a}){return{name:`dest-${c}`,argTypeName:e??"string",synonyms:[...Vr.dest.map(r=>`${r}-${c}`)],description:a}}b(Xo,"getParam_dest");var Jr={name:"bare",description:`special param that is used as the only param allowed that doesn't have a "double-dash-specifier=" form. one "bare" arg is allowed atow. if a bare arg is found, it will be mapped to this param info.`,synonyms:["bare-arg","bare-param","no-name","manco","arg-with-no-name","param-with-no-name"],argTypeName:"string"};var Hi=Ho({paramName:"path",description:"for referencing/ingesting file(s)/folder(s) in a fs"}),Xi=Xo({paramName:"path",description:"for indicating where to put generated file(s)/folder(s)"});var Y=!1;function It({paramInfo:c,valueString:e}){let a=`[${It.name}]`;try{switch(c.argTypeName){case"string":let t=e;return(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'"))&&(t=t.slice(1),t=t.slice(0,t.length-1)),t;case"integer":if(e===void 0)throw new Error("integer arg value is undefined. integers must be a valid integer string (E: ce17acde3b863ec5e2fdcc594f0f1423)");let r=Number.parseInt(e);if(typeof r!="number")throw new Error(`arg value string (${e})did not parse to an integer. parse result: ${r} (E: 43cde93160458610ffb49fd16a02d123)`);return r;case"boolean":if(e===void 0||e===""){if(!c.isFlag)throw new Error("valueString is undefined or empty string but paramInfo.argTypeName === 'boolean' and paramInfo.isFlag is falsy. (E: 482e595c0ec7344b04def76c1441d623)");return!0}else{if(e===null)throw new Error("(UNEXPECTED) valueString === null? (E: 78f548b93026407968356d9c4f106223)");if(!["true","false"].includes(e))throw new Error(`invalid boolean valueString ("${e}"). must be either "true" or "false" (E: ba7a0d0804131acc2bd9ab37c0382523)`);return e==="true"}default:throw new Error("(UNEXPECTED) invalid paramInfo.argTypeName (E: c8b03ccb71394d22a29858b98753a123)")}}catch(t){throw console.error(`${a} ${m(t)}`),t}}b(It,"getValueFromRawString");function _t({argIdentifier:c,paramInfos:e,throwIfNotFound:a}){let t=`[${_t.name}]`;try{let r=e.filter(o=>o.name===c||(o.synonyms??[]).includes(c));if(r.length===1)return O(r[0]);if(r.length>1)throw new Error(`(UNEXPECTED) multiple param infos found with argIdentifier. do you have overlapping arg names/synonyms? (${c} found in (${r.length} param infos)) (E: d599a6647c5ead6d9fbac4e4c96e6d23)`);if(a)throw new Error(`(UNEXPECTED) param info not found for argIdentifier (${c}) (E: 47e704068f2eb5a0551cf45d0e72c823)`);return}catch(r){throw console.error(`${t} ${m(r)}`),r}}b(_t,"getParamInfo");function Yr({rawArg:c}){let e=`[${Yr.name}]`;try{Y&&console.log(`${e} starting... (I: 5d51b75b7a025e2e3fa498da7c08ac24)`);let a=b(o=>o.startsWith('"')&&o.endsWith('"')?"double":o.startsWith("'")&&o.endsWith("'")?"single":void 0,"fnGetQuoteType"),t=b(o=>a(o)?o.slice(0,o.length-1).slice(1):o,"fnStripQuotes"),r=a(c);if(r)return{prefix:void 0,identifier:void 0,isNameValuePair:!1,valueInfo:{rawValueString:c.concat(),resolvedValueString:t(c),singleQuoted:r==="single",doubleQuoted:r==="double"}};if(c.match(/^(--\w|-\w|:\w)/))if(c.includes("=")){let o=/^(--|-|:)([\w\-]+)=(['"]?.+['"]?)$/,i=c.match(o);if(!i)throw new Error(`invalid rawArg (${c}). expected an arg matching regexp ${o}. (E: 05ca56163e184faeb66456a0e9190b28)`);let[n,s,l,d]=i,f=a(d);return{prefix:s,identifier:l,isNameValuePair:!0,valueInfo:{rawValueString:d,resolvedValueString:f?t(d):d,singleQuoted:f==="single",doubleQuoted:f==="double"}}}else{let o=/^(--|-|:)([\w\-]+)$/,i=c.match(o);if(!i)throw new Error(`invalid rawArg (${c}). expected an arg matching regexp ${o}. at this point, it should have a prefix (e.g. "--"), and a single identifier (should be a flag since there is no equal sign). (E: 93305923465d9449bdce3f81373fae24)`);let[n,s,l]=i;return{prefix:s,identifier:l,isNameValuePair:!1,valueInfo:{rawValueString:void 0,resolvedValueString:"true",singleQuoted:!1,doubleQuoted:!1}}}else{if(c.includes("="))throw new Error(`invalid rawArg (${c}). isn't quoted, doesn't start with prefix, but it does have an equal sign? that's bad. (E: e8ad15211ce6fd56a4a214c2778c4724)`);return{prefix:void 0,identifier:void 0,isNameValuePair:!1,valueInfo:{rawValueString:c,resolvedValueString:c,doubleQuoted:!1,singleQuoted:!1}}}}catch(a){throw console.error(`${e} ${a.message}`),a}finally{Y&&console.log(`${e} complete.`)}}b(Yr,"parseRawArg");function At({args:c,paramInfos:e,bareArgParamInfo:a=O(Jr),logalot:t}){let r=`[${At.name}]`;try{(Y||t)&&console.log(`${r} starting... (I: f389aaa490796dfd823bc7b9d4e58b23)`);let o=!1;return c.map((n,s)=>{let l,d,f,{prefix:h,identifier:u,isNameValuePair:g,valueInfo:E}=Yr({rawArg:n});if(h){if((Y||t)&&console.log(`identifier: ${u} (I: 519ce129a1e34753a9070d3a205c9a8b)`),!u)throw new Error("(UNEXPECTED) prefix truthy but identifier falsy? (E: f33ab3a2b623acc0d1bc36685edfaf24)");if(l=u,!E)throw new Error("(UNEXPECTED) !valueInfo? (E: 05249a361a59008cd313d2dfa8f08b24)");if(g){Y&&console.log(`${r} identifier with equals: ${u}. (I: 5f8ae91d1ddd4a7f94c0f4fb7e688502)`);let w=_t({argIdentifier:l,paramInfos:e,throwIfNotFound:!0});f={...w,value:It({paramInfo:w,valueString:E.rawValueString}),identifier:l}}else{Y&&console.log(`${r} identifier without equals: ${u}`),l=u;let w=_t({argIdentifier:l,paramInfos:e,throwIfNotFound:!0});f={...w,value:It({paramInfo:w,valueString:void 0}),identifier:l,isFlag:!0}}}else if(s===0){if(!E)throw new Error("(UNEXPECTED) argIndex === 0 but valueInfo falsy? (E: 4642b42c855593b7ffdacb85f27dab24)");if(!E.rawValueString)throw new Error("(UNEXPECTED) !valueInfo.rawValueString? (E: 0b35f71eb8227cdd67ccfc32f2e45824)");if(E.singleQuoted)throw new Error("first arg is quoted? (single). a bare arg in first position must be a command/flag. (E: 28cce820417fd3b4f95ba6c7e94b4624)");if(E.doubleQuoted)throw new Error("first arg is quoted? (double). a bare arg in first position must be a command/flag. (E: 0b948c87081043fdb168f08ba05ebbce)");l=E.rawValueString,f={..._t({argIdentifier:l,paramInfos:e,throwIfNotFound:!0}),value:!0,identifier:l,isFlag:!0}}else{if((Y||t)&&console.log("bare arg found. (I: d6f67074c7e44a63864948d4bf04bee8)"),!a)throw new Error(`bare arg found (one without prefix like "--" or ":") but there is no param info expected for bare args. You must provide which param info a bare arg maps to in this ${At.name} call. (E: 650dd3695d62f0f87dd0cbafbf068c23)`);if(o)throw new Error('You can have the first arg - a special arg like a command - be bare (without prefix like "--" or ":") and one additional non-positional arg be bare. But more than one non-positional bare arg found. Also remember if the arg has spaces then you have to enclose it with single or double quotes. (E: 74dea8f13f0c14e3b7a2f125c7faca23)');o=!0;let w=O(a);f={...w,isBare:!0,identifier:w.name,value:It({paramInfo:w,valueString:n})}}return Y&&console.log(`${r} argInfo: ${$(f)}`),f})}catch(o){throw console.error(`${r} ${m(o)}`),o}finally{(Y||t)&&console.log(`${r} complete.`)}}b(At,"buildArgInfos");var z={undefined:"undefined",preparing:"preparing",started:"started",inserted:"inserted",updated:"updated",merged_dna:"merged_dna",merged_state:"merged_state",already_synced:"already_synced",completed:"completed"},Wo={...rr},rn={...Wo,sync:"sync"};var ca={encrypt_gib:"encrypt-gib"},nn=Object.values(ca);var Vo={characters:"characters",spell_out:"spell-out",cardinal:"cardinal",number:"number",ordinal:"ordinal",digits:"digits",fraction:"fraction",unit:"unit",date:"date",time:"time",telephone:"telephone",address:"address",interjection:"interjection",expletive:"expletive"};var be=class c{static{b(this,"Ssml")}static lc=`[${c.name}]`;static wrapSsmlSpeak(e,a=!0){return"<speak>"+e.reduce((r,o)=>a?r+"<p>"+o+"</p>":r+o,"")+"</speak>"}static unwrapSsmlSpeak(e){return e.replace(/\<speak\>/g,"").replace(/\<\/speak\>/g,"")}static p(e){return"<p>"+e+"</p>"}static s(e){return"<s>"+e+"</s>"}static stripSsml(e){return e.replace(/\<\/p\>[ ]*\<p\>/g,"<p>").replace(/\<p\>(?=[ ])/g,"<p>").replace(/\<\/p\>(?=[ ])/g,"</p>").replace(/\<[\/]*p\>/g,`
|
|
2
|
+
|
|
3
|
+
`).replace(/(<([^>]*)>)/ig,"").replace(/ +/g," ").replace(/\\n\\n\\n/g,`
|
|
4
|
+
|
|
5
|
+
`).replace(/^\n+/,"").replace(/\n+$/,"")}static phoneme(e,a,t="ipa"){return`<phoneme alphabet="${t}" ph="${a}">${e}</phoneme>`}static emphasis(e,a="moderate"){return`<emphasis level="${a}">${e}</emphasis>`}static prosody(e,{rate:a,pitch:t,volume:r}){let o=`${c.lc}${c.prosody.name}`,i="";if(a||a===0){let n=typeof a=="number"?a+"%":a;i+=`rate="${n}"`}if(t||t===0){let n;if(typeof t=="number"){let s=t;t>=0?(s>50&&console.warn(`${o} max: 50, actual: ${s} (W: 7fd9706e59f24dba896e2de149904677)`),n="+"+s+"%"):(s<-33.3&&console.warn(`${o} min: ${-33.3}, actual: ${s} (W: 90f4c21672034c51a8a95dcfcd281f98)`),n="-"+s+"%")}else n=t;i=i&&i+" ",i+=`pitch="${n}"`}if(r||r===0){let n;if(typeof r=="number"){let s=r;s>=0?(s>4.08&&console.warn(`${o} max: ${4.08}, actual: ${s} (W: 7db9521e6b3e418faca89d2f5cfa4f2c)`),n="+"+s+"%"):s<-12&&console.warn(`${o} min: -12, actual: ${s} (W: 49210d930272498e828d2c9a815ceea0)`),n=s+"%"}else n=r;i=i&&i+" ",i+=r?`volume="${n}"`:""}return"<prosody "+i+">"+e+"</prosody>"}static speech(e){return`<say-as interpret-as="interjection">${e}</say-as>`}static amazon(e,a){return`<amazon:effect name="${e}">${a}</amazon:effect>`}static audio(e){return`<audio src="${e}" />`}static break({strength:e,s:a,ms:t}){let r=`${c.lc}${c.break.name}`;if(e)return`<break strength="${e}"/>`;if(a||a===0)return a<0?(console.warn(`${r} min: 0, actual: ${a} (W: 6ff97060a6734f20b16a81a20d06630e)`),a=0):a>10&&(console.warn(`${r} max: 10, actual: ${a} (W: d57ed120e09c4fcaa19b864bdf9f1fc7)`),a=10),`<break time="${a}s"/>`;if(t||t===0)return t<0?(console.warn(`min: 0, actual: ${t} (W: 0addf6dbab1844a9906bd18a859be3d7)`),t=0):t>1e4&&(console.warn(`max: 10000, actual: ${t} (W: f46b9868ec6d4ef2abd4f2aefe879427)`),t=1e4),`<break time="${t}ms"/>`;throw new Error("Unknown break parameters (E: 1ae569301a354c28a54cc06b58c93b87)")}static sub(e,a){return`<sub alias="${a}">${e}</sub>`}static w(e,a){return`<w role="${a}">${e}</w>`}static sayAs({text:e,interpret:a,format:t}){let r=`${c.lc}[${c.sayAs.name}]`;try{if(t){if(a!==Vo.date)throw new Error('`format` arg requires (implies) `interpret` === "date" (E: 2a470b25ac284ec4bec9eb3e6a704b6b)');return`<say-as interpret-as="${a}" format="${t}">${e}</say-as>`}else return`<say-as interpret-as="${a}">${e}</say-as>`}catch(o){throw console.error(`${r} ${o.message}`),o}}};var x=!1;var Qe={upperfirst:"upperfirst",uppereach:"uppereach",lowerfirst:"lowerfirst",lowereach:"lowereach",none:"none"},he={p:"paragraph",paragraph:"paragraph",s:"sentence",sentence:"sentence",n:"newline",newline:"newline",delim:"delim"},Gt=class c{static{b(this,"Lex")}lc=`[${c.name}]`;data;defaultLanguage;defaultLineConcat;defaultDelim;defaultCapitalize;requestLanguage;defaultKeywordMode;defaultPropsMode;constructor(e,{defaultLanguage:a="en-US",requestLanguage:t="en-US",defaultLineConcat:r=he.delim,defaultDelim:o="",defaultCapitalize:i="none",defaultKeywordMode:n="any",defaultPropsMode:s="prop"}){if(!e)throw new Error("data required (E: 2f8db30fa9d71d76db616ab110392c22)");this.data=e,this.defaultLanguage=a??"en-US",this.defaultLineConcat=r??he.delim,this.defaultDelim=o??"",this.defaultCapitalize=i??"none",this.requestLanguage=t??"en-US",this.defaultKeywordMode=n??"any",this.defaultPropsMode=s??"prop"}get(e,{language:a=this.requestLanguage,specifier:t,keywords:r,keywordMode:o=this.defaultKeywordMode,lineIndex:i,lineConcat:n=this.defaultLineConcat,lineConcatDelim:s=this.defaultDelim,capitalize:l=this.defaultCapitalize,vars:d,ssmlVars:f,props:h,propsMode:u=this.defaultPropsMode,fnDatumPredicate:g}={language:this.requestLanguage,keywordMode:this.defaultKeywordMode,lineConcat:this.defaultLineConcat,lineConcatDelim:this.defaultDelim,capitalize:this.defaultCapitalize,propsMode:this.defaultPropsMode}){let E=`${this.lc}[${this.get.name}]`;try{x&&console.log(`${E} starting... (I: e4e76a6bb301010fc13cf4456efcdc22)`);let w=this.data[e];if(!w)throw new Error(`Data id not found: ${e} (E: 4a79897167714dd5a34df77953072aaf)`);if(w=this.filterLexData({lexData:w,language:a,specifier:t,keywords:r,keywordMode:o,props:h,propsMode:u,fnDatumPredicate:g}),w.length===0)return null;let A=this.pickDatum(w),_=this.extractLines({lexDatum:A,resultAs:"text",lineIndex:i});_=this.replaceTemplateRefs({lines:_,resultAs:"text"}),_=this.replaceTemplateVars({lines:_,vars:d}),_=this.capitalizeLines({lines:_,resultAs:"text",capitalize:l});let B=this.concatLines({lines:_,lineType:"text",lineConcat:n,lineConcatDelim:s}),S=this.extractLines({lexDatum:A,resultAs:"ssml",lineIndex:i});S=this.replaceTemplateRefs({lines:S,resultAs:"ssml"}),S=this.replaceTemplateVars({lines:S,vars:f||d}),S=this.capitalizeLines({lines:S,resultAs:"ssml",capitalize:l});let R=this.concatLines({lines:S,lineType:"ssml",lineConcat:n,lineConcatDelim:s});return{text:B,ssml:R,datum:A,rawData:w}}catch(w){throw console.error(`${E} ${w.message}`),w}finally{x&&console.log(`${E} complete.`)}}find({fnDatumPredicate:e}){let a=`${this.lc}[${this.find.name}]`;try{if(x&&console.log(`${a} starting... (I: 35e26d234ca2d0e987b39ee939f29c22)`),!e)throw new Error("only fnDatumPredicate implemented atow (E: 8c8babd2fa6fc4cb223b7b8c10ad5c22)");let t={},r=Object.keys(this.data);for(let o=0;o<r.length;o++){let i=r[o],n=this.data[i].filter(s=>e(s));n.length>0&&(t[i]=n)}return Object.keys(t).length>0?t:null}catch(t){throw console.error(`${a} ${t.message}`),t}finally{x&&console.log(`${a} complete.`)}}_(e,a){return this.get(e,a)}getVariant(e,a){return this.get(e,a)}variant(e,a){return this.get(e,a)}getTranslation(e,a){return this.get(e,a)}translate(e,a){return this.get(e,a)}getSynonym(e,a){return this.get(e,a)}synonym(e,a){return this.get(e,a)}getI18n(e,a){return this.get(e,a)}i18n(e,a){return this.get(e,a)}extractLines({lexDatum:e,resultAs:a,lineIndex:t}){let r=`${this.lc}[${this.extractLines.name}]`;try{if(x&&console.log(`${r} starting... (I: 0c21a7ed7c1b56251f39342380c47922)`),(!e.texts||e.texts.length===0)&&(!e.ssmls||e.ssmls.length===0))throw new Error(`Invalid lexDatum. Datum texts and ssmls are both undefined. lexDatum: ${JSON.stringify(e)}.`);let o=t||t===0;return a==="text"&&e.texts&&e.texts.length>0?o?[e.texts[t]]:e.texts:a==="text"?(console.warn("building text lines from ssml (W: cfb59a05efda475ab7511acc659a5ee3)"),o?[be.stripSsml(e.ssmls[t])]:e.ssmls.map(i=>be.stripSsml(i))):e.ssmls&&e.ssmls.length>0?o?[e.ssmls[t]]:e.ssmls:o?[e.texts[t]]:e.texts}catch(o){throw console.error(`${r} ${o.message}`),o}finally{x&&console.log(`${r} complete.`)}}replaceTemplateVars({lines:e,vars:a}){let t=`${this.lc}[${this.replaceTemplateVars.name}]`;try{x&&console.log(`${t} starting... (I: a756e7603d03d427c60c202cb4f6dd22)`);let r=b(o=>{let i=Object.keys(a||{});return x&&console.log(`${t} varNames: ${JSON.stringify(i)} (I: d9351cf582420b35eb3eceb923e64f22)`),i.reduce((n,s)=>(x&&console.log(`${t} varName: ${s} (I: 8c0e4261972945d2bb4624efad14870b)`),n.replace(new RegExp("\\$"+s,"g"),a[s])),o)},"replaceVarsSingleLine");return a?e.map(o=>r(o)):e}catch(r){throw console.error(`${t} ${r.message}`),r}finally{x&&console.log(`${t} complete.`)}}replaceTemplateRefs({lines:e,resultAs:a}){let t=`${this.lc}[${this.replaceTemplateRefs.name}]`;try{x&&console.log(`${t} starting... (I: 548949b651bbec84de5b25f3c01cf422)`);let r=/\$\([\w-]+\|?[\w-|\{\}:'"\s,\[\].,<>]+\)/,o=b(i=>{let n=r.exec(i);if(n){let s=n[0];s=s.substring(2,s.length-1);let l=s.split("|"),d=l[0],f=l.length===2?JSON.parse(l[1]):{};f.lineConcat||(f.lineConcat=he.delim,f.lineConcatDelim="");let h=this.get(d,f),u=a==="text"?h.text:h.ssml;return i=i.replace(r,u),r.test(i)?o(i):i}else return i},"replaceRefsSingleLine");return e.map(i=>o(i))}catch(r){throw console.error(`${t} ${r.message}`),r}finally{x&&console.log(`${t} complete.`)}}capitalizeLines({lines:e,resultAs:a,capitalize:t}){let r=`${this.lc}[${this.capitalizeLines.name}]`;try{x&&console.log(`${r} starting... (I: b0ec8263fd94c68ee53fdf61534c8322)`);let o=b((f,h,u)=>f.substr(0,h)+u+f.substr(h+u.length),"replaceAt"),i=b(f=>f===""?"":f.charAt(0).toUpperCase()+f.slice(1),"upperText"),n=b(f=>{if(f==="")return"";if(f.charAt(0)==="<"){let h=f.indexOf(">")+1;return o(f,h,f[h].toUpperCase())}else return i(f)},"upperSsml"),s=b(f=>f===""?"":f.charAt(0).toLowerCase()+f.slice(1),"lowerText"),l=b(f=>{if(f==="")return"";if(f.charAt(0)==="<"){let h=f.indexOf(">")+1;return o(f,h,f[h].toLowerCase())}else return s(f)},"lowerSsml"),d=e[0];switch(t){case Qe.upperfirst:return e[0]=a==="text"?i(d):n(d),e;case Qe.uppereach:return e.map(f=>a==="text"?i(f):n(f));case Qe.lowerfirst:return e[0]=a==="text"?s(d):l(d),e;case Qe.lowereach:return e.map(f=>a==="text"?s(f):l(f));case Qe.none:return e;default:throw new Error(`Unknown LexCapitalize: ${t}`)}}catch(o){throw console.error(`${r} ${o.message}`),o}finally{x&&console.log(`${r} complete.`)}}concatLines({lines:e,lineType:a,lineConcat:t,lineConcatDelim:r}){let o=`${this.lc}[${this.concatLines.name}]`;try{x&&console.log(`${o} starting... (I: 59e0a7b89457283751b376295b61bb22)`);let i=e[0],n=b(()=>{let s="<p>";return i.length<s.length||i.substring(0,s.length).toLowerCase()!==s?e.map(l=>`<p>${l}</p>`).join(""):e.join("")},"concatSsmlP");switch(t){case he.p:return a==="text"?e.join(`
|
|
6
|
+
|
|
7
|
+
`):n();case he.s:if(a==="text")return e.map(s=>{let l=s.substring(s.length-1);return[".","!","?"].includes(l)?s:s+"."}).join(" ");{let s="<s>";return i.length<s.length||i.substring(0,s.length).toLowerCase()!==s?e.map(l=>`<s>${l}</s>`).join(""):e.join("")}case he.n:return a==="text"?e.join(`
|
|
8
|
+
`):n();case he.delim:return e.join(r);default:throw new Error(`Unknown LexLineConcat: ${t} (E: e19f9c44217f4eb5999e2085d3f77b5c)`)}}catch(i){throw console.error(`${o} ${i.message}`),i}finally{x&&console.log(`${o} complete.`)}}filterLexData({lexData:e,language:a,specifier:t,keywords:r,keywordMode:o,props:i,propsMode:n,fnDatumPredicate:s}){let l=`${this.lc}[${this.filterLexData.name}]`;try{x&&console.log(`${l} starting... (I: 1091755e98f390954d296575d1096722)`);let d=e.concat();if(a&&(d=this.filterLanguage(d,a)),t&&(d=d.filter(f=>f.specifier&&f.specifier===t)),r&&r.length>0)switch(r=r.map(f=>f.toLocaleLowerCase()),o){case"any":d=d.filter(f=>f.keywords&&f.keywords.some(h=>r.map(u=>u.toLocaleLowerCase()).some(u=>h===u)));break;case"all":d=d.filter(f=>{let h=(f.keywords||[]).map(u=>u.toLocaleLowerCase());return r.every(u=>h.includes(u))});break;case"none":d=d.filter(f=>{let h=(f.keywords||[]).map(u=>u.toLocaleLowerCase());return r.every(u=>!h.includes(u))});break;default:console.error(`${l} Unknown keywordMode: ${o}`);break}return i&&(d=this.filterProps({result:d,props:i,propsMode:n})),s&&(d=d.filter(f=>s(f))),d}catch(d){throw console.error(`${l} ${d.message}`),d}finally{x&&console.log(`${l} complete.`)}}filterProps({result:e,props:a,propsMode:t}){if(t==="prop"){let r=a;return e.filter(o=>Object.keys(r).every(i=>{let n=r[i],s=o.props?o.props[i]:void 0;return n(s)}))}else if(t==="props"){let r=a;return e.filter(o=>r(o.props))}else throw new Error(`Invalid propsMode: ${t} (E: 216a926144d2436a900b81ffe0aa6174)`)}filterLanguage(e,a){return e=e.filter(t=>t.language&&t.language===a||!t.language&&this.defaultLanguage.length===2&&a.startsWith(this.defaultLanguage)||!t.language&&this.defaultLanguage===a),e}pickDatum(e){let a=`${this.lc}[${this.pickDatum.name}]`;try{if(x&&console.log(`${a} starting... (I: f95c8585a8274f78a1e724d6ab58ff22)`),!e)throw new Error("lexData required (E: cedb1fd9b67856c33b41c7dd4aab7c22)");if(e.length===0)return null;if(e.length===1)return e[0];{let t=e.reduce((i,n)=>i+(n.weighting?n.weighting:1),0),r=Math.random()*t,o=null;return e.reduce((i,n)=>o?-1:(i+=n.weighting?n.weighting:1,i>=r&&(o=n),i),0),o}}catch(t){throw console.error(`${a} ${t.message}`),t}finally{x&&console.log(`${a} complete.`)}}};var v={hi:"hi",welcome:"welcome",bye:"bye",yes:"yes",no:"no",learn:"learn",wtg:"wtg"},P={help:"semantic_help",hello:"semantic_hello",bye:"semantic_bye",yes:"semantic_yes",no:"semantic_no",cancel:"semantic_cancel",skip:"semantic_skip",forget:"semantic_forget",next:"semantic_next",please:"semantic_please",in_progress:"semantic_in_progress",list:"semantic_list",request:"semantic_request",count:"semantic_count",options:"semantic_options",ready:"semantic_ready",stop:"semantic_stop",result:"semantic_result",unknown:"semantic_unknown",default:"semantic_default"};function V(c,e){return e.flatMap(a=>({texts:[a],language:"en-US",props:{semanticId:c}}))}b(V,"toLexDatums_Semantics");function pe(c,e){return e.flatMap(a=>({texts:[a],language:"en-US",props:{atomicId:c}}))}b(pe,"toLexDatums_Atomics");var Jo={[P.help]:[...V(P.help,["h","help","help me"])],[P.yes]:[...V(P.yes,["yes","y","yeah","yea","aye","yup","yep","sure","ok","sounds good","go for it","yes please","yes thanks","ok thanks","uh huh","god yes","affirmative","ten four","10-4","roger"])],[P.no]:[...V(P.no,["no","n","nah","nay","nope","uh uh","no thanks","ick","nuh uh","god no","no way","not at all","negative","that's a negative","nein"])],[P.cancel]:[...V(P.cancel,["cancel","nm","nevermind","cancel that","don't worry about it"])],[P.skip]:[...V(P.skip,["skip","sk"])],[P.forget]:[...V(P.forget,["forget","forget this","forget this one"])],[P.next]:[...V(P.next,["next"])],[P.bye]:[...V(P.bye,["bye","bye bye","see you later","see you"])],[P.unknown]:[...V(P.unknown,["are you mocking me, human?","mmhmm...","i see...","does not compute...","indeed"])]},Yo={[v.hi]:[...pe(v.hi,["hi","howdy","hello","greetings","good day","hello there","good day to you","yo"])],[v.welcome]:[...pe(v.welcome,["welcome"])],[v.yes]:[...pe(v.yes,["yes","y","yeah","yea","aye","yup","yep","sure","ok","sounds good","go for it","yes please","yes thanks","ok thanks","uh huh","god yes","affirmative","ten four","10-4","roger"])],[v.no]:[...pe(v.no,["no","n","nope","no thanks","no thank you"])],[v.bye]:[...pe(v.bye,["bye","bye bye","adios","ciao","later"])],[v.learn]:[...pe(v.learn,["learn","study","review"])],[v.wtg]:[...pe(v.wtg,["wtg","nice","not bad","pretty good","good job"])]},Qo={...Jo,...Yo},Qr={...O(Qo)},Ko={...O(Qr)},yn=new Gt(Ko,{requestLanguage:"en-US",defaultLanguage:"en-US",defaultCapitalize:"none",defaultLineConcat:"delim",defaultDelim:`
|
|
9
|
+
|
|
10
|
+
`,defaultKeywordMode:"any",defaultPropsMode:"prop"}),Kr={...O(Qr)};Kr[P.bye].push({texts:["EOL"],ssmls:[be.sub("EOL","end of line")],language:"en-US",props:{semanticId:P.bye},weighting:100});Kr[P.unknown]=[...V(P.unknown,["i'm not quite sure what you mean","does not compute"])];var Ne=!1;function Zr({robbotData:c}){let e=`[${Zr.name}]`;try{if(Ne&&console.log(`${e} starting...`),!c)throw new Error("robbotData required (E: 1ac78ffae5354b67acb64a34cfe23c2f)");let a=[],{name:t,uuid:r,classname:o,outputPrefix:i,outputSuffix:n}=c;return t?t.match(Me)||a.push(`name must match regexp: ${Me}`):a.push("name required."),r?r.match(Ut)||a.push(`uuid must match regexp: ${Ut}`):a.push("uuid required."),i&&(i.match(ve)||a.push(`outputPrefix must match regexp: ${ve}`)),n&&(n.match(ve)||a.push(`outputSuffix must match regexp: ${ve}`)),o&&(o.match(Me)||a.push(`classname must match regexp: ${Me}`)),a}catch(a){throw console.error(`${e} ${a.message}`),a}finally{Ne&&console.log(`${e} complete.`)}}b(Zr,"validateCommonRobbotData");async function la({robbotIbGib:c}){let e=`[${la.name}]`;try{Ne&&console.log(`${e} starting... (I: f7b34d791a483b8c5a9d188da66d3f22)`);let a=await X({ibGib:c})??[];if(!c.data)throw new Error("robbotIbGib.data required (E: 754a8d2540610696aff04b0d159daa23)");let t=[],{robbotClassname:r,robbotName:o,robbotId:i}=eo({robbotIb:c.ib});r||t.push("robbotClassname required (E: 3234d39bf1c74ec3aff59f374282dfc8)"),o||t.push("robbotName required (E: b329dcc62ff548d7aa0681393b2c7057)"),i||t.push("robbotId required (E: b562c953bfaf4dd49e4d3a08304ee2fc)");let n=Zr({robbotData:c.data}),s=[...a??[],...t??[],...n??[]];return s.length>0?s:void 0}catch(a){throw console.error(`${e} ${a.message}`),a}finally{Ne&&console.log(`${e} complete.`)}}b(la,"validateCommonRobbotIbGib");function eo({robbotIb:c}){let e=`[${eo.name}]`;try{if(!c)throw new Error("robbotIb required (E: 4a35881058094f1a90bb4ea37052d6d7)");let a=c.split(" ");return{robbotClassname:a[2],robbotName:a[3],robbotId:a[4]}}catch(a){throw console.error(`${e} ${a.message}`),a}}b(eo,"parseRobbotIb");async function da({fnPromptRobbot:c,ibgibs:e,space:a}){let t=`[${da.name}]`;try{if(Ne&&console.log(`${t} starting...`),!e)throw new Error("(UNEXPECTED) ibgibs service required. (E: 4be5d20dc81fcdabb8d7d4cd47458522)");a=a??await e.getLocalUserSpace({lock:!0});let r=await c(a,null);if(!r)throw new Error("robbot prompt returned nothing. canceled? (E: 1a08529b53bd3d79c6587b196e5e0823)");let o=r.newIbGib;try{await ne(1e3);let i=[];i.push(o),r.intermediateIbGibs?.forEach(d=>i.push(d)),r.dnas?.forEach(d=>i.push(d));for(let d=0;d<i.length;d++){let f=i[d],h=await X({ibGib:f});if((h??[]).length>0)throw new Error(`(unexpected) invalid robbot ibgib created. validationErrors: ${h}. robbot: ${$(o.toIbGibDto())} (E: a683268621cd6dd3dd60310b164c4d22)`)}await Se({resTransform:r,space:a});let{zeroSpace:n,fnBroadcast:s,fnUpdateBootstrap:l}=e;await ft({ibGib:o,space:a,fnBroadcast:b(d=>s(d),"fnBroadcast")}),await bt({type:"robbots",rel8nName:Ue,ibGibsToRel8:[o],space:a,zeroSpace:n,fnUpdateBootstrap:l,fnBroadcast:s})}catch(i){throw console.error(`${t} ${i.message}`),i}return o}catch(r){console.error(`${t} ${r.message}`);return}finally{Ne&&console.log(`${t} complete.`)}}b(da,"createNewRobbot");var Tt="secret";var to=!1;function Pt({participants:c}){let e=`[${Pt.name}]`;try{to&&console.log(`${e} starting... (I: 43c9a4f1fa1bbc944b98f8eed2f81924)`);let a=c.filter(t=>t.s_d==="src");if(a.length!==1)throw new Error("(UNEXPECTED) participants_src.length !== 1? atow (03/2024) only one src participant is expected. (E: ed4b3ae15f5da34c77655553aaf82224)");return a.at(0).id}catch(a){throw console.error(`${e} ${m(a)}`),a}finally{to&&console.log(`${e} complete.`)}}b(Pt,"getSrcLocalSpaceId");var p=!1,Nt=class c{static{b(this,"MetaspaceBase")}cacheSvc;lc=`[${c.name}]`;instanceId=new Date().toUTCString();_initialized=!1;get initialized(){return this._initialized}_initializedSubj;initialized$;_initializing=!1;get initializing(){return this._initializing}_latestSubj;latestObs;async getLocalUserSpace({lock:e=!1,localSpaceId:a}){let t=`${this.lc}[${this.getLocalUserSpace.name}]`;try{p&&console.log(`${t} starting...`),e??=!1;let r=await ze({zeroSpace:this.zeroSpace})??void 0;return await Kt({zeroSpace:this.zeroSpace,bootstrapIbGib:r,lock:e,callerInstanceId:this.instanceId,localSpaceId:a,fnDtoToSpace:b(i=>this.metaspaceFactory.fnDtoToSpace(i),"fnDtoToSpace"),localSpaceCacheSvc:this.cacheSvc})}catch(r){throw console.error(`${t} ${r.message}`),r}finally{p&&console.log(`${t} complete.`)}}async getLocalUserSpaces({lock:e=!1}){let a=`${this.lc}[${this.getLocalUserSpaces.name}]`;try{p&&console.log(`${a} starting...`);let t=[];e??=!1;let r=await ze({zeroSpace:this.zeroSpace});if(!r)throw new Error("(UNEXPECTED) bootstrapIbGib falsy (E: fff2de921a3ee56a1d70e4ac320e4122)");if(!r.data)throw new Error("(UNEXPECTED) bootstrapIbGib data falsy (E: 7f9d08050f214078b2f85dd2ed47e005)");if(!r.data[Ae])throw new Error(`(UNEXPECTED) bootstrapIbGib data invalid. data[${Ae}] falsy (E: 37614e2e8f914d6ab7c605cf064a80d2)`);if(r.data[Ae].length===0)throw new Error(`(UNEXPECTED) bootstrapIbGib data invalid. data[${Ae}] length === 0 (E: d57691d17e6b4d7ea3a8fed36c0f47e5)`);let o=r.data[Ae];for(let i=0;i<o.length;i++){let n=o[i];if(!n)throw new Error("(UNEXPECTED) localSpaceId falsy (E: 582c520897f5355d642229eae122ac22)");let s=await Kt({zeroSpace:this.zeroSpace,bootstrapIbGib:r,lock:e,localSpaceId:n,callerInstanceId:this.instanceId,fnDtoToSpace:b(l=>this.metaspaceFactory.fnDtoToSpace(l),"fnDtoToSpace"),localSpaceCacheSvc:this.cacheSvc});t.push(s)}return t}catch(t){throw console.error(`${a} ${t.message}`),t}finally{p&&console.log(`${a} complete.`)}}passwordCache={};_syncing=!1;get syncing(){return this._syncing}sagaInfoMap={};_alwaysAutosyncTjpAddrsCache=new Set;isPrompting=!1;_precalculatedIds=[];getUUIDSync(){let e=`${this.lc}[${this.getUUIDSync.name}]`;try{p&&console.log(`${e} starting...`);let a=this._precalculatedIds.pop();if(!a)throw new Error("no precalculated ids? (E: 14915489b21d031ee9ca695737ac6923)");return this._precalculatedIds.length<100&&this.precalculateSomeUUIDsPlease(),a}catch(a){throw console.error(`${e} ${a.message}`),a}finally{p&&console.log(`${e} complete.`)}}async precalculateSomeUUIDsPlease(){let e=`${this.lc}[${this.precalculateSomeUUIDsPlease.name}]`;try{p&&console.log(`${e} starting...`);let a=[];for(let t=0;t<500;t++){let r=await M();a.push(r)}this._precalculatedIds=a}catch(a){throw console.error(`${e} ${a.message}`),a}finally{p&&console.log(`${e} complete.`)}}async initializeObservables(){let e=`${this.lc}[${this.initializeObservables.name}]`;try{p&&console.log(`${e} starting... (I: f5dc6d6352eaf2f41809ddec76ea5923)`),this._initializedSubj=await Je({replay:!0}),this.initialized$=this._initializedSubj.asObservable(),this._latestSubj=await Je(),this.latestObs=this._latestSubj.asObservable()}catch(a){throw console.error(`${e} ${a.message}`),a}finally{p&&console.log(`${e} complete.`)}}metaspaceFactory={};getFnAlert;getFnPrompt;getFnPromptPassword;constructor(e){this.cacheSvc=e;let a=`${this.lc}[ctor]`;p&&(console.log(`${a}${Ht}`),console.timeLog(Ht),console.log(`${a} created. (I: 5fe7af9fccc2488282eecc8255729cec)`))}async initializeMetaspaceFactory({metaspaceFactory:e}){let a=`[${this.initializeMetaspaceFactory.name}]`;try{p&&console.log(`${a} starting... (I: 0b84dfb68c1e89e0af880d4461fe4b23)`),this.metaspaceFactory=e}catch(t){throw console.error(`${a} ${t.message}`),t}finally{p&&console.log(`${a} complete.`)}}async initialize({spaceName:e,metaspaceFactory:a,getFnAlert:t,getFnPrompt:r,getFnPromptPassword:o}){let i=`${this.lc}[${this.initialize.name}]`;try{if(this.instanceId=await M(),!t)throw new Error("getFnAlert required (E: c7ded289d9b6265b6d1294988faba923)");if(!r)throw new Error("getFnPrompt required (E: cce7733db0abbf9a41fa45b6b9bf9523)");if(!o)throw new Error("getFnPromptPassword required (E: cadae9f5df9a7c310e76b63cb6afb623)");this.getFnAlert=t,this.getFnPrompt=r,this.getFnPromptPassword=o;let n=`${i}[timer]`;p&&(n=i+"[timer 71cbfa]",console.log(`${i} starting timer ${n}`),console.time(n)),await this.precalculateSomeUUIDsPlease(),await this.initializeObservables(),p&&console.timeLog(n),await this.initializeMetaspaceFactory({metaspaceFactory:a??={}}),await this.initializeLocalSpaces({spaceName:e}),p&&console.timeLog(n),await this.initializeSpecialIbGibs_required({timerName:n}),await this.initializeSpecialIbGibs_outerspaces({timerName:n}),await this.initializeSpecialIbGibs_other({timerName:n}),p&&(console.timeEnd(n),console.log(`${i} timer ${n} complete.`)),this._initialized=!0,await this._initializedSubj.next(Ee),console.log(`${i} initialized (I: e3b3a9652c09445cb055013166ff089c)`)}catch(n){throw console.error(`${i} ${n.message}`),n}}async initializeSpecialIbGibs_required({timerName:e}){let a=`[${this.initializeSpecialIbGibs_required.name}]`;try{p&&console.log(`${a} starting... (I: 8cb7f63d766ab38885dc63d8da9cd323)`),await this.getSpecialIbGib({type:"latest",initialize:!0}),p&&console.timeLog(e),await this.getSpecialIbGib({type:"roots",initialize:!0}),p&&console.timeLog(e),await this.getSpecialIbGib({type:"tags",initialize:!0}),p&&console.timeLog(e),await this.getSpecialIbGib({type:Re.aliases,initialize:!0}),p&&console.timeLog(e),await this.getSpecialIbGib({type:"robbots",initialize:!0}),p&&console.timeLog(e),await this.getSpecialIbGib({type:"apps",initialize:!0}),p&&console.timeLog(e),await this.getSpecialIbGib({type:"secrets",initialize:!0}),p&&console.timeLog(e),await this.getSpecialIbGib({type:"encryptions",initialize:!0}),p&&console.timeLog(e)}catch(t){throw console.error(`${a} ${t.message}`),t}finally{p&&console.log(`${a} complete.`)}}async initializeSpecialIbGibs_outerspaces({timerName:e}){let a=`[${this.initializeSpecialIbGibs_outerspaces.name}]`;try{p&&console.log(`${a} starting... (I: 4f5ca25899384ceabd65e30cdf58f889)`),await this.getSpecialIbGib({type:"outerspaces",initialize:!0}),p&&console.timeLog(e),await this.getSpecialIbGib({type:"autosyncs",initialize:!0}),p&&console.timeLog(e),await this.loadAutoSyncs()}catch(t){throw console.error(`${a} ${t.message}`),t}finally{p&&console.log(`${a} complete.`)}}async initializeSpecialIbGibs_other({timerName:e}){let a=`[${this.initializeSpecialIbGibs_other.name}]`;try{p&&console.log(`${a} starting... (I: 3cad0b16f5dac3686929dd1923ee3623)`)}catch(t){throw console.error(`${a} ${t.message}`),t}finally{p&&console.log(`${a} complete.`)}}async initializeLocalSpaces({spaceName:e}){let a=`${this.lc}[${this.initializeLocalSpaces.name}]`;try{p&&console.log(`${a} starting...`);let t=this.zeroSpace;t.gib||(t.gib=await q({ibGib:t,hasTjp:!1})),p&&console.log(`${a} getting bootstrap ibgib (I: a4ad1cfd5c6f895e879d9e6a5f607b22)`);let r=Ya,o=await ze({zeroSpace:t});o?(p&&console.log(`${a} getting bootstrap ibgib with locking from zero space...`),o=await je({space:t,scope:r,secondsValid:Va,fn:b(async()=>{let i=await ze({zeroSpace:t});if(!i)throw new Error("failed to get validated bootstrapIbGib (E: a4318a8183c3d8979981c29bd4ecb223)");return i},"fn"),callerInstanceId:this.instanceId}),p&&console.log(`${a} got bootstrap ibgib with locking from zero space.`)):(p&&console.log(`${a} getting from default space...not found. bootstrap space not found. will create... (I: 3170ac1a310d41f29f2b2b075cde6bdb)`),await this.createLocalSpaceAndUpdateBootstrap({zeroSpace:t,allowCancel:!1,createBootstrap:!0,spaceName:e}))}catch(t){throw p&&console.log(`${a} getting from default space...not found. bootstrap space not found. (E: 617bb62c3b6c4c01a5faec7f06c719fd)`),console.error(`${a} ${t.message}`),t}finally{p&&console.log(`${a} complete.`)}}createNewLocalSpace({opts:e,fnLocalSpaceFactory:a}){let t=`[${this.createNewLocalSpace.name}]`;try{if(p&&console.log(`${t} starting... (I: ac652df9d652459d98832be8483544d1)`),!e)throw new Error("opts required (E: f1d50207b35c96985ba6c2e1a18a4e23)");if(e.getFnPrompt||(p&&console.log(`${t} incoming opts getFnPrompt falsy. using this.getFnPrompt (I: 1f331752ac81ffc48e2da0b27dafba23)`),e.getFnPrompt=this.getFnPrompt),a??=this.metaspaceFactory.fnDefaultLocalSpaceFactory,!a)throw new Error("neither fnLocalSpaceFactory nor this.fnDefaultLocalSpaceFactory provided (E: 5142df9dbae63fd0ffef8165782dc423)");return a(e)}catch(r){throw console.error(`${t} ${r.message}`),r}finally{p&&console.log(`${t} complete.`)}}async createLocalSpaceAndUpdateBootstrap({zeroSpace:e,allowCancel:a,createBootstrap:t,spaceName:r,getFnPrompt:o}){let i=`${this.lc}[${this.createLocalSpaceAndUpdateBootstrap.name}]`;try{let n;if(a){if(n=await this.createNewLocalSpace({opts:{allowCancel:a,spaceName:r,logalot:p,getFnPrompt:o??this.getFnPrompt}}),!n)return}else do n=await this.createNewLocalSpace({opts:{allowCancel:a,spaceName:r,logalot:p,getFnPrompt:o??this.getFnPrompt}});while(!n);t&&(p&&console.log(`${i} creating new bootstrap ibgib (I: ecc58dd4af21a0c69a16b3d71dad9c22)`),await ht({space:n,zeroSpace:e,setSpaceAsDefault:!0,createIfNotFound:!0}));let s=await e.argy({ibMetadata:Er({space:n}),argData:{cmd:"put",ibGibAddrs:[y({ibGib:n})]},ibGibs:[n]});p&&console.log(`${i} save the localSpace in default zero space (I: 1b34fb9f548042ab9d9ae0619377e370)`);let l=await e.witness(s);if(l?.data?.success)p&&console.log(`${i} default zero space witnessed the user space (I: b6314ea887d34609904db3bb76ae2f9b)`);else throw new Error(`${l?.data?.errors?.join("|")||"There was a problem with zeroSpace witnessing the new localSpace (E: b952e888a4954cc5b671034b8384e750)"}`);p&&console.log(`${i} save the new localSpace in its own space (I: e1f520f2cc614b1fa9c1ebd1c4dd6957)`);let d=await n.witness(s);if(d?.data?.success)p&&console.log(`${i} user space witnessed itself`);else throw new Error(`${d?.data?.errors?.join("|")||"There was a problem with localSpace witnessing itself. (E: 33d4b1ffcca64160afe67046531958b5)"}`);return await ht({space:n,zeroSpace:this.zeroSpace}),n}catch(n){throw console.error(`${i} ${n.message}`),this.getFnAlert()({title:"failed",msg:`failed to initialize the local space. error: ${n.message}`}),n}}async createTagIbGib({text:e,icon:a,description:t,space:r}){let o=`${this.lc}[${this.createTagIbGib.name}]`;try{if(r=r??await this.getLocalUserSpace({}),!r)throw new Error("space falsy and localUserSpace not initialized (E: 18f846b645124210a2ff1611641a8daf)");return wr({text:e,icon:a,description:t,space:r,zeroSpace:this.zeroSpace,fnBroadcast:b(i=>this.fnBroadcast(i),"fnBroadcast"),fnUpdateBootstrap:b(i=>this.fnUpdateBootstrap(i),"fnUpdateBootstrap")})}catch(i){throw console.error(`${o} ${i.message}`),i}}async trash({ibGib_Context:e,rel8nName_Context:a,addr:t,space:r}){let o=`${this.lc}[${this.trash.name}]`;try{if(p&&console.log(`${o} starting... (I: 4cf73be6e3294124a78a4a45368bfbcc)`),!e)throw new Error("ibGib_Context required (E: 09dd5e5a9f784953a42d70b1827ba442)");if(!a)throw new Error("rel8nName_Context required (E: cb6edaaac586773b08fd18855fc11322)");if(!t)throw new Error("addr required (E: 14f27805749c499098cebc0b1b11bc57)");if(r=r??await this.getLocalUserSpace({}),!r)throw new Error("space falsy and localUserSpace not initialized (E: f81574e3437a4b88acd044b2abdc1ae4)");await $r({ibGib_Context:e,rel8nName_Context:a,addr:t,space:r,zeroSpace:this.zeroSpace,fnBroadcast:b(i=>this.fnBroadcast(i),"fnBroadcast"),fnUpdateBootstrap:b(i=>this.fnUpdateBootstrap(i),"fnUpdateBootstrap")})}catch(i){throw console.error(`${o} ${i.message}`),i}finally{p&&console.log(`${o} complete.`)}}async archive({ibGib_Context:e,rel8nName_Context:a,addr:t,space:r}){let o=`${this.lc}[${this.archive.name}]`;try{if(p&&console.log(`${o} starting... (I: 785b44dbb7b048cb8c210a907b73b4c8)`),!e)throw new Error("ibGib_Context required (E: dc277b47aa4f42118ad14bfc817bf1d5)");if(!a)throw new Error("rel8nName_Context required (E: 87bd7ffa820645e9bdfb17fc726249ba)");if(!t)throw new Error("addr required (E: f6ce4e1325c84aa9b3da31c5b9dcc787)");if(r=r??await this.getLocalUserSpace({}),!r)throw new Error("space falsy and localUserSpace not initialized (E: d6e0b1618eec400e820de6ac37491d39)");await Ir({ibGib_Context:e,rel8nName_Context:a,addr:t,space:r,zeroSpace:this.zeroSpace,fnBroadcast:b(i=>this.fnBroadcast(i),"fnBroadcast"),fnUpdateBootstrap:b(i=>this.fnUpdateBootstrap(i),"fnUpdateBootstrap")}),p&&console.log(`${o} archived '${t.slice(0,32)}...' (I: 767b06c8cadd58c618924f0cd98a1723)`)}catch(i){throw console.error(`${o} ${i.message}`),i}finally{p&&console.log(`${o} complete.`)}}async getConfigAddr({key:e,space:a}){let t=`${this.lc}[${this.getConfigAddr.name}](${e})`;try{if(p&&console.log(`${t} getting...`),a=a??await this.getLocalUserSpace({}),!a)throw new Error("space falsy and could not get local space. (E: b6e7fcc09c6244b99b2e6e6ece398db0)");return hr({key:e,space:a})}catch(r){console.error(`${t} ${r.message}`);return}}fnUpdateBootstrap=b(async e=>{await ht({space:e,zeroSpace:this.zeroSpace})},"fnUpdateBootstrap");fnBroadcast=b(e=>{this._latestSubj.next(e)},"fnBroadcast");async setConfigAddr({key:e,addr:a,space:t}){let r=`${this.lc}[${this.setConfigAddr.name}]`;try{if(t=t??await this.getLocalUserSpace({}),!t)throw new Error("space falsy and localUserSpace not initialized (?) (E: 2149c59ebd584a118304dd54656aa800)");return await pr({key:e,addr:a,space:t,zeroSpace:this.zeroSpace,fnUpdateBootstrap:b(o=>this.fnUpdateBootstrap(o),"fnUpdateBootstrap")})}catch(o){throw console.error(`${r} ${o.message}`),o}}async getCurrentRoot({space:e}){let a=`${this.lc}[${this.getCurrentRoot.name}]`;try{if(e=e??await this.getLocalUserSpace({}),!e)throw new Error("space falsy and localUserSpace not initialized (?) (E: 1f4dc5e9560341a993bf0b28accd75fe)");for(;this.initializing;)p&&console.log(`${a} hacky wait while initializing ibgibs service (I: 5fd759510e584cb69b232259b891cca1)`),await ne(100);let t=await this.getSpecialIbGib({type:"roots",space:e});if(!t)throw new Error("Roots not initialized. (E: e7712dc3d183487e98cd44a2b4324bc2)");if(!t.rel8ns)throw new Error("Roots not initialized properly. No rel8ns. (E: 689f47f5d1da4a868d1c1ddd2ff13e17)");if(!t.rel8ns.current)throw new Error("Roots not initialized properly. No current root. (E: 962acd3f60474a329bfbd7682c003916)");if(t.rel8ns.current.length===0)throw new Error("Invalid Roots: empty current root rel8n. (E: fbdc13c157514efa86ade1bf9a38bbd6)");if(t.rel8ns.current.length>1)throw new Error("Invalid Roots: multiple current roots selected. (E: 370fe6e3920a4a1299f879e6fcbbc448)");let r=t.rel8ns.current[0],o=await this.get({addr:r,space:e});if(o.ibGibs?.length===1)return o.ibGibs[0];throw new Error(`could not get current root. addr: ${r} (E: 69de35c5f71e45a1a5d83228e136642b)`)}catch(t){console.error(`${a} ${t.message}`);return}}async setCurrentRoot({root:e,space:a}){let t=`${this.lc}[${this.setCurrentRoot.name}]`;try{if(!e)throw new Error("root required.");if(a=a??await this.getLocalUserSpace({}),!a)throw new Error("space falsy and localUserSpace not initialized (?) (E: 222a3f5b39fc47ccb2a4aa3ddcd49969)");return ur({root:e,space:a,zeroSpace:this.zeroSpace,fnBroadcast:b(r=>this.fnBroadcast(r),"fnBroadcast"),fnUpdateBootstrap:b(r=>this.fnUpdateBootstrap(r),"fnUpdateBootstrap")})}catch(r){throw console.error(`${t} ${r.message}`),r}}async rel8ToCurrentRoot({ibGib:e,linked:a,rel8nName:t,space:r}){let o=`${this.lc}[${this.rel8ToCurrentRoot.name}]`;try{if(r=r??await this.getLocalUserSpace({}),!r)throw new Error("space falsy and localUserSpace not initialized (?) (E: cbc4e519414a405eab7fe470eadbf8f0)");return mr({ibGib:e,linked:a,rel8nName:t,space:r,zeroSpace:this.zeroSpace,fnBroadcast:b(i=>this.fnBroadcast(i),"fnBroadcast"),fnUpdateBootstrap:b(i=>this.fnUpdateBootstrap(i),"fnUpdateBootstrap")})}catch(i){console.error(`${o} ${i.message}`);return}}async rel8ToSpecialIbGib(e){let a=`${this.lc}[${this.rel8ToSpecialIbGib.name}](type:${e.type},rel8nName:${e.rel8nName})`;try{let{type:t,rel8nName:r,ibGibsToRel8:o,ibGibsToUnRel8:i,addrsToUnRel8:n,linked:s,severPast:l,deletePreviousSpecialIbGib:d,space:f}=e;if(f=f??await this.getLocalUserSpace({}),!f)throw new Error("space falsy and localUserSpace not initialized (?) (E: af863928bbc945549ffc4dcca830a70a)");return bt({...e,space:f,zeroSpace:this.zeroSpace,fnUpdateBootstrap:b(h=>this.fnUpdateBootstrap(h),"fnUpdateBootstrap"),fnBroadcast:b(h=>this.fnBroadcast(h),"fnBroadcast")})}catch(t){throw console.error(`${a} ${t.message}`),t}}async registerNewIbGib({ibGib:e,space:a}){let t=`${this.lc}[${this.registerNewIbGib.name}]`;try{let r=y({ibGib:e});if(t=`${t}[${r}]`,a=a??await this.getLocalUserSpace({}),!a)throw new Error("space falsy and localUserSpace not initialized (?) (E: d7e6d609a784449087cbaf1bbfb6b0c2)");return p&&console.log(`${t} starting...`),ft({ibGib:e,space:a,fnBroadcast:b(o=>this.fnBroadcast(o),"fnBroadcast")})}catch(r){throw console.error(`${t} ${r.message}`),r}finally{p&&console.log(`${t} complete.`)}}async pingLatest_Local({ibGib:e,tjpIbGib:a,space:t,useCache:r}){let o=`${this.lc}[${this.pingLatest_Local.name}]`;p&&console.log(`${o} starting...`);try{if(!e){p&&console.log(`${o} ibGib falsy.`);return}if(J({ibGib:e})){console.warn(`${o} tried to ping latest for primitive. returning early... (W: 06c50cfe028cc04cca67e97a48e6fe22)`);return}if(e.ib.startsWith("witness space IonicSpace_V1")){let{spaceId:d}=qe({spaceIb:e.ib}),f=await this.getLocalUserSpace({localSpaceId:d});await this._latestSubj.next({ib:"IbGibTimelineUpdateInfo",latestIbGib:f,latestAddr:y({ibGib:f}),tjpAddr:`${e.ib}^gib`});return}if(t=t??await this.getLocalUserSpace({}),!t){console.warn(`${o} space falsy and localUserSpace not initialized. (W: e6708e58618947a6b66f6a49406cbf35)`);return}let i,n=y({ibGib:e}),s,l=await this.getLatestAddr({ibGib:e,tjp:a,space:t})??n;if(a||(a=await this.getTjpIbGib({ibGib:e,space:t}),a||(console.warn(`${o} tjp not found for ${n}? Should at least just be the ibGib's address itself. (W: 15d9c6daca7e442e968af36b4c18b8f7)`),a=e)),s=y({ibGib:a}),l===n)p&&console.log(`${o} latestAddr === ibGibAddr (I: f38042421fcc3d148a26ed56651c2522)`),i=e;else{p&&console.log(`${o} later version found. ibGibAddr: ${n}
|
|
11
|
+
latestAddr: ${l} (I: 53cabd1643df7d43635af642e4c90922)`);let d=await this.get({addr:l,space:t});if(!d.success||d.ibGibs?.length!==1)throw new Error("latest not found (E: bc54e433573a5a89c6436dc6a3b60922)");i=d.ibGibs[0]}if(i&&l&&s)await this._latestSubj.next({ib:"IbGibTimelineUpdateInfo",latestIbGib:i,latestAddr:l,tjpAddr:s});else{debugger;throw new Error("(UNEXPECTED) latestIbGib, latestAddr and tjpAddr should all be truthy. (E: 20e71fa1a72c45deb1dc5083903a8622)")}}catch(i){console.error(`${o} ${i.message}`)}finally{p&&console.log(`${o} complete.`)}}async persistTransformResult({resTransform:e,force:a,space:t}){let r=`${this.lc}[${this.persistTransformResult.name}]`;try{if(t=t??await this.getLocalUserSpace({}),!t)throw new Error("space falsy and localUserSpace not initialized (?) (E: f8b3d06006874b479240eb45f4015628)");return Se({resTransform:e,force:a,space:t})}catch(o){throw console.error(`${r} ${o.message}`),o}}async get({addr:e,addrs:a,isDna:t,space:r}){let o=`${this.lc}[${this.get.name}]`;try{if(r=r??await this.getLocalUserSpace({}),!r)throw new Error("space falsy and localUserSpace not initialized (?) (E: 86ccdcf3417a45b4a3a8c280fb9a6df7)");return dt({addr:e,addrs:a,isDna:t,space:r})}catch(i){return console.error(`${o} ${i.message}`),Promise.resolve({errorMsg:i.message})}}async put({ibGib:e,ibGibs:a,isDna:t,force:r,space:o}){let i=`${this.lc}[${this.put.name}]`;try{if(o=o??await this.getLocalUserSpace({}),!o)throw new Error("space falsy and localUserSpace not initialized (?) (E: a00eebe0e3d348d09fda62a6be486b6c)");return Yt({ibGib:e,ibGibs:a,isDna:t,force:r,space:o})}catch(n){return console.error(`${i} ${n.message}`),Promise.resolve({errorMsg:n.message})}}async delete({addr:e,isDna:a,space:t}){let r=`${this.lc}[${this.delete.name}]`;try{if(t=t??await this.getLocalUserSpace({}),!t)throw new Error("space falsy and localUserSpace not initialized (?) (E: b4250b0045dc40629447f2cbd162faaa)");return fr({addr:e,isDna:a,space:t})}catch(o){return console.error(`${r} ${o.message}`),Promise.resolve({errorMsg:o.message})}}async getDependencyGraph(e){let a=`${this.lc}[${this.getDependencyGraph.name}]`;try{if(e.space=e.space??await this.getLocalUserSpace({})??null,!e.space)throw new Error("(UNEXPECTED) space falsy and localUserSpace not initialized (?) (E: e2a35a23d12d48ebadcfd4f1a396d6c1)");return wt(e)}catch(t){throw console.error(`${a} ${t.message}`),t}}async getLatestAddr({ibGib:e,addr:a,tjpAddr:t,tjp:r,space:o}){let i=`${this.lc}[${this.getLatestAddr.name}]`;p&&console.log(`${i} starting...`);try{if(!e&&!r&&!t&&!a)throw new Error("ibGib && tjp && tjpAddr && addr are all falsy (E: fe725654342c4d80a33219160b5d81d3)");if(o=o??await this.getLocalUserSpace({}),!o)throw new Error("space falsy and localUserSpace not initialized (?) (E: fd01bb85e91f4c54bfe8b35714d48a38)");let n=await He({ibGibs:e?[e]:void 0,addrs:a?[a]:void 0,tjpAddrs:t?[t]:void 0,tjps:r?[r]:void 0,space:o});if(!n)throw new Error("resGetLatest falsy (E: 3851bbe4427ae11771f222234e8c6622)");if(!n.data)throw new Error("invalid resGetLatest: data falsy (E: 134e0f1f65edc69c6951c32e00a4bb22)");if(n.data.success){let s=n.data.latestAddrsMap;if(s){let l=Object.keys(s);if(l.length===1)return s[l[0]]||void 0;if(l.length===0)return n.data.addrsNotFound?.length===1,void 0;throw new Error("(UNEXPECTED) latestAddrsMap has multiple entries? We only asked for one. (E: 790518290f6b46729017684698539222)")}else{if(n.data.addrs?.length===1)return n.data.addrs[0];if(n.data.addrsNotFound?.length===1)return}if(n.data.addrsErrored?.length===1){let l=n.data.errors?.join("|")??"[unspecified error(s)] (E: 24f338036aa84ac99e3c39a660207222)";throw new Error(`resGetLatest had error(s): ${l}`)}else throw new Error(`unknown error, invalid resGetLatest: ${$(n)} (E: 6aa5aa225ebf49b588664370cb8feb22)`)}else{let s=n.data.errors?.join("|")??"[unspecified error(s)] (E: dcd6dcd6ec052fd112a4d48f1afa2922)";throw new Error(`resGetLatest had error(s): ${s}`)}}catch(n){throw console.error(`${i} ${n.message}`),n}finally{p&&console.log(`${i} complete.`)}}async getTjpIbGib({ibGib:e,naive:a=!0,space:t}){let r=`${this.lc}[${this.getTjpIbGib.name}]`;try{if(t=t??await this.getLocalUserSpace({}),!t)throw new Error("space falsy and localUserSpace not initialized (?) (E: 0ec806bd2c5641c4844a3698c922e1f6)");return t?gr({ibGib:e,naive:a,space:t}):(console.warn(`${r} space falsy and localUserSpace not initialized.`),e)}catch(o){throw console.error(`${r} ${o.message}`),o}}async getSpecialIbGib({type:e,initialize:a,space:t,lock:r,dontWarnIfNotExist:o}){let i=`${this.lc}[${this.getSpecialIbGib.name}]`;try{if(t=t??await this.getLocalUserSpace({lock:r}),!t)throw new Error("space falsy and localUserSpace not initialized (?) (E: e08e85d8422e479f9d101194fd26cbda)");for(;this.initializing;)p&&console.log(`${i} hacky wait while initializing ibgibs service (I: 497d4becb94f4515a2ec389630420d6c)`),await ne(100);return br({type:e,initialize:a,space:t,zeroSpace:this.zeroSpace,fnUpdateBootstrap:b(n=>this.fnUpdateBootstrap(n),"fnUpdateBootstrap"),fnBroadcast:b(n=>this.fnBroadcast(n),"fnBroadcast"),fnGetInitializing:b(()=>this._initializing,"fnGetInitializing"),fnSetInitializing:b(n=>{this._initializing=n},"fnSetInitializing"),dontWarnIfNotExist:o})}catch(n){return console.error(`${i} ${n.message}`),null}}async getSpecialRel8dIbGibs({type:e,rel8nName:a,space:t}){let r=`${this.lc}[${this.getSpecialRel8dIbGibs.name}]`;try{if(t=t??await this.getLocalUserSpace({}),!t)throw new Error("space falsy and localUserSpace not initialized (?) (E: 476c7d7c68f34197b740be5df09238a2)");return Qt({type:e,rel8nName:a,space:t})}catch(o){throw console.error(`${r} ${o.message}`),o}}async getPasswordForSecrets({secretIbGibs:e,fnPromptPassword:a,dontPrompt:t,checkCacheFirst:r,cacheAfter:o}){let i=`${this.lc}[${this.getPasswordForSecrets.name}]`,n=!1;try{let s=0;for(;this.isPrompting;)if(p&&console.log(`${i} hacky wait while already prompting (I: 852007c8549d42c096defe0105b5e2e6)`),await ne(100),s++,s>1e3)throw n=!0,new Error("attempted to prompt for user password, but already prompting for quite awhile now. (E: 8bd4dc907422dd95862b2038ffe2b822)");let l=e.map(w=>y({ibGib:w})).join("");if(r){let w=await this.getCachedSecretPassword({cacheKey:l});if(w)return p&&console.log(`${i} using cachedPassword.`),w}if(t)return null;this.isPrompting=!0;let d=[];for(let w=0;w<e.length;w++){let A=e[w];if(!A.data)throw new Error("invalid secretIbGib. data falsy.");if(A.data.type==="password"){let _=A.data;d.push(_)}else throw new Error("Only password secrets are implemented atm.")}let f="-------------",h=d.map(w=>`name: ${w.name}
|
|
12
|
+
description: ${w.description}
|
|
13
|
+
hint: ${w.hint}`).join(`
|
|
14
|
+
`+f+`
|
|
15
|
+
`),u="Gimme a password.",g=`Enter the password corresponding to the following secret(s):
|
|
16
|
+
|
|
17
|
+
${f}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
${h}
|
|
21
|
+
`,E=await a(u,g);return E&&o&&await this.setCachedSecretPassword({cacheKey:l,secretPassword:E}),E}catch(s){throw console.error(`${i} ${s.message}`),s}finally{n||(this.isPrompting=!1)}}async getCiphertextIbGib({plaintext:e,password:a,encryptionIbGib:t,confirm:r,persist:o,ibRoot:i,publicIbMetadata:n,publicMetadata:s}){let l=`${this.lc}[${this.getCiphertextIbGib.name}]`;try{let d=t.data;if(d?.method!==ca.encrypt_gib)throw new Error("only encrypt-gib is implemented. (E: 1d8eb1be6d3f44f0a79b498f237147e6");let f=d,h=await Wt({dataToEncrypt:e,secret:a,initialRecursions:f.initialRecursions,recursionsPerHash:f.recursionsPerHash,salt:f.salt,saltStrategy:f.saltStrategy,hashAlgorithm:f.hashAlgorithm,encryptedDataDelimiter:f.encryptedDataDelimiter,blockMode:d.blockMode?d.blockModeOptions:void 0,indexingMode:d.indexingMode,confirm:r});if((h.warnings?.length??!1)&&console.warn(`${l} warnings: ${h.warnings.join(`
|
|
22
|
+
`)}`),h.errors?.length??!1)throw new Error(h.errors.join(`
|
|
23
|
+
`));if(!h.encryptedData)throw new Error("encryptedData is falsy");let u={ciphertext:h.encryptedData,uuid:await M()};s&&(u.metadata=s);let E={newIbGib:await _r({parentPrimitiveIb:i||st,ib:n?`${i||st} ${n}`:`${i||st}`,data:u,rel8ns:void 0})};return o&&await this.persistTransformResult({resTransform:E}),E}catch(d){throw console.error(`${l} ${d.message}`),d}}async getPlaintextString({ciphertextIbGib:e,secretIbGibs:a,fnPromptPassword:t,dontPrompt:r,space:o}){let i=`${this.lc}[${this.getPlaintextString.name}]`;try{if((a||[]).length===0)throw new Error("secretIbGibs required. (E: 99a605b540c54b6db4d2ffe2caeb226a)");if(!e.data)throw new Error("ciphertextIbGib.data falsy (E: 598fc6473149e240a7d6916ecf642323)");if(!e.data.ciphertext)throw new Error("ciphertextIbGib.data.ciphertext falsy (E: 0e764a71ec214132a5a528f17f495a7c)");if(!e.rel8ns?.encryption)throw new Error("ciphertextIbGib.rel8ns.encryption falsy (E: a0b4d5d8674b4d0191fa619164153022)");if(e.rel8ns.encryption.length!==1)throw new Error("ciphertextIbGib.rel8ns!.encryption!.length !== 1 (E: a4a463e1ef0e45b4917eb04cb40d8173)");let n=e.rel8ns.encryption[0],s=await this.get({addr:n,space:o});if(!s.success)throw new Error("get encryption failed (E: feef34c05fae439c81ade7fc23037af1)");if((s.ibGibs||[]).length!==1)throw new Error("get encryption retrieved non-1 length (eesh) (E: 5d7e2023cc2b4e349574c17d5cfc8867)");let l=s.ibGibs[0];if(!l.data)throw new Error("encryptionIbGib.data falsy (E: 409a243afbf24c20987524f6588816fa)");let d=await this.getPasswordForSecrets({secretIbGibs:a,fnPromptPassword:t,dontPrompt:r,checkCacheFirst:!0,cacheAfter:!0});l.data.initialRecursions||console.warn(`${i} using default initialRecursions because encryptionIbGib does not state this explicitly (W: 66774cbfccd44423949d34167da6d50b)`),l.data.recursionsPerHash||console.warn(`${i} using default recursionsPerHash because encryptionIbGib does not state this explicitly (W: 29e264094f384d259319ba8587cd4f63)`),l.data.saltStrategy||console.warn(`${i} using default saltStrategy because encryptionIbGib does not state this explicitly (W: 7a5acadb8d634c7e87f62c86b57ac7a2)`),l.data.hashAlgorithm||console.warn(`${i} using default hashAlgorithm because encryptionIbGib does not state this explicitly(W: 2254db3569534b239a8c471b700c8500)`);let f=l.data.blockMode?Ka:Qa;if(l.data.blockMode){if(!l.data.blockModeOptions)throw new Error("invalid encryptionIbGib.data. blockMode is truthy but blockModeOptions is falsy. (E: 84bbc27a5248b7c4734a1674e41dd224)");l.data.indexingMode||console.warn(`${i} not complete. using default indexingMode ${f} because encryptionIbGib does not state this explicitly. (W: c15797cd8d0740ea886a348c10be2e5c)`)}p&&console.log(`${i} starting decrypt... (I: e14176ebc9a7470fb977d2184f1e2430)`);let h="sync_log decrypt";console.time(h),console.timeLog(h,"decrypting...");let u=await Vt({encryptedData:e.data.ciphertext,secret:d??"",initialRecursions:l.data.initialRecursions||Za,recursionsPerHash:l.data.recursionsPerHash||tr,salt:l.data.salt,saltStrategy:l.data.saltStrategy||er,hashAlgorithm:l.data.hashAlgorithm||ar,encryptedDataDelimiter:l.data.encryptedDataDelimiter,blockMode:l.data.blockMode?l.data.blockModeOptions:void 0,indexingMode:l.data.indexingMode||f});if(console.timeLog(h,"decrypting complete."),console.timeEnd(h),p&&console.log(`${i} decrypt complete. (I: 15a8182230294a8a96504ba3667f039a)`),u.errors?.length??!1)throw new Error(u.errors.join("|"));if(!u.decryptedData)throw new Error("(UNEXPECTED) resDecrypt has no errors but resDecrypt.decryptedData falsy? (E: 06e73992fb02e45e3c18db33f9a61b23)");return u.decryptedData}catch(n){throw console.error(`${i} ${n.message}`),n}}async getCachedSecretPassword({cacheKey:e}){let a=`${this.lc}[${this.getCachedSecretPassword.name}]`;try{if(!e)throw new Error("secretAddr required");let t=this.passwordCache[e];if(!t){p&&console.log(`${a} secretAddr not cached: ${e}`);return}p&&console.log(`${a} starting decrypt...`);let r=await Vt({encryptedData:t.encryptedPassword,secret:t.tempMetaPassword,initialRecursions:1e4,recursionsPerHash:5,salt:t.salt,saltStrategy:"appendPerHash",hashAlgorithm:"SHA-512"});if(p&&console.log(`${a} decrypt complete.`),!r.decryptedData)throw new Error("resDecrypt.decryptedData falsy");return r.decryptedData}catch(t){console.error(`${a} ${t.message}`);return}}async setCachedSecretPassword({cacheKey:e,secretPassword:a,force:t}){let r=`${this.lc}[${this.getCachedSecretPassword.name}]`;try{if(!e)throw new Error("secretAddr required");if(this.passwordCache[e])if(t)p&&console.log(`already cached, but force is true: ${e}`),delete this.passwordCache[e];else{p&&console.log(`already cached: ${e}`);return}let o=await M(256),i=await M(),n=await Wt({dataToEncrypt:a,secret:o,initialRecursions:1e4,recursionsPerHash:5,salt:i,saltStrategy:"appendPerHash",hashAlgorithm:"SHA-512"});if(!n.encryptedData)throw new Error("resEncrypt.encryptedData falsy");let s=n.encryptedData,l={tempMetaPassword:o,salt:i,encryptedPassword:s};this.passwordCache[e]=l,p&&console.log(`${r} entry added for ${e}.`)}catch(o){console.error(`${r} ${o.message}`);return}}async _createOuterspaceAndRequiredIbGibs({space:e,fnPromptSecret:a,fnPromptEncryption:t,fnPromptOuterSpace:r}){let o=`${this.lc}[${this._createOuterspaceAndRequiredIbGibs.name}]`;try{let i=await this._createSecret({space:e,fnPromptSecret:a});if(p&&console.log(`${o} createdSecret: ${i} (I: 9fc011d8ecb1e10c86c86025be4d5c22)`),!i)return!1;let n=await this._createEncryption({space:e,fnPromptEncryption:t});if(p&&console.log(`${o} createdEncryption: ${n} (I: 6796bbeb7338471e965cf1806d0dea9c)`),!n)return!1;let s=await this._createOuterspace({space:e,fnPromptOuterSpace:r});return p&&console.log(`${o} createdOuterspace: ${s} (I: 6796bbeb7338471e965cf1806d0dea9c)`),s}catch(i){return console.error(`${o} ${i.message}`),!1}}async _createSecret({space:e,fnPromptSecret:a}){let t=`${this.lc}[${this._createSecret.name}]`;try{p&&console.log(`${t} starting...`);let r=this.getFnAlert(),o=await this.getSpecialRel8dIbGibs({type:"secrets",rel8nName:Tt,space:e});for(o.length===0&&await r({title:"first create some stuff...",msg:"First we'll need to do a couple things, like create a secret password, an encryption setting, and a cloud endpoint."});o.length===0;){let i=await a(e);if(i===void 0)return await r({title:"cancelled",msg:"Cancelled."}),!1;await this.registerNewIbGib({ibGib:i}),await this.rel8ToSpecialIbGib({type:"secrets",rel8nName:Tt,ibGibsToRel8:[i],space:e}),o=await this.getSpecialRel8dIbGibs({type:"secrets",rel8nName:Tt,space:e})}return!0}catch(r){throw console.error(`${t} ${r.message}`),r}finally{p&&console.log(`${t} complete.`)}}async _createEncryption({space:e,fnPromptEncryption:a}){let t=`${this.lc}[${this._createEncryption.name}]`;try{p&&console.log(`${t} starting...`);let r=this.getFnAlert(),o=await this.getSpecialRel8dIbGibs({type:"encryptions",rel8nName:nt,space:e});for(o.length===0&&await r({title:"next create an encryption...",msg:"Now we need to create an encryption setting. If you don't know what this is, just fill in the requirements and leave the others as defaults."});o.length===0;){let i=await a(e);if(i===void 0)return await this.getFnAlert()({title:"cancelled",msg:"Cancelled."}),!1;await this.registerNewIbGib({ibGib:i,space:e}),await this.rel8ToSpecialIbGib({type:"encryptions",rel8nName:nt,ibGibsToRel8:[i],space:e}),o=await this.getSpecialRel8dIbGibs({type:"encryptions",rel8nName:nt,space:e})}return!0}catch(r){throw console.error(`${t} ${r.message}`),r}finally{p&&console.log(`${t} complete.`)}}async _createOuterspace({space:e,fnPromptOuterSpace:a}){let t=`${this.lc}[${this._createOuterspace.name}]`;try{let r=this.getFnAlert(),o=await this.getSpecialRel8dIbGibs({type:"outerspaces",rel8nName:Be,space:e});for(o.length===0&&await r({title:"Now to outerspace...",msg:"Great! Now we can create an outerspace ibgib, which is like a connection from this local space to other spaces (like the cloud)."});o.length===0;){let i=await a(e);if(i===void 0)break;await this.registerNewIbGib({ibGib:i,space:e}),await this.rel8ToSpecialIbGib({type:"outerspaces",rel8nName:Be,ibGibsToRel8:[i],space:e}),await r({title:"Good job",msg:"Great! Now we can use this space to synchronize & import ibgibs."}),o=await this.getSpecialRel8dIbGibs({type:"outerspaces",rel8nName:Be,space:e})}return o.length>0?!0:(await r({title:"cancelled",msg:"Cancelled."}),!1)}catch(r){throw console.log(`${t} ${r.message}`),r}}async getAppRobbotIbGibs({createIfNone:e,fnPromptRobbot:a,space:t}){let r=`${this.lc}[${this.getAppRobbotIbGibs.name}]`;try{if(t=t??await this.getLocalUserSpace({}),!t)throw new Error("space falsy and localUserSpace not initialized (?) (E: bf09346708ba4d6e9a1389bd1b66d500)");let o=await this.getSpecialRel8dIbGibs({type:"robbots",rel8nName:Ue,space:t}),i=[];for(let n=0;n<o.length;n++){let s=o[n],l=y({ibGib:s}),d=await this.getLatestAddr({ibGib:s,space:t});if(d&&d!==l){let h=await this.get({addr:d,space:t});if(!h||!h?.success||(h?.ibGibs??[]).length===0)throw new Error("could not get newer robbot ibgib (E: 15fa346c8ac17edb96e4b0870104c122)");s=h.ibGibs[0],l=y({ibGib:s})}let f=await la({robbotIbGib:s});(f??[]).length===0?i.push(s):console.error(`${r} robbot ibGib (${l}) has validation errors: ${f}`)}return i.length===0&&e&&(console.error(`${r} creating new robbot but should be not casting this on next line in src code. (E: 3252c5917e11421dbc1c26b280b8aeef)`),await da({ibgibs:this,space:t,fnPromptRobbot:a})&&(i=await this.getSpecialRel8dIbGibs({type:"robbots",rel8nName:Ue,space:t}))),i}catch(o){return console.error(`${r} ${o.message}`),[]}}async getAppAppIbGibs({createIfNone:e,fnPromptApp:a,space:t}){let r=`${this.lc}[${this.getAppAppIbGibs.name}]`;try{if(t=t??await this.getLocalUserSpace({}),!t)throw new Error("space falsy and localUserSpace not initialized (?) (E: a5aec4d94f764c6a964179bbb743b577)");let o=await this.getSpecialRel8dIbGibs({type:"apps",rel8nName:ke,space:t}),i=[];for(let n=0;n<o.length;n++){let s=o[n],l=y({ibGib:s}),d=await this.getLatestAddr({ibGib:s});if(d&&d!==l){let f=await this.get({addr:d,space:t});if(!f||!f?.success||(f?.ibGibs??[]).length===0)throw new Error("could not get newer app ibgib (E: de6a77634b1e4e16914ef110bb263d7c)");i.push(f.ibGibs[0])}else i.push(s)}return i.length===0&&e&&(console.error(`${r} creating new app but should be not casting this on next line in src code. (E: 3252c5917e11421dbc1c26b280b8aeef)`),await ct({ibgibs:this,space:t,fnPromptApp:a})&&(i=await this.getSpecialRel8dIbGibs({type:"apps",rel8nName:ke,space:t}))),i}catch(o){return console.error(`${r} ${o.message}`),[]}}subSagaSyncTimeLog;async syncIbGibs({localSpace:e,dependencyGraphIbGibs:a,syncSpaceIbGibs:t}){let r=`${this.lc}[${this.syncIbGibs.name}]`;try{if(this.syncing){console.warn("already syncing. (E: dfa3ad58e97f4b18b4e4d7dc252208fb)");return}if(Object.values(this.sagaInfoMap).length>0)throw new Error("this._syncing is false but sagaInfoMap not cleaned up(?). (E: bb69c808877c4931b5481585043c18e7)(UNEXPECTED)");this._syncing=!0;let o=(await M()).slice(0,24),i=await Je({replay:!0}),n=`sync_log ${o}`;if(console.time(n),console.timeLog(n,"start"),this.subSagaSyncTimeLog=await i.subscribe(Et({next:b(async u=>{p&&console.log(`${r}[obs.next] next called (I: 9af8d3267b0ff473fe5f8024f0dbed23)`),u.data?.statusCode===z.completed&&console.timeLog(n,"StatusCode.complete")},"next"),error:b(async u=>{p&&console.log(`${r}[obs.error] error called (I: 976b08ab82d64299b17927eac16b1693)`),console.timeEnd(n),this.subSagaSyncTimeLog||console.error(`${r}[obs.error] (unexpected) this.subSagaSyncTimeLog falsy (E: e1e82df8a1d94e7fbe55f638f3b4a53e)`),await this.subSagaSyncTimeLog.unsubscribe()},"error"),complete:b(async()=>{p&&console.log(`${r}[obs.complete] complete called (I: 72307340e2b34b22b0787e3a3c906c06)`),console.timeEnd(n),this.subSagaSyncTimeLog||console.error(`${r}[obs.complete] (unexpected) this.subSagaSyncTimeLog falsy (E: 89429f426206444d8d6431492e585213)`),await this.subSagaSyncTimeLog?.unsubscribe()},"complete")})),p&&console.log(`${r} starting...`),!a||a.length===0)throw new Error("dependencyGraphIbGibs required. (E: 404c36475fb84fc285a23a67c0b8fcb2)");if(!t||t.length===0)throw new Error("syncSpaceIbGibs required (E: c5a022454b9ce34856e141e61e337d24)");let s=e??await this.getLocalUserSpace({});if(!s?.data)throw new Error("localUserSpace?.data falsy (E: e7ff57e4d529cde903619078ee9b6e23)");if(!s.gib)throw new Error("localUserSpace.gib falsy (E: 884d86d20e7a4468b3c8b2c3ab7dba7e)");p&&console.log(`${r} get sync spaces (returns if none)`);let l=[{id:s.data.uuid,gib:s.gib,s_d:"src"},...t.map(u=>{if(!u.data)throw new Error("syncSpaceIbGib.data required. (E: 3c192771e84445a4b6476d5193b07e9d)");if(!u.data.uuid)throw new Error("syncSpaceIbGib.data.uuid required. (E: d27e9998227840f99d45a3ed245f3196)");if(!u.gib)throw new Error("syncSpaceIbGib.gib required. (E: db73aceb2f8445d8964ae49b59957072)");return{id:u.data.uuid,gib:u.gib,s_d:"dest"}})];p&&console.log(`${r} syncing to spaces in parallel...`);let d=await M(),f=[],h=t.map(async u=>{let g=await this._createNewSyncSagaInfo({multiSpaceOpId:d,allIbGibsToSync:a,syncSpace:u,participants:l,sagaId:o,syncStatus$:i});this.sagaInfoMap[g.sagaId]=g,f.push(g);try{await this._startSync({syncSagaInfo:g,syncTimelogName:n})}catch(E){throw console.error(`${r} (UNEXPECTED) ${E.message}`),E}});return console.timeLog(n,"awaiting all startSyncPromises starting..."),await Promise.all(h),console.timeLog(n,"awaiting all startSyncPromises complete."),await this._handleSagaUpdates(),f}catch(o){throw console.error(`${r} ${o.message}`),await this._finalizeAllSyncSagas_NoThrow({error:o}),o}finally{p&&console.log(`${r} complete.`)}}async _finalizeSyncSaga({sagaInfo:e,error:a}){let t=`${this.lc}[${this._finalizeSyncSaga.name}]`;try{if(p&&console.log(`${t} starting...`),e.complete)return;if(!e.syncStatus$)throw new Error("(UNEXPECTED) this.syncStatus$ falsy? (E: 1fc3817823752f66a6a190b8107fe523)");if(!e.syncStatus$.isCompleteOrErrored&&a){let i=typeof a=="string"?a:a.message??`${t} something went wrong (E: d7db873d9e8b4f14b5b490cadd9730f4)`;if(console.error(i),!e.syncStatus$.error)throw new Error("(UNEXPECTED) sagaInfo.syncStatus$.error is falsy? (E: 8522f275dbbf0885db75aead27d72923)");await e.syncStatus$.error(i)}let r=[],o=e.syncStatusSubscriptions??[];for(let i=0;i<o.length;i++){let n=o[i];await n.unsubscribed()||await n.unsubscribe()}p&&console.log(`${t} setting sagaInfo.complete to true (I: 85c34469cdac404782c2024ad6b6fbd1)`),e.complete=!0,this._updateSagaInfoMapAndIsSyncingFlag(),p&&console.log(`${t} complete.`)}catch(r){throw console.error(`${t} ${r.message}`),p&&console.log(`${t} setting sagaInfo.complete to true (I: 23de6ef45eaf47a1918038dce3da7d78)`),e.complete=!0,r}finally{p&&console.log(`${t} complete.`)}}async _finalizeAllSyncSagas_NoThrow({error:e}){let a=`${this.lc}[${this._finalizeAllSyncSagas_NoThrow.name}]`;try{let t=Object.values(this.sagaInfoMap).filter(r=>!r.complete);for(let r=0;r<t.length;r++){let o=t[r];await this._finalizeSyncSaga({sagaInfo:o,error:e})}}catch(t){console.error(`${a}(UNEXPECTED) ${t.message}`)}finally{this._updateSagaInfoMapAndIsSyncingFlag()}}_updateSagaInfoMapAndIsSyncingFlag(){let e=`${this.lc}[${this._updateSagaInfoMapAndIsSyncingFlag.name}]`;try{if(p&&console.log(`${e} starting...`),Object.keys(this.sagaInfoMap||{}).length===0){this.sagaInfoMap={},this._syncing&&(this._syncing=!1);return}Object.values(this.sagaInfoMap).every(r=>r.complete)&&(p&&console.log(`${e} all sagaInfos are complete. finalizing sync. (I: f6d94deb5509e6b2e5371b9bfc007422)`),this.sagaInfoMap={},this._syncing=!1,p&&console.log(`${e} this._syncing is now false.`))}catch(a){throw console.error(`${e} ${a.message}`),a}finally{p&&console.log(`${e} complete.`)}}async _createNewSyncSagaInfo({multiSpaceOpId:e,allIbGibsToSync:a,syncSpace:t,participants:r,sagaId:o,syncStatus$:i}){let n=`${this.lc}[${this._createNewSyncSagaInfo.name}]`;try{if(!e)throw new Error("multiSpaceOpId required. (E: a7e228dbd63948d784a67ddbb342e4f7)");if(!t.data)throw new Error("syncSpace.data required. (E: 1c44334cf4545de147ef2dc675406a23)");let s=a.map(g=>y({ibGib:g})),l=a.filter(g=>Gr({ibGib:g})).map(g=>y({ibGib:g})),d=a.filter(g=>g.gib!==se&&g.data?.isTjp===!0).map(g=>y({ibGib:g})),f=s.filter(g=>!l.includes(g)),h={multiSpaceOpId:e,outerSpace:t,spaceId:t.data.uuid,sagaId:o,participants:r,witnessFnArgsAndResults$:await Je({replay:!0}),syncStatus$:i,syncStatusSubscriptions:[],syncIbGibs_All:a,syncAddrs_All:s,syncAddrs_All_AreTjps:d,syncAddrs_All_WithTjps:l,syncAddrs_All_WithoutTjps:f,syncAddrs_Skipped:[],syncAddrs_ToDo:[],syncAddrs_InProgress:[],syncAddrs_Failed:[]},u=`sync_log ${h.sagaId}`;return console.timeLog(u),h}catch(s){throw console.error(`${n} ${s.message}`),s}}async _startSync({syncSagaInfo:e,syncTimelogName:a}){let t=`${this.lc}[${this._startSync.name}]`;try{let{multiSpaceOpId:r,participants:o,sagaId:i,outerSpace:n,syncIbGibs_All:s,syncAddrs_All:l,syncAddrs_All_WithTjps:d,syncAddrs_All_WithoutTjps:f}=e;console.timeLog(a,"getLocalUserSpace starting...");let h=await this.getLocalUserSpace({});if(!h)throw new Error("localUserSpace required (E: e01fc13ce7c5a802b50aa0f9b2c13a23)");if(!h.data)throw new Error("localUserSpace.data required (E: e01fc13ce7c5a802b50aa0f9b2c13a23)");console.timeLog(a,"getLocalUserSpace complete.");let u=await n.argy({argData:{cmd:"put",cmdModifiers:["sync"],sagaId:i,participants:o,ibGibAddrs:l,ibGibAddrs_All_Tjps:d,ibGibAddrs_All_NonTjps:f},ibGibs:s,ibMetadata:`sync src ${h.data.name} srcId ${h.data.uuid}`});u.syncSagaInfo=e,e.witnessFnArgsAndResults$.next(u),console.timeLog(a,"syncSpace witness starting...");let g=await n.witness(u);if(console.timeLog(a,"syncSpace witness complete."),!g.data?.statusTjpAddr)throw new Error(`resStartSync.data.statusTjpAddr is falsy. sagaId: ${i} (E: 727b5cc1a0254497bc6e06e9c6760564)`);return e.witnessFnArgsAndResults$.next(g),g}catch(r){throw console.error(`${t} ${r.message}`),r}}async _handleSagaUpdates(){let e=`${this.lc}[${this._handleSagaUpdates.name}]`;try{let a=Object.values(this.sagaInfoMap);for(let t=0;t<a.length;t++){let r=a[t],o=await r.syncStatus$.subscribe(Et({next:b(async i=>{p&&console.log(`${e}(sagaId: ${r.sagaId}) subscribe next triggered. status: ${i?.data?.statusCode} (I: 41e1f61e5e1b422ead1d72a1c92c7d51)`),await this._handleSyncStatusIbGib({status:i,sagaInfo:r})},"next"),error:b(async i=>{let n=`${e}(sagaId: ${r.sagaId}) syncStatus$.error: ${i}`;console.error(n),await this._finalizeSyncSaga({sagaInfo:r,error:n})},"error"),complete:b(async()=>{p&&console.log(`${e}(sagaId: ${r.sagaId}) syncStatus$.complete.`),await o.unsubscribe()},"complete")}))}}catch(a){throw console.error(`${e} ${a.message}`),a}}async _handleSyncStatusIbGib({status:e,sagaInfo:a}){let t=`${this.lc}[${this._handleSyncStatusIbGib.name}]`;try{if(p&&console.log(`${t} starting...`),!e)throw new Error("falsy status. (E: 8da370a9f3df48a98cc08f1cccf5f2dc)");if(!e.data)throw new Error("falsy status.data. (E: 996d458c5cde4622ba1ed54c7e188815)");if(!e.data.statusCode)throw new Error("falsy status.data.statusCode (E: 7f2bec6b9dd0484eb7ef97966e6dd027)");let r=Pt({participants:a.participants}),o=await this.getLocalUserSpace({lock:!1,localSpaceId:r});if(!o)throw new Error(`(UNEXPECTED) couldn't get the local space (id: ${r}) in the middle of a saga? (E: b921a1530148ccdae688cb8a13715324)`);(await this.put({ibGibs:e.statusIbGibGraph,space:o})).success||console.error(`${t}(UNEXPECTED) couldn't save status graph locally? sagaId: ${a.sagaId} (E: b472101897824195b96b658c441dfb55)`);let n=e.data.statusCode;switch(p&&console.log(`${t} status update received. statusCode: ${n}. sagaId: ${a.sagaId}. spaceId: ${a.spaceId}`),n){case z.started:break;case z.inserted:break;case z.updated:break;case z.merged_dna:await this._handleSyncStatus_Merged({status:e,sagaInfo:a});break;case z.merged_state:await this._handleSyncStatus_Merged({status:e,sagaInfo:a});break;case z.already_synced:break;case z.completed:await this._handleSyncStatus_Complete({sagaInfo:a});break;case z.undefined:throw new Error(`statusCode is "undefined". Maybe published a primitive? sagaId: ${a.sagaId} (E: c98376f35b194adf9bf12ff9259a2569)`);default:throw new Error(`(UNEXPECTED) unknown status.data.statusCode (${e.data.statusCode}). sagaId: ${a.sagaId} (E: e4872abfc1ae4c27905793ca0f937a9b)`)}p&&console.log(`${t} complete.`)}catch(r){let o=`${t} ${r.message}`;if(console.error(o),!a.syncStatus$?.error)throw new Error("(UNEXPECTED) sagaInfo.syncStatus$.error falsy? (E: 36cc488835aeb12e1ae6b7a49d0d8523)");await a.syncStatus$.error(o)}}async _handleSyncStatus_Merged({status:e,sagaInfo:a}){let t=`${this.lc}[${this._handleSyncStatus_Merged.name}]`;try{if(p&&console.log(`${t} starting...`),(e.createdIbGibs??[]).length===0&&(e.storeOnlyIbGibs??[]).length===0)throw new Error("status.createdIbGibs and/or status.storeOnlyIbGibs required when merging. (E: d118bde47fb9434fa95d747f8e4f6b33)");if(Object.keys(e.ibGibsMergeMap??{}).length===0)throw new Error("status.ibGibsMergeMap required when merging. (E: 0f06238e5535408f8980e0f9f82cf564)");p&&console.log(`${t} validated.`);let r=Pt({participants:a.participants}),o=await this.getLocalUserSpace({localSpaceId:r});if(!o)throw new Error(`(UNEXPECTED) couldn't get src participant with space id (${r}) in the middle of a saga? (E: c75732b748f6a168254e38dc5548e824)`);let i=b(async s=>{let l=Sr({ibGibs:s});for(let d=0;d<Object.keys(l).length;d++){let f=Object.keys(l)[d],h=l[f],u=h[h.length-1];await this.registerNewIbGib({ibGib:u,space:o})}},"registerLatestInTimelines");if(e.createdIbGibs?.length??!1){if(p&&console.log(`${t} putting createdIbGibs (${e.createdIbGibs.length}): ${e.createdIbGibs.map(l=>y({ibGib:l})).join(`
|
|
24
|
+
`)}.`),!(await this.put({ibGibs:e.createdIbGibs,space:o})).success)throw new Error("Couldn't save created ibGibs locally? (E: f8bc91259c5043d589cd2e7ad2220c1f)");e.storeOnlyIbGibs&&await i(e.storeOnlyIbGibs)}else p&&console.log(`${t} no createdIbGibs`);if(e.storeOnlyIbGibs?.length??!1){if(p&&console.log(`${t} putting into local space the storeOnlyIbGibs (${e.storeOnlyIbGibs.length}): ${e.storeOnlyIbGibs.map(l=>y({ibGib:l})).join(`
|
|
25
|
+
`)}.`),console.warn(`${t} putting storeOnlyIbGibs (${e.storeOnlyIbGibs.length}): ${e.storeOnlyIbGibs.map(l=>y({ibGib:l})).join(`
|
|
26
|
+
`)}.`),!(await this.put({ibGibs:e.storeOnlyIbGibs,space:o})).success)throw new Error("Couldn't save storeonly ibGibs locally? (E: c5ab044718ab42bba27f5852149b7ddc)");await i(e.storeOnlyIbGibs)}else p&&console.log(`${t} no storeOnlyIbGibs`);let n=Object.values(e.ibGibsMergeMap??{});for(let s=0;s<n.length;s++){let l=n[s];p&&console.log(`${t} registering latestIbGib in localUserSpace: ${y({ibGib:l})}`),await this.registerNewIbGib({ibGib:l,space:o})}p&&console.log(`${t} complete.`)}catch(r){throw console.error(`${t} ${r.message}`),r}}async _handleSyncStatus_Complete({sagaInfo:e}){let a=`${this.lc}[${this._handleSyncStatus_Complete.name}]`;try{await this._finalizeSyncSaga({sagaInfo:e}),Object.values(this.sagaInfoMap).every(r=>r.complete)&&await this._finalizeAllSyncSagas_NoThrow({})}catch(t){console.error(`${a} ${t.message}`),await this._finalizeAllSyncSagas_NoThrow({error:t})}}async _getLatestIbGibsWithTjps({ibGibs:e,warnIfMultipleLocalTimelines:a}){let t=`${this.lc}[${this._getLatestIbGibsWithTjps.name}]`;try{let r=[],o=e.filter(s=>s.data?.isTjp||(s.rel8ns?.tjp?.length??0)>0||s.gib?.includes(ye)),i=Ha({items:o,keyFn:b(s=>H({gib:s.gib}).tjpGib??"","keyFn")}),n=Object.keys(i);for(let s=0;s<n.length;s++){let l=i[n[s]];if(a){let f={};for(let h of l){let u=h.data?.isTjp?-1:h.data?.n??-2;if(u===-2)throw new Error("ibGibFrame.data.n is undefined. We're only working with those with n right now!");f[u]=(f[u]??0)+1}Object.values(f).some(h=>h>1)&&console.warn(`${t} we have multiple local timelines.`)}let d=l.sort((f,h)=>(f.data?.n??-1)>(h.data?.n??-1)?1:-1)[l.length-1];r.push(d)}return r}catch(r){throw console.error(`${t} ${r.message}`),r}}async enableAutosync({tjpIbGibs:e}){let a=`${this.lc}[${this.enableAutosync.name}]`;try{if(p&&console.log(`${a} starting...`),(e??[]).length===0)throw new Error("tjps required. (E: 3e3bb6ef1a3d483795440e0efcef8e04)");if(e.some(s=>!s.data?.isTjp)){let s=e.filter(l=>!l.data?.isTjp).map(l=>y({ibGib:l}));console.warn(`${a} unrelating tjp whose data.isTjp is false. tjpAddrs: ${s.join("|")} (W: 03b3d7a94e6d4ccaace3df4657a82322)`)}let t=e.map(s=>y({ibGib:s})),r=t.filter(s=>!this._alwaysAutosyncTjpAddrsCache.has(s));if(r.length===0){console.warn(`${a} all tjpAddrs already auto syncing. tjpAddrs: ${t.join(`
|
|
27
|
+
`)} (W: 7fbe51c8187840efa1b259417053bd22)`);return}let o=await this.getSpecialIbGib({type:"autosyncs"});if(!o?.rel8ns)throw new Error("autosyncsIbGib?.rel8ns falsy (E: 963313139e919c09aade8b8c412d7b23)");let i=o.rel8ns[_e]??[];if(r=t.filter(s=>!i.includes(s)),r.length===0){console.error(`${a} (UNEXPECTED) all tjpAddrs already auto syncing per special ibgib. Proceeding without throwing here, but this means that the cache is out of sync with the special ibgib also. tjpAddrs: ${t.join(`
|
|
28
|
+
`)} (E: 574e163118f043fa8c50cfd575e62122)`);return}let n=r.map(s=>e.filter(l=>y({ibGib:l})===s)[0]);await this.rel8ToSpecialIbGib({type:"autosyncs",ibGibsToRel8:n,rel8nName:_e}),r.forEach(s=>{this._alwaysAutosyncTjpAddrsCache.add(s)})}catch(t){throw console.error(`${a} ${t.message}`),t}finally{p&&console.log(`${a} complete.`)}}async disableAutosync({tjpIbGibs:e}){let a=`${this.lc}[${this.disableAutosync.name}]`;try{if(p&&console.log(`${a} starting...`),(e??[]).length===0)throw new Error("tjps required. (E: 7b7e34e20b5848b882e14ff8b6c53622)");if(e.some(l=>!l.data?.isTjp)){let l=e.filter(d=>!d.data?.isTjp).map(d=>y({ibGib:d}));console.warn(`${a} unrelating tjp whose data.isTjp is false. tjpAddrs: ${l.join("|")} (W: 7babdf67dda54a2a9905c6c45ef36522)`)}let t=e.map(l=>y({ibGib:l})),r=await this.getSpecialIbGib({type:"autosyncs"});if(!r?.rel8ns)throw new Error("(UNEXPECTED) invalid autosyncIbGibs. rel8ns falsy. (E: 5f6211c8a41896003db8bfc40230af22)");let o=r.rel8ns[_e]??[],i=[];if(t.forEach(l=>{o.includes(l)?(p&&console.log(`${a} disabling autosync for ${l} (I: 63087804e6c436143971e5039b5e5e22)`),i.push(l)):p&&console.log(`${a} already NOT auto syncing ${l} (I: 88e00fea009964cd2bab4cc580aa2922)`)}),i.length===0){console.warn(`${a} tried to disable autosync for tjpAddrs but none were valid. returning early. (W: f9bdda90d906471aa56804d76b6e9522)`);return}let n=Array.from(new Set(i)),s=n.map(l=>e.filter(d=>y({ibGib:d})===l)[0]);await this.rel8ToSpecialIbGib({type:"autosyncs",ibGibsToUnRel8:s,rel8nName:_e}),n.forEach(l=>{this._alwaysAutosyncTjpAddrsCache.delete(l)})}catch(t){throw console.error(`${a} ${t.message}`),t}finally{p&&console.log(`${a} complete.`)}}async loadAutoSyncs(){let e=`${this.lc}[${this.loadAutoSyncs.name}]`;try{p&&console.log(`${e} starting...`);let a=await this.getSpecialIbGib({type:"autosyncs"});if(!a){console.warn(`${e} autosyncsIbGib ("autosyncs") special ibgib not found not found. maybe fine, no idea. (W: 30ad2df15b38999106883358722fd425)`);return}a.rel8ns&&(this._alwaysAutosyncTjpAddrsCache=new Set(a.rel8ns[_e]))}catch(a){throw console.error(`${e} ${a.message}`),a}finally{p&&console.log(`${e} complete.`)}}autosyncIsEnabled({tjp:e}){let a=`${this.lc}[${this.autosyncIsEnabled.name}]`;try{return p&&console.log(`${a} starting...`),this._alwaysAutosyncTjpAddrsCache.has(y({ibGib:e}))}catch(t){throw console.error(`${a} ${t.message}`),t}finally{p&&console.log(`${a} complete.`)}}};var ue=".",Q="utf8",me="ibgib",ge=`000_${$e}`,K="ibgibs",Z="meta",ee="bin",te="dna",we="l",Ct="This is a filesystem space. The ibgib data contains settings for the space itself, and the witness ibgib object interfaces with a back end that is hierarchical like a filesystem. Descend from this class if you're working with a similar space.",ao=240,xt="/",ro=32;function fa(){return async({title:c,msg:e})=>{let a=`[${fa.name}]`,t;try{if(!e)throw new Error("msg required. (E: c39d1656b6b803e11bad46efe15b6823)");t=await Xe({title:c,msg:e})}catch(r){throw console.error(`${a} ${m(r)}`),r}return t||t===""?t:null}}b(fa,"getFnPrompt");var Ce=!1,Lt=class c extends vr{static{b(this,"SpaceBase_V1")}lc=`[${c.name}]`;cacheSvc;constructor(e,a){super(e,a),this.initialized=this.initialize()}async witnessImpl(e){let a=`${this.lc}[${this.witnessImpl.name}]`;return Ce&&console.log(`${a}`),await this.routeAndDoCommand({cmd:e.data.cmd,cmdModifiers:e.data.cmdModifiers??[],arg:e})}routeAndDoCommand({cmd:e,cmdModifiers:a,arg:t}){let r=`${this.lc}[${this.routeAndDoCommand.name}]`;switch(e){case le.get:return(a??[]).length===0?this.get(t):a.includes("can")?this.canGet(t):a.includes("latest")?a.includes("addrs")?this.getLatestAddrs(t):this.getLatestIbGibs(t):a.includes("tjps")?a.includes("addrs")?this.getTjpAddrs(t):this.getTjpIbGibs(t):a.includes("addrs")?this.getAddrs(t):a.includes("dependency-graph")?this.getDependencyGraph(t):this.get(t);case le.put:return(a??[]).length===0?this.put(t):a.includes("can")?this.canPut(t):this.put(t);case le.delete:return(a??[]).length===0?this.delete(t):a.includes("can")?this.canDelete(t):this.delete(t);default:throw new Error(`${r} unknown cmd: ${e}. cmdModifiers: ${a}`)}}get(e){return this.getImpl(e)}put(e){return this.putImpl(e)}delete(e){return this.deleteImpl(e)}deleteImpl(e){let a=`${this.lc}[${this.deleteImpl.name}]`;throw new Error(`${a} not implemented in base class`)}getAddrs(e){return this.getAddrsImpl(e)}getAddrsImpl(e){let a=`${this.lc}[${this.getAddrsImpl.name}]`;throw new Error(`${a} not implemented in base class`)}getLatestIbGibs(e){return this.getLatestIbGibsImpl(e)}getLatestIbGibsImpl(e){let a=`${this.lc}[${this.getLatestIbGibsImpl.name}]`;throw new Error(`${a} not implemented in base class`)}getLatestAddrs(e){return this.getLatestAddrsImpl(e)}getLatestAddrsImpl(e){let a=`${this.lc}[${this.getLatestAddrsImpl.name}]`;throw new Error(`${a} not implemented in base class`)}getTjpIbGibs(e){return this.getTjpIbGibsImpl(e)}getTjpIbGibsImpl(e){let a=`${this.lc}[${this.getTjpIbGibsImpl.name}]`;throw new Error(`${a} not implemented in base class`)}getTjpAddrs(e){return this.getTjpAddrsImpl(e)}getTjpAddrsImpl(e){let a=`${this.lc}[${this.getTjpAddrsImpl.name}]`;throw new Error(`${a} not implemented in base class`)}canGet(e){return this.canGetImpl(e)}canGetImpl(e){let a=`${this.lc}[${this.canGetImpl.name}]`;throw new Error(`${a} not implemented in base class`)}canPut(e){return this.canPutImpl(e)}canPutImpl(e){let a=`${this.lc}[${this.canPutImpl.name}]`;throw new Error(`${a} not implemented in base class`)}canDelete(e){return this.canPutImpl(e)}canDeleteImpl(e){let a=`${this.lc}[${this.canDeleteImpl.name}]`;throw new Error(`${a} not implemented in base class`)}getDependencyGraph(e){return this.getDependencyGraphImpl(e)}async getDependencyGraphImpl(e){let a=`${this.lc}[${this.getDependencyGraphImpl.name}]`;try{if(Ce&&console.log(`${a} starting... (I: 0e5fe807a0169224781f6c2833f34826)`),!e.data)throw new Error("(UNEXPECTED) arg.data falsy? (E: 45eba816295a97a0e55f981861a03f26)");if((e.data.ibGibAddrs??[]).length===0)throw new Error("arg.data.ibGibAddrs is falsy/empty (E: 70adc939c7b80c9938d8fa18fd7c5826)");let t={space:this,ibGibAddrs:e.data.ibGibAddrs,live:e.data.live||!0},r=await wt(t),o=Object.values(r),i={optsAddr:y({ibGib:e}),count:o.length,addrs:Object.keys(r)};return this.resulty({resultData:i,ibGibs:o})}catch(t){throw console.error(`${a} ${m(t)}`),t}finally{Ce&&console.log(`${a} complete.`)}}async validateWitnessArg(e){let a=`${this.lc}[${this.validateWitnessArg.name}]`,t=[];try{if(t=await super.validateWitnessArg(e),!e.data)return t.push("arg.data required (E: 8ee544d7d88a45c6adcbc15838a283a7)"),t;if(!this.data)return t.push("this.data required (E: 64f80642d7de44329355d6f907e272c8)"),t;let{cmd:r,ibGibAddrs:o}=e.data,i=e.data.cmdModifiers??[],n=e.ibGibs;r||t.push("arg.data.cmd required (E: 72a11ee87a0d4896bcacd65a9c0284d9)"),Object.values(le).includes(r)||t.push(`unknown arg.data.cmd: ${r}. (E: 95282ce61e97429f8049e61ec9f14f0b)`);let s=o?.length??0;if(r===le.get&&!i?.includes("addrs")&&!i?.includes("latest")&&s===0&&t.push(`ibGibAddrs required when cmd is ${r}. (E: ee55a3f60b90423cbe054f27c34ab7d5)`),r===le.put){Ce&&console.log(`${a} validate put cmd`);let l=n?.length??0;if(l===0)t.push(`ibGibs required when cmd is ${r}. (E: b3a422169f7344a48a1d44e7ad1ba44e)`);else if(this.data.validateIbGibAddrsMatchIbGibs)if(Ce&&console.log(`${a} validateIbGibAddrsMatchIbGibs true, so doing so.`),l!==s)t.push("ibGibsLength !== ibGibAddrsLength and this.data.validateIbGibAddrsMatchIbGibs is true. (E: 6c6bf824ab32443aa4d6b8bf4f8113dd)");else{Ce&&console.log(`${a} validateIbGibAddrsMatchIbGibs, lengths match. validating intrinsically`);let d=o.concat();for(let f=0;f<n.length;f++){let h=n[f],u=await X({ibGib:h});if(u?.length??!1){let g=y({ibGib:h});u.forEach(E=>t.push(`(${g}) ERROR: ${E}`))}else{let g=y({ibGib:h}),E=d.indexOf(g);if(E===-1){t.push(`ibGibAddrs don't map to calculated ibGib addrs. calculated Addr: (${g}) (E: b21b3a7a74db43e5a8722acc97274646)`);break}else d.splice(E,1)}}}}return t}catch(r){throw console.error(`${a} ${m(r)}`),r}finally{t?.length>0&&console.error(`${a} errors: ${t}`)}}async argy({argData:e,ibMetadata:a,noTimestamp:t,ibGibs:r}){let o=await Te({argData:e,ibMetadata:a,noTimestamp:t});return r&&(o.ibGibs=r),o}async resulty({resultData:e,ibGibs:a}){let t=await yt({ibMetadata:yr({space:this}),resultData:e});return a&&(t.ibGibs=a),t}};var I=!1,oo={version:"3",uuid:it,name:$e,classname:"FilesystemSpace_V1",baseDir:ue,encoding:Q,baseSubPath:me,spaceSubPath:ge,ibgibsSubPath:K,metaSubPath:Z,binSubPath:ee,dnaSubPath:te,longSubPath:we,longPathLength:ao,mitigateLongPaths:!0,persistOptsAndResultIbGibs:!1,validateIbGibAddrsMatchIbGibs:!1,longPollingIntervalMs:Ie,allowPrimitiveArgs:!1,catchAllErrors:!0,description:Ct,trace:!1};var Ke=class c extends Lt{static{b(this,"FilesystemSpace_V1")}lc=`[${c.name}]`;ibGibs={};pathExistsMap={};constructor(e,a){super(e??O(oo),a)}async validateWitnessArg(e){let a=`${this.lc}[${this.validateWitnessArg.name}]`,t=[];try{t=await super.validateWitnessArg(e)||[],e.data?.cmd==="put"&&(e.ibGibs||[]).length===0&&t.push('when "put" cmd is called, ibGibs required.'),e.data?.cmd==="get"&&(e.data?.ibGibAddrs||[]).length===0&&t.push('when "get" cmd is called, ibGibAddrs required.')}catch(r){throw console.error(`${a} ${m(r)}`),r}finally{t?.length>0&&console.error(`${a} errors: ${t}`)}return t}async initialize(){let e=`${this.lc}[${this.initialize.name}]`;try{I&&console.log(`${e} starting...`),this.data||(this.data=O(oo),this.data=this.data),this.data?.classname||(this.data.classname=c.name),this.data.baseDir||(this.data.baseDir=ue),this.data.encoding||(this.data.encoding=Q),this.data.baseSubPath||(this.data.baseSubPath=me),this.data.spaceSubPath||(this.data.spaceSubPath=ge),this.data.ibgibsSubPath||(this.data.ibgibsSubPath=K),this.data.metaSubPath||(this.data.metaSubPath=Z),this.data.binSubPath||(this.data.binSubPath=ee),this.data.dnaSubPath||(this.data.dnaSubPath=te),this.ib=pt({space:this,classname:c.name}),this.gib=await q({ibGib:this})}catch(a){console.error(`${e} ${m(a)}`)}finally{I&&console.log(`${e} complete.`)}}hasInCache({addr:e}){return J({gib:C({ibGibAddr:e}).gib})?Promise.resolve(!1):Object.keys(this.ibGibs).includes(e)?Promise.resolve(!0):this.cacheSvc?this.cacheSvc.has({addr:e}):Promise.resolve(!1)}async putInCache({addr:e,ibGib:a}){let t=`${this.lc}[${this.putInCache.name}][${e}]`;try{if(I&&console.log(`${t} starting...`),!a)throw new Error("ibGib required (E: 993e26fe40894bab9feccac3938f37df)");if(J({ibGib:a})){I&&console.log(`${t} skipping caching primitive (I: a04dfb691582a4db8a0bfecfefe5e622)`);return}else I&&console.log(`${t} caching addr (I: b996a306f256ee5f39db1e2f5d515c22)`);this.ibGibs[e]=a,this.cacheSvc&&await this.cacheSvc.put({addr:e,ibGib:a})}catch(r){throw console.error(`${t} ${m(r)}`),r}finally{I&&console.log(`${t} complete.`)}}async getFromCache({addr:e}){let a=`${this.lc}[${this.getFromCache.name}]`;try{I&&console.log(`${a} starting...`);let t=this.ibGibs[e];return!t&&this.cacheSvc&&(t=(await this.cacheSvc.get({addr:e}))?.ibGib),t}catch(t){throw console.error(`${a} ${m(t)}`),t}finally{I&&console.log(`${a} complete.`)}}deleteFromCache({addr:e}){let a=`${this.lc}[${this.getFromCache.name}]`;try{return I&&console.log(`${a} starting...`),delete this.ibGibs[e],Promise.resolve()}catch(t){throw console.error(`${a} ${m(t)}`),t}finally{I&&console.log(`${a} complete.`)}}async getImpl(e){let a=`${this.lc}[${this.getImpl.name}]`,t=[],r={optsAddr:y({ibGib:e})},o;try{if(!e.data)throw new Error("arg.data is falsy");let{ibGibAddrs:i,isDna:n}=e.data;i||=[];let s=i.filter(d=>de({addr:d})),l=i.filter(d=>!s.includes(d));I&&console.log(`${a} getting non-bin ibgibs. ibGibAddrsNonBin: ${l}`);for(let d=0;d<l.length;d++){let f=l[d];if(!e.data.force&&await this.hasInCache({addr:f})){I&&console.log(`${a} YES found in naive cache. (I: 0b23f394fd944c2a96df3543dd0a59c5)`);let h=await this.getFromCache({addr:f});if(!h)throw new Error("(UNEXPECTED) we had in cache but failed to retrieve? (E: 4af334f7a90cb22ffa3b549d0db19a22)");t.push(h)}else{let h=await this.getFile({addr:f,isDna:n});h?.success&&h.ibGib?(await this.putInCache({addr:f,ibGib:h.ibGib}),t.push(h.ibGib)):(o||(o=[]),o.push(f))}}for(let d=0;d<s.length;d++){let f=s[d],{binHash:h,binExt:u}=ea({addr:f});I&&console.log(`${a} getting binHash.binExt: ${h}.${u}`);let g=await this.getFile({addr:f});g?.success&&g.ibGib?(I&&console.log(`${a} getResult.success. ibGib.data?.length: ${g.ibGib.data?.length}`),t.push(g.ibGib)):(I&&console.log(`${a} not found in files. (binData is not cached atm)`),o||(o=[]),o.push(f))}o&&o.length>0?(I&&console.log(`${a}[${this.data.uuid.substring(0,8)}] notFoundIbGibAddrs: ${o} (I: 10f7e35e75445a1d64b353851d00b923)`),r.addrsNotFound=o,r.errors??=[],r.errors.push("notFoundIbGibAddrs.length > 0 (E: e7eadcfa2f4643238590469bc917a35c)"),r.success=!1):r.success=!0}catch(i){let n=m(i);console.error(`${a} error: ${n}`),r.errors=[n]}try{let i=await this.resulty({resultData:r});return t.length>0&&(i.ibGibs=t),i}catch(i){throw console.error(`${a} ${m(i)}`),i}}async putImpl(e){let a=`${this.lc}[${this.putImpl.name}]`,t={optsAddr:y({ibGib:e})},r=[];try{if(I&&console.log("validating arg and internal state..."),!e.data)throw new Error("arg.data required. (E: d64a46e5efab4b09b57850ecf0854386)");if(e.ibGibs?.length===0)throw new Error("arg.ibGibs required. (E: b4930d564b284fb9b26b542f14143a28)");return I&&console.log("arg and internal state validated...calling impl func"),await this.putIbGibsImpl(e)}catch(i){let n=m(i);console.error(`${a} error: ${n}`),t.errors=r.concat([n]),t.success=!1}return await this.resulty({resultData:t})}async putIbGibsImpl(e){let a=`${this.lc}[${this.putIbGibsImpl.name}]`,t={optsAddr:y({ibGib:e})},r=[],o=[],i=[];try{if(!e.data)throw new Error("arg.data is falsy (E: aae5757c158d4a799deb7fca9d6245f0)");let{isDna:s,force:l}=e.data,d=e.ibGibs||[],f=[];for(let h=0;h<d.length;h++){let u=d[h],g=y({ibGib:u});I&&console.log(`${a} checking to see if already exists...`);let E=await this.getFile({addr:g,isDna:s});if(E?.success&&E.ibGib)if(I&&console.log(`${a} already exists...`),l){I&&console.log(`${a} Forcing save of already put addr: ${g} (I: 325f363e5d438b43c24b810c150e4e22)`);let w=await this.putFile({ibGib:u,isDna:s});w.success?s||await this.putInCache({addr:g,ibGib:u}):(r.push(w.errorMsg||`${a} error putting ${g}`),i.push(g))}else I&&o.push(`${a} skipping (non-force) of already exists addr: ${g} (W: b7fbe22473014dd090db88aee631fecb)`),f.push(g);else{I&&console.log(`${a} does NOT already exist...`);let w=await this.putFile({ibGib:u,isDna:s});w.success?s||await this.putInCache({addr:g,ibGib:u}):(r.push(w.errorMsg||`${a} error putting ${g}`),i.push(g))}}f.length>0&&(t.addrsAlreadyHave=f),o.length>0&&(t.warnings=o),r.length===0?t.success=!0:(t.errors=r,t.addrsErrored=i)}catch(s){let l=m(s);console.error(`${a} error: ${l}`),t.errors=r.concat([l]),t.addrsErrored=i,t.success=!1}return await this.resulty({resultData:t})}async deleteImpl(e){let a=`${this.lc}[${this.deleteImpl.name}]`,t={optsAddr:y({ibGib:e})},r=[],o=[],i=[],n=[];try{if(!e.data)throw new Error("arg.data is falsy");let{isDna:l}=e.data,d=e.data.ibGibAddrs||[];for(let f=0;f<d.length;f++){let h=d[f];await this.deleteFromCache({addr:h});let u=await this.deleteFile({addr:h,isDna:l});u?.success?i.push(h):(r.push(u.errorMsg||`delete failed: addr (${h})`),n.push(h))}if(o.length>0&&(t.warnings=o),r.length===0)t.success=!0,t.addrs=i;else if(t.errors=r,t.addrsErrored=n,i.length>0){let f=`some addrs (${i.length}) were indeed deleted, but not all. See result addrs and addrsErrored.`;t.warnings=(t.warnings||[]).concat([f])}}catch(l){let d=m(l);console.error(`${a} error: ${d}`),t.errors=r.concat([d]),t.addrsErrored=n,t.success=!1}return await this.resulty({resultData:t})}async getAddrsImpl(e){let a=`${this.lc}[${this.getAddrsImpl.name}]`;throw new Error(`${a} not implemented. (E: 74dd50ce4b564559bc44d6c08d446cb3)`)}async canGetImpl(e){let a=`${this.lc}[${this.canGetImpl.name}]`,t={optsAddr:y({ibGib:e})};try{throw new Error("not implemented (E: 2a45977c584c6bbbc4f164c16106bd22)")}catch(o){let i=m(o);console.error(`${a} error: ${i}`),t.errors=[i]}return await this.resulty({resultData:t})}async canPutImpl(e){let a=`${this.lc}[${this.canPutImpl.name}]`,t={optsAddr:y({ibGib:e})};try{throw new Error("not implemented (E: 25a005d496efc69faefdec155ffb4a22)")}catch(o){let i=m(o);console.error(`${a} error: ${i}`),t.errors=[i]}return await this.resulty({resultData:t})}async canDeleteImpl(e){let a=`${this.lc}[${this.canDeleteImpl.name}]`;throw new Error(`${a} not implemented (E: a3306138b4ac429ba5f8f293ad7dd07b)`)}async getLatestAddrsImpl(e){let a=`${this.lc}[${this.getLatestAddrsImpl.name}]`,t={optsAddr:y({ibGib:e})};try{if(I&&console.log(`${a} starting...`),!e.data)throw new Error("arg.data required (E: cd92cb965d711c8014455c69e898ac23)");if(!e.data.ibGibAddrs)throw new Error("arg.data.ibGibAddrs required (E: 2d0824f9b8aec916a751ef17e2d4a823)");if(e.data.ibGibAddrs.length===0)throw new Error("arg.data.ibGibAddrs required to be non-zero (E: 2d0824f9b8aec916a751ef17e2d4a823)");let r=new Set,o=new Set,i=new Set;t.latestAddrsMap={};for(let n=0;n<e.data.ibGibAddrs.length;n++){let s=e.data.ibGibAddrs[n],l=await this.getFile({addr:s});if(l?.success&&l.ibGib){let d=l.ibGib,f=await this.getLatestAddrImpl({ibGib:d});f?(r.add(f),t.latestAddrsMap[s]=f):(console.warn(`expecting latestAddr to either be assigned or throw. Adding addr (${s}) to addrsErrored. (W: 35c3712b1a1e579ccf28c389eb2ecc22)`),i.add(s))}else if(l?.success)o.add(s),t.latestAddrsMap[s]=null;else if(l.errorMsg)i.add(s);else throw new Error(`unknown (invalid) getResult: ${$(l)} (E: 2674ad5d30294be29a3d3fdcf54ef6d9)`)}t.addrs=r.size>0?[...r]:void 0,t.addrsErrored=i.size>0?[...i]:void 0,t.addrsNotFound=o.size>0?[...o]:void 0,t.success=!0}catch(r){let o=m(r);console.error(`${a} error: ${o}`),t.errors=[o]}try{return await this.resulty({resultData:t})}catch(r){throw console.error(`${a}[resulty] ${m(r)}`),r}}async getLatestAddrImpl({ibGib:e,ibGibAddr:a}){let t=`${this.lc}[${this.getLatestAddrImpl.name}]`;I&&console.log(`${t} starting...`);try{if(!e&&!a)throw new Error("either ibGib or ibGibAddr required (E: 1f8f0cb61d1b4c708b06762048735c22)");if(e&&a&&y({ibGib:e})!==a)throw new Error("(UNEXPECTED) both ibGib and ibGibAddr provided but they don't match? (E: 01d1938252ef49b53d41d58abfaac523)");a||=y({ibGib:e});let{ib:r,gib:o}=C({ibGibAddr:a});if(!o)throw new Error("(UNEXPECTED) gib falsy? (E: d2506b99162e27348310f8e7e68e4523)");if(J({gib:o}))return console.warn(`${t} incoming ibGibAddr is primitive. Why are we calling getLatest on a primitive? returning incoming addr. (W: 57fcf479d5cc48d393841ec3d53587fa)`),a;if(["fork","mut8","rel8"].includes(r))return I&&console.log(`${t} probably is dna (ib === fork/mut8/rel8). returning incoming ibGibAddr early. (I: 2081628936de6a36bbb51224f0223523)`),a;let n=H({ibGibAddr:a}),{tjpGib:s}=n;s||=o;let l=await this.getMetaStoneAddrs({tjpGib:s,ibGibAddr:a});if(l.length===0)return I&&console.warn(`${t} no metastones found for given ibGibAddr (${a}). returning incoming ibGibAddr (W: a6a35cbbf40745e8a3e202226bb457ff)`),a;let f=l.map(_=>[_,C({ibGibAddr:_}).ib]).map(([_,B])=>[_,lt({ib:B})]).sort((_,B)=>{let[S,R]=_,[qi,at]=B;return R.n>at.n?-1:R.n<at.n?1:R.timestampInTicks>at.timestampInTicks?-1:R.timestampInTicks<at.timestampInTicks?1:0});if(I&&(console.log(`${t} console.dir(metaStoneAddrsAndIbInfos_descending)... (I: 1bb5e7d994248e8b6559ca2863c72123)`),console.dir(f)),f.length===0)throw new Error("(UNEXPECTED) metaStoneAddrsAndIbInfos_descending is empty? earlier in the function there should have been a check. did getMetaStoneAddrs return a populated list but no stones were found? (E: 63c035ebed77741f2330c7a625823f23)");let[h,u]=f[0];I&&console.log(`${t} [latestMetaStoneAddr, latestMetaStoneInfo]: ${[h,u]} (I: 1307ca46b4abd62c7a30fe87c08fa923)`);let g,E=await this.getFile({addr:h,isDna:!1});if(E?.success&&E.ibGib){g=E.ibGib;let _=await lr({ibGib:g})??[];if(_.length>0)throw new Error(`invalid metastone (${h}) for tjpGib (${s}). errors: ${_.join("|")} (E: 7fa7c6fa696d860cc7a9148861f96123)`)}else throw new Error(`(UNEXPECTED) we just found a metastone addr (${h}) that was read from the directory's contents, but we can't get the file? (E: 3b934b4adcd9d0efee7820f8d4012e23)`);let A=g.rel8ns[sr].at(0);if(!A)throw new Error("metastone passed validation but latestMetaStoneRel8ns[META_STONE_TARGET_REL8N_NAME].at(0) is empty? (E: c188ec0089ad86efe4d925c118599d23)");return A}catch(r){throw console.error(`${t} ${m(r)}`),r}finally{I&&console.log(`${t} complete.`)}}async persistOptsAndResultIbGibs({arg:e,result:a}){let t=`${this.lc}[${this.persistOptsAndResultIbGibs.name}]`;(I||this.data?.trace)&&console.log(`${t} doing arg?.data?.cmd: ${e?.data?.cmd}, result?.data?.success: ${a?.data?.success}`);let r=[e,a??Ee],o=await Te({argData:{cmd:"put",catchAllErrors:!0,ibGibAddrs:r.map(n=>y({ibGib:n}))}});o.ibGibs=r;let i=await this.putIbGibsImpl(o);if(!i?.data)throw new Error("resPut.data falsy (E: f3115254240b8eff6cd82878a4a35a23)");(!i.data.success||i.data.errors)&&console.error(`${t} Errors persisting arg & result: ${(i.data?.errors??["unknown errs"]).join(`
|
|
29
|
+
`)}. (E: 65ef314a4f8e445d851dab5b290e9a03)`)}async ensurePermissions(){let e=`${this.lc}[${this.ensurePermissions.name}]`,a="ibgib_permissionRequested_ensurePermissions";try{return!0}catch(t){return console.error(`${e} Dont have permissions... error: ${m(t)}`),!1}}async ensureAllDirsExist(){let e=`${this.lc}[${this.ensureAllDirsExist.name}]`;console.warn(`${e} not implemented in base class (W: c1b63ec036134db5960e0d3ea169d15b)`)}getTjpSubpath({viaTargetAddr:e,viaTargetTjpGib:a,viaMetaStoneAddr:t,pathSeparator:r=xt}){let o=`${this.lc}[${this.getTjpSubpath.name}]`;try{if(I&&console.log(`${o} starting... (I: c65dabcf47acf6d6881087b404861e23)`),!e&&!a&&!t)throw new Error("either viaTargetAddr/TargetTjpGib/metaStoneAddr required (E: a784c4f0369e6e38eafcdf3289c38523)");if(!this.data)throw new Error("(UNEXPECTED) this.data falsy? (E: 441ff1b038366a1c07a94cf128454923)");if(r||(console.warn(`${o} pathSeparator falsy? using default: "${xt}" (W: 295d21ab226743dd83a721f78870ab6e)`),r=xt),a||(t?a=lt({ib:C({ibGibAddr:t}).ib}).tjpGib:a=H({ibGibAddr:e}).tjpGib),!a)throw new Error("targetTjpGib could not be gotten. are you sure this has a tjp? or is the ibGib a stone? (E: e507f1996aaa68a229a3158b3dbc5723)");let{baseSubPath:i,spaceSubPath:n,ibgibsSubPath:s}=this.data;return`${i}${r}${n}${r}${s}${r}${a}`}catch(i){throw console.error(`${o} ${m(i)}`),i}finally{I&&console.log(`${o} complete.`)}}async buildPath({addr:e,isDna:a,isBin:t,ensureMetaStonePaths:r,pathSeparator:o="/",pretendItsALongPath:i=!1,addrIsForAMetaStone:n}){let s=`${this.lc}[${this.buildPath.name}]`;try{I&&console.log(`${s} starting... (I: d630823bbe0e1a1aa3592103768e8423)`);let l=this.data;if(!l)throw new Error("this.data required (E: d2553d11b637577aa7b074387b613f23)");if(!e)throw new Error("addr required (E: 68149eccdbe2e6ef95eb50d588d68423)");let d;o||="/";let{ib:f,gib:h}=C({ibGibAddr:e});if(!h)throw new Error("gib required in building paths. if it's a primitive ibgib, then it shouldn't be put into/gotten from a space (E: 8a34bc925496c35d1892638623ec0a23)");d=`${l.baseSubPath}${o}${l.spaceSubPath}${o}`,I&&console.log(`${s} resPath as of space subpath: ${d} (I: 5feccfadec1d8ac856243e78377c1e23)`);let u=Fe({addr:e});u&&(n=!0);let g=h.split(ye);if(g.length===1)if(a?(d+=`${l.dnaSubPath}${o}`,I&&console.log(`${s} resPath dna appended subpath: ${d} (I: eecd26dfc1699110ae5b91dd68438f23)`)):t&&(d+=`${l.binSubPath}${o}`,I&&console.log(`${s} resPath bin appended subpath: ${d} (I: b53248d5b8d142108cf5a363f148980b)`)),n||u){let S;u?S=lt({ib:f}).tjpGib:S=H({ibGibAddr:e}).tjpGib??C({ibGibAddr:e}).gib,d+=`${S}${o}`}else d+=`${h}${o}`;else if(g.length===2){let{tjpGib:S,punctiliarHash:R}=H({gib:h,gibDelimiter:ye});d+=`${S}${o}${R}${o}`}else throw new Error(`invalid gib atow (11/2023). expected only one gib delimiter (${ye}) that splits two pieces of the gib, but we have ${g.length} many pieces. gib: ${h} (E: 7d5f8608d79854e6d1d2878975258423)`);let E=!!l.mitigateLongPaths,w=l.longPathLength,A;if(de({addr:e})){let{binExt:S}=ea({addr:e});A=S.concat()}else A="json";let _=`${f}.${A}`,B=`${e}.${A}`;if(E&&w){let S=" you have to place the root folder higher up in the OS's filesystem. (and you should put in a change request to the OS to fix their weak sauce/move to/fund a better OS.) Will try what we have and hope+pray.";if(d.length>=w)throw new Error(`path is already too long without even having a filename. ${S} (E: c126522a5cda4c2acb6de3a92fc2c423)`);if(d.length+f.length>=w||i)if(I&&console.warn(`${s} the path is too long when adding the full ib as the filename (even without the ext). (W: 3011a1e58641c53274d4776f58bb5323)`),n)u&&console.error(`can't even get a metastone ib in the path. ${S} (E: 962c52deb7a5b57842c97676a1192623)`),d+=B;else{I&&console.log(`${s} non metastone ib found (not logging ib here for privacy). will try to shorten... (I: 73dcb3f019c9b48b92fe67a9c4f2f123)`);let R=await this.buildPath_getShorterFilenameExtSubpath_ibTooLong_nonMetaStone({ib:f,ext:A,pathSeparator:o});d+=R,d.length>=w&&console.error(`${s} shortened filenamePlusExt and the path is still too long. i give up. ${S} (E: df9e52098b94a99212c15c167e4d9f23)`)}else n?d+=B:d+=_}else n?d+=B:d+=_;return I&&console.log(`${s} returning resPath: ${d} (I: 62a76a630335a872a4fc5f25dec4b623)`),d}catch(l){throw console.error(`${s} ${m(l)}`),l}finally{I&&console.log(`${s} complete.`)}}async buildPath_getShorterFilenameExtSubpath_ibTooLong_nonMetaStone({ib:e,ext:a,pathSeparator:t}){let r=`${this.lc}[${this.buildPath_getShorterFilenameExtSubpath_ibTooLong_nonMetaStone.name}]`;try{I&&console.log(`${r} starting... (I: 1f14c5de4174d726182c5dc97bd62a23)`);let o="",i=this.data.longSubPath||we;i.length!==1&&(console.warn(`${r} longSubPath (this.data.longSubPath || IBGIB_LONG_SUBPATH) longer than one char. should be 1 char. substringing to the first char. (W: 8c19a983730f4b62ac4208f7d21c90fc)`),i=i.substring(0,1)||"l"),o+=`${i}${t}`;let s=(await Bt({s:e})).substring(0,4);o+=`${s}${t}`;let l=e.substring(0,ro);return o+=`${l}.${a}`,o}catch(o){throw console.error(`${r} ${m(o)}`),o}finally{I&&console.log(`${r} complete.`)}}};var ha={version:"1",uuid:it,name:$e,classname:"WebFilesystemSpace_V1",baseDir:fe(),encoding:Q,baseSubPath:me,spaceSubPath:ge,ibgibsSubPath:K,metaSubPath:Z,binSubPath:ee,dnaSubPath:te,longSubPath:we,mitigateLongPaths:!1,longPathLength:9999999999999,persistOptsAndResultIbGibs:!1,validateIbGibAddrsMatchIbGibs:!1,longPollingIntervalMs:Ie,allowPrimitiveArgs:!1,catchAllErrors:!0,description:Ct,trace:!1},ae={ascii:"ascii",utf8:"utf8",utf_8:"utf-8","utf-8":"utf-8",utf16le:"utf16le",ucs2:"ucs2",ucs_2:"ucs-2","ucs-2":"ucs-2",base64:"base64",base64url:"base64url",latin1:"latin1",binary:"binary",hex:"hex"},io=Object.values(ae),no=[ae.utf8,ae.utf16le,ae.base64,ae.binary,void 0];var L=T,so=new mt;async function pa({path:c,directory:e,encoding:a}){let t=`[${pa.name}]`;try{L&&(console.log(`${t} starting...`),(c.includes("bootstrap^gib")||c.includes("gib/bootstrap.json"))&&console.log(`${t} trying bootstrap^gib... (I: cde10726c55737e5c5a2e0a66a188e24)`));let r=so.join(e,c);L&&console.log(`${t} fullPath: ${r} (I: e5cfdd62247c6ba05dffb64d8f25d424)`),a||="utf8";let o,i=await ma(r,{encoding:a});return i instanceof Uint8Array?o=aa(i):typeof i=="string"&&(o=i),L&&(console.log(`${t} record found. data length: ${o?.length??0}. fullPath: ${r}. console.dir(resRead)... (I: be5cfbf04874b4e8e4787ad966cb8424)`),console.dir(o)),o??null}catch(r){return L&&console.log(`${t} fullPath not found from directory (${e}) and path (${c})
|
|
30
|
+
error:
|
|
31
|
+
${m(r)} (I: 8f93e583c048fac0682f55ca74df0324)`),null}finally{L&&console.log(`${t} complete. (I: 22a6958aee350e4d99b76057ec8b9224)`)}}b(pa,"tryRead");async function ua({path:c,directory:e,encoding:a}){let t=`[${ua.name}]`;try{L&&(console.log(`${t} starting...`),c.includes("bootstrap^gib")&&console.log(`${t} trying bootstrap^gib... (I: acdb59d399ca16c45456392d935c0524)`));let r=so.join(e,c);L&&console.log(`${t} fullPath: ${r} (I: abef0200a4b823b446713349ca102924)`),a||="utf8";let o,i=kt([a,...io]),{dataBuffer:n,dataString:s,inputPath:l,detectedEncoding:d}=await co({inputPath:c,encodingsToTry:i});if(!n)throw new Error("getFileDataAndEncoding yielded falsy dataBuffer (E: f748ffc8c71c92be06a3566102ba8e24)");return o=n,L&&(console.log(`${t} record found. data length: ${o?.length??0}. fullPath: ${r}. console.dir(resRead)... (I: b0c1da7e3849edd3edef899d74b21a24)`),console.dir(o)),{dataBuffer:n,dataString:s,inputPath:l,detectedEncoding:d}}catch(r){return L&&console.log(`${t} fullPath not found from directory (${e}) and path (${c})
|
|
32
|
+
error:
|
|
33
|
+
${m(r)} (I: 04b11599387ab37adf2b18a5f767cd24)`),null}finally{L&&console.log(`${t} complete. (I: baa1e9d18134bc451b56bb5a56150824)`)}}b(ua,"tryRead_bin");async function co({inputPath:c,encodingsToTry:e=no}){let a=`[${co.name}]`;try{L&&console.log(`${a} starting... (I: be8a697780bd9f2dcc4e55ed557d3b24)`),e&&console.warn(`${a} encodingsToTry (${$(e)}) is ignored in this web version of this function. (W: 1dda04d8e0b7fb046cff5d89d3903924)`);let t=await ma(c);if(t instanceof Uint8Array){if(t.length===0)return console.warn(`${a} file at inputPath (${c}) has dataBuffer.length === 0, i.e., no data content. we are treating this as utf8. (W: 8159ac120ec276df17484c1d32870424)`),{inputPath:c,dataBuffer:t,detectedEncoding:ae.utf8,dataString:""};{let r=aa(t);return{inputPath:c,dataString:r,detectedEncoding:ae.utf8,dataBuffer:t}}}else{if(typeof t=="string")return{inputPath:c,dataString:t,detectedEncoding:ae.utf8,dataBuffer:void 0};if(t)throw new Error("(UNEXPECTED) resRead not Uint8Array, not string, not falsy? (E: bdeceb4c354da36708e31406adb30124)");return{inputPath:c,dataString:void 0,detectedEncoding:void 0,dataBuffer:void 0}}}catch(t){let r=m(t);throw r.startsWith("ENOENT:")||console.error(`${a} ${r}`),t}finally{L&&console.log(`${a} complete.`)}}b(co,"getFileDataAndEncoding");function Ze(c){let e=`[${Ze.name}]`;try{L&&console.log(`${e} starting... (I: c911bff0cb7333dfd45bde6925cce524)`);let a=c.split("/");if(a.length<3)throw new Error(`fullPath (${c}) must have at least 3 pieces (E: d99c38d035551af3e85b7f767d911324)`);let t=a.shift();t==="."&&(t=fe());let r=a.shift(),o=a.join("/");return{dbName:t,storeName:r,key:o}}catch(a){throw console.error(`${e} ${m(a)}`),a}finally{L&&console.log(`${e} complete.`)}}b(Ze,"parseFullPath");async function Dt(c,e,a){let t=`[${Dt.name}]`;try{L&&console.log(`${t} starting... (I: 18c4f3558ab1f150382948556ab5f924)`);let{dbName:r,storeName:o,key:i}=Ze(c);if(typeof e=="string"||e instanceof Uint8Array)await Cr({dbName:r,storeName:o,key:i,value:e});else throw new Error("(UNEXPECTED) data not string or Uint8Array? (E: ac3e1c15484dbc7188c75e62ab78b124)")}catch(r){throw console.error(`${t} ${m(r)}`),r}finally{L&&console.log(`${t} complete.`)}}b(Dt,"writeFile");async function ma(c,e){let a=`[${ma.name}]`;try{L&&console.log(`${a} starting... (I: 37fd6ea3d79fc1ab797049ef00f6e224)`);let{dbName:t,storeName:r,key:o}=Ze(c);return await gt({dbName:t,storeName:r,key:o})}catch(t){throw console.error(`${a} ${m(t)}`),t}finally{L&&console.log(`${a} complete.`)}}b(ma,"readFile");async function ga(c,e){let a=`[${ga.name}]`;L&&(console.log(c),console.log(JSON.stringify(e)));let{dbName:t,storeName:r,key:o}=Ze(c);await xr({dbName:t,storeName:r,pathToRm:o})}b(ga,"rm");async function wa(c,e){let a=`[${wa.name}]`,{dbName:t,storeName:r,key:o}=Ze(c);return await Lr({dbName:t,storeName:r,dirPath:o,withFileTypes:e?.withFileTypes??!1})}b(wa,"readdir");var G=T,xe=new mt,oe=class c extends Ke{static{b(this,"WebFilesystemSpace_V1")}lc=`[${c.name}]`;constructor(e,a){super(e??O(ha),a);let t=`${this.lc}[ctor]`}static async createFromDto(e){let a=`[${Ke.name}][${this.createFromDto.name}]`;G&&console.log(`${a}`);let t=new c;return await t.initialized,await t.loadIbGibDto(e),t}async validateWitnessArg(e){let a=`${this.lc}[${this.validateWitnessArg.name}]`,t=[];try{t=await super.validateWitnessArg(e)||[],e.data?.cmd==="put"&&(e.ibGibs||[]).length===0&&t.push('when "put" cmd is called, ibGibs required.'),e.data?.cmd==="get"&&(e.data?.ibGibAddrs||[]).length===0&&t.push('when "get" cmd is called, ibGibAddrs required.')}catch(r){throw console.error(`${a} ${m(r)}`),r}finally{t?.length>0&&console.error(`${a} errors: ${t}`)}return t}async initialize(){let e=`${this.lc}[${this.initialize.name}]`;try{if(G&&console.log(`${e} starting...`),this.data||(this.data=O(ha),this.data=this.data),this.data.classname!==c.name&&(this.data.classname&&console.warn(`${e} this.data.classname (${this.data.classname}) !== ${c.name}. overriding this. (W: 400ef8f8626132bf763b5c68bc1d3424)`),this.data.classname=c.name),this.data.encoding||(this.data.encoding=Q),this.data.baseDir||(this.data.baseDir=ue),!this.data.uuid)throw new Error("this.data.uuid is falsy. right now i'm assuming data.uuid is truthy. this is what i'm using atow (12/2024) as the indexeddb db.store to be the uuid via the baseSubPath (E: cd3475cc43d1384dccf0b20dd322b124)");this.data.baseSubPath=this.data.uuid,this.data.spaceSubPath||(this.data.spaceSubPath=ge),this.data.ibgibsSubPath||(this.data.ibgibsSubPath=K),this.data.metaSubPath||(this.data.metaSubPath=Z),this.data.binSubPath||(this.data.binSubPath=ee),this.data.dnaSubPath||(this.data.dnaSubPath=te),this.data.longSubPath===void 0&&(this.data.longSubPath=we),this.data.longPathLength===void 0&&(this.data.longPathLength=9999999999999),this.data.mitigateLongPaths===void 0&&(this.data.mitigateLongPaths=!1),this.ib=pt({space:this,classname:this.data.classname}),this.gib=await q({ibGib:this})}catch(a){console.error(`${e} ${m(a)}`)}finally{G&&console.log(`${e} complete.`)}}async putFile({ibGib:e,isDna:a}){let t=`${this.lc}[${this.putFile.name}]`,r={};try{if(!e)throw new Error("ibGib required. (E: bb41678a0e46f60782db4641e7355a24)");let o=this.data,i="",n="",s=y({ibGib:e}),l=de({addr:s});i=await this.buildPath({addr:s,isDna:a??!1,isBin:l,ensureMetaStonePaths:!0});let d=xe.join(o.baseDir,i);G&&console.log(`${t} fullPath: ${d} (I: accfac2f2ee924da0184e241c2408624)`),G&&console.log(`${t} path: ${i}, directory: ${o.baseDir}, thisData.encoding: ${o.encoding} (I: 498dd4e293f7da0eef4b3dea2ee32524)`);let f;if(l){if(n=e.data,!n)throw new Error("(UNEXPECTED) binIbGib.data falsy? I'm trying to have data always populated for bin ibgibs even if it is an empty Uint8Array. (E: 861489baffc294baf7b463333f389824)");await Dt(d,n)}else{let h=ut({ibGib:e});n=JSON.stringify(h),f=o.encoding||"utf8",await Dt(d,n,f)}r.success=!0}catch(o){let i=`${t} ${m(o)}`;console.error(i),r.errorMsg=i}return r}async deleteFile({addr:e,isDna:a}){let t=`${this.lc}[${this.deleteFile.name}]`,r={};try{if(!e)throw new Error("addr required. (E: a2ca4b3ae9bb79891fd86c98af3de624)");if(!this.data)throw new Error("this.data required (E: 6b6163a397c42adf5b03ca5117c0d624)");let o=this.data,i="";de({addr:e})?i=await this.buildPath({addr:e,isDna:!1,isBin:!0,ensureMetaStonePaths:!1}):i=await this.buildPath({addr:e,isDna:a??!1,ensureMetaStonePaths:!0}),G&&console.log(`${t} path: ${i}, directory: ${o.baseDir}`);let n=xe.join(this.data.baseDir,i);await ga(n,{force:!0}),G&&console.log(`${t} deleted. path: ${i}`),r.success=!0}catch(o){let i=`${t} ${m(o)}`;i.includes("File does not exist")?G&&console.log(`${t} attempted to delete non-existent file. ${i} (I: 839257fb70d62a3273335d8536b15724)`):console.error(i),r.errorMsg=i}return r}async getFile({addr:e,isDna:a}){let t=`${this.lc}[${this.getFile.name}(${e})]`,r={};try{if(G&&console.log(`${t} starting... (I: 07e34fff2d9c7108dd79e5d6f93ed724)`),!e)throw new Error("addr required");let o=this.data,{ib:i}=C({ibGibAddr:e}),n=de({addr:e}),l=["fork","mut8","rel8","plan"].some(f=>f===i||f.startsWith(i+" ")),d=[];if(a||l?d.push(await this.buildPath({addr:e,isDna:!0,ensureMetaStonePaths:!1})):n&&d.push(await this.buildPath({addr:e,isDna:!1,isBin:!0,ensureMetaStonePaths:!1})),d.push(await this.buildPath({addr:e,isDna:!1,ensureMetaStonePaths:!1})),Fe({addr:e})||d.push(await this.buildPath({addr:e,isDna:!1,ensureMetaStonePaths:!1,pretendItsALongPath:!0})),n){let f=null,{binEncoding:h,binHash:u}=Ar({addr:e});if(u==="0"){let{ib:g,gib:E}=C({ibGibAddr:e});r.ibGib={ib:g,gib:E,data:new Uint8Array(0)}}else{for(let g of d){let E=await ua({path:g,directory:o.baseDir,encoding:h??o.encoding});if(E){f=E;break}}if(f){let{ib:g,gib:E}=C({ibGibAddr:e}),w={ib:g,gib:E,data:f.dataBuffer};r.ibGib=w}else G&&console.log(`${t} paths not found: ${JSON.stringify(d)} (I: 9116435fa6198d1e2e40ed4467e72924)`)}}else{let f=null;for(let h of d){let u=await pa({path:h,directory:o.baseDir,encoding:o.encoding});if(u){f=u;break}}f?r.ibGib=JSON.parse(f):G&&console.log(`${t} paths not found: ${JSON.stringify(d)} (I: 52287b4a0fb3e3fa5f893fa92bc15324)`)}r.success=!0}catch(o){let i=`${t} ${m(o)}`;console.error(i),r.errorMsg=i}finally{G&&console.log(`${t} complete. (I: d648c9b72261e509dac1e36279f8eb24)`)}return r}async ensurePermissions(){let e=`${this.lc}[${this.ensurePermissions.name}]`;return G&&console.log(`${e} always returns true in base class (I: eaa254b35aadb047b2c4af58f9ec6f24)`),!0}async ensureAllDirsExist(){let e=`${this.lc}[${this.ensureAllDirsExist.name}]`;try{console.warn(`${e} does nothing in web filesystem space. do I need to do anything in this concrete class? (W: 6f71512c4b32df68e483cf54e17e3124)`)}catch(a){throw console.error(`${e} ${m(a)}`),a}finally{G&&console.log(`${e} complete.`)}}async ensureDirsImpl(e){let a=`${this.lc}[${this.ensureDirsImpl.name}]`;try{console.warn(`${a} not implemented in this web-based class. do i need this? (W: 0c50f3eb750f11108e7cd2a1263d8124)`)}catch(t){throw console.error(`${a} ${m(t)}`),t}finally{G&&console.log(`${a} complete.`)}}async getMetaStoneAddrs({ibGibAddr:e,tjpGib:a,fnFilterIb:t}){let r=`${this.lc}[${this.getMetaStoneAddrs.name}]`;try{G&&console.log(`${r} starting... (I: f9da77d2c1920dc33efabee27847d624)`);let o=await this.buildPath({addr:e,ensureMetaStonePaths:!1,isDna:!1,addrIsForAMetaStone:!0}),i=xe.join(this.data.baseDir,o);G&&console.log(`${r} fullPath: ${i} (I: 7d69faa728f178ef5261291b4a44a424)`);let s=H({ibGibAddr:e}).tjpGib?xe.dirname(xe.join(i,"..")):xe.dirname(i);G&&console.log(`${r} containingDir: ${s} (I: 867174fbd4b3640d023dce741208b624)`);let l=t?g=>g.startsWith(Jt)&&t(g):g=>g.startsWith(Jt),d=[];try{G&&console.log(`${r} calling readdir(containingDir) (I: 9adcee17e5b5121a36f3d6e29d3fb224)`),d=await wa(s,{recursive:!1,withFileTypes:!1})}catch(g){m(g).includes("ENOENT")?G&&console.log(`${r} readdir errors: ${m(g)} (I: 95d041a148844dd09700875a1a82c424)`):console.warn(`${r} readdir error did not contain ENOENT...not sure what this is...maybe a different OS no dir exists emsg? Treating this as if dir does not exist. (W: 4fee7ed52dc4c987559eead57c89f724)`),d=[]}if(d.length===0)return G&&console.log(`${r} filenames: [empty]. no metastones found. (I: b42abb33f7636b49c195b36fca6dce24)`),[];G&&console.log(`${r} filenames: ${d} (I: 18e77f7451ce57bbbccddf9bef768624)`);let f=".json",h=5,u=d.filter(g=>{let[E,w]=g.split(zt);return!!w?.endsWith(f)&&l(E)}).map(g=>g.substring(0,g.length-h)).filter(g=>Fe({addr:g})&&g.includes(a));G&&console.log(`${r} filtered/mapped filenames -> metaStoneAddrs: ${u} (I: d0396296e7de1167d226f3c84a283424)`);for(let g=0;g<u.length;g++){let E=u[g],w=ot({addr:E});if((w??[]).length>0)throw new Error(`(UNEXPECTED) invalid metastone found? metaStoneAddr (${E}) had basic validation errors: ${w.join("|")} (E: c41e8797d56833c55e32d5b4c8f79524)`);let{ib:A}=C({ibGibAddr:E}),_=cr({ib:A});if(_.length>0)throw new Error(`(UNEXPECTED) metaStoneIb had validation errors? metaStoneErrors: ${_.join("|")} (E: 28ab913c2d7376843e7d94584fc94324)`)}return G&&console.log(`${r} returning metaStoneAddrs: ${u} (I: 491d7c31691e4938eb9d087f5854fa24)`),u}catch(o){throw console.error(`${r} ${m(o)}`),o}finally{G&&console.log(`${r} complete.`)}}};var lo=b(async({allowCancel:c,spaceName:e,logalot:a})=>{let t="[fnCreateNewLocalSpace]";try{if(a&&console.log(`${t} starting... (I: b05e12810c1d32269b0fa7e965ccfd24)`),e&&!Zt(e))throw new Error(`spaceName (${e}) is invalid. (E: c54aa952ee34102befe5f47681cdf624)`);if(!e&&(await b(async()=>{let d=await fa()({title:"greetings program",msg:`this website does not use cookies. it's driven by ibgib's innovative protocol, and all of YOUR data is stored in a "local space" on YOUR device. in browsers, this means in IndexedDB.
|
|
34
|
+
|
|
35
|
+
so give your local space a name like 'phone_alice' or 'web_bob_foo', or leave blank to get a random name. then click ok.
|
|
36
|
+
`});d===""&&!c?e="space_"+(await M()).slice(0,10):d&&Zt(d)&&(e=d)},"promptName")(),!e))return;let r=new Date,o=re(r),i=r.getMilliseconds(),n=new oe({version:"1",uuid:await M(),isTjp:!0,timestamp:o,timestampMs:i,name:e,baseDir:ue,spaceSubPath:e,baseSubPath:me,binSubPath:ee,dnaSubPath:te,ibgibsSubPath:K,metaSubPath:Z,encoding:Q,persistOptsAndResultIbGibs:Xa,validateIbGibAddrsMatchIbGibs:!0,trace:!1,description:Wa,allowPrimitiveArgs:!1,catchAllErrors:!0,longPollingIntervalMs:Ie},void 0);if(a&&console.log(`${t} localSpace.ib: ${n.ib} (I: f57802654c5be84eb96d36d477425924)`),a&&console.log(`${t} localSpace.gib: ${n.gib} (before sha256v1) (I: 4171271b7c1484e90205824a31067924)`),a&&console.log(`${t} localSpace.data: ${$(n.data||"falsy")} (I: 01221a1d7f6f19accf05b17534e3e624)`),a&&console.log(`${t} localSpace.rel8ns: ${$(n.rel8ns||"falsy")} (I: 750a7ec2b25b5d344dea900cf14ca524)`),n.gib=await q({ibGib:ut({ibGib:n}),hasTjp:!0}),n.gib===se)throw new Error("localSpace.gib not updated correctly. (E: 277f8305ec3fd8dd4b023616c1fa0624)");return a&&console.log(`${t} localSpace.gib: ${n.gib} (after sha256v1) (I: d3ab464fdb4500d95a50bf1e7c036524)`),n}catch(r){throw console.error(`${t} ${m(r)}`),r}finally{a&&console.log(`${t} complete.`)}},"fnCreateNewLocalSpace"),fo=b(c=>Promise.resolve(oe.createFromDto(c)),"fnDtoToSpace_webFilesystem");var D=T,Le=new Map,Ea="zero_space^gib",bo=new Set,Ot=class c extends Nt{static{b(this,"Metaspace_Webspace")}cacheSvc;lc=`[${c.name}]`;get zeroSpace(){let e=`[${this.lc}][get zeroSpace]`;if(Le.has(Ea))return Le.get(Ea);if(this.metaspaceFactory.fnZeroSpaceFactory){let a=this.metaspaceFactory.fnZeroSpaceFactory();return Le.set(Ea,a),a}else throw new Error(`${e} (UNEXPECTED) this.metaspaceFactory.fnZeroSpaceFactory falsy. not initialized? (E: 9e6c6954dacd868b18c9f34a71e63523)`)}constructor(e){super(e),this.cacheSvc=e;let a=`${this.lc}[ctor]`;D&&(console.log(`${a}${ta}`),console.timeLog(ta),console.log(`${a} created. (I: 5690dc2ebf774df3a442bd463dee7455)`))}async initializeMetaspaceFactory({metaspaceFactory:e}){let a=`[${this.initializeMetaspaceFactory.name}]`;try{D&&console.log(`${a} starting... (I: 5a29670439ac47634dcdfe25225c8223)`),await super.initializeMetaspaceFactory({metaspaceFactory:e}),e.fnDefaultLocalSpaceFactory??=async t=>{let r=await lo(t);if(!r)throw new Error("(UNEXPECTED) createdSpace undefined? (E: 21258175efdd1a9cb1f9fc8ab59e0324)");if(!r.data?.uuid)throw new Error("(UNEXPECTED) createdSpace.data.uuid undefined? (E: 0a6c44c078d9e21e92f703adbc995c24)");let o=r.data.uuid;await oa({dbName:fe(),storeName:o,logalot:D});let i=y({ibGib:r});return Le.set(i,r),r},e.fnDtoToSpace??=async t=>{let r=t.data?.uuid;if(!r)throw new Error("spaceDto.data?.uuid falsy? (E: b73bded9ebede92b8ef53b8d05dca225)");bo.has(r)||(await oa({dbName:fe(),storeName:r,logalot:D}),bo.add(r));let o=y({ibGib:t}),i=Le.get(o);if(i=void 0,!i){if(i=await fo(t),!i.data?.uuid)throw new Error("(UNEXPECTED) resCreateNewSpace.data.uuid undefined? (E: f1e0e75f02b607b349b4102a8c8f7724)");Le.set(o,i)}return i},this.metaspaceFactory.fnZeroSpaceFactory??=()=>{let t=new oe(void 0,void 0);return t.gib="gib",t}}catch(t){throw console.error(`${a} ${m(t)}`),t}finally{D&&console.log(`${a} complete.`)}}async initialize(e){let a=`${this.lc}[${this.initialize.name}]`;await this.initializeZeroSpace(),await super.initialize(e)}async initializeZeroSpace(){let e=`[${this.initializeZeroSpace.name}]`;try{D&&console.log(`${e} starting... (I: a3364e9601c70c8163e67868e5d67723)`),D&&console.log(`${e} we are assuming zero space storage is initialized in indexed db. atow (03/2025), this is done in initBlankGibStorage in index.mts (I: cb1dd69b21efc2fc366956349e865125)`)}catch(a){throw console.error(`${e} ${m(a)}`),a}finally{D&&console.log(`${e} complete.`)}}async getLocalUserSpace({lock:e,localSpaceId:a}){let t=`${this.lc}[${this.getLocalUserSpace.name}]`;try{D&&console.log(`${t} starting... (I: e68ae7f617e4a1af026ab1ac1c52f425)`);let r=await super.getLocalUserSpace({lock:e,localSpaceId:a});return r?((await X({ibGib:r})??[]).length>0&&console.error("(UNEXPECTED) local user space is invalid intrinsically? when did this happen? (E: df5c8e62c204a6972e364fa33d9b7725)"),r):(console.error("(UNEXPECTED) local user space falsy? NOTE: This error is just logged, not thrown as I don't know if this is always improper behavior. (E: 3c7cac40d11b26c3fd95183d06ffc225)"),r)}catch(r){throw console.error(`${t} ${m(r)}`),r}finally{D&&console.log(`${t} complete.`)}}async rel8ToCurrentRoot(e){let a=`${this.lc}[${this.rel8ToCurrentRoot.name}]`;try{D&&console.log(`${a} starting... (I: 0f999532d51b1ad2084ed30670297125)`);let t=e.space??await this.getLocalUserSpace({});if(!t)throw new Error("(UNEXPECTED) space falsy and couldn't get default local user space? (E: e8b63af1b0fb692c4761fe9627eaf525)");await je({fn:b(async()=>{let r=`${this.lc}[${this.rel8ToCurrentRoot.name}]`;try{return D&&console.log(`${r} starting... (I: 5444c70bd93b13b59ef9cd06ee72d825)`),super.rel8ToCurrentRoot(e)}catch(o){throw console.error(`${r} ${m(o)}`),o}finally{D&&console.log(`${r} complete.`)}},"fn"),scope:a,secondsValid:60,maxDelayMs:100,maxLockAttempts:600,space:t,callerInstanceId:this.instanceId})}catch(t){throw console.error(`${a} ${m(t)}`),t}finally{D&&console.log(`${a} complete.`)}}async rel8ToSpecialIbGib(e){let a=`${this.lc}[${this.rel8ToSpecialIbGib.name}]`;try{D&&console.log(`${a} starting... (I: 906d2e553f163405f3238f141ed6fb25)`);let t=e.space??await this.getLocalUserSpace({});if(!t)throw new Error("(UNEXPECTED) space falsy and couldn't get default local user space? (E: 3c587503d08aa8b8cda25bb7064bf125)");return await je({fn:b(async()=>{let o=`${this.lc}[${this.rel8ToCurrentRoot.name}]`;try{return D&&console.log(`${o} starting... (I: 3b9f44934d88196bc3d0087cadd23125)`),super.rel8ToSpecialIbGib(e)}catch(i){throw console.error(`${o} ${m(i)}`),i}finally{D&&console.log(`${o} complete.`)}},"fn"),scope:a,secondsValid:60,maxDelayMs:100,maxLockAttempts:600,space:t,callerInstanceId:this.instanceId})}catch(t){throw console.error(`${a} ${m(t)}`),t}finally{D&&console.log(`${a} complete.`)}}};async function ya(c){let e=`[${ya.name}]`,a=!0;try{a&&console.log(`${e} starting...`);let t=c.getGlobalThis(c.config);if(t.bootstrapStarted)if(t.bootstrapPromise)console.warn(`${e} already bootstrapping \u2014 awaiting that promise.`);else throw new Error("(UNEXPECTED) bootstrapStarted but bootstrapPromise is falsy?");else t.bootstrapStarted=!0,t.bootstrapPromise=new Promise(async(r,o)=>{try{let i=c.getOpeningArgs?await c.getOpeningArgs():["--interactive"],n=c.paramInfos??[{name:"interactive",isFlag:!0,argTypeName:"boolean"}],s=ti({paramInfos:n});if(s.length>0)throw new Error(`(UNEXPECTED) invalid PARAM_INFOS: ${s.join("|")}`);let l=At({args:i,paramInfos:n,logalot:a});if(c.validateArgInfos){let d=c.validateArgInfos({argInfos:l});if(d)throw new Error(`Arg validation errors: ${d}`)}await ho({opts:c,args:i,argInfos:l,logalot:a}),r()}catch(i){o(i)}});if(await t.bootstrapPromise,c.onReady){let r=b(()=>t.appInstance||null,"getApp");await c.onReady(r())}}catch(t){throw console.error(`${e} ${m(t)}`),t}finally{a&&console.log(`
|
|
37
|
+
${e} complete.`)}}b(ya,"bootstrapIbGibApp");async function ho({opts:c,args:e,argInfos:a,logalot:t}){let r=`[${ho.name}]`;try{t&&console.log(`${r} starting...`);let o=await po({opts:c,logalot:t}),i=Pr();i.metaspace=o;let n=c.getGlobalThis(c.config);n.metaspace=o,c.ensureTags&&await wo({metaspace:o,tags:c.ensureTags,logalot:t}),c.registerAgentFunctionInfos&&c.registerAgentFunctionInfos();let s=await ei({args:e,interpretedArgInfos:a});await o.persistTransformResult({resTransform:s}),n.initialCommentIbGib=s.newIbGib;let l=new kr;await l.initialized,l.setWrappedIbGib({ibGib:s.newIbGib}),n.initialCommentIbGibProxy=l,c.resolveIdentity&&(n.identity=await c.resolveIdentity(o)),await uo({opts:c,resRequestCommentIbGib:s,metaspace:o,logalot:t})}catch(o){throw console.error(`${r} ${m(o)}`),o}finally{t&&console.log(`
|
|
38
|
+
${r} complete.`)}}b(ho,"execFromArgs");async function po({opts:c,logalot:e}){let a=`[${po.name}]`;try{e&&console.log(`${a} starting...`);let t=new Ot(void 0),r=c.localSpaceNamePrefix?`${c.localSpaceNamePrefix}_local_space_name`:"local_space_name",o=await gt({dbName:c.config.dbName,storeName:c.config.storeName,key:r}),i=c.localSpaceNamePrefix??"app_space",n=o?void 0:await Zo(i);return await t.initialize({spaceName:n,metaspaceFactory:void 0,getFnAlert:b(()=>({title:s,msg:l})=>ra({title:s,msg:l}),"getFnAlert"),getFnPrompt:b(()=>({title:s,msg:l})=>Xe({title:s,msg:l,confirm:!1}),"getFnPrompt"),getFnPromptPassword:b(()=>()=>Nr({confirm:!0}),"getFnPromptPassword")}),t}catch(t){throw console.error(`${a} ${m(t)}`),t}finally{e&&console.log(`${a} complete.`)}}b(po,"initMetaspace");async function Zo(c){let e=c+"_"+jt({count:12});if(!Xt.test(e))throw new Error(`(UNEXPECTED) generated space name (${e}) failed regexp`);return e}b(Zo,"generateLocalSpaceName");async function uo({opts:c,resRequestCommentIbGib:e,metaspace:a,logalot:t}){let r=`[${uo.name}]`;try{t&&console.log(`${r} starting...`);let o=await a.getLocalUserSpace({lock:!1});if(!o)throw new Error("(UNEXPECTED) localUserSpace falsy?");let i=c.fnGetOrCreateApp?await c.fnGetOrCreateApp(a,o):await mo({AppClass:c.AppClass,defaultAppData:c.defaultAppData,onBeforeCreate:c.onBeforeCreate,onAppLoaded:c.onAppLoaded,metaspace:a,space:o}),n=c.getGlobalThis(c.config);n.appInstance=i,i.metaspace=a,await i.witness(e.newIbGib)}catch(o){throw console.error(`${r} ${m(o)}`),o}finally{t&&console.log(`${r} complete.`)}}b(uo,"execInteractive");async function mo({AppClass:c,defaultAppData:e,onBeforeCreate:a,onAppLoaded:t,metaspace:r,space:o}){let i=`[${mo.name}]`,n=!0;try{n&&console.log(`${i} starting...`);let s=await r.getSpecialIbGib({type:Re.apps,initialize:!1,lock:!1,space:o});if(!s)throw new Error("(UNEXPECTED) no apps index ibgib");if(!s.rel8ns)throw new Error("(UNEXPECTED) appsIbGib.rel8ns falsy");let l=(s.rel8ns[ke]??[]).filter(g=>{let{ib:E}=C({ibGibAddr:g});return nr({appIb:E}).appClassname===c.name}),d,f,h=!1;if(l.length===0)h=!0,a&&await a(r,o),d=await go({AppClass:c,defaultAppData:e,metaspace:r,space:o}),f=y({ibGib:d});else if(l.length===1)f=l[0];else{let g=l.map(A=>C({ibGibAddr:A}).ib).map((A,_)=>`
|
|
39
|
+
${_}) ${A}`),E,w=!1;do{let A=await Xe({title:"Which App?",msg:`${w?"huh? ":""}Multiple apps found. Which one?${g}`}),_=Number.parseInt(A);w=Number.isNaN(_)||_>=l.length,w||(E=_)}while(w);f=l[E]}let u=await dt({addr:f,space:o});if(u.success&&u.ibGibs?.length===1)d=u.ibGibs[0];else throw new Error(`Couldn't get app (${f}).`);if(!d.witness){let g=new c(void 0,void 0);await g.loadIbGibDto(d),d=g}return t&&(d=await t(d,h)),d}catch(s){throw console.error(`${i} ${m(s)}`),s}finally{n&&console.log(`${i} complete.`)}}b(mo,"defaultGetOrCreateApp");async function go({AppClass:c,defaultAppData:e,metaspace:a,space:t}){let r=`[${go.name}]`,o=!0;try{o&&console.log(`${r} starting...`);let n=await ct({fnPromptApp:async()=>{let s=`${c.name}_${jt({count:8})}`,l=O(e);l.name=s,l.uuid=await M();let d=void 0,{classname:f}=l,h=ir({appData:l,classname:f});return await ce.firstGen({ib:h,parentIbGib:ce.primitive({ib:`app ${f}`}),data:l,rel8ns:d,dna:!0,linkedRel8ns:[qt.ancestor,qt.past],nCounter:!0,tjp:{timestamp:!0}})},space:t,ibgibs:a});if(!n)throw new Error("Failed to create app (falsy).");if(n?.data?.classname!==c.name)throw new Error("(UNEXPECTED) wrong app classname.");return n}catch(i){throw console.error(`${r} ${m(i)}`),i}finally{o&&console.log(`${r} complete.`)}}b(go,"createAndSaveNewApp");async function wo({metaspace:c,tags:e,logalot:a}){let t=`[${wo.name}]`;try{a&&console.log(`${t} starting...`);let r=await c.getSpecialRel8dIbGibs({type:"tags",rel8nName:Ja});for(let o of e)r.some(i=>i.data?.text===o.text)||await c.createTagIbGib({text:o.text,icon:o.icon,description:o.description,space:void 0})}catch(r){throw console.error(`${t} ${m(r)}`),r}finally{a&&console.log(`${t} complete.`)}}b(wo,"ensureTagsExist");async function ei({args:c,interpretedArgInfos:e}){let a=c.join(" "),t={uuid:await M(),text:a,args:c,interpretedArgInfos:e,textTimestamp:re()};return await ce.firstGen({parentIbGib:ce.primitive({ib:"comment"}),ib:`comment ${a.substring(0,32).replace(/ /g,"_")}`,data:t,dna:!0,tjp:{uuid:!0,timestamp:!0},nCounter:!0})}b(ei,"createRequestCommentIbGib_Common");function ti({paramInfos:c}){let e=[],a=[];return c.forEach(t=>{[t.name,...t.synonyms??[]].forEach(o=>{a.includes(o.toLowerCase())&&e.push(`Duplicate identifier found: ${o}`),a.push(o.toLowerCase())})}),e}b(ti,"validateParamInfos");var Eo;(function(c){c.roots="roots",c.tags="tags",c.latest="latest",c.outerspaces="outerspaces",c.secrets="secrets",c.encryptions="encryptions"})(Eo||(Eo={}));var Mt={ib:"ib",gib:"gib",ibgib:"ibgib"};var De=!1;function $a({ibGib:c}){let e=`[${$a.name}]`;try{if(De&&console.log(`${e} starting...`),!c)throw new Error("ibGib required (E: 1237b2d4602a3d526f6b159cb6ad0922)");let{ib:a,data:t,rel8ns:r}=c;if(!r)return De&&console.log(`${e} rel8ns falsy, not a pic (I: 563a3e779b85b070550581e652e0ca22)`),!1;let o=r.ancestor||[];return o&&o.includes("pic^gib")?!0:t?t.binHash&&t.ext&&t.filename&&a?.includes("pic")?(De&&console.log(`${e} has binHash, ext, filename and ib has pic (I: f754b6b023d5379ee770038617edc722)`),!0):(De&&console.log(`${e} reached end, doesn't have pic qualities. not a pic. (I: 298c5e9a2916445df1cdd22a96f57522)`),!1):(De&&console.log(`${e} data falsy, not a pic (I: 6c05c03cdfca4085aef8f2a19df91690)`),!1)}catch(a){throw console.error(`${e} ${a.message}`),a}finally{De&&console.log(`${e} complete.`)}}b($a,"isPic");var N=!1,vt=class c extends Ur{static{b(this,"AppBase_V1")}lc=`[${c.name}]`;constructor(e,a){super(e,a)}async witnessImpl(e){let a=`${this.lc}[${this.witnessImpl.name}]`;try{N&&console.log(`${a} starting...`),await this.loadNewerSelfIfAvailable();let t;return sa({ibGib:e})?t=await this.routeAndDoArg({arg:e}):t=await this.doNonArg({ibGib:e}),t||(console.warn(`${a} result still falsy. doing default handler. (W: aba0de32c3835056447d7de3a2fb0223)`),t=await this.doDefault({ibGib:e})),t||console.warn(`${a} result falsy...Could not produce result? Was doDefault implemented in concrete class? (W: 15e70486bc33922f9388961bab815223)`),t}catch(t){throw console.error(`${a} ${m(t)}`),t}finally{N&&console.log(`${a} complete.`)}}async routeAndDoArg({arg:e}){let a=`${this.lc}[${this.routeAndDoArg.name}]`;try{N&&console.log(`${a} starting...`);let t=e;if(!sa({ibGib:t}))throw new Error("ibGib is not an arg (E: f0e36b13acbcdb1123ee72bdb9ee7723)");return Br({ibGib:t})?this.doCmdArg({arg:e}):void 0}catch(t){if(console.error(`${a} ${m(t)}`),this.data?.catchAllErrors)return await Mr({rawMsg:m(t)});throw t}finally{N&&console.log(`${a} complete.`)}}doCmdArg({arg:e}){let a=`${this.lc}[${this.doCmdArg.name}]`;try{if(N&&console.log(`${a} starting...`),!e.data?.cmd)throw new Error("invalid cmd arg. arg.data.cmd required. (E: aec4dd5bd967fbf36f9c4fad22210222)");if(e.data.cmd===Mt.ib)return this.doCmdIb({arg:e});if(e.data.cmd===Mt.gib)return this.doCmdGib({arg:e});if(e.data.cmd===Mt.ibgib)return this.doCmdIbgib({arg:e});throw new Error(`unknown arg.data.cmd: ${e.data.cmd} (E: 721fa6a5166327134f9504c1caa3e422)`)}catch(t){throw console.error(`${a} ${m(t)}`),t}finally{N&&console.log(`${a} complete.`)}}doCmdIb({arg:e}){let a=`${this.lc}[${this.doCmdIb.name}]`;try{throw N&&console.log(`${a} starting...`),new Error("not implemented in base class (E: 7298662a2b8f67611d16a8af0e499422)")}catch(t){throw console.error(`${a} ${m(t)}`),t}finally{N&&console.log(`${a} complete.`)}}doCmdGib({arg:e}){let a=`${this.lc}[${this.doCmdGib.name}]`;try{throw N&&console.log(`${a} starting...`),new Error("not implemented in base class (E: b6bf2c788c734051956481be7283d006)")}catch(t){throw console.error(`${a} ${m(t)}`),t}finally{N&&console.log(`${a} complete.`)}}doCmdIbgib({arg:e}){let a=`${this.lc}[${this.doCmdIbgib.name}]`;try{throw N&&console.log(`${a} starting...`),new Error("not implemented in base class (E: 4fee11f05315467abd036cd8555d27db)")}catch(t){throw console.error(`${a} ${m(t)}`),t}finally{N&&console.log(`${a} complete.`)}}doPic({ibGib:e}){let a=`${this.lc}[${this.doPic.name}]`;try{throw N&&console.log(`${a} starting...`),new Error("not implemented in base class (E: 16ba889931644d42ad9e476757dd0617)")}catch(t){throw console.error(`${a} ${m(t)}`),t}finally{N&&console.log(`${a} complete.`)}}doComment({ibGib:e}){let a=`${this.lc}[${this.doComment.name}]`;try{throw N&&console.log(`${a} starting...`),new Error("not implemented in base class (E: 0486a7864729456d993a1afe246faea4)")}catch(t){throw console.error(`${a} ${m(t)}`),t}finally{N&&console.log(`${a} complete.`)}}doNonArg({ibGib:e}){let a=`${this.lc}[${this.doNonArg.name}]`;try{return N&&console.log(`${a} starting...`),Ve({ibGib:e})?this.doComment({ibGib:e}):$a({ibGib:e})?this.doPic({ibGib:e}):this.doDefault({ibGib:e})}catch(t){throw console.error(`${a} ${m(t)}`),t}finally{N&&console.log(`${a} complete.`)}}doDefault({ibGib:e}){let a=`${this.lc}[${this.doDefault.name}]`;try{throw N&&console.log(`${a} starting...`),new Error("not implemented in base class (E: 5038662186617aaf1f0cc698fd1f9622)")}catch(t){throw console.error(`${a} ${m(t)}`),t}finally{N&&console.log(`${a} complete.`)}}async validateThis(){let e=`${this.lc}[${this.validateThis.name}]`;try{return N&&console.log(`${e} starting...`),this.data,[...or({appData:this.data})]}catch(a){throw console.error(`${e} ${m(a)}`),a}finally{N&&console.log(`${e} complete.`)}}async argy({argData:e,ibMetadata:a,noTimestamp:t,ibGibs:r}){let o=await Te({argData:e,ibMetadata:a,noTimestamp:t});return r&&(o.ibGibs=r),o}async resulty({resultData:e,ibGibs:a}){let t=await yt({resultData:e});return a&&(t.ibGibs=a),t}};function yo({ibGib:c}){if(!Ve({ibGib:c}))return!1;let e=c.data;return!!(e?.args?.length&&e?.interpretedArgInfos?.length)}b(yo,"isRequestComment");var ai={help:"help",quit:"quit"},yd=Object.values(ai),Ia={name:"interactive",isFlag:!0,synonyms:["i"],argTypeName:"boolean",allowMultiple:!1},$o=[Ia];var ie=Ge,Rt=class c extends vt{static{b(this,"SpaceGibApp_V1")}lc=`[${c.name}]`;constructor(e,a){super(e,a);let t=`${this.lc}[ctor]`;try{ie&&console.log(`${t} starting...`),this.initialized=this.initialize()}catch(r){throw console.error(`${t} ${m(r)}`),r}finally{ie&&console.log(`${t} complete.`)}}getAddlMetadata(){return super.getAddlMetadata()}parseAddlMetadataString({ib:e}){if(!e)throw new Error("ib required (E: aec93595c12cc15ee71d92dd8a4f4f23)");let a=`[${this.parseAddlMetadataString.name}]`;try{let[t,r,o,i]=e.split("_");return{atom:t,classnameIsh:r,nameIsh:o,idIsh:i}}catch(t){throw console.error(`${a} ${m(t)}`),t}}async handleNewContextChild({newChild:e}){let a=`${this.lc}[${this.handleNewContextChild.name}]`;try{ie&&console.log(`${a} starting... (I: 8494f1d374a8490bb4598c8bffa1fe75)`)}catch(t){throw console.error(`${a} ${m(t)}`),t}finally{ie&&console.log(`${a} complete.`)}}async doNonArg({ibGib:e}){let a=`${this.lc}[${this.doNonArg.name}]`;try{return ie&&console.log(`${a} starting...`),yo({ibGib:e})?await this.doContextRequestComment({requestCommentIbGib:e}):await super.doNonArg({ibGib:e})}catch(t){throw console.error(`${a} ${m(t)}`),t}finally{ie&&console.log(`${a} complete.`)}}async doContextRequestComment({requestCommentIbGib:e}){let a=`${this.lc}[${this.doContextRequestComment.name}]`;try{ie&&console.log(`${a} starting...`);let{interpretedArgInfos:t}=e.data;return t.some(r=>r.name===Ia.name)?(await this.initializeContext({contextIbGib:e,rel8nName:dr}),console.log(`${this.lc} space-gib initialized and ready.`)):console.warn(`${a} other requests not implemented yet.`),Ee}catch(t){throw console.error(`${a} ${m(t)}`),t}finally{ie&&console.log(`${a} complete.`)}}};var ri="",oi="space_gib",ii="SpaceGib: ibgib durable storage and SaaS provider at ibgib.space.",Io={version:"1",uuid:ri,name:oi,description:ii,classname:"SpaceGibApp_V1",icon:"cube",persistOptsAndResultIbGibs:!1,allowPrimitiveArgs:!0,catchAllErrors:!0,trace:!1};var k={agentId:$t,agentName:Pe,repromptWithResult:{type:"boolean",description:"Set this to true if you want to be reprompted with the function's result. Unless you really want a fire-and-forget style of function call, set this to true. NOTE: This is ignored with tellUser command, so you can't call tellUser and then repromptWithResult of true and then tellUser again."},notesToSelf:{type:"string",description:"Quick note scratchpad related to a requested function. For example, you could write your intent here."}};var Aa=class c{static{b(this,"CommandService_V1")}lc=`[${c.name}]`;commandQueue=[];isProcessing=!1;constructor(){}enqueueCommand(e){this.commandQueue.push(e),this.isProcessing||this.startProcessing()}startProcessing(){this.isProcessing=!0,this.processQueue().finally(()=>{this.isProcessing=!1,this.commandQueue.length>0&&this.startProcessing()})}async processQueue(){let e=`${this.lc}[${this.processQueue.name}]`;for(;this.commandQueue.length>0;){let a=this.commandQueue.shift();if(a)try{let t=await this.executeCommand(a.command,a.anonApiFn);a.resolve(t)}catch(t){console.error(`Error executing command ${a.command.cmd} ${a.command.cmdModifiers?.join(",")??""}:`,t),a.reject(t)}}}async executeCommand(e,a){let t=`[${c.name}.${this.executeCommand.name}]`;try{let r=a??Array.from(zr().entries()).map(o=>o[1]).find(o=>o.cmd===e.cmd&&o.cmdModifiers.every(i=>!!e.cmdModifiers?.includes(i)));if(r){console.log(`${t} command executing. cmdData: ${$(e)}`),e.notesToSelf&&console.log(`${t} Notes to self: ${e.notesToSelf}. (I: ebcc5471b2b309ba186281c134f77e25)`);let o=this.getCommandArgs(e,r);return await r.functionImpl(o)}else throw new Error(`${t} Unknown command: ${e.cmd} with modifiers ${e.cmdModifiers?.join(", ")} (E: cc9cb829f118de05b762020213ef2825)`)}catch(r){debugger;let o=`${t} ${m(r)}`;return console.error(o),{errorMsg:o}}}getCommandArgs(e,a){return e}},_a;function F(){return _a||(_a=new Aa),_a}b(F,"getCommandService");var j="## Examples: ";var Sa=T,Ga="getIbGibs",Ta="ibgib",Pa=[Ga],ni={ibGibAddrs:["project SomeProject 1748386170000^A2D75E05B14E264619D24ABA4F1A1B2328E183B4524CC26029E54B84BF7BFD73.02544DDD1E042D481EAF62E36229EEC54F20C1899250D6F664ABB48A2013C994"],notesToSelf:"Example of getting a single ibgib. Note that even though it's only getting a single ibgib, it still passes in an array. Usually reprompt is set because you're calling this to see the full ibgib record(s).",repromptWithResult:!0},si={ibGibAddrs:["project SomeProject 1748386170000^A2D75E05B14E264619D24ABA4F1A1B2328E183B4524CC26029E54B84BF7BFD73.02544DDD1E042D481EAF62E36229EEC54F20C1899250D6F664ABB48A2013C994","comment HelloWorld^98289357698348694683943689487958972634583644598269186EA90A3F4A73.298986986BC82792837498759817F9827395872AC87519CDAFFE8175786E5098"],notesToSelf:"Example of getting multiple ibgibs. Usually reprompt is set because you're calling this to see the full ibgib record(s).",repromptWithResult:!0},ci=[j,$(ni),$(si)].join(`
|
|
40
|
+
`),li=["Gets one or more full ibgib records via their addrs.","Note that all of these must be in a single space, determined by the spaceId arg. IF not provided, then the default local user space will be used.",ci].join(`
|
|
41
|
+
`),di={type:"array",description:"The ibGib addresses (ib^gib) of the ibGibs to load.",items:{type:"string",description:'caret-delimited ib^gib address, e.g., "comment HelloWorld^98289357698348694683943689487958972634583644598269186EA90A3F4A73.298986986BC82792837498759817F9827395872AC87519CDAFFE8175786E5098"'}},fi={name:Ga,description:li,parameters:{type:"object",properties:{...k,spaceId:{type:"string",description:"The id of the local user space. If not provided, will use the default local space. Only provide this if you don't want to use the default space. Agents should either leave this unset, or if they are trying to mut8 an ibGib that is inside *their* subspace, then they should provide this. Otherwise, it will look in the default space which will be incorrect. In the future, agents will have a different API for interacting with their subspaces, but for now this may be used (if the agent even has access to their subspace id. it's so early in dev, I'm not sure if this is true.)"},ibGibAddrs:di,getLatest:{type:"boolean",description:"Set to true if you want to get the latest ibgib in a timeline for the given incoming ibGibAddr. This is usually going to be true, unless you are specifically looking for ibGibs in the past or some other use case where you want the specific ibGib in time, so agents should explicitly decide this before calling this function (but no need to tell the user or anything, just make this decision)."}},required:["ibGibAddrs"]}};function bi(c){let e=F(),a={...c,cmd:Ta,cmdModifiers:Pa};return new Promise((t,r)=>{e.enqueueCommand({command:a,resolve:t,reject:r})})}b(bi,"getIbGibsViaCmd");async function _o(c){let e=`[${_o.name}]`;try{Sa&&console.log(`${e} starting... (I: genuuid)`),console.log(`${e} ${Ta} ${Pa} opts: ${$(c)}`);let{spaceId:a,ibGibAddrs:t,getLatest:r}=c;if(!t)throw new Error("(UNEXPECTED) ibGibAddrs falsy? (E: e9beaad8ab3cf56608dd5fc79c4c1825)");if(t.length===0)throw new Error("ibGibAddrs is empty (E: f0b1462f482872acba0612c8eb461925)");let o=await W();if(!o)throw new Error(`${e} metaspace falsy ($1: 85aa77c76e583edda3549ff59fadf825)`);let i=await o.getLocalUserSpace({localSpaceId:a});if(!i)throw a?new Error(`could not get local user space for spaceId (${a}) ($1: genuuid)`):new Error("(UNEXPECTED) couldn't get default local user space? ($1: 9b1528024148052dd871b4f323881825)");let n={};if(r){let f=await He({addrs:t,space:i});if(!f.data)throw new Error("(UNEXPECTED) resLatestAddrs.data falsy? we tried calling getLatestAddrs and this means there is a problem lower in the lib. (E: 0baaf8072abd4feed8330ab503925b25)");if(f.data.latestAddrsMap)Object.entries(f.data.latestAddrsMap).forEach(([h,u])=>{if(u)n[h]=u;else{debugger;console.warn(`${e} we're getting latest addrs and I don't know what it means downstream when we get a null for latest addr. (W: bb1db99ccf189afff83a1b5807263a25)`),n[h]=h}});else throw new Error("(UNEXPECTED) resLatestAddrs.data.latestAddrsMap falsy? we tried calling getLatestAddrs and this was supposed to be the resulting map. This means there is a problem lower in the lib. (E: 9dcca8343a284dfb1a43cf282b82f825)")}let s=r?Object.values(n):t;if(s.length!==t.length)throw new Error("(UNEXPECTED) addrsToGet.length !== ibGibAddrs.length? at this point it's assumed that these are the same length (E: 745698a1ba78a14077d648e8d0150825)");let l=await o.get({addrs:s,space:i});if(l.errorMsg||(l.ibGibs??[]).length!==s.length)throw new Error(`getIbGibs failed. error: ${m(l.errorMsg??`[unknown error. resGet.ibGib length (${(l.ibGibs??[]).length}). addrsToGet.length (${s.length})]`)} (E: 09aca916068c6254580f5e29fb63e825)`);let d={};return l.ibGibs.forEach(f=>{let h=y({ibGib:f});if(!s.find(g=>g===h))throw new Error(`ibGibAddr (${h}) in result ibGibs not found in addrsToGet (${s})? Here are the original ibGibAddrs: ${t}. Here is the resGet.ibGibs: ${$(l.ibGibs)} (E: 07535883a3a89fcb686f2409bf799825)`);d[h]=f}),Sa&&console.log(`${e} resMap: ${$(d)} (I: 70d79d873dd271949b48d837c286d825)`),d}catch(a){throw console.error(`${e} ${m(a)}`),a}finally{Sa&&console.log(`${e} complete.`)}}b(_o,"getIbGibsImpl");var Ao={nameOrId:Ga,fnViaCmd:bi,functionImpl:_o,cmd:Ta,cmdModifiers:Pa,schema:fi};var et="project";var Yd=`${Xr}_${et}`,So=32;var tt=T;function Na({name:c}){let e=`[${Na.name}]`;try{tt&&console.log(`${e} starting... (I: ec0c81cb0e8ec820f882ecafc2fbc825)`);let a=Ft({text:c,length:So});if(!a)throw new Error(`${e} Could not generate safeName from name: ${c}. (E: genuuid)`);return a}catch(a){throw console.error(`${e} ${m(a)}`),a}finally{tt&&console.log(`${e} complete.`)}}b(Na,"getProjectSafeName");function Ca({ib:c}){let e=`[${Ca.name}]`;try{if(tt&&console.log(`${e} starting... parsing ib: ${c}`),!c)throw new Error(`${e} ib required (E: genuuid)`);let a=c.split(" ");if(a.length!==3)throw new Error(`${e} Invalid project ib format. Expected 3 space-delimited pieces. Got: ${a.length}. ib: ${c} (E: genuuid)`);let[t,r,o]=a;if(t!==et)throw new Error(`${e} Invalid atom. Expected '${et}', got '${t}'. ib: ${c} (E: genuuid)`);if(!r)throw new Error(`${e} safeName segment is empty. ib: ${c} (E: genuuid)`);if(!o)throw new Error(`${e} addlMetadataText segment is empty. ib: ${c} (E: genuuid)`);let i=o.split("_");if(i.length!==1)throw new Error(`${e} Could not parse addlMetadataText. Expected 1 underscore-delimited piece. Got: ${i.length}. addlMetadataText: ${o} (E: genuuid)`);let n=i[0],s=parseInt(n,10);if(isNaN(s))throw new Error(`${e} Could not parse timestampInTicks from addlMetadataText. isNan. Expected a decimal number. timestampInTicksStr: ${n}. addlMetadataText: ${o} (E: genuuid)`);let d={atom:et,safeName:r,addlMetadataText:o,addlMetadata:{timestampInTicks:s}};return tt&&console.log(`${e} parsed info: ${$(d)}`),d}catch(a){throw console.error(`${e} ${a.message}`),a}finally{tt&&console.log(`${e} complete.`)}}b(Ca,"parseProjectIb");var xa=T,Ma="mut8IbGib",va="ibgib",Ra=[Ma],Oa=["uuid","timestamp","timestampMs","n","textTimestamp"],hi={ibGibAddr:"project SomeProject 1748386170000^A2D75E05B14E264619D24ABA4F1A1B2328E183B4524CC26029E54B84BF7BFD73.02544DDD1E042D481EAF62E36229EEC54F20C1899250D6F664ABB48A2013C994",dataToAddOrPatchJSONString:JSON.stringify({name:"New Title"}),mut8Ib:"project NewTitle 1748386170000",notesToSelf:`Example of editing/adding a project ibgib's "title". In project ibgibs, this is in the "data.name" field, and the 2nd spot in the ib is a alphanumerics-only version of the name.`,repromptWithResult:!1},pi={ibGibAddr:"project SomeProject^A2D75E05B14E264619D24ABA4F1A1B2328E183B4524CC26029E54B84BF7BFD73.02544DDD1E042D481EAF62E36229EEC54F20C1899250D6F664ABB48A2013C994",dataToAddOrPatchJSONString:JSON.stringify({description:"Updated description for the project. You do not have to include all the properties, only the ones you want to change/patch."}),notesToSelf:"Example of editing/adding an ibGib's description. This will change the description in the ibGib's data map.",repromptWithResult:!1},ui={ibGibAddr:"project SomeProject^AAAA2827879982375961098098B239047928374987987F6029E54B84BF7BFD73.02544DDD1E042D481EAF62E36229EEC54F20C1899250D6F664ABB48A2013C994",dataToRemoveJSONString:JSON.stringify({identity:{middleInitial:""}}),notesToSelf:`Example of removing a nested key. This will delete the "middleInitial" property from the "identity" object in an ibgib's data map.`,repromptWithResult:!0},mi={ibGibAddr:"project SomeProject^AAAA2827879982375961098098B239047928374987987F6029E54B84BF7BFD73.02544DDD1E042D481EAF62E36229EEC54F20C1899250D6F664ABB48A2013C994",dataToRenameJSONString:JSON.stringify({identity:{oldKeyName:"newKeyName"}}),notesToSelf:`Example of renaming a key. This will rename the "oldKeyName" key to "newKeyName" in an ibgib's data map.`,repromptWithResult:!1},gi={ibGibAddr:"project SomeProject^AAAA2827879982375961098098B239047928374987987F6029E54B84BF7BFD73.02544DDD1E042D481EAF62E36229EEC54F20C1899250D6F664ABB48A2013C994",mut8Ib:"project SomeNewIb",notesToSelf:'Example of renaming a key. This will rename the "ib" value, in this case "project SomeProject" to the new value. Empty values will throw.',repromptWithResult:!0},wi=[j,$(hi),$(pi),$(ui),$(mi),$(gi)].join(`
|
|
42
|
+
`),Ei=["Edits an ibGib's intrinsic data map via the mut8 transform.","This can include setting/updating an ibgib's data, renaming keys or removing data properties entirely, or changing the ib.","It operates on a specific ibGib identified by its address.",`**Note**: Certain intrinsic data properties are disallowed from being edited, renamed, or removed, including: \`${Oa.join("`, `")}\`. Any attempts to modify these paths will be ignored.`,"In the business domain, this can include multiple things, like editing a name, description, or other internal property. The following are only a couple of examples, but really it's any internal data for an ibgib.","",wi,"**Note**: Even though each one individually is optional, at least one of dataToRenameJSONString, dataToRemoveJSONString, dataToAddOrPatchJSONString, or mut8Ib is required."].join(`
|
|
43
|
+
`),La="Ibgib data can have any structure, so there is no way to know the keys beforehand. OpenAPI schema only allows for known props. So this arg should be a valid JSON string, i.e., the output of JSON.stringify(actualArg).",Da='Disallowed paths like "uuid" or "timestamp" cannot be added or patched. See function description for all disallowed keys.',yi={name:Ma,description:Ei,parameters:{type:"object",properties:{...k,spaceId:{type:"string",description:"The id of the local user space. If not provided, will use the default local space. Only provide this if you don't want to use the default space. Agents should either leave this unset, or if they are trying to mut8 an ibGib that is inside *their* subspace, then they should provide this. Otherwise, it will look in the default space which will be incorrect. In the future, agents will have a different API for interacting with their subspaces, but for now this may be used (if the agent even has access to their subspace id. it's so early in dev, I'm not sure if this is true.)"},ibGibAddr:{type:"string",description:"The content address of the ibGib to edit."},dataToRenameJSONString:{type:"object",description:["Specifies data properties to rename the key.",Da,La].join(`
|
|
44
|
+
`)},dataToRemoveJSONString:{type:"string",description:["Specifies data properties to remove entirely.",Da,La].join(`
|
|
45
|
+
`)},dataToAddOrPatchJSONString:{type:"string",description:['Subset of ibgib.data to be added or patched (or upserted if you like). So if you want to change the "name" property, then you specify that as the stringified version of { "name": "Some Name" }.',Da,La].join(`
|
|
46
|
+
`)},mut8Ib:{type:"string",description:"Optional. If provided, will mutate the ib of the ibGib."}},required:["ibGibAddr"]}};function $i(c){let e=F(),a={...c,cmd:va,cmdModifiers:Ra,mut8Ib:c.mut8Ib?.trim()||void 0};return new Promise((t,r)=>{e.enqueueCommand({command:a,resolve:t,reject:r})})}b($i,"mut8IbGibViaCmd");async function Go(c){let e=`[${Go.name}]`;try{xa&&console.log(`${e} starting... (I: genuuid)`),console.log(`${e} ${va} ${Ra} opts: ${$(c)}`);let{spaceId:a,ibGibAddr:t,dataToRenameJSONString:r,dataToRemoveJSONString:o,dataToAddOrPatchJSONString:i,mut8Ib:n,newName:s,newDescription:l}=c,d=await W();if(!d)throw new Error(`${e} metaspace falsy (E: 1a3f5e6c8d9a7b01f2e3d4c5b6a708d9)`);let f=await d.getLocalUserSpace({localSpaceId:a});if(!f)throw a?new Error(`could not get local user space for spaceId (${a}) (E: 61fc28fbdf3fd69ae7c9214fe74c2825)`):new Error("(UNEXPECTED) couldn't get default local user space? (E: 593028fc4038c1cb713a8b1d757da825)");if(s||l!==void 0)if(s){if(i)throw new Error("cannot have newName and dataToAddOrPatchJSONString in the same function call. (E: 72bf6c3c8d8e18a9284f5b0e16d63525)");i=JSON.stringify({name:s});let A=Na({name:s}),_=await d.getLatestAddr({addr:t,space:f}),{ib:B}=C({ibGibAddr:_}),{addlMetadataText:S,atom:R}=Ca({ib:B});n=`${R} ${A} ${S}`,l&&(i=JSON.stringify({description:l}))}else i=JSON.stringify({description:l});let h=r?JSON.parse(r):void 0,u=o?JSON.parse(o):void 0,g=i?JSON.parse(i):void 0;if(!t)throw new Error(`${e} ibGibAddr is required. (E: genuuid)`);let E=b((A,_)=>{if(!A)return;Object.keys(A).forEach(S=>{if(Oa.includes(S))throw new Error(`invalid map. includes disallowed path/key: ${S}. cannot contain any of the following keys: ${Oa} (E: 855afe854d78e4bf68e7ad88798d0825) (E: fc9c2c9549783685c859c3c4fbb84825)`)})},"fnValidateMap");if(h&&E(h,"dataToRename"),u&&E(u,"dataToRemove"),g&&E(g,"dataToAddOrPatch"),n){let A=["^"];if(A.forEach(_=>{if(n.includes(_))throw new Error(`invalid mut8Ib property. includes character: ${_}. Cannot include any of the following characters: ${A} (E: 855afe854d78e4bf68e7ad88798d0825)`)}),typeof n!="string"||n.length===0)throw new Error(`${e} mut8Ib must be a non-empty string. (E: 392678cef0a5458e0e4bca6869dc6825)`)}xa&&console.log(`${e} Mutating timeline ibGib... (I: genuuid)`);let w=await We({timelineAddr:t,mut8Opts:{dataToRename:h,dataToRemove:u,dataToAddOrPatch:g,mut8Ib:n},metaspace:d,space:f});if(!w)throw new Error(`${e} Mutate timeline transform failed: No new timeline ibGib returned. (E: genuuid)`);return console.log(`${e} Mutated timeline ibGib processed.`),w}catch(a){throw console.error(`${e} ${m(a)}`),a}finally{xa&&console.log(`${e} complete.`)}}b(Go,"mut8IbGibImpl");var To={nameOrId:Ma,fnViaCmd:$i,functionImpl:Go,cmd:va,cmdModifiers:Ra,schema:yi};var Po=[Ao,To];var No=T,Ii={agentId:"someidprobablylookslikeahash",agentType:"sometypehere",notesToSelf:"Example of a getContextInfo function call. DO NOT USE THESE AS YOUR ACTUAL ARGS. THIS IS ONLY AN EXAMPLE TO SHOW THE SHAPE OF THE FUNCTION CALL!!",repromptWithResult:!0},_i=[j,$(Ii)].join(`
|
|
47
|
+
`);function Ai(c){let e=F(),a={cmd:"agent",cmdModifiers:["getContextInfo"],agentId:c.agentId,agentType:c.agentType,repromptWithResult:c?.repromptWithResult,notesToSelf:c?.notesToSelf};return new Promise((t,r)=>{e.enqueueCommand({command:a,resolve:t,reject:r})})}b(Ai,"getContextInfoViaCmd");async function Co(c){let e=`[${Co.name}]`;try{No&&console.log(`${e} starting... (I: genuuid)`);let{agentId:a,agentType:t}=c,o=await Ye().getAgentById({agentId:a,agentType:t});if(!o)throw new Error(`agent not found for opts: ${$(c)} (E: b0da990f27c85c29e5bf148299507225)`);if(!o.data)throw new Error(`(UNEXPECTED) agent.data is falsy? opts: ${$(c)} (E: a8b357b5c68e5485144e2358d1a60425)`);let i=await W(),n=o.data["@currentContextTjpAddr"],s=o.data.superSpaceId,l=await i.getLocalUserSpace({localSpaceId:s,lock:!1}),d=await i.get({addrs:[n],space:l});if(d.errorMsg||(d.ibGibs??[]).length!==1)throw new Error(`couldn't get context ibgib (${n}) from super space (${s}). errorMsg: ${d.errorMsg??"[unknown error]"} (E: 63514d4521e1dc26860354ccbcb02125)`);let f=d.ibGibs.at(0),h,u=await i.getLatestAddr({ibGib:f,space:l});if(u){let g=await i.get({addrs:[u],space:l});if(g.errorMsg||(g.ibGibs??[]).length!==1)throw new Error(`couldn't get latest context ibgib (${u}) from super space (${s}). errorMsg: ${g.errorMsg??"[unknown error]"} (E: 450727cc12e226f8b741dd7b0efbfe25)`);h=g.ibGibs.at(0)}return{contextAddr:n,contextIbGib:f,latestContextAddr:u,latestContextIbGib:h}}catch(a){let t=`${e} ${m(a)}`;throw console.error(t),new Error(t)}finally{No&&console.log(`${e} complete.`)}}b(Co,"getContextInfoImpl");var xo={nameOrId:"getContextInfo",fnViaCmd:Ai,functionImpl:Co,cmd:"agent",cmdModifiers:["getContextInfo"],schema:{name:"getContextInfo",description:`Gets context info *about your current context ibgib in which you are conversing*. For example, agent's must always "be" in a single location ibgib which is their current primary context. When this ibgib's timeline changes (when a mut8/rel8 happens on it and a new ibgib frame is registered with the metaspace and published via the metaspace's pubsub mechanism), then the agent will be made aware of the new children ibgibs added to that timeline. The context address will probably be the TJP address as this defines the timeline's starting point and is used to refer to the entire timeline. Note that the context will always be in the agent's super space.
|
|
48
|
+
NOTE: This function DOES NOT get any and all context info, e.g., it does not get the website's current css colors. It is specifically to get info regarding YOUR CURRENT default context ibgib info.
|
|
49
|
+
|
|
50
|
+
${_i}`,parameters:{type:"object",properties:{...k,agentId:$t,agentType:Fr},required:["agentId","agentType"]}}};var Lo=T,Ua="helloWorld",Do="agent",Oo=[Ua],Si={agentsSelfIdentifiedName:"Coolguy",agentId:"someidprobablylookslikeahash",agentType:"sometypehere",notesToSelf:"Example of a helloWorld function call. DO NOT USE THESE AS YOUR ACTUAL NAME/ID/TYPE! THIS IS ONLY AN EXAMPLE TO SHOW THE SHAPE OF THE FUNCTION CALL!!",repromptWithResult:!1},Gi=[j,$(Si)].join(`
|
|
51
|
+
`),Ti=["Introductory function that does a couple things. First, it just makes sure that the basic function calling plumbing is working with the agent. Next, it also confirms the agent is aware of his/her/its id and type. Also, it empowers the agent to choose his/her/its own name with which to interact with user(s) and other agent(s) (only one user implemented atow 04/2025).NOTE: This does not say anything to the user proper. You have to call tellUser (or some other function in the future possibly) to converse with the user. This function only does init.",Gi].join(`
|
|
52
|
+
`),Pi={type:"string",description:"unique identifier for the agent. Should be provided to the agent in system instructions upon creation."},Ni={type:"string",description:"type of the agent that governs basic responsibilities. Should be provided to the agent in system instructions upon creation."};function Ci(c){let e=F(),a={...c,cmd:Do,cmdModifiers:Oo};return new Promise((t,r)=>{e.enqueueCommand({command:a,resolve:t,reject:r})})}b(Ci,"helloWorldViaCmd");async function Mo(c){let e=`[${Mo.name}]`;try{Lo&&console.log(`${e} starting... (I: genuuid)`);let{agentId:a,agentType:t,agentsSelfIdentifiedName:r}=c,i=await Ye().getAgentById({agentId:a,agentType:t});if(!i)throw new Error(`agent not found for opts: ${$(c)} (E: b0da990f27c85c29e5bf148299507225)`);await i.updateName({name:r})}catch(a){debugger;let t=`${e} ${m(a)}`;return console.error(t),{errorMsg:t}}finally{Lo&&console.log(`${e} complete.`)}}b(Mo,"helloWorldImpl");var vo={nameOrId:Ua,fnViaCmd:Ci,functionImpl:Mo,cmd:Do,cmdModifiers:Oo,schema:{name:Ua,description:Ti,parameters:{type:"object",properties:{...k,agentsSelfIdentifiedName:Pe,agentId:Pi,agentType:Ni},required:["agentsSelfIdentifiedName","agentId","agentType"]}}};var Oe=T,Ba="tellUser",xi="agent",Li=[Ba],Di={text:"Hello user, this is an example of how I can tell you something!",agentName:"Zarquon",notesToSelf:"Example of a tellUser function call. Note repromptWithResult is false b/c it is ignored with tellUser cmd.",repromptWithResult:!1},Oi=[j,$(Di)].join(`
|
|
53
|
+
`),Mi=`Use this to talk with the user. DON'T just add text on the canvas! Use this function as it adds a comment to the chat log which the user can see.
|
|
54
|
+
|
|
55
|
+
${Oi}`;function Ro(c){let e=`[${Ro.name}]`;try{Oe&&console.log(`${e} starting... (I: 39ce6d58e154b8463170463f20d44925)`),Oe&&console.log(`${e} tellUserViaCmd raw incoming opts: ${$(c)} (I: 2ff6e7fc49b12e335affa1cb3af11125)`);let a=F(),t={...c,cmd:"agent",cmdModifiers:["tellUser"],repromptWithResult:!1};return Oe&&console.log(`${e} tellUserViaCmd command: ${$(t)} (I: d7c86c41cf2578e1ccdd30f4dbc62625)`),new Promise((r,o)=>{a.enqueueCommand({command:t,resolve:r,reject:o})})}catch(a){throw console.error(`${e} ${m(a)}`),a}finally{Oe&&console.log(`${e} complete.`)}}b(Ro,"tellUserViaCmd");async function Uo(c){let e=`[${Uo.name}]`;try{Oe&&console.log(`${e} starting... (I: badce195ed1817dd686c7098511e1f25)`),console.log(`${e} agent tell user opts: ${$(c)}`);let a=await W(),t=c.contextIbGibAddr;if(!t)throw new Error("contextIbGibAddr is falsy (was not provided by model if this was a function call request). This should be required in the gemini schema. (E: 2585778dc7f6fc74322f40745d7f4d25)");let r=ot({addr:t})??[];if(r.length>0){console.log(`${e} returning early because agent has provided a non-ibgib addr for contextAddr: ${t}. addrErrors: ${r}. opts: ${$(c)} (I: 66c39c5031723254de46c254b096dc25)`);return}if(J({gib:C({ibGibAddr:t}).gib})){console.log(`${e} agent has acked by calling this with a primitive context address. This will not propagate to the user's current context. opts: ${$(c)} (I: a0687328201af74ed9d9e24ad4a5b825)`);return}let o=await a.getLocalUserSpace({lock:!1});if(!o)throw new Error("(UNEXPECTED) couldn't get default local user space? (E: 2fdac9f814d620ce6341cfc10942f525)");let{newIbGib:i}=await na({text:c.text,addlMetadataText:Hr({textSrc:jr.AI,other:`${c.agentName}_${c.agentId}`}),saveInSpace:!0,space:o}),n,s=await a.getLatestAddr({addr:t,space:o});if(s){let l=await a.get({addrs:[s],space:o});if(l.errorMsg||(l.ibGibs??[]).length!==1)throw new Error(`couldn't get latest context ibgib (${s}) from super space (${o.ib}). errorMsg: ${l.errorMsg??"[unknown error]"} (E: 450727cc12e226f8b741dd7b0efbfe25)`);n=l.ibGibs.at(0)}if(!n)throw new Error(`(UNEXPECTED) couldn't get latest context ibgib? (${s}) (E: cb50a6cb984a60c139a4f16a26290d25)`);await ia({timeline:n,metaspace:a,rel8nInfos:[{rel8nName:"comment",ibGibs:[i]}],space:o})}catch(a){throw console.error(`${e} ${m(a)}`),a}finally{Oe&&console.log(`${e} complete.`)}}b(Uo,"tellUserImpl");var vi={type:"string",description:"The text content to display to the user in the chat log. This is how you, as the agent, communicate with the user."},Ri={type:"string",description:"This is the address of the ibgib in which you wish to communicate with the user (and/or other agents when implemented). If you don't know this, you should call the getContextInfo function (the actual name may vary slightly as we are in active development right now, but this should be included in your available functions)."},Bo={nameOrId:Ba,fnViaCmd:Ro,functionImpl:Uo,cmd:xi,cmdModifiers:Li,schema:{name:Ba,description:Mi,parameters:{type:"object",properties:{...k,text:vi,contextIbGibAddr:Ri,agentName:Pe},required:["text","contextIbGibAddr","agentName"]}}};var ko=[Bo,vo,xo];var ka=T,Fa="editText",ja="ibgib",za=[Fa],Ui={ibGibAddr:"comment HelloThereImBob 1748386170000^A2D75E05B14E264619D2ACCCCABF234128E183B4524CC26029E54B84BF7BFD73.61985691826359867236266716461787826378AFFF23984723987FDA2013C8CB",newText:"This is the newly edited text",notesToSelf:"Example of an ibgib's data.text property.",repromptWithResult:!1},Bi=[j,$(Ui)].join(`
|
|
56
|
+
`),ki=["Edits an ibGib's data.text property and performs additional business logic on other fields within the ibGib record, like timestamps, updating the ib, etc.","",Bi].join(`
|
|
57
|
+
`),Fi={name:Fa,description:ki,parameters:{type:"object",properties:{...k,spaceId:{type:"string",description:"The id of the local user space. If not provided, will use the default local space. Only provide this if you don't want to use the default space. Agents should either leave this unset, or if they are trying to mut8 an ibGib that is inside *their* subspace, then they should provide this. Otherwise, it will look in the default space which will be incorrect. In the future, agents will have a different API for interacting with their subspaces, but for now this may be used (if the agent even has access to their subspace id. it's so early in dev, I'm not sure if this is true.)"},ibGibAddr:{type:"string",description:"The content address of the ibGib to edit."},newText:{type:"string",description:"The new text to set for the ibGib's data.text property."}},required:["ibGibAddr"]}};function ji(c){let e=F(),a={...c,cmd:ja,cmdModifiers:za};return new Promise((t,r)=>{e.enqueueCommand({command:a,resolve:t,reject:r})})}b(ji,"viaCmd");async function Fo(c){let e=`[${Fo.name}]`;try{ka&&console.log(`${e} starting... (I: genuuid)`),console.log(`${e} ${ja} ${za} opts: ${$(c)}`);let{spaceId:a,ibGibAddr:t,newText:r}=c,o=await W();if(!o)throw new Error(`${e} metaspace falsy (E: 1a3f5e6c8d9a7b01f2e3d4c5b6a708d9)`);let i=await o.getLocalUserSpace({localSpaceId:a});if(!i)throw a?new Error(`could not get local user space for spaceId (${a}) (E: 61fc28fbdf3fd69ae7c9214fe74c2825)`):new Error("(UNEXPECTED) couldn't get default local user space? (E: 593028fc4038c1cb713a8b1d757da825)");if(r??="",!t)throw new Error(`${e} ibGibAddr is required. (E: genuuid)`);let n=Rr({commentText:r,addlMetadataText:rt()});ka&&console.log(`${e} Mutating timeline ibGib... (I: genuuid)`);let s=await We({timelineAddr:t,mut8Opts:{dataToAddOrPatch:{text:r,textTimestamp:re()},mut8Ib:n},metaspace:o,space:i});if(!s)throw new Error(`${e} Mutate timeline transform failed: No new timeline ibGib returned. (E: genuuid)`);return console.log(`${e} Mutated timeline ibGib processed.`),s}catch(a){throw console.error(`${e} ${m(a)}`),a}finally{ka&&console.log(`${e} complete.`)}}b(Fo,"fnImpl");var jo={nameOrId:Fa,fnViaCmd:ji,functionImpl:Fo,cmd:ja,cmdModifiers:za,schema:Fi};var zo=[jo];var qo=Ge,zi=new Map([...ko,...zo,...Po].map(c=>[c.nameOrId,c]));function qa(){let c=`[${qa.name}]`;try{qo&&console.log(`${c} starting... (I: e6bad47eedd044beadadbd63361128ea)`),qr({functionInfos:zi})}catch(e){throw console.error(`${c} ${m(e)}`),e}finally{qo&&console.log(`${c} complete.`)}}b(qa,"registerDeprecatedFunctionNamesAndFunctionInfos_Web");console.log(`[space-gib bootstrap] version: ${Dr}`);async function Jb(){await ya({config:Tr,getGlobalThis:Or,AppClass:Rt,defaultAppData:Io,paramInfos:$o,registerAgentFunctionInfos:qa,localSpaceNamePrefix:"space_gib_",onReady:b(async c=>{Ge&&console.log(`[bootstrapSpaceGibApp] Engine ready. app: ${c?.ib}`),await Wr().onEngineReady()},"onReady")})}b(Jb,"bootstrapSpaceGibApp");export{Jb as bootstrapSpaceGibApp};
|
|
58
|
+
//# sourceMappingURL=bootstrap.mjs.map
|