@serii84/vertex-partner-provider 1.0.20 → 1.0.22

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.
Files changed (2) hide show
  1. package/index.js +34 -8
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  /**
2
2
  * Vertex Partner Provider for OpenCode
3
- * v1.0.20 - Normalize finish_reason to string (some models return object)
3
+ * v1.0.22 - Fix: remove null values from delta, remove empty usage
4
4
  */
5
5
 
6
+ const DEBUG = process.env.VERTEX_DEBUG === 'true';
7
+
6
8
  const { createOpenAICompatible } = require('@ai-sdk/openai-compatible');
7
9
  const { GoogleAuth } = require('google-auth-library');
8
10
 
@@ -28,18 +30,25 @@ function cleanResponse(parsed) {
28
30
 
29
31
  // Normalize finish_reason to a string (some models return an object)
30
32
  if (choice.finish_reason && typeof choice.finish_reason === 'object') {
31
- // Extract string value from object, common patterns: {type: "stop"}, {reason: "stop"}
32
33
  choice.finish_reason = choice.finish_reason.type
33
34
  || choice.finish_reason.reason
34
35
  || choice.finish_reason.stop_reason
35
36
  || 'stop';
36
37
  }
37
38
 
39
+ // Clean up delta - remove null values and non-standard fields
38
40
  if (choice.delta) {
39
41
  if (!choice.delta.content && choice.delta.reasoning_content) {
40
42
  choice.delta.content = choice.delta.reasoning_content;
41
43
  }
42
44
  delete choice.delta.reasoning_content;
45
+
46
+ // Remove null values from delta - OpenAI format uses empty object, not nulls
47
+ for (const key of Object.keys(choice.delta)) {
48
+ if (choice.delta[key] === null) {
49
+ delete choice.delta[key];
50
+ }
51
+ }
43
52
  }
44
53
 
45
54
  if (choice.message) {
@@ -50,14 +59,19 @@ function cleanResponse(parsed) {
50
59
  }
51
60
  }
52
61
  }
53
-
62
+
63
+ // Clean usage - only keep standard fields, remove if empty/invalid
54
64
  if (parsed.usage) {
55
65
  const { prompt_tokens, completion_tokens, total_tokens } = parsed.usage;
56
- parsed.usage = { prompt_tokens, completion_tokens, total_tokens };
66
+ if (prompt_tokens != null || completion_tokens != null || total_tokens != null) {
67
+ parsed.usage = { prompt_tokens, completion_tokens, total_tokens };
68
+ } else {
69
+ delete parsed.usage;
70
+ }
57
71
  }
58
-
72
+
59
73
  delete parsed.metadata;
60
-
74
+
61
75
  return parsed;
62
76
  }
63
77
 
@@ -97,15 +111,27 @@ function transformStream(response) {
97
111
 
98
112
  try {
99
113
  const parsed = JSON.parse(data);
100
-
114
+
115
+ if (DEBUG) {
116
+ console.log('[VERTEX DEBUG] Raw chunk:', JSON.stringify(parsed, null, 2));
117
+ }
118
+
101
119
  // Skip empty choices (usage-only chunk)
102
120
  if (parsed.choices && parsed.choices.length === 0) {
103
121
  continue;
104
122
  }
105
-
123
+
106
124
  const cleaned = cleanResponse(parsed);
125
+
126
+ if (DEBUG) {
127
+ console.log('[VERTEX DEBUG] Cleaned chunk:', JSON.stringify(cleaned, null, 2));
128
+ }
129
+
107
130
  controller.enqueue(encoder.encode('data: ' + JSON.stringify(cleaned) + '\n\n'));
108
131
  } catch (e) {
132
+ if (DEBUG) {
133
+ console.log('[VERTEX DEBUG] JSON parse error:', e.message, 'Data:', data);
134
+ }
109
135
  // Skip invalid JSON
110
136
  }
111
137
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serii84/vertex-partner-provider",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
4
4
  "description": "Vertex AI partner models (GLM, Kimi, DeepSeek) for OpenCode",
5
5
  "main": "index.js",
6
6
  "scripts": {