@serii84/vertex-partner-provider 1.0.11 → 1.0.15
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 +3 -95
- 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.15 - No transform, pass through raw (debug)
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
const { createOpenAICompatible } = require('@ai-sdk/openai-compatible');
|
|
@@ -20,85 +20,6 @@ async function getAuthToken(googleAuthOptions) {
|
|
|
20
20
|
return token.token;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
function transformStream(response) {
|
|
24
|
-
const reader = response.body.getReader();
|
|
25
|
-
const decoder = new TextDecoder();
|
|
26
|
-
const encoder = new TextEncoder();
|
|
27
|
-
|
|
28
|
-
let buffer = '';
|
|
29
|
-
|
|
30
|
-
const transformedStream = new ReadableStream({
|
|
31
|
-
async pull(controller) {
|
|
32
|
-
try {
|
|
33
|
-
const { done, value } = await reader.read();
|
|
34
|
-
|
|
35
|
-
if (done) {
|
|
36
|
-
controller.close();
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
buffer += decoder.decode(value, { stream: true });
|
|
41
|
-
const lines = buffer.split('\n');
|
|
42
|
-
buffer = lines.pop() || '';
|
|
43
|
-
|
|
44
|
-
for (const line of lines) {
|
|
45
|
-
if (!line.trim()) {
|
|
46
|
-
controller.enqueue(encoder.encode('\n'));
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (line.startsWith('data: ')) {
|
|
51
|
-
const data = line.slice(6).trim();
|
|
52
|
-
|
|
53
|
-
if (data === '[DONE]') {
|
|
54
|
-
controller.enqueue(encoder.encode('data: [DONE]\n\n'));
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
try {
|
|
59
|
-
const parsed = JSON.parse(data);
|
|
60
|
-
|
|
61
|
-
// Skip empty choices array (usage chunk at end)
|
|
62
|
-
if (parsed.choices && parsed.choices.length === 0) {
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
|
|
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;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
controller.enqueue(encoder.encode('data: ' + JSON.stringify(parsed) + '\n\n'));
|
|
81
|
-
} catch (e) {
|
|
82
|
-
// Pass through unparseable lines
|
|
83
|
-
controller.enqueue(encoder.encode(line + '\n'));
|
|
84
|
-
}
|
|
85
|
-
} else {
|
|
86
|
-
controller.enqueue(encoder.encode(line + '\n'));
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
} catch (err) {
|
|
90
|
-
controller.error(err);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
return new Response(transformedStream, {
|
|
96
|
-
headers: response.headers,
|
|
97
|
-
status: response.status,
|
|
98
|
-
statusText: response.statusText,
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
23
|
function createVertexPartner(options = {}) {
|
|
103
24
|
const {
|
|
104
25
|
project = process.env.GOOGLE_VERTEX_PROJECT,
|
|
@@ -121,21 +42,8 @@ function createVertexPartner(options = {}) {
|
|
|
121
42
|
const headers = new Headers(init?.headers);
|
|
122
43
|
headers.set('Authorization', `Bearer ${token}`);
|
|
123
44
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
try {
|
|
127
|
-
const body = JSON.parse(init.body);
|
|
128
|
-
isStreaming = body.stream === true;
|
|
129
|
-
} catch (e) {}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const response = await fetch(url, { ...init, headers });
|
|
133
|
-
|
|
134
|
-
if (isStreaming && response.ok) {
|
|
135
|
-
return transformStream(response);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return response;
|
|
45
|
+
// Just pass through - no transform
|
|
46
|
+
return fetch(url, { ...init, headers });
|
|
139
47
|
};
|
|
140
48
|
|
|
141
49
|
const provider = createOpenAICompatible({
|