@thanh01.pmt/curriculum-kit 1.4.31 → 1.4.33
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 +126 -1
- package/dist/ai/index.cjs.map +1 -1
- package/dist/ai/index.d.cts +10 -46
- package/dist/ai/index.d.ts +10 -46
- package/dist/ai/index.mjs +126 -1
- package/dist/ai/index.mjs.map +1 -1
- package/dist/index.cjs +128 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +128 -1
- package/dist/index.mjs.map +1 -1
- 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.map +1 -1
- package/dist/pipeline/index.cjs +48 -1
- package/dist/pipeline/index.cjs.map +1 -1
- package/dist/pipeline/index.mjs +48 -1
- package/dist/pipeline/index.mjs.map +1 -1
- package/dist/{streamRunner-DYHFhNUr.d.cts → streamRunner-B0Z1nAG5.d.cts} +76 -1
- package/dist/{streamRunner-DYHFhNUr.d.ts → streamRunner-B0Z1nAG5.d.ts} +76 -1
- package/dist/workflow/index.cjs +48 -1
- package/dist/workflow/index.cjs.map +1 -1
- package/dist/workflow/index.mjs +48 -1
- package/dist/workflow/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/ai/index.d.cts
CHANGED
|
@@ -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, c as ChunkType } from '../streamRunner-
|
|
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 resolveApiKey, k as runCurriculumAIInference, s as streamCurriculumAIInference } from '../streamRunner-
|
|
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';
|
|
7
7
|
import { z } from 'zod';
|
|
8
8
|
|
|
9
9
|
interface LessonPromptInput {
|
|
@@ -1260,52 +1260,16 @@ declare class LLMJudgeEngine {
|
|
|
1260
1260
|
static evaluateArtifact(artifactType: string, content: string, lessonTitle: string): JudgeEvaluationResult;
|
|
1261
1261
|
}
|
|
1262
1262
|
|
|
1263
|
-
/** Định nghĩa tool (OpenAI-compatible function schema) cho LLM tool-calling */
|
|
1264
|
-
interface ToolDefinition {
|
|
1265
|
-
type: 'function';
|
|
1266
|
-
function: {
|
|
1267
|
-
name: string;
|
|
1268
|
-
description: string;
|
|
1269
|
-
/** JSON Schema cho tham số */
|
|
1270
|
-
parameters: Record<string, unknown>;
|
|
1271
|
-
};
|
|
1272
|
-
}
|
|
1273
|
-
/** Tool call hoàn chỉnh sau khi aggregate các delta */
|
|
1274
|
-
interface AggregatedToolCall {
|
|
1275
|
-
id: string;
|
|
1276
|
-
name: string;
|
|
1277
|
-
/** JSON string arguments từ model */
|
|
1278
|
-
arguments: string;
|
|
1279
|
-
}
|
|
1280
|
-
/** Kết quả thực thi tool do caller cung cấp */
|
|
1281
|
-
interface ToolExecutionResult {
|
|
1282
|
-
toolCallId: string;
|
|
1283
|
-
name: string;
|
|
1284
|
-
/** Kết quả serialize thành JSON string khi gửi lại model */
|
|
1285
|
-
result: unknown;
|
|
1286
|
-
isError?: boolean;
|
|
1287
|
-
}
|
|
1288
|
-
/** Executor: nhận (name, parsedArgs) → kết quả. Throw = lỗi tool (báo lại model) */
|
|
1289
|
-
type ToolExecutor = (name: string, args: Record<string, unknown>) => Promise<unknown>;
|
|
1290
|
-
/** Cấu hình vòng lặp tool-calling */
|
|
1291
|
-
interface ToolLoopConfig {
|
|
1292
|
-
tools: ToolDefinition[];
|
|
1293
|
-
executor: ToolExecutor;
|
|
1294
|
-
/** Số vòng tool-call tối đa (chống vòng lặp vô hạn). Mặc định 4 */
|
|
1295
|
-
maxRounds?: number;
|
|
1296
|
-
/** Báo mỗi lần bắt đầu thực thi tool (để UI hiển thị) */
|
|
1297
|
-
onToolStart?: (name: string, args: Record<string, unknown>) => void;
|
|
1298
|
-
/** Báo kết quả tool */
|
|
1299
|
-
onToolResult?: (result: ToolExecutionResult) => void;
|
|
1300
|
-
/** Báo lỗi tool (không dừng workflow — tool error được đưa lại cho model tự xử lý) */
|
|
1301
|
-
onToolError?: (name: string, error: string) => void;
|
|
1302
|
-
}
|
|
1303
|
-
|
|
1304
1263
|
/**
|
|
1305
1264
|
* Stream chat CÓ tool-calling (vòng lặp: model → tool → kết quả → model → …).
|
|
1306
|
-
*
|
|
1307
|
-
*
|
|
1265
|
+
* Route qua customToolInference (host AI SDK gateway) khi được truyền — unified
|
|
1266
|
+
* tracing mandate. Không có customToolInference:
|
|
1267
|
+
* - CURRICULUM_KIT_REQUIRE_CUSTOM_INFERENCE=1 → fail-loud ERR_CUSTOM_INFERENCE_REQUIRED
|
|
1268
|
+
* (raw-fetch routes nằm ngoài biên telemetry của host).
|
|
1269
|
+
* - Ngược lại → raw-fetch legacy (OpenRouter/DeepSeek/Alibaba/NVIDIA).
|
|
1270
|
+
* Tool error KHÔNG làm chết stream: lỗi được đóng gói gửi lại model để tự xử lý
|
|
1271
|
+
* (và được báo qua onToolError cho observability).
|
|
1308
1272
|
*/
|
|
1309
1273
|
declare function streamCurriculumAIInferenceWithTools(messages: ChatMessage[], projectContext: string, options: StreamRunnerOptions, loop: ToolLoopConfig, onChunk?: (token: string, type: ChunkType) => void): Promise<string>;
|
|
1310
1274
|
|
|
1311
|
-
export { type ActivityPromptInput, type
|
|
1275
|
+
export { type ActivityPromptInput, type AsyncLLMJudgeInput, type AuditCurriculumQualityInput, ChatMessage, ChunkType, type CodeLabPromptInput, DEFAULT_ENABLED_PROVIDERS, type DiagnosticQuizPromptInput, type ExtensionPromptInput, type GenerateActivityInput, type GenerateCodeLabInput, type GenerateDiagnosticQuizInput, type GenerateExtensionInput, type GenerateHandoutInput, type GenerateLessonMasterInput, type GenerateProjectInstructionInput, type GenerateSelfLabInput, type GenerateSlidesInput, type GenerateTeacherGuideInput, type GenerateWorksheetInput, type HandoutPromptInput, type HtmlDeckSlidePromptInput, type JudgeEvaluationResult, type JudgePromptInput, LLMJudgeEngine, type LessonPromptInput, type MarpMarkdownSlidePromptInput, type ModelPolicyResolution, ModelPolicyResolver, type ModelProviderKey, ModelResolutionOptions, type MultiProviderPolicyResolution, type ProjectInstructionPromptInput, SLIDE_CANONICAL_METHODOLOGY, type SelfLabPromptInput, type SlidesPromptInput, type StreamDiagnosticQuizInput, type StreamLessonMasterInput, StreamRunnerOptions, type StreamSelfLabInput, type TeacherGuidePromptInput, ToolLoopConfig, type WorksheetPromptInput, activityTools, analystTools, assessorTools, auditCurriculumQualityFlow, buildActivityPrompt, buildCodeLabPrompt, buildDiagnosticQuizPrompt, buildExtensionPrompt, buildHandoutPrompt, buildHtmlDeckSlidePrompt, buildJudgePrompt, buildLessonMasterPrompt, buildMarpMarkdownSlidePrompt, buildProjectInstructionPrompt, buildSelfLabPrompt, buildSlidesPrompt, buildTeacherGuidePrompt, buildWorksheetPrompt, contentTools, designerTools, generateActivityFlow, generateCodeLabFlow, generateDiagnosticQuizFlow, generateExtensionFlow, generateHandoutFlow, generateLessonMasterFlow, generateProjectInstructionFlow, generateSelfLabFlow, generateSlidesFlow, generateTeacherGuideFlow, generateWorksheetFlow, illustratorTools, packagerTools, researcherTools, reviewerTools, streamCurriculumAIInferenceWithTools, streamDiagnosticQuizFlow, streamLessonMasterFlow, streamSelfLabFlow, techSmeTools };
|
package/dist/ai/index.d.ts
CHANGED
|
@@ -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, c as ChunkType } from '../streamRunner-
|
|
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 resolveApiKey, k as runCurriculumAIInference, s as streamCurriculumAIInference } from '../streamRunner-
|
|
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';
|
|
7
7
|
import { z } from 'zod';
|
|
8
8
|
|
|
9
9
|
interface LessonPromptInput {
|
|
@@ -1260,52 +1260,16 @@ declare class LLMJudgeEngine {
|
|
|
1260
1260
|
static evaluateArtifact(artifactType: string, content: string, lessonTitle: string): JudgeEvaluationResult;
|
|
1261
1261
|
}
|
|
1262
1262
|
|
|
1263
|
-
/** Định nghĩa tool (OpenAI-compatible function schema) cho LLM tool-calling */
|
|
1264
|
-
interface ToolDefinition {
|
|
1265
|
-
type: 'function';
|
|
1266
|
-
function: {
|
|
1267
|
-
name: string;
|
|
1268
|
-
description: string;
|
|
1269
|
-
/** JSON Schema cho tham số */
|
|
1270
|
-
parameters: Record<string, unknown>;
|
|
1271
|
-
};
|
|
1272
|
-
}
|
|
1273
|
-
/** Tool call hoàn chỉnh sau khi aggregate các delta */
|
|
1274
|
-
interface AggregatedToolCall {
|
|
1275
|
-
id: string;
|
|
1276
|
-
name: string;
|
|
1277
|
-
/** JSON string arguments từ model */
|
|
1278
|
-
arguments: string;
|
|
1279
|
-
}
|
|
1280
|
-
/** Kết quả thực thi tool do caller cung cấp */
|
|
1281
|
-
interface ToolExecutionResult {
|
|
1282
|
-
toolCallId: string;
|
|
1283
|
-
name: string;
|
|
1284
|
-
/** Kết quả serialize thành JSON string khi gửi lại model */
|
|
1285
|
-
result: unknown;
|
|
1286
|
-
isError?: boolean;
|
|
1287
|
-
}
|
|
1288
|
-
/** Executor: nhận (name, parsedArgs) → kết quả. Throw = lỗi tool (báo lại model) */
|
|
1289
|
-
type ToolExecutor = (name: string, args: Record<string, unknown>) => Promise<unknown>;
|
|
1290
|
-
/** Cấu hình vòng lặp tool-calling */
|
|
1291
|
-
interface ToolLoopConfig {
|
|
1292
|
-
tools: ToolDefinition[];
|
|
1293
|
-
executor: ToolExecutor;
|
|
1294
|
-
/** Số vòng tool-call tối đa (chống vòng lặp vô hạn). Mặc định 4 */
|
|
1295
|
-
maxRounds?: number;
|
|
1296
|
-
/** Báo mỗi lần bắt đầu thực thi tool (để UI hiển thị) */
|
|
1297
|
-
onToolStart?: (name: string, args: Record<string, unknown>) => void;
|
|
1298
|
-
/** Báo kết quả tool */
|
|
1299
|
-
onToolResult?: (result: ToolExecutionResult) => void;
|
|
1300
|
-
/** Báo lỗi tool (không dừng workflow — tool error được đưa lại cho model tự xử lý) */
|
|
1301
|
-
onToolError?: (name: string, error: string) => void;
|
|
1302
|
-
}
|
|
1303
|
-
|
|
1304
1263
|
/**
|
|
1305
1264
|
* Stream chat CÓ tool-calling (vòng lặp: model → tool → kết quả → model → …).
|
|
1306
|
-
*
|
|
1307
|
-
*
|
|
1265
|
+
* Route qua customToolInference (host AI SDK gateway) khi được truyền — unified
|
|
1266
|
+
* tracing mandate. Không có customToolInference:
|
|
1267
|
+
* - CURRICULUM_KIT_REQUIRE_CUSTOM_INFERENCE=1 → fail-loud ERR_CUSTOM_INFERENCE_REQUIRED
|
|
1268
|
+
* (raw-fetch routes nằm ngoài biên telemetry của host).
|
|
1269
|
+
* - Ngược lại → raw-fetch legacy (OpenRouter/DeepSeek/Alibaba/NVIDIA).
|
|
1270
|
+
* Tool error KHÔNG làm chết stream: lỗi được đóng gói gửi lại model để tự xử lý
|
|
1271
|
+
* (và được báo qua onToolError cho observability).
|
|
1308
1272
|
*/
|
|
1309
1273
|
declare function streamCurriculumAIInferenceWithTools(messages: ChatMessage[], projectContext: string, options: StreamRunnerOptions, loop: ToolLoopConfig, onChunk?: (token: string, type: ChunkType) => void): Promise<string>;
|
|
1310
1274
|
|
|
1311
|
-
export { type ActivityPromptInput, type
|
|
1275
|
+
export { type ActivityPromptInput, type AsyncLLMJudgeInput, type AuditCurriculumQualityInput, ChatMessage, ChunkType, type CodeLabPromptInput, DEFAULT_ENABLED_PROVIDERS, type DiagnosticQuizPromptInput, type ExtensionPromptInput, type GenerateActivityInput, type GenerateCodeLabInput, type GenerateDiagnosticQuizInput, type GenerateExtensionInput, type GenerateHandoutInput, type GenerateLessonMasterInput, type GenerateProjectInstructionInput, type GenerateSelfLabInput, type GenerateSlidesInput, type GenerateTeacherGuideInput, type GenerateWorksheetInput, type HandoutPromptInput, type HtmlDeckSlidePromptInput, type JudgeEvaluationResult, type JudgePromptInput, LLMJudgeEngine, type LessonPromptInput, type MarpMarkdownSlidePromptInput, type ModelPolicyResolution, ModelPolicyResolver, type ModelProviderKey, ModelResolutionOptions, type MultiProviderPolicyResolution, type ProjectInstructionPromptInput, SLIDE_CANONICAL_METHODOLOGY, type SelfLabPromptInput, type SlidesPromptInput, type StreamDiagnosticQuizInput, type StreamLessonMasterInput, StreamRunnerOptions, type StreamSelfLabInput, type TeacherGuidePromptInput, ToolLoopConfig, type WorksheetPromptInput, activityTools, analystTools, assessorTools, auditCurriculumQualityFlow, buildActivityPrompt, buildCodeLabPrompt, buildDiagnosticQuizPrompt, buildExtensionPrompt, buildHandoutPrompt, buildHtmlDeckSlidePrompt, buildJudgePrompt, buildLessonMasterPrompt, buildMarpMarkdownSlidePrompt, buildProjectInstructionPrompt, buildSelfLabPrompt, buildSlidesPrompt, buildTeacherGuidePrompt, buildWorksheetPrompt, contentTools, designerTools, generateActivityFlow, generateCodeLabFlow, generateDiagnosticQuizFlow, generateExtensionFlow, generateHandoutFlow, generateLessonMasterFlow, generateProjectInstructionFlow, generateSelfLabFlow, generateSlidesFlow, generateTeacherGuideFlow, generateWorksheetFlow, illustratorTools, packagerTools, researcherTools, reviewerTools, streamCurriculumAIInferenceWithTools, streamDiagnosticQuizFlow, streamLessonMasterFlow, streamSelfLabFlow, techSmeTools };
|
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
|
}
|
|
@@ -5122,6 +5169,16 @@ async function runTurn(endpoint, model, apiKey, messages, tools, idleTimeoutMs,
|
|
|
5122
5169
|
return { content: fullRaw, toolCalls };
|
|
5123
5170
|
}
|
|
5124
5171
|
async function streamCurriculumAIInferenceWithTools(messages, projectContext, options, loop, onChunk) {
|
|
5172
|
+
if (options.customToolInference) {
|
|
5173
|
+
return runToolLoopWithCustomInference(messages, projectContext, options, loop, onChunk);
|
|
5174
|
+
}
|
|
5175
|
+
if (resolveApiKey("CURRICULUM_KIT_REQUIRE_CUSTOM_INFERENCE") === "1") {
|
|
5176
|
+
throw createAiInferenceError({
|
|
5177
|
+
errorCode: "ERR_CUSTOM_INFERENCE_REQUIRED",
|
|
5178
|
+
message: "customToolInference is REQUIRED (CURRICULUM_KIT_REQUIRE_CUSTOM_INFERENCE=1): pass buildKitToolInference(...) so tool-calling turns flow through the host AI SDK gateway and its unified Langfuse tracing. Raw-fetch tool-loop provider routes are disabled by mandate.",
|
|
5179
|
+
rawError: { mandate: "CURRICULUM_KIT_REQUIRE_CUSTOM_INFERENCE", hasCustomToolInference: false }
|
|
5180
|
+
});
|
|
5181
|
+
}
|
|
5125
5182
|
const route = resolveProviderRoute(options);
|
|
5126
5183
|
const maxTokens = options.maxTokens ?? 32768;
|
|
5127
5184
|
const maxRounds = loop.maxRounds ?? 4;
|
|
@@ -5186,6 +5243,74 @@ Guidelines:
|
|
|
5186
5243
|
}
|
|
5187
5244
|
return finalContent;
|
|
5188
5245
|
}
|
|
5246
|
+
async function runToolLoopWithCustomInference(messages, projectContext, options, loop, onChunk) {
|
|
5247
|
+
const infer = options.customToolInference;
|
|
5248
|
+
const maxTokens = options.maxTokens ?? 32768;
|
|
5249
|
+
const maxRounds = loop.maxRounds ?? 4;
|
|
5250
|
+
const systemInstruction = `${options.systemPersona || "You are Curriculum OS Assistant."}
|
|
5251
|
+
|
|
5252
|
+
Project Context:
|
|
5253
|
+
${projectContext}
|
|
5254
|
+
|
|
5255
|
+
Guidelines:
|
|
5256
|
+
1. Answer precisely using the provided tools when they help (project status, deep research, production declaration, gate approval).
|
|
5257
|
+
2. Keep Markdown formatting. Never invent tool results.`;
|
|
5258
|
+
const convo = [
|
|
5259
|
+
{ role: "system", content: systemInstruction },
|
|
5260
|
+
...messages.map((m) => ({ role: m.role === "assistant" || m.role === "model" ? "assistant" : "user", content: m.content }))
|
|
5261
|
+
];
|
|
5262
|
+
let finalContent = "";
|
|
5263
|
+
for (let round = 0; round < maxRounds; round++) {
|
|
5264
|
+
let turn;
|
|
5265
|
+
try {
|
|
5266
|
+
turn = await infer({ messages: convo, tools: loop.tools, temperature: options.temperature ?? 0.3, maxTokens, onChunk: onChunk ?? (() => {
|
|
5267
|
+
}) });
|
|
5268
|
+
} catch (err) {
|
|
5269
|
+
const msg = String(err?.message || err);
|
|
5270
|
+
if (/tool/i.test(msg) && /40[04]|400|not support|invalid/i.test(msg)) {
|
|
5271
|
+
console.warn("[toolLoop] custom gateway rejected tools \u2014 degrading to plain chat:", msg.slice(0, 120));
|
|
5272
|
+
const plain = await infer({ messages: convo, tools: [], temperature: options.temperature ?? 0.3, maxTokens, onChunk: onChunk ?? (() => {
|
|
5273
|
+
}) });
|
|
5274
|
+
finalContent = plain.content;
|
|
5275
|
+
break;
|
|
5276
|
+
}
|
|
5277
|
+
throw err;
|
|
5278
|
+
}
|
|
5279
|
+
const { content, toolCalls } = turn;
|
|
5280
|
+
if (toolCalls.length === 0) {
|
|
5281
|
+
finalContent = content;
|
|
5282
|
+
break;
|
|
5283
|
+
}
|
|
5284
|
+
if (content) finalContent = content;
|
|
5285
|
+
convo.push({ role: "assistant", content: content || null, tool_calls: toolCalls.map((t) => ({ id: t.id, type: "function", function: { name: t.name, arguments: t.arguments } })) });
|
|
5286
|
+
for (const call of toolCalls) {
|
|
5287
|
+
let parsedArgs = {};
|
|
5288
|
+
try {
|
|
5289
|
+
parsedArgs = JSON.parse(call.arguments || "{}");
|
|
5290
|
+
} catch {
|
|
5291
|
+
}
|
|
5292
|
+
loop.onToolStart?.(call.name, parsedArgs);
|
|
5293
|
+
let resultPayload;
|
|
5294
|
+
let isError = false;
|
|
5295
|
+
try {
|
|
5296
|
+
resultPayload = await loop.executor(call.name, parsedArgs);
|
|
5297
|
+
} catch (err) {
|
|
5298
|
+
isError = true;
|
|
5299
|
+
resultPayload = { error: err?.message || String(err) };
|
|
5300
|
+
loop.onToolError?.(call.name, err?.message || String(err));
|
|
5301
|
+
}
|
|
5302
|
+
const exec = { toolCallId: call.id, name: call.name, result: resultPayload, isError };
|
|
5303
|
+
loop.onToolResult?.(exec);
|
|
5304
|
+
convo.push({ role: "tool", tool_call_id: call.id, content: JSON.stringify(resultPayload).slice(0, 12e3) });
|
|
5305
|
+
}
|
|
5306
|
+
if (round === maxRounds - 1) {
|
|
5307
|
+
const last = await infer({ messages: convo, tools: [], temperature: options.temperature ?? 0.3, maxTokens, onChunk: onChunk ?? (() => {
|
|
5308
|
+
}) });
|
|
5309
|
+
finalContent = last.content;
|
|
5310
|
+
}
|
|
5311
|
+
}
|
|
5312
|
+
return finalContent;
|
|
5313
|
+
}
|
|
5189
5314
|
|
|
5190
5315
|
export { DEFAULT_ARTIFACT_STREAM_IDLE_MS, DEFAULT_ARTIFACT_STREAM_TOTAL_MS, DEFAULT_ENABLED_PROVIDERS, LLMJudgeEngine, ModelPolicyResolver, NVIDIA_MODELS, SLIDE_CANONICAL_METHODOLOGY, activityTools, analystTools, assessorTools, auditCurriculumQualityFlow, buildActivityPrompt, buildCodeLabPrompt, buildDiagnosticQuizPrompt, buildExtensionPrompt, buildHandoutPrompt, buildHtmlDeckSlidePrompt, buildJudgePrompt, buildLessonMasterPrompt, buildMarpMarkdownSlidePrompt, 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, resolveApiKey, reviewerTools, runCurriculumAIInference, streamCurriculumAIInference, streamCurriculumAIInferenceWithTools, streamDiagnosticQuizFlow, streamLessonMasterFlow, streamSelfLabFlow, techSmeTools };
|
|
5191
5316
|
//# sourceMappingURL=index.mjs.map
|