@umituz/react-native-ai-gemini-provider 3.0.23 → 3.0.24
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
package/src/global.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare const __DEV__: boolean;
|
|
@@ -150,11 +150,31 @@ export function createChatSession(config: GeminiChatConfig = {}) {
|
|
|
150
150
|
|
|
151
151
|
return {
|
|
152
152
|
async send(parts: GeminiMessagePart[]): Promise<ChatSendResult> {
|
|
153
|
+
if (__DEV__) {
|
|
154
|
+
console.log("[ChatSession.send] >>> SENDING TO GEMINI SDK");
|
|
155
|
+
console.log("[ChatSession.send] parts count:", parts.length);
|
|
156
|
+
parts.forEach((p, i) => {
|
|
157
|
+
if ("text" in p) console.log(`[ChatSession.send] part[${i}] text:`, (p.text ?? "").substring(0, 200));
|
|
158
|
+
if ("inlineData" in p) console.log(`[ChatSession.send] part[${i}] inlineData: mime=${(p as GeminiInlineDataPart).inlineData.mimeType}, size=${(p as GeminiInlineDataPart).inlineData.data.length}`);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
153
162
|
const result = await chat.sendMessage(parts as Part[]);
|
|
154
163
|
if (!result.response) throw new Error("No response from Gemini SDK");
|
|
155
164
|
const candidate = result.response.candidates?.[0];
|
|
165
|
+
const text = result.response.text();
|
|
166
|
+
|
|
167
|
+
if (__DEV__) {
|
|
168
|
+
console.log("[ChatSession.send] <<< GEMINI SDK RESPONSE");
|
|
169
|
+
console.log("[ChatSession.send] finishReason:", candidate?.finishReason ?? "N/A");
|
|
170
|
+
console.log("[ChatSession.send] safetyRatings:", JSON.stringify(candidate?.safetyRatings ?? []));
|
|
171
|
+
console.log("[ChatSession.send] response text length:", text.length);
|
|
172
|
+
console.log("[ChatSession.send] response text:", text.substring(0, 500));
|
|
173
|
+
console.log("[ChatSession.send] response FULL text:", text);
|
|
174
|
+
}
|
|
175
|
+
|
|
156
176
|
return {
|
|
157
|
-
text
|
|
177
|
+
text,
|
|
158
178
|
finishReason: candidate?.finishReason ?? undefined,
|
|
159
179
|
};
|
|
160
180
|
},
|
|
@@ -180,13 +200,40 @@ export function createChatSession(config: GeminiChatConfig = {}) {
|
|
|
180
200
|
export async function sendChatMessage(
|
|
181
201
|
opts: SendChatMessageOptions,
|
|
182
202
|
): Promise<string> {
|
|
203
|
+
if (__DEV__) {
|
|
204
|
+
console.log("═══════════════════════════════════════════════════");
|
|
205
|
+
console.log("[sendChatMessage] >>> START");
|
|
206
|
+
console.log("[sendChatMessage] model:", opts.model ?? DEFAULT_MODELS.CHAT);
|
|
207
|
+
console.log("[sendChatMessage] message:", opts.message.substring(0, 200));
|
|
208
|
+
console.log("[sendChatMessage] history count:", opts.history.length);
|
|
209
|
+
console.log("[sendChatMessage] systemPrompt length:", opts.systemPrompt?.length ?? 0);
|
|
210
|
+
console.log("[sendChatMessage] systemPrompt (first 500):", opts.systemPrompt?.substring(0, 500));
|
|
211
|
+
console.log("[sendChatMessage] generationConfig:", JSON.stringify(opts.generationConfig));
|
|
212
|
+
console.log("[sendChatMessage] safetySettings:", opts.safetySettings ? JSON.stringify(opts.safetySettings) : "USING DEFAULT (BLOCK_NONE)");
|
|
213
|
+
console.log("[sendChatMessage] attachments:", opts.attachments?.length ?? 0);
|
|
214
|
+
}
|
|
215
|
+
|
|
183
216
|
const trimmed = trimChatHistory(
|
|
184
217
|
opts.history,
|
|
185
218
|
opts.historyMaxChars,
|
|
186
219
|
opts.historyMinMessages,
|
|
187
220
|
);
|
|
221
|
+
|
|
222
|
+
if (__DEV__) {
|
|
223
|
+
console.log("[sendChatMessage] history after trim:", trimmed.length, "messages");
|
|
224
|
+
trimmed.forEach((m, i) => console.log(`[sendChatMessage] history[${i}]: role=${m.role}, content=${m.content.substring(0, 100)}`));
|
|
225
|
+
}
|
|
226
|
+
|
|
188
227
|
const geminiHistory = buildChatHistory(trimmed);
|
|
189
228
|
|
|
229
|
+
if (__DEV__) {
|
|
230
|
+
console.log("[sendChatMessage] geminiHistory (SDK format):", geminiHistory.length, "turns");
|
|
231
|
+
geminiHistory.forEach((h, i) => {
|
|
232
|
+
const text = "text" in h.parts[0] ? (h.parts[0] as { text: string }).text : "[non-text]";
|
|
233
|
+
console.log(`[sendChatMessage] geminiHistory[${i}]: role=${h.role}, text=${text.substring(0, 100)}`);
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
190
237
|
const session = createChatSession({
|
|
191
238
|
model: opts.model ?? DEFAULT_MODELS.CHAT,
|
|
192
239
|
systemInstruction: opts.systemPrompt,
|
|
@@ -202,7 +249,16 @@ export async function sendChatMessage(
|
|
|
202
249
|
|
|
203
250
|
const result = await session.send(parts);
|
|
204
251
|
|
|
252
|
+
if (__DEV__) {
|
|
253
|
+
console.log("[sendChatMessage] finishReason:", result.finishReason);
|
|
254
|
+
console.log("[sendChatMessage] response text length:", result.text.length);
|
|
255
|
+
console.log("[sendChatMessage] response FULL:", result.text);
|
|
256
|
+
console.log("[sendChatMessage] <<< END");
|
|
257
|
+
console.log("═══════════════════════════════════════════════════");
|
|
258
|
+
}
|
|
259
|
+
|
|
205
260
|
if (result.finishReason === "SAFETY") {
|
|
261
|
+
if (__DEV__) console.warn("[sendChatMessage] ⚠️ SAFETY FILTER TRIGGERED but has text, returning partial");
|
|
206
262
|
if (result.text.trim()) return result.text;
|
|
207
263
|
throw new Error("Response blocked by safety filter.");
|
|
208
264
|
}
|
|
@@ -78,6 +78,12 @@ class GeminiClient {
|
|
|
78
78
|
}))
|
|
79
79
|
: PERMISSIVE_SAFETY;
|
|
80
80
|
|
|
81
|
+
if (__DEV__) {
|
|
82
|
+
console.log("[GeminiClient.getModel] model:", effectiveModel);
|
|
83
|
+
console.log("[GeminiClient.getModel] systemInstruction length:", opts.systemInstruction?.length ?? 0);
|
|
84
|
+
console.log("[GeminiClient.getModel] safetySettings:", JSON.stringify(sdkSafety.map(s => ({ category: s.category, threshold: s.threshold }))));
|
|
85
|
+
}
|
|
86
|
+
|
|
81
87
|
return this.client.getGenerativeModel({
|
|
82
88
|
model: effectiveModel,
|
|
83
89
|
...(opts.systemInstruction && { systemInstruction: opts.systemInstruction }),
|