mycomesh-consumer 0.1.46 → 0.1.47
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/package.json +1 -1
- package/src/consumer-runtime.mjs +10 -1
- package/src/consumer.mjs +1 -1
package/package.json
CHANGED
package/src/consumer-runtime.mjs
CHANGED
|
@@ -1403,7 +1403,16 @@ export function responseSse(payload, compact = false) {
|
|
|
1403
1403
|
export function chatCompletionSse(payload, includeUsage = false) {
|
|
1404
1404
|
const id = String(payload?.id || `chatcmpl_${bytesToHex(randomBytes(16))}`); const model = String(payload?.model || ""); const created = Number(payload?.created || Math.floor(Date.now() / 1000)); const chunks = [];
|
|
1405
1405
|
const chunk = (index, delta, finishReason = null) => chunks.push(`data: ${JSON.stringify({ id, object: "chat.completion.chunk", created, model, choices: [{ index, delta, finish_reason: finishReason }] })}\n\n`);
|
|
1406
|
-
(Array.isArray(payload?.choices) ? payload.choices : []).forEach((choice, fallbackIndex) => {
|
|
1406
|
+
(Array.isArray(payload?.choices) ? payload.choices : []).forEach((choice, fallbackIndex) => {
|
|
1407
|
+
const index = Number.isInteger(choice.index) ? choice.index : fallbackIndex;
|
|
1408
|
+
const message = choice.message || {};
|
|
1409
|
+
chunk(index, { role: String(message.role || "assistant") });
|
|
1410
|
+
if (message.content) chunk(index, { content: String(message.content) });
|
|
1411
|
+
(Array.isArray(message.tool_calls) ? message.tool_calls : []).forEach((call, toolIndex) => {
|
|
1412
|
+
chunk(index, { tool_calls: [{ index: toolIndex, id: call.id, type: call.type || "function", function: { name: call.function?.name, arguments: String(call.function?.arguments || "") } }] });
|
|
1413
|
+
});
|
|
1414
|
+
chunk(index, {}, choice.finish_reason || "stop");
|
|
1415
|
+
});
|
|
1407
1416
|
if (includeUsage && payload?.usage) chunks.push(`data: ${JSON.stringify({ id, object: "chat.completion.chunk", created, model, choices: [], usage: payload.usage })}\n\n`);
|
|
1408
1417
|
chunks.push("data: [DONE]\n\n"); return chunks;
|
|
1409
1418
|
}
|
package/src/consumer.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
createConsumerServer,
|
|
12
12
|
} from "./consumer-runtime.mjs";
|
|
13
13
|
|
|
14
|
-
export const CONSUMER_RELEASE_VERSION = "0.1.
|
|
14
|
+
export const CONSUMER_RELEASE_VERSION = "0.1.47";
|
|
15
15
|
export const API_COMMANDS = new Set(["health", "models", "responses", "chat"]);
|
|
16
16
|
const API_VALUE_OPTIONS = new Set([
|
|
17
17
|
"--base-url",
|