@victor-software-house/pi-openai-proxy 4.9.1 → 4.9.2
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/index.mjs +6 -3
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -324,6 +324,8 @@ const toolArgsSchema = z.record(z.string().trim(), z.unknown());
|
|
|
324
324
|
function convertMessages(messages) {
|
|
325
325
|
const systemParts = [];
|
|
326
326
|
const piMessages = [];
|
|
327
|
+
const toolCallNames = /* @__PURE__ */ new Map();
|
|
328
|
+
for (const msg of messages) if (msg !== void 0 && msg.role === "assistant" && "tool_calls" in msg) for (const tc of msg.tool_calls ?? []) toolCallNames.set(tc.id, tc.function.name);
|
|
327
329
|
for (let i = 0; i < messages.length; i++) {
|
|
328
330
|
const msg = messages[i];
|
|
329
331
|
if (msg === void 0) continue;
|
|
@@ -337,7 +339,8 @@ function convertMessages(messages) {
|
|
|
337
339
|
const assistantMsg = convertAssistantMessage(msg.content ?? null, msg.tool_calls);
|
|
338
340
|
piMessages.push(assistantMsg);
|
|
339
341
|
} else if (msg.role === "tool") {
|
|
340
|
-
const
|
|
342
|
+
const toolName = toolCallNames.get(msg.tool_call_id) ?? "";
|
|
343
|
+
const toolMsg = convertToolMessage(msg.content, msg.tool_call_id, toolName);
|
|
341
344
|
piMessages.push(toolMsg);
|
|
342
345
|
}
|
|
343
346
|
}
|
|
@@ -442,11 +445,11 @@ function convertAssistantMessage(textContent, toolCalls) {
|
|
|
442
445
|
timestamp: Date.now()
|
|
443
446
|
};
|
|
444
447
|
}
|
|
445
|
-
function convertToolMessage(content, toolCallId) {
|
|
448
|
+
function convertToolMessage(content, toolCallId, toolName) {
|
|
446
449
|
return {
|
|
447
450
|
role: "toolResult",
|
|
448
451
|
toolCallId,
|
|
449
|
-
toolName
|
|
452
|
+
toolName,
|
|
450
453
|
content: [{
|
|
451
454
|
type: "text",
|
|
452
455
|
text: content
|
package/package.json
CHANGED