@paean-ai/adk 0.2.25 → 0.2.26

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.
@@ -65,11 +65,13 @@ class Gemini extends import_base_llm.BaseLlm {
65
65
  this.headers = headers;
66
66
  this.isGemini3Preview = (0, import_model_name.isGemini3PreviewModel)(model);
67
67
  const canReadEnv = typeof process === "object";
68
+ const aiStudioApiKey = canReadEnv ? process.env["AI_STUDIO_API_KEY"] : void 0;
69
+ const useAiStudioMode = !!aiStudioApiKey;
68
70
  this.apiEndpoint = apiEndpoint;
69
71
  if (!this.apiEndpoint && canReadEnv) {
70
72
  this.apiEndpoint = process.env["GEMINI_API_ENDPOINT"];
71
73
  }
72
- if (!this.apiEndpoint && this.isGemini3Preview) {
74
+ if (!this.apiEndpoint && this.isGemini3Preview && !useAiStudioMode) {
73
75
  this.apiEndpoint = GEMINI3_PREVIEW_API_ENDPOINT;
74
76
  import_logger.logger.info(`Using Gemini 3 preview endpoint: ${this.apiEndpoint}`);
75
77
  }
@@ -80,6 +82,15 @@ class Gemini extends import_base_llm.BaseLlm {
80
82
  useVertexAI = vertexAIfromEnv.toLowerCase() === "true" || vertexAIfromEnv === "1";
81
83
  }
82
84
  }
85
+ if (useAiStudioMode) {
86
+ if (useVertexAI) {
87
+ import_logger.logger.info(
88
+ "AI_STUDIO_API_KEY set \u2014 overriding Vertex AI mode to use AI Studio (generativelanguage.googleapis.com)"
89
+ );
90
+ }
91
+ useVertexAI = false;
92
+ this.apiKey = aiStudioApiKey;
93
+ }
83
94
  if (this.isGemini3Preview && useVertexAI) {
84
95
  const availableApiKey = apiKey || (canReadEnv ? process.env["GOOGLE_GENAI_API_KEY"] || process.env["GEMINI_API_KEY"] : void 0);
85
96
  if (availableApiKey) {
@@ -258,10 +269,10 @@ class Gemini extends import_base_llm.BaseLlm {
258
269
  }
259
270
  if (hasFunctionCalls) {
260
271
  if (pendingFCResponse && ((_i = pendingFCResponse.content) == null ? void 0 : _i.parts)) {
261
- const newFCParts = (((_j = llmResponse.content) == null ? void 0 : _j.parts) || []).filter(
262
- (p) => p.functionCall
272
+ const newParts = (((_j = llmResponse.content) == null ? void 0 : _j.parts) || []).filter(
273
+ (p) => p.functionCall || p.thoughtSignature
263
274
  );
264
- pendingFCResponse.content.parts.push(...newFCParts);
275
+ pendingFCResponse.content.parts.push(...newParts);
265
276
  pendingFCResponse.usageMetadata = llmResponse.usageMetadata;
266
277
  } else {
267
278
  pendingFCResponse = llmResponse;
@@ -282,7 +293,14 @@ class Gemini extends import_base_llm.BaseLlm {
282
293
  const partsWithSig = pendingFCResponse.content.parts.filter(
283
294
  (p) => p.thoughtSignature
284
295
  ).length;
285
- if (partsWithSig === 0) {
296
+ if (partsWithSig === 0 && thoughtSignature) {
297
+ for (const part of pendingFCResponse.content.parts) {
298
+ if (part.functionCall) {
299
+ part.thoughtSignature = thoughtSignature;
300
+ break;
301
+ }
302
+ }
303
+ } else if (partsWithSig === 0) {
286
304
  import_logger.logger.warn(
287
305
  `[Gemini3] No thoughtSignature on merged function call parts \u2014 may cause 400 on next request`
288
306
  );
@@ -27,6 +27,7 @@ __export(llm_response_exports, {
27
27
  createLlmResponse: () => createLlmResponse
28
28
  });
29
29
  module.exports = __toCommonJS(llm_response_exports);
30
+ var import_genai = require("@google/genai");
30
31
  /**
31
32
  * @license
32
33
  * Copyright 2025 Google LLC
@@ -45,6 +46,12 @@ function createLlmResponse(response) {
45
46
  finishReason: candidate.finishReason
46
47
  };
47
48
  }
49
+ if (candidate.finishReason === import_genai.FinishReason.STOP) {
50
+ return {
51
+ usageMetadata,
52
+ finishReason: candidate.finishReason
53
+ };
54
+ }
48
55
  return {
49
56
  errorCode: candidate.finishReason,
50
57
  errorMessage: candidate.finishMessage,
@@ -371,6 +371,7 @@ function mergeParallelFunctionResponseEvents(functionResponseEvents) {
371
371
  const actionsList = functionResponseEvents.map((event) => event.actions || {});
372
372
  const mergedActions = mergeEventActions(actionsList);
373
373
  return createEvent({
374
+ invocationId: baseEvent.invocationId,
374
375
  author: baseEvent.author,
375
376
  branch: baseEvent.branch,
376
377
  content: { role: "user", parts: mergedParts },
@@ -1012,6 +1012,7 @@ const _LlmAgent = class _LlmAgent extends BaseAgent {
1012
1012
  const allEmpty = llmResponse.content.parts.every(
1013
1013
  (p) => {
1014
1014
  if (p.functionCall || p.functionResponse || p.executableCode || p.codeExecutionResult) return false;
1015
+ if (p.inlineData || p.fileData) return false;
1015
1016
  if ("text" in p && typeof p.text === "string" && p.text.length > 0) return false;
1016
1017
  return true;
1017
1018
  }
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import { createEventActions } from "./event_actions.js";
7
7
  function createEvent(params = {}) {
8
- const event = {
8
+ return {
9
9
  ...params,
10
10
  id: params.id || createNewEventId(),
11
11
  invocationId: params.invocationId || "",
@@ -15,7 +15,6 @@ function createEvent(params = {}) {
15
15
  branch: params.branch,
16
16
  timestamp: params.timestamp || Date.now()
17
17
  };
18
- return event;
19
18
  }
20
19
  function isFinalResponse(event) {
21
20
  if (event.actions.skipSummarization || event.longRunningToolIds && event.longRunningToolIds.length > 0) {