@thanh01.pmt/curriculum-kit 1.4.32 → 1.4.34

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-Bv-eIkhg.cjs';
2
2
  export { A as AIProviderName, N as NVIDIA_MODELS, g as getAIModel } from '../provider-factory-Bv-eIkhg.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, n as ToolLoopConfig, c as ChunkType } from '../streamRunner-B0Z1nAG5.cjs';
6
- export { A as AggregatedToolCall, D as DEFAULT_ARTIFACT_STREAM_IDLE_MS, d as DEFAULT_ARTIFACT_STREAM_TOTAL_MS, F as FallbackTarget, I as IdleAbort, f as StreamAbortController, T as ToolDefinition, l as ToolExecutionResult, m as ToolExecutor, j as createIdleAbortController, h as createStreamAbortController, e as extractThoughtAndContent, g as getDesignatedFallbackChain, b as getDesignatedFallbackConfig, a as isModelAllowed, i as isProviderEnabled, r as resolveApiKey, k as runCurriculumAIInference, s as streamCurriculumAIInference } from '../streamRunner-B0Z1nAG5.cjs';
5
+ import { a as ChatMessage, S as StreamRunnerOptions, n as ToolLoopConfig, C as ChunkType } from '../streamRunner-BzlJrAGZ.cjs';
6
+ export { A as AggregatedToolCall, D as DEFAULT_ARTIFACT_STREAM_IDLE_MS, d as DEFAULT_ARTIFACT_STREAM_TOTAL_MS, F as FallbackTarget, I as IdleAbort, f as StreamAbortController, T as ToolDefinition, l as ToolExecutionResult, m as ToolExecutor, j as createIdleAbortController, h as createStreamAbortController, e as extractThoughtAndContent, g as getDesignatedFallbackChain, c as getDesignatedFallbackConfig, b as isModelAllowed, i as isProviderEnabled, r as resolveApiKey, k as runCurriculumAIInference, s as streamCurriculumAIInference } from '../streamRunner-BzlJrAGZ.cjs';
7
7
  import { z } from 'zod';
8
8
 
9
9
  interface LessonPromptInput {
@@ -2,8 +2,8 @@ import { M as ModelResolutionOptions } from '../provider-factory-Bv-eIkhg.js';
2
2
  export { A as AIProviderName, N as NVIDIA_MODELS, g as getAIModel } from '../provider-factory-Bv-eIkhg.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, n as ToolLoopConfig, c as ChunkType } from '../streamRunner-B0Z1nAG5.js';
6
- export { A as AggregatedToolCall, D as DEFAULT_ARTIFACT_STREAM_IDLE_MS, d as DEFAULT_ARTIFACT_STREAM_TOTAL_MS, F as FallbackTarget, I as IdleAbort, f as StreamAbortController, T as ToolDefinition, l as ToolExecutionResult, m as ToolExecutor, j as createIdleAbortController, h as createStreamAbortController, e as extractThoughtAndContent, g as getDesignatedFallbackChain, b as getDesignatedFallbackConfig, a as isModelAllowed, i as isProviderEnabled, r as resolveApiKey, k as runCurriculumAIInference, s as streamCurriculumAIInference } from '../streamRunner-B0Z1nAG5.js';
5
+ import { a as ChatMessage, S as StreamRunnerOptions, n as ToolLoopConfig, C as ChunkType } from '../streamRunner-BzlJrAGZ.js';
6
+ export { A as AggregatedToolCall, D as DEFAULT_ARTIFACT_STREAM_IDLE_MS, d as DEFAULT_ARTIFACT_STREAM_TOTAL_MS, F as FallbackTarget, I as IdleAbort, f as StreamAbortController, T as ToolDefinition, l as ToolExecutionResult, m as ToolExecutor, j as createIdleAbortController, h as createStreamAbortController, e as extractThoughtAndContent, g as getDesignatedFallbackChain, c as getDesignatedFallbackConfig, b as isModelAllowed, i as isProviderEnabled, r as resolveApiKey, k as runCurriculumAIInference, s as streamCurriculumAIInference } from '../streamRunner-BzlJrAGZ.js';
7
7
  import { z } from 'zod';
8
8
 
9
9
  interface LessonPromptInput {
package/dist/ai/index.mjs CHANGED
@@ -926,6 +926,52 @@ async function runCurriculumAIInference(messages, projectContext, options = {},
926
926
  }
927
927
 
928
928
  // src/ai/provider-factory.ts
929
+ function cleanNonStreamingFetch() {
930
+ return async (input, init) => {
931
+ const res = await fetch(input, init);
932
+ let wantsStream = false;
933
+ try {
934
+ const body = init?.body;
935
+ if (typeof body === "string") wantsStream = /"stream"\s*:\s*true/.test(body);
936
+ } catch {
937
+ }
938
+ if (wantsStream) return res;
939
+ const contentType = res.headers.get("content-type") || "";
940
+ if (!contentType.includes("text/event-stream") && !contentType.includes("application/json")) return res;
941
+ const text = await res.text();
942
+ const trimmed = text.trim();
943
+ if (trimmed.startsWith("data:")) {
944
+ let content = "";
945
+ let lastChunk = null;
946
+ for (const line of trimmed.split("\n")) {
947
+ const l = line.trim();
948
+ if (!l || !l.startsWith("data:")) continue;
949
+ const jsonStr = l.slice(5).trim();
950
+ if (jsonStr === "[DONE]") continue;
951
+ try {
952
+ const chunk = JSON.parse(jsonStr);
953
+ lastChunk = chunk;
954
+ content += chunk.choices?.[0]?.delta?.content || "";
955
+ } catch {
956
+ }
957
+ }
958
+ const assembled = {
959
+ id: lastChunk?.id || "chatcmpl-" + Date.now(),
960
+ object: "chat.completion",
961
+ created: lastChunk?.created || Math.floor(Date.now() / 1e3),
962
+ model: lastChunk?.model || "9router",
963
+ choices: [{ index: 0, message: { role: "assistant", content }, finish_reason: "stop" }],
964
+ usage: lastChunk?.usage || void 0
965
+ };
966
+ const headers = new Headers(res.headers);
967
+ headers.set("content-type", "application/json");
968
+ return new Response(JSON.stringify(assembled), { status: res.status, statusText: res.statusText, headers });
969
+ }
970
+ const doneIndex = text.indexOf("data: [DONE]");
971
+ if (doneIndex === -1) return res;
972
+ return new Response(text.slice(0, doneIndex).trim(), { status: res.status, statusText: res.statusText, headers: res.headers });
973
+ };
974
+ }
929
975
  var DEFAULT_MODELS = {
930
976
  "9router": "fast-reasoning",
931
977
  ninerouter: "fast-reasoning",
@@ -965,7 +1011,8 @@ function getAIModel(options = {}) {
965
1011
  const rawUrl = options.baseURL || resolveApiKey("NINEROUTER_BASE_URL") || resolveApiKey("NINE_ROUTER_BASE_URL") || "https://ai-router.orchable.app/v1";
966
1012
  const ninerouter = createOpenAI({
967
1013
  apiKey,
968
- baseURL: rawUrl.replace(/^["']|["']$/g, "").trim()
1014
+ baseURL: rawUrl.replace(/^["']|["']$/g, "").trim(),
1015
+ fetch: cleanNonStreamingFetch()
969
1016
  });
970
1017
  return ninerouter.chat(resolvedModelName || "fast-reasoning");
971
1018
  }