@serii84/vertex-partner-provider 1.0.3 → 1.0.6
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 +2 -25
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Vertex Partner Provider for OpenCode
|
|
3
|
+
* No logging - clean output
|
|
3
4
|
*/
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
try {
|
|
7
|
-
const mod = require('@ai-sdk/openai-compatible');
|
|
8
|
-
createOpenAICompatible = mod.createOpenAICompatible;
|
|
9
|
-
console.error('[vertex-partner] Loaded @ai-sdk/openai-compatible, exports:', Object.keys(mod));
|
|
10
|
-
} catch (e) {
|
|
11
|
-
console.error('[vertex-partner] FAILED to load @ai-sdk/openai-compatible:', e.message);
|
|
12
|
-
}
|
|
13
|
-
|
|
6
|
+
const { createOpenAICompatible } = require('@ai-sdk/openai-compatible');
|
|
14
7
|
const { GoogleAuth } = require('google-auth-library');
|
|
15
8
|
|
|
16
9
|
let authClient = null;
|
|
@@ -22,26 +15,19 @@ async function getAuthToken(googleAuthOptions) {
|
|
|
22
15
|
...googleAuthOptions,
|
|
23
16
|
});
|
|
24
17
|
}
|
|
25
|
-
|
|
26
18
|
const client = await authClient.getClient();
|
|
27
19
|
const token = await client.getAccessToken();
|
|
28
20
|
return token.token;
|
|
29
21
|
}
|
|
30
22
|
|
|
31
23
|
function createVertexPartner(options = {}) {
|
|
32
|
-
console.error('[vertex-partner] createVertexPartner called');
|
|
33
|
-
console.error('[vertex-partner] createOpenAICompatible available:', typeof createOpenAICompatible);
|
|
34
|
-
|
|
35
24
|
const {
|
|
36
25
|
project = process.env.GOOGLE_VERTEX_PROJECT,
|
|
37
26
|
location = process.env.GOOGLE_VERTEX_LOCATION || 'global',
|
|
38
27
|
publisher,
|
|
39
28
|
googleAuthOptions,
|
|
40
|
-
...rest
|
|
41
29
|
} = options;
|
|
42
30
|
|
|
43
|
-
console.error('[vertex-partner] Config:', { project, location, publisher });
|
|
44
|
-
|
|
45
31
|
if (!project) throw new Error('project is required');
|
|
46
32
|
if (!publisher) throw new Error('publisher is required');
|
|
47
33
|
|
|
@@ -50,31 +36,22 @@ function createVertexPartner(options = {}) {
|
|
|
50
36
|
: `${location}-aiplatform.googleapis.com`;
|
|
51
37
|
|
|
52
38
|
const baseURL = `https://${baseHost}/v1/projects/${project}/locations/${location}/endpoints/openapi`;
|
|
53
|
-
console.error(`[vertex-partner] baseURL: ${baseURL}`);
|
|
54
39
|
|
|
55
40
|
const authFetch = async (url, init) => {
|
|
56
|
-
console.error(`[vertex-partner] authFetch called with: ${url}`);
|
|
57
41
|
const token = await getAuthToken(googleAuthOptions);
|
|
58
42
|
const headers = new Headers(init?.headers);
|
|
59
43
|
headers.set('Authorization', `Bearer ${token}`);
|
|
60
44
|
return fetch(url, { ...init, headers });
|
|
61
45
|
};
|
|
62
46
|
|
|
63
|
-
if (!createOpenAICompatible) {
|
|
64
|
-
throw new Error('@ai-sdk/openai-compatible not loaded!');
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
console.error('[vertex-partner] Creating provider with baseURL:', baseURL);
|
|
68
47
|
const provider = createOpenAICompatible({
|
|
69
48
|
name: `vertex-${publisher}`,
|
|
70
49
|
baseURL,
|
|
71
50
|
fetch: authFetch,
|
|
72
51
|
});
|
|
73
|
-
console.error('[vertex-partner] Provider created');
|
|
74
52
|
|
|
75
53
|
const wrappedProvider = (modelId) => {
|
|
76
54
|
const fullModelId = modelId.includes('/') ? modelId : `${publisher}/${modelId}`;
|
|
77
|
-
console.error(`[vertex-partner] Creating model: ${fullModelId}`);
|
|
78
55
|
return provider(fullModelId);
|
|
79
56
|
};
|
|
80
57
|
|