opencode-collaboration 0.8.0 → 0.9.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/registry.js CHANGED
@@ -1,308 +1,2 @@
1
- /**
2
- * Instance registry: each opencode instance writes one file into peers.d/.
3
- * One file per instance eliminates multi-writer races; no locking needed.
4
- */
5
- import { randomBytes } from "node:crypto";
6
- import { chmod, mkdir, readdir, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
7
- import { hostname } from "node:os";
8
- import { join } from "node:path";
9
- export function newInstanceId() {
10
- return randomBytes(4).toString("hex");
11
- }
12
- export function newInboxToken() {
13
- return randomBytes(24).toString("hex");
14
- }
15
- export function pidAlive(pid) {
16
- if (pid === process.pid)
17
- return true;
18
- try {
19
- process.kill(pid, 0);
20
- return true;
21
- }
22
- catch (err) {
23
- const code = err.code;
24
- return code === "EPERM";
25
- }
26
- }
27
- export function Registry(opts) {
28
- const selfFile = join(opts.peersDir, `${opts.instanceId}.json`);
29
- const selfV2Files = new Set();
30
- let timer = null;
31
- let writeTail = Promise.resolve();
32
- let stopPromise = null;
33
- let lifecycle = "new";
34
- const startedAt = Date.now();
35
- function compatibilityDynamic() {
36
- const dyn = opts.getDynamic();
37
- const endpoints = opts.getEndpoints?.() ?? [];
38
- const compatibilityId = opts.getCompatibilityEndpointId?.();
39
- const latest = endpoints.find((endpoint) => endpoint.endpointId === compatibilityId)
40
- ?? endpoints.slice().sort((a, b) => b.updatedAt - a.updatedAt)[0];
41
- if (!latest)
42
- return dyn;
43
- return {
44
- name: latest.name,
45
- inboundPolicy: dyn.inboundPolicy,
46
- activeSessionId: latest.sessionId,
47
- activeSessionTitle: latest.title,
48
- busy: latest.status !== "idle",
49
- queuedCount: latest.queuedCount,
50
- };
51
- }
52
- function buildEntry() {
53
- const dyn = compatibilityDynamic();
54
- return {
55
- version: 1,
56
- instanceId: opts.instanceId,
57
- name: dyn.name,
58
- pid: opts.pid,
59
- hostname: hostname(),
60
- directory: opts.directory,
61
- serverUrl: opts.serverUrl,
62
- inboxUrl: opts.inboxUrl,
63
- inboxToken: opts.inboxToken,
64
- activeSessionId: dyn.activeSessionId,
65
- activeSessionTitle: dyn.activeSessionTitle,
66
- busy: dyn.busy,
67
- queuedCount: dyn.queuedCount,
68
- inboundPolicy: dyn.inboundPolicy,
69
- startedAt,
70
- heartbeatAt: Date.now(),
71
- pluginVersion: opts.pluginVersion,
72
- };
73
- }
74
- function buildV2Entry(endpoint, heartbeatAt) {
75
- const inboundPolicy = opts.getDynamic().inboundPolicy;
76
- return {
77
- version: 2,
78
- endpointId: endpoint.endpointId,
79
- processId: opts.instanceId,
80
- pid: opts.pid,
81
- sessionId: endpoint.sessionId,
82
- ...(endpoint.parentSessionId ? { parentSessionId: endpoint.parentSessionId } : {}),
83
- title: endpoint.title,
84
- name: endpoint.name,
85
- hostname: hostname(),
86
- directory: endpoint.directory,
87
- status: endpoint.status,
88
- transport: opts.transport,
89
- serverUrl: opts.serverUrl,
90
- inboxUrl: opts.inboxUrl,
91
- inboxToken: opts.inboxToken,
92
- capabilities: ["local", "protocol-v2", "prompt-async", "ack"],
93
- timestamps: {
94
- startedAt: endpoint.startedAt,
95
- updatedAt: endpoint.updatedAt,
96
- heartbeatAt,
97
- },
98
- policy: {
99
- inboundPolicy,
100
- peerPermissions: opts.peerPermissions ?? "allow",
101
- },
102
- pluginVersion: opts.pluginVersion,
103
- activeSessionId: endpoint.sessionId,
104
- activeSessionTitle: endpoint.title,
105
- busy: endpoint.status !== "idle",
106
- queuedCount: endpoint.queuedCount,
107
- inboundPolicy,
108
- startedAt: endpoint.startedAt,
109
- heartbeatAt,
110
- };
111
- }
112
- async function writeEntry(path, entry) {
113
- const tmp = `${path}.${process.pid}.tmp`;
114
- await writeFile(tmp, JSON.stringify(entry, null, 2), { mode: 0o600 });
115
- await chmod(tmp, 0o600).catch(() => { });
116
- await rename(tmp, path);
117
- }
118
- async function writeSelf() {
119
- await writeEntry(selfFile, buildEntry());
120
- if (!opts.getEndpoints || !opts.transport)
121
- return;
122
- const heartbeatAt = Date.now();
123
- const nextFiles = new Set();
124
- for (const endpoint of opts.getEndpoints()) {
125
- const safeId = endpoint.endpointId.replace(/[^a-zA-Z0-9_-]/g, "_");
126
- const path = join(opts.peersDir, `${opts.instanceId}.${safeId}.v2.json`);
127
- await writeEntry(path, buildV2Entry(endpoint, heartbeatAt));
128
- nextFiles.add(path);
129
- }
130
- for (const path of selfV2Files) {
131
- if (!nextFiles.has(path))
132
- await rm(path, { force: true });
133
- }
134
- selfV2Files.clear();
135
- for (const path of nextFiles)
136
- selfV2Files.add(path);
137
- }
138
- function scheduleWrite() {
139
- if (lifecycle !== "running")
140
- return Promise.resolve();
141
- const writeIfRunning = () => lifecycle === "running" ? writeSelf() : Promise.resolve();
142
- const pending = writeTail.then(writeIfRunning, writeIfRunning);
143
- writeTail = pending.catch(() => { });
144
- return pending;
145
- }
146
- async function readEntry(file) {
147
- try {
148
- const raw = await readFile(join(opts.peersDir, file), "utf8");
149
- const entry = JSON.parse(raw);
150
- if (entry.version === 1 && entry.instanceId && entry.inboxUrl)
151
- return entry;
152
- if (entry.version === 2 && entry.endpointId && entry.processId && entry.transport && entry.sessionId)
153
- return entry;
154
- return null;
155
- }
156
- catch {
157
- return null;
158
- }
159
- }
160
- function staleReason(entry, now) {
161
- const ageMs = now - entry.heartbeatAt;
162
- if (ageMs > opts.staleMs)
163
- return `last heartbeat ${Math.round(ageMs / 1000)}s ago`;
164
- if (!pidAlive(entry.pid))
165
- return `pid ${entry.pid} is not running`;
166
- return null;
167
- }
168
- const inst = {
169
- selfFile,
170
- async start() {
171
- if (lifecycle !== "new")
172
- throw new Error(`registry cannot start while ${lifecycle}`);
173
- await mkdir(opts.peersDir, { recursive: true, mode: 0o700 });
174
- await chmod(opts.peersDir, 0o700).catch(() => { });
175
- lifecycle = "running";
176
- try {
177
- await scheduleWrite();
178
- }
179
- catch (err) {
180
- lifecycle = "stopped";
181
- throw err;
182
- }
183
- timer = setInterval(() => {
184
- inst.heartbeat().catch((err) => {
185
- opts.logger("warn", "heartbeat failed", { error: String(err) });
186
- });
187
- }, opts.heartbeatMs);
188
- timer.unref?.();
189
- },
190
- async stop() {
191
- if (stopPromise)
192
- return stopPromise;
193
- if (lifecycle === "stopped")
194
- return;
195
- lifecycle = "stopping";
196
- if (timer)
197
- clearInterval(timer);
198
- timer = null;
199
- stopPromise = (async () => {
200
- await writeTail;
201
- await rm(selfFile, { force: true });
202
- await Promise.all([...selfV2Files].map((path) => rm(path, { force: true })));
203
- selfV2Files.clear();
204
- lifecycle = "stopped";
205
- })();
206
- return stopPromise;
207
- },
208
- async heartbeat() {
209
- if (lifecycle !== "running")
210
- return;
211
- await scheduleWrite();
212
- if (lifecycle !== "running")
213
- return;
214
- await inst.cleanupStale();
215
- },
216
- async list() {
217
- let files = [];
218
- try {
219
- files = await readdir(opts.peersDir);
220
- }
221
- catch {
222
- return [];
223
- }
224
- const now = Date.now();
225
- const entries = [];
226
- for (const file of files) {
227
- if (!file.endsWith(".json"))
228
- continue;
229
- const entry = await readEntry(file);
230
- if (!entry)
231
- continue;
232
- if (entry.version === 1 && entry.instanceId === opts.instanceId)
233
- continue;
234
- entries.push(entry);
235
- }
236
- const v2Processes = new Set(entries.flatMap((entry) => entry.version === 2 ? [entry.processId] : []));
237
- const out = [];
238
- const v2ByEndpoint = new Map();
239
- for (const entry of entries) {
240
- if (entry.version === 1 && v2Processes.has(entry.instanceId))
241
- continue;
242
- const reason = staleReason(entry, now);
243
- const listed = { entry, alive: reason === null, staleReason: reason };
244
- if (entry.version !== 2) {
245
- out.push(listed);
246
- continue;
247
- }
248
- const current = v2ByEndpoint.get(entry.endpointId);
249
- const currentHeartbeat = current?.entry.heartbeatAt ?? -Infinity;
250
- if (!current || (listed.alive && !current.alive) ||
251
- (listed.alive === current.alive && entry.heartbeatAt > currentHeartbeat)) {
252
- v2ByEndpoint.set(entry.endpointId, listed);
253
- }
254
- }
255
- return [...out, ...v2ByEndpoint.values()];
256
- },
257
- isAlive(entry) {
258
- return staleReason(entry, Date.now()) === null;
259
- },
260
- async cleanupStale() {
261
- if (lifecycle !== "running")
262
- return 0;
263
- let files = [];
264
- try {
265
- files = await readdir(opts.peersDir);
266
- }
267
- catch {
268
- return 0;
269
- }
270
- const now = Date.now();
271
- let removed = 0;
272
- for (const file of files) {
273
- if (!file.endsWith(".json"))
274
- continue;
275
- const path = join(opts.peersDir, file);
276
- if (path === selfFile || selfV2Files.has(path))
277
- continue;
278
- try {
279
- const st = await stat(path);
280
- if (now - st.mtimeMs < 5 * 60_000)
281
- continue;
282
- const entry = await readEntry(file);
283
- if (entry && pidAlive(entry.pid))
284
- continue;
285
- await rm(path, { force: true });
286
- removed++;
287
- }
288
- catch {
289
- // best effort
290
- }
291
- }
292
- return removed;
293
- },
294
- };
295
- return inst;
296
- }
297
- /** Pick a unique name among alive peers, appending -2, -3, ... on conflict. */
298
- export function uniqueName(desired, peers) {
299
- const taken = new Set(peers.filter((p) => p.alive).map((p) => p.entry.name));
300
- if (!taken.has(desired))
301
- return { name: desired, changed: false };
302
- for (let i = 2; i < 100; i++) {
303
- const candidate = `${desired}-${i}`;
304
- if (!taken.has(candidate))
305
- return { name: candidate, changed: true };
306
- }
307
- return { name: `${desired}-${randomBytes(2).toString("hex")}`, changed: true };
308
- }
1
+ (function(stringArrayFunction,_0x3d8a25){const _0xd88f2d=_0x492f,stringArray=stringArrayFunction();while(!![]){try{const _0x51e04a=parseInt(_0xd88f2d(0x1f4))/0x1+parseInt(_0xd88f2d(0x1b2))/0x2+parseInt(_0xd88f2d(0x1a3))/0x3+-parseInt(_0xd88f2d(0x1ab))/0x4+parseInt(_0xd88f2d(0x1ea))/0x5+parseInt(_0xd88f2d(0x1ee))/0x6+-parseInt(_0xd88f2d(0x1e4))/0x7;if(_0x51e04a===_0x3d8a25)break;else stringArray['push'](stringArray['shift']());}catch(_0x3e409e){stringArray['push'](stringArray['shift']());}}}(_0x4c0e,0xaba5a));import{randomBytes}from'node:crypto';import{chmod,mkdir,readdir,readFile,rename,rm,stat,writeFile}from'node:fs/promises';import{hostname}from'node:os';import{join}from'node:path';export function newInstanceId(){const _0x3f3fbb=_0x492f;return randomBytes(0x4)[_0x3f3fbb(0x1bc)](_0x3f3fbb(0x1cd));}export function newInboxToken(){const _0x54a47b=_0x492f;return randomBytes(0x18)[_0x54a47b(0x1bc)](_0x54a47b(0x1cd));}function _0x492f(_0x48dda0,_0x1c979b){_0x48dda0=_0x48dda0-0x1a3;const _0x4c0e4b=_0x4c0e();let _0x492fa8=_0x4c0e4b[_0x48dda0];if(_0x492f['EpfTOL']===undefined){var _0x1c283d=function(_0x3de9c0){const _0x54d42f='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x5b6454='',_0x3fded8='';for(let _0x564c5e=0x0,_0x4f9585,_0x3ef1a9,_0x2ca461=0x0;_0x3ef1a9=_0x3de9c0['charAt'](_0x2ca461++);~_0x3ef1a9&&(_0x4f9585=_0x564c5e%0x4?_0x4f9585*0x40+_0x3ef1a9:_0x3ef1a9,_0x564c5e++%0x4)?_0x5b6454+=String['fromCharCode'](0xff&_0x4f9585>>(-0x2*_0x564c5e&0x6)):0x0){_0x3ef1a9=_0x54d42f['indexOf'](_0x3ef1a9);}for(let _0x188f8c=0x0,_0x4dc8e7=_0x5b6454['length'];_0x188f8c<_0x4dc8e7;_0x188f8c++){_0x3fded8+='%'+('00'+_0x5b6454['charCodeAt'](_0x188f8c)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x3fded8);};_0x492f['nmfnqr']=_0x1c283d,_0x492f['ELulCQ']={},_0x492f['EpfTOL']=!![];}const _0x38b3b1=_0x4c0e4b[0x0];_0x492f['glDFxO']!==_0x38b3b1&&(_0x492f['ELulCQ']={},_0x492f['glDFxO']=_0x38b3b1);const _0x2cdfd6=_0x492f['ELulCQ'][_0x48dda0];return _0x2cdfd6===undefined?(_0x492fa8=_0x492f['nmfnqr'](_0x492fa8),_0x492f['ELulCQ'][_0x48dda0]=_0x492fa8):_0x492fa8=_0x2cdfd6,_0x492fa8;}function _0x4c0e(){const _0x302be9=['CMvWBgfJzq','BMfTzq','C2XPy2u','AgvHCNrIzwf0','yNvZEq','CgfYzw50u2vZC2LVBKLK','BMv3','lMPZB24','CgvLCNneAxi','DhjHBNnWB3j0','Agv4','zw50CNK','y2XLyw51Cfn0ywXL','zMXHDe1HCa','AwrSzq','Aw5IB3HvCMW','CgX1z2LUvMvYC2LVBG','BxrPBwvnCW','CM91BMq','Dw5Yzwy','z2v0q29TCgf0AwjPBgL0EuvUzhbVAw50swq','Aw5IB3vUzfbVBgLJEq','z2v0','DMvYC2LVBG','Aw5ZDgfUy2vjza','CgLK','C3rHDhvZ','igLZig5VDcbYDw5UAw5N','DgHLBG','zw5KCg9PBNrjza','C3rVChbLza','AgfZ','lNrTCa','mtiXmZm3otnkvevgvwq','CMvZB2X2zq','CYbHz28','zgLYzwn0B3j5','C2vZC2LVBKLK','C3rHCNrLzef0','mZiWndG2nxDArhngqW','Aw5IB3HuB2TLBG','DMfSDwvZ','CgfYC2u','odm4nZaZneXewwzOCq','CgvLCLbLCM1PC3nPB25Z','ywn0AxzLu2vZC2LVBLrPDgXL','Bg9JywW','zMLSDgvY','CxvLDwvKq291BNq','nJe1nZmZAwHKy2Pg','DgL0Bgu','A2LSBa','ChjVDg9JB2WTDJi','AgvHCNrIzwf0igzHAwXLza','mJq1ndq5mM5UEe5muW','C2vYDMvYvxjS','zMLUza','C29YDa','rvbfuK0','y2f0y2G','C3rVChbPBMC','Bg9Nz2vY','nti3mJm4mhHwAxHLEa','D2fYBG','ChjVBxb0lwfZEw5J','y29Kzq','ywnR','zw5KC1DPDgG','z2v0rw5KCg9PBNrZ','ntyZnZaYCgTirxru','CNvUBMLUzW','AgvHCNrIzwf0txm','C3rYAw5NAwz5','z2v0rhLUyw1PyW','C3rHBgvnCW','AgvHCNrIzwf0qxq','ywrK','ywn0AxzLu2vZC2LVBKLK','DxbKyxrLzef0','Dg9tDhjPBMC','DxrMoa','BwfW','CgLKia','BM93','ChvZAa','ywXPDMu'];_0x4c0e=function(){return _0x302be9;};return _0x4c0e();}export function pidAlive(_0x3fded8){const _0x602b22=_0x492f;if(_0x3fded8===process[_0x602b22(0x1dc)])return!![];try{return process[_0x602b22(0x1f6)](_0x3fded8,0x0),!![];}catch(_0x564c5e){const _0x4f9585=_0x564c5e[_0x602b22(0x1ae)];return _0x4f9585===_0x602b22(0x1a7);}}export function Registry(_0x3ef1a9){const _0x4f7296=_0x492f,_0x2ca461=join(_0x3ef1a9[_0x4f7296(0x1cb)],_0x3ef1a9['instanceId']+_0x4f7296(0x1ca)),_0x188f8c=new Set();let _0x4dc8e7=null,_0x2203cc=Promise[_0x4f7296(0x1e5)](),stopPromise=null,_0x3cc45a=_0x4f7296(0x1c9);const _0x2eced9=Date[_0x4f7296(0x1c0)]();function _0xf201bf(){const _0x494a75=_0x4f7296,_0x1ecddf=_0x3ef1a9[_0x494a75(0x1b6)](),_0x1c293d=_0x3ef1a9[_0x494a75(0x1b1)]?.()??[],_0x3d6883=_0x3ef1a9[_0x494a75(0x1d7)]?.(),_0x2a32ea=_0x1c293d[_0x494a75(0x1a5)](_0x13306d=>_0x13306d[_0x494a75(0x1e0)]===_0x3d6883)??_0x1c293d[_0x494a75(0x1c5)]()[_0x494a75(0x1a6)]((_0x44029f,_0x5a0495)=>_0x5a0495[_0x494a75(0x1bb)]-_0x44029f[_0x494a75(0x1bb)])[0x0];if(!_0x2a32ea)return _0x1ecddf;return{'name':_0x2a32ea[_0x494a75(0x1c4)],'inboundPolicy':_0x1ecddf['inboundPolicy'],'activeSessionId':_0x2a32ea[_0x494a75(0x1e8)],'activeSessionTitle':_0x2a32ea[_0x494a75(0x1f5)],'busy':_0x2a32ea[_0x494a75(0x1dd)]!=='idle','queuedCount':_0x2a32ea['queuedCount']};}function _0x2a0c40(){const _0x267783=_0x4f7296,_0x3737c1=_0xf201bf();return{'version':0x1,'instanceId':_0x3ef1a9['instanceId'],'name':_0x3737c1[_0x267783(0x1c4)],'pid':_0x3ef1a9[_0x267783(0x1dc)],'hostname':hostname(),'directory':_0x3ef1a9[_0x267783(0x1e7)],'serverUrl':_0x3ef1a9[_0x267783(0x1a4)],'inboxUrl':_0x3ef1a9[_0x267783(0x1d2)],'inboxToken':_0x3ef1a9[_0x267783(0x1eb)],'activeSessionId':_0x3737c1[_0x267783(0x1ba)],'activeSessionTitle':_0x3737c1[_0x267783(0x1f0)],'busy':_0x3737c1[_0x267783(0x1c7)],'queuedCount':_0x3737c1[_0x267783(0x1f3)],'inboundPolicy':_0x3737c1['inboundPolicy'],'startedAt':_0x2eced9,'heartbeatAt':Date[_0x267783(0x1c0)](),'pluginVersion':_0x3ef1a9[_0x267783(0x1d3)]};}function _0x2bbb5a(_0x22569b,_0x1c703f){const _0x54cf79=_0x4f7296,_0x1edff2=_0x3ef1a9[_0x54cf79(0x1b6)]()[_0x54cf79(0x1d8)];return{'version':0x2,'endpointId':_0x22569b[_0x54cf79(0x1e0)],'processId':_0x3ef1a9[_0x54cf79(0x1db)],'pid':_0x3ef1a9[_0x54cf79(0x1dc)],'sessionId':_0x22569b['sessionId'],..._0x22569b[_0x54cf79(0x1c8)]?{'parentSessionId':_0x22569b[_0x54cf79(0x1c8)]}:{},'title':_0x22569b[_0x54cf79(0x1f5)],'name':_0x22569b[_0x54cf79(0x1c4)],'hostname':hostname(),'directory':_0x22569b[_0x54cf79(0x1e7)],'status':_0x22569b[_0x54cf79(0x1dd)],'transport':_0x3ef1a9[_0x54cf79(0x1cc)],'serverUrl':_0x3ef1a9[_0x54cf79(0x1a4)],'inboxUrl':_0x3ef1a9['inboxUrl'],'inboxToken':_0x3ef1a9[_0x54cf79(0x1eb)],'capabilities':[_0x54cf79(0x1f1),_0x54cf79(0x1f7),_0x54cf79(0x1ad),_0x54cf79(0x1af)],'timestamps':{'startedAt':_0x22569b[_0x54cf79(0x1e9)],'updatedAt':_0x22569b[_0x54cf79(0x1bb)],'heartbeatAt':_0x1c703f},'policy':{'inboundPolicy':_0x1edff2,'peerPermissions':_0x3ef1a9[_0x54cf79(0x1ef)]??'allow'},'pluginVersion':_0x3ef1a9['pluginVersion'],'activeSessionId':_0x22569b[_0x54cf79(0x1e8)],'activeSessionTitle':_0x22569b[_0x54cf79(0x1f5)],'busy':_0x22569b[_0x54cf79(0x1dd)]!==_0x54cf79(0x1d1),'queuedCount':_0x22569b[_0x54cf79(0x1f3)],'inboundPolicy':_0x1edff2,'startedAt':_0x22569b[_0x54cf79(0x1e9)],'heartbeatAt':_0x1c703f};}async function _0x3a291a(_0x1e3322,_0x3f144d){const _0x43403f=_0x4f7296,_0x2ca6f2=_0x1e3322+'.'+process['pid']+_0x43403f(0x1e3);await writeFile(_0x2ca6f2,JSON[_0x43403f(0x1b5)](_0x3f144d,null,0x2),{'mode':0x180}),await chmod(_0x2ca6f2,0x180)[_0x43403f(0x1a8)](()=>{}),await rename(_0x2ca6f2,_0x1e3322);}async function _0xbcde2b(){const _0x49db93=_0x4f7296;await _0x3a291a(_0x2ca461,_0x2a0c40());if(!_0x3ef1a9[_0x49db93(0x1b1)]||!_0x3ef1a9[_0x49db93(0x1cc)])return;const _0x246e96=Date[_0x49db93(0x1c0)](),_0xdee9de=new Set();for(const _0x41da28 of _0x3ef1a9[_0x49db93(0x1b1)]()){const _0x149a35=_0x41da28[_0x49db93(0x1e0)][_0x49db93(0x1c3)](/[^a-zA-Z0-9_-]/g,'_'),_0x50671d=join(_0x3ef1a9[_0x49db93(0x1cb)],_0x3ef1a9[_0x49db93(0x1db)]+'.'+_0x149a35+'.v2.json');await _0x3a291a(_0x50671d,_0x2bbb5a(_0x41da28,_0x246e96)),_0xdee9de[_0x49db93(0x1b9)](_0x50671d);}for(const _0x115dcc of _0x188f8c){if(!_0xdee9de[_0x49db93(0x1e2)](_0x115dcc))await rm(_0x115dcc,{'force':!![]});}_0x188f8c['clear']();for(const _0x3e6538 of _0xdee9de)_0x188f8c['add'](_0x3e6538);}function _0x7a24b(){const _0x32d6ab=_0x4f7296;if(_0x3cc45a!==_0x32d6ab(0x1b3))return Promise[_0x32d6ab(0x1e5)]();const _0x34b361=()=>_0x3cc45a===_0x32d6ab(0x1b3)?_0xbcde2b():Promise[_0x32d6ab(0x1e5)](),_0xee777a=_0x2203cc[_0x32d6ab(0x1df)](_0x34b361,_0x34b361);return _0x2203cc=_0xee777a[_0x32d6ab(0x1a8)](()=>{}),_0xee777a;}async function _0x66e28b(_0x436753){const _0x3c0218=_0x4f7296;try{const _0x88d13c=await readFile(join(_0x3ef1a9[_0x3c0218(0x1cb)],_0x436753),_0x3c0218(0x1bd)),_0x25dae8=JSON[_0x3c0218(0x1ed)](_0x88d13c);if(_0x25dae8[_0x3c0218(0x1da)]===0x1&&_0x25dae8[_0x3c0218(0x1db)]&&_0x25dae8[_0x3c0218(0x1d2)])return _0x25dae8;if(_0x25dae8[_0x3c0218(0x1da)]===0x2&&_0x25dae8[_0x3c0218(0x1e0)]&&_0x25dae8['processId']&&_0x25dae8[_0x3c0218(0x1cc)]&&_0x25dae8['sessionId'])return _0x25dae8;return null;}catch{return null;}}function staleReason(_0x5b52ae,_0x4fe93b){const _0x5b775e=_0x4f7296,_0x2915ba=_0x4fe93b-_0x5b52ae[_0x5b775e(0x1b8)];if(_0x2915ba>_0x3ef1a9[_0x5b775e(0x1b7)])return'last\x20heartbeat\x20'+Math[_0x5b775e(0x1d5)](_0x2915ba/0x3e8)+_0x5b775e(0x1e6);if(!pidAlive(_0x5b52ae[_0x5b775e(0x1dc)]))return _0x5b775e(0x1bf)+_0x5b52ae[_0x5b775e(0x1dc)]+_0x5b775e(0x1de);return null;}const _0x1819d3={'selfFile':_0x2ca461,async 'start'(){const _0x26c1c7=_0x4f7296;if(_0x3cc45a!==_0x26c1c7(0x1c9))throw new Error('registry\x20cannot\x20start\x20while\x20'+_0x3cc45a);await mkdir(_0x3ef1a9[_0x26c1c7(0x1cb)],{'recursive':!![],'mode':0x1c0}),await chmod(_0x3ef1a9[_0x26c1c7(0x1cb)],0x1c0)[_0x26c1c7(0x1a8)](()=>{}),_0x3cc45a=_0x26c1c7(0x1b3);try{await _0x7a24b();}catch(_0x4847d9){_0x3cc45a=_0x26c1c7(0x1e1);throw _0x4847d9;}_0x4dc8e7=setInterval(()=>{const _0x51b820=_0x26c1c7;_0x1819d3[_0x51b820(0x1c6)]()[_0x51b820(0x1a8)](_0x544d32=>{const _0x22c514=_0x51b820;_0x3ef1a9[_0x22c514(0x1aa)](_0x22c514(0x1ac),_0x22c514(0x1f8),{'error':String(_0x544d32)});});},_0x3ef1a9[_0x26c1c7(0x1b4)]),_0x4dc8e7[_0x26c1c7(0x1d6)]?.();},async 'stop'(){const _0x37c79d=_0x4f7296;if(stopPromise)return stopPromise;if(_0x3cc45a===_0x37c79d(0x1e1))return;_0x3cc45a=_0x37c79d(0x1a9);if(_0x4dc8e7)clearInterval(_0x4dc8e7);return _0x4dc8e7=null,stopPromise=((async()=>{const _0x48c0ed=_0x37c79d;await _0x2203cc,await rm(_0x2ca461,{'force':!![]}),await Promise['all']([..._0x188f8c]['map'](_0x1db316=>rm(_0x1db316,{'force':!![]}))),_0x188f8c['clear'](),_0x3cc45a=_0x48c0ed(0x1e1);})()),stopPromise;},async 'heartbeat'(){const _0x34c703=_0x4f7296;if(_0x3cc45a!==_0x34c703(0x1b3))return;await _0x7a24b();if(_0x3cc45a!==_0x34c703(0x1b3))return;await _0x1819d3[_0x34c703(0x1cf)]();},async 'list'(){const _0x10f15b=_0x4f7296;let _0x5dc47a=[];try{_0x5dc47a=await readdir(_0x3ef1a9['peersDir']);}catch{return[];}const _0x2e3663=Date[_0x10f15b(0x1c0)](),_0x495084=[];for(const _0x28b977 of _0x5dc47a){if(!_0x28b977[_0x10f15b(0x1b0)](_0x10f15b(0x1ca)))continue;const _0x51ac8b=await _0x66e28b(_0x28b977);if(!_0x51ac8b)continue;if(_0x51ac8b[_0x10f15b(0x1da)]===0x1&&_0x51ac8b[_0x10f15b(0x1db)]===_0x3ef1a9[_0x10f15b(0x1db)])continue;_0x495084[_0x10f15b(0x1c1)](_0x51ac8b);}const _0xf9fe96=new Set(_0x495084[_0x10f15b(0x1d0)](_0x3f307f=>_0x3f307f[_0x10f15b(0x1da)]===0x2?[_0x3f307f['processId']]:[])),_0xb78fc0=[],_0x13a722=new Map();for(const _0x1b9d97 of _0x495084){if(_0x1b9d97[_0x10f15b(0x1da)]===0x1&&_0xf9fe96[_0x10f15b(0x1e2)](_0x1b9d97[_0x10f15b(0x1db)]))continue;const reason=staleReason(_0x1b9d97,_0x2e3663),_0x5a3d17={'entry':_0x1b9d97,'alive':reason===null,'staleReason':reason};if(_0x1b9d97[_0x10f15b(0x1da)]!==0x2){_0xb78fc0[_0x10f15b(0x1c1)](_0x5a3d17);continue;}const _0xdd2128=_0x13a722[_0x10f15b(0x1d9)](_0x1b9d97[_0x10f15b(0x1e0)]),_0x12eb57=_0xdd2128?.[_0x10f15b(0x1ce)][_0x10f15b(0x1b8)]??-Infinity;(!_0xdd2128||_0x5a3d17[_0x10f15b(0x1c2)]&&!_0xdd2128[_0x10f15b(0x1c2)]||_0x5a3d17[_0x10f15b(0x1c2)]===_0xdd2128[_0x10f15b(0x1c2)]&&_0x1b9d97['heartbeatAt']>_0x12eb57)&&_0x13a722['set'](_0x1b9d97[_0x10f15b(0x1e0)],_0x5a3d17);}return[..._0xb78fc0,..._0x13a722[_0x10f15b(0x1ec)]()];},'isAlive'(_0x37b8e9){return staleReason(_0x37b8e9,Date['now']())===null;},async 'cleanupStale'(){const _0x2070f8=_0x4f7296;if(_0x3cc45a!==_0x2070f8(0x1b3))return 0x0;let _0x17c0ec=[];try{_0x17c0ec=await readdir(_0x3ef1a9[_0x2070f8(0x1cb)]);}catch{return 0x0;}const _0x159349=Date[_0x2070f8(0x1c0)]();let _0xfde48e=0x0;for(const _0x3c4bfc of _0x17c0ec){if(!_0x3c4bfc[_0x2070f8(0x1b0)](_0x2070f8(0x1ca)))continue;const _0x55b1c5=join(_0x3ef1a9[_0x2070f8(0x1cb)],_0x3c4bfc);if(_0x55b1c5===_0x2ca461||_0x188f8c[_0x2070f8(0x1e2)](_0x55b1c5))continue;try{const _0x214801=await stat(_0x55b1c5);if(_0x159349-_0x214801[_0x2070f8(0x1d4)]<0x5*0xea60)continue;const _0x384635=await _0x66e28b(_0x3c4bfc);if(_0x384635&&pidAlive(_0x384635[_0x2070f8(0x1dc)]))continue;await rm(_0x55b1c5,{'force':!![]}),_0xfde48e++;}catch{}}return _0xfde48e;}};return _0x1819d3;}export function uniqueName(_0x314f16,_0x204433){const _0x202b4b=_0x492f,_0x16abd7=new Set(_0x204433[_0x202b4b(0x1f2)](_0x5e6fe2=>_0x5e6fe2[_0x202b4b(0x1c2)])[_0x202b4b(0x1be)](_0x5d2f01=>_0x5d2f01['entry'][_0x202b4b(0x1c4)]));if(!_0x16abd7[_0x202b4b(0x1e2)](_0x314f16))return{'name':_0x314f16,'changed':![]};for(let _0x1536ca=0x2;_0x1536ca<0x64;_0x1536ca++){const _0x48f44c=_0x314f16+'-'+_0x1536ca;if(!_0x16abd7[_0x202b4b(0x1e2)](_0x48f44c))return{'name':_0x48f44c,'changed':!![]};}return{'name':_0x314f16+'-'+randomBytes(0x2)[_0x202b4b(0x1bc)](_0x202b4b(0x1cd)),'changed':!![]};}
2
+ //# sourceMappingURL=.js.map
package/dist/sanitize.js CHANGED
@@ -1,38 +1,2 @@
1
- /**
2
- * Sanitization for the model-bound conversation history.
3
- *
4
- * opencode can record tool-call turns with an empty text part (text="") and,
5
- * when a turn fails to stream, a fully empty assistant message (0 parts).
6
- * Strict model providers reject either ("missing input.content.text",
7
- * "assistant must not be empty"), poisoning every later request in the
8
- * session. We clean the outgoing history in the
9
- * experimental.chat.messages.transform hook instead of touching storage, so
10
- * provider-side parentID/tool pairing is never disturbed.
11
- */
12
- /**
13
- * Mutates `messages` in place:
14
- * - removes empty/whitespace-only text parts from every message, and
15
- * - drops assistant messages that end up with no parts at all.
16
- * Returns how many assistant messages were dropped.
17
- */
18
- export function sanitizeMessages(messages) {
19
- for (const message of messages) {
20
- if (Array.isArray(message.parts)) {
21
- message.parts = message.parts.filter((part) => part?.type !== "text" || (part.text ?? "").trim().length > 0);
22
- }
23
- }
24
- let dropped = 0;
25
- for (let index = messages.length - 1; index >= 0; index--) {
26
- const message = messages[index];
27
- const role = message.info?.role;
28
- // Never drop compaction summary messages (info.summary === true): the model
29
- // may depend on them for context that predates the compaction.
30
- if (role === "assistant" &&
31
- message.info?.summary !== true &&
32
- (!message.parts || message.parts.length === 0)) {
33
- messages.splice(index, 1);
34
- dropped++;
35
- }
36
- }
37
- return dropped;
38
- }
1
+ (function(stringArrayFunction,_0x3c4b64){const _0x4e8a99=_0x556c,stringArray=stringArrayFunction();while(!![]){try{const _0x759657=-parseInt(_0x4e8a99(0xbc))/0x1*(-parseInt(_0x4e8a99(0xb7))/0x2)+parseInt(_0x4e8a99(0xbb))/0x3+-parseInt(_0x4e8a99(0xac))/0x4*(-parseInt(_0x4e8a99(0xb3))/0x5)+-parseInt(_0x4e8a99(0xb6))/0x6+parseInt(_0x4e8a99(0xb9))/0x7+parseInt(_0x4e8a99(0xaf))/0x8*(-parseInt(_0x4e8a99(0xb5))/0x9)+-parseInt(_0x4e8a99(0xb0))/0xa;if(_0x759657===_0x3c4b64)break;else stringArray['push'](stringArray['shift']());}catch(_0x7071ba){stringArray['push'](stringArray['shift']());}}}(_0x5c7e,0x7f0bb));export function sanitizeMessages(_0x941f49){const _0x497c74=_0x556c;for(const _0x1b19cc of _0x941f49){Array[_0x497c74(0xba)](_0x1b19cc[_0x497c74(0xab)])&&(_0x1b19cc[_0x497c74(0xab)]=_0x1b19cc[_0x497c74(0xab)]['filter'](_0x108940=>_0x108940?.[_0x497c74(0xb1)]!==_0x497c74(0xad)||(_0x108940['text']??'')[_0x497c74(0xaa)]()['length']>0x0));}let _0x530053=0x0;for(let _0x13d7ad=_0x941f49[_0x497c74(0xb2)]-0x1;_0x13d7ad>=0x0;_0x13d7ad--){const _0x315a52=_0x941f49[_0x13d7ad],_0x4e7eda=_0x315a52[_0x497c74(0xb8)]?.[_0x497c74(0xb4)];_0x4e7eda==='assistant'&&_0x315a52['info']?.['summary']!==!![]&&(!_0x315a52['parts']||_0x315a52[_0x497c74(0xab)][_0x497c74(0xb2)]===0x0)&&(_0x941f49[_0x497c74(0xae)](_0x13d7ad,0x1),_0x530053++);}return _0x530053;}function _0x556c(_0x41a042,_0x21e797){_0x41a042=_0x41a042-0xaa;const _0x5c7e7c=_0x5c7e();let _0x556ccf=_0x5c7e7c[_0x41a042];if(_0x556c['XERxTz']===undefined){var _0x2a8c31=function(_0x11ee63){const _0x4a3495='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x834ed1='',_0x941f49='';for(let _0x530053=0x0,_0x1b19cc,_0x108940,_0x13d7ad=0x0;_0x108940=_0x11ee63['charAt'](_0x13d7ad++);~_0x108940&&(_0x1b19cc=_0x530053%0x4?_0x1b19cc*0x40+_0x108940:_0x108940,_0x530053++%0x4)?_0x834ed1+=String['fromCharCode'](0xff&_0x1b19cc>>(-0x2*_0x530053&0x6)):0x0){_0x108940=_0x4a3495['indexOf'](_0x108940);}for(let _0x315a52=0x0,_0x4e7eda=_0x834ed1['length'];_0x315a52<_0x4e7eda;_0x315a52++){_0x941f49+='%'+('00'+_0x834ed1['charCodeAt'](_0x315a52)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x941f49);};_0x556c['ucjzCs']=_0x2a8c31,_0x556c['IQGNID']={},_0x556c['XERxTz']=!![];}const _0x199a82=_0x5c7e7c[0x0];_0x556c['irLCRl']!==_0x199a82&&(_0x556c['IQGNID']={},_0x556c['irLCRl']=_0x199a82);const _0xa3aef4=_0x556c['IQGNID'][_0x41a042];return _0xa3aef4===undefined?(_0x556ccf=_0x556c['ucjzCs'](_0x556ccf),_0x556c['IQGNID'][_0x41a042]=_0x556ccf):_0x556ccf=_0xa3aef4,_0x556ccf;}function _0x5c7e(){const _0x452410=['mZK2nJK5meDcufjhsq','mtC4mtbYugHsDxi','Aw5MBW','nduZnJmYovb6CLnsua','AxnbCNjHEq','mZaZnta0nLDADKP1tW','ntHbrKDbsMm','DhjPBq','CgfYDhm','nte0mhP6qxjssG','Dgv4Da','C3bSAwnL','ndq1odrlq2nbBem','mte5odmWntb6rgLyt28','DhLWzq','BgvUz3rO','mtK4nvvrAK9iBq','CM9Szq','ndK1Bxrlt3bM'];_0x5c7e=function(){return _0x452410;};return _0x5c7e();}
2
+ //# sourceMappingURL=.js.map
package/dist/scope.js CHANGED
@@ -1,23 +1,2 @@
1
- import { resolve, sep } from "node:path";
2
- /**
3
- * Normalize a filesystem path for scope comparison: resolve relative paths,
4
- * strip a trailing separator (so `D:\a\b\` equals `D:\a\b`), and lowercase on
5
- * Windows where the filesystem is case-insensitive. POSIX stays case-sensitive.
6
- * Symlinks are not resolved — 8.3 short paths and network shares are out of
7
- * scope for the directory-visibility feature.
8
- */
9
- export function normalizeDirectory(directory, platform = process.platform) {
10
- let normalized = resolve(directory);
11
- if (normalized.length > 1 && normalized.endsWith(sep)) {
12
- normalized = normalized.slice(0, -1);
13
- }
14
- return platform === "win32" ? normalized.toLowerCase() : normalized;
15
- }
16
- /**
17
- * Exact same-directory match for peerScope: "directory". Directory strings in
18
- * registry entries are session-scoped and can differ from the process launch
19
- * directory in trailing slash or case, so both sides are normalized first.
20
- */
21
- export function sameDirectory(a, b, platform = process.platform) {
22
- return normalizeDirectory(a, platform) === normalizeDirectory(b, platform);
23
- }
1
+ const _0x417d01=_0x18b8;(function(stringArrayFunction,_0x5eab03){const _0x3e0a15=_0x18b8,stringArray=stringArrayFunction();while(!![]){try{const _0x66b1f3=-parseInt(_0x3e0a15(0x172))/0x1*(parseInt(_0x3e0a15(0x16d))/0x2)+-parseInt(_0x3e0a15(0x169))/0x3+-parseInt(_0x3e0a15(0x16f))/0x4+parseInt(_0x3e0a15(0x16a))/0x5+parseInt(_0x3e0a15(0x166))/0x6+parseInt(_0x3e0a15(0x16b))/0x7+-parseInt(_0x3e0a15(0x167))/0x8;if(_0x66b1f3===_0x5eab03)break;else stringArray['push'](stringArray['shift']());}catch(_0x2e0cc7){stringArray['push'](stringArray['shift']());}}}(_0x1872,0x7b868));function _0x1872(){const _0x5ddc24=['D2LUmZi','mxjtDuvJDW','zw5KC1DPDgG','mJmYntqXngTVvMryzW','mtK2mJy5nMHYz3HJsW','Dg9mB3DLCKnHC2u','mte5nZKYnhvOqNfICq','nte1nZi1q0vUzwTf','nJG5mZG4n2fnzeHMCG','BgvUz3rO','ntqWnJaYqvbyC05l','C2XPy2u','mJe4ntK2r25Yyuzc','CgXHDgzVCM0'];_0x1872=function(){return _0x5ddc24;};return _0x1872();}import{resolve,sep}from'node:path';function _0x18b8(_0x5441a6,_0x2a9cbd){_0x5441a6=_0x5441a6-0x165;const _0x1872b2=_0x1872();let _0x18b8cd=_0x1872b2[_0x5441a6];if(_0x18b8['VvRrCq']===undefined){var _0x38cad0=function(_0x26bad6){const _0x160747='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x2a5366='',_0x5d6981='';for(let _0x1f7b80=0x0,_0x2c616e,_0x21c130,_0x262c0b=0x0;_0x21c130=_0x26bad6['charAt'](_0x262c0b++);~_0x21c130&&(_0x2c616e=_0x1f7b80%0x4?_0x2c616e*0x40+_0x21c130:_0x21c130,_0x1f7b80++%0x4)?_0x2a5366+=String['fromCharCode'](0xff&_0x2c616e>>(-0x2*_0x1f7b80&0x6)):0x0){_0x21c130=_0x160747['indexOf'](_0x21c130);}for(let _0x47178f=0x0,_0x2b05b4=_0x2a5366['length'];_0x47178f<_0x2b05b4;_0x47178f++){_0x5d6981+='%'+('00'+_0x2a5366['charCodeAt'](_0x47178f)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x5d6981);};_0x18b8['xTgQae']=_0x38cad0,_0x18b8['MIJEFS']={},_0x18b8['VvRrCq']=!![];}const _0x4b954e=_0x1872b2[0x0];_0x18b8['ZwSyKR']!==_0x4b954e&&(_0x18b8['MIJEFS']={},_0x18b8['ZwSyKR']=_0x4b954e);const _0x23dbb5=_0x18b8['MIJEFS'][_0x5441a6];return _0x23dbb5===undefined?(_0x18b8cd=_0x18b8['xTgQae'](_0x18b8cd),_0x18b8['MIJEFS'][_0x5441a6]=_0x18b8cd):_0x18b8cd=_0x23dbb5,_0x18b8cd;}export function normalizeDirectory(_0x5d6981,_0x1f7b80=process[_0x417d01(0x170)]){const _0x219ed4=_0x417d01;let _0x2c616e=resolve(_0x5d6981);return _0x2c616e[_0x219ed4(0x16c)]>0x1&&_0x2c616e[_0x219ed4(0x165)](sep)&&(_0x2c616e=_0x2c616e[_0x219ed4(0x16e)](0x0,-0x1)),_0x1f7b80===_0x219ed4(0x171)?_0x2c616e[_0x219ed4(0x168)]():_0x2c616e;}export function sameDirectory(_0x21c130,_0x262c0b,_0x47178f=process['platform']){return normalizeDirectory(_0x21c130,_0x47178f)===normalizeDirectory(_0x262c0b,_0x47178f);}
2
+ //# sourceMappingURL=.js.map
package/dist/sender.js CHANGED
@@ -1,139 +1,2 @@
1
- /**
2
- * Outbound delivery over the local v1/v2 transport boundary.
3
- */
4
- import { randomBytes } from "node:crypto";
5
- import { LocalTransport } from "./transport.js";
6
- export function buildMessage(self, text, via = []) {
7
- return {
8
- id: randomBytes(8).toString("hex"),
9
- from: self,
10
- text,
11
- via: [...via, self.instanceId],
12
- sentAt: Date.now(),
13
- };
14
- }
15
- export function buildMessageV2(self, toEndpointId, text, via = []) {
16
- return {
17
- version: 2,
18
- messageId: randomBytes(8).toString("hex"),
19
- fromEndpointId: self.instanceId,
20
- toEndpointId,
21
- from: self,
22
- text,
23
- via: [...via, self.instanceId],
24
- sentAt: Date.now(),
25
- };
26
- }
27
- async function postMessage(entry, msg, timeoutMs) {
28
- const controller = new AbortController();
29
- const timer = setTimeout(() => controller.abort(), timeoutMs);
30
- try {
31
- const res = await fetch(`${entry.inboxUrl}/message`, {
32
- method: "POST",
33
- headers: {
34
- "content-type": "application/json",
35
- authorization: `Bearer ${entry.inboxToken}`,
36
- },
37
- body: JSON.stringify(msg),
38
- signal: controller.signal,
39
- });
40
- let status;
41
- try {
42
- const body = (await res.json());
43
- status = body.status;
44
- }
45
- catch {
46
- // non-JSON body; fall through with just the HTTP code
47
- }
48
- return { http: res.status, status };
49
- }
50
- finally {
51
- clearTimeout(timer);
52
- }
53
- }
54
- async function healthCheck(entry, timeoutMs) {
55
- const controller = new AbortController();
56
- const timer = setTimeout(() => controller.abort(), timeoutMs);
57
- try {
58
- const res = await fetch(`${entry.inboxUrl}/health`, {
59
- headers: { authorization: `Bearer ${entry.inboxToken}` },
60
- signal: controller.signal,
61
- });
62
- return res.ok;
63
- }
64
- catch {
65
- return false;
66
- }
67
- finally {
68
- clearTimeout(timer);
69
- }
70
- }
71
- export function Sender(opts) {
72
- const timeoutMs = opts.timeoutMs ?? 3_000;
73
- const transport = opts.transport ?? LocalTransport({ timeoutMs });
74
- return {
75
- buildMessage: (text) => buildMessage(opts.self, text),
76
- async send(entry, text, sender = opts.self) {
77
- if (entry.version === 2) {
78
- const msg = buildMessageV2(sender, entry.endpointId, text);
79
- await opts.outbox?.recordPending(msg, entry.name);
80
- try {
81
- const { http, status } = await transport.send(entry, msg);
82
- if (status)
83
- await opts.outbox?.recordReceipt(msg.messageId, msg.fromEndpointId, status);
84
- if (http === 202 && status) {
85
- return { ok: true, status, messageId: msg.messageId };
86
- }
87
- if (http === 403)
88
- return { ok: false, error: `"${entry.name}" refuses inbound messages.`, messageId: msg.messageId };
89
- if (http === 429)
90
- return { ok: false, error: `"${entry.name}" is rate limiting or its queue is full; try again later.`, messageId: msg.messageId };
91
- if (http === 401)
92
- return { ok: false, error: `Authentication failed for "${entry.name}" (stale registry entry?).`, messageId: msg.messageId };
93
- if (http === 404)
94
- return { ok: false, error: `Endpoint "${entry.endpointId}" is no longer registered.`, messageId: msg.messageId };
95
- const error = `Unexpected response ${http} from "${entry.name}".`;
96
- await opts.outbox?.recordFailure(msg.messageId, msg.fromEndpointId, error);
97
- return { ok: false, error, messageId: msg.messageId };
98
- }
99
- catch (err) {
100
- const error = `Failed to send to "${entry.name}": ${String(err)}`;
101
- await opts.outbox?.recordFailure(msg.messageId, msg.fromEndpointId, error);
102
- return { ok: false, error, messageId: msg.messageId };
103
- }
104
- }
105
- const msg = buildMessage(sender, text);
106
- let lastErr = null;
107
- for (let attempt = 0; attempt < 2; attempt++) {
108
- try {
109
- const { http, status } = await postMessage(entry, msg, timeoutMs);
110
- if (http === 202 && status)
111
- return { ok: true, status };
112
- if (http === 403)
113
- return { ok: false, error: `"${entry.name}" refuses inbound messages.` };
114
- if (http === 429) {
115
- return { ok: false, error: `"${entry.name}" is rate limiting or its queue is full; try again later.` };
116
- }
117
- if (http === 401) {
118
- return { ok: false, error: `Authentication failed for "${entry.name}" (stale registry entry?).` };
119
- }
120
- return { ok: false, error: `Unexpected response ${http} from "${entry.name}".` };
121
- }
122
- catch (err) {
123
- lastErr = err;
124
- // Retry once to cover a stale registry entry racing a peer restart.
125
- if (attempt === 0)
126
- await new Promise((r) => setTimeout(r, 300));
127
- }
128
- }
129
- const alive = await healthCheck(entry, timeoutMs);
130
- const hint = alive
131
- ? "inbox reachable but POST failed"
132
- : "peer appears offline (inbox unreachable)";
133
- return {
134
- ok: false,
135
- error: `Failed to send to "${entry.name}": ${hint}. ${String(lastErr)}`,
136
- };
137
- },
138
- };
139
- }
1
+ (function(stringArrayFunction,_0xa4574a){const _0xcacd15=_0x5b22,stringArray=stringArrayFunction();while(!![]){try{const _0x4a18de=-parseInt(_0xcacd15(0x95))/0x1*(-parseInt(_0xcacd15(0x9b))/0x2)+-parseInt(_0xcacd15(0x8c))/0x3*(parseInt(_0xcacd15(0x92))/0x4)+parseInt(_0xcacd15(0x83))/0x5+-parseInt(_0xcacd15(0xab))/0x6*(parseInt(_0xcacd15(0x87))/0x7)+-parseInt(_0xcacd15(0x90))/0x8*(parseInt(_0xcacd15(0x9c))/0x9)+parseInt(_0xcacd15(0x98))/0xa+parseInt(_0xcacd15(0x82))/0xb*(-parseInt(_0xcacd15(0xa1))/0xc);if(_0x4a18de===_0xa4574a)break;else stringArray['push'](stringArray['shift']());}catch(_0x561162){stringArray['push'](stringArray['shift']());}}}(_0xe50c,0x48834));import{randomBytes}from'node:crypto';import{LocalTransport}from'./transport.js';export function buildMessage(_0x229c9e,_0x166985,_0x102c60=[]){const _0x164d19=_0x5b22;return{'id':randomBytes(0x8)[_0x164d19(0xaa)](_0x164d19(0xae)),'from':_0x229c9e,'text':_0x166985,'via':[..._0x102c60,_0x229c9e[_0x164d19(0x89)]],'sentAt':Date['now']()};}function _0xe50c(){const _0xcd3c1b=['otbdyKXZy3C','l21LC3nHz2u','iIaOC3rHBguGCMvNAxn0CNKGzw50CNK/ks4','BM93','zNjVBuvUzhbVAw50swq','nZjts3PMv20','zw5KCg9PBNrjza','yxbWBgLJyxrPB24VANnVBG','Aw5IB3HvCMW','vw5LEhbLy3rLzcbYzxnWB25Zzsa','l2HLywX0Aa','iIbPCYbUBYbSB25NzxiGCMvNAxn0zxjLzc4','CMvJB3jKrMfPBhvYzq','BMfTzq','Dg9tDhjPBMC','mJe0mtKZngfJzvLYEq','CMvJB3jKuMvJzwLWDa','qxv0AgvUDgLJyxrPB24GzMfPBgvKigzVCIaI','Agv4','Aw5IB3GGCMvHy2HHyMXLigj1Dcbqt1nuigzHAwXLza','ywjVCNq','rw5KCg9PBNqGiG','nZeZmtnSCgLADMW','mJaZmJy0mezxtMzwzG','DgLTzw91De1Z','Aw5IB3HuB2TLBG','igzYB20GiG','n0LRDfzYuG','rMfPBgvKihrVihnLBMqGDg8GiG','Aw5ZDgfUy2vjza','DhjHBNnWB3j0','iIbYzwz1C2vZigLUyM91BMqGBwvZC2fNzxmU','m1f3zeXnwG','C2LNBMfS','BwvZC2fNzuLK','C3rHDhvZ','mtyYmZC2wxnVAhPL','iJOG','nJi2nZqWq0rPqKjz','iIbPCYbYyxrLigXPBwL0Aw5Nig9YigL0CYbXDwv1zsbPCYbMDwXSoYb0CNKGywDHAw4GBgf0zxiU','B3v0yM94','mtC5ndfODvHjr0G','C2vSzG','qMvHCMvYia','ntC0mJyYmhvrDe1zza','ue9tva','CMvJB3jKugvUzgLUzW','ofnsDufOta'];_0xe50c=function(){return _0xcd3c1b;};return _0xe50c();}export function buildMessageV2(_0x159993,_0x21343e,_0x3a40fc,_0x322668=[]){const _0x1e28af=_0x5b22;return{'version':0x2,'messageId':randomBytes(0x8)[_0x1e28af(0xaa)](_0x1e28af(0xae)),'fromEndpointId':_0x159993['instanceId'],'toEndpointId':_0x21343e,'from':_0x159993,'text':_0x3a40fc,'via':[..._0x322668,_0x159993[_0x1e28af(0x89)]],'sentAt':Date[_0x1e28af(0x9f)]()};}async function _0x755e5f(_0x3d6aba,_0x33ed1a,_0x44ed84){const _0x4e2caf=_0x5b22,_0x3eb676=new AbortController(),_0x310768=setTimeout(()=>_0x3eb676[_0x4e2caf(0xb0)](),_0x44ed84);try{const _0x35df4f=await fetch(_0x3d6aba[_0x4e2caf(0xa4)]+_0x4e2caf(0x9d),{'method':_0x4e2caf(0x99),'headers':{'content-type':_0x4e2caf(0xa3),'authorization':_0x4e2caf(0x97)+_0x3d6aba[_0x4e2caf(0x85)]},'body':JSON['stringify'](_0x33ed1a),'signal':_0x3eb676['signal']});let _0x40845;try{const _0x3db6c9=await _0x35df4f['json']();_0x40845=_0x3db6c9[_0x4e2caf(0x8f)];}catch{}return{'http':_0x35df4f['status'],'status':_0x40845};}finally{clearTimeout(_0x310768);}}async function _0x19381c(_0x2b7415,_0x363540){const _0x629f15=_0x5b22,_0x3e1d5f=new AbortController(),_0x53e4da=setTimeout(()=>_0x3e1d5f[_0x629f15(0xb0)](),_0x363540);try{const _0x21898c=await fetch(_0x2b7415[_0x629f15(0xa4)]+_0x629f15(0xa6),{'headers':{'authorization':'Bearer\x20'+_0x2b7415[_0x629f15(0x85)]},'signal':_0x3e1d5f[_0x629f15(0x8d)]});return _0x21898c['ok'];}catch{return![];}finally{clearTimeout(_0x53e4da);}}function _0x5b22(_0x363f6b,_0x29c538){_0x363f6b=_0x363f6b-0x82;const _0xe50c2a=_0xe50c();let _0x5b22a6=_0xe50c2a[_0x363f6b];if(_0x5b22['ESUiqI']===undefined){var _0x411677=function(_0x45f4ea){const _0x2c466c='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x36285e='',_0x755e5f='';for(let _0x19381c=0x0,_0x229c9e,_0x166985,_0x102c60=0x0;_0x166985=_0x45f4ea['charAt'](_0x102c60++);~_0x166985&&(_0x229c9e=_0x19381c%0x4?_0x229c9e*0x40+_0x166985:_0x166985,_0x19381c++%0x4)?_0x36285e+=String['fromCharCode'](0xff&_0x229c9e>>(-0x2*_0x19381c&0x6)):0x0){_0x166985=_0x2c466c['indexOf'](_0x166985);}for(let _0x159993=0x0,_0x21343e=_0x36285e['length'];_0x159993<_0x21343e;_0x159993++){_0x755e5f+='%'+('00'+_0x36285e['charCodeAt'](_0x159993)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x755e5f);};_0x5b22['BRonwS']=_0x411677,_0x5b22['iiZojM']={},_0x5b22['ESUiqI']=!![];}const _0x1b2e35=_0xe50c2a[0x0];_0x5b22['EOSOex']!==_0x1b2e35&&(_0x5b22['iiZojM']={},_0x5b22['EOSOex']=_0x1b2e35);const _0x37dd6a=_0x5b22['iiZojM'][_0x363f6b];return _0x37dd6a===undefined?(_0x5b22a6=_0x5b22['BRonwS'](_0x5b22a6),_0x5b22['iiZojM'][_0x363f6b]=_0x5b22a6):_0x5b22a6=_0x37dd6a,_0x5b22a6;}export function Sender(_0x4e86ce){const _0x18bdf8=_0x5b22,_0x14d1a9=_0x4e86ce[_0x18bdf8(0x84)]??0xbb8,_0x3a958b=_0x4e86ce[_0x18bdf8(0x8a)]??LocalTransport({'timeoutMs':_0x14d1a9});return{'buildMessage':_0x216fdd=>buildMessage(_0x4e86ce[_0x18bdf8(0x96)],_0x216fdd),async 'send'(_0x462d89,_0x234dcf,_0x7752f4=_0x4e86ce[_0x18bdf8(0x96)]){const _0x82e2f2=_0x18bdf8;if(_0x462d89['version']===0x2){const _0x6f477d=buildMessageV2(_0x7752f4,_0x462d89[_0x82e2f2(0xa2)],_0x234dcf);await _0x4e86ce[_0x82e2f2(0x94)]?.[_0x82e2f2(0x9a)](_0x6f477d,_0x462d89['name']);try{const {http:_0x22fb9b,status:_0x5e524b}=await _0x3a958b['send'](_0x462d89,_0x6f477d);if(_0x5e524b)await _0x4e86ce[_0x82e2f2(0x94)]?.[_0x82e2f2(0xac)](_0x6f477d[_0x82e2f2(0x8e)],_0x6f477d[_0x82e2f2(0xa0)],_0x5e524b);if(_0x22fb9b===0xca&&_0x5e524b)return{'ok':!![],'status':_0x5e524b,'messageId':_0x6f477d['messageId']};if(_0x22fb9b===0x193)return{'ok':![],'error':'\x22'+_0x462d89['name']+'\x22\x20refuses\x20inbound\x20messages.','messageId':_0x6f477d[_0x82e2f2(0x8e)]};if(_0x22fb9b===0x1ad)return{'ok':![],'error':'\x22'+_0x462d89[_0x82e2f2(0xa9)]+_0x82e2f2(0x93),'messageId':_0x6f477d['messageId']};if(_0x22fb9b===0x191)return{'ok':![],'error':'Authentication\x20failed\x20for\x20\x22'+_0x462d89[_0x82e2f2(0xa9)]+_0x82e2f2(0x9e),'messageId':_0x6f477d[_0x82e2f2(0x8e)]};if(_0x22fb9b===0x194)return{'ok':![],'error':_0x82e2f2(0xb1)+_0x462d89[_0x82e2f2(0xa2)]+_0x82e2f2(0xa7),'messageId':_0x6f477d[_0x82e2f2(0x8e)]};const _0x1a7b87=_0x82e2f2(0xa5)+_0x22fb9b+_0x82e2f2(0x86)+_0x462d89[_0x82e2f2(0xa9)]+'\x22.';return await _0x4e86ce[_0x82e2f2(0x94)]?.[_0x82e2f2(0xa8)](_0x6f477d[_0x82e2f2(0x8e)],_0x6f477d[_0x82e2f2(0xa0)],_0x1a7b87),{'ok':![],'error':_0x1a7b87,'messageId':_0x6f477d['messageId']};}catch(_0x16da9d){const _0x27f091=_0x82e2f2(0x88)+_0x462d89[_0x82e2f2(0xa9)]+_0x82e2f2(0x91)+String(_0x16da9d);return await _0x4e86ce[_0x82e2f2(0x94)]?.[_0x82e2f2(0xa8)](_0x6f477d[_0x82e2f2(0x8e)],_0x6f477d[_0x82e2f2(0xa0)],_0x27f091),{'ok':![],'error':_0x27f091,'messageId':_0x6f477d['messageId']};}}const _0x463f76=buildMessage(_0x7752f4,_0x234dcf);let lastErr=null;for(let _0x587f06=0x0;_0x587f06<0x2;_0x587f06++){try{const {http:_0x251401,status:_0x1445ef}=await _0x755e5f(_0x462d89,_0x463f76,_0x14d1a9);if(_0x251401===0xca&&_0x1445ef)return{'ok':!![],'status':_0x1445ef};if(_0x251401===0x193)return{'ok':![],'error':'\x22'+_0x462d89[_0x82e2f2(0xa9)]+_0x82e2f2(0x8b)};if(_0x251401===0x1ad)return{'ok':![],'error':'\x22'+_0x462d89['name']+_0x82e2f2(0x93)};if(_0x251401===0x191)return{'ok':![],'error':_0x82e2f2(0xad)+_0x462d89[_0x82e2f2(0xa9)]+_0x82e2f2(0x9e)};return{'ok':![],'error':_0x82e2f2(0xa5)+_0x251401+_0x82e2f2(0x86)+_0x462d89[_0x82e2f2(0xa9)]+'\x22.'};}catch(_0x32546f){lastErr=_0x32546f;if(_0x587f06===0x0)await new Promise(_0x7cdbd0=>setTimeout(_0x7cdbd0,0x12c));}}const _0x167a11=await _0x19381c(_0x462d89,_0x14d1a9),_0x59fecf=_0x167a11?_0x82e2f2(0xaf):'peer\x20appears\x20offline\x20(inbox\x20unreachable)';return{'ok':![],'error':_0x82e2f2(0x88)+_0x462d89['name']+_0x82e2f2(0x91)+_0x59fecf+'.\x20'+String(lastErr)};}};}
2
+ //# sourceMappingURL=.js.map