@kehto/paja 0.21.3 → 0.22.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 +15 -2
- package/dist/browser-host.js +633 -140
- package/dist/browser-host.js.map +1 -1
- package/dist/{chunk-HG2CUTQC.js → chunk-RMYEHOOR.js} +75 -5
- package/dist/chunk-RMYEHOOR.js.map +1 -0
- package/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +5 -5
- package/dist/chunk-HG2CUTQC.js.map +0 -1
package/dist/browser-host.js
CHANGED
|
@@ -3187,6 +3187,17 @@ function unblock(state, identity) {
|
|
|
3187
3187
|
}
|
|
3188
3188
|
};
|
|
3189
3189
|
}
|
|
3190
|
+
function setQuota(state, identity, bytes) {
|
|
3191
|
+
const key = toKey(identity);
|
|
3192
|
+
const entry = getEntry(state, key);
|
|
3193
|
+
return {
|
|
3194
|
+
...state,
|
|
3195
|
+
entries: {
|
|
3196
|
+
...state.entries,
|
|
3197
|
+
[key]: { ...entry, quota: bytes }
|
|
3198
|
+
}
|
|
3199
|
+
};
|
|
3200
|
+
}
|
|
3190
3201
|
function getQuota(state, identity) {
|
|
3191
3202
|
const key = toKey(identity);
|
|
3192
3203
|
const entry = state.entries[key];
|
|
@@ -3775,10 +3786,10 @@ function createSessionRegistry(notifier, onRegister) {
|
|
|
3775
3786
|
},
|
|
3776
3787
|
unregister(windowId) {
|
|
3777
3788
|
const pubkey2 = byWindowId2.get(windowId);
|
|
3778
|
-
if (pubkey2) {
|
|
3789
|
+
if (pubkey2 !== void 0 && byPubkey2.get(pubkey2)?.windowId === windowId) {
|
|
3779
3790
|
byPubkey2.delete(pubkey2);
|
|
3780
|
-
byWindowId2.delete(windowId);
|
|
3781
3791
|
}
|
|
3792
|
+
byWindowId2.delete(windowId);
|
|
3782
3793
|
byWindowIdEntry.delete(windowId);
|
|
3783
3794
|
pendingUpdates2.delete(windowId);
|
|
3784
3795
|
},
|
|
@@ -3939,15 +3950,20 @@ function createAclState(persistence, defaultPolicy = "permissive", onMutation) {
|
|
|
3939
3950
|
if (!entry) return void 0;
|
|
3940
3951
|
return {
|
|
3941
3952
|
pubkey: pubkey2 || "",
|
|
3953
|
+
dTag,
|
|
3954
|
+
aggregateHash,
|
|
3942
3955
|
capabilities: bitsToCapabilities(entry.caps),
|
|
3943
3956
|
blocked: entry.blocked,
|
|
3944
3957
|
stateQuota: entry.quota
|
|
3945
3958
|
};
|
|
3946
3959
|
},
|
|
3947
3960
|
getAllEntries() {
|
|
3948
|
-
return Object.entries(state.entries).map(([, entry]) => {
|
|
3961
|
+
return Object.entries(state.entries).map(([key, entry]) => {
|
|
3962
|
+
const separator = key.lastIndexOf(":");
|
|
3949
3963
|
return {
|
|
3950
3964
|
pubkey: "",
|
|
3965
|
+
dTag: key.slice(0, separator),
|
|
3966
|
+
aggregateHash: key.slice(separator + 1),
|
|
3951
3967
|
capabilities: bitsToCapabilities(entry.caps),
|
|
3952
3968
|
blocked: entry.blocked,
|
|
3953
3969
|
stateQuota: entry.quota
|
|
@@ -3958,10 +3974,20 @@ function createAclState(persistence, defaultPolicy = "permissive", onMutation) {
|
|
|
3958
3974
|
const id = toIdentity(pubkey2, dTag, aggregateHash);
|
|
3959
3975
|
return getQuota(state, id);
|
|
3960
3976
|
},
|
|
3977
|
+
setStateQuota(pubkey2, dTag, aggregateHash, bytes) {
|
|
3978
|
+
if (!Number.isSafeInteger(bytes) || bytes < 0) {
|
|
3979
|
+
throw new RangeError("State quota must be a non-negative safe integer byte count");
|
|
3980
|
+
}
|
|
3981
|
+
const id = toIdentity(pubkey2, dTag, aggregateHash);
|
|
3982
|
+
ensureRuntimeDefaultEntry(id);
|
|
3983
|
+
state = setQuota(state, id, bytes);
|
|
3984
|
+
},
|
|
3961
3985
|
persist() {
|
|
3962
3986
|
try {
|
|
3963
3987
|
persistence.persist(serialize(state));
|
|
3988
|
+
return true;
|
|
3964
3989
|
} catch {
|
|
3990
|
+
return false;
|
|
3965
3991
|
}
|
|
3966
3992
|
},
|
|
3967
3993
|
load() {
|
|
@@ -3977,7 +4003,9 @@ function createAclState(persistence, defaultPolicy = "permissive", onMutation) {
|
|
|
3977
4003
|
state = createState(defaultPolicy);
|
|
3978
4004
|
try {
|
|
3979
4005
|
persistence.persist("");
|
|
4006
|
+
return true;
|
|
3980
4007
|
} catch {
|
|
4008
|
+
return false;
|
|
3981
4009
|
}
|
|
3982
4010
|
}
|
|
3983
4011
|
};
|
|
@@ -4335,12 +4363,17 @@ function handleRelaySubscribe(context, windowId, msg, m) {
|
|
|
4335
4363
|
const filters = m.filters ?? [];
|
|
4336
4364
|
if (!subId) return;
|
|
4337
4365
|
const subKey = `${windowId}:${subId}`;
|
|
4338
|
-
|
|
4366
|
+
const entry = { windowId, filters };
|
|
4367
|
+
subscriptions.set(subKey, entry);
|
|
4368
|
+
const isActive = () => subscriptions.get(subKey) === entry && context.canReadRelay(windowId);
|
|
4369
|
+
const send = (response) => {
|
|
4370
|
+
if (isActive()) hooks.sendToNapplet(windowId, normalizeRelayServiceResponse(response));
|
|
4371
|
+
};
|
|
4339
4372
|
const seenIds = /* @__PURE__ */ new Set();
|
|
4340
4373
|
function deliver(event, relayHints) {
|
|
4341
4374
|
if (seenIds.has(event.id)) return;
|
|
4342
4375
|
seenIds.add(event.id);
|
|
4343
|
-
if (
|
|
4376
|
+
if (isActive()) {
|
|
4344
4377
|
sendRelayEvent(hooks, windowId, subId, createRelayEventResultWithHints(event, relayHints));
|
|
4345
4378
|
}
|
|
4346
4379
|
}
|
|
@@ -4351,22 +4384,16 @@ function handleRelaySubscribe(context, windowId, msg, m) {
|
|
|
4351
4384
|
const relayService = relayServiceFrom(context);
|
|
4352
4385
|
const cacheService = !serviceRegistry["relay"] ? serviceRegistry["cache"] : void 0;
|
|
4353
4386
|
if (!isShellKind && relayService) {
|
|
4354
|
-
relayService.handleMessage(windowId, msg,
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
});
|
|
4358
|
-
if (cacheService) {
|
|
4359
|
-
cacheService.handleMessage(windowId, msg, (resp) => {
|
|
4360
|
-
if (!subscriptions.has(subKey)) return;
|
|
4361
|
-
hooks.sendToNapplet(windowId, normalizeRelayServiceResponse(resp));
|
|
4362
|
-
});
|
|
4363
|
-
}
|
|
4387
|
+
relayService.handleMessage(windowId, msg, send);
|
|
4388
|
+
if (cacheService && isActive()) cacheService.handleMessage(windowId, msg, send);
|
|
4389
|
+
if (!isActive()) closeRelayBackends(context, windowId, subId, subKey);
|
|
4364
4390
|
return;
|
|
4365
4391
|
}
|
|
4366
4392
|
const relayHint = typeof m.relay === "string" && m.relay.length > 0 ? m.relay : void 0;
|
|
4367
|
-
|
|
4393
|
+
if (!isActive()) return;
|
|
4394
|
+
deliverFromRuntimeBackends(context, subId, subKey, filters, isShellKind, deliver, send, isActive, relayHint);
|
|
4368
4395
|
}
|
|
4369
|
-
function deliverFromRuntimeBackends(context,
|
|
4396
|
+
function deliverFromRuntimeBackends(context, subId, subKey, filters, isShellKind, deliver, send, isActive, relayHint) {
|
|
4370
4397
|
const { hooks } = context;
|
|
4371
4398
|
const cache2 = hooks.cache;
|
|
4372
4399
|
if (cache2?.isAvailable() && !isShellKind) {
|
|
@@ -4377,7 +4404,7 @@ function deliverFromRuntimeBackends(context, windowId, subId, subKey, filters, i
|
|
|
4377
4404
|
}
|
|
4378
4405
|
const pool = hooks.relayPool;
|
|
4379
4406
|
if (!pool?.isAvailable() && !isShellKind) {
|
|
4380
|
-
|
|
4407
|
+
send({ type: "relay.eose", subId });
|
|
4381
4408
|
return;
|
|
4382
4409
|
}
|
|
4383
4410
|
if (!pool?.isAvailable() || isShellKind) return;
|
|
@@ -4386,15 +4413,16 @@ function deliverFromRuntimeBackends(context, windowId, subId, subKey, filters, i
|
|
|
4386
4413
|
const eoseFallbackTimer = setTimeout(() => {
|
|
4387
4414
|
if (!eoseSent) {
|
|
4388
4415
|
eoseSent = true;
|
|
4389
|
-
|
|
4416
|
+
send({ type: "relay.eose", subId });
|
|
4390
4417
|
}
|
|
4391
4418
|
}, 15e3);
|
|
4392
4419
|
const subscription = pool.subscribe(filters, (item) => {
|
|
4420
|
+
if (!isActive()) return;
|
|
4393
4421
|
if (item === "EOSE") {
|
|
4394
4422
|
clearTimeout(eoseFallbackTimer);
|
|
4395
4423
|
if (!eoseSent) {
|
|
4396
4424
|
eoseSent = true;
|
|
4397
|
-
|
|
4425
|
+
send({ type: "relay.eose", subId });
|
|
4398
4426
|
}
|
|
4399
4427
|
return;
|
|
4400
4428
|
}
|
|
@@ -4412,6 +4440,31 @@ function deliverFromRuntimeBackends(context, windowId, subId, subKey, filters, i
|
|
|
4412
4440
|
clearTimeout(eoseFallbackTimer);
|
|
4413
4441
|
subscription.unsubscribe();
|
|
4414
4442
|
});
|
|
4443
|
+
if (!isActive()) pool.untrackSubscription(subKey);
|
|
4444
|
+
}
|
|
4445
|
+
function closeRelayBackends(context, windowId, subId, subKey) {
|
|
4446
|
+
const relay = context.serviceRegistry["relay"] ?? context.serviceRegistry["relay-pool"];
|
|
4447
|
+
const cache2 = !context.serviceRegistry["relay"] ? context.serviceRegistry["cache"] : void 0;
|
|
4448
|
+
for (const service of /* @__PURE__ */ new Set([relay, cache2])) {
|
|
4449
|
+
try {
|
|
4450
|
+
service?.handleMessage(windowId, { type: "relay.close", subId }, () => {
|
|
4451
|
+
});
|
|
4452
|
+
} catch {
|
|
4453
|
+
}
|
|
4454
|
+
}
|
|
4455
|
+
try {
|
|
4456
|
+
context.hooks.relayPool?.untrackSubscription(subKey);
|
|
4457
|
+
} catch {
|
|
4458
|
+
}
|
|
4459
|
+
}
|
|
4460
|
+
function revokeRelaySubscriptions(context, windowId) {
|
|
4461
|
+
const entries = [...context.subscriptions].filter(([, entry]) => entry.windowId === windowId);
|
|
4462
|
+
for (const [key] of entries) context.subscriptions.delete(key);
|
|
4463
|
+
for (const [key] of entries) {
|
|
4464
|
+
const subId = key.slice(windowId.length + 1);
|
|
4465
|
+
closeRelayBackends(context, windowId, subId, key);
|
|
4466
|
+
context.hooks.sendToNapplet(windowId, { type: "relay.closed", subId, reason: "denied: relay:read" });
|
|
4467
|
+
}
|
|
4415
4468
|
}
|
|
4416
4469
|
function handleRelayClose(context, windowId, msg, m) {
|
|
4417
4470
|
const { hooks, subscriptions } = context;
|
|
@@ -5794,6 +5847,7 @@ function createRuntime(hooks) {
|
|
|
5794
5847
|
if (mutation.type === "revoke" && mutation.capability !== "relay:read") return;
|
|
5795
5848
|
for (const entry of sessionRegistry2.getAllEntries()) {
|
|
5796
5849
|
if (entry.dTag === mutation.dTag && entry.aggregateHash === mutation.aggregateHash) {
|
|
5850
|
+
revokeRelaySubscriptions({ hooks, serviceRegistry, subscriptions }, entry.windowId);
|
|
5797
5851
|
incRuntime?.revokeWindow(entry.windowId);
|
|
5798
5852
|
}
|
|
5799
5853
|
}
|
|
@@ -5851,7 +5905,17 @@ function createRuntime(hooks) {
|
|
|
5851
5905
|
manifestCache2.load();
|
|
5852
5906
|
const domainHandlers = createRuntimeDomainHandlers({ hooks, serviceRegistry, sessionRegistry: sessionRegistry2, aclState });
|
|
5853
5907
|
const napHandlers = {
|
|
5854
|
-
relay: createRelayHandler({
|
|
5908
|
+
relay: createRelayHandler({
|
|
5909
|
+
hooks,
|
|
5910
|
+
serviceRegistry,
|
|
5911
|
+
subscriptions,
|
|
5912
|
+
eventBuffer,
|
|
5913
|
+
replayDetector,
|
|
5914
|
+
canReadRelay(windowId) {
|
|
5915
|
+
const entry = sessionRegistry2.getEntryByWindowId(windowId);
|
|
5916
|
+
return !!entry && aclState.check("", entry.dTag, entry.aggregateHash, "relay:read");
|
|
5917
|
+
}
|
|
5918
|
+
}),
|
|
5855
5919
|
identity: createIdentityHandler({ hooks, serviceRegistry }),
|
|
5856
5920
|
count: createCountHandler({ hooks, serviceRegistry }),
|
|
5857
5921
|
inc: incRuntime.handleMessage,
|
|
@@ -7670,7 +7734,7 @@ function createRelayPoolService(options) {
|
|
|
7670
7734
|
subId,
|
|
7671
7735
|
result: createRelayEventResultWithHints(item, observedRelayUrls ?? relayUrls2)
|
|
7672
7736
|
});
|
|
7673
|
-
}, relayUrls2);
|
|
7737
|
+
}, relayUrls2, relayHint !== void 0);
|
|
7674
7738
|
tracked.set(subKey, { handle, eoseTimer });
|
|
7675
7739
|
return;
|
|
7676
7740
|
}
|
|
@@ -10002,9 +10066,10 @@ function discoveredReadRelays(ctx, authors, lists) {
|
|
|
10002
10066
|
}
|
|
10003
10067
|
return { relays: [...relays], missingAuthors };
|
|
10004
10068
|
}
|
|
10005
|
-
function
|
|
10069
|
+
function immediateReadPlan(ctx, relayHints) {
|
|
10006
10070
|
const hints = allowed(ctx, relayHints ?? []);
|
|
10007
|
-
|
|
10071
|
+
if (hints.length > 0) return { relays: hints, origin: "hint" };
|
|
10072
|
+
return { relays: allowed(ctx, ctx.fallbackRelays), origin: "fallback" };
|
|
10008
10073
|
}
|
|
10009
10074
|
function recordRelay(collector, id, relayUrl2) {
|
|
10010
10075
|
let set = collector.relayMap.get(id);
|
|
@@ -10047,8 +10112,8 @@ function buildQueryResult(collector, options, incomplete, subscribedAny) {
|
|
|
10047
10112
|
if (!subscribedAny) result2.error = "relay list unavailable";
|
|
10048
10113
|
return result2;
|
|
10049
10114
|
}
|
|
10050
|
-
function relayPoolSubscribe(ctx, filters, relayUrl2, cb) {
|
|
10051
|
-
return ctx.relayPool.subscribe(filters, [relayUrl2], cb);
|
|
10115
|
+
function relayPoolSubscribe(ctx, filters, relayUrl2, cb, origin) {
|
|
10116
|
+
return ctx.relayPool.subscribe(filters, [relayUrl2], cb, origin);
|
|
10052
10117
|
}
|
|
10053
10118
|
function startQueryImpl(ctx, filters, options, sink) {
|
|
10054
10119
|
if (!ctx.relayPool.isAvailable()) {
|
|
@@ -10098,7 +10163,7 @@ function startQueryImpl(ctx, filters, options, sink) {
|
|
|
10098
10163
|
if (finished || discoveryPending || collector.pendingVerifications > 0) return;
|
|
10099
10164
|
if (activeRelays.size === 0 || eoseRelays.size >= activeRelays.size) finalize();
|
|
10100
10165
|
}
|
|
10101
|
-
function attachRelay(relayUrl2) {
|
|
10166
|
+
function attachRelay(relayUrl2, origin) {
|
|
10102
10167
|
if (finished || activeRelays.has(relayUrl2)) return;
|
|
10103
10168
|
activeRelays.add(relayUrl2);
|
|
10104
10169
|
try {
|
|
@@ -10111,7 +10176,7 @@ function startQueryImpl(ctx, filters, options, sink) {
|
|
|
10111
10176
|
}
|
|
10112
10177
|
recordRelay(collector, item.id, relayUrl2);
|
|
10113
10178
|
admitEvent(ctx, collector, item, sink, () => !finished, maybeFinalize);
|
|
10114
|
-
});
|
|
10179
|
+
}, origin);
|
|
10115
10180
|
subscribedAny = true;
|
|
10116
10181
|
if (finished) {
|
|
10117
10182
|
try {
|
|
@@ -10126,13 +10191,21 @@ function startQueryImpl(ctx, filters, options, sink) {
|
|
|
10126
10191
|
incomplete = true;
|
|
10127
10192
|
}
|
|
10128
10193
|
}
|
|
10129
|
-
function attachMany(relayUrls2) {
|
|
10130
|
-
for (const relayUrl2 of relayUrls2) attachRelay(relayUrl2);
|
|
10194
|
+
function attachMany(relayUrls2, origin) {
|
|
10195
|
+
for (const relayUrl2 of relayUrls2) attachRelay(relayUrl2, origin);
|
|
10196
|
+
}
|
|
10197
|
+
function attachHintedAndDiscovered(hintRelays, discoveredRelays) {
|
|
10198
|
+
attachMany(hintRelays, "hint");
|
|
10199
|
+
attachMany(discoveredRelays, "nip65");
|
|
10200
|
+
if (hintRelays.length === 0 && discoveredRelays.length === 0) {
|
|
10201
|
+
attachMany(allowed(ctx, ctx.fallbackRelays), "fallback");
|
|
10202
|
+
}
|
|
10131
10203
|
}
|
|
10132
10204
|
timer = setTimeout(() => finalize(true), options?.timeoutMs ?? ctx.defaultTimeoutMs);
|
|
10133
10205
|
if (authors.length === 0) {
|
|
10134
10206
|
discoveryPending = false;
|
|
10135
|
-
attachMany(allowed(ctx,
|
|
10207
|
+
attachMany(allowed(ctx, options?.relays ?? []), "hint");
|
|
10208
|
+
attachMany(allowed(ctx, ctx.fallbackRelays), "fallback");
|
|
10136
10209
|
maybeFinalize();
|
|
10137
10210
|
} else {
|
|
10138
10211
|
let loaded;
|
|
@@ -10141,7 +10214,8 @@ function startQueryImpl(ctx, filters, options, sink) {
|
|
|
10141
10214
|
} catch {
|
|
10142
10215
|
discoveryPending = false;
|
|
10143
10216
|
incomplete = true;
|
|
10144
|
-
|
|
10217
|
+
const immediate = immediateReadPlan(ctx, options?.relays);
|
|
10218
|
+
attachMany(immediate.relays, immediate.origin);
|
|
10145
10219
|
maybeFinalize();
|
|
10146
10220
|
return { result: result2, close: () => finalize(true) };
|
|
10147
10221
|
}
|
|
@@ -10149,17 +10223,17 @@ function startQueryImpl(ctx, filters, options, sink) {
|
|
|
10149
10223
|
const discovery = discoveredReadRelays(ctx, authors, loaded);
|
|
10150
10224
|
discoveryPending = false;
|
|
10151
10225
|
incomplete ||= discovery.missingAuthors.length > 0;
|
|
10152
|
-
|
|
10153
|
-
attachMany(initial.length > 0 ? initial : allowed(ctx, ctx.fallbackRelays));
|
|
10226
|
+
attachHintedAndDiscovered(allowed(ctx, options?.relays ?? []), discovery.relays);
|
|
10154
10227
|
maybeFinalize();
|
|
10155
10228
|
} else {
|
|
10156
|
-
|
|
10229
|
+
const immediate = immediateReadPlan(ctx, options?.relays);
|
|
10230
|
+
attachMany(immediate.relays, immediate.origin);
|
|
10157
10231
|
void Promise.resolve(loaded).then((lists) => {
|
|
10158
10232
|
if (finished) return;
|
|
10159
10233
|
const discovery = discoveredReadRelays(ctx, authors, lists);
|
|
10160
10234
|
discoveryPending = false;
|
|
10161
10235
|
incomplete ||= discovery.missingAuthors.length > 0;
|
|
10162
|
-
attachMany(discovery.relays);
|
|
10236
|
+
attachMany(discovery.relays, "nip65");
|
|
10163
10237
|
maybeFinalize();
|
|
10164
10238
|
}).catch(() => {
|
|
10165
10239
|
if (finished) return;
|
|
@@ -10205,7 +10279,7 @@ function closeLiveSub(sub) {
|
|
|
10205
10279
|
}
|
|
10206
10280
|
sub.handles.clear();
|
|
10207
10281
|
}
|
|
10208
|
-
function attachLiveRelay(ctx, sub, filters, relayUrl2, sink) {
|
|
10282
|
+
function attachLiveRelay(ctx, sub, filters, relayUrl2, sink, origin) {
|
|
10209
10283
|
if (sub.closed || sub.relays.has(relayUrl2)) return false;
|
|
10210
10284
|
sub.relays.add(relayUrl2);
|
|
10211
10285
|
try {
|
|
@@ -10217,7 +10291,7 @@ function attachLiveRelay(ctx, sub, filters, relayUrl2, sink) {
|
|
|
10217
10291
|
sub.seen.add(item.id);
|
|
10218
10292
|
sink.event(createRelayEventResultWithHints(item, [relayUrl2]));
|
|
10219
10293
|
});
|
|
10220
|
-
});
|
|
10294
|
+
}, origin);
|
|
10221
10295
|
if (sub.closed) {
|
|
10222
10296
|
try {
|
|
10223
10297
|
handle.unsubscribe();
|
|
@@ -10243,8 +10317,15 @@ function startSubscription(ctx, filters, options, sink) {
|
|
|
10243
10317
|
};
|
|
10244
10318
|
let discoveryOpen = authors.length > 0;
|
|
10245
10319
|
let discoveryTimer;
|
|
10246
|
-
function attachMany(relayUrls2) {
|
|
10247
|
-
for (const relayUrl2 of relayUrls2) attachLiveRelay(ctx, sub, filters, relayUrl2, sink);
|
|
10320
|
+
function attachMany(relayUrls2, origin) {
|
|
10321
|
+
for (const relayUrl2 of relayUrls2) attachLiveRelay(ctx, sub, filters, relayUrl2, sink, origin);
|
|
10322
|
+
}
|
|
10323
|
+
function attachHintedAndDiscovered(hintRelays, discoveredRelays) {
|
|
10324
|
+
attachMany(hintRelays, "hint");
|
|
10325
|
+
attachMany(discoveredRelays, "nip65");
|
|
10326
|
+
if (hintRelays.length === 0 && discoveredRelays.length === 0) {
|
|
10327
|
+
attachMany(allowed(ctx, ctx.fallbackRelays), "fallback");
|
|
10328
|
+
}
|
|
10248
10329
|
}
|
|
10249
10330
|
function closeUnavailable() {
|
|
10250
10331
|
if (sub.closed || sub.handles.size > 0) return;
|
|
@@ -10255,7 +10336,8 @@ function startSubscription(ctx, filters, options, sink) {
|
|
|
10255
10336
|
closeUnavailable();
|
|
10256
10337
|
} else if (authors.length === 0) {
|
|
10257
10338
|
discoveryOpen = false;
|
|
10258
|
-
|
|
10339
|
+
const immediate = immediateReadPlan(ctx, options?.relays);
|
|
10340
|
+
attachMany(immediate.relays, immediate.origin);
|
|
10259
10341
|
closeUnavailable();
|
|
10260
10342
|
} else {
|
|
10261
10343
|
let loaded;
|
|
@@ -10263,18 +10345,19 @@ function startSubscription(ctx, filters, options, sink) {
|
|
|
10263
10345
|
loaded = ctx.loadRelayLists(authors);
|
|
10264
10346
|
} catch {
|
|
10265
10347
|
discoveryOpen = false;
|
|
10266
|
-
|
|
10348
|
+
const immediate = immediateReadPlan(ctx, options?.relays);
|
|
10349
|
+
attachMany(immediate.relays, immediate.origin);
|
|
10267
10350
|
closeUnavailable();
|
|
10268
10351
|
loaded = /* @__PURE__ */ new Map();
|
|
10269
10352
|
}
|
|
10270
10353
|
if (discoveryOpen && loaded instanceof Map) {
|
|
10271
10354
|
const discovery = discoveredReadRelays(ctx, authors, loaded);
|
|
10272
10355
|
discoveryOpen = false;
|
|
10273
|
-
|
|
10274
|
-
attachMany(initial.length > 0 ? initial : allowed(ctx, ctx.fallbackRelays));
|
|
10356
|
+
attachHintedAndDiscovered(allowed(ctx, options?.relays ?? []), discovery.relays);
|
|
10275
10357
|
closeUnavailable();
|
|
10276
10358
|
} else if (discoveryOpen) {
|
|
10277
|
-
|
|
10359
|
+
const immediate = immediateReadPlan(ctx, options?.relays);
|
|
10360
|
+
attachMany(immediate.relays, immediate.origin);
|
|
10278
10361
|
discoveryTimer = setTimeout(() => {
|
|
10279
10362
|
discoveryOpen = false;
|
|
10280
10363
|
closeUnavailable();
|
|
@@ -10283,7 +10366,7 @@ function startSubscription(ctx, filters, options, sink) {
|
|
|
10283
10366
|
if (!discoveryOpen || sub.closed) return;
|
|
10284
10367
|
discoveryOpen = false;
|
|
10285
10368
|
clearTimeout(discoveryTimer);
|
|
10286
|
-
attachMany(discoveredReadRelays(ctx, authors, lists).relays);
|
|
10369
|
+
attachMany(discoveredReadRelays(ctx, authors, lists).relays, "nip65");
|
|
10287
10370
|
closeUnavailable();
|
|
10288
10371
|
}).catch(() => {
|
|
10289
10372
|
if (!discoveryOpen || sub.closed) return;
|
|
@@ -13258,10 +13341,7 @@ function createCryptoAdapter(shellHooks) {
|
|
|
13258
13341
|
function createAclPersistence() {
|
|
13259
13342
|
return {
|
|
13260
13343
|
persist(data) {
|
|
13261
|
-
|
|
13262
|
-
localStorage.setItem("napplet:acl", data);
|
|
13263
|
-
} catch {
|
|
13264
|
-
}
|
|
13344
|
+
localStorage.setItem("napplet:acl", data);
|
|
13265
13345
|
},
|
|
13266
13346
|
load() {
|
|
13267
13347
|
try {
|
|
@@ -14243,10 +14323,10 @@ function registerNip5dSessionIfNeeded({
|
|
|
14243
14323
|
if (existing && previousRegistration === sourceRegistrationId) {
|
|
14244
14324
|
return;
|
|
14245
14325
|
}
|
|
14326
|
+
state.environments.delete(windowId);
|
|
14246
14327
|
if (existing && previousRegistration !== void 0) {
|
|
14247
14328
|
runtime.destroyWindow(windowId);
|
|
14248
14329
|
runtime.sessionRegistry.unregister(windowId);
|
|
14249
|
-
state.environments.delete(windowId);
|
|
14250
14330
|
}
|
|
14251
14331
|
if (existing && previousRegistration === void 0) {
|
|
14252
14332
|
state.sessionRegistration.set(windowId, sourceRegistrationId);
|
|
@@ -16237,7 +16317,8 @@ var SECTION_IDS = {
|
|
|
16237
16317
|
acl: "paja-section-acl",
|
|
16238
16318
|
signer: "paja-section-signer",
|
|
16239
16319
|
"resource-servers": "paja-section-resource-servers",
|
|
16240
|
-
messages: "paja-section-messages"
|
|
16320
|
+
messages: "paja-section-messages",
|
|
16321
|
+
events: "paja-section-events"
|
|
16241
16322
|
};
|
|
16242
16323
|
function installPajaSidebarSections() {
|
|
16243
16324
|
const collapsed = {};
|
|
@@ -18979,6 +19060,159 @@ function dedupe(urls) {
|
|
|
18979
19060
|
return out;
|
|
18980
19061
|
}
|
|
18981
19062
|
|
|
19063
|
+
// ../../node_modules/.pnpm/nostr-tools@2.23.3_typescript@5.9.3/node_modules/nostr-tools/lib/esm/utils.js
|
|
19064
|
+
var utf8Decoder6 = new TextDecoder("utf-8");
|
|
19065
|
+
var utf8Encoder6 = new TextEncoder();
|
|
19066
|
+
function normalizeURL2(url) {
|
|
19067
|
+
try {
|
|
19068
|
+
if (url.indexOf("://") === -1)
|
|
19069
|
+
url = "wss://" + url;
|
|
19070
|
+
let p = new URL(url);
|
|
19071
|
+
if (p.protocol === "http:")
|
|
19072
|
+
p.protocol = "ws:";
|
|
19073
|
+
else if (p.protocol === "https:")
|
|
19074
|
+
p.protocol = "wss:";
|
|
19075
|
+
p.pathname = p.pathname.replace(/\/+/g, "/");
|
|
19076
|
+
if (p.pathname.endsWith("/"))
|
|
19077
|
+
p.pathname = p.pathname.slice(0, -1);
|
|
19078
|
+
if (p.port === "80" && p.protocol === "ws:" || p.port === "443" && p.protocol === "wss:")
|
|
19079
|
+
p.port = "";
|
|
19080
|
+
p.searchParams.sort();
|
|
19081
|
+
p.hash = "";
|
|
19082
|
+
return p.toString();
|
|
19083
|
+
} catch (e) {
|
|
19084
|
+
throw new Error(`Invalid URL: ${url}`);
|
|
19085
|
+
}
|
|
19086
|
+
}
|
|
19087
|
+
|
|
19088
|
+
// src/browser-relay-transport.ts
|
|
19089
|
+
function relaySources(urls) {
|
|
19090
|
+
const sources2 = /* @__PURE__ */ new Map();
|
|
19091
|
+
for (const source of urls) {
|
|
19092
|
+
const url = normalizeURL2(source);
|
|
19093
|
+
if (!sources2.has(url)) sources2.set(url, source);
|
|
19094
|
+
}
|
|
19095
|
+
return [...sources2].map(([url, source]) => ({ url, source }));
|
|
19096
|
+
}
|
|
19097
|
+
function subscribePajaLive(pool, relayUrls2, filters, next, observe, maxWait, label = "kehto-paja-runtime") {
|
|
19098
|
+
const sources2 = relaySources(relayUrls2);
|
|
19099
|
+
const activeFilters = filters.length ? filters : [{}];
|
|
19100
|
+
const seen = /* @__PURE__ */ new Set();
|
|
19101
|
+
const ended = /* @__PURE__ */ new Set();
|
|
19102
|
+
const subscriptions = /* @__PURE__ */ new Set();
|
|
19103
|
+
const controller = new AbortController();
|
|
19104
|
+
let closed = false;
|
|
19105
|
+
let eosed = false;
|
|
19106
|
+
const finishRelay = (url) => {
|
|
19107
|
+
if (closed || eosed) return;
|
|
19108
|
+
ended.add(url);
|
|
19109
|
+
if (ended.size === sources2.length) {
|
|
19110
|
+
eosed = true;
|
|
19111
|
+
next("EOSE");
|
|
19112
|
+
}
|
|
19113
|
+
};
|
|
19114
|
+
if (!sources2.length) queueMicrotask(() => {
|
|
19115
|
+
if (!closed) next("EOSE");
|
|
19116
|
+
});
|
|
19117
|
+
for (const { url, source } of sources2) {
|
|
19118
|
+
if (pool.allowConnectingToRelay?.(url, ["read", activeFilters]) === false) {
|
|
19119
|
+
queueMicrotask(() => finishRelay(url));
|
|
19120
|
+
continue;
|
|
19121
|
+
}
|
|
19122
|
+
void pool.ensureRelay(url, {
|
|
19123
|
+
connectionTimeout: Math.min(pool.maxWaitForConnection ?? maxWait, maxWait),
|
|
19124
|
+
abort: controller.signal
|
|
19125
|
+
}).then((relay) => {
|
|
19126
|
+
if (closed) return;
|
|
19127
|
+
pool.onRelayConnectionSuccess?.(url);
|
|
19128
|
+
const subscribe = (retry) => {
|
|
19129
|
+
if (closed) return;
|
|
19130
|
+
const subscription = relay.subscribe(activeFilters, {
|
|
19131
|
+
label,
|
|
19132
|
+
eoseTimeout: maxWait,
|
|
19133
|
+
onevent(event) {
|
|
19134
|
+
if (closed) return;
|
|
19135
|
+
if (pool.trackRelays) {
|
|
19136
|
+
const history = pool.seenOn.get(event.id) ?? /* @__PURE__ */ new Set();
|
|
19137
|
+
history.add(relay);
|
|
19138
|
+
pool.seenOn.set(event.id, history);
|
|
19139
|
+
}
|
|
19140
|
+
try {
|
|
19141
|
+
observe(event, source);
|
|
19142
|
+
} catch {
|
|
19143
|
+
}
|
|
19144
|
+
if (seen.has(event.id)) return;
|
|
19145
|
+
seen.add(event.id);
|
|
19146
|
+
next(event);
|
|
19147
|
+
},
|
|
19148
|
+
oneose: () => finishRelay(url),
|
|
19149
|
+
onclose(reason) {
|
|
19150
|
+
const signer = pool.automaticallyAuth?.(url);
|
|
19151
|
+
if (!closed && !retry && signer && reason.startsWith("auth-required: ")) {
|
|
19152
|
+
void relay.auth(signer).then(() => subscribe(true)).catch(() => finishRelay(url));
|
|
19153
|
+
} else finishRelay(url);
|
|
19154
|
+
}
|
|
19155
|
+
});
|
|
19156
|
+
if (closed && !subscription.closed) subscription.close("paja query closed");
|
|
19157
|
+
else if (!subscription.closed) subscriptions.add(subscription);
|
|
19158
|
+
};
|
|
19159
|
+
subscribe(false);
|
|
19160
|
+
}).catch(() => {
|
|
19161
|
+
if (!closed) pool.onRelayConnectionFailure?.(url);
|
|
19162
|
+
finishRelay(url);
|
|
19163
|
+
});
|
|
19164
|
+
}
|
|
19165
|
+
return {
|
|
19166
|
+
unsubscribe(reason = "paja unsubscribe") {
|
|
19167
|
+
if (closed) return;
|
|
19168
|
+
closed = true;
|
|
19169
|
+
controller.abort();
|
|
19170
|
+
for (const subscription of subscriptions) {
|
|
19171
|
+
if (subscription.closed) continue;
|
|
19172
|
+
try {
|
|
19173
|
+
void Promise.resolve(subscription.close(reason)).catch(() => {
|
|
19174
|
+
});
|
|
19175
|
+
} catch {
|
|
19176
|
+
}
|
|
19177
|
+
}
|
|
19178
|
+
subscriptions.clear();
|
|
19179
|
+
}
|
|
19180
|
+
};
|
|
19181
|
+
}
|
|
19182
|
+
async function queryPajaLive(pool, relayUrls2, filters, maxWait, observe, collectUntilLimit = false, signal) {
|
|
19183
|
+
const batches = await Promise.all((filters.length ? filters : [{}]).map((filter) => {
|
|
19184
|
+
const limit = collectUntilLimit && typeof filter.limit === "number" && filter.limit >= 0 ? filter.limit : Infinity;
|
|
19185
|
+
if (limit === 0 || signal?.aborted) return Promise.resolve([]);
|
|
19186
|
+
return new Promise((resolve) => {
|
|
19187
|
+
const events2 = [];
|
|
19188
|
+
let subscription;
|
|
19189
|
+
let finished = false;
|
|
19190
|
+
const finish = (reason) => {
|
|
19191
|
+
if (finished) return;
|
|
19192
|
+
finished = true;
|
|
19193
|
+
clearTimeout(timer);
|
|
19194
|
+
signal?.removeEventListener("abort", abort);
|
|
19195
|
+
subscription?.unsubscribe(reason);
|
|
19196
|
+
resolve(events2);
|
|
19197
|
+
};
|
|
19198
|
+
const abort = () => finish("paja query aborted");
|
|
19199
|
+
const timer = setTimeout(() => finish("paja query timeout"), maxWait);
|
|
19200
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
19201
|
+
subscription = subscribePajaLive(pool, relayUrls2, [filter], (item) => {
|
|
19202
|
+
if (finished) return;
|
|
19203
|
+
if (item === "EOSE") return finish("closed automatically on eose");
|
|
19204
|
+
events2.push(item);
|
|
19205
|
+
if (events2.length >= limit) finish("paja query limit reached");
|
|
19206
|
+
}, observe, maxWait, collectUntilLimit ? "kehto-paja-candidates" : "kehto-paja-query");
|
|
19207
|
+
if (finished) subscription.unsubscribe();
|
|
19208
|
+
if (signal?.aborted) abort();
|
|
19209
|
+
});
|
|
19210
|
+
}));
|
|
19211
|
+
const events = /* @__PURE__ */ new Map();
|
|
19212
|
+
for (const event of batches.flat()) events.set(event.id, event);
|
|
19213
|
+
return [...events.values()].sort((a, b) => b.created_at - a.created_at);
|
|
19214
|
+
}
|
|
19215
|
+
|
|
18982
19216
|
// src/browser-relay-runtime.ts
|
|
18983
19217
|
var PAJA_NIP65_RELAY_LIST_KIND = 10002;
|
|
18984
19218
|
var PAJA_CONTACT_LIST_KIND = 3;
|
|
@@ -19026,78 +19260,6 @@ function collectMemoryEvents(events, filters) {
|
|
|
19026
19260
|
}
|
|
19027
19261
|
return [...out.values()].sort((a, b) => b.created_at - a.created_at);
|
|
19028
19262
|
}
|
|
19029
|
-
function subscribeLive(pool, relayUrls2, filters, next) {
|
|
19030
|
-
const activeFilters = filters.length > 0 ? filters : [{}];
|
|
19031
|
-
const requests = relayUrls2.flatMap((url) => activeFilters.map((filter) => ({ url, filter })));
|
|
19032
|
-
if (requests.length === 0) {
|
|
19033
|
-
queueMicrotask(() => next("EOSE"));
|
|
19034
|
-
return { unsubscribe() {
|
|
19035
|
-
} };
|
|
19036
|
-
}
|
|
19037
|
-
const sub = pool.subscribeMap(requests, {
|
|
19038
|
-
label: "kehto-paja-runtime",
|
|
19039
|
-
maxWait: PAJA_LIVE_QUERY_WAIT_MS,
|
|
19040
|
-
onevent: (event) => next(event),
|
|
19041
|
-
oneose: () => next("EOSE")
|
|
19042
|
-
});
|
|
19043
|
-
return {
|
|
19044
|
-
unsubscribe() {
|
|
19045
|
-
void sub.close("paja unsubscribe");
|
|
19046
|
-
}
|
|
19047
|
-
};
|
|
19048
|
-
}
|
|
19049
|
-
function queryLiveBounded(pool, relayUrls2, filter, maxWaitMs, limit, signal) {
|
|
19050
|
-
if (limit === 0 || signal?.aborted) return Promise.resolve([]);
|
|
19051
|
-
return new Promise((resolve) => {
|
|
19052
|
-
const events = [];
|
|
19053
|
-
let settled = false;
|
|
19054
|
-
let closeRequested = false;
|
|
19055
|
-
let closeReason = "paja query limit reached";
|
|
19056
|
-
let subscription;
|
|
19057
|
-
let abort;
|
|
19058
|
-
const finish = () => {
|
|
19059
|
-
if (settled) return;
|
|
19060
|
-
settled = true;
|
|
19061
|
-
if (abort) signal?.removeEventListener("abort", abort);
|
|
19062
|
-
resolve(events);
|
|
19063
|
-
};
|
|
19064
|
-
const close = (reason = closeReason) => {
|
|
19065
|
-
closeRequested = true;
|
|
19066
|
-
closeReason = reason;
|
|
19067
|
-
if (!subscription) return;
|
|
19068
|
-
void Promise.resolve(subscription.close(reason)).catch(() => {
|
|
19069
|
-
});
|
|
19070
|
-
finish();
|
|
19071
|
-
};
|
|
19072
|
-
abort = () => close("paja query aborted");
|
|
19073
|
-
signal?.addEventListener("abort", abort, { once: true });
|
|
19074
|
-
subscription = pool.subscribeEose(relayUrls2, filter, {
|
|
19075
|
-
label: "kehto-paja-runtime",
|
|
19076
|
-
maxWait: maxWaitMs,
|
|
19077
|
-
onevent(event) {
|
|
19078
|
-
if (events.length >= limit) return;
|
|
19079
|
-
events.push(event);
|
|
19080
|
-
if (events.length === limit) close();
|
|
19081
|
-
},
|
|
19082
|
-
onclose: finish
|
|
19083
|
-
});
|
|
19084
|
-
if (closeRequested) close();
|
|
19085
|
-
});
|
|
19086
|
-
}
|
|
19087
|
-
async function queryLive(pool, relayUrls2, filters, maxWaitMs = PAJA_LIVE_QUERY_WAIT_MS, collectUntilLimit = false, signal) {
|
|
19088
|
-
const activeFilters = filters.length > 0 ? filters : [{}];
|
|
19089
|
-
const batches = await Promise.all(activeFilters.map((filter) => {
|
|
19090
|
-
const limit = typeof filter.limit === "number" && filter.limit >= 0 ? filter.limit : void 0;
|
|
19091
|
-
if (collectUntilLimit && limit !== void 0) return queryLiveBounded(pool, relayUrls2, filter, maxWaitMs, limit, signal);
|
|
19092
|
-
return pool.querySync(relayUrls2, filter, {
|
|
19093
|
-
label: "kehto-paja-runtime",
|
|
19094
|
-
maxWait: maxWaitMs
|
|
19095
|
-
});
|
|
19096
|
-
}));
|
|
19097
|
-
const out = /* @__PURE__ */ new Map();
|
|
19098
|
-
for (const event of batches.flat()) out.set(event.id, event);
|
|
19099
|
-
return [...out.values()].sort((a, b) => b.created_at - a.created_at);
|
|
19100
|
-
}
|
|
19101
19263
|
async function publishLive(pool, relayUrls2, event) {
|
|
19102
19264
|
const results = await Promise.allSettled(pool.publish(relayUrls2, event));
|
|
19103
19265
|
return Object.fromEntries(relayUrls2.map((relayUrl2, index) => [relayUrl2, results[index]?.status === "fulfilled"]));
|
|
@@ -19140,12 +19302,33 @@ function createPajaRelayBackend(getSimulation, confirmRequest, livePool = new Si
|
|
|
19140
19302
|
const fixtureEvents = getSimulation().relay.fixtures.flatMap(toNostrEvent);
|
|
19141
19303
|
const acceptedMemoryEvents = [];
|
|
19142
19304
|
const subscribers = /* @__PURE__ */ new Set();
|
|
19305
|
+
let relayEventObserver;
|
|
19306
|
+
let relayRequestObserver;
|
|
19307
|
+
const observeRelayRequest = (context, relayUrls2) => {
|
|
19308
|
+
if (relayUrls2.length === 0) return;
|
|
19309
|
+
relayRequestObserver?.({ ...context, relayUrls: [...relayUrls2] });
|
|
19310
|
+
};
|
|
19311
|
+
const observeRelayEvent = (context, relayUrls2, event, source) => {
|
|
19312
|
+
relayEventObserver?.({
|
|
19313
|
+
...context,
|
|
19314
|
+
relayUrls: [...relayUrls2],
|
|
19315
|
+
event,
|
|
19316
|
+
sightedOn: [source]
|
|
19317
|
+
});
|
|
19318
|
+
};
|
|
19143
19319
|
const isAvailable = () => getSimulation().relay.mode !== "disabled" && getPajaRelayUrls(getSimulation()).length > 0;
|
|
19144
19320
|
const cachedEvents = () => getSimulation().relay.mode === "memory" ? [...fixtureEvents, ...acceptedMemoryEvents] : [];
|
|
19145
|
-
const query = async (relayUrls2, filters, maxWaitMs) => {
|
|
19321
|
+
const query = async (relayUrls2, filters, maxWaitMs, context = { reason: "host" }) => {
|
|
19146
19322
|
const cached = collectMemoryEvents(cachedEvents(), filters);
|
|
19147
19323
|
if (getSimulation().relay.mode !== "live" || relayUrls2.length === 0) return cached;
|
|
19148
|
-
|
|
19324
|
+
observeRelayRequest(context, relayUrls2);
|
|
19325
|
+
const liveEvents = await queryPajaLive(
|
|
19326
|
+
livePool,
|
|
19327
|
+
relayUrls2,
|
|
19328
|
+
filters,
|
|
19329
|
+
maxWaitMs ?? PAJA_LIVE_QUERY_WAIT_MS,
|
|
19330
|
+
(event, source) => observeRelayEvent(context, relayUrls2, event, source)
|
|
19331
|
+
);
|
|
19149
19332
|
const out = /* @__PURE__ */ new Map();
|
|
19150
19333
|
for (const event of [...cached, ...liveEvents]) out.set(event.id, event);
|
|
19151
19334
|
return [...out.values()].sort((a, b) => b.created_at - a.created_at);
|
|
@@ -19153,7 +19336,16 @@ function createPajaRelayBackend(getSimulation, confirmRequest, livePool = new Si
|
|
|
19153
19336
|
const queryContactListCandidates = async (relayUrls2, filters, maxWaitMs, signal) => {
|
|
19154
19337
|
const cached = collectMemoryEvents(cachedEvents(), filters);
|
|
19155
19338
|
if (signal?.aborted || getSimulation().relay.mode !== "live" || relayUrls2.length === 0) return cached;
|
|
19156
|
-
|
|
19339
|
+
observeRelayRequest({ reason: "host" }, relayUrls2);
|
|
19340
|
+
const liveEvents = await queryPajaLive(
|
|
19341
|
+
livePool,
|
|
19342
|
+
relayUrls2,
|
|
19343
|
+
filters,
|
|
19344
|
+
maxWaitMs ?? PAJA_LIVE_QUERY_WAIT_MS,
|
|
19345
|
+
(event, source) => observeRelayEvent({ reason: "host" }, relayUrls2, event, source),
|
|
19346
|
+
true,
|
|
19347
|
+
signal
|
|
19348
|
+
);
|
|
19157
19349
|
const out = /* @__PURE__ */ new Map();
|
|
19158
19350
|
for (const event of [...cached, ...liveEvents]) out.set(event.id, event);
|
|
19159
19351
|
return [...out.values()].sort((a, b) => b.created_at - a.created_at);
|
|
@@ -19182,7 +19374,7 @@ function createPajaRelayBackend(getSimulation, confirmRequest, livePool = new Si
|
|
|
19182
19374
|
return { outcomes };
|
|
19183
19375
|
}
|
|
19184
19376
|
const backend = {
|
|
19185
|
-
subscription(relayUrls2, filtersInput) {
|
|
19377
|
+
subscription(relayUrls2, filtersInput, context = { reason: "host" }) {
|
|
19186
19378
|
return {
|
|
19187
19379
|
subscribe(next) {
|
|
19188
19380
|
const filters = normalizedFilters(filtersInput);
|
|
@@ -19192,7 +19384,15 @@ function createPajaRelayBackend(getSimulation, confirmRequest, livePool = new Si
|
|
|
19192
19384
|
};
|
|
19193
19385
|
subscribers.add(subscriber);
|
|
19194
19386
|
for (const event of collectMemoryEvents(cachedEvents(), filters)) next(event);
|
|
19195
|
-
|
|
19387
|
+
if (getSimulation().relay.mode === "live") observeRelayRequest(context, relayUrls2);
|
|
19388
|
+
const liveSub = getSimulation().relay.mode === "live" ? subscribePajaLive(
|
|
19389
|
+
livePool,
|
|
19390
|
+
relayUrls2,
|
|
19391
|
+
filters,
|
|
19392
|
+
subscriber.next,
|
|
19393
|
+
(event, source) => observeRelayEvent(context, relayUrls2, event, source),
|
|
19394
|
+
PAJA_LIVE_QUERY_WAIT_MS
|
|
19395
|
+
) : null;
|
|
19196
19396
|
queueMicrotask(() => {
|
|
19197
19397
|
if (subscribers.has(subscriber) && !liveSub) next("EOSE");
|
|
19198
19398
|
});
|
|
@@ -19209,12 +19409,12 @@ function createPajaRelayBackend(getSimulation, confirmRequest, livePool = new Si
|
|
|
19209
19409
|
const attempt = await attemptPublish(relayUrls2, event);
|
|
19210
19410
|
if (attempt.error) throw new Error(attempt.error);
|
|
19211
19411
|
},
|
|
19212
|
-
request(relayUrls2, filtersInput) {
|
|
19412
|
+
request(relayUrls2, filtersInput, context = { reason: "host" }) {
|
|
19213
19413
|
return {
|
|
19214
19414
|
subscribe(observer) {
|
|
19215
19415
|
const filters = normalizedFilters(filtersInput);
|
|
19216
19416
|
let active = true;
|
|
19217
|
-
query(relayUrls2, filters).then((matched) => {
|
|
19417
|
+
query(relayUrls2, filters, void 0, context).then((matched) => {
|
|
19218
19418
|
if (!active) return;
|
|
19219
19419
|
for (const event of matched) observer.next(event);
|
|
19220
19420
|
observer.complete();
|
|
@@ -19233,11 +19433,18 @@ function createPajaRelayBackend(getSimulation, confirmRequest, livePool = new Si
|
|
|
19233
19433
|
},
|
|
19234
19434
|
async countWithRelay(relayUrls2, filters) {
|
|
19235
19435
|
if (getSimulation().relay.mode !== "live") throw new Error("count unavailable");
|
|
19436
|
+
observeRelayRequest({ reason: "host" }, relayUrls2);
|
|
19236
19437
|
return countLive(livePool, relayUrls2, normalizedFilters(filters));
|
|
19237
19438
|
},
|
|
19238
19439
|
observedRelayUrls(eventId) {
|
|
19239
19440
|
return [...livePool.seenOn?.get(eventId) ?? []].map((relay) => relay.url);
|
|
19240
19441
|
},
|
|
19442
|
+
setRelayEventObserver(observer) {
|
|
19443
|
+
relayEventObserver = observer;
|
|
19444
|
+
},
|
|
19445
|
+
setRelayRequestObserver(observer) {
|
|
19446
|
+
relayRequestObserver = observer;
|
|
19447
|
+
},
|
|
19241
19448
|
query,
|
|
19242
19449
|
async publishToRelays(relayUrls2, event) {
|
|
19243
19450
|
return (await attemptPublish(relayUrls2, event)).outcomes;
|
|
@@ -19357,8 +19564,8 @@ function createPajaRelayListLoader(backend, getSimulation, signerProvider, getHo
|
|
|
19357
19564
|
}
|
|
19358
19565
|
function createPajaOutboxRelayPool(backend) {
|
|
19359
19566
|
return {
|
|
19360
|
-
subscribe(filters, relayUrls2, callback) {
|
|
19361
|
-
return backend.subscription(relayUrls2, filters).subscribe((item) => callback(item));
|
|
19567
|
+
subscribe(filters, relayUrls2, callback, origin) {
|
|
19568
|
+
return backend.subscription(relayUrls2, filters, { reason: "outbox", origin }).subscribe((item) => callback(item));
|
|
19362
19569
|
},
|
|
19363
19570
|
publish(event, relayUrls2) {
|
|
19364
19571
|
return backend.publishToRelays(relayUrls2, event);
|
|
@@ -21510,9 +21717,10 @@ function createDevServices(backend, getSimulation, relayConfig, onThemeService,
|
|
|
21510
21717
|
}
|
|
21511
21718
|
if (getSimulation().relay.mode === "live") {
|
|
21512
21719
|
services.relay = createRelayPoolService({
|
|
21513
|
-
subscribe: (filters, callback, relayUrls2) => backend.subscription(
|
|
21720
|
+
subscribe: (filters, callback, relayUrls2, fromHint) => backend.subscription(
|
|
21514
21721
|
(relayUrls2 ?? getReadRelays()).filter((url) => isPajaRelayAllowed(url, getAllRelays)),
|
|
21515
|
-
filters
|
|
21722
|
+
filters,
|
|
21723
|
+
{ reason: fromHint ? "hint" : "host" }
|
|
21516
21724
|
).subscribe((item) => {
|
|
21517
21725
|
if (item === "EOSE" || typeof item === "object" && item !== null) {
|
|
21518
21726
|
callback(
|
|
@@ -21809,6 +22017,241 @@ function forwardPajaHotkey(event) {
|
|
|
21809
22017
|
}));
|
|
21810
22018
|
}
|
|
21811
22019
|
|
|
22020
|
+
// src/browser-relay-panel.ts
|
|
22021
|
+
var PAJA_EVENT_COUNTER_RESET_ID = "event-counter-reset";
|
|
22022
|
+
var RELAY_BOXES = [
|
|
22023
|
+
{
|
|
22024
|
+
kind: "nip65",
|
|
22025
|
+
label: "outbox relays (NIP-65)",
|
|
22026
|
+
reason: "outbox",
|
|
22027
|
+
origin: "nip65",
|
|
22028
|
+
configured: false,
|
|
22029
|
+
emptyNote: "no author-routed reads"
|
|
22030
|
+
},
|
|
22031
|
+
{ kind: "hint", label: "relay hints", reason: "outbox", origin: "hint", configured: false },
|
|
22032
|
+
{ kind: "fallback", label: "fallback relays", reason: "outbox", origin: "fallback", configured: true },
|
|
22033
|
+
{ kind: "unattributed", label: "outbox relays (unattributed)", reason: "outbox", configured: false },
|
|
22034
|
+
{ kind: "scoped", label: "scoped relay", reason: "hint", configured: false },
|
|
22035
|
+
{ kind: "host", label: "host pool", reason: "host", configured: false }
|
|
22036
|
+
];
|
|
22037
|
+
function boxKindFor(reason, origin) {
|
|
22038
|
+
if (reason === "outbox") return origin ?? "unattributed";
|
|
22039
|
+
return reason === "hint" ? "scoped" : "host";
|
|
22040
|
+
}
|
|
22041
|
+
function emptyBox() {
|
|
22042
|
+
return { count: 0, reads: /* @__PURE__ */ new Map(), relays: /* @__PURE__ */ new Map() };
|
|
22043
|
+
}
|
|
22044
|
+
function distinctRelayUrls(urls) {
|
|
22045
|
+
const unique = /* @__PURE__ */ new Map();
|
|
22046
|
+
for (const url of urls) {
|
|
22047
|
+
if (url.length === 0) continue;
|
|
22048
|
+
const key = normalizeURL2(url);
|
|
22049
|
+
if (!unique.has(key)) unique.set(key, url);
|
|
22050
|
+
}
|
|
22051
|
+
return [...unique.values()];
|
|
22052
|
+
}
|
|
22053
|
+
function createPajaRelayEventCounter(onChange) {
|
|
22054
|
+
const boxes = /* @__PURE__ */ new Map();
|
|
22055
|
+
const eventIds = /* @__PURE__ */ new Set();
|
|
22056
|
+
let total = 0;
|
|
22057
|
+
const boxFor = (kind) => {
|
|
22058
|
+
let box = boxes.get(kind);
|
|
22059
|
+
if (!box) {
|
|
22060
|
+
box = emptyBox();
|
|
22061
|
+
boxes.set(kind, box);
|
|
22062
|
+
}
|
|
22063
|
+
return box;
|
|
22064
|
+
};
|
|
22065
|
+
const relayFor = (kind, relayUrl2) => {
|
|
22066
|
+
const box = boxFor(kind);
|
|
22067
|
+
const key = normalizeURL2(relayUrl2);
|
|
22068
|
+
let relay = box.relays.get(key);
|
|
22069
|
+
if (!relay) {
|
|
22070
|
+
relay = { relayUrl: relayUrl2, count: 0, kinds: /* @__PURE__ */ new Map() };
|
|
22071
|
+
box.relays.set(key, relay);
|
|
22072
|
+
}
|
|
22073
|
+
return relay;
|
|
22074
|
+
};
|
|
22075
|
+
return {
|
|
22076
|
+
get total() {
|
|
22077
|
+
return total;
|
|
22078
|
+
},
|
|
22079
|
+
get uniqueEvents() {
|
|
22080
|
+
return eventIds.size;
|
|
22081
|
+
},
|
|
22082
|
+
snapshot(inventory) {
|
|
22083
|
+
const out = [];
|
|
22084
|
+
for (const spec of RELAY_BOXES) {
|
|
22085
|
+
const box = boxes.get(spec.kind);
|
|
22086
|
+
const configured = spec.configured ? inventory?.[spec.kind] ?? [] : [];
|
|
22087
|
+
const seen = /* @__PURE__ */ new Set();
|
|
22088
|
+
const relays = [];
|
|
22089
|
+
const push = (relayUrl2, isConfigured) => {
|
|
22090
|
+
const key = normalizeURL2(relayUrl2);
|
|
22091
|
+
if (seen.has(key)) return;
|
|
22092
|
+
seen.add(key);
|
|
22093
|
+
const relay = box?.relays.get(key);
|
|
22094
|
+
relays.push({
|
|
22095
|
+
relayUrl: relayUrl2,
|
|
22096
|
+
count: relay?.count ?? 0,
|
|
22097
|
+
readCount: box?.reads.get(key) ?? 0,
|
|
22098
|
+
configured: isConfigured,
|
|
22099
|
+
kinds: [...relay?.kinds.entries() ?? []].sort(([left], [right]) => left - right).map(([kind, count]) => ({ kind, count }))
|
|
22100
|
+
});
|
|
22101
|
+
};
|
|
22102
|
+
for (const url of configured) push(url, true);
|
|
22103
|
+
for (const relay of box?.relays.values() ?? []) push(relay.relayUrl, false);
|
|
22104
|
+
if (relays.length === 0 && !(spec.emptyNote && total > 0)) continue;
|
|
22105
|
+
relays.sort((left, right) => right.count - left.count);
|
|
22106
|
+
out.push({
|
|
22107
|
+
kind: spec.kind,
|
|
22108
|
+
label: spec.label,
|
|
22109
|
+
reason: spec.reason,
|
|
22110
|
+
...spec.origin ? { origin: spec.origin } : {},
|
|
22111
|
+
count: box?.count ?? 0,
|
|
22112
|
+
relays,
|
|
22113
|
+
...relays.length === 0 && spec.emptyNote ? { emptyNote: spec.emptyNote } : {}
|
|
22114
|
+
});
|
|
22115
|
+
}
|
|
22116
|
+
return out;
|
|
22117
|
+
},
|
|
22118
|
+
recordRead(reason, relayUrls2, origin) {
|
|
22119
|
+
const kind = boxKindFor(reason, origin);
|
|
22120
|
+
const box = boxFor(kind);
|
|
22121
|
+
let changed = false;
|
|
22122
|
+
for (const relayUrl2 of distinctRelayUrls(relayUrls2)) {
|
|
22123
|
+
const key = normalizeURL2(relayUrl2);
|
|
22124
|
+
box.reads.set(key, (box.reads.get(key) ?? 0) + 1);
|
|
22125
|
+
relayFor(kind, relayUrl2);
|
|
22126
|
+
changed = true;
|
|
22127
|
+
}
|
|
22128
|
+
if (changed) onChange?.();
|
|
22129
|
+
},
|
|
22130
|
+
recordEvent(reason, event, sightedOn, origin) {
|
|
22131
|
+
if (typeof event !== "object" || event === null) return;
|
|
22132
|
+
const kind = event.kind;
|
|
22133
|
+
if (typeof kind !== "number" || !Number.isSafeInteger(kind) || kind < 0) return;
|
|
22134
|
+
const relays = distinctRelayUrls(sightedOn);
|
|
22135
|
+
if (relays.length === 0) return;
|
|
22136
|
+
const box = boxFor(boxKindFor(reason, origin));
|
|
22137
|
+
for (const relayUrl2 of relays) {
|
|
22138
|
+
const relay = relayFor(boxKindFor(reason, origin), relayUrl2);
|
|
22139
|
+
relay.count += 1;
|
|
22140
|
+
relay.kinds.set(kind, (relay.kinds.get(kind) ?? 0) + 1);
|
|
22141
|
+
box.count += 1;
|
|
22142
|
+
total += 1;
|
|
22143
|
+
}
|
|
22144
|
+
const id = event.id;
|
|
22145
|
+
if (typeof id === "string" && id.length > 0) eventIds.add(id);
|
|
22146
|
+
onChange?.();
|
|
22147
|
+
},
|
|
22148
|
+
reset() {
|
|
22149
|
+
boxes.clear();
|
|
22150
|
+
eventIds.clear();
|
|
22151
|
+
total = 0;
|
|
22152
|
+
onChange?.();
|
|
22153
|
+
}
|
|
22154
|
+
};
|
|
22155
|
+
}
|
|
22156
|
+
function installPajaEventCounterReset(counter) {
|
|
22157
|
+
const button2 = document.getElementById(PAJA_EVENT_COUNTER_RESET_ID);
|
|
22158
|
+
const onClick = (event) => {
|
|
22159
|
+
event.stopPropagation();
|
|
22160
|
+
counter.reset();
|
|
22161
|
+
};
|
|
22162
|
+
button2?.addEventListener("click", onClick);
|
|
22163
|
+
return () => button2?.removeEventListener("click", onClick);
|
|
22164
|
+
}
|
|
22165
|
+
function renderPajaEventKindCounts(counter, inventory) {
|
|
22166
|
+
const container = document.getElementById("event-kind-counts");
|
|
22167
|
+
const total = document.getElementById("event-kind-total");
|
|
22168
|
+
const boxes = counter.snapshot(inventory);
|
|
22169
|
+
if (total) {
|
|
22170
|
+
total.textContent = boxes.length === 0 ? "" : `${counter.total}`;
|
|
22171
|
+
total.title = `${counter.total} relay receipt${counter.total === 1 ? "" : "s"} \xB7 ${counter.uniqueEvents} unique event${counter.uniqueEvents === 1 ? "" : "s"}`;
|
|
22172
|
+
}
|
|
22173
|
+
if (!container) return;
|
|
22174
|
+
if (boxes.length === 0) {
|
|
22175
|
+
const empty = document.createElement("div");
|
|
22176
|
+
empty.className = "event-empty";
|
|
22177
|
+
empty.textContent = "no relay events yet";
|
|
22178
|
+
container.replaceChildren(empty);
|
|
22179
|
+
return;
|
|
22180
|
+
}
|
|
22181
|
+
const busiest = Math.max(1, ...boxes.flatMap((box) => box.relays.map((relay) => relay.count)));
|
|
22182
|
+
container.replaceChildren(...boxes.map((box) => {
|
|
22183
|
+
const section = document.createElement("div");
|
|
22184
|
+
section.className = "event-box";
|
|
22185
|
+
section.dataset.relayBox = box.kind;
|
|
22186
|
+
section.dataset.relayReason = box.reason;
|
|
22187
|
+
const head = document.createElement("div");
|
|
22188
|
+
head.className = "event-box-head";
|
|
22189
|
+
const name = document.createElement("span");
|
|
22190
|
+
name.className = "event-box-name";
|
|
22191
|
+
name.textContent = box.label;
|
|
22192
|
+
const boxCount = document.createElement("span");
|
|
22193
|
+
boxCount.className = box.relays.length === 0 ? "event-box-note" : "event-box-count";
|
|
22194
|
+
boxCount.textContent = box.relays.length === 0 ? box.emptyNote ?? "0" : String(box.count);
|
|
22195
|
+
head.append(name, boxCount);
|
|
22196
|
+
section.append(head);
|
|
22197
|
+
for (const relay of box.relays) {
|
|
22198
|
+
const row = document.createElement("div");
|
|
22199
|
+
row.className = "event-relay";
|
|
22200
|
+
row.dataset.relayUrl = relay.relayUrl;
|
|
22201
|
+
row.dataset.relayCount = String(relay.count);
|
|
22202
|
+
row.dataset.relayReads = String(relay.readCount);
|
|
22203
|
+
if (relay.configured) row.dataset.relayConfigured = "true";
|
|
22204
|
+
const rowHead = document.createElement("div");
|
|
22205
|
+
rowHead.className = "event-relay-head";
|
|
22206
|
+
const url = document.createElement("span");
|
|
22207
|
+
url.className = "event-relay-url";
|
|
22208
|
+
url.textContent = relay.relayUrl;
|
|
22209
|
+
url.title = relay.relayUrl;
|
|
22210
|
+
const bar = document.createElement("span");
|
|
22211
|
+
bar.className = "event-bar";
|
|
22212
|
+
const fill = document.createElement("span");
|
|
22213
|
+
fill.className = "event-bar-fill";
|
|
22214
|
+
fill.style.width = `${Math.round(relay.count / busiest * 100)}%`;
|
|
22215
|
+
bar.append(fill);
|
|
22216
|
+
const relayCount = document.createElement("span");
|
|
22217
|
+
relayCount.className = "event-relay-count";
|
|
22218
|
+
relayCount.textContent = String(relay.count);
|
|
22219
|
+
rowHead.append(url, bar, relayCount);
|
|
22220
|
+
if (relay.count === 0) {
|
|
22221
|
+
const idle = document.createElement("span");
|
|
22222
|
+
idle.className = "event-relay-idle";
|
|
22223
|
+
idle.textContent = relay.readCount > 0 ? "silent" : "unused";
|
|
22224
|
+
idle.title = relay.readCount > 0 ? `Paja read from this relay ${relay.readCount} time${relay.readCount === 1 ? "" : "s"} and received no events` : "configured for this box and not used yet this session";
|
|
22225
|
+
rowHead.append(idle);
|
|
22226
|
+
}
|
|
22227
|
+
row.append(rowHead);
|
|
22228
|
+
if (relay.kinds.length > 0) {
|
|
22229
|
+
const kinds = document.createElement("div");
|
|
22230
|
+
kinds.className = "event-kinds";
|
|
22231
|
+
kinds.replaceChildren(...relay.kinds.map(({ kind, count }) => {
|
|
22232
|
+
const kindRow = document.createElement("div");
|
|
22233
|
+
kindRow.className = "event-row";
|
|
22234
|
+
kindRow.dataset.eventKind = String(kind);
|
|
22235
|
+
const kindCell = document.createElement("span");
|
|
22236
|
+
kindCell.className = "event-kind";
|
|
22237
|
+
kindCell.textContent = String(kind);
|
|
22238
|
+
const separator = document.createElement("span");
|
|
22239
|
+
separator.className = "event-separator";
|
|
22240
|
+
separator.textContent = "-";
|
|
22241
|
+
const countCell = document.createElement("span");
|
|
22242
|
+
countCell.className = "event-count";
|
|
22243
|
+
countCell.textContent = String(count);
|
|
22244
|
+
kindRow.append(kindCell, separator, countCell);
|
|
22245
|
+
return kindRow;
|
|
22246
|
+
}));
|
|
22247
|
+
row.append(kinds);
|
|
22248
|
+
}
|
|
22249
|
+
section.append(row);
|
|
22250
|
+
}
|
|
22251
|
+
return section;
|
|
22252
|
+
}));
|
|
22253
|
+
}
|
|
22254
|
+
|
|
21812
22255
|
// src/local-target.ts
|
|
21813
22256
|
var PAJA_LOCAL_SINGLE_FILE_HINT = "Paja opens self-contained single-file index.html only; relative scripts, styles, and images do not load.";
|
|
21814
22257
|
var MAX_DTAG_LENGTH = 128;
|
|
@@ -22003,6 +22446,12 @@ function escapeHtml(value) {
|
|
|
22003
22446
|
|
|
22004
22447
|
// src/browser-devtools.ts
|
|
22005
22448
|
var PAJA_LOG_LIMIT = 500;
|
|
22449
|
+
var FS_PICKER_METHODS = {
|
|
22450
|
+
"fs.pickFile.result": "showOpenFilePicker",
|
|
22451
|
+
"fs.pickFiles.result": "showOpenFilePicker",
|
|
22452
|
+
"fs.pickDirectory.result": "showDirectoryPicker",
|
|
22453
|
+
"fs.pickSaveFile.result": "showSaveFilePicker"
|
|
22454
|
+
};
|
|
22006
22455
|
var proxyToReal = /* @__PURE__ */ new WeakMap();
|
|
22007
22456
|
var realToProxy = /* @__PURE__ */ new WeakMap();
|
|
22008
22457
|
var proxyContexts = /* @__PURE__ */ new WeakMap();
|
|
@@ -22038,7 +22487,15 @@ function describeMessageDetail(raw) {
|
|
|
22038
22487
|
const value = raw;
|
|
22039
22488
|
for (const key of ["error", "message", "reason"]) {
|
|
22040
22489
|
const detail = value[key];
|
|
22041
|
-
if (typeof detail === "string" && detail.length > 0)
|
|
22490
|
+
if (typeof detail === "string" && detail.length > 0) {
|
|
22491
|
+
if (detail === "unsupported") {
|
|
22492
|
+
const picker = FS_PICKER_METHODS[raw.type];
|
|
22493
|
+
if (picker && !browserPickers()[picker]) {
|
|
22494
|
+
return `unsupported: this browser does not provide ${picker}. Workspace FS may still be available; ACL permission does not add browser APIs.`;
|
|
22495
|
+
}
|
|
22496
|
+
}
|
|
22497
|
+
return detail;
|
|
22498
|
+
}
|
|
22042
22499
|
}
|
|
22043
22500
|
return raw.type.endsWith(".error") ? compactMessageDetail(value) : "";
|
|
22044
22501
|
}
|
|
@@ -22137,8 +22594,10 @@ function installPajaOriginRegistryProxy(originRegistry2, stateRef) {
|
|
|
22137
22594
|
}
|
|
22138
22595
|
function renderPajaDevtools(state, options) {
|
|
22139
22596
|
renderInterfaceControls(state);
|
|
22597
|
+
renderFsSupport(state);
|
|
22140
22598
|
renderAclControls(state, options.bridge);
|
|
22141
22599
|
renderSignerStatus(state, options.devSignerPubkey);
|
|
22600
|
+
renderPajaEventKindCounts(state.relayEventCounts, state.relayInventory?.());
|
|
22142
22601
|
}
|
|
22143
22602
|
function renderPajaMessageLog(state) {
|
|
22144
22603
|
const container = document.getElementById("message-log");
|
|
@@ -22190,6 +22649,21 @@ function renderInterfaceControls(state) {
|
|
|
22190
22649
|
return button2;
|
|
22191
22650
|
}));
|
|
22192
22651
|
}
|
|
22652
|
+
function renderFsSupport(state) {
|
|
22653
|
+
const status = document.getElementById("paja-fs-support");
|
|
22654
|
+
if (!status) return;
|
|
22655
|
+
if (!domainEnabled(state.simulation, "fs")) {
|
|
22656
|
+
status.textContent = "FS disabled by host.";
|
|
22657
|
+
return;
|
|
22658
|
+
}
|
|
22659
|
+
if (!state.services?.includes("fs")) {
|
|
22660
|
+
status.textContent = "FS unavailable: browser workspace storage could not be opened.";
|
|
22661
|
+
return;
|
|
22662
|
+
}
|
|
22663
|
+
const pickers = browserPickers();
|
|
22664
|
+
const availability = (available) => available ? "available" : "unavailable";
|
|
22665
|
+
status.textContent = `FS: Workspace available. Native pickers: open ${availability(pickers.showOpenFilePicker)}, save ${availability(pickers.showSaveFilePicker)}, directory ${availability(pickers.showDirectoryPicker)}.`;
|
|
22666
|
+
}
|
|
22193
22667
|
function renderAclControls(state, bridge) {
|
|
22194
22668
|
const container = document.getElementById("acl-controls");
|
|
22195
22669
|
if (!container) return;
|
|
@@ -22207,7 +22681,7 @@ function renderAclControls(state, bridge) {
|
|
|
22207
22681
|
button2.dataset.aclCapability = capability;
|
|
22208
22682
|
button2.dataset.enabled = String(allowed2);
|
|
22209
22683
|
button2.textContent = capability;
|
|
22210
|
-
button2.title = `${capability} ${allowed2 ? "allowed" : "blocked"}`;
|
|
22684
|
+
button2.title = `${capability} permission ${allowed2 ? "allowed" : "blocked"}; browser support is separate`;
|
|
22211
22685
|
button2.addEventListener("click", () => state.setAclCapability(capability, !allowed2));
|
|
22212
22686
|
return button2;
|
|
22213
22687
|
}));
|
|
@@ -25715,10 +26189,12 @@ function snapshotPajaBrowserState(state, runtime) {
|
|
|
25715
26189
|
status: tab.status,
|
|
25716
26190
|
initSent: tab.windowId ? runtime.readyWindowIds.has(tab.windowId) : false
|
|
25717
26191
|
})),
|
|
25718
|
-
messageLog: [...state.messageLog]
|
|
26192
|
+
messageLog: [...state.messageLog],
|
|
26193
|
+
relayEventCounts: state.relayEventCounts.snapshot(state.relayInventory()),
|
|
26194
|
+
relayInventory: state.relayInventory()
|
|
25719
26195
|
};
|
|
25720
26196
|
}
|
|
25721
|
-
function createPajaBrowserState(context) {
|
|
26197
|
+
function createPajaBrowserState(context, relayEventCounts, relayInventory) {
|
|
25722
26198
|
const {
|
|
25723
26199
|
config,
|
|
25724
26200
|
bridge,
|
|
@@ -25744,6 +26220,8 @@ function createPajaBrowserState(context) {
|
|
|
25744
26220
|
status: "booting",
|
|
25745
26221
|
messageFilter: "",
|
|
25746
26222
|
messageLog: [],
|
|
26223
|
+
relayEventCounts,
|
|
26224
|
+
relayInventory,
|
|
25747
26225
|
reload() {
|
|
25748
26226
|
reloadPajaTarget(this, context);
|
|
25749
26227
|
},
|
|
@@ -25885,6 +26363,13 @@ async function installPajaHost() {
|
|
|
25885
26363
|
getIdentity: getWindowIdentity,
|
|
25886
26364
|
getInitialValues: () => ({ ...getSimulation().config.values })
|
|
25887
26365
|
});
|
|
26366
|
+
const relayEventCounts = createPajaRelayEventCounter(() => {
|
|
26367
|
+
if (stateRef) renderPajaEventKindCounts(stateRef.relayEventCounts, stateRef.relayInventory());
|
|
26368
|
+
});
|
|
26369
|
+
const disposeEventCounterReset = installPajaEventCounterReset(relayEventCounts);
|
|
26370
|
+
const relayInventory = () => ({
|
|
26371
|
+
fallback: adapter.relayConfig.getRelayConfig().outbox
|
|
26372
|
+
});
|
|
25888
26373
|
const adapter = createPajaAdapter(config, getSimulation, (theme) => {
|
|
25889
26374
|
runtime.themeService = theme;
|
|
25890
26375
|
}, themeBroadcast.onBroadcast, confirmationController.confirm, signerController, getWindowIdentity, () => stateRef?.reload(), {
|
|
@@ -25911,6 +26396,13 @@ async function installPajaHost() {
|
|
|
25911
26396
|
return candidates.some((candidate) => candidate.id === id) ? id : void 0;
|
|
25912
26397
|
}
|
|
25913
26398
|
}, confirmationController.activation, notifyController?.serviceOptions, configController?.serviceOptions, resourceSettings.getServers);
|
|
26399
|
+
const relayBackend = adapter.relayPool.getRelayPool();
|
|
26400
|
+
relayBackend?.setRelayEventObserver((sighting) => {
|
|
26401
|
+
relayEventCounts.recordEvent(sighting.reason, sighting.event, sighting.sightedOn, sighting.origin);
|
|
26402
|
+
});
|
|
26403
|
+
relayBackend?.setRelayRequestObserver((request) => {
|
|
26404
|
+
relayEventCounts.recordRead(request.reason, request.relayUrls, request.origin);
|
|
26405
|
+
});
|
|
25914
26406
|
await adapter.ready;
|
|
25915
26407
|
const bridge = createShellBridge(adapter);
|
|
25916
26408
|
const stopIdentityChanges = signerController.subscribe(() => {
|
|
@@ -25937,7 +26429,7 @@ async function installPajaHost() {
|
|
|
25937
26429
|
setStatus: (state2, status) => setStatus(state2, status)
|
|
25938
26430
|
};
|
|
25939
26431
|
contextRef = context;
|
|
25940
|
-
const state = createPajaBrowserState(context);
|
|
26432
|
+
const state = createPajaBrowserState(context, relayEventCounts, relayInventory);
|
|
25941
26433
|
stateRef = state;
|
|
25942
26434
|
const stopIntentCatalogChanges = subscribePajaIntentCatalogChanges(state, context);
|
|
25943
26435
|
window.addEventListener("pagehide", stopIntentCatalogChanges, { once: true });
|
|
@@ -25959,6 +26451,7 @@ async function installPajaHost() {
|
|
|
25959
26451
|
window.addEventListener("pagehide", () => notifyController?.dispose(), { once: true });
|
|
25960
26452
|
window.addEventListener("pagehide", () => configController?.dispose(), { once: true });
|
|
25961
26453
|
window.addEventListener("pagehide", disposeConsolePanel, { once: true });
|
|
26454
|
+
window.addEventListener("pagehide", disposeEventCounterReset, { once: true });
|
|
25962
26455
|
window.addEventListener("pagehide", resourceSettings.dispose, { once: true });
|
|
25963
26456
|
window.__KEHTO_PAJA__ = state;
|
|
25964
26457
|
window.addEventListener("message", (event) => {
|