@umituz/react-native-ai-gemini-provider 1.1.0 → 1.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-ai-gemini-provider",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Google Gemini AI provider for React Native applications",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -129,39 +129,58 @@ class GeminiClientService {
129
129
  }),
130
130
  }));
131
131
 
132
- const result = await this.executeWithRetry(() =>
133
- genModel.generateContent({
134
- contents: sdkContents as Parameters<typeof genModel.generateContent>[0] extends { contents: infer C } ? C : never,
135
- generationConfig,
136
- }),
137
- );
132
+ try {
133
+ const result = await this.executeWithRetry(() =>
134
+ genModel.generateContent({
135
+ contents: sdkContents as Parameters<typeof genModel.generateContent>[0] extends { contents: infer C } ? C : never,
136
+ generationConfig,
137
+ }),
138
+ );
138
139
 
139
- const response = result.response;
140
-
141
- return {
142
- candidates: response.candidates?.map((candidate) => ({
143
- content: {
144
- parts: candidate.content.parts
145
- .map((part): GeminiPart | null => {
146
- if ("text" in part && part.text !== undefined) {
147
- return { text: part.text };
148
- }
149
- if ("inlineData" in part && part.inlineData) {
150
- return {
151
- inlineData: {
152
- mimeType: part.inlineData.mimeType,
153
- data: part.inlineData.data,
154
- },
155
- };
156
- }
157
- return null;
158
- })
159
- .filter((p): p is GeminiPart => p !== null),
160
- role: (candidate.content.role || "model") as "user" | "model",
161
- },
162
- finishReason: candidate.finishReason as GeminiFinishReason | undefined,
163
- })),
164
- };
140
+ const response = result.response;
141
+
142
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
143
+ // eslint-disable-next-line no-console
144
+ console.log("[Gemini] Content generated:", {
145
+ candidatesCount: response.candidates?.length ?? 0,
146
+ finishReason: response.candidates?.[0]?.finishReason,
147
+ });
148
+ }
149
+
150
+ return {
151
+ candidates: response.candidates?.map((candidate) => ({
152
+ content: {
153
+ parts: candidate.content.parts
154
+ .map((part): GeminiPart | null => {
155
+ if ("text" in part && part.text !== undefined) {
156
+ return { text: part.text };
157
+ }
158
+ if ("inlineData" in part && part.inlineData) {
159
+ return {
160
+ inlineData: {
161
+ mimeType: part.inlineData.mimeType,
162
+ data: part.inlineData.data,
163
+ },
164
+ };
165
+ }
166
+ return null;
167
+ })
168
+ .filter((p): p is GeminiPart => p !== null),
169
+ role: (candidate.content.role || "model") as "user" | "model",
170
+ },
171
+ finishReason: candidate.finishReason as GeminiFinishReason | undefined,
172
+ })),
173
+ };
174
+ } catch (error) {
175
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
176
+ // eslint-disable-next-line no-console
177
+ console.error("[Gemini] Content generation failed:", {
178
+ model,
179
+ error: error instanceof Error ? error.message : String(error),
180
+ });
181
+ }
182
+ throw error;
183
+ }
165
184
  }
166
185
 
167
186
  /**
@@ -165,7 +165,26 @@ class GeminiProviderService {
165
165
  model: string,
166
166
  input: Record<string, unknown>,
167
167
  ): Promise<T> {
168
- return this.executeGeneration<T>(model, input);
168
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
169
+ // eslint-disable-next-line no-console
170
+ console.log("[GeminiProvider] Run started:", {
171
+ model,
172
+ hasPrompt: !!input.prompt,
173
+ outputFormat: input.outputFormat,
174
+ });
175
+ }
176
+
177
+ const result = await this.executeGeneration<T>(model, input);
178
+
179
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
180
+ // eslint-disable-next-line no-console
181
+ console.log("[GeminiProvider] Run completed:", {
182
+ model,
183
+ hasResult: !!result,
184
+ });
185
+ }
186
+
187
+ return result;
169
188
  }
170
189
 
171
190
  /**
@@ -233,17 +252,25 @@ class GeminiProviderService {
233
252
  model: string,
234
253
  input: Record<string, unknown>,
235
254
  ): Promise<T> {
236
- // Check if this is an image generation request
237
- if (input.generateImage === true || input.type === "image") {
255
+ const isImageGeneration = input.generateImage === true || input.type === "image";
256
+
257
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
258
+ // eslint-disable-next-line no-console
259
+ console.log("[GeminiProvider] Execute generation:", {
260
+ model,
261
+ isImageGeneration,
262
+ promptLength: String(input.prompt || "").length,
263
+ });
264
+ }
265
+
266
+ if (isImageGeneration) {
238
267
  const prompt = String(input.prompt || "");
239
268
  const images = input.images as GeminiImageInput[] | undefined;
240
269
  const result = await geminiClientService.generateImage(prompt, images);
241
270
  return result as T;
242
271
  }
243
272
 
244
- // Regular content generation
245
273
  const contents = this.buildContents(input);
246
-
247
274
  const response = await geminiClientService.generateContent(
248
275
  model,
249
276
  contents,
@@ -327,11 +354,17 @@ class GeminiProviderService {
327
354
  const imagePart = parts.find((p) => p.inlineData);
328
355
  const imageData = imagePart?.inlineData;
329
356
 
330
- if (input.outputFormat === "text") {
331
- return text as T;
357
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
358
+ // eslint-disable-next-line no-console
359
+ console.log("[GeminiProvider] Format response:", {
360
+ hasText: !!text,
361
+ textLength: text?.length ?? 0,
362
+ hasImage: !!imageData,
363
+ outputFormat: input.outputFormat,
364
+ });
332
365
  }
333
366
 
334
- // Return full result with image data if available
367
+ // Build result object - always return { text } for consistency
335
368
  const result: Record<string, unknown> = {
336
369
  text,
337
370
  response,