@thanh01.pmt/curriculum-kit 1.0.15 → 1.0.17

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.
@@ -2,8 +2,8 @@ import { M as ModelResolutionOptions } from '../provider-factory-DxzOVEmh.cjs';
2
2
  export { A as AIProviderName, N as NVIDIA_MODELS, g as getAIModel } from '../provider-factory-DxzOVEmh.cjs';
3
3
  import { MilestoneInput, LessonPlan, ActivityLab, ProjectGraph, CodeLab, Worksheet, Handout, SlideDeck, TeacherGuide, Extension, CurriculumQualityReport, ProjectInstruction, SelfLab, DiagnosticQuiz } from '../schemas/index.cjs';
4
4
  import * as ai from 'ai';
5
- import { C as ChatMessage, S as StreamRunnerOptions, c as ChunkType } from '../streamRunner-CcpmxOf1.cjs';
6
- export { F as FallbackTarget, e as extractThoughtAndContent, g as getDesignatedFallbackChain, b as getDesignatedFallbackConfig, a as isModelAllowed, i as isProviderEnabled, r as runCurriculumAIInference, s as streamCurriculumAIInference } from '../streamRunner-CcpmxOf1.cjs';
5
+ import { C as ChatMessage, S as StreamRunnerOptions, c as ChunkType } from '../streamRunner-DtQq0HV_.cjs';
6
+ export { D as DEFAULT_ARTIFACT_STREAM_IDLE_MS, d as DEFAULT_ARTIFACT_STREAM_TOTAL_MS, F as FallbackTarget, I as IdleAbort, f as StreamAbortController, j as createIdleAbortController, h as createStreamAbortController, e as extractThoughtAndContent, g as getDesignatedFallbackChain, b as getDesignatedFallbackConfig, a as isModelAllowed, i as isProviderEnabled, r as runCurriculumAIInference, s as streamCurriculumAIInference } from '../streamRunner-DtQq0HV_.cjs';
7
7
  import { z } from 'zod';
8
8
 
9
9
  interface LessonPromptInput {
@@ -2,8 +2,8 @@ import { M as ModelResolutionOptions } from '../provider-factory-DxzOVEmh.js';
2
2
  export { A as AIProviderName, N as NVIDIA_MODELS, g as getAIModel } from '../provider-factory-DxzOVEmh.js';
3
3
  import { MilestoneInput, LessonPlan, ActivityLab, ProjectGraph, CodeLab, Worksheet, Handout, SlideDeck, TeacherGuide, Extension, CurriculumQualityReport, ProjectInstruction, SelfLab, DiagnosticQuiz } from '../schemas/index.js';
4
4
  import * as ai from 'ai';
5
- import { C as ChatMessage, S as StreamRunnerOptions, c as ChunkType } from '../streamRunner-CcpmxOf1.js';
6
- export { F as FallbackTarget, e as extractThoughtAndContent, g as getDesignatedFallbackChain, b as getDesignatedFallbackConfig, a as isModelAllowed, i as isProviderEnabled, r as runCurriculumAIInference, s as streamCurriculumAIInference } from '../streamRunner-CcpmxOf1.js';
5
+ import { C as ChatMessage, S as StreamRunnerOptions, c as ChunkType } from '../streamRunner-DtQq0HV_.js';
6
+ export { D as DEFAULT_ARTIFACT_STREAM_IDLE_MS, d as DEFAULT_ARTIFACT_STREAM_TOTAL_MS, F as FallbackTarget, I as IdleAbort, f as StreamAbortController, j as createIdleAbortController, h as createStreamAbortController, e as extractThoughtAndContent, g as getDesignatedFallbackChain, b as getDesignatedFallbackConfig, a as isModelAllowed, i as isProviderEnabled, r as runCurriculumAIInference, s as streamCurriculumAIInference } from '../streamRunner-DtQq0HV_.js';
7
7
  import { z } from 'zod';
8
8
 
9
9
  interface LessonPromptInput {
package/dist/ai/index.mjs CHANGED
@@ -248,29 +248,46 @@ function extractThoughtAndContent(rawText) {
248
248
  content: content.trim()
249
249
  };
250
250
  }
251
- function createIdleAbortController(idleMs) {
251
+ var DEFAULT_ARTIFACT_STREAM_IDLE_MS = 45e3;
252
+ var DEFAULT_ARTIFACT_STREAM_TOTAL_MS = 42e4;
253
+ function createStreamAbortController(options) {
254
+ const envIdle = Number(process.env.ARTIFACT_STREAM_IDLE_TIMEOUT_MS || process.env.STREAM_IDLE_TIMEOUT_MS);
255
+ const envTotal = Number(process.env.ARTIFACT_STREAM_TOTAL_TIMEOUT_MS || process.env.STREAM_TOTAL_TIMEOUT_MS);
256
+ const idleMs = Number.isFinite(options?.idleMs) && options.idleMs > 0 ? options.idleMs : Number.isFinite(envIdle) && envIdle > 0 ? envIdle : DEFAULT_ARTIFACT_STREAM_IDLE_MS;
257
+ const totalMs = Number.isFinite(options?.totalMs) && options.totalMs > 0 ? options.totalMs : Number.isFinite(envTotal) && envTotal > 0 ? envTotal : DEFAULT_ARTIFACT_STREAM_TOTAL_MS;
252
258
  const controller = new AbortController();
253
- let timer = null;
254
- const arm = () => {
255
- if (timer) clearTimeout(timer);
256
- timer = setTimeout(
259
+ let idleTimer = null;
260
+ let totalTimer = null;
261
+ const armIdle = () => {
262
+ if (idleTimer) clearTimeout(idleTimer);
263
+ idleTimer = setTimeout(
257
264
  () => controller.abort(new Error(`Idle timeout: no data for ${Math.round(idleMs / 1e3)}s`)),
258
265
  idleMs
259
266
  );
260
- timer?.unref?.();
267
+ idleTimer?.unref?.();
261
268
  };
262
- arm();
269
+ armIdle();
270
+ if (totalMs > 0) {
271
+ totalTimer = setTimeout(
272
+ () => controller.abort(new Error(`Total stream timeout after ${Math.round(totalMs / 1e3)}s`)),
273
+ totalMs
274
+ );
275
+ totalTimer?.unref?.();
276
+ }
263
277
  return {
264
278
  signal: controller.signal,
265
- /** Reset the idle window (call on every received chunk). */
266
- kick: arm,
267
- /** Clear the pending timer once the request lifecycle is over. */
279
+ kick: armIdle,
268
280
  dispose: () => {
269
- if (timer) clearTimeout(timer);
270
- timer = null;
281
+ if (idleTimer) clearTimeout(idleTimer);
282
+ if (totalTimer) clearTimeout(totalTimer);
283
+ idleTimer = null;
284
+ totalTimer = null;
271
285
  }
272
286
  };
273
287
  }
288
+ function createIdleAbortController(idleMs, totalMs) {
289
+ return createStreamAbortController({ idleMs, totalMs });
290
+ }
274
291
  async function processOpenAISSEStream(response, onChunk, idle, toolCallCollector) {
275
292
  if (!response.body) return "";
276
293
  const reader = response.body.getReader();
@@ -454,7 +471,7 @@ Guidelines:
454
471
  if (isNvidiaPreferred || uniqueNvidiaModels.length > 0) {
455
472
  for (const model of uniqueNvidiaModels) {
456
473
  try {
457
- const idle = createIdleAbortController(18e4);
474
+ const idle = createStreamAbortController({ idleMs: options.idleTimeoutMs, totalMs: options.timeoutMs });
458
475
  const res = await fetch("https://integrate.api.nvidia.com/v1/chat/completions", {
459
476
  method: "POST",
460
477
  headers: {
@@ -498,7 +515,7 @@ Guidelines:
498
515
  const uniqueOrModels = Array.from(new Set(openrouterModels));
499
516
  for (const model of uniqueOrModels) {
500
517
  try {
501
- const idle = createIdleAbortController(18e4);
518
+ const idle = createStreamAbortController({ idleMs: options.idleTimeoutMs, totalMs: options.timeoutMs });
502
519
  const res = await fetch("https://openrouter.ai/api/v1/chat/completions", {
503
520
  method: "POST",
504
521
  headers: {
@@ -537,7 +554,7 @@ Guidelines:
537
554
  const dsModel = options.model?.includes("deepseek-reasoner") ? "deepseek-reasoner" : "deepseek-chat";
538
555
  if (isModelAllowed(dsModel)) {
539
556
  try {
540
- const idle = createIdleAbortController(18e4);
557
+ const idle = createStreamAbortController({ idleMs: options.idleTimeoutMs, totalMs: options.timeoutMs });
541
558
  const res = await fetch("https://api.deepseek.com/chat/completions", {
542
559
  method: "POST",
543
560
  headers: {
@@ -572,7 +589,7 @@ Guidelines:
572
589
  const baseUrl = alibabaKey.startsWith("sk-sp-") ? "https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions" : "https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions";
573
590
  for (const qwenModel of qwenModels) {
574
591
  try {
575
- const idle = createIdleAbortController(18e4);
592
+ const idle = createStreamAbortController({ idleMs: options.idleTimeoutMs, totalMs: options.timeoutMs });
576
593
  const payload = {
577
594
  model: qwenModel,
578
595
  messages: formattedMessages,
@@ -615,7 +632,7 @@ Guidelines:
615
632
  ];
616
633
  for (const gModel of geminiModels) {
617
634
  try {
618
- const idle = createIdleAbortController(18e4);
635
+ const idle = createStreamAbortController({ idleMs: options.idleTimeoutMs, totalMs: options.timeoutMs });
619
636
  const res = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/${gModel}:streamGenerateContent?alt=sse&key=${geminiKey}`, {
620
637
  method: "POST",
621
638
  headers: { "Content-Type": "application/json" },
@@ -651,7 +668,7 @@ Guidelines:
651
668
  const { provider, model } = target;
652
669
  if (provider === "nvidia" && nvidiaKey && isProviderEnabled("nvidia")) {
653
670
  try {
654
- const idle = createIdleAbortController(18e4);
671
+ const idle = createStreamAbortController({ idleMs: options.idleTimeoutMs, totalMs: options.timeoutMs });
655
672
  const res = await fetch("https://integrate.api.nvidia.com/v1/chat/completions", {
656
673
  method: "POST",
657
674
  headers: {
@@ -683,7 +700,7 @@ Guidelines:
683
700
  }
684
701
  } else if (provider === "openrouter" && openrouterKey && isProviderEnabled("openrouter")) {
685
702
  try {
686
- const idle = createIdleAbortController(18e4);
703
+ const idle = createStreamAbortController({ idleMs: options.idleTimeoutMs, totalMs: options.timeoutMs });
687
704
  const res = await fetch("https://openrouter.ai/api/v1/chat/completions", {
688
705
  method: "POST",
689
706
  headers: {
@@ -718,7 +735,7 @@ Guidelines:
718
735
  } else if ((provider === "alibaba" || provider === "dashscope") && alibabaKey && isProviderEnabled("alibaba")) {
719
736
  const baseUrl = alibabaKey.startsWith("sk-sp-") ? "https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions" : "https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions";
720
737
  try {
721
- const idle = createIdleAbortController(18e4);
738
+ const idle = createStreamAbortController({ idleMs: options.idleTimeoutMs, totalMs: options.timeoutMs });
722
739
  const res = await fetch(baseUrl, {
723
740
  method: "POST",
724
741
  headers: {
@@ -750,7 +767,7 @@ Guidelines:
750
767
  }
751
768
  } else if ((provider === "google" || provider === "gemini") && geminiKey && (isProviderEnabled("gemini") || isProviderEnabled("google"))) {
752
769
  try {
753
- const idle = createIdleAbortController(18e4);
770
+ const idle = createStreamAbortController({ idleMs: options.idleTimeoutMs, totalMs: options.timeoutMs });
754
771
  const res = await fetch(
755
772
  `https://generativelanguage.googleapis.com/v1beta/models/${model}:streamGenerateContent?alt=sse&key=${geminiKey}`,
756
773
  {
@@ -4945,6 +4962,6 @@ Guidelines:
4945
4962
  return finalContent;
4946
4963
  }
4947
4964
 
4948
- export { DEFAULT_ENABLED_PROVIDERS, LLMJudgeEngine, ModelPolicyResolver, NVIDIA_MODELS, activityTools, analystTools, assessorTools, auditCurriculumQualityFlow, buildActivityPrompt, buildCodeLabPrompt, buildDiagnosticQuizPrompt, buildExtensionPrompt, buildHandoutPrompt, buildJudgePrompt, buildLessonMasterPrompt, buildProjectInstructionPrompt, buildSelfLabPrompt, buildSlidesPrompt, buildTeacherGuidePrompt, buildWorksheetPrompt, contentTools, designerTools, extractThoughtAndContent, generateActivityFlow, generateCodeLabFlow, generateDiagnosticQuizFlow, generateExtensionFlow, generateHandoutFlow, generateLessonMasterFlow, generateProjectInstructionFlow, generateSelfLabFlow, generateSlidesFlow, generateTeacherGuideFlow, generateWorksheetFlow, getAIModel, getDesignatedFallbackChain, getDesignatedFallbackConfig, illustratorTools, isModelAllowed, isProviderEnabled, packagerTools, researcherTools, reviewerTools, runCurriculumAIInference, streamCurriculumAIInference, streamCurriculumAIInferenceWithTools, streamDiagnosticQuizFlow, streamLessonMasterFlow, streamSelfLabFlow, techSmeTools };
4965
+ export { DEFAULT_ARTIFACT_STREAM_IDLE_MS, DEFAULT_ARTIFACT_STREAM_TOTAL_MS, DEFAULT_ENABLED_PROVIDERS, LLMJudgeEngine, ModelPolicyResolver, NVIDIA_MODELS, activityTools, analystTools, assessorTools, auditCurriculumQualityFlow, buildActivityPrompt, buildCodeLabPrompt, buildDiagnosticQuizPrompt, buildExtensionPrompt, buildHandoutPrompt, buildJudgePrompt, buildLessonMasterPrompt, buildProjectInstructionPrompt, buildSelfLabPrompt, buildSlidesPrompt, buildTeacherGuidePrompt, buildWorksheetPrompt, contentTools, createIdleAbortController, createStreamAbortController, designerTools, extractThoughtAndContent, generateActivityFlow, generateCodeLabFlow, generateDiagnosticQuizFlow, generateExtensionFlow, generateHandoutFlow, generateLessonMasterFlow, generateProjectInstructionFlow, generateSelfLabFlow, generateSlidesFlow, generateTeacherGuideFlow, generateWorksheetFlow, getAIModel, getDesignatedFallbackChain, getDesignatedFallbackConfig, illustratorTools, isModelAllowed, isProviderEnabled, packagerTools, researcherTools, reviewerTools, runCurriculumAIInference, streamCurriculumAIInference, streamCurriculumAIInferenceWithTools, streamDiagnosticQuizFlow, streamLessonMasterFlow, streamSelfLabFlow, techSmeTools };
4949
4966
  //# sourceMappingURL=index.mjs.map
4950
4967
  //# sourceMappingURL=index.mjs.map