@serii84/vertex-partner-provider 1.0.13 → 1.0.17

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 +31 -18
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Vertex Partner Provider for OpenCode
3
- * v1.0.13 - Proper SSE format
3
+ * v1.0.17 - Skip usage-only chunk at end (empty choices)
4
4
  */
5
5
 
6
6
  const { createOpenAICompatible } = require('@ai-sdk/openai-compatible');
@@ -20,6 +20,32 @@ async function getAuthToken(googleAuthOptions) {
20
20
  return token.token;
21
21
  }
22
22
 
23
+ function cleanChunk(parsed) {
24
+ if (parsed.choices) {
25
+ for (const choice of parsed.choices) {
26
+ delete choice.matched_stop;
27
+ delete choice.logprobs;
28
+
29
+ if (choice.delta) {
30
+ if (!choice.delta.content && choice.delta.reasoning_content) {
31
+ choice.delta.content = choice.delta.reasoning_content;
32
+ }
33
+ delete choice.delta.reasoning_content;
34
+ }
35
+ }
36
+ }
37
+
38
+ if (parsed.usage) {
39
+ // Keep only standard fields
40
+ const { prompt_tokens, completion_tokens, total_tokens } = parsed.usage;
41
+ parsed.usage = { prompt_tokens, completion_tokens, total_tokens };
42
+ }
43
+
44
+ delete parsed.metadata;
45
+
46
+ return parsed;
47
+ }
48
+
23
49
  function transformStream(response) {
24
50
  const reader = response.body.getReader();
25
51
  const decoder = new TextDecoder();
@@ -39,7 +65,6 @@ function transformStream(response) {
39
65
 
40
66
  buffer += decoder.decode(value, { stream: true });
41
67
 
42
- // Process complete SSE messages (separated by double newline)
43
68
  let boundary;
44
69
  while ((boundary = buffer.indexOf('\n\n')) !== -1) {
45
70
  const message = buffer.slice(0, boundary);
@@ -47,7 +72,6 @@ function transformStream(response) {
47
72
 
48
73
  if (!message.trim()) continue;
49
74
 
50
- // Handle data lines
51
75
  if (message.startsWith('data: ')) {
52
76
  const data = message.slice(6);
53
77
 
@@ -59,25 +83,14 @@ function transformStream(response) {
59
83
  try {
60
84
  const parsed = JSON.parse(data);
61
85
 
62
- // Skip chunks with empty choices
86
+ // Skip the usage-only chunk (empty choices array)
87
+ // This chunk causes issues with some parsers
63
88
  if (parsed.choices && parsed.choices.length === 0) {
64
89
  continue;
65
90
  }
66
91
 
67
- // Transform choices
68
- if (parsed.choices) {
69
- for (const choice of parsed.choices) {
70
- if (choice.delta) {
71
- // Convert reasoning_content to content
72
- if (!choice.delta.content && choice.delta.reasoning_content) {
73
- choice.delta.content = choice.delta.reasoning_content;
74
- }
75
- delete choice.delta.reasoning_content;
76
- }
77
- }
78
- }
79
-
80
- controller.enqueue(encoder.encode('data: ' + JSON.stringify(parsed) + '\n\n'));
92
+ const cleaned = cleanChunk(parsed);
93
+ controller.enqueue(encoder.encode('data: ' + JSON.stringify(cleaned) + '\n\n'));
81
94
  } catch (e) {
82
95
  // Skip invalid JSON
83
96
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serii84/vertex-partner-provider",
3
- "version": "1.0.13",
3
+ "version": "1.0.17",
4
4
  "description": "Vertex AI partner models (GLM, Kimi, DeepSeek) for OpenCode",
5
5
  "main": "index.js",
6
6
  "scripts": {