@avalant/piece-promptx-gemini 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/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # pieces-promptx-gemini
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build pieces-promptx-gemini` to build the library.
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@avalant/piece-promptx-gemini",
3
+ "version": "0.0.1",
4
+ "type": "commonjs",
5
+ "main": "./src/index.js",
6
+ "types": "./src/index.d.ts",
7
+ "dependencies": {
8
+ "@ai-sdk/anthropic": "1.2.12",
9
+ "@ai-sdk/google": "1.2.19",
10
+ "@ai-sdk/openai": "1.3.22",
11
+ "@ai-sdk/replicate": "0.2.8",
12
+ "@google/generative-ai": "0.21.0",
13
+ "@sinclair/typebox": "0.34.11",
14
+ "ai": "4.3.16",
15
+ "axios": "1.8.3",
16
+ "axios-retry": "4.4.1",
17
+ "deepmerge-ts": "7.1.0",
18
+ "fast-glob": "3.3.3",
19
+ "mime-types": "2.1.35",
20
+ "nanoid": "3.3.8",
21
+ "semver": "7.6.0",
22
+ "zod": "3.25.76",
23
+ "@activepieces/pieces-common": "0.6.0",
24
+ "@activepieces/pieces-framework": "0.15.0",
25
+ "@activepieces/shared": "0.17.2",
26
+ "tslib": "2.8.1"
27
+ },
28
+ "overrides": {
29
+ "@tryfabric/martian": {
30
+ "@notionhq/client": "$@notionhq/client"
31
+ },
32
+ "vite": {
33
+ "rollup": "npm:@rollup/wasm-node"
34
+ }
35
+ },
36
+ "resolutions": {
37
+ "rollup": "npm:@rollup/wasm-node"
38
+ }
39
+ }
@@ -0,0 +1,34 @@
1
+ {
2
+ "Google Gemini": "Google Gemini",
3
+ "Talk to Google Gemini using your available PromptX credits. Use the many tools Gemini has to offer using your PromptX credits per request": "Talk to Google Gemini using your available PromptX credits. Use the many tools Gemini has to offer using your PromptX credits per request",
4
+ "\nFollow these instructions to get your API Key:\n1. Visit the following website: https://makersuite.google.com/app/apikey\n2. Once on the website, locate and click on the option to obtain your API Key.\nPlease note this piece uses a API in the beta phase that may change at any time.\n": "\nFollow these instructions to get your API Key:\n1. Visit the following website: https://makersuite.google.com/app/apikey\n2. Once on the website, locate and click on the option to obtain your API Key.\nPlease note this piece uses a API in the beta phase that may change at any time.\n",
5
+ "Generate Content": "Generate Content",
6
+ "Generate Content from Image": "Generate Content from Image",
7
+ "Chat Gemini": "Chat Gemini",
8
+ "Custom API Call": "Custom API Call",
9
+ "Generate content using Google Gemini using the \"gemini-pro\" model": "Generate content using Google Gemini using the \"gemini-pro\" model",
10
+ "Generate content using Google Gemini using the \"gemini-pro-vision\" model": "Generate content using Google Gemini using the \"gemini-pro-vision\" model",
11
+ "Chat with Google Gemini": "Chat with Google Gemini",
12
+ "Make a custom API call to a specific endpoint": "Make a custom API call to a specific endpoint",
13
+ "Prompt": "Prompt",
14
+ "Model": "Model",
15
+ "Image": "Image",
16
+ "Memory Key": "Memory Key",
17
+ "Method": "Method",
18
+ "Headers": "Headers",
19
+ "Query Parameters": "Query Parameters",
20
+ "Body": "Body",
21
+ "No Error on Failure": "No Error on Failure",
22
+ "Timeout (in seconds)": "Timeout (in seconds)",
23
+ "The prompt to generate content from.": "The prompt to generate content from.",
24
+ "The model which will generate the completion": "The model which will generate the completion",
25
+ "The image to generate content from.": "The image to generate content from.",
26
+ "A memory key that will keep the chat history. Keep it empty to leave Gemini without memory of previous messages.": "A memory key that will keep the chat history. Keep it empty to leave Gemini without memory of previous messages.",
27
+ "Authorization headers are injected automatically from your connection.": "Authorization headers are injected automatically from your connection.",
28
+ "GET": "GET",
29
+ "POST": "POST",
30
+ "PATCH": "PATCH",
31
+ "PUT": "PUT",
32
+ "DELETE": "DELETE",
33
+ "HEAD": "HEAD"
34
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export declare const googleGeminiAuth: import("@activepieces/pieces-framework").CustomAuthProperty<{
2
+ server: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
3
+ username: import("@activepieces/pieces-framework").ShortTextProperty<true>;
4
+ password: import("@activepieces/pieces-framework").SecretTextProperty<true>;
5
+ }>;
6
+ export declare const googleGemini: import("@activepieces/pieces-framework").Piece<import("@activepieces/pieces-framework").CustomAuthProperty<{
7
+ server: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
8
+ username: import("@activepieces/pieces-framework").ShortTextProperty<true>;
9
+ password: import("@activepieces/pieces-framework").SecretTextProperty<true>;
10
+ }>>;
package/src/index.js ADDED
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.googleGemini = exports.googleGeminiAuth = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const pieces_framework_1 = require("@activepieces/pieces-framework");
6
+ const shared_1 = require("@activepieces/shared");
7
+ const chat_gemini_action_1 = require("./lib/actions/chat-gemini.action");
8
+ const generate_content_from_image_action_1 = require("./lib/actions/generate-content-from-image.action");
9
+ const generate_content_action_1 = require("./lib/actions/generate-content.action");
10
+ const pmtx_api_1 = require("./lib/common/pmtx-api");
11
+ exports.googleGeminiAuth = pieces_framework_1.PieceAuth.CustomAuth({
12
+ required: true,
13
+ props: {
14
+ server: pieces_framework_1.Property.StaticDropdown({
15
+ displayName: 'Server',
16
+ options: {
17
+ options: [
18
+ {
19
+ label: 'Production',
20
+ value: 'production',
21
+ },
22
+ {
23
+ label: 'Test',
24
+ value: 'staging',
25
+ },
26
+ ],
27
+ },
28
+ required: true,
29
+ defaultValue: 'production',
30
+ }),
31
+ username: pieces_framework_1.Property.ShortText({
32
+ displayName: 'Username',
33
+ description: 'PromptX username',
34
+ required: true,
35
+ }),
36
+ password: pieces_framework_1.PieceAuth.SecretText({
37
+ displayName: 'Password',
38
+ description: 'PromptX password',
39
+ required: true,
40
+ }),
41
+ },
42
+ validate: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
43
+ const { username, password } = auth;
44
+ if (!username || !password) {
45
+ return {
46
+ valid: false,
47
+ error: 'Empty Username or Password',
48
+ };
49
+ }
50
+ const loginUrl = pmtx_api_1.baseUrlMap[auth.server].loginUrl;
51
+ const isStaging = auth.server === 'staging';
52
+ const body = isStaging
53
+ ? new URLSearchParams({ username, password }).toString()
54
+ : JSON.stringify({ username, password });
55
+ const headers = {
56
+ 'Content-Type': isStaging
57
+ ? 'application/x-www-form-urlencoded'
58
+ : 'application/json',
59
+ };
60
+ const response = yield fetch(loginUrl, {
61
+ method: 'POST',
62
+ body,
63
+ headers,
64
+ });
65
+ if (response.status === 200) {
66
+ return {
67
+ valid: true,
68
+ };
69
+ }
70
+ else {
71
+ const data = yield response.json();
72
+ return {
73
+ valid: false,
74
+ error: (data === null || data === void 0 ? void 0 : data.error) || (data === null || data === void 0 ? void 0 : data.message),
75
+ };
76
+ }
77
+ }),
78
+ });
79
+ exports.googleGemini = (0, pieces_framework_1.createPiece)({
80
+ displayName: 'PromptX Google Gemini',
81
+ auth: exports.googleGeminiAuth,
82
+ description: 'Talk to Google Gemini using your available PromptX credits. Use the many tools Gemini has to offer using your PromptX credits per request',
83
+ minimumSupportedRelease: '0.63.0',
84
+ logoUrl: 'https://cdn.activepieces.com/pieces/google-gemini.png',
85
+ categories: [shared_1.PieceCategory.ARTIFICIAL_INTELLIGENCE],
86
+ authors: ['tumrabert'],
87
+ actions: [generate_content_action_1.generateContentAction, generate_content_from_image_action_1.generateContentFromImageAction, chat_gemini_action_1.chatGemini],
88
+ triggers: [],
89
+ });
90
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/pieces/community/promptx-gemini/src/index.ts"],"names":[],"mappings":";;;;AAAA,qEAIwC;AACxC,iDAAqD;AACrD,yEAA8D;AAC9D,yGAAkG;AAClG,mFAA8E;AAC9E,oDAAmD;AAEtC,QAAA,gBAAgB,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EAAE,QAAQ,EAAE,CAAC,CAAC;QAC3C,MAAM,OAAO,GAAG;YACd,cAAc,EAAE,SAAS;gBACvB,CAAC,CAAC,mCAAmC;gBACrC,CAAC,CAAC,kBAAkB;SACvB,CAAC;QAEF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,QAAQ,EAAE;YACrC,MAAM,EAAE,MAAM;YACd,IAAI;YACJ,OAAO;SACR,CAAC,CAAC;QAEH,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YAC5B,OAAO;gBACL,KAAK,EAAE,IAAI;aACZ,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnC,OAAO;gBACL,KAAK,EAAE,KAAK;gBACZ,KAAK,EAAE,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,MAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,CAAA;aACpC,CAAC;QACJ,CAAC;IACH,CAAC,CAAA;CACF,CAAC,CAAC;AACU,QAAA,YAAY,GAAG,IAAA,8BAAW,EAAC;IACtC,WAAW,EAAE,uBAAuB;IACpC,IAAI,EAAE,wBAAgB;IACtB,WAAW,EAAE,2IAA2I;IACxJ,uBAAuB,EAAE,QAAQ;IACjC,OAAO,EAAE,uDAAuD;IAChE,UAAU,EAAE,CAAC,sBAAa,CAAC,uBAAuB,CAAC;IACnD,OAAO,EAAE,CAAC,WAAW,CAAC;IACtB,OAAO,EAAE,CAAC,+CAAqB,EAAE,mEAA8B,EAAE,+BAAU,CAAC;IAC5E,QAAQ,EAAE,EAAE;CACb,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ export declare const chatGemini: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").CustomAuthProperty<{
2
+ server: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
3
+ username: import("@activepieces/pieces-framework").ShortTextProperty<true>;
4
+ password: import("@activepieces/pieces-framework").SecretTextProperty<true>;
5
+ }>, {
6
+ model: import("@activepieces/pieces-framework").DropdownProperty<string, true>;
7
+ prompt: import("@activepieces/pieces-framework").LongTextProperty<true>;
8
+ memoryKey: import("@activepieces/pieces-framework").ShortTextProperty<false>;
9
+ }>;
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.chatGemini = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const generative_ai_1 = require("@google/generative-ai");
6
+ const pieces_framework_1 = require("@activepieces/pieces-framework");
7
+ const zod_1 = require("zod");
8
+ const index_1 = require("../../index");
9
+ const common_1 = require("../common/common");
10
+ const pieces_common_1 = require("@activepieces/pieces-common");
11
+ const pmtx_api_1 = require("../common/pmtx-api");
12
+ exports.chatGemini = (0, pieces_framework_1.createAction)({
13
+ auth: index_1.googleGeminiAuth,
14
+ name: 'chat_gemini',
15
+ displayName: 'Chat Gemini',
16
+ description: 'Chat with Google Gemini',
17
+ props: {
18
+ model: pieces_framework_1.Property.Dropdown({
19
+ displayName: 'Model',
20
+ required: true,
21
+ description: 'The model which will generate the completion',
22
+ refreshers: [],
23
+ defaultValue: common_1.defaultLLM,
24
+ options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
25
+ let geminiKey;
26
+ try {
27
+ geminiKey = String(yield (0, pmtx_api_1.getApiKeyFormAuth)(auth));
28
+ }
29
+ catch (error) {
30
+ console.error(error);
31
+ return {
32
+ disabled: true,
33
+ placeholder: 'Unable to fetch OpenAI key. Check connection',
34
+ options: [],
35
+ };
36
+ }
37
+ return (0, common_1.getGeminiModelOptions)({ auth: geminiKey });
38
+ }),
39
+ }),
40
+ prompt: pieces_framework_1.Property.LongText({
41
+ displayName: 'Prompt',
42
+ required: true,
43
+ description: 'The prompt to generate content from.',
44
+ }),
45
+ memoryKey: pieces_framework_1.Property.ShortText({
46
+ displayName: 'Memory Key',
47
+ description: 'A memory key that will keep the chat history. Keep it empty to leave Gemini without memory of previous messages.',
48
+ required: false,
49
+ }),
50
+ },
51
+ run(_a) {
52
+ return tslib_1.__awaiter(this, arguments, void 0, function* ({ auth, propsValue, store }) {
53
+ yield pieces_common_1.propsValidation.validateZod(propsValue, {
54
+ memoryKey: zod_1.z.string().max(128).optional(),
55
+ });
56
+ const { model, prompt, memoryKey } = propsValue;
57
+ const geminiKey = yield (0, pmtx_api_1.getApiKeyFormAuth)(auth);
58
+ const genAI = new generative_ai_1.GoogleGenerativeAI(geminiKey);
59
+ const geminiModel = genAI.getGenerativeModel({ model });
60
+ let history = [];
61
+ if (memoryKey) {
62
+ const storedHistory = yield store.get(memoryKey, pieces_framework_1.StoreScope.PROJECT);
63
+ if (Array.isArray(storedHistory)) {
64
+ history = storedHistory;
65
+ }
66
+ }
67
+ const chat = geminiModel.startChat({
68
+ history: history,
69
+ });
70
+ const result = yield chat.sendMessage(prompt);
71
+ const responseText = result.response.text();
72
+ if (memoryKey) {
73
+ const updatedHistory = yield chat.getHistory();
74
+ yield store.put(memoryKey, updatedHistory, pieces_framework_1.StoreScope.PROJECT);
75
+ }
76
+ return {
77
+ response: responseText,
78
+ history: history,
79
+ };
80
+ });
81
+ },
82
+ });
83
+ //# sourceMappingURL=chat-gemini.action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat-gemini.action.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/promptx-gemini/src/lib/actions/chat-gemini.action.ts"],"names":[],"mappings":";;;;AAAA,yDAAoE;AACpE,qEAIwC;AACxC,6BAAwB;AACxB,uCAA+C;AAC/C,6CAAqE;AACrE,+DAA8D;AAC9D,iDAAwE;AAE3D,QAAA,UAAU,GAAG,IAAA,+BAAY,EAAC;IACrC,IAAI,EAAE,wBAAgB;IACtB,IAAI,EAAE,aAAa;IACnB,WAAW,EAAE,aAAa;IAC1B,WAAW,EAAE,yBAAyB;IACtC,KAAK,EAAE;QACL,KAAK,EAAE,2BAAQ,CAAC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AAA,4BAAiB,EAAC,IAAuB,CAAC,CAAC;YAC3E,MAAM,KAAK,GAAG,IAAI,kCAAkB,CAAC,SAAS,CAAC,CAAC;YAChD,MAAM,WAAW,GAAG,KAAK,CAAC,kBAAkB,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;YACxD,IAAI,OAAO,GAAc,EAAE,CAAC;YAE5B,IAAI,SAAS,EAAE,CAAC;gBACd,MAAM,aAAa,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,SAAS,EAAE,6BAAU,CAAC,OAAO,CAAC,CAAC;gBACrE,IAAI,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC;oBACjC,OAAO,GAAG,aAAa,CAAC;gBAC1B,CAAC;YACH,CAAC;YAED,MAAM,IAAI,GAAG,WAAW,CAAC,SAAS,CAAC;gBACjC,OAAO,EAAE,OAAO;aACjB,CAAC,CAAC;YAEH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;YAC9C,MAAM,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;YAE5C,IAAI,SAAS,EAAE,CAAC;gBACd,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;gBAC/C,MAAM,KAAK,CAAC,GAAG,CAAC,SAAS,EAAE,cAAc,EAAE,6BAAU,CAAC,OAAO,CAAC,CAAC;YACjE,CAAC;YAED,OAAO;gBACL,QAAQ,EAAE,YAAY;gBACtB,OAAO,EAAE,OAAO;aACjB,CAAC;QACJ,CAAC;KAAA;CACF,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ export declare const generateContentFromImageAction: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").CustomAuthProperty<{
2
+ server: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
3
+ username: import("@activepieces/pieces-framework").ShortTextProperty<true>;
4
+ password: import("@activepieces/pieces-framework").SecretTextProperty<true>;
5
+ }>, {
6
+ prompt: import("@activepieces/pieces-framework").LongTextProperty<true>;
7
+ image: import("@activepieces/pieces-framework").FileProperty<true>;
8
+ model: import("@activepieces/pieces-framework").DropdownProperty<string, true>;
9
+ }>;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateContentFromImageAction = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs_1 = require("fs");
6
+ const os_1 = require("os");
7
+ const path_1 = require("path");
8
+ const generative_ai_1 = require("@google/generative-ai");
9
+ const server_1 = require("@google/generative-ai/server");
10
+ const nanoid_1 = require("nanoid");
11
+ const pieces_framework_1 = require("@activepieces/pieces-framework");
12
+ const index_1 = require("../../index");
13
+ const common_1 = require("../common/common");
14
+ const pmtx_api_1 = require("../common/pmtx-api");
15
+ exports.generateContentFromImageAction = (0, pieces_framework_1.createAction)({
16
+ description: 'Generate content using Google Gemini using the "gemini-pro-vision" model',
17
+ displayName: 'Generate Content from Image',
18
+ name: 'generate_content_from_image',
19
+ auth: index_1.googleGeminiAuth,
20
+ props: {
21
+ prompt: pieces_framework_1.Property.LongText({
22
+ displayName: 'Prompt',
23
+ required: true,
24
+ description: 'The prompt to generate content from.',
25
+ }),
26
+ image: pieces_framework_1.Property.File({
27
+ displayName: 'Image',
28
+ required: true,
29
+ description: 'The image to generate content from.',
30
+ }),
31
+ model: pieces_framework_1.Property.Dropdown({
32
+ displayName: 'Model',
33
+ required: true,
34
+ description: 'The model which will generate the completion',
35
+ refreshers: [],
36
+ defaultValue: common_1.defaultLLM,
37
+ options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
38
+ let geminiKey;
39
+ try {
40
+ geminiKey = String(yield (0, pmtx_api_1.getApiKeyFormAuth)(auth));
41
+ }
42
+ catch (error) {
43
+ console.error(error);
44
+ return {
45
+ disabled: true,
46
+ placeholder: 'Unable to fetch OpenAI key. Check connection',
47
+ options: [],
48
+ };
49
+ }
50
+ return (0, common_1.getGeminiModelOptions)({ auth: geminiKey });
51
+ }),
52
+ }),
53
+ },
54
+ run(_a) {
55
+ return tslib_1.__awaiter(this, arguments, void 0, function* ({ auth, propsValue }) {
56
+ const tempFilePath = (0, path_1.join)((0, os_1.tmpdir)(), `gemini-image-${(0, nanoid_1.nanoid)()}.${propsValue.image.extension}`);
57
+ try {
58
+ const imageBuffer = Buffer.from(propsValue.image.base64, 'base64');
59
+ yield fs_1.promises.writeFile(tempFilePath, imageBuffer);
60
+ const geminiKey = yield (0, pmtx_api_1.getApiKeyFormAuth)(auth);
61
+ const fileManager = new server_1.GoogleAIFileManager(geminiKey);
62
+ const uploadResult = yield fileManager.uploadFile(tempFilePath, {
63
+ mimeType: `image/${propsValue.image.extension}`,
64
+ displayName: propsValue.image.filename,
65
+ });
66
+ const genAI = new generative_ai_1.GoogleGenerativeAI(geminiKey);
67
+ const model = genAI.getGenerativeModel({ model: propsValue.model });
68
+ const result = yield model.generateContent([
69
+ propsValue.prompt,
70
+ {
71
+ fileData: {
72
+ fileUri: uploadResult.file.uri,
73
+ mimeType: uploadResult.file.mimeType,
74
+ },
75
+ },
76
+ ]);
77
+ const response = yield result.response;
78
+ return {
79
+ text: response.text(),
80
+ raw: response,
81
+ };
82
+ }
83
+ catch (error) {
84
+ console.error('Error in generate content from image:', error);
85
+ throw error;
86
+ }
87
+ finally {
88
+ yield fs_1.promises.unlink(tempFilePath).catch(() => void 0);
89
+ }
90
+ });
91
+ },
92
+ });
93
+ //# sourceMappingURL=generate-content-from-image.action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-content-from-image.action.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/promptx-gemini/src/lib/actions/generate-content-from-image.action.ts"],"names":[],"mappings":";;;;AAAA,2BAAoC;AACpC,2BAA4B;AAC5B,+BAA4B;AAC5B,yDAA2D;AAC3D,yDAAmE;AACnE,mCAAgC;AAChC,qEAAwE;AACxE,uCAA+C;AAC/C,6CAAqE;AACrE,i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,CAAC,uCAAuC,EAAE,KAAK,CAAC,CAAC;gBAC9D,MAAM,KAAK,CAAC;YACd,CAAC;oBAAS,CAAC;gBACT,MAAM,aAAE,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;KAAA;CACF,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ export declare const generateContentAction: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").CustomAuthProperty<{
2
+ server: import("@activepieces/pieces-framework").StaticDropdownProperty<string, true>;
3
+ username: import("@activepieces/pieces-framework").ShortTextProperty<true>;
4
+ password: import("@activepieces/pieces-framework").SecretTextProperty<true>;
5
+ }>, {
6
+ prompt: import("@activepieces/pieces-framework").LongTextProperty<true>;
7
+ model: import("@activepieces/pieces-framework").DropdownProperty<string, true>;
8
+ }>;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateContentAction = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const index_1 = require("../../index");
6
+ const pieces_framework_1 = require("@activepieces/pieces-framework");
7
+ const generative_ai_1 = require("@google/generative-ai");
8
+ const pmtx_api_1 = require("../common/pmtx-api");
9
+ const common_1 = require("../common/common");
10
+ exports.generateContentAction = (0, pieces_framework_1.createAction)({
11
+ description: 'Generate content using Google Gemini using the "gemini-pro" model',
12
+ displayName: 'Generate Content',
13
+ name: 'generate_content',
14
+ auth: index_1.googleGeminiAuth,
15
+ props: {
16
+ prompt: pieces_framework_1.Property.LongText({
17
+ displayName: 'Prompt',
18
+ required: true,
19
+ description: 'The prompt to generate content from.',
20
+ }),
21
+ model: pieces_framework_1.Property.Dropdown({
22
+ displayName: 'Model',
23
+ required: true,
24
+ description: 'The model which will generate the completion',
25
+ refreshers: [],
26
+ defaultValue: common_1.defaultLLM,
27
+ options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
28
+ let geminiKey;
29
+ try {
30
+ geminiKey = String(yield (0, pmtx_api_1.getApiKeyFormAuth)(auth));
31
+ }
32
+ catch (error) {
33
+ console.error(error);
34
+ return {
35
+ disabled: true,
36
+ placeholder: 'Unable to fetch OpenAI key. Check connection',
37
+ options: [],
38
+ };
39
+ }
40
+ return (0, common_1.getGeminiModelOptions)({ auth: geminiKey });
41
+ }),
42
+ }),
43
+ },
44
+ run(_a) {
45
+ return tslib_1.__awaiter(this, arguments, void 0, function* ({ auth, propsValue }) {
46
+ const geminiKey = yield (0, pmtx_api_1.getApiKeyFormAuth)(auth);
47
+ const genAI = new generative_ai_1.GoogleGenerativeAI(geminiKey);
48
+ const model = genAI.getGenerativeModel({ model: propsValue.model });
49
+ const result = yield model.generateContent(propsValue.prompt);
50
+ return result.response.text();
51
+ });
52
+ },
53
+ });
54
+ //# sourceMappingURL=generate-content.action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-content.action.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/promptx-gemini/src/lib/actions/generate-content.action.ts"],"names":[],"mappings":";;;;AAAA,uCAA+C;AAC/C,qEAAwE;AACxE,yDAA2D;AAC3D,iDAAwE;AACxE,6CAAqE;AAExD,QAAA,qBAAqB,GAAG,IAAA,+BAAY,EAAC;IAChD,WAAW,EACT,mEAAmE;IACrE,WAAW,EAAE,kBAAkB;IAC/B,IAAI,EAAE,kBAAkB;IACxB,IAAI,EAAE,wBAAgB;IACtB,KAAK,EAAE;QACL,MAAM,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YACxB,WAAW,EAAE,QAAQ;YACrB,QAAQ,EAAE,IAAI;YACd,WAAW,EAAE,sCAAsC;SACpD,CAAC;QACF,KAAK,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YACvB,WAAW,EAAE,OAAO;YACpB,QAAQ,EAAE,IAAI;YACd,WAAW,EAAE,8CAA8C;YAC3D,UAAU,EAAE,EAAE;YACd,YAAY,EAAE,mBAAU;YACxB,OAAO,EAAE,KAAiB,EAAE,oDAAZ,EAAE,IAAI,EAAE;gBACtB,IAAI,SAAiB,CAAC;gBACtB,IAAI,CAAC;oBACH,SAAS,GAAG,MAAM,CAAC,MAAM,IAAA,4BAAiB,EAAC,IAAuB,CAAC,CAAC,CAAC;gBACvE,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;oBACrB,OAAO;wBACL,QAAQ,EAAE,IAAI;wBACd,WAAW,EAAE,8CAA8C;wBAC3D,OAAO,EAAE,EAAE;qBACZ,CAAC;gBACJ,CAAC;gBAED,OAAO,IAAA,8BAAqB,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;YACpD,CAAC,CAAA;SACF,CAAC;KACH;IACK,GAAG;qEAAC,EAAE,IAAI,EAAE,UAAU,EAAE;YAC5B,MAAM,SAAS,GAAW,MAAM,IAAA,4BAAiB,EAAC,IAAuB,CAAC,CAAC;YAC3E,MAAM,KAAK,GAAG,IAAI,kCAAkB,CAAC,SAAS,CAAC,CAAC;YAChD,MAAM,KAAK,GAAG,KAAK,CAAC,kBAAkB,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC;YACpE,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,eAAe,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;YAC9D,OAAO,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;QAChC,CAAC;KAAA;CACF,CAAC,CAAC"}
@@ -0,0 +1,16 @@
1
+ export declare const defaultLLM = "gemini-1.5-flash";
2
+ export declare const allowedLLMs: string[];
3
+ export declare const getGeminiModelOptions: ({ auth, }: {
4
+ auth: string | undefined | unknown;
5
+ }) => Promise<{
6
+ disabled: boolean;
7
+ placeholder: string;
8
+ options: never[];
9
+ } | {
10
+ disabled: boolean;
11
+ options: {
12
+ label: string;
13
+ value: string;
14
+ }[];
15
+ placeholder?: undefined;
16
+ }>;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getGeminiModelOptions = exports.allowedLLMs = exports.defaultLLM = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const pieces_common_1 = require("@activepieces/pieces-common");
6
+ exports.defaultLLM = 'gemini-1.5-flash';
7
+ exports.allowedLLMs = [
8
+ 'gemini-1.5-flash',
9
+ 'gemini-1.5-flash-8b',
10
+ 'gemini-1.5-pro',
11
+ 'gemini-2.0-flash',
12
+ 'gemini-2.0-flash-lite',
13
+ 'gemini-2.5-flash',
14
+ 'gemini-2.5-pro',
15
+ ];
16
+ const getGeminiModelOptions = (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth, }) {
17
+ if (!auth) {
18
+ return {
19
+ disabled: true,
20
+ placeholder: 'Enter your API key first',
21
+ options: [],
22
+ };
23
+ }
24
+ try {
25
+ const { body } = yield pieces_common_1.httpClient.sendRequest({
26
+ method: pieces_common_1.HttpMethod.GET,
27
+ url: `https://generativelanguage.googleapis.com/v1beta/models?key=${auth}`,
28
+ });
29
+ const options = body.models
30
+ .filter((model) => exports.allowedLLMs.some((allowed) => model.name.startsWith(`models/${allowed}`)))
31
+ .map((model) => ({
32
+ label: model.displayName,
33
+ value: model.name.replace('models/', ''),
34
+ }));
35
+ return {
36
+ disabled: false,
37
+ options,
38
+ };
39
+ }
40
+ catch (_b) {
41
+ return {
42
+ disabled: true,
43
+ options: [],
44
+ placeholder: "Couldn't load models, API key is invalid",
45
+ };
46
+ }
47
+ });
48
+ exports.getGeminiModelOptions = getGeminiModelOptions;
49
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/promptx-gemini/src/lib/common/common.ts"],"names":[],"mappings":";;;;AAAA,+DAAqE;AAExD,QAAA,UAAU,GAAG,kBAAkB,CAAC;AAE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2
+ export type PromptXAuthType = {
3
+ server: 'production' | 'staging';
4
+ username: string;
5
+ password: string;
6
+ };
7
+ export type AccessTokenResponse = {
8
+ access_token?: string;
9
+ error?: string;
10
+ message?: string;
11
+ };
12
+ type UrlConfig = {
13
+ loginUrl: string;
14
+ quotaCheckUrl: string;
15
+ addTokenUrl: string;
16
+ myProfileUrl: string;
17
+ getAIKeyUrl: string;
18
+ };
19
+ type UsagePackage = {
20
+ package_name: string;
21
+ total_tokens_used: number;
22
+ limit_token_usage: number;
23
+ token_available: number;
24
+ total_credit_used: number;
25
+ limit_credit_usage: number;
26
+ credit_available: number;
27
+ };
28
+ type UserInfo = {
29
+ userIAM2ID: string;
30
+ email: string;
31
+ username: string;
32
+ };
33
+ interface Usage {
34
+ inputTokens: number;
35
+ outputTokens: number;
36
+ totalTokens: number;
37
+ }
38
+ interface AppUsageData {
39
+ appId?: string;
40
+ userId: string;
41
+ model: string;
42
+ projectId: string;
43
+ flowId: string;
44
+ agentId?: string;
45
+ component: string;
46
+ usage: Usage;
47
+ }
48
+ export declare const baseUrlMap: Record<string, UrlConfig>;
49
+ export declare const getAccessToken: ({ server, username, password, }: PromptXAuthType) => Promise<string>;
50
+ export declare const addTokenUsage: (data: AppUsageData, server: "production" | "staging", access_token: string) => Promise<any>;
51
+ export declare const getUsagePlan: (server: "production" | "staging", access_token: string) => Promise<UsagePackage>;
52
+ export declare const getUserProfile: (server: "production" | "staging", access_token: string) => Promise<UserInfo>;
53
+ export declare const getStoreData: (store: Store, server: "production" | "staging", access_token: string) => Promise<{
54
+ userId: unknown;
55
+ apiKey: string;
56
+ }>;
57
+ export declare const getAiApiKey: (server: "production" | "staging", access_token: string) => Promise<string>;
58
+ export declare const getApiKeyFormAuth: (auth: PromptXAuthType) => Promise<string>;
59
+ export {};
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getApiKeyFormAuth = exports.getAiApiKey = exports.getStoreData = exports.getUserProfile = exports.getUsagePlan = exports.addTokenUsage = exports.getAccessToken = exports.baseUrlMap = void 0;
4
+ const tslib_1 = require("tslib");
5
+ exports.baseUrlMap = {
6
+ production: {
7
+ loginUrl: 'https://centerapp.io/center/auth/login',
8
+ quotaCheckUrl: 'https://promptxai.com/zero-service/pmtx-ai-token-api/v1/quota-check',
9
+ addTokenUrl: 'https://promptxai.com/zero-service/pmtx-ai-token-api/v1/token-used',
10
+ myProfileUrl: 'https://centerapp.io/center//api/v1/users/me',
11
+ getAIKeyUrl: 'https://promptxai.com/zero-service/pmtx-ai-token-api/v1/api-key?key=geminiKey',
12
+ },
13
+ staging: {
14
+ loginUrl: 'https://test.oneweb.tech/zero-service/pmtx/login',
15
+ quotaCheckUrl: 'https://test.oneweb.tech/zero-service/pmtx-ai-token-api/v1/quota-check',
16
+ addTokenUrl: 'https://test.oneweb.tech/zero-service/pmtx-ai-token-api/v1/token-used',
17
+ myProfileUrl: 'https://mocha.centerapp.io/center//api/v1/users/me',
18
+ getAIKeyUrl: 'https://test.oneweb.tech/zero-service/pmtx-ai-token-api/v1/api-key?key=geminiKey',
19
+ },
20
+ };
21
+ const getAccessToken = (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ server, username, password, }) {
22
+ const isStaging = server === 'staging';
23
+ const body = isStaging
24
+ ? new URLSearchParams({ username, password }).toString()
25
+ : JSON.stringify({ username, password });
26
+ const headers = {
27
+ 'Content-Type': isStaging
28
+ ? 'application/x-www-form-urlencoded'
29
+ : 'application/json',
30
+ };
31
+ const response = yield fetch(exports.baseUrlMap[server].loginUrl, {
32
+ method: 'POST',
33
+ body,
34
+ headers,
35
+ });
36
+ const data = yield response.json();
37
+ if (response.status !== 200) {
38
+ throw new Error((data === null || data === void 0 ? void 0 : data.error) || (data === null || data === void 0 ? void 0 : data.message));
39
+ }
40
+ if (!data.access_token) {
41
+ throw new Error((data === null || data === void 0 ? void 0 : data.error) || (data === null || data === void 0 ? void 0 : data.message));
42
+ }
43
+ return data.access_token;
44
+ });
45
+ exports.getAccessToken = getAccessToken;
46
+ const addTokenUsage = (data, server, access_token) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
47
+ try {
48
+ const response = yield fetch(exports.baseUrlMap[server]['addTokenUrl'], {
49
+ method: 'POST',
50
+ headers: {
51
+ 'Content-Type': 'application/json',
52
+ Authorization: `Bearer ${access_token}`,
53
+ },
54
+ body: JSON.stringify(data),
55
+ });
56
+ if (response.status !== 200) {
57
+ throw new Error(`API error: ${response.statusText}`);
58
+ }
59
+ const result = yield response.json();
60
+ return result;
61
+ }
62
+ catch (error) {
63
+ console.error('Failed to send token usage:', error);
64
+ throw error;
65
+ }
66
+ });
67
+ exports.addTokenUsage = addTokenUsage;
68
+ const getUsagePlan = (server, access_token) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
69
+ const response = yield fetch(exports.baseUrlMap[server]['quotaCheckUrl'], {
70
+ headers: {
71
+ 'Content-Type': 'application/json',
72
+ Authorization: `Bearer ${access_token}`,
73
+ },
74
+ });
75
+ if (response.status !== 201) {
76
+ throw new Error(`API error: ${response.statusText}`);
77
+ }
78
+ const result = yield response.json();
79
+ return result;
80
+ });
81
+ exports.getUsagePlan = getUsagePlan;
82
+ const getUserProfile = (server, access_token) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
83
+ const response = yield fetch(exports.baseUrlMap[server]['myProfileUrl'], {
84
+ headers: {
85
+ 'Content-Type': 'application/json',
86
+ Authorization: `Bearer ${access_token}`,
87
+ },
88
+ });
89
+ if (response.status !== 200) {
90
+ throw new Error(`API error: ${response.statusText}`);
91
+ }
92
+ const result = yield response.json();
93
+ return result;
94
+ });
95
+ exports.getUserProfile = getUserProfile;
96
+ const getStoreData = (store, server, access_token) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
97
+ // Get store data
98
+ let userId = yield store.get('userId');
99
+ const apiKey = yield (0, exports.getAiApiKey)(server, access_token);
100
+ if (!userId) {
101
+ const userInfo = yield (0, exports.getUserProfile)(server, access_token);
102
+ store.put('userId', userInfo.userIAM2ID);
103
+ userId = userInfo.userIAM2ID;
104
+ }
105
+ return {
106
+ userId,
107
+ apiKey,
108
+ };
109
+ });
110
+ exports.getStoreData = getStoreData;
111
+ const getAiApiKey = (server, access_token) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
112
+ const response = yield fetch(exports.baseUrlMap[server]['getAIKeyUrl'], {
113
+ headers: {
114
+ 'Content-Type': 'application/json',
115
+ Authorization: `Bearer ${access_token}`,
116
+ },
117
+ });
118
+ if (response.status !== 201) {
119
+ throw new Error(`API error: ${response.statusText}`);
120
+ }
121
+ const result = yield response.json();
122
+ if (!result.geminiKey) {
123
+ throw new Error('No AI Api Key found for Avalant geminiKey');
124
+ }
125
+ return result.geminiKey;
126
+ });
127
+ exports.getAiApiKey = getAiApiKey;
128
+ const getApiKeyFormAuth = (auth) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
129
+ let accessToken;
130
+ let geminiKey;
131
+ try {
132
+ accessToken = yield (0, exports.getAccessToken)(auth);
133
+ geminiKey = yield (0, exports.getAiApiKey)(auth.server, accessToken);
134
+ return geminiKey;
135
+ }
136
+ catch (error) {
137
+ console.error(error);
138
+ throw new Error('Unable to fetch gemini key. Check connection');
139
+ }
140
+ });
141
+ exports.getApiKeyFormAuth = getApiKeyFormAuth;
142
+ //# sourceMappingURL=pmtx-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pmtx-api.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/promptx-gemini/src/lib/common/pmtx-api.ts"],"names":[],"mappings":";;;;AAuDa,QAAA,UAAU,GAA8B;IACnD,UAAU,EAAE;QACV,QAAQ,EAAE,wCAAwC;QAClD,aAAa,EACX,qEAAqE;QACvE,WAAW,EACT,oEAAoE;QACtE,YAAY,EAAE,8CAA8C;QAC5D,WAAW,EACT,+EAA+E;KAClF;IACD,OAAO,EAAE;QACP,QAAQ,EAAE,kDAAkD;QAC5D,aAAa,EACX,wEAAwE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