@mmmbuto/zai-codex-bridge 0.1.3 → 0.1.5
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/server.js +30 -19
package/package.json
CHANGED
package/src/server.js
CHANGED
|
@@ -71,25 +71,34 @@ function translateResponsesToChat(request) {
|
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
//
|
|
75
|
-
if (request.input
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
74
|
+
// Handle input: can be string (simple user message) or array (message history)
|
|
75
|
+
if (request.input) {
|
|
76
|
+
if (typeof request.input === 'string') {
|
|
77
|
+
// Simple string input -> user message
|
|
78
|
+
messages.push({
|
|
79
|
+
role: 'user',
|
|
80
|
+
content: request.input
|
|
81
|
+
});
|
|
82
|
+
} else if (Array.isArray(request.input)) {
|
|
83
|
+
// Array of message objects
|
|
84
|
+
for (const item of request.input) {
|
|
85
|
+
const msg = {
|
|
86
|
+
role: item.role,
|
|
87
|
+
content: flattenContent(item.content)
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// Handle tool calls if present
|
|
91
|
+
if (item.tool_calls && Array.isArray(item.tool_calls)) {
|
|
92
|
+
msg.tool_calls = item.tool_calls;
|
|
93
|
+
}
|
|
86
94
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
95
|
+
// Handle tool call ID for tool responses
|
|
96
|
+
if (item.tool_call_id) {
|
|
97
|
+
msg.tool_call_id = item.tool_call_id;
|
|
98
|
+
}
|
|
91
99
|
|
|
92
|
-
|
|
100
|
+
messages.push(msg);
|
|
101
|
+
}
|
|
93
102
|
}
|
|
94
103
|
}
|
|
95
104
|
|
|
@@ -181,9 +190,11 @@ function translateChatToResponses(chatResponse) {
|
|
|
181
190
|
* Make upstream request to Z.AI
|
|
182
191
|
*/
|
|
183
192
|
async function makeUpstreamRequest(path, body, headers) {
|
|
184
|
-
//
|
|
193
|
+
// Ensure base URL ends with / for proper path concatenation
|
|
194
|
+
const baseUrl = ZAI_BASE_URL.endsWith('/') ? ZAI_BASE_URL : ZAI_BASE_URL + '/';
|
|
195
|
+
// Remove leading slash from path to avoid replacing base URL path
|
|
185
196
|
const cleanPath = path.startsWith('/') ? path.slice(1) : path;
|
|
186
|
-
const url = new URL(cleanPath,
|
|
197
|
+
const url = new URL(cleanPath, baseUrl);
|
|
187
198
|
|
|
188
199
|
const upstreamHeaders = {
|
|
189
200
|
'Content-Type': 'application/json',
|