@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/workflow/index.cjs
CHANGED
|
@@ -958,6 +958,52 @@ var init_streamRunner = __esm({
|
|
|
958
958
|
DEFAULT_ARTIFACT_STREAM_TOTAL_MS = 48e4;
|
|
959
959
|
}
|
|
960
960
|
});
|
|
961
|
+
function cleanNonStreamingFetch() {
|
|
962
|
+
return async (input, init) => {
|
|
963
|
+
const res = await fetch(input, init);
|
|
964
|
+
let wantsStream = false;
|
|
965
|
+
try {
|
|
966
|
+
const body = init?.body;
|
|
967
|
+
if (typeof body === "string") wantsStream = /"stream"\s*:\s*true/.test(body);
|
|
968
|
+
} catch {
|
|
969
|
+
}
|
|
970
|
+
if (wantsStream) return res;
|
|
971
|
+
const contentType = res.headers.get("content-type") || "";
|
|
972
|
+
if (!contentType.includes("text/event-stream") && !contentType.includes("application/json")) return res;
|
|
973
|
+
const text = await res.text();
|
|
974
|
+
const trimmed = text.trim();
|
|
975
|
+
if (trimmed.startsWith("data:")) {
|
|
976
|
+
let content = "";
|
|
977
|
+
let lastChunk = null;
|
|
978
|
+
for (const line of trimmed.split("\n")) {
|
|
979
|
+
const l = line.trim();
|
|
980
|
+
if (!l || !l.startsWith("data:")) continue;
|
|
981
|
+
const jsonStr = l.slice(5).trim();
|
|
982
|
+
if (jsonStr === "[DONE]") continue;
|
|
983
|
+
try {
|
|
984
|
+
const chunk = JSON.parse(jsonStr);
|
|
985
|
+
lastChunk = chunk;
|
|
986
|
+
content += chunk.choices?.[0]?.delta?.content || "";
|
|
987
|
+
} catch {
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
const assembled = {
|
|
991
|
+
id: lastChunk?.id || "chatcmpl-" + Date.now(),
|
|
992
|
+
object: "chat.completion",
|
|
993
|
+
created: lastChunk?.created || Math.floor(Date.now() / 1e3),
|
|
994
|
+
model: lastChunk?.model || "9router",
|
|
995
|
+
choices: [{ index: 0, message: { role: "assistant", content }, finish_reason: "stop" }],
|
|
996
|
+
usage: lastChunk?.usage || void 0
|
|
997
|
+
};
|
|
998
|
+
const headers = new Headers(res.headers);
|
|
999
|
+
headers.set("content-type", "application/json");
|
|
1000
|
+
return new Response(JSON.stringify(assembled), { status: res.status, statusText: res.statusText, headers });
|
|
1001
|
+
}
|
|
1002
|
+
const doneIndex = text.indexOf("data: [DONE]");
|
|
1003
|
+
if (doneIndex === -1) return res;
|
|
1004
|
+
return new Response(text.slice(0, doneIndex).trim(), { status: res.status, statusText: res.statusText, headers: res.headers });
|
|
1005
|
+
};
|
|
1006
|
+
}
|
|
961
1007
|
function getAIModel(options = {}) {
|
|
962
1008
|
const designated = getDesignatedFallbackConfig();
|
|
963
1009
|
const defaultProvider = process.env.DEFAULT_AI_PROVIDER || process.env.LLM_PROVIDER || detectDefaultProvider();
|
|
@@ -976,7 +1022,8 @@ function getAIModel(options = {}) {
|
|
|
976
1022
|
const rawUrl = options.baseURL || resolveApiKey("NINEROUTER_BASE_URL") || resolveApiKey("NINE_ROUTER_BASE_URL") || "https://ai-router.orchable.app/v1";
|
|
977
1023
|
const ninerouter = openai.createOpenAI({
|
|
978
1024
|
apiKey,
|
|
979
|
-
baseURL: rawUrl.replace(/^["']|["']$/g, "").trim()
|
|
1025
|
+
baseURL: rawUrl.replace(/^["']|["']$/g, "").trim(),
|
|
1026
|
+
fetch: cleanNonStreamingFetch()
|
|
980
1027
|
});
|
|
981
1028
|
return ninerouter.chat(resolvedModelName || "fast-reasoning");
|
|
982
1029
|
}
|