@thanh01.pmt/curriculum-kit 1.4.26 → 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.cjs +103 -6
- package/dist/ai/index.cjs.map +1 -1
- package/dist/ai/index.d.cts +4 -4
- package/dist/ai/index.d.ts +4 -4
- package/dist/ai/index.mjs +103 -7
- package/dist/ai/index.mjs.map +1 -1
- package/dist/index.cjs +104 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.mjs +104 -7
- package/dist/index.mjs.map +1 -1
- package/dist/media/index.cjs +87 -5
- package/dist/media/index.cjs.map +1 -1
- package/dist/media/index.d.cts +1 -1
- package/dist/media/index.d.ts +1 -1
- package/dist/media/index.mjs +87 -5
- package/dist/media/index.mjs.map +1 -1
- package/dist/{milestoneBundleGenerator-CzSOeAzU.d.cts → milestoneBundleGenerator-CN6F1zPs.d.cts} +1 -1
- package/dist/{milestoneBundleGenerator-Bkba8OPG.d.ts → milestoneBundleGenerator-DTiJ5gIh.d.ts} +1 -1
- package/dist/pipeline/index.cjs +23 -4
- package/dist/pipeline/index.cjs.map +1 -1
- package/dist/pipeline/index.d.cts +3 -3
- package/dist/pipeline/index.d.ts +3 -3
- package/dist/pipeline/index.mjs +23 -4
- package/dist/pipeline/index.mjs.map +1 -1
- package/dist/{provider-factory-DxzOVEmh.d.cts → provider-factory-Bv-eIkhg.d.cts} +1 -1
- package/dist/{provider-factory-DxzOVEmh.d.ts → provider-factory-Bv-eIkhg.d.ts} +1 -1
- package/dist/storage/index.d.cts +2 -2
- package/dist/storage/index.d.ts +2 -2
- package/dist/{streamRunner-CYESG6IE.d.cts → streamRunner-kpS4MZP1.d.cts} +2 -1
- package/dist/{streamRunner-CYESG6IE.d.ts → streamRunner-kpS4MZP1.d.ts} +2 -1
- package/dist/workflow/index.cjs +102 -6
- package/dist/workflow/index.cjs.map +1 -1
- package/dist/workflow/index.d.cts +1 -1
- package/dist/workflow/index.d.ts +1 -1
- package/dist/workflow/index.mjs +102 -6
- package/dist/workflow/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LanguageModel } from 'ai';
|
|
2
2
|
|
|
3
|
-
type AIProviderName = 'google' | 'openai' | 'deepseek' | 'alibaba' | 'dashscope' | 'ollama' | 'nvidia' | 'openrouter';
|
|
3
|
+
type AIProviderName = '9router' | 'ninerouter' | 'google' | 'openai' | 'deepseek' | 'alibaba' | 'dashscope' | 'ollama' | 'nvidia' | 'openrouter';
|
|
4
4
|
interface ModelResolutionOptions {
|
|
5
5
|
provider?: AIProviderName;
|
|
6
6
|
modelName?: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LanguageModel } from 'ai';
|
|
2
2
|
|
|
3
|
-
type AIProviderName = 'google' | 'openai' | 'deepseek' | 'alibaba' | 'dashscope' | 'ollama' | 'nvidia' | 'openrouter';
|
|
3
|
+
type AIProviderName = '9router' | 'ninerouter' | 'google' | 'openai' | 'deepseek' | 'alibaba' | 'dashscope' | 'ollama' | 'nvidia' | 'openrouter';
|
|
4
4
|
interface ModelResolutionOptions {
|
|
5
5
|
provider?: AIProviderName;
|
|
6
6
|
modelName?: string;
|
package/dist/storage/index.d.cts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { I as ICurriculumStorage, a as SotDocument, L as LessonArtifactSummary, P as ProjectStatusReport, c as PipelineState, b as ArtifactLifecycleInfo } from '../types-BUJGYiep.cjs';
|
|
2
2
|
export { A as ArtifactLifecycleState, Q as QualityAuditReport, R as ReviewRecord, S as SmartResumeContext, T as TaskLifecycleState } from '../types-BUJGYiep.cjs';
|
|
3
3
|
import { SupabaseClient } from '@supabase/supabase-js';
|
|
4
|
-
import { M as MilestoneCurriculumBundle } from '../milestoneBundleGenerator-
|
|
4
|
+
import { M as MilestoneCurriculumBundle } from '../milestoneBundleGenerator-CN6F1zPs.cjs';
|
|
5
5
|
import '../schemas/index.cjs';
|
|
6
6
|
import 'zod';
|
|
7
|
-
import '../provider-factory-
|
|
7
|
+
import '../provider-factory-Bv-eIkhg.cjs';
|
|
8
8
|
import 'ai';
|
|
9
9
|
|
|
10
10
|
declare function computeContentHash(content: string): string;
|
package/dist/storage/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { I as ICurriculumStorage, a as SotDocument, L as LessonArtifactSummary, P as ProjectStatusReport, c as PipelineState, b as ArtifactLifecycleInfo } from '../types-BUJGYiep.js';
|
|
2
2
|
export { A as ArtifactLifecycleState, Q as QualityAuditReport, R as ReviewRecord, S as SmartResumeContext, T as TaskLifecycleState } from '../types-BUJGYiep.js';
|
|
3
3
|
import { SupabaseClient } from '@supabase/supabase-js';
|
|
4
|
-
import { M as MilestoneCurriculumBundle } from '../milestoneBundleGenerator-
|
|
4
|
+
import { M as MilestoneCurriculumBundle } from '../milestoneBundleGenerator-DTiJ5gIh.js';
|
|
5
5
|
import '../schemas/index.js';
|
|
6
6
|
import 'zod';
|
|
7
|
-
import '../provider-factory-
|
|
7
|
+
import '../provider-factory-Bv-eIkhg.js';
|
|
8
8
|
import 'ai';
|
|
9
9
|
|
|
10
10
|
declare function computeContentHash(content: string): string;
|
|
@@ -39,6 +39,7 @@ interface StreamRunnerOptions {
|
|
|
39
39
|
onChunk: (token: string, type: ChunkType) => void;
|
|
40
40
|
}) => Promise<string>;
|
|
41
41
|
}
|
|
42
|
+
declare function resolveApiKey(keyName: string, explicitKey?: string): string;
|
|
42
43
|
/**
|
|
43
44
|
* Checks if a specific AI provider is enabled via environment variables.
|
|
44
45
|
* Supported env controls:
|
|
@@ -105,4 +106,4 @@ declare function streamCurriculumAIInference(messages: ChatMessage[], projectCon
|
|
|
105
106
|
*/
|
|
106
107
|
declare function runCurriculumAIInference(messages: ChatMessage[], projectContext: string, options?: StreamRunnerOptions, onChunk?: (token: string, type: ChunkType) => void): Promise<string>;
|
|
107
108
|
|
|
108
|
-
export { type ChatMessage as C, DEFAULT_ARTIFACT_STREAM_IDLE_MS as D, type FallbackTarget as F, type IdleAbort as I, type StreamRunnerOptions as S, isModelAllowed as a, getDesignatedFallbackConfig as b, type ChunkType as c, DEFAULT_ARTIFACT_STREAM_TOTAL_MS as d, extractThoughtAndContent as e, type StreamAbortController as f, getDesignatedFallbackChain as g, createStreamAbortController as h, isProviderEnabled as i, createIdleAbortController as j, runCurriculumAIInference as r, streamCurriculumAIInference as s };
|
|
109
|
+
export { type ChatMessage as C, DEFAULT_ARTIFACT_STREAM_IDLE_MS as D, type FallbackTarget as F, type IdleAbort as I, type StreamRunnerOptions as S, isModelAllowed as a, getDesignatedFallbackConfig as b, type ChunkType as c, DEFAULT_ARTIFACT_STREAM_TOTAL_MS as d, extractThoughtAndContent as e, type StreamAbortController as f, getDesignatedFallbackChain as g, createStreamAbortController as h, isProviderEnabled as i, createIdleAbortController as j, runCurriculumAIInference as k, resolveApiKey as r, streamCurriculumAIInference as s };
|
|
@@ -39,6 +39,7 @@ interface StreamRunnerOptions {
|
|
|
39
39
|
onChunk: (token: string, type: ChunkType) => void;
|
|
40
40
|
}) => Promise<string>;
|
|
41
41
|
}
|
|
42
|
+
declare function resolveApiKey(keyName: string, explicitKey?: string): string;
|
|
42
43
|
/**
|
|
43
44
|
* Checks if a specific AI provider is enabled via environment variables.
|
|
44
45
|
* Supported env controls:
|
|
@@ -105,4 +106,4 @@ declare function streamCurriculumAIInference(messages: ChatMessage[], projectCon
|
|
|
105
106
|
*/
|
|
106
107
|
declare function runCurriculumAIInference(messages: ChatMessage[], projectContext: string, options?: StreamRunnerOptions, onChunk?: (token: string, type: ChunkType) => void): Promise<string>;
|
|
107
108
|
|
|
108
|
-
export { type ChatMessage as C, DEFAULT_ARTIFACT_STREAM_IDLE_MS as D, type FallbackTarget as F, type IdleAbort as I, type StreamRunnerOptions as S, isModelAllowed as a, getDesignatedFallbackConfig as b, type ChunkType as c, DEFAULT_ARTIFACT_STREAM_TOTAL_MS as d, extractThoughtAndContent as e, type StreamAbortController as f, getDesignatedFallbackChain as g, createStreamAbortController as h, isProviderEnabled as i, createIdleAbortController as j, runCurriculumAIInference as r, streamCurriculumAIInference as s };
|
|
109
|
+
export { type ChatMessage as C, DEFAULT_ARTIFACT_STREAM_IDLE_MS as D, type FallbackTarget as F, type IdleAbort as I, type StreamRunnerOptions as S, isModelAllowed as a, getDesignatedFallbackConfig as b, type ChunkType as c, DEFAULT_ARTIFACT_STREAM_TOTAL_MS as d, extractThoughtAndContent as e, type StreamAbortController as f, getDesignatedFallbackChain as g, createStreamAbortController as h, isProviderEnabled as i, createIdleAbortController as j, runCurriculumAIInference as k, resolveApiKey as r, streamCurriculumAIInference as s };
|
package/dist/workflow/index.cjs
CHANGED
|
@@ -204,14 +204,19 @@ function isModelAllowed(model) {
|
|
|
204
204
|
});
|
|
205
205
|
}
|
|
206
206
|
function getDesignatedFallbackChain() {
|
|
207
|
-
const rawProviders = resolveApiKey("FALLBACK_AI_PROVIDER") || resolveApiKey("FALLBACK_AI_PROVIDERS") || resolveApiKey("DEFAULT_AI_PROVIDER") || "nvidia,openrouter";
|
|
208
|
-
const rawModels = resolveApiKey("FALLBACK_AI_MODEL") || resolveApiKey("FALLBACK_AI_MODELS") || resolveApiKey("DEFAULT_AI_MODEL") || "
|
|
207
|
+
const rawProviders = resolveApiKey("FALLBACK_AI_PROVIDER") || resolveApiKey("FALLBACK_AI_PROVIDERS") || resolveApiKey("DEFAULT_AI_PROVIDER") || "9router,nvidia,openrouter";
|
|
208
|
+
const rawModels = resolveApiKey("FALLBACK_AI_MODEL") || resolveApiKey("FALLBACK_AI_MODELS") || resolveApiKey("DEFAULT_AI_MODEL") || "fast-reasoning,deep-reasoning,mid-range,free-tier";
|
|
209
209
|
const providerList = rawProviders.split(",").map((p) => p.trim().toLowerCase()).filter((p) => p.length > 0 && isProviderEnabled(p));
|
|
210
210
|
const modelList = rawModels.split(",").map((m) => m.trim()).filter((m) => m.length > 0 && isModelAllowed(m));
|
|
211
211
|
const chain = [];
|
|
212
212
|
for (const provider of providerList) {
|
|
213
213
|
let providerModels = [];
|
|
214
|
-
if (provider === "
|
|
214
|
+
if (provider === "9router" || provider === "ninerouter") {
|
|
215
|
+
providerModels = modelList.filter((m) => ["fast-reasoning", "deep-reasoning", "mid-range", "free-tier"].includes(m));
|
|
216
|
+
if (providerModels.length === 0) {
|
|
217
|
+
providerModels = ["fast-reasoning", "mid-range", "free-tier"];
|
|
218
|
+
}
|
|
219
|
+
} else if (provider === "nvidia") {
|
|
215
220
|
providerModels = modelList.filter((m) => m.startsWith("nvidia/") || m.startsWith("meta/") || m.startsWith("mistralai/"));
|
|
216
221
|
if (providerModels.length === 0) {
|
|
217
222
|
providerModels = ["nvidia/nemotron-3-ultra-550b-a55b:free", "nvidia/nemotron-3.5-lightning-30b-a3b"];
|
|
@@ -250,7 +255,7 @@ function getDesignatedFallbackChain() {
|
|
|
250
255
|
function getDesignatedFallbackConfig() {
|
|
251
256
|
const chain = getDesignatedFallbackChain();
|
|
252
257
|
if (chain.length > 0) return chain[0];
|
|
253
|
-
return { provider: "
|
|
258
|
+
return { provider: "9router", model: "fast-reasoning" };
|
|
254
259
|
}
|
|
255
260
|
function extractThoughtAndContent(rawText) {
|
|
256
261
|
let text = rawText || "";
|
|
@@ -489,8 +494,51 @@ Guidelines:
|
|
|
489
494
|
}))
|
|
490
495
|
];
|
|
491
496
|
const providerErrors = {};
|
|
492
|
-
const requestedModel = options.model || "
|
|
497
|
+
const requestedModel = options.model || "fast-reasoning";
|
|
493
498
|
const isNvidiaPreferred = requestedModel.startsWith("nvidia/") || Boolean(nvidiaKey && !openrouterKey) && isProviderEnabled("nvidia");
|
|
499
|
+
const ninerouterKey = resolveApiKey("NINEROUTER_API_KEY") || resolveApiKey("NINE_ROUTER_API_KEY");
|
|
500
|
+
if (ninerouterKey && isProviderEnabled("9router")) {
|
|
501
|
+
const rawUrl = resolveApiKey("NINEROUTER_BASE_URL") || resolveApiKey("NINE_ROUTER_BASE_URL") || "https://ai-router.orchable.app/v1";
|
|
502
|
+
const ninerouterBaseUrl = rawUrl.replace(/^["']|["']$/g, "").replace(/\/$/, "");
|
|
503
|
+
const candidateModels = [
|
|
504
|
+
options.model || "fast-reasoning",
|
|
505
|
+
"fast-reasoning",
|
|
506
|
+
"mid-range",
|
|
507
|
+
"free-tier"
|
|
508
|
+
].filter((m) => isModelAllowed(m));
|
|
509
|
+
const unique9RouterModels = Array.from(new Set(candidateModels));
|
|
510
|
+
for (const model of unique9RouterModels) {
|
|
511
|
+
try {
|
|
512
|
+
const idle = createStreamAbortController({ idleMs: 45e3, totalMs: 3e5 });
|
|
513
|
+
const res = await fetch(`${ninerouterBaseUrl}/chat/completions`, {
|
|
514
|
+
method: "POST",
|
|
515
|
+
headers: {
|
|
516
|
+
"Authorization": `Bearer ${ninerouterKey}`,
|
|
517
|
+
"Content-Type": "application/json"
|
|
518
|
+
},
|
|
519
|
+
body: JSON.stringify({
|
|
520
|
+
model,
|
|
521
|
+
messages: formattedMessages,
|
|
522
|
+
max_tokens: maxTokens,
|
|
523
|
+
temperature,
|
|
524
|
+
stream: true,
|
|
525
|
+
stream_options: { include_usage: true }
|
|
526
|
+
}),
|
|
527
|
+
signal: idle.signal
|
|
528
|
+
});
|
|
529
|
+
if (res.ok) {
|
|
530
|
+
const text = await processOpenAISSEStream(res, onChunk, idle);
|
|
531
|
+
if (text && text.trim()) return text;
|
|
532
|
+
} else {
|
|
533
|
+
const errText = await res.text().catch(() => "");
|
|
534
|
+
providerErrors[`9router_${model}`] = `HTTP ${res.status}: ${errText.slice(0, 120)}`;
|
|
535
|
+
}
|
|
536
|
+
} catch (e) {
|
|
537
|
+
providerErrors[`9router_${model}`] = e?.message || "Network error";
|
|
538
|
+
console.warn(`[9Router Stream] Failover for ${model}:`, e?.message || e);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}
|
|
494
542
|
if (nvidiaKey && isProviderEnabled("nvidia")) {
|
|
495
543
|
const candidateNemotronModels = [
|
|
496
544
|
requestedModel.startsWith("nvidia/") ? requestedModel : "nvidia/nemotron-3-ultra-550b-a55b:free",
|
|
@@ -700,7 +748,41 @@ Guidelines:
|
|
|
700
748
|
);
|
|
701
749
|
for (const target of fallbackChain) {
|
|
702
750
|
const { provider, model } = target;
|
|
703
|
-
if (provider === "
|
|
751
|
+
if ((provider === "9router" || provider === "ninerouter") && ninerouterKey && isProviderEnabled("9router")) {
|
|
752
|
+
try {
|
|
753
|
+
const rawUrl = resolveApiKey("NINEROUTER_BASE_URL") || resolveApiKey("NINE_ROUTER_BASE_URL") || "https://ai-router.orchable.app/v1";
|
|
754
|
+
const fbBaseUrl = rawUrl.replace(/["']/g, "").replace(/\/$/, "");
|
|
755
|
+
const idle = createStreamAbortController({ idleMs: 45e3, totalMs: 3e5 });
|
|
756
|
+
const res = await fetch(`${fbBaseUrl}/chat/completions`, {
|
|
757
|
+
method: "POST",
|
|
758
|
+
headers: {
|
|
759
|
+
"Authorization": `Bearer ${ninerouterKey}`,
|
|
760
|
+
"Content-Type": "application/json"
|
|
761
|
+
},
|
|
762
|
+
body: JSON.stringify({
|
|
763
|
+
model,
|
|
764
|
+
messages: formattedMessages,
|
|
765
|
+
max_tokens: maxTokens,
|
|
766
|
+
temperature,
|
|
767
|
+
stream: true,
|
|
768
|
+
stream_options: { include_usage: true }
|
|
769
|
+
}),
|
|
770
|
+
signal: idle.signal
|
|
771
|
+
});
|
|
772
|
+
if (res.ok) {
|
|
773
|
+
const text = await processOpenAISSEStream(res, onChunk, idle);
|
|
774
|
+
if (text && text.trim()) {
|
|
775
|
+
console.log(`[streamRunner] \u2705 Designated fallback 9Router (${model}) succeeded!`);
|
|
776
|
+
return text;
|
|
777
|
+
}
|
|
778
|
+
} else {
|
|
779
|
+
const errText = await res.text().catch(() => "");
|
|
780
|
+
providerErrors[`designated_fallback_9router_${model}`] = `HTTP ${res.status}: ${errText.slice(0, 120)}`;
|
|
781
|
+
}
|
|
782
|
+
} catch (e) {
|
|
783
|
+
providerErrors[`designated_fallback_9router_${model}`] = e?.message || "Network error";
|
|
784
|
+
}
|
|
785
|
+
} else if (provider === "nvidia" && nvidiaKey && isProviderEnabled("nvidia")) {
|
|
704
786
|
try {
|
|
705
787
|
const nvdIdle = options.idleTimeoutMs ?? 18e4;
|
|
706
788
|
const nvdTotal = options.timeoutMs ?? 6e5;
|
|
@@ -872,6 +954,15 @@ function getAIModel(options = {}) {
|
|
|
872
954
|
console.warn(`[provider-factory] Model "${resolvedModelName}" is not permitted by ALLOWED_AI_MODELS. Using designated model "${designated.model}".`);
|
|
873
955
|
resolvedModelName = designated.model;
|
|
874
956
|
}
|
|
957
|
+
if (provider === "9router" || provider === "ninerouter") {
|
|
958
|
+
const apiKey = options.apiKey || resolveApiKey("NINEROUTER_API_KEY") || resolveApiKey("NINE_ROUTER_API_KEY") || "";
|
|
959
|
+
const rawUrl = options.baseURL || resolveApiKey("NINEROUTER_BASE_URL") || resolveApiKey("NINE_ROUTER_BASE_URL") || "https://ai-router.orchable.app/v1";
|
|
960
|
+
const ninerouter = openai.createOpenAI({
|
|
961
|
+
apiKey,
|
|
962
|
+
baseURL: rawUrl.replace(/^["']|["']$/g, "").trim()
|
|
963
|
+
});
|
|
964
|
+
return ninerouter.chat(resolvedModelName || "fast-reasoning");
|
|
965
|
+
}
|
|
875
966
|
if (provider === "nvidia") {
|
|
876
967
|
const apiKey = options.apiKey || process.env.NVIDIA_API_KEY || "";
|
|
877
968
|
const nvidia = openai.createOpenAI({
|
|
@@ -940,6 +1031,9 @@ function getAIModel(options = {}) {
|
|
|
940
1031
|
return fallback.chat(resolvedModelName);
|
|
941
1032
|
}
|
|
942
1033
|
function detectDefaultProvider() {
|
|
1034
|
+
if ((process.env.NINEROUTER_API_KEY || resolveApiKey("NINEROUTER_API_KEY") || resolveApiKey("NINE_ROUTER_API_KEY")) && isProviderEnabled("9router")) {
|
|
1035
|
+
return "9router";
|
|
1036
|
+
}
|
|
943
1037
|
if (process.env.NVIDIA_API_KEY && isProviderEnabled("nvidia")) {
|
|
944
1038
|
return "nvidia";
|
|
945
1039
|
}
|
|
@@ -965,6 +1059,8 @@ var init_provider_factory = __esm({
|
|
|
965
1059
|
"src/ai/provider-factory.ts"() {
|
|
966
1060
|
init_streamRunner();
|
|
967
1061
|
DEFAULT_MODELS = {
|
|
1062
|
+
"9router": "fast-reasoning",
|
|
1063
|
+
ninerouter: "fast-reasoning",
|
|
968
1064
|
nvidia: "nvidia/nemotron-3-ultra-550b-a55b:free",
|
|
969
1065
|
openrouter: "@preset/coding-free",
|
|
970
1066
|
alibaba: "qwen3.7-plus",
|