@serii84/vertex-partner-provider 1.0.11 → 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 +18 -17
  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.11 - Convert reasoning_content to content, emit all chunks
3
+ * v1.0.13 - Proper SSE format
4
4
  */
5
5
 
6
6
  const { createOpenAICompatible } = require('@ai-sdk/openai-compatible');
@@ -38,17 +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()) {
46
- controller.enqueue(encoder.encode('\n'));
47
- continue;
48
- }
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);
47
+
48
+ if (!message.trim()) continue;
49
49
 
50
- if (line.startsWith('data: ')) {
51
- const data = line.slice(6).trim();
50
+ // Handle data lines
51
+ if (message.startsWith('data: ')) {
52
+ const data = message.slice(6);
52
53
 
53
54
  if (data === '[DONE]') {
54
55
  controller.enqueue(encoder.encode('data: [DONE]\n\n'));
@@ -58,7 +59,7 @@ function transformStream(response) {
58
59
  try {
59
60
  const parsed = JSON.parse(data);
60
61
 
61
- // Skip empty choices array (usage chunk at end)
62
+ // Skip chunks with empty choices
62
63
  if (parsed.choices && parsed.choices.length === 0) {
63
64
  continue;
64
65
  }
@@ -67,11 +68,10 @@ function transformStream(response) {
67
68
  if (parsed.choices) {
68
69
  for (const choice of parsed.choices) {
69
70
  if (choice.delta) {
70
- // If content is null/empty but reasoning_content exists, use it
71
+ // Convert reasoning_content to content
71
72
  if (!choice.delta.content && choice.delta.reasoning_content) {
72
73
  choice.delta.content = choice.delta.reasoning_content;
73
74
  }
74
- // Remove the non-standard field
75
75
  delete choice.delta.reasoning_content;
76
76
  }
77
77
  }
@@ -79,16 +79,17 @@ function transformStream(response) {
79
79
 
80
80
  controller.enqueue(encoder.encode('data: ' + JSON.stringify(parsed) + '\n\n'));
81
81
  } catch (e) {
82
- // Pass through unparseable lines
83
- controller.enqueue(encoder.encode(line + '\n'));
82
+ // Skip invalid JSON
84
83
  }
85
- } else {
86
- controller.enqueue(encoder.encode(line + '\n'));
87
84
  }
88
85
  }
89
86
  } catch (err) {
90
87
  controller.error(err);
91
88
  }
89
+ },
90
+
91
+ cancel() {
92
+ reader.cancel();
92
93
  }
93
94
  });
94
95
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serii84/vertex-partner-provider",
3
- "version": "1.0.11",
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": {