@core-ai/google-vertex 0.14.0
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/LICENSE +21 -0
- package/README.md +105 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +49 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Omnifact (https://omnifact.ai)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# @core-ai/google-vertex
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@core-ai/google-vertex)
|
|
4
|
+
|
|
5
|
+
Google on Vertex AI provider package for `@core-ai/core-ai`. It uses the [`@google/genai`](https://www.npmjs.com/package/@google/genai) client in Vertex AI mode and shares chat, embedding, image generation, structured-output, and reasoning behavior with `@core-ai/google-genai`.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @core-ai/core-ai @core-ai/google-vertex zod
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { generate } from '@core-ai/core-ai';
|
|
17
|
+
import { createGoogleVertex } from '@core-ai/google-vertex';
|
|
18
|
+
|
|
19
|
+
const googleVertex = createGoogleVertex({
|
|
20
|
+
projectId: process.env.GOOGLE_VERTEX_PROJECT,
|
|
21
|
+
region: 'europe-west1',
|
|
22
|
+
});
|
|
23
|
+
const model = googleVertex.chatModel('gemini-2.5-flash');
|
|
24
|
+
|
|
25
|
+
const result = await generate({
|
|
26
|
+
model,
|
|
27
|
+
messages: [{ role: 'user', content: 'Hello!' }],
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
console.log(result.content);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Authentication
|
|
34
|
+
|
|
35
|
+
By default, the provider uses [Google Application Default Credentials (ADC)](https://cloud.google.com/docs/authentication/application-default-credentials):
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
const googleVertex = createGoogleVertex({
|
|
39
|
+
projectId: process.env.GOOGLE_VERTEX_PROJECT,
|
|
40
|
+
region: 'europe-west1',
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
To authenticate with an explicit service account, parse its JSON key and pass it as `credentials`:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
const rawCredentials = process.env.GOOGLE_APPLICATION_CREDENTIALS_JSON;
|
|
48
|
+
const credentialsJson = rawCredentials?.trim().startsWith('{')
|
|
49
|
+
? rawCredentials
|
|
50
|
+
: Buffer.from(rawCredentials ?? '', 'base64').toString('utf8');
|
|
51
|
+
|
|
52
|
+
const googleVertex = createGoogleVertex({
|
|
53
|
+
projectId: process.env.GOOGLE_VERTEX_PROJECT,
|
|
54
|
+
region: 'europe-west1',
|
|
55
|
+
credentials: JSON.parse(credentialsJson),
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
You can also inject a preconfigured `GoogleGenAI` client:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { GoogleGenAI } from '@google/genai';
|
|
63
|
+
|
|
64
|
+
const googleVertex = createGoogleVertex({
|
|
65
|
+
client: new GoogleGenAI({
|
|
66
|
+
vertexai: true,
|
|
67
|
+
project: 'my-project',
|
|
68
|
+
location: 'europe-west1',
|
|
69
|
+
}),
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Models and regions
|
|
74
|
+
|
|
75
|
+
Pass Vertex AI model IDs to the corresponding model factory:
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
const chat = googleVertex.chatModel('gemini-2.5-flash');
|
|
79
|
+
const embeddings = googleVertex.embeddingModel('gemini-embedding-001');
|
|
80
|
+
const image = googleVertex.imageModel('gemini-2.5-flash-image');
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Model availability varies by region. A provider instance targets one region, so create separate providers when models are hosted in different locations.
|
|
84
|
+
|
|
85
|
+
## Image generation
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
import { generateImage } from '@core-ai/core-ai';
|
|
89
|
+
|
|
90
|
+
const result = await generateImage({
|
|
91
|
+
model: googleVertex.imageModel('gemini-2.5-flash-image'),
|
|
92
|
+
prompt: 'A watercolor robot in a mountain cabin at sunrise',
|
|
93
|
+
size: '1024x1024',
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
console.log(result.images[0]?.base64);
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Gemini image models use native multimodal generation. Imagen models such as
|
|
100
|
+
`imagen-4.0-generate-001` remain available through the same `imageModel()`
|
|
101
|
+
factory when the selected Vertex AI region and project support them.
|
|
102
|
+
|
|
103
|
+
## Provider options and capabilities
|
|
104
|
+
|
|
105
|
+
This provider shares its model behavior with `@core-ai/google-genai`. Provider options remain namespaced under `google`. `@core-ai/google-vertex` re-exports the applicable provider-option schemas, capability helpers, and reasoning metadata types.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { GoogleGenAIOptions } from '@google/genai';
|
|
2
|
+
import { GoogleGenAIProvider, GoogleGenAIClient } from '@core-ai/google-genai';
|
|
3
|
+
export { GoogleEmbedProviderOptions, GoogleGenAIClient, GoogleGenerateProviderOptions, GoogleImageProviderOptions, GoogleModelCapabilities, GoogleModelProviderOptions, GoogleReasoningMetadata, getGoogleModelCapabilities, googleEmbedProviderOptionsSchema, googleGenerateProviderOptionsSchema, googleImageProviderOptionsSchema, googleProviderOptionsSchema } from '@core-ai/google-genai';
|
|
4
|
+
|
|
5
|
+
type GoogleVertexServiceAccountCredentials = NonNullable<NonNullable<GoogleGenAIOptions['googleAuthOptions']>['credentials']>;
|
|
6
|
+
type GoogleVertexProviderOptions = {
|
|
7
|
+
projectId?: string;
|
|
8
|
+
region?: string;
|
|
9
|
+
credentials?: GoogleVertexServiceAccountCredentials;
|
|
10
|
+
client?: GoogleGenAIClient;
|
|
11
|
+
};
|
|
12
|
+
type GoogleVertexProvider = GoogleGenAIProvider;
|
|
13
|
+
declare function createGoogleVertex(options?: GoogleVertexProviderOptions): GoogleVertexProvider;
|
|
14
|
+
|
|
15
|
+
export { type GoogleVertexProvider, type GoogleVertexProviderOptions, type GoogleVertexServiceAccountCredentials, createGoogleVertex };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// src/provider.ts
|
|
2
|
+
import { GoogleGenAI } from "@google/genai";
|
|
3
|
+
import {
|
|
4
|
+
createGoogleGenAIProvider
|
|
5
|
+
} from "@core-ai/google-genai";
|
|
6
|
+
var PROVIDER_ID = "google-vertex";
|
|
7
|
+
function createGoogleVertex(options = {}) {
|
|
8
|
+
const client = options.client ?? createGoogleVertexClient(options);
|
|
9
|
+
return createGoogleGenAIProvider(
|
|
10
|
+
{ client },
|
|
11
|
+
{
|
|
12
|
+
providerId: PROVIDER_ID
|
|
13
|
+
}
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
function createGoogleVertexClient(options) {
|
|
17
|
+
if (!options.projectId) {
|
|
18
|
+
throw new Error("createGoogleVertex: projectId is required.");
|
|
19
|
+
}
|
|
20
|
+
if (!options.region) {
|
|
21
|
+
throw new Error("createGoogleVertex: region is required.");
|
|
22
|
+
}
|
|
23
|
+
const googleAuthOptions = options.credentials ? {
|
|
24
|
+
credentials: options.credentials
|
|
25
|
+
} : void 0;
|
|
26
|
+
return new GoogleGenAI({
|
|
27
|
+
vertexai: true,
|
|
28
|
+
project: options.projectId,
|
|
29
|
+
location: options.region,
|
|
30
|
+
...googleAuthOptions ? { googleAuthOptions } : {}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// src/index.ts
|
|
35
|
+
import {
|
|
36
|
+
getGoogleModelCapabilities,
|
|
37
|
+
googleEmbedProviderOptionsSchema,
|
|
38
|
+
googleGenerateProviderOptionsSchema,
|
|
39
|
+
googleImageProviderOptionsSchema,
|
|
40
|
+
googleProviderOptionsSchema
|
|
41
|
+
} from "@core-ai/google-genai";
|
|
42
|
+
export {
|
|
43
|
+
createGoogleVertex,
|
|
44
|
+
getGoogleModelCapabilities,
|
|
45
|
+
googleEmbedProviderOptionsSchema,
|
|
46
|
+
googleGenerateProviderOptionsSchema,
|
|
47
|
+
googleImageProviderOptionsSchema,
|
|
48
|
+
googleProviderOptionsSchema
|
|
49
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@core-ai/google-vertex",
|
|
3
|
+
"version": "0.14.0",
|
|
4
|
+
"description": "Vertex AI Google provider package for @core-ai/core-ai",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Omnifact (https://omnifact.ai)",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/agdevhq/core-ai.git",
|
|
10
|
+
"directory": "packages/google-vertex"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"llm",
|
|
14
|
+
"ai",
|
|
15
|
+
"google",
|
|
16
|
+
"gemini",
|
|
17
|
+
"imagen",
|
|
18
|
+
"vertex",
|
|
19
|
+
"vertex-ai",
|
|
20
|
+
"google-cloud",
|
|
21
|
+
"provider",
|
|
22
|
+
"sdk"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.js",
|
|
31
|
+
"require": "./dist/index.js",
|
|
32
|
+
"default": "./dist/index.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"README.md",
|
|
38
|
+
"LICENSE"
|
|
39
|
+
],
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public",
|
|
42
|
+
"provenance": true
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsup",
|
|
46
|
+
"lint": "eslint src/ --max-warnings 0",
|
|
47
|
+
"check-types": "tsc --noEmit",
|
|
48
|
+
"test": "vitest run",
|
|
49
|
+
"test:watch": "vitest"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@core-ai/core-ai": "^0.14.0",
|
|
53
|
+
"@core-ai/google-genai": "^0.14.0",
|
|
54
|
+
"@google/genai": "^1.42.0"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"zod": "^4.0.0"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@core-ai/eslint-config": "*",
|
|
61
|
+
"@core-ai/typescript-config": "*",
|
|
62
|
+
"typescript": "^5.7.3",
|
|
63
|
+
"vitest": "^3.2.4"
|
|
64
|
+
}
|
|
65
|
+
}
|