@serii84/vertex-partner-provider 1.0.10 → 1.0.11
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 +21 -27
- 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.
|
|
3
|
+
* v1.0.11 - Convert reasoning_content to content, emit all chunks
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
const { createOpenAICompatible } = require('@ai-sdk/openai-compatible');
|
|
@@ -42,7 +42,10 @@ function transformStream(response) {
|
|
|
42
42
|
buffer = lines.pop() || '';
|
|
43
43
|
|
|
44
44
|
for (const line of lines) {
|
|
45
|
-
if (!line.trim())
|
|
45
|
+
if (!line.trim()) {
|
|
46
|
+
controller.enqueue(encoder.encode('\n'));
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
46
49
|
|
|
47
50
|
if (line.startsWith('data: ')) {
|
|
48
51
|
const data = line.slice(6).trim();
|
|
@@ -55,41 +58,32 @@ function transformStream(response) {
|
|
|
55
58
|
try {
|
|
56
59
|
const parsed = JSON.parse(data);
|
|
57
60
|
|
|
58
|
-
// Skip empty choices
|
|
59
|
-
if (
|
|
61
|
+
// Skip empty choices array (usage chunk at end)
|
|
62
|
+
if (parsed.choices && parsed.choices.length === 0) {
|
|
60
63
|
continue;
|
|
61
64
|
}
|
|
62
65
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
// If only reasoning was present, set empty content
|
|
75
|
-
if (!choice.delta.content) {
|
|
76
|
-
choice.delta.content = '';
|
|
66
|
+
// Transform choices
|
|
67
|
+
if (parsed.choices) {
|
|
68
|
+
for (const choice of parsed.choices) {
|
|
69
|
+
if (choice.delta) {
|
|
70
|
+
// If content is null/empty but reasoning_content exists, use it
|
|
71
|
+
if (!choice.delta.content && choice.delta.reasoning_content) {
|
|
72
|
+
choice.delta.content = choice.delta.reasoning_content;
|
|
73
|
+
}
|
|
74
|
+
// Remove the non-standard field
|
|
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
|
-
|
|
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) {
|
|
82
|
+
// Pass through unparseable lines
|
|
91
83
|
controller.enqueue(encoder.encode(line + '\n'));
|
|
92
84
|
}
|
|
85
|
+
} else {
|
|
86
|
+
controller.enqueue(encoder.encode(line + '\n'));
|
|
93
87
|
}
|
|
94
88
|
}
|
|
95
89
|
} catch (err) {
|