@thanh01.pmt/curriculum-kit 1.0.14 → 1.0.15

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
@@ -13525,11 +13525,11 @@ var DeterministicPipelineRunner = class {
13525
13525
  // src/services/prefillService.ts
13526
13526
  init_streamRunner();
13527
13527
  var DEFAULT_STREAM_IDLE_MS = 45e3;
13528
- var DEFAULT_STREAM_TOTAL_MS = 3e5;
13528
+ var DEFAULT_STREAM_TOTAL_MS = 42e4;
13529
13529
  var LAYER_TOTAL_BUDGET_MS = {
13530
- 1: 18e4,
13531
- 2: 36e4,
13532
- 3: 36e4
13530
+ 1: 42e4,
13531
+ 2: 42e4,
13532
+ 3: 42e4
13533
13533
  };
13534
13534
  function resolveStreamBudget(layer, opts) {
13535
13535
  const envIdle = Number(process.env.WIZARD_PREFILL_IDLE_TIMEOUT_MS);
@@ -13596,29 +13596,111 @@ function createStreamAbortSignal(budget) {
13596
13596
  }
13597
13597
  };
13598
13598
  }
13599
+ function closeTruncatedJson(candidate) {
13600
+ let inStr = false;
13601
+ let esc2 = false;
13602
+ const stack = [];
13603
+ for (let i = 0; i < candidate.length; i++) {
13604
+ const ch = candidate[i];
13605
+ if (esc2) {
13606
+ esc2 = false;
13607
+ continue;
13608
+ }
13609
+ if (inStr) {
13610
+ if (ch === "\\") esc2 = true;
13611
+ else if (ch === '"') inStr = false;
13612
+ continue;
13613
+ }
13614
+ if (ch === '"') inStr = true;
13615
+ else if (ch === "{" || ch === "[") stack.push(ch);
13616
+ else if (ch === "}" || ch === "]") stack.pop();
13617
+ }
13618
+ if (stack.length === 0 && !inStr) return null;
13619
+ let out = candidate;
13620
+ out = out.replace(/,\s*$/, "");
13621
+ if (inStr) {
13622
+ out = out.replace(/\\+$/, "");
13623
+ out += '"';
13624
+ }
13625
+ while (stack.length > 0) {
13626
+ out += stack.pop() === "{" ? "}" : "]";
13627
+ }
13628
+ return out;
13629
+ }
13630
+ function stripLlmJsonWrappers(rawText) {
13631
+ let cleaned = rawText.replace(/<think>[\s\S]*?<\/think>/gi, "").replace(/```json\s*/gi, "").replace(/```\s*/g, "").trim();
13632
+ const firstBrace = cleaned.indexOf("{");
13633
+ if (firstBrace > 0) {
13634
+ cleaned = cleaned.slice(firstBrace);
13635
+ }
13636
+ return cleaned.trim();
13637
+ }
13599
13638
  function safeParseJson(rawText) {
13600
13639
  if (!rawText) return null;
13601
- const cleaned = rawText.replace(/```json\s*/gi, "").replace(/```\s*/g, "").trim();
13640
+ const cleaned = stripLlmJsonWrappers(rawText);
13641
+ if (!cleaned) return null;
13602
13642
  try {
13603
13643
  return JSON.parse(cleaned);
13604
13644
  } catch {
13605
- const firstBrace = cleaned.indexOf("{");
13645
+ }
13646
+ const firstBrace = cleaned.indexOf("{");
13647
+ if (firstBrace === -1) return null;
13648
+ const buildCandidates = () => {
13649
+ const list = [];
13650
+ const closed = closeTruncatedJson(cleaned.slice(firstBrace));
13651
+ if (closed) list.push(closed);
13606
13652
  const lastBrace = cleaned.lastIndexOf("}");
13607
- if (firstBrace !== -1 && lastBrace !== -1 && lastBrace > firstBrace) {
13608
- const candidate = cleaned.slice(firstBrace, lastBrace + 1);
13609
- try {
13610
- return JSON.parse(candidate);
13611
- } catch {
13653
+ if (lastBrace > firstBrace) {
13654
+ list.push(cleaned.slice(firstBrace, lastBrace + 1));
13655
+ }
13656
+ return list;
13657
+ };
13658
+ for (const candidate of buildCandidates()) {
13659
+ try {
13660
+ return JSON.parse(candidate);
13661
+ } catch {
13662
+ }
13663
+ try {
13664
+ return JSON.parse(jsonrepair.jsonrepair(candidate));
13665
+ } catch {
13666
+ }
13667
+ }
13668
+ let depth = 0;
13669
+ let inStr = false;
13670
+ let esc2 = false;
13671
+ for (let i = firstBrace; i < cleaned.length; i++) {
13672
+ const ch = cleaned[i];
13673
+ if (esc2) {
13674
+ esc2 = false;
13675
+ continue;
13676
+ }
13677
+ if (inStr) {
13678
+ if (ch === "\\") esc2 = true;
13679
+ else if (ch === '"') inStr = false;
13680
+ continue;
13681
+ }
13682
+ if (ch === '"') inStr = true;
13683
+ else if (ch === "{") depth++;
13684
+ else if (ch === "}") {
13685
+ depth--;
13686
+ if (depth === 0) {
13687
+ const candidate = cleaned.slice(firstBrace, i + 1);
13612
13688
  try {
13613
- const repaired = jsonrepair.jsonrepair(candidate);
13614
- return JSON.parse(repaired);
13689
+ return JSON.parse(candidate);
13690
+ } catch {
13691
+ }
13692
+ try {
13693
+ return JSON.parse(jsonrepair.jsonrepair(candidate));
13615
13694
  } catch {
13616
- return null;
13617
13695
  }
13618
13696
  }
13619
13697
  }
13620
- return null;
13621
13698
  }
13699
+ try {
13700
+ return JSON.parse(jsonrepair.jsonrepair(cleaned));
13701
+ } catch {
13702
+ }
13703
+ return null;
13622
13704
  }
13623
13705
  async function streamLLMWithFallback(systemPrompt, userPrompt, apiKeys = {}, onChunk, preferredModel, preferredProvider, budget) {
13624
13706
  const alibabaKey = apiKeys.alibaba || apiKeys.dashscope || process.env.ALIBABA_API_KEY || process.env.DASHSCOPE_API_KEY;
@@ -16790,6 +16872,7 @@ exports.buildStandardsContext = buildStandardsContext;
16790
16872
  exports.buildStandardsContextBlock = buildStandardsContextBlock;
16791
16873
  exports.buildTeacherGuidePrompt = buildTeacherGuidePrompt;
16792
16874
  exports.buildWorksheetPrompt = buildWorksheetPrompt;
16875
+ exports.closeTruncatedJson = closeTruncatedJson;
16793
16876
  exports.computeContentHash = computeContentHash;
16794
16877
  exports.computePackingSpec = computePackingSpec;
16795
16878
  exports.conductPreliminaryResearch = conductPreliminaryResearch;
@@ -16896,6 +16979,7 @@ exports.streamLLMWithFallback = streamLLMWithFallback;
16896
16979
  exports.streamLayerPrefillWithFallback = streamLayerPrefillWithFallback;
16897
16980
  exports.streamLessonMasterFlow = streamLessonMasterFlow;
16898
16981
  exports.streamSelfLabFlow = streamSelfLabFlow;
16982
+ exports.stripLlmJsonWrappers = stripLlmJsonWrappers;
16899
16983
  exports.techSmeTools = techSmeTools;
16900
16984
  exports.topoSort = topoSort;
16901
16985
  exports.uploadAssetToBucket = uploadAssetToBucket;