@thanh01.pmt/curriculum-kit 1.4.26 → 1.4.27

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.
Files changed (40) hide show
  1. package/LICENSE +21 -0
  2. package/dist/ai/index.cjs +68 -5
  3. package/dist/ai/index.cjs.map +1 -1
  4. package/dist/ai/index.d.cts +4 -4
  5. package/dist/ai/index.d.ts +4 -4
  6. package/dist/ai/index.mjs +68 -6
  7. package/dist/ai/index.mjs.map +1 -1
  8. package/dist/index.cjs +69 -5
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +5 -5
  11. package/dist/index.d.ts +5 -5
  12. package/dist/index.mjs +69 -6
  13. package/dist/index.mjs.map +1 -1
  14. package/dist/media/index.cjs +52 -4
  15. package/dist/media/index.cjs.map +1 -1
  16. package/dist/media/index.d.cts +1 -1
  17. package/dist/media/index.d.ts +1 -1
  18. package/dist/media/index.mjs +52 -4
  19. package/dist/media/index.mjs.map +1 -1
  20. package/dist/{milestoneBundleGenerator-CzSOeAzU.d.cts → milestoneBundleGenerator-CN6F1zPs.d.cts} +1 -1
  21. package/dist/{milestoneBundleGenerator-Bkba8OPG.d.ts → milestoneBundleGenerator-DTiJ5gIh.d.ts} +1 -1
  22. package/dist/pipeline/index.cjs +23 -4
  23. package/dist/pipeline/index.cjs.map +1 -1
  24. package/dist/pipeline/index.d.cts +3 -3
  25. package/dist/pipeline/index.d.ts +3 -3
  26. package/dist/pipeline/index.mjs +23 -4
  27. package/dist/pipeline/index.mjs.map +1 -1
  28. package/dist/{provider-factory-DxzOVEmh.d.cts → provider-factory-Bv-eIkhg.d.cts} +1 -1
  29. package/dist/{provider-factory-DxzOVEmh.d.ts → provider-factory-Bv-eIkhg.d.ts} +1 -1
  30. package/dist/storage/index.d.cts +2 -2
  31. package/dist/storage/index.d.ts +2 -2
  32. package/dist/{streamRunner-CYESG6IE.d.cts → streamRunner-kpS4MZP1.d.cts} +2 -1
  33. package/dist/{streamRunner-CYESG6IE.d.ts → streamRunner-kpS4MZP1.d.ts} +2 -1
  34. package/dist/workflow/index.cjs +67 -5
  35. package/dist/workflow/index.cjs.map +1 -1
  36. package/dist/workflow/index.d.cts +1 -1
  37. package/dist/workflow/index.d.ts +1 -1
  38. package/dist/workflow/index.mjs +67 -5
  39. package/dist/workflow/index.mjs.map +1 -1
  40. package/package.json +22 -23
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Tony Pham
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/ai/index.cjs CHANGED
@@ -177,14 +177,19 @@ function isModelAllowed(model) {
177
177
  });
178
178
  }
179
179
  function getDesignatedFallbackChain() {
180
- const rawProviders = resolveApiKey("FALLBACK_AI_PROVIDER") || resolveApiKey("FALLBACK_AI_PROVIDERS") || resolveApiKey("DEFAULT_AI_PROVIDER") || "nvidia,openrouter";
181
- const rawModels = resolveApiKey("FALLBACK_AI_MODEL") || resolveApiKey("FALLBACK_AI_MODELS") || resolveApiKey("DEFAULT_AI_MODEL") || "nvidia/nemotron-3-ultra-550b-a55b:free,@preset/coding-free,deepseek/deepseek-chat:free";
180
+ const rawProviders = resolveApiKey("FALLBACK_AI_PROVIDER") || resolveApiKey("FALLBACK_AI_PROVIDERS") || resolveApiKey("DEFAULT_AI_PROVIDER") || "9router,nvidia,openrouter";
181
+ const rawModels = resolveApiKey("FALLBACK_AI_MODEL") || resolveApiKey("FALLBACK_AI_MODELS") || resolveApiKey("DEFAULT_AI_MODEL") || "fast-reasoning,deep-reasoning,mid-range,free-tier";
182
182
  const providerList = rawProviders.split(",").map((p) => p.trim().toLowerCase()).filter((p) => p.length > 0 && isProviderEnabled(p));
183
183
  const modelList = rawModels.split(",").map((m) => m.trim()).filter((m) => m.length > 0 && isModelAllowed(m));
184
184
  const chain = [];
185
185
  for (const provider of providerList) {
186
186
  let providerModels = [];
187
- if (provider === "nvidia") {
187
+ if (provider === "9router" || provider === "ninerouter") {
188
+ providerModels = modelList.filter((m) => ["fast-reasoning", "deep-reasoning", "mid-range", "free-tier"].includes(m));
189
+ if (providerModels.length === 0) {
190
+ providerModels = ["fast-reasoning", "mid-range", "free-tier"];
191
+ }
192
+ } else if (provider === "nvidia") {
188
193
  providerModels = modelList.filter((m) => m.startsWith("nvidia/") || m.startsWith("meta/") || m.startsWith("mistralai/"));
189
194
  if (providerModels.length === 0) {
190
195
  providerModels = ["nvidia/nemotron-3-ultra-550b-a55b:free", "nvidia/nemotron-3.5-lightning-30b-a3b"];
@@ -223,7 +228,7 @@ function getDesignatedFallbackChain() {
223
228
  function getDesignatedFallbackConfig() {
224
229
  const chain = getDesignatedFallbackChain();
225
230
  if (chain.length > 0) return chain[0];
226
- return { provider: "nvidia", model: "nvidia/nemotron-3-ultra-550b-a55b:free" };
231
+ return { provider: "9router", model: "fast-reasoning" };
227
232
  }
228
233
  function extractThoughtAndContent(rawText) {
229
234
  let text = rawText || "";
@@ -467,8 +472,51 @@ Guidelines:
467
472
  }))
468
473
  ];
469
474
  const providerErrors = {};
470
- const requestedModel = options.model || "@preset/coding-free";
475
+ const requestedModel = options.model || "fast-reasoning";
471
476
  const isNvidiaPreferred = requestedModel.startsWith("nvidia/") || Boolean(nvidiaKey && !openrouterKey) && isProviderEnabled("nvidia");
477
+ const ninerouterKey = resolveApiKey("NINEROUTER_API_KEY") || resolveApiKey("NINE_ROUTER_API_KEY");
478
+ if (ninerouterKey && isProviderEnabled("9router")) {
479
+ const rawUrl = resolveApiKey("NINEROUTER_BASE_URL") || resolveApiKey("NINE_ROUTER_BASE_URL") || "https://ai-router.orchable.app/v1";
480
+ const ninerouterBaseUrl = rawUrl.replace(/^["']|["']$/g, "").replace(/\/$/, "");
481
+ const candidateModels = [
482
+ options.model || "fast-reasoning",
483
+ "fast-reasoning",
484
+ "mid-range",
485
+ "free-tier"
486
+ ].filter((m) => isModelAllowed(m));
487
+ const unique9RouterModels = Array.from(new Set(candidateModels));
488
+ for (const model of unique9RouterModels) {
489
+ try {
490
+ const idle = createStreamAbortController({ idleMs: 45e3, totalMs: 3e5 });
491
+ const res = await fetch(`${ninerouterBaseUrl}/chat/completions`, {
492
+ method: "POST",
493
+ headers: {
494
+ "Authorization": `Bearer ${ninerouterKey}`,
495
+ "Content-Type": "application/json"
496
+ },
497
+ body: JSON.stringify({
498
+ model,
499
+ messages: formattedMessages,
500
+ max_tokens: maxTokens,
501
+ temperature,
502
+ stream: true,
503
+ stream_options: { include_usage: true }
504
+ }),
505
+ signal: idle.signal
506
+ });
507
+ if (res.ok) {
508
+ const text = await processOpenAISSEStream(res, onChunk, idle);
509
+ if (text && text.trim()) return text;
510
+ } else {
511
+ const errText = await res.text().catch(() => "");
512
+ providerErrors[`9router_${model}`] = `HTTP ${res.status}: ${errText.slice(0, 120)}`;
513
+ }
514
+ } catch (e) {
515
+ providerErrors[`9router_${model}`] = e?.message || "Network error";
516
+ console.warn(`[9Router Stream] Failover for ${model}:`, e?.message || e);
517
+ }
518
+ }
519
+ }
472
520
  if (nvidiaKey && isProviderEnabled("nvidia")) {
473
521
  const candidateNemotronModels = [
474
522
  requestedModel.startsWith("nvidia/") ? requestedModel : "nvidia/nemotron-3-ultra-550b-a55b:free",
@@ -835,6 +883,8 @@ async function runCurriculumAIInference(messages, projectContext, options = {},
835
883
 
836
884
  // src/ai/provider-factory.ts
837
885
  var DEFAULT_MODELS = {
886
+ "9router": "fast-reasoning",
887
+ ninerouter: "fast-reasoning",
838
888
  nvidia: "nvidia/nemotron-3-ultra-550b-a55b:free",
839
889
  openrouter: "@preset/coding-free",
840
890
  alibaba: "qwen3.7-plus",
@@ -866,6 +916,15 @@ function getAIModel(options = {}) {
866
916
  console.warn(`[provider-factory] Model "${resolvedModelName}" is not permitted by ALLOWED_AI_MODELS. Using designated model "${designated.model}".`);
867
917
  resolvedModelName = designated.model;
868
918
  }
919
+ if (provider === "9router" || provider === "ninerouter") {
920
+ const apiKey = options.apiKey || resolveApiKey("NINEROUTER_API_KEY") || resolveApiKey("NINE_ROUTER_API_KEY") || "";
921
+ const rawUrl = options.baseURL || resolveApiKey("NINEROUTER_BASE_URL") || resolveApiKey("NINE_ROUTER_BASE_URL") || "https://ai-router.orchable.app/v1";
922
+ const ninerouter = openai.createOpenAI({
923
+ apiKey,
924
+ baseURL: rawUrl.replace(/^["']|["']$/g, "").trim()
925
+ });
926
+ return ninerouter.chat(resolvedModelName || "fast-reasoning");
927
+ }
869
928
  if (provider === "nvidia") {
870
929
  const apiKey = options.apiKey || process.env.NVIDIA_API_KEY || "";
871
930
  const nvidia = openai.createOpenAI({
@@ -934,6 +993,9 @@ function getAIModel(options = {}) {
934
993
  return fallback.chat(resolvedModelName);
935
994
  }
936
995
  function detectDefaultProvider() {
996
+ if ((process.env.NINEROUTER_API_KEY || resolveApiKey("NINEROUTER_API_KEY") || resolveApiKey("NINE_ROUTER_API_KEY")) && isProviderEnabled("9router")) {
997
+ return "9router";
998
+ }
937
999
  if (process.env.NVIDIA_API_KEY && isProviderEnabled("nvidia")) {
938
1000
  return "nvidia";
939
1001
  }
@@ -5130,6 +5192,7 @@ exports.isModelAllowed = isModelAllowed;
5130
5192
  exports.isProviderEnabled = isProviderEnabled;
5131
5193
  exports.packagerTools = packagerTools;
5132
5194
  exports.researcherTools = researcherTools;
5195
+ exports.resolveApiKey = resolveApiKey;
5133
5196
  exports.reviewerTools = reviewerTools;
5134
5197
  exports.runCurriculumAIInference = runCurriculumAIInference;
5135
5198
  exports.streamCurriculumAIInference = streamCurriculumAIInference;