@serii84/vertex-partner-provider 1.0.23 → 1.0.25
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 +19 -12
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Vertex Partner Provider for OpenCode
|
|
3
|
-
* v1.0.
|
|
3
|
+
* v1.0.25 - Skip all empty choices chunks (including usage-only)
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
|
|
6
9
|
const DEBUG = process.env.VERTEX_DEBUG === 'true';
|
|
10
|
+
const DEBUG_FILE = process.env.VERTEX_DEBUG_FILE || '/tmp/vertex-debug.log';
|
|
11
|
+
|
|
12
|
+
function debugLog(...args) {
|
|
13
|
+
if (!DEBUG) return;
|
|
14
|
+
const timestamp = new Date().toISOString();
|
|
15
|
+
const message = args.map(a => typeof a === 'string' ? a : JSON.stringify(a, null, 2)).join(' ');
|
|
16
|
+
fs.appendFileSync(DEBUG_FILE, `[${timestamp}] ${message}\n`);
|
|
17
|
+
}
|
|
7
18
|
|
|
8
19
|
const { createOpenAICompatible } = require('@ai-sdk/openai-compatible');
|
|
9
20
|
const { GoogleAuth } = require('google-auth-library');
|
|
@@ -119,26 +130,22 @@ function transformStream(response) {
|
|
|
119
130
|
try {
|
|
120
131
|
const parsed = JSON.parse(data);
|
|
121
132
|
|
|
122
|
-
|
|
123
|
-
console.log('[VERTEX DEBUG] Raw chunk:', JSON.stringify(parsed, null, 2));
|
|
124
|
-
}
|
|
133
|
+
debugLog('Raw chunk:', parsed);
|
|
125
134
|
|
|
126
135
|
const cleaned = cleanResponse(parsed);
|
|
127
136
|
|
|
128
|
-
// Skip chunks
|
|
129
|
-
|
|
137
|
+
// Skip chunks with empty choices (including usage-only chunks)
|
|
138
|
+
// The AI SDK may not handle empty choices arrays correctly
|
|
139
|
+
if (!cleaned.choices || cleaned.choices.length === 0) {
|
|
140
|
+
debugLog('Skipping chunk with empty choices');
|
|
130
141
|
continue;
|
|
131
142
|
}
|
|
132
143
|
|
|
133
|
-
|
|
134
|
-
console.log('[VERTEX DEBUG] Cleaned chunk:', JSON.stringify(cleaned, null, 2));
|
|
135
|
-
}
|
|
144
|
+
debugLog('Cleaned chunk:', cleaned);
|
|
136
145
|
|
|
137
146
|
controller.enqueue(encoder.encode('data: ' + JSON.stringify(cleaned) + '\n\n'));
|
|
138
147
|
} catch (e) {
|
|
139
|
-
|
|
140
|
-
console.log('[VERTEX DEBUG] JSON parse error:', e.message, 'Data:', data);
|
|
141
|
-
}
|
|
148
|
+
debugLog('JSON parse error:', e.message, 'Data:', data);
|
|
142
149
|
// Skip invalid JSON
|
|
143
150
|
}
|
|
144
151
|
}
|