@serii84/vertex-partner-provider 1.0.3 → 1.0.7

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 (3) hide show
  1. package/index.js +16 -26
  2. package/package.json +1 -1
  3. package/test.js +0 -78
package/index.js CHANGED
@@ -1,16 +1,9 @@
1
1
  /**
2
2
  * Vertex Partner Provider for OpenCode
3
+ * Forces non-streaming to avoid parsing issues
3
4
  */
4
5
 
5
- let createOpenAICompatible;
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,35 @@ 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
- return fetch(url, { ...init, headers });
44
+
45
+ // Force non-streaming by modifying the request body
46
+ let modifiedInit = { ...init, headers };
47
+ if (init?.body) {
48
+ try {
49
+ const body = JSON.parse(init.body);
50
+ body.stream = false; // Force non-streaming
51
+ modifiedInit.body = JSON.stringify(body);
52
+ } catch (e) {
53
+ // If body isn't JSON, leave it as is
54
+ }
55
+ }
56
+
57
+ return fetch(url, modifiedInit);
61
58
  };
62
59
 
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
60
  const provider = createOpenAICompatible({
69
61
  name: `vertex-${publisher}`,
70
62
  baseURL,
71
63
  fetch: authFetch,
72
64
  });
73
- console.error('[vertex-partner] Provider created');
74
65
 
75
66
  const wrappedProvider = (modelId) => {
76
67
  const fullModelId = modelId.includes('/') ? modelId : `${publisher}/${modelId}`;
77
- console.error(`[vertex-partner] Creating model: ${fullModelId}`);
78
68
  return provider(fullModelId);
79
69
  };
80
70
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serii84/vertex-partner-provider",
3
- "version": "1.0.3",
3
+ "version": "1.0.7",
4
4
  "description": "Vertex AI partner models (GLM, Kimi, DeepSeek) for OpenCode",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/test.js DELETED
@@ -1,78 +0,0 @@
1
- /**
2
- * Test script for Vertex Partner Provider
3
- *
4
- * Run with: node test.js
5
- *
6
- * Requires: gcloud auth application-default login
7
- */
8
-
9
- const { createGLM, createDeepSeek, createKimi } = require('./index.js');
10
- const { generateText, tool } = require('ai');
11
- const { z } = require('zod');
12
-
13
- const PROJECT = process.env.GOOGLE_VERTEX_PROJECT || 'noter-1c2a1';
14
-
15
- async function testBasicChat() {
16
- console.log('\nšŸ“ Test 1: Basic Chat');
17
- console.log('-'.repeat(40));
18
-
19
- const glm = createGLM({ project: PROJECT, location: 'global' });
20
- const model = glm('glm-4.7-maas');
21
-
22
- console.log('Model ID:', model.modelId);
23
-
24
- const result = await generateText({
25
- model,
26
- prompt: 'Say "Hello from GLM!" and nothing else.',
27
- });
28
-
29
- console.log('āœ… Response:', result.text);
30
- return true;
31
- }
32
-
33
- async function testToolCalling() {
34
- console.log('\nšŸ”§ Test 2: Tool Calling');
35
- console.log('-'.repeat(40));
36
-
37
- const glm = createGLM({ project: PROJECT, location: 'global' });
38
-
39
- const result = await generateText({
40
- model: glm('glm-4.7-maas'),
41
- prompt: 'What is the weather in San Francisco? Use the weather tool.',
42
- tools: {
43
- weather: tool({
44
- description: 'Get the weather for a location',
45
- parameters: z.object({
46
- location: z.string().describe('The city name'),
47
- }),
48
- execute: async ({ location }) => {
49
- return { location, temperature: 72, condition: 'sunny' };
50
- },
51
- }),
52
- },
53
- maxSteps: 3,
54
- });
55
-
56
- console.log('āœ… Response:', result.text);
57
- console.log('Tool calls:', result.toolCalls?.length || 0);
58
- return true;
59
- }
60
-
61
- async function main() {
62
- console.log('='.repeat(50));
63
- console.log('Vertex Partner Provider Test Suite');
64
- console.log('='.repeat(50));
65
- console.log(`Project: ${PROJECT}`);
66
-
67
- try {
68
- await testBasicChat();
69
- await testToolCalling();
70
- console.log('\nāœ… All tests passed!');
71
- } catch (error) {
72
- console.error('\nāŒ Test failed:', error.message);
73
- if (error.cause) console.error('Cause:', JSON.stringify(error.cause, null, 2));
74
- process.exit(1);
75
- }
76
- }
77
-
78
- main();