@ours.network/sdk 3.0.4 → 3.1.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/README.md +19 -0
- package/dist/api/contacts.js +1 -1
- package/dist/api/files.js +1 -1
- package/dist/api/history.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-2X5HGMMO.js +5 -0
- package/dist/{chunk-63FBQ35M.js → chunk-2ZQPUBE4.js} +1 -1
- package/dist/{chunk-3FAS7737.js → chunk-3CPIRV4P.js} +1 -1
- package/dist/{chunk-SQWLTVUX.js → chunk-3ZIC5X5I.js} +1 -1
- package/dist/{chunk-IOL6KZNO.js → chunk-4QU3AKO6.js} +1 -1
- package/dist/{chunk-L57CP5UJ.js → chunk-5JKYJZAR.js} +1 -1
- package/dist/{chunk-VD57XFNA.js → chunk-7Q3OCSPV.js} +1 -1
- package/dist/{chunk-6ATIPILE.js → chunk-7ZZWD64L.js} +1 -1
- package/dist/chunk-AAXXFRZP.js +4 -0
- package/dist/{chunk-XEK46DXF.js → chunk-AH3RIV2J.js} +1 -1
- package/dist/{chunk-HBHUWDY3.js → chunk-E34QSIVP.js} +1 -1
- package/dist/{chunk-O2K2ME7S.js → chunk-FCQYDCQA.js} +1 -1
- package/dist/{chunk-QWAZLLE2.js → chunk-IFCOOPD7.js} +2 -2
- package/dist/chunk-MGNMJ64X.js +174 -0
- package/dist/chunk-N4N4OLEW.js +2 -0
- package/dist/{chunk-6DRJYMF2.js → chunk-P2AAWXWI.js} +1 -1
- package/dist/{chunk-S6GRTEIM.js → chunk-PMN5M2JA.js} +1 -1
- package/dist/{chunk-TKIAVV2O.js → chunk-RL3OEL5W.js} +1 -1
- package/dist/{chunk-JV64HCOG.js → chunk-UZF6OB3R.js} +1 -1
- package/dist/{chunk-4EICEZ36.js → chunk-VQTATA4V.js} +1 -1
- package/dist/{chunk-CBKH6ILH.js → chunk-W34RPHBG.js} +1 -1
- package/dist/{chunk-FMQOOSOQ.js → chunk-WBCVUXOI.js} +1 -1
- package/dist/{chunk-MR2LCJLF.js → chunk-WD7K5KPL.js} +1 -1
- package/dist/{chunk-ULS3S767.js → chunk-WZQNO4PZ.js} +1 -1
- package/dist/chunk-XIWAQH6S.js +61 -0
- package/dist/{chunk-FP33FQ2P.js → chunk-XKPZWKI4.js} +1 -1
- package/dist/{chunk-RFU57I64.js → chunk-Y77ZVHTD.js} +1 -1
- package/dist/{chunk-VH4CORJZ.js → chunk-ZOZFAMAX.js} +1 -1
- package/dist/client/http.d.ts +3 -0
- package/dist/client/http.js +1 -1
- package/dist/client/select.js +1 -1
- package/dist/client.d.ts +1 -0
- package/dist/client.js +1 -1
- package/dist/cluster/control.js +1 -1
- package/dist/cluster/manifest.js +1 -1
- package/dist/config.d.ts +3 -0
- package/dist/config.js +1 -1
- package/dist/connector.js +1 -1
- package/dist/gc.js +1 -1
- package/dist/history-retention.d.ts +37 -0
- package/dist/history-retention.js +2 -0
- package/dist/history.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/migration.js +1 -1
- package/dist/identity/model.js +1 -1
- package/dist/identity/provision.js +1 -1
- package/dist/identity/reaper.js +1 -1
- package/dist/identity/release.js +1 -1
- package/dist/identity/staged.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/internal/daemon.js +1 -1
- 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/351F16D444E6DAA252D4A8D829D17204360D9015FEF670ACE68FB4747BB3B14E.muflo +0 -0
- package/dist/notify.js +1 -1
- package/dist/runtime/config-drift.js +1 -1
- package/dist/runtime/env.d.ts +1 -0
- package/dist/runtime/env.js +1 -1
- package/dist/state.js +1 -1
- package/dist/sweeps.js +1 -1
- package/dist/uploads.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-6HS337DC.js +0 -4
- package/dist/chunk-EHCBEY52.js +0 -2
- package/dist/chunk-TXAIJEXA.js +0 -171
- package/dist/chunk-WS6UFNKF.js +0 -5
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import{b as O,d as m,j as g}from"./chunk-XIWAQH6S.js";import{createHash as C,randomUUID as D}from"node:crypto";import*as a from"node:fs";import{dirname as b,join as p,resolve as H,sep as M}from"node:path";import U from"better-sqlite3";var E=200,F=50,S=2*1024*1024,q=8*1024*1024,k="history.sqlite3",h=1,y=new Map,I=new Map,T=new Map,X=t=>p(t.dir,k),z=t=>p(t.dir,"blobs","sha256");function x(){return{write_failures:0,message_write_failures:0,file_write_failures:0,receipt_update_failures:0,last_failure_at_ms:null}}function j(t){return{...I.get(t.dir)??x()}}function J(t,e,r,s){let i=I.get(t.dir)??x();if(i.write_failures+=1,i.last_failure_at_ms=Date.now(),e==="message"?i.message_write_failures+=1:e==="file"?i.file_write_failures+=1:i.receipt_update_failures+=1,I.set(t.dir,i),s==="out"&&r){let n=T.get(t.dir);n||(n=new Set,T.set(t.dir,n)),n.add(r)}}function Z(t,e){let r=T.get(t.dir);return r?.delete(e)?(r.size===0&&T.delete(t.dir),!0):!1}function P(t){t.exec(`
|
|
3
|
+
CREATE TABLE IF NOT EXISTS history_meta (
|
|
4
|
+
key TEXT PRIMARY KEY,
|
|
5
|
+
value TEXT NOT NULL
|
|
6
|
+
);
|
|
7
|
+
CREATE TABLE IF NOT EXISTS wire_items (
|
|
8
|
+
wire_id TEXT PRIMARY KEY,
|
|
9
|
+
item_kind TEXT NOT NULL CHECK (item_kind IN ('message','file'))
|
|
10
|
+
);
|
|
11
|
+
CREATE TABLE IF NOT EXISTS messages (
|
|
12
|
+
seq INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
13
|
+
wire_id TEXT NOT NULL UNIQUE,
|
|
14
|
+
peer_cid TEXT NOT NULL,
|
|
15
|
+
peer_name_snapshot TEXT NOT NULL,
|
|
16
|
+
direction TEXT NOT NULL CHECK (direction IN ('in','out')),
|
|
17
|
+
body TEXT NOT NULL,
|
|
18
|
+
occurred_at_ms INTEGER NOT NULL,
|
|
19
|
+
reply_to_wire_id TEXT,
|
|
20
|
+
reply_to_sentence INTEGER,
|
|
21
|
+
encryption TEXT NOT NULL CHECK (encryption IN ('legacy','e2e')),
|
|
22
|
+
inbox_state TEXT NOT NULL CHECK (inbox_state IN ('pending_introduction','unread','read')),
|
|
23
|
+
delivery_state TEXT,
|
|
24
|
+
human_read_at_ms INTEGER,
|
|
25
|
+
inserted_at_ms INTEGER NOT NULL
|
|
26
|
+
);
|
|
27
|
+
CREATE INDEX IF NOT EXISTS messages_unread_seq ON messages(inbox_state, seq ASC);
|
|
28
|
+
CREATE INDEX IF NOT EXISTS messages_peer_seq ON messages(peer_cid, seq DESC);
|
|
29
|
+
CREATE TRIGGER IF NOT EXISTS messages_release_wire AFTER DELETE ON messages BEGIN
|
|
30
|
+
DELETE FROM wire_items WHERE wire_id = OLD.wire_id AND item_kind = 'message';
|
|
31
|
+
END;
|
|
32
|
+
CREATE TABLE IF NOT EXISTS files (
|
|
33
|
+
seq INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
34
|
+
wire_id TEXT NOT NULL UNIQUE,
|
|
35
|
+
peer_cid TEXT NOT NULL,
|
|
36
|
+
peer_name_snapshot TEXT NOT NULL,
|
|
37
|
+
direction TEXT NOT NULL CHECK (direction IN ('in','out')),
|
|
38
|
+
filename TEXT NOT NULL,
|
|
39
|
+
mime TEXT NOT NULL,
|
|
40
|
+
byte_length INTEGER NOT NULL,
|
|
41
|
+
sha256 TEXT NOT NULL,
|
|
42
|
+
blob_relpath TEXT NOT NULL,
|
|
43
|
+
occurred_at_ms INTEGER NOT NULL,
|
|
44
|
+
reply_to_wire_id TEXT,
|
|
45
|
+
reply_to_sentence INTEGER,
|
|
46
|
+
encryption TEXT NOT NULL CHECK (encryption IN ('legacy','e2e')),
|
|
47
|
+
inbox_state TEXT NOT NULL CHECK (inbox_state IN ('pending_introduction','unread','read')),
|
|
48
|
+
delivery_state TEXT,
|
|
49
|
+
human_read_at_ms INTEGER,
|
|
50
|
+
inserted_at_ms INTEGER NOT NULL
|
|
51
|
+
);
|
|
52
|
+
CREATE INDEX IF NOT EXISTS files_unread_seq ON files(inbox_state, seq ASC);
|
|
53
|
+
CREATE INDEX IF NOT EXISTS files_peer_seq ON files(peer_cid, seq DESC);
|
|
54
|
+
CREATE TRIGGER IF NOT EXISTS files_release_wire AFTER DELETE ON files BEGIN
|
|
55
|
+
DELETE FROM wire_items WHERE wire_id = OLD.wire_id AND item_kind = 'file';
|
|
56
|
+
END;
|
|
57
|
+
CREATE TABLE IF NOT EXISTS monitoring_items (
|
|
58
|
+
seq INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
59
|
+
item_id TEXT NOT NULL UNIQUE,
|
|
60
|
+
source_cid TEXT NOT NULL,
|
|
61
|
+
source_name_snapshot TEXT NOT NULL,
|
|
62
|
+
direction TEXT NOT NULL CHECK (direction IN ('in','out')),
|
|
63
|
+
peer_cid TEXT NOT NULL,
|
|
64
|
+
peer_name_snapshot TEXT NOT NULL,
|
|
65
|
+
body TEXT NOT NULL,
|
|
66
|
+
occurred_at_ms INTEGER NOT NULL,
|
|
67
|
+
queue_state TEXT NOT NULL CHECK (queue_state IN ('pending','processed')),
|
|
68
|
+
inserted_at_ms INTEGER NOT NULL
|
|
69
|
+
);
|
|
70
|
+
CREATE INDEX IF NOT EXISTS monitoring_pending_seq ON monitoring_items(queue_state, seq ASC);
|
|
71
|
+
CREATE TABLE IF NOT EXISTS control_requests (
|
|
72
|
+
seq INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
73
|
+
item_id TEXT NOT NULL UNIQUE,
|
|
74
|
+
sender_cid TEXT NOT NULL,
|
|
75
|
+
sender_name_snapshot TEXT NOT NULL,
|
|
76
|
+
payload TEXT NOT NULL,
|
|
77
|
+
occurred_at_ms INTEGER NOT NULL,
|
|
78
|
+
queue_state TEXT NOT NULL CHECK (queue_state IN ('pending','processed')),
|
|
79
|
+
inserted_at_ms INTEGER NOT NULL
|
|
80
|
+
);
|
|
81
|
+
CREATE INDEX IF NOT EXISTS control_pending_seq ON control_requests(queue_state, seq ASC);
|
|
82
|
+
`);let e=t.prepare("SELECT value FROM history_meta WHERE key = ?").pluck().get("schema_version");if(e!==void 0&&Number(e)!==h)throw new Error(`unsupported history database schema ${String(e)} (expected ${h})`);t.prepare("INSERT OR IGNORE INTO history_meta(key, value) VALUES (?, ?)").run("schema_version",String(h))}function d(t){let e=y.get(t.dir);if(e)return e;a.mkdirSync(t.dir,{recursive:!0,mode:448}),a.chmodSync(t.dir,448);let r=X(t),s=!a.existsSync(r)||a.statSync(r).size===0;s||O(r);let i=new U(r);try{a.chmodSync(r,384),s&&i.pragma("auto_vacuum = INCREMENTAL"),i.pragma("journal_mode = WAL"),i.pragma("synchronous = NORMAL"),i.pragma("foreign_keys = ON"),i.pragma("busy_timeout = 5000"),P(i);for(let n of["","-wal","-shm"]){let o=`${r}${n}`;a.existsSync(o)&&a.chmodSync(o,384)}}catch(n){throw i.close(),n}return y.set(t.dir,i),i}function v(t){let e=y.get(t.dir);e&&(y.delete(t.dir),e.close())}function W(t){if(!t.wireId||t.wireId.length>256)throw new Error("invalid wire_id");if(!t.peerCid||t.peerCid.length>256)throw new Error("invalid peer cid");if(!t.peerName||t.peerName.length>512)throw new Error("invalid peer name");if(!Number.isSafeInteger(t.occurredAtMs)||t.occurredAtMs<0)throw new Error("invalid timestamp");if(t.replyToWireId!==void 0&&(!t.replyToWireId||t.replyToWireId.length>256))throw new Error("invalid reply wire_id");if(t.replyToSentence!==void 0&&(!Number.isSafeInteger(t.replyToSentence)||t.replyToSentence<1))throw new Error("invalid reply sentence")}function G(t){if(W(t),t.kind==="message"){if(Buffer.byteLength(t.body,"utf8")>S)throw new Error("message body exceeds host limit");return}if(!t.filename||t.filename.length>512||/[\0]/.test(t.filename))throw new Error("invalid filename");if(t.mime.length>512||/[\r\n\0]/.test(t.mime))throw new Error("invalid MIME type");if(t.bytes.byteLength>q)throw new Error("file exceeds host limit")}function R(t){return t.reply_to_wire_id?t.reply_to_sentence===null?{wire_id:t.reply_to_wire_id}:{wire_id:t.reply_to_wire_id,sentence:t.reply_to_sentence}:null}function w(t){return new Date(t).toISOString()}function L(t){let e={id:t.peer_cid,name:t.peer_name_snapshot};return{seq:t.seq,msg_id:t.seq,wire_id:t.wire_id,from:e,peer:e,direction:t.direction,text:t.body,body:t.body,occurred_at_ms:t.occurred_at_ms,date:w(t.occurred_at_ms),encryption:t.encryption,transport:t.encryption==="e2e"?"double_ratchet":"legacy_box",inbox_state:t.inbox_state,status:t.inbox_state,delivery_state:t.delivery_state,human_read_at_ms:t.human_read_at_ms,reply_to:R(t)}}function f(t,e){let r={id:e.peer_cid,name:e.peer_name_snapshot},s=e.mime||"application/octet-stream";return{seq:e.seq,file_id:e.seq,wire_id:e.wire_id,from:r,peer:r,direction:e.direction,filename:e.filename,mime:s,size:e.byte_length,byte_length:e.byte_length,sha256:e.sha256,occurred_at_ms:e.occurred_at_ms,date:w(e.occurred_at_ms),encryption:e.encryption,inbox_state:e.inbox_state,status:e.inbox_state,delivery_state:e.delivery_state,human_read_at_ms:e.human_read_at_ms,reply_to:R(e),blob_path:p(t.dir,e.blob_relpath),kind:s.startsWith("audio/")?"voice_message":"file"}}function B(t,e){let r=C("sha256").update(e).digest("hex"),s=p("blobs","sha256",r.slice(0,2),r),i=p(t.dir,s);if(a.mkdirSync(b(i),{recursive:!0,mode:448}),a.chmodSync(b(i),448),!a.existsSync(i)){let n=p(b(i),`.${r}.${process.pid}.${D()}.tmp`);try{a.writeFileSync(n,e,{flag:"wx",mode:384}),a.chmodSync(n,384);try{a.renameSync(n,i)}catch(o){if(!a.existsSync(i))throw o;a.rmSync(n,{force:!0})}}catch(o){try{a.rmSync(n,{force:!0})}catch{}throw o}}return a.chmodSync(i,384),{sha256:r,relpath:s}}function ee(t,e){G(e);let r=d(t);if(e.direction==="out"&&e.inboxState!==void 0)throw new Error("outbound event cannot set inbox state");let s=e.direction==="in"?e.inboxState??"unread":"read",i=e.direction==="out"?"sent":null;if(e.kind==="message"){let u=r.transaction(()=>r.prepare(`
|
|
83
|
+
INSERT INTO wire_items(wire_id, item_kind) VALUES (?, 'message')
|
|
84
|
+
ON CONFLICT(wire_id) DO NOTHING
|
|
85
|
+
`).run(e.wireId).changes!==1?!1:(r.prepare(`
|
|
86
|
+
INSERT INTO messages (
|
|
87
|
+
wire_id, peer_cid, peer_name_snapshot, direction, body, occurred_at_ms,
|
|
88
|
+
reply_to_wire_id, reply_to_sentence, encryption, inbox_state,
|
|
89
|
+
delivery_state, human_read_at_ms, inserted_at_ms
|
|
90
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
91
|
+
`).run(e.wireId,e.peerCid,e.peerName,e.direction,e.body,e.occurredAtMs,e.replyToWireId??null,e.replyToSentence??null,e.encryption,s,i,e.direction==="out"?e.occurredAtMs:null,Date.now()),!0))();return u&&m(t.dir,Buffer.byteLength(e.body,"utf8")),u}if(r.prepare("SELECT 1 FROM wire_items WHERE wire_id = ?").get(e.wireId))return!1;let o=B(t,e.bytes),_;try{_=r.transaction(()=>r.prepare(`
|
|
92
|
+
INSERT INTO wire_items(wire_id, item_kind) VALUES (?, 'file')
|
|
93
|
+
ON CONFLICT(wire_id) DO NOTHING
|
|
94
|
+
`).run(e.wireId).changes!==1?!1:(r.prepare(`
|
|
95
|
+
INSERT INTO files (
|
|
96
|
+
wire_id, peer_cid, peer_name_snapshot, direction, filename, mime,
|
|
97
|
+
byte_length, sha256, blob_relpath, occurred_at_ms, reply_to_wire_id,
|
|
98
|
+
reply_to_sentence, encryption, inbox_state, delivery_state,
|
|
99
|
+
human_read_at_ms, inserted_at_ms
|
|
100
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
101
|
+
`).run(e.wireId,e.peerCid,e.peerName,e.direction,e.filename,e.mime||"application/octet-stream",e.bytes.byteLength,o.sha256,o.relpath,e.occurredAtMs,e.replyToWireId??null,e.replyToSentence??null,e.encryption,s,i,e.direction==="out"?e.occurredAtMs:null,Date.now()),!0))()}catch(u){throw g(t.dir,o.relpath),u}return _?m(t.dir,e.bytes.byteLength):g(t.dir,o.relpath),_}function te(t,e){if(!e.itemId||!e.sourceCid||!e.sourceName||!e.peerCid||!e.peerName)throw new Error("invalid monitoring event metadata");if(!Number.isSafeInteger(e.occurredAtMs)||e.occurredAtMs<0)throw new Error("invalid monitoring timestamp");if(Buffer.byteLength(e.body,"utf8")>S)throw new Error("monitoring body exceeds host limit");let r=d(t).prepare(`
|
|
102
|
+
INSERT INTO monitoring_items (
|
|
103
|
+
item_id, source_cid, source_name_snapshot, direction, peer_cid,
|
|
104
|
+
peer_name_snapshot, body, occurred_at_ms, queue_state, inserted_at_ms
|
|
105
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'pending', ?)
|
|
106
|
+
ON CONFLICT(item_id) DO NOTHING
|
|
107
|
+
`).run(e.itemId,e.sourceCid,e.sourceName,e.direction,e.peerCid,e.peerName,e.body,e.occurredAtMs,Date.now()).changes===1;return r&&m(t.dir,Buffer.byteLength(e.body,"utf8")),r}function re(t,e){if(!e.itemId||!e.senderCid||!e.senderName)throw new Error("invalid control event metadata");if(!Number.isSafeInteger(e.occurredAtMs)||e.occurredAtMs<0)throw new Error("invalid control timestamp");if(Buffer.byteLength(e.payload,"utf8")>S)throw new Error("control payload exceeds host limit");let r=d(t).prepare(`
|
|
108
|
+
INSERT INTO control_requests (
|
|
109
|
+
item_id, sender_cid, sender_name_snapshot, payload,
|
|
110
|
+
occurred_at_ms, queue_state, inserted_at_ms
|
|
111
|
+
) VALUES (?, ?, ?, ?, ?, 'pending', ?)
|
|
112
|
+
ON CONFLICT(item_id) DO NOTHING
|
|
113
|
+
`).run(e.itemId,e.senderCid,e.senderName,e.payload,e.occurredAtMs,Date.now()).changes===1;return r&&m(t.dir,Buffer.byteLength(e.payload,"utf8")),r}function ie(t,e){let r=d(t),s=r.transaction(()=>{let i=r.prepare(`
|
|
114
|
+
UPDATE messages SET inbox_state = 'unread'
|
|
115
|
+
WHERE direction = 'in' AND peer_cid = ? AND inbox_state = 'pending_introduction'
|
|
116
|
+
`).run(e).changes,n=r.prepare(`
|
|
117
|
+
UPDATE files SET inbox_state = 'unread'
|
|
118
|
+
WHERE direction = 'in' AND peer_cid = ? AND inbox_state = 'pending_introduction'
|
|
119
|
+
`).run(e).changes;return i+n})();return s>0&&m(t.dir),s}function ne(t,e){let r=d(t),s=r.prepare(`
|
|
120
|
+
SELECT DISTINCT blob_relpath FROM files
|
|
121
|
+
WHERE direction = 'in' AND peer_cid = ? AND inbox_state = 'pending_introduction'
|
|
122
|
+
`).pluck().all(e),i=r.transaction(()=>{let n=r.prepare(`
|
|
123
|
+
DELETE FROM messages
|
|
124
|
+
WHERE direction = 'in' AND peer_cid = ? AND inbox_state = 'pending_introduction'
|
|
125
|
+
`).run(e).changes,o=r.prepare(`
|
|
126
|
+
DELETE FROM files
|
|
127
|
+
WHERE direction = 'in' AND peer_cid = ? AND inbox_state = 'pending_introduction'
|
|
128
|
+
`).run(e).changes;return n+o})();for(let n of s)g(t.dir,n);return i>0&&m(t.dir),i}function se(t){let e=d(t);return{pending_introductions:Number(e.prepare(`
|
|
129
|
+
SELECT
|
|
130
|
+
(SELECT COUNT(*) FROM messages WHERE inbox_state = 'pending_introduction') +
|
|
131
|
+
(SELECT COUNT(*) FROM files WHERE inbox_state = 'pending_introduction')
|
|
132
|
+
`).pluck().get()),monitoring_copies:Number(e.prepare(`
|
|
133
|
+
SELECT COUNT(*) FROM monitoring_items WHERE queue_state = 'pending'
|
|
134
|
+
`).pluck().get()),control_requests:Number(e.prepare(`
|
|
135
|
+
SELECT COUNT(*) FROM control_requests WHERE queue_state = 'pending'
|
|
136
|
+
`).pluck().get())}}function N(t){let e=t??F;if(!Number.isSafeInteger(e)||e<1||e>E)throw new Error(`limit must be an integer from 1 to ${E}`);return e}function oe(t){return d(t).prepare(`
|
|
137
|
+
SELECT seq, wire_id, peer_cid, peer_name_snapshot, occurred_at_ms,
|
|
138
|
+
reply_to_wire_id, reply_to_sentence, encryption
|
|
139
|
+
FROM messages
|
|
140
|
+
WHERE direction = 'in' AND inbox_state = 'unread'
|
|
141
|
+
ORDER BY seq ASC
|
|
142
|
+
`).all().map(r=>({seq:r.seq,msg_id:r.seq,wire_id:r.wire_id,from:{id:r.peer_cid,name:r.peer_name_snapshot},occurred_at_ms:r.occurred_at_ms,date:w(r.occurred_at_ms),encryption:r.encryption,inbox_state:"unread",status:"unread",reply_to:R(r)}))}function ae(t,e={}){let r=d(t),s=N(e.limit),i=e.wire_ids,n=r.transaction(()=>{let o;if(i!==void 0){if(i.length<1||i.length>E)throw new Error(`wire_ids must contain 1-${E} items`);if(new Set(i).size!==i.length)throw new Error("wire_ids must not contain duplicates");let c=r.prepare(`
|
|
143
|
+
SELECT * FROM messages WHERE wire_id = ? AND direction = 'in' AND inbox_state = 'unread'
|
|
144
|
+
`);if(o=i.map(l=>c.get(l)).filter(l=>!!l),o.length!==i.length)throw new Error("selected message wire_id is unknown, stale, or no longer unread")}else o=r.prepare(`
|
|
145
|
+
SELECT * FROM messages
|
|
146
|
+
WHERE direction = 'in' AND inbox_state = 'unread'
|
|
147
|
+
ORDER BY seq ASC LIMIT ?
|
|
148
|
+
`).all(s);let _=r.prepare(`
|
|
149
|
+
UPDATE messages SET inbox_state = 'read'
|
|
150
|
+
WHERE seq = ? AND direction = 'in' AND inbox_state = 'unread'
|
|
151
|
+
`);for(let c of o){if(_.run(c.seq).changes!==1)throw new Error(`message row ${c.seq} changed during read batch`);c.inbox_state="read"}let u=Number(r.prepare(`
|
|
152
|
+
SELECT COUNT(*) FROM messages WHERE direction = 'in' AND inbox_state = 'unread'
|
|
153
|
+
`).pluck().get());return{messages:o.map(L),remaining:u}})();return n.messages.length>0&&m(t.dir),n}function de(t){return d(t).prepare(`
|
|
154
|
+
SELECT * FROM files WHERE direction = 'in' AND inbox_state = 'unread' ORDER BY seq ASC
|
|
155
|
+
`).all().map(r=>f(t,r))}function ce(t,e={}){let r=d(t),s=N(e.limit),i=e.wire_ids;return r.transaction(()=>{let o;if(i!==void 0){if(i.length<1||i.length>E)throw new Error(`wire_ids must contain 1-${E} items`);if(new Set(i).size!==i.length)throw new Error("wire_ids must not contain duplicates");let c=r.prepare(`
|
|
156
|
+
SELECT * FROM files WHERE wire_id = ? AND direction = 'in' AND inbox_state = 'unread'
|
|
157
|
+
`);if(o=i.map(l=>c.get(l)).filter(l=>!!l),o.length!==i.length)throw new Error("selected file wire_id is unknown, stale, or no longer unread")}else o=r.prepare(`
|
|
158
|
+
SELECT * FROM files WHERE direction = 'in' AND inbox_state = 'unread'
|
|
159
|
+
ORDER BY seq ASC LIMIT ?
|
|
160
|
+
`).all(s);let _=r.prepare(`
|
|
161
|
+
UPDATE files SET inbox_state = 'read', human_read_at_ms = COALESCE(human_read_at_ms, ?)
|
|
162
|
+
WHERE seq = ? AND direction = 'in' AND inbox_state = 'unread'
|
|
163
|
+
`);for(let c of o){let l=Date.now();if(_.run(l,c.seq).changes!==1)throw new Error(`file row ${c.seq} changed during read batch`);c.inbox_state="read",c.human_read_at_ms=l}let u=Number(r.prepare(`
|
|
164
|
+
SELECT COUNT(*) FROM files WHERE direction = 'in' AND inbox_state = 'unread'
|
|
165
|
+
`).pluck().get());return{files:o.map(c=>f(t,c)),remaining:u}})()}function A(t){let e=[],r=[];return t.peer_cid!==void 0&&(e.push("peer_cid = ?"),r.push(t.peer_cid)),t.direction!==void 0&&(e.push("direction = ?"),r.push(t.direction)),t.before_seq!==void 0&&(e.push("seq < ?"),r.push(t.before_seq)),{sql:e.length?`WHERE ${e.join(" AND ")}`:"",args:r}}function _e(t,e={}){let r=d(t),s=N(e.limit),i=A(e),n=r.prepare(`SELECT * FROM messages ${i.sql} ORDER BY seq DESC LIMIT ?`).all(...i.args,s+1),o=n.length>s;return o&&n.pop(),{items:n.map(L),next_cursor:o?n.at(-1).seq:null}}function ue(t,e){let r=d(t).prepare("SELECT * FROM messages WHERE wire_id = ?").get(e);return r?L(r):null}function le(t,e){let r=d(t).prepare(`
|
|
166
|
+
SELECT COUNT(*) AS total,
|
|
167
|
+
SUM(CASE WHEN direction = 'in' AND inbox_state = 'unread' THEN 1 ELSE 0 END) AS unread
|
|
168
|
+
FROM messages WHERE peer_cid = ?
|
|
169
|
+
`).get(e.peer_cid);return{total:Number(r.total),unread:Number(r.unread??0)}}function me(t,e={}){let r=d(t),s=N(e.limit),i=A(e),n=r.prepare(`SELECT * FROM files ${i.sql} ORDER BY seq DESC LIMIT ?`).all(...i.args,s+1),o=n.length>s;return o&&n.pop(),{items:n.map(_=>f(t,_)),next_cursor:o?n.at(-1).seq:null}}function Y(t,e){let r=d(t).prepare("SELECT * FROM files WHERE wire_id = ?").get(e);return r?f(t,r):null}function pe(t,e){let r=Y(t,e);if(!r||!a.existsSync(r.blob_path))return null;let s=H(t.dir),i=H(r.blob_path);return i.startsWith(`${s}${M}`)?i:null}function Ee(t,e,r,s){let i=d(t),n=r==="read"?2:1;i.transaction(()=>{for(let _ of s)for(let u of["messages","files"])i.prepare(`
|
|
170
|
+
UPDATE ${u}
|
|
171
|
+
SET delivery_state = ?, human_read_at_ms = CASE WHEN ? = 'read' THEN COALESCE(human_read_at_ms, ?) ELSE human_read_at_ms END
|
|
172
|
+
WHERE wire_id = ? AND peer_cid = ? AND direction = 'out'
|
|
173
|
+
AND (CASE delivery_state WHEN 'read' THEN 2 WHEN 'delivered' THEN 1 WHEN 'sent' THEN 0 ELSE -1 END) < ?
|
|
174
|
+
`).run(r,r,Date.now(),_,e,n)})(),s.length>0&&m(t.dir)}function ge(t){let e=d(t);return{messages:Number(e.prepare("SELECT COUNT(*) FROM messages WHERE direction='in' AND inbox_state='unread'").pluck().get()),files:Number(e.prepare("SELECT COUNT(*) FROM files WHERE direction='in' AND inbox_state='unread'").pluck().get())}}export{X as a,z as b,j as c,J as d,Z as e,d as f,v as g,ee as h,te as i,re as j,ie as k,ne as l,se as m,oe as n,ae as o,de as p,ce as q,_e as r,ue as s,le as t,me as u,Y as v,pe as w,Ee as x,ge as y};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import{e as o}from"./chunk-2X5HGMMO.js";var n=["OURS_STATE_DIR","OURS_BROKER_URL","OURS_PORT","OURS_API_VISIBILITY","OURS_HISTORY_MAX_BYTES","OURS_CONFIG"],i=Object.fromEntries(n.map(e=>[e,process.env[e]])),{stateDir:s,brokerUrl:a}=o();function c(){let e=n.filter(t=>process.env[t]!==i[t]);if(e.length===0)return;let r=e.map(t=>`${t}: was ${JSON.stringify(i[t]??"(unset)")} at import, is now ${JSON.stringify(process.env[t]??"(unset)")}`).join("; ");throw new Error(`configuration changed after @ours.network/sdk was imported (${r}). The SDK reads its config ONCE, at module load, because CONFIG and STATE_DIR back process-wide singletons that cannot be re-pointed once identities exist. Setting these after the import does not fail and does not take effect \u2014 without this check the daemon would boot against ${JSON.stringify(s)} and broker ${JSON.stringify(a)} and look like it worked. Set every OURS_* config variable BEFORE the first import of this package.`)}export{c as a};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a as p}from"./chunk-65KGEJBX.js";import{a}from"./chunk-JTBQO6IT.js";var c=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,i){let r=await this.fetchImpl(`${this.base}/api/v1/${e}`,{method:"POST",headers:this.headers({"content-type":"application/json"}),body:JSON.stringify(i??{})}),t;try{t=await r.json()}catch{throw new Error(`${e}: the daemon returned a non-JSON response (HTTP ${r.status})`)}if(t&&typeof t=="object"&&!Array.isArray(t)&&"error"in t){let s=t.error,o=s!==null&&typeof s=="object"&&"code"in s&&"message"in s;if(r.status===400&&o){let{code:y,message:d,details:l}=s;throw new p(y,d,l)}let n=o?s.message:String(s);throw new Error(`${e}: ${n} (HTTP ${r.status})`)}if(!r.ok)throw new Error(`${e}: the daemon returned HTTP ${r.status} with no error field`);return t}async get(e,i){let r=await this.fetchImpl(`${this.base}${e}`,{headers:i?this.headers():{}}),t;try{t=await r.json()}catch{throw new Error(`GET ${e}: the daemon returned a non-JSON response (HTTP ${r.status})`)}if(t&&typeof t=="object"&&"error"in t)throw new Error(`GET ${e}: ${String(t.error)} (HTTP ${r.status})`);if(!r.ok)throw new Error(`GET ${e}: the daemon returned HTTP ${r.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(e={}){return this.post("getMessages",e)}listHistory(e={}){return this.post("listHistory",e)}getHistoryItem(e){return this.post("getHistoryItem",e)}getHistorySummary(e){return this.post("getHistorySummary",e)}listFiles(e={}){return this.post("listFiles",e)}getFileInfo(e){return this.post("getFileInfo",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,i={}){let r=i.since??"tip",t=`/identities/${encodeURIComponent(e)}/notifications`,s=i.kinds?.length?`&kinds=${encodeURIComponent(i.kinds.join(","))}`:"";for(;!i.signal?.aborted;){let o;try{let n=await this.fetchImpl(`${this.base}${t}?since=${r}${s}`,{headers:this.headers(),signal:i.signal});try{o=await n.json()}catch{throw new Error(`watchNotifications(${e}): the daemon returned a non-JSON response (HTTP ${n.status})`)}}catch(n){if(i.signal?.aborted)return;throw n}if("error"in o)throw new Error(`watchNotifications(${e}): ${o.error}`);r=o.cursor;for(let n of o.events)yield a(n&&typeof n=="object"?n:{})}}async fetchFile(e){let i=await this.fetchImpl(`${this.base}/files/${encodeURIComponent(e)}`,{headers:this.headers()});if(!i.ok){let r=`HTTP ${i.status}`;try{let t=await i.json();t&&t.error!==void 0&&(r=String(t.error))}catch{}throw new Error(`fetchFile(${e}): ${r}`)}return new Uint8Array(await i.arrayBuffer())}async openFile(e){let i=await this.fetchImpl(`${this.base}/files/${encodeURIComponent(e)}`,{headers:this.headers()});if(!i.ok){let r=`HTTP ${i.status}`;try{let t=await i.json();t&&t.error!==void 0&&(r=String(t.error))}catch{}throw new Error(`openFile(${e}): ${r}`)}if(!i.body)throw new Error(`openFile(${e}): the daemon returned no body`);return i.body}async uploadFile(e,i){let r=e instanceof Uint8Array?e.byteLength:i.size;if(r===void 0)throw new Error("uploadFile: `size` is required when the body is a stream (the route needs Content-Length)");let t=await this.fetchImpl(`${this.base}/files/upload`,{method:"POST",headers:{...this.headers(),"x-ours-filename":encodeURIComponent(i.filename),"Content-Type":i.mime||"application/octet-stream","Content-Length":String(r)},body:e,...e instanceof Uint8Array?{}:{duplex:"half"}});if(!t.ok){let s=`HTTP ${t.status}`;try{let o=await t.json();o&&o.error!==void 0&&(s=String(o.error))}catch{}throw new Error(`uploadFile(${i.filename}): ${s}`)}return await t.json()}};export{c as a};
|
|
2
|
+
import{a as p}from"./chunk-65KGEJBX.js";import{a}from"./chunk-JTBQO6IT.js";var c=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,i){let r=await this.fetchImpl(`${this.base}/api/v1/${e}`,{method:"POST",headers:this.headers({"content-type":"application/json"}),body:JSON.stringify(i??{})}),t;try{t=await r.json()}catch{throw new Error(`${e}: the daemon returned a non-JSON response (HTTP ${r.status})`)}if(t&&typeof t=="object"&&!Array.isArray(t)&&"error"in t){let s=t.error,o=s!==null&&typeof s=="object"&&"code"in s&&"message"in s;if(r.status===400&&o){let{code:y,message:d,details:l}=s;throw new p(y,d,l)}let n=o?s.message:String(s);throw new Error(`${e}: ${n} (HTTP ${r.status})`)}if(!r.ok)throw new Error(`${e}: the daemon returned HTTP ${r.status} with no error field`);return t}async get(e,i){let r=await this.fetchImpl(`${this.base}${e}`,{headers:i?this.headers():{}}),t;try{t=await r.json()}catch{throw new Error(`GET ${e}: the daemon returned a non-JSON response (HTTP ${r.status})`)}if(t&&typeof t=="object"&&"error"in t)throw new Error(`GET ${e}: ${String(t.error)} (HTTP ${r.status})`);if(!r.ok)throw new Error(`GET ${e}: the daemon returned HTTP ${r.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(e={}){return this.post("getMessages",e)}listHistory(e={}){return this.post("listHistory",e)}getHistoryItem(e){return this.post("getHistoryItem",e)}getHistorySummary(e){return this.post("getHistorySummary",e)}listFiles(e={}){return this.post("listFiles",e)}getFileInfo(e){return this.post("getFileInfo",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)}historyStorage(){return this.get("/history-storage",!0)}async*watchNotifications(e,i={}){let r=i.since??"tip",t=`/identities/${encodeURIComponent(e)}/notifications`,s=i.kinds?.length?`&kinds=${encodeURIComponent(i.kinds.join(","))}`:"";for(;!i.signal?.aborted;){let o;try{let n=await this.fetchImpl(`${this.base}${t}?since=${r}${s}`,{headers:this.headers(),signal:i.signal});try{o=await n.json()}catch{throw new Error(`watchNotifications(${e}): the daemon returned a non-JSON response (HTTP ${n.status})`)}}catch(n){if(i.signal?.aborted)return;throw n}if("error"in o)throw new Error(`watchNotifications(${e}): ${o.error}`);r=o.cursor;for(let n of o.events)yield a(n&&typeof n=="object"?n:{})}}async fetchFile(e){let i=await this.fetchImpl(`${this.base}/files/${encodeURIComponent(e)}`,{headers:this.headers()});if(!i.ok){let r=`HTTP ${i.status}`;try{let t=await i.json();t&&t.error!==void 0&&(r=String(t.error))}catch{}throw new Error(`fetchFile(${e}): ${r}`)}return new Uint8Array(await i.arrayBuffer())}async openFile(e){let i=await this.fetchImpl(`${this.base}/files/${encodeURIComponent(e)}`,{headers:this.headers()});if(!i.ok){let r=`HTTP ${i.status}`;try{let t=await i.json();t&&t.error!==void 0&&(r=String(t.error))}catch{}throw new Error(`openFile(${e}): ${r}`)}if(!i.body)throw new Error(`openFile(${e}): the daemon returned no body`);return i.body}async uploadFile(e,i){let r=e instanceof Uint8Array?e.byteLength:i.size;if(r===void 0)throw new Error("uploadFile: `size` is required when the body is a stream (the route needs Content-Length)");let t=await this.fetchImpl(`${this.base}/files/upload`,{method:"POST",headers:{...this.headers(),"x-ours-filename":encodeURIComponent(i.filename),"Content-Type":i.mime||"application/octet-stream","Content-Length":String(r)},body:e,...e instanceof Uint8Array?{}:{duplex:"half"}});if(!t.ok){let s=`HTTP ${t.status}`;try{let o=await t.json();o&&o.error!==void 0&&(s=String(o.error))}catch{}throw new Error(`uploadFile(${i.filename}): ${s}`)}return await t.json()}};export{c as a};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a as F}from"./chunk-
|
|
2
|
+
import{a as F}from"./chunk-N4N4OLEW.js";import{b as H,c as x}from"./chunk-W34RPHBG.js";import{d as B}from"./chunk-WZQNO4PZ.js";import{O as L,e as u,g as T,i as c,j as r,k as w,l as D,m as M,n as A,s as U,u as P,v as C}from"./chunk-AH3RIV2J.js";import{a as O,b as $,c as k}from"./chunk-YRPUM6JG.js";import{j as N}from"./chunk-7Q3OCSPV.js";import{h as I}from"./chunk-RL3OEL5W.js";import{a as g,b,c as l,e as S,q as R,r as v,v as E}from"./chunk-5JKYJZAR.js";import{d as h,i as s,j as o}from"./chunk-IFCOOPD7.js";import{adapt_wrapper as j}from"@adapt-toolkit/sdk/executables";var _=!1;function ne(){return _}function z(){if(_)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.');_=!0,F()}async function se(){z(),s?.update("wrapper"),k(O());let W=["--broker_address",h,"--test_mode","--logger_config","--level","INFO","--stdout","stderr","--logger_config_end"];o(`booting wrapper (unit ${$.hash.slice(0,12)}\u2026, broker ${h})`),b(await j.start(W)),g.on_packet_created_cb=e=>o(`wrapper: packet ready ${e.slice(0,12)}\u2026`),g.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 C()}catch(e){o("failed to start the contact-book registrar (local contact book disabled):",String(e))}v(),c(w());let m=E(),a=r&&m.includes(r)?[r,...m.filter(e=>e!==r)]:m,d=Math.max(0,Number(process.env.OURS_TEST_FAKE_RESTORE_COUNT||"")||0),f=Math.max(0,Number(process.env.OURS_TEST_FAKE_RESTORE_MS||"")||0),K=a.length===0&&d>0?d:a.length;s?.update("identities",{completed:0,total:K});for(let e of a)U.add(e);if(a.length===0&&d>0){o(`TEST: simulating ${d} fake identity restore(s), ${f}ms each`);for(let e=0;e<d;e++)f>0&&await new Promise(n=>setTimeout(n,f)),s?.update("identities",{completed:e+1,total:d})}else if(a.length===0)o("no persisted identities \u2014 start with create_identity");else{o(`restoring ${a.length} identit${a.length===1?"y":"ies"}: ${a.join(", ")}`);for(let[e,n]of a.entries()){try{let t=await P(n);S&&await L(t);let i=R(t.dir);i&&(t.temp=i)}catch(t){throw o(`failed to restore "${n}":`,String(t)),t}s?.update("identities",{completed:e+1,total:a.length})}}s?.update("reconciliation"),B(),c(w()),r&&!l.has(r)&&(o(`root marker names a missing identity "${r}" \u2014 clearing it`),c(null),D()),r&&o(`root identity: ${r}`);{let e=r?l.get(r):void 0;r&&!e&&o(`re-delegation on upgrade DEGRADED: root "${r}" is not among the restored identities \u2014 role certs not refreshed this boot`);let n=[];if(e)for(let t of l.values()){if(t.name===e.name)continue;let i;try{i=M(t)}catch{i=void 0}if(!(!i||!i.hasCert)){if(i.rootCid!==e.cid){o(`[${t.name}] re-delegation skipped: delegated by a different root (${i.rootCid.slice(0,12)}\u2026), not this host root \u2014 left as-is`);continue}try{await A(e,t),n.push(t)}catch(y){N(t,{event:"redelegation_failed",error:String(y).slice(0,300)}),o(`[${t.name}] boot re-delegation (upgrade cert refresh) failed:`,String(y))}}}for(let t of l.values()){await u(t),await T(t);for(let i of[1e4,3e4,9e4])setTimeout(()=>{u(t).catch(()=>{})},i),setTimeout(()=>{T(t).catch(()=>{})},i)}n.length>0&&o(`refreshed ${n.length} role delegation cert(s) against the live AD on boot`)}I(),await x(),await H()}export{ne as a,se as b};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{c as p}from"./chunk-
|
|
2
|
+
import{c as p}from"./chunk-5JKYJZAR.js";import{c as d,j as a}from"./chunk-IFCOOPD7.js";import{join as h}from"node:path";import*as i from"node:fs";var r=new Map,l=new Set,c=new Map,S=new Set;function k(e){if(!Number.isInteger(e)||e<=0)return!1;try{return process.kill(e,0),!0}catch(t){return t.code==="EPERM"}}function x(e){if(!Number.isInteger(e)||e<=1)return!1;try{return process.kill(e,0),!1}catch(t){return t.code==="ESRCH"}}function m(e){for(let t of r.values())if(t.token===e)return t}var f=()=>h(d,"bindings.json");function g(){try{i.mkdirSync(d,{recursive:!0});let e=`${f()}.tmp`;i.writeFileSync(e,JSON.stringify({pid:process.pid,bound:[...r.keys()],holders:[...r.values()].map(t=>({identity:t.identity,pid:t.pid}))})),i.renameSync(e,f())}catch(e){a("failed to persist bindings snapshot:",String(e))}}function I(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(l.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=p.get(n.identity);if(!o)return r.delete(n.identity),g(),{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 _(e,t){let n=c.get(e),o=n?.token;if(!o)return;for(let[u,y]of[...r])y.token===o&&u!==t&&r.delete(u);let s=r.get(t)?.epoch??0;r.set(t,{identity:t,token:o,pid:n?.pid??0,sid:e,epoch:s+1,boundAt:Date.now()}),l.delete(o),g()}export{r as a,l as b,c,S as d,k as e,x as f,m as g,g as h,I as i,_ as j};
|
|
@@ -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-3CPIRV4P.js";import{M as o}from"./chunk-65KGEJBX.js";import{r as y,s as n,t as g,u as m,v as u}from"./chunk-MGNMJ64X.js";function a(t,r={}){let e=s(t);try{return y(e,r)}catch(i){throw o("list_history",String(i))}}function p(t,r){let e=s(t);try{return n(e,r.wire_id)}catch(i){throw o("get_history_item",String(i))}}function S(t,r){let e=s(t);try{return g(e,r)}catch(i){throw o("get_history_summary",String(i))}}function f(t,r={}){let e=s(t);try{return m(e,r)}catch(i){throw o("list_files",String(i))}}function h(t,r){let e=s(t);try{return u(e,r.wire_id)}catch(i){throw o("get_file_info",String(i))}}export{a,p as b,S as c,f as d,h as e};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{d as a,e as l,g as c}from"./chunk-
|
|
2
|
+
import{d as a,e as l,g as c}from"./chunk-AH3RIV2J.js";import{c as o}from"./chunk-5JKYJZAR.js";import{f as r,j as n}from"./chunk-IFCOOPD7.js";var e=null,i=!1;function s(){e||(e=setInterval(()=>{i||(i=!0,(async()=>{try{for(let t of o.values())await a(t),await l(t),await c(t)}finally{i=!1}})())},r),e.unref?.(),n(`protocol maintenance timer armed (every ${r}ms)`))}function u(){e&&(clearInterval(e),e=null)}export{s as a,u as b};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{b as u}from"./chunk-
|
|
2
|
+
import{b as u}from"./chunk-Y77ZVHTD.js";import{s as l}from"./chunk-AH3RIV2J.js";import{a as f,f as s}from"./chunk-RL3OEL5W.js";import{c as d,d as a,q as c}from"./chunk-5JKYJZAR.js";import{c as o,j as m}from"./chunk-IFCOOPD7.js";import{join as h}from"node:path";import*as n from"node:fs";function E(e=process.env.OURS_SESSION_REAPER_INTERVAL_MS){if(e===void 0||e.trim()==="")return 5e3;let i=Number(e);return Number.isFinite(i)?Math.max(100,Math.trunc(i)):5e3}async function R(){let e=[...d.values(),...[...a.values()].map(r=>r.identity)],i=[];for(let r of e){let t=r.temp;if(!t||t.closing||!s(t.owner.pid))continue;let p=f.get(r.name);p&&!s(p.pid)||i.push(u(r,`stale lease \u2014 owner pid ${t.owner.pid} is dead`).then(()=>{a.delete(r.name)}).catch(y=>m(`[${r.name}] stale-temp reclaim failed:`,String(y))))}await Promise.all(i)}async function $(){if(n.existsSync(o))for(let e of n.readdirSync(o,{withFileTypes:!0})){if(!e.isDirectory()||d.has(e.name)||a.has(e.name))continue;let i=h(o,e.name),r=c(i);if(!(!r||!s(r.owner.pid)))try{n.rmSync(i,{recursive:!0,force:!0}),l.delete(e.name),m(`[${e.name}] removed orphaned temporary-identity dir (owner pid ${r.owner.pid} confirmed dead)`)}catch(t){throw new Error(`[${e.name}] failed to remove orphaned temporary-identity dir: ${String(t)}`)}}}export{E as a,R as b,$ as c};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{A as f,E as u,I as p,K as m,f as l,j as c,m as w}from"./chunk-
|
|
2
|
+
import{A as f,E as u,I as p,K as m,f as l,j as c,m as w}from"./chunk-AH3RIV2J.js";import{c as s,e as d}from"./chunk-5JKYJZAR.js";function x(e,t){if(!c||!s.has(c))return null;let n=s.get(t)??[...s.values()].find(r=>r.cid===t);if(!n||n.name===e.name)return null;let i=r=>r.name===c||w(r).roleId!=="";return i(e)&&i(n)?n:null}async function S(e,t,n){let i=m(t),r=await f(async a=>(await u(e,"::actor::connect_sibling",{name:t.name,target_ad:e.pw.packet.NewBinaryFromBuffer(i).Attach(a),text:n},a)).Reduce("wire_id").Visualize());return l(e),{text:`"${t.name}" was not a contact yet \u2014 connected as an intra-root sibling (delegation-cert auto-accept) and delivered the message.`,wireId:r}}async function N(e,t,n){if(!d)throw new Error(`"${t}" is not a contact, and the local contact book is unavailable.`);let i=p(),r=i[t]??Object.values(i).find(o=>o.container_id===t);if(!r)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(r.container_id===e.cid)throw new Error("that contact-book entry is this identity itself.");let a=Buffer.from(r.address_document,"base64url"),g=Buffer.from(r.registrar_sig,"base64url"),y=m(e),k=await f(async o=>{let b=await u(d,"::actor::mint_introduction",{joiner_ad:d.pw.packet.NewBinaryFromBuffer(y).Attach(o),target_ad:d.pw.packet.NewBinaryFromBuffer(a).Attach(o)},o),h=Buffer.from(b.Reduce("intro").GetBinary());return(await u(e,"::actor::connect_local",{name:r.name,target_ad:e.pw.packet.NewBinaryFromBuffer(a).Attach(o),intro:e.pw.packet.NewBinaryFromBuffer(h).Attach(o),entry_sig:e.pw.packet.NewBinaryFromBuffer(g).Attach(o),text:n},o)).Reduce("wire_id").Visualize()});return l(e),{text:`"${r.name}" was not a contact yet \u2014 connected via the local contact book and sent the message with the introduction. If "${r.name}" requires approval for local introductions, delivery completes once they approve.`,wireId:k}}var q=e=>{let t=r=>!e.Reduce(r).IsNil(),n=e.Reduce("wire_id").Visualize(),i=t("sent_to")?e.Reduce("sent_to").Visualize():"";if(t("downgrade_refused"))return{kind:"refused",wireId:n,cid:i};if(t("migrating"))return{kind:"migrating",wireId:n,cid:i,queued:t("queued")?Number(e.Reduce("queued").Visualize()):0};if(t("route")){let r=t("retained")&&!e.Reduce("retained").GetBoolean();return{kind:"e2e",wireId:n,cid:i,notRetained:r}}return t("deferred")?{kind:"deferred",wireId:n,queued:t("queued")?Number(e.Reduce("queued").Visualize()):0}:{kind:"sent",wireId:n}};export{x as a,S as b,N as c,q as d};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a as P,b,c as w,d as H,e as M,f as T,g as N,h as L,i as B,j}from"./chunk-
|
|
2
|
+
import{a as P,b,c as w,d as H,e as M,f as T,g as N,h as L,i as B,j}from"./chunk-ZOZFAMAX.js";import{a as E,b as J,c as _}from"./chunk-AAXXFRZP.js";import{a as $,b as U,c as V,d as X,e as q}from"./chunk-UZF6OB3R.js";import{a as z,b as D,c as G,d as K}from"./chunk-XKPZWKI4.js";import{a as Q,b as W,c as Y,d as Z}from"./chunk-3ZIC5X5I.js";import{b as u,c as v,d as h,e as S,f as k,g as x,h as O,i as R,j as C,k as F}from"./chunk-3CPIRV4P.js";import{a as f}from"./chunk-65KGEJBX.js";import{c as d}from"./chunk-RL3OEL5W.js";import{o as I}from"./chunk-5JKYJZAR.js";import{j as m,n as g}from"./chunk-IFCOOPD7.js";var ie="/api/v1/",e=i=>(t,n)=>i(t,n),s=i=>t=>i(t),ne=i=>(t,n)=>i(n),ee={createIdentity:e(u),createTemporaryIdentity:e(v),closeTemporaryIdentityOp:e(h),createRootIdentity:e(S),defineLocalIdentityFile:ne(k),chooseIdentity:e(x),listIdentities:s(O),currentIdentity:s(R),removeIdentity:e(C),releaseLease:s(F),generateInvite:e(P),listInvites:s(b),revokeInvite:e(w),addContact:e(H),listContacts:s(M),listLocalContactBook:s(T),setLocalBookPolicy:e(N),removeContact:e(L),renameContact:e(B),respondToIntroduction:e(j),setBio:e(Q),advertiseMigrate:s(W),readvertiseOnUpgrade:s(Z),setPersona:e(Y),sendMessage:e(z),sendFile:e(D),listIncomingMessages:s(G),getMessages:e(K),listHistory:e($),getHistoryItem:e(U),getHistorySummary:e(V),listFiles:e(X),getFileInfo:e(q),listIncomingFiles:s(E),getFiles:e(J),saveFileFallbackNotice:e(_)},l=new Map,te=(i,t)=>{let n=i.headers[t];return typeof n=="string"&&n!==""?n:void 0};function oe(i){let t=te(i,"x-ours-lease-token"),n=te(i,"x-ours-client-pid"),y=n?parseInt(n,10):NaN,a=Number.isInteger(y)?y:void 0,o=t?`api:${I(t)}`:"api:anonymous";return d.set(o,{token:t,pid:a}),l.set(o,(l.get(o)??0)+1),{ctx:{sessionId:()=>o,leaseToken:()=>d.get(o)?.token,clientPid:()=>d.get(o)?.pid},release:()=>{let r=(l.get(o)??1)-1;if(r>0){l.set(o,r);return}l.delete(o),d.delete(o)}}}var c=(i,t,n)=>{i.writableEnded||(i.writeHead(t,{"Content-Type":"application/json"}),i.end(JSON.stringify(n??null)))};async function ge(i,t,n,y){let a=n.slice(ie.length);if(!g(i,t))return;if(i.method!=="POST"){c(t,405,{error:"method not allowed: the typed API is POST-only"});return}let o=Object.prototype.hasOwnProperty.call(ee,a)?ee[a]:void 0;if(!o){c(t,404,{error:`unknown operation "${a}"`});return}let r;try{r=await y(i)}catch{c(t,400,{error:"the request body must be JSON"});return}if(r===null||typeof r!="object"||Array.isArray(r)){c(t,400,{error:"the request body must be a JSON object"});return}let A=oe(i);try{c(t,200,await o(A.ctx,r))}catch(p){if(p instanceof f){c(t,400,{error:{code:p.code,message:p.message,...p.details?{details:p.details}:{}}});return}m("api handler error:",a,String(p)),c(t,500,{error:`internal error in ${a}: ${String(p)}`})}finally{A.release()}}export{ie as a,ee as b,oe as c,ge as d};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a as l}from"./chunk-
|
|
2
|
+
import{a as l}from"./chunk-E34QSIVP.js";import{A as p,B as f,E as m,m as o}from"./chunk-AH3RIV2J.js";import{c as r}from"./chunk-5JKYJZAR.js";import{j as u}from"./chunk-IFCOOPD7.js";var A=()=>d,d=!0,C=d?2:1;function g(e,n){let a=[];for(let t of r.values()){if(t.name===e.name)continue;let i=o(t);if(i.rootCid!==e.cid)continue;let c=f(t,"::actor::export_address_document_native",n);a.push({cid:c.Reduce("identity").Reduce("container_id"),role_id:i.roleId,name:t.name,bio:i.bio,persona:i.persona,caps:l(t),child_ad:c})}return a}var s=new Set;async function y(e){if(!s.has(e.name)){s.add(e.name);try{await p(async n=>{await m(e,"::a2a_cluster::reconcile",{pending_handle:"",children:g(e,n)},n)})}catch(n){u(`[${e.name}] cluster sweep failed:`,String(n))}finally{s.delete(e.name)}}}var w=6e4;function T(){setInterval(()=>{if(d)for(let e of r.values())o(e).roleId===""&&y(e)},w).unref()}export{A as a,C as b,y as c,T as d};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import*as u from"node:fs";import{basename as m,dirname as d,join as p,resolve as y,sep as x}from"node:path";import ee from"better-sqlite3";var H="history.sqlite3",O=p("blobs","sha256"),Y=256,Q=1024,j=8,te=128*1024*1024,ie=1024*1024,D=5*60*1e3,q=50,ne=5e3,l=null,k=0,L=!1,_=null,E=!1,C=q,b=new Set,M=new Map,F=0,U=0,N=0,W=null,A={state:"disabled",enabled:!1,max_bytes:0,physical_bytes:0,overflow_bytes:0,protected_logical_bytes:0,eligible_logical_bytes:0,protected_items:0,eligible_items:0,newest_item_retained:!1,maintenance_pending:!1,compaction_blocked_identities:[],evicted_messages:0,evicted_files:0,orphaned_blobs_removed:0,last_run_at_ms:null};function se(i){return Number.isSafeInteger(i)&&i>=0}function re(i){if(!l)return!1;let t=l.stateDir,e=y(i);return e===t||e.startsWith(`${t}${x}`)}function R(i,t){let e;try{e=u.lstatSync(i)}catch{return 0}if(!e.isFile())return 0;let n=`${String(e.dev)}:${String(e.ino)}`;return e.ino&&t.has(n)?0:(e.ino&&t.add(n),typeof e.blocks=="number"?e.blocks*512:e.size)}function P(i,t){let e;try{e=u.readdirSync(i,{withFileTypes:!0})}catch{return}for(let n of e){let s=p(i,n.name);n.isDirectory()?P(s,t):n.isFile()&&t(s)}}function v(i){let t;try{t=u.readdirSync(i,{withFileTypes:!0})}catch{return[]}return t.filter(e=>e.isDirectory()).map(e=>p(i,e.name,H)).filter(e=>u.existsSync(e)).sort()}function T(i=l?.stateDir){if(!i)return 0;let t=new Set,e=0;for(let n of v(i)){for(let s of["","-wal","-shm"])e+=R(`${n}${s}`,t);P(p(d(n),O),s=>{e+=R(s,t)})}return e}function f(i){let t=new ee(i);return t.pragma("busy_timeout = 50"),t.pragma("foreign_keys = ON"),t}function ae(i){let t=i&&typeof i=="object"&&"code"in i?String(i.code??""):"";return t==="SQLITE_BUSY"||t.startsWith("SQLITE_BUSY_")||t==="SQLITE_LOCKED"||t.startsWith("SQLITE_LOCKED_")?!0:/(?:database|table) is locked|database is busy/i.test(String(i))}function g(i,t){ae(i)?E=!0:b.add(t)}function I(i){let t=i.pragma("wal_checkpoint(TRUNCATE)");return Number(t[0]?.busy??0)===0?!0:(E=!0,!1)}function oe(i){if(!u.existsSync(i))return;let t=m(d(i)),e=null;try{e=f(i);let n=Number(e.pragma("auto_vacuum",{simple:!0}));if(n===2){b.delete(t);return}if(n===1){e.pragma("auto_vacuum = INCREMENTAL"),b.delete(t);return}if(R(i,new Set)>te){b.add(t);return}if(!I(e))return;e.pragma("journal_mode = DELETE"),e.pragma("auto_vacuum = INCREMENTAL"),e.exec("VACUUM"),e.pragma("journal_mode = WAL"),b.delete(t)}catch(n){g(n,t)}finally{try{e?.close()}catch{}}}function le(i){let t=null;try{t=f(i);let e=t.prepare(`
|
|
3
|
+
SELECT kind, seq, occurred_at_ms, inserted_at_ms, logical_bytes, eligible FROM (
|
|
4
|
+
SELECT 'message' AS kind, seq, occurred_at_ms, inserted_at_ms,
|
|
5
|
+
length(CAST(body AS BLOB)) + 512 AS logical_bytes,
|
|
6
|
+
CASE WHEN inbox_state = 'read' AND direction = 'in' THEN 1
|
|
7
|
+
WHEN direction = 'out' AND delivery_state IN ('delivered','read') THEN 1 ELSE 0 END AS eligible
|
|
8
|
+
FROM messages
|
|
9
|
+
UNION ALL
|
|
10
|
+
SELECT 'file' AS kind, seq, occurred_at_ms, inserted_at_ms, byte_length + 512 AS logical_bytes,
|
|
11
|
+
CASE WHEN direction = 'in' AND inbox_state = 'read' AND human_read_at_ms <= ? THEN 1
|
|
12
|
+
WHEN direction = 'out' AND delivery_state IN ('delivered','read') THEN 1 ELSE 0 END AS eligible
|
|
13
|
+
FROM files
|
|
14
|
+
) ORDER BY inserted_at_ms DESC, occurred_at_ms DESC, kind DESC, seq DESC LIMIT 1
|
|
15
|
+
`).get(Date.now()-D);return e?{identityDir:d(i),kind:e.kind,seq:e.seq,occurredAtMs:e.occurred_at_ms,insertedAtMs:e.inserted_at_ms,logicalBytes:Number(e.logical_bytes),eligible:e.eligible===1}:null}catch(e){return g(e,m(d(i))),null}finally{try{t?.close()}catch{}}}function ce(i,t){return i.insertedAtMs!==t.insertedAtMs?i.insertedAtMs>t.insertedAtMs:i.occurredAtMs!==t.occurredAtMs?i.occurredAtMs>t.occurredAtMs:i.identityDir!==t.identityDir?i.identityDir>t.identityDir:i.kind!==t.kind?i.kind>t.kind:i.seq>t.seq}function z(i){let t=null;for(let e of i){let n=le(e);n&&(!t||ce(n,t))&&(t=n)}return t}function G(i,t){return!!t&&i.identityDir===t.identityDir&&i.kind===t.kind&&i.seq===t.seq}function $(i,t,e){return`${y(i)}\0${t}\0${e}`}function de(i,t){let e=[];for(let n of i){let s=null;try{s=f(n);let r=s.prepare(`
|
|
16
|
+
SELECT kind, seq, wire_id, occurred_at_ms, inserted_at_ms, logical_bytes, blob_relpath FROM (
|
|
17
|
+
SELECT 'message' AS kind, seq, wire_id, occurred_at_ms, inserted_at_ms,
|
|
18
|
+
length(CAST(body AS BLOB)) + 512 AS logical_bytes, NULL AS blob_relpath
|
|
19
|
+
FROM messages WHERE (direction = 'in' AND inbox_state = 'read')
|
|
20
|
+
OR (direction = 'out' AND delivery_state IN ('delivered','read'))
|
|
21
|
+
UNION ALL
|
|
22
|
+
SELECT 'file' AS kind, seq, wire_id, occurred_at_ms, inserted_at_ms,
|
|
23
|
+
byte_length + 512 AS logical_bytes, blob_relpath
|
|
24
|
+
FROM files WHERE (direction = 'in' AND inbox_state = 'read' AND human_read_at_ms <= ?)
|
|
25
|
+
OR (direction = 'out' AND delivery_state IN ('delivered','read'))
|
|
26
|
+
) ORDER BY occurred_at_ms ASC, inserted_at_ms ASC, kind ASC, seq ASC LIMIT ?
|
|
27
|
+
`).all(Date.now()-D,Y+1);for(let a of r){let o={dbPath:n,identityDir:d(n),kind:a.kind,seq:a.seq,wireId:a.wire_id,occurredAtMs:a.occurred_at_ms,insertedAtMs:a.inserted_at_ms,logicalBytes:Number(a.logical_bytes),eligible:!0,blobRelpath:a.blob_relpath};!G(o,t)&&!M.has($(o.identityDir,o.kind,o.wireId))&&e.push(o)}}catch(r){g(r,m(d(n)))}finally{try{s?.close()}catch{}}}return e.sort((n,s)=>n.occurredAtMs-s.occurredAtMs||n.insertedAtMs-s.insertedAtMs||n.identityDir.localeCompare(s.identityDir)||n.kind.localeCompare(s.kind)||n.seq-s.seq),e.slice(0,Y)}function ue(i,t){let e=y(p(i,O)),n=y(i,t);return n.startsWith(`${e}${x}`)?n:null}function V(i,t){let e=y(p(i,"blobs")),n=y(d(t));for(;n.startsWith(`${e}${x}`);){try{u.rmdirSync(n)}catch{break}n=d(n)}}function X(i,t,e){if(i.prepare("SELECT 1 FROM files WHERE blob_relpath = ? LIMIT 1").get(e))return!1;let n=ue(t,e);if(!n)return!1;try{return u.lstatSync(n).isFile()?(u.unlinkSync(n),V(t,n),!0):!1}catch{return!1}}function be(i,t){let e=[],n=0;for(let a of i)if(e.push(a),n+=Math.max(1,a.logicalBytes),n>=t)break;let s=new Map;for(let a of e){let o=s.get(a.dbPath)??[];o.push(a),s.set(a.dbPath,o)}let r=0;for(let[a,o]of s){let c=null;try{c=f(a);let S=[];c.transaction(()=>{let w=c.prepare(`
|
|
28
|
+
DELETE FROM messages WHERE seq = ? AND inbox_state = 'read'
|
|
29
|
+
AND (direction = 'in' OR delivery_state IN ('delivered','read'))
|
|
30
|
+
`),Z=c.prepare(`
|
|
31
|
+
DELETE FROM files WHERE seq = ? AND (
|
|
32
|
+
(direction = 'in' AND inbox_state = 'read' AND human_read_at_ms <= ?)
|
|
33
|
+
OR (direction = 'out' AND delivery_state IN ('delivered','read'))
|
|
34
|
+
)
|
|
35
|
+
`);for(let h of o)(h.kind==="message"?w.run(h.seq).changes:Z.run(h.seq,Date.now()-D).changes)===1&&(r+=1,h.kind==="message"?F+=1:(U+=1,h.blobRelpath&&S.push(h.blobRelpath)))})();for(let w of new Set(S))X(c,d(a),w)&&(N+=1);I(c),Number(c.pragma("auto_vacuum",{simple:!0}))===2?(c.pragma(`incremental_vacuum(${Q})`),I(c),b.delete(m(d(a)))):b.add(m(d(a)))}catch(S){g(S,m(d(a)))}finally{try{c?.close()}catch{}}}return r}function me(i){let t=d(i),e=null,n=0;try{e=f(i);let s=new Set(e.prepare("SELECT DISTINCT blob_relpath FROM files").pluck().all().map(o=>y(t,o))),r=p(t,O),a=[];P(r,o=>a.push(o));for(let o of a)if(!s.has(y(o)))try{u.unlinkSync(o),n+=1,V(t,o)}catch{}}catch(s){g(s,m(t))}finally{try{e?.close()}catch{}}return n}function _e(i,t){let e={protectedBytes:0,eligibleBytes:0,protectedItems:0,eligibleItems:0,newestRetained:!1};for(let n of i){let s=null;try{s=f(n);let r=s.prepare(`
|
|
36
|
+
SELECT
|
|
37
|
+
COALESCE(SUM(CASE WHEN eligible = 1 THEN logical_bytes ELSE 0 END), 0) AS eligible_bytes,
|
|
38
|
+
COALESCE(SUM(CASE WHEN eligible = 0 THEN logical_bytes ELSE 0 END), 0) AS protected_bytes,
|
|
39
|
+
COALESCE(SUM(eligible), 0) AS eligible_items,
|
|
40
|
+
COALESCE(SUM(CASE WHEN eligible = 0 THEN 1 ELSE 0 END), 0) AS protected_items
|
|
41
|
+
FROM (
|
|
42
|
+
SELECT length(CAST(body AS BLOB)) + 512 AS logical_bytes,
|
|
43
|
+
CASE WHEN direction = 'in' AND inbox_state = 'read' THEN 1
|
|
44
|
+
WHEN direction = 'out' AND delivery_state IN ('delivered','read') THEN 1 ELSE 0 END AS eligible
|
|
45
|
+
FROM messages
|
|
46
|
+
UNION ALL
|
|
47
|
+
SELECT byte_length + 512 AS logical_bytes,
|
|
48
|
+
CASE WHEN direction = 'in' AND inbox_state = 'read' AND human_read_at_ms <= ? THEN 1
|
|
49
|
+
WHEN direction = 'out' AND delivery_state IN ('delivered','read') THEN 1 ELSE 0 END AS eligible
|
|
50
|
+
FROM files
|
|
51
|
+
UNION ALL
|
|
52
|
+
SELECT length(CAST(body AS BLOB)) + 512, 0 FROM monitoring_items
|
|
53
|
+
UNION ALL
|
|
54
|
+
SELECT length(CAST(payload AS BLOB)) + 512, 0 FROM control_requests
|
|
55
|
+
)
|
|
56
|
+
`).get(Date.now()-D);e.eligibleBytes+=Number(r.eligible_bytes),e.protectedBytes+=Number(r.protected_bytes),e.eligibleItems+=Number(r.eligible_items),e.protectedItems+=Number(r.protected_items)}catch(r){g(r,m(d(n)))}finally{try{s?.close()}catch{}}}t?.eligible&&(e.newestRetained=!0,e.eligibleItems=Math.max(0,e.eligibleItems-1),e.protectedItems+=1,e.eligibleBytes=Math.max(0,e.eligibleBytes-t.logicalBytes),e.protectedBytes+=t.logicalBytes);for(let n of M.values()){let s=null;try{s=f(p(n.identityDir,H));let r=n.kind==="file"?"files":"messages",a=n.kind==="file"?"byte_length + 512":"length(CAST(body AS BLOB)) + 512",o=n.kind==="file"?`((direction = 'in' AND inbox_state = 'read' AND human_read_at_ms <= ?)
|
|
57
|
+
OR (direction = 'out' AND delivery_state IN ('delivered','read')))`:`((direction = 'in' AND inbox_state = 'read')
|
|
58
|
+
OR (direction = 'out' AND delivery_state IN ('delivered','read')))`,c=s.prepare(`
|
|
59
|
+
SELECT seq, ${a} AS logical_bytes FROM ${r}
|
|
60
|
+
WHERE wire_id = ? AND ${o}
|
|
61
|
+
`).get(...n.kind==="file"?[n.wireId,Date.now()-D]:[n.wireId]);if(!c||G({identityDir:n.identityDir,kind:n.kind,seq:c.seq},t))continue;let S=Number(c.logical_bytes);e.eligibleItems=Math.max(0,e.eligibleItems-1),e.protectedItems+=1,e.eligibleBytes=Math.max(0,e.eligibleBytes-S),e.protectedBytes+=S}catch(r){g(r,m(n.identityDir))}finally{try{s?.close()}catch{}}}return e}function fe(i){let t=!1;for(let e of i){let n=m(d(e)),s=null;try{s=f(e),Number(s.pragma("auto_vacuum",{simple:!0}))===2?Number(s.pragma("freelist_count",{simple:!0}))>0&&(t=!0):b.add(n)}catch(r){g(r,n)}finally{try{s?.close()}catch{}}}return t}function ye(i){for(let t of i){let e=m(d(t)),n=null;try{n=f(t);let s=I(n);if(Number(n.pragma("auto_vacuum",{simple:!0}))===2){n.pragma(`incremental_vacuum(${Q})`);let r=I(n);s&&r&&b.delete(e)}else b.add(e)}catch(s){g(s,e)}finally{try{n?.close()}catch{}}}}function ge(i,t,e){let n=l?.maxBytes??0,s=n>0,r=s?Math.max(0,i-n):0,a=[...b].sort(),o;return s?r===0?o="within_cap":E||t.eligibleItems>0||e?o="maintenance_pending":a.length>0?o="compaction_blocked":o="protected_overflow":o="disabled",{state:o,enabled:s,max_bytes:n,physical_bytes:i,overflow_bytes:r,protected_logical_bytes:t.protectedBytes,eligible_logical_bytes:t.eligibleBytes,protected_items:t.protectedItems,eligible_items:t.eligibleItems,newest_item_retained:t.newestRetained,maintenance_pending:o==="maintenance_pending",compaction_blocked_identities:a,evicted_messages:F,evicted_files:U,orphaned_blobs_removed:N,last_run_at_ms:W}}function pe(i){let t=new Set(i.map(e=>m(d(e))));for(let e of b)t.has(e)||b.delete(e)}function J(){let i=l?v(l.stateDir):[];pe(i);let t=l?T(l.stateDir):0;return k=t,A=ge(t,_e(i,z(i)),fe(i)),A}function B(){if(_||!l||l.maxBytes===0)return;let i=E?C:0;C=E?Math.min(ne,C*2):q,_=setTimeout(()=>{_=null,K(1)},i),_.unref?.()}function Ae(i,t){if(!se(t))throw new Error("historyMaxBytes must be a non-negative safe integer");_&&(clearTimeout(_),_=null),l={stateDir:y(i),maxBytes:t},k=0,L=!1,E=!1,C=q,b.clear(),M.clear(),F=0,U=0,N=0,W=null;for(let e of v(l.stateDir))oe(e),N+=me(e);return K(2)}function De(i,t=0){!l||l.maxBytes===0||!re(i)||(k+=Math.max(0,t)+ie,k>=l.maxBytes&&K(j).maintenance_pending&&B())}function K(i=j){if(!l)return A;if(L)return B(),A;L=!0,E=!1;try{for(let e=0;e<Math.max(1,i);e+=1){let n=T(l.stateDir);if(l.maxBytes===0||n<=l.maxBytes)break;let s=v(l.stateDir);ye(s);let r=T(l.stateDir);if(r<=l.maxBytes)break;let a=r<n;n=r;let o=z(s),c=de(s,o);if(c.length===0){if(!a)break;continue}if(be(c,n-l.maxBytes)===0)break}W=Date.now();let t=J();return t.maintenance_pending&&B(),t}finally{L=!1}}function Ne(){if(!l)return{...A,compaction_blocked_identities:[...A.compaction_blocked_identities]};let i=J();return{...i,compaction_blocked_identities:[...i.compaction_blocked_identities]}}function Ie(){_&&(clearTimeout(_),_=null)}function Me(i,t,e){for(let n of e)M.set($(i,t,n),{identityDir:i,kind:t,wireId:n})}function Le(i,t,e){for(let n of e)M.delete($(i,t,n))}function Ce(i,t){let e=p(i,H);if(!u.existsSync(e))return!1;let n=null;try{n=f(e);let s=X(n,i,t);return s&&(N+=1),s}finally{try{n?.close()}catch{}}}export{T as a,oe as b,Ae as c,De as d,K as e,Ne as f,Ie as g,Me as h,Le as i,Ce as j};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{g as D}from"./chunk-
|
|
2
|
+
import{g as D}from"./chunk-4QU3AKO6.js";import{b as L,g as V}from"./chunk-VXVW4KJU.js";import{a as T,b as C,c as q,d as F}from"./chunk-WBCVUXOI.js";import{a as R}from"./chunk-P55RJGZU.js";import{a as w}from"./chunk-3CPIRV4P.js";import{A,B as U,C as E,D as N,E as O,F as P,M as l,a as I}from"./chunk-65KGEJBX.js";import{A as h,E as S,z as M}from"./chunk-AH3RIV2J.js";import{j as k,o as B}from"./chunk-7Q3OCSPV.js";import{j as m}from"./chunk-IFCOOPD7.js";import{e as y,n as $,o as v}from"./chunk-MGNMJ64X.js";import{readFile as K}from"node:fs/promises";import{basename as G}from"node:path";function j(a,n){if(a)return n!==void 0?{wire_id:a,sentence:n}:{wire_id:a}}async function oe(a,n){let i=w(a),{contact:d,text:s}=n,o=j(n.reply_to_wire_id,n.reply_to_sentence);try{let e=await h(async r=>F(await S(i,"::a2a_messaging::send_message",{contact:d,text:s,...o?{reply_to:o}:{}},r)));switch(e.kind){case"refused":m(`[e2e-route] refused cid=${e.cid} wire_id=${e.wireId} (downgrade_refused)`);break;case"migrating":m(`[migration] queued cid=${e.cid} wire_id=${e.wireId} (migrating, ${e.queued} queued)`);break;case"e2e":m(`[e2e-route] cid=${e.cid} wire_id=${e.wireId} verdict=e2e (core delivered over migrated session)${e.notRetained?" NOT RETAINED (oversized)":""}`),e.notRetained&&k(i,{event:"send_not_retained",wire_id:e.wireId,kind:"message"});break;default:break}return e.kind==="sent"||e.kind==="e2e"?{...e,sent:!0,wire_id:e.wireId,history_stored:!y(i,e.wireId)}:e}catch(e){if(!/Unknown contact/.test(String(e)))throw l("send_message",String(e));try{let r=T(i,d),g=r?await C(i,r,s):await q(i,d,s);return{kind:"introduced",text:g.text,wireId:g.wireId,wire_id:g.wireId,sent:!0,history_stored:!y(i,g.wireId)}}catch(r){throw l("send_message",String(r),"FALLBACK_FAILED")}}}async function ae(a,n){let i=w(a),{contact:d,path:s,data_base64:o,upload_id:e,filename:r,mime:g}=n;if((s?1:0)+(o?1:0)+(e?1:0)!=1)throw e?N():A();let f,c,x=null;try{if(s)f=await K(s),c=r??G(s);else if(e){let t=D(i,e);if(!t)throw O(e);x=t.meta,f=t.buf,c=r??t.meta.filename}else{if(!r)throw U();f=Buffer.from(o,"base64"),c=r}}catch(t){throw t instanceof I?t:E(String(t))}let p=g??(s?R(s):x?.mime||""),b=j(n.reply_to_wire_id,n.reply_to_sentence),z=L(),u;try{u=M(t=>V({packet:{NewBinaryFromBuffer:_=>i.pw.packet.NewBinaryFromBuffer(_)},lifetime:t,filename:c,mime:p,payload:f,replyTo:b,cap:z}))}catch(t){throw t instanceof I?t:l("send_file",String(t))}if(!u.ok)throw P({filename:c,bytes:u.bytes,limit:u.cap,envelopeBytes:u.envelopeBytes,maxPayloadBytes:u.maxPayloadBytes});try{let t=await h(async _=>{let H=i.pw.packet.NewBinaryFromBuffer(f).Attach(_);return F(await S(i,"::a2a_messaging::send_file",{contact:d,filename:c,mime:p,data:H,...b?{reply_to:b}:{}},_))});switch(t.kind){case"refused":m(`[e2e-route] refused cid=${t.cid} wire_id=${t.wireId} (downgrade_refused, file)`);break;case"migrating":m(`[migration] file-defer cid=${t.cid} wire_id=${t.wireId} (migrating, not queued)`);break;case"e2e":m(`[e2e-route] cid=${t.cid} wire_id=${t.wireId} verdict=e2e file (core delivered over migrated session)${t.notRetained?" NOT RETAINED (oversized)":""}`),t.notRetained&&k(i,{event:"send_not_retained",wire_id:t.wireId,kind:"file"});break;default:break}return t.kind==="sent"||t.kind==="e2e"?{...t,filename:c,bytes:f.length,mime:p,sent:!0,wire_id:t.wireId,history_stored:!y(i,t.wireId)}:{...t,filename:c,bytes:f.length,mime:p}}catch(t){throw l("send_file",String(t))}}async function de(a){let n=w(a);try{return $(n)}catch(i){throw l("list_incoming_messages",String(i))}}async function ce(a,n={}){let i=w(a);try{let d=v(i,n);B(i);let s=new Map;for(let o of d.messages){let e=s.get(o.from.id);e||(e=[],s.set(o.from.id,e)),e.push(o.wire_id)}for(let[o,e]of s)try{await h(async r=>{await S(i,"::actor::send_read_receipts",{sender_id:o,wire_ids:e},r)})}catch(r){m(`[${i.name}] read-receipt attempt failed sender_id=${o} count=${e.length}:`,String(r))}return d}catch(d){throw l("get_messages",String(d))}}export{oe as a,ae as b,de as c,ce as d};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a as C}from"./chunk-JOKNFUW3.js";import{A as k,B as x,E as D,N as E,i as T,j as I,l as _,s as y,z as R}from"./chunk-
|
|
2
|
+
import{a as C}from"./chunk-JOKNFUW3.js";import{A as k,B as x,E as D,N as E,i as T,j as I,l as _,s as y,z as R}from"./chunk-AH3RIV2J.js";import{a as p,d as u,f as d,h as S}from"./chunk-RL3OEL5W.js";import{a as v,c as l,q as w}from"./chunk-5JKYJZAR.js";import{c as m,j as n}from"./chunk-IFCOOPD7.js";import{g as $}from"./chunk-MGNMJ64X.js";import{join as b}from"node:path";import*as i from"node:fs";function A(e){try{$(e)}catch(t){n(`closeHistory(${e.name}) failed:`,String(t))}try{v.remove_packet(e.cid)}catch(t){n(`remove_packet(${e.cid}) failed:`,String(t))}l.delete(e.name);try{E(e)}catch(t){n(`failed to unpublish "${e.name}" from the contact book:`,String(t))}p.has(e.name)&&(p.delete(e.name),S()),e.name===I&&(T(null),_());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 r=e.temp;return r?(r.closing||(r.closing=(async()=>{n(`[${e.name}] closing temporary identity (${t})`);let o=[];try{o=R(a=>C(x(e,"::a2a_messaging::list_contacts",a)))}catch(a){n(`[${e.name}] contact snapshot failed during close (continuing with local cleanup):`,String(a))}let s=0,c=0;u.add(e.name);try{for(let a of o)try{await k(async P=>{let h=(await D(e,"::a2a_messaging::remove_contact",{contact:a.container_id},P)).Reduce("notified");return h.IsNil()?!1:h.GetBoolean()})?s++:c++}catch(g){c++,n(`[${e.name}] remove-me to ${a.container_id} failed (continuing):`,String(g))}}finally{u.delete(e.name)}let f=A(e);return f?n(`[${e.name}] temporary identity close: LOCAL DELETE FAILED \u2014 ${f}`):n(`[${e.name}] temporary identity closed: ${o.length} contact(s), ${s} remove-me notice(s) queued, ${c} not sent (delivery unverified by design)`),{attempted:o.length,notified:s,failed:c,deleteError:f}})()),r.closing):Promise.reject(new Error(`identity "${e.name}" is not temporary`))}async function K(){let e=[];for(let t of[...l.values()]){let r=t.temp;if(!r||r.closing||!d(r.owner.pid))continue;let o=p.get(t.name);o&&!d(o.pid)||e.push(F(t,`stale lease \u2014 owner pid ${r.owner.pid} is dead`).catch(s=>n(`[${t.name}] stale-temp reclaim failed:`,String(s))))}await Promise.all(e)}function Q(){if(i.existsSync(m))for(let e of i.readdirSync(m,{withFileTypes:!0})){if(!e.isDirectory()||l.has(e.name))continue;let t=b(m,e.name),r=w(t);if(!(!r||!d(r.owner.pid)))try{i.rmSync(t,{recursive:!0,force:!0}),y.delete(e.name),n(`[${e.name}] removed orphaned temporary-identity dir (owner pid ${r.owner.pid} dead, no live packet)`)}catch(o){n(`[${e.name}] failed to remove orphaned temporary-identity dir:`,String(o))}}}export{A as a,F as b,K as c,Q as d};
|
|
@@ -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-3CPIRV4P.js";import{a as B,b as z,f as P,g as N,i as L,j as A}from"./chunk-JOKNFUW3.js";import{M as r,y as T,z as j}from"./chunk-65KGEJBX.js";import{A as u,B as p,E as l,I as x,M as I,N as S,a as V,f,z as y}from"./chunk-AH3RIV2J.js";import{o as C}from"./chunk-7Q3OCSPV.js";import{d as _,g as k}from"./chunk-RL3OEL5W.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:L(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=A(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:B(p(a,"::a2a_messaging::list_contacts",e)),pending:P(p(a,"::actor::list_pending_introductions",e)),roots:N(p(a,"::a2a_messaging::list_contact_roots",e)),degraded:V(p(a,"::a2a_messaging::list_degraded_contacts",e)),renames:z(p(a,"::a2a_messaging::list_import_renames",e))}))}catch(e){throw r("list_contacts",String(e))}}async function X(s){let a=Object.values(x()),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 I(e),t.push("published in the local contact book")):i===!1&&(S(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 C(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};
|
package/dist/client/http.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type * as messagingApi from '../api/messaging.js';
|
|
|
6
6
|
import type * as profileApi from '../api/profile.js';
|
|
7
7
|
import type { SessionContext } from '../api/types.js';
|
|
8
8
|
import { type NotificationEvent } from '../events.js';
|
|
9
|
+
import type { HistoryStorageStatus } from '../history-retention.js';
|
|
9
10
|
/** The argument object of an `OursApi` operation, with `ctx` dropped. */
|
|
10
11
|
type Arg<F> = F extends (ctx: SessionContext, a: infer A) => unknown ? A : never;
|
|
11
12
|
/** The argument object of the one operation that takes no `ctx`. */
|
|
@@ -169,6 +170,8 @@ export declare class OursClient {
|
|
|
169
170
|
unread(): Promise<{
|
|
170
171
|
identities: Array<Record<string, unknown>>;
|
|
171
172
|
}>;
|
|
173
|
+
/** `GET /history-storage` — body-free daemon-wide retention/accounting telemetry. */
|
|
174
|
+
historyStorage(): Promise<HistoryStorageStatus>;
|
|
172
175
|
/**
|
|
173
176
|
* Long-poll `GET /identities/<name>/notifications`, yielding each content-free
|
|
174
177
|
* event as it lands. Primes at EOF (the backlog is skipped, matching the
|
package/dist/client/http.js
CHANGED
|
@@ -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-P2AAWXWI.js";import"../chunk-65KGEJBX.js";import"../chunk-JTBQO6IT.js";export{a as OursClient};
|
package/dist/client/select.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}from"../chunk-
|
|
2
|
+
import{a,b,c,d,e,f,g,h}from"../chunk-FCQYDCQA.js";import"../chunk-P2AAWXWI.js";import"../chunk-65KGEJBX.js";import"../chunk-JTBQO6IT.js";import"../chunk-2X5HGMMO.js";export{d as DAEMON_TOKEN_FILE,c as DEFAULT_DAEMON_PORT,a as DaemonSelectionError,b as DaemonUnavailableError,g as assertDaemonStateDir,h as attachOursClient,f as describeDaemonConfig,e as resolveDaemonConfig};
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './errors.js';
|
|
2
2
|
export * from './client/http.js';
|
|
3
3
|
export * from './client/select.js';
|
|
4
|
+
export type { HistoryRetentionState, HistoryStorageStatus } from './history-retention.js';
|
|
4
5
|
export type { MessageReceivedRecord, MessengerNotificationEvent, NotificationEvent, ReceiptKind, ReceiptReceivedRecord, SyncRequiredRecord, UnknownNotificationEvent, } from './events.js';
|
package/dist/client.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a as I,b as J,c as L,d as O,e as P,f as Q,g as T,h as V}from"./chunk-
|
|
2
|
+
import{a as I,b as J,c as L,d as O,e as P,f as Q,g as T,h as V}from"./chunk-FCQYDCQA.js";import{a as G}from"./chunk-P2AAWXWI.js";import{A as k,B as q,C as w,D as K,E as U,F as b,G as l,H as z,I as A,J as B,K as C,L as D,M as F,a as e,b as t,c as o,d as i,e as r,f as n,g as c,h as s,i as p,j as R,k as f,l as a,m as d,n as v,o as y,p as m,q as x,r as S,s as g,t as E,u as N,v as j,w as u,x as H,y as M,z as h}from"./chunk-65KGEJBX.js";import"./chunk-JTBQO6IT.js";import"./chunk-2X5HGMMO.js";export{O as DAEMON_TOKEN_FILE,L as DEFAULT_DAEMON_PORT,I as DaemonSelectionError,J as DaemonUnavailableError,G as OursClient,e as OursError,T as assertDaemonStateDir,V as attachOursClient,Q as describeDaemonConfig,o as errBindingReassigned,E as errBoundElsewhere,i as errBoundIdentityGone,C as errDuplicateId,b as errFileTooLarge,w as errFileUnreadable,j as errIdentityClosedWithError,H as errIdentityPartiallyRemoved,A as errInvalidSelection,B as errMalformedId,n as errNameTaken,c as errNoLeaseHeaders,m as errNoLeaseToken,h as errNoPolicyArgs,z as errNoRoot,y as errNoSuchIdentity,t as errNotBound,R as errNotBoundNoName,f as errNotTemporary,v as errPathNotAbsolute,M as errPublicInviteNamed,s as errRandomNameExhausted,p as errRootExists,u as errRootHasRoles,l as errSaveFileFallback,k as errSendFileArgs,q as errSendFileFilenameRequired,K as errSendFileUploadArgs,d as errTempClosedWithError,r as errTempClosingBound,x as errTempClosingChoose,a as errTempOwnedElsewhereClose,N as errTempOwnedElsewhereRemove,S as errTempOwnedLive,g as errTempStale,F as errTool,D as errUnknownOrStaleId,U as errUploadNotFound,P as resolveDaemonConfig};
|
package/dist/cluster/control.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-WZQNO4PZ.js";import"../chunk-E34QSIVP.js";import"../chunk-AH3RIV2J.js";import"../chunk-YRPUM6JG.js";import"../chunk-7Q3OCSPV.js";import"../chunk-RL3OEL5W.js";import"../chunk-5JKYJZAR.js";import"../chunk-IFCOOPD7.js";import"../chunk-ZHH3PWEW.js";import"../chunk-Y3VPZJTG.js";import"../chunk-MGNMJ64X.js";import"../chunk-XIWAQH6S.js";import"../chunk-JTBQO6IT.js";import"../chunk-2X5HGMMO.js";export{b as PROTOCOL_VERSION,c as clusterSweep,a as envelopeDispatch,d as startClusterSweep};
|
package/dist/cluster/manifest.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-E34QSIVP.js";import"../chunk-AH3RIV2J.js";import"../chunk-YRPUM6JG.js";import"../chunk-7Q3OCSPV.js";import"../chunk-RL3OEL5W.js";import"../chunk-5JKYJZAR.js";import"../chunk-IFCOOPD7.js";import"../chunk-ZHH3PWEW.js";import"../chunk-Y3VPZJTG.js";import"../chunk-MGNMJ64X.js";import"../chunk-XIWAQH6S.js";import"../chunk-JTBQO6IT.js";import"../chunk-2X5HGMMO.js";export{b as buildManifest,d as findAgentOf,c as listAgentsFor,a as manifestCapabilities};
|
package/dist/config.d.ts
CHANGED
|
@@ -6,10 +6,13 @@ export interface OursConfig {
|
|
|
6
6
|
port: number;
|
|
7
7
|
stateDir: string;
|
|
8
8
|
gcIntervalMs: number;
|
|
9
|
+
/** Daemon-wide physical history cap. Zero disables rotation (unlimited). */
|
|
10
|
+
historyMaxBytes: number;
|
|
9
11
|
apiVisibility: ApiVisibility;
|
|
10
12
|
apiToken?: string;
|
|
11
13
|
stt?: SttUserConfig;
|
|
12
14
|
}
|
|
15
|
+
export declare const DEFAULT_HISTORY_MAX_BYTES: number;
|
|
13
16
|
export declare const DEFAULT_CONFIG: OursConfig;
|
|
14
17
|
export declare function configPath(): string;
|
|
15
18
|
export declare function loadConfig(): OursConfig;
|
package/dist/config.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,l,m}from"./chunk-
|
|
2
|
+
import{a,b,c,d,e,f,g,h,i,j,k,l,m,n}from"./chunk-2X5HGMMO.js";export{f as API_TOKEN_FILENAME,a as API_VISIBILITIES,c as DEFAULT_CONFIG,b as DEFAULT_HISTORY_MAX_BYTES,k as IDENTITY_FILENAME,g as apiTokenPath,l as buildIdentityFile,d as configPath,h as explicitApiToken,e as loadConfig,i as resolveApiToken,m as resolveIdentityFilePath,j as writeConfig,n as writeIdentityFile};
|