noosphere 0.2.1 → 0.2.2
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/dist/index.cjs +29 -62
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +29 -62
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -279,7 +279,6 @@ var UsageTracker = class {
|
|
|
279
279
|
// src/providers/pi-ai.ts
|
|
280
280
|
var import_pi_ai = require("@mariozechner/pi-ai");
|
|
281
281
|
var KNOWN_PROVIDERS = ["anthropic", "google", "openai", "xai", "groq", "cerebras", "openrouter", "zai"];
|
|
282
|
-
var LOCAL_PROVIDERS = /* @__PURE__ */ new Set(["ollama"]);
|
|
283
282
|
var FETCH_TIMEOUT_MS = 8e3;
|
|
284
283
|
var OPENAI_CHAT_PREFIXES = ["gpt-", "o1", "o3", "o4", "chatgpt-", "codex-"];
|
|
285
284
|
var OPENAI_REASONING_PREFIXES = ["o1", "o3", "o4"];
|
|
@@ -420,35 +419,7 @@ var PiAiProvider = class {
|
|
|
420
419
|
if (modality && modality !== "llm") return [];
|
|
421
420
|
await this.ensureDynamicModels();
|
|
422
421
|
const models = [];
|
|
423
|
-
const
|
|
424
|
-
for (const provider of KNOWN_PROVIDERS) {
|
|
425
|
-
try {
|
|
426
|
-
const providerModels = (0, import_pi_ai.getModels)(provider);
|
|
427
|
-
for (const m of providerModels) {
|
|
428
|
-
seenIds.add(m.id);
|
|
429
|
-
models.push({
|
|
430
|
-
id: m.id,
|
|
431
|
-
provider: "pi-ai",
|
|
432
|
-
name: m.name || m.id,
|
|
433
|
-
modality: "llm",
|
|
434
|
-
local: LOCAL_PROVIDERS.has(String(m.provider)),
|
|
435
|
-
cost: {
|
|
436
|
-
price: m.cost.input ?? 0,
|
|
437
|
-
unit: m.cost.input > 0 ? "per_1m_tokens" : "free"
|
|
438
|
-
},
|
|
439
|
-
capabilities: {
|
|
440
|
-
contextWindow: m.contextWindow,
|
|
441
|
-
maxTokens: m.maxTokens,
|
|
442
|
-
supportsVision: m.input.includes("image"),
|
|
443
|
-
supportsStreaming: true
|
|
444
|
-
}
|
|
445
|
-
});
|
|
446
|
-
}
|
|
447
|
-
} catch {
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
for (const [id, m] of this.dynamicModels) {
|
|
451
|
-
if (seenIds.has(id)) continue;
|
|
422
|
+
for (const [, m] of this.dynamicModels) {
|
|
452
423
|
models.push({
|
|
453
424
|
id: m.id,
|
|
454
425
|
provider: "pi-ai",
|
|
@@ -583,24 +554,15 @@ var PiAiProvider = class {
|
|
|
583
554
|
async ensureDynamicModels() {
|
|
584
555
|
if (this.dynamicModelsFetched) return;
|
|
585
556
|
this.dynamicModelsFetched = true;
|
|
586
|
-
const staticIds = /* @__PURE__ */ new Set();
|
|
587
|
-
for (const provider of KNOWN_PROVIDERS) {
|
|
588
|
-
try {
|
|
589
|
-
for (const m of (0, import_pi_ai.getModels)(provider)) {
|
|
590
|
-
staticIds.add(m.id);
|
|
591
|
-
}
|
|
592
|
-
} catch {
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
557
|
const fetchPromises = [];
|
|
596
558
|
for (const [providerKey, configFactory] of Object.entries(PROVIDER_APIS)) {
|
|
597
559
|
const apiKey = this.keys[providerKey];
|
|
598
560
|
if (!apiKey) continue;
|
|
599
|
-
fetchPromises.push(this.fetchProviderModels(configFactory(apiKey), apiKey
|
|
561
|
+
fetchPromises.push(this.fetchProviderModels(configFactory(apiKey), apiKey));
|
|
600
562
|
}
|
|
601
563
|
await Promise.allSettled(fetchPromises);
|
|
602
564
|
}
|
|
603
|
-
async fetchProviderModels(config, apiKey
|
|
565
|
+
async fetchProviderModels(config, apiKey) {
|
|
604
566
|
try {
|
|
605
567
|
const controller = new AbortController();
|
|
606
568
|
const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
@@ -613,11 +575,11 @@ var PiAiProvider = class {
|
|
|
613
575
|
if (!res.ok) return;
|
|
614
576
|
const data = await res.json();
|
|
615
577
|
const entries = config.extractEntries(data);
|
|
616
|
-
const
|
|
578
|
+
const staticTemplate = this.findStaticTemplate(config.providerName);
|
|
617
579
|
for (const entry of entries) {
|
|
618
580
|
const id = entry.id;
|
|
619
581
|
if (!config.filterChat(id)) continue;
|
|
620
|
-
|
|
582
|
+
const staticMatch = this.findStaticModel(config.providerName, id);
|
|
621
583
|
this.dynamicModels.set(id, {
|
|
622
584
|
id,
|
|
623
585
|
name: entry.name ?? id,
|
|
@@ -625,10 +587,10 @@ var PiAiProvider = class {
|
|
|
625
587
|
provider: config.providerName,
|
|
626
588
|
baseUrl: config.piBaseUrl,
|
|
627
589
|
reasoning: config.isReasoning(id),
|
|
628
|
-
input: ["text", "image"],
|
|
629
|
-
cost:
|
|
630
|
-
contextWindow: entry.contextWindow ??
|
|
631
|
-
maxTokens: entry.maxTokens ??
|
|
590
|
+
input: staticMatch?.input ?? ["text", "image"],
|
|
591
|
+
cost: staticMatch?.cost ?? staticTemplate?.cost ?? { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
592
|
+
contextWindow: entry.contextWindow ?? staticMatch?.contextWindow ?? staticTemplate?.contextWindow ?? 128e3,
|
|
593
|
+
maxTokens: entry.maxTokens ?? staticMatch?.maxTokens ?? staticTemplate?.maxTokens ?? 16384
|
|
632
594
|
});
|
|
633
595
|
}
|
|
634
596
|
} finally {
|
|
@@ -645,6 +607,14 @@ var PiAiProvider = class {
|
|
|
645
607
|
return null;
|
|
646
608
|
}
|
|
647
609
|
}
|
|
610
|
+
findStaticModel(providerName, modelId) {
|
|
611
|
+
try {
|
|
612
|
+
const models = (0, import_pi_ai.getModels)(providerName);
|
|
613
|
+
return models.find((m) => m.id === modelId) ?? null;
|
|
614
|
+
} catch {
|
|
615
|
+
return null;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
648
618
|
/** Force re-fetch of dynamic models from provider APIs */
|
|
649
619
|
async refreshDynamicModels() {
|
|
650
620
|
this.dynamicModelsFetched = false;
|
|
@@ -652,18 +622,24 @@ var PiAiProvider = class {
|
|
|
652
622
|
await this.ensureDynamicModels();
|
|
653
623
|
}
|
|
654
624
|
findModel(modelId) {
|
|
625
|
+
if (modelId) {
|
|
626
|
+
const dynamic = this.dynamicModels.get(modelId);
|
|
627
|
+
if (dynamic) return { model: dynamic, provider: String(dynamic.provider) };
|
|
628
|
+
}
|
|
629
|
+
if (!modelId) {
|
|
630
|
+
const first = this.dynamicModels.values().next();
|
|
631
|
+
if (!first.done && first.value) {
|
|
632
|
+
return { model: first.value, provider: String(first.value.provider) };
|
|
633
|
+
}
|
|
634
|
+
}
|
|
655
635
|
for (const provider of KNOWN_PROVIDERS) {
|
|
656
636
|
try {
|
|
657
637
|
const models = (0, import_pi_ai.getModels)(provider);
|
|
658
|
-
const found = modelId ? models.find((m) => m.id === modelId) :
|
|
638
|
+
const found = modelId ? models.find((m) => m.id === modelId) : void 0;
|
|
659
639
|
if (found) return { model: found, provider };
|
|
660
640
|
} catch {
|
|
661
641
|
}
|
|
662
642
|
}
|
|
663
|
-
if (modelId) {
|
|
664
|
-
const dynamic = this.dynamicModels.get(modelId);
|
|
665
|
-
if (dynamic) return { model: dynamic, provider: String(dynamic.provider) };
|
|
666
|
-
}
|
|
667
643
|
return { model: null, provider: null };
|
|
668
644
|
}
|
|
669
645
|
};
|
|
@@ -1044,11 +1020,6 @@ var PIPELINE_TAG_MAP = {
|
|
|
1044
1020
|
"text-to-image": { modality: "image", limit: 50 },
|
|
1045
1021
|
"text-to-speech": { modality: "tts", limit: 30 }
|
|
1046
1022
|
};
|
|
1047
|
-
var DEFAULT_MODELS = [
|
|
1048
|
-
{ id: "stabilityai/stable-diffusion-xl-base-1.0", provider: "huggingface", name: "SDXL Base", modality: "image", local: false, cost: { price: 0, unit: "free" } },
|
|
1049
|
-
{ id: "facebook/mms-tts-eng", provider: "huggingface", name: "MMS TTS English", modality: "tts", local: false, cost: { price: 0, unit: "free" } },
|
|
1050
|
-
{ id: "meta-llama/Llama-3.1-8B-Instruct", provider: "huggingface", name: "Llama 3.1 8B", modality: "llm", local: false, cost: { price: 0, unit: "free" } }
|
|
1051
|
-
];
|
|
1052
1023
|
var HuggingFaceProvider = class {
|
|
1053
1024
|
id = "huggingface";
|
|
1054
1025
|
name = "HuggingFace Inference";
|
|
@@ -1068,17 +1039,13 @@ var HuggingFaceProvider = class {
|
|
|
1068
1039
|
if (!this.dynamicModels) {
|
|
1069
1040
|
await this.fetchHubModels();
|
|
1070
1041
|
}
|
|
1071
|
-
const all = this.dynamicModels ??
|
|
1042
|
+
const all = this.dynamicModels ?? [];
|
|
1072
1043
|
if (modality) return all.filter((m) => m.modality === modality);
|
|
1073
1044
|
return all;
|
|
1074
1045
|
}
|
|
1075
1046
|
async fetchHubModels() {
|
|
1076
1047
|
const seenIds = /* @__PURE__ */ new Set();
|
|
1077
1048
|
const models = [];
|
|
1078
|
-
for (const d of DEFAULT_MODELS) {
|
|
1079
|
-
seenIds.add(d.id);
|
|
1080
|
-
models.push(d);
|
|
1081
|
-
}
|
|
1082
1049
|
const fetches = Object.entries(PIPELINE_TAG_MAP).map(
|
|
1083
1050
|
([tag, { modality, limit }]) => this.fetchByPipelineTag(tag, modality, limit)
|
|
1084
1051
|
);
|