@kehto/paja 0.28.0 → 0.29.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 +21 -0
- package/dist/browser-host.js +117 -5
- package/dist/browser-host.js.map +1 -1
- package/dist/{chunk-2M7FG76K.js → chunk-EROJQR3U.js} +71 -6
- package/dist/chunk-EROJQR3U.js.map +1 -0
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +55 -1
- package/dist/index.js +3 -1
- package/package.json +2 -2
- package/dist/chunk-2M7FG76K.js.map +0 -1
|
@@ -488,6 +488,7 @@ var PAJA_EVENT_COUNTER_RESET_LABEL = "reset";
|
|
|
488
488
|
var PAJA_EVENT_COUNTER_RESET_TITLE = "reset counter";
|
|
489
489
|
|
|
490
490
|
// src/host-page.ts
|
|
491
|
+
import { renderNappletFramePolicyMeta } from "@kehto/shell";
|
|
491
492
|
function renderPajaHtml(config) {
|
|
492
493
|
const configJson = escapeJsonForHtml(JSON.stringify(config));
|
|
493
494
|
const targetLabel = escapeAttribute(getTargetLabel(config));
|
|
@@ -496,6 +497,7 @@ function renderPajaHtml(config) {
|
|
|
496
497
|
<head>
|
|
497
498
|
<meta charset="utf-8">
|
|
498
499
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
500
|
+
${renderNappletFramePolicyMeta()}
|
|
499
501
|
<title>@kehto/paja</title>
|
|
500
502
|
<style>
|
|
501
503
|
:root {
|
|
@@ -1018,6 +1020,16 @@ function isPublicHostname(value) {
|
|
|
1018
1020
|
// src/runtime-resolver.ts
|
|
1019
1021
|
var PAJA_NAPPLET_MANIFEST_KIND = NAPPLET_KIND_NAMED;
|
|
1020
1022
|
var PAJA_NAPPLET_MANIFEST_KINDS = NAPPLET_KINDS;
|
|
1023
|
+
var PajaRelayUnreachableError = class extends Error {
|
|
1024
|
+
constructor(message, connections) {
|
|
1025
|
+
super(message);
|
|
1026
|
+
this.connections = connections;
|
|
1027
|
+
this.name = "PajaRelayUnreachableError";
|
|
1028
|
+
}
|
|
1029
|
+
connections;
|
|
1030
|
+
/** Stable discriminator for hosts that cannot rely on `instanceof` across bundles. */
|
|
1031
|
+
code = "relay-unreachable";
|
|
1032
|
+
};
|
|
1021
1033
|
function decodePajaPointer(value) {
|
|
1022
1034
|
const trimmed = value.trim();
|
|
1023
1035
|
const decoded = decode(trimmed);
|
|
@@ -1102,9 +1114,17 @@ async function resolvePointerEvent(pointer, pool, relays, maxWaitMs) {
|
|
|
1102
1114
|
const result = await queryPointerRelays(pool, relays, filter, maxWaitMs);
|
|
1103
1115
|
const event = result.events.filter((candidate) => matchesPointer(pointer, candidate)).sort((a, b) => b.created_at - a.created_at || a.id.localeCompare(b.id))[0];
|
|
1104
1116
|
if (!event) {
|
|
1117
|
+
const connections = result.connections;
|
|
1118
|
+
if (connections && connections.total > 0 && connections.connected.length === 0) {
|
|
1119
|
+
throw new PajaRelayUnreachableError(
|
|
1120
|
+
describeRelayUnreachable(pointer.type, connections, maxWaitMs),
|
|
1121
|
+
connections
|
|
1122
|
+
);
|
|
1123
|
+
}
|
|
1105
1124
|
if (result.timedOut) {
|
|
1125
|
+
const connectedNote = connections ? ` (${connections.connected.length} of ${connections.total} relays connected)` : "";
|
|
1106
1126
|
throw new Error(
|
|
1107
|
-
`Relay resolution timed out after ${maxWaitMs}ms for ${pointer.type} pointer across ${relays.length} relays before complete EOSE.`
|
|
1127
|
+
`Relay resolution timed out after ${maxWaitMs}ms for ${pointer.type} pointer across ${relays.length} relays before complete EOSE${connectedNote}.`
|
|
1108
1128
|
);
|
|
1109
1129
|
}
|
|
1110
1130
|
const failures = relayFailureReasons(result.reasons);
|
|
@@ -1121,11 +1141,55 @@ async function resolvePointerEvent(pointer, pool, relays, maxWaitMs) {
|
|
|
1121
1141
|
}
|
|
1122
1142
|
return event;
|
|
1123
1143
|
}
|
|
1124
|
-
function queryPointerRelays(pool, relays, filter, maxWaitMs) {
|
|
1125
|
-
|
|
1126
|
-
|
|
1144
|
+
async function queryPointerRelays(pool, relays, filter, maxWaitMs) {
|
|
1145
|
+
const tracker = trackRelayConnections(pool, relays, maxWaitMs);
|
|
1146
|
+
const result = pool.subscribeManyEose ? await queryPointerRelaySubscription(pool, relays, filter, maxWaitMs) : await queryPointerRelaySync(pool, relays, filter, maxWaitMs);
|
|
1147
|
+
return tracker ? { ...result, connections: tracker.snapshot() } : result;
|
|
1148
|
+
}
|
|
1149
|
+
function trackRelayConnections(pool, relays, maxWaitMs) {
|
|
1150
|
+
const ensureRelay = pool.ensureRelay?.bind(pool);
|
|
1151
|
+
if (!ensureRelay) return null;
|
|
1152
|
+
const urls = [...new Set(relays)];
|
|
1153
|
+
const connected = [];
|
|
1154
|
+
const failed = [];
|
|
1155
|
+
const pending = new Set(urls);
|
|
1156
|
+
for (const url of urls) {
|
|
1157
|
+
const settle = (outcome, reason) => {
|
|
1158
|
+
if (!pending.delete(url)) return;
|
|
1159
|
+
if (outcome === "connected") connected.push(url);
|
|
1160
|
+
else failed.push({ url, reason: reason ?? "connection failed" });
|
|
1161
|
+
};
|
|
1162
|
+
try {
|
|
1163
|
+
ensureRelay(url, { connectionTimeout: maxWaitMs }).then(
|
|
1164
|
+
() => settle("connected"),
|
|
1165
|
+
(error) => settle("failed", describeRelayFailure(error))
|
|
1166
|
+
);
|
|
1167
|
+
} catch (error) {
|
|
1168
|
+
settle("failed", describeRelayFailure(error));
|
|
1169
|
+
}
|
|
1127
1170
|
}
|
|
1128
|
-
return
|
|
1171
|
+
return {
|
|
1172
|
+
snapshot: () => ({
|
|
1173
|
+
total: urls.length,
|
|
1174
|
+
connected: [...connected],
|
|
1175
|
+
failed: [...failed],
|
|
1176
|
+
pending: [...pending]
|
|
1177
|
+
})
|
|
1178
|
+
};
|
|
1179
|
+
}
|
|
1180
|
+
function describeRelayFailure(error) {
|
|
1181
|
+
const text = error instanceof Error ? error.message : String(error ?? "");
|
|
1182
|
+
const trimmed = text.trim();
|
|
1183
|
+
return (trimmed.length > 0 ? trimmed : "connection failed").slice(0, 160);
|
|
1184
|
+
}
|
|
1185
|
+
function describeRelayUnreachable(pointerType, connections, maxWaitMs) {
|
|
1186
|
+
const reasons = relayFailureReasons(connections.failed.map((entry) => entry.reason));
|
|
1187
|
+
const parts = [
|
|
1188
|
+
`No relay connection could be opened for the ${pointerType} pointer: 0 of ${connections.total} relays connected within ${maxWaitMs}ms (${connections.failed.length} failed, ${connections.pending.length} still connecting).`,
|
|
1189
|
+
"The browser is offline, the relays are blocked, or the browser reached its WebSocket connection limit (for example many open tabs each holding relay connections) \u2014 close some tabs and retry."
|
|
1190
|
+
];
|
|
1191
|
+
if (reasons.length > 0) parts.push(`Relay errors: ${reasons.join("; ")}.`);
|
|
1192
|
+
return parts.join(" ");
|
|
1129
1193
|
}
|
|
1130
1194
|
function queryPointerRelaySubscription(pool, relays, filter, maxWaitMs) {
|
|
1131
1195
|
return new Promise((resolve2) => {
|
|
@@ -2475,6 +2539,7 @@ export {
|
|
|
2475
2539
|
renderPajaHtml,
|
|
2476
2540
|
PAJA_NAPPLET_MANIFEST_KIND,
|
|
2477
2541
|
PAJA_NAPPLET_MANIFEST_KINDS,
|
|
2542
|
+
PajaRelayUnreachableError,
|
|
2478
2543
|
decodePajaPointer,
|
|
2479
2544
|
resolvePajaPointer,
|
|
2480
2545
|
injectPajaRuntimeCsp,
|
|
@@ -2513,4 +2578,4 @@ export {
|
|
|
2513
2578
|
validatePajaLlmVaultPassword,
|
|
2514
2579
|
createPajaLlmVault
|
|
2515
2580
|
};
|
|
2516
|
-
//# sourceMappingURL=chunk-
|
|
2581
|
+
//# sourceMappingURL=chunk-EROJQR3U.js.map
|