@thanh01.pmt/curriculum-kit 1.4.32 → 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 +48 -1
- package/dist/ai/index.cjs.map +1 -1
- package/dist/ai/index.mjs +48 -1
- package/dist/ai/index.mjs.map +1 -1
- package/dist/index.cjs +48 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +48 -1
- package/dist/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/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/index.cjs
CHANGED
|
@@ -991,6 +991,52 @@ var init_streamRunner = __esm({
|
|
|
991
991
|
exports.DEFAULT_ARTIFACT_STREAM_TOTAL_MS = 48e4;
|
|
992
992
|
}
|
|
993
993
|
});
|
|
994
|
+
function cleanNonStreamingFetch() {
|
|
995
|
+
return async (input, init) => {
|
|
996
|
+
const res = await fetch(input, init);
|
|
997
|
+
let wantsStream = false;
|
|
998
|
+
try {
|
|
999
|
+
const body = init?.body;
|
|
1000
|
+
if (typeof body === "string") wantsStream = /"stream"\s*:\s*true/.test(body);
|
|
1001
|
+
} catch {
|
|
1002
|
+
}
|
|
1003
|
+
if (wantsStream) return res;
|
|
1004
|
+
const contentType = res.headers.get("content-type") || "";
|
|
1005
|
+
if (!contentType.includes("text/event-stream") && !contentType.includes("application/json")) return res;
|
|
1006
|
+
const text = await res.text();
|
|
1007
|
+
const trimmed = text.trim();
|
|
1008
|
+
if (trimmed.startsWith("data:")) {
|
|
1009
|
+
let content = "";
|
|
1010
|
+
let lastChunk = null;
|
|
1011
|
+
for (const line of trimmed.split("\n")) {
|
|
1012
|
+
const l = line.trim();
|
|
1013
|
+
if (!l || !l.startsWith("data:")) continue;
|
|
1014
|
+
const jsonStr = l.slice(5).trim();
|
|
1015
|
+
if (jsonStr === "[DONE]") continue;
|
|
1016
|
+
try {
|
|
1017
|
+
const chunk = JSON.parse(jsonStr);
|
|
1018
|
+
lastChunk = chunk;
|
|
1019
|
+
content += chunk.choices?.[0]?.delta?.content || "";
|
|
1020
|
+
} catch {
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
const assembled = {
|
|
1024
|
+
id: lastChunk?.id || "chatcmpl-" + Date.now(),
|
|
1025
|
+
object: "chat.completion",
|
|
1026
|
+
created: lastChunk?.created || Math.floor(Date.now() / 1e3),
|
|
1027
|
+
model: lastChunk?.model || "9router",
|
|
1028
|
+
choices: [{ index: 0, message: { role: "assistant", content }, finish_reason: "stop" }],
|
|
1029
|
+
usage: lastChunk?.usage || void 0
|
|
1030
|
+
};
|
|
1031
|
+
const headers = new Headers(res.headers);
|
|
1032
|
+
headers.set("content-type", "application/json");
|
|
1033
|
+
return new Response(JSON.stringify(assembled), { status: res.status, statusText: res.statusText, headers });
|
|
1034
|
+
}
|
|
1035
|
+
const doneIndex = text.indexOf("data: [DONE]");
|
|
1036
|
+
if (doneIndex === -1) return res;
|
|
1037
|
+
return new Response(text.slice(0, doneIndex).trim(), { status: res.status, statusText: res.statusText, headers: res.headers });
|
|
1038
|
+
};
|
|
1039
|
+
}
|
|
994
1040
|
function getAIModel(options = {}) {
|
|
995
1041
|
const designated = getDesignatedFallbackConfig();
|
|
996
1042
|
const defaultProvider = process.env.DEFAULT_AI_PROVIDER || process.env.LLM_PROVIDER || detectDefaultProvider();
|
|
@@ -1009,7 +1055,8 @@ function getAIModel(options = {}) {
|
|
|
1009
1055
|
const rawUrl = options.baseURL || resolveApiKey("NINEROUTER_BASE_URL") || resolveApiKey("NINE_ROUTER_BASE_URL") || "https://ai-router.orchable.app/v1";
|
|
1010
1056
|
const ninerouter = openai.createOpenAI({
|
|
1011
1057
|
apiKey,
|
|
1012
|
-
baseURL: rawUrl.replace(/^["']|["']$/g, "").trim()
|
|
1058
|
+
baseURL: rawUrl.replace(/^["']|["']$/g, "").trim(),
|
|
1059
|
+
fetch: cleanNonStreamingFetch()
|
|
1013
1060
|
});
|
|
1014
1061
|
return ninerouter.chat(resolvedModelName || "fast-reasoning");
|
|
1015
1062
|
}
|