@google/adk 2.4.0 → 2.5.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.
Files changed (326) hide show
  1. package/dist/cjs/a2a/a2a_remote_agent.js +17 -2
  2. package/dist/cjs/a2a/a2a_remote_agent_utils.js +8 -4
  3. package/dist/cjs/a2a/agent_card.js +5 -81
  4. package/dist/cjs/a2a/agent_to_a2a.js +7 -0
  5. package/dist/cjs/a2a/event_converter_utils.js +10 -3
  6. package/dist/cjs/agents/agent_engine_client.js +282 -55
  7. package/dist/cjs/agents/base_agent.js +111 -68
  8. package/dist/cjs/agents/functions.js +62 -85
  9. package/dist/cjs/agents/instructions.js +7 -6
  10. package/dist/cjs/agents/invocation_context.js +2 -2
  11. package/dist/cjs/agents/llm_agent.js +105 -95
  12. package/dist/cjs/agents/processors/content_processor_utils.js +42 -15
  13. package/dist/cjs/agents/processors/content_request_processor.js +28 -11
  14. package/dist/cjs/agents/processors/context_compactor_request_processor.js +5 -1
  15. package/dist/cjs/agents/processors/instructions_llm_request_processor.js +1 -1
  16. package/dist/cjs/agents/processors/nl_planning_processor.js +2 -1
  17. package/dist/cjs/artifacts/file_artifact_service.js +1 -1
  18. package/dist/cjs/cli/cli_eval.js +884 -17
  19. package/dist/cjs/cli/utils/cleanup.js +84 -0
  20. package/dist/cjs/cli/utils/envs.js +33 -2
  21. package/dist/cjs/cli/utils/evals.js +75 -8
  22. package/dist/cjs/cli/utils/logs.js +128 -9
  23. package/dist/cjs/cli/utils/path_validation.js +83 -0
  24. package/dist/cjs/code_executors/container_code_executor.js +158 -36
  25. package/dist/cjs/common.js +50 -12
  26. package/dist/cjs/context/compaction_utils.js +19 -0
  27. package/dist/cjs/events/event.js +7 -3
  28. package/dist/cjs/features/feature_registry.js +5 -0
  29. package/dist/cjs/index.js +29 -14
  30. package/dist/cjs/models/google_llm.js +33 -2
  31. package/dist/cjs/models/interactions_utils.js +3 -0
  32. package/dist/cjs/plugins/base_plugin.js +45 -21
  33. package/dist/cjs/plugins/plugin_manager.js +27 -0
  34. package/dist/cjs/runner/runner.js +306 -189
  35. package/dist/cjs/sessions/base_session_service.js +1 -4
  36. package/dist/cjs/sessions/database_session_service.js +191 -19
  37. package/dist/cjs/sessions/db/operations.js +70 -1
  38. package/dist/cjs/sessions/db/schema.js +4 -0
  39. package/dist/cjs/sessions/in_memory_session_service.js +2 -2
  40. package/dist/cjs/sessions/vertex_ai_session_service.js +11 -3
  41. package/dist/cjs/skills/loader.js +29 -28
  42. package/dist/cjs/telemetry/api/instrumentation.js +632 -0
  43. package/dist/cjs/telemetry/api/internal/common/accumulators.js +169 -0
  44. package/dist/cjs/telemetry/api/internal/common/attributes.js +131 -0
  45. package/dist/cjs/telemetry/api/internal/common/config.js +159 -0
  46. package/dist/cjs/telemetry/api/internal/common/error.js +98 -0
  47. package/dist/cjs/telemetry/api/internal/common/finish_reason.js +63 -0
  48. package/dist/cjs/telemetry/api/internal/common/genai_messages.js +217 -0
  49. package/dist/cjs/telemetry/api/internal/common/http_exchange.js +169 -0
  50. package/dist/cjs/telemetry/api/internal/common/provider_name.js +87 -0
  51. package/dist/cjs/telemetry/api/internal/common/redaction.js +148 -0
  52. package/dist/cjs/telemetry/api/internal/common/serialization.js +58 -0
  53. package/dist/cjs/telemetry/api/internal/common/token_usage.js +118 -0
  54. package/dist/cjs/telemetry/api/internal/logs/inference.js +50 -0
  55. package/dist/cjs/telemetry/api/internal/logs/logger.js +46 -0
  56. package/dist/cjs/telemetry/api/internal/logs/mcp.js +141 -0
  57. package/dist/cjs/telemetry/api/internal/metrics/agent.js +128 -0
  58. package/dist/cjs/telemetry/api/internal/metrics/inference_start_hook.js +56 -0
  59. package/dist/cjs/telemetry/api/internal/metrics/meters.js +189 -0
  60. package/dist/cjs/telemetry/api/internal/metrics/tool.js +147 -0
  61. package/dist/cjs/telemetry/api/internal/metrics/workflow.js +132 -0
  62. package/dist/cjs/telemetry/api/internal/trace/agent.js +52 -0
  63. package/dist/cjs/telemetry/api/internal/trace/compaction.js +78 -0
  64. package/dist/cjs/telemetry/api/internal/trace/inference.js +132 -0
  65. package/dist/cjs/telemetry/api/internal/trace/live.js +52 -0
  66. package/dist/cjs/telemetry/api/internal/trace/node.js +73 -0
  67. package/dist/cjs/telemetry/api/internal/trace/propagation.js +67 -0
  68. package/dist/cjs/telemetry/api/internal/trace/tool.js +122 -0
  69. package/dist/cjs/telemetry/api/internal/trace/tracer.js +77 -0
  70. package/dist/cjs/telemetry/api/internal/trace/workflow.js +77 -0
  71. package/dist/cjs/telemetry/export/agent_engine.js +90 -0
  72. package/dist/cjs/telemetry/export/agent_runtime.js +73 -0
  73. package/dist/cjs/telemetry/export/google_cloud.js +763 -0
  74. package/dist/cjs/telemetry/export/request_driven_metric_reader.js +303 -0
  75. package/dist/cjs/telemetry/{setup.js → export/setup.js} +72 -5
  76. package/dist/cjs/tools/agent_tool.js +9 -1
  77. package/dist/cjs/tools/application_integration_tool/application_integration_toolset.js +22 -34
  78. package/dist/cjs/tools/application_integration_tool/clients/connections_client.js +60 -20
  79. package/dist/cjs/tools/application_integration_tool/clients/integration_client.js +26 -10
  80. package/dist/cjs/tools/application_integration_tool/integration_connector_tool.js +14 -23
  81. package/dist/cjs/tools/base_toolset.js +1 -1
  82. package/dist/cjs/tools/computer_use/base_computer.js +125 -0
  83. package/dist/cjs/tools/computer_use/computer_use_actions.js +502 -0
  84. package/dist/cjs/tools/computer_use/computer_use_tool.js +244 -0
  85. package/dist/cjs/tools/computer_use/computer_use_toolset.js +360 -0
  86. package/dist/cjs/tools/function_tool.js +15 -5
  87. package/dist/cjs/tools/google_api_tool/google_api_toolset.js +3 -2
  88. package/dist/cjs/tools/google_api_tool/googleapi_to_openapi_converter.js +3 -1
  89. package/dist/cjs/tools/load_artifacts_tool.js +15 -5
  90. package/dist/cjs/tools/load_memory_tool.js +2 -5
  91. package/dist/cjs/tools/mcp/mcp_session_manager.js +23 -3
  92. package/dist/cjs/tools/mcp/mcp_tool.js +7 -3
  93. package/dist/cjs/tools/mcp/mcp_toolset.js +18 -6
  94. package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +30 -29
  95. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -2
  96. package/dist/cjs/tools/openapi_tool/rest_api_tool.js +45 -14
  97. package/dist/cjs/tools/skill/load_skill_resource_tool.js +7 -0
  98. package/dist/cjs/tools/skill/load_skill_tool.js +3 -0
  99. package/dist/cjs/tools/skill/run_skill_script_tool.js +12 -2
  100. package/dist/cjs/tools/toolbox_toolset.js +47 -28
  101. package/dist/cjs/utils/async_queue.js +37 -3
  102. package/dist/cjs/utils/client_labels.js +9 -11
  103. package/dist/cjs/utils/env_aware_utils.js +13 -7
  104. package/dist/cjs/utils/error_utils.js +40 -2
  105. package/dist/cjs/utils/failover_utils.js +10 -9
  106. package/dist/cjs/utils/gemini_schema_util.js +125 -12
  107. package/dist/cjs/utils/id_provider.js +63 -0
  108. package/dist/cjs/utils/model_name.js +15 -0
  109. package/dist/cjs/utils/simple_zod_to_json.js +13 -31
  110. package/dist/cjs/utils/ssrf_guard.js +46 -16
  111. package/dist/cjs/version.js +1 -1
  112. package/dist/cjs/workflow/index.js +2 -0
  113. package/dist/cjs/workflow/node_runner.js +24 -80
  114. package/dist/cjs/workflow/nodes/parallel_worker.js +18 -7
  115. package/dist/cjs/workflow/run_llm_agent_as_node.js +19 -14
  116. package/dist/cjs/workflow/utils/retry_utils.js +2 -2
  117. package/dist/cjs/workflow/workflow.js +12 -12
  118. package/dist/esm/a2a/a2a_remote_agent.js +23 -3
  119. package/dist/esm/a2a/a2a_remote_agent_utils.js +8 -4
  120. package/dist/esm/a2a/agent_card.js +5 -83
  121. package/dist/esm/a2a/agent_to_a2a.js +7 -0
  122. package/dist/esm/a2a/event_converter_utils.js +10 -3
  123. package/dist/esm/agents/agent_engine_client.js +293 -55
  124. package/dist/esm/agents/base_agent.js +111 -72
  125. package/dist/esm/agents/functions.js +67 -89
  126. package/dist/esm/agents/instructions.js +7 -6
  127. package/dist/esm/agents/invocation_context.js +2 -2
  128. package/dist/esm/agents/llm_agent.js +111 -100
  129. package/dist/esm/agents/processors/content_processor_utils.js +42 -15
  130. package/dist/esm/agents/processors/content_request_processor.js +28 -11
  131. package/dist/esm/agents/processors/context_compactor_request_processor.js +5 -1
  132. package/dist/esm/agents/processors/instructions_llm_request_processor.js +1 -1
  133. package/dist/esm/agents/processors/nl_planning_processor.js +2 -1
  134. package/dist/esm/artifacts/file_artifact_service.js +1 -1
  135. package/dist/esm/cli/cli_eval.js +880 -17
  136. package/dist/esm/cli/utils/cleanup.js +56 -0
  137. package/dist/esm/cli/utils/envs.js +33 -2
  138. package/dist/esm/cli/utils/evals.js +74 -8
  139. package/dist/esm/cli/utils/logs.js +128 -9
  140. package/dist/esm/cli/utils/path_validation.js +45 -0
  141. package/dist/esm/code_executors/container_code_executor.js +158 -36
  142. package/dist/esm/common.js +49 -6
  143. package/dist/esm/context/compaction_utils.js +19 -0
  144. package/dist/esm/events/event.js +7 -3
  145. package/dist/esm/features/feature_registry.js +5 -0
  146. package/dist/esm/index.js +27 -15
  147. package/dist/esm/models/google_llm.js +33 -2
  148. package/dist/esm/models/interactions_utils.js +3 -0
  149. package/dist/esm/plugins/base_plugin.js +45 -21
  150. package/dist/esm/plugins/plugin_manager.js +27 -0
  151. package/dist/esm/runner/runner.js +310 -192
  152. package/dist/esm/sessions/base_session_service.js +1 -4
  153. package/dist/esm/sessions/database_session_service.js +191 -19
  154. package/dist/esm/sessions/db/operations.js +70 -1
  155. package/dist/esm/sessions/db/schema.js +4 -0
  156. package/dist/esm/sessions/in_memory_session_service.js +2 -2
  157. package/dist/esm/sessions/vertex_ai_session_service.js +11 -3
  158. package/dist/esm/skills/loader.js +29 -28
  159. package/dist/esm/telemetry/api/instrumentation.js +655 -0
  160. package/dist/esm/telemetry/api/internal/common/accumulators.js +139 -0
  161. package/dist/esm/telemetry/api/internal/common/attributes.js +94 -0
  162. package/dist/esm/telemetry/api/internal/common/config.js +128 -0
  163. package/dist/esm/telemetry/api/internal/common/error.js +69 -0
  164. package/dist/esm/telemetry/api/internal/common/finish_reason.js +35 -0
  165. package/dist/esm/telemetry/api/internal/common/genai_messages.js +188 -0
  166. package/dist/esm/telemetry/api/internal/common/http_exchange.js +142 -0
  167. package/dist/esm/telemetry/api/internal/common/provider_name.js +59 -0
  168. package/dist/esm/telemetry/api/internal/common/redaction.js +121 -0
  169. package/dist/esm/telemetry/api/internal/common/serialization.js +30 -0
  170. package/dist/esm/telemetry/api/internal/common/token_usage.js +85 -0
  171. package/dist/esm/telemetry/api/internal/logs/inference.js +23 -0
  172. package/dist/esm/telemetry/api/internal/logs/logger.js +19 -0
  173. package/dist/esm/telemetry/api/internal/logs/mcp.js +113 -0
  174. package/dist/esm/telemetry/api/internal/metrics/agent.js +107 -0
  175. package/dist/esm/telemetry/api/internal/metrics/inference_start_hook.js +29 -0
  176. package/dist/esm/telemetry/api/internal/metrics/meters.js +165 -0
  177. package/dist/esm/telemetry/api/internal/metrics/tool.js +119 -0
  178. package/dist/esm/telemetry/api/internal/metrics/workflow.js +112 -0
  179. package/dist/esm/telemetry/api/internal/trace/agent.js +25 -0
  180. package/dist/esm/telemetry/api/internal/trace/compaction.js +50 -0
  181. package/dist/esm/telemetry/api/internal/trace/inference.js +107 -0
  182. package/dist/esm/telemetry/api/internal/trace/live.js +28 -0
  183. package/dist/esm/telemetry/api/internal/trace/node.js +44 -0
  184. package/dist/esm/telemetry/api/internal/trace/propagation.js +39 -0
  185. package/dist/esm/telemetry/api/internal/trace/tool.js +96 -0
  186. package/dist/esm/telemetry/api/internal/trace/tracer.js +52 -0
  187. package/dist/esm/telemetry/api/internal/trace/workflow.js +54 -0
  188. package/dist/esm/telemetry/export/agent_engine.js +67 -0
  189. package/dist/esm/telemetry/export/agent_runtime.js +46 -0
  190. package/dist/esm/telemetry/export/google_cloud.js +733 -0
  191. package/dist/esm/telemetry/export/request_driven_metric_reader.js +276 -0
  192. package/dist/esm/telemetry/export/setup.js +160 -0
  193. package/dist/esm/tools/agent_tool.js +9 -1
  194. package/dist/esm/tools/application_integration_tool/application_integration_toolset.js +23 -35
  195. package/dist/esm/tools/application_integration_tool/clients/connections_client.js +64 -21
  196. package/dist/esm/tools/application_integration_tool/clients/integration_client.js +26 -10
  197. package/dist/esm/tools/application_integration_tool/integration_connector_tool.js +14 -23
  198. package/dist/esm/tools/base_toolset.js +1 -1
  199. package/dist/esm/tools/computer_use/base_computer.js +99 -0
  200. package/dist/esm/tools/computer_use/computer_use_actions.js +477 -0
  201. package/dist/esm/tools/computer_use/computer_use_tool.js +217 -0
  202. package/dist/esm/tools/computer_use/computer_use_toolset.js +344 -0
  203. package/dist/esm/tools/function_tool.js +15 -5
  204. package/dist/esm/tools/google_api_tool/google_api_toolset.js +3 -2
  205. package/dist/esm/tools/google_api_tool/googleapi_to_openapi_converter.js +3 -1
  206. package/dist/esm/tools/load_artifacts_tool.js +15 -5
  207. package/dist/esm/tools/load_memory_tool.js +2 -5
  208. package/dist/esm/tools/mcp/mcp_session_manager.js +23 -3
  209. package/dist/esm/tools/mcp/mcp_tool.js +7 -3
  210. package/dist/esm/tools/mcp/mcp_toolset.js +18 -6
  211. package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +27 -26
  212. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -2
  213. package/dist/esm/tools/openapi_tool/rest_api_tool.js +45 -14
  214. package/dist/esm/tools/skill/load_skill_resource_tool.js +7 -0
  215. package/dist/esm/tools/skill/load_skill_tool.js +3 -0
  216. package/dist/esm/tools/skill/run_skill_script_tool.js +12 -2
  217. package/dist/esm/tools/toolbox_toolset.js +47 -28
  218. package/dist/esm/utils/async_queue.js +37 -3
  219. package/dist/esm/utils/client_labels.js +9 -11
  220. package/dist/esm/utils/env_aware_utils.js +12 -7
  221. package/dist/esm/utils/error_utils.js +37 -1
  222. package/dist/esm/utils/failover_utils.js +10 -9
  223. package/dist/esm/utils/gemini_schema_util.js +124 -11
  224. package/dist/esm/utils/id_provider.js +33 -0
  225. package/dist/esm/utils/model_name.js +14 -0
  226. package/dist/esm/utils/simple_zod_to_json.js +13 -31
  227. package/dist/esm/utils/ssrf_guard.js +55 -15
  228. package/dist/esm/version.js +1 -1
  229. package/dist/esm/workflow/index.js +2 -1
  230. package/dist/esm/workflow/node_runner.js +26 -80
  231. package/dist/esm/workflow/nodes/parallel_worker.js +16 -6
  232. package/dist/esm/workflow/run_llm_agent_as_node.js +19 -14
  233. package/dist/esm/workflow/utils/retry_utils.js +2 -2
  234. package/dist/esm/workflow/workflow.js +12 -12
  235. package/dist/types/a2a/a2a_remote_agent.d.ts +6 -0
  236. package/dist/types/a2a/a2a_remote_agent_utils.d.ts +3 -2
  237. package/dist/types/agents/agent_engine_client.d.ts +121 -3
  238. package/dist/types/agents/base_agent.d.ts +2 -0
  239. package/dist/types/agents/processors/content_processor_utils.d.ts +9 -9
  240. package/dist/types/agents/run_config.d.ts +14 -0
  241. package/dist/types/cli/cli_eval.d.ts +172 -9
  242. package/dist/types/cli/utils/cleanup.d.ts +18 -0
  243. package/dist/types/cli/utils/envs.d.ts +13 -3
  244. package/dist/types/cli/utils/evals.d.ts +64 -1
  245. package/dist/types/cli/utils/logs.d.ts +19 -2
  246. package/dist/types/cli/utils/path_validation.d.ts +30 -0
  247. package/dist/types/code_executors/container_code_executor.d.ts +49 -8
  248. package/dist/types/common.d.ts +16 -9
  249. package/dist/types/context/compaction_utils.d.ts +13 -1
  250. package/dist/types/events/event.d.ts +3 -0
  251. package/dist/types/features/feature_registry.d.ts +1 -0
  252. package/dist/types/index.d.ts +9 -6
  253. package/dist/types/plugins/base_plugin.d.ts +50 -21
  254. package/dist/types/plugins/plugin_manager.d.ts +13 -0
  255. package/dist/types/runner/runner.d.ts +11 -0
  256. package/dist/types/sessions/base_session_service.d.ts +0 -2
  257. package/dist/types/sessions/db/operations.d.ts +2 -1
  258. package/dist/types/sessions/db/schema.d.ts +5 -3
  259. package/dist/types/telemetry/api/instrumentation.d.ts +259 -0
  260. package/dist/types/telemetry/api/internal/common/accumulators.d.ts +91 -0
  261. package/dist/types/telemetry/api/internal/common/attributes.d.ts +90 -0
  262. package/dist/types/telemetry/api/internal/common/config.d.ts +61 -0
  263. package/dist/types/telemetry/api/internal/common/error.d.ts +29 -0
  264. package/dist/types/telemetry/api/internal/common/finish_reason.d.ts +18 -0
  265. package/dist/types/telemetry/api/internal/common/genai_messages.d.ts +26 -0
  266. package/dist/types/telemetry/api/internal/common/http_exchange.d.ts +50 -0
  267. package/dist/types/telemetry/api/internal/common/provider_name.d.ts +16 -0
  268. package/dist/types/telemetry/api/internal/common/redaction.d.ts +14 -0
  269. package/dist/types/telemetry/api/internal/common/serialization.d.ts +18 -0
  270. package/dist/types/telemetry/api/internal/common/token_usage.d.ts +47 -0
  271. package/dist/types/telemetry/api/internal/logs/inference.d.ts +15 -0
  272. package/dist/types/telemetry/api/internal/logs/logger.d.ts +13 -0
  273. package/dist/types/telemetry/api/internal/logs/mcp.d.ts +31 -0
  274. package/dist/types/telemetry/api/internal/metrics/agent.d.ts +28 -0
  275. package/dist/types/telemetry/api/internal/metrics/inference_start_hook.d.ts +12 -0
  276. package/dist/types/telemetry/api/internal/metrics/meters.d.ts +57 -0
  277. package/dist/types/telemetry/api/internal/metrics/tool.d.ts +44 -0
  278. package/dist/types/telemetry/api/internal/metrics/workflow.d.ts +32 -0
  279. package/dist/types/telemetry/api/internal/trace/agent.d.ts +14 -0
  280. package/dist/types/telemetry/api/internal/trace/compaction.d.ts +20 -0
  281. package/dist/types/telemetry/api/internal/trace/inference.d.ts +31 -0
  282. package/dist/types/telemetry/api/internal/trace/live.d.ts +21 -0
  283. package/dist/types/telemetry/api/internal/trace/node.d.ts +22 -0
  284. package/dist/types/telemetry/api/internal/trace/propagation.d.ts +22 -0
  285. package/dist/types/telemetry/api/internal/trace/tool.d.ts +57 -0
  286. package/dist/types/telemetry/api/internal/trace/tracer.d.ts +31 -0
  287. package/dist/types/telemetry/api/internal/trace/workflow.d.ts +21 -0
  288. package/dist/types/telemetry/export/agent_engine.d.ts +23 -0
  289. package/dist/types/telemetry/export/agent_runtime.d.ts +40 -0
  290. package/dist/types/telemetry/export/google_cloud.d.ts +189 -0
  291. package/dist/types/telemetry/export/request_driven_metric_reader.d.ts +144 -0
  292. package/dist/types/telemetry/{setup.d.ts → export/setup.d.ts} +3 -0
  293. package/dist/types/tools/agent_tool.d.ts +1 -1
  294. package/dist/types/tools/application_integration_tool/clients/connections_client.d.ts +13 -4
  295. package/dist/types/tools/base_toolset.d.ts +1 -1
  296. package/dist/types/tools/computer_use/base_computer.d.ts +281 -0
  297. package/dist/types/tools/computer_use/computer_use_actions.d.ts +53 -0
  298. package/dist/types/tools/computer_use/computer_use_tool.d.ts +108 -0
  299. package/dist/types/tools/computer_use/computer_use_toolset.d.ts +132 -0
  300. package/dist/types/tools/google_api_tool/google_api_toolset.d.ts +2 -0
  301. package/dist/types/tools/load_artifacts_tool.d.ts +5 -1
  302. package/dist/types/tools/load_memory_tool.d.ts +13 -7
  303. package/dist/types/tools/mcp/mcp_session_manager.d.ts +16 -0
  304. package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +8 -8
  305. package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +7 -3
  306. package/dist/types/tools/toolbox_toolset.d.ts +15 -20
  307. package/dist/types/utils/async_queue.d.ts +14 -0
  308. package/dist/types/utils/env_aware_utils.d.ts +11 -0
  309. package/dist/types/utils/error_utils.d.ts +4 -0
  310. package/dist/types/utils/gemini_schema_util.d.ts +27 -6
  311. package/dist/types/utils/id_provider.d.ts +43 -0
  312. package/dist/types/utils/model_name.d.ts +8 -0
  313. package/dist/types/utils/ssrf_guard.d.ts +2 -0
  314. package/dist/types/version.d.ts +1 -1
  315. package/dist/types/workflow/index.d.ts +1 -1
  316. package/dist/types/workflow/nodes/parallel_worker.d.ts +8 -1
  317. package/dist/web/index_web.js +86 -88
  318. package/dist/web/index_web.js.map +4 -4
  319. package/package.json +13 -15
  320. package/dist/cjs/telemetry/google_cloud.js +0 -116
  321. package/dist/cjs/telemetry/tracing.js +0 -393
  322. package/dist/esm/telemetry/google_cloud.js +0 -99
  323. package/dist/esm/telemetry/setup.js +0 -88
  324. package/dist/esm/telemetry/tracing.js +0 -361
  325. package/dist/types/telemetry/google_cloud.d.ts +0 -9
  326. package/dist/types/telemetry/tracing.d.ts +0 -143
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { Attributes, Span } from '@opentelemetry/api';
7
+ import type { LlmRequest } from '../../../../models/llm_request.js';
8
+ import type { LlmResponse } from '../../../../models/llm_response.js';
9
+ import { type ResolvedTelemetryConfig } from '../common/config.js';
10
+ import { type OperationDetails } from '../common/genai_messages.js';
11
+ /** Parameters for {@link startInferenceSpan}. */
12
+ export interface StartInferenceSpanParams {
13
+ readonly llmRequest: LlmRequest;
14
+ /** Attributes the span shares with the call's log record. */
15
+ readonly commonAttributes: Attributes;
16
+ }
17
+ /** Starts a `generate_content {model}` span under the active context. */
18
+ export declare function startInferenceSpan({ llmRequest, commonAttributes, }: StartInferenceSpanParams): Span;
19
+ /**
20
+ * Builds the attributes one model response contributes to both the span and
21
+ * the log record: its finish reason and its token usage.
22
+ */
23
+ export declare function buildResponseAttributes(llmResponse: LlmResponse): Attributes;
24
+ /** Records one model response on its `generate_content` span. */
25
+ export declare function setInferenceResponseAttributes(span: Span, llmResponse: LlmResponse, config: ResolvedTelemetryConfig): void;
26
+ /**
27
+ * Records the operation details of a model call on its span, as JSON: all of
28
+ * them when content capture includes spans, otherwise only the view without
29
+ * message content.
30
+ */
31
+ export declare function setInferenceOperationDetails(span: Span, details: OperationDetails, config: ResolvedTelemetryConfig): void;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Content } from '@google/genai';
7
+ import type { Span } from '@opentelemetry/api';
8
+ import type { InvocationContext } from '../../../../agents/invocation_context.js';
9
+ /** Parameters for recording live history `send_data` attributes on a span. */
10
+ export interface SetSendDataAttributesParams {
11
+ /** The invocation context for the current agent run. */
12
+ readonly invocationContext: InvocationContext;
13
+ /** The ID of the event. */
14
+ readonly eventId: string;
15
+ /** A list of content objects. */
16
+ readonly data: Content[];
17
+ }
18
+ /**
19
+ * Sets `send_data` attributes on the given span.
20
+ */
21
+ export declare function setSendDataAttributes(span: Span, { invocationContext, eventId, data }: SetSendDataAttributesParams): void;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { Span } from '@opentelemetry/api';
7
+ import type { BaseNode } from '../../../../workflow/base_node.js';
8
+ /**
9
+ * Whether a node is traced by a span of its own kind rather than by
10
+ * `invoke_node`: an agent opens `invoke_agent` and a workflow
11
+ * `invoke_workflow`.
12
+ */
13
+ export declare function hasOwnInvocationSpan(node: BaseNode): boolean;
14
+ /** Parameters for {@link startNodeSpan}. */
15
+ export interface StartNodeSpanParams {
16
+ readonly nodeName: string;
17
+ readonly sessionId: string;
18
+ }
19
+ /** Starts an `invoke_node {nodeName}` span under the active context. */
20
+ export declare function startNodeSpan({ nodeName, sessionId, }: StartNodeSpanParams): Span;
21
+ /** Records the ids of the events a node emitted on its span, if it emitted any. */
22
+ export declare function setAssociatedEventIds(span: Span, eventIds: readonly string[]): void;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { TextMapGetter } from '@opentelemetry/api';
7
+ /** Incoming request headers, such as Node's `IncomingMessage.headers`. */
8
+ export type IncomingHeaders = Readonly<Record<string, string | string[] | undefined>>;
9
+ /**
10
+ * Reads incoming request headers for the propagator, matching names
11
+ * case-insensitively. An array value is returned as is; the W3C propagator
12
+ * reads its first element.
13
+ */
14
+ export declare const INCOMING_HEADERS_GETTER: TextMapGetter<IncomingHeaders>;
15
+ /**
16
+ * Returns the headers a `fetch(input, init)` call sends, with each injected
17
+ * header added unless the call already sets it.
18
+ *
19
+ * As in `fetch`, `init.headers` replaces the headers of a `Request` input
20
+ * when given, and the `Request` headers are kept otherwise.
21
+ */
22
+ export declare function addMissingHeaders(input: Parameters<typeof globalThis.fetch>[0], init: Parameters<typeof globalThis.fetch>[1], injected: Readonly<Record<string, string>>): Headers;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { Attributes, Span } from '@opentelemetry/api';
7
+ import type { Event } from '../../../../events/event.js';
8
+ import type { Skill } from '../../../../skills/skill.js';
9
+ import type { BaseTool } from '../../../../tools/base_tool.js';
10
+ import type { ResolvedTelemetryConfig } from '../common/config.js';
11
+ /** The outcome of one tool call, as recorded on its `execute_tool` span. */
12
+ export type ToolCallOutcome = {
13
+ readonly kind: 'response';
14
+ readonly functionResponseEvent?: Event;
15
+ /** An error type the tool reported in its response instead of throwing. */
16
+ readonly errorType?: string;
17
+ } | {
18
+ readonly kind: 'error';
19
+ readonly errorType: string;
20
+ };
21
+ /** Parameters for {@link buildToolCallAttributes}. */
22
+ export interface ToolCallAttributesParams {
23
+ readonly tool: BaseTool;
24
+ readonly args: Record<string, unknown>;
25
+ readonly agentName?: string;
26
+ readonly outcome: ToolCallOutcome;
27
+ readonly config: ResolvedTelemetryConfig;
28
+ }
29
+ /**
30
+ * Builds the attributes of an `execute_tool` span.
31
+ *
32
+ * The call arguments and result are message content, so they are recorded
33
+ * only when content capture includes spans, and the result has credential
34
+ * secrets removed.
35
+ */
36
+ export declare function buildToolCallAttributes({ tool, args, agentName, outcome, config, }: ToolCallAttributesParams): Attributes;
37
+ /** Builds the attributes of an `execute_tool (merged)` span. */
38
+ export declare function buildMergedToolCallsAttributes(responseEventId: string): Attributes;
39
+ /** What a skill tool reported about the skill it worked on. */
40
+ export interface SkillReport {
41
+ /** The skill name the tool was asked for, which may not exist. */
42
+ readonly skillName: string;
43
+ /** The resource or script path, for a resource load or a script run. */
44
+ readonly resourceName?: string;
45
+ /** Whether the tool loaded the skill itself, as opposed to part of it. */
46
+ readonly isSkillLoad: boolean;
47
+ /** Whether the tool executed a skill script. */
48
+ readonly isSkillScript?: boolean;
49
+ /** The skill, once the tool has resolved it. */
50
+ readonly skill?: Skill;
51
+ }
52
+ /** Names an `execute_tool` span after the skill and resource it touched. */
53
+ export declare function buildSkillSpanName(toolName: string, report: SkillReport): string;
54
+ /** Builds the skill attributes of an `execute_tool` span. */
55
+ export declare function buildSkillAttributes(report: SkillReport): Attributes;
56
+ /** Records a skill on its `execute_tool` span: the span name and attributes. */
57
+ export declare function setSkillSpanAttributes(span: Span, toolName: string, report: SkillReport): void;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { type Context, type Span, type Tracer } from '@opentelemetry/api';
7
+ /**
8
+ * Returns the ADK tracer from the global `TracerProvider`.
9
+ *
10
+ * Resolved on every call rather than once at import, like the logger, so the
11
+ * tracer carries the schema URL whichever provider the application registers
12
+ * and whenever it registers it.
13
+ */
14
+ export declare function getTracer(): Tracer;
15
+ /**
16
+ * Binds an async generator to OpenTelemetry context for trace propagation.
17
+ *
18
+ * @param ctx The OpenTelemetry context to bind the generator to.
19
+ * @param generator The async generator to be bound to the context.
20
+ * @returns A new async generator that executes all operations within the provided context.
21
+ */
22
+ export declare function bindOtelContextToAsyncGenerator<T>(ctx: Context, generator: AsyncGenerator<T, void, void>): AsyncGenerator<T, void, void>;
23
+ /**
24
+ * Records a failure on a span: the exception and an ERROR status.
25
+ *
26
+ * The status message is the error type rather than the error message, which
27
+ * can carry user data that the content capture setting does not gate. Only an
28
+ * `Error` instance is recorded as an exception; any other thrown value is
29
+ * recorded by its type alone.
30
+ */
31
+ export declare function setSpanError(span: Span, error: unknown): void;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { type Context, type Span } from '@opentelemetry/api';
7
+ /** Parameters for {@link startWorkflowSpan}. */
8
+ export interface StartWorkflowSpanParams {
9
+ readonly workflowName: string;
10
+ readonly sessionId: string;
11
+ readonly nested: boolean;
12
+ readonly parentContext?: Context;
13
+ }
14
+ /**
15
+ * Starts an `invoke_workflow {workflowName}` span.
16
+ *
17
+ * A workflow started inside another workflow is marked
18
+ * `gen_ai.workflow.nested`; the outermost one carries no such attribute. The
19
+ * top span of a trace also carries `supportID` when the request supplied one.
20
+ */
21
+ export declare function startWorkflowSpan({ workflowName, sessionId, nested, parentContext, }: StartWorkflowSpanParams): Span;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * Runs `fn` in a context that continues an Agent Engine request trace.
8
+ *
9
+ * When `Google-Agent-Engine-Traceparent` holds a valid W3C traceparent and no
10
+ * span is active, the Agent Engine span becomes the remote parent of the
11
+ * spans `fn` starts. An invalid value is ignored. The `traceparent` header is
12
+ * recorded as the `supportID` attribute of the invocation's top span.
13
+ *
14
+ * Without either header, `fn` runs in the active context unchanged.
15
+ *
16
+ * @experimental (Experimental, subject to change)
17
+ *
18
+ * @param headers The incoming request headers, such as Node's
19
+ * `IncomingMessage.headers`.
20
+ * @param fn The request handler to run.
21
+ * @returns What `fn` returns.
22
+ */
23
+ export declare function runWithAgentEngineContext<T>(headers: Readonly<Record<string, string | string[] | undefined>>, fn: () => T): T;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { OTelHooks } from './setup.js';
7
+ /**
8
+ * Hooks a server calls at the start and end of every request, so telemetry is
9
+ * exported while the request still holds the CPU.
10
+ *
11
+ * Neither hook throws, and {@link AgentRuntimeRequestHooks.onRequestEnd}
12
+ * never rejects: a telemetry failure never breaks the request.
13
+ *
14
+ * @experimental (Experimental, subject to change)
15
+ */
16
+ export interface AgentRuntimeRequestHooks {
17
+ /** Call when a request arrives. */
18
+ onRequestStart(): void;
19
+ /**
20
+ * Call when the handler ends the response, before the response completes.
21
+ * Resolves once metrics are drained and spans and logs are flushed.
22
+ */
23
+ onRequestEnd(): Promise<void>;
24
+ }
25
+ /**
26
+ * Builds the request hooks that drive export for the given processors and
27
+ * readers on a runtime that throttles the CPU between requests.
28
+ *
29
+ * Each request start and end drives every request-driven metric reader in
30
+ * `otelHooks.metricReaders`. Each request end also force-flushes every span and
31
+ * log record processor in `otelHooks`. Other metric readers are left alone:
32
+ * flushing them would collect outside the request-driven reader's spacing
33
+ * rules.
34
+ *
35
+ * @experimental (Experimental, subject to change)
36
+ *
37
+ * @param otelHooks The processors and readers to drive, usually the result of
38
+ * {@link getGcpExporters}.
39
+ */
40
+ export declare function agentRuntimeRequestHooks(otelHooks: OTelHooks): AgentRuntimeRequestHooks;
@@ -0,0 +1,189 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { Resource } from '@opentelemetry/resources';
7
+ import { BatchLogRecordProcessor, BatchLogRecordProcessorOptions, LogRecordExporter, ReadWriteLogRecord } from '@opentelemetry/sdk-logs';
8
+ import { AggregationTemporality, InstrumentType, PushMetricExporter, ResourceMetrics } from '@opentelemetry/sdk-metrics';
9
+ import { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';
10
+ import { GoogleAuth } from 'google-auth-library';
11
+ import { agentRuntimeRequestHooks, type AgentRuntimeRequestHooks } from './agent_runtime.js';
12
+ import { OtelExportersConfig, OTelHooks } from './setup.js';
13
+ export { agentRuntimeRequestHooks, type AgentRuntimeRequestHooks };
14
+ /**
15
+ * Resolved project identifiers from the Cloud Resource Manager API.
16
+ */
17
+ export interface ProjectInfo {
18
+ readonly id: string;
19
+ readonly number: string;
20
+ }
21
+ /**
22
+ * Clears the cached project identifiers.
23
+ */
24
+ export declare function clearProjectCache(): void;
25
+ /**
26
+ * Selects standard or mTLS endpoint based on environment settings.
27
+ */
28
+ export declare function getTelemetryEndpoint(defaultEndpoint: string, mtlsEndpoint: string): string;
29
+ /**
30
+ * Returns the Vertex Agent Engine User-Agent header when telemetry is enabled.
31
+ */
32
+ export declare function getAgentEngineUserAgentHeader(): Record<string, string>;
33
+ /**
34
+ * Authenticated OTLP trace exporter wrapper sending spans to Google Cloud.
35
+ */
36
+ export declare class AuthenticatedTraceExporter implements SpanExporter {
37
+ private readonly auth;
38
+ private readonly endpoint;
39
+ private readonly userAgentHeaders;
40
+ private readonly delegate;
41
+ private currentHeaders;
42
+ private warnedAuthFailure;
43
+ constructor(auth: GoogleAuth, endpoint: string, userAgentHeaders?: Record<string, string>);
44
+ /**
45
+ * Exports spans to Google Cloud.
46
+ *
47
+ * @param spans Spans to export.
48
+ * @param resultCallback Callback called with the export result.
49
+ */
50
+ export(spans: ReadableSpan[], resultCallback: (result: {
51
+ code: number;
52
+ error?: Error;
53
+ }) => void): void;
54
+ private exportAsync;
55
+ /**
56
+ * Shuts down the trace exporter.
57
+ */
58
+ shutdown(): Promise<void>;
59
+ /**
60
+ * Flushes pending traces.
61
+ */
62
+ forceFlush(): Promise<void>;
63
+ }
64
+ /**
65
+ * Authenticated OTLP metric exporter wrapper sending metrics to Google Cloud.
66
+ */
67
+ export declare class AuthenticatedMetricExporter implements PushMetricExporter {
68
+ private readonly auth;
69
+ private readonly endpoint;
70
+ private readonly userAgentHeaders;
71
+ private readonly delegate;
72
+ private currentHeaders;
73
+ private warnedAuthFailure;
74
+ constructor(auth: GoogleAuth, endpoint: string, userAgentHeaders?: Record<string, string>);
75
+ /**
76
+ * Exports metrics to Google Cloud.
77
+ *
78
+ * @param metrics Metrics to export.
79
+ * @param resultCallback Callback called with the export result.
80
+ */
81
+ export(metrics: ResourceMetrics, resultCallback: (result: {
82
+ code: number;
83
+ error?: Error;
84
+ }) => void): void;
85
+ private exportAsync;
86
+ /**
87
+ * Shuts down the metric exporter.
88
+ */
89
+ shutdown(): Promise<void>;
90
+ /**
91
+ * Flushes pending metrics.
92
+ */
93
+ forceFlush(): Promise<void>;
94
+ /**
95
+ * Selects aggregation temporality for instrument type.
96
+ *
97
+ * @param instrumentType Instrument type.
98
+ */
99
+ selectAggregationTemporality(instrumentType: InstrumentType): AggregationTemporality;
100
+ }
101
+ /**
102
+ * Authenticated OTLP log exporter wrapper sending logs to Google Cloud.
103
+ */
104
+ export declare class AuthenticatedLogExporter implements LogRecordExporter {
105
+ private readonly auth;
106
+ private readonly endpoint;
107
+ private readonly userAgentHeaders;
108
+ private readonly delegate;
109
+ private currentHeaders;
110
+ private warnedAuthFailure;
111
+ constructor(auth: GoogleAuth, endpoint: string, userAgentHeaders?: Record<string, string>);
112
+ /**
113
+ * Exports log records to Google Cloud.
114
+ *
115
+ * @param logs Log records to export.
116
+ * @param resultCallback Callback called with the export result.
117
+ */
118
+ export(logs: ReadWriteLogRecord[], resultCallback: (result: {
119
+ code: number;
120
+ error?: Error;
121
+ }) => void): void;
122
+ private exportAsync;
123
+ /**
124
+ * Shuts down the log exporter.
125
+ */
126
+ shutdown(): Promise<void>;
127
+ /**
128
+ * Flushes pending log records.
129
+ */
130
+ forceFlush(): Promise<void>;
131
+ }
132
+ /**
133
+ * Options for configuring {@link GCPBatchLogRecordProcessor}.
134
+ */
135
+ export interface GCPBatchLogRecordProcessorOptions extends Partial<BatchLogRecordProcessorOptions> {
136
+ readonly exporter: LogRecordExporter;
137
+ readonly projectId?: string;
138
+ }
139
+ /**
140
+ * Batching log processor keeping Cloud Logging log names and labels stable.
141
+ */
142
+ export declare class GCPBatchLogRecordProcessor extends BatchLogRecordProcessor {
143
+ private readonly defaultLogName;
144
+ private readonly logResource;
145
+ constructor(exporterOrOptions: LogRecordExporter | GCPBatchLogRecordProcessorOptions, projectId?: string);
146
+ onEmit(logRecord: ReadWriteLogRecord): void;
147
+ }
148
+ /**
149
+ * Looks up project number and ID via Cloud Resource Manager API with in-memory caching.
150
+ *
151
+ * Successful lookups require the `resourcemanager.projects.get` permission.
152
+ *
153
+ * @param project The project ID or number to query.
154
+ * @param auth Optional GoogleAuth instance to use.
155
+ * @returns Resolved project identifiers, or empty strings if resolution fails.
156
+ */
157
+ export declare function fetchProject(project?: string, auth?: GoogleAuth): Promise<ProjectInfo>;
158
+ /**
159
+ * Resolves the GCP project ID from parameter, environment, or Application Default Credentials.
160
+ *
161
+ * @param auth Optional GoogleAuth instance to use for resolution.
162
+ * @returns The resolved project ID, or undefined if it cannot be determined.
163
+ */
164
+ export declare function getGcpProjectId(auth?: GoogleAuth): Promise<string | undefined>;
165
+ /**
166
+ * Builds the OTel resource describing a Google Cloud deployment.
167
+ *
168
+ * Applies layered precedence: common resource, Agent Runtime resource,
169
+ * OTel environment detector, GCP detector, and Agent Registry URN enrichment.
170
+ *
171
+ * @param projectId Optional project ID. Falls back to GOOGLE_CLOUD_PROJECT or ADC.
172
+ * @returns Detected Resource object.
173
+ */
174
+ export declare function getGcpResource(projectId?: string): Promise<Resource>;
175
+ /**
176
+ * Returns OTel processors and readers configured for export to Google Cloud.
177
+ *
178
+ * Sends traces, metrics, and logs via OTLP over HTTP to telemetry.googleapis.com.
179
+ * On Agent Runtime (`GOOGLE_CLOUD_AGENT_ENGINE_ID` set) the metric reader is
180
+ * request-driven and starts no background timer. Custom servers calling
181
+ * `getGcpExporters` with {@link maybeSetOtelProviders} on Agent Runtime must
182
+ * wrap each request with {@link agentRuntimeRequestHooks} to drive the metric
183
+ * reader and flush the span and log processors; without those hooks, the reader
184
+ * never collects except on `forceFlush()` or `shutdown()`.
185
+ *
186
+ * @param config Configuration options for enabled signals and project.
187
+ * @returns OTelHooks containing configured processors and readers.
188
+ */
189
+ export declare function getGcpExporters(config?: OtelExportersConfig): Promise<OTelHooks>;
@@ -0,0 +1,144 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { MetricReader, type PushMetricExporter } from '@opentelemetry/sdk-metrics';
7
+ /**
8
+ * The minimum spacing, in milliseconds, between two metric exports to
9
+ * telemetry.googleapis.com.
10
+ *
11
+ * Every ADK metric reader that exports there stays at or above it: it is the
12
+ * default floor of {@link RequestDrivenMetricReader} and the export interval of
13
+ * the periodic reader. The backend tolerates slightly faster points to absorb
14
+ * drift, but that is not a supported rate.
15
+ */
16
+ export declare const MIN_EXPORT_INTERVAL_MS = 5000;
17
+ declare const REQUEST_DRIVEN_METRIC_READER_SIGNATURE_SYMBOL: unique symbol;
18
+ /** Options for {@link RequestDrivenMetricReader}. */
19
+ export interface RequestDrivenMetricReaderOptions {
20
+ /** The exporter each collect is sent to. */
21
+ readonly exporter: PushMetricExporter;
22
+ /**
23
+ * The spacing of the guidepost grid, in milliseconds. Defaults to
24
+ * `OTEL_METRIC_EXPORT_INTERVAL`, or 60000.
25
+ */
26
+ readonly exportIntervalMillis?: number;
27
+ /**
28
+ * The timeout of one collect and one export, in milliseconds. Defaults to
29
+ * `OTEL_METRIC_EXPORT_TIMEOUT`, or 30000.
30
+ */
31
+ readonly exportTimeoutMillis?: number;
32
+ /**
33
+ * The minimum spacing between two collects, in milliseconds. Defaults to
34
+ * `GOOGLE_CLOUD_AGENT_ENGINE_METRICS_COLLECTION_INTERVAL_FLOOR_MS`, or
35
+ * `MIN_EXPORT_INTERVAL_MS`.
36
+ */
37
+ readonly floorMillis?: number;
38
+ /** A monotonic millisecond clock. Defaults to `performance.now`. */
39
+ readonly now?: () => number;
40
+ }
41
+ /**
42
+ * Returns whether `obj` is a {@link RequestDrivenMetricReader}, including one
43
+ * from another copy of this package.
44
+ */
45
+ export declare function isRequestDrivenMetricReader(obj: unknown): obj is RequestDrivenMetricReader;
46
+ /**
47
+ * A metric reader that collects and exports only from the request path, with
48
+ * no background timer.
49
+ *
50
+ * On a runtime that bills per request, such as Agent Runtime, the CPU is
51
+ * throttled as soon as a request ends. A periodic reader's timer gets no CPU
52
+ * between requests, so its exports are delayed or dropped. This reader keeps
53
+ * three invariants instead:
54
+ *
55
+ * - I1, export only while serving: every collect runs while a request is in
56
+ * flight, the only time the CPU is guaranteed.
57
+ * - I2, a floor: two collects are never closer than `floorMillis`.
58
+ * - I3, a guidepost: the export period is a grid of hint times, not a
59
+ * schedule. Under sustained load a passed guidepost forces a collect, so
60
+ * points cannot pile up.
61
+ *
62
+ * Collects are triggered by:
63
+ *
64
+ * - {@link onRequestEnd}, when the last request in flight ends and the floor
65
+ * allows it (the drain).
66
+ * - {@link onRequestStart}, when the request overlaps another one and a
67
+ * guidepost has passed. A guidepost that lands within the floor of the last
68
+ * collect is muted, and the grid moves one period on.
69
+ * - The start of a model call, when 1.5 periods have passed since the later
70
+ * of the start of the busy period and the last collect. The model-call
71
+ * instrumentation calls this through a hook the reader installs when a
72
+ * `MeterProvider` registers it. Because that hook uses a single
73
+ * process-global slot where the last registered reader wins, only a single
74
+ * active reader is supported.
75
+ *
76
+ * Residual loss case: a request shorter than the floor that ends right after
77
+ * a collect has its drain muted by the floor. If it is the last request
78
+ * before the process goes idle, no later collect comes and its points are
79
+ * lost.
80
+ *
81
+ * The defaults come from `OTEL_METRIC_EXPORT_INTERVAL` (60000),
82
+ * `OTEL_METRIC_EXPORT_TIMEOUT` (30000) and
83
+ * `GOOGLE_CLOUD_AGENT_ENGINE_METRICS_COLLECTION_INTERVAL_FLOOR_MS` (5000). An
84
+ * explicit option wins over its variable. A value that is not a valid number
85
+ * logs a warning and uses the default.
86
+ *
87
+ * None of the request methods throws or rejects.
88
+ */
89
+ export declare class RequestDrivenMetricReader extends MetricReader {
90
+ readonly [REQUEST_DRIVEN_METRIC_READER_SIGNATURE_SYMBOL] = true;
91
+ private readonly exporter;
92
+ private readonly now;
93
+ private readonly periodMillis;
94
+ private readonly exportTimeoutMillis;
95
+ private readonly floorMillis;
96
+ private readonly inferenceStartHook;
97
+ private inFlight;
98
+ private lastCollect?;
99
+ /** When in-flight last went from zero to one. */
100
+ private busyStart?;
101
+ private nextDue;
102
+ /** The collect now running; set while one runs, so collects never overlap. */
103
+ private runningCollect?;
104
+ private isShutdown;
105
+ private warnedNoRequest;
106
+ constructor({ exporter, exportIntervalMillis, exportTimeoutMillis, floorMillis, now, }: RequestDrivenMetricReaderOptions);
107
+ /** Marks a request as started, and collects if a guidepost has passed. */
108
+ onRequestStart(): void;
109
+ /**
110
+ * Marks a request as ended. Collects when no request is left in flight and
111
+ * the floor allows it, and resolves once any running collect has exported.
112
+ */
113
+ onRequestEnd(): Promise<void>;
114
+ /** Collects at a model-call start if the busy period is overdue. */
115
+ onInferenceStart(): void;
116
+ /**
117
+ * Registers the model-call start hook when a provider initializes this
118
+ * reader.
119
+ *
120
+ * Because the hook uses a single process-global slot where the last
121
+ * registered reader wins, only a single active reader is supported.
122
+ */
123
+ protected onInitialized(): void;
124
+ /** Shuts down the reader, exports remaining metrics, and cleans up hooks. */
125
+ protected onShutdown(): Promise<void>;
126
+ /** Flushes any in-flight and pending metric exports. */
127
+ protected onForceFlush(): Promise<void>;
128
+ private canCollect;
129
+ private floorAllows;
130
+ /**
131
+ * Returns whether the current busy period has gone 1.5 periods without a
132
+ * collect. A collect from an earlier busy period does not count, so a short
133
+ * request after an idle gap is never overdue: collecting at its model call
134
+ * would set the floor and mute the drain that carries its points.
135
+ */
136
+ private isOverdue;
137
+ /** Starts a collect, and moves the guidepost grid past `now`. */
138
+ private startCollect;
139
+ /** Runs one collect and export as the running collect. Never rejects. */
140
+ private runExclusive;
141
+ private collectAndExport;
142
+ private export;
143
+ }
144
+ export {};
@@ -7,10 +7,13 @@ import { Resource } from '@opentelemetry/resources';
7
7
  import { LogRecordProcessor } from '@opentelemetry/sdk-logs';
8
8
  import { MetricReader } from '@opentelemetry/sdk-metrics';
9
9
  import { SpanProcessor } from '@opentelemetry/sdk-trace-base';
10
+ import type { GoogleAuth } from 'google-auth-library';
10
11
  export interface OtelExportersConfig {
11
12
  enableTracing?: boolean;
12
13
  enableMetrics?: boolean;
13
14
  enableLogging?: boolean;
15
+ projectId?: string;
16
+ auth?: GoogleAuth;
14
17
  }
15
18
  /**
16
19
  * Configuration hooks for OpenTelemetry setup.
@@ -37,7 +37,7 @@ export declare function isAgentTool(obj: unknown): obj is AgentTool;
37
37
  * application. The agent's input schema is used to define the tool's input
38
38
  * parameters, and the agent's output is returned as the tool's result.
39
39
  *
40
- * @param config: The configuration of the agent tool.
40
+ * @param config The configuration of the agent tool.
41
41
  */
42
42
  export declare class AgentTool extends BaseTool {
43
43
  /** A unique symbol to identify ADK agent tool class. */