@paean-ai/adk 0.2.6 → 0.2.8
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/cjs/index.js +11 -11
- package/dist/cjs/index.js.map +3 -3
- package/dist/cjs/models/google_llm.js +57 -10
- package/dist/esm/index.js +11 -11
- package/dist/esm/index.js.map +3 -3
- package/dist/esm/models/google_llm.js +62 -11
- package/dist/web/index.js +1 -1
- package/dist/web/index.js.map +3 -3
- package/dist/web/models/google_llm.js +62 -11
- package/package.json +1 -1
|
@@ -36,7 +36,11 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
|
|
|
36
36
|
* Copyright 2025 Google LLC
|
|
37
37
|
* SPDX-License-Identifier: Apache-2.0
|
|
38
38
|
*/
|
|
39
|
-
import {
|
|
39
|
+
import {
|
|
40
|
+
createPartFromText,
|
|
41
|
+
FinishReason,
|
|
42
|
+
GoogleGenAI
|
|
43
|
+
} from "@google/genai";
|
|
40
44
|
import { logger } from "../utils/logger.js";
|
|
41
45
|
import { isGemini3PreviewModel } from "../utils/model_name.js";
|
|
42
46
|
import { GoogleLLMVariant } from "../utils/variant_utils.js";
|
|
@@ -87,11 +91,15 @@ class Gemini extends BaseLlm {
|
|
|
87
91
|
if (this.isGemini3Preview && useVertexAI) {
|
|
88
92
|
const availableApiKey = apiKey || (canReadEnv ? process.env["GOOGLE_GENAI_API_KEY"] || process.env["GEMINI_API_KEY"] : void 0);
|
|
89
93
|
if (availableApiKey) {
|
|
90
|
-
logger.info(
|
|
94
|
+
logger.info(
|
|
95
|
+
"Gemini 3 preview detected with Vertex AI mode. Switching to API key mode for correct endpoint handling."
|
|
96
|
+
);
|
|
91
97
|
useVertexAI = false;
|
|
92
98
|
this.apiKey = availableApiKey;
|
|
93
99
|
} else {
|
|
94
|
-
logger.warn(
|
|
100
|
+
logger.warn(
|
|
101
|
+
"Gemini 3 preview requires API key authentication for correct endpoint handling. Set GEMINI_API_KEY or GOOGLE_GENAI_API_KEY environment variable for best compatibility."
|
|
102
|
+
);
|
|
95
103
|
}
|
|
96
104
|
}
|
|
97
105
|
this.vertexai = useVertexAI;
|
|
@@ -132,7 +140,7 @@ class Gemini extends BaseLlm {
|
|
|
132
140
|
*/
|
|
133
141
|
generateContentAsync(llmRequest, stream = false) {
|
|
134
142
|
return __asyncGenerator(this, null, function* () {
|
|
135
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
143
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
136
144
|
this.preprocessRequest(llmRequest);
|
|
137
145
|
this.maybeAppendUserContent(llmRequest);
|
|
138
146
|
logger.info(
|
|
@@ -148,6 +156,7 @@ class Gemini extends BaseLlm {
|
|
|
148
156
|
config: llmRequest.config
|
|
149
157
|
}));
|
|
150
158
|
let thoughtText = "";
|
|
159
|
+
let thoughtSignature;
|
|
151
160
|
let text = "";
|
|
152
161
|
let usageMetadata;
|
|
153
162
|
let lastResponse;
|
|
@@ -161,6 +170,9 @@ class Gemini extends BaseLlm {
|
|
|
161
170
|
if (firstPart == null ? void 0 : firstPart.text) {
|
|
162
171
|
if ("thought" in firstPart && firstPart.thought) {
|
|
163
172
|
thoughtText += firstPart.text;
|
|
173
|
+
if ("thoughtSignature" in firstPart && firstPart.thoughtSignature) {
|
|
174
|
+
thoughtSignature = firstPart.thoughtSignature;
|
|
175
|
+
}
|
|
164
176
|
} else {
|
|
165
177
|
text += firstPart.text;
|
|
166
178
|
}
|
|
@@ -168,7 +180,11 @@ class Gemini extends BaseLlm {
|
|
|
168
180
|
} else if ((thoughtText || text) && (!firstPart || !firstPart.inlineData)) {
|
|
169
181
|
const parts = [];
|
|
170
182
|
if (thoughtText) {
|
|
171
|
-
|
|
183
|
+
const thoughtPart = { text: thoughtText, thought: true };
|
|
184
|
+
if (thoughtSignature) {
|
|
185
|
+
thoughtPart.thoughtSignature = thoughtSignature;
|
|
186
|
+
}
|
|
187
|
+
parts.push(thoughtPart);
|
|
172
188
|
}
|
|
173
189
|
if (text) {
|
|
174
190
|
parts.push(createPartFromText(text));
|
|
@@ -183,7 +199,17 @@ class Gemini extends BaseLlm {
|
|
|
183
199
|
thoughtText = "";
|
|
184
200
|
text = "";
|
|
185
201
|
}
|
|
202
|
+
if (this.isGemini3Preview && thoughtSignature && ((_e = llmResponse.content) == null ? void 0 : _e.parts)) {
|
|
203
|
+
for (const part of llmResponse.content.parts) {
|
|
204
|
+
if (part.functionCall && !part.thoughtSignature) {
|
|
205
|
+
part.thoughtSignature = thoughtSignature;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
186
209
|
yield llmResponse;
|
|
210
|
+
if ((_g = (_f = llmResponse.content) == null ? void 0 : _f.parts) == null ? void 0 : _g.some((part) => part.functionCall)) {
|
|
211
|
+
thoughtSignature = void 0;
|
|
212
|
+
}
|
|
187
213
|
}
|
|
188
214
|
} catch (temp) {
|
|
189
215
|
error = [temp];
|
|
@@ -195,10 +221,14 @@ class Gemini extends BaseLlm {
|
|
|
195
221
|
throw error[0];
|
|
196
222
|
}
|
|
197
223
|
}
|
|
198
|
-
if ((text || thoughtText) && ((
|
|
224
|
+
if ((text || thoughtText) && ((_i = (_h = lastResponse == null ? void 0 : lastResponse.candidates) == null ? void 0 : _h[0]) == null ? void 0 : _i.finishReason) === FinishReason.STOP) {
|
|
199
225
|
const parts = [];
|
|
200
226
|
if (thoughtText) {
|
|
201
|
-
|
|
227
|
+
const thoughtPart = { text: thoughtText, thought: true };
|
|
228
|
+
if (thoughtSignature) {
|
|
229
|
+
thoughtPart.thoughtSignature = thoughtSignature;
|
|
230
|
+
}
|
|
231
|
+
parts.push(thoughtPart);
|
|
202
232
|
}
|
|
203
233
|
if (text) {
|
|
204
234
|
parts.push({ text });
|
|
@@ -213,11 +243,28 @@ class Gemini extends BaseLlm {
|
|
|
213
243
|
}
|
|
214
244
|
} else {
|
|
215
245
|
const response = yield new __await(this.apiClient.models.generateContent({
|
|
216
|
-
model: (
|
|
246
|
+
model: (_j = llmRequest.model) != null ? _j : this.model,
|
|
217
247
|
contents: llmRequest.contents,
|
|
218
248
|
config: llmRequest.config
|
|
219
249
|
}));
|
|
220
|
-
|
|
250
|
+
const llmResponse = createLlmResponse(response);
|
|
251
|
+
if (this.isGemini3Preview && ((_k = llmResponse.content) == null ? void 0 : _k.parts)) {
|
|
252
|
+
let thoughtSig;
|
|
253
|
+
for (const part of llmResponse.content.parts) {
|
|
254
|
+
if (part.thought && part.thoughtSignature) {
|
|
255
|
+
thoughtSig = part.thoughtSignature;
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (thoughtSig) {
|
|
260
|
+
for (const part of llmResponse.content.parts) {
|
|
261
|
+
if (part.functionCall && !part.thoughtSignature) {
|
|
262
|
+
part.thoughtSignature = thoughtSig;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
yield llmResponse;
|
|
221
268
|
}
|
|
222
269
|
});
|
|
223
270
|
}
|
|
@@ -240,7 +287,9 @@ class Gemini extends BaseLlm {
|
|
|
240
287
|
logger.debug("Using custom API endpoint: ".concat(this.apiEndpoint));
|
|
241
288
|
if (this.isGemini3Preview) {
|
|
242
289
|
httpOptions.apiVersion = "";
|
|
243
|
-
logger.info(
|
|
290
|
+
logger.info(
|
|
291
|
+
"Gemini 3 preview mode: using direct API path without version prefix"
|
|
292
|
+
);
|
|
244
293
|
}
|
|
245
294
|
}
|
|
246
295
|
this._apiClient = new GoogleGenAI({
|
|
@@ -304,7 +353,9 @@ class Gemini extends BaseLlm {
|
|
|
304
353
|
llmRequest.liveConnectConfig.systemInstruction = {
|
|
305
354
|
role: "system",
|
|
306
355
|
// TODO - b/425992518: validate type casting works well.
|
|
307
|
-
parts: [
|
|
356
|
+
parts: [
|
|
357
|
+
createPartFromText(llmRequest.config.systemInstruction)
|
|
358
|
+
]
|
|
308
359
|
};
|
|
309
360
|
}
|
|
310
361
|
llmRequest.liveConnectConfig.tools = (_c = llmRequest.config) == null ? void 0 : _c.tools;
|