@kehto/paja 0.35.3 → 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 +22 -3
- package/dist/browser-host.js +2867 -1761
- package/dist/browser-host.js.map +1 -1
- package/dist/{chunk-HTLBCTIN.js → chunk-F3KNRWX7.js} +174 -74
- package/dist/chunk-F3KNRWX7.js.map +1 -0
- package/dist/cli.d.ts +2 -1
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -1
- package/dist/{server-B7uqpu8g.d.ts → server-D1H77278.d.ts} +36 -1
- package/package.json +6 -6
- package/dist/chunk-HTLBCTIN.js.map +0 -1
|
@@ -1,3 +1,61 @@
|
|
|
1
|
+
// src/multiplayer-config.ts
|
|
2
|
+
import { normalizePermissionScope } from "@kehto/firewall";
|
|
3
|
+
var HEX = /^[0-9a-f]{64}$/u;
|
|
4
|
+
function record(value) {
|
|
5
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
6
|
+
}
|
|
7
|
+
function text(value) {
|
|
8
|
+
if (typeof value !== "string" || !value.trim() || value.length > 256) throw new Error("Expected nonempty text (at most 256 characters).");
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
function normalizePajaCvmRelays(value) {
|
|
12
|
+
if (!Array.isArray(value) || !value.length || value.length > 16) throw new Error("Configure 1\u201316 relay URLs.");
|
|
13
|
+
return [...new Set(value.map((item) => {
|
|
14
|
+
if (typeof item !== "string") throw new Error("Invalid relay URL.");
|
|
15
|
+
const url = new URL(item);
|
|
16
|
+
if (!["ws:", "wss:"].includes(url.protocol) || !url.hostname || url.username || url.password || url.search || url.hash || url.pathname !== "/") throw new Error("Relay URLs must be WS(S) origins without credentials.");
|
|
17
|
+
return url.origin;
|
|
18
|
+
}))];
|
|
19
|
+
}
|
|
20
|
+
function normalizePajaCvmFamily(value) {
|
|
21
|
+
if (!record(value) || !record(value.server) || typeof value.server.pubkey !== "string" || !HEX.test(value.server.pubkey)) throw new Error("Each registry family needs a provider public key.");
|
|
22
|
+
if (!Array.isArray(value.tools) || !value.tools.length || value.tools.length > 64) throw new Error("Each family needs 1\u201364 tool name/hash pins.");
|
|
23
|
+
const tools = value.tools.map((tool) => {
|
|
24
|
+
if (!record(tool) || typeof tool.schemaHash !== "string" || !HEX.test(tool.schemaHash)) throw new Error("Each tool needs its CEP-15 schema hash.");
|
|
25
|
+
return { name: text(tool.name), schemaHash: tool.schemaHash };
|
|
26
|
+
});
|
|
27
|
+
if (new Set(tools.map((tool) => tool.name)).size !== tools.length) throw new Error("Family tool names must be unique.");
|
|
28
|
+
return {
|
|
29
|
+
family: text(value.family),
|
|
30
|
+
server: { pubkey: value.server.pubkey, relays: normalizePajaCvmRelays(value.server.relays) },
|
|
31
|
+
tools,
|
|
32
|
+
...value.description === void 0 ? {} : { description: text(value.description) },
|
|
33
|
+
...value.categories === void 0 ? {} : { categories: Array.isArray(value.categories) ? value.categories.map(text) : (() => {
|
|
34
|
+
throw new Error("Categories must be a text list.");
|
|
35
|
+
})() }
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function iceServer(value) {
|
|
39
|
+
if (!record(value) || !Array.isArray(value.urls) || !value.urls.length || value.urls.length > 8) throw new Error("Each ICE server needs 1\u20138 URLs.");
|
|
40
|
+
const urls = value.urls.map((url) => normalizePermissionScope({ kind: "ice", value: url }).value);
|
|
41
|
+
if (value.username !== void 0 && typeof value.username !== "string") throw new Error("Invalid ICE username.");
|
|
42
|
+
if (value.credential !== void 0 && typeof value.credential !== "string") throw new Error("Invalid ICE credential.");
|
|
43
|
+
return { urls, ...value.username === void 0 ? {} : { username: value.username }, ...value.credential === void 0 ? {} : { credential: value.credential } };
|
|
44
|
+
}
|
|
45
|
+
function normalizePajaMultiplayer(value) {
|
|
46
|
+
if (value === void 0) return void 0;
|
|
47
|
+
if (!record(value) || value.profile !== "soy-rtc/1") throw new Error("Select a supported multiplayer signaling profile.");
|
|
48
|
+
if (!Array.isArray(value.registry) || value.registry.length > 16) throw new Error("Configure at most 16 registry families.");
|
|
49
|
+
if (value.iceServers !== void 0 && (!Array.isArray(value.iceServers) || value.iceServers.length > 8)) throw new Error("Configure at most 8 ICE servers.");
|
|
50
|
+
return {
|
|
51
|
+
profile: value.profile,
|
|
52
|
+
relays: normalizePajaCvmRelays(value.relays),
|
|
53
|
+
registry: value.registry.map(normalizePajaCvmFamily),
|
|
54
|
+
...Array.isArray(value.iceServers) ? { iceServers: value.iceServers.map(iceServer) } : {},
|
|
55
|
+
...value.developmentNamespace === void 0 ? {} : { developmentNamespace: text(value.developmentNamespace) }
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
1
59
|
// src/config-file.ts
|
|
2
60
|
import { readFileSync } from "fs";
|
|
3
61
|
import { resolve } from "path";
|
|
@@ -191,7 +249,8 @@ function normalizePajaSimulation(raw) {
|
|
|
191
249
|
},
|
|
192
250
|
cvm: {
|
|
193
251
|
enabled: cvmEnabled
|
|
194
|
-
}
|
|
252
|
+
},
|
|
253
|
+
...raw?.multiplayer === void 0 ? {} : { multiplayer: normalizePajaMultiplayer(raw.multiplayer) }
|
|
195
254
|
};
|
|
196
255
|
}
|
|
197
256
|
function summarizePajaSimulation(simulation) {
|
|
@@ -316,7 +375,8 @@ function mergeSimulationOptions(base, override) {
|
|
|
316
375
|
values: { ...base.theme?.values, ...override.theme?.values }
|
|
317
376
|
},
|
|
318
377
|
intent: { ...base.intent, ...override.intent },
|
|
319
|
-
cvm: { ...base.cvm, ...override.cvm }
|
|
378
|
+
cvm: { ...base.cvm, ...override.cvm },
|
|
379
|
+
multiplayer: override.multiplayer ?? base.multiplayer
|
|
320
380
|
};
|
|
321
381
|
}
|
|
322
382
|
function isRecord(value) {
|
|
@@ -603,6 +663,15 @@ function renderPajaHtml(config) {
|
|
|
603
663
|
.resource-servers label { white-space: normal; }
|
|
604
664
|
.resource-servers textarea { width: 100%; min-width: 0; padding: 6px; resize: vertical; }
|
|
605
665
|
.resource-servers small, .resource-servers [role="status"] { color: var(--muted); overflow-wrap: anywhere; }
|
|
666
|
+
#paja-cvm-form { padding-bottom: 16px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
|
|
667
|
+
#paja-cvm-form > label { position: static; width: auto; height: auto; overflow: visible; clip-path: none; }
|
|
668
|
+
#paja-cvm-form input[type="text"], #paja-cvm-form select { width: 100%; min-width: 0; padding: 6px; }
|
|
669
|
+
#paja-cvm-tools { min-width: 0; max-height: 180px; overflow: auto; }
|
|
670
|
+
#paja-cvm-tools label { display: flex; overflow-wrap: anywhere; }
|
|
671
|
+
#paja-cvm-tools input { flex: 0 0 16px; width: 16px; min-height: 16px; }
|
|
672
|
+
#paja-cvm-json[readonly] { opacity: 0.8; }
|
|
673
|
+
#paja-cvm-saved > div { display: flex; gap: 6px; margin-bottom: 6px; }
|
|
674
|
+
#paja-cvm-saved button:first-child { flex: 1; min-width: 0; overflow-wrap: anywhere; }
|
|
606
675
|
.switch-grid, .acl-grid { display: flex; flex-wrap: wrap; gap: 6px; }
|
|
607
676
|
.hint { margin: 0; color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
|
|
608
677
|
.toggle { height: 24px; padding: 0 8px; color: var(--muted); }
|
|
@@ -792,6 +861,36 @@ function renderPajaHtml(config) {
|
|
|
792
861
|
<div id="paja-resource-servers-status" role="status" aria-live="polite"></div>
|
|
793
862
|
</form>
|
|
794
863
|
</div></details>
|
|
864
|
+
<details class="section" id="paja-section-multiplayer" data-paja-section="multiplayer">
|
|
865
|
+
<summary class="section-title">Multiplayer providers<span class="section-chevron" aria-hidden="true">\u203A</span></summary><div class="section-body">
|
|
866
|
+
<form class="resource-servers" id="paja-cvm-form">
|
|
867
|
+
<label for="paja-cvm-discovery">Discover CVM tools</label>
|
|
868
|
+
<input id="paja-cvm-discovery" type="text" placeholder="nevent, schema hash, or https://provider.example" spellcheck="false" aria-describedby="paja-cvm-help">
|
|
869
|
+
<button type="button" id="paja-cvm-find">Discover</button>
|
|
870
|
+
<small id="paja-cvm-help">Uses your host relays, event relay hints, or the website's .well-known/napplet.json. Family labels and tool membership are local choices.</small>
|
|
871
|
+
<label for="paja-cvm-results">Providers found</label>
|
|
872
|
+
<select id="paja-cvm-results" disabled></select>
|
|
873
|
+
<label for="paja-cvm-label">Local family label</label>
|
|
874
|
+
<input id="paja-cvm-label" type="text" maxlength="256" disabled>
|
|
875
|
+
<fieldset id="paja-cvm-tools" hidden></fieldset>
|
|
876
|
+
<label for="paja-cvm-json">Family configuration (JSON)</label>
|
|
877
|
+
<small id="paja-cvm-origin">Source: manual JSON</small>
|
|
878
|
+
<textarea id="paja-cvm-json" rows="8" spellcheck="false" aria-describedby="paja-cvm-origin paja-cvm-status"></textarea>
|
|
879
|
+
<button type="button" id="paja-cvm-manual">Edit JSON manually</button>
|
|
880
|
+
<button type="button" id="paja-cvm-new">New manual family</button>
|
|
881
|
+
<button type="submit" id="paja-cvm-save">Save family and reload</button>
|
|
882
|
+
<div id="paja-cvm-status" role="status" aria-live="polite"></div>
|
|
883
|
+
<span>Saved CVM families</span>
|
|
884
|
+
<div id="paja-cvm-saved"></div>
|
|
885
|
+
</form>
|
|
886
|
+
<form class="resource-servers" id="paja-multiplayer-form">
|
|
887
|
+
<label for="paja-multiplayer-input">Provider configuration (JSON)</label>
|
|
888
|
+
<textarea id="paja-multiplayer-input" rows="8" spellcheck="false" aria-describedby="paja-multiplayer-help paja-multiplayer-status"></textarea>
|
|
889
|
+
<small id="paja-multiplayer-help">Configure signaling relays and CVM families using your provider's settings. Saving reloads all apps. Clear to restore the host default.</small>
|
|
890
|
+
<button type="submit">Save and reload</button>
|
|
891
|
+
<div id="paja-multiplayer-status" role="status" aria-live="polite"></div>
|
|
892
|
+
</form>
|
|
893
|
+
</div></details>
|
|
795
894
|
<details class="section" id="paja-section-security" data-paja-section="security" open>
|
|
796
895
|
<summary class="section-title">Security<span class="section-chevron" aria-hidden="true">\u203A</span></summary><div class="section-body">
|
|
797
896
|
<label class="section-title" for="paja-nested-context-lock">Frame-creation lock (experimental)</label>
|
|
@@ -1224,8 +1323,8 @@ function trackRelayConnections(pool, relays, maxWaitMs) {
|
|
|
1224
1323
|
};
|
|
1225
1324
|
}
|
|
1226
1325
|
function describeRelayFailure(error) {
|
|
1227
|
-
const
|
|
1228
|
-
const trimmed =
|
|
1326
|
+
const text2 = error instanceof Error ? error.message : String(error ?? "");
|
|
1327
|
+
const trimmed = text2.trim();
|
|
1229
1328
|
return (trimmed.length > 0 ? trimmed : "connection failed").slice(0, 160);
|
|
1230
1329
|
}
|
|
1231
1330
|
function describeRelayUnreachable(pointerType, connections, maxWaitMs) {
|
|
@@ -1583,15 +1682,15 @@ async function sha256Hex(bytes) {
|
|
|
1583
1682
|
|
|
1584
1683
|
// src/installed-napplet-catalog.ts
|
|
1585
1684
|
import { manifestToIntentCatalogEntry } from "@kehto/services";
|
|
1586
|
-
function matchesInstalledNappletRecord(
|
|
1587
|
-
return target.id ===
|
|
1685
|
+
function matchesInstalledNappletRecord(record2, target) {
|
|
1686
|
+
return target.id === record2.id && target.aggregateHash === record2.aggregateHash;
|
|
1588
1687
|
}
|
|
1589
1688
|
var InstalledNappletCatalog = class {
|
|
1590
1689
|
records = /* @__PURE__ */ new Map();
|
|
1591
1690
|
listeners = /* @__PURE__ */ new Set();
|
|
1592
1691
|
/** Insert or replace a record from an already resolver-verified pointer. */
|
|
1593
1692
|
install(resolved) {
|
|
1594
|
-
const
|
|
1693
|
+
const record2 = freezeRecord({
|
|
1595
1694
|
id: resolved.manifest.catalogId,
|
|
1596
1695
|
dTag: resolved.dTag,
|
|
1597
1696
|
aggregateHash: resolved.aggregateHash,
|
|
@@ -1605,10 +1704,10 @@ var InstalledNappletCatalog = class {
|
|
|
1605
1704
|
params: [...archetype.params]
|
|
1606
1705
|
}))
|
|
1607
1706
|
});
|
|
1608
|
-
const previous = this.records.get(
|
|
1609
|
-
this.records.set(
|
|
1610
|
-
this.notify(
|
|
1611
|
-
return
|
|
1707
|
+
const previous = this.records.get(record2.id);
|
|
1708
|
+
this.records.set(record2.id, record2);
|
|
1709
|
+
this.notify(record2.id, previous, record2);
|
|
1710
|
+
return record2;
|
|
1612
1711
|
}
|
|
1613
1712
|
/** Remove an artifact explicitly; frame teardown never calls this method. */
|
|
1614
1713
|
remove(id) {
|
|
@@ -1645,10 +1744,10 @@ var InstalledNappletCatalog = class {
|
|
|
1645
1744
|
* @returns Named intent candidates usable under the supplied host policy.
|
|
1646
1745
|
*/
|
|
1647
1746
|
intentCatalog(canReceiveIntent = () => true) {
|
|
1648
|
-
return this.installed().filter(canReceiveIntent).map((
|
|
1649
|
-
catalogId:
|
|
1650
|
-
...
|
|
1651
|
-
archetypes:
|
|
1747
|
+
return this.installed().filter(canReceiveIntent).map((record2) => manifestToIntentCatalogEntry({
|
|
1748
|
+
catalogId: record2.id,
|
|
1749
|
+
...record2.title === void 0 ? {} : { title: record2.title },
|
|
1750
|
+
archetypes: record2.archetypes.map((archetype) => ({
|
|
1652
1751
|
slug: archetype.slug,
|
|
1653
1752
|
convention: archetype.convention,
|
|
1654
1753
|
params: [...archetype.params]
|
|
@@ -1688,12 +1787,12 @@ function copyPointer(pointer) {
|
|
|
1688
1787
|
relays: Object.freeze([...pointer.relays])
|
|
1689
1788
|
});
|
|
1690
1789
|
}
|
|
1691
|
-
function freezeRecord(
|
|
1790
|
+
function freezeRecord(record2) {
|
|
1692
1791
|
return Object.freeze({
|
|
1693
|
-
...
|
|
1694
|
-
requires: Object.freeze([...
|
|
1695
|
-
optional: Object.freeze([...
|
|
1696
|
-
archetypes: Object.freeze(
|
|
1792
|
+
...record2,
|
|
1793
|
+
requires: Object.freeze([...record2.requires]),
|
|
1794
|
+
optional: Object.freeze([...record2.optional ?? []]),
|
|
1795
|
+
archetypes: Object.freeze(record2.archetypes.map((archetype) => Object.freeze({ ...archetype, params: Object.freeze([...archetype.params]) })))
|
|
1697
1796
|
});
|
|
1698
1797
|
}
|
|
1699
1798
|
|
|
@@ -2453,10 +2552,10 @@ function canonicalToolChoiceModes(tools, requested) {
|
|
|
2453
2552
|
return TOOL_CHOICE_ORDER.filter((mode) => mode === "auto" || mode === "none" || wanted.has(mode));
|
|
2454
2553
|
}
|
|
2455
2554
|
function normalizeRecord(input) {
|
|
2456
|
-
const
|
|
2457
|
-
const name =
|
|
2458
|
-
const model =
|
|
2459
|
-
const id =
|
|
2555
|
+
const text2 = (value) => typeof value === "string" ? value : "";
|
|
2556
|
+
const name = text2(input.name).trim();
|
|
2557
|
+
const model = text2(input.model).trim();
|
|
2558
|
+
const id = text2(input.id);
|
|
2460
2559
|
if (!/^[A-Za-z0-9_-]{1,64}$/.test(id)) throw new Error("Invalid connection id.");
|
|
2461
2560
|
if (!name || name.length > 64) throw new Error("Enter a connection name of up to 64 characters.");
|
|
2462
2561
|
if (!model || model.length > 200) throw new Error("Enter the exact provider model identifier.");
|
|
@@ -2467,12 +2566,12 @@ function normalizeRecord(input) {
|
|
|
2467
2566
|
if (credentialHeader !== void 0 && !CREDENTIAL_HEADERS.has(credentialHeader)) throw new Error("Unknown credential header.");
|
|
2468
2567
|
if (!["vault", "session", "none"].includes(credentialStorage)) throw new Error("Unknown credential storage.");
|
|
2469
2568
|
const tools = input.tools === true;
|
|
2470
|
-
const
|
|
2569
|
+
const record2 = {
|
|
2471
2570
|
id,
|
|
2472
2571
|
name,
|
|
2473
|
-
presetId:
|
|
2572
|
+
presetId: text2(input.presetId).slice(0, 64),
|
|
2474
2573
|
protocol,
|
|
2475
|
-
baseUrl: normalizePajaLlmBaseUrl(
|
|
2574
|
+
baseUrl: normalizePajaLlmBaseUrl(text2(input.baseUrl)),
|
|
2476
2575
|
model,
|
|
2477
2576
|
images: input.images === true,
|
|
2478
2577
|
json: input.json === true,
|
|
@@ -2481,7 +2580,7 @@ function normalizeRecord(input) {
|
|
|
2481
2580
|
credentialStorage,
|
|
2482
2581
|
...credentialHeader ? { credentialHeader } : {}
|
|
2483
2582
|
};
|
|
2484
|
-
return Object.freeze(
|
|
2583
|
+
return Object.freeze(record2);
|
|
2485
2584
|
}
|
|
2486
2585
|
function readRecords(storage) {
|
|
2487
2586
|
if (!storage) return [];
|
|
@@ -2520,9 +2619,9 @@ function createPajaLlmConnectionStore(storage = storageOrNull()) {
|
|
|
2520
2619
|
};
|
|
2521
2620
|
return {
|
|
2522
2621
|
list: () => records,
|
|
2523
|
-
get: (id) => records.find((
|
|
2524
|
-
save(
|
|
2525
|
-
const normalized = normalizeRecord({ ...
|
|
2622
|
+
get: (id) => records.find((record2) => record2.id === id),
|
|
2623
|
+
save(record2) {
|
|
2624
|
+
const normalized = normalizeRecord({ ...record2 });
|
|
2526
2625
|
const index = records.findIndex((entry) => entry.id === normalized.id);
|
|
2527
2626
|
if (index === -1 && records.length >= MAX_CONNECTIONS) throw new Error(`Paja keeps at most ${MAX_CONNECTIONS} connections.`);
|
|
2528
2627
|
records = index === -1 ? [...records, normalized] : records.map((entry, position) => position === index ? normalized : entry);
|
|
@@ -2530,7 +2629,7 @@ function createPajaLlmConnectionStore(storage = storageOrNull()) {
|
|
|
2530
2629
|
return normalized;
|
|
2531
2630
|
},
|
|
2532
2631
|
remove(id) {
|
|
2533
|
-
const next = records.filter((
|
|
2632
|
+
const next = records.filter((record2) => record2.id !== id);
|
|
2534
2633
|
if (next.length === records.length) return false;
|
|
2535
2634
|
records = next;
|
|
2536
2635
|
persist();
|
|
@@ -2542,30 +2641,30 @@ function createPajaLlmConnectionStore(storage = storageOrNull()) {
|
|
|
2542
2641
|
}
|
|
2543
2642
|
};
|
|
2544
2643
|
}
|
|
2545
|
-
function describePajaLlmRoute(
|
|
2546
|
-
const preset = LLM_PROVIDER_PRESETS.find((entry) => entry.id ===
|
|
2547
|
-
const origin = new URL(
|
|
2644
|
+
function describePajaLlmRoute(record2) {
|
|
2645
|
+
const preset = LLM_PROVIDER_PRESETS.find((entry) => entry.id === record2.presetId);
|
|
2646
|
+
const origin = new URL(record2.baseUrl).origin;
|
|
2548
2647
|
const label = preset && preset.id !== "custom" ? `${preset.label} at ${origin}` : origin;
|
|
2549
2648
|
return `Paja (this browser) \u2192 ${label}`;
|
|
2550
2649
|
}
|
|
2551
|
-
function toConnection(
|
|
2552
|
-
const tools =
|
|
2650
|
+
function toConnection(record2) {
|
|
2651
|
+
const tools = record2.tools === true;
|
|
2553
2652
|
return {
|
|
2554
|
-
id:
|
|
2555
|
-
name:
|
|
2556
|
-
model:
|
|
2557
|
-
route: describePajaLlmRoute(
|
|
2558
|
-
images:
|
|
2559
|
-
json:
|
|
2653
|
+
id: record2.id,
|
|
2654
|
+
name: record2.name,
|
|
2655
|
+
model: record2.model,
|
|
2656
|
+
route: describePajaLlmRoute(record2),
|
|
2657
|
+
images: record2.images,
|
|
2658
|
+
json: record2.json,
|
|
2560
2659
|
tools,
|
|
2561
|
-
toolChoiceModes: tools ? canonicalToolChoiceModes(true,
|
|
2660
|
+
toolChoiceModes: tools ? canonicalToolChoiceModes(true, record2.toolChoiceModes) : []
|
|
2562
2661
|
};
|
|
2563
2662
|
}
|
|
2564
|
-
function meets(
|
|
2565
|
-
if (requirements.model !== void 0 && requirements.model !==
|
|
2566
|
-
if (requirements.images === true && !
|
|
2567
|
-
if (requirements.tools === true &&
|
|
2568
|
-
return !(requirements.json === true && !
|
|
2663
|
+
function meets(record2, requirements) {
|
|
2664
|
+
if (requirements.model !== void 0 && requirements.model !== record2.model) return false;
|
|
2665
|
+
if (requirements.images === true && !record2.images) return false;
|
|
2666
|
+
if (requirements.tools === true && record2.tools !== true) return false;
|
|
2667
|
+
return !(requirements.json === true && !record2.json);
|
|
2569
2668
|
}
|
|
2570
2669
|
function describeRequirements(requirements) {
|
|
2571
2670
|
const parts = [
|
|
@@ -2593,20 +2692,20 @@ function countToolResults(request) {
|
|
|
2593
2692
|
function createPajaLlmHost(options) {
|
|
2594
2693
|
const { store, vault, confirm, getIdentity } = options;
|
|
2595
2694
|
const provider = options.provider ?? createHttpLlmProvider({ stream: true });
|
|
2596
|
-
function endpointFor(
|
|
2695
|
+
function endpointFor(record2, credential) {
|
|
2597
2696
|
return {
|
|
2598
|
-
protocol:
|
|
2599
|
-
baseUrl:
|
|
2600
|
-
model:
|
|
2697
|
+
protocol: record2.protocol,
|
|
2698
|
+
baseUrl: record2.baseUrl,
|
|
2699
|
+
model: record2.model,
|
|
2601
2700
|
...credential === void 0 ? {} : { credential },
|
|
2602
|
-
...
|
|
2701
|
+
...record2.credentialHeader ? { credentialHeader: record2.credentialHeader } : {}
|
|
2603
2702
|
};
|
|
2604
2703
|
}
|
|
2605
|
-
async function ensureCredential(
|
|
2606
|
-
if (
|
|
2607
|
-
const existing = vault.getCredential(
|
|
2704
|
+
async function ensureCredential(record2, signal) {
|
|
2705
|
+
if (record2.credentialStorage === "none") return void 0;
|
|
2706
|
+
const existing = vault.getCredential(record2.id);
|
|
2608
2707
|
if (existing !== void 0) return existing;
|
|
2609
|
-
if (
|
|
2708
|
+
if (record2.credentialStorage === "session") {
|
|
2610
2709
|
options.openPanel();
|
|
2611
2710
|
throw new LlmServiceError("unsupported", "This connection's API key was kept for one session only. Enter it again in Language models.");
|
|
2612
2711
|
}
|
|
@@ -2614,7 +2713,7 @@ function createPajaLlmHost(options) {
|
|
|
2614
2713
|
const unlocked = await options.requestUnlock(signal);
|
|
2615
2714
|
if (!unlocked) throw new LlmServiceError("user-cancelled", "The credential vault stayed locked.");
|
|
2616
2715
|
}
|
|
2617
|
-
const credential = vault.getCredential(
|
|
2716
|
+
const credential = vault.getCredential(record2.id);
|
|
2618
2717
|
if (credential === void 0) {
|
|
2619
2718
|
options.openPanel();
|
|
2620
2719
|
throw new LlmServiceError("unsupported", "No API key is stored for this connection. Enter it again in Language models.");
|
|
@@ -2624,7 +2723,7 @@ function createPajaLlmHost(options) {
|
|
|
2624
2723
|
async function select(context, requirements, prompt) {
|
|
2625
2724
|
const signal = prompt?.signal;
|
|
2626
2725
|
const napplet = getIdentity(context.windowId);
|
|
2627
|
-
const candidates = store.list().filter((
|
|
2726
|
+
const candidates = store.list().filter((record2) => meets(record2, requirements));
|
|
2628
2727
|
if (candidates.length === 0) {
|
|
2629
2728
|
const configure = await confirm({ action: "llm-configure", windowId: context.windowId, napplet, requirements: describeRequirements(requirements), configured: store.list().length, ...signal ? { signal } : {} });
|
|
2630
2729
|
if (!configure) return null;
|
|
@@ -2640,24 +2739,24 @@ function createPajaLlmHost(options) {
|
|
|
2640
2739
|
isConfigured: () => store.list().length > 0,
|
|
2641
2740
|
select,
|
|
2642
2741
|
describe(_context, connectionId) {
|
|
2643
|
-
const
|
|
2644
|
-
return
|
|
2742
|
+
const record2 = store.get(connectionId);
|
|
2743
|
+
return record2 ? toConnection(record2) : null;
|
|
2645
2744
|
},
|
|
2646
2745
|
async authorize(context, connection, request, prompt) {
|
|
2647
2746
|
const signal = prompt?.signal;
|
|
2648
|
-
const
|
|
2649
|
-
if (!
|
|
2650
|
-
buildLlmProviderRequest(endpointFor(
|
|
2651
|
-
await ensureCredential(
|
|
2747
|
+
const record2 = store.get(connection.id);
|
|
2748
|
+
if (!record2) throw new LlmServiceError("selection-expired", "The selected connection was removed; select again.");
|
|
2749
|
+
buildLlmProviderRequest(endpointFor(record2), request, { stream: true });
|
|
2750
|
+
await ensureCredential(record2, signal);
|
|
2652
2751
|
if (signal?.aborted) return false;
|
|
2653
2752
|
return confirm({
|
|
2654
2753
|
...signal ? { signal } : {},
|
|
2655
2754
|
action: "llm",
|
|
2656
2755
|
windowId: context.windowId,
|
|
2657
2756
|
napplet: getIdentity(context.windowId),
|
|
2658
|
-
connection:
|
|
2659
|
-
model:
|
|
2660
|
-
route: describePajaLlmRoute(
|
|
2757
|
+
connection: record2.name,
|
|
2758
|
+
model: record2.model,
|
|
2759
|
+
route: describePajaLlmRoute(record2),
|
|
2661
2760
|
messages: request.messages.length,
|
|
2662
2761
|
characters: countCharacters(request),
|
|
2663
2762
|
images: countLlmImages(request.messages),
|
|
@@ -2668,10 +2767,10 @@ function createPajaLlmHost(options) {
|
|
|
2668
2767
|
});
|
|
2669
2768
|
},
|
|
2670
2769
|
async generate(_context, connection, request, hooks) {
|
|
2671
|
-
const
|
|
2672
|
-
if (!
|
|
2673
|
-
const credential = await ensureCredential(
|
|
2674
|
-
return provider(endpointFor(
|
|
2770
|
+
const record2 = store.get(connection.id);
|
|
2771
|
+
if (!record2) throw new LlmServiceError("selection-expired", "The selected connection was removed; select again.");
|
|
2772
|
+
const credential = await ensureCredential(record2);
|
|
2773
|
+
return provider(endpointFor(record2, credential), request, hooks.signal, (event) => hooks.onDelta(event));
|
|
2675
2774
|
},
|
|
2676
2775
|
subscribe(listener) {
|
|
2677
2776
|
const stopStore = store.subscribe(listener);
|
|
@@ -2837,6 +2936,7 @@ function createPajaLlmVault(options = {}) {
|
|
|
2837
2936
|
}
|
|
2838
2937
|
|
|
2839
2938
|
export {
|
|
2939
|
+
normalizePajaMultiplayer,
|
|
2840
2940
|
PajaSimulationError,
|
|
2841
2941
|
PAJA_SIMULATION_DOMAINS,
|
|
2842
2942
|
normalizePajaSimulation,
|
|
@@ -2898,4 +2998,4 @@ export {
|
|
|
2898
2998
|
validatePajaLlmVaultPassword,
|
|
2899
2999
|
createPajaLlmVault
|
|
2900
3000
|
};
|
|
2901
|
-
//# sourceMappingURL=chunk-
|
|
3001
|
+
//# sourceMappingURL=chunk-F3KNRWX7.js.map
|