@ours.network/sdk 1.3.1 → 1.5.0
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/dist/api/contacts.js +1 -1
- package/dist/api/conversations.js +1 -1
- package/dist/api/files.js +1 -1
- package/dist/api/identity.js +1 -1
- package/dist/api/messaging.js +1 -1
- package/dist/api/profile.js +1 -1
- package/dist/book.js +1 -1
- package/dist/boot.js +1 -1
- package/dist/{chunk-6D4VEJ7G.js → chunk-25ZST4S3.js} +1 -1
- package/dist/{chunk-75SBIMZV.js → chunk-2HB7I5JM.js} +1 -1
- package/dist/{chunk-QZA7SEVN.js → chunk-4Q5FJDMI.js} +1 -1
- package/dist/{chunk-6TQNPR4I.js → chunk-4UYU3SJ3.js} +1 -1
- package/dist/chunk-A7MUL47A.js +2 -0
- package/dist/{chunk-KM47NXDZ.js → chunk-AC6ND2CA.js} +1 -1
- package/dist/chunk-BL54LJNA.js +2 -0
- package/dist/{chunk-UXUO7HJ6.js → chunk-GLMGYTRX.js} +1 -1
- package/dist/{chunk-2HS7JGHP.js → chunk-KIIBATGV.js} +1 -1
- package/dist/{chunk-UN44T5Z5.js → chunk-LFJI7SYO.js} +1 -1
- package/dist/{chunk-7MXGWXS4.js → chunk-LLUMHNBP.js} +1 -1
- package/dist/{chunk-KBXZ7WK6.js → chunk-MLISCAHB.js} +1 -1
- package/dist/{chunk-HVJRHUSY.js → chunk-OCBN326X.js} +1 -1
- package/dist/{chunk-XTYFZQI6.js → chunk-OS7QJTVD.js} +1 -1
- package/dist/{chunk-G7RFUBUL.js → chunk-PGG2Y65Y.js} +1 -1
- package/dist/{chunk-3RMDFCEE.js → chunk-R7NCFWZO.js} +1 -1
- package/dist/{chunk-XYSQZW3X.js → chunk-V63EMP3U.js} +1 -1
- package/dist/{chunk-JPG44TVX.js → chunk-VVPDTS5O.js} +1 -1
- package/dist/chunk-VXVW4KJU.js +2 -0
- package/dist/{chunk-EHZNOPG6.js → chunk-WXVWLASM.js} +1 -1
- package/dist/{chunk-ZAI7AWG2.js → chunk-XDMG3N3D.js} +1 -1
- package/dist/{chunk-QKNFHB65.js → chunk-XWILWDUO.js} +1 -1
- package/dist/{chunk-2G3YBZBM.js → chunk-YQQKPG4Q.js} +1 -1
- package/dist/client/http.js +1 -1
- package/dist/client.js +1 -1
- package/dist/cluster/control.js +1 -1
- package/dist/cluster/manifest.js +1 -1
- package/dist/connector.js +1 -1
- package/dist/daemon.js +1 -1
- package/dist/errors.d.ts +10 -2
- package/dist/errors.js +1 -1
- package/dist/gc.js +1 -1
- package/dist/http/api-routes.js +1 -1
- package/dist/http/server.js +1 -1
- package/dist/identity/hierarchy.js +1 -1
- package/dist/identity/lease.js +1 -1
- package/dist/identity/lifecycle.js +1 -1
- package/dist/identity/model.js +1 -1
- package/dist/identity/provision.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/messaging/file-limit.d.ts +156 -0
- package/dist/messaging/file-limit.js +2 -0
- package/dist/messaging/send.js +1 -1
- package/dist/mufl/handlers.js +1 -1
- package/dist/mufl/tx.js +1 -1
- package/dist/mufl_code/7962BB01B1D3E782A1F80B083A900AEC30BAC8F8CE79282B31821802B94A39B6.muflo +0 -0
- package/dist/notify.js +1 -1
- package/dist/render/adapt-to-json.js +1 -1
- package/dist/runtime/env.js +1 -1
- package/dist/state.js +1 -1
- package/dist/sweeps.js +1 -1
- package/package.json +3 -3
- package/dist/chunk-3S6XRE6Q.js +0 -2
- package/dist/chunk-UM73BGFH.js +0 -2
package/dist/api/contacts.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a,b,c,d,e,f,g,h,i,j}from"../chunk-
|
|
2
|
+
import{a,b,c,d,e,f,g,h,i,j}from"../chunk-AC6ND2CA.js";import"../chunk-PGG2Y65Y.js";import"../chunk-25ZST4S3.js";import"../chunk-BL54LJNA.js";import"../chunk-XWILWDUO.js";import"../chunk-V63EMP3U.js";import"../chunk-MLISCAHB.js";import"../chunk-4UYU3SJ3.js";import"../chunk-YRPUM6JG.js";import"../chunk-VVPDTS5O.js";import"../chunk-DIRW7I4S.js";import"../chunk-OCBN326X.js";import"../chunk-KIIBATGV.js";import"../chunk-WXVWLASM.js";import"../chunk-ZHH3PWEW.js";import"../chunk-LKFYUCN7.js";import"../chunk-P55RJGZU.js";import"../chunk-XYU2DSWR.js";import"../chunk-IB2U7K6Y.js";export{d as addContact,a as generateInvite,e as listContacts,b as listInvites,f as listLocalContactBook,h as removeContact,i as renameContact,j as respondToIntroduction,c as revokeInvite,g as setLocalBookPolicy};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a,b,c,d}from"../chunk-
|
|
2
|
+
import{a,b,c,d}from"../chunk-GLMGYTRX.js";import"../chunk-PGG2Y65Y.js";import"../chunk-25ZST4S3.js";import"../chunk-BL54LJNA.js";import"../chunk-XWILWDUO.js";import"../chunk-V63EMP3U.js";import"../chunk-MLISCAHB.js";import"../chunk-4UYU3SJ3.js";import"../chunk-YRPUM6JG.js";import"../chunk-VVPDTS5O.js";import"../chunk-DIRW7I4S.js";import"../chunk-OCBN326X.js";import"../chunk-KIIBATGV.js";import"../chunk-WXVWLASM.js";import"../chunk-ZHH3PWEW.js";import"../chunk-LKFYUCN7.js";import"../chunk-P55RJGZU.js";import"../chunk-XYU2DSWR.js";import"../chunk-IB2U7K6Y.js";export{a as getConversation,b as getReceipts,c as markRead,d as setConversationPolicy};
|
package/dist/api/files.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a,b,c,d}from"../chunk-
|
|
2
|
+
import{a,b,c,d}from"../chunk-2HB7I5JM.js";import"../chunk-PGG2Y65Y.js";import"../chunk-25ZST4S3.js";import"../chunk-BL54LJNA.js";import"../chunk-XWILWDUO.js";import"../chunk-V63EMP3U.js";import"../chunk-MLISCAHB.js";import"../chunk-4UYU3SJ3.js";import"../chunk-YRPUM6JG.js";import"../chunk-VVPDTS5O.js";import"../chunk-DIRW7I4S.js";import"../chunk-OCBN326X.js";import"../chunk-KIIBATGV.js";import"../chunk-WXVWLASM.js";import"../chunk-ZHH3PWEW.js";import"../chunk-LKFYUCN7.js";import"../chunk-P55RJGZU.js";import"../chunk-XYU2DSWR.js";import"../chunk-IB2U7K6Y.js";export{d as deferFiles,b as getFiles,a as listIncomingFiles,c as saveFileFallbackNotice};
|
package/dist/api/identity.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a,b,c,d,e,f,g,h,i,j,k}from"../chunk-
|
|
2
|
+
import{a,b,c,d,e,f,g,h,i,j,k}from"../chunk-PGG2Y65Y.js";import"../chunk-25ZST4S3.js";import"../chunk-BL54LJNA.js";import"../chunk-XWILWDUO.js";import"../chunk-V63EMP3U.js";import"../chunk-MLISCAHB.js";import"../chunk-4UYU3SJ3.js";import"../chunk-YRPUM6JG.js";import"../chunk-VVPDTS5O.js";import"../chunk-DIRW7I4S.js";import"../chunk-OCBN326X.js";import"../chunk-KIIBATGV.js";import"../chunk-WXVWLASM.js";import"../chunk-ZHH3PWEW.js";import"../chunk-LKFYUCN7.js";import"../chunk-P55RJGZU.js";import"../chunk-XYU2DSWR.js";import"../chunk-IB2U7K6Y.js";export{g as chooseIdentity,d as closeTemporaryIdentityOp,b as createIdentity,e as createRootIdentity,c as createTemporaryIdentity,i as currentIdentity,f as defineLocalIdentityFile,h as listIdentities,k as releaseLease,j as removeIdentity,a as requireBound};
|
package/dist/api/messaging.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a,b,c,d,e}from"../chunk-
|
|
2
|
+
import{a,b,c,d,e}from"../chunk-A7MUL47A.js";import"../chunk-VXVW4KJU.js";import"../chunk-LFJI7SYO.js";import"../chunk-PGG2Y65Y.js";import"../chunk-25ZST4S3.js";import"../chunk-BL54LJNA.js";import"../chunk-XWILWDUO.js";import"../chunk-V63EMP3U.js";import"../chunk-MLISCAHB.js";import"../chunk-4UYU3SJ3.js";import"../chunk-YRPUM6JG.js";import"../chunk-VVPDTS5O.js";import"../chunk-DIRW7I4S.js";import"../chunk-OCBN326X.js";import"../chunk-KIIBATGV.js";import"../chunk-WXVWLASM.js";import"../chunk-ZHH3PWEW.js";import"../chunk-LKFYUCN7.js";import"../chunk-P55RJGZU.js";import"../chunk-XYU2DSWR.js";import"../chunk-IB2U7K6Y.js";export{e as deferMessages,d as getMessages,c as listIncomingMessages,b as sendFile,a as sendMessage};
|
package/dist/api/profile.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a,b,c,d}from"../chunk-
|
|
2
|
+
import{a,b,c,d}from"../chunk-XDMG3N3D.js";import"../chunk-PGG2Y65Y.js";import"../chunk-25ZST4S3.js";import"../chunk-BL54LJNA.js";import"../chunk-XWILWDUO.js";import"../chunk-V63EMP3U.js";import"../chunk-MLISCAHB.js";import"../chunk-4UYU3SJ3.js";import"../chunk-YRPUM6JG.js";import"../chunk-VVPDTS5O.js";import"../chunk-DIRW7I4S.js";import"../chunk-OCBN326X.js";import"../chunk-KIIBATGV.js";import"../chunk-WXVWLASM.js";import"../chunk-ZHH3PWEW.js";import"../chunk-LKFYUCN7.js";import"../chunk-P55RJGZU.js";import"../chunk-XYU2DSWR.js";import"../chunk-IB2U7K6Y.js";export{b as advertiseMigrate,d as readvertiseOnUpgrade,a as setBio,c as setPersona};
|
package/dist/book.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{K as a,L as b,M as c,N as d,O as e,P as f,Q as g,R as h,S as i,T as j}from"./chunk-
|
|
2
|
+
import{K as a,L as b,M as c,N as d,O as e,P as f,Q as g,R as h,S as i,T as j}from"./chunk-4UYU3SJ3.js";import"./chunk-YRPUM6JG.js";import"./chunk-VVPDTS5O.js";import"./chunk-DIRW7I4S.js";import"./chunk-OCBN326X.js";import"./chunk-KIIBATGV.js";import"./chunk-WXVWLASM.js";import"./chunk-ZHH3PWEW.js";import"./chunk-LKFYUCN7.js";import"./chunk-P55RJGZU.js";import"./chunk-XYU2DSWR.js";import"./chunk-IB2U7K6Y.js";export{a as bookDir,c as bookPath,f as exportAdBlob,g as exportSigningSecret,j as pinRegistrar,h as publishToBook,d as readBook,b as registrarKeyPath,i as unpublishFromBook,e as writeBook};
|
package/dist/boot.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a,b}from"./chunk-
|
|
2
|
+
import{a,b}from"./chunk-R7NCFWZO.js";import"./chunk-IU6MOFTJ.js";import"./chunk-25ZST4S3.js";import"./chunk-XWILWDUO.js";import"./chunk-V63EMP3U.js";import"./chunk-MLISCAHB.js";import"./chunk-4UYU3SJ3.js";import"./chunk-YRPUM6JG.js";import"./chunk-VVPDTS5O.js";import"./chunk-DIRW7I4S.js";import"./chunk-OCBN326X.js";import"./chunk-KIIBATGV.js";import"./chunk-WXVWLASM.js";import"./chunk-ZHH3PWEW.js";import"./chunk-LKFYUCN7.js";import"./chunk-P55RJGZU.js";import"./chunk-XYU2DSWR.js";import"./chunk-IB2U7K6Y.js";export{b as bootWrapper,a as wrapperBooted};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a as E,b as k,d as A}from"./chunk-
|
|
2
|
+
import{a as E,b as k,d as A}from"./chunk-MLISCAHB.js";import{E as T,F as I,G as _,J as R,S as x,x as y}from"./chunk-4UYU3SJ3.js";import{a as S}from"./chunk-VVPDTS5O.js";import{a as l,d as u,e as d,g as w}from"./chunk-OCBN326X.js";import{a as $,c as m,q as v}from"./chunk-KIIBATGV.js";import{c as s,i as r}from"./chunk-WXVWLASM.js";import{join as b}from"node:path";import*as i from"node:fs";function D(e){try{$.remove_packet(e.cid)}catch(t){r(`remove_packet(${e.cid}) failed:`,String(t))}m.delete(e.name);try{x(e)}catch(t){r(`failed to unpublish "${e.name}" from the contact book:`,String(t))}l.has(e.name)&&(l.delete(e.name),w()),e.name===k&&(E(null),A());try{i.rmSync(e.dir,{recursive:!0,force:!0}),y.delete(e.name)}catch(t){return`deleting ${e.dir} failed: ${String(t)}`}return null}function F(e,t){let n=e.temp;return n?(n.closing||(n.closing=(async()=>{r(`[${e.name}] closing temporary identity (${t})`);let o=[];try{o=T(a=>S(_(e,"::a2a_messaging::list_contacts",a)))}catch(a){r(`[${e.name}] contact snapshot failed during close (continuing with local cleanup):`,String(a))}let p=0,c=0;u.add(e.name);try{for(let a of o)try{await I(async C=>{let h=(await R(e,"::a2a_messaging::remove_contact",{contact:a.container_id},C)).Reduce("notified");return h.IsNil()?!1:h.GetBoolean()})?p++:c++}catch(g){c++,r(`[${e.name}] remove-me to ${a.container_id} failed (continuing):`,String(g))}}finally{u.delete(e.name)}let f=D(e);return f?r(`[${e.name}] temporary identity close: LOCAL DELETE FAILED \u2014 ${f}`):r(`[${e.name}] temporary identity closed: ${o.length} contact(s), ${p} remove-me notice(s) queued, ${c} not sent (delivery unverified by design)`),{attempted:o.length,notified:p,failed:c,deleteError:f}})()),n.closing):Promise.reject(new Error(`identity "${e.name}" is not temporary`))}function H(){for(let e of[...m.values()]){let t=e.temp;if(!t||t.closing||d(t.owner.pid))continue;let n=l.get(e.name);n&&d(n.pid)||F(e,`stale lease \u2014 owner pid ${t.owner.pid} is dead`).catch(o=>r(`[${e.name}] stale-temp reclaim failed:`,String(o)))}}function J(){if(i.existsSync(s))for(let e of i.readdirSync(s,{withFileTypes:!0})){if(!e.isDirectory()||m.has(e.name))continue;let t=b(s,e.name),n=v(t);if(!(!n||d(n.owner.pid)))try{i.rmSync(t,{recursive:!0,force:!0}),y.delete(e.name),r(`[${e.name}] removed orphaned temporary-identity dir (owner pid ${n.owner.pid} dead, no live packet)`)}catch(o){r(`[${e.name}] failed to remove orphaned temporary-identity dir:`,String(o))}}}export{D as a,F as b,H as c,J as d};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a as s}from"./chunk-
|
|
2
|
+
import{a as s}from"./chunk-PGG2Y65Y.js";import{G as h,H as y,I as x,J as F,K as l}from"./chunk-BL54LJNA.js";import{E as S,F as d,G as _,J as f,m as c}from"./chunk-4UYU3SJ3.js";import{d as g,f as p}from"./chunk-VVPDTS5O.js";import{t as m,u as a,v as w}from"./chunk-KIIBATGV.js";async function M(n){let r=s(n);try{return S(t=>g(_(r,"::actor::list_incoming_files",t)))}catch(t){throw l("list_incoming_files",String(t))}}async function N(n,r={}){let t=s(n),{wire_ids:e}=r;if(e!==void 0){if(e.length<1||e.length>a)throw h(a);if(e.some(i=>!m(i)))throw y();if(new Set(e).size!==e.length)throw x()}try{let i=await d(async o=>{let u=await f(t,"::actor::get_files",e===void 0?{}:{wire_ids:e},o);return await p(t,u.Reduce("files"))});return c(t),{files:i.files,text:i.text,mode:e===void 0?"all_unread":"selected",requested:e??null}}catch(i){let o=String(i);throw e!==void 0&&/unknown, stale, or no longer unread/i.test(o)?F():l("get_files",o)}}function P(n,r){let t=s(n);return{existsOnDisk:w(t,r.wire_id)!==null}}async function T(n,r){let t=s(n),{file_ids:e}=r;try{let i=await d(async o=>(await f(t,"::actor::defer_files",{file_ids:e},o)).Reduce("deferred").Visualize());return c(t),{deferred:i}}catch(i){throw l("defer_files",String(i))}}export{M as a,N as b,P as c,T as d};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{F as m,J as s,r as c,s as l,u as f}from"./chunk-
|
|
2
|
+
import{F as m,J as s,r as c,s as l,u as f}from"./chunk-4UYU3SJ3.js";import{c as o}from"./chunk-KIIBATGV.js";import{f as i,i as a}from"./chunk-WXVWLASM.js";var e=null,n=!1;function v(){e||(e=setInterval(()=>{n||(n=!0,(async()=>{try{for(let t of o.values()){try{await m(async r=>{await s(t,"::actor::gc",{},r)})}catch(r){a(`gc(${t.name}) failed:`,String(r))}await c(t),await l(t),await f(t)}}finally{n=!1}})())},i),e.unref?.(),a(`message GC timer armed (every ${i}ms)`))}function w(){e&&(clearInterval(e),e=null)}export{v as a,w as b};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{b as H}from"./chunk-YRPUM6JG.js";import{c as me}from"./chunk-JPG44TVX.js";import{d as de}from"./chunk-HVJRHUSY.js";import{a as L,c as x,d as k,e as J,f as se,g as oe,h as G,i as D,j as I,k as B,l as M,p as ae,w as ce}from"./chunk-2HS7JGHP.js";import{c as V,i as l,o as j,p as ne}from"./chunk-EHZNOPG6.js";import{a as ue}from"./chunk-LKFYUCN7.js";import{c as le,f as fe,g as pe}from"./chunk-XYU2DSWR.js";import{join as ke}from"node:path";import*as _ from"node:fs";import{AdaptObjectLifetime as $e}from"@adapt-toolkit/sdk/common";import{object_to_adapt_value as be}from"@adapt-toolkit/sdk/wrapper";import*as y from"node:fs";import{randomBytes as ze}from"node:crypto";import*as $ from"node:fs";import{randomBytes as Ve}from"node:crypto";import{PacketWrapperConfigurator as Te}from"@adapt-toolkit/sdk/wrappers";import{AdaptObjectLifetime as xe}from"@adapt-toolkit/sdk/common";function qe(e){let t=[],o=e.Reduce("degraded");if(o.IsNil())return t;for(let n=0;;n++){let a=o.Reduce(n);if(a.IsNil())break;t.push({cid:a.Reduce("container_id").Visualize(),name:a.Reduce("name").Visualize(),attempts:Number(a.Reduce("attempts").Visualize()),queued:Number(a.Reduce("queued").Visualize())})}return t}function Ie(e){let t=[],o=e.Reduce("queues");if(o.IsNil())return t;for(let n=0;;n++){let a=o.Reduce(n);if(a.IsNil())break;t.push({cid:a.Reduce("container_id").Visualize(),queued:Number(a.Reduce("queued").Visualize()),degraded:a.Reduce("degraded").GetBoolean()})}return t}async function Y(e,t){try{let o=await h(async n=>{let a=await v(e,"::a2a_messaging::flush_deferred",{contact:t},n);return Number(a.Reduce("flushed").Visualize())});o>0&&l(`[${e.name}] flushed ${o} deferred message(s) to ${t.slice(0,12)}\u2026`)}catch(o){l(`[${e.name}] deferred flush to ${t.slice(0,12)}\u2026 failed:`,String(o))}}async function ge(e){try{let t=await h(async n=>{let a=await v(e,"::a2a_messaging::restore_degraded_contacts",{},n);return Number(a.Reduce("requested").Visualize())});t>0&&l(`[${e.name}] contact restore requested for ${t} degraded contact(s)`);let o=S(n=>Ie(R(e,"::a2a_messaging::list_deferred_queues",n)));for(let n of o)n.degraded||await Y(e,n.cid)}catch(t){l(`[${e.name}] contact-restore sweep failed:`,String(t))}}async function Ne(e){try{let t=await h(async o=>{let n=await v(e,"::a2a_messaging::reconcile_advertise",{},o),a=u=>n.Reduce(u).IsNil()?0:Number(n.Reduce(u).Visualize());return{changed:/true/i.test(n.Reduce("changed").Visualize()),capabilityAdvertised:a("capability_advertised"),legacyReadvertised:a("legacy_readvertised")}});(t.capabilityAdvertised>0||t.legacyReadvertised>0)&&l(`[${e.name}] capability reconcile: changed=${t.changed} advertised=${t.capabilityAdvertised} legacy_migration_bootstrap=${t.legacyReadvertised}`)}catch(t){l(`[${e.name}] capability reconcile sweep failed:`,String(t))}}var K=new Set;function q(e){if(!K.has(e.name)){K.add(e.name);for(let t of[2e3,15e3])setTimeout(()=>{t===15e3&&K.delete(e.name);let o=x.get(e.name);o&&Ne(o)},t)}}async function Ce(e){try{let t=await h(async o=>{let n=await v(e,"::a2a_messaging::readvertise_e2e_recovery",{},o);return Number(n.Reduce("readvertised").Visualize())});t>0&&l(`[${e.name}] re-advertised fresh AD to ${t} e2e contact(s) (session recovery)`)}catch(t){l(`[${e.name}] e2e recovery re-advertise failed:`,String(t))}try{await h(async t=>{await v(e,"::a2a_messaging::sweep_e2e_migrations",{},t)})}catch(t){l(`[${e.name}] e2e migration sweep failed:`,String(t))}try{let t=await h(async o=>{let n=await v(e,"::a2a_messaging::redrive_unacked_sweep",{},o),a=u=>n.Reduce(u).IsNil()?0:Number(n.Reduce(u).Visualize());return{redriven:a("redriven_contacts"),purged:a("purged_contacts"),deferred:a("deferred_contacts")}});(t.redriven>0||t.purged>0||t.deferred>0)&&l(`[${e.name}] unacked sweep: redriven=${t.redriven} ttl_purged=${t.purged} deferred=${t.deferred} contact(s)`)}catch(t){l(`[${e.name}] unacked redrive sweep failed:`,String(t))}}function ye(e,t){e.pw.on_return_data=o=>{let n=new xe;o.Attach(n);try{let a=o.Reduce("kind").Visualize();if(a==="save_state"){z(e);return}if(a==="notify_agent"){let i=o.Reduce("payload"),f=i.Reduce("event").Visualize();if(f==="message_received"){let s=i.Reduce("sender_name").Visualize(),r=i.Reduce("sender_id"),c=r.IsNil()?"":r.Visualize(),d=i.Reduce("msg_id").Visualize(),p=i.Reduce("wire_id"),m=p.IsNil()?"":p.Visualize(),w=i.Reduce("date").Visualize();g(e,{event:"message_received",from:s,sender_name:s,sender_id:c,msg_id:d,wire_id:m,date:w}),P(e),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] new message from ${s} (#${d})`))}else if(f==="receipt_received"){let s=i.Reduce("sender_id"),r=s.IsNil()?"":String(s.Visualize()),c=i.Reduce("kind"),d=c.IsNil()?"":String(c.Visualize()),p=[],m=i.Reduce("wire_ids");if(!m.IsNil())for(let O=0;;O++){let re=m.Reduce(O);if(re.IsNil())break;p.push(String(re.Visualize()))}let w=i.Reduce("date"),b=w.IsNil()?new Date().toISOString():String(w.Visualize());g(e,{event:"receipt_received",sender_id:r,kind:d,wire_ids:p,date:b})}else if(f==="file_received"){let s=i.Reduce("sender_name").Visualize(),r=i.Reduce("sender_id").Visualize(),c=i.Reduce("file_id").Visualize(),d=i.Reduce("wire_id").Visualize(),p=i.Reduce("filename").Visualize(),m=i.Reduce("mime").Visualize(),w=i.Reduce("bytes").Visualize(),b=i.Reduce("date").Visualize();g(e,{event:"file_received",from:s,sender_id:r,file_id:c,wire_id:d,filename:p,mime:m,bytes:w,date:b}),P(e),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] new file ${p} (${w} B) from ${s} (sender_id ${r}, file_id ${c}, wire_id ${d})`))}else if(f==="contact_accepted"){let s=i.Reduce("name").Visualize(),r=i.Reduce("container_id").Visualize();q(e),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] contact "${s}" (${r}) accepted your invite.`))}else if(f==="local_contact_added"){let s=i.Reduce("name").Visualize(),r=i.Reduce("container_id").Visualize();q(e),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] local contact "${s}" (${r}) connected via the contact book.`))}else if(f==="contact_name_collision"){let s=i.Reduce("message").Visualize(),r=i.Reduce("desired").Visualize(),c=i.Reduce("assigned").Visualize(),d=i.Reduce("existing_container_id").Visualize(),p=i.Reduce("container_id").Visualize();g(e,{event:"contact_name_collision",desired:r,assigned:c,existing_container_id:d,container_id:p}),l(`[${e.name}] CONTACT NAME COLLISION \u2014 ${s}`),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] \u26A0 ${s}`))}else if(f==="sibling_contact_added"){let s=i.Reduce("name").Visualize(),r=i.Reduce("container_id").Visualize();g(e,{event:"sibling_contact_added",from:s}),q(e),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] sibling "${s}" (${r}) connected (intra-root auto-accept).`))}else if(f==="local_contact_request"){let s=i.Reduce("name").Visualize(),r=i.Reduce("container_id").Visualize();g(e,{event:"local_contact_request",from:s}),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] pending local introduction from "${s}" (${r}) \u2014 approve or reject with respond_to_introduction.`))}else if(f==="pending_message"){let s=i.Reduce("sender_name").Visualize(),r=i.Reduce("queued").Visualize();g(e,{event:"pending_message",from:s,queued:r}),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] "${s}" queued a message awaiting introduction approval (${r} queued).`))}else if(f==="e2e_restore_rejected")g(e,{event:"e2e_restore_rejected"}),l(`[${e.name}] E2E RESTORE REJECTED \u2014 corrupt session blob failed pickle_key validation; reset to empty e2e state, self-heal fallback will re-establish`),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] persisted e2e sessions were corrupt \u2014 rejected cleanly, sessions re-establishing`));else if(f==="contact_restored"){let s=i.Reduce("name").Visualize(),r=i.Reduce("container_id").Visualize();g(e,{event:"contact_restored",from:s}),l(`[${e.name}] contact "${s}" restored (re-keyed)`),process.nextTick(()=>void Y(e,String(r)))}else if(f==="migration_active"){let s=i.Reduce("cid").Visualize(),r=i.Reduce("role").Visualize(),c=T(i,"epoch"),d=T(i,"session_id");g(e,{event:"migration_active",cid:String(s),role:String(r),...c?{epoch:c}:{},...d?{session_id:d}:{}}),l(`[migration] active cid=${s} role=${r}${c?` epoch=${c}`:""}${d?` session_id=${d}`:""}`)}else if(f==="e2e_app_send"){let s=i.Reduce("cid").Visualize(),r=T(i,"session_id"),c=i.Reduce("olm_type").Visualize(),d=i.Reduce("wire_id").Visualize(),p=i.Reduce("retained").IsNil()?void 0:i.Reduce("retained").GetBoolean(),m=[],w=i.Reduce("evicted");if(!w.IsNil())for(let b=0;;b++){let O=w.Reduce(b);if(O.IsNil())break;m.push(String(O.Visualize()))}g(e,{event:"e2e_app_send",cid:String(s),session_id:r,olm_type:String(c),wire_id:String(d),...p===!1?{retained:!1}:{},...m.length?{evicted:m}:{}}),l(`[${e.name}] [e2e-app] send cid=${s} session_id=${r} olm_type=${c} wire_id=${d}${p===!1?" retained=false":""}${m.length?` evicted=${m.join(",")}`:""}`),m.length&&process.nextTick(()=>t.onNotify(e.name,`[${e.name}] redrive window overflow: ${m.length} older unacked send(s) lost their auto-resend guarantee (${m.join(", ")})`))}else if(f==="dedup_degraded"){let s=i.Reduce("cid").Visualize(),r=i.Reduce("dropped_wire_id").Visualize();g(e,{event:"dedup_degraded",cid:String(s),dropped_wire_id:String(r)}),l(`[${e.name}] [e2e-app] DEDUP DEGRADED cid=${s} dropped_wire_id=${r} (storage ceiling \u2014 a late redrive of that id could re-deposit)`),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] dedup window overflowed for ${String(s).slice(0,12)}\u2026 \u2014 one oldest entry dropped (guarantee loss surfaced)`))}else if(f==="e2e_delivery_expired"){let s=i.Reduce("cid").Visualize(),r=[],c=i.Reduce("wire_ids");if(!c.IsNil())for(let d=0;;d++){let p=c.Reduce(d);if(p.IsNil())break;r.push(String(p.Visualize()))}g(e,{event:"e2e_delivery_expired",cid:String(s),wire_ids:r}),l(`[${e.name}] [e2e-app] delivery EXPIRED (2-day TTL, receipt never arrived) cid=${s} wire_ids=${r.join(",")}`),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] ${r.length} message(s)/file(s) to ${String(s).slice(0,12)}\u2026 expired undelivered (no receipt within 2 days)`))}else if(f==="e2e_app_recv"){let s=i.Reduce("cid").Visualize(),r=T(i,"session_id"),c=i.Reduce("ok").GetBoolean(),d=i.Reduce("wire_id").Visualize(),p=i.Reduce("code").IsNil()?void 0:String(i.Reduce("code").Visualize()),m=!i.Reduce("duplicate").IsNil(),w=!i.Reduce("file").IsNil();g(e,{event:"e2e_app_recv",cid:String(s),session_id:r,ok:c,wire_id:String(d),...p?{code:p}:{},...m?{duplicate:!0}:{},...w?{file:!0}:{}}),l(`[${e.name}] [e2e-app] recv cid=${s} session_id=${r} ok=${c} wire_id=${d}${p?` code=${p}`:""}${m?" duplicate=true":""}${w?" file=true":""}`)}else if(f==="e2e_rekey"){let s=i.Reduce("cid").Visualize(),r=i.Reduce("role").Visualize(),c=T(i,"session_id"),d=i.Reduce("attempts").IsNil()?void 0:String(i.Reduce("attempts").Visualize()),p=i.Reduce("peer_supports").IsNil()?void 0:String(i.Reduce("peer_supports").Visualize()),m=i.Reduce("rejected").IsNil()?void 0:String(i.Reduce("rejected").Visualize());g(e,{event:"e2e_rekey",cid:String(s),role:String(r),...c?{session_id:c}:{},...d?{attempts:d}:{},...p?{peer_supports:p}:{},...m?{rejected:m}:{}}),l(`[${e.name}] [e2e-rekey] cid=${s} role=${r}${c?` session_id=${c}`:""}${d?` attempts=${d}`:""}${p?` peer_supports=${p}`:""}${m?` rejected=${m}`:""}`)}else if(f==="migration_deferred_flush"){let s=i.Reduce("cid").Visualize(),r=i.Reduce("wire_id").Visualize();g(e,{event:"migration_deferred_flush",cid:String(s),wire_id:String(r)}),l(`[migration] flush-notify cid=${s} wire_id=${r} (deferred\u2192e2e; core delivers)`)}else if(f==="migration_stalled"){let s=i.Reduce("cid").Visualize(),r=i.Reduce("phase").Visualize(),c=i.Reduce("attempts").Visualize();g(e,{event:"migration_stalled",cid:String(s),phase:String(r),attempts:String(c)}),l(`[migration] stalled-notify cid=${s} phase=${r} attempts=${c} (core re-drives via sweep)`)}else if(f==="downgrade_refused"){let s=i.Reduce("cid").Visualize(),r=i.Reduce("wire_id"),c=r.IsNil()?"":String(r.Visualize());g(e,{event:"downgrade_refused",cid:String(s),...c?{wire_id:c}:{}}),l(`[e2e-route] downgrade-dropped cid=${s}${c?` wire_id=${c}`:""} (legacy plaintext from a migrated peer \u2014 dropped by core)`),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] a message from a migrated contact was rejected as an unsafe downgrade (dropped).`))}else if(f==="contact_removed"){let s=String(i.Reduce("cid").Visualize()),r=de.has(e.name);g(e,{event:"contact_removed",cid:s,by:r?"local":"peer"}),r||(l(`[${e.name}] contact ${s} removed you (authenticated peer removal notice) \u2014 dropped from contacts`),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] contact ${s.slice(0,12)}\u2026 removed you as a contact (the removal was applied locally too).`)))}else if(f==="monitoring_disabled"){let s=String(i.Reduce("cid").Visualize()),r=i.Reduce("cause"),c=r.IsNil()?"":String(r.Visualize());g(e,{event:"monitoring_disabled",cid:s,...c?{cause:c}:{}}),l(`[${e.name}] monitoring disabled (cid=${s}${c?` cause=${c}`:""})`),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] the monitoring/control-plane binding was disabled${c==="control_plane_removed_contact"?" \u2014 the control plane removed you as a contact":""}.`))}else f==="control_request"||f==="host_provision_child"||f==="host_destroy_child"||f==="host_mint_child_invite"||f==="host_set_child_monitoring"?l(`[${e.name}] ${f}: the daemon-side control plane is removed \u2014 ignoring`):g(e,{event:f});return}let u=e.pending.shift();if(!u)return;clearTimeout(u.timer),u.resolve(o.Reduce("payload").Detach())}finally{n.Finalize()}},e.pw.on_transaction_failure=o=>{let n=e.pending.shift();n?(clearTimeout(n.timer),n.reject(new Error(o))):(l(`[${e.name}] inbound transaction rejected:`,o),g(e,{event:"inbound_error",message:o}),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] inbound transaction rejected: ${o}`)))}}import{join as Q}from"node:path";import*as N from"node:fs";var E=()=>Q(V,j),Z=()=>Q(E(),"registrar.key"),X=()=>Q(E(),"book.json");function _e(){try{let e=JSON.parse(N.readFileSync(X(),"utf8"));return e&&typeof e.entries=="object"?e.entries:{}}catch{return{}}}function we(e){N.mkdirSync(E(),{recursive:!0});let t=`${X()}.tmp`;N.writeFileSync(t,JSON.stringify({v:1,entries:e},null,2),{mode:384}),N.renameSync(t,X())}function ee(e){return S(t=>Buffer.from(R(e,"::actor::export_address_document",t).GetBinary()))}function C(e){return S(t=>Buffer.from(R(e,"::actor::export_signing_secret",t).Serialize()).toString("hex"))}async function he(e){if(!k)throw new Error("registrar is not available");let t=ee(e),o=await h(async a=>{let u=await v(k,"::actor::sign_book_entry",{name:e.name,ad:k.pw.packet.NewBinaryFromBuffer(t).Attach(a)},a);return Buffer.from(u.Reduce("sig").GetBinary()).toString("base64url")}),n=_e();n[e.name]={v:1,name:e.name,container_id:e.cid,address_document:t.toString("base64url"),published_at:new Date().toISOString(),registrar_sig:o},we(n),l(`[${e.name}] published to the local contact book`)}function rt(e){let t=_e(),o=Object.entries(t).find(([,n])=>n.container_id===e.cid);o&&(delete t[o[0]],we(t),l(`[${e.name}] removed from the local contact book (entry "${o[0]}")`))}async function ve(e){if(!J)throw new Error("registrar is not available");await h(async t=>{await v(e,"::actor::pin_registrar",{registrar_ad:e.pw.packet.NewBinaryFromBuffer(J).Attach(t)},t)})}function U(e,t,o,n=!0,a,u=!1){let i=new Te;i.deferred_exposure=u;let f=["--unit_hash",H.hash,"--seed_phrase",t,"--unit_dir_path",H.dir];return a&&f.push("--init_trn_argument",JSON.stringify(a)),i.process_arguments(f),new Promise((s,r)=>{let c=setTimeout(()=>r(new Error(`packet creation for "${e}" timed out`)),3e4);L.packet_manager.create_packet(i,d=>{clearTimeout(c);let p={name:e,cid:S(m=>d.packet.GetContainerID().Attach(m).Visualize()),pw:d,dir:o,pending:[],lock:Promise.resolve()};ye(p,Se),n&&x.set(e,p),l(`[${e}] packet created \u2014 container id ${p.cid}`),s(p)},H.contents)})}var A=new Set(ce());A.size>0&&l(`reserved ${A.size} persisted identity name(s) at module load: ${[...A].join(", ")}`);async function yt(e,t={exposeLocal:!0,localAutoAccept:!0}){if(A.has(e)||x.has(e))throw new Error(`identity name "${e}" is reserved \u2014 a persisted identity with this name is restoring, present, or being provisioned; refusing to provision over it`);A.add(e);try{let o=G(e);$.mkdirSync(o,{recursive:!0,mode:448});let n;t.temp&&(n={owner:{tokenHash:t.temp.tokenHash,pid:t.temp.pid},createdAt:Date.now()},ae(o,n));let a=Ve(24).toString("hex"),u=await U(e,a,o);return n&&(u.temp=n),$.writeFileSync(D(o),C(u),{mode:384}),await h(async i=>{await v(u,"::a2a_messaging::set_my_name",{name:e},i)}),await ve(u),t.localAutoAccept||await h(async i=>{await v(u,"::actor::set_local_policy",{auto_accept:!1},i)}),t.exposeLocal&&await he(u),z(u),u}catch(o){throw A.delete(e),o}}async function _t(e){let t=G(e),o=$.readFileSync(D(t),"utf8").trim(),n=await U(e,"",t,!1,o,!0);l(`[${e}] created QUARANTINED (no routing/broker registration, not client-bindable) \u2014 importing state before exposure`);let a=Number(process.env.OURS_TEST_RESTORE_HOLD_MS||"")||0;a>0&&(l(`[${e}] TEST HOLD: keeping restore open ${a}ms (OURS_TEST_RESTORE_HOLD_MS)`),await new Promise(s=>setTimeout(s,a)));let u=s=>/timed out waiting for the transaction result/.test(String(s)),i=(s,r,c)=>{l(`[${e}] ${s} ${r} \u2014 identity left UNEXPOSED and UNTRACKED (fail-closed)`);try{g(n,{event:"restore_fail_closed",step:s,error:String(c).slice(0,300)})}catch{}x.delete(e);try{L.remove_packet(n.cid)}catch(d){l(`[${e}] quarantined-packet teardown failed:`,String(d))}throw new Error(`identity "${e}": ${s} failed during restore (${r}) \u2014 left unexposed (fail-closed)`)},f=(s,r)=>i(s,"outcome UNKNOWN (timeout): the transaction may still execute and exposure would race it",r);if(Re(t)){let s=!1;try{if(process.env.OURS_TEST_FORCE_IMPORT_TIMEOUT==="1")throw new Error("timed out waiting for the transaction result (forced by OURS_TEST_FORCE_IMPORT_TIMEOUT)");let r=$.readFileSync(I(t));await h(async c=>{let d=n.pw.packet.ParseValue(new Uint8Array(r)).Attach(c),p=Number(process.env.OURS_IMPORT_TIMEOUT_MS||"")||void 0;await v(n,"::actor::import_state",d,c,p)}),s=!0,l(`[${e}] state import completed (positively observed)`)}catch(r){u(r)&&f("import_state",r),l(`[${e}] FAILED TO IMPORT SAVED STATE \u2014 continuing with the reseeded identity; surviving contacts (if the blob was partially migrated) self-heal via contact restore:`,String(r)),g(n,{event:"state_import_failed",error:String(r).slice(0,300)});try{let c=`${I(t)}.failed-${Date.now()}`;$.renameSync(I(t),c),$.chmodSync(c,384),l(`[${e}] unreadable state blob preserved as state_data.bin.failed-*`)}catch{}}if(s){try{let d=await h(async p=>{let m=await v(n,"::a2a_messaging::commit_e2e_restore",{},p),w=m.Reduce("status").Visualize(),b=m.Reduce("sessions").IsNil()?"0":m.Reduce("sessions").Visualize();return{status:String(w),sessions:String(b)}});l(`[${e}] e2e restore commit: status=${d.status} sessions=${d.sessions}`)}catch(d){u(d)&&f("commit_e2e_restore",d),l(`[${e}] E2E RESTORE REJECTED \u2014 staged session blob failed pickle_key validation; discarding it, fresh account + self-heal fallback take over: ${String(d).slice(0,260)}`),g(n,{event:"e2e_restore_rejected",origin:"restore",error:String(d).slice(0,300)});try{await h(async p=>{await v(n,"::a2a_messaging::reject_e2e_restore",{},p)})}catch(p){u(p)&&f("reject_e2e_restore",p),l(`[${e}] reject_e2e_restore failed (staging is transient; continuing):`,String(p))}}try{n.pw.refresh_identity_proof_document(),l(`[${e}] transport IPD refreshed from post-import state`)}catch(d){i("ipd_refresh","FAILED (IPD would advertise a stale bundle)",d)}let r=!1,c="";try{if(process.env.OURS_TEST_FORCE_IPD_INCOHERENT==="1")throw new Error("forced incoherent (OURS_TEST_FORCE_IPD_INCOHERENT)");let d=S(w=>String(R(n,"::a2a_messaging::e2e_self_fp",w).Reduce("ik").Visualize())),p=n.pw.identity_proof_document.Visualize(),m=d.replace(/^0x/i,"");r=m.length>=32&&p.toLowerCase().includes(m.toLowerCase()),c=d.slice(0,18),g(n,{event:"ipd_coherence",ik:d,coherent:r})}catch(d){i("ipd_coherence","probe FAILED (coherence unprovable)",d)}l(`[${e}] IPD/e2e coherence: account_ik=${c}\u2026 ipd_advertises_it=${r}`),r||i("ipd_coherence","IPD does NOT advertise the live account ik",new Error("incoherent transport IPD"))}}return L.expose_packet(n.cid),x.set(e,n),l(`[${e}] EXPOSED (routing + broker registration) \u2014 import phase complete`),await ge(n),P(n),n}async function It(){y.mkdirSync(E(),{recursive:!0});let e;try{e=y.readFileSync(Z(),"utf8").trim()}catch{}let t=ze(24).toString("hex");se(await U(j,t,E(),!1,e)),e||y.writeFileSync(Z(),C(k),{mode:384}),oe(ee(k)),l(`contact-book registrar ready (${k.cid})`)}function Re(e){try{return y.existsSync(I(e))&&y.statSync(I(e)).size>0}catch{return!1}}function Ee(e){let t=S(u=>Buffer.from(R(e,"::actor::export_state",u).Serialize()));y.mkdirSync(e.dir,{recursive:!0,mode:448});let o=I(e.dir),n=`${o}.tmp`,a;try{a=y.openSync(n,"w",384),y.fchmodSync(a,384),y.writeFileSync(a,t),y.fsyncSync(a),y.closeSync(a),a=void 0,y.renameSync(n,o),y.chmodSync(o,384);try{y.chmodSync(D(e.dir),384)}catch{}let u=y.openSync(e.dir,"r");try{y.fsyncSync(u)}finally{y.closeSync(u)}}catch(u){if(a!==void 0)try{y.closeSync(a)}catch{}try{y.rmSync(n,{force:!0})}catch{}throw u}}function z(e){try{Ee(e),e.persistFailed&&(e.persistFailed=!1,l(`[${e.name}] persist recovered \u2014 quarantine lifted`),g(e,{event:"persist_recovered"}))}catch(t){e.persistFailed=!0,l(`[${e.name}] PERSIST FAILED \u2014 identity quarantined (fail-closed), outbound of this txn withheld:`,String(t));try{g(e,{event:"persist_failed",error:String(t).slice(0,300)})}catch{}throw process.nextTick(()=>te(e.name,`[${e.name}] PERSIST FAILED \u2014 messaging quarantined until the state file is writable again`)),t}}function S(e){let t=new $e;try{return e(t)}finally{t.Finalize()}}async function h(e){let t=new $e;try{return await e(t)}finally{t.Finalize()}}function R(e,t,o,n){let a=be({name:t,targ:n}),u=e.pw.packet.ExecuteTransaction(a);return a.Destroy(),o?u.Attach(o):u}async function Ae(e,t){let o=e.lock,n;e.lock=new Promise(a=>n=a),await o;try{return await t()}finally{n()}}function Oe(e,t,o=25e3){return new Promise((n,a)=>{let u=setTimeout(()=>{let i=e.pending.findIndex(f=>f.timer===u);i>=0&&e.pending.splice(i,1),a(new Error("timed out waiting for the transaction result"))},o);e.pending.push({resolve:n,reject:a,timer:u}),e.pw.add_client_message(t)})}function v(e,t,o,n,a){if(e.persistFailed)try{z(e)}catch(i){return Promise.reject(new Error(`identity "${e.name}" is quarantined: state persist is failing (${String(i)}) \u2014 mutations are rejected until state_data.bin is writable again`))}let u=be({name:t,targ:o});return Ae(e,()=>Oe(e,u,a)).then(i=>{if(u.Destroy(),e.persistFailed){try{i.Destroy()}catch{}throw new Error(`identity "${e.name}": state persist FAILED \u2014 this transaction's outbound was withheld (fail-closed); fix the state directory and retry`)}return n?i.Attach(n):i},i=>{try{u.Destroy()}catch{}throw i})}var F=null;function Lt(e){F?.uninstall(),F=e===null?null:{hook:e,uninstall:le("notification",e)}}function Bt(e){F?.hook===e&&(F.uninstall(),F=null)}function te(e,t){pe(e,t)}var Se={onNotify:(e,t)=>te(e,t)},W=new Map;function De(e){let t=W.get(e);if(!(!t||t.size===0))for(let o of[...t])try{o()}catch{}}function Pe(e,t){return new Promise(o=>{let n=W.get(e);n||(n=new Set,W.set(e,n));let a=!1,u=()=>{a||(a=!0,n.delete(i),n.size===0&&W.delete(e),clearTimeout(f),o())},i=u,f=setTimeout(u,t);n.add(i)})}function g(e,t){try{_.mkdirSync(e.dir,{recursive:!0,mode:448}),_.appendFileSync(B(e.dir),JSON.stringify(t)+`
|
|
2
|
+
import{b as H}from"./chunk-YRPUM6JG.js";import{c as me}from"./chunk-VVPDTS5O.js";import{d as de}from"./chunk-OCBN326X.js";import{a as L,c as x,d as k,e as J,f as se,g as oe,h as G,i as D,j as I,k as B,l as M,p as ae,w as ce}from"./chunk-KIIBATGV.js";import{c as V,i as l,o as j,p as ne}from"./chunk-WXVWLASM.js";import{a as ue}from"./chunk-LKFYUCN7.js";import{c as le,f as fe,g as pe}from"./chunk-XYU2DSWR.js";import{join as ke}from"node:path";import*as _ from"node:fs";import{AdaptObjectLifetime as $e}from"@adapt-toolkit/sdk/common";import{object_to_adapt_value as be}from"@adapt-toolkit/sdk/wrapper";import*as y from"node:fs";import{randomBytes as ze}from"node:crypto";import*as $ from"node:fs";import{randomBytes as Ve}from"node:crypto";import{PacketWrapperConfigurator as Te}from"@adapt-toolkit/sdk/wrappers";import{AdaptObjectLifetime as xe}from"@adapt-toolkit/sdk/common";function qe(e){let t=[],o=e.Reduce("degraded");if(o.IsNil())return t;for(let n=0;;n++){let a=o.Reduce(n);if(a.IsNil())break;t.push({cid:a.Reduce("container_id").Visualize(),name:a.Reduce("name").Visualize(),attempts:Number(a.Reduce("attempts").Visualize()),queued:Number(a.Reduce("queued").Visualize())})}return t}function Ie(e){let t=[],o=e.Reduce("queues");if(o.IsNil())return t;for(let n=0;;n++){let a=o.Reduce(n);if(a.IsNil())break;t.push({cid:a.Reduce("container_id").Visualize(),queued:Number(a.Reduce("queued").Visualize()),degraded:a.Reduce("degraded").GetBoolean()})}return t}async function Y(e,t){try{let o=await h(async n=>{let a=await v(e,"::a2a_messaging::flush_deferred",{contact:t},n);return Number(a.Reduce("flushed").Visualize())});o>0&&l(`[${e.name}] flushed ${o} deferred message(s) to ${t.slice(0,12)}\u2026`)}catch(o){l(`[${e.name}] deferred flush to ${t.slice(0,12)}\u2026 failed:`,String(o))}}async function ge(e){try{let t=await h(async n=>{let a=await v(e,"::a2a_messaging::restore_degraded_contacts",{},n);return Number(a.Reduce("requested").Visualize())});t>0&&l(`[${e.name}] contact restore requested for ${t} degraded contact(s)`);let o=S(n=>Ie(R(e,"::a2a_messaging::list_deferred_queues",n)));for(let n of o)n.degraded||await Y(e,n.cid)}catch(t){l(`[${e.name}] contact-restore sweep failed:`,String(t))}}async function Ne(e){try{let t=await h(async o=>{let n=await v(e,"::a2a_messaging::reconcile_advertise",{},o),a=u=>n.Reduce(u).IsNil()?0:Number(n.Reduce(u).Visualize());return{changed:/true/i.test(n.Reduce("changed").Visualize()),capabilityAdvertised:a("capability_advertised"),legacyReadvertised:a("legacy_readvertised")}});(t.capabilityAdvertised>0||t.legacyReadvertised>0)&&l(`[${e.name}] capability reconcile: changed=${t.changed} advertised=${t.capabilityAdvertised} legacy_migration_bootstrap=${t.legacyReadvertised}`)}catch(t){l(`[${e.name}] capability reconcile sweep failed:`,String(t))}}var K=new Set;function q(e){if(!K.has(e.name)){K.add(e.name);for(let t of[2e3,15e3])setTimeout(()=>{t===15e3&&K.delete(e.name);let o=x.get(e.name);o&&Ne(o)},t)}}async function Ce(e){try{let t=await h(async o=>{let n=await v(e,"::a2a_messaging::readvertise_e2e_recovery",{},o);return Number(n.Reduce("readvertised").Visualize())});t>0&&l(`[${e.name}] re-advertised fresh AD to ${t} e2e contact(s) (session recovery)`)}catch(t){l(`[${e.name}] e2e recovery re-advertise failed:`,String(t))}try{await h(async t=>{await v(e,"::a2a_messaging::sweep_e2e_migrations",{},t)})}catch(t){l(`[${e.name}] e2e migration sweep failed:`,String(t))}try{let t=await h(async o=>{let n=await v(e,"::a2a_messaging::redrive_unacked_sweep",{},o),a=u=>n.Reduce(u).IsNil()?0:Number(n.Reduce(u).Visualize());return{redriven:a("redriven_contacts"),purged:a("purged_contacts"),deferred:a("deferred_contacts")}});(t.redriven>0||t.purged>0||t.deferred>0)&&l(`[${e.name}] unacked sweep: redriven=${t.redriven} ttl_purged=${t.purged} deferred=${t.deferred} contact(s)`)}catch(t){l(`[${e.name}] unacked redrive sweep failed:`,String(t))}}function ye(e,t){e.pw.on_return_data=o=>{let n=new xe;o.Attach(n);try{let a=o.Reduce("kind").Visualize();if(a==="save_state"){z(e);return}if(a==="notify_agent"){let i=o.Reduce("payload"),f=i.Reduce("event").Visualize();if(f==="message_received"){let s=i.Reduce("sender_name").Visualize(),r=i.Reduce("sender_id"),c=r.IsNil()?"":r.Visualize(),d=i.Reduce("msg_id").Visualize(),p=i.Reduce("wire_id"),m=p.IsNil()?"":p.Visualize(),w=i.Reduce("date").Visualize();g(e,{event:"message_received",from:s,sender_name:s,sender_id:c,msg_id:d,wire_id:m,date:w}),P(e),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] new message from ${s} (#${d})`))}else if(f==="receipt_received"){let s=i.Reduce("sender_id"),r=s.IsNil()?"":String(s.Visualize()),c=i.Reduce("kind"),d=c.IsNil()?"":String(c.Visualize()),p=[],m=i.Reduce("wire_ids");if(!m.IsNil())for(let O=0;;O++){let re=m.Reduce(O);if(re.IsNil())break;p.push(String(re.Visualize()))}let w=i.Reduce("date"),b=w.IsNil()?new Date().toISOString():String(w.Visualize());g(e,{event:"receipt_received",sender_id:r,kind:d,wire_ids:p,date:b})}else if(f==="file_received"){let s=i.Reduce("sender_name").Visualize(),r=i.Reduce("sender_id").Visualize(),c=i.Reduce("file_id").Visualize(),d=i.Reduce("wire_id").Visualize(),p=i.Reduce("filename").Visualize(),m=i.Reduce("mime").Visualize(),w=i.Reduce("bytes").Visualize(),b=i.Reduce("date").Visualize();g(e,{event:"file_received",from:s,sender_id:r,file_id:c,wire_id:d,filename:p,mime:m,bytes:w,date:b}),P(e),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] new file ${p} (${w} B) from ${s} (sender_id ${r}, file_id ${c}, wire_id ${d})`))}else if(f==="contact_accepted"){let s=i.Reduce("name").Visualize(),r=i.Reduce("container_id").Visualize();q(e),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] contact "${s}" (${r}) accepted your invite.`))}else if(f==="local_contact_added"){let s=i.Reduce("name").Visualize(),r=i.Reduce("container_id").Visualize();q(e),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] local contact "${s}" (${r}) connected via the contact book.`))}else if(f==="contact_name_collision"){let s=i.Reduce("message").Visualize(),r=i.Reduce("desired").Visualize(),c=i.Reduce("assigned").Visualize(),d=i.Reduce("existing_container_id").Visualize(),p=i.Reduce("container_id").Visualize();g(e,{event:"contact_name_collision",desired:r,assigned:c,existing_container_id:d,container_id:p}),l(`[${e.name}] CONTACT NAME COLLISION \u2014 ${s}`),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] \u26A0 ${s}`))}else if(f==="sibling_contact_added"){let s=i.Reduce("name").Visualize(),r=i.Reduce("container_id").Visualize();g(e,{event:"sibling_contact_added",from:s}),q(e),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] sibling "${s}" (${r}) connected (intra-root auto-accept).`))}else if(f==="local_contact_request"){let s=i.Reduce("name").Visualize(),r=i.Reduce("container_id").Visualize();g(e,{event:"local_contact_request",from:s}),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] pending local introduction from "${s}" (${r}) \u2014 approve or reject with respond_to_introduction.`))}else if(f==="pending_message"){let s=i.Reduce("sender_name").Visualize(),r=i.Reduce("queued").Visualize();g(e,{event:"pending_message",from:s,queued:r}),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] "${s}" queued a message awaiting introduction approval (${r} queued).`))}else if(f==="e2e_restore_rejected")g(e,{event:"e2e_restore_rejected"}),l(`[${e.name}] E2E RESTORE REJECTED \u2014 corrupt session blob failed pickle_key validation; reset to empty e2e state, self-heal fallback will re-establish`),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] persisted e2e sessions were corrupt \u2014 rejected cleanly, sessions re-establishing`));else if(f==="contact_restored"){let s=i.Reduce("name").Visualize(),r=i.Reduce("container_id").Visualize();g(e,{event:"contact_restored",from:s}),l(`[${e.name}] contact "${s}" restored (re-keyed)`),process.nextTick(()=>void Y(e,String(r)))}else if(f==="migration_active"){let s=i.Reduce("cid").Visualize(),r=i.Reduce("role").Visualize(),c=T(i,"epoch"),d=T(i,"session_id");g(e,{event:"migration_active",cid:String(s),role:String(r),...c?{epoch:c}:{},...d?{session_id:d}:{}}),l(`[migration] active cid=${s} role=${r}${c?` epoch=${c}`:""}${d?` session_id=${d}`:""}`)}else if(f==="e2e_app_send"){let s=i.Reduce("cid").Visualize(),r=T(i,"session_id"),c=i.Reduce("olm_type").Visualize(),d=i.Reduce("wire_id").Visualize(),p=i.Reduce("retained").IsNil()?void 0:i.Reduce("retained").GetBoolean(),m=[],w=i.Reduce("evicted");if(!w.IsNil())for(let b=0;;b++){let O=w.Reduce(b);if(O.IsNil())break;m.push(String(O.Visualize()))}g(e,{event:"e2e_app_send",cid:String(s),session_id:r,olm_type:String(c),wire_id:String(d),...p===!1?{retained:!1}:{},...m.length?{evicted:m}:{}}),l(`[${e.name}] [e2e-app] send cid=${s} session_id=${r} olm_type=${c} wire_id=${d}${p===!1?" retained=false":""}${m.length?` evicted=${m.join(",")}`:""}`),m.length&&process.nextTick(()=>t.onNotify(e.name,`[${e.name}] redrive window overflow: ${m.length} older unacked send(s) lost their auto-resend guarantee (${m.join(", ")})`))}else if(f==="dedup_degraded"){let s=i.Reduce("cid").Visualize(),r=i.Reduce("dropped_wire_id").Visualize();g(e,{event:"dedup_degraded",cid:String(s),dropped_wire_id:String(r)}),l(`[${e.name}] [e2e-app] DEDUP DEGRADED cid=${s} dropped_wire_id=${r} (storage ceiling \u2014 a late redrive of that id could re-deposit)`),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] dedup window overflowed for ${String(s).slice(0,12)}\u2026 \u2014 one oldest entry dropped (guarantee loss surfaced)`))}else if(f==="e2e_delivery_expired"){let s=i.Reduce("cid").Visualize(),r=[],c=i.Reduce("wire_ids");if(!c.IsNil())for(let d=0;;d++){let p=c.Reduce(d);if(p.IsNil())break;r.push(String(p.Visualize()))}g(e,{event:"e2e_delivery_expired",cid:String(s),wire_ids:r}),l(`[${e.name}] [e2e-app] delivery EXPIRED (2-day TTL, receipt never arrived) cid=${s} wire_ids=${r.join(",")}`),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] ${r.length} message(s)/file(s) to ${String(s).slice(0,12)}\u2026 expired undelivered (no receipt within 2 days)`))}else if(f==="e2e_app_recv"){let s=i.Reduce("cid").Visualize(),r=T(i,"session_id"),c=i.Reduce("ok").GetBoolean(),d=i.Reduce("wire_id").Visualize(),p=i.Reduce("code").IsNil()?void 0:String(i.Reduce("code").Visualize()),m=!i.Reduce("duplicate").IsNil(),w=!i.Reduce("file").IsNil();g(e,{event:"e2e_app_recv",cid:String(s),session_id:r,ok:c,wire_id:String(d),...p?{code:p}:{},...m?{duplicate:!0}:{},...w?{file:!0}:{}}),l(`[${e.name}] [e2e-app] recv cid=${s} session_id=${r} ok=${c} wire_id=${d}${p?` code=${p}`:""}${m?" duplicate=true":""}${w?" file=true":""}`)}else if(f==="e2e_rekey"){let s=i.Reduce("cid").Visualize(),r=i.Reduce("role").Visualize(),c=T(i,"session_id"),d=i.Reduce("attempts").IsNil()?void 0:String(i.Reduce("attempts").Visualize()),p=i.Reduce("peer_supports").IsNil()?void 0:String(i.Reduce("peer_supports").Visualize()),m=i.Reduce("rejected").IsNil()?void 0:String(i.Reduce("rejected").Visualize());g(e,{event:"e2e_rekey",cid:String(s),role:String(r),...c?{session_id:c}:{},...d?{attempts:d}:{},...p?{peer_supports:p}:{},...m?{rejected:m}:{}}),l(`[${e.name}] [e2e-rekey] cid=${s} role=${r}${c?` session_id=${c}`:""}${d?` attempts=${d}`:""}${p?` peer_supports=${p}`:""}${m?` rejected=${m}`:""}`)}else if(f==="migration_deferred_flush"){let s=i.Reduce("cid").Visualize(),r=i.Reduce("wire_id").Visualize();g(e,{event:"migration_deferred_flush",cid:String(s),wire_id:String(r)}),l(`[migration] flush-notify cid=${s} wire_id=${r} (deferred\u2192e2e; core delivers)`)}else if(f==="migration_stalled"){let s=i.Reduce("cid").Visualize(),r=i.Reduce("phase").Visualize(),c=i.Reduce("attempts").Visualize();g(e,{event:"migration_stalled",cid:String(s),phase:String(r),attempts:String(c)}),l(`[migration] stalled-notify cid=${s} phase=${r} attempts=${c} (core re-drives via sweep)`)}else if(f==="downgrade_refused"){let s=i.Reduce("cid").Visualize(),r=i.Reduce("wire_id"),c=r.IsNil()?"":String(r.Visualize());g(e,{event:"downgrade_refused",cid:String(s),...c?{wire_id:c}:{}}),l(`[e2e-route] downgrade-dropped cid=${s}${c?` wire_id=${c}`:""} (legacy plaintext from a migrated peer \u2014 dropped by core)`),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] a message from a migrated contact was rejected as an unsafe downgrade (dropped).`))}else if(f==="contact_removed"){let s=String(i.Reduce("cid").Visualize()),r=de.has(e.name);g(e,{event:"contact_removed",cid:s,by:r?"local":"peer"}),r||(l(`[${e.name}] contact ${s} removed you (authenticated peer removal notice) \u2014 dropped from contacts`),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] contact ${s.slice(0,12)}\u2026 removed you as a contact (the removal was applied locally too).`)))}else if(f==="monitoring_disabled"){let s=String(i.Reduce("cid").Visualize()),r=i.Reduce("cause"),c=r.IsNil()?"":String(r.Visualize());g(e,{event:"monitoring_disabled",cid:s,...c?{cause:c}:{}}),l(`[${e.name}] monitoring disabled (cid=${s}${c?` cause=${c}`:""})`),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] the monitoring/control-plane binding was disabled${c==="control_plane_removed_contact"?" \u2014 the control plane removed you as a contact":""}.`))}else f==="control_request"||f==="host_provision_child"||f==="host_destroy_child"||f==="host_mint_child_invite"||f==="host_set_child_monitoring"?l(`[${e.name}] ${f}: the daemon-side control plane is removed \u2014 ignoring`):g(e,{event:f});return}let u=e.pending.shift();if(!u)return;clearTimeout(u.timer),u.resolve(o.Reduce("payload").Detach())}finally{n.Finalize()}},e.pw.on_transaction_failure=o=>{let n=e.pending.shift();n?(clearTimeout(n.timer),n.reject(new Error(o))):(l(`[${e.name}] inbound transaction rejected:`,o),g(e,{event:"inbound_error",message:o}),process.nextTick(()=>t.onNotify(e.name,`[${e.name}] inbound transaction rejected: ${o}`)))}}import{join as Q}from"node:path";import*as N from"node:fs";var E=()=>Q(V,j),Z=()=>Q(E(),"registrar.key"),X=()=>Q(E(),"book.json");function _e(){try{let e=JSON.parse(N.readFileSync(X(),"utf8"));return e&&typeof e.entries=="object"?e.entries:{}}catch{return{}}}function we(e){N.mkdirSync(E(),{recursive:!0});let t=`${X()}.tmp`;N.writeFileSync(t,JSON.stringify({v:1,entries:e},null,2),{mode:384}),N.renameSync(t,X())}function ee(e){return S(t=>Buffer.from(R(e,"::actor::export_address_document",t).GetBinary()))}function C(e){return S(t=>Buffer.from(R(e,"::actor::export_signing_secret",t).Serialize()).toString("hex"))}async function he(e){if(!k)throw new Error("registrar is not available");let t=ee(e),o=await h(async a=>{let u=await v(k,"::actor::sign_book_entry",{name:e.name,ad:k.pw.packet.NewBinaryFromBuffer(t).Attach(a)},a);return Buffer.from(u.Reduce("sig").GetBinary()).toString("base64url")}),n=_e();n[e.name]={v:1,name:e.name,container_id:e.cid,address_document:t.toString("base64url"),published_at:new Date().toISOString(),registrar_sig:o},we(n),l(`[${e.name}] published to the local contact book`)}function rt(e){let t=_e(),o=Object.entries(t).find(([,n])=>n.container_id===e.cid);o&&(delete t[o[0]],we(t),l(`[${e.name}] removed from the local contact book (entry "${o[0]}")`))}async function ve(e){if(!J)throw new Error("registrar is not available");await h(async t=>{await v(e,"::actor::pin_registrar",{registrar_ad:e.pw.packet.NewBinaryFromBuffer(J).Attach(t)},t)})}function U(e,t,o,n=!0,a,u=!1){let i=new Te;i.deferred_exposure=u;let f=["--unit_hash",H.hash,"--seed_phrase",t,"--unit_dir_path",H.dir];return a&&f.push("--init_trn_argument",JSON.stringify(a)),i.process_arguments(f),new Promise((s,r)=>{let c=setTimeout(()=>r(new Error(`packet creation for "${e}" timed out`)),3e4);L.packet_manager.create_packet(i,d=>{clearTimeout(c);let p={name:e,cid:S(m=>d.packet.GetContainerID().Attach(m).Visualize()),pw:d,dir:o,pending:[],lock:Promise.resolve()};ye(p,Se),n&&x.set(e,p),l(`[${e}] packet created \u2014 container id ${p.cid}`),s(p)},H.contents)})}var A=new Set(ce());A.size>0&&l(`reserved ${A.size} persisted identity name(s) at module load: ${[...A].join(", ")}`);async function yt(e,t={exposeLocal:!0,localAutoAccept:!0}){if(A.has(e)||x.has(e))throw new Error(`identity name "${e}" is reserved \u2014 a persisted identity with this name is restoring, present, or being provisioned; refusing to provision over it`);A.add(e);try{let o=G(e);$.mkdirSync(o,{recursive:!0,mode:448});let n;t.temp&&(n={owner:{tokenHash:t.temp.tokenHash,pid:t.temp.pid},createdAt:Date.now()},ae(o,n));let a=Ve(24).toString("hex"),u=await U(e,a,o);return n&&(u.temp=n),$.writeFileSync(D(o),C(u),{mode:384}),await h(async i=>{await v(u,"::a2a_messaging::set_my_name",{name:e},i)}),await ve(u),t.localAutoAccept||await h(async i=>{await v(u,"::actor::set_local_policy",{auto_accept:!1},i)}),t.exposeLocal&&await he(u),z(u),u}catch(o){throw A.delete(e),o}}async function _t(e){let t=G(e),o=$.readFileSync(D(t),"utf8").trim(),n=await U(e,"",t,!1,o,!0);l(`[${e}] created QUARANTINED (no routing/broker registration, not client-bindable) \u2014 importing state before exposure`);let a=Number(process.env.OURS_TEST_RESTORE_HOLD_MS||"")||0;a>0&&(l(`[${e}] TEST HOLD: keeping restore open ${a}ms (OURS_TEST_RESTORE_HOLD_MS)`),await new Promise(s=>setTimeout(s,a)));let u=s=>/timed out waiting for the transaction result/.test(String(s)),i=(s,r,c)=>{l(`[${e}] ${s} ${r} \u2014 identity left UNEXPOSED and UNTRACKED (fail-closed)`);try{g(n,{event:"restore_fail_closed",step:s,error:String(c).slice(0,300)})}catch{}x.delete(e);try{L.remove_packet(n.cid)}catch(d){l(`[${e}] quarantined-packet teardown failed:`,String(d))}throw new Error(`identity "${e}": ${s} failed during restore (${r}) \u2014 left unexposed (fail-closed)`)},f=(s,r)=>i(s,"outcome UNKNOWN (timeout): the transaction may still execute and exposure would race it",r);if(Re(t)){let s=!1;try{if(process.env.OURS_TEST_FORCE_IMPORT_TIMEOUT==="1")throw new Error("timed out waiting for the transaction result (forced by OURS_TEST_FORCE_IMPORT_TIMEOUT)");let r=$.readFileSync(I(t));await h(async c=>{let d=n.pw.packet.ParseValue(new Uint8Array(r)).Attach(c),p=Number(process.env.OURS_IMPORT_TIMEOUT_MS||"")||void 0;await v(n,"::actor::import_state",d,c,p)}),s=!0,l(`[${e}] state import completed (positively observed)`)}catch(r){u(r)&&f("import_state",r),l(`[${e}] FAILED TO IMPORT SAVED STATE \u2014 continuing with the reseeded identity; surviving contacts (if the blob was partially migrated) self-heal via contact restore:`,String(r)),g(n,{event:"state_import_failed",error:String(r).slice(0,300)});try{let c=`${I(t)}.failed-${Date.now()}`;$.renameSync(I(t),c),$.chmodSync(c,384),l(`[${e}] unreadable state blob preserved as state_data.bin.failed-*`)}catch{}}if(s){try{let d=await h(async p=>{let m=await v(n,"::a2a_messaging::commit_e2e_restore",{},p),w=m.Reduce("status").Visualize(),b=m.Reduce("sessions").IsNil()?"0":m.Reduce("sessions").Visualize();return{status:String(w),sessions:String(b)}});l(`[${e}] e2e restore commit: status=${d.status} sessions=${d.sessions}`)}catch(d){u(d)&&f("commit_e2e_restore",d),l(`[${e}] E2E RESTORE REJECTED \u2014 staged session blob failed pickle_key validation; discarding it, fresh account + self-heal fallback take over: ${String(d).slice(0,260)}`),g(n,{event:"e2e_restore_rejected",origin:"restore",error:String(d).slice(0,300)});try{await h(async p=>{await v(n,"::a2a_messaging::reject_e2e_restore",{},p)})}catch(p){u(p)&&f("reject_e2e_restore",p),l(`[${e}] reject_e2e_restore failed (staging is transient; continuing):`,String(p))}}try{n.pw.refresh_identity_proof_document(),l(`[${e}] transport IPD refreshed from post-import state`)}catch(d){i("ipd_refresh","FAILED (IPD would advertise a stale bundle)",d)}let r=!1,c="";try{if(process.env.OURS_TEST_FORCE_IPD_INCOHERENT==="1")throw new Error("forced incoherent (OURS_TEST_FORCE_IPD_INCOHERENT)");let d=S(w=>String(R(n,"::a2a_messaging::e2e_self_fp",w).Reduce("ik").Visualize())),p=n.pw.identity_proof_document.Visualize(),m=d.replace(/^0x/i,"");r=m.length>=32&&p.toLowerCase().includes(m.toLowerCase()),c=d.slice(0,18),g(n,{event:"ipd_coherence",ik:d,coherent:r})}catch(d){i("ipd_coherence","probe FAILED (coherence unprovable)",d)}l(`[${e}] IPD/e2e coherence: account_ik=${c}\u2026 ipd_advertises_it=${r}`),r||i("ipd_coherence","IPD does NOT advertise the live account ik",new Error("incoherent transport IPD"))}}return L.expose_packet(n.cid),x.set(e,n),l(`[${e}] EXPOSED (routing + broker registration) \u2014 import phase complete`),await ge(n),P(n),n}async function It(){y.mkdirSync(E(),{recursive:!0});let e;try{e=y.readFileSync(Z(),"utf8").trim()}catch{}let t=ze(24).toString("hex");se(await U(j,t,E(),!1,e)),e||y.writeFileSync(Z(),C(k),{mode:384}),oe(ee(k)),l(`contact-book registrar ready (${k.cid})`)}function Re(e){try{return y.existsSync(I(e))&&y.statSync(I(e)).size>0}catch{return!1}}function Ee(e){let t=S(u=>Buffer.from(R(e,"::actor::export_state",u).Serialize()));y.mkdirSync(e.dir,{recursive:!0,mode:448});let o=I(e.dir),n=`${o}.tmp`,a;try{a=y.openSync(n,"w",384),y.fchmodSync(a,384),y.writeFileSync(a,t),y.fsyncSync(a),y.closeSync(a),a=void 0,y.renameSync(n,o),y.chmodSync(o,384);try{y.chmodSync(D(e.dir),384)}catch{}let u=y.openSync(e.dir,"r");try{y.fsyncSync(u)}finally{y.closeSync(u)}}catch(u){if(a!==void 0)try{y.closeSync(a)}catch{}try{y.rmSync(n,{force:!0})}catch{}throw u}}function z(e){try{Ee(e),e.persistFailed&&(e.persistFailed=!1,l(`[${e.name}] persist recovered \u2014 quarantine lifted`),g(e,{event:"persist_recovered"}))}catch(t){e.persistFailed=!0,l(`[${e.name}] PERSIST FAILED \u2014 identity quarantined (fail-closed), outbound of this txn withheld:`,String(t));try{g(e,{event:"persist_failed",error:String(t).slice(0,300)})}catch{}throw process.nextTick(()=>te(e.name,`[${e.name}] PERSIST FAILED \u2014 messaging quarantined until the state file is writable again`)),t}}function S(e){let t=new $e;try{return e(t)}finally{t.Finalize()}}async function h(e){let t=new $e;try{return await e(t)}finally{t.Finalize()}}function R(e,t,o,n){let a=be({name:t,targ:n}),u=e.pw.packet.ExecuteTransaction(a);return a.Destroy(),o?u.Attach(o):u}async function Ae(e,t){let o=e.lock,n;e.lock=new Promise(a=>n=a),await o;try{return await t()}finally{n()}}function Oe(e,t,o=25e3){return new Promise((n,a)=>{let u=setTimeout(()=>{let i=e.pending.findIndex(f=>f.timer===u);i>=0&&e.pending.splice(i,1),a(new Error("timed out waiting for the transaction result"))},o);e.pending.push({resolve:n,reject:a,timer:u}),e.pw.add_client_message(t)})}function v(e,t,o,n,a){if(e.persistFailed)try{z(e)}catch(i){return Promise.reject(new Error(`identity "${e.name}" is quarantined: state persist is failing (${String(i)}) \u2014 mutations are rejected until state_data.bin is writable again`))}let u=be({name:t,targ:o});return Ae(e,()=>Oe(e,u,a)).then(i=>{if(u.Destroy(),e.persistFailed){try{i.Destroy()}catch{}throw new Error(`identity "${e.name}": state persist FAILED \u2014 this transaction's outbound was withheld (fail-closed); fix the state directory and retry`)}return n?i.Attach(n):i},i=>{try{u.Destroy()}catch{}throw i})}var F=null;function Lt(e){F?.uninstall(),F=e===null?null:{hook:e,uninstall:le("notification",e)}}function Bt(e){F?.hook===e&&(F.uninstall(),F=null)}function te(e,t){pe(e,t)}var Se={onNotify:(e,t)=>te(e,t)},W=new Map;function De(e){let t=W.get(e);if(!(!t||t.size===0))for(let o of[...t])try{o()}catch{}}function Pe(e,t){return new Promise(o=>{let n=W.get(e);n||(n=new Set,W.set(e,n));let a=!1,u=()=>{a||(a=!0,n.delete(i),n.size===0&&W.delete(e),clearTimeout(f),o())},i=u,f=setTimeout(u,t);n.add(i)})}function g(e,t){try{_.mkdirSync(e.dir,{recursive:!0,mode:448}),_.appendFileSync(B(e.dir),JSON.stringify(t)+`
|
|
3
3
|
`)}catch(o){l(`[${e.name}] failed to append notifications.log:`,String(o))}De(e.name),fe(e,t)}function Mt(e){let t=B(e.dir),o="";try{o=_.readFileSync(t,"utf8")}catch{return new Set}let n=[];for(let a of o.split(`
|
|
4
4
|
`))if(a.trim())try{n.push(JSON.parse(a))}catch{}return ue(n)}function T(e,t){let o=e.Reduce(t);return o.IsNil()?"":Buffer.from(o.GetBinary()).toString("hex")}var Fe=Number(process.env.OURS_NOTIFY_LONGPOLL_MS)>0?Number(process.env.OURS_NOTIFY_LONGPOLL_MS):25e3,je=250;function ie(e){try{return _.statSync(e).size}catch{return 0}}function Le(e,t,o){if(o<=t)return{events:[],cursor:t};let n=Buffer.alloc(o-t),a=0;try{let s=_.openSync(e,"r");try{a=_.readSync(s,n,0,n.length,t)}finally{_.closeSync(s)}}catch{return{events:[],cursor:t}}let u=n.subarray(0,a),i=u.lastIndexOf(10);if(i===-1)return{events:[],cursor:t};let f=[];for(let s of u.subarray(0,i+1).toString("utf8").split(`
|
|
5
5
|
`))if(s.trim())try{f.push(JSON.parse(s))}catch{}return{events:f,cursor:t+i+1}}async function Ht(e,t,o,n){let a=B(ke(V,o)),u=(r,c)=>{t.writableEnded||(t.writeHead(200,{"Content-Type":"application/json"}),t.end(JSON.stringify({cursor:r,events:c})))};if(n===null||n==="tip"){u(ie(a),[]);return}let i=parseInt(n,10);if(!Number.isFinite(i)||i<0){t.writableEnded||(t.writeHead(400,{"Content-Type":"application/json"}),t.end(JSON.stringify({error:"invalid since cursor"})));return}let f=!1;e.on("close",()=>{f=!0});let s=Date.now()+Fe;for(;!f;){let r=ie(a);if(i>r&&(i=0),r>i){let{events:c,cursor:d}=Le(a,i,r);if(c.length>0){u(d,c);return}i=d}if(Date.now()>=s)break;await Pe(o,Math.min(je,s-Date.now()))}f||u(ie(a),[])}function P(e){try{let{unread:t,unreadFiles:o}=S(u=>{let f=me(R(e,"::actor::list_incoming_messages",u)).filter(c=>c.status==="unread"),s=R(e,"::actor::list_incoming_files",u),r=[];if(!s.IsNil())for(let c=0;;c++){let d=s.Reduce(c);if(d.IsNil())break;d.Reduce("status").Visualize()==="unread"&&r.push({file_id:d.Reduce("file_id").Visualize(),sender_id:d.Reduce("sender_id").Visualize(),from:d.Reduce("sender_name").Visualize(),filename:d.Reduce("filename").Visualize(),mime:d.Reduce("mime").Visualize(),bytes:d.Reduce("size").Visualize(),date:d.Reduce("date").Visualize(),wire_id:d.Reduce("wire_id").Visualize()})}return{unread:f,unreadFiles:r}}),n={count:t.length,recent:t.slice(-10).map(u=>({from:u.sender_name,msg_id:u.msg_id,date:u.date})),files:o.length,unread_files:o.slice(-10)};_.mkdirSync(e.dir,{recursive:!0,mode:448});let a=`${M(e.dir)}.tmp`;_.writeFileSync(a,JSON.stringify(n)),_.renameSync(a,M(e.dir))}catch(t){l(`[${e.name}] failed to refresh unread snapshot:`,String(t))}}function qt(){let e=[],t=[];try{t=_.readdirSync(V,{withFileTypes:!0})}catch{return{identities:e}}for(let o of t){if(!o.isDirectory()||ne(o.name)!==null)continue;let n;try{n=JSON.parse(_.readFileSync(M(ke(V,o.name)),"utf8"))}catch{continue}let a=Number.isSafeInteger(n.count)&&Number(n.count)>=0?Number(n.count):0,u=Number.isSafeInteger(n.files)&&Number(n.files)>=0?Number(n.files):0;if(a===0&&u===0)continue;let i=Array.isArray(n.recent)?n.recent.slice(-10).flatMap(s=>{if(!s||typeof s!="object")return[];let r=s;return typeof r.from!="string"||!["string","number"].includes(typeof r.msg_id)||typeof r.date!="string"?[]:[{from:r.from,msg_id:r.msg_id,date:r.date}]}):[],f=Array.isArray(n.unread_files)?n.unread_files.slice(-10).flatMap(s=>{if(!s||typeof s!="object")return[];let r=s;return typeof r.from!="string"||typeof r.filename!="string"||typeof r.mime!="string"||typeof r.wire_id!="string"?[]:[{from:r.from,filename:r.filename,mime:r.mime,wire_id:r.wire_id,...typeof r.sender_id=="string"?{sender_id:r.sender_id}:{},...["string","number"].includes(typeof r.file_id)?{file_id:r.file_id}:{},...["string","number"].includes(typeof r.bytes)?{bytes:r.bytes}:{},...typeof r.date=="string"?{date:r.date}:{}}]}):[];e.push({name:o.name,count:a,recent:i,files:u,unread_files:f})}return e.sort((o,n)=>String(o.name).localeCompare(String(n.name))),{identities:e}}export{Lt as a,Bt as b,te as c,Se as d,De as e,Pe as f,g,Mt as h,T as i,ie as j,Le as k,Ht as l,P as m,qt as n,qe as o,Ie as p,Y as q,ge as r,Ne as s,q as t,Ce as u,ye as v,U as w,A as x,yt as y,_t as z,It as A,Re as B,Ee as C,z as D,S as E,h as F,R as G,Ae as H,Oe as I,v as J,E as K,Z as L,X as M,_e as N,we as O,ee as P,C as Q,he as R,rt as S,ve as T};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import{b as O,g as q}from"./chunk-VXVW4KJU.js";import{a as T,b as C,c as N,d as F}from"./chunk-LFJI7SYO.js";import{a as u}from"./chunk-PGG2Y65Y.js";import{A as E,B as P,C as A,D as M,K as c,a as v}from"./chunk-BL54LJNA.js";import{E as k,F as _,G as R,J as p,g as S,h as $,m as x}from"./chunk-4UYU3SJ3.js";import{c as b}from"./chunk-VVPDTS5O.js";import{i as m}from"./chunk-WXVWLASM.js";import{d as B}from"./chunk-LKFYUCN7.js";import{a as I}from"./chunk-P55RJGZU.js";import{readFile as U}from"node:fs/promises";import{basename as z}from"node:path";function L(s,i){if(s)return i!==void 0?{wire_id:s,sentence:i}:{wire_id:s}}async function re(s,i){let t=u(s),{contact:o,text:n}=i,a=L(i.reply_to_wire_id,i.reply_to_sentence);try{let r=await _(async d=>F(await p(t,"::a2a_messaging::send_message",{contact:o,text:n,...a?{reply_to:a}:{}},d)));switch(r.kind){case"refused":m(`[e2e-route] refused cid=${r.cid} wire_id=${r.wireId} (downgrade_refused)`);break;case"migrating":m(`[migration] queued cid=${r.cid} wire_id=${r.wireId} (migrating, ${r.queued} queued)`);break;case"e2e":m(`[e2e-route] cid=${r.cid} wire_id=${r.wireId} verdict=e2e (core delivered over migrated session)${r.notRetained?" NOT RETAINED (oversized)":""}`),r.notRetained&&S(t,{event:"send_not_retained",wire_id:r.wireId,kind:"message"});break;default:break}return r}catch(r){if(!/Unknown contact/.test(String(r)))throw c("send_message",String(r));try{let d=T(t,o);return{kind:"introduced",text:d?await C(t,d,n):await N(t,o,n)}}catch(d){throw c("send_message",String(d),"FALLBACK_FAILED")}}}async function ie(s,i){let t=u(s),{contact:o,path:n,data_base64:a,filename:r,mime:d}=i;if((n?1:0)+(a?1:0)!=1)throw E();let f,g;try{if(n)f=await U(n),g=r??z(n);else{if(!r)throw P();f=Buffer.from(a,"base64"),g=r}}catch(e){throw e instanceof v?e:A(String(e))}let y=d??(n?I(n):""),h=L(i.reply_to_wire_id,i.reply_to_sentence),D=O(),l;try{l=k(e=>q({packet:{NewBinaryFromBuffer:w=>t.pw.packet.NewBinaryFromBuffer(w)},lifetime:e,filename:g,mime:y,payload:f,replyTo:h,cap:D}))}catch(e){throw e instanceof v?e:c("send_file",String(e))}if(!l.ok)throw M({filename:g,bytes:l.bytes,limit:l.cap,envelopeBytes:l.envelopeBytes,maxPayloadBytes:l.maxPayloadBytes});try{let e=await _(async w=>{let V=t.pw.packet.NewBinaryFromBuffer(f).Attach(w);return F(await p(t,"::a2a_messaging::send_file",{contact:o,filename:g,mime:y,data:V,...h?{reply_to:h}:{}},w))});switch(e.kind){case"refused":m(`[e2e-route] refused cid=${e.cid} wire_id=${e.wireId} (downgrade_refused, file)`);break;case"migrating":m(`[migration] file-defer cid=${e.cid} wire_id=${e.wireId} (migrating, not queued)`);break;case"e2e":m(`[e2e-route] cid=${e.cid} wire_id=${e.wireId} verdict=e2e file (core delivered over migrated session)${e.notRetained?" NOT RETAINED (oversized)":""}`),e.notRetained&&S(t,{event:"send_not_retained",wire_id:e.wireId,kind:"file"});break;default:break}return{...e,filename:g,bytes:f.length,mime:y}}catch(e){throw c("send_file",String(e))}}async function ne(s){let i=u(s);try{return k(t=>b(R(i,"::actor::list_incoming_messages",t)))}catch(t){throw c("list_incoming_messages",String(t))}}async function se(s){let i=u(s);try{let t=await _(async n=>{let a=await p(i,"::actor::get_messages",{},n);return b(a.Reduce("messages"))});x(i);let o=$(i);return B(t,o)}catch(t){throw c("get_messages",String(t))}}async function oe(s,i){let t=u(s),{msg_ids:o}=i;try{let n=await _(async a=>(await p(t,"::actor::defer_messages",{msg_ids:o},a)).Reduce("deferred").Visualize());return x(t),{deferred:n}}catch(n){throw c("defer_messages",String(n))}}export{re as a,ie as b,ne as c,se as d,oe as e};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a as d}from"./chunk-
|
|
2
|
+
import{a as d}from"./chunk-PGG2Y65Y.js";import{K as r,y as T,z as j}from"./chunk-BL54LJNA.js";import{E as y,F as u,G as p,J as l,N,R as L,S as A,m as z,o as P,t as f}from"./chunk-4UYU3SJ3.js";import{a as C,b as V,g as x,h as I,j as S,k as B}from"./chunk-VVPDTS5O.js";import{d as _,f as k}from"./chunk-OCBN326X.js";async function U(s,a={}){let e=d(s),{name:i,mode:o}=a;if(o==="public"&&i)throw T();try{return await u(async t=>{let n={};i&&(n.name=i),o&&(n.mode=o);let c=await l(e,"::a2a_messaging::generate_invite",n,t);return{blob:S(Buffer.from(c.Reduce("invite").GetBinary())),inviteId:c.Reduce("invite_id").Visualize(),mode:c.Reduce("mode").Visualize()==="public"?"public":"one_time"}})}catch(t){throw r("generate_invite",String(t))}}async function $(s){let a=d(s);try{return y(e=>{let i=p(a,"::a2a_messaging::list_invites",e),o=[];if(i.IsNil())return o;for(let t of i.GetKeys()){let n=i.Reduce(t);if(n.IsNil())continue;let c=n.Reduce("assigned").Visualize(),m=n.Reduce("created").Visualize();o.push({invite_id:typeof t=="string"?t:t.Visualize(),mode:n.Reduce("mode").Visualize(),assigned:c==="%%NIL"?"":c,created:m==="%%NIL"?"":m})}return o})}catch(e){throw r("list_invites",String(e))}}async function H(s,a){let e=d(s),{invite_id:i}=a;try{return await u(async o=>{let t=await l(e,"::a2a_messaging::revoke_invite",{invite_id:i},o),n=t.Reduce("was_public");return{revoked:t.Reduce("revoked").GetBoolean(),wasPublic:n.IsNil()?!1:n.GetBoolean()}})}catch(o){throw r("revoke_invite",String(o))}}async function J(s,a){let e=d(s),{invite:i,name:o}=a,t;try{if(t=B(i),t.length===0)throw new Error("the invite blob is empty")}catch(n){throw r("add_contact",n instanceof Error?n.message:"the invite blob is not valid.","INVITE_MALFORMED")}try{return await u(async n=>{let m={invite:e.pw.packet.NewBinaryFromBuffer(t).Attach(n)};o&&(m.name=o);let g=await l(e,"::a2a_messaging::add_contact",m,n),R=g.Reduce("container_id").Visualize(),v=g.Reduce("pending").Visualize(),h=g.Reduce("inviter_name").Visualize(),w=b=>!b||b==="%%NIL",G=w(v)?w(h)?R:h:v;return f(e),{display:G,cid:R}})}catch(n){throw r("add_contact",String(n))}}async function Q(s){let a=d(s);try{return y(e=>({contacts:C(p(a,"::a2a_messaging::list_contacts",e)),pending:x(p(a,"::actor::list_pending_introductions",e)),roots:I(p(a,"::a2a_messaging::list_contact_roots",e)),degraded:P(p(a,"::a2a_messaging::list_degraded_contacts",e)),renames:V(p(a,"::a2a_messaging::list_import_renames",e))}))}catch(e){throw r("list_contacts",String(e))}}async function X(s){let a=Object.values(N()),e=s.leaseToken(),i=e?k(e)?.identity:void 0;return a.map(o=>({name:o.name,container_id:o.container_id,published_at:o.published_at,isMine:o.name===i}))}async function Y(s,a){let e=d(s),{expose:i,auto_accept:o}=a;if(i===void 0&&o===void 0)throw j();let t=[];try{return o!==void 0&&(await u(async n=>{await l(e,"::actor::set_local_policy",{auto_accept:o},n)}),t.push(`auto_accept=${o}`)),i===!0?(await L(e),t.push("published in the local contact book")):i===!1&&(A(e),t.push("removed from the local contact book")),{identity:e.name,changes:t}}catch(n){throw r("set_local_book_policy",String(n))}}async function Z(s,a){let e=d(s),{contact:i}=a;try{return _.add(e.name),await u(async o=>{let t=await l(e,"::a2a_messaging::remove_contact",{contact:i},o),n=t.Reduce("removed").Visualize(),c=t.Reduce("container_id").Visualize(),m=t.Reduce("notified"),g=m.IsNil()?void 0:m.GetBoolean();return{name:n,cid:c,notified:g}})}catch(o){throw r("remove_contact",String(o))}finally{_.delete(e.name)}}async function ee(s,a){let e=d(s),{contact:i,name:o}=a;try{return await u(async t=>{let n=await l(e,"::a2a_messaging::rename_contact",{contact:i,name:o},t);return{from:n.Reduce("renamed").Visualize(),cid:n.Reduce("container_id").Visualize()}})}catch(t){throw r("rename_contact",String(t))}}async function te(s,a){let e=d(s),{contact:i,action:o}=a;try{if(o==="approve"){let t=await u(async n=>{let c=await l(e,"::actor::approve_introduction",{contact:i},n);return{action:"approve",name:c.Reduce("approved").Visualize(),cid:c.Reduce("container_id").Visualize(),flushed:c.Reduce("flushed").Visualize()}});return z(e),f(e),t}return await u(async t=>{let n=await l(e,"::actor::reject_introduction",{contact:i},t);return{action:"reject",name:n.Reduce("rejected").Visualize(),dropped:n.Reduce("dropped_messages").Visualize()}})}catch(t){throw r("respond_to_introduction",String(t))}}export{U as a,$ as b,H as c,J as d,Q as e,X as f,Y as g,Z as h,ee as i,te as j};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
+
var t=class extends Error{constructor(o,r,i){super(r);this.code=o;this.details=i;this.name="OursError"}},s=()=>new t("NOT_BOUND","No identity bound to this session. Call choose_identity (or create_identity) first."),a=()=>new t("BINDING_REASSIGNED","Your identity binding was reassigned to another session. Call choose_identity again to continue."),d=e=>new t("BOUND_IDENTITY_GONE",`The bound identity "${e}" no longer exists. Choose another with choose_identity.`),l=e=>new t("TEMP_CLOSING",`The temporary identity "${e}" is closing and no longer accepts work. Its contacts are being notified and its local state deleted.`),_=(e,n)=>new t("NAME_TAKEN",`${e} failed: an identity named "${n}" already exists.`),c=()=>new t("NO_LEASE_HEADERS","create_temporary_identity failed: this client is not connected through the ours connector (no lease token / client pid headers), so there is no session lease to own the identity. Launch ours via the connector (`ours-mcp proxy`)."),E=()=>new t("RANDOM_NAME_EXHAUSTED","create_temporary_identity failed: could not pick a free random name after 5 attempts \u2014 retry."),y=e=>new t("ROOT_EXISTS",`create_root_identity failed: a root identity already exists ("${e}") \u2014 one root per host. Nothing to do.`),p=()=>new t("NOT_BOUND_NO_NAME","close_temporary_identity failed: no identity is bound to this session and no name was given."),N=e=>new t("NOT_TEMPORARY",`close_temporary_identity failed: "${e}" is a permanent identity. Use remove_identity if you really mean to delete it.`),O=(e,n)=>new t("TEMP_OWNED_ELSEWHERE",`close_temporary_identity failed: "${e}" is owned by another LIVE session (owner pid ${n}) \u2014 one session cannot delete another's temporary identity.`),h=(e,n,o)=>new t("DELETE_PARTIAL",`Temporary identity "${e}" closed with an error: ${n}. ${o}`),T=e=>new t("PATH_NOT_ABSOLUTE",`define_local_identity_file failed: path must be absolute (got "${e}").`),m=e=>new t("NO_SUCH_IDENTITY",`choose_identity failed: no identity named "${e}". Create it with create_identity.`),u=()=>new t("NO_LEASE_TOKEN","choose_identity failed: this client is not connected through the ours connector (no lease token header). Launch ours via the connector (`ours-mcp proxy`)."),w=e=>new t("TEMP_CLOSING",`choose_identity failed: temporary identity "${e}" is closing \u2014 its state is being deleted.`),A=(e,n)=>new t("TEMP_OWNED_ELSEWHERE",`choose_identity failed: "${e}" is a TEMPORARY identity owned by another live session (owner pid ${n}). Ownership is exclusive and cannot be overridden \u2014 not even with force. Create your own with create_temporary_identity.`),I=(e,n)=>new t("TEMP_STALE",`choose_identity failed: temporary identity "${e}" is STALE \u2014 its owning session (pid ${n}) is gone and it is pending automatic cleanup. It cannot be adopted by another session; use close_temporary_identity to reclaim (clean it up) now.`),L=e=>new t("BOUND_ELSEWHERE",`choose_identity declined: "${e}" is currently bound to another live session. Do not retry with force=true on your own \u2014 tell the user it is in use elsewhere and ask whether to forcibly rebind it here; only retry with force=true after they explicitly confirm.`),g=(e,n)=>new t("TEMP_OWNED_ELSEWHERE",`remove_identity failed: "${e}" is a TEMPORARY identity owned by another LIVE session (owner pid ${n}) \u2014 one session cannot delete another's temporary identity.`),f=(e,n,o)=>new t("DELETE_PARTIAL",`Temporary identity "${e}" closed with an error: ${n}.${o}`),R=(e,n)=>new t("ROOT_HAS_ROLES",`remove_identity failed: "${e}" is the root identity and still has ${n.length} role(s): ${n.join(", ")}. Remove the roles first.`),D=(e,n)=>new t("DELETE_PARTIAL",`Identity "${e}" removed from memory, but ${n}`),S=()=>new t("PUBLIC_INVITE_NAMED","generate_invite failed: a public invite cannot pre-assign a contact name \u2014 every redeemer would be registered under it. Omit `name` for a public invite."),x=()=>new t("NO_POLICY_ARGS","set_local_book_policy: pass expose and/or auto_accept."),b=()=>new t("SEND_ARGS","send_file: provide exactly one of `path` or `data_base64`."),$=()=>new t("SEND_ARGS","send_file: `filename` is required with `data_base64`."),C=e=>new t("FILE_UNREADABLE",`send_file: cannot read file: ${e}`),M=e=>new t("FILE_TOO_LARGE",`send_file: "${e.filename}" is ${e.bytes} bytes. This send's envelope would serialize to ${e.envelopeBytes} bytes, over the transport's ${e.limit}-byte budget \u2014 the largest payload it can carry with this filename, MIME and reply reference is ${e.maxPayloadBytes} bytes. Nothing was sent.`,e),v=(e,n)=>new t("CONNECTOR_TOO_OLD","save_file could not be completed by your ours connector: it reached the daemon directly, which means the connector is too old to stream the bytes and write them as your OS user. Update the ours connector to use save_file, or fall back to get_files and copy the returned path yourself (`cp`)."+(n?"":` (Also note: no file with wire_id ${e} is currently on disk for this identity \u2014 run get_files first.)`)),P=()=>new t("NO_ROOT","No root identity exists on this host \u2014 create one with create_root_identity first."),B=e=>new t("INVALID_SELECTION",`get_files failed: wire_ids must contain 1-${e} items.`),U=()=>new t("MALFORMED_ID","get_files failed: every selected wire_id must be exactly 64 hexadecimal characters."),F=()=>new t("DUPLICATE_ID","get_files failed: wire_ids must not contain duplicates."),H=()=>new t("UNKNOWN_OR_STALE_ID","get_files failed: one or more selected wire_ids is unknown, stale, or no longer unread; no files were retrieved."),G=(e,n,o="TX_FAILED")=>new t(o,`${e} failed: ${n}`);export{t as a,s as b,a as c,d,l as e,_ as f,c as g,E as h,y as i,p as j,N as k,O as l,h as m,T as n,m as o,u as p,w as q,A as r,I as s,L as t,g as u,f as v,R as w,D as x,S as y,x as z,b as A,$ as B,C,M as D,v as E,P as F,B as G,U as H,F as I,H as J,G as K};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a}from"./chunk-
|
|
2
|
+
import{a}from"./chunk-PGG2Y65Y.js";import{K as i}from"./chunk-BL54LJNA.js";import{E as u,F as d,G as l,J as p}from"./chunk-4UYU3SJ3.js";function m(s){let o=[],r=s.Reduce("messages");if(r.IsNil())return o;for(let e=0;;e++){let t=r.Reduce(e);if(t.IsNil())break;let n=t.Reduce("wire_id"),c=t.Reduce("receipt");o.push({dir:t.Reduce("dir").Visualize()==="out"?"out":"in",text:t.Reduce("text").Visualize(),date:t.Reduce("date").Visualize(),read:t.Reduce("read").GetBoolean(),wire_id:n.IsNil()?"":n.Visualize(),receipt:c.IsNil()?null:c.Visualize()})}return o}async function _(s,o){let r=a(s);try{let e=u(t=>m(l(r,"::actor::get_conversation",t,{contact:o.contact})));return{contact:o.contact,messages:e}}catch(e){throw i("get_conversation",String(e))}}async function v(s,o){let r=a(s);try{let e=u(t=>{let n=l(r,"::actor::get_receipts",t,{contact:o.contact}).Reduce("receipts"),c={};if(n.IsNil())return c;for(let R of n.GetKeys()){let y=R.Visualize();c[y]=n.Reduce(y).Visualize()}return c});return{contact:o.contact,receipts:e}}catch(e){throw i("get_receipts",String(e))}}async function h(s,o){let r=a(s);try{let e=await d(async t=>{let n=await p(r,"::actor::mark_read",{contact:o.contact},t);return Number(n.Reduce("marked").Visualize())});return{contact:o.contact,marked:e}}catch(e){throw i("mark_read",String(e))}}async function C(s,o){let r=a(s);try{return await d(async e=>{let t=await p(r,"::actor::set_local_policy",{keep_history:o.keep_history},e);return{keepHistory:t.Reduce("keep_history").GetBoolean(),autoAccept:t.Reduce("auto_accept").GetBoolean()}})}catch(e){throw i("set_local_policy",String(e))}}export{_ as a,v as b,h as c,C as d};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{c as i,i as a}from"./chunk-
|
|
2
|
+
import{c as i,i as a}from"./chunk-WXVWLASM.js";import{join as n}from"node:path";import{createHash as u}from"node:crypto";import*as r from"node:fs";var m;function P(t){m=t}var v=new Map,g=null,y=null;function T(t){g=t}function I(t){y=t}var _=t=>n(i,t),d=t=>n(t,"identity.key"),h=t=>n(t,"state_data.bin"),F=t=>n(t,"notifications.log"),W=t=>n(t,"unread.json"),x=t=>n(t.dir,"files"),c=t=>n(t,"temp.json"),E=t=>u("sha256").update(t).digest("hex");function H(t,e){r.writeFileSync(c(t),JSON.stringify({v:1,owner:{token_sha256:e.owner.tokenHash,pid:e.owner.pid},created_at:e.createdAt}),{mode:384})}function M(t){try{let e=JSON.parse(r.readFileSync(c(t),"utf8"));return e.v!==1||typeof e.owner?.token_sha256!="string"||typeof e.owner?.pid!="number"?null:{owner:{tokenHash:e.owner.token_sha256,pid:e.owner.pid},createdAt:typeof e.created_at=="number"?e.created_at:0}}catch{return null}}function R(){for(let t of w()){let e=n(i,t);try{r.chmodSync(e,448)}catch(o){a(`[${t}] chmod 0700 failed:`,String(o))}for(let o of[h(e),d(e)])if(r.existsSync(o))try{r.chmodSync(o,384)}catch(s){a(`[${t}] chmod 0600 ${o} failed:`,String(s))}}}var k=t=>/^[A-Za-z0-9]+$/.test(t)&&t.length>0&&t.length<=128,$=t=>/^[A-Fa-f0-9]{64}$/.test(t),j=32;function B(t,e){if(!k(e))return null;let o=x(t),s;try{s=r.readdirSync(o)}catch{return null}let l=`${e}-`,p=s.find(f=>f.startsWith(l));return p?n(o,p):null}function w(){return r.existsSync(i)?r.readdirSync(i,{withFileTypes:!0}).filter(t=>t.isDirectory()&&r.existsSync(d(n(i,t.name)))).map(t=>t.name):[]}export{m as a,P as b,v as c,g as d,y as e,T as f,I as g,_ as h,d as i,h as j,F as k,W as l,x as m,c as n,E as o,H as p,M as q,R as r,k as s,$ as t,j as u,B as v,w};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{b as s,e as p}from"./chunk-
|
|
2
|
+
import{b as s,e as p}from"./chunk-MLISCAHB.js";import{F as f,J as c,N as g,P as l,t as u}from"./chunk-4UYU3SJ3.js";import{c as d,d as a}from"./chunk-KIIBATGV.js";function S(e,t){if(!s||!d.has(s))return null;let r=d.get(t)??[...d.values()].find(n=>n.cid===t);if(!r||r.name===e.name)return null;let i=n=>n.name===s||p(n).roleId!=="";return i(e)&&i(r)?r:null}async function V(e,t,r){let i=l(t);return await f(async n=>{await c(e,"::actor::connect_sibling",{name:t.name,target_ad:e.pw.packet.NewBinaryFromBuffer(i).Attach(n),text:r},n)}),u(e),`"${t.name}" was not a contact yet \u2014 connected as an intra-root sibling (delegation-cert auto-accept) and delivered the message.`}async function N(e,t,r){if(!a)throw new Error(`"${t}" is not a contact, and the local contact book is unavailable.`);let i=g(),n=i[t]??Object.values(i).find(o=>o.container_id===t);if(!n)throw new Error(`"${t}" is not a contact and has no local contact-book entry. Use generate_invite/add_contact for remote peers, or list_local_contact_book to see local ones.`);if(n.container_id===e.cid)throw new Error("that contact-book entry is this identity itself.");let m=Buffer.from(n.address_document,"base64url"),w=Buffer.from(n.registrar_sig,"base64url"),y=l(e);return await f(async o=>{let k=await c(a,"::actor::mint_introduction",{joiner_ad:a.pw.packet.NewBinaryFromBuffer(y).Attach(o),target_ad:a.pw.packet.NewBinaryFromBuffer(m).Attach(o)},o),b=Buffer.from(k.Reduce("intro").GetBinary());await c(e,"::actor::connect_local",{name:n.name,target_ad:e.pw.packet.NewBinaryFromBuffer(m).Attach(o),intro:e.pw.packet.NewBinaryFromBuffer(b).Attach(o),entry_sig:e.pw.packet.NewBinaryFromBuffer(w).Attach(o),text:r},o)}),u(e),`"${n.name}" was not a contact yet \u2014 connected via the local contact book and sent the message with the introduction. If "${n.name}" requires approval for local introductions, delivery completes once they approve.`}var R=e=>{let t=n=>!e.Reduce(n).IsNil(),r=e.Reduce("wire_id").Visualize(),i=t("sent_to")?e.Reduce("sent_to").Visualize():"";if(t("downgrade_refused"))return{kind:"refused",wireId:r,cid:i};if(t("migrating"))return{kind:"migrating",wireId:r,cid:i,queued:t("queued")?Number(e.Reduce("queued").Visualize()):0};if(t("route")){let n=t("retained")&&!e.Reduce("retained").GetBoolean();return{kind:"e2e",wireId:r,cid:i,notRetained:n}}return t("deferred")?{kind:"deferred",wireId:r,queued:t("queued")?Number(e.Reduce("queued").Visualize()):0}:{kind:"sent",wireId:r}};export{S as a,V as b,N as c,R as d};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{
|
|
2
|
+
import{a as me}from"./chunk-NBEWKZG4.js";import{d as H}from"./chunk-V64IUVSS.js";import{a as z}from"./chunk-37D5PCFY.js";import{a as le,b as G}from"./chunk-4Q5FJDMI.js";import{a as pe,d as fe}from"./chunk-YQQKPG4Q.js";import{b as ce}from"./chunk-R7NCFWZO.js";import{b as re,c as ae}from"./chunk-25ZST4S3.js";import{b as de}from"./chunk-XWILWDUO.js";import{C as se,a as ne,b as A,l as oe,n as ie}from"./chunk-4UYU3SJ3.js";import{a as D,b as q,c as h,e as j,f as ee,g as te}from"./chunk-OCBN326X.js";import{c as I,o as Y,v as Z}from"./chunk-KIIBATGV.js";import{a as P,b as K,c as M,d as Q,e as R,g as W,h as $,i as d,m as k,p as X}from"./chunk-WXVWLASM.js";import{createServer as Se}from"node:http";import{randomUUID as Ie}from"node:crypto";import*as b from"node:fs";me();function ve(s){if(!s||typeof s!="object"||Array.isArray(s))return!1;let p=s;return p.jsonrpc==="2.0"&&p.method==="initialize"}var Te=["brokerUrl","port","stateDir","gcIntervalMs","apiVisibility"];function ue(s){return new Promise((p,f)=>{let O="";s.on("data",m=>O+=m),s.on("end",()=>{try{p(JSON.parse(O))}catch(m){f(m)}}),s.on("error",f)})}async function ze(s={}){try{return await ke(s)}catch(p){throw $?.failed(),d(`fatal startup error: ${p?.stack??p}`),p}}async function ke(s){let p=s.handleSignals!==!1;if(process.env.OURS_TEST_STARTUP_FAIL==="1")throw new Error("forced startup failure (OURS_TEST_STARTUP_FAIL)");if(s.config){let t=Te.filter(e=>s.config[e]!==K[e]);if(t.length>0)throw new Error(`startDaemon(config) disagrees with the config resolved at module load (${t.join(", ")}). The engine reads its config when src/runtime/env.ts is imported, so a later override cannot move the state dir, port or broker \u2014 set OURS_* env or config.json before importing the SDK.`)}let f=s.mcp,O=f?.isInitializeRequest??ve,m=null;if(typeof s.onIdentityNotify=="function"){let t=s.onIdentityNotify;m=(e,i)=>{t(e,i,D.get(e)?.sid??null)},ne(m)}d("booting wrapper\u2026");try{await ce(),le()}catch(t){throw m&&A(m),G(),t}d(`wrapper ready (identities=${I.size}), starting HTTP server\u2026`),$?.update("server");let l={},v=new Map,T=new Map,ge=3e4,U=t=>{let e=T.get(t);e?e.n++:T.set(t,{n:1,since:Date.now()})},J=t=>{let e=T.get(t);e&&--e.n<=0&&T.delete(t)},B=()=>{let t=0;for(let e of[...v.keys()]){if(e==="stdio")continue;let i=h.get(e)?.pid;if(i===void 0||i<=1||j(i))continue;let n=T.get(e);if(n&&n.n>0&&Date.now()-n.since<ge)continue;let o=v.get(e);v.delete(e),delete l[e],h.delete(e),T.delete(e),o?.close().catch(()=>{}),f?.onSessionClosed?.(e),t++,d(`session ${e.slice(0,8)}\u2026 reaped (client pid ${i} dead)`)}return t},F=setInterval(()=>{B(),ae()},6e4);F.unref?.();let _=1e3,he=10*6e4,u=new Map,ye=(t,e)=>{let i=Array.isArray(e)?e:[e];for(let n of i){let o=n;!o||typeof o!="object"||o.id===void 0||o.id===null||typeof o.method!="string"||u.set(`${t}:${String(o.id)}`,{method:o.method,at:Date.now()})}if(u.size>_){let n=Date.now()-he;for(let[o,r]of u)if(r.at<n&&u.delete(o),u.size<=_)break;for(;u.size>_;){let o=u.keys().next();if(o.done)break;u.delete(o.value)}}},we=(t,e)=>{try{let i=e instanceof Error?e.message:String(e),n=/No connection established for request ID:\s*(\S+)/.exec(i);if(!n)return;let o=n[1],r=u.get(`${t}:${o}`);u.delete(`${t}:${o}`),d(`UNDELIVERABLE RESPONSE session=${t.slice(0,8)}\u2026 request_id=${o} method=${r?.method??"unknown"} age_ms=${r?Date.now()-r.at:"unknown"} at=${new Date().toISOString()} \u2014 the answer was produced but its stream was already gone`)}catch{}},y=Se(async(t,e)=>{let i=new URL(t.url,`http://localhost:${R}`);if(t.method==="GET"&&i.pathname==="/state-dir"){e.writeHead(200,{"Content-Type":"application/json"}),e.end(JSON.stringify({stateDir:M,version:P,compat:1}));return}if(t.method==="GET"&&(i.pathname==="/version"||i.pathname==="/info")){e.writeHead(200,{"Content-Type":"application/json"}),e.end(JSON.stringify({name:"ours",version:P,compat:1,protocol:de,pid:process.pid,stateDir:M}));return}if(t.method==="GET"&&i.pathname==="/identities"){if(!k(t,e))return;e.writeHead(200,{"Content-Type":"application/json"}),e.end(JSON.stringify({identities:[...I.values()].map(n=>({name:n.name,...n.temp?{temporary:!0,stale:!j(n.temp.owner.pid)}:{}}))}));return}if(t.method==="GET"&&i.pathname==="/unread"){if(!k(t,e))return;e.writeHead(200,{"Content-Type":"application/json"}),e.end(JSON.stringify(ie()));return}{let n=/^\/identities\/([^/]+)\/notifications$/.exec(i.pathname);if(t.method==="GET"&&n){if(!k(t,e))return;let o=decodeURIComponent(n[1]);if(X(o)!==null){e.writeHead(400,{"Content-Type":"application/json"}),e.end(JSON.stringify({error:"invalid identity name"}));return}await oe(t,e,o,i.searchParams.get("since"));return}}{let n=/^\/files\/([^/]+)$/.exec(i.pathname);if(t.method==="GET"&&n){if(!k(t,e))return;let o=decodeURIComponent(n[1]),r=t.headers["x-ours-lease-token"],S=typeof r=="string"&&r?ee(r):void 0,g=S?I.get(S.identity):void 0;if(!g){e.writeHead(401,{"Content-Type":"application/json"}),e.end(JSON.stringify({error:"no identity bound to this session"}));return}let w=Z(g,o);if(!w){e.writeHead(404,{"Content-Type":"application/json"}),e.end(JSON.stringify({error:"no such file for the bound identity (run get_files first, or it belongs to another identity)"}));return}try{let c=b.statSync(w);e.writeHead(200,{"Content-Type":"application/octet-stream","Content-Length":String(c.size)});let C=b.createReadStream(w);C.on("error",()=>{try{e.destroy()}catch{}}),C.pipe(e)}catch(c){e.writeHead(500,{"Content-Type":"application/json"}),e.end(JSON.stringify({error:`failed to read file: ${String(c)}`}))}return}}if(i.pathname.startsWith(pe)){await fe(t,e,i.pathname,ue);return}if(i.pathname!=="/mcp"||!f){e.writeHead(404,{"Content-Type":"text/plain"}),e.end("Not found");return}if(k(t,e))try{if(t.method==="POST"){let n=await ue(t),o=t.headers["mcp-session-id"],r=t.headers["x-ours-lease-token"],S=t.headers["x-ours-client-pid"],g=S?parseInt(S,10):void 0,w={token:r,pid:Number.isInteger(g)?g:void 0};if(o&&l[o]){h.set(o,w),ye(o,n),U(o),H(e);try{await l[o].handleRequest(t,e,n)}finally{J(o)}}else if(!o&&O(n)){B();let c=f.createTransport({sessionIdGenerator:()=>Ie(),onsessioninitialized:a=>{l[a]=c,h.set(a,w),v.set(a,N),f.onSessionInitialized?.(a,N),d(`session ${a.slice(0,8)}\u2026 initialized`)}}),C={sessionId:()=>c.sessionId??"pending",leaseToken:()=>h.get(c.sessionId??"pending")?.token,clientPid:()=>h.get(c.sessionId??"pending")?.pid},N=f.createServer(C);N.server.onerror=a=>we(c.sessionId??"pending",a),c.onclose=()=>{let a=c.sessionId;a&&(delete l[a],v.delete(a),h.delete(a),f.onSessionClosed?.(a),d(`session ${a.slice(0,8)}\u2026 closed (lease kept)`))},await N.connect(c),H(e),await c.handleRequest(t,e,n)}else e.writeHead(400,{"Content-Type":"application/json"}),e.end(JSON.stringify({jsonrpc:"2.0",error:{code:-32e3,message:"Bad Request: No valid session ID"},id:null}))}else if(t.method==="GET"){let n=t.headers["mcp-session-id"];if(!n||!l[n]){e.writeHead(400,{"Content-Type":"text/plain"}),e.end("Invalid or missing session ID");return}U(n),H(e);try{await l[n].handleRequest(t,e)}finally{J(n)}}else if(t.method==="DELETE"){let n=t.headers["mcp-session-id"];if(!n||!l[n]){e.writeHead(400,{"Content-Type":"text/plain"}),e.end("Invalid or missing session ID");return}let o=h.get(n)?.token??t.headers["x-ours-lease-token"];if(o){for(let[r,S]of[...D]){if(S.token!==o)continue;D.delete(r);let g=I.get(r);g?.temp&&g.temp.owner.tokenHash===Y(o)&&!g.temp.closing&&re(g,"owning session released its lease").catch(w=>d(`[${r}] close on lease release failed:`,String(w)))}q.delete(o),te(),d(`lease released by token \u2026${o.slice(-6)}`)}await l[n].handleRequest(t,e)}else e.writeHead(405,{"Content-Type":"text/plain"}),e.end("Method not allowed")}catch(n){d("HTTP handler error:",String(n)),e.headersSent||(e.writeHead(500,{"Content-Type":"application/json"}),e.end(JSON.stringify({jsonrpc:"2.0",error:{code:-32603,message:"Internal server error"},id:null})))}});y.requestTimeout=0;let V=!1,x=async()=>{if(!V){V=!0,clearInterval(F),G(),m&&A(m);for(let t of Object.keys(l)){try{await l[t].close()}catch{}delete l[t]}v.clear();for(let t of I.values())try{se(t)}catch(e){d(`[${t.name}] shutdown save failed:`,String(e))}y.closeAllConnections?.()}};try{await new Promise((t,e)=>{let i=n=>e(n);y.once("error",i),y.listen(R,"127.0.0.1",()=>{y.off("error",i),$?.ready(),d(`MCP server v${s.version??P} ready (transport=http, port=${R}, visibility=${W}, identities=${I.size}, state=${M}, broker=${Q})`),t()})})}catch(t){throw await x(),t}let E=async()=>{d("shutting down\u2026"),await x(),y.close(),process.exit(0)};p&&(process.on("SIGINT",E),process.on("SIGTERM",E));let L=y.address();return{port:typeof L=="object"&&L!==null?L.port:R,close:async()=>{p&&(process.off("SIGINT",E),process.off("SIGTERM",E)),await x(),await new Promise(t=>y.close(()=>t()))}}}export{ze as a};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{E as m,F as p,G as l,J as a,P as f}from"./chunk-
|
|
2
|
+
import{E as m,F as p,G as l,J as a,P as f}from"./chunk-4UYU3SJ3.js";import{c as u}from"./chunk-KIIBATGV.js";import{c as d,i}from"./chunk-WXVWLASM.js";import{join as x}from"node:path";import*as r from"node:fs";function V(e){y=e}var c=()=>x(d,"root.json"),y=null;function $(){try{let e=JSON.parse(r.readFileSync(c(),"utf8"));return typeof e.name=="string"?e.name:null}catch{return null}}function I(e){r.mkdirSync(d,{recursive:!0});let o=`${c()}.tmp`;r.writeFileSync(o,JSON.stringify({v:1,name:e})),r.renameSync(o,c())}function G(){r.rmSync(c(),{force:!0})}function z(e){return m(o=>{let t=l(e,"::actor::describe_identity",o);return{bio:t.Reduce("bio").Visualize(),persona:t.Reduce("persona").Visualize(),hasCert:t.Reduce("has_cert").GetBoolean(),roleId:t.Reduce("role_id").Visualize(),rootCid:t.Reduce("root_cid").Visualize(),rootName:t.Reduce("root_name").Visualize(),monitoringEnabled:t.Reduce("monitoring_enabled").GetBoolean()}})}async function A(e,o){await p(async t=>{let n=f(o),s=await a(e,"::actor::sign_delegation",{role_ad:e.pw.packet.NewBinaryFromBuffer(n).Attach(t),role_id:o.name},t),g=Buffer.from(s.Reduce("cert").GetBinary()),B=await a(e,"::actor::export_root_profile",{},t),w=Buffer.from(B.Reduce("profile").GetBinary()),h=f(e),_=Buffer.from((await a(o,"::actor::export_v1_address_document",{},t)).Reduce("ad").GetBinary()),R=await a(e,"::actor::sign_delegation",{role_ad:e.pw.packet.NewBinaryFromBuffer(_).Attach(t),role_id:o.name},t),b=Buffer.from(R.Reduce("cert").GetBinary());await a(o,"::actor::set_delegation",{cert:o.pw.packet.NewBinaryFromBuffer(g).Attach(t),root_ad:o.pw.packet.NewBinaryFromBuffer(h).Attach(t),root_profile:o.pw.packet.NewBinaryFromBuffer(w).Attach(t),cert_v1:o.pw.packet.NewBinaryFromBuffer(b).Attach(t)},t)}),i(`[${o.name}] delegated as a role under root "${e.name}"`)}async function C(e){y=e.name,I(e.name);let o=[],t=[];for(let n of u.values())if(n.name!==e.name&&!n.temp)try{await A(e,n),o.push(n.name)}catch(s){i(`failed to adopt "${n.name}" as a role under new root "${e.name}":`,String(s)),t.push(n.name)}return i(`[${e.name}] established as the host root${o.length?` (adopted ${o.length} role(s))`:""}`),{adopted:o,failed:t}}export{V as a,y as b,$ as c,G as d,z as e,A as f,C as g};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{c as a}from"./chunk-
|
|
2
|
+
import{c as a}from"./chunk-KIIBATGV.js";import{c as d,i as u}from"./chunk-WXVWLASM.js";import{join as h}from"node:path";import*as r from"node:fs";var i=new Map,g=new Set,c=new Map,k=new Set;function E(e){if(!Number.isInteger(e)||e<=0)return!1;try{return process.kill(e,0),!0}catch(t){return t.code==="EPERM"}}function m(e){for(let t of i.values())if(t.token===e)return t}var f=()=>h(d,"bindings.json");function l(){try{r.mkdirSync(d,{recursive:!0});let e=`${f()}.tmp`;r.writeFileSync(e,JSON.stringify({pid:process.pid,bound:[...i.keys()],holders:[...i.values()].map(t=>({identity:t.identity,pid:t.pid}))})),r.renameSync(e,f())}catch(e){u("failed to persist bindings snapshot:",String(e))}}function _(e){let t=c.get(e)?.token;if(!t)return{code:"NOT_BOUND",error:"No identity bound to this session. Call choose_identity (or create_identity) first."};if(g.has(t))return{code:"BINDING_REASSIGNED",error:"Your identity binding was reassigned to another session. Call choose_identity again to continue."};let n=m(t);if(!n)return{code:"NOT_BOUND",error:"No identity bound to this session. Call choose_identity (or create_identity) first."};let o=a.get(n.identity);if(!o)return i.delete(n.identity),l(),{code:"BOUND_IDENTITY_GONE",error:`The bound identity "${n.identity}" no longer exists. Choose another with choose_identity.`};if(o.temp?.closing)return{code:"TEMP_CLOSING",error:`The temporary identity "${o.name}" is closing and no longer accepts work. Its contacts are being notified and its local state deleted.`};n.sid=e;let s=c.get(e)?.pid;return s&&(n.pid=s),{id:o}}function x(e,t){let n=c.get(e),o=n?.token;if(!o)return;for(let[p,y]of[...i])y.token===o&&p!==t&&i.delete(p);let s=i.get(t)?.epoch??0;i.set(t,{identity:t,token:o,pid:n?.pid??0,sid:e,epoch:s+1,boundAt:Date.now()}),g.delete(o),l()}export{i as a,g as b,c,k as d,E as e,m as f,l as g,_ as h,x as i};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a}from"./chunk-
|
|
2
|
+
import{a}from"./chunk-BL54LJNA.js";import{a as n}from"./chunk-XYU2DSWR.js";var p=class{base;leaseToken;clientPid;apiToken;fetchImpl;constructor(e){this.base=e.url.replace(/\/+$/,""),this.leaseToken=e.leaseToken,this.clientPid=e.clientPid??process.pid,this.apiToken=e.apiToken,this.fetchImpl=e.fetch??globalThis.fetch}headers(e={}){return{"x-ours-lease-token":this.leaseToken,"x-ours-client-pid":String(this.clientPid),...this.apiToken?{"x-ours-api-token":this.apiToken}:{},...e}}async post(e,s){let i=await this.fetchImpl(`${this.base}/api/v1/${e}`,{method:"POST",headers:this.headers({"content-type":"application/json"}),body:JSON.stringify(s??{})}),t;try{t=await i.json()}catch{throw new Error(`${e}: the daemon returned a non-JSON response (HTTP ${i.status})`)}if(t&&typeof t=="object"&&!Array.isArray(t)&&"error"in t){let r=t.error,o=r!==null&&typeof r=="object"&&"code"in r&&"message"in r;if(i.status===400&&o){let{code:y,message:d}=r;throw new a(y,d)}let c=o?r.message:String(r);throw new Error(`${e}: ${c} (HTTP ${i.status})`)}if(!i.ok)throw new Error(`${e}: the daemon returned HTTP ${i.status} with no error field`);return t}async get(e,s){let i=await this.fetchImpl(`${this.base}${e}`,{headers:s?this.headers():{}}),t;try{t=await i.json()}catch{throw new Error(`GET ${e}: the daemon returned a non-JSON response (HTTP ${i.status})`)}if(t&&typeof t=="object"&&"error"in t)throw new Error(`GET ${e}: ${String(t.error)} (HTTP ${i.status})`);if(!i.ok)throw new Error(`GET ${e}: the daemon returned HTTP ${i.status} with no error field`);return t}createIdentity(e){return this.post("createIdentity",e)}createTemporaryIdentity(e){return this.post("createTemporaryIdentity",e)}closeTemporaryIdentityOp(e={}){return this.post("closeTemporaryIdentityOp",e)}createRootIdentity(e){return this.post("createRootIdentity",e)}defineLocalIdentityFile(e){return this.post("defineLocalIdentityFile",e)}chooseIdentity(e){return this.post("chooseIdentity",e)}listIdentities(){return this.post("listIdentities",{})}currentIdentity(){return this.post("currentIdentity",{})}removeIdentity(e){return this.post("removeIdentity",e)}releaseLease(){return this.post("releaseLease",{})}generateInvite(e={}){return this.post("generateInvite",e)}listInvites(){return this.post("listInvites",{})}revokeInvite(e){return this.post("revokeInvite",e)}addContact(e){return this.post("addContact",e)}listContacts(){return this.post("listContacts",{})}listLocalContactBook(){return this.post("listLocalContactBook",{})}setLocalBookPolicy(e){return this.post("setLocalBookPolicy",e)}removeContact(e){return this.post("removeContact",e)}renameContact(e){return this.post("renameContact",e)}respondToIntroduction(e){return this.post("respondToIntroduction",e)}setBio(e){return this.post("setBio",e)}advertiseMigrate(){return this.post("advertiseMigrate",{})}readvertiseOnUpgrade(){return this.post("readvertiseOnUpgrade",{})}setPersona(e){return this.post("setPersona",e)}sendMessage(e){return this.post("sendMessage",e)}sendFile(e){return this.post("sendFile",e)}listIncomingMessages(){return this.post("listIncomingMessages",{})}getMessages(){return this.post("getMessages",{})}deferMessages(e){return this.post("deferMessages",e)}deferFiles(e){return this.post("deferFiles",e)}getConversation(e){return this.post("getConversation",e)}getReceipts(e){return this.post("getReceipts",e)}markRead(e){return this.post("markRead",e)}setConversationPolicy(e){return this.post("setConversationPolicy",e)}listIncomingFiles(){return this.post("listIncomingFiles",{})}getFiles(e={}){return this.post("getFiles",e)}saveFileFallbackNotice(e){return this.post("saveFileFallbackNotice",e)}version(){return this.get("/version",!1)}stateDir(){return this.get("/state-dir",!1)}async identities(){return(await this.get("/identities",!0)).identities}unread(){return this.get("/unread",!0)}async*watchNotifications(e,s={}){let i=s.since??"tip",t=`/identities/${encodeURIComponent(e)}/notifications`;for(;!s.signal?.aborted;){let r;try{let o=await this.fetchImpl(`${this.base}${t}?since=${i}`,{headers:this.headers(),signal:s.signal});try{r=await o.json()}catch{throw new Error(`watchNotifications(${e}): the daemon returned a non-JSON response (HTTP ${o.status})`)}}catch(o){if(s.signal?.aborted)return;throw o}if("error"in r)throw new Error(`watchNotifications(${e}): ${r.error}`);i=r.cursor;for(let o of r.events)yield n(o&&typeof o=="object"?o:{})}}async fetchFile(e){let s=await this.fetchImpl(`${this.base}/files/${encodeURIComponent(e)}`,{headers:this.headers()});if(!s.ok){let i=`HTTP ${s.status}`;try{let t=await s.json();t&&t.error!==void 0&&(i=String(t.error))}catch{}throw new Error(`fetchFile(${e}): ${i}`)}return new Uint8Array(await s.arrayBuffer())}};export{p as a};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a as se,b as A}from"./chunk-
|
|
2
|
+
import{a as se,b as A}from"./chunk-25ZST4S3.js";import{K as p,a as T,f as k,g as q,h as W,i as z,j as U,k as Y,l as G,m as J,n as K,o as Q,p as S,q as X,r as Z,s as ee,t as te,u as oe,v as ne,w as re,x as ie}from"./chunk-BL54LJNA.js";import{a as ae,c as de}from"./chunk-XWILWDUO.js";import{b as f,e as b,f as N,g as E}from"./chunk-MLISCAHB.js";import{F as M,J as j,x as L,y as _}from"./chunk-4UYU3SJ3.js";import{a as h,b as v,e as I,f as B,g as H,h as V,i as g}from"./chunk-OCBN326X.js";import{c,o as w,p as $}from"./chunk-KIIBATGV.js";import{i as R,p as x}from"./chunk-WXVWLASM.js";import{k as D,m as F}from"./chunk-IB2U7K6Y.js";import{randomBytes as ce}from"node:crypto";import{isAbsolute as me}from"node:path";function le(r){try{return b(r)}catch{return null}}function C(r){let o=le(r);return{name:r.name,cid:r.cid,bio:o?.bio??"",persona:o?.persona??"",roleId:o?.roleId??"",rootCid:o?.rootCid??"",rootName:o?.rootName??""}}async function P(r,o){o&&await M(async e=>{await j(r,"::a2a_messaging::set_my_bio",{bio:o},e)})}function pe(r){let o=V(r.sessionId());if(!("error"in o))return o.id;throw new T(o.code,o.error)}async function ke(r,o){let{name:e,bio:i,exposeLocal:d,localAutoAccept:s}=o,n=x(e);if(n)throw p("create_identity",n,"NAME_INVALID");if(c.has(e))throw k("create_identity",e);try{let t=await _(e,{exposeLocal:d,localAutoAccept:s});await P(t,i);let a,l=null,m=[],u=[],y=f?c.get(f):void 0;if(y)await N(y,t),a="role",l=y.name,ae()&&de(y);else{a="root";let O=await E(t);m=O.adopted,u=O.failed}return g(r.sessionId(),e),{info:C(t),hierarchy:a,underRoot:l,adopted:m,failed:u,exposedLocal:d,localAutoAccept:s}}catch(t){throw p("create_identity",String(t),"PROVISION_FAILED")}}async function Ae(r,o){let{bio:e,exposeLocal:i,localAutoAccept:d}=o,s=r.leaseToken(),n=r.clientPid();if(!s||!n)throw q();let t=o.name;if(t!==void 0){let l=x(t);if(l)throw p("create_temporary_identity",l,"NAME_INVALID");if(c.has(t)||L.has(t))throw k("create_temporary_identity",t)}else{for(let l=0;l<5&&t===void 0;l++){let m=`tmp-${ce(5).toString("hex")}`;!c.has(m)&&!L.has(m)&&(t=m)}if(t===void 0)throw W()}let a=t;try{let l=await _(a,{exposeLocal:i,localAutoAccept:d,temp:{tokenHash:w(s),pid:n}});return await P(l,e),g(r.sessionId(),a),{info:C(l),ownerPid:n,exposedLocal:i,localAutoAccept:d}}catch(l){throw p("create_temporary_identity",String(l),"PROVISION_FAILED")}}async function Ce(r,o){let e=r.leaseToken(),i;if(o.name!==void 0){if(i=c.get(o.name),!i)return{name:o.name,result:null}}else{let n=e?B(e):void 0;if(i=n?c.get(n.identity):void 0,!i)throw U()}if(!i.temp)throw Y(i.name);let d=i.temp.owner,s=e!==void 0&&d.tokenHash===w(e);if(!s&&!i.temp.closing&&I(d.pid))throw G(i.name,d.pid);try{let n=await A(i,s?"explicit close by owner":"stale reclaim via close_temporary_identity");if(n.deleteError){let t=n.attempted===0?"It had no contacts, so no remove-me notices were needed.":`Remove-me notices: ${n.notified}/${n.attempted} queued, ${n.failed} not sent (best effort \u2014 delivery and remote contact deletion are not guaranteed).`;throw J(i.name,n.deleteError,t)}return{name:i.name,result:n}}catch(n){throw n instanceof T?n:p("close_temporary_identity",String(n),"CLOSE_FAILED")}}async function ve(r,o){let{name:e,bio:i,exposeLocal:d,localAutoAccept:s,skipIfRootExists:n}=o,t=x(e);if(t)throw p("create_root_identity",t,"NAME_INVALID");let a=f;if(n&&a&&c.has(a))throw z(a);if(c.has(e))throw k("create_root_identity",e);try{let l=await _(e,{exposeLocal:d,localAutoAccept:s});await P(l,i);let m=f?c.get(f):void 0;if(m&&m.name!==e)return await N(m,l),g(r.sessionId(),e),{info:C(l),hierarchy:"role",underRoot:m.name,adopted:[],failed:[],exposedLocal:d,localAutoAccept:s};let{adopted:u,failed:y}=await E(l);return g(r.sessionId(),e),{info:C(l),hierarchy:"root",underRoot:null,adopted:u,failed:y,exposedLocal:d,localAutoAccept:s}}catch(l){throw p("create_root_identity",String(l),"PROVISION_FAILED")}}async function Le(r){if(!me(r.path))throw K(r.path);let o={name:r.name,force:r.force,exposeLocal:r.exposeLocal,localAutoAccept:r.localAutoAccept};try{return{written:F(r.path,o,r.overwrite),json:D(o)}}catch(e){throw p("define_local_identity_file",String(e),"WRITE_FAILED")}}async function Se(r,o){let{name:e,force:i}=o;if(!c.has(e))throw Q(e);let d=r.sessionId(),s=r.leaseToken();if(!s)throw S();let n=c.get(e);if(n.temp){if(n.temp.closing)throw X(e);let m=n.temp.owner;if(m.tokenHash!==w(s))throw I(m.pid)?Z(e,m.pid):ee(e,m.pid);let u=r.clientPid();if(u&&u!==m.pid){m.pid=u;try{$(n.dir,n.temp)}catch(y){R(`[${e}] temp marker refresh failed:`,String(y))}}}let t=h.get(e);if(t&&t.token!==s)if(!I(t.pid))R(`auto-reclaiming "${e}" from dead client pid ${t.pid}`),h.delete(e);else if(i)v.add(t.token),h.delete(e);else throw te(e);let a=[...h.values()].find(m=>m.token===s&&m.identity!==e)?.identity,l=a&&c.has(a)?a:null;return g(d,e),{name:e,cid:c.get(e).cid,switchedFrom:l}}async function Ne(r){if(c.size===0)return[];let o=r.leaseToken(),e=t=>{let a=h.get(t);return a?a.token===o?"mine":I(a.pid)?"other-live":null:null},i=t=>{if(!t.temp)return null;let a=t.temp.owner.pid;return t.temp.closing?{state:"closing",ownerPid:a}:o!==void 0&&t.temp.owner.tokenHash===w(o)?{state:"mine",ownerPid:a}:I(a)?{state:"other-live",ownerPid:a}:{state:"stale",ownerPid:a}},d=(t,a)=>({name:t.name,cid:t.cid,kind:a,temp:i(t),session:e(t.name)}),s=f?c.get(f):void 0,n=[];if(s){n.push({...d(s,"root"),temp:null});for(let t of c.values())t.name!==s.name&&b(t).roleId!==""&&n.push(d(t,"role"));for(let t of c.values())t.name===s.name||b(t).roleId!==""||n.push(d(t,"flat"))}else for(let t of c.values())n.push(d(t,"flat"));return n}async function Ee(r){let o=pe(r),e=le(o);return{name:o.name,cid:o.cid,bio:e?.bio??"",persona:e?.persona??"",roleId:e?.roleId??"",rootCid:e?.rootCid??"",rootName:e?.rootName??"",temporary:o.temp!==void 0,isRoot:o.name===f,described:e!==null}}async function Pe(r,o){let{name:e}=o,i=c.get(e);if(!i)throw p("remove_identity",`no identity named "${e}".`,"NO_SUCH_IDENTITY");if(i.temp){let s=r.leaseToken(),n=i.temp.owner;if((s===void 0||n.tokenHash!==w(s))&&!i.temp.closing&&I(n.pid))throw oe(e,n.pid);try{let t=await A(i,"remove_identity");if(t.deleteError){let a=t.attempted===0?"":` Remove-me notices: ${t.notified}/${t.attempted} queued, ${t.failed} not sent (best effort).`;throw ne(e,t.deleteError,a)}return{name:e,kind:"temporary",close:t}}catch(t){throw t instanceof T?t:p("remove_identity",String(t),"CLOSE_FAILED")}}if(e===f){let s=[...c.values()].filter(n=>n.name!==e&&b(n).rootCid===i.cid);if(s.length>0)throw re(e,s.map(n=>n.name))}let d=se(i);if(d)throw ie(e,d);return{name:e,kind:"permanent"}}async function Oe(r){let o=r.leaseToken();if(!o)throw S();let e=[];for(let[i,d]of[...h]){if(d.token!==o)continue;h.delete(i),e.push(i);let s=c.get(i);s?.temp&&s.temp.owner.tokenHash===w(o)&&!s.temp.closing&&A(s,"owning session released its lease").catch(n=>R(`[${i}] close on lease release failed:`,String(n)))}return v.delete(o),H(),R(`lease released by token \u2026${o.slice(-6)}`),{released:e}}export{pe as a,ke as b,Ae as c,Ce as d,ve as e,Le as f,Se as g,Ne as h,Ee as i,Pe as j,Oe as k};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a as H}from"./chunk-IU6MOFTJ.js";import{c as L,d as B}from"./chunk-
|
|
2
|
+
import{a as H}from"./chunk-IU6MOFTJ.js";import{c as L,d as B}from"./chunk-25ZST4S3.js";import{d as F}from"./chunk-XWILWDUO.js";import{a as u,b as n,c as A,d as U,e as P,f as C}from"./chunk-MLISCAHB.js";import{A as N,T as M,g as k,s as h,u as g,x as I,z as D}from"./chunk-4UYU3SJ3.js";import{a as v,b as E,c as O}from"./chunk-YRPUM6JG.js";import{g as $}from"./chunk-OCBN326X.js";import{a as f,b as _,c as l,d as b,q as y,r as S,w as R}from"./chunk-KIIBATGV.js";import{d as m,h as s,i as o}from"./chunk-WXVWLASM.js";import{adapt_wrapper as K}from"@adapt-toolkit/sdk/executables";var T=!1;function ne(){return T}function j(){if(T)throw new Error('bootWrapper() has already run in this process. It boots the ADAPT environment, which can only be initialised once \u2014 a second call fails inside the native layer with "Failed to invoke initializer in ADAPT environment", which names neither the double init nor the caller. NOTE THAT startDaemon() CALLS bootWrapper() ITSELF: the two are alternatives, not steps. Use startDaemon() for the HTTP daemon, or bootWrapper() alone for a stdio/in-process host \u2014 never both.');T=!0,H()}async function ae(){j(),s?.update("wrapper"),O(v());let x=["--broker_address",m,"--test_mode","--logger_config","--level","INFO","--stdout","stderr","--logger_config_end"];o(`booting wrapper (unit ${E.hash.slice(0,12)}\u2026, broker ${m})`),_(await K.start(x)),f.on_packet_created_cb=e=>o(`wrapper: packet ready ${e.slice(0,12)}\u2026`),f.start();let p=Number(process.env.OURS_TEST_BOOT_HOLD_MS||"")||0;p>0&&(o(`TEST HOLD: boot window open ${p}ms (OURS_TEST_BOOT_HOLD_MS)`),await new Promise(e=>setTimeout(e,p))),s?.update("registrar");try{await N()}catch(e){o("failed to start the contact-book registrar (local contact book disabled):",String(e))}S();let i=R(),d=Math.max(0,Number(process.env.OURS_TEST_FAKE_RESTORE_COUNT||"")||0),c=Math.max(0,Number(process.env.OURS_TEST_FAKE_RESTORE_MS||"")||0),W=i.length===0&&d>0?d:i.length;s?.update("identities",{completed:0,total:W});for(let e of i)I.add(e);if(i.length===0&&d>0){o(`TEST: simulating ${d} fake identity restore(s), ${c}ms each`);for(let e=0;e<d;e++)c>0&&await new Promise(a=>setTimeout(a,c)),s?.update("identities",{completed:e+1,total:d})}else if(i.length===0)o("no persisted identities \u2014 start with create_identity");else{o(`restoring ${i.length} identit${i.length===1?"y":"ies"}: ${i.join(", ")}`);for(let[e,a]of i.entries()){try{let t=await D(a);b&&await M(t);let r=y(t.dir);r&&(t.temp=r)}catch(t){o(`failed to restore "${a}":`,String(t))}s?.update("identities",{completed:e+1,total:i.length})}}s?.update("reconciliation"),F(),u(A()),n&&!l.has(n)&&(o(`root marker names a missing identity "${n}" \u2014 clearing it`),u(null),U()),n&&o(`root identity: ${n}`);{let e=n?l.get(n):void 0;n&&!e&&o(`re-delegation on upgrade DEGRADED: root "${n}" is not among the restored identities \u2014 role certs not refreshed this boot`);let a=[];if(e)for(let t of l.values()){if(t.name===e.name)continue;let r;try{r=P(t)}catch{r=void 0}if(!(!r||!r.hasCert)){if(r.rootCid!==e.cid){o(`[${t.name}] re-delegation skipped: delegated by a different root (${r.rootCid.slice(0,12)}\u2026), not this host root \u2014 left as-is`);continue}try{await C(e,t),a.push(t)}catch(w){k(t,{event:"redelegation_failed",error:String(w).slice(0,300)}),o(`[${t.name}] boot re-delegation (upgrade cert refresh) failed:`,String(w))}}}for(let t of l.values()){await h(t),await g(t);for(let r of[1e4,3e4,9e4])setTimeout(()=>{h(t).catch(()=>{})},r),setTimeout(()=>{g(t).catch(()=>{})},r)}a.length>0&&o(`refreshed ${a.length} role delegation cert(s) against the live AD on boot`)}$(),B(),L()}export{ne as a,ae as b};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{e as d}from"./chunk-
|
|
2
|
+
import{e as d}from"./chunk-MLISCAHB.js";import{E as a,G as c}from"./chunk-4UYU3SJ3.js";import{c as s}from"./chunk-KIIBATGV.js";function y(e){try{return a(n=>{let i=c(e,"::a2a_capabilities::get_manifest",n).Reduce("capabilities");return i.IsNil()?[]:[...i.GetKeys()].map(t=>typeof t=="string"?t:t.Visualize())})}catch{return[]}}function R(e){let n="",i="",t="",u="",l=[];try{a(g=>{let p=c(e,"::a2a_capabilities::get_manifest",g),r=o=>{let f=p.Reduce(o);return f.IsNil()?"":f.Visualize()};n=r("app_id"),i=r("name"),t=r("description"),u=r("version");let m=p.Reduce("capabilities");m.IsNil()||(l=[...m.GetKeys()].map(o=>typeof o=="string"?o:o.Visualize()))})}catch{}return{app_id:n,name:i,description:t,version:u,capabilities:l,monitoring_status:"unbound"}}function h(e){let n=[];for(let i of s.values()){if(i.name===e.name)continue;let t=d(i);t.rootCid===e.cid&&n.push({name:i.name,cid:i.cid,role_id:t.roleId,bio:t.bio,monitoring:t.monitoringEnabled,capabilities:y(i)})}return n}function v(e,n){let i=s.get(n)??[...s.values()].find(t=>t.cid===n);return!i||i.name===e.name?null:d(i).rootCid===e.cid?i:null}export{y as a,R as b,h as c,v as d};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{c as p,h as w,j as I,k as b,l as x}from"./chunk-DIRW7I4S.js";import{m as h}from"./chunk-
|
|
2
|
+
import{c as p,h as w,j as I,k as b,l as x}from"./chunk-DIRW7I4S.js";import{m as h}from"./chunk-KIIBATGV.js";import{b as _}from"./chunk-WXVWLASM.js";import{b as z}from"./chunk-P55RJGZU.js";import{basename as M,join as $}from"node:path";import{createHash as S,randomUUID as G}from"node:crypto";import{mkdir as C,open as O,rename as v,unlink as N,lstat as D}from"node:fs/promises";import{brotliCompressSync as K,brotliDecompressSync as P}from"node:zlib";function Z(e){let n=[];if(e.IsNil())return n;for(let i of e.GetKeys()){let t=e.Reduce(i);t.IsNil()||n.push({name:t.Reduce("name").Visualize(),container_id:t.Reduce("container_id").Visualize()})}return n}function ee(e){let n={};if(e.IsNil())return n;for(let i of e.GetKeys()){let t=e.Reduce(i);t.IsNil()||(n[typeof i=="string"?i:i.Visualize()]=t.Visualize())}return n}function te(e){let n=[];if(e.IsNil())return n;for(let i=0;;i++){let t=e.Reduce(i);if(t.IsNil())break;let s=t.Reduce("reply_to"),o=null;if(!s.IsNil()){o={wire_id:s.Reduce("wire_id").Visualize()};let r=s.Reduce("sentence");r.IsNil()||(o.sentence=parseInt(r.Visualize(),10))}n.push({msg_id:parseInt(t.Reduce("msg_id").Visualize(),10),sender_id:t.Reduce("sender_id").Visualize(),sender_name:t.Reduce("sender_name").Visualize(),text:t.Reduce("text").Visualize(),date:t.Reduce("date").Visualize(),status:t.Reduce("status").Visualize(),wire_id:t.Reduce("wire_id").Visualize(),reply_to:o})}return n}function ie(e){let n=[];if(e.IsNil())return n;for(let i=0;;i++){let t=e.Reduce(i);if(t.IsNil())break;let s=t.Reduce("filename").Visualize(),o=t.Reduce("mime").Visualize()||"application/octet-stream",r=t.Reduce("reply_to"),a=null;if(!r.IsNil()){a={wire_id:r.Reduce("wire_id").Visualize()};let u=parseInt(r.Reduce("sentence").Visualize(),10);Number.isSafeInteger(u)&&u>0&&(a.sentence=u)}n.push({file_id:parseInt(t.Reduce("file_id").Visualize(),10),wire_id:t.Reduce("wire_id").Visualize(),from:{id:t.Reduce("sender_id").Visualize(),name:t.Reduce("sender_name").Visualize()},filename:s,mime:o,size:parseInt(t.Reduce("size").Visualize(),10),size_source:"received_payload",status:t.Reduce("status").Visualize(),date:t.Reduce("date").Visualize(),sha256:null,reply_to:a,kind:p(o,s)?"voice_message":"file"})}return n}function ne(e){if(e.length===0)return"No files received.";let n=[];for(let i of e){let t=i.kind==="voice_message"?"\u{1F3A4} voice message \xB7 ":"";n.push(` \u2022 ${t}${i.filename} (${i.mime}, ${i.size} B) from ${i.from.name} [${i.status}] {${i.wire_id}} sender_id=${i.from.id}`)}return`${n.length} file(s):
|
|
3
3
|
${n.join(`
|
|
4
4
|
`)}`}async function j(e,n,i){await C(e,{recursive:!0,mode:448});let t=await D(e);if(!t.isDirectory()||t.isSymbolicLink())throw new Error("received-files directory is not a safe directory");let s=$(e,`.${M(n)}.${G()}.tmp`),o=await O(s,"wx",384);try{await o.writeFile(i),await o.sync()}catch(r){throw await o.close().catch(()=>{}),await N(s).catch(()=>{}),r}await o.close();try{await v(s,n)}catch(r){throw await N(s).catch(()=>{}),r}}async function re(e,n){let i=[];if(n.IsNil())return{text:"No new files.",files:i};let t=h(e),s=[];for(let o=0;;o++){let r=n.Reduce(o);if(r.IsNil())break;let a=r.Reduce("filename").Visualize(),u=r.Reduce("mime").Visualize()||"application/octet-stream",f=r.Reduce("sender_name").Visualize(),A=r.Reduce("sender_id").Visualize(),F=parseInt(r.Reduce("file_id").Visualize(),10),B=r.Reduce("date").Visualize(),d=r.Reduce("wire_id").Visualize(),c=Buffer.from(r.Reduce("data").GetBinary()),V=S("sha256").update(c).digest("hex"),l=$(t,`${d}-${z(a)}`);await j(t,l,c);let g={file_id:F,wire_id:d,from:{id:A,name:f},filename:a,path:l,mime:u,size:c.length,sha256:V,status:"processed",date:B,kind:p(u,a)?"voice_message":"file",sender:f};if(p(u,a)){let y=w(_.stt),m;if(!y.ready)m={kind:"unconfigured",reason:y.reason};else{let R=await I(c,a,u,_.stt);m=R.ok?{kind:"transcript",text:R.text}:{kind:"failed",error:R.error}}g.transcription=b(y,m,{audioPath:l,wireId:d}),s.push(x({sender:f,wire:d,savedPath:l,sizeBytes:c.length},m)),i.push(g);continue}i.push(g),s.push(` \u2022 ${a} (${u}, ${c.length} B, sha256 ${V}) from ${f} \u2192 ${l} {${d}}`)}return s.length===0?{text:"No new files.",files:i}:{text:`${s.length} new file(s) written to your identity's files dir \u2014 paths + metadata below (bytes stay on disk, never in this result). If your OS user can read the path, use it directly; otherwise use save_file({ wire_id, dest_path }) to stream a copy to a path you can write:
|
|
5
5
|
${s.join(`
|