@thanh01.pmt/curriculum-kit 1.4.27 → 1.4.28

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/ai/index.mjs CHANGED
@@ -719,7 +719,41 @@ Guidelines:
719
719
  );
720
720
  for (const target of fallbackChain) {
721
721
  const { provider, model } = target;
722
- if (provider === "nvidia" && nvidiaKey && isProviderEnabled("nvidia")) {
722
+ if ((provider === "9router" || provider === "ninerouter") && ninerouterKey && isProviderEnabled("9router")) {
723
+ try {
724
+ const rawUrl = resolveApiKey("NINEROUTER_BASE_URL") || resolveApiKey("NINE_ROUTER_BASE_URL") || "https://ai-router.orchable.app/v1";
725
+ const fbBaseUrl = rawUrl.replace(/["']/g, "").replace(/\/$/, "");
726
+ const idle = createStreamAbortController({ idleMs: 45e3, totalMs: 3e5 });
727
+ const res = await fetch(`${fbBaseUrl}/chat/completions`, {
728
+ method: "POST",
729
+ headers: {
730
+ "Authorization": `Bearer ${ninerouterKey}`,
731
+ "Content-Type": "application/json"
732
+ },
733
+ body: JSON.stringify({
734
+ model,
735
+ messages: formattedMessages,
736
+ max_tokens: maxTokens,
737
+ temperature,
738
+ stream: true,
739
+ stream_options: { include_usage: true }
740
+ }),
741
+ signal: idle.signal
742
+ });
743
+ if (res.ok) {
744
+ const text = await processOpenAISSEStream(res, onChunk, idle);
745
+ if (text && text.trim()) {
746
+ console.log(`[streamRunner] \u2705 Designated fallback 9Router (${model}) succeeded!`);
747
+ return text;
748
+ }
749
+ } else {
750
+ const errText = await res.text().catch(() => "");
751
+ providerErrors[`designated_fallback_9router_${model}`] = `HTTP ${res.status}: ${errText.slice(0, 120)}`;
752
+ }
753
+ } catch (e) {
754
+ providerErrors[`designated_fallback_9router_${model}`] = e?.message || "Network error";
755
+ }
756
+ } else if (provider === "nvidia" && nvidiaKey && isProviderEnabled("nvidia")) {
723
757
  try {
724
758
  const nvdIdle = options.idleTimeoutMs ?? 18e4;
725
759
  const nvdTotal = options.timeoutMs ?? 6e5;