@google/adk 2.2.1 → 2.3.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 (226) hide show
  1. package/dist/cjs/a2a/a2a_remote_agent.js +4 -1
  2. package/dist/cjs/a2a/agent_card.js +102 -26
  3. package/dist/cjs/a2a/agent_to_a2a.js +1 -1
  4. package/dist/cjs/agents/functions.js +199 -25
  5. package/dist/cjs/agents/instructions.js +4 -1
  6. package/dist/cjs/agents/invocation_context.js +26 -4
  7. package/dist/cjs/agents/langgraph_agent.js +152 -0
  8. package/dist/cjs/agents/llm_agent.js +175 -101
  9. package/dist/cjs/agents/processors/code_execution_request_processor.js +10 -6
  10. package/dist/cjs/agents/remote_agent.js +187 -0
  11. package/dist/cjs/artifacts/in_memory_artifact_service.js +14 -0
  12. package/dist/cjs/auth/auth_handler.js +37 -5
  13. package/dist/cjs/auth/auth_schemes.js +9 -0
  14. package/dist/cjs/cli/cli_eval.js +532 -0
  15. package/dist/cjs/cli/utils/envs.js +116 -0
  16. package/dist/cjs/cli/utils/evals.js +137 -0
  17. package/dist/cjs/cli/utils/logs.js +150 -0
  18. package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +7 -2
  19. package/dist/cjs/code_executors/code_execution_utils.js +48 -16
  20. package/dist/cjs/code_executors/code_executor_context.js +6 -2
  21. package/dist/cjs/common.js +72 -0
  22. package/dist/cjs/context/summarizers/llm_summarizer.js +12 -10
  23. package/dist/cjs/context/token_based_context_compactor.js +2 -1
  24. package/dist/cjs/events/event.js +4 -2
  25. package/dist/cjs/examples/example_util.js +23 -2
  26. package/dist/cjs/flows/llm_flows/audio_transcriber.js +170 -0
  27. package/dist/cjs/index.js +97 -1
  28. package/dist/cjs/integrations/agent_registry/helpers.js +1 -1
  29. package/dist/cjs/models/gemini_llm_connection.js +16 -8
  30. package/dist/cjs/models/google_llm.js +13 -16
  31. package/dist/cjs/models/llm_response.js +9 -1
  32. package/dist/cjs/models/registry.js +1 -1
  33. package/dist/cjs/models/routed_llm.js +9 -8
  34. package/dist/cjs/planners/plan_re_act_planner.js +1 -1
  35. package/dist/cjs/runner/in_memory_runner.js +6 -11
  36. package/dist/cjs/runner/runner.js +105 -33
  37. package/dist/cjs/sessions/db/operations.js +1 -1
  38. package/dist/cjs/sessions/in_memory_session_service.js +3 -1
  39. package/dist/cjs/sessions/state.js +8 -4
  40. package/dist/cjs/sessions/vertex_ai_session_service.js +34 -15
  41. package/dist/cjs/telemetry/tracing.js +97 -66
  42. package/dist/cjs/tools/agent_tool.js +44 -0
  43. package/dist/cjs/tools/apihub_tool/apihub_toolset.js +142 -0
  44. package/dist/cjs/tools/apihub_tool/clients/apihub_client.js +272 -0
  45. package/dist/cjs/tools/apihub_tool/clients/secret_client.js +148 -0
  46. package/dist/cjs/tools/apihub_tool/clients/service_account.js +48 -0
  47. package/dist/cjs/tools/application_integration_tool/application_integration_toolset.js +185 -0
  48. package/dist/cjs/tools/application_integration_tool/clients/cloud_request.js +133 -0
  49. package/dist/cjs/tools/application_integration_tool/clients/connections_client.js +603 -0
  50. package/dist/cjs/tools/application_integration_tool/clients/integration_client.js +219 -0
  51. package/dist/cjs/tools/crewai_tool.js +132 -0
  52. package/dist/cjs/tools/example_tool.js +10 -0
  53. package/dist/cjs/tools/function_tool.js +319 -0
  54. package/dist/cjs/tools/google_api_tool/google_api_tool.js +97 -0
  55. package/dist/cjs/tools/google_api_tool/google_api_tool_set.js +226 -0
  56. package/dist/cjs/tools/google_api_tool/google_api_tool_sets.js +58 -0
  57. package/dist/cjs/tools/google_api_tool/googleapi_to_openapi_converter.js +440 -0
  58. package/dist/cjs/tools/google_api_tool/index.js +64 -0
  59. package/dist/cjs/tools/langchain_tool.js +172 -0
  60. package/dist/cjs/tools/mcp/index.js +12 -0
  61. package/dist/cjs/tools/mcp/mcp_session_manager.js +25 -0
  62. package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +1 -2
  63. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +46 -2
  64. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -1
  65. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
  66. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +14 -2
  67. package/dist/cjs/tools/retrieval/base_retrieval_tool.js +18 -3
  68. package/dist/cjs/tools/toolbox_tool.js +108 -0
  69. package/dist/cjs/utils/env_aware_utils.js +6 -8
  70. package/dist/cjs/utils/error_utils.js +11 -11
  71. package/dist/cjs/utils/file_extension_utils.js +11 -0
  72. package/dist/cjs/utils/file_utils.js +2 -24
  73. package/dist/cjs/utils/gemini_schema_util.js +4 -1
  74. package/dist/cjs/utils/json_utils.js +49 -0
  75. package/dist/cjs/utils/live_connection_utils.js +4 -5
  76. package/dist/cjs/utils/logger_node.js +7 -1
  77. package/dist/cjs/utils/object_notation_utils.js +6 -3
  78. package/dist/cjs/utils/streaming_utils.js +12 -12
  79. package/dist/cjs/version.js +1 -1
  80. package/dist/esm/a2a/a2a_remote_agent.js +4 -1
  81. package/dist/esm/a2a/agent_card.js +103 -27
  82. package/dist/esm/a2a/agent_to_a2a.js +5 -2
  83. package/dist/esm/agents/functions.js +198 -25
  84. package/dist/esm/agents/instructions.js +4 -1
  85. package/dist/esm/agents/invocation_context.js +24 -4
  86. package/dist/esm/agents/langgraph_agent.js +123 -0
  87. package/dist/esm/agents/llm_agent.js +185 -104
  88. package/dist/esm/agents/processors/code_execution_request_processor.js +13 -8
  89. package/dist/esm/agents/remote_agent.js +164 -0
  90. package/dist/esm/artifacts/in_memory_artifact_service.js +14 -0
  91. package/dist/esm/auth/auth_handler.js +37 -5
  92. package/dist/esm/auth/auth_schemes.js +8 -0
  93. package/dist/esm/cli/cli_eval.js +510 -0
  94. package/dist/esm/cli/utils/envs.js +78 -0
  95. package/dist/esm/cli/utils/evals.js +109 -0
  96. package/dist/esm/cli/utils/logs.js +111 -0
  97. package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +7 -2
  98. package/dist/esm/code_executors/code_execution_utils.js +46 -16
  99. package/dist/esm/code_executors/code_executor_context.js +5 -2
  100. package/dist/esm/common.js +67 -3
  101. package/dist/esm/context/summarizers/llm_summarizer.js +12 -10
  102. package/dist/esm/context/token_based_context_compactor.js +2 -1
  103. package/dist/esm/events/event.js +4 -2
  104. package/dist/esm/examples/example_util.js +21 -1
  105. package/dist/esm/flows/llm_flows/audio_transcriber.js +142 -0
  106. package/dist/esm/index.js +99 -1
  107. package/dist/esm/integrations/agent_registry/helpers.js +1 -1
  108. package/dist/esm/models/gemini_llm_connection.js +16 -8
  109. package/dist/esm/models/google_llm.js +14 -17
  110. package/dist/esm/models/llm_response.js +9 -1
  111. package/dist/esm/models/registry.js +1 -1
  112. package/dist/esm/models/routed_llm.js +9 -8
  113. package/dist/esm/planners/plan_re_act_planner.js +1 -1
  114. package/dist/esm/runner/in_memory_runner.js +6 -11
  115. package/dist/esm/runner/runner.js +105 -33
  116. package/dist/esm/sessions/db/operations.js +1 -1
  117. package/dist/esm/sessions/in_memory_session_service.js +3 -1
  118. package/dist/esm/sessions/state.js +8 -4
  119. package/dist/esm/sessions/vertex_ai_session_service.js +34 -15
  120. package/dist/esm/telemetry/tracing.js +97 -66
  121. package/dist/esm/tools/agent_tool.js +44 -0
  122. package/dist/esm/tools/apihub_tool/apihub_toolset.js +106 -0
  123. package/dist/esm/tools/apihub_tool/clients/apihub_client.js +244 -0
  124. package/dist/esm/tools/apihub_tool/clients/secret_client.js +132 -0
  125. package/dist/esm/tools/apihub_tool/clients/service_account.js +21 -0
  126. package/dist/esm/tools/application_integration_tool/application_integration_toolset.js +163 -0
  127. package/dist/esm/tools/application_integration_tool/clients/cloud_request.js +103 -0
  128. package/dist/esm/tools/application_integration_tool/clients/connections_client.js +561 -0
  129. package/dist/esm/tools/application_integration_tool/clients/integration_client.js +215 -0
  130. package/dist/esm/tools/crewai_tool.js +107 -0
  131. package/dist/esm/tools/example_tool.js +13 -1
  132. package/dist/esm/tools/function_tool.js +316 -0
  133. package/dist/esm/tools/google_api_tool/google_api_tool.js +70 -0
  134. package/dist/esm/tools/google_api_tool/google_api_tool_set.js +188 -0
  135. package/dist/esm/tools/google_api_tool/google_api_tool_sets.js +24 -0
  136. package/dist/esm/tools/google_api_tool/googleapi_to_openapi_converter.js +393 -0
  137. package/dist/esm/tools/google_api_tool/index.js +33 -0
  138. package/dist/esm/tools/langchain_tool.js +148 -0
  139. package/dist/esm/tools/mcp/index.js +6 -0
  140. package/dist/esm/tools/mcp/mcp_session_manager.js +25 -0
  141. package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +1 -2
  142. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +50 -3
  143. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -1
  144. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
  145. package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -2
  146. package/dist/esm/tools/retrieval/base_retrieval_tool.js +16 -2
  147. package/dist/esm/tools/toolbox_tool.js +80 -0
  148. package/dist/esm/utils/env_aware_utils.js +6 -8
  149. package/dist/esm/utils/error_utils.js +9 -10
  150. package/dist/esm/utils/file_extension_utils.js +11 -0
  151. package/dist/esm/utils/file_utils.js +2 -23
  152. package/dist/esm/utils/gemini_schema_util.js +4 -1
  153. package/dist/esm/utils/json_utils.js +21 -0
  154. package/dist/esm/utils/live_connection_utils.js +4 -5
  155. package/dist/esm/utils/logger_node.js +7 -1
  156. package/dist/esm/utils/object_notation_utils.js +4 -2
  157. package/dist/esm/utils/streaming_utils.js +11 -11
  158. package/dist/esm/version.js +1 -1
  159. package/dist/types/a2a/a2a_remote_agent.d.ts +9 -0
  160. package/dist/types/a2a/agent_card.d.ts +44 -1
  161. package/dist/types/a2a/agent_to_a2a.d.ts +9 -0
  162. package/dist/types/a2a/index.d.ts +1 -0
  163. package/dist/types/agents/functions.d.ts +33 -1
  164. package/dist/types/agents/invocation_context.d.ts +20 -1
  165. package/dist/types/agents/langgraph_agent.d.ts +153 -0
  166. package/dist/types/agents/remote_agent.d.ts +68 -0
  167. package/dist/types/auth/auth_handler.d.ts +28 -1
  168. package/dist/types/auth/auth_schemes.d.ts +13 -0
  169. package/dist/types/cli/cli_eval.d.ts +173 -0
  170. package/dist/types/cli/utils/envs.d.ts +23 -0
  171. package/dist/types/cli/utils/evals.d.ts +47 -0
  172. package/dist/types/cli/utils/logs.d.ts +38 -0
  173. package/dist/types/code_executors/code_execution_utils.d.ts +39 -0
  174. package/dist/types/code_executors/code_executor_context.d.ts +1 -0
  175. package/dist/types/common.d.ts +27 -4
  176. package/dist/types/events/event.d.ts +4 -0
  177. package/dist/types/examples/example_util.d.ts +17 -0
  178. package/dist/types/flows/llm_flows/audio_transcriber.d.ts +85 -0
  179. package/dist/types/index.d.ts +16 -1
  180. package/dist/types/models/gemini_llm_connection.d.ts +6 -7
  181. package/dist/types/models/routed_llm.d.ts +1 -1
  182. package/dist/types/runner/in_memory_runner.d.ts +2 -1
  183. package/dist/types/runner/runner.d.ts +34 -0
  184. package/dist/types/sessions/state.d.ts +5 -1
  185. package/dist/types/sessions/vertex_ai_session_service.d.ts +8 -0
  186. package/dist/types/skills/skill.d.ts +1 -1
  187. package/dist/types/telemetry/tracing.d.ts +4 -2
  188. package/dist/types/tools/apihub_tool/apihub_toolset.d.ts +122 -0
  189. package/dist/types/tools/apihub_tool/clients/apihub_client.d.ts +142 -0
  190. package/dist/types/tools/apihub_tool/clients/secret_client.d.ts +55 -0
  191. package/dist/types/tools/apihub_tool/clients/service_account.d.ts +11 -0
  192. package/dist/types/tools/application_integration_tool/application_integration_toolset.d.ts +86 -0
  193. package/dist/types/tools/application_integration_tool/clients/cloud_request.d.ts +53 -0
  194. package/dist/types/tools/application_integration_tool/clients/connections_client.d.ts +215 -0
  195. package/dist/types/tools/application_integration_tool/clients/integration_client.d.ts +72 -0
  196. package/dist/types/tools/crewai_tool.d.ts +85 -0
  197. package/dist/types/tools/example_tool.d.ts +10 -0
  198. package/dist/types/tools/function_tool.d.ts +32 -0
  199. package/dist/types/tools/google_api_tool/google_api_tool.d.ts +30 -0
  200. package/dist/types/tools/google_api_tool/google_api_tool_set.d.ts +78 -0
  201. package/dist/types/tools/google_api_tool/google_api_tool_sets.d.ts +33 -0
  202. package/dist/types/tools/google_api_tool/googleapi_to_openapi_converter.d.ts +164 -0
  203. package/dist/types/tools/google_api_tool/index.d.ts +11 -0
  204. package/dist/types/tools/langchain_tool.d.ts +103 -0
  205. package/dist/types/tools/mcp/index.d.ts +3 -0
  206. package/dist/types/tools/mcp/mcp_session_manager.d.ts +34 -1
  207. package/dist/types/tools/mcp/mcp_toolset.d.ts +15 -0
  208. package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +19 -0
  209. package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +18 -1
  210. package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +2 -1
  211. package/dist/types/tools/retrieval/base_retrieval_tool.d.ts +15 -0
  212. package/dist/types/tools/toolbox_tool.d.ts +73 -0
  213. package/dist/types/utils/env_aware_utils.d.ts +18 -2
  214. package/dist/types/utils/error_utils.d.ts +7 -0
  215. package/dist/types/utils/file_utils.d.ts +6 -1
  216. package/dist/types/utils/gemini_schema_util.d.ts +1 -2
  217. package/dist/types/utils/json_utils.d.ts +11 -0
  218. package/dist/types/utils/object_notation_utils.d.ts +7 -0
  219. package/dist/types/utils/streaming_utils.d.ts +11 -4
  220. package/dist/types/version.d.ts +1 -1
  221. package/dist/web/index_web.js +102 -103
  222. package/dist/web/index_web.js.map +4 -4
  223. package/package.json +8 -3
  224. package/dist/cjs/models/gemini_continuation.js +0 -232
  225. package/dist/esm/models/gemini_continuation.js +0 -205
  226. package/dist/types/models/gemini_continuation.d.ts +0 -59
@@ -65,6 +65,17 @@ export interface RunnerConfig {
65
65
  * An optional resumability configuration applied to the runner.
66
66
  */
67
67
  resumabilityConfig?: ResumabilityConfig;
68
+ /**
69
+ * Whether to create the session when `runAsync` is given a session id that
70
+ * does not exist. Defaults to `false`, which reports the missing session as
71
+ * an error instead.
72
+ *
73
+ * Enabling this trades a loud failure for a silent one: a caller that
74
+ * mistypes a session id gets a new empty conversation rather than an error.
75
+ * Turn it on only where the session id is a key the caller owns and a first
76
+ * use is expected to create it.
77
+ */
78
+ autoCreateSession?: boolean;
68
79
  }
69
80
  /**
70
81
  * A unique symbol to identify ADK agent classes.
@@ -116,12 +127,20 @@ export declare class Runner {
116
127
  readonly memoryService?: BaseMemoryService;
117
128
  readonly credentialService?: BaseCredentialService;
118
129
  readonly resumabilityConfig?: ResumabilityConfig;
130
+ readonly autoCreateSession: boolean;
119
131
  /**
120
132
  * Creates a new Runner instance.
121
133
  *
122
134
  * @param input The configuration for the runner.
123
135
  */
124
136
  constructor(input: RunnerConfig);
137
+ /**
138
+ * Looks the session up, creating it first when `autoCreateSession` is set.
139
+ *
140
+ * A runner with no `appName` cannot address a session, so it falls through to
141
+ * the plain lookup rather than creating one under an undefined app name.
142
+ */
143
+ private resolveSession;
125
144
  /**
126
145
  * Runs the agent with a new, ephemeral session.
127
146
  *
@@ -171,6 +190,21 @@ export declare class Runner {
171
190
  * plugins; there is nothing to lack if there is only one loop.
172
191
  */
173
192
  private runRoot;
193
+ /**
194
+ * Runs the on_event plugin callbacks on an event and appends the result to
195
+ * the session unless it is partial.
196
+ *
197
+ * @returns The event as streamed to the caller.
198
+ */
199
+ private processAndAppendEvent;
200
+ /**
201
+ * Seals an aborted invocation in session history: answers its dangling
202
+ * function calls with error responses, or records a plain abort event when
203
+ * there is nothing to answer.
204
+ *
205
+ * @returns The synthetic events after plugin processing and persistence.
206
+ */
207
+ private synthesizeAbortEvents;
174
208
  /**
175
209
  * Saves artifacts from the message parts and replaces the inline data with
176
210
  * a file name placeholder and optional file reference.
@@ -56,6 +56,9 @@ export declare class State {
56
56
  /**
57
57
  * Returns the value of the state dict for the given key.
58
58
  *
59
+ * Only keys the state holds itself are found. Names inherited from
60
+ * `Object.prototype`, such as `toString`, are treated as missing.
61
+ *
59
62
  * @param key The key to get the value for.
60
63
  * @param defaultValue The default value to return if the key is not found.
61
64
  * @return The value of the state for the given key, or the default value if
@@ -70,7 +73,8 @@ export declare class State {
70
73
  */
71
74
  set(key: string, value: unknown): void;
72
75
  /**
73
- * Whether the state has pending delta.
76
+ * Whether the state holds the given key, either as a stored value or as a
77
+ * pending delta. Names inherited from `Object.prototype` are not keys.
74
78
  */
75
79
  has(key: string): boolean;
76
80
  /**
@@ -20,7 +20,15 @@ export declare function isVertexAiConnectionString(uri?: string): boolean;
20
20
  */
21
21
  export declare function quoteFilterLiteral(value: string): string;
22
22
  export interface VertexAiSessionServiceOptions {
23
+ /**
24
+ * Google Cloud project ID. Defaults to `process.env.GOOGLE_CLOUD_PROJECT`
25
+ * unless `expressModeApiKey` is passed.
26
+ */
23
27
  projectId?: string;
28
+ /**
29
+ * Google Cloud location. Defaults to `process.env.GOOGLE_CLOUD_LOCATION`
30
+ * unless `expressModeApiKey` is passed.
31
+ */
24
32
  location?: string;
25
33
  agentEngineId?: string;
26
34
  expressModeApiKey?: string;
@@ -15,7 +15,7 @@ export declare const FrontmatterSchema: z.ZodPreprocess<z.ZodObject<{
15
15
  compatibility: z.ZodOptional<z.ZodString>;
16
16
  'allowed-tools': z.ZodOptional<z.ZodString>;
17
17
  metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodAny>>;
18
- }, z.core.$loose>>;
18
+ }, z.core.$loose>, unknown>;
19
19
  export interface Frontmatter {
20
20
  name: string;
21
21
  description: string;
@@ -63,16 +63,18 @@ export interface TraceToolCallParams {
63
63
  tool: BaseTool;
64
64
  args: Record<string, unknown>;
65
65
  functionResponseEvent: Event;
66
+ invocationContext: InvocationContext;
66
67
  }
67
68
  /**
68
69
  * Traces tool call.
69
70
  *
70
71
  * @param params The parameters object containing tool, args, and function response event.
71
72
  */
72
- export declare function traceToolCall({ tool, args, functionResponseEvent, }: TraceToolCallParams): void;
73
+ export declare function traceToolCall({ tool, args, functionResponseEvent, invocationContext, }: TraceToolCallParams): void;
73
74
  export interface TraceMergedToolCallsParams {
74
75
  responseEventId: string;
75
76
  functionResponseEvent: Event;
77
+ invocationContext: InvocationContext;
76
78
  }
77
79
  /**
78
80
  * Traces merged tool call events.
@@ -82,7 +84,7 @@ export interface TraceMergedToolCallsParams {
82
84
  *
83
85
  * @param params The parameters object containing response event ID and function response event.
84
86
  */
85
- export declare function traceMergedToolCalls({ responseEventId, functionResponseEvent, }: TraceMergedToolCallsParams): void;
87
+ export declare function traceMergedToolCalls({ responseEventId, functionResponseEvent, invocationContext, }: TraceMergedToolCallsParams): void;
86
88
  export interface TraceCallLlmParams {
87
89
  invocationContext: InvocationContext;
88
90
  eventId: string;
@@ -0,0 +1,122 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { OpenAPIV3 } from 'openapi-types';
7
+ import { ReadonlyContext } from '../../agents/readonly_context.js';
8
+ import { AuthCredential } from '../../auth/auth_credential.js';
9
+ import { BaseTool } from '../base_tool.js';
10
+ import { BaseToolset } from '../base_toolset.js';
11
+ import { RestApiTool } from '../openapi_tool/rest_api_tool.js';
12
+ import { BaseAPIHubClient } from './clients/apihub_client.js';
13
+ /** Options for {@link APIHubToolset}. */
14
+ export interface APIHubToolsetOptions {
15
+ /**
16
+ * The API Hub resource to build tools from. It must name an API, and may
17
+ * also name a version and a spec, for example
18
+ * `projects/my-project/locations/us-central1/apis/my-api`. An API Hub
19
+ * console URL is also accepted.
20
+ *
21
+ * When it names a spec, that spec is used. Otherwise the first spec of the
22
+ * named version, or of the first version of the named API, is used.
23
+ */
24
+ apihubResourceName: string;
25
+ /**
26
+ * An OAuth access token for API Hub, for example the output of
27
+ * `gcloud auth print-access-token`. Ignored when `apihubClient` is set.
28
+ */
29
+ accessToken?: string;
30
+ /**
31
+ * The content of a service account key file, as a JSON string, used to
32
+ * authenticate to API Hub when `accessToken` is not set. Ignored when
33
+ * `apihubClient` is set.
34
+ */
35
+ serviceAccountJson?: string;
36
+ /**
37
+ * The toolset name. When empty, it is set from the spec's `info.title` in
38
+ * snake_case, or `unnamed` when the spec has no title.
39
+ */
40
+ name?: string;
41
+ /**
42
+ * The toolset description. When empty, it is set from the spec's
43
+ * `info.description`.
44
+ */
45
+ description?: string;
46
+ /**
47
+ * When true, the spec is fetched on the first call to `getTools` or
48
+ * `getTool` instead of when the toolset is constructed.
49
+ */
50
+ lazyLoadSpec?: boolean;
51
+ /** Auth scheme applied to every tool the spec produces. */
52
+ authScheme?: OpenAPIV3.SecuritySchemeObject;
53
+ /** Auth credential applied to every tool the spec produces. */
54
+ authCredential?: AuthCredential;
55
+ /**
56
+ * The client that fetches the spec. Defaults to an {@link APIHubClient}
57
+ * built from `accessToken` and `serviceAccountJson`.
58
+ */
59
+ apihubClient?: BaseAPIHubClient;
60
+ }
61
+ /**
62
+ * Builds one tool per operation of an API registered in API Hub.
63
+ *
64
+ * The toolset fetches an OpenAPI spec from API Hub, parses it as YAML or JSON,
65
+ * and hands it to an {@link OpenAPIToolset}, which produces a
66
+ * {@link RestApiTool} for each operation.
67
+ *
68
+ * ```ts
69
+ * const toolset = new APIHubToolset({
70
+ * apihubResourceName:
71
+ * 'projects/my-project/locations/us-central1/apis/my-api',
72
+ * });
73
+ * const agent = new LlmAgent({
74
+ * name: 'api_agent',
75
+ * model: 'gemini-flash-latest',
76
+ * tools: [toolset],
77
+ * });
78
+ * ```
79
+ *
80
+ * By default the spec is fetched when the toolset is constructed. A
81
+ * constructor cannot wait for the request, so a failure is reported by the
82
+ * first call to `getTools` or `getTool`, and every later call reports the same
83
+ * failure.
84
+ *
85
+ * With `lazyLoadSpec`, the spec is fetched on the first call to `getTools` or
86
+ * `getTool`. A successful result is kept, including a spec that produced no
87
+ * tools. A failed fetch is not kept, so the next call fetches again.
88
+ */
89
+ export declare class APIHubToolset extends BaseToolset {
90
+ /** The toolset name, filled in from the spec when empty. */
91
+ name: string;
92
+ /** The toolset description, filled in from the spec when empty. */
93
+ description: string;
94
+ readonly apihubResourceName: string;
95
+ readonly lazyLoadSpec: boolean;
96
+ private readonly apihubClient;
97
+ private readonly authScheme?;
98
+ private readonly authCredential?;
99
+ private toolsetPromise?;
100
+ constructor(options: APIHubToolsetOptions);
101
+ /**
102
+ * Returns one tool per operation in the spec, or an empty array when the
103
+ * spec is empty.
104
+ *
105
+ * @throws When the spec cannot be fetched or is not valid YAML or JSON.
106
+ */
107
+ getTools(context?: ReadonlyContext): Promise<BaseTool[]>;
108
+ /**
109
+ * Returns the tool with the given name, or `undefined` when the spec
110
+ * produced no such tool.
111
+ *
112
+ * Unlike `OpenAPIToolset.getTool`, the result is a Promise, because the spec
113
+ * may still be loading.
114
+ *
115
+ * @param name The tool name, which is the operation ID in snake_case.
116
+ * @throws When the spec cannot be fetched or is not valid YAML or JSON.
117
+ */
118
+ getTool(name: string): Promise<RestApiTool | undefined>;
119
+ close(): Promise<void>;
120
+ private loadToolset;
121
+ private prepareTools;
122
+ }
@@ -0,0 +1,142 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * Fetches the content of an API specification registered in API Hub.
8
+ *
9
+ * Implement this interface to give an `APIHubToolset` a different source of
10
+ * specs, such as a cache, a local file, or a test double.
11
+ */
12
+ export interface BaseAPIHubClient {
13
+ /**
14
+ * Returns the content of the spec that `path` resolves to.
15
+ *
16
+ * @param path An API, API version or API spec resource name, or an API Hub
17
+ * console URL.
18
+ */
19
+ getSpecContent(path: string): Promise<string>;
20
+ }
21
+ /** Options for {@link APIHubClient}. */
22
+ export interface APIHubClientOptions {
23
+ /**
24
+ * An OAuth access token sent as the bearer token on every request, for
25
+ * example the output of `gcloud auth print-access-token`. Takes precedence
26
+ * over `serviceAccountJson`.
27
+ */
28
+ accessToken?: string;
29
+ /**
30
+ * The content of a service account key file, as a JSON string. Used to mint
31
+ * access tokens when `accessToken` is not set. When neither is set, the
32
+ * client uses application default credentials.
33
+ */
34
+ serviceAccountJson?: string;
35
+ }
36
+ /** An API resource as API Hub returns it. */
37
+ export interface APIHubApi {
38
+ /** Resource name, `projects/{p}/locations/{l}/apis/{a}`. */
39
+ name: string;
40
+ /** Resource names of the versions of this API. */
41
+ versions?: string[];
42
+ }
43
+ /** An API version resource as API Hub returns it. */
44
+ export interface APIHubApiVersion {
45
+ /** Resource name, `projects/{p}/locations/{l}/apis/{a}/versions/{v}`. */
46
+ name: string;
47
+ /** Resource names of the specs attached to this version. */
48
+ specs?: string[];
49
+ }
50
+ /** The resource names parsed out of an API Hub path or URL. */
51
+ export interface APIHubResourceNames {
52
+ /** `projects/{p}/locations/{l}/apis/{a}`. */
53
+ apiResourceName: string;
54
+ /** `.../apis/{a}/versions/{v}`, when the input names a version. */
55
+ apiVersionResourceName?: string;
56
+ /** `.../versions/{v}/specs/{s}`, when the input names a version and a spec. */
57
+ apiSpecResourceName?: string;
58
+ }
59
+ /**
60
+ * Client for the API Hub REST API.
61
+ *
62
+ * Each request sends a bearer token. The token is `accessToken` when it is
63
+ * set; otherwise the client mints one from `serviceAccountJson`, or from
64
+ * application default credentials when that is not set either. Minted tokens
65
+ * are cached and refreshed by `google-auth-library`.
66
+ */
67
+ export declare class APIHubClient implements BaseAPIHubClient {
68
+ private readonly accessToken?;
69
+ private readonly serviceAccountJson?;
70
+ private auth?;
71
+ constructor(options?: APIHubClientOptions);
72
+ /**
73
+ * Returns the content of the first spec that `path` resolves to.
74
+ *
75
+ * - A path naming an API resolves to the first spec of its first version.
76
+ * - A path naming an API version resolves to the first spec of that version.
77
+ * - A path naming an API spec resolves to that spec.
78
+ *
79
+ * `path` may be a resource name such as
80
+ * `projects/my-project/locations/us-central1/apis/my-api`, or a console URL
81
+ * such as
82
+ * `https://console.cloud.google.com/apigee/api-hub/locations/us-central1/apis/my-api?project=my-project`.
83
+ *
84
+ * @param path The API, API version or API spec to read.
85
+ * @return The decoded spec content, or `''` when the spec is empty.
86
+ * @throws When the path cannot be parsed, when the API has no versions, when
87
+ * the version has no specs, or when a request fails.
88
+ */
89
+ getSpecContent(path: string): Promise<string>;
90
+ /**
91
+ * Lists the APIs registered in a project and location.
92
+ *
93
+ * @param project The Google Cloud project ID.
94
+ * @param location The API Hub location, for example `us-central1`.
95
+ * @return The APIs, or an empty array when there are none.
96
+ */
97
+ listApis(project: string, location: string): Promise<APIHubApi[]>;
98
+ /**
99
+ * Gets an API by resource name.
100
+ *
101
+ * @param apiResourceName `projects/{p}/locations/{l}/apis/{a}`.
102
+ */
103
+ getApi(apiResourceName: string): Promise<APIHubApi>;
104
+ /**
105
+ * Gets an API version by resource name.
106
+ *
107
+ * @param apiVersionName `projects/{p}/locations/{l}/apis/{a}/versions/{v}`.
108
+ */
109
+ getApiVersion(apiVersionName: string): Promise<APIHubApiVersion>;
110
+ /** Reads the base64-encoded contents of a spec and decodes them as UTF-8. */
111
+ private fetchSpec;
112
+ /** Sends an authenticated GET request and parses the JSON response. */
113
+ private get;
114
+ /**
115
+ * Returns the bearer token for the next request.
116
+ *
117
+ * `GoogleAuth` is created once and reused, so that it can cache the token
118
+ * and refresh it when it expires.
119
+ */
120
+ private getAccessToken;
121
+ /**
122
+ * Builds the error for a token that could not be obtained.
123
+ *
124
+ * Without a service account, the likely fix is to supply a credential. With
125
+ * one, the key itself was rejected, so the error says so and gives the
126
+ * reason.
127
+ */
128
+ private tokenError;
129
+ private createAuth;
130
+ }
131
+ /**
132
+ * Extracts the API, API version and API spec resource names from an API Hub
133
+ * resource path or console URL.
134
+ *
135
+ * The project comes from a `projects/{p}` segment, or from a `project` query
136
+ * parameter when the path has none. The location and the API are required.
137
+ * The spec name is returned only when both a version and a spec are present.
138
+ *
139
+ * @param urlOrPath A resource name, or a console URL under `api-hub/`.
140
+ * @throws When the project, the location or the API cannot be found.
141
+ */
142
+ export declare function extractResourceName(urlOrPath: string): APIHubResourceNames;
@@ -0,0 +1,55 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /** Options for {@link SecretManagerClient}. */
7
+ export interface SecretManagerClientOptions {
8
+ /**
9
+ * The content of a service account key file, as a JSON string, not a path.
10
+ * Takes precedence over `authToken`.
11
+ */
12
+ serviceAccountJson?: string;
13
+ /** An existing OAuth access token. */
14
+ authToken?: string;
15
+ }
16
+ /**
17
+ * Reads secrets from Google Cloud Secret Manager.
18
+ *
19
+ * The client authenticates with `serviceAccountJson` when it is set, then with
20
+ * `authToken`, and otherwise with application default credentials.
21
+ *
22
+ * `@google-cloud/secret-manager` is an optional peer dependency. It is loaded
23
+ * on the first call to {@link SecretManagerClient.getSecret}, so constructing
24
+ * the client does not require it.
25
+ */
26
+ export declare class SecretManagerClient {
27
+ private readonly credentials?;
28
+ private readonly authToken?;
29
+ private clientPromise?;
30
+ /**
31
+ * @throws `Invalid service account JSON: ...` when `serviceAccountJson`
32
+ * does not parse.
33
+ */
34
+ constructor(options?: SecretManagerClientOptions);
35
+ /**
36
+ * Returns the payload of a secret version as a UTF-8 string.
37
+ *
38
+ * @param resourceName The secret version, in the form
39
+ * `projects/{project}/secrets/{secret}/versions/{version}`. Use
40
+ * `latest` as the version to read the newest one.
41
+ * @throws When default credentials are needed and cannot be resolved, or
42
+ * when Secret Manager returns an error, such as a missing secret or a
43
+ * denied permission.
44
+ */
45
+ getSecret(resourceName: string): Promise<string>;
46
+ /**
47
+ * Resolves the Secret Manager client, loading the optional peer and the
48
+ * credentials on first use.
49
+ *
50
+ * A created client is kept. A failure is not kept, so the next call tries
51
+ * again, for example once default credentials become available.
52
+ */
53
+ private getClient;
54
+ private createClient;
55
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * Parses a service account key from its JSON text.
8
+ *
9
+ * @throws `Invalid service account JSON: ...` when `json` does not parse.
10
+ */
11
+ export declare function parseServiceAccountJson(json: string): Record<string, string>;
@@ -0,0 +1,86 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { BaseTool } from '../base_tool.js';
7
+ import { BaseToolset } from '../base_toolset.js';
8
+ /** Options of {@link ApplicationIntegrationToolset}. */
9
+ export interface ApplicationIntegrationToolsetOptions {
10
+ /** The Google Cloud project ID. */
11
+ project: string;
12
+ /** The Google Cloud location, such as `us-central1`. */
13
+ location: string;
14
+ /** The integration name. Set it together with `trigger`. */
15
+ integration?: string;
16
+ /** The API trigger ID of the integration, such as `api_trigger/my_trigger`. */
17
+ trigger?: string;
18
+ /**
19
+ * The Integration Connectors connection name. Set it together with
20
+ * `entityOperations`, `actions`, or both.
21
+ */
22
+ connection?: string;
23
+ /**
24
+ * Operations to expose, keyed by entity name, such as
25
+ * `{Issues: ['LIST', 'GET']}`. An empty list exposes every operation the
26
+ * entity supports.
27
+ */
28
+ entityOperations?: Record<string, string[]>;
29
+ /** Connection actions to expose, such as `['ExecuteCustomQuery']`. */
30
+ actions?: string[];
31
+ /** Prefix of every generated tool name. Defaults to `''`. */
32
+ toolName?: string;
33
+ /** Text appended to every generated tool description. Defaults to `''`. */
34
+ toolInstructions?: string;
35
+ /**
36
+ * A service-account key, as a JSON string. It authenticates both the spec
37
+ * requests and the generated tools. When omitted, both use Application
38
+ * Default Credentials.
39
+ */
40
+ serviceAccountJson?: string;
41
+ }
42
+ /**
43
+ * A toolset generated from a Google Cloud Application Integration API trigger,
44
+ * or from the entity operations and actions of an Integration Connectors
45
+ * connection.
46
+ *
47
+ * The constructor only validates the options. The first `getTools` call
48
+ * fetches the spec and builds the tools, and later calls reuse them.
49
+ *
50
+ * @example
51
+ * // Every operation of an integration API trigger.
52
+ * const integrationToolset = new ApplicationIntegrationToolset({
53
+ * project: 'my-project',
54
+ * location: 'us-central1',
55
+ * integration: 'my-integration',
56
+ * trigger: 'api_trigger/my_trigger',
57
+ * });
58
+ *
59
+ * @example
60
+ * // Entity operations and actions of a connection.
61
+ * const connectionToolset = new ApplicationIntegrationToolset({
62
+ * project: 'my-project',
63
+ * location: 'us-central1',
64
+ * connection: 'my-connection',
65
+ * entityOperations: {Issues: ['LIST', 'GET'], Projects: []},
66
+ * actions: ['ExecuteCustomQuery'],
67
+ * });
68
+ */
69
+ export declare class ApplicationIntegrationToolset extends BaseToolset {
70
+ private readonly options;
71
+ private toolsPromise?;
72
+ /**
73
+ * @throws Error Unless the options name either an integration and a trigger,
74
+ * or a connection with at least one entity operation or action.
75
+ */
76
+ constructor(options: ApplicationIntegrationToolsetOptions);
77
+ /**
78
+ * Returns the generated tools.
79
+ *
80
+ * The first call fetches the spec and builds the tools. Concurrent calls
81
+ * share that load. When it fails, the next call tries again.
82
+ */
83
+ getTools(): Promise<BaseTool[]>;
84
+ close(): Promise<void>;
85
+ private loadTools;
86
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /** OAuth scope every Integration Connectors and Application Integration call needs. */
7
+ export declare const CLOUD_PLATFORM_SCOPE = "https://www.googleapis.com/auth/cloud-platform";
8
+ /** Wraps a failure as `An unexpected error occurred: …`. */
9
+ export declare function unexpectedError(e: unknown): Error;
10
+ /**
11
+ * Supplies cloud-platform access tokens from a service-account key, or from
12
+ * Application Default Credentials when no key is given.
13
+ *
14
+ * One instance holds one `GoogleAuth`, which caches the token and refreshes it
15
+ * before it expires.
16
+ */
17
+ export declare class CloudPlatformTokenSource {
18
+ private readonly serviceAccountJson?;
19
+ private auth?;
20
+ constructor(serviceAccountJson?: string | undefined);
21
+ /**
22
+ * Returns an access token.
23
+ *
24
+ * @throws Error When no key is given and Application Default Credentials are
25
+ * unavailable, or when no token is issued.
26
+ */
27
+ getAccessToken(): Promise<string>;
28
+ private getAuth;
29
+ }
30
+ /** Options for {@link sendCloudRequest}. */
31
+ export interface SendCloudRequestOptions {
32
+ /** The request URL. */
33
+ url: string;
34
+ /** The HTTP method. */
35
+ method: 'GET' | 'POST';
36
+ /** The JSON request body for a POST request. */
37
+ body?: unknown;
38
+ /** Supplies the bearer token. */
39
+ tokenSource: CloudPlatformTokenSource;
40
+ /** The message for an HTTP 400 or 404 response. */
41
+ invalidRequestMessage: string;
42
+ }
43
+ /**
44
+ * Sends an authenticated JSON request to a Google Cloud API and returns the
45
+ * parsed response body.
46
+ *
47
+ * @param options The request URL, method, body, token source, and 400/404 message.
48
+ * @throws Error `invalidRequestMessage` for HTTP 400 and 404,
49
+ * `Request error: …` for any other non-2xx status or a failed fetch, and
50
+ * `An unexpected error occurred: …` for anything else, such as a missing
51
+ * credential or a body that is not JSON.
52
+ */
53
+ export declare function sendCloudRequest(options: SendCloudRequestOptions): Promise<unknown>;