@kehto/paja 0.28.1 → 0.30.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.
@@ -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 {
@@ -596,6 +598,11 @@ function renderPajaHtml(config) {
596
598
  .llm-connections { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; }
597
599
  .llm-connection { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 6px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 4px; background: #0b0d0b; font-size: 11px; }
598
600
  .llm-connection-label { min-width: 0; overflow-wrap: anywhere; color: var(--text); }
601
+ .llm-form label[hidden] { display: none; }
602
+ .llm-model-status:empty { display: none; }
603
+ .llm-model-status { margin: 0; min-height: 0; }
604
+ .llm-model-status[data-state="ready"] { color: #9fd08a; }
605
+ .llm-model-status[data-state="error"] { color: #e6a5a5; }
599
606
  .llm-select-dialog select, .llm-vault-dialog input { width: 100%; min-width: 0; padding: 4px 8px; }
600
607
  .llm-vault-dialog .config-error:empty { display: none; }
601
608
  .signer { color: var(--muted); word-break: break-all; font-size: 12px; }
@@ -769,7 +776,9 @@ function renderPajaHtml(config) {
769
776
  <label>Provider<select id="paja-llm-preset" aria-label="Provider preset"></select></label>
770
777
  <label>Name<input id="paja-llm-name" type="text" required maxlength="64" spellcheck="false"></label>
771
778
  <label>API base URL<input id="paja-llm-base-url" type="url" required spellcheck="false" placeholder="API root; presets fill this in"></label>
772
- <label>Model<input id="paja-llm-model" type="text" required maxlength="200" spellcheck="false" list="paja-llm-model-examples"><datalist id="paja-llm-model-examples"></datalist></label>
779
+ <label id="paja-llm-model-field">Model<input id="paja-llm-model" type="text" required maxlength="200" spellcheck="false" list="paja-llm-model-examples"><datalist id="paja-llm-model-examples"></datalist></label>
780
+ <label id="paja-llm-model-select-field" hidden>Model<select id="paja-llm-model-select" required aria-describedby="paja-llm-model-status"></select></label>
781
+ <p class="hint llm-model-status" id="paja-llm-model-status" role="status" aria-live="polite"></p>
773
782
  <label>API key<input id="paja-llm-credential" type="password" autocomplete="off" spellcheck="false"></label>
774
783
  <label class="llm-check"><input id="paja-llm-remember" type="checkbox"><span>Remember the key, encrypted with a vault password</span></label>
775
784
  <label class="llm-check"><input id="paja-llm-images" type="checkbox"><span>Accepts image input</span></label>
@@ -1018,6 +1027,16 @@ function isPublicHostname(value) {
1018
1027
  // src/runtime-resolver.ts
1019
1028
  var PAJA_NAPPLET_MANIFEST_KIND = NAPPLET_KIND_NAMED;
1020
1029
  var PAJA_NAPPLET_MANIFEST_KINDS = NAPPLET_KINDS;
1030
+ var PajaRelayUnreachableError = class extends Error {
1031
+ constructor(message, connections) {
1032
+ super(message);
1033
+ this.connections = connections;
1034
+ this.name = "PajaRelayUnreachableError";
1035
+ }
1036
+ connections;
1037
+ /** Stable discriminator for hosts that cannot rely on `instanceof` across bundles. */
1038
+ code = "relay-unreachable";
1039
+ };
1021
1040
  function decodePajaPointer(value) {
1022
1041
  const trimmed = value.trim();
1023
1042
  const decoded = decode(trimmed);
@@ -1102,9 +1121,17 @@ async function resolvePointerEvent(pointer, pool, relays, maxWaitMs) {
1102
1121
  const result = await queryPointerRelays(pool, relays, filter, maxWaitMs);
1103
1122
  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
1123
  if (!event) {
1124
+ const connections = result.connections;
1125
+ if (connections && connections.total > 0 && connections.connected.length === 0) {
1126
+ throw new PajaRelayUnreachableError(
1127
+ describeRelayUnreachable(pointer.type, connections, maxWaitMs),
1128
+ connections
1129
+ );
1130
+ }
1105
1131
  if (result.timedOut) {
1132
+ const connectedNote = connections ? ` (${connections.connected.length} of ${connections.total} relays connected)` : "";
1106
1133
  throw new Error(
1107
- `Relay resolution timed out after ${maxWaitMs}ms for ${pointer.type} pointer across ${relays.length} relays before complete EOSE.`
1134
+ `Relay resolution timed out after ${maxWaitMs}ms for ${pointer.type} pointer across ${relays.length} relays before complete EOSE${connectedNote}.`
1108
1135
  );
1109
1136
  }
1110
1137
  const failures = relayFailureReasons(result.reasons);
@@ -1121,11 +1148,55 @@ async function resolvePointerEvent(pointer, pool, relays, maxWaitMs) {
1121
1148
  }
1122
1149
  return event;
1123
1150
  }
1124
- function queryPointerRelays(pool, relays, filter, maxWaitMs) {
1125
- if (pool.subscribeManyEose) {
1126
- return queryPointerRelaySubscription(pool, relays, filter, maxWaitMs);
1151
+ async function queryPointerRelays(pool, relays, filter, maxWaitMs) {
1152
+ const tracker = trackRelayConnections(pool, relays, maxWaitMs);
1153
+ const result = pool.subscribeManyEose ? await queryPointerRelaySubscription(pool, relays, filter, maxWaitMs) : await queryPointerRelaySync(pool, relays, filter, maxWaitMs);
1154
+ return tracker ? { ...result, connections: tracker.snapshot() } : result;
1155
+ }
1156
+ function trackRelayConnections(pool, relays, maxWaitMs) {
1157
+ const ensureRelay = pool.ensureRelay?.bind(pool);
1158
+ if (!ensureRelay) return null;
1159
+ const urls = [...new Set(relays)];
1160
+ const connected = [];
1161
+ const failed = [];
1162
+ const pending = new Set(urls);
1163
+ for (const url of urls) {
1164
+ const settle = (outcome, reason) => {
1165
+ if (!pending.delete(url)) return;
1166
+ if (outcome === "connected") connected.push(url);
1167
+ else failed.push({ url, reason: reason ?? "connection failed" });
1168
+ };
1169
+ try {
1170
+ ensureRelay(url, { connectionTimeout: maxWaitMs }).then(
1171
+ () => settle("connected"),
1172
+ (error) => settle("failed", describeRelayFailure(error))
1173
+ );
1174
+ } catch (error) {
1175
+ settle("failed", describeRelayFailure(error));
1176
+ }
1127
1177
  }
1128
- return queryPointerRelaySync(pool, relays, filter, maxWaitMs);
1178
+ return {
1179
+ snapshot: () => ({
1180
+ total: urls.length,
1181
+ connected: [...connected],
1182
+ failed: [...failed],
1183
+ pending: [...pending]
1184
+ })
1185
+ };
1186
+ }
1187
+ function describeRelayFailure(error) {
1188
+ const text = error instanceof Error ? error.message : String(error ?? "");
1189
+ const trimmed = text.trim();
1190
+ return (trimmed.length > 0 ? trimmed : "connection failed").slice(0, 160);
1191
+ }
1192
+ function describeRelayUnreachable(pointerType, connections, maxWaitMs) {
1193
+ const reasons = relayFailureReasons(connections.failed.map((entry) => entry.reason));
1194
+ const parts = [
1195
+ `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).`,
1196
+ "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."
1197
+ ];
1198
+ if (reasons.length > 0) parts.push(`Relay errors: ${reasons.join("; ")}.`);
1199
+ return parts.join(" ");
1129
1200
  }
1130
1201
  function queryPointerRelaySubscription(pool, relays, filter, maxWaitMs) {
1131
1202
  return new Promise((resolve2) => {
@@ -2475,6 +2546,7 @@ export {
2475
2546
  renderPajaHtml,
2476
2547
  PAJA_NAPPLET_MANIFEST_KIND,
2477
2548
  PAJA_NAPPLET_MANIFEST_KINDS,
2549
+ PajaRelayUnreachableError,
2478
2550
  decodePajaPointer,
2479
2551
  resolvePajaPointer,
2480
2552
  injectPajaRuntimeCsp,
@@ -2513,4 +2585,4 @@ export {
2513
2585
  validatePajaLlmVaultPassword,
2514
2586
  createPajaLlmVault
2515
2587
  };
2516
- //# sourceMappingURL=chunk-2M7FG76K.js.map
2588
+ //# sourceMappingURL=chunk-4GUFJFK7.js.map