@activepieces/piece-google-vertexai 0.0.1
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/package.json +17 -0
- package/src/index.d.ts +4 -0
- package/src/index.js +21 -0
- package/src/index.js.map +1 -0
- package/src/lib/actions/generate-content.d.ts +19 -0
- package/src/lib/actions/generate-content.js +156 -0
- package/src/lib/actions/generate-content.js.map +1 -0
- package/src/lib/actions/generate-image.d.ts +18 -0
- package/src/lib/actions/generate-image.js +140 -0
- package/src/lib/actions/generate-image.js.map +1 -0
- package/src/lib/actions/index.d.ts +3 -0
- package/src/lib/actions/index.js +10 -0
- package/src/lib/actions/index.js.map +1 -0
- package/src/lib/actions/raw-request.d.ts +18 -0
- package/src/lib/actions/raw-request.js +37 -0
- package/src/lib/actions/raw-request.js.map +1 -0
- package/src/lib/auth.d.ts +5 -0
- package/src/lib/auth.js +63 -0
- package/src/lib/auth.js.map +1 -0
- package/src/lib/common.d.ts +37 -0
- package/src/lib/common.js +163 -0
- package/src/lib/common.js.map +1 -0
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@activepieces/piece-google-vertexai",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"main": "./src/index.js",
|
|
5
|
+
"types": "./src/index.d.ts",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@activepieces/pieces-common": "0.11.7",
|
|
8
|
+
"@activepieces/pieces-framework": "0.25.6",
|
|
9
|
+
"@activepieces/shared": "0.41.0",
|
|
10
|
+
"@google/genai": "1.43.0",
|
|
11
|
+
"google-auth-library": "10.6.1"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc -p tsconfig.lib.json && cp package.json dist/",
|
|
15
|
+
"lint": "eslint 'src/**/*.ts'"
|
|
16
|
+
}
|
|
17
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const googleVertexai: import("@activepieces/pieces-framework").Piece<import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
2
|
+
serviceAccountJson: import("@activepieces/pieces-framework").LongTextProperty<true>;
|
|
3
|
+
}>>;
|
|
4
|
+
export { vertexAiAuth, GoogleVertexAIAuthValue } from "./lib/auth";
|
package/src/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.vertexAiAuth = exports.googleVertexai = void 0;
|
|
4
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
5
|
+
const shared_1 = require("@activepieces/shared");
|
|
6
|
+
const auth_1 = require("./lib/auth");
|
|
7
|
+
const actions_1 = require("./lib/actions");
|
|
8
|
+
exports.googleVertexai = (0, pieces_framework_1.createPiece)({
|
|
9
|
+
displayName: "Google Vertex AI",
|
|
10
|
+
description: "Generate content and images using Gemini and Imagen models on Google Vertex AI.",
|
|
11
|
+
auth: auth_1.vertexAiAuth,
|
|
12
|
+
minimumSupportedRelease: "0.71.4",
|
|
13
|
+
logoUrl: "https://cdn.activepieces.com/pieces/google-vertexai.png",
|
|
14
|
+
categories: [shared_1.PieceCategory.ARTIFICIAL_INTELLIGENCE],
|
|
15
|
+
authors: ["alinperghel", "onyedikachi-david"],
|
|
16
|
+
actions: [actions_1.generateContent, actions_1.generateImage, actions_1.customApiCall],
|
|
17
|
+
triggers: [],
|
|
18
|
+
});
|
|
19
|
+
var auth_2 = require("./lib/auth");
|
|
20
|
+
Object.defineProperty(exports, "vertexAiAuth", { enumerable: true, get: function () { return auth_2.vertexAiAuth; } });
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,qEAA6D;AAC7D,iDAAqD;AACrD,qCAA0C;AAC1C,2CAA8E;AAEjE,QAAA,cAAc,GAAG,IAAA,8BAAW,EAAC;IACxC,WAAW,EAAE,kBAAkB;IAC/B,WAAW,EAAE,iFAAiF;IAC9F,IAAI,EAAE,mBAAY;IAClB,uBAAuB,EAAE,QAAQ;IACjC,OAAO,EAAE,yDAAyD;IAClE,UAAU,EAAE,CAAC,sBAAa,CAAC,uBAAuB,CAAC;IACnD,OAAO,EAAE,CAAC,aAAa,EAAE,mBAAmB,CAAC;IAC7C,OAAO,EAAE,CAAC,yBAAe,EAAE,uBAAa,EAAE,uBAAa,CAAC;IACxD,QAAQ,EAAE,EAAE;CACb,CAAC,CAAC;AAEH,mCAAmE;AAA1D,oGAAA,YAAY,OAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ThinkingLevel } from '@google/genai';
|
|
2
|
+
export declare const generateContent: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
3
|
+
serviceAccountJson: import("@activepieces/pieces-framework").LongTextProperty<true>;
|
|
4
|
+
}>, {
|
|
5
|
+
location: import("@activepieces/pieces-framework").DropdownProperty<string, true, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
6
|
+
serviceAccountJson: import("@activepieces/pieces-framework").LongTextProperty<true>;
|
|
7
|
+
}>>;
|
|
8
|
+
model: import("@activepieces/pieces-framework").DropdownProperty<string, true, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
9
|
+
serviceAccountJson: import("@activepieces/pieces-framework").LongTextProperty<true>;
|
|
10
|
+
}>>;
|
|
11
|
+
systemMessage: import("@activepieces/pieces-framework").LongTextProperty<false>;
|
|
12
|
+
userMessage: import("@activepieces/pieces-framework").LongTextProperty<true>;
|
|
13
|
+
imageUrls: import("@activepieces/pieces-framework").ArrayProperty<false>;
|
|
14
|
+
temperature: import("@activepieces/pieces-framework").NumberProperty<false>;
|
|
15
|
+
maxOutputTokens: import("@activepieces/pieces-framework").NumberProperty<false>;
|
|
16
|
+
thinkingLevel: import("@activepieces/pieces-framework").StaticDropdownProperty<ThinkingLevel, false>;
|
|
17
|
+
thinkingBudget: import("@activepieces/pieces-framework").NumberProperty<false>;
|
|
18
|
+
includeThoughts: import("@activepieces/pieces-framework").CheckboxProperty<false>;
|
|
19
|
+
}>;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateContent = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
6
|
+
const genai_1 = require("@google/genai");
|
|
7
|
+
const auth_1 = require("../auth");
|
|
8
|
+
const common_1 = require("../common");
|
|
9
|
+
exports.generateContent = (0, pieces_framework_1.createAction)({
|
|
10
|
+
auth: auth_1.vertexAiAuth,
|
|
11
|
+
name: 'generate_content',
|
|
12
|
+
displayName: 'Generate Content',
|
|
13
|
+
description: 'Call a Gemini model on Vertex AI to generate a text response.',
|
|
14
|
+
props: {
|
|
15
|
+
location: pieces_framework_1.Property.Dropdown({
|
|
16
|
+
displayName: 'Location',
|
|
17
|
+
description: 'Google Cloud region where your Vertex AI resources are hosted.',
|
|
18
|
+
required: true,
|
|
19
|
+
refreshers: [],
|
|
20
|
+
defaultValue: 'us-central1',
|
|
21
|
+
auth: auth_1.vertexAiAuth,
|
|
22
|
+
options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) { return (0, common_1.getVertexAILocationOptions)(auth); }),
|
|
23
|
+
}),
|
|
24
|
+
model: pieces_framework_1.Property.Dropdown({
|
|
25
|
+
displayName: 'Model',
|
|
26
|
+
description: 'Gemini model to use for content generation.',
|
|
27
|
+
required: true,
|
|
28
|
+
refreshers: ['location'],
|
|
29
|
+
defaultValue: 'gemini-2.5-flash',
|
|
30
|
+
auth: auth_1.vertexAiAuth,
|
|
31
|
+
options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth, location }) {
|
|
32
|
+
return (0, common_1.getVertexAIModelOptions)(auth, location);
|
|
33
|
+
}),
|
|
34
|
+
}),
|
|
35
|
+
systemMessage: pieces_framework_1.Property.LongText({
|
|
36
|
+
displayName: 'System Message',
|
|
37
|
+
description: "Instructions that guide the model's behavior throughout the conversation.",
|
|
38
|
+
required: false,
|
|
39
|
+
}),
|
|
40
|
+
userMessage: pieces_framework_1.Property.LongText({
|
|
41
|
+
displayName: 'User Message',
|
|
42
|
+
description: 'The prompt to send to the model.',
|
|
43
|
+
required: true,
|
|
44
|
+
}),
|
|
45
|
+
imageUrls: pieces_framework_1.Property.Array({
|
|
46
|
+
displayName: 'Image URLs',
|
|
47
|
+
description: 'Public image URLs to include alongside the user message. The model will analyze these images.',
|
|
48
|
+
required: false,
|
|
49
|
+
}),
|
|
50
|
+
temperature: pieces_framework_1.Property.Number({
|
|
51
|
+
displayName: 'Temperature',
|
|
52
|
+
description: 'Controls randomness. Lower values are more deterministic (0–2). Leave empty to use the model default.',
|
|
53
|
+
required: false,
|
|
54
|
+
}),
|
|
55
|
+
maxOutputTokens: pieces_framework_1.Property.Number({
|
|
56
|
+
displayName: 'Max Output Tokens',
|
|
57
|
+
description: 'Maximum number of tokens to generate. Leave empty to use the model default.',
|
|
58
|
+
required: false,
|
|
59
|
+
}),
|
|
60
|
+
thinkingLevel: pieces_framework_1.Property.StaticDropdown({
|
|
61
|
+
displayName: 'Thinking Level',
|
|
62
|
+
description: 'Controls how much the model thinks before responding. Supported on Gemini 2.5 and later models.',
|
|
63
|
+
required: false,
|
|
64
|
+
options: {
|
|
65
|
+
options: [
|
|
66
|
+
{ label: 'Low', value: genai_1.ThinkingLevel.LOW },
|
|
67
|
+
{ label: 'Medium', value: genai_1.ThinkingLevel.MEDIUM },
|
|
68
|
+
{ label: 'High', value: genai_1.ThinkingLevel.HIGH },
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
}),
|
|
72
|
+
thinkingBudget: pieces_framework_1.Property.Number({
|
|
73
|
+
displayName: 'Thinking Budget (tokens)',
|
|
74
|
+
description: 'Maximum number of tokens the model can use for internal reasoning. Set to 0 to disable thinking. Supported on Gemini 2.5 and later models.',
|
|
75
|
+
required: false,
|
|
76
|
+
}),
|
|
77
|
+
includeThoughts: pieces_framework_1.Property.Checkbox({
|
|
78
|
+
displayName: 'Include Thoughts in Response',
|
|
79
|
+
description: "When enabled, the model's reasoning is returned alongside the final response. Supported on Gemini 2.5 and later models.",
|
|
80
|
+
required: false,
|
|
81
|
+
defaultValue: false,
|
|
82
|
+
}),
|
|
83
|
+
},
|
|
84
|
+
run(context) {
|
|
85
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
var _a, _b, _c;
|
|
87
|
+
const { location, model, systemMessage, userMessage, imageUrls, temperature, maxOutputTokens, thinkingLevel, thinkingBudget, includeThoughts, } = context.propsValue;
|
|
88
|
+
const auth = context.auth;
|
|
89
|
+
const rawCredentials = JSON.parse(auth.props.serviceAccountJson);
|
|
90
|
+
const credentials = Object.assign(Object.assign({}, rawCredentials), { private_key: (_a = rawCredentials.private_key) === null || _a === void 0 ? void 0 : _a.replace(/\\n/g, '\n') });
|
|
91
|
+
const ai = new genai_1.GoogleGenAI({
|
|
92
|
+
vertexai: true,
|
|
93
|
+
project: credentials.project_id,
|
|
94
|
+
location: location,
|
|
95
|
+
googleAuthOptions: {
|
|
96
|
+
credentials,
|
|
97
|
+
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
const parts = [{ text: userMessage }];
|
|
101
|
+
for (const imageUrl of (_b = imageUrls) !== null && _b !== void 0 ? _b : []) {
|
|
102
|
+
try {
|
|
103
|
+
const imageResponse = yield fetch(imageUrl);
|
|
104
|
+
if (!imageResponse.ok) {
|
|
105
|
+
throw new Error(`HTTP ${imageResponse.status} ${imageResponse.statusText}`);
|
|
106
|
+
}
|
|
107
|
+
const arrayBuffer = yield imageResponse.arrayBuffer();
|
|
108
|
+
const base64 = Buffer.from(arrayBuffer).toString('base64');
|
|
109
|
+
const mimeType = (_c = imageResponse.headers.get('content-type')) !== null && _c !== void 0 ? _c : 'image/jpeg';
|
|
110
|
+
parts.push({ inlineData: { data: base64, mimeType } });
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
throw new Error(`Failed to fetch image (${imageUrl}): ${err instanceof Error ? err.message : String(err)}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const config = {};
|
|
117
|
+
if (systemMessage) {
|
|
118
|
+
config.systemInstruction = systemMessage;
|
|
119
|
+
}
|
|
120
|
+
if (temperature !== undefined && temperature !== null) {
|
|
121
|
+
config.temperature = temperature;
|
|
122
|
+
}
|
|
123
|
+
if (maxOutputTokens !== undefined && maxOutputTokens !== null) {
|
|
124
|
+
config.maxOutputTokens = maxOutputTokens;
|
|
125
|
+
}
|
|
126
|
+
const thinkingConfig = {};
|
|
127
|
+
let hasThinkingConfig = false;
|
|
128
|
+
if (thinkingLevel) {
|
|
129
|
+
thinkingConfig.thinkingLevel = thinkingLevel;
|
|
130
|
+
hasThinkingConfig = true;
|
|
131
|
+
}
|
|
132
|
+
if (thinkingBudget !== undefined && thinkingBudget !== null) {
|
|
133
|
+
thinkingConfig.thinkingBudget = thinkingBudget;
|
|
134
|
+
hasThinkingConfig = true;
|
|
135
|
+
}
|
|
136
|
+
if (includeThoughts) {
|
|
137
|
+
thinkingConfig.includeThoughts = true;
|
|
138
|
+
hasThinkingConfig = true;
|
|
139
|
+
}
|
|
140
|
+
if (hasThinkingConfig) {
|
|
141
|
+
config.thinkingConfig = thinkingConfig;
|
|
142
|
+
}
|
|
143
|
+
const response = yield ai.models.generateContent({
|
|
144
|
+
model,
|
|
145
|
+
contents: [{ role: 'user', parts }],
|
|
146
|
+
config,
|
|
147
|
+
});
|
|
148
|
+
return {
|
|
149
|
+
text: response.text,
|
|
150
|
+
candidates: response.candidates,
|
|
151
|
+
usageMetadata: response.usageMetadata,
|
|
152
|
+
};
|
|
153
|
+
});
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
//# sourceMappingURL=generate-content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-content.js","sourceRoot":"","sources":["../../../../src/lib/actions/generate-content.ts"],"names":[],"mappings":";;;;AAAA,qEAAwE;AACxE,yCAMuB;AACvB,kCAAgE;AAChE,sCAAgF;AAEnE,QAAA,eAAe,GAAG,IAAA,+BAAY,EAAC;IAC1C,IAAI,EAAE,mBAAY;IAClB,IAAI,EAAE,kBAAkB;IACxB,WAAW,EAAE,kBAAkB;IAC/B,WAAW,EAAE,+DAA+D;IAC5E,KAAK,EAAE;QACL,QAAQ,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YAC1B,WAAW,EAAE,UAAU;YACvB,WAAW,EAAE,gEAAgE;YAC7E,QAAQ,EAAE,IAAI;YACd,UAAU,EAAE,EAAE;YACd,YAAY,EAAE,aAAa;YAC3B,IAAI,EAAE,mBAAY;YAClB,OAAO,EAAE,KAAiB,EAAE,oDAAZ,EAAE,IAAI,EAAE,IACtB,OAAA,IAAA,mCAA0B,EAAC,IAA2C,CAAC,CAAA,GAAA;SAC1E,CAAC;QACF,KAAK,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YACvB,WAAW,EAAE,OAAO;YACpB,WAAW,EAAE,6CAA6C;YAC1D,QAAQ,EAAE,IAAI;YACd,UAAU,EAAE,CAAC,UAAU,CAAC;YACxB,YAAY,EAAE,kBAAkB;YAChC,IAAI,EAAE,mBAAY;YAClB,OAAO,EAAE,KAA2B,EAAE,oDAAtB,EAAE,IAAI,EAAE,QAAQ,EAAE;gBAChC,OAAA,IAAA,gCAAuB,EACrB,IAA2C,EAC3C,QAA8B,CAC/B,CAAA;cAAA;SACJ,CAAC;QACF,aAAa,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YAC/B,WAAW,EAAE,gBAAgB;YAC7B,WAAW,EAAE,2EAA2E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eAAe,EAAE,CAAC;gBACpB,cAAc,CAAC,eAAe,GAAG,IAAI,CAAC;gBACtC,iBAAiB,GAAG,IAAI,CAAC;YAC3B,CAAC;YACD,IAAI,iBAAiB,EAAE,CAAC;gBACtB,MAAM,CAAC,cAAc,GAAG,cAAc,CAAC;YACzC,CAAC;YAED,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC,MAAM,CAAC,eAAe,CAAC;gBAC/C,KAAK;gBACL,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;gBACnC,MAAM;aACP,CAAC,CAAC;YAEH,OAAO;gBACL,IAAI,EAAE,QAAQ,CAAC,IAAI;gBACnB,UAAU,EAAE,QAAQ,CAAC,UAAU;gBAC/B,aAAa,EAAE,QAAQ,CAAC,aAAa;aACtC,CAAC;QACJ,CAAC;KAAA;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const generateImage: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
2
|
+
serviceAccountJson: import("@activepieces/pieces-framework").LongTextProperty<true>;
|
|
3
|
+
}>, {
|
|
4
|
+
location: import("@activepieces/pieces-framework").DropdownProperty<string, true, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
5
|
+
serviceAccountJson: import("@activepieces/pieces-framework").LongTextProperty<true>;
|
|
6
|
+
}>>;
|
|
7
|
+
model: import("@activepieces/pieces-framework").DropdownProperty<string, true, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
8
|
+
serviceAccountJson: import("@activepieces/pieces-framework").LongTextProperty<true>;
|
|
9
|
+
}>>;
|
|
10
|
+
prompt: import("@activepieces/pieces-framework").LongTextProperty<true>;
|
|
11
|
+
negativePrompt: import("@activepieces/pieces-framework").LongTextProperty<false>;
|
|
12
|
+
numberOfImages: import("@activepieces/pieces-framework").NumberProperty<false>;
|
|
13
|
+
aspectRatio: import("@activepieces/pieces-framework").StaticDropdownProperty<string, false>;
|
|
14
|
+
outputMimeType: import("@activepieces/pieces-framework").StaticDropdownProperty<string, false>;
|
|
15
|
+
seed: import("@activepieces/pieces-framework").NumberProperty<false>;
|
|
16
|
+
enhancePrompt: import("@activepieces/pieces-framework").CheckboxProperty<false>;
|
|
17
|
+
addWatermark: import("@activepieces/pieces-framework").CheckboxProperty<false>;
|
|
18
|
+
}>;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateImage = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
6
|
+
const genai_1 = require("@google/genai");
|
|
7
|
+
const auth_1 = require("../auth");
|
|
8
|
+
const common_1 = require("../common");
|
|
9
|
+
exports.generateImage = (0, pieces_framework_1.createAction)({
|
|
10
|
+
auth: auth_1.vertexAiAuth,
|
|
11
|
+
name: 'generate_image',
|
|
12
|
+
displayName: 'Generate Image',
|
|
13
|
+
description: 'Generate an image from a text prompt using Google Imagen models on Vertex AI.',
|
|
14
|
+
props: {
|
|
15
|
+
location: pieces_framework_1.Property.Dropdown({
|
|
16
|
+
displayName: 'Location',
|
|
17
|
+
description: 'Google Cloud region where your Vertex AI resources are hosted.',
|
|
18
|
+
required: true,
|
|
19
|
+
refreshers: [],
|
|
20
|
+
defaultValue: 'us-central1',
|
|
21
|
+
auth: auth_1.vertexAiAuth,
|
|
22
|
+
options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) { return (0, common_1.getVertexAILocationOptions)(auth); }),
|
|
23
|
+
}),
|
|
24
|
+
model: pieces_framework_1.Property.Dropdown({
|
|
25
|
+
displayName: 'Model',
|
|
26
|
+
description: 'Imagen model to use for image generation.',
|
|
27
|
+
required: true,
|
|
28
|
+
refreshers: ['location'],
|
|
29
|
+
defaultValue: 'imagen-4.0-generate-001',
|
|
30
|
+
auth: auth_1.vertexAiAuth,
|
|
31
|
+
options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth, location }) {
|
|
32
|
+
return (0, common_1.getVertexAIImageModelOptions)(auth, location);
|
|
33
|
+
}),
|
|
34
|
+
}),
|
|
35
|
+
prompt: pieces_framework_1.Property.LongText({
|
|
36
|
+
displayName: 'Prompt',
|
|
37
|
+
description: 'A text description of the image you want to generate.',
|
|
38
|
+
required: true,
|
|
39
|
+
}),
|
|
40
|
+
negativePrompt: pieces_framework_1.Property.LongText({
|
|
41
|
+
displayName: 'Negative Prompt',
|
|
42
|
+
description: 'Describe what you do NOT want in the image.',
|
|
43
|
+
required: false,
|
|
44
|
+
}),
|
|
45
|
+
numberOfImages: pieces_framework_1.Property.Number({
|
|
46
|
+
displayName: 'Number of Images',
|
|
47
|
+
description: 'Number of images to generate (1–4).',
|
|
48
|
+
required: false,
|
|
49
|
+
defaultValue: 1,
|
|
50
|
+
}),
|
|
51
|
+
aspectRatio: pieces_framework_1.Property.StaticDropdown({
|
|
52
|
+
displayName: 'Aspect Ratio',
|
|
53
|
+
description: 'Aspect ratio of the generated image.',
|
|
54
|
+
required: false,
|
|
55
|
+
defaultValue: '1:1',
|
|
56
|
+
options: {
|
|
57
|
+
options: [
|
|
58
|
+
{ label: 'Square (1:1)', value: '1:1' },
|
|
59
|
+
{ label: 'Portrait (3:4)', value: '3:4' },
|
|
60
|
+
{ label: 'Landscape (4:3)', value: '4:3' },
|
|
61
|
+
{ label: 'Portrait (9:16)', value: '9:16' },
|
|
62
|
+
{ label: 'Landscape (16:9)', value: '16:9' },
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
}),
|
|
66
|
+
outputMimeType: pieces_framework_1.Property.StaticDropdown({
|
|
67
|
+
displayName: 'Output Format',
|
|
68
|
+
description: 'Image format for the generated output.',
|
|
69
|
+
required: false,
|
|
70
|
+
defaultValue: 'image/png',
|
|
71
|
+
options: {
|
|
72
|
+
options: [
|
|
73
|
+
{ label: 'PNG', value: 'image/png' },
|
|
74
|
+
{ label: 'JPEG', value: 'image/jpeg' },
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
}),
|
|
78
|
+
seed: pieces_framework_1.Property.Number({
|
|
79
|
+
displayName: 'Seed',
|
|
80
|
+
description: 'Random seed for reproducible results. Requires "Add Watermark" to be disabled.',
|
|
81
|
+
required: false,
|
|
82
|
+
}),
|
|
83
|
+
enhancePrompt: pieces_framework_1.Property.Checkbox({
|
|
84
|
+
displayName: 'Enhance Prompt',
|
|
85
|
+
description: 'When enabled, the model rewrites your prompt to improve output quality.',
|
|
86
|
+
required: false,
|
|
87
|
+
defaultValue: false,
|
|
88
|
+
}),
|
|
89
|
+
addWatermark: pieces_framework_1.Property.Checkbox({
|
|
90
|
+
displayName: 'Add Watermark',
|
|
91
|
+
description: 'When enabled, adds an invisible watermark to generated images.',
|
|
92
|
+
required: false,
|
|
93
|
+
defaultValue: false,
|
|
94
|
+
}),
|
|
95
|
+
},
|
|
96
|
+
run(context) {
|
|
97
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
var _a, _b;
|
|
99
|
+
const { location, model, prompt, negativePrompt, numberOfImages, aspectRatio, outputMimeType, seed, enhancePrompt, addWatermark, } = context.propsValue;
|
|
100
|
+
const auth = context.auth;
|
|
101
|
+
const rawCredentials = JSON.parse(auth.props.serviceAccountJson);
|
|
102
|
+
const credentials = Object.assign(Object.assign({}, rawCredentials), { private_key: (_a = rawCredentials.private_key) === null || _a === void 0 ? void 0 : _a.replace(/\\n/g, '\n') });
|
|
103
|
+
const ai = new genai_1.GoogleGenAI({
|
|
104
|
+
vertexai: true,
|
|
105
|
+
project: credentials.project_id,
|
|
106
|
+
location,
|
|
107
|
+
googleAuthOptions: {
|
|
108
|
+
credentials,
|
|
109
|
+
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
const response = yield ai.models.generateImages({
|
|
113
|
+
model,
|
|
114
|
+
prompt,
|
|
115
|
+
config: Object.assign(Object.assign(Object.assign(Object.assign({}, (negativePrompt ? { negativePrompt } : {})), { numberOfImages: numberOfImages !== null && numberOfImages !== void 0 ? numberOfImages : 1, aspectRatio: aspectRatio !== null && aspectRatio !== void 0 ? aspectRatio : '1:1', outputMimeType: outputMimeType !== null && outputMimeType !== void 0 ? outputMimeType : 'image/png' }), (seed !== undefined && seed !== null ? { seed } : {})), { enhancePrompt: enhancePrompt !== null && enhancePrompt !== void 0 ? enhancePrompt : false, addWatermark: addWatermark !== null && addWatermark !== void 0 ? addWatermark : false }),
|
|
116
|
+
});
|
|
117
|
+
const generated = (_b = response.generatedImages) !== null && _b !== void 0 ? _b : [];
|
|
118
|
+
if (generated.length === 0) {
|
|
119
|
+
throw new Error('No images were generated. The prompt may have been blocked by safety filters.');
|
|
120
|
+
}
|
|
121
|
+
const ext = (outputMimeType !== null && outputMimeType !== void 0 ? outputMimeType : 'image/png') === 'image/jpeg' ? 'jpg' : 'png';
|
|
122
|
+
const images = yield Promise.all(generated.map((img, index) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
var _a;
|
|
124
|
+
const imageBytes = (_a = img.image) === null || _a === void 0 ? void 0 : _a.imageBytes;
|
|
125
|
+
if (!imageBytes) {
|
|
126
|
+
throw new Error(img.raiFilteredReason
|
|
127
|
+
? `Image ${index + 1} was filtered: ${img.raiFilteredReason}`
|
|
128
|
+
: `Image ${index + 1} did not return any data.`);
|
|
129
|
+
}
|
|
130
|
+
const file = yield context.files.write({
|
|
131
|
+
fileName: `generated-image-${index + 1}.${ext}`,
|
|
132
|
+
data: Buffer.from(imageBytes, 'base64'),
|
|
133
|
+
});
|
|
134
|
+
return Object.assign({ image: file }, (img.enhancedPrompt ? { enhancedPrompt: img.enhancedPrompt } : {}));
|
|
135
|
+
})));
|
|
136
|
+
return { images, model, prompt };
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
//# sourceMappingURL=generate-image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-image.js","sourceRoot":"","sources":["../../../../src/lib/actions/generate-image.ts"],"names":[],"mappings":";;;;AAAA,qEAAwE;AACxE,yCAA4C;AAC5C,kCAAgE;AAChE,sCAAqF;AAExE,QAAA,aAAa,GAAG,IAAA,+BAAY,EAAC;IACxC,IAAI,EAAE,mBAAY;IAClB,IAAI,EAAE,gBAAgB;IACtB,WAAW,EAAE,gBAAgB;IAC7B,WAAW,EACT,+EAA+E;IACjF,KAAK,EAAE;QACL,QAAQ,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YAC1B,WAAW,EAAE,UAAU;YACvB,WAAW,EAAE,gEAAgE;YAC7E,QAAQ,EAAE,IAAI;YACd,UAAU,EAAE,EAAE;YACd,YAAY,EAAE,aAAa;YAC3B,IAAI,EAAE,mBAAY;YAClB,OAAO,EAAE,KAAiB,EAAE,oDAAZ,EAAE,IAAI,EAAE,IACtB,OAAA,IAAA,mCAA0B,EAAC,IAA2C,CAAC,CAAA,GAAA;SAC1E,CAAC;QACF,KAAK,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YACvB,WAAW,EAAE,OAAO;YACpB,WAAW,EAAE,2CAA2C;YACxD,QAAQ,EAAE,IAAI;YACd,UAAU,EAAE,CAAC,UAAU,CAAC;YACxB,YAAY,EAAE,yBAAyB;YACvC,IAAI,EAAE,mBAAY;YAClB,OAAO,EAAE,KAA2B,EAAE,oDAAtB,EAAE,IAAI,EAAE,QAAQ,EAAE;gBAChC,OAAA,IAAA,qCAA4B,EAC1B,IAA2C,EAC3C,QAA8B,CAC/B,CAAA;cAAA;SACJ,CAAC;QACF,MAAM,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YACxB,WAAW,EAAE,QAAQ;YACrB,WAAW,EAAE,uDAAuD;YACpE,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,cAAc,EAAE,2BAAQ,CAAC,QAAQ,CAA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rC,QAAQ,EAAE,mBAAmB,KAAK,GAAG,CAAC,IAAI,GAAG,EAAE;oBAC/C,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC;iBACxC,CAAC,CAAC;gBAEH,uBACE,KAAK,EAAE,IAAI,IACR,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,GAAG,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EACrE;YACJ,CAAC,CAAA,CAAC,CACH,CAAC;YAEF,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;QACnC,CAAC;KAAA;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.customApiCall = exports.generateImage = exports.generateContent = void 0;
|
|
4
|
+
var generate_content_1 = require("./generate-content");
|
|
5
|
+
Object.defineProperty(exports, "generateContent", { enumerable: true, get: function () { return generate_content_1.generateContent; } });
|
|
6
|
+
var generate_image_1 = require("./generate-image");
|
|
7
|
+
Object.defineProperty(exports, "generateImage", { enumerable: true, get: function () { return generate_image_1.generateImage; } });
|
|
8
|
+
var raw_request_1 = require("./raw-request");
|
|
9
|
+
Object.defineProperty(exports, "customApiCall", { enumerable: true, get: function () { return raw_request_1.customApiCall; } });
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/actions/index.ts"],"names":[],"mappings":";;;AAAA,uDAAqD;AAA5C,mHAAA,eAAe,OAAA;AACxB,mDAAiD;AAAxC,+GAAA,aAAa,OAAA;AACtB,6CAA8C;AAArC,4GAAA,aAAa,OAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const customApiCall: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
2
|
+
serviceAccountJson: import("@activepieces/pieces-framework").LongTextProperty<true>;
|
|
3
|
+
}>, {
|
|
4
|
+
url: import("@activepieces/pieces-framework").DynamicProperties<true, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
5
|
+
serviceAccountJson: import("@activepieces/pieces-framework").LongTextProperty<true>;
|
|
6
|
+
}> | undefined>;
|
|
7
|
+
method: import("@activepieces/pieces-framework").StaticDropdownProperty<import("@activepieces/pieces-common").HttpMethod, false> | import("@activepieces/pieces-framework").StaticDropdownProperty<import("@activepieces/pieces-common").HttpMethod, true>;
|
|
8
|
+
headers: import("@activepieces/pieces-framework").ObjectProperty<false> | import("@activepieces/pieces-framework").ObjectProperty<true>;
|
|
9
|
+
queryParams: import("@activepieces/pieces-framework").ObjectProperty<false> | import("@activepieces/pieces-framework").ObjectProperty<true>;
|
|
10
|
+
body_type: import("@activepieces/pieces-framework").StaticDropdownProperty<string, false>;
|
|
11
|
+
body: import("@activepieces/pieces-framework").DynamicProperties<false, import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
12
|
+
serviceAccountJson: import("@activepieces/pieces-framework").LongTextProperty<true>;
|
|
13
|
+
}> | undefined>;
|
|
14
|
+
response_is_binary: import("@activepieces/pieces-framework").CheckboxProperty<false>;
|
|
15
|
+
failsafe: import("@activepieces/pieces-framework").CheckboxProperty<false> | import("@activepieces/pieces-framework").CheckboxProperty<true>;
|
|
16
|
+
timeout: import("@activepieces/pieces-framework").NumberProperty<false> | import("@activepieces/pieces-framework").NumberProperty<true>;
|
|
17
|
+
followRedirects: import("@activepieces/pieces-framework").CheckboxProperty<false>;
|
|
18
|
+
}>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.customApiCall = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_common_1 = require("@activepieces/pieces-common");
|
|
6
|
+
const google_auth_library_1 = require("google-auth-library");
|
|
7
|
+
const auth_1 = require("../auth");
|
|
8
|
+
function parseRawCredentials(auth) {
|
|
9
|
+
var _a;
|
|
10
|
+
const raw = JSON.parse(auth.props.serviceAccountJson);
|
|
11
|
+
return Object.assign(Object.assign({}, raw), { private_key: (_a = raw.private_key) === null || _a === void 0 ? void 0 : _a.replace(/\\n/g, '\n') });
|
|
12
|
+
}
|
|
13
|
+
exports.customApiCall = (0, pieces_common_1.createCustomApiCallAction)({
|
|
14
|
+
auth: auth_1.vertexAiAuth,
|
|
15
|
+
baseUrl: (auth) => {
|
|
16
|
+
try {
|
|
17
|
+
const credentials = parseRawCredentials(auth);
|
|
18
|
+
return `https://aiplatform.googleapis.com/v1/projects/${credentials.project_id}`;
|
|
19
|
+
}
|
|
20
|
+
catch (_a) {
|
|
21
|
+
return 'https://aiplatform.googleapis.com/v1';
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
authMapping: (auth) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
const credentials = parseRawCredentials(auth);
|
|
26
|
+
const googleAuth = new google_auth_library_1.GoogleAuth({
|
|
27
|
+
credentials,
|
|
28
|
+
projectId: credentials.project_id,
|
|
29
|
+
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
|
|
30
|
+
});
|
|
31
|
+
const accessToken = yield googleAuth.getAccessToken();
|
|
32
|
+
if (!accessToken)
|
|
33
|
+
throw new Error('Failed to obtain access token');
|
|
34
|
+
return { Authorization: `Bearer ${accessToken}` };
|
|
35
|
+
}),
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingURL=raw-request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raw-request.js","sourceRoot":"","sources":["../../../../src/lib/actions/raw-request.ts"],"names":[],"mappings":";;;;AAAA,+DAAwE;AACxE,6DAAiD;AACjD,kCAAgE;AAEhE,SAAS,mBAAmB,CAAC,IAA6B;;IACxD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACtD,uCAAY,GAAG,KAAE,WAAW,EAAE,MAAA,GAAG,CAAC,WAAW,0CAAE,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,IAAG;AACzE,CAAC;AAEY,QAAA,aAAa,GAAG,IAAA,yCAAyB,EAAC;IACrD,IAAI,EAAE,mBAAY;IAClB,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;QAChB,IAAI,CAAC;YACH,MAAM,WAAW,GAAG,mBAAmB,CAAC,IAA+B,CAAC,CAAC;YACzE,OAAO,iDAAiD,WAAW,CAAC,UAAU,EAAE,CAAC;QACnF,CAAC;QAAC,WAAM,CAAC;YACP,OAAO,sCAAsC,CAAC;QAChD,CAAC;IACH,CAAC;IACD,WAAW,EAAE,CAAO,IAAI,EAAE,EAAE;QAC1B,MAAM,WAAW,GAAG,mBAAmB,CAAC,IAA+B,CAAC,CAAC;QACzE,MAAM,UAAU,GAAG,IAAI,gCAAU,CAAC;YAChC,WAAW;YACX,SAAS,EAAE,WAAW,CAAC,UAAU;YACjC,MAAM,EAAE,CAAC,gDAAgD,CAAC;SAC3D,CAAC,CAAC;QACH,MAAM,WAAW,GAAG,MAAM,UAAU,CAAC,cAAc,EAAE,CAAC;QACtD,IAAI,CAAC,WAAW;YAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;QACnE,OAAO,EAAE,aAAa,EAAE,UAAU,WAAW,EAAE,EAAE,CAAC;IACpD,CAAC,CAAA;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { AppConnectionValueForAuthProperty } from '@activepieces/pieces-framework';
|
|
2
|
+
export declare const vertexAiAuth: import("@activepieces/pieces-framework").CustomAuthProperty<{
|
|
3
|
+
serviceAccountJson: import("@activepieces/pieces-framework").LongTextProperty<true>;
|
|
4
|
+
}>;
|
|
5
|
+
export type GoogleVertexAIAuthValue = AppConnectionValueForAuthProperty<typeof vertexAiAuth>;
|
package/src/lib/auth.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.vertexAiAuth = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_framework_1 = require("@activepieces/pieces-framework");
|
|
6
|
+
exports.vertexAiAuth = pieces_framework_1.PieceAuth.CustomAuth({
|
|
7
|
+
description: `
|
|
8
|
+
To authenticate with Google Vertex AI using a Service Account:
|
|
9
|
+
1. Go to [Google Cloud Console](https://console.cloud.google.com).
|
|
10
|
+
2. Create a new project or select an existing one.
|
|
11
|
+
3. Enable the **Vertex AI API** under *APIs & Services > Enabled APIs*.
|
|
12
|
+
4. Create a Service Account:
|
|
13
|
+
- Go to **IAM & Admin > Service Accounts**.
|
|
14
|
+
- Click **Create Service Account**, fill in the details and click **Create**.
|
|
15
|
+
- Grant the **Vertex AI User** role.
|
|
16
|
+
5. Create a JSON key:
|
|
17
|
+
- Click on the created service account.
|
|
18
|
+
- Go to the **Keys** tab.
|
|
19
|
+
- Click **Add Key > Create new key**, choose **JSON** and click **Create**.
|
|
20
|
+
- The JSON key file will be downloaded automatically.
|
|
21
|
+
6. Copy the **entire contents** of the downloaded JSON file and paste it below.
|
|
22
|
+
`,
|
|
23
|
+
required: true,
|
|
24
|
+
props: {
|
|
25
|
+
serviceAccountJson: pieces_framework_1.Property.LongText({
|
|
26
|
+
displayName: 'Service Account JSON',
|
|
27
|
+
description: 'The complete JSON content from your Google Service Account key file.',
|
|
28
|
+
required: true,
|
|
29
|
+
}),
|
|
30
|
+
},
|
|
31
|
+
validate: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
|
|
32
|
+
try {
|
|
33
|
+
const credentials = JSON.parse(auth.serviceAccountJson);
|
|
34
|
+
if (!credentials.type || credentials.type !== 'service_account') {
|
|
35
|
+
return { valid: false, error: 'Invalid service account JSON: missing or incorrect "type" field.' };
|
|
36
|
+
}
|
|
37
|
+
if (!credentials.project_id) {
|
|
38
|
+
return { valid: false, error: 'Invalid service account JSON: missing "project_id" field.' };
|
|
39
|
+
}
|
|
40
|
+
if (!credentials.private_key) {
|
|
41
|
+
return { valid: false, error: 'Invalid service account JSON: missing "private_key" field.' };
|
|
42
|
+
}
|
|
43
|
+
if (!credentials.client_email) {
|
|
44
|
+
return { valid: false, error: 'Invalid service account JSON: missing "client_email" field.' };
|
|
45
|
+
}
|
|
46
|
+
const { JWT } = yield Promise.resolve().then(() => tslib_1.__importStar(require('google-auth-library')));
|
|
47
|
+
const jwtClient = new JWT({
|
|
48
|
+
email: credentials.client_email,
|
|
49
|
+
key: credentials.private_key.replace(/\\n/g, '\n'),
|
|
50
|
+
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
|
|
51
|
+
});
|
|
52
|
+
yield jwtClient.authorize();
|
|
53
|
+
return { valid: true };
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
if (e instanceof SyntaxError) {
|
|
57
|
+
return { valid: false, error: 'Invalid JSON format. Please copy the complete service account JSON file.' };
|
|
58
|
+
}
|
|
59
|
+
return { valid: false, error: `Authentication failed: ${e instanceof Error ? e.message : 'Unknown error'}` };
|
|
60
|
+
}
|
|
61
|
+
}),
|
|
62
|
+
});
|
|
63
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/lib/auth.ts"],"names":[],"mappings":";;;;AAAA,qEAAwG;AAE3F,QAAA,YAAY,GAAG,4BAAS,CAAC,UAAU,CAAC;IAC/C,WAAW,EAAE;;;;;;;;;;;;;;;GAeZ;IACD,QAAQ,EAAE,IAAI;IACd,KAAK,EAAE;QACL,kBAAkB,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YACpC,WAAW,EAAE,sBAAsB;YACnC,WAAW,E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WAAW,EAAE,CAAC;gBAC7B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,0EAA0E,EAAE,CAAC;YAC7G,CAAC;YACD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,0BAA0B,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,EAAE,CAAC;QAC/G,CAAC;IACH,CAAC,CAAA;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { GoogleVertexAIAuthValue } from './auth';
|
|
2
|
+
export declare function getVertexAILocationOptions(auth: GoogleVertexAIAuthValue | undefined): Promise<{
|
|
3
|
+
disabled: boolean;
|
|
4
|
+
placeholder: string;
|
|
5
|
+
options: never[];
|
|
6
|
+
} | {
|
|
7
|
+
disabled: boolean;
|
|
8
|
+
options: {
|
|
9
|
+
label: string;
|
|
10
|
+
value: string;
|
|
11
|
+
}[];
|
|
12
|
+
placeholder?: undefined;
|
|
13
|
+
}>;
|
|
14
|
+
export declare function getVertexAIModelOptions(auth: GoogleVertexAIAuthValue | undefined, location: string | undefined): Promise<{
|
|
15
|
+
disabled: boolean;
|
|
16
|
+
placeholder: string;
|
|
17
|
+
options: never[];
|
|
18
|
+
} | {
|
|
19
|
+
disabled: boolean;
|
|
20
|
+
options: {
|
|
21
|
+
label: string;
|
|
22
|
+
value: string;
|
|
23
|
+
}[];
|
|
24
|
+
placeholder?: undefined;
|
|
25
|
+
}>;
|
|
26
|
+
export declare function getVertexAIImageModelOptions(auth: GoogleVertexAIAuthValue | undefined, location: string | undefined): Promise<{
|
|
27
|
+
disabled: boolean;
|
|
28
|
+
placeholder: string;
|
|
29
|
+
options: never[];
|
|
30
|
+
} | {
|
|
31
|
+
disabled: boolean;
|
|
32
|
+
options: {
|
|
33
|
+
label: string;
|
|
34
|
+
value: string;
|
|
35
|
+
}[];
|
|
36
|
+
placeholder?: undefined;
|
|
37
|
+
}>;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getVertexAILocationOptions = getVertexAILocationOptions;
|
|
4
|
+
exports.getVertexAIModelOptions = getVertexAIModelOptions;
|
|
5
|
+
exports.getVertexAIImageModelOptions = getVertexAIImageModelOptions;
|
|
6
|
+
const tslib_1 = require("tslib");
|
|
7
|
+
const genai_1 = require("@google/genai");
|
|
8
|
+
const pieces_common_1 = require("@activepieces/pieces-common");
|
|
9
|
+
const google_auth_library_1 = require("google-auth-library");
|
|
10
|
+
const VERTEX_AI_LOCATIONS = [
|
|
11
|
+
{ label: 'us-central1 (Iowa)', value: 'us-central1' },
|
|
12
|
+
{ label: 'us-east1 (South Carolina)', value: 'us-east1' },
|
|
13
|
+
{ label: 'us-east4 (Northern Virginia)', value: 'us-east4' },
|
|
14
|
+
{ label: 'us-east5 (Columbus)', value: 'us-east5' },
|
|
15
|
+
{ label: 'us-south1 (Dallas)', value: 'us-south1' },
|
|
16
|
+
{ label: 'us-west1 (Oregon)', value: 'us-west1' },
|
|
17
|
+
{ label: 'us-west4 (Las Vegas)', value: 'us-west4' },
|
|
18
|
+
{ label: 'northamerica-northeast1 (Montréal)', value: 'northamerica-northeast1' },
|
|
19
|
+
{ label: 'northamerica-northeast2 (Toronto)', value: 'northamerica-northeast2' },
|
|
20
|
+
{ label: 'europe-central2 (Warsaw)', value: 'europe-central2' },
|
|
21
|
+
{ label: 'europe-north1 (Finland)', value: 'europe-north1' },
|
|
22
|
+
{ label: 'europe-southwest1 (Madrid)', value: 'europe-southwest1' },
|
|
23
|
+
{ label: 'europe-west1 (Belgium)', value: 'europe-west1' },
|
|
24
|
+
{ label: 'europe-west2 (London)', value: 'europe-west2' },
|
|
25
|
+
{ label: 'europe-west3 (Frankfurt)', value: 'europe-west3' },
|
|
26
|
+
{ label: 'europe-west4 (Netherlands)', value: 'europe-west4' },
|
|
27
|
+
{ label: 'europe-west6 (Zürich)', value: 'europe-west6' },
|
|
28
|
+
{ label: 'europe-west8 (Milan)', value: 'europe-west8' },
|
|
29
|
+
{ label: 'europe-west9 (Paris)', value: 'europe-west9' },
|
|
30
|
+
{ label: 'europe-west12 (Turin)', value: 'europe-west12' },
|
|
31
|
+
{ label: 'me-central1 (Doha)', value: 'me-central1' },
|
|
32
|
+
{ label: 'me-central2 (Dammam)', value: 'me-central2' },
|
|
33
|
+
{ label: 'me-west1 (Tel Aviv)', value: 'me-west1' },
|
|
34
|
+
{ label: 'africa-south1 (Johannesburg)', value: 'africa-south1' },
|
|
35
|
+
{ label: 'asia-east1 (Taiwan)', value: 'asia-east1' },
|
|
36
|
+
{ label: 'asia-east2 (Hong Kong)', value: 'asia-east2' },
|
|
37
|
+
{ label: 'asia-northeast1 (Tokyo)', value: 'asia-northeast1' },
|
|
38
|
+
{ label: 'asia-northeast2 (Osaka)', value: 'asia-northeast2' },
|
|
39
|
+
{ label: 'asia-northeast3 (Seoul)', value: 'asia-northeast3' },
|
|
40
|
+
{ label: 'asia-south1 (Mumbai)', value: 'asia-south1' },
|
|
41
|
+
{ label: 'asia-south2 (Delhi)', value: 'asia-south2' },
|
|
42
|
+
{ label: 'asia-southeast1 (Singapore)', value: 'asia-southeast1' },
|
|
43
|
+
{ label: 'asia-southeast2 (Jakarta)', value: 'asia-southeast2' },
|
|
44
|
+
{ label: 'australia-southeast1 (Sydney)', value: 'australia-southeast1' },
|
|
45
|
+
{ label: 'australia-southeast2 (Melbourne)', value: 'australia-southeast2' },
|
|
46
|
+
];
|
|
47
|
+
function parseCredentials(auth) {
|
|
48
|
+
var _a;
|
|
49
|
+
const raw = JSON.parse(auth.props.serviceAccountJson);
|
|
50
|
+
return Object.assign(Object.assign({}, raw), { private_key: (_a = raw.private_key) === null || _a === void 0 ? void 0 : _a.replace(/\\n/g, '\n') });
|
|
51
|
+
}
|
|
52
|
+
function buildGenAIClient(credentials, location) {
|
|
53
|
+
return new genai_1.GoogleGenAI({
|
|
54
|
+
vertexai: true,
|
|
55
|
+
project: credentials['project_id'],
|
|
56
|
+
location,
|
|
57
|
+
googleAuthOptions: {
|
|
58
|
+
credentials,
|
|
59
|
+
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function fetchVertexAIModels(auth, location, nameFilter) {
|
|
64
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
var _a, e_1, _b, _c;
|
|
66
|
+
var _d, _e;
|
|
67
|
+
const credentials = parseCredentials(auth);
|
|
68
|
+
const ai = buildGenAIClient(credentials, location);
|
|
69
|
+
const options = [];
|
|
70
|
+
const pager = yield ai.models.list({ config: { queryBase: true } });
|
|
71
|
+
try {
|
|
72
|
+
for (var _f = true, pager_1 = tslib_1.__asyncValues(pager), pager_1_1; pager_1_1 = yield pager_1.next(), _a = pager_1_1.done, !_a; _f = true) {
|
|
73
|
+
_c = pager_1_1.value;
|
|
74
|
+
_f = false;
|
|
75
|
+
const model = _c;
|
|
76
|
+
if (!((_d = model.name) === null || _d === void 0 ? void 0 : _d.toLowerCase().includes(nameFilter)))
|
|
77
|
+
continue;
|
|
78
|
+
const modelId = model.name.replace(/^(publishers\/google\/models\/|models\/)/, '');
|
|
79
|
+
options.push({ label: (_e = model.displayName) !== null && _e !== void 0 ? _e : modelId, value: modelId });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
83
|
+
finally {
|
|
84
|
+
try {
|
|
85
|
+
if (!_f && !_a && (_b = pager_1.return)) yield _b.call(pager_1);
|
|
86
|
+
}
|
|
87
|
+
finally { if (e_1) throw e_1.error; }
|
|
88
|
+
}
|
|
89
|
+
return options;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function getVertexAILocationOptions(auth) {
|
|
93
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
var _a;
|
|
95
|
+
if (!auth) {
|
|
96
|
+
return { disabled: true, placeholder: 'Connect your account first', options: [] };
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const credentials = parseCredentials(auth);
|
|
100
|
+
const googleAuth = new google_auth_library_1.GoogleAuth({
|
|
101
|
+
credentials,
|
|
102
|
+
projectId: credentials['project_id'],
|
|
103
|
+
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
|
|
104
|
+
});
|
|
105
|
+
const accessToken = yield googleAuth.getAccessToken();
|
|
106
|
+
if (!accessToken)
|
|
107
|
+
throw new Error('Failed to obtain access token');
|
|
108
|
+
const response = yield pieces_common_1.httpClient.sendRequest({
|
|
109
|
+
method: pieces_common_1.HttpMethod.GET,
|
|
110
|
+
url: `https://aiplatform.googleapis.com/v1/projects/${credentials['project_id']}/locations`,
|
|
111
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
112
|
+
});
|
|
113
|
+
const options = ((_a = response.body.locations) !== null && _a !== void 0 ? _a : []).map((loc) => ({
|
|
114
|
+
label: loc.locationId,
|
|
115
|
+
value: loc.locationId,
|
|
116
|
+
}));
|
|
117
|
+
if (options.length > 0) {
|
|
118
|
+
return { disabled: false, options };
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
catch (_b) {
|
|
122
|
+
// fall through to static list
|
|
123
|
+
}
|
|
124
|
+
return { disabled: false, options: VERTEX_AI_LOCATIONS };
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
function getVertexAIModelOptions(auth, location) {
|
|
128
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
if (!auth) {
|
|
130
|
+
return { disabled: true, placeholder: 'Connect your account first', options: [] };
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
const options = yield fetchVertexAIModels(auth, location !== null && location !== void 0 ? location : 'us-central1', 'gemini');
|
|
134
|
+
return { disabled: false, options };
|
|
135
|
+
}
|
|
136
|
+
catch (_a) {
|
|
137
|
+
return {
|
|
138
|
+
disabled: true,
|
|
139
|
+
options: [],
|
|
140
|
+
placeholder: "Couldn't load models. Check your credentials or location.",
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function getVertexAIImageModelOptions(auth, location) {
|
|
146
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
if (!auth) {
|
|
148
|
+
return { disabled: true, placeholder: 'Connect your account first', options: [] };
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
const options = yield fetchVertexAIModels(auth, location !== null && location !== void 0 ? location : 'us-central1', 'imagen');
|
|
152
|
+
return { disabled: false, options };
|
|
153
|
+
}
|
|
154
|
+
catch (_a) {
|
|
155
|
+
return {
|
|
156
|
+
disabled: true,
|
|
157
|
+
options: [],
|
|
158
|
+
placeholder: "Couldn't load models. Check your credentials or location.",
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/lib/common.ts"],"names":[],"mappings":";;AAuFA,gEAmCC;AAED,0DAiBC;AAED,oEAiBC;;AAhKD,yCAA4C;AAC5C,+DAAqE;AACrE,6DAAiD;AAGjD,MAAM,mBAAmB,GAAG;IAC1B,EAAE,KAAK,EAAE,oBAAoB,EAAE,KAAK,EAAE,aAAa,EAAE;IACrD,EAAE,KAAK,EAAE,2BAA2B,EAAE,KAAK,EAAE,UAAU,EAAE;IACzD,EAAE,KAAK,EAAE,8BAA8B,EAAE,KAAK,EAAE,UAAU,EAAE;IAC5D,EAAE,KAAK,EAAE,qBAAqB,EAAE,KAAK,EAAE,UAAU,EAAE;IACnD,EAAE,KAAK,EAAE,oBAAoB,EAAE,KAAK,EAAE,WAAW,EAAE;IACnD,EAAE,KAAK,EAAE,mBAAmB,EAAE,KAAK,E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