@kehto/paja 0.36.0 → 0.37.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.
@@ -8,7 +8,7 @@ function text(value) {
8
8
  if (typeof value !== "string" || !value.trim() || value.length > 256) throw new Error("Expected nonempty text (at most 256 characters).");
9
9
  return value;
10
10
  }
11
- function relayUrls(value) {
11
+ function normalizePajaCvmRelays(value) {
12
12
  if (!Array.isArray(value) || !value.length || value.length > 16) throw new Error("Configure 1\u201316 relay URLs.");
13
13
  return [...new Set(value.map((item) => {
14
14
  if (typeof item !== "string") throw new Error("Invalid relay URL.");
@@ -17,7 +17,7 @@ function relayUrls(value) {
17
17
  return url.origin;
18
18
  }))];
19
19
  }
20
- function family(value) {
20
+ function normalizePajaCvmFamily(value) {
21
21
  if (!record(value) || !record(value.server) || typeof value.server.pubkey !== "string" || !HEX.test(value.server.pubkey)) throw new Error("Each registry family needs a provider public key.");
22
22
  if (!Array.isArray(value.tools) || !value.tools.length || value.tools.length > 64) throw new Error("Each family needs 1\u201364 tool name/hash pins.");
23
23
  const tools = value.tools.map((tool) => {
@@ -27,7 +27,7 @@ function family(value) {
27
27
  if (new Set(tools.map((tool) => tool.name)).size !== tools.length) throw new Error("Family tool names must be unique.");
28
28
  return {
29
29
  family: text(value.family),
30
- server: { pubkey: value.server.pubkey, relays: relayUrls(value.server.relays) },
30
+ server: { pubkey: value.server.pubkey, relays: normalizePajaCvmRelays(value.server.relays) },
31
31
  tools,
32
32
  ...value.description === void 0 ? {} : { description: text(value.description) },
33
33
  ...value.categories === void 0 ? {} : { categories: Array.isArray(value.categories) ? value.categories.map(text) : (() => {
@@ -49,8 +49,8 @@ function normalizePajaMultiplayer(value) {
49
49
  if (value.iceServers !== void 0 && (!Array.isArray(value.iceServers) || value.iceServers.length > 8)) throw new Error("Configure at most 8 ICE servers.");
50
50
  return {
51
51
  profile: value.profile,
52
- relays: relayUrls(value.relays),
53
- registry: value.registry.map(family),
52
+ relays: normalizePajaCvmRelays(value.relays),
53
+ registry: value.registry.map(normalizePajaCvmFamily),
54
54
  ...Array.isArray(value.iceServers) ? { iceServers: value.iceServers.map(iceServer) } : {},
55
55
  ...value.developmentNamespace === void 0 ? {} : { developmentNamespace: text(value.developmentNamespace) }
56
56
  };
@@ -168,11 +168,11 @@ function normalizePajaSimulation(raw) {
168
168
  if (identityMode === "fixed" && !isHexPubkey(pubkey)) {
169
169
  throw new PajaSimulationError('Invalid simulation: identity.pubkey must be a 64-character hex string when identity.mode is "fixed".');
170
170
  }
171
- const relayUrls2 = raw?.relay?.urls ?? DEFAULT_RELAY_URLS;
172
- if (relayMode !== "disabled" && relayUrls2.length === 0) {
171
+ const relayUrls = raw?.relay?.urls ?? DEFAULT_RELAY_URLS;
172
+ if (relayMode !== "disabled" && relayUrls.length === 0) {
173
173
  throw new PajaSimulationError("Invalid simulation: relay.urls must contain at least one URL when relay.mode is enabled.");
174
174
  }
175
- for (const url of relayUrls2) {
175
+ for (const url of relayUrls) {
176
176
  if (typeof url !== "string" || url.trim().length === 0) {
177
177
  throw new PajaSimulationError("Invalid simulation: relay.urls entries must be non-empty strings.");
178
178
  }
@@ -213,7 +213,7 @@ function normalizePajaSimulation(raw) {
213
213
  },
214
214
  relay: {
215
215
  mode: relayMode,
216
- urls: relayUrls2.map((url) => url.trim()),
216
+ urls: relayUrls.map((url) => url.trim()),
217
217
  fixtures: raw?.relay?.fixtures ?? []
218
218
  },
219
219
  storage: {
@@ -663,6 +663,15 @@ function renderPajaHtml(config) {
663
663
  .resource-servers label { white-space: normal; }
664
664
  .resource-servers textarea { width: 100%; min-width: 0; padding: 6px; resize: vertical; }
665
665
  .resource-servers small, .resource-servers [role="status"] { color: var(--muted); overflow-wrap: anywhere; }
666
+ #paja-cvm-form { padding-bottom: 16px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
667
+ #paja-cvm-form > label { position: static; width: auto; height: auto; overflow: visible; clip-path: none; }
668
+ #paja-cvm-form input[type="text"], #paja-cvm-form select { width: 100%; min-width: 0; padding: 6px; }
669
+ #paja-cvm-tools { min-width: 0; max-height: 180px; overflow: auto; }
670
+ #paja-cvm-tools label { display: flex; overflow-wrap: anywhere; }
671
+ #paja-cvm-tools input { flex: 0 0 16px; width: 16px; min-height: 16px; }
672
+ #paja-cvm-json[readonly] { opacity: 0.8; }
673
+ #paja-cvm-saved > div { display: flex; gap: 6px; margin-bottom: 6px; }
674
+ #paja-cvm-saved button:first-child { flex: 1; min-width: 0; overflow-wrap: anywhere; }
666
675
  .switch-grid, .acl-grid { display: flex; flex-wrap: wrap; gap: 6px; }
667
676
  .hint { margin: 0; color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
668
677
  .toggle { height: 24px; padding: 0 8px; color: var(--muted); }
@@ -854,6 +863,26 @@ function renderPajaHtml(config) {
854
863
  </div></details>
855
864
  <details class="section" id="paja-section-multiplayer" data-paja-section="multiplayer">
856
865
  <summary class="section-title">Multiplayer providers<span class="section-chevron" aria-hidden="true">\u203A</span></summary><div class="section-body">
866
+ <form class="resource-servers" id="paja-cvm-form">
867
+ <label for="paja-cvm-discovery">Discover CVM tools</label>
868
+ <input id="paja-cvm-discovery" type="text" placeholder="nevent, schema hash, or https://provider.example" spellcheck="false" aria-describedby="paja-cvm-help">
869
+ <button type="button" id="paja-cvm-find">Discover</button>
870
+ <small id="paja-cvm-help">Uses your host relays, event relay hints, or the website's .well-known/napplet.json. Family labels and tool membership are local choices.</small>
871
+ <label for="paja-cvm-results">Providers found</label>
872
+ <select id="paja-cvm-results" disabled></select>
873
+ <label for="paja-cvm-label">Local family label</label>
874
+ <input id="paja-cvm-label" type="text" maxlength="256" disabled>
875
+ <fieldset id="paja-cvm-tools" hidden></fieldset>
876
+ <label for="paja-cvm-json">Family configuration (JSON)</label>
877
+ <small id="paja-cvm-origin">Source: manual JSON</small>
878
+ <textarea id="paja-cvm-json" rows="8" spellcheck="false" aria-describedby="paja-cvm-origin paja-cvm-status"></textarea>
879
+ <button type="button" id="paja-cvm-manual">Edit JSON manually</button>
880
+ <button type="button" id="paja-cvm-new">New manual family</button>
881
+ <button type="submit" id="paja-cvm-save">Save family and reload</button>
882
+ <div id="paja-cvm-status" role="status" aria-live="polite"></div>
883
+ <span>Saved CVM families</span>
884
+ <div id="paja-cvm-saved"></div>
885
+ </form>
857
886
  <form class="resource-servers" id="paja-multiplayer-form">
858
887
  <label for="paja-multiplayer-input">Provider configuration (JSON)</label>
859
888
  <textarea id="paja-multiplayer-input" rows="8" spellcheck="false" aria-describedby="paja-multiplayer-help paja-multiplayer-status"></textarea>
@@ -2084,8 +2113,8 @@ async function fetchPinnedResource(input, signal) {
2084
2113
  const timer = setTimeout(() => controller.abort(new Error("Resource request timed out")), RESOURCE_TIMEOUT_MS);
2085
2114
  try {
2086
2115
  controller.signal.throwIfAborted();
2087
- const family2 = isIP(hostname);
2088
- const answers = family2 ? [{ address: hostname, family: family2 }] : await abortable(dnsLookup(hostname, { all: true, verbatim: true }), controller.signal);
2116
+ const family = isIP(hostname);
2117
+ const answers = family ? [{ address: hostname, family }] : await abortable(dnsLookup(hostname, { all: true, verbatim: true }), controller.signal);
2089
2118
  controller.signal.throwIfAborted();
2090
2119
  const answer = answers.find((candidate) => isPublicResourceAddress(candidate.address));
2091
2120
  if (!answer) throw new Error("Resource destination resolved to a blocked address");
@@ -2103,7 +2132,7 @@ async function fetchPinnedResource(input, signal) {
2103
2132
  method: "GET",
2104
2133
  agent: false,
2105
2134
  headers: { accept: "*/*", host: url.host },
2106
- ...family2 ? {} : { servername: hostname },
2135
+ ...family ? {} : { servername: hostname },
2107
2136
  lookup(_hostname, options, callback) {
2108
2137
  if (options.all) callback(null, [{ address: answer.address, family: answer.family }]);
2109
2138
  else callback(null, answer.address, answer.family);
@@ -2158,12 +2187,12 @@ function abortable(pending, signal) {
2158
2187
  });
2159
2188
  }
2160
2189
  function isPublicResourceAddress(address) {
2161
- const family2 = isIP(address);
2162
- if (family2 === 4) {
2190
+ const family = isIP(address);
2191
+ if (family === 4) {
2163
2192
  const [a, b, c] = address.split(".").map(Number);
2164
2193
  return a !== 0 && a !== 10 && a !== 127 && a < 224 && !(a === 100 && b >= 64 && b <= 127) && !(a === 169 && b === 254) && !(a === 172 && b >= 16 && b <= 31) && !(a === 192 && (b === 168 || b === 0 && (c === 0 || c === 2) || b === 88 && c === 99)) && !(a === 198 && (b === 18 || b === 19 || b === 51 && c === 100)) && !(a === 203 && b === 0 && c === 113);
2165
2194
  }
2166
- if (family2 !== 6) return false;
2195
+ if (family !== 6) return false;
2167
2196
  let canonical;
2168
2197
  try {
2169
2198
  canonical = new URL(`http://[${address}]/`).hostname.slice(1, -1);
@@ -2969,4 +2998,4 @@ export {
2969
2998
  validatePajaLlmVaultPassword,
2970
2999
  createPajaLlmVault
2971
3000
  };
2972
- //# sourceMappingURL=chunk-DK5RJN5P.js.map
3001
+ //# sourceMappingURL=chunk-F3KNRWX7.js.map