@openfn/language-gemini 1.0.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/dist/index.cjs ADDED
@@ -0,0 +1,189 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/index.ts
20
+ var src_exports = {};
21
+ __export(src_exports, {
22
+ createClient: () => createClient,
23
+ cursor: () => import_language_common2.cursor,
24
+ dataPath: () => import_language_common2.dataPath,
25
+ dataValue: () => import_language_common2.dataValue,
26
+ dateFns: () => import_language_common2.dateFns,
27
+ deepResearch: () => deepResearch,
28
+ default: () => src_default,
29
+ each: () => import_language_common2.each,
30
+ execute: () => execute2,
31
+ field: () => import_language_common2.field,
32
+ fields: () => import_language_common2.fields,
33
+ fn: () => import_language_common2.fn,
34
+ generateImage: () => generateImage,
35
+ lastReferenceValue: () => import_language_common2.lastReferenceValue,
36
+ merge: () => import_language_common2.merge,
37
+ prompt: () => prompt,
38
+ sourceValue: () => import_language_common2.sourceValue
39
+ });
40
+ module.exports = __toCommonJS(src_exports);
41
+
42
+ // src/Adaptor.ts
43
+ var Adaptor_exports = {};
44
+ __export(Adaptor_exports, {
45
+ createClient: () => createClient,
46
+ cursor: () => import_language_common2.cursor,
47
+ dataPath: () => import_language_common2.dataPath,
48
+ dataValue: () => import_language_common2.dataValue,
49
+ dateFns: () => import_language_common2.dateFns,
50
+ deepResearch: () => deepResearch,
51
+ each: () => import_language_common2.each,
52
+ execute: () => execute2,
53
+ field: () => import_language_common2.field,
54
+ fields: () => import_language_common2.fields,
55
+ fn: () => import_language_common2.fn,
56
+ generateImage: () => generateImage,
57
+ lastReferenceValue: () => import_language_common2.lastReferenceValue,
58
+ merge: () => import_language_common2.merge,
59
+ prompt: () => prompt,
60
+ sourceValue: () => import_language_common2.sourceValue
61
+ });
62
+ var import_genai = require("@google/genai");
63
+
64
+ // src/Utils.ts
65
+ var import_language_common = require("@openfn/language-common");
66
+ var import_util = require("@openfn/language-common/util");
67
+
68
+ // src/Adaptor.ts
69
+ var import_language_common2 = require("@openfn/language-common");
70
+ var client;
71
+ function createClient(state) {
72
+ const { apiKey } = state.configuration;
73
+ client = new import_genai.GoogleGenAI({
74
+ apiKey
75
+ });
76
+ return state;
77
+ }
78
+ function execute2(...operations) {
79
+ const initialState = {
80
+ references: [],
81
+ data: null
82
+ };
83
+ return (state) => {
84
+ return (0, import_language_common.execute)(createClient, ...operations)({
85
+ ...initialState,
86
+ ...state
87
+ });
88
+ };
89
+ }
90
+ function prompt(message, options = {}) {
91
+ return async (state) => {
92
+ const [resolvedMessage, resolvedOpts] = (0, import_util.expandReferences)(
93
+ state,
94
+ message,
95
+ options
96
+ );
97
+ const modelName = resolvedOpts.model || "gemini-2.5-flash-lite";
98
+ const msg = await client.models.generateContent({
99
+ model: modelName,
100
+ contents: resolvedMessage,
101
+ config: resolvedOpts.config
102
+ });
103
+ const text = msg.text;
104
+ console.log("\u221A Prompt operation completed");
105
+ return (0, import_language_common.composeNextState)(state, { response: msg.text });
106
+ };
107
+ }
108
+ function deepResearch(message, options = {}) {
109
+ return async (state) => {
110
+ var _a, _b, _c, _d;
111
+ const [resolvedMessage, resolvedOpts] = (0, import_util.expandReferences)(
112
+ state,
113
+ message,
114
+ options
115
+ );
116
+ const modelName = resolvedOpts.model || "gemini-2.5-flash-lite";
117
+ const tools = resolvedOpts.tools || [{ googleSearch: {} }];
118
+ const msg = await client.models.generateContent({
119
+ model: modelName,
120
+ contents: resolvedMessage,
121
+ config: {
122
+ tools,
123
+ ...resolvedOpts.config
124
+ }
125
+ });
126
+ const text = msg.text;
127
+ console.log("\u221A Deep research operation completed");
128
+ return (0, import_language_common.composeNextState)(state, {
129
+ response: msg.text,
130
+ citations: (_b = (_a = msg.candidates[msg.candidates.length - 1]) == null ? void 0 : _a.groundingMetadata) == null ? void 0 : _b.groundingSupports,
131
+ groundingChunks: (_d = (_c = msg.candidates[msg.candidates.length - 1]) == null ? void 0 : _c.groundingMetadata) == null ? void 0 : _d.groundingChunks
132
+ });
133
+ };
134
+ }
135
+ function generateImage(promptText, options = {}) {
136
+ return async (state) => {
137
+ const [resolvedPrompt, resolvedOpts] = (0, import_util.expandReferences)(
138
+ state,
139
+ promptText,
140
+ options
141
+ );
142
+ const modelName = resolvedOpts.model || "gemini-3-pro-image-preview";
143
+ const result = await client.models.generateContent({
144
+ model: modelName,
145
+ contents: resolvedPrompt,
146
+ config: {
147
+ imageConfig: {
148
+ aspectRatio: resolvedOpts.aspectRatio || "1:1",
149
+ imageSize: resolvedOpts.imageSize || "1K"
150
+ },
151
+ ...resolvedOpts.config
152
+ }
153
+ });
154
+ let base64;
155
+ for (const part of result.candidates[0].content.parts) {
156
+ if (part.text) {
157
+ console.log(part.text);
158
+ } else if (part.inlineData) {
159
+ base64 = part.inlineData.data;
160
+ }
161
+ console.log("\u221A Generate image operation completed");
162
+ return (0, import_language_common.composeNextState)(state, {
163
+ base64
164
+ });
165
+ }
166
+ };
167
+ }
168
+
169
+ // src/index.ts
170
+ var src_default = Adaptor_exports;
171
+ // Annotate the CommonJS export names for ESM import in node:
172
+ 0 && (module.exports = {
173
+ createClient,
174
+ cursor,
175
+ dataPath,
176
+ dataValue,
177
+ dateFns,
178
+ deepResearch,
179
+ each,
180
+ execute,
181
+ field,
182
+ fields,
183
+ fn,
184
+ generateImage,
185
+ lastReferenceValue,
186
+ merge,
187
+ prompt,
188
+ sourceValue
189
+ });
package/dist/index.js ADDED
@@ -0,0 +1,169 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/Adaptor.ts
8
+ var Adaptor_exports = {};
9
+ __export(Adaptor_exports, {
10
+ createClient: () => createClient,
11
+ cursor: () => cursor,
12
+ dataPath: () => dataPath,
13
+ dataValue: () => dataValue,
14
+ dateFns: () => dateFns,
15
+ deepResearch: () => deepResearch,
16
+ each: () => each,
17
+ execute: () => execute2,
18
+ field: () => field,
19
+ fields: () => fields,
20
+ fn: () => fn,
21
+ generateImage: () => generateImage,
22
+ lastReferenceValue: () => lastReferenceValue,
23
+ merge: () => merge,
24
+ prompt: () => prompt,
25
+ sourceValue: () => sourceValue
26
+ });
27
+ import { GoogleGenAI } from "@google/genai";
28
+
29
+ // src/Utils.ts
30
+ import {
31
+ execute,
32
+ composeNextState
33
+ } from "@openfn/language-common";
34
+ import { expandReferences } from "@openfn/language-common/util";
35
+
36
+ // src/Adaptor.ts
37
+ import {
38
+ dataPath,
39
+ dataValue,
40
+ dateFns,
41
+ cursor,
42
+ each,
43
+ field,
44
+ fields,
45
+ fn,
46
+ lastReferenceValue,
47
+ merge,
48
+ sourceValue
49
+ } from "@openfn/language-common";
50
+ var client;
51
+ function createClient(state) {
52
+ const { apiKey } = state.configuration;
53
+ client = new GoogleGenAI({
54
+ apiKey
55
+ });
56
+ return state;
57
+ }
58
+ function execute2(...operations) {
59
+ const initialState = {
60
+ references: [],
61
+ data: null
62
+ };
63
+ return (state) => {
64
+ return execute(createClient, ...operations)({
65
+ ...initialState,
66
+ ...state
67
+ });
68
+ };
69
+ }
70
+ function prompt(message, options = {}) {
71
+ return async (state) => {
72
+ const [resolvedMessage, resolvedOpts] = expandReferences(
73
+ state,
74
+ message,
75
+ options
76
+ );
77
+ const modelName = resolvedOpts.model || "gemini-2.5-flash-lite";
78
+ const msg = await client.models.generateContent({
79
+ model: modelName,
80
+ contents: resolvedMessage,
81
+ config: resolvedOpts.config
82
+ });
83
+ const text = msg.text;
84
+ console.log("\u221A Prompt operation completed");
85
+ return composeNextState(state, { response: msg.text });
86
+ };
87
+ }
88
+ function deepResearch(message, options = {}) {
89
+ return async (state) => {
90
+ var _a, _b, _c, _d;
91
+ const [resolvedMessage, resolvedOpts] = expandReferences(
92
+ state,
93
+ message,
94
+ options
95
+ );
96
+ const modelName = resolvedOpts.model || "gemini-2.5-flash-lite";
97
+ const tools = resolvedOpts.tools || [{ googleSearch: {} }];
98
+ const msg = await client.models.generateContent({
99
+ model: modelName,
100
+ contents: resolvedMessage,
101
+ config: {
102
+ tools,
103
+ ...resolvedOpts.config
104
+ }
105
+ });
106
+ const text = msg.text;
107
+ console.log("\u221A Deep research operation completed");
108
+ return composeNextState(state, {
109
+ response: msg.text,
110
+ citations: (_b = (_a = msg.candidates[msg.candidates.length - 1]) == null ? void 0 : _a.groundingMetadata) == null ? void 0 : _b.groundingSupports,
111
+ groundingChunks: (_d = (_c = msg.candidates[msg.candidates.length - 1]) == null ? void 0 : _c.groundingMetadata) == null ? void 0 : _d.groundingChunks
112
+ });
113
+ };
114
+ }
115
+ function generateImage(promptText, options = {}) {
116
+ return async (state) => {
117
+ const [resolvedPrompt, resolvedOpts] = expandReferences(
118
+ state,
119
+ promptText,
120
+ options
121
+ );
122
+ const modelName = resolvedOpts.model || "gemini-3-pro-image-preview";
123
+ const result = await client.models.generateContent({
124
+ model: modelName,
125
+ contents: resolvedPrompt,
126
+ config: {
127
+ imageConfig: {
128
+ aspectRatio: resolvedOpts.aspectRatio || "1:1",
129
+ imageSize: resolvedOpts.imageSize || "1K"
130
+ },
131
+ ...resolvedOpts.config
132
+ }
133
+ });
134
+ let base64;
135
+ for (const part of result.candidates[0].content.parts) {
136
+ if (part.text) {
137
+ console.log(part.text);
138
+ } else if (part.inlineData) {
139
+ base64 = part.inlineData.data;
140
+ }
141
+ console.log("\u221A Generate image operation completed");
142
+ return composeNextState(state, {
143
+ base64
144
+ });
145
+ }
146
+ };
147
+ }
148
+
149
+ // src/index.ts
150
+ var src_default = Adaptor_exports;
151
+ export {
152
+ createClient,
153
+ cursor,
154
+ dataPath,
155
+ dataValue,
156
+ dateFns,
157
+ deepResearch,
158
+ src_default as default,
159
+ each,
160
+ execute2 as execute,
161
+ field,
162
+ fields,
163
+ fn,
164
+ generateImage,
165
+ lastReferenceValue,
166
+ merge,
167
+ prompt,
168
+ sourceValue
169
+ };
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@openfn/language-gemini",
3
+ "version": "1.0.0",
4
+ "description": "OpenFn gemini adaptor",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./dist/index.js",
9
+ "types": "./types/index.d.ts",
10
+ "require": "./dist/index.cjs"
11
+ },
12
+ "./package.json": "./package.json"
13
+ },
14
+ "author": "Open Function Group",
15
+ "license": "LGPLv3",
16
+ "files": [
17
+ "dist/",
18
+ "types/",
19
+ "ast.json",
20
+ "configuration-schema.json"
21
+ ],
22
+ "dependencies": {
23
+ "@google/genai": "^1.37.0",
24
+ "@openfn/language-common": "3.2.1"
25
+ },
26
+ "devDependencies": {
27
+ "assertion-error": "2.0.0",
28
+ "chai": "4.3.6",
29
+ "deep-eql": "4.1.1",
30
+ "mocha": "^10.7.3",
31
+ "rimraf": "3.0.2"
32
+ },
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "https://github.com/openfn/adaptors.git"
36
+ },
37
+ "types": "types/index.d.ts",
38
+ "main": "dist/index.cjs",
39
+ "scripts": {
40
+ "build": "pnpm clean && build-adaptor gemini",
41
+ "_test": "mocha --experimental-specifier-resolution=node --no-warnings",
42
+ "_test:watch": "mocha -w --experimental-specifier-resolution=node --no-warnings",
43
+ "clean": "rimraf dist types docs",
44
+ "pack": "pnpm pack --pack-destination ../../dist"
45
+ }
46
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Creates a Gemini client
3
+ * @param state
4
+ * @returns {state}
5
+ */
6
+ export declare function createClient(state: any): any;
7
+ /**
8
+ * Executes a series of operations.
9
+ * @private
10
+ * @param operations
11
+ * @returns {operation}
12
+ */
13
+ export declare function execute(...operations: any[]): (state: any) => any;
14
+ /**
15
+ * Prompt the Gemini interface to respond
16
+ * @example
17
+ * prompt(`Summarize this text: ${JSON.stringify($.data)}`);
18
+ * @public
19
+ * @function
20
+ * @param {string} message - The prompt
21
+ * @param {PromptOptions} options - Model and other parameters
22
+ * @returns {operation}
23
+ */
24
+ export declare function prompt(message: string, options?: any): (state: any) => Promise<State>;
25
+ /**
26
+ * Prompt Gemini deep research (using Google Search grounding)
27
+ * @example
28
+ * deepResearch(`Find recent news about OpenFn`);
29
+ * @public
30
+ * @function
31
+ * @param {string} message - The research query
32
+ * @param {DeepResearchOptions} options - Model and tools
33
+ * @returns {operation}
34
+ */
35
+ export declare function deepResearch(message: string, options?: any): (state: any) => Promise<State>;
36
+ /**
37
+ * Generate an image using Gemini/Imagen
38
+ * @example
39
+ * generateImage("A futuristic city skyline");
40
+ * @public
41
+ * @function
42
+ * @param {string} promptText - The image prompt
43
+ * @param {object} options - Model and generation options
44
+ * @returns {operation}
45
+ */
46
+ export declare function generateImage(promptText: string, options?: any): (state: any) => Promise<State>;
47
+ export { dataPath, dataValue, dateFns, cursor, each, field, fields, fn, lastReferenceValue, merge, sourceValue, } from '@openfn/language-common';
@@ -0,0 +1,3 @@
1
+ import { execute, composeNextState } from '@openfn/language-common';
2
+ import { expandReferences } from '@openfn/language-common/util';
3
+ export { execute as commonExecute, composeNextState, expandReferences };
@@ -0,0 +1,3 @@
1
+ import * as Adaptor from './Adaptor';
2
+ export default Adaptor;
3
+ export * from './Adaptor';