@serii84/vertex-partner-provider 1.0.10 → 1.0.13

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 +28 -33
  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.10 - Skip reasoning_content, only pass actual content
3
+ * v1.0.13 - Proper SSE format
4
4
  */
5
5
 
6
6
  const { createOpenAICompatible } = require('@ai-sdk/openai-compatible');
@@ -38,14 +38,18 @@ function transformStream(response) {
38
38
  }
39
39
 
40
40
  buffer += decoder.decode(value, { stream: true });
41
- const lines = buffer.split('\n');
42
- buffer = lines.pop() || '';
43
41
 
44
- for (const line of lines) {
45
- if (!line.trim()) continue;
42
+ // Process complete SSE messages (separated by double newline)
43
+ let boundary;
44
+ while ((boundary = buffer.indexOf('\n\n')) !== -1) {
45
+ const message = buffer.slice(0, boundary);
46
+ buffer = buffer.slice(boundary + 2);
46
47
 
47
- if (line.startsWith('data: ')) {
48
- const data = line.slice(6).trim();
48
+ if (!message.trim()) continue;
49
+
50
+ // Handle data lines
51
+ if (message.startsWith('data: ')) {
52
+ const data = message.slice(6);
49
53
 
50
54
  if (data === '[DONE]') {
51
55
  controller.enqueue(encoder.encode('data: [DONE]\n\n'));
@@ -55,46 +59,37 @@ function transformStream(response) {
55
59
  try {
56
60
  const parsed = JSON.parse(data);
57
61
 
58
- // Skip empty choices
59
- if (!parsed.choices || parsed.choices.length === 0) {
62
+ // Skip chunks with empty choices
63
+ if (parsed.choices && parsed.choices.length === 0) {
60
64
  continue;
61
65
  }
62
66
 
63
- let hasContent = false;
64
-
65
- for (const choice of parsed.choices) {
66
- if (choice.delta) {
67
- // Only keep chunks that have actual content (not reasoning)
68
- if (choice.delta.content && choice.delta.content !== null) {
69
- hasContent = true;
70
- }
71
- // Remove reasoning_content entirely
72
- delete choice.delta.reasoning_content;
73
-
74
- // If only reasoning was present, set empty content
75
- if (!choice.delta.content) {
76
- choice.delta.content = '';
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;
77
76
  }
78
77
  }
79
-
80
- // Pass through finish_reason chunks
81
- if (choice.finish_reason) {
82
- hasContent = true;
83
- }
84
78
  }
85
79
 
86
- // Only emit if there's actual content or it's a finish chunk
87
- if (hasContent || parsed.choices.some(c => c.finish_reason)) {
88
- controller.enqueue(encoder.encode('data: ' + JSON.stringify(parsed) + '\n\n'));
89
- }
80
+ controller.enqueue(encoder.encode('data: ' + JSON.stringify(parsed) + '\n\n'));
90
81
  } catch (e) {
91
- controller.enqueue(encoder.encode(line + '\n'));
82
+ // Skip invalid JSON
92
83
  }
93
84
  }
94
85
  }
95
86
  } catch (err) {
96
87
  controller.error(err);
97
88
  }
89
+ },
90
+
91
+ cancel() {
92
+ reader.cancel();
98
93
  }
99
94
  });
100
95
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serii84/vertex-partner-provider",
3
- "version": "1.0.10",
3
+ "version": "1.0.13",
4
4
  "description": "Vertex AI partner models (GLM, Kimi, DeepSeek) for OpenCode",
5
5
  "main": "index.js",
6
6
  "scripts": {