@paean-ai/adk 0.2.14 → 0.2.15

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.
Files changed (254) hide show
  1. package/dist/cjs/index.js +11 -11
  2. package/dist/cjs/index.js.map +3 -3
  3. package/dist/esm/index.js +11 -11
  4. package/dist/esm/index.js.map +3 -3
  5. package/dist/types/agents/llm_agent.d.ts +4 -0
  6. package/dist/web/index.js +1 -1
  7. package/dist/web/index.js.map +3 -3
  8. package/package.json +1 -1
  9. package/dist/cjs/agents/active_streaming_tool.js +0 -44
  10. package/dist/cjs/agents/base_agent.js +0 -245
  11. package/dist/cjs/agents/base_llm_processor.js +0 -44
  12. package/dist/cjs/agents/callback_context.js +0 -98
  13. package/dist/cjs/agents/content_processor_utils.js +0 -346
  14. package/dist/cjs/agents/functions.js +0 -385
  15. package/dist/cjs/agents/instructions.js +0 -110
  16. package/dist/cjs/agents/invocation_context.js +0 -107
  17. package/dist/cjs/agents/live_request_queue.js +0 -136
  18. package/dist/cjs/agents/llm_agent.js +0 -1212
  19. package/dist/cjs/agents/loop_agent.js +0 -68
  20. package/dist/cjs/agents/parallel_agent.js +0 -78
  21. package/dist/cjs/agents/readonly_context.js +0 -68
  22. package/dist/cjs/agents/run_config.js +0 -70
  23. package/dist/cjs/agents/sequential_agent.js +0 -84
  24. package/dist/cjs/agents/transcription_entry.js +0 -27
  25. package/dist/cjs/artifacts/base_artifact_service.js +0 -27
  26. package/dist/cjs/artifacts/gcs_artifact_service.js +0 -140
  27. package/dist/cjs/artifacts/in_memory_artifact_service.js +0 -119
  28. package/dist/cjs/auth/auth_credential.js +0 -46
  29. package/dist/cjs/auth/auth_handler.js +0 -92
  30. package/dist/cjs/auth/auth_schemes.js +0 -62
  31. package/dist/cjs/auth/auth_tool.js +0 -27
  32. package/dist/cjs/auth/credential_service/base_credential_service.js +0 -27
  33. package/dist/cjs/auth/credential_service/in_memory_credential_service.js +0 -63
  34. package/dist/cjs/auth/exchanger/base_credential_exchanger.js +0 -40
  35. package/dist/cjs/auth/exchanger/credential_exchanger_registry.js +0 -59
  36. package/dist/cjs/code_executors/base_code_executor.js +0 -76
  37. package/dist/cjs/code_executors/built_in_code_executor.js +0 -58
  38. package/dist/cjs/code_executors/code_execution_utils.js +0 -142
  39. package/dist/cjs/code_executors/code_executor_context.js +0 -198
  40. package/dist/cjs/common.js +0 -181
  41. package/dist/cjs/events/event.js +0 -119
  42. package/dist/cjs/events/event_actions.js +0 -83
  43. package/dist/cjs/examples/base_example_provider.js +0 -40
  44. package/dist/cjs/examples/example.js +0 -27
  45. package/dist/cjs/examples/example_util.js +0 -107
  46. package/dist/cjs/index_web.js +0 -33
  47. package/dist/cjs/memory/base_memory_service.js +0 -27
  48. package/dist/cjs/memory/in_memory_memory_service.js +0 -97
  49. package/dist/cjs/memory/memory_entry.js +0 -27
  50. package/dist/cjs/models/base_llm.js +0 -95
  51. package/dist/cjs/models/base_llm_connection.js +0 -27
  52. package/dist/cjs/models/gemini_llm_connection.js +0 -132
  53. package/dist/cjs/models/google_llm.js +0 -559
  54. package/dist/cjs/models/llm_request.js +0 -82
  55. package/dist/cjs/models/llm_response.js +0 -71
  56. package/dist/cjs/models/registry.js +0 -121
  57. package/dist/cjs/plugins/base_plugin.js +0 -236
  58. package/dist/cjs/plugins/logging_plugin.js +0 -222
  59. package/dist/cjs/plugins/plugin_manager.js +0 -239
  60. package/dist/cjs/plugins/security_plugin.js +0 -153
  61. package/dist/cjs/runner/in_memory_runner.js +0 -58
  62. package/dist/cjs/runner/runner.js +0 -277
  63. package/dist/cjs/sessions/base_session_service.js +0 -71
  64. package/dist/cjs/sessions/in_memory_session_service.js +0 -184
  65. package/dist/cjs/sessions/session.js +0 -48
  66. package/dist/cjs/sessions/state.js +0 -101
  67. package/dist/cjs/telemetry/google_cloud.js +0 -85
  68. package/dist/cjs/telemetry/setup.js +0 -97
  69. package/dist/cjs/telemetry/tracing.js +0 -231
  70. package/dist/cjs/tools/agent_tool.js +0 -134
  71. package/dist/cjs/tools/base_tool.js +0 -107
  72. package/dist/cjs/tools/base_toolset.js +0 -76
  73. package/dist/cjs/tools/forwarding_artifact_service.js +0 -71
  74. package/dist/cjs/tools/function_tool.js +0 -101
  75. package/dist/cjs/tools/google_search_tool.js +0 -76
  76. package/dist/cjs/tools/long_running_tool.js +0 -63
  77. package/dist/cjs/tools/mcp/mcp_session_manager.js +0 -65
  78. package/dist/cjs/tools/mcp/mcp_tool.js +0 -65
  79. package/dist/cjs/tools/mcp/mcp_toolset.js +0 -61
  80. package/dist/cjs/tools/tool_confirmation.js +0 -49
  81. package/dist/cjs/tools/tool_context.js +0 -129
  82. package/dist/cjs/utils/client_labels.js +0 -56
  83. package/dist/cjs/utils/deep_clone.js +0 -44
  84. package/dist/cjs/utils/env_aware_utils.js +0 -83
  85. package/dist/cjs/utils/gemini_schema_util.js +0 -88
  86. package/dist/cjs/utils/logger.js +0 -121
  87. package/dist/cjs/utils/model_name.js +0 -76
  88. package/dist/cjs/utils/simple_zod_to_json.js +0 -191
  89. package/dist/cjs/utils/variant_utils.js +0 -55
  90. package/dist/cjs/version.js +0 -39
  91. package/dist/esm/agents/active_streaming_tool.js +0 -14
  92. package/dist/esm/agents/base_agent.js +0 -214
  93. package/dist/esm/agents/base_llm_processor.js +0 -13
  94. package/dist/esm/agents/callback_context.js +0 -68
  95. package/dist/esm/agents/content_processor_utils.js +0 -315
  96. package/dist/esm/agents/functions.js +0 -344
  97. package/dist/esm/agents/instructions.js +0 -80
  98. package/dist/esm/agents/invocation_context.js +0 -76
  99. package/dist/esm/agents/live_request_queue.js +0 -106
  100. package/dist/esm/agents/llm_agent.js +0 -1180
  101. package/dist/esm/agents/loop_agent.js +0 -38
  102. package/dist/esm/agents/parallel_agent.js +0 -48
  103. package/dist/esm/agents/readonly_context.js +0 -38
  104. package/dist/esm/agents/run_config.js +0 -39
  105. package/dist/esm/agents/sequential_agent.js +0 -54
  106. package/dist/esm/agents/transcription_entry.js +0 -5
  107. package/dist/esm/artifacts/base_artifact_service.js +0 -5
  108. package/dist/esm/artifacts/gcs_artifact_service.js +0 -110
  109. package/dist/esm/artifacts/in_memory_artifact_service.js +0 -89
  110. package/dist/esm/auth/auth_credential.js +0 -16
  111. package/dist/esm/auth/auth_handler.js +0 -62
  112. package/dist/esm/auth/auth_schemes.js +0 -31
  113. package/dist/esm/auth/auth_tool.js +0 -5
  114. package/dist/esm/auth/credential_service/base_credential_service.js +0 -5
  115. package/dist/esm/auth/credential_service/in_memory_credential_service.js +0 -33
  116. package/dist/esm/auth/exchanger/base_credential_exchanger.js +0 -10
  117. package/dist/esm/auth/exchanger/credential_exchanger_registry.js +0 -29
  118. package/dist/esm/code_executors/base_code_executor.js +0 -46
  119. package/dist/esm/code_executors/built_in_code_executor.js +0 -28
  120. package/dist/esm/code_executors/code_execution_utils.js +0 -108
  121. package/dist/esm/code_executors/code_executor_context.js +0 -168
  122. package/dist/esm/common.js +0 -98
  123. package/dist/esm/events/event.js +0 -83
  124. package/dist/esm/events/event_actions.js +0 -52
  125. package/dist/esm/examples/base_example_provider.js +0 -10
  126. package/dist/esm/examples/example.js +0 -5
  127. package/dist/esm/examples/example_util.js +0 -76
  128. package/dist/esm/index_web.js +0 -6
  129. package/dist/esm/memory/base_memory_service.js +0 -5
  130. package/dist/esm/memory/in_memory_memory_service.js +0 -67
  131. package/dist/esm/memory/memory_entry.js +0 -5
  132. package/dist/esm/models/base_llm.js +0 -64
  133. package/dist/esm/models/base_llm_connection.js +0 -5
  134. package/dist/esm/models/gemini_llm_connection.js +0 -102
  135. package/dist/esm/models/google_llm.js +0 -533
  136. package/dist/esm/models/llm_request.js +0 -50
  137. package/dist/esm/models/llm_response.js +0 -41
  138. package/dist/esm/models/registry.js +0 -91
  139. package/dist/esm/plugins/base_plugin.js +0 -206
  140. package/dist/esm/plugins/logging_plugin.js +0 -192
  141. package/dist/esm/plugins/plugin_manager.js +0 -209
  142. package/dist/esm/plugins/security_plugin.js +0 -119
  143. package/dist/esm/runner/in_memory_runner.js +0 -28
  144. package/dist/esm/runner/runner.js +0 -247
  145. package/dist/esm/sessions/base_session_service.js +0 -41
  146. package/dist/esm/sessions/in_memory_session_service.js +0 -154
  147. package/dist/esm/sessions/session.js +0 -18
  148. package/dist/esm/sessions/state.js +0 -71
  149. package/dist/esm/telemetry/google_cloud.js +0 -54
  150. package/dist/esm/telemetry/setup.js +0 -67
  151. package/dist/esm/telemetry/tracing.js +0 -195
  152. package/dist/esm/tools/agent_tool.js +0 -104
  153. package/dist/esm/tools/base_tool.js +0 -77
  154. package/dist/esm/tools/base_toolset.js +0 -46
  155. package/dist/esm/tools/forwarding_artifact_service.js +0 -41
  156. package/dist/esm/tools/function_tool.js +0 -71
  157. package/dist/esm/tools/google_search_tool.js +0 -46
  158. package/dist/esm/tools/long_running_tool.js +0 -33
  159. package/dist/esm/tools/mcp/mcp_session_manager.js +0 -35
  160. package/dist/esm/tools/mcp/mcp_tool.js +0 -35
  161. package/dist/esm/tools/mcp/mcp_toolset.js +0 -31
  162. package/dist/esm/tools/tool_confirmation.js +0 -19
  163. package/dist/esm/tools/tool_context.js +0 -99
  164. package/dist/esm/utils/client_labels.js +0 -26
  165. package/dist/esm/utils/deep_clone.js +0 -14
  166. package/dist/esm/utils/env_aware_utils.js +0 -49
  167. package/dist/esm/utils/gemini_schema_util.js +0 -58
  168. package/dist/esm/utils/logger.js +0 -89
  169. package/dist/esm/utils/model_name.js +0 -41
  170. package/dist/esm/utils/simple_zod_to_json.js +0 -160
  171. package/dist/esm/utils/variant_utils.js +0 -24
  172. package/dist/esm/version.js +0 -9
  173. package/dist/web/agents/active_streaming_tool.js +0 -14
  174. package/dist/web/agents/base_agent.js +0 -265
  175. package/dist/web/agents/base_llm_processor.js +0 -13
  176. package/dist/web/agents/callback_context.js +0 -68
  177. package/dist/web/agents/content_processor_utils.js +0 -315
  178. package/dist/web/agents/functions.js +0 -344
  179. package/dist/web/agents/instructions.js +0 -80
  180. package/dist/web/agents/invocation_context.js +0 -76
  181. package/dist/web/agents/live_request_queue.js +0 -124
  182. package/dist/web/agents/llm_agent.js +0 -1310
  183. package/dist/web/agents/loop_agent.js +0 -71
  184. package/dist/web/agents/parallel_agent.js +0 -83
  185. package/dist/web/agents/readonly_context.js +0 -38
  186. package/dist/web/agents/run_config.js +0 -54
  187. package/dist/web/agents/sequential_agent.js +0 -99
  188. package/dist/web/agents/transcription_entry.js +0 -5
  189. package/dist/web/artifacts/base_artifact_service.js +0 -5
  190. package/dist/web/artifacts/gcs_artifact_service.js +0 -126
  191. package/dist/web/artifacts/in_memory_artifact_service.js +0 -89
  192. package/dist/web/auth/auth_credential.js +0 -16
  193. package/dist/web/auth/auth_handler.js +0 -62
  194. package/dist/web/auth/auth_schemes.js +0 -31
  195. package/dist/web/auth/auth_tool.js +0 -5
  196. package/dist/web/auth/credential_service/base_credential_service.js +0 -5
  197. package/dist/web/auth/credential_service/in_memory_credential_service.js +0 -33
  198. package/dist/web/auth/exchanger/base_credential_exchanger.js +0 -10
  199. package/dist/web/auth/exchanger/credential_exchanger_registry.js +0 -29
  200. package/dist/web/code_executors/base_code_executor.js +0 -46
  201. package/dist/web/code_executors/built_in_code_executor.js +0 -28
  202. package/dist/web/code_executors/code_execution_utils.js +0 -105
  203. package/dist/web/code_executors/code_executor_context.js +0 -168
  204. package/dist/web/common.js +0 -98
  205. package/dist/web/events/event.js +0 -101
  206. package/dist/web/events/event_actions.js +0 -67
  207. package/dist/web/examples/base_example_provider.js +0 -10
  208. package/dist/web/examples/example.js +0 -5
  209. package/dist/web/examples/example_util.js +0 -75
  210. package/dist/web/index_web.js +0 -6
  211. package/dist/web/memory/base_memory_service.js +0 -5
  212. package/dist/web/memory/in_memory_memory_service.js +0 -67
  213. package/dist/web/memory/memory_entry.js +0 -5
  214. package/dist/web/models/base_llm.js +0 -64
  215. package/dist/web/models/base_llm_connection.js +0 -5
  216. package/dist/web/models/gemini_llm_connection.js +0 -120
  217. package/dist/web/models/google_llm.js +0 -574
  218. package/dist/web/models/llm_request.js +0 -50
  219. package/dist/web/models/llm_response.js +0 -41
  220. package/dist/web/models/registry.js +0 -91
  221. package/dist/web/plugins/base_plugin.js +0 -206
  222. package/dist/web/plugins/logging_plugin.js +0 -192
  223. package/dist/web/plugins/plugin_manager.js +0 -209
  224. package/dist/web/plugins/security_plugin.js +0 -119
  225. package/dist/web/runner/in_memory_runner.js +0 -28
  226. package/dist/web/runner/runner.js +0 -278
  227. package/dist/web/sessions/base_session_service.js +0 -41
  228. package/dist/web/sessions/in_memory_session_service.js +0 -154
  229. package/dist/web/sessions/session.js +0 -18
  230. package/dist/web/sessions/state.js +0 -87
  231. package/dist/web/telemetry/google_cloud.js +0 -54
  232. package/dist/web/telemetry/setup.js +0 -67
  233. package/dist/web/telemetry/tracing.js +0 -210
  234. package/dist/web/tools/agent_tool.js +0 -118
  235. package/dist/web/tools/base_tool.js +0 -77
  236. package/dist/web/tools/base_toolset.js +0 -46
  237. package/dist/web/tools/forwarding_artifact_service.js +0 -41
  238. package/dist/web/tools/function_tool.js +0 -71
  239. package/dist/web/tools/google_search_tool.js +0 -46
  240. package/dist/web/tools/long_running_tool.js +0 -50
  241. package/dist/web/tools/mcp/mcp_session_manager.js +0 -35
  242. package/dist/web/tools/mcp/mcp_tool.js +0 -35
  243. package/dist/web/tools/mcp/mcp_toolset.js +0 -31
  244. package/dist/web/tools/tool_confirmation.js +0 -19
  245. package/dist/web/tools/tool_context.js +0 -99
  246. package/dist/web/utils/client_labels.js +0 -26
  247. package/dist/web/utils/deep_clone.js +0 -14
  248. package/dist/web/utils/env_aware_utils.js +0 -49
  249. package/dist/web/utils/gemini_schema_util.js +0 -58
  250. package/dist/web/utils/logger.js +0 -89
  251. package/dist/web/utils/model_name.js +0 -41
  252. package/dist/web/utils/simple_zod_to_json.js +0 -174
  253. package/dist/web/utils/variant_utils.js +0 -24
  254. package/dist/web/version.js +0 -9
@@ -1,132 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- "use strict";
8
- var __defProp = Object.defineProperty;
9
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
- var __getOwnPropNames = Object.getOwnPropertyNames;
11
- var __hasOwnProp = Object.prototype.hasOwnProperty;
12
- var __export = (target, all) => {
13
- for (var name in all)
14
- __defProp(target, name, { get: all[name], enumerable: true });
15
- };
16
- var __copyProps = (to, from, except, desc) => {
17
- if (from && typeof from === "object" || typeof from === "function") {
18
- for (let key of __getOwnPropNames(from))
19
- if (!__hasOwnProp.call(to, key) && key !== except)
20
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
- }
22
- return to;
23
- };
24
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
- var gemini_llm_connection_exports = {};
26
- __export(gemini_llm_connection_exports, {
27
- GeminiLlmConnection: () => GeminiLlmConnection
28
- });
29
- module.exports = __toCommonJS(gemini_llm_connection_exports);
30
- var import_logger = require("../utils/logger.js");
31
- /**
32
- * @license
33
- * Copyright 2025 Google LLC
34
- * SPDX-License-Identifier: Apache-2.0
35
- */
36
- class GeminiLlmConnection {
37
- constructor(geminiSession) {
38
- this.geminiSession = geminiSession;
39
- }
40
- /**
41
- * Sends the conversation history to the gemini model.
42
- *
43
- * You call this method right after setting up the model connection.
44
- * The model will respond if the last content is from user, otherwise it will
45
- * wait for new user input before responding.
46
- *
47
- * @param history The conversation history to send to the model.
48
- */
49
- async sendHistory(history) {
50
- const contents = history.filter(
51
- (content) => {
52
- var _a;
53
- return content.parts && ((_a = content.parts[0]) == null ? void 0 : _a.text);
54
- }
55
- );
56
- if (contents.length > 0) {
57
- this.geminiSession.sendClientContent({
58
- turns: contents,
59
- turnComplete: contents[contents.length - 1].role === "user"
60
- });
61
- } else {
62
- import_logger.logger.info("no content is sent");
63
- }
64
- }
65
- /**
66
- * Sends a user content to the gemini model.
67
- *
68
- * The model will respond immediately upon receiving the content.
69
- * If you send function responses, all parts in the content should be function
70
- * responses.
71
- *
72
- * @param content The content to send to the model.
73
- */
74
- async sendContent(content) {
75
- if (!content.parts) {
76
- throw new Error("Content must have parts.");
77
- }
78
- if (content.parts[0].functionResponse) {
79
- const functionResponses = content.parts.map((part) => part.functionResponse).filter((fr) => !!fr);
80
- import_logger.logger.debug("Sending LLM function response:", functionResponses);
81
- this.geminiSession.sendToolResponse({
82
- functionResponses
83
- });
84
- } else {
85
- import_logger.logger.debug("Sending LLM new content", content);
86
- this.geminiSession.sendClientContent({
87
- turns: [content],
88
- turnComplete: true
89
- });
90
- }
91
- }
92
- /**
93
- * Sends a chunk of audio or a frame of video to the model in realtime.
94
- *
95
- * @param blob The blob to send to the model.
96
- */
97
- async sendRealtime(blob) {
98
- import_logger.logger.debug("Sending LLM Blob:", blob);
99
- this.geminiSession.sendRealtimeInput({ media: blob });
100
- }
101
- /**
102
- * Builds a full text response.
103
- *
104
- * The text should not be partial and the returned LlmResponse is not be
105
- * partial.
106
- *
107
- * @param text The text to be included in the response.
108
- * @returns An LlmResponse containing the full text.
109
- */
110
- buildFullTextResponse(text) {
111
- return {
112
- content: {
113
- role: "model",
114
- parts: [{ text }]
115
- }
116
- };
117
- }
118
- // TODO(b/425992518): GenAI SDK inconsistent API, missing methods.
119
- async *receive() {
120
- throw new Error("Not Implemented.");
121
- }
122
- /**
123
- * Closes the llm server connection.
124
- */
125
- async close() {
126
- this.geminiSession.close();
127
- }
128
- }
129
- // Annotate the CommonJS export names for ESM import in node:
130
- 0 && (module.exports = {
131
- GeminiLlmConnection
132
- });
@@ -1,559 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- "use strict";
8
- var __defProp = Object.defineProperty;
9
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
- var __getOwnPropNames = Object.getOwnPropertyNames;
11
- var __hasOwnProp = Object.prototype.hasOwnProperty;
12
- var __export = (target, all) => {
13
- for (var name in all)
14
- __defProp(target, name, { get: all[name], enumerable: true });
15
- };
16
- var __copyProps = (to, from, except, desc) => {
17
- if (from && typeof from === "object" || typeof from === "function") {
18
- for (let key of __getOwnPropNames(from))
19
- if (!__hasOwnProp.call(to, key) && key !== except)
20
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
- }
22
- return to;
23
- };
24
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
- var google_llm_exports = {};
26
- __export(google_llm_exports, {
27
- Gemini: () => Gemini
28
- });
29
- module.exports = __toCommonJS(google_llm_exports);
30
- var import_genai = require("@google/genai");
31
- var import_logger = require("../utils/logger.js");
32
- var import_model_name = require("../utils/model_name.js");
33
- var import_variant_utils = require("../utils/variant_utils.js");
34
- var import_base_llm = require("./base_llm.js");
35
- var import_gemini_llm_connection = require("./gemini_llm_connection.js");
36
- var import_llm_response = require("./llm_response.js");
37
- /**
38
- * @license
39
- * Copyright 2025 Google LLC
40
- * SPDX-License-Identifier: Apache-2.0
41
- */
42
- const AGENT_ENGINE_TELEMETRY_TAG = "remote_reasoning_engine";
43
- const AGENT_ENGINE_TELEMETRY_ENV_VARIABLE_NAME = "GOOGLE_CLOUD_AGENT_ENGINE_ID";
44
- const GEMINI3_PREVIEW_API_ENDPOINT = "https://aiplatform.googleapis.com/v1/publishers/google";
45
- class Gemini extends import_base_llm.BaseLlm {
46
- /**
47
- * @param params The parameters for creating a Gemini instance.
48
- */
49
- constructor({
50
- model,
51
- apiKey,
52
- vertexai,
53
- project,
54
- location,
55
- headers,
56
- apiEndpoint
57
- }) {
58
- if (!model) {
59
- model = "gemini-2.5-flash";
60
- }
61
- super({ model });
62
- this.project = project;
63
- this.location = location;
64
- this.apiKey = apiKey;
65
- this.headers = headers;
66
- this.isGemini3Preview = (0, import_model_name.isGemini3PreviewModel)(model);
67
- const canReadEnv = typeof process === "object";
68
- this.apiEndpoint = apiEndpoint;
69
- if (!this.apiEndpoint && canReadEnv) {
70
- this.apiEndpoint = process.env["GEMINI_API_ENDPOINT"];
71
- }
72
- if (!this.apiEndpoint && this.isGemini3Preview) {
73
- this.apiEndpoint = GEMINI3_PREVIEW_API_ENDPOINT;
74
- import_logger.logger.info(`Using Gemini 3 preview endpoint: ${this.apiEndpoint}`);
75
- }
76
- let useVertexAI = !!vertexai;
77
- if (!useVertexAI && canReadEnv) {
78
- const vertexAIfromEnv = process.env["GOOGLE_GENAI_USE_VERTEXAI"];
79
- if (vertexAIfromEnv) {
80
- useVertexAI = vertexAIfromEnv.toLowerCase() === "true" || vertexAIfromEnv === "1";
81
- }
82
- }
83
- if (this.isGemini3Preview && useVertexAI) {
84
- const availableApiKey = apiKey || (canReadEnv ? process.env["GOOGLE_GENAI_API_KEY"] || process.env["GEMINI_API_KEY"] : void 0);
85
- if (availableApiKey) {
86
- import_logger.logger.info(
87
- "Gemini 3 preview detected with Vertex AI mode. Switching to API key mode for correct endpoint handling."
88
- );
89
- useVertexAI = false;
90
- this.apiKey = availableApiKey;
91
- } else {
92
- import_logger.logger.warn(
93
- "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."
94
- );
95
- }
96
- }
97
- this.vertexai = useVertexAI;
98
- if (this.vertexai) {
99
- if (canReadEnv && !this.project) {
100
- this.project = process.env["GOOGLE_CLOUD_PROJECT"];
101
- }
102
- if (canReadEnv && !this.location) {
103
- this.location = process.env["GOOGLE_CLOUD_LOCATION"];
104
- }
105
- if (!this.project) {
106
- throw new Error(
107
- "VertexAI project must be provided via constructor or GOOGLE_CLOUD_PROJECT environment variable."
108
- );
109
- }
110
- if (!this.location) {
111
- throw new Error(
112
- "VertexAI location must be provided via constructor or GOOGLE_CLOUD_LOCATION environment variable."
113
- );
114
- }
115
- } else {
116
- if (!this.apiKey && canReadEnv) {
117
- this.apiKey = process.env["GOOGLE_GENAI_API_KEY"] || process.env["GEMINI_API_KEY"];
118
- }
119
- if (!this.apiKey) {
120
- throw new Error(
121
- "API key must be provided via constructor or GOOGLE_GENAI_API_KEY or GEMINI_API_KEY environment variable."
122
- );
123
- }
124
- }
125
- }
126
- /**
127
- * Sends a request to the Gemini model.
128
- *
129
- * @param llmRequest LlmRequest, the request to send to the Gemini model.
130
- * @param stream bool = false, whether to do streaming call.
131
- * @yields LlmResponse: The model response.
132
- */
133
- async *generateContentAsync(llmRequest, stream = false) {
134
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
135
- this.preprocessRequest(llmRequest);
136
- this.maybeAppendUserContent(llmRequest);
137
- import_logger.logger.info(
138
- `Sending out request, model: ${llmRequest.model}, backend: ${this.apiBackend}, stream: ${stream}`
139
- );
140
- if ((_a = llmRequest.config) == null ? void 0 : _a.httpOptions) {
141
- llmRequest.config.httpOptions.headers = {
142
- ...llmRequest.config.httpOptions.headers,
143
- ...this.trackingHeaders
144
- };
145
- }
146
- if (stream) {
147
- const streamResult = await this.apiClient.models.generateContentStream({
148
- model: (_b = llmRequest.model) != null ? _b : this.model,
149
- contents: llmRequest.contents,
150
- config: llmRequest.config
151
- });
152
- let thoughtText = "";
153
- let thoughtSignature;
154
- let text = "";
155
- let usageMetadata;
156
- let lastResponse;
157
- if (this.isGemini3Preview && this.cachedThoughtSignature) {
158
- import_logger.logger.info(
159
- `[Gemini3] Starting new request with CACHED thoughtSignature (length: ${this.cachedThoughtSignature.length})`
160
- );
161
- }
162
- for await (const response of streamResult) {
163
- lastResponse = response;
164
- const llmResponse = (0, import_llm_response.createLlmResponse)(response);
165
- usageMetadata = llmResponse.usageMetadata;
166
- const firstPart = (_d = (_c = llmResponse.content) == null ? void 0 : _c.parts) == null ? void 0 : _d[0];
167
- const hasFunctionCalls = (_f = (_e = llmResponse.content) == null ? void 0 : _e.parts) == null ? void 0 : _f.some(
168
- (part) => part.functionCall
169
- );
170
- if (this.isGemini3Preview && ((_g = llmResponse.content) == null ? void 0 : _g.parts)) {
171
- for (const part of llmResponse.content.parts) {
172
- if (part.thoughtSignature && !thoughtSignature) {
173
- thoughtSignature = part.thoughtSignature;
174
- this.cachedThoughtSignature = thoughtSignature;
175
- import_logger.logger.info(
176
- `[Gemini3] Captured and CACHED thoughtSignature from response part (length: ${thoughtSignature.length})`
177
- );
178
- break;
179
- }
180
- }
181
- }
182
- if (firstPart == null ? void 0 : firstPart.text) {
183
- if ("thought" in firstPart && firstPart.thought) {
184
- thoughtText += firstPart.text;
185
- if ("thoughtSignature" in firstPart && firstPart.thoughtSignature) {
186
- thoughtSignature = firstPart.thoughtSignature;
187
- this.cachedThoughtSignature = thoughtSignature;
188
- import_logger.logger.info(
189
- `[Gemini3] Captured and CACHED thoughtSignature from thought part (length: ${thoughtSignature.length})`
190
- );
191
- }
192
- } else {
193
- text += firstPart.text;
194
- }
195
- llmResponse.partial = true;
196
- if (this.isGemini3Preview && hasFunctionCalls) {
197
- const responseHasSignature = (_i = (_h = llmResponse.content) == null ? void 0 : _h.parts) == null ? void 0 : _i.some(
198
- (p) => p.thoughtSignature
199
- );
200
- import_logger.logger.info(
201
- `[Gemini3] Chunk has thought AND function calls. Response has signature: ${responseHasSignature}`
202
- );
203
- thoughtText = "";
204
- thoughtSignature = void 0;
205
- text = "";
206
- }
207
- } else if ((thoughtText || text) && (!firstPart || !firstPart.inlineData)) {
208
- if (this.isGemini3Preview && hasFunctionCalls && llmResponse.content) {
209
- import_logger.logger.info(
210
- `[Gemini3] Merging thought with function calls. Has accumulated signature: ${!!thoughtSignature}`
211
- );
212
- const prependParts = [];
213
- if (thoughtText) {
214
- const thoughtPart = { text: thoughtText, thought: true };
215
- if (thoughtSignature) {
216
- thoughtPart.thoughtSignature = thoughtSignature;
217
- }
218
- prependParts.push(thoughtPart);
219
- import_logger.logger.info(
220
- `[Gemini3] Created thought part with signature: ${!!thoughtSignature}`
221
- );
222
- }
223
- if (text) {
224
- prependParts.push((0, import_genai.createPartFromText)(text));
225
- }
226
- if (!thoughtText && thoughtSignature) {
227
- let signatureApplied = false;
228
- for (const part of llmResponse.content.parts || []) {
229
- if (part.functionCall && !signatureApplied) {
230
- if (!part.thoughtSignature) {
231
- part.thoughtSignature = thoughtSignature;
232
- import_logger.logger.info(
233
- `[Gemini3] Applied accumulated signature to first function call: ${part.functionCall.name}`
234
- );
235
- }
236
- signatureApplied = true;
237
- }
238
- }
239
- }
240
- llmResponse.content.parts = [
241
- ...prependParts,
242
- ...llmResponse.content.parts || []
243
- ];
244
- import_logger.logger.info(
245
- `[Gemini3] Final merged content has ${llmResponse.content.parts.length} parts`
246
- );
247
- for (let i = 0; i < llmResponse.content.parts.length; i++) {
248
- const p = llmResponse.content.parts[i];
249
- import_logger.logger.info(
250
- `[Gemini3] Part ${i}: thought=${!!p.thought}, functionCall=${((_j = p.functionCall) == null ? void 0 : _j.name) || "none"}, hasSignature=${!!p.thoughtSignature}`
251
- );
252
- }
253
- thoughtText = "";
254
- thoughtSignature = void 0;
255
- text = "";
256
- } else {
257
- const parts = [];
258
- if (thoughtText) {
259
- const thoughtPart = { text: thoughtText, thought: true };
260
- if (thoughtSignature) {
261
- thoughtPart.thoughtSignature = thoughtSignature;
262
- }
263
- parts.push(thoughtPart);
264
- }
265
- if (text) {
266
- parts.push((0, import_genai.createPartFromText)(text));
267
- }
268
- yield {
269
- content: {
270
- role: "model",
271
- parts
272
- },
273
- usageMetadata: llmResponse.usageMetadata
274
- };
275
- thoughtText = "";
276
- thoughtSignature = void 0;
277
- text = "";
278
- }
279
- }
280
- if (this.isGemini3Preview && hasFunctionCalls && ((_k = llmResponse.content) == null ? void 0 : _k.parts)) {
281
- const hasExistingSignature = llmResponse.content.parts.some(
282
- (p) => p.thoughtSignature
283
- );
284
- if (!hasExistingSignature && thoughtSignature) {
285
- for (const part of llmResponse.content.parts) {
286
- if (part.functionCall) {
287
- part.thoughtSignature = thoughtSignature;
288
- import_logger.logger.info(
289
- `[Gemini3] Applied cached signature to first function call: ${part.functionCall.name}`
290
- );
291
- break;
292
- }
293
- }
294
- }
295
- const functionCallNames = llmResponse.content.parts.filter((p) => p.functionCall).map((p) => p.functionCall.name);
296
- let partsWithSig = llmResponse.content.parts.filter(
297
- (p) => p.thoughtSignature
298
- ).length;
299
- if (partsWithSig === 0) {
300
- const signatureToUse = thoughtSignature || this.cachedThoughtSignature;
301
- if (signatureToUse) {
302
- for (const part of llmResponse.content.parts) {
303
- if (part.functionCall && !part.thoughtSignature) {
304
- part.thoughtSignature = signatureToUse;
305
- import_logger.logger.info(
306
- `[Gemini3] Applied CACHED signature to function call: ${part.functionCall.name} (API didn't return new signature, using ${thoughtSignature ? "local" : "class-level"} cache)`
307
- );
308
- partsWithSig = 1;
309
- break;
310
- }
311
- }
312
- }
313
- }
314
- import_logger.logger.info(
315
- `[Gemini3] Yielding function call response: calls=[${functionCallNames.join(", ")}], partsWithSignature=${partsWithSig}`
316
- );
317
- if (partsWithSig === 0) {
318
- import_logger.logger.warn(
319
- `[Gemini3] WARNING: No thoughtSignature found and no cached signature available! This may cause 400 errors on next request.`
320
- );
321
- }
322
- }
323
- yield llmResponse;
324
- }
325
- if ((text || thoughtText) && ((_m = (_l = lastResponse == null ? void 0 : lastResponse.candidates) == null ? void 0 : _l[0]) == null ? void 0 : _m.finishReason) === import_genai.FinishReason.STOP) {
326
- const parts = [];
327
- if (thoughtText) {
328
- const thoughtPart = { text: thoughtText, thought: true };
329
- if (thoughtSignature) {
330
- thoughtPart.thoughtSignature = thoughtSignature;
331
- }
332
- parts.push(thoughtPart);
333
- }
334
- if (text) {
335
- parts.push({ text });
336
- }
337
- yield {
338
- content: {
339
- role: "model",
340
- parts
341
- },
342
- usageMetadata
343
- };
344
- }
345
- } else {
346
- const response = await this.apiClient.models.generateContent({
347
- model: (_n = llmRequest.model) != null ? _n : this.model,
348
- contents: llmRequest.contents,
349
- config: llmRequest.config
350
- });
351
- const llmResponse = (0, import_llm_response.createLlmResponse)(response);
352
- if (this.isGemini3Preview && ((_o = llmResponse.content) == null ? void 0 : _o.parts)) {
353
- let thoughtSig;
354
- let hasThoughtPartWithSignature = false;
355
- for (const part of llmResponse.content.parts) {
356
- if (part.thoughtSignature) {
357
- thoughtSig = part.thoughtSignature;
358
- this.cachedThoughtSignature = thoughtSig;
359
- if (part.thought) {
360
- hasThoughtPartWithSignature = true;
361
- }
362
- break;
363
- }
364
- }
365
- import_logger.logger.info(
366
- `[Gemini3] Non-streaming response: hasSignature=${!!thoughtSig}, hasThoughtPart=${hasThoughtPartWithSignature}, hasCachedSig=${!!this.cachedThoughtSignature}`
367
- );
368
- if (thoughtSig && !hasThoughtPartWithSignature) {
369
- let signatureApplied = false;
370
- for (const part of llmResponse.content.parts) {
371
- if (part.functionCall) {
372
- if (!signatureApplied && !part.thoughtSignature) {
373
- part.thoughtSignature = thoughtSig;
374
- import_logger.logger.info(
375
- `[Gemini3] Applied signature to first function call: ${part.functionCall.name}`
376
- );
377
- }
378
- signatureApplied = true;
379
- }
380
- }
381
- }
382
- const hasFunctionCalls = llmResponse.content.parts.some(
383
- (p) => p.functionCall
384
- );
385
- if (hasFunctionCalls) {
386
- let partsWithSig = llmResponse.content.parts.filter(
387
- (p) => p.thoughtSignature
388
- ).length;
389
- if (partsWithSig === 0 && this.cachedThoughtSignature) {
390
- for (const part of llmResponse.content.parts) {
391
- if (part.functionCall && !part.thoughtSignature) {
392
- part.thoughtSignature = this.cachedThoughtSignature;
393
- import_logger.logger.info(
394
- `[Gemini3] Applied CACHED signature to function call: ${part.functionCall.name} (API didn't return new signature)`
395
- );
396
- partsWithSig = 1;
397
- break;
398
- }
399
- }
400
- }
401
- for (let i = 0; i < llmResponse.content.parts.length; i++) {
402
- const p = llmResponse.content.parts[i];
403
- import_logger.logger.info(
404
- `[Gemini3] Response Part ${i}: thought=${!!p.thought}, functionCall=${((_p = p.functionCall) == null ? void 0 : _p.name) || "none"}, hasSignature=${!!p.thoughtSignature}`
405
- );
406
- }
407
- if (partsWithSig === 0) {
408
- import_logger.logger.warn(
409
- `[Gemini3] WARNING: No thoughtSignature found and no cached signature available! This may cause 400 errors on next request.`
410
- );
411
- }
412
- }
413
- }
414
- yield llmResponse;
415
- }
416
- }
417
- get apiClient() {
418
- if (this._apiClient) {
419
- return this._apiClient;
420
- }
421
- const combinedHeaders = {
422
- ...this.trackingHeaders,
423
- ...this.headers
424
- };
425
- if (this.vertexai) {
426
- this._apiClient = new import_genai.GoogleGenAI({
427
- vertexai: this.vertexai,
428
- project: this.project,
429
- location: this.location,
430
- httpOptions: { headers: combinedHeaders }
431
- });
432
- } else {
433
- const httpOptions = { headers: combinedHeaders };
434
- if (this.apiEndpoint) {
435
- httpOptions.baseUrl = this.apiEndpoint;
436
- import_logger.logger.debug(`Using custom API endpoint: ${this.apiEndpoint}`);
437
- if (this.isGemini3Preview) {
438
- httpOptions.apiVersion = "";
439
- import_logger.logger.info(
440
- `Gemini 3 preview mode: using direct API path without version prefix`
441
- );
442
- }
443
- }
444
- this._apiClient = new import_genai.GoogleGenAI({
445
- apiKey: this.apiKey,
446
- vertexai: false,
447
- httpOptions
448
- });
449
- }
450
- return this._apiClient;
451
- }
452
- get apiBackend() {
453
- if (!this._apiBackend) {
454
- this._apiBackend = this.apiClient.vertexai ? import_variant_utils.GoogleLLMVariant.VERTEX_AI : import_variant_utils.GoogleLLMVariant.GEMINI_API;
455
- }
456
- return this._apiBackend;
457
- }
458
- get liveApiVersion() {
459
- if (!this._liveApiVersion) {
460
- this._liveApiVersion = this.apiBackend === import_variant_utils.GoogleLLMVariant.VERTEX_AI ? "v1beta1" : "v1alpha";
461
- }
462
- return this._liveApiVersion;
463
- }
464
- get liveApiClient() {
465
- if (!this._liveApiClient) {
466
- const httpOptions = {
467
- headers: this.trackingHeaders,
468
- apiVersion: this.liveApiVersion
469
- };
470
- if (this.apiEndpoint) {
471
- httpOptions.baseUrl = this.apiEndpoint;
472
- if (this.isGemini3Preview) {
473
- httpOptions.apiVersion = "";
474
- }
475
- }
476
- this._liveApiClient = new import_genai.GoogleGenAI({
477
- apiKey: this.apiKey,
478
- httpOptions
479
- });
480
- }
481
- return this._liveApiClient;
482
- }
483
- /**
484
- * Connects to the Gemini model and returns an llm connection.
485
- *
486
- * @param llmRequest LlmRequest, the request to send to the Gemini model.
487
- * @returns BaseLlmConnection, the connection to the Gemini model.
488
- */
489
- async connect(llmRequest) {
490
- var _a, _b, _c, _d;
491
- if ((_a = llmRequest.liveConnectConfig) == null ? void 0 : _a.httpOptions) {
492
- if (!llmRequest.liveConnectConfig.httpOptions.headers) {
493
- llmRequest.liveConnectConfig.httpOptions.headers = {};
494
- }
495
- Object.assign(
496
- llmRequest.liveConnectConfig.httpOptions.headers,
497
- this.trackingHeaders
498
- );
499
- llmRequest.liveConnectConfig.httpOptions.apiVersion = this.isGemini3Preview ? "" : this.liveApiVersion;
500
- }
501
- if ((_b = llmRequest.config) == null ? void 0 : _b.systemInstruction) {
502
- llmRequest.liveConnectConfig.systemInstruction = {
503
- role: "system",
504
- // TODO - b/425992518: validate type casting works well.
505
- parts: [
506
- (0, import_genai.createPartFromText)(llmRequest.config.systemInstruction)
507
- ]
508
- };
509
- }
510
- llmRequest.liveConnectConfig.tools = (_c = llmRequest.config) == null ? void 0 : _c.tools;
511
- const liveSession = await this.liveApiClient.live.connect({
512
- model: (_d = llmRequest.model) != null ? _d : this.model,
513
- config: llmRequest.liveConnectConfig,
514
- callbacks: {
515
- // TODO - b/425992518: GenAI SDK inconsistent API, missing methods.
516
- onmessage: () => {
517
- }
518
- }
519
- });
520
- return new import_gemini_llm_connection.GeminiLlmConnection(liveSession);
521
- }
522
- preprocessRequest(llmRequest) {
523
- if (this.apiBackend === import_variant_utils.GoogleLLMVariant.GEMINI_API) {
524
- if (llmRequest.config) {
525
- llmRequest.config.labels = void 0;
526
- }
527
- if (llmRequest.contents) {
528
- for (const content of llmRequest.contents) {
529
- if (!content.parts) continue;
530
- for (const part of content.parts) {
531
- removeDisplayNameIfPresent(part.inlineData);
532
- removeDisplayNameIfPresent(part.fileData);
533
- }
534
- }
535
- }
536
- }
537
- }
538
- }
539
- /**
540
- * A list of model name patterns that are supported by this LLM.
541
- *
542
- * @returns A list of supported models.
543
- */
544
- Gemini.supportedModels = [
545
- /gemini-.*/,
546
- // fine-tuned vertex endpoint pattern
547
- /projects\/.+\/locations\/.+\/endpoints\/.+/,
548
- // vertex gemini long name
549
- /projects\/.+\/locations\/.+\/publishers\/google\/models\/gemini.+/
550
- ];
551
- function removeDisplayNameIfPresent(dataObj) {
552
- if (dataObj && dataObj.displayName) {
553
- dataObj.displayName = void 0;
554
- }
555
- }
556
- // Annotate the CommonJS export names for ESM import in node:
557
- 0 && (module.exports = {
558
- Gemini
559
- });