@serii84/vertex-partner-provider 1.0.27 → 1.0.30
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/index.js +28 -9
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Vertex Partner Provider for OpenCode
|
|
3
|
-
* v1.0.
|
|
3
|
+
* v1.0.30 - Use @ai-sdk/openai instead of openai-compatible
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
const fs = require('fs');
|
|
@@ -16,7 +16,7 @@ function debugLog(...args) {
|
|
|
16
16
|
fs.appendFileSync(DEBUG_FILE, `[${timestamp}] ${message}\n`);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
const {
|
|
19
|
+
const { createOpenAI } = require('@ai-sdk/openai');
|
|
20
20
|
const { GoogleAuth } = require('google-auth-library');
|
|
21
21
|
|
|
22
22
|
let authClient = null;
|
|
@@ -61,7 +61,7 @@ function cleanResponse(parsed) {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
// Clean up delta - remove null values and non-standard fields
|
|
64
|
-
//
|
|
64
|
+
// Don't include delta on finish chunks at all
|
|
65
65
|
if (choice.delta && !choice.finish_reason) {
|
|
66
66
|
const cleanDelta = {};
|
|
67
67
|
if (choice.delta.role) cleanDelta.role = choice.delta.role;
|
|
@@ -69,10 +69,8 @@ function cleanResponse(parsed) {
|
|
|
69
69
|
else if (choice.delta.reasoning_content) cleanDelta.content = choice.delta.reasoning_content;
|
|
70
70
|
if (choice.delta.tool_calls) cleanDelta.tool_calls = choice.delta.tool_calls;
|
|
71
71
|
cleanChoice.delta = cleanDelta;
|
|
72
|
-
} else if (choice.delta) {
|
|
73
|
-
// On finish chunks, include empty delta for compatibility
|
|
74
|
-
cleanChoice.delta = {};
|
|
75
72
|
}
|
|
73
|
+
// Note: intentionally NOT including delta on finish chunks
|
|
76
74
|
|
|
77
75
|
if (choice.message) {
|
|
78
76
|
const cleanMessage = { role: choice.message.role };
|
|
@@ -113,6 +111,26 @@ function transformStream(response) {
|
|
|
113
111
|
const { done, value } = await reader.read();
|
|
114
112
|
|
|
115
113
|
if (done) {
|
|
114
|
+
// Process any remaining data in buffer
|
|
115
|
+
if (buffer.trim()) {
|
|
116
|
+
debugLog('Processing remaining buffer:', buffer);
|
|
117
|
+
if (buffer.startsWith('data: ')) {
|
|
118
|
+
const data = buffer.slice(6).trim();
|
|
119
|
+
if (data === '[DONE]') {
|
|
120
|
+
controller.enqueue(encoder.encode('data: [DONE]\n\n'));
|
|
121
|
+
} else if (data) {
|
|
122
|
+
try {
|
|
123
|
+
const parsed = JSON.parse(data);
|
|
124
|
+
const cleaned = cleanResponse(parsed);
|
|
125
|
+
if (cleaned.choices && cleaned.choices.length > 0) {
|
|
126
|
+
controller.enqueue(encoder.encode('data: ' + JSON.stringify(cleaned) + '\n\n'));
|
|
127
|
+
}
|
|
128
|
+
} catch (e) {
|
|
129
|
+
debugLog('Final buffer parse error:', e.message);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
116
134
|
controller.close();
|
|
117
135
|
return;
|
|
118
136
|
}
|
|
@@ -130,8 +148,8 @@ function transformStream(response) {
|
|
|
130
148
|
const data = message.slice(6);
|
|
131
149
|
|
|
132
150
|
if (data === '[DONE]') {
|
|
133
|
-
debugLog('
|
|
134
|
-
|
|
151
|
+
debugLog('Forwarding [DONE]');
|
|
152
|
+
controller.enqueue(encoder.encode('data: [DONE]\n\n'));
|
|
135
153
|
continue;
|
|
136
154
|
}
|
|
137
155
|
|
|
@@ -259,10 +277,11 @@ function createVertexPartner(options = {}) {
|
|
|
259
277
|
}
|
|
260
278
|
};
|
|
261
279
|
|
|
262
|
-
const provider =
|
|
280
|
+
const provider = createOpenAI({
|
|
263
281
|
name: `vertex-${publisher}`,
|
|
264
282
|
baseURL,
|
|
265
283
|
fetch: authFetch,
|
|
284
|
+
compatibility: 'compatible', // Use compatible mode for non-OpenAI endpoints
|
|
266
285
|
});
|
|
267
286
|
|
|
268
287
|
const wrappedProvider = (modelId) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serii84/vertex-partner-provider",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.30",
|
|
4
4
|
"description": "Vertex AI partner models (GLM, Kimi, DeepSeek) for OpenCode",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"author": "",
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@ai-sdk/openai
|
|
13
|
+
"@ai-sdk/openai": "^1.3.22",
|
|
14
14
|
"google-auth-library": "^10.5.0"
|
|
15
15
|
}
|
|
16
16
|
}
|