@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.
- package/README.md +8 -0
- package/dist/browser-host.js +744 -359
- package/dist/browser-host.js.map +1 -1
- package/dist/{chunk-DK5RJN5P.js → chunk-F3KNRWX7.js} +45 -16
- package/dist/chunk-F3KNRWX7.js.map +1 -0
- package/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +3 -3
- package/dist/chunk-DK5RJN5P.js.map +0 -1
package/dist/browser-host.js
CHANGED
|
@@ -2605,11 +2605,11 @@ function invalid(message3) {
|
|
|
2605
2605
|
throw new NappletResolutionError("invalid-manifest", message3);
|
|
2606
2606
|
}
|
|
2607
2607
|
function single(tags, name) {
|
|
2608
|
-
const
|
|
2609
|
-
if (
|
|
2608
|
+
const matches3 = tags.filter((tag) => tag[0] === name);
|
|
2609
|
+
if (matches3.length > 1 || matches3.some((tag) => tag.length !== 2 || !tag[1])) {
|
|
2610
2610
|
invalid(`manifest ${name} tag must have one value and occur at most once`);
|
|
2611
2611
|
}
|
|
2612
|
-
return
|
|
2612
|
+
return matches3[0]?.[1];
|
|
2613
2613
|
}
|
|
2614
2614
|
function declarations(tags, name, pattern) {
|
|
2615
2615
|
return [...new Set(tags.filter((tag) => tag[0] === name).map((tag) => {
|
|
@@ -2949,7 +2949,7 @@ var CacheStorageNappletArtifactCache = class {
|
|
|
2949
2949
|
};
|
|
2950
2950
|
}
|
|
2951
2951
|
const key = aggregateKey(input.manifest.dTag, input.manifest.aggregateHash);
|
|
2952
|
-
const
|
|
2952
|
+
const record6 = {
|
|
2953
2953
|
schemaVersion: SCHEMA_VERSION,
|
|
2954
2954
|
dTag: input.manifest.dTag,
|
|
2955
2955
|
aggregateHash: input.manifest.aggregateHash,
|
|
@@ -2966,7 +2966,7 @@ var CacheStorageNappletArtifactCache = class {
|
|
|
2966
2966
|
blobHashes,
|
|
2967
2967
|
writtenAt: now2
|
|
2968
2968
|
};
|
|
2969
|
-
const aggregateBytes = new TextEncoder().encode(JSON.stringify(
|
|
2969
|
+
const aggregateBytes = new TextEncoder().encode(JSON.stringify(record6));
|
|
2970
2970
|
await cache2.put(this.aggregateUrl(key), new Response(responseBody(aggregateBytes), {
|
|
2971
2971
|
headers: { "content-type": "application/json" }
|
|
2972
2972
|
}));
|
|
@@ -5593,8 +5593,8 @@ function handleRelaySubscribe(context, windowId, msg, m) {
|
|
|
5593
5593
|
const subKey = `${windowId}:${subId}`;
|
|
5594
5594
|
const isShellKind = isShellKindQuery(filters);
|
|
5595
5595
|
const pool = hooks.relayPool;
|
|
5596
|
-
const
|
|
5597
|
-
const plan = Object.freeze({ operation: "subscribe", relayUrls: Object.freeze([...new Set(
|
|
5596
|
+
const relayUrls2 = isShellKind ? [] : typeof m.relay === "string" && m.relay.length > 0 ? [m.relay] : pool?.selectRelayTier(filters) ?? [];
|
|
5597
|
+
const plan = Object.freeze({ operation: "subscribe", relayUrls: Object.freeze([...new Set(relayUrls2)]), localOnly: isShellKind });
|
|
5598
5598
|
if (!isShellKind && !pool?.subscribeToRelays) {
|
|
5599
5599
|
if (pool && !legacyRelayAdapterWarnings.has(pool)) {
|
|
5600
5600
|
legacyRelayAdapterWarnings.add(pool);
|
|
@@ -5631,7 +5631,7 @@ function handleRelaySubscribe(context, windowId, msg, m) {
|
|
|
5631
5631
|
{ type: "relay.closed", subId, reason: "relay authorization unavailable or denied" }
|
|
5632
5632
|
));
|
|
5633
5633
|
}
|
|
5634
|
-
function deliverFromRuntimeBackends(context, subId, subKey, filters, isShellKind, deliver, send, isActive,
|
|
5634
|
+
function deliverFromRuntimeBackends(context, subId, subKey, filters, isShellKind, deliver, send, isActive, relayUrls2) {
|
|
5635
5635
|
const { hooks } = context;
|
|
5636
5636
|
const cache2 = hooks.cache;
|
|
5637
5637
|
if (cache2?.isAvailable() && !isShellKind) {
|
|
@@ -5653,7 +5653,7 @@ function deliverFromRuntimeBackends(context, subId, subKey, filters, isShellKind
|
|
|
5653
5653
|
send({ type: "relay.eose", subId });
|
|
5654
5654
|
}
|
|
5655
5655
|
}, 15e3);
|
|
5656
|
-
const subscription = pool.subscribeToRelays([...
|
|
5656
|
+
const subscription = pool.subscribeToRelays([...relayUrls2], filters, (item) => {
|
|
5657
5657
|
if (!isActive()) return;
|
|
5658
5658
|
if (item === "EOSE") {
|
|
5659
5659
|
clearTimeout(eoseFallbackTimer);
|
|
@@ -5664,7 +5664,7 @@ function deliverFromRuntimeBackends(context, subId, subKey, filters, isShellKind
|
|
|
5664
5664
|
return;
|
|
5665
5665
|
}
|
|
5666
5666
|
const event = item;
|
|
5667
|
-
deliver(event, [...
|
|
5667
|
+
deliver(event, [...relayUrls2]);
|
|
5668
5668
|
if (cache2?.isAvailable() && !isShellKind) {
|
|
5669
5669
|
try {
|
|
5670
5670
|
cache2.store(event);
|
|
@@ -5951,8 +5951,8 @@ function handleRelayQuery(context, windowId, input) {
|
|
|
5951
5951
|
}
|
|
5952
5952
|
throw new Error("relay adapter requires explicit planned execution");
|
|
5953
5953
|
}
|
|
5954
|
-
const
|
|
5955
|
-
plan = { operation: "query", relayUrls:
|
|
5954
|
+
const relayUrls2 = !pool?.isAvailable() ? [] : typeof message3.relay === "string" && message3.relay.length > 0 ? [message3.relay] : pool.selectRelayTier(filters);
|
|
5955
|
+
plan = { operation: "query", relayUrls: relayUrls2, localOnly: !pool?.isAvailable() };
|
|
5956
5956
|
}
|
|
5957
5957
|
plan = Object.freeze({ ...plan, operation: "query", relayUrls: Object.freeze([...new Set(plan.relayUrls)]) });
|
|
5958
5958
|
} catch (error) {
|
|
@@ -9001,7 +9001,7 @@ function executeRelayOperation(options2, tracked, publishEvent, windowId, messag
|
|
|
9001
9001
|
send({ type: "relay.eose", subId });
|
|
9002
9002
|
return;
|
|
9003
9003
|
}
|
|
9004
|
-
const
|
|
9004
|
+
const relayUrls2 = [...plan.relayUrls];
|
|
9005
9005
|
let eoseSent = false;
|
|
9006
9006
|
const eoseTimer = setTimeout(() => {
|
|
9007
9007
|
if (!eoseSent) {
|
|
@@ -9025,9 +9025,9 @@ function executeRelayOperation(options2, tracked, publishEvent, windowId, messag
|
|
|
9025
9025
|
send({
|
|
9026
9026
|
type: "relay.event",
|
|
9027
9027
|
subId,
|
|
9028
|
-
result: createRelayEventResultWithHints(item, observedRelayUrls ??
|
|
9028
|
+
result: createRelayEventResultWithHints(item, observedRelayUrls ?? relayUrls2)
|
|
9029
9029
|
});
|
|
9030
|
-
},
|
|
9030
|
+
}, relayUrls2, typeof relayMessage.relay === "string" && relayMessage.relay.length > 0);
|
|
9031
9031
|
entry.handle = handle;
|
|
9032
9032
|
if (tracked.get(subKey) !== entry) {
|
|
9033
9033
|
handle.unsubscribe();
|
|
@@ -9066,8 +9066,8 @@ function createRelayPoolService(options2) {
|
|
|
9066
9066
|
const relayHint = typeof relayMessage.relay === "string" && relayMessage.relay.length > 0 ? relayMessage.relay : void 0;
|
|
9067
9067
|
const operation = message22.type === "relay.query" ? "query" : message22.type === "relay.publishEncrypted" ? "publishEncrypted" : message22.type === "relay.publish" ? "publish" : "subscribe";
|
|
9068
9068
|
const selected = relayHint ? [relayHint] : operation === "publish" || operation === "publishEncrypted" ? options2.selectPublishRelayTier?.() ?? options2.selectRelayTier([]) : options2.selectRelayTier(filters);
|
|
9069
|
-
const
|
|
9070
|
-
return Object.freeze({ operation, relayUrls: Object.freeze(
|
|
9069
|
+
const relayUrls2 = [...new Set(selected.map((url) => String(url).trim()).filter(Boolean))];
|
|
9070
|
+
return Object.freeze({ operation, relayUrls: Object.freeze(relayUrls2), localOnly: relayUrls2.length === 0 });
|
|
9071
9071
|
}
|
|
9072
9072
|
function publishEvent(relayMessage, resultType, send, plan, signal) {
|
|
9073
9073
|
const id = typeof relayMessage.id === "string" ? relayMessage.id : "";
|
|
@@ -12143,8 +12143,8 @@ function startQueryImpl(ctx, filters, options2, sink) {
|
|
|
12143
12143
|
incomplete = true;
|
|
12144
12144
|
}
|
|
12145
12145
|
}
|
|
12146
|
-
function attachMany(
|
|
12147
|
-
for (const relayUrl2 of
|
|
12146
|
+
function attachMany(relayUrls2, origin, authorsByRelay) {
|
|
12147
|
+
for (const relayUrl2 of relayUrls2) {
|
|
12148
12148
|
attachRelay(relayUrl2, origin, origin === "nip65" ? authorsByRelay?.get(relayUrl2) ?? [] : authors);
|
|
12149
12149
|
}
|
|
12150
12150
|
}
|
|
@@ -12336,8 +12336,8 @@ function startSubscription(ctx, filters, options2, sink) {
|
|
|
12336
12336
|
};
|
|
12337
12337
|
let discoveryOpen = authors.length > 0;
|
|
12338
12338
|
let discoveryTimer;
|
|
12339
|
-
function attachMany(
|
|
12340
|
-
for (const relayUrl2 of
|
|
12339
|
+
function attachMany(relayUrls2, origin, authorsByRelay) {
|
|
12340
|
+
for (const relayUrl2 of relayUrls2) {
|
|
12341
12341
|
attachLiveRelay(ctx, sub, filters, relayUrl2, sink, {
|
|
12342
12342
|
origin,
|
|
12343
12343
|
authors: origin === "nip65" ? authorsByRelay?.get(relayUrl2) ?? [] : authors
|
|
@@ -12451,11 +12451,11 @@ async function publishImpl(ctx, template, options2) {
|
|
|
12451
12451
|
if (publishTargets.error) {
|
|
12452
12452
|
return { ok: false, event: signed, eventId: signed.id, error: publishTargets.error };
|
|
12453
12453
|
}
|
|
12454
|
-
const
|
|
12455
|
-
if (
|
|
12454
|
+
const relayUrls2 = publishTargets.relayUrls;
|
|
12455
|
+
if (relayUrls2.length === 0) return { ok: false, event: signed, eventId: signed.id, error: "relay list unavailable" };
|
|
12456
12456
|
let relays;
|
|
12457
12457
|
try {
|
|
12458
|
-
relays = normalizePublishResult(await ctx.relayPool.publish(signed,
|
|
12458
|
+
relays = normalizePublishResult(await ctx.relayPool.publish(signed, relayUrls2), relayUrls2);
|
|
12459
12459
|
} catch (err2) {
|
|
12460
12460
|
return { ok: false, event: signed, eventId: signed.id, error: err2 instanceof Error ? err2.message : "publish failed" };
|
|
12461
12461
|
}
|
|
@@ -12522,12 +12522,12 @@ function createRelayPoolOutboxRouter(options2) {
|
|
|
12522
12522
|
}
|
|
12523
12523
|
};
|
|
12524
12524
|
}
|
|
12525
|
-
function normalizePublishResult(res,
|
|
12525
|
+
function normalizePublishResult(res, relayUrls2) {
|
|
12526
12526
|
const out = {};
|
|
12527
12527
|
if (res && typeof res === "object") {
|
|
12528
|
-
for (const url of
|
|
12528
|
+
for (const url of relayUrls2) out[url] = res[url] ?? false;
|
|
12529
12529
|
} else {
|
|
12530
|
-
for (const url of
|
|
12530
|
+
for (const url of relayUrls2) out[url] = true;
|
|
12531
12531
|
}
|
|
12532
12532
|
return out;
|
|
12533
12533
|
}
|
|
@@ -13498,22 +13498,22 @@ async function verifiedTools(server, request, opts) {
|
|
|
13498
13498
|
async function entries(families, select22, request, opts) {
|
|
13499
13499
|
const found = [];
|
|
13500
13500
|
const inventories = /* @__PURE__ */ new Map();
|
|
13501
|
-
for (const
|
|
13502
|
-
if (!select22.schemaHash && select22.family &&
|
|
13503
|
-
if (opts.server && opts.server.pubkey !==
|
|
13504
|
-
const server = opts.server ??
|
|
13501
|
+
for (const family of families) {
|
|
13502
|
+
if (!select22.schemaHash && select22.family && family.family !== select22.family) continue;
|
|
13503
|
+
if (opts.server && opts.server.pubkey !== family.server.pubkey) continue;
|
|
13504
|
+
const server = opts.server ?? family.server;
|
|
13505
13505
|
const key = JSON.stringify(server);
|
|
13506
13506
|
let tools = inventories.get(key);
|
|
13507
13507
|
if (!tools) {
|
|
13508
13508
|
tools = await verifiedTools(server, request, opts);
|
|
13509
13509
|
inventories.set(key, tools);
|
|
13510
13510
|
}
|
|
13511
|
-
const selected = select22.schemaHash ? tools.filter((tool2) => tool2.schemaHash === select22.schemaHash) :
|
|
13511
|
+
const selected = select22.schemaHash ? tools.filter((tool2) => tool2.schemaHash === select22.schemaHash) : family.tools.map((pin) => tools.find((tool2) => tool2.name === pin.name && tool2.schemaHash === pin.schemaHash));
|
|
13512
13512
|
if (!selected.length || selected.some((tool2) => !tool2)) continue;
|
|
13513
13513
|
const verified = selected;
|
|
13514
13514
|
found.push({
|
|
13515
|
-
family:
|
|
13516
|
-
...
|
|
13515
|
+
family: family.family,
|
|
13516
|
+
...family.description ? { description: family.description } : {},
|
|
13517
13517
|
schemaHashes: [...new Set(verified.map((tool2) => tool2.schemaHash))],
|
|
13518
13518
|
selected: server,
|
|
13519
13519
|
providers: [server],
|
|
@@ -13528,24 +13528,24 @@ async function handleCvmRegistry(message22, families, request) {
|
|
|
13528
13528
|
const listing = type === "cvm.registry.list";
|
|
13529
13529
|
const select22 = selector(listing ? message22.query : message22.selector, listing);
|
|
13530
13530
|
const opts = options(message22.options);
|
|
13531
|
-
const
|
|
13532
|
-
if (listing && (
|
|
13531
|
+
const query2 = message22.query ?? {};
|
|
13532
|
+
if (listing && (query2.limit !== void 0 && (!Number.isInteger(query2.limit) || Number(query2.limit) < 1) || query2.search !== void 0 && typeof query2.search !== "string" || query2.category !== void 0 && typeof query2.category !== "string")) throw new Error("invalid request");
|
|
13533
13533
|
if (type === "cvm.registry.call" && (typeof message22.tool !== "string" || !message22.tool || message22.args !== void 0 && !record2(message22.args))) throw new Error("invalid request");
|
|
13534
13534
|
if (!families.length) {
|
|
13535
13535
|
if (type === "cvm.registry.has") return { has: false };
|
|
13536
13536
|
throw new Error("unsupported method");
|
|
13537
13537
|
}
|
|
13538
|
-
const candidates = listing ? families.filter((
|
|
13539
|
-
let
|
|
13538
|
+
const candidates = listing ? families.filter((family) => (query2.category === void 0 || family.categories?.includes(String(query2.category))) && (query2.search === void 0 || `${family.family} ${family.description ?? ""}`.toLowerCase().includes(String(query2.search).toLowerCase()))) : families;
|
|
13539
|
+
let matches3;
|
|
13540
13540
|
try {
|
|
13541
|
-
|
|
13541
|
+
matches3 = await entries(candidates, select22, request, opts);
|
|
13542
13542
|
} catch (error) {
|
|
13543
13543
|
if (type === "cvm.registry.has") return { has: false };
|
|
13544
13544
|
throw error;
|
|
13545
13545
|
}
|
|
13546
|
-
if (listing) return { entries:
|
|
13547
|
-
if (type === "cvm.registry.has") return { has:
|
|
13548
|
-
const entry =
|
|
13546
|
+
if (listing) return { entries: matches3.slice(0, typeof query2.limit === "number" ? query2.limit : void 0) };
|
|
13547
|
+
if (type === "cvm.registry.has") return { has: matches3.length > 0 };
|
|
13548
|
+
const entry = matches3[0];
|
|
13549
13549
|
if (!entry) throw new Error(select22.schemaHash ? "schema mismatch" : "family not found");
|
|
13550
13550
|
if (type === "cvm.registry.describe") return { entry };
|
|
13551
13551
|
if (!entry.tools.some((tool2) => tool2.name === message22.tool)) throw new Error("schema mismatch");
|
|
@@ -13572,10 +13572,10 @@ function relayPlan(relays) {
|
|
|
13572
13572
|
if (origins.some((origin) => origin === null)) throw new Error("invalid relay");
|
|
13573
13573
|
return Object.freeze([...new Set(origins)]);
|
|
13574
13574
|
}
|
|
13575
|
-
function validQuery(
|
|
13576
|
-
if (
|
|
13577
|
-
if (!
|
|
13578
|
-
const value =
|
|
13575
|
+
function validQuery(query2) {
|
|
13576
|
+
if (query2 === void 0) return true;
|
|
13577
|
+
if (!query2 || typeof query2 !== "object") return false;
|
|
13578
|
+
const value = query2;
|
|
13579
13579
|
return (value.search === void 0 || typeof value.search === "string" && value.search.length <= 256) && (value.limit === void 0 || Number.isSafeInteger(value.limit) && value.limit > 0 && value.limit <= 100) && (value.kinds === void 0 || Array.isArray(value.kinds) && value.kinds.every((kind) => Number.isSafeInteger(kind))) && (value.relays === void 0 || Array.isArray(value.relays) && value.relays.length <= 32);
|
|
13580
13580
|
}
|
|
13581
13581
|
function validServer(server) {
|
|
@@ -14700,15 +14700,15 @@ function normalizePlan(candidate) {
|
|
|
14700
14700
|
if (!candidate || typeof candidate.resource !== "string" || !candidate.resource || !Array.isArray(candidate.signalingRelayUrls) || !Array.isArray(candidate.iceEndpoints)) throw new Error("signaling unavailable");
|
|
14701
14701
|
if (candidate.iceEndpoints.some((endpoint) => typeof endpoint !== "string" || !endpoint)) throw new Error("Invalid ICE endpoint");
|
|
14702
14702
|
const iceEndpoints = [...new Set(candidate.iceEndpoints)];
|
|
14703
|
-
const
|
|
14703
|
+
const relayUrls2 = [...new Set(candidate.signalingRelayUrls.map((url) => {
|
|
14704
14704
|
if (typeof url !== "string") throw new Error("signaling unavailable");
|
|
14705
14705
|
const parsed = new URL(url);
|
|
14706
14706
|
if (parsed.protocol !== "ws:" && parsed.protocol !== "wss:" || !parsed.hostname) throw new Error("signaling unavailable");
|
|
14707
14707
|
return url.trim();
|
|
14708
14708
|
}))];
|
|
14709
|
-
const origins = [...new Set(
|
|
14709
|
+
const origins = [...new Set(relayUrls2.map((url) => new URL(url).origin))];
|
|
14710
14710
|
const plan = Object.freeze({
|
|
14711
|
-
signalingRelayUrls: Object.freeze(
|
|
14711
|
+
signalingRelayUrls: Object.freeze(relayUrls2),
|
|
14712
14712
|
iceEndpoints: Object.freeze(iceEndpoints),
|
|
14713
14713
|
resource: candidate.resource
|
|
14714
14714
|
});
|
|
@@ -15352,9 +15352,9 @@ var DmMemoryStore = class {
|
|
|
15352
15352
|
this.messagesByConversation.set(message22.conversationId, list);
|
|
15353
15353
|
return message22;
|
|
15354
15354
|
}
|
|
15355
|
-
conversations(
|
|
15356
|
-
const offset =
|
|
15357
|
-
const limit =
|
|
15355
|
+
conversations(query2 = {}) {
|
|
15356
|
+
const offset = query2.cursor ? Number.parseInt(query2.cursor, 10) || 0 : 0;
|
|
15357
|
+
const limit = query2.limit ?? 50;
|
|
15358
15358
|
const conversations = [...this.messagesByConversation.entries()].map(([id, messages]) => {
|
|
15359
15359
|
const latest = messages[messages.length - 1];
|
|
15360
15360
|
return {
|
|
@@ -15369,10 +15369,10 @@ var DmMemoryStore = class {
|
|
|
15369
15369
|
const next = offset + page.length < conversations.length ? String(offset + page.length) : void 0;
|
|
15370
15370
|
return { conversations: page, ...next ? { cursor: next } : {} };
|
|
15371
15371
|
}
|
|
15372
|
-
messages(
|
|
15373
|
-
const offset =
|
|
15374
|
-
const limit =
|
|
15375
|
-
const all = this.messagesByConversation.get(
|
|
15372
|
+
messages(query2) {
|
|
15373
|
+
const offset = query2.cursor ? Number.parseInt(query2.cursor, 10) || 0 : 0;
|
|
15374
|
+
const limit = query2.limit ?? 100;
|
|
15375
|
+
const all = this.messagesByConversation.get(query2.conversationId) ?? [];
|
|
15376
15376
|
const page = all.slice(offset, offset + limit);
|
|
15377
15377
|
const next = offset + page.length < all.length ? String(offset + page.length) : void 0;
|
|
15378
15378
|
return { messages: page, ...next ? { cursor: next } : {} };
|
|
@@ -15402,16 +15402,16 @@ var Nip17DmRuntime = class {
|
|
|
15402
15402
|
adapter() {
|
|
15403
15403
|
return {
|
|
15404
15404
|
status: () => this.status(),
|
|
15405
|
-
conversations: (
|
|
15406
|
-
messages: (
|
|
15405
|
+
conversations: (query2) => this.conversations(query2),
|
|
15406
|
+
messages: (query2) => this.messages(query2),
|
|
15407
15407
|
send: (request) => this.send(request),
|
|
15408
15408
|
subscribe: (request, onMessage) => this.subscribe(request, onMessage),
|
|
15409
15409
|
unsubscribe: (subscriptionId) => this.unsubscribe(subscriptionId),
|
|
15410
15410
|
planRelays: (operation) => this.planRelays(operation),
|
|
15411
|
-
conversationsWithRelays: (
|
|
15412
|
-
messagesWithRelays: (
|
|
15413
|
-
sendWithRelays: (request,
|
|
15414
|
-
subscribeWithRelays: (request, onMessage,
|
|
15411
|
+
conversationsWithRelays: (query2, relayUrls2, signal) => this.conversationsWithRelays(query2, relayUrls2, signal),
|
|
15412
|
+
messagesWithRelays: (query2, relayUrls2, signal) => this.messagesWithRelays(query2, relayUrls2, signal),
|
|
15413
|
+
sendWithRelays: (request, relayUrls2, signal) => this.sendWithRelays(request, relayUrls2, signal),
|
|
15414
|
+
subscribeWithRelays: (request, onMessage, relayUrls2, signal) => this.subscribeWithRelays(request, onMessage, relayUrls2, signal),
|
|
15415
15415
|
close: () => this.close()
|
|
15416
15416
|
};
|
|
15417
15417
|
}
|
|
@@ -15461,12 +15461,12 @@ var Nip17DmRuntime = class {
|
|
|
15461
15461
|
const rumor = this.unwrapVerified(wrap);
|
|
15462
15462
|
return rumor ? this.normalizeRumor(rumor, status) : null;
|
|
15463
15463
|
}
|
|
15464
|
-
async loadHistory(
|
|
15464
|
+
async loadHistory(relayUrls2, signal) {
|
|
15465
15465
|
if (this.historyLoaded || !this.options.relayPool.query) return;
|
|
15466
15466
|
this.historyLoading ??= (async () => {
|
|
15467
15467
|
const filters = [{ kinds: [NIP17_GIFT_WRAP_KIND], "#p": [this.ownerPubkey], limit: 1e3 }];
|
|
15468
15468
|
if (signal?.aborted) throw new Error("cancelled");
|
|
15469
|
-
const wraps = await this.options.relayPool.query(filters, [...
|
|
15469
|
+
const wraps = await this.options.relayPool.query(filters, [...relayUrls2 ?? this.planRelays("history")]);
|
|
15470
15470
|
if (signal?.aborted) throw new Error("cancelled");
|
|
15471
15471
|
for (const wrap of wraps) this.ingestWrap(wrap, "received");
|
|
15472
15472
|
this.historyLoaded = true;
|
|
@@ -15483,28 +15483,28 @@ var Nip17DmRuntime = class {
|
|
|
15483
15483
|
capabilities: ["send", "receive", "subscribe", "history"]
|
|
15484
15484
|
};
|
|
15485
15485
|
}
|
|
15486
|
-
async conversations(
|
|
15486
|
+
async conversations(query2) {
|
|
15487
15487
|
await this.loadHistory();
|
|
15488
|
-
return this.store.conversations(
|
|
15488
|
+
return this.store.conversations(query2);
|
|
15489
15489
|
}
|
|
15490
|
-
async conversationsWithRelays(
|
|
15491
|
-
await this.loadHistory(
|
|
15490
|
+
async conversationsWithRelays(query2, relayUrls2, signal) {
|
|
15491
|
+
await this.loadHistory(relayUrls2, signal);
|
|
15492
15492
|
if (signal.aborted) throw new Error("cancelled");
|
|
15493
|
-
return this.store.conversations(
|
|
15493
|
+
return this.store.conversations(query2);
|
|
15494
15494
|
}
|
|
15495
|
-
async messages(
|
|
15495
|
+
async messages(query2) {
|
|
15496
15496
|
await this.loadHistory();
|
|
15497
|
-
return this.store.messages(
|
|
15497
|
+
return this.store.messages(query2);
|
|
15498
15498
|
}
|
|
15499
|
-
async messagesWithRelays(
|
|
15500
|
-
await this.loadHistory(
|
|
15499
|
+
async messagesWithRelays(query2, relayUrls2, signal) {
|
|
15500
|
+
await this.loadHistory(relayUrls2, signal);
|
|
15501
15501
|
if (signal.aborted) throw new Error("cancelled");
|
|
15502
|
-
return this.store.messages(
|
|
15502
|
+
return this.store.messages(query2);
|
|
15503
15503
|
}
|
|
15504
15504
|
async send(request) {
|
|
15505
15505
|
return this.sendWithRelays(request, this.planRelays("send"), { aborted: false });
|
|
15506
15506
|
}
|
|
15507
|
-
async sendWithRelays(request,
|
|
15507
|
+
async sendWithRelays(request, relayUrls2, signal) {
|
|
15508
15508
|
if (signal.aborted) throw new Error("cancelled");
|
|
15509
15509
|
if (!this.options.relayPool.isAvailable()) throw new Error("relay unavailable");
|
|
15510
15510
|
if (!Array.isArray(request.recipients) || request.recipients.length === 0) throw new Error("invalid recipient");
|
|
@@ -15520,7 +15520,7 @@ var Nip17DmRuntime = class {
|
|
|
15520
15520
|
if (signal.aborted) throw new Error("cancelled");
|
|
15521
15521
|
for (const wrap of wraps) {
|
|
15522
15522
|
if (signal.aborted) throw new Error("cancelled");
|
|
15523
|
-
await Promise.resolve(this.options.relayPool.publish(wrap,
|
|
15523
|
+
await Promise.resolve(this.options.relayPool.publish(wrap, relayUrls2));
|
|
15524
15524
|
}
|
|
15525
15525
|
const conversationId = request.conversationId ?? this.store.conversationIdFor([this.ownerPubkey, ...recipients]);
|
|
15526
15526
|
const message22 = this.store.upsertMessage({
|
|
@@ -15536,10 +15536,10 @@ var Nip17DmRuntime = class {
|
|
|
15536
15536
|
async subscribe(request, onMessage) {
|
|
15537
15537
|
return this.subscribeWithRelays(request, onMessage, this.planRelays("subscribe"), { aborted: false });
|
|
15538
15538
|
}
|
|
15539
|
-
async subscribeWithRelays(request, onMessage,
|
|
15539
|
+
async subscribeWithRelays(request, onMessage, relayUrls2, signal) {
|
|
15540
15540
|
if (signal.aborted) throw new Error("cancelled");
|
|
15541
15541
|
if (!this.options.relayPool.isAvailable()) throw new Error("relay unavailable");
|
|
15542
|
-
await this.loadHistory(
|
|
15542
|
+
await this.loadHistory(relayUrls2, signal);
|
|
15543
15543
|
const subscriptionId = `dm-nip17-${++subscriptionCounter}`;
|
|
15544
15544
|
const filters = [{ kinds: [NIP17_GIFT_WRAP_KIND], "#p": [this.ownerPubkey] }];
|
|
15545
15545
|
const sub = { conversationId: request.conversationId, onMessage };
|
|
@@ -15551,7 +15551,7 @@ var Nip17DmRuntime = class {
|
|
|
15551
15551
|
if (!message22) return;
|
|
15552
15552
|
const active = this.live.get(subscriptionId);
|
|
15553
15553
|
if (active && (!active.conversationId || active.conversationId === message22.conversationId)) active.onMessage(message22);
|
|
15554
|
-
}, [...
|
|
15554
|
+
}, [...relayUrls2]);
|
|
15555
15555
|
if (this.live.get(subscriptionId) !== sub) {
|
|
15556
15556
|
handle.unsubscribe();
|
|
15557
15557
|
throw new Error("subscription cancelled");
|
|
@@ -18101,7 +18101,7 @@ function text2(value) {
|
|
|
18101
18101
|
if (typeof value !== "string" || !value.trim() || value.length > 256) throw new Error("Expected nonempty text (at most 256 characters).");
|
|
18102
18102
|
return value;
|
|
18103
18103
|
}
|
|
18104
|
-
function
|
|
18104
|
+
function normalizePajaCvmRelays(value) {
|
|
18105
18105
|
if (!Array.isArray(value) || !value.length || value.length > 16) throw new Error("Configure 1\u201316 relay URLs.");
|
|
18106
18106
|
return [...new Set(value.map((item) => {
|
|
18107
18107
|
if (typeof item !== "string") throw new Error("Invalid relay URL.");
|
|
@@ -18110,7 +18110,7 @@ function relayUrls(value) {
|
|
|
18110
18110
|
return url.origin;
|
|
18111
18111
|
}))];
|
|
18112
18112
|
}
|
|
18113
|
-
function
|
|
18113
|
+
function normalizePajaCvmFamily(value) {
|
|
18114
18114
|
if (!record4(value) || !record4(value.server) || typeof value.server.pubkey !== "string" || !HEX.test(value.server.pubkey)) throw new Error("Each registry family needs a provider public key.");
|
|
18115
18115
|
if (!Array.isArray(value.tools) || !value.tools.length || value.tools.length > 64) throw new Error("Each family needs 1\u201364 tool name/hash pins.");
|
|
18116
18116
|
const tools = value.tools.map((tool2) => {
|
|
@@ -18120,7 +18120,7 @@ function family(value) {
|
|
|
18120
18120
|
if (new Set(tools.map((tool2) => tool2.name)).size !== tools.length) throw new Error("Family tool names must be unique.");
|
|
18121
18121
|
return {
|
|
18122
18122
|
family: text2(value.family),
|
|
18123
|
-
server: { pubkey: value.server.pubkey, relays:
|
|
18123
|
+
server: { pubkey: value.server.pubkey, relays: normalizePajaCvmRelays(value.server.relays) },
|
|
18124
18124
|
tools,
|
|
18125
18125
|
...value.description === void 0 ? {} : { description: text2(value.description) },
|
|
18126
18126
|
...value.categories === void 0 ? {} : { categories: Array.isArray(value.categories) ? value.categories.map(text2) : (() => {
|
|
@@ -18142,8 +18142,8 @@ function normalizePajaMultiplayer(value) {
|
|
|
18142
18142
|
if (value.iceServers !== void 0 && (!Array.isArray(value.iceServers) || value.iceServers.length > 8)) throw new Error("Configure at most 8 ICE servers.");
|
|
18143
18143
|
return {
|
|
18144
18144
|
profile: value.profile,
|
|
18145
|
-
relays:
|
|
18146
|
-
registry: value.registry.map(
|
|
18145
|
+
relays: normalizePajaCvmRelays(value.relays),
|
|
18146
|
+
registry: value.registry.map(normalizePajaCvmFamily),
|
|
18147
18147
|
...Array.isArray(value.iceServers) ? { iceServers: value.iceServers.map(iceServer) } : {},
|
|
18148
18148
|
...value.developmentNamespace === void 0 ? {} : { developmentNamespace: text2(value.developmentNamespace) }
|
|
18149
18149
|
};
|
|
@@ -18231,13 +18231,13 @@ function parsePajaBlossomUri(value) {
|
|
|
18231
18231
|
if (value.length > 8192 || /[\s\u0000-\u001f\u007f]/u.test(value)) return null;
|
|
18232
18232
|
const match = BLOSSOM_URI.exec(value);
|
|
18233
18233
|
if (!match?.[1]) return null;
|
|
18234
|
-
const
|
|
18234
|
+
const query2 = match[3] ?? "";
|
|
18235
18235
|
try {
|
|
18236
|
-
decodeURIComponent(
|
|
18236
|
+
decodeURIComponent(query2);
|
|
18237
18237
|
} catch {
|
|
18238
18238
|
return null;
|
|
18239
18239
|
}
|
|
18240
|
-
const params = new URLSearchParams(
|
|
18240
|
+
const params = new URLSearchParams(query2);
|
|
18241
18241
|
const authors = [];
|
|
18242
18242
|
for (const author of params.getAll("as")) {
|
|
18243
18243
|
if (!HEX_64.test(author)) return null;
|
|
@@ -18791,6 +18791,379 @@ function installPajaMultiplayerSettings(initial) {
|
|
|
18791
18791
|
return () => form.removeEventListener("submit", submit);
|
|
18792
18792
|
}
|
|
18793
18793
|
|
|
18794
|
+
// src/cvm-discovery.ts
|
|
18795
|
+
var HASH6 = /^[0-9a-f]{64}$/u;
|
|
18796
|
+
var MAX_BYTES = 1e6;
|
|
18797
|
+
var LIMIT = 64;
|
|
18798
|
+
function record5(value) {
|
|
18799
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
18800
|
+
}
|
|
18801
|
+
function parseCvmDiscoveryInput(input) {
|
|
18802
|
+
const text3 = input.trim().replace(/^nostr:/iu, "");
|
|
18803
|
+
if (!text3 || text3.length > 2048) throw new Error("Enter a nevent, a 64-character tool schema hash, or a website URL.");
|
|
18804
|
+
if (/^naddr1/iu.test(text3)) throw new Error("CVM announcements use nevent. Addressable naddr family manifests are not defined by ContextVM.");
|
|
18805
|
+
if (/^[0-9a-f]{64}$/iu.test(text3)) return { type: "hash", hash: text3.toLowerCase() };
|
|
18806
|
+
if (/^nevent1/iu.test(text3)) {
|
|
18807
|
+
const decoded = decode(text3);
|
|
18808
|
+
if (decoded.type !== "nevent" || decoded.data.kind !== void 0 && ![11316, 11317].includes(decoded.data.kind)) throw new Error("Use a CVM server or tool-list announcement (kind 11316 or 11317).");
|
|
18809
|
+
return { type: "event", id: decoded.data.id, author: decoded.data.author, relays: decoded.data.relays?.length ? normalizePajaCvmRelays(decoded.data.relays) : [] };
|
|
18810
|
+
}
|
|
18811
|
+
const url = new URL(text3.includes("://") ? text3 : `https://${text3}`);
|
|
18812
|
+
if (url.protocol !== "https:" || url.username || url.password || !url.hostname.includes(".")) throw new Error("Use an HTTPS website URL without credentials.");
|
|
18813
|
+
return { type: "website", url: `${url.origin}/.well-known/napplet.json` };
|
|
18814
|
+
}
|
|
18815
|
+
async function websiteProvider(url, deps, signal) {
|
|
18816
|
+
let response;
|
|
18817
|
+
try {
|
|
18818
|
+
response = await deps.fetch(url, { signal, credentials: "omit", redirect: "error", referrerPolicy: "no-referrer" });
|
|
18819
|
+
} catch (error) {
|
|
18820
|
+
if (signal.aborted) throw error;
|
|
18821
|
+
throw new Error("Cannot read the discovery document. The website must allow cross-origin requests (CORS).");
|
|
18822
|
+
}
|
|
18823
|
+
if (!response.ok) throw new Error(`Discovery document returned HTTP ${response.status}.`);
|
|
18824
|
+
if (Number(response.headers.get("content-length")) > MAX_BYTES) throw new Error("Discovery document is too large.");
|
|
18825
|
+
const reader = response.body?.getReader();
|
|
18826
|
+
if (!reader) throw new Error("Discovery document is empty.");
|
|
18827
|
+
const decoder = new TextDecoder();
|
|
18828
|
+
let body = "", bytes = 0;
|
|
18829
|
+
try {
|
|
18830
|
+
for (; ; ) {
|
|
18831
|
+
const chunk = await reader.read();
|
|
18832
|
+
if (chunk.done) break;
|
|
18833
|
+
bytes += chunk.value.byteLength;
|
|
18834
|
+
if (bytes > MAX_BYTES) throw new Error("Discovery document is too large.");
|
|
18835
|
+
body += decoder.decode(chunk.value, { stream: true });
|
|
18836
|
+
}
|
|
18837
|
+
body += decoder.decode();
|
|
18838
|
+
} finally {
|
|
18839
|
+
await reader.cancel();
|
|
18840
|
+
reader.releaseLock();
|
|
18841
|
+
}
|
|
18842
|
+
const document2 = JSON.parse(body);
|
|
18843
|
+
if (!record5(document2) || document2.version !== 1 || !record5(document2.backend) || typeof document2.backend.pubkey !== "string" || !HASH6.test(document2.backend.pubkey)) throw new Error("Expected version 1 with backend.pubkey and backend.relays.");
|
|
18844
|
+
return { pubkey: document2.backend.pubkey, relays: normalizePajaCvmRelays(document2.backend.relays) };
|
|
18845
|
+
}
|
|
18846
|
+
function matches2(event, filter) {
|
|
18847
|
+
return (!filter.ids || filter.ids.includes(event.id)) && (!filter.authors || filter.authors.includes(event.pubkey)) && (!filter.kinds || filter.kinds.includes(event.kind)) && Object.entries(filter).every(([key, values]) => !key.startsWith("#") || !Array.isArray(values) || event.tags.some((tag) => tag[0] === key.slice(1) && values.includes(tag[1])));
|
|
18848
|
+
}
|
|
18849
|
+
async function query(deps, relays, filter, signal) {
|
|
18850
|
+
signal.throwIfAborted();
|
|
18851
|
+
const events = await deps.query(relays, [{ ...filter, limit: LIMIT }], signal);
|
|
18852
|
+
signal.throwIfAborted();
|
|
18853
|
+
return events.slice(0, LIMIT).filter((event) => {
|
|
18854
|
+
try {
|
|
18855
|
+
const { id, pubkey: pubkey2, sig, kind, created_at, tags, content } = event;
|
|
18856
|
+
return content.length <= MAX_BYTES && matches2(event, filter) && verifyEvent({ id, pubkey: pubkey2, sig, kind, created_at, tags, content });
|
|
18857
|
+
} catch {
|
|
18858
|
+
return false;
|
|
18859
|
+
}
|
|
18860
|
+
}).sort((a, b) => b.created_at - a.created_at || a.id.localeCompare(b.id));
|
|
18861
|
+
}
|
|
18862
|
+
async function inventory(event) {
|
|
18863
|
+
const payload = JSON.parse(event.content);
|
|
18864
|
+
if (!record5(payload) || !Array.isArray(payload.tools) || !payload.tools.length || payload.tools.length > LIMIT || payload.nextCursor !== void 0) throw new Error("Announcement must contain a complete inventory of 1\u201364 tools.");
|
|
18865
|
+
const names = /* @__PURE__ */ new Set();
|
|
18866
|
+
const tools = [];
|
|
18867
|
+
for (const raw of payload.tools) {
|
|
18868
|
+
if (!record5(raw) || typeof raw.name !== "string" || !raw.name.trim() || raw.name.length > 256 || names.has(raw.name) || !record5(raw.inputSchema) || raw.outputSchema !== void 0 && !record5(raw.outputSchema)) throw new Error("Announcement contains an invalid tool schema.");
|
|
18869
|
+
names.add(raw.name);
|
|
18870
|
+
const schemaHash = await computeCvmToolSchemaHash({
|
|
18871
|
+
name: raw.name,
|
|
18872
|
+
inputSchema: raw.inputSchema,
|
|
18873
|
+
...record5(raw.outputSchema) ? { outputSchema: raw.outputSchema } : {}
|
|
18874
|
+
});
|
|
18875
|
+
const metadata = record5(raw._meta) ? raw._meta["io.contextvm/common-schema"] : void 0;
|
|
18876
|
+
if (metadata !== void 0 && (!record5(metadata) || metadata.schemaHash !== schemaHash)) throw new Error("Announcement schema hash does not match its tool definition.");
|
|
18877
|
+
const tags = event.tags.filter((tag) => tag[0] === "i" && tag[2] === raw.name);
|
|
18878
|
+
if (tags.some((tag) => tag[1] !== schemaHash)) throw new Error("Announcement schema tag does not match its tool definition.");
|
|
18879
|
+
tools.push({ name: raw.name, schemaHash });
|
|
18880
|
+
}
|
|
18881
|
+
return tools;
|
|
18882
|
+
}
|
|
18883
|
+
async function discoverCvmFamilies(input, deps, signal) {
|
|
18884
|
+
const reference = parseCvmDiscoveryInput(input);
|
|
18885
|
+
let relays, events;
|
|
18886
|
+
if (reference.type === "website") {
|
|
18887
|
+
const provider = await websiteProvider(reference.url, deps, signal);
|
|
18888
|
+
relays = provider.relays;
|
|
18889
|
+
events = await query(deps, relays, { kinds: [11317], authors: [provider.pubkey] }, signal);
|
|
18890
|
+
} else {
|
|
18891
|
+
relays = normalizePajaCvmRelays(reference.type === "event" && reference.relays.length ? reference.relays : deps.relays);
|
|
18892
|
+
events = await query(deps, relays, reference.type === "hash" ? { kinds: [11317], "#i": [reference.hash] } : { ids: [reference.id], kinds: [11316, 11317], ...reference.author ? { authors: [reference.author] } : {} }, signal);
|
|
18893
|
+
if (reference.type === "event" && events[0]?.kind === 11316) events = await query(deps, relays, { kinds: [11317], authors: [events[0].pubkey] }, signal);
|
|
18894
|
+
}
|
|
18895
|
+
const latest = /* @__PURE__ */ new Map();
|
|
18896
|
+
for (const event of events) if (!latest.has(event.pubkey)) latest.set(event.pubkey, event);
|
|
18897
|
+
const relayLists = reference.type === "website" || !latest.size ? [] : await query(deps, relays, { kinds: [10002], authors: [...latest.keys()] }, signal);
|
|
18898
|
+
const candidates = [];
|
|
18899
|
+
let failure4;
|
|
18900
|
+
for (const event of latest.values()) {
|
|
18901
|
+
try {
|
|
18902
|
+
const tools = await inventory(event);
|
|
18903
|
+
if (reference.type === "hash" && !tools.some((tool2) => tool2.schemaHash === reference.hash)) throw new Error("Announcement does not implement the requested schema hash.");
|
|
18904
|
+
const relayList = relayLists.find((list) => list.pubkey === event.pubkey);
|
|
18905
|
+
const relayTags = relayList?.tags.filter((tag) => tag[0] === "r");
|
|
18906
|
+
const unmarked = relayTags?.filter((tag) => !tag[2]);
|
|
18907
|
+
const providerRelays = relayTags ? normalizePajaCvmRelays((unmarked?.length ? unmarked : relayTags).map((tag) => tag[1])) : relays;
|
|
18908
|
+
candidates.push({
|
|
18909
|
+
config: { family: `cvm.${event.pubkey.slice(0, 12)}`, server: { pubkey: event.pubkey, relays: providerRelays }, tools },
|
|
18910
|
+
eventId: event.id,
|
|
18911
|
+
source: `${reference.type === "website" ? reference.url : input.trim()} \xB7 event ${event.id}`
|
|
18912
|
+
});
|
|
18913
|
+
} catch (error) {
|
|
18914
|
+
failure4 = error;
|
|
18915
|
+
}
|
|
18916
|
+
}
|
|
18917
|
+
signal.throwIfAborted();
|
|
18918
|
+
if (!candidates.length) throw failure4 ?? new Error("No verified tool announcements found. Check the reference and discovery relays; hash searches require CEP-15 i tags.");
|
|
18919
|
+
return candidates;
|
|
18920
|
+
}
|
|
18921
|
+
|
|
18922
|
+
// src/cvm-family-store.ts
|
|
18923
|
+
var KEY2 = "kehto:paja:cvm-families:v1";
|
|
18924
|
+
function normalize(value) {
|
|
18925
|
+
if (!Array.isArray(value) || value.length > 16) throw new Error("Save at most 16 CVM families.");
|
|
18926
|
+
const pairs = /* @__PURE__ */ new Set();
|
|
18927
|
+
return value.map((entry) => {
|
|
18928
|
+
if (!entry || typeof entry.source !== "string" || entry.source.length > 4096 || typeof entry.manual !== "boolean") throw new Error("Invalid saved CVM family.");
|
|
18929
|
+
const config = normalizePajaCvmFamily(entry.config);
|
|
18930
|
+
const pair = JSON.stringify([config.family, config.server.pubkey]);
|
|
18931
|
+
if (pairs.has(pair)) throw new Error("This family label and provider are already saved.");
|
|
18932
|
+
pairs.add(pair);
|
|
18933
|
+
return { config, source: entry.source, manual: entry.manual };
|
|
18934
|
+
});
|
|
18935
|
+
}
|
|
18936
|
+
function readCvmFamilies() {
|
|
18937
|
+
try {
|
|
18938
|
+
return normalize(JSON.parse(localStorage.getItem(KEY2) ?? "[]"));
|
|
18939
|
+
} catch {
|
|
18940
|
+
return [];
|
|
18941
|
+
}
|
|
18942
|
+
}
|
|
18943
|
+
function saveCvmFamilies(entries2) {
|
|
18944
|
+
localStorage.setItem(KEY2, JSON.stringify(normalize(entries2)));
|
|
18945
|
+
}
|
|
18946
|
+
function mergeCvmFamilies(configured, saved) {
|
|
18947
|
+
const entries2 = /* @__PURE__ */ new Map();
|
|
18948
|
+
for (const config of [...configured, ...saved.map((entry) => entry.config)]) entries2.set(JSON.stringify([config.family, config.server.pubkey]), config);
|
|
18949
|
+
return [...entries2.values()];
|
|
18950
|
+
}
|
|
18951
|
+
|
|
18952
|
+
// src/browser-cvm-settings.ts
|
|
18953
|
+
function installPajaCvmSettings(deps) {
|
|
18954
|
+
const form = document.getElementById("paja-cvm-form");
|
|
18955
|
+
if (!form) return () => void 0;
|
|
18956
|
+
const input = form.querySelector("#paja-cvm-discovery");
|
|
18957
|
+
const find = form.querySelector("#paja-cvm-find");
|
|
18958
|
+
const results = form.querySelector("#paja-cvm-results");
|
|
18959
|
+
const label = form.querySelector("#paja-cvm-label");
|
|
18960
|
+
const tools = form.querySelector("#paja-cvm-tools");
|
|
18961
|
+
const json = form.querySelector("#paja-cvm-json");
|
|
18962
|
+
const origin = form.querySelector("#paja-cvm-origin");
|
|
18963
|
+
const status = form.querySelector("#paja-cvm-status");
|
|
18964
|
+
const savedList = form.querySelector("#paja-cvm-saved");
|
|
18965
|
+
const manual = form.querySelector("#paja-cvm-manual");
|
|
18966
|
+
const create = form.querySelector("#paja-cvm-new");
|
|
18967
|
+
const save = form.querySelector("#paja-cvm-save");
|
|
18968
|
+
const saved = readCvmFamilies();
|
|
18969
|
+
const listeners = new AbortController();
|
|
18970
|
+
let request;
|
|
18971
|
+
let candidates = [];
|
|
18972
|
+
let selected;
|
|
18973
|
+
let editingIndex;
|
|
18974
|
+
let manualMode = true;
|
|
18975
|
+
const on = (element3, type, listener) => element3.addEventListener(type, listener, { signal: listeners.signal });
|
|
18976
|
+
const showError = (error) => {
|
|
18977
|
+
status.textContent = error instanceof Error ? error.message : "Unable to save this family.";
|
|
18978
|
+
};
|
|
18979
|
+
function preview() {
|
|
18980
|
+
if (!selected || manualMode) return;
|
|
18981
|
+
const checked = Array.from(tools.querySelectorAll("input:checked")).map((item) => Number(item.value));
|
|
18982
|
+
json.value = JSON.stringify({ ...selected.config, family: label.value, tools: selected.config.tools.filter((_tool, index) => checked.includes(index)) }, null, 2);
|
|
18983
|
+
save.disabled = !label.value.trim() || !checked.length;
|
|
18984
|
+
}
|
|
18985
|
+
function choose2(entry) {
|
|
18986
|
+
selected = entry;
|
|
18987
|
+
manualMode = entry.manual;
|
|
18988
|
+
json.readOnly = !entry.manual;
|
|
18989
|
+
origin.textContent = entry.manual ? "Source: manual JSON" : `Source: ${entry.source}`;
|
|
18990
|
+
label.value = entry.config.family;
|
|
18991
|
+
label.disabled = entry.manual;
|
|
18992
|
+
tools.replaceChildren();
|
|
18993
|
+
tools.hidden = entry.manual;
|
|
18994
|
+
const legend = document.createElement("legend");
|
|
18995
|
+
legend.textContent = "Tools in this local family";
|
|
18996
|
+
tools.append(legend);
|
|
18997
|
+
entry.config.tools.forEach((tool2, index) => {
|
|
18998
|
+
const row = document.createElement("label");
|
|
18999
|
+
const checkbox = document.createElement("input");
|
|
19000
|
+
checkbox.type = "checkbox";
|
|
19001
|
+
checkbox.value = String(index);
|
|
19002
|
+
checkbox.checked = true;
|
|
19003
|
+
row.append(checkbox, document.createTextNode(` ${tool2.name}`));
|
|
19004
|
+
tools.append(row);
|
|
19005
|
+
});
|
|
19006
|
+
json.value = JSON.stringify(entry.config, null, 2);
|
|
19007
|
+
save.disabled = false;
|
|
19008
|
+
status.textContent = "Review the provider, local label, and tool pins before saving.";
|
|
19009
|
+
}
|
|
19010
|
+
function cancel() {
|
|
19011
|
+
request?.abort();
|
|
19012
|
+
request = void 0;
|
|
19013
|
+
find.disabled = false;
|
|
19014
|
+
}
|
|
19015
|
+
on(find, "click", () => {
|
|
19016
|
+
cancel();
|
|
19017
|
+
const controller = new AbortController();
|
|
19018
|
+
request = controller;
|
|
19019
|
+
const timeout = setTimeout(() => controller.abort(new Error("Discovery timed out. Check the website and relay connections.")), 15e3);
|
|
19020
|
+
find.disabled = true;
|
|
19021
|
+
save.disabled = true;
|
|
19022
|
+
manualMode = false;
|
|
19023
|
+
results.disabled = true;
|
|
19024
|
+
results.replaceChildren();
|
|
19025
|
+
candidates = [];
|
|
19026
|
+
selected = void 0;
|
|
19027
|
+
editingIndex = void 0;
|
|
19028
|
+
json.value = "";
|
|
19029
|
+
json.readOnly = true;
|
|
19030
|
+
label.disabled = true;
|
|
19031
|
+
tools.hidden = true;
|
|
19032
|
+
origin.textContent = "Source: discovery pending";
|
|
19033
|
+
status.textContent = "Looking for verified tool announcements\u2026";
|
|
19034
|
+
void discoverCvmFamilies(input.value, deps, controller.signal).then((found) => {
|
|
19035
|
+
if (request !== controller || listeners.signal.aborted) return;
|
|
19036
|
+
candidates = found;
|
|
19037
|
+
const placeholder = document.createElement("option");
|
|
19038
|
+
placeholder.value = "";
|
|
19039
|
+
placeholder.textContent = "Choose a provider";
|
|
19040
|
+
results.append(placeholder);
|
|
19041
|
+
found.forEach((candidate, index) => {
|
|
19042
|
+
const option = document.createElement("option");
|
|
19043
|
+
option.value = String(index);
|
|
19044
|
+
const pubkey2 = candidate.config.server.pubkey;
|
|
19045
|
+
option.textContent = `${candidate.config.tools.length} tools \xB7 ${pubkey2.slice(0, 12)}\u2026${pubkey2.slice(-12)}`;
|
|
19046
|
+
option.title = pubkey2;
|
|
19047
|
+
results.append(option);
|
|
19048
|
+
});
|
|
19049
|
+
results.disabled = false;
|
|
19050
|
+
status.textContent = `${found.length} verified provider${found.length === 1 ? "" : "s"} found. Choose one to review.`;
|
|
19051
|
+
if (found.length === 1) {
|
|
19052
|
+
results.value = "0";
|
|
19053
|
+
choose2({ config: found[0].config, source: found[0].source, manual: false });
|
|
19054
|
+
}
|
|
19055
|
+
}).catch((error) => {
|
|
19056
|
+
if (request === controller && !listeners.signal.aborted) showError(controller.signal.aborted ? controller.signal.reason : error);
|
|
19057
|
+
}).finally(() => {
|
|
19058
|
+
clearTimeout(timeout);
|
|
19059
|
+
if (request === controller) {
|
|
19060
|
+
request = void 0;
|
|
19061
|
+
find.disabled = false;
|
|
19062
|
+
}
|
|
19063
|
+
});
|
|
19064
|
+
});
|
|
19065
|
+
on(input, "input", () => {
|
|
19066
|
+
cancel();
|
|
19067
|
+
results.disabled = true;
|
|
19068
|
+
candidates = [];
|
|
19069
|
+
selected = void 0;
|
|
19070
|
+
if (!manualMode) {
|
|
19071
|
+
json.value = "";
|
|
19072
|
+
save.disabled = true;
|
|
19073
|
+
origin.textContent = "Source: no selection";
|
|
19074
|
+
}
|
|
19075
|
+
status.textContent = "";
|
|
19076
|
+
});
|
|
19077
|
+
on(input, "keydown", (event) => {
|
|
19078
|
+
if (event.key === "Enter") {
|
|
19079
|
+
event.preventDefault();
|
|
19080
|
+
find.click();
|
|
19081
|
+
}
|
|
19082
|
+
});
|
|
19083
|
+
on(results, "change", () => {
|
|
19084
|
+
const candidate = results.value === "" ? void 0 : candidates[Number(results.value)];
|
|
19085
|
+
if (candidate) {
|
|
19086
|
+
editingIndex = void 0;
|
|
19087
|
+
choose2({ config: candidate.config, source: candidate.source, manual: false });
|
|
19088
|
+
} else {
|
|
19089
|
+
selected = void 0;
|
|
19090
|
+
json.value = "";
|
|
19091
|
+
save.disabled = true;
|
|
19092
|
+
origin.textContent = "Source: no selection";
|
|
19093
|
+
}
|
|
19094
|
+
});
|
|
19095
|
+
on(label, "input", preview);
|
|
19096
|
+
on(tools, "change", preview);
|
|
19097
|
+
on(manual, "click", () => {
|
|
19098
|
+
cancel();
|
|
19099
|
+
manualMode = true;
|
|
19100
|
+
selected = void 0;
|
|
19101
|
+
json.readOnly = false;
|
|
19102
|
+
label.disabled = true;
|
|
19103
|
+
tools.hidden = true;
|
|
19104
|
+
results.disabled = true;
|
|
19105
|
+
origin.textContent = "Source: manual JSON";
|
|
19106
|
+
status.textContent = "Enter or edit a family object, then save.";
|
|
19107
|
+
save.disabled = false;
|
|
19108
|
+
json.focus();
|
|
19109
|
+
});
|
|
19110
|
+
on(create, "click", () => {
|
|
19111
|
+
editingIndex = void 0;
|
|
19112
|
+
json.value = "";
|
|
19113
|
+
manual.click();
|
|
19114
|
+
});
|
|
19115
|
+
on(form, "submit", (event) => {
|
|
19116
|
+
event.preventDefault();
|
|
19117
|
+
try {
|
|
19118
|
+
if (request || !manualMode && !selected) throw new Error("Choose a provider before saving.");
|
|
19119
|
+
const config = normalizePajaCvmFamily(JSON.parse(json.value));
|
|
19120
|
+
const entry = { config, source: manualMode ? "Manual JSON" : selected.source, manual: manualMode };
|
|
19121
|
+
const next = [...saved];
|
|
19122
|
+
const index = editingIndex ?? next.findIndex((item) => item.config.family === config.family && item.config.server.pubkey === config.server.pubkey);
|
|
19123
|
+
if (index >= 0) next[index] = entry;
|
|
19124
|
+
else next.push(entry);
|
|
19125
|
+
saveCvmFamilies(next);
|
|
19126
|
+
location.reload();
|
|
19127
|
+
} catch (error) {
|
|
19128
|
+
showError(error);
|
|
19129
|
+
}
|
|
19130
|
+
});
|
|
19131
|
+
for (const [index, entry] of saved.entries()) {
|
|
19132
|
+
const row = document.createElement("div");
|
|
19133
|
+
const view = document.createElement("button");
|
|
19134
|
+
view.type = "button";
|
|
19135
|
+
view.textContent = `${entry.config.family} \xB7 ${entry.config.server.pubkey.slice(0, 12)}`;
|
|
19136
|
+
on(view, "click", () => {
|
|
19137
|
+
cancel();
|
|
19138
|
+
editingIndex = index;
|
|
19139
|
+
choose2(entry);
|
|
19140
|
+
});
|
|
19141
|
+
const remove = document.createElement("button");
|
|
19142
|
+
remove.type = "button";
|
|
19143
|
+
remove.textContent = "Remove";
|
|
19144
|
+
remove.setAttribute("aria-label", `Remove ${entry.config.family}`);
|
|
19145
|
+
on(remove, "click", () => {
|
|
19146
|
+
try {
|
|
19147
|
+
saveCvmFamilies(saved.filter((_item, i4) => i4 !== index));
|
|
19148
|
+
location.reload();
|
|
19149
|
+
} catch (error) {
|
|
19150
|
+
showError(error);
|
|
19151
|
+
}
|
|
19152
|
+
});
|
|
19153
|
+
row.append(view, remove);
|
|
19154
|
+
savedList.append(row);
|
|
19155
|
+
}
|
|
19156
|
+
if (!saved.length) savedList.textContent = "No saved families.";
|
|
19157
|
+
if (saved[0]) {
|
|
19158
|
+
editingIndex = 0;
|
|
19159
|
+
choose2(saved[0]);
|
|
19160
|
+
}
|
|
19161
|
+
return () => {
|
|
19162
|
+
cancel();
|
|
19163
|
+
listeners.abort();
|
|
19164
|
+
};
|
|
19165
|
+
}
|
|
19166
|
+
|
|
18794
19167
|
// src/local-target.ts
|
|
18795
19168
|
var PAJA_LOCAL_SINGLE_FILE_HINT = "Paja opens self-contained single-file index.html only; relative scripts, styles, and images do not load.";
|
|
18796
19169
|
var MAX_DTAG_LENGTH = 128;
|
|
@@ -19048,25 +19421,25 @@ function createSendToNapplet(originRegistry2) {
|
|
|
19048
19421
|
}
|
|
19049
19422
|
function createRelayPoolAdapter(shellHooks, originRegistry2) {
|
|
19050
19423
|
return {
|
|
19051
|
-
subscribeToRelays(
|
|
19424
|
+
subscribeToRelays(relayUrls2, filters, callback) {
|
|
19052
19425
|
const pool = shellHooks.relayPool.getRelayPool();
|
|
19053
19426
|
if (!pool) return { unsubscribe() {
|
|
19054
19427
|
} };
|
|
19055
|
-
const sub = pool.subscription([...
|
|
19428
|
+
const sub = pool.subscription([...relayUrls2], filters).subscribe((item) => {
|
|
19056
19429
|
callback(item === "EOSE" ? "EOSE" : item);
|
|
19057
19430
|
});
|
|
19058
19431
|
return { unsubscribe: () => sub.unsubscribe() };
|
|
19059
19432
|
},
|
|
19060
|
-
publishToRelays(
|
|
19433
|
+
publishToRelays(relayUrls2, event) {
|
|
19061
19434
|
const pool = shellHooks.relayPool.getRelayPool();
|
|
19062
19435
|
if (!pool) return;
|
|
19063
|
-
return pool.publish([...
|
|
19436
|
+
return pool.publish([...relayUrls2], event);
|
|
19064
19437
|
},
|
|
19065
|
-
subscribe(filters, callback,
|
|
19438
|
+
subscribe(filters, callback, relayUrls2) {
|
|
19066
19439
|
const pool = shellHooks.relayPool.getRelayPool();
|
|
19067
19440
|
if (!pool) return { unsubscribe() {
|
|
19068
19441
|
} };
|
|
19069
|
-
const urls =
|
|
19442
|
+
const urls = relayUrls2 ?? shellHooks.relayPool.selectRelayTier(filters);
|
|
19070
19443
|
const sub = pool.subscription(urls, filters).subscribe((item) => {
|
|
19071
19444
|
if (item === "EOSE") callback("EOSE");
|
|
19072
19445
|
else callback(item);
|
|
@@ -19076,8 +19449,8 @@ function createRelayPoolAdapter(shellHooks, originRegistry2) {
|
|
|
19076
19449
|
publish(event) {
|
|
19077
19450
|
const pool = shellHooks.relayPool.getRelayPool();
|
|
19078
19451
|
if (!pool) return;
|
|
19079
|
-
const
|
|
19080
|
-
return pool.publish(
|
|
19452
|
+
const relayUrls2 = shellHooks.relayPool.selectRelayTier([]);
|
|
19453
|
+
return pool.publish(relayUrls2, event);
|
|
19081
19454
|
},
|
|
19082
19455
|
selectRelayTier(filters) {
|
|
19083
19456
|
return shellHooks.relayPool.selectRelayTier(filters);
|
|
@@ -20676,7 +21049,7 @@ function createIntentUriNormalizer() {
|
|
|
20676
21049
|
if (!/^[a-z0-9][a-z0-9-]*$/u.test(archetype) || !/^[a-z0-9][a-z0-9-]*$/u.test(action)) {
|
|
20677
21050
|
fail2("Intent URI archetype and action must be lowercase slugs");
|
|
20678
21051
|
}
|
|
20679
|
-
const
|
|
21052
|
+
const query2 = match[3];
|
|
20680
21053
|
const fragment = match[4];
|
|
20681
21054
|
const supplied = options2 === void 0 ? {} : options2;
|
|
20682
21055
|
if (!supplied || typeof supplied !== "object" || Array.isArray(supplied)) fail2("Intent options must be an object");
|
|
@@ -20699,11 +21072,11 @@ function createIntentUriNormalizer() {
|
|
|
20699
21072
|
};
|
|
20700
21073
|
}
|
|
20701
21074
|
let payload;
|
|
20702
|
-
if (
|
|
21075
|
+
if (query2 !== void 0) {
|
|
20703
21076
|
if (hasOwn2(parsedOptions, "payload")) fail2("Intent URI query cannot accompany options.payload");
|
|
20704
|
-
if (
|
|
21077
|
+
if (query2.length > 0) {
|
|
20705
21078
|
const fields = /* @__PURE__ */ Object.create(null);
|
|
20706
|
-
for (const field of
|
|
21079
|
+
for (const field of query2.split("&")) {
|
|
20707
21080
|
const equal = field.indexOf("=");
|
|
20708
21081
|
if (equal <= 0 || field.indexOf("=", equal + 1) >= 0) fail2("Intent URI query fields must be name=value");
|
|
20709
21082
|
const name = decode2(field.slice(0, equal), "a query name");
|
|
@@ -20935,9 +21308,9 @@ function nappletNamespacePrelude(domains, normalizeIntentUri2, frameLock) {
|
|
|
20935
21308
|
}
|
|
20936
21309
|
const entries2 = [];
|
|
20937
21310
|
const names = /* @__PURE__ */ new Set();
|
|
20938
|
-
const
|
|
20939
|
-
if (
|
|
20940
|
-
for (const pair of
|
|
21311
|
+
const query2 = topic.slice(queryStart + 1);
|
|
21312
|
+
if (query2) {
|
|
21313
|
+
for (const pair of query2.split("&")) {
|
|
20941
21314
|
const separator = pair.indexOf("=");
|
|
20942
21315
|
if (separator < 0) {
|
|
20943
21316
|
throw new TypeError("Convention query parameters must use name=value form");
|
|
@@ -21741,8 +22114,8 @@ function nappletNamespacePrelude(domains, normalizeIntentUri2, frameLock) {
|
|
|
21741
22114
|
urls: Array.from(urls || [])
|
|
21742
22115
|
}, "resource.bytesMany.result", (msg) => Array.isArray(msg.items) ? msg.items.map((item) => {
|
|
21743
22116
|
if (!item || typeof item !== "object") throw new TypeError("resource bulk result is malformed");
|
|
21744
|
-
const
|
|
21745
|
-
return
|
|
22117
|
+
const record6 = item;
|
|
22118
|
+
return record6.ok === true ? { ...item, blob: decode2(record6.blob, record6.mime) } : item;
|
|
21746
22119
|
}) : [], {
|
|
21747
22120
|
timeoutMs: null,
|
|
21748
22121
|
signal: options2?.signal,
|
|
@@ -21825,12 +22198,12 @@ function nappletNamespacePrelude(domains, normalizeIntentUri2, frameLock) {
|
|
|
21825
22198
|
};
|
|
21826
22199
|
return {
|
|
21827
22200
|
registry: {
|
|
21828
|
-
list: (
|
|
22201
|
+
list: (query2) => req("cvm.registry.list", query2 === void 0 ? {} : { query: query2 }, (msg) => fieldOrThrow(msg, "entries", "cvm.registry.list.result missing entries")),
|
|
21829
22202
|
has: (selector2, options2) => registryRequest("has", selector2, options2),
|
|
21830
22203
|
describe: (selector2, options2) => registryRequest("describe", selector2, options2),
|
|
21831
22204
|
call: (selector2, tool2, args, options2) => registryRequest("call", selector2, options2, { tool: tool2, ...args === void 0 ? {} : { args } })
|
|
21832
22205
|
},
|
|
21833
|
-
discover: (
|
|
22206
|
+
discover: (query2) => req("cvm.discover", query2 === void 0 ? {} : { query: query2 }, (msg) => Array.isArray(msg.servers) ? msg.servers : []),
|
|
21834
22207
|
request: cvmRequest,
|
|
21835
22208
|
listTools: async (server, options2) => {
|
|
21836
22209
|
const result3 = await mcpCall(server, "tools/list", void 0, options2);
|
|
@@ -22257,8 +22630,8 @@ function nappletNamespacePrelude(domains, normalizeIntentUri2, frameLock) {
|
|
|
22257
22630
|
const req = (type, payload) => request({ type, ...payload }, `${type}.result`, withoutEnvelope, { rejectOnError: false });
|
|
22258
22631
|
return {
|
|
22259
22632
|
status: () => req("dm.status", {}),
|
|
22260
|
-
conversations: (
|
|
22261
|
-
messages: (
|
|
22633
|
+
conversations: (query2) => req("dm.conversations", query2 ?? {}),
|
|
22634
|
+
messages: (query2) => req("dm.messages", query2 ?? {}),
|
|
22262
22635
|
send: (requestPayload) => req("dm.send", requestPayload ?? {}),
|
|
22263
22636
|
subscribe: (requestPayload) => req("dm.subscribe", requestPayload ?? {}),
|
|
22264
22637
|
unsubscribe: (subscriptionId) => req("dm.unsubscribe", { subscriptionId }),
|
|
@@ -23983,7 +24356,7 @@ function normalizeRecord(input) {
|
|
|
23983
24356
|
if (credentialHeader !== void 0 && !CREDENTIAL_HEADERS.has(credentialHeader)) throw new Error("Unknown credential header.");
|
|
23984
24357
|
if (!["vault", "session", "none"].includes(credentialStorage)) throw new Error("Unknown credential storage.");
|
|
23985
24358
|
const tools = input.tools === true;
|
|
23986
|
-
const
|
|
24359
|
+
const record6 = {
|
|
23987
24360
|
id,
|
|
23988
24361
|
name,
|
|
23989
24362
|
presetId: text3(input.presetId).slice(0, 64),
|
|
@@ -23997,7 +24370,7 @@ function normalizeRecord(input) {
|
|
|
23997
24370
|
credentialStorage,
|
|
23998
24371
|
...credentialHeader ? { credentialHeader } : {}
|
|
23999
24372
|
};
|
|
24000
|
-
return Object.freeze(
|
|
24373
|
+
return Object.freeze(record6);
|
|
24001
24374
|
}
|
|
24002
24375
|
function readRecords(storage) {
|
|
24003
24376
|
if (!storage) return [];
|
|
@@ -24036,9 +24409,9 @@ function createPajaLlmConnectionStore(storage = storageOrNull()) {
|
|
|
24036
24409
|
};
|
|
24037
24410
|
return {
|
|
24038
24411
|
list: () => records,
|
|
24039
|
-
get: (id) => records.find((
|
|
24040
|
-
save(
|
|
24041
|
-
const normalized2 = normalizeRecord({ ...
|
|
24412
|
+
get: (id) => records.find((record6) => record6.id === id),
|
|
24413
|
+
save(record6) {
|
|
24414
|
+
const normalized2 = normalizeRecord({ ...record6 });
|
|
24042
24415
|
const index = records.findIndex((entry) => entry.id === normalized2.id);
|
|
24043
24416
|
if (index === -1 && records.length >= MAX_CONNECTIONS) throw new Error(`Paja keeps at most ${MAX_CONNECTIONS} connections.`);
|
|
24044
24417
|
records = index === -1 ? [...records, normalized2] : records.map((entry, position) => position === index ? normalized2 : entry);
|
|
@@ -24046,7 +24419,7 @@ function createPajaLlmConnectionStore(storage = storageOrNull()) {
|
|
|
24046
24419
|
return normalized2;
|
|
24047
24420
|
},
|
|
24048
24421
|
remove(id) {
|
|
24049
|
-
const next = records.filter((
|
|
24422
|
+
const next = records.filter((record6) => record6.id !== id);
|
|
24050
24423
|
if (next.length === records.length) return false;
|
|
24051
24424
|
records = next;
|
|
24052
24425
|
persist();
|
|
@@ -24058,30 +24431,30 @@ function createPajaLlmConnectionStore(storage = storageOrNull()) {
|
|
|
24058
24431
|
}
|
|
24059
24432
|
};
|
|
24060
24433
|
}
|
|
24061
|
-
function describePajaLlmRoute(
|
|
24062
|
-
const preset = LLM_PROVIDER_PRESETS.find((entry) => entry.id ===
|
|
24063
|
-
const origin = new URL(
|
|
24434
|
+
function describePajaLlmRoute(record6) {
|
|
24435
|
+
const preset = LLM_PROVIDER_PRESETS.find((entry) => entry.id === record6.presetId);
|
|
24436
|
+
const origin = new URL(record6.baseUrl).origin;
|
|
24064
24437
|
const label = preset && preset.id !== "custom" ? `${preset.label} at ${origin}` : origin;
|
|
24065
24438
|
return `Paja (this browser) \u2192 ${label}`;
|
|
24066
24439
|
}
|
|
24067
|
-
function toConnection(
|
|
24068
|
-
const tools =
|
|
24440
|
+
function toConnection(record6) {
|
|
24441
|
+
const tools = record6.tools === true;
|
|
24069
24442
|
return {
|
|
24070
|
-
id:
|
|
24071
|
-
name:
|
|
24072
|
-
model:
|
|
24073
|
-
route: describePajaLlmRoute(
|
|
24074
|
-
images:
|
|
24075
|
-
json:
|
|
24443
|
+
id: record6.id,
|
|
24444
|
+
name: record6.name,
|
|
24445
|
+
model: record6.model,
|
|
24446
|
+
route: describePajaLlmRoute(record6),
|
|
24447
|
+
images: record6.images,
|
|
24448
|
+
json: record6.json,
|
|
24076
24449
|
tools,
|
|
24077
|
-
toolChoiceModes: tools ? canonicalToolChoiceModes(true,
|
|
24450
|
+
toolChoiceModes: tools ? canonicalToolChoiceModes(true, record6.toolChoiceModes) : []
|
|
24078
24451
|
};
|
|
24079
24452
|
}
|
|
24080
|
-
function meets(
|
|
24081
|
-
if (requirements3.model !== void 0 && requirements3.model !==
|
|
24082
|
-
if (requirements3.images === true && !
|
|
24083
|
-
if (requirements3.tools === true &&
|
|
24084
|
-
return !(requirements3.json === true && !
|
|
24453
|
+
function meets(record6, requirements3) {
|
|
24454
|
+
if (requirements3.model !== void 0 && requirements3.model !== record6.model) return false;
|
|
24455
|
+
if (requirements3.images === true && !record6.images) return false;
|
|
24456
|
+
if (requirements3.tools === true && record6.tools !== true) return false;
|
|
24457
|
+
return !(requirements3.json === true && !record6.json);
|
|
24085
24458
|
}
|
|
24086
24459
|
function describeRequirements2(requirements3) {
|
|
24087
24460
|
const parts = [
|
|
@@ -24109,20 +24482,20 @@ function countToolResults(request) {
|
|
|
24109
24482
|
function createPajaLlmHost(options2) {
|
|
24110
24483
|
const { store: store2, vault, confirm, getIdentity } = options2;
|
|
24111
24484
|
const provider = options2.provider ?? createHttpLlmProvider({ stream: true });
|
|
24112
|
-
function endpointFor(
|
|
24485
|
+
function endpointFor(record6, credential) {
|
|
24113
24486
|
return {
|
|
24114
|
-
protocol:
|
|
24115
|
-
baseUrl:
|
|
24116
|
-
model:
|
|
24487
|
+
protocol: record6.protocol,
|
|
24488
|
+
baseUrl: record6.baseUrl,
|
|
24489
|
+
model: record6.model,
|
|
24117
24490
|
...credential === void 0 ? {} : { credential },
|
|
24118
|
-
...
|
|
24491
|
+
...record6.credentialHeader ? { credentialHeader: record6.credentialHeader } : {}
|
|
24119
24492
|
};
|
|
24120
24493
|
}
|
|
24121
|
-
async function ensureCredential(
|
|
24122
|
-
if (
|
|
24123
|
-
const existing = vault.getCredential(
|
|
24494
|
+
async function ensureCredential(record6, signal) {
|
|
24495
|
+
if (record6.credentialStorage === "none") return void 0;
|
|
24496
|
+
const existing = vault.getCredential(record6.id);
|
|
24124
24497
|
if (existing !== void 0) return existing;
|
|
24125
|
-
if (
|
|
24498
|
+
if (record6.credentialStorage === "session") {
|
|
24126
24499
|
options2.openPanel();
|
|
24127
24500
|
throw new LlmServiceError("unsupported", "This connection's API key was kept for one session only. Enter it again in Language models.");
|
|
24128
24501
|
}
|
|
@@ -24130,7 +24503,7 @@ function createPajaLlmHost(options2) {
|
|
|
24130
24503
|
const unlocked = await options2.requestUnlock(signal);
|
|
24131
24504
|
if (!unlocked) throw new LlmServiceError("user-cancelled", "The credential vault stayed locked.");
|
|
24132
24505
|
}
|
|
24133
|
-
const credential = vault.getCredential(
|
|
24506
|
+
const credential = vault.getCredential(record6.id);
|
|
24134
24507
|
if (credential === void 0) {
|
|
24135
24508
|
options2.openPanel();
|
|
24136
24509
|
throw new LlmServiceError("unsupported", "No API key is stored for this connection. Enter it again in Language models.");
|
|
@@ -24140,7 +24513,7 @@ function createPajaLlmHost(options2) {
|
|
|
24140
24513
|
async function select3(context, requirements3, prompt) {
|
|
24141
24514
|
const signal = prompt?.signal;
|
|
24142
24515
|
const napplet = getIdentity(context.windowId);
|
|
24143
|
-
const candidates = store2.list().filter((
|
|
24516
|
+
const candidates = store2.list().filter((record6) => meets(record6, requirements3));
|
|
24144
24517
|
if (candidates.length === 0) {
|
|
24145
24518
|
const configure = await confirm({ action: "llm-configure", windowId: context.windowId, napplet, requirements: describeRequirements2(requirements3), configured: store2.list().length, ...signal ? { signal } : {} });
|
|
24146
24519
|
if (!configure) return null;
|
|
@@ -24156,24 +24529,24 @@ function createPajaLlmHost(options2) {
|
|
|
24156
24529
|
isConfigured: () => store2.list().length > 0,
|
|
24157
24530
|
select: select3,
|
|
24158
24531
|
describe(_context, connectionId) {
|
|
24159
|
-
const
|
|
24160
|
-
return
|
|
24532
|
+
const record6 = store2.get(connectionId);
|
|
24533
|
+
return record6 ? toConnection(record6) : null;
|
|
24161
24534
|
},
|
|
24162
24535
|
async authorize(context, connection, request, prompt) {
|
|
24163
24536
|
const signal = prompt?.signal;
|
|
24164
|
-
const
|
|
24165
|
-
if (!
|
|
24166
|
-
buildLlmProviderRequest(endpointFor(
|
|
24167
|
-
await ensureCredential(
|
|
24537
|
+
const record6 = store2.get(connection.id);
|
|
24538
|
+
if (!record6) throw new LlmServiceError("selection-expired", "The selected connection was removed; select again.");
|
|
24539
|
+
buildLlmProviderRequest(endpointFor(record6), request, { stream: true });
|
|
24540
|
+
await ensureCredential(record6, signal);
|
|
24168
24541
|
if (signal?.aborted) return false;
|
|
24169
24542
|
return confirm({
|
|
24170
24543
|
...signal ? { signal } : {},
|
|
24171
24544
|
action: "llm",
|
|
24172
24545
|
windowId: context.windowId,
|
|
24173
24546
|
napplet: getIdentity(context.windowId),
|
|
24174
|
-
connection:
|
|
24175
|
-
model:
|
|
24176
|
-
route: describePajaLlmRoute(
|
|
24547
|
+
connection: record6.name,
|
|
24548
|
+
model: record6.model,
|
|
24549
|
+
route: describePajaLlmRoute(record6),
|
|
24177
24550
|
messages: request.messages.length,
|
|
24178
24551
|
characters: countCharacters(request),
|
|
24179
24552
|
images: countLlmImages(request.messages),
|
|
@@ -24184,10 +24557,10 @@ function createPajaLlmHost(options2) {
|
|
|
24184
24557
|
});
|
|
24185
24558
|
},
|
|
24186
24559
|
async generate(_context, connection, request, hooks) {
|
|
24187
|
-
const
|
|
24188
|
-
if (!
|
|
24189
|
-
const credential = await ensureCredential(
|
|
24190
|
-
return provider(endpointFor(
|
|
24560
|
+
const record6 = store2.get(connection.id);
|
|
24561
|
+
if (!record6) throw new LlmServiceError("selection-expired", "The selected connection was removed; select again.");
|
|
24562
|
+
const credential = await ensureCredential(record6);
|
|
24563
|
+
return provider(endpointFor(record6, credential), request, hooks.signal, (event) => hooks.onDelta(event));
|
|
24191
24564
|
},
|
|
24192
24565
|
subscribe(listener) {
|
|
24193
24566
|
const stopStore = store2.subscribe(listener);
|
|
@@ -24462,17 +24835,17 @@ function createChooserDialog() {
|
|
|
24462
24835
|
if (context.signal?.aborted) return Promise.resolve(null);
|
|
24463
24836
|
const wanted = [context.requirements.model ? `model ${context.requirements.model}` : null, context.requirements.images ? "image input" : null, context.requirements.json ? "JSON output" : null, context.requirements.tools ? "tool calling" : null].filter(Boolean).join(", ");
|
|
24464
24837
|
copy.textContent = `${context.napplet.dTag} (${context.windowId}) asks to use a language model${wanted ? ` with ${wanted}` : ""}. Selecting does not send anything yet; each generation asks for consent.`;
|
|
24465
|
-
select3.replaceChildren(...candidates.map((
|
|
24838
|
+
select3.replaceChildren(...candidates.map((record6) => {
|
|
24466
24839
|
const option = document.createElement("option");
|
|
24467
|
-
option.value =
|
|
24468
|
-
option.textContent = `${
|
|
24840
|
+
option.value = record6.id;
|
|
24841
|
+
option.textContent = `${record6.name} \u2014 ${record6.model} (${new URL(record6.baseUrl).origin})`;
|
|
24469
24842
|
return option;
|
|
24470
24843
|
}));
|
|
24471
24844
|
select3.selectedIndex = candidates.length > 0 ? 0 : -1;
|
|
24472
24845
|
return new Promise((resolve) => {
|
|
24473
24846
|
const mine = (value) => {
|
|
24474
24847
|
detach();
|
|
24475
|
-
resolve(candidates.find((
|
|
24848
|
+
resolve(candidates.find((record6) => record6.id === value) ?? null);
|
|
24476
24849
|
};
|
|
24477
24850
|
const detach = withdrawOnAbort(context.signal, () => {
|
|
24478
24851
|
if (settle4 === mine) finish(null);
|
|
@@ -24653,21 +25026,21 @@ function installPajaLlmPanel(options2) {
|
|
|
24653
25026
|
}
|
|
24654
25027
|
function renderList() {
|
|
24655
25028
|
if (!elements) return;
|
|
24656
|
-
const rows = store2.list().map((
|
|
25029
|
+
const rows = store2.list().map((record6) => {
|
|
24657
25030
|
const item = document.createElement("li");
|
|
24658
25031
|
item.className = "llm-connection";
|
|
24659
|
-
item.dataset.llmConnection =
|
|
25032
|
+
item.dataset.llmConnection = record6.id;
|
|
24660
25033
|
const label = document.createElement("span");
|
|
24661
25034
|
label.className = "llm-connection-label";
|
|
24662
|
-
const tier =
|
|
24663
|
-
label.textContent = `${
|
|
24664
|
-
label.title = `${
|
|
25035
|
+
const tier = record6.credentialStorage === "vault" ? vault.isUnlocked() ? "key unlocked" : "key encrypted, locked" : record6.credentialStorage === "session" ? vault.getCredential(record6.id) ? "key for this session" : "key missing" : "no key";
|
|
25036
|
+
label.textContent = `${record6.name} \xB7 ${record6.model} \xB7 ${new URL(record6.baseUrl).origin} \xB7 ${tier}`;
|
|
25037
|
+
label.title = `${record6.protocol}${record6.images ? " \xB7 images" : ""}${record6.json ? " \xB7 json" : ""}${record6.tools ? " \xB7 tools" : ""}`;
|
|
24665
25038
|
const remove = document.createElement("button");
|
|
24666
25039
|
remove.type = "button";
|
|
24667
25040
|
remove.textContent = "Remove";
|
|
24668
|
-
remove.setAttribute("aria-label", `Remove connection ${
|
|
25041
|
+
remove.setAttribute("aria-label", `Remove connection ${record6.name}`);
|
|
24669
25042
|
remove.addEventListener("click", () => {
|
|
24670
|
-
void removeConnection(
|
|
25043
|
+
void removeConnection(record6);
|
|
24671
25044
|
});
|
|
24672
25045
|
item.append(label, remove);
|
|
24673
25046
|
return item;
|
|
@@ -24676,16 +25049,16 @@ function installPajaLlmPanel(options2) {
|
|
|
24676
25049
|
elements.lock.hidden = !vault.isUnlocked();
|
|
24677
25050
|
if (rows.length === 0) setStatus2("No model connections yet. Napplets asking for a model see an explicit unsupported result until you add one.");
|
|
24678
25051
|
}
|
|
24679
|
-
async function removeConnection(
|
|
24680
|
-
if (
|
|
25052
|
+
async function removeConnection(record6) {
|
|
25053
|
+
if (record6.credentialStorage === "vault" && !vault.isUnlocked() && vault.hasStoredSecrets()) {
|
|
24681
25054
|
if (!await requestUnlock()) {
|
|
24682
25055
|
setStatus2("Unlock the vault to remove a connection with a remembered key.", true);
|
|
24683
25056
|
return;
|
|
24684
25057
|
}
|
|
24685
25058
|
}
|
|
24686
|
-
await vault.removeCredential(
|
|
24687
|
-
store2.remove(
|
|
24688
|
-
setStatus2(`Removed ${
|
|
25059
|
+
await vault.removeCredential(record6.id);
|
|
25060
|
+
store2.remove(record6.id);
|
|
25061
|
+
setStatus2(`Removed ${record6.name}.`);
|
|
24689
25062
|
renderList();
|
|
24690
25063
|
options2.onChange?.();
|
|
24691
25064
|
}
|
|
@@ -24704,9 +25077,9 @@ function installPajaLlmPanel(options2) {
|
|
|
24704
25077
|
setModelStatus("Choose or type a model id.", "error");
|
|
24705
25078
|
return;
|
|
24706
25079
|
}
|
|
24707
|
-
let
|
|
25080
|
+
let record6;
|
|
24708
25081
|
try {
|
|
24709
|
-
|
|
25082
|
+
record6 = {
|
|
24710
25083
|
id: createId(),
|
|
24711
25084
|
name: elements.name.value,
|
|
24712
25085
|
presetId: preset?.id ?? "custom",
|
|
@@ -24724,8 +25097,8 @@ function installPajaLlmPanel(options2) {
|
|
|
24724
25097
|
setStatus2("The key was not saved: the vault stayed locked.", true);
|
|
24725
25098
|
return;
|
|
24726
25099
|
}
|
|
24727
|
-
if (storage !== "none") await vault.setCredential(
|
|
24728
|
-
store2.save(
|
|
25100
|
+
if (storage !== "none") await vault.setCredential(record6.id, credential, storage);
|
|
25101
|
+
store2.save(record6);
|
|
24729
25102
|
} catch (error) {
|
|
24730
25103
|
setStatus2(error instanceof Error ? error.message : "Could not save the connection.", true);
|
|
24731
25104
|
return;
|
|
@@ -24733,7 +25106,7 @@ function installPajaLlmPanel(options2) {
|
|
|
24733
25106
|
elements.credential.value = "";
|
|
24734
25107
|
elements.name.value = "";
|
|
24735
25108
|
elements.model.value = "";
|
|
24736
|
-
setStatus2(storage === "vault" ? `Saved ${
|
|
25109
|
+
setStatus2(storage === "vault" ? `Saved ${record6.name}; its key is encrypted in the vault.` : storage === "session" ? `Saved ${record6.name}; its key lasts until this page closes.` : `Saved ${record6.name} without a key.`);
|
|
24737
25110
|
renderList();
|
|
24738
25111
|
options2.onChange?.();
|
|
24739
25112
|
}
|
|
@@ -24850,6 +25223,7 @@ var SECTION_IDS = {
|
|
|
24850
25223
|
acl: "paja-section-acl",
|
|
24851
25224
|
signer: "paja-section-signer",
|
|
24852
25225
|
"resource-servers": "paja-section-resource-servers",
|
|
25226
|
+
multiplayer: "paja-section-multiplayer",
|
|
24853
25227
|
llm: "paja-section-llm",
|
|
24854
25228
|
messages: "paja-section-messages",
|
|
24855
25229
|
events: "paja-section-events"
|
|
@@ -24872,7 +25246,7 @@ function installPajaSidebarSections() {
|
|
|
24872
25246
|
for (const key of keys) {
|
|
24873
25247
|
const section = document.getElementById(SECTION_IDS[key]);
|
|
24874
25248
|
if (!section) continue;
|
|
24875
|
-
section.open = collapsed[key]
|
|
25249
|
+
if (collapsed[key] !== void 0) section.open = !collapsed[key];
|
|
24876
25250
|
let lastOpen = section.open;
|
|
24877
25251
|
const toggle = () => {
|
|
24878
25252
|
if (section.open === lastOpen) return;
|
|
@@ -26641,15 +27015,15 @@ function createNostrCvmTransport(options2 = {}) {
|
|
|
26641
27015
|
return session.initializing;
|
|
26642
27016
|
}
|
|
26643
27017
|
return {
|
|
26644
|
-
planDiscover(
|
|
26645
|
-
const relays =
|
|
27018
|
+
planDiscover(query2) {
|
|
27019
|
+
const relays = query2?.relays && query2.relays.length > 0 ? query2.relays : defaultRelays;
|
|
26646
27020
|
return Object.freeze([...new Set(relays.map(canonicalRelay))]);
|
|
26647
27021
|
},
|
|
26648
27022
|
planRequest(server) {
|
|
26649
27023
|
return Object.freeze(resolveRelays(server));
|
|
26650
27024
|
},
|
|
26651
|
-
async discover(
|
|
26652
|
-
const configured =
|
|
27025
|
+
async discover(query2, execution) {
|
|
27026
|
+
const configured = query2?.relays && query2.relays.length > 0 ? query2.relays : defaultRelays;
|
|
26653
27027
|
const relays = [...new Set(configured.map(canonicalRelay))];
|
|
26654
27028
|
if (relays.length === 0) return [];
|
|
26655
27029
|
if (execution?.signal.aborted) throw new Error("policy denied");
|
|
@@ -26658,7 +27032,7 @@ function createNostrCvmTransport(options2 = {}) {
|
|
|
26658
27032
|
await new Promise((resolve, reject2) => {
|
|
26659
27033
|
const sub = pool.subscribe(
|
|
26660
27034
|
relays,
|
|
26661
|
-
{ kinds: [KIND_ANNOUNCE_SERVER, KIND_ANNOUNCE_TOOLS], limit:
|
|
27035
|
+
{ kinds: [KIND_ANNOUNCE_SERVER, KIND_ANNOUNCE_TOOLS], limit: query2?.limit ? query2.limit * 4 : 100 },
|
|
26662
27036
|
{
|
|
26663
27037
|
onevent(event) {
|
|
26664
27038
|
if (event.kind === KIND_ANNOUNCE_SERVER) announces.set(event.pubkey, event);
|
|
@@ -26697,9 +27071,9 @@ function createNostrCvmTransport(options2 = {}) {
|
|
|
26697
27071
|
}
|
|
26698
27072
|
servers.push(server);
|
|
26699
27073
|
}
|
|
26700
|
-
const search =
|
|
27074
|
+
const search = query2?.search?.toLowerCase();
|
|
26701
27075
|
const filtered = search ? servers.filter((s) => `${s.name ?? ""} ${s.description ?? ""}`.toLowerCase().includes(search)) : servers;
|
|
26702
|
-
return
|
|
27076
|
+
return query2?.limit ? filtered.slice(0, query2.limit) : filtered;
|
|
26703
27077
|
},
|
|
26704
27078
|
async request(server, message3, requestOptions, execution) {
|
|
26705
27079
|
if (execution?.signal.aborted) throw new Error("policy denied");
|
|
@@ -27134,7 +27508,7 @@ function createBrowserBleController(activation, api = browserBluetoothApi()) {
|
|
|
27134
27508
|
function createPajaCatalogIntentService(adapter, host) {
|
|
27135
27509
|
const resolver = createCatalogIntentResolver({
|
|
27136
27510
|
loadCatalog: () => host.catalog.intentCatalog(
|
|
27137
|
-
(
|
|
27511
|
+
(record6) => resolveShellEnvironment(adapter, record6).capabilities.domains.includes("intent")
|
|
27138
27512
|
),
|
|
27139
27513
|
targets: host.controller,
|
|
27140
27514
|
getDefaultHandler: host.getDefaultHandler,
|
|
@@ -27199,8 +27573,8 @@ function relaySources(urls) {
|
|
|
27199
27573
|
}
|
|
27200
27574
|
return [...sources2].map(([url, source]) => ({ url, source }));
|
|
27201
27575
|
}
|
|
27202
|
-
function subscribePajaLive(pool,
|
|
27203
|
-
const sources2 = relaySources(
|
|
27576
|
+
function subscribePajaLive(pool, relayUrls2, filters, next, observe, maxWait, label = "kehto-paja-runtime") {
|
|
27577
|
+
const sources2 = relaySources(relayUrls2);
|
|
27204
27578
|
const activeFilters = filters.length ? filters : [{}];
|
|
27205
27579
|
const seen = /* @__PURE__ */ new Set();
|
|
27206
27580
|
const ended = /* @__PURE__ */ new Set();
|
|
@@ -27284,7 +27658,7 @@ function subscribePajaLive(pool, relayUrls3, filters, next, observe, maxWait, la
|
|
|
27284
27658
|
}
|
|
27285
27659
|
};
|
|
27286
27660
|
}
|
|
27287
|
-
async function queryPajaLive(pool,
|
|
27661
|
+
async function queryPajaLive(pool, relayUrls2, filters, maxWait, observe, collectUntilLimit = false, signal) {
|
|
27288
27662
|
const batches = await Promise.all((filters.length ? filters : [{}]).map((filter) => {
|
|
27289
27663
|
const limit = collectUntilLimit && typeof filter.limit === "number" && filter.limit >= 0 ? filter.limit : Infinity;
|
|
27290
27664
|
if (limit === 0 || signal?.aborted) return Promise.resolve([]);
|
|
@@ -27303,7 +27677,7 @@ async function queryPajaLive(pool, relayUrls3, filters, maxWait, observe, collec
|
|
|
27303
27677
|
const abort = () => finish("paja query aborted");
|
|
27304
27678
|
const timer = setTimeout(() => finish("paja query timeout"), maxWait);
|
|
27305
27679
|
signal?.addEventListener("abort", abort, { once: true });
|
|
27306
|
-
subscription = subscribePajaLive(pool,
|
|
27680
|
+
subscription = subscribePajaLive(pool, relayUrls2, [filter], (item) => {
|
|
27307
27681
|
if (finished2) return;
|
|
27308
27682
|
if (item === "EOSE") return finish("closed automatically on eose");
|
|
27309
27683
|
events2.push(item);
|
|
@@ -27365,13 +27739,13 @@ function collectMemoryEvents(events, filters) {
|
|
|
27365
27739
|
}
|
|
27366
27740
|
return [...out.values()].sort((a, b) => b.created_at - a.created_at);
|
|
27367
27741
|
}
|
|
27368
|
-
async function publishLive(pool,
|
|
27369
|
-
const results = await Promise.allSettled(pool.publish(
|
|
27370
|
-
return Object.fromEntries(
|
|
27742
|
+
async function publishLive(pool, relayUrls2, event) {
|
|
27743
|
+
const results = await Promise.allSettled(pool.publish(relayUrls2, event));
|
|
27744
|
+
return Object.fromEntries(relayUrls2.map((relayUrl2, index) => [relayUrl2, results[index]?.status === "fulfilled"]));
|
|
27371
27745
|
}
|
|
27372
|
-
async function countLive(pool,
|
|
27746
|
+
async function countLive(pool, relayUrls2, filters, signal) {
|
|
27373
27747
|
let failure4 = new Error("count unavailable");
|
|
27374
|
-
for (const relayUrl2 of
|
|
27748
|
+
for (const relayUrl2 of relayUrls2) {
|
|
27375
27749
|
if (signal?.aborted) throw new Error("count cancelled");
|
|
27376
27750
|
const controller = new AbortController();
|
|
27377
27751
|
let timeout;
|
|
@@ -27424,36 +27798,36 @@ function createPajaRelayBackend(getSimulation, confirmRequest, livePool = new Si
|
|
|
27424
27798
|
const subscribers = /* @__PURE__ */ new Set();
|
|
27425
27799
|
let relayEventObserver;
|
|
27426
27800
|
let relayRequestObserver;
|
|
27427
|
-
const observeRelayRequest = (context,
|
|
27428
|
-
if (
|
|
27429
|
-
relayRequestObserver?.({ ...context, relayUrls: [...
|
|
27801
|
+
const observeRelayRequest = (context, relayUrls2) => {
|
|
27802
|
+
if (relayUrls2.length === 0) return;
|
|
27803
|
+
relayRequestObserver?.({ ...context, relayUrls: [...relayUrls2] });
|
|
27430
27804
|
};
|
|
27431
27805
|
const attributeAuthors = (context, filters) => {
|
|
27432
27806
|
const authors = readAuthors(context.authors ?? filters.flatMap((filter) => filter.authors ?? []));
|
|
27433
27807
|
return authors.length === 0 && context.authors === void 0 ? context : { ...context, authors };
|
|
27434
27808
|
};
|
|
27435
|
-
const observeRelayEvent = (context,
|
|
27809
|
+
const observeRelayEvent = (context, relayUrls2, event, source) => {
|
|
27436
27810
|
relayEventObserver?.({
|
|
27437
27811
|
...context,
|
|
27438
|
-
relayUrls: [...
|
|
27812
|
+
relayUrls: [...relayUrls2],
|
|
27439
27813
|
event,
|
|
27440
27814
|
sightedOn: [source]
|
|
27441
27815
|
});
|
|
27442
27816
|
};
|
|
27443
27817
|
const isAvailable = () => getSimulation().relay.mode !== "disabled" && getPajaRelayUrls(getSimulation()).length > 0;
|
|
27444
27818
|
const cachedEvents = () => getSimulation().relay.mode === "memory" ? [...fixtureEvents, ...acceptedMemoryEvents] : [];
|
|
27445
|
-
const
|
|
27819
|
+
const query2 = async (relayUrls2, filters, maxWaitMs, context = { reason: "host" }, signal) => {
|
|
27446
27820
|
if (signal?.aborted) return [];
|
|
27447
27821
|
const cached = collectMemoryEvents(cachedEvents(), filters);
|
|
27448
|
-
if (getSimulation().relay.mode !== "live" ||
|
|
27822
|
+
if (getSimulation().relay.mode !== "live" || relayUrls2.length === 0) return cached;
|
|
27449
27823
|
const readContext = attributeAuthors(context, filters);
|
|
27450
|
-
observeRelayRequest(readContext,
|
|
27824
|
+
observeRelayRequest(readContext, relayUrls2);
|
|
27451
27825
|
const liveEvents = await queryPajaLive(
|
|
27452
27826
|
livePool,
|
|
27453
|
-
|
|
27827
|
+
relayUrls2,
|
|
27454
27828
|
filters,
|
|
27455
27829
|
maxWaitMs ?? PAJA_LIVE_QUERY_WAIT_MS,
|
|
27456
|
-
(event, source) => observeRelayEvent(readContext,
|
|
27830
|
+
(event, source) => observeRelayEvent(readContext, relayUrls2, event, source),
|
|
27457
27831
|
false,
|
|
27458
27832
|
signal
|
|
27459
27833
|
);
|
|
@@ -27461,17 +27835,17 @@ function createPajaRelayBackend(getSimulation, confirmRequest, livePool = new Si
|
|
|
27461
27835
|
for (const event of [...cached, ...liveEvents]) out.set(event.id, event);
|
|
27462
27836
|
return [...out.values()].sort((a, b) => b.created_at - a.created_at);
|
|
27463
27837
|
};
|
|
27464
|
-
const queryContactListCandidates = async (
|
|
27838
|
+
const queryContactListCandidates = async (relayUrls2, filters, maxWaitMs, signal) => {
|
|
27465
27839
|
const cached = collectMemoryEvents(cachedEvents(), filters);
|
|
27466
|
-
if (signal?.aborted || getSimulation().relay.mode !== "live" ||
|
|
27840
|
+
if (signal?.aborted || getSimulation().relay.mode !== "live" || relayUrls2.length === 0) return cached;
|
|
27467
27841
|
const readContext = attributeAuthors({ reason: "host" }, filters);
|
|
27468
|
-
observeRelayRequest(readContext,
|
|
27842
|
+
observeRelayRequest(readContext, relayUrls2);
|
|
27469
27843
|
const liveEvents = await queryPajaLive(
|
|
27470
27844
|
livePool,
|
|
27471
|
-
|
|
27845
|
+
relayUrls2,
|
|
27472
27846
|
filters,
|
|
27473
27847
|
maxWaitMs ?? PAJA_LIVE_QUERY_WAIT_MS,
|
|
27474
|
-
(event, source) => observeRelayEvent(readContext,
|
|
27848
|
+
(event, source) => observeRelayEvent(readContext, relayUrls2, event, source),
|
|
27475
27849
|
true,
|
|
27476
27850
|
signal
|
|
27477
27851
|
);
|
|
@@ -27486,16 +27860,16 @@ function createPajaRelayBackend(getSimulation, confirmRequest, livePool = new Si
|
|
|
27486
27860
|
if (matchesAnyFilter2(event, subscriber.filters)) subscriber.next(event);
|
|
27487
27861
|
}
|
|
27488
27862
|
}
|
|
27489
|
-
async function attemptPublish(
|
|
27863
|
+
async function attemptPublish(relayUrls2, event, signerContext) {
|
|
27490
27864
|
const simulation = getSimulation();
|
|
27491
|
-
const rejected2 = Object.fromEntries(
|
|
27865
|
+
const rejected2 = Object.fromEntries(relayUrls2.map((url) => [url, false]));
|
|
27492
27866
|
if (simulation.relay.mode === "disabled") {
|
|
27493
27867
|
return { outcomes: rejected2, error: "relay unavailable" };
|
|
27494
27868
|
}
|
|
27495
27869
|
if (signerContext?.isCurrent && !signerContext.isCurrent() || !await confirmRequest({ action: "publish", event, ...signerContext ? { signerContext } : {} }) || signerContext?.isCurrent && !signerContext.isCurrent()) {
|
|
27496
27870
|
return { outcomes: rejected2, error: "publish denied" };
|
|
27497
27871
|
}
|
|
27498
|
-
const outcomes = simulation.relay.mode === "live" ? await publishLive(livePool,
|
|
27872
|
+
const outcomes = simulation.relay.mode === "live" ? await publishLive(livePool, relayUrls2, event) : Object.fromEntries(relayUrls2.map((url) => [url, true]));
|
|
27499
27873
|
if (!Object.values(outcomes).some(Boolean)) {
|
|
27500
27874
|
return { outcomes, error: "publish failed" };
|
|
27501
27875
|
}
|
|
@@ -27503,7 +27877,7 @@ function createPajaRelayBackend(getSimulation, confirmRequest, livePool = new Si
|
|
|
27503
27877
|
return { outcomes };
|
|
27504
27878
|
}
|
|
27505
27879
|
const backend = {
|
|
27506
|
-
subscription(
|
|
27880
|
+
subscription(relayUrls2, filtersInput, context = { reason: "host" }) {
|
|
27507
27881
|
return {
|
|
27508
27882
|
subscribe(next) {
|
|
27509
27883
|
const filters = normalizedFilters(filtersInput);
|
|
@@ -27514,13 +27888,13 @@ function createPajaRelayBackend(getSimulation, confirmRequest, livePool = new Si
|
|
|
27514
27888
|
subscribers.add(subscriber);
|
|
27515
27889
|
for (const event of collectMemoryEvents(cachedEvents(), filters)) next(event);
|
|
27516
27890
|
const readContext = attributeAuthors(context, filters);
|
|
27517
|
-
if (getSimulation().relay.mode === "live") observeRelayRequest(readContext,
|
|
27891
|
+
if (getSimulation().relay.mode === "live") observeRelayRequest(readContext, relayUrls2);
|
|
27518
27892
|
const liveSub = getSimulation().relay.mode === "live" ? subscribePajaLive(
|
|
27519
27893
|
livePool,
|
|
27520
|
-
|
|
27894
|
+
relayUrls2,
|
|
27521
27895
|
filters,
|
|
27522
27896
|
subscriber.next,
|
|
27523
|
-
(event, source) => observeRelayEvent(readContext,
|
|
27897
|
+
(event, source) => observeRelayEvent(readContext, relayUrls2, event, source),
|
|
27524
27898
|
PAJA_LIVE_QUERY_WAIT_MS
|
|
27525
27899
|
) : null;
|
|
27526
27900
|
queueMicrotask(() => {
|
|
@@ -27535,16 +27909,16 @@ function createPajaRelayBackend(getSimulation, confirmRequest, livePool = new Si
|
|
|
27535
27909
|
}
|
|
27536
27910
|
};
|
|
27537
27911
|
},
|
|
27538
|
-
async publish(
|
|
27539
|
-
const attempt = await attemptPublish(
|
|
27912
|
+
async publish(relayUrls2, event, signerContext) {
|
|
27913
|
+
const attempt = await attemptPublish(relayUrls2, event, signerContext);
|
|
27540
27914
|
if (attempt.error) throw new Error(attempt.error);
|
|
27541
27915
|
},
|
|
27542
|
-
request(
|
|
27916
|
+
request(relayUrls2, filtersInput, context = { reason: "host" }) {
|
|
27543
27917
|
return {
|
|
27544
27918
|
subscribe(observer) {
|
|
27545
27919
|
const filters = normalizedFilters(filtersInput);
|
|
27546
27920
|
let active = true;
|
|
27547
|
-
|
|
27921
|
+
query2(relayUrls2, filters, void 0, context).then((matched) => {
|
|
27548
27922
|
if (!active) return;
|
|
27549
27923
|
for (const event of matched) observer.next(event);
|
|
27550
27924
|
observer.complete();
|
|
@@ -27557,15 +27931,15 @@ function createPajaRelayBackend(getSimulation, confirmRequest, livePool = new Si
|
|
|
27557
27931
|
}
|
|
27558
27932
|
};
|
|
27559
27933
|
},
|
|
27560
|
-
async count(
|
|
27934
|
+
async count(relayUrls2, filters) {
|
|
27561
27935
|
if (getSimulation().relay.mode !== "live") throw new Error("count unavailable");
|
|
27562
|
-
return (await countLive(livePool,
|
|
27936
|
+
return (await countLive(livePool, relayUrls2, normalizedFilters(filters))).count;
|
|
27563
27937
|
},
|
|
27564
|
-
async countWithRelay(
|
|
27938
|
+
async countWithRelay(relayUrls2, filters, signal) {
|
|
27565
27939
|
if (getSimulation().relay.mode !== "live") throw new Error("count unavailable");
|
|
27566
27940
|
if (signal?.aborted) throw new Error("count cancelled");
|
|
27567
|
-
observeRelayRequest(attributeAuthors({ reason: "host" }, filters),
|
|
27568
|
-
return countLive(livePool,
|
|
27941
|
+
observeRelayRequest(attributeAuthors({ reason: "host" }, filters), relayUrls2);
|
|
27942
|
+
return countLive(livePool, relayUrls2, normalizedFilters(filters), signal);
|
|
27569
27943
|
},
|
|
27570
27944
|
observedRelayUrls(eventId) {
|
|
27571
27945
|
return [...livePool.seenOn?.get(eventId) ?? []].map((relay) => relay.url);
|
|
@@ -27576,23 +27950,23 @@ function createPajaRelayBackend(getSimulation, confirmRequest, livePool = new Si
|
|
|
27576
27950
|
setRelayRequestObserver(observer) {
|
|
27577
27951
|
relayRequestObserver = observer;
|
|
27578
27952
|
},
|
|
27579
|
-
query,
|
|
27580
|
-
async publishToRelays(
|
|
27581
|
-
return (await attemptPublish(
|
|
27953
|
+
query: query2,
|
|
27954
|
+
async publishToRelays(relayUrls2, event, signerContext) {
|
|
27955
|
+
return (await attemptPublish(relayUrls2, event, signerContext)).outcomes;
|
|
27582
27956
|
},
|
|
27583
|
-
async publishWebrtcSignal(
|
|
27584
|
-
if (getSimulation().relay.mode !== "live" ||
|
|
27957
|
+
async publishWebrtcSignal(relayUrls2, event) {
|
|
27958
|
+
if (getSimulation().relay.mode !== "live" || relayUrls2.length === 0 || event.kind !== PAJA_WEBRTC_SIGNAL_KIND || !verifyEvent(event)) {
|
|
27585
27959
|
throw new Error("signaling unavailable");
|
|
27586
27960
|
}
|
|
27587
|
-
const outcomes = await publishLive(livePool,
|
|
27961
|
+
const outcomes = await publishLive(livePool, relayUrls2, event);
|
|
27588
27962
|
if (!Object.values(outcomes).some(Boolean)) throw new Error("signaling unavailable");
|
|
27589
27963
|
retainPublishedEvent(event, "live");
|
|
27590
27964
|
},
|
|
27591
|
-
async publishDmGiftWrap(
|
|
27592
|
-
if (getSimulation().relay.mode !== "live" ||
|
|
27965
|
+
async publishDmGiftWrap(relayUrls2, event) {
|
|
27966
|
+
if (getSimulation().relay.mode !== "live" || relayUrls2.length === 0 || event.kind !== NIP17_GIFT_WRAP_KIND2 || !verifyEvent(event)) {
|
|
27593
27967
|
throw new Error("DM relay publication failed");
|
|
27594
27968
|
}
|
|
27595
|
-
const outcomes = await publishLive(livePool,
|
|
27969
|
+
const outcomes = await publishLive(livePool, relayUrls2, event);
|
|
27596
27970
|
if (!Object.values(outcomes).some(Boolean)) throw new Error("DM relay publication failed");
|
|
27597
27971
|
retainPublishedEvent(event, "live");
|
|
27598
27972
|
},
|
|
@@ -27634,7 +28008,7 @@ function getPajaBootstrapRelayUrls(getSimulation, getHostRelayUrls) {
|
|
|
27634
28008
|
function createPajaContactListLoader(backend, getSimulation, getHostRelayUrls) {
|
|
27635
28009
|
return async (pubkey2, signal) => {
|
|
27636
28010
|
if (!/^[0-9a-fA-F]{64}$/.test(pubkey2) || signal?.aborted) return [];
|
|
27637
|
-
const
|
|
28011
|
+
const relayUrls2 = getPajaBootstrapRelayUrls(getSimulation, getHostRelayUrls);
|
|
27638
28012
|
if (signal?.aborted) return [];
|
|
27639
28013
|
const filters = [{
|
|
27640
28014
|
kinds: [PAJA_CONTACT_LIST_KIND],
|
|
@@ -27642,7 +28016,7 @@ function createPajaContactListLoader(backend, getSimulation, getHostRelayUrls) {
|
|
|
27642
28016
|
limit: PAJA_CONTACT_LIST_CANDIDATE_LIMIT
|
|
27643
28017
|
}];
|
|
27644
28018
|
const contactQuery = contactListCandidateQueries.get(backend);
|
|
27645
|
-
const candidates = contactQuery ? await contactQuery(
|
|
28019
|
+
const candidates = contactQuery ? await contactQuery(relayUrls2, filters, PAJA_LIVE_QUERY_WAIT_MS, signal) : await backend.query(relayUrls2, filters, PAJA_LIVE_QUERY_WAIT_MS);
|
|
27646
28020
|
if (signal?.aborted) return [];
|
|
27647
28021
|
return candidates.filter((event) => event.kind === PAJA_CONTACT_LIST_KIND && event.pubkey.toLowerCase() === pubkey2.toLowerCase()).sort((left, right) => right.created_at - left.created_at || left.id.localeCompare(right.id)).slice(0, PAJA_CONTACT_LIST_CANDIDATE_LIMIT);
|
|
27648
28022
|
};
|
|
@@ -27684,11 +28058,11 @@ function createPajaRelayListLoader(backend, getSimulation, getHostRelayUrls) {
|
|
|
27684
28058
|
}
|
|
27685
28059
|
function createPajaOutboxRelayPool(backend) {
|
|
27686
28060
|
return {
|
|
27687
|
-
subscribe(filters,
|
|
27688
|
-
return backend.subscription(
|
|
28061
|
+
subscribe(filters, relayUrls2, callback, origin, authors) {
|
|
28062
|
+
return backend.subscription(relayUrls2, filters, { reason: "outbox", origin, authors }).subscribe((item) => callback(item));
|
|
27689
28063
|
},
|
|
27690
|
-
publish(event,
|
|
27691
|
-
return backend.publishToRelays(
|
|
28064
|
+
publish(event, relayUrls2) {
|
|
28065
|
+
return backend.publishToRelays(relayUrls2, event);
|
|
27692
28066
|
},
|
|
27693
28067
|
isAvailable() {
|
|
27694
28068
|
return backend.isAvailable();
|
|
@@ -27732,14 +28106,14 @@ function createPajaDevSigner(getSimulation, confirm, source) {
|
|
|
27732
28106
|
}
|
|
27733
28107
|
function createDmRelayPool(backend, getRelays) {
|
|
27734
28108
|
return {
|
|
27735
|
-
subscribe(filters, callback,
|
|
27736
|
-
const subscription = backend.subscription(
|
|
28109
|
+
subscribe(filters, callback, relayUrls2) {
|
|
28110
|
+
const subscription = backend.subscription(relayUrls2 ?? getRelays(), filters).subscribe((item) => {
|
|
27737
28111
|
if (item === "EOSE" || typeof item === "object" && item !== null) callback(item);
|
|
27738
28112
|
});
|
|
27739
28113
|
return { unsubscribe: () => subscription.unsubscribe() };
|
|
27740
28114
|
},
|
|
27741
|
-
publish: (event,
|
|
27742
|
-
query: (filters,
|
|
28115
|
+
publish: (event, relayUrls2) => backend.publishDmGiftWrap([...relayUrls2 ?? getRelays()], event),
|
|
28116
|
+
query: (filters, relayUrls2) => backend.query(relayUrls2 ?? getRelays(), filters),
|
|
27743
28117
|
selectRelayTier: (_filters) => getRelays(),
|
|
27744
28118
|
isAvailable: () => backend.isAvailable()
|
|
27745
28119
|
};
|
|
@@ -28179,11 +28553,11 @@ function createPajaUploadRuntime(options2) {
|
|
|
28179
28553
|
if (currentGeneration !== generation2) return;
|
|
28180
28554
|
identity = { pubkey: signerPubkey, signer };
|
|
28181
28555
|
if (simulation.upload.servers.length > 0 || !simulation.upload.discoverServers) return;
|
|
28182
|
-
const
|
|
28183
|
-
if (
|
|
28556
|
+
const relayUrls2 = options2.getRelayUrls();
|
|
28557
|
+
if (relayUrls2.length === 0) return;
|
|
28184
28558
|
let events;
|
|
28185
28559
|
try {
|
|
28186
|
-
events = await options2.queryDiscovery(
|
|
28560
|
+
events = await options2.queryDiscovery(relayUrls2, [{
|
|
28187
28561
|
kinds: [BLOSSOM_SERVER_LIST_KIND],
|
|
28188
28562
|
authors: [signerPubkey],
|
|
28189
28563
|
limit: 1
|
|
@@ -28909,7 +29283,7 @@ function applyFinalLimits(entries2, filters, queryOptions) {
|
|
|
28909
29283
|
// src/browser-common.ts
|
|
28910
29284
|
var HEX_643 = /^[0-9a-f]{64}$/i;
|
|
28911
29285
|
var SHORTCODE = /^:[a-zA-Z0-9_+-]+:$/;
|
|
28912
|
-
function
|
|
29286
|
+
function relayUrls(values) {
|
|
28913
29287
|
const urls = /* @__PURE__ */ new Set();
|
|
28914
29288
|
for (const value of values) {
|
|
28915
29289
|
try {
|
|
@@ -28921,16 +29295,16 @@ function relayUrls2(values) {
|
|
|
28921
29295
|
return [...urls];
|
|
28922
29296
|
}
|
|
28923
29297
|
function profileTarget(target, defaults) {
|
|
28924
|
-
if (HEX_643.test(target)) return { pubkey: target.toLowerCase(), relays:
|
|
29298
|
+
if (HEX_643.test(target)) return { pubkey: target.toLowerCase(), relays: relayUrls(defaults) };
|
|
28925
29299
|
try {
|
|
28926
29300
|
const decoded = decode(target);
|
|
28927
29301
|
if (decoded.type === "npub") {
|
|
28928
|
-
return { pubkey: decoded.data.toLowerCase(), relays:
|
|
29302
|
+
return { pubkey: decoded.data.toLowerCase(), relays: relayUrls(defaults) };
|
|
28929
29303
|
}
|
|
28930
29304
|
if (decoded.type === "nprofile") {
|
|
28931
29305
|
return {
|
|
28932
29306
|
pubkey: decoded.data.pubkey.toLowerCase(),
|
|
28933
|
-
relays:
|
|
29307
|
+
relays: relayUrls([
|
|
28934
29308
|
...(decoded.data.relays ?? []).filter((relay) => isPajaRelayAllowed(relay, () => defaults)),
|
|
28935
29309
|
...defaults
|
|
28936
29310
|
])
|
|
@@ -29006,7 +29380,7 @@ function reactionTags(target, reaction, customEmojiHref) {
|
|
|
29006
29380
|
return tags;
|
|
29007
29381
|
}
|
|
29008
29382
|
function createPajaCommonBackend(options2) {
|
|
29009
|
-
const
|
|
29383
|
+
const query2 = (filters, relays = options2.getRelays(), signal) => options2.relay.query([...relays], filters, PAJA_LIVE_QUERY_WAIT_MS, void 0, signal);
|
|
29010
29384
|
const identity = async (signal) => {
|
|
29011
29385
|
if (signal?.aborted) throw new Error("user-denied");
|
|
29012
29386
|
const active = options2.getSigner();
|
|
@@ -29021,7 +29395,7 @@ function createPajaCommonBackend(options2) {
|
|
|
29021
29395
|
return active;
|
|
29022
29396
|
};
|
|
29023
29397
|
const currentContacts = async (author, relays, signal) => {
|
|
29024
|
-
const events = await
|
|
29398
|
+
const events = await query2([{ kinds: [3], authors: [author], limit: 16 }], relays, signal);
|
|
29025
29399
|
return newestVerified(events, (event) => event.kind === 3 && event.pubkey.toLowerCase() === author);
|
|
29026
29400
|
};
|
|
29027
29401
|
const publish = async (active, author, template, relays, signal) => {
|
|
@@ -29074,14 +29448,14 @@ function createPajaCommonBackend(options2) {
|
|
|
29074
29448
|
return resolved?.relays ?? null;
|
|
29075
29449
|
}
|
|
29076
29450
|
if (operation === "react" && (typeof target !== "string" || !HEX_643.test(target)) || operation === "report" && (!target || typeof target !== "object")) return null;
|
|
29077
|
-
return
|
|
29451
|
+
return relayUrls(options2.getRelays());
|
|
29078
29452
|
},
|
|
29079
29453
|
async getProfile(target, relays, signal) {
|
|
29080
29454
|
const resolved = profileTarget(target, relays ? [...relays] : options2.getRelays());
|
|
29081
29455
|
if (!resolved) return { ok: false, pubkey: "", error: "invalid-profile-target" };
|
|
29082
29456
|
const plannedRelays = relays ?? resolved.relays;
|
|
29083
29457
|
try {
|
|
29084
|
-
const events = await
|
|
29458
|
+
const events = await query2([{ kinds: [0], authors: [resolved.pubkey], limit: 16 }], plannedRelays, signal);
|
|
29085
29459
|
if (signal?.aborted) return { ok: false, pubkey: resolved.pubkey, error: "user-denied" };
|
|
29086
29460
|
const event = newestVerified(events, (candidate) => candidate.kind === 0 && candidate.pubkey.toLowerCase() === resolved.pubkey);
|
|
29087
29461
|
if (!event) return { ok: true, pubkey: resolved.pubkey, profile: null };
|
|
@@ -29105,7 +29479,7 @@ function createPajaCommonBackend(options2) {
|
|
|
29105
29479
|
if (!HEX_643.test(targetEventId)) return { ok: false, error: "invalid-target" };
|
|
29106
29480
|
try {
|
|
29107
29481
|
const active = await signer(signal);
|
|
29108
|
-
const events = await
|
|
29482
|
+
const events = await query2([{ ids: [targetEventId], limit: 8 }], relays, signal);
|
|
29109
29483
|
if (signal?.aborted) return { ok: false, error: "user-denied" };
|
|
29110
29484
|
const target = newestVerified(events, (event) => event.id === targetEventId.toLowerCase());
|
|
29111
29485
|
if (!target) return { ok: false, error: "invalid-target" };
|
|
@@ -29129,7 +29503,7 @@ function createPajaCommonBackend(options2) {
|
|
|
29129
29503
|
if (target.pubkey && !explicitAuthor) return { ok: false, error: "invalid-target" };
|
|
29130
29504
|
let author = explicitAuthor ?? null;
|
|
29131
29505
|
if (!author) {
|
|
29132
|
-
const events = await
|
|
29506
|
+
const events = await query2([{ ids: [target.id], limit: 8 }], relays, signal);
|
|
29133
29507
|
author = newestVerified(events, (event) => event.id === target.id.toLowerCase())?.pubkey ?? null;
|
|
29134
29508
|
}
|
|
29135
29509
|
if (signal?.aborted) return { ok: false, error: "user-denied" };
|
|
@@ -29880,7 +30254,7 @@ function waitForIceGathering(connection) {
|
|
|
29880
30254
|
var PROFILE = "soy-rtc/1";
|
|
29881
30255
|
var encoder = new TextEncoder();
|
|
29882
30256
|
var HEX2 = /^[0-9a-f]{64}$/u;
|
|
29883
|
-
var
|
|
30257
|
+
var MAX_BYTES2 = 16384;
|
|
29884
30258
|
function validate2(request) {
|
|
29885
30259
|
if (!request?.scope || !["room", "direct"].includes(request.scope.type)) throw new Error("Invalid WebRTC scope");
|
|
29886
30260
|
if (request.scope.type === "room") {
|
|
@@ -29971,7 +30345,7 @@ function createPajaWebrtcProfile(options2) {
|
|
|
29971
30345
|
received = 0;
|
|
29972
30346
|
bytes = 0;
|
|
29973
30347
|
}
|
|
29974
|
-
if (size >
|
|
30348
|
+
if (size > MAX_BYTES2 || ++received > 240 || (bytes += size) > 524288) return;
|
|
29975
30349
|
try {
|
|
29976
30350
|
emit(s, { type: "message", sessionId: s.id, from: p.key, payload: JSON.parse(event.data) });
|
|
29977
30351
|
} catch {
|
|
@@ -30101,7 +30475,7 @@ function createPajaWebrtcProfile(options2) {
|
|
|
30101
30475
|
open: (request, context) => openProfileSession(options2, self, sessions, openings, request, context, start, close),
|
|
30102
30476
|
send(id, payload, context) {
|
|
30103
30477
|
const s = requireSession(id, context), json = JSON.stringify(payload);
|
|
30104
|
-
if (json === void 0 || encoder.encode(json).length >
|
|
30478
|
+
if (json === void 0 || encoder.encode(json).length > MAX_BYTES2) throw new Error("Payload exceeds 16 KiB JSON limit");
|
|
30105
30479
|
const channels = [...s.peers.values()].filter((p) => p.joined && p.channel?.readyState === "open").map((p) => p.channel);
|
|
30106
30480
|
if (!channels.length) throw new Error("peer unavailable");
|
|
30107
30481
|
if (channels.some((c) => c.bufferedAmount + encoder.encode(json).length > 262144)) throw new Error("QUEUE_FULL");
|
|
@@ -30134,7 +30508,7 @@ async function openProfileSession(options2, self, sessions, openings, request, c
|
|
|
30134
30508
|
sessions.set(s.id, s);
|
|
30135
30509
|
context.signal?.addEventListener("abort", () => close(s), { once: true });
|
|
30136
30510
|
setTimeout(() => start(s), 0);
|
|
30137
|
-
const session = { id: s.id, scope: request.scope, channel, ...request.protocol ? { protocol: request.protocol } : {}, state: "connecting", ordered: true, maxPayloadBytes:
|
|
30511
|
+
const session = { id: s.id, scope: request.scope, channel, ...request.protocol ? { protocol: request.protocol } : {}, state: "connecting", ordered: true, maxPayloadBytes: MAX_BYTES2 };
|
|
30138
30512
|
return { session };
|
|
30139
30513
|
} finally {
|
|
30140
30514
|
openings.delete(identity);
|
|
@@ -30790,7 +31164,7 @@ async function createPajaBrowserFsBackend(options2) {
|
|
|
30790
31164
|
const snapshot4 = await snapshotEntry(entry, watchOptions?.recursive === true);
|
|
30791
31165
|
assertPendingWatch(pending);
|
|
30792
31166
|
const callback = onChange ?? (() => void 0);
|
|
30793
|
-
const
|
|
31167
|
+
const record6 = {
|
|
30794
31168
|
windowId,
|
|
30795
31169
|
path: entry.path,
|
|
30796
31170
|
directory: entry.handle.kind === "directory",
|
|
@@ -30799,16 +31173,16 @@ async function createPajaBrowserFsBackend(options2) {
|
|
|
30799
31173
|
snapshot: snapshot4,
|
|
30800
31174
|
closed: false
|
|
30801
31175
|
};
|
|
30802
|
-
backendWatches.add(
|
|
30803
|
-
|
|
30804
|
-
void pollWatch(
|
|
31176
|
+
backendWatches.add(record6);
|
|
31177
|
+
record6.timer = setInterval(() => {
|
|
31178
|
+
void pollWatch(record6);
|
|
30805
31179
|
}, WATCH_INTERVAL_MS);
|
|
30806
31180
|
return {
|
|
30807
31181
|
close() {
|
|
30808
|
-
if (
|
|
30809
|
-
|
|
30810
|
-
if (
|
|
30811
|
-
backendWatches.delete(
|
|
31182
|
+
if (record6.closed) return;
|
|
31183
|
+
record6.closed = true;
|
|
31184
|
+
if (record6.timer !== void 0) clearInterval(record6.timer);
|
|
31185
|
+
backendWatches.delete(record6);
|
|
30812
31186
|
}
|
|
30813
31187
|
};
|
|
30814
31188
|
} finally {
|
|
@@ -30887,8 +31261,8 @@ function createDevServices(backend, getSimulation, relayConfig, onThemeService,
|
|
|
30887
31261
|
const getWriteRelays = () => relayConfig.getRelayUrls(["outbox"]);
|
|
30888
31262
|
const getAllRelays = () => relayConfig.getRelayUrls();
|
|
30889
31263
|
const baseOutboxRouter = createOutboxRouter(backend, getSimulation, relayConfig, confirmRequest, signerProvider);
|
|
30890
|
-
const queryApprovedResourceRelays = async (
|
|
30891
|
-
const unique = [...new Set(
|
|
31264
|
+
const queryApprovedResourceRelays = async (relayUrls2, filters, context) => {
|
|
31265
|
+
const unique = [...new Set(relayUrls2.filter((relay) => isPajaRelayAllowed(relay, () => relayConfig.getRelayUrls())))];
|
|
30892
31266
|
const batches = await Promise.all(unique.map((relay) => context.authorizeNetwork(
|
|
30893
31267
|
relay,
|
|
30894
31268
|
(signal) => backend.query([relay], filters, PAJA_LIVE_QUERY_WAIT_MS, { reason: "host" }, signal)
|
|
@@ -30906,9 +31280,9 @@ function createDevServices(backend, getSimulation, relayConfig, onThemeService,
|
|
|
30906
31280
|
context
|
|
30907
31281
|
);
|
|
30908
31282
|
const newestRelayList = relayListEvents.filter((event) => event.kind === 10002 && event.pubkey.toLowerCase() === pubkey2.toLowerCase() && verifyEvent(event)).sort((left, right) => right.created_at - left.created_at || left.id.localeCompare(right.id))[0];
|
|
30909
|
-
const
|
|
30910
|
-
if (newestRelayList)
|
|
30911
|
-
const routed = selectWriteRelays(
|
|
31283
|
+
const registry3 = createNip65Registry();
|
|
31284
|
+
if (newestRelayList) registry3.ingest(newestRelayList);
|
|
31285
|
+
const routed = selectWriteRelays(registry3.getRelayList(pubkey2) ?? []);
|
|
30912
31286
|
const resourceEvents = await queryApprovedResourceRelays(
|
|
30913
31287
|
[...relayConfig.outboxRelays, ...routed],
|
|
30914
31288
|
[{ kinds: [BLOSSOM_SERVER_LIST_KIND2], authors: [pubkey2], limit: 1 }],
|
|
@@ -30989,8 +31363,8 @@ function createDevServices(backend, getSimulation, relayConfig, onThemeService,
|
|
|
30989
31363
|
}
|
|
30990
31364
|
if (getSimulation().relay.mode === "live") {
|
|
30991
31365
|
const relayOptions = {
|
|
30992
|
-
subscribe: (filters, callback,
|
|
30993
|
-
(
|
|
31366
|
+
subscribe: (filters, callback, relayUrls2, fromHint) => backend.subscription(
|
|
31367
|
+
(relayUrls2 ?? getReadRelays()).filter((url) => isPajaRelayAllowed(url, getAllRelays)),
|
|
30994
31368
|
filters,
|
|
30995
31369
|
{ reason: fromHint ? "hint" : "host" }
|
|
30996
31370
|
).subscribe((item) => {
|
|
@@ -31007,7 +31381,7 @@ function createDevServices(backend, getSimulation, relayConfig, onThemeService,
|
|
|
31007
31381
|
};
|
|
31008
31382
|
const relayPublishers = (relay) => ({
|
|
31009
31383
|
publish: (event) => relay.publish(getWriteRelays(), event),
|
|
31010
|
-
publishToRelays: (
|
|
31384
|
+
publishToRelays: (relayUrls2, event) => relay.publish([...relayUrls2].filter((url) => isPajaRelayAllowed(url, getAllRelays)), event)
|
|
31011
31385
|
});
|
|
31012
31386
|
services.relay = scopePajaService(
|
|
31013
31387
|
createRelayPoolService({ ...relayOptions, ...relayPublishers(backend) }),
|
|
@@ -31100,8 +31474,9 @@ function createDevServices(backend, getSimulation, relayConfig, onThemeService,
|
|
|
31100
31474
|
if (getSimulation().capabilities.domains.theme) services.theme = theme.handler;
|
|
31101
31475
|
if (getSimulation().capabilities.domains.config && config) services.config = config.handler;
|
|
31102
31476
|
const multiplayerConfig = getSimulation().multiplayer;
|
|
31477
|
+
const registry2 = mergeCvmFamilies(multiplayerConfig?.registry ?? [], readCvmFamilies());
|
|
31103
31478
|
const multiplayer = multiplayerConfig && getSimulation().relay.mode === "live" && backend.isAvailable() ? createPajaMultiplayerServices({
|
|
31104
|
-
config: multiplayerConfig,
|
|
31479
|
+
config: { ...multiplayerConfig, registry: registry2 },
|
|
31105
31480
|
scopeKey,
|
|
31106
31481
|
namespace: (windowId) => getIdentity?.(windowId).signalingNamespace,
|
|
31107
31482
|
backend: (windowId, isCurrent) => scopeFor2(windowId, isCurrent).backend
|
|
@@ -31109,6 +31484,7 @@ function createDevServices(backend, getSimulation, relayConfig, onThemeService,
|
|
|
31109
31484
|
if (getSimulation().cvm.enabled && getSimulation().relay.mode === "live" && backend.isAvailable()) {
|
|
31110
31485
|
const cvm = (relay) => {
|
|
31111
31486
|
const service = createCvmServiceHandler({
|
|
31487
|
+
registry: registry2,
|
|
31112
31488
|
transport: createNostrCvmTransport({
|
|
31113
31489
|
defaultRelays: relayConfig.allRelays,
|
|
31114
31490
|
pool: createPajaCvmRelayPool(relay),
|
|
@@ -31162,13 +31538,13 @@ function createDevServices(backend, getSimulation, relayConfig, onThemeService,
|
|
|
31162
31538
|
}
|
|
31163
31539
|
const webrtcController = !multiplayer && getSimulation().relay.mode === "live" && backend.isAvailable() ? createPajaWebrtcController({
|
|
31164
31540
|
relay: {
|
|
31165
|
-
subscribe(
|
|
31166
|
-
const subscription = backend.subscription([...
|
|
31541
|
+
subscribe(relayUrls2, filters, onEvent) {
|
|
31542
|
+
const subscription = backend.subscription([...relayUrls2], filters).subscribe((item) => {
|
|
31167
31543
|
if (typeof item === "object" && item !== null) onEvent(item);
|
|
31168
31544
|
});
|
|
31169
31545
|
return { close: () => subscription.unsubscribe() };
|
|
31170
31546
|
},
|
|
31171
|
-
publish: (
|
|
31547
|
+
publish: (relayUrls2, event) => backend.publishWebrtcSignal([...relayUrls2], event)
|
|
31172
31548
|
},
|
|
31173
31549
|
getSigner: (windowId) => createRuntimeSigner(getSimulation, confirmRequest, signerProvider, windowId ? getSignerSource?.(windowId) : void 0),
|
|
31174
31550
|
getPubkey: () => getRuntimePubkey(getSimulation, signerProvider),
|
|
@@ -31232,7 +31608,7 @@ function createPajaAdapter(config, getSimulation, onThemeService, onThemeBroadca
|
|
|
31232
31608
|
getSimulation,
|
|
31233
31609
|
getSigner: () => createRuntimeSigner(getSimulation, confirmRequest, signerProvider),
|
|
31234
31610
|
getProviderPubkey: () => signerProvider?.getPubkey() ?? null,
|
|
31235
|
-
queryDiscovery: (
|
|
31611
|
+
queryDiscovery: (relayUrls2, filters) => relayBackend.query(relayUrls2, filters),
|
|
31236
31612
|
getRelayUrls: () => relayConfig.getRelayUrls(["discovery", "super"]),
|
|
31237
31613
|
confirmRequest,
|
|
31238
31614
|
getNappletIdentity: resolveIdentity,
|
|
@@ -31427,11 +31803,11 @@ function createPajaRelayEventCounter(onChange) {
|
|
|
31427
31803
|
get uniqueEvents() {
|
|
31428
31804
|
return eventIds.size;
|
|
31429
31805
|
},
|
|
31430
|
-
snapshot(
|
|
31806
|
+
snapshot(inventory2) {
|
|
31431
31807
|
const out = [];
|
|
31432
31808
|
for (const spec of RELAY_BOXES) {
|
|
31433
31809
|
const box = boxes.get(spec.kind);
|
|
31434
|
-
const configured = spec.configured ?
|
|
31810
|
+
const configured = spec.configured ? inventory2?.[spec.kind] ?? [] : [];
|
|
31435
31811
|
const seen = /* @__PURE__ */ new Set();
|
|
31436
31812
|
const relays = [];
|
|
31437
31813
|
const push = (relayUrl2, isConfigured) => {
|
|
@@ -31464,11 +31840,11 @@ function createPajaRelayEventCounter(onChange) {
|
|
|
31464
31840
|
}
|
|
31465
31841
|
return out;
|
|
31466
31842
|
},
|
|
31467
|
-
recordRead(reason,
|
|
31843
|
+
recordRead(reason, relayUrls2, origin, authors) {
|
|
31468
31844
|
const kind = boxKindFor(reason, origin);
|
|
31469
31845
|
const box = boxFor(kind);
|
|
31470
31846
|
let changed = false;
|
|
31471
|
-
for (const relayUrl2 of distinctRelayUrls(
|
|
31847
|
+
for (const relayUrl2 of distinctRelayUrls(relayUrls2)) {
|
|
31472
31848
|
const key = normalizeURL2(relayUrl2);
|
|
31473
31849
|
box.reads.set(key, (box.reads.get(key) ?? 0) + 1);
|
|
31474
31850
|
relayFor(kind, relayUrl2);
|
|
@@ -31531,10 +31907,10 @@ function renderBoxAuthors(authors) {
|
|
|
31531
31907
|
function shortPubkey(pubkey2) {
|
|
31532
31908
|
return pubkey2.length > 12 ? `${pubkey2.slice(0, 8)}\u2026${pubkey2.slice(-4)}` : pubkey2;
|
|
31533
31909
|
}
|
|
31534
|
-
function renderPajaEventKindCounts(counter,
|
|
31910
|
+
function renderPajaEventKindCounts(counter, inventory2) {
|
|
31535
31911
|
const container = document.getElementById("event-kind-counts");
|
|
31536
31912
|
const total = document.getElementById("event-kind-total");
|
|
31537
|
-
const boxes = counter.snapshot(
|
|
31913
|
+
const boxes = counter.snapshot(inventory2);
|
|
31538
31914
|
if (total) {
|
|
31539
31915
|
total.textContent = boxes.length === 0 ? "" : `${counter.total}`;
|
|
31540
31916
|
total.title = `${counter.total} relay receipt${counter.total === 1 ? "" : "s"} \xB7 ${counter.uniqueEvents} unique event${counter.uniqueEvents === 1 ? "" : "s"}`;
|
|
@@ -32271,10 +32647,10 @@ function createPajaSignerConsentStore(storage = readPajaSignerConsentStorage())
|
|
|
32271
32647
|
if (context.isCurrent && !context.isCurrent()) return null;
|
|
32272
32648
|
const normalizedKind = normalizeKind(kind);
|
|
32273
32649
|
if (normalizedKind === null) return null;
|
|
32274
|
-
const
|
|
32275
|
-
if (!
|
|
32276
|
-
const trusted = action === "sign" ?
|
|
32277
|
-
const kinds = action === "sign" ?
|
|
32650
|
+
const record6 = recordFor(context);
|
|
32651
|
+
if (!record6) return null;
|
|
32652
|
+
const trusted = action === "sign" ? record6.trusted : record6.publishTrusted;
|
|
32653
|
+
const kinds = action === "sign" ? record6.kinds : record6.publishKinds;
|
|
32278
32654
|
if (trusted) return "napplet";
|
|
32279
32655
|
return kinds.includes(normalizedKind) ? "kind" : null;
|
|
32280
32656
|
},
|
|
@@ -32282,39 +32658,39 @@ function createPajaSignerConsentStore(storage = readPajaSignerConsentStorage())
|
|
|
32282
32658
|
if (context.isCurrent && !context.isCurrent()) return false;
|
|
32283
32659
|
const normalizedKind = normalizeKind(kind);
|
|
32284
32660
|
if (normalizedKind === null) return false;
|
|
32285
|
-
const
|
|
32286
|
-
if (!
|
|
32287
|
-
const kinds = action === "sign" ?
|
|
32288
|
-
if ((action === "sign" ?
|
|
32661
|
+
const record6 = ensureRecord(context);
|
|
32662
|
+
if (!record6) return false;
|
|
32663
|
+
const kinds = action === "sign" ? record6.kinds : record6.publishKinds;
|
|
32664
|
+
if ((action === "sign" ? record6.trusted : record6.publishTrusted) || kinds.includes(normalizedKind)) return true;
|
|
32289
32665
|
if (kinds.length >= MAX_KINDS_PER_SUBJECT) return false;
|
|
32290
32666
|
const next = [...kinds, normalizedKind].sort((left, right) => left - right);
|
|
32291
|
-
if (action === "sign")
|
|
32292
|
-
else
|
|
32667
|
+
if (action === "sign") record6.kinds = next;
|
|
32668
|
+
else record6.publishKinds = next;
|
|
32293
32669
|
persist();
|
|
32294
32670
|
return true;
|
|
32295
32671
|
},
|
|
32296
32672
|
trustNapplet(context, action = "sign") {
|
|
32297
32673
|
if (context.isCurrent && !context.isCurrent()) return false;
|
|
32298
|
-
const
|
|
32299
|
-
if (!
|
|
32674
|
+
const record6 = ensureRecord(context);
|
|
32675
|
+
if (!record6) return false;
|
|
32300
32676
|
if (action === "sign") {
|
|
32301
|
-
|
|
32302
|
-
|
|
32677
|
+
record6.trusted = true;
|
|
32678
|
+
record6.kinds = [];
|
|
32303
32679
|
} else {
|
|
32304
|
-
|
|
32305
|
-
|
|
32680
|
+
record6.publishTrusted = true;
|
|
32681
|
+
record6.publishKinds = [];
|
|
32306
32682
|
}
|
|
32307
32683
|
persist();
|
|
32308
32684
|
return true;
|
|
32309
32685
|
},
|
|
32310
32686
|
trustVersion(context) {
|
|
32311
32687
|
if (context.isCurrent && !context.isCurrent()) return false;
|
|
32312
|
-
const
|
|
32313
|
-
if (!
|
|
32314
|
-
|
|
32315
|
-
|
|
32316
|
-
|
|
32317
|
-
|
|
32688
|
+
const record6 = ensureRecord(context);
|
|
32689
|
+
if (!record6) return false;
|
|
32690
|
+
record6.trusted = true;
|
|
32691
|
+
record6.kinds = [];
|
|
32692
|
+
record6.publishTrusted = true;
|
|
32693
|
+
record6.publishKinds = [];
|
|
32318
32694
|
persist();
|
|
32319
32695
|
return true;
|
|
32320
32696
|
},
|
|
@@ -32365,13 +32741,13 @@ function readConsentDocument(storage) {
|
|
|
32365
32741
|
if (parsed.version !== PAJA_SIGNER_CONSENT_VERSION || !Array.isArray(parsed.grants)) return empty();
|
|
32366
32742
|
const grants = [];
|
|
32367
32743
|
for (const candidate of parsed.grants.slice(0, MAX_CONSENT_SUBJECTS)) {
|
|
32368
|
-
const
|
|
32369
|
-
if (!
|
|
32744
|
+
const record6 = normalizeRecord2(candidate);
|
|
32745
|
+
if (!record6 || grants.some((existing) => sameSubject(existing, record6))) continue;
|
|
32370
32746
|
if (!warnedLegacyConsent && candidate && typeof candidate === "object" && !("publishTrusted" in candidate) && !("publishKinds" in candidate)) {
|
|
32371
32747
|
warnedLegacyConsent = true;
|
|
32372
32748
|
console.warn("[KEHTO-PAJA-SIGNER-CONSENT-V1] Loaded older signing-only approvals. Publishing still requires approval; review the current napplet version to allow signing and publishing together. This warning appears once per host module lifetime.");
|
|
32373
32749
|
}
|
|
32374
|
-
grants.push(
|
|
32750
|
+
grants.push(record6);
|
|
32375
32751
|
}
|
|
32376
32752
|
return { version: PAJA_SIGNER_CONSENT_VERSION, grants };
|
|
32377
32753
|
} catch {
|
|
@@ -32577,15 +32953,15 @@ function createPajaConfirmationController(getState, options2 = {}) {
|
|
|
32577
32953
|
deny.addEventListener("click", onDeny);
|
|
32578
32954
|
dialog.addEventListener("cancel", onCancel);
|
|
32579
32955
|
}
|
|
32580
|
-
const cancelMatching = (
|
|
32956
|
+
const cancelMatching = (matches3) => {
|
|
32581
32957
|
for (let index = queue.length - 1; index >= 0; index--) {
|
|
32582
32958
|
const pending = queue[index];
|
|
32583
|
-
if (!
|
|
32959
|
+
if (!matches3(pending.request)) continue;
|
|
32584
32960
|
queue.splice(index, 1);
|
|
32585
32961
|
recordPajaConfirmation(getState(), pending.request, false);
|
|
32586
32962
|
pending.deny();
|
|
32587
32963
|
}
|
|
32588
|
-
if (active &&
|
|
32964
|
+
if (active && matches3(active.request)) settle4(false);
|
|
32589
32965
|
};
|
|
32590
32966
|
return {
|
|
32591
32967
|
confirm(request) {
|
|
@@ -33463,15 +33839,15 @@ function runtimeTabWindowId(config, tab) {
|
|
|
33463
33839
|
}
|
|
33464
33840
|
|
|
33465
33841
|
// src/installed-napplet-catalog.ts
|
|
33466
|
-
function matchesInstalledNappletRecord(
|
|
33467
|
-
return target.id ===
|
|
33842
|
+
function matchesInstalledNappletRecord(record6, target) {
|
|
33843
|
+
return target.id === record6.id && target.aggregateHash === record6.aggregateHash;
|
|
33468
33844
|
}
|
|
33469
33845
|
var InstalledNappletCatalog = class {
|
|
33470
33846
|
records = /* @__PURE__ */ new Map();
|
|
33471
33847
|
listeners = /* @__PURE__ */ new Set();
|
|
33472
33848
|
/** Insert or replace a record from an already resolver-verified pointer. */
|
|
33473
33849
|
install(resolved) {
|
|
33474
|
-
const
|
|
33850
|
+
const record6 = freezeRecord({
|
|
33475
33851
|
id: resolved.manifest.catalogId,
|
|
33476
33852
|
dTag: resolved.dTag,
|
|
33477
33853
|
aggregateHash: resolved.aggregateHash,
|
|
@@ -33485,10 +33861,10 @@ var InstalledNappletCatalog = class {
|
|
|
33485
33861
|
params: [...archetype.params]
|
|
33486
33862
|
}))
|
|
33487
33863
|
});
|
|
33488
|
-
const previous = this.records.get(
|
|
33489
|
-
this.records.set(
|
|
33490
|
-
this.notify(
|
|
33491
|
-
return
|
|
33864
|
+
const previous = this.records.get(record6.id);
|
|
33865
|
+
this.records.set(record6.id, record6);
|
|
33866
|
+
this.notify(record6.id, previous, record6);
|
|
33867
|
+
return record6;
|
|
33492
33868
|
}
|
|
33493
33869
|
/** Remove an artifact explicitly; frame teardown never calls this method. */
|
|
33494
33870
|
remove(id) {
|
|
@@ -33525,10 +33901,10 @@ var InstalledNappletCatalog = class {
|
|
|
33525
33901
|
* @returns Named intent candidates usable under the supplied host policy.
|
|
33526
33902
|
*/
|
|
33527
33903
|
intentCatalog(canReceiveIntent = () => true) {
|
|
33528
|
-
return this.installed().filter(canReceiveIntent).map((
|
|
33529
|
-
catalogId:
|
|
33530
|
-
...
|
|
33531
|
-
archetypes:
|
|
33904
|
+
return this.installed().filter(canReceiveIntent).map((record6) => manifestToIntentCatalogEntry({
|
|
33905
|
+
catalogId: record6.id,
|
|
33906
|
+
...record6.title === void 0 ? {} : { title: record6.title },
|
|
33907
|
+
archetypes: record6.archetypes.map((archetype) => ({
|
|
33532
33908
|
slug: archetype.slug,
|
|
33533
33909
|
convention: archetype.convention,
|
|
33534
33910
|
params: [...archetype.params]
|
|
@@ -33568,12 +33944,12 @@ function copyPointer(pointer) {
|
|
|
33568
33944
|
relays: Object.freeze([...pointer.relays])
|
|
33569
33945
|
});
|
|
33570
33946
|
}
|
|
33571
|
-
function freezeRecord(
|
|
33947
|
+
function freezeRecord(record6) {
|
|
33572
33948
|
return Object.freeze({
|
|
33573
|
-
...
|
|
33574
|
-
requires: Object.freeze([...
|
|
33575
|
-
optional: Object.freeze([...
|
|
33576
|
-
archetypes: Object.freeze(
|
|
33949
|
+
...record6,
|
|
33950
|
+
requires: Object.freeze([...record6.requires]),
|
|
33951
|
+
optional: Object.freeze([...record6.optional ?? []]),
|
|
33952
|
+
archetypes: Object.freeze(record6.archetypes.map((archetype) => Object.freeze({ ...archetype, params: Object.freeze([...archetype.params]) })))
|
|
33577
33953
|
});
|
|
33578
33954
|
}
|
|
33579
33955
|
|
|
@@ -33884,22 +34260,22 @@ function createPajaIntentTargetOptions(getState, getContext, effects = {}) {
|
|
|
33884
34260
|
const state = getState();
|
|
33885
34261
|
const context = getContext();
|
|
33886
34262
|
if (!state || !context) return null;
|
|
33887
|
-
const
|
|
33888
|
-
if (!
|
|
34263
|
+
const record6 = context.runtime.catalog.get(params.handler);
|
|
34264
|
+
if (!record6 || !recordSupportsDelivery(record6, params)) return null;
|
|
33889
34265
|
for (const stale of state.tabs) {
|
|
33890
|
-
if (!isPajaLocalTarget(stale.resolvedTarget) && catalogIdForTarget(stale.resolvedTarget) === params.handler && !matchesInstalledNappletRecord(
|
|
34266
|
+
if (!isPajaLocalTarget(stale.resolvedTarget) && catalogIdForTarget(stale.resolvedTarget) === params.handler && !matchesInstalledNappletRecord(record6, catalogIdentity(stale.resolvedTarget))) closeRuntimeTab(state, context, stale.id);
|
|
33891
34267
|
}
|
|
33892
34268
|
const current = state.tabs.find(
|
|
33893
|
-
(tab2) => !isPajaLocalTarget(tab2.resolvedTarget) && matchesInstalledNappletRecord(
|
|
34269
|
+
(tab2) => !isPajaLocalTarget(tab2.resolvedTarget) && matchesInstalledNappletRecord(record6, catalogIdentity(tab2.resolvedTarget)) && isCurrentRuntimeTabGeneration(state, context, tab2)
|
|
33894
34270
|
);
|
|
33895
34271
|
if (current && params.behavior?.reuse !== false) {
|
|
33896
34272
|
activateRuntimeTab(state, context, current.id);
|
|
33897
34273
|
effects.persistTabs?.(state);
|
|
33898
|
-
return bindPajaIntentGeneration(current,
|
|
34274
|
+
return bindPajaIntentGeneration(current, record6, context.runtime);
|
|
33899
34275
|
}
|
|
33900
|
-
const resolved = await resolvePajaPointer(
|
|
33901
|
-
if (resolved.manifest.catalogId !==
|
|
33902
|
-
const currentRecord = context.runtime.catalog.validateCurrent(
|
|
34276
|
+
const resolved = await resolvePajaPointer(record6.pointer.value, pajaPointerResolverOptions(context));
|
|
34277
|
+
if (resolved.manifest.catalogId !== record6.id || resolved.aggregateHash !== record6.aggregateHash || !resolvedSupportsDelivery(resolved, params)) return null;
|
|
34278
|
+
const currentRecord = context.runtime.catalog.validateCurrent(record6, catalogIdentity(resolved));
|
|
33903
34279
|
if (!currentRecord) return null;
|
|
33904
34280
|
const tab = addRuntimeTab(state, context, currentRecord.pointer.value, resolved);
|
|
33905
34281
|
effects.persistTabs?.(state);
|
|
@@ -33979,8 +34355,8 @@ function pajaPointerResolverOptions(context) {
|
|
|
33979
34355
|
maxWaitMs: context.config.target.pointer?.maxWaitMs
|
|
33980
34356
|
};
|
|
33981
34357
|
}
|
|
33982
|
-
function recordSupportsDelivery(
|
|
33983
|
-
return
|
|
34358
|
+
function recordSupportsDelivery(record6, params) {
|
|
34359
|
+
return record6.archetypes.some(
|
|
33984
34360
|
(archetype) => archetype.slug === params.archetype && archetype.convention === params.convention
|
|
33985
34361
|
);
|
|
33986
34362
|
}
|
|
@@ -33992,17 +34368,17 @@ function resolvedSupportsDelivery(resolved, params) {
|
|
|
33992
34368
|
function findRuntimeTabGeneration(state, generation2) {
|
|
33993
34369
|
return state.tabs.find((tab) => runtimeTabGenerationId(tab) === generation2.id) ?? null;
|
|
33994
34370
|
}
|
|
33995
|
-
function bindPajaIntentGeneration(tab,
|
|
34371
|
+
function bindPajaIntentGeneration(tab, record6, runtime) {
|
|
33996
34372
|
const generation2 = { id: runtimeTabGenerationId(tab) };
|
|
33997
|
-
runtime.intentRecords.set(generation2,
|
|
34373
|
+
runtime.intentRecords.set(generation2, record6);
|
|
33998
34374
|
return generation2;
|
|
33999
34375
|
}
|
|
34000
34376
|
function isCurrentPajaIntentGeneration(generation2, state, context, tab) {
|
|
34001
34377
|
return isPendingPajaIntentGeneration(generation2, state, context, tab) && isCurrentRuntimeTabGeneration(state, context, tab);
|
|
34002
34378
|
}
|
|
34003
34379
|
function isPendingPajaIntentGeneration(generation2, state, context, tab) {
|
|
34004
|
-
const
|
|
34005
|
-
return
|
|
34380
|
+
const record6 = context.runtime.intentRecords.get(generation2);
|
|
34381
|
+
return record6 !== void 0 && state.tabs.includes(tab) && !tab.admissionController.signal.aborted && runtimeTabGenerationId(tab) === generation2.id && !isPajaLocalTarget(tab.resolvedTarget) && context.runtime.catalog.validateCurrent(record6, catalogIdentity(tab.resolvedTarget)) !== null;
|
|
34006
34382
|
}
|
|
34007
34383
|
function invalidatePajaIntentGeneration(generation2, runtime) {
|
|
34008
34384
|
const waiters = runtime.readyWaiters.get(generation2);
|
|
@@ -34013,8 +34389,8 @@ function invalidatePajaIntentGeneration(generation2, runtime) {
|
|
|
34013
34389
|
function subscribePajaIntentCatalogChanges(state, context) {
|
|
34014
34390
|
return context.runtime.catalog.onChanged((id) => {
|
|
34015
34391
|
for (const [generation2] of context.runtime.readyWaiters) {
|
|
34016
|
-
const
|
|
34017
|
-
if (!
|
|
34392
|
+
const record6 = context.runtime.intentRecords.get(generation2);
|
|
34393
|
+
if (!record6 || record6.id !== id) continue;
|
|
34018
34394
|
const tab = findRuntimeTabGeneration(state, generation2);
|
|
34019
34395
|
if (!tab || !isCurrentPajaIntentGeneration(generation2, state, context, tab)) {
|
|
34020
34396
|
invalidatePajaIntentGeneration(generation2, context.runtime);
|
|
@@ -35304,11 +35680,11 @@ function createPajaNotifyController(options2) {
|
|
|
35304
35680
|
};
|
|
35305
35681
|
const removeNotification = (windowId, notificationId, reason) => {
|
|
35306
35682
|
const key = notificationKey(windowId, notificationId);
|
|
35307
|
-
const
|
|
35308
|
-
if (!
|
|
35683
|
+
const record6 = active.get(key);
|
|
35684
|
+
if (!record6) return;
|
|
35309
35685
|
active.delete(key);
|
|
35310
|
-
|
|
35311
|
-
if (reason)
|
|
35686
|
+
record6.element.remove();
|
|
35687
|
+
if (reason) record6.emit({ type: "notify.dismissed", notificationId, reason });
|
|
35312
35688
|
};
|
|
35313
35689
|
const hasPermission = (windowId, channel) => {
|
|
35314
35690
|
const grants = permissions.get(windowId);
|
|
@@ -35415,9 +35791,9 @@ function createPajaNotifyController(options2) {
|
|
|
35415
35791
|
};
|
|
35416
35792
|
const destroyWindow = (windowId) => {
|
|
35417
35793
|
epochs.delete(windowId);
|
|
35418
|
-
for (const [key,
|
|
35794
|
+
for (const [key, record6] of active) {
|
|
35419
35795
|
if (!key.startsWith(`${windowId}\0`)) continue;
|
|
35420
|
-
|
|
35796
|
+
record6.element.remove();
|
|
35421
35797
|
active.delete(key);
|
|
35422
35798
|
}
|
|
35423
35799
|
badges.get(windowId)?.remove();
|
|
@@ -35439,7 +35815,7 @@ function createPajaNotifyController(options2) {
|
|
|
35439
35815
|
dispose() {
|
|
35440
35816
|
if (disposed) return;
|
|
35441
35817
|
disposed = true;
|
|
35442
|
-
for (const
|
|
35818
|
+
for (const record6 of active.values()) record6.element.remove();
|
|
35443
35819
|
for (const badge of badges.values()) badge.remove();
|
|
35444
35820
|
active.clear();
|
|
35445
35821
|
badges.clear();
|
|
@@ -36248,6 +36624,15 @@ async function installPajaHost() {
|
|
|
36248
36624
|
});
|
|
36249
36625
|
adapter.permissions = permissionController.adapter;
|
|
36250
36626
|
const relayBackend = adapter.relayPool.getRelayPool();
|
|
36627
|
+
const disposeCvmSettings = installPajaCvmSettings({
|
|
36628
|
+
relays: [...runtime.currentSimulation.relay.urls],
|
|
36629
|
+
fetch: window.fetch.bind(window),
|
|
36630
|
+
query: (relays, filters, signal) => {
|
|
36631
|
+
if (!relayBackend || runtime.currentSimulation.relay.mode !== "live") throw new Error("CVM discovery requires live relays.");
|
|
36632
|
+
return relayBackend.query(relays, filters, 5e3, { reason: "host" }, signal);
|
|
36633
|
+
}
|
|
36634
|
+
});
|
|
36635
|
+
window.addEventListener("pagehide", disposeCvmSettings, { once: true });
|
|
36251
36636
|
relayBackend?.setRelayEventObserver((sighting) => {
|
|
36252
36637
|
relayEventCounts.recordEvent(sighting.reason, sighting.event, sighting.sightedOn, sighting.origin);
|
|
36253
36638
|
});
|
|
@@ -36307,10 +36692,10 @@ async function installPajaHost() {
|
|
|
36307
36692
|
const pointers = new Set(readPajaIntentCatalogPointers());
|
|
36308
36693
|
const previous = catalogPointers.get(id);
|
|
36309
36694
|
if (previous) pointers.delete(previous);
|
|
36310
|
-
const
|
|
36311
|
-
if (
|
|
36312
|
-
pointers.add(
|
|
36313
|
-
catalogPointers.set(id,
|
|
36695
|
+
const record6 = runtime.catalog.get(id);
|
|
36696
|
+
if (record6) {
|
|
36697
|
+
pointers.add(record6.pointer.value);
|
|
36698
|
+
catalogPointers.set(id, record6.pointer.value);
|
|
36314
36699
|
} else catalogPointers.delete(id);
|
|
36315
36700
|
writePajaIntentCatalogPointers([...pointers]);
|
|
36316
36701
|
});
|