@thanh01.pmt/curriculum-kit 1.0.10 → 1.0.11

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 CHANGED
@@ -13549,7 +13549,7 @@ function safeParseJson(rawText) {
13549
13549
  return null;
13550
13550
  }
13551
13551
  }
13552
- async function streamLLMWithFallback(systemPrompt, userPrompt, apiKeys = {}, onChunk) {
13552
+ async function streamLLMWithFallback(systemPrompt, userPrompt, apiKeys = {}, onChunk, preferredModel, preferredProvider) {
13553
13553
  const alibabaKey = apiKeys.alibaba || apiKeys.dashscope || process.env.ALIBABA_API_KEY || process.env.DASHSCOPE_API_KEY;
13554
13554
  const nvidiaKey = apiKeys.nvidia || process.env.NVIDIA_API_KEY;
13555
13555
  const deepseekKey = apiKeys.deepseek || process.env.DEEPSEEK_API_KEY;
@@ -13557,6 +13557,11 @@ async function streamLLMWithFallback(systemPrompt, userPrompt, apiKeys = {}, onC
13557
13557
  const geminiKey = apiKeys.gemini || process.env.GEMINI_API_KEY;
13558
13558
  const openrouterPreset = process.env.OPENROUTER_FREE_PRESET || "@preset/coding-free";
13559
13559
  const candidates = [];
13560
+ if (preferredModel) {
13561
+ const prov = preferredProvider || "openrouter";
13562
+ const key = apiKeys[prov] || (prov === "openrouter" ? openrouterKey : prov === "nvidia" ? nvidiaKey : prov === "alibaba" ? alibabaKey : geminiKey) || "";
13563
+ candidates.push({ provider: prov, model: preferredModel, apiKey: key });
13564
+ }
13560
13565
  if (openrouterKey && isProviderEnabled("openrouter")) {
13561
13566
  const orModels = [
13562
13567
  openrouterPreset,
@@ -13564,40 +13569,49 @@ async function streamLLMWithFallback(systemPrompt, userPrompt, apiKeys = {}, onC
13564
13569
  "nvidia/nemotron-3-super-120b-a12b:free",
13565
13570
  "nvidia/nemotron-3-ultra-550b-a55b:free",
13566
13571
  "nvidia/nemotron-3.5-lightning:free",
13567
- "minimax/minimax-m3:free",
13568
13572
  "cohere/north-mini-code:free"
13569
13573
  ].filter((m) => isModelAllowed(m));
13570
13574
  for (const m of Array.from(new Set(orModels))) {
13571
- candidates.push({ provider: "openrouter", model: m, apiKey: openrouterKey });
13575
+ if (!candidates.some((c) => c.provider === "openrouter" && c.model === m)) {
13576
+ candidates.push({ provider: "openrouter", model: m, apiKey: openrouterKey });
13577
+ }
13572
13578
  }
13573
13579
  }
13574
13580
  if (nvidiaKey && isProviderEnabled("nvidia")) {
13575
13581
  const nemotronModels = [
13576
- "nvidia/nemotron-3-ultra-550b-a55b:free",
13582
+ "nvidia/nemotron-3-ultra-550b-a55b",
13577
13583
  "nvidia/nemotron-3.5-lightning-30b-a3b",
13578
13584
  "nvidia/nemotron-3-super-120b-a12b",
13579
13585
  "nvidia/llama-3.1-nemotron-70b-instruct"
13580
13586
  ].filter((m) => isModelAllowed(m));
13581
13587
  for (const m of nemotronModels) {
13582
- candidates.push({ provider: "nvidia", model: m, apiKey: nvidiaKey });
13588
+ if (!candidates.some((c) => c.provider === "nvidia" && c.model === m)) {
13589
+ candidates.push({ provider: "nvidia", model: m, apiKey: nvidiaKey });
13590
+ }
13583
13591
  }
13584
13592
  }
13585
13593
  if (alibabaKey && isProviderEnabled("alibaba")) {
13586
13594
  const aliModels = ["qwen-plus", "qwen-turbo", "qwen3.7-plus"].filter((m) => isModelAllowed(m));
13587
13595
  for (const m of aliModels) {
13588
- candidates.push({ provider: "alibaba", model: m, apiKey: alibabaKey });
13596
+ if (!candidates.some((c) => c.provider === "alibaba" && c.model === m)) {
13597
+ candidates.push({ provider: "alibaba", model: m, apiKey: alibabaKey });
13598
+ }
13589
13599
  }
13590
13600
  }
13591
13601
  if (deepseekKey && isProviderEnabled("deepseek")) {
13592
13602
  const dsModels = ["deepseek-chat", "deepseek-coder"].filter((m) => isModelAllowed(m));
13593
13603
  for (const m of dsModels) {
13594
- candidates.push({ provider: "deepseek", model: m, apiKey: deepseekKey });
13604
+ if (!candidates.some((c) => c.provider === "deepseek" && c.model === m)) {
13605
+ candidates.push({ provider: "deepseek", model: m, apiKey: deepseekKey });
13606
+ }
13595
13607
  }
13596
13608
  }
13597
13609
  if (geminiKey && (isProviderEnabled("gemini") || isProviderEnabled("google"))) {
13598
13610
  const gModels = ["gemini-1.5-flash", "gemini-2.0-flash", "gemini-1.5-pro"].filter((m) => isModelAllowed(m));
13599
13611
  for (const m of gModels) {
13600
- candidates.push({ provider: "google", model: m, apiKey: geminiKey });
13612
+ if (!candidates.some((c) => c.provider === "google" && c.model === m)) {
13613
+ candidates.push({ provider: "google", model: m, apiKey: geminiKey });
13614
+ }
13601
13615
  }
13602
13616
  }
13603
13617
  const fallbackChain = getDesignatedFallbackChain();
@@ -13626,15 +13640,27 @@ THINKING DIRECTIVE: Keep reasoning concise, structured, and focused strictly on
13626
13640
  system: systemInstructions,
13627
13641
  prompt: userPrompt,
13628
13642
  temperature: 0.2,
13629
- abortSignal: AbortSignal.timeout(25e3)
13643
+ includeRawChunks: true,
13644
+ abortSignal: AbortSignal.timeout(6e4)
13630
13645
  });
13631
13646
  let fullContent = "";
13632
13647
  for await (const part of streamResult.fullStream) {
13633
13648
  if (part.type === "reasoning-delta") {
13634
- onChunk?.(part.text, "thought");
13649
+ const thoughtText = part.text ?? part.delta ?? "";
13650
+ if (thoughtText) onChunk?.(thoughtText, "thought");
13651
+ } else if (part.type === "raw") {
13652
+ const raw = part.rawValue;
13653
+ const delta = raw?.choices?.[0]?.delta;
13654
+ const reasoning = delta?.reasoning_content || delta?.reasoning;
13655
+ if (reasoning) {
13656
+ onChunk?.(reasoning, "thought");
13657
+ }
13635
13658
  } else if (part.type === "text-delta") {
13636
- fullContent += part.text;
13637
- onChunk?.(part.text, "content");
13659
+ const textDelta = part.text ?? part.delta ?? "";
13660
+ if (textDelta) {
13661
+ fullContent += textDelta;
13662
+ onChunk?.(textDelta, "content");
13663
+ }
13638
13664
  }
13639
13665
  }
13640
13666
  if (fullContent.trim()) {
@@ -13822,7 +13848,9 @@ REQUIREMENT: Synthesize all parameters above and produce the high-fidelity pre-f
13822
13848
  (chunk, type) => {
13823
13849
  if (type === "content") rawContent += chunk;
13824
13850
  onChunk?.(chunk, type);
13825
- }
13851
+ },
13852
+ options.model,
13853
+ options.provider
13826
13854
  );
13827
13855
  const parsed = safeParseJson(rawContent);
13828
13856
  return {