@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/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
|
}
|