@google/adk 2.2.0 → 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 (241) 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/a2a/event_converter_utils.js +5 -1
  5. package/dist/cjs/a2a/metadata_converter_utils.js +2 -1
  6. package/dist/cjs/agents/functions.js +199 -25
  7. package/dist/cjs/agents/instructions.js +4 -1
  8. package/dist/cjs/agents/invocation_context.js +26 -4
  9. package/dist/cjs/agents/langgraph_agent.js +152 -0
  10. package/dist/cjs/agents/llm_agent.js +175 -101
  11. package/dist/cjs/agents/processors/code_execution_request_processor.js +10 -6
  12. package/dist/cjs/agents/remote_agent.js +187 -0
  13. package/dist/cjs/artifacts/in_memory_artifact_service.js +14 -0
  14. package/dist/cjs/auth/auth_handler.js +37 -5
  15. package/dist/cjs/auth/auth_schemes.js +9 -0
  16. package/dist/cjs/cli/cli_eval.js +532 -0
  17. package/dist/cjs/cli/utils/envs.js +116 -0
  18. package/dist/cjs/cli/utils/evals.js +137 -0
  19. package/dist/cjs/cli/utils/logs.js +150 -0
  20. package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +7 -2
  21. package/dist/cjs/code_executors/code_execution_utils.js +48 -16
  22. package/dist/cjs/code_executors/code_executor_context.js +6 -2
  23. package/dist/cjs/common.js +90 -0
  24. package/dist/cjs/context/summarizers/llm_summarizer.js +12 -10
  25. package/dist/cjs/context/token_based_context_compactor.js +2 -1
  26. package/dist/cjs/events/abort_events.js +135 -0
  27. package/dist/cjs/events/event.js +4 -2
  28. package/dist/cjs/events/internal_metadata.js +131 -0
  29. package/dist/cjs/examples/example_util.js +23 -2
  30. package/dist/cjs/flows/llm_flows/audio_transcriber.js +170 -0
  31. package/dist/cjs/index.js +97 -1
  32. package/dist/cjs/integrations/agent_registry/helpers.js +1 -1
  33. package/dist/cjs/models/gemini_llm_connection.js +16 -8
  34. package/dist/cjs/models/google_llm.js +13 -16
  35. package/dist/cjs/models/llm_response.js +9 -1
  36. package/dist/cjs/models/registry.js +1 -1
  37. package/dist/cjs/models/routed_llm.js +9 -8
  38. package/dist/cjs/planners/plan_re_act_planner.js +1 -1
  39. package/dist/cjs/plugins/debug_logging_plugin.js +653 -0
  40. package/dist/cjs/plugins/plugin_manager.js +1 -1
  41. package/dist/cjs/plugins/tool_call_integrity_plugin.js +364 -0
  42. package/dist/cjs/runner/in_memory_runner.js +6 -11
  43. package/dist/cjs/runner/runner.js +121 -35
  44. package/dist/cjs/sessions/db/operations.js +1 -1
  45. package/dist/cjs/sessions/in_memory_session_service.js +3 -1
  46. package/dist/cjs/sessions/state.js +8 -4
  47. package/dist/cjs/sessions/vertex_ai_session_service.js +34 -15
  48. package/dist/cjs/telemetry/tracing.js +97 -66
  49. package/dist/cjs/tools/agent_tool.js +44 -0
  50. package/dist/cjs/tools/apihub_tool/apihub_toolset.js +142 -0
  51. package/dist/cjs/tools/apihub_tool/clients/apihub_client.js +272 -0
  52. package/dist/cjs/tools/apihub_tool/clients/secret_client.js +148 -0
  53. package/dist/cjs/tools/apihub_tool/clients/service_account.js +48 -0
  54. package/dist/cjs/tools/application_integration_tool/application_integration_toolset.js +185 -0
  55. package/dist/cjs/tools/application_integration_tool/clients/cloud_request.js +133 -0
  56. package/dist/cjs/tools/application_integration_tool/clients/connections_client.js +603 -0
  57. package/dist/cjs/tools/application_integration_tool/clients/integration_client.js +219 -0
  58. package/dist/cjs/tools/crewai_tool.js +132 -0
  59. package/dist/cjs/tools/example_tool.js +10 -0
  60. package/dist/cjs/tools/function_tool.js +319 -0
  61. package/dist/cjs/tools/google_api_tool/google_api_tool.js +97 -0
  62. package/dist/cjs/tools/google_api_tool/google_api_tool_set.js +226 -0
  63. package/dist/cjs/tools/google_api_tool/google_api_tool_sets.js +58 -0
  64. package/dist/cjs/tools/google_api_tool/googleapi_to_openapi_converter.js +440 -0
  65. package/dist/cjs/tools/google_api_tool/index.js +64 -0
  66. package/dist/cjs/tools/langchain_tool.js +172 -0
  67. package/dist/cjs/tools/mcp/index.js +12 -0
  68. package/dist/cjs/tools/mcp/mcp_session_manager.js +25 -0
  69. package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +1 -2
  70. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +46 -2
  71. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -1
  72. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
  73. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +14 -2
  74. package/dist/cjs/tools/retrieval/base_retrieval_tool.js +18 -3
  75. package/dist/cjs/tools/toolbox_tool.js +108 -0
  76. package/dist/cjs/utils/env_aware_utils.js +6 -8
  77. package/dist/cjs/utils/error_utils.js +11 -11
  78. package/dist/cjs/utils/file_extension_utils.js +11 -0
  79. package/dist/cjs/utils/file_utils.js +2 -24
  80. package/dist/cjs/utils/gemini_schema_util.js +4 -1
  81. package/dist/cjs/utils/json_utils.js +49 -0
  82. package/dist/cjs/utils/live_connection_utils.js +4 -5
  83. package/dist/cjs/utils/logger_node.js +7 -1
  84. package/dist/cjs/utils/object_notation_utils.js +6 -3
  85. package/dist/cjs/utils/streaming_utils.js +12 -12
  86. package/dist/cjs/version.js +1 -1
  87. package/dist/esm/a2a/a2a_remote_agent.js +4 -1
  88. package/dist/esm/a2a/agent_card.js +103 -27
  89. package/dist/esm/a2a/agent_to_a2a.js +5 -2
  90. package/dist/esm/a2a/event_converter_utils.js +5 -1
  91. package/dist/esm/a2a/metadata_converter_utils.js +2 -1
  92. package/dist/esm/agents/functions.js +198 -25
  93. package/dist/esm/agents/instructions.js +4 -1
  94. package/dist/esm/agents/invocation_context.js +24 -4
  95. package/dist/esm/agents/langgraph_agent.js +123 -0
  96. package/dist/esm/agents/llm_agent.js +185 -104
  97. package/dist/esm/agents/processors/code_execution_request_processor.js +13 -8
  98. package/dist/esm/agents/remote_agent.js +164 -0
  99. package/dist/esm/artifacts/in_memory_artifact_service.js +14 -0
  100. package/dist/esm/auth/auth_handler.js +37 -5
  101. package/dist/esm/auth/auth_schemes.js +8 -0
  102. package/dist/esm/cli/cli_eval.js +510 -0
  103. package/dist/esm/cli/utils/envs.js +78 -0
  104. package/dist/esm/cli/utils/evals.js +109 -0
  105. package/dist/esm/cli/utils/logs.js +111 -0
  106. package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +7 -2
  107. package/dist/esm/code_executors/code_execution_utils.js +46 -16
  108. package/dist/esm/code_executors/code_executor_context.js +5 -2
  109. package/dist/esm/common.js +87 -3
  110. package/dist/esm/context/summarizers/llm_summarizer.js +12 -10
  111. package/dist/esm/context/token_based_context_compactor.js +2 -1
  112. package/dist/esm/events/abort_events.js +110 -0
  113. package/dist/esm/events/event.js +4 -2
  114. package/dist/esm/events/internal_metadata.js +97 -0
  115. package/dist/esm/examples/example_util.js +21 -1
  116. package/dist/esm/flows/llm_flows/audio_transcriber.js +142 -0
  117. package/dist/esm/index.js +99 -1
  118. package/dist/esm/integrations/agent_registry/helpers.js +1 -1
  119. package/dist/esm/models/gemini_llm_connection.js +16 -8
  120. package/dist/esm/models/google_llm.js +14 -17
  121. package/dist/esm/models/llm_response.js +9 -1
  122. package/dist/esm/models/registry.js +1 -1
  123. package/dist/esm/models/routed_llm.js +9 -8
  124. package/dist/esm/planners/plan_re_act_planner.js +1 -1
  125. package/dist/esm/plugins/debug_logging_plugin.js +615 -0
  126. package/dist/esm/plugins/plugin_manager.js +1 -1
  127. package/dist/esm/plugins/tool_call_integrity_plugin.js +339 -0
  128. package/dist/esm/runner/in_memory_runner.js +6 -11
  129. package/dist/esm/runner/runner.js +124 -35
  130. package/dist/esm/sessions/db/operations.js +1 -1
  131. package/dist/esm/sessions/in_memory_session_service.js +3 -1
  132. package/dist/esm/sessions/state.js +8 -4
  133. package/dist/esm/sessions/vertex_ai_session_service.js +34 -15
  134. package/dist/esm/telemetry/tracing.js +97 -66
  135. package/dist/esm/tools/agent_tool.js +44 -0
  136. package/dist/esm/tools/apihub_tool/apihub_toolset.js +106 -0
  137. package/dist/esm/tools/apihub_tool/clients/apihub_client.js +244 -0
  138. package/dist/esm/tools/apihub_tool/clients/secret_client.js +132 -0
  139. package/dist/esm/tools/apihub_tool/clients/service_account.js +21 -0
  140. package/dist/esm/tools/application_integration_tool/application_integration_toolset.js +163 -0
  141. package/dist/esm/tools/application_integration_tool/clients/cloud_request.js +103 -0
  142. package/dist/esm/tools/application_integration_tool/clients/connections_client.js +561 -0
  143. package/dist/esm/tools/application_integration_tool/clients/integration_client.js +215 -0
  144. package/dist/esm/tools/crewai_tool.js +107 -0
  145. package/dist/esm/tools/example_tool.js +13 -1
  146. package/dist/esm/tools/function_tool.js +316 -0
  147. package/dist/esm/tools/google_api_tool/google_api_tool.js +70 -0
  148. package/dist/esm/tools/google_api_tool/google_api_tool_set.js +188 -0
  149. package/dist/esm/tools/google_api_tool/google_api_tool_sets.js +24 -0
  150. package/dist/esm/tools/google_api_tool/googleapi_to_openapi_converter.js +393 -0
  151. package/dist/esm/tools/google_api_tool/index.js +33 -0
  152. package/dist/esm/tools/langchain_tool.js +148 -0
  153. package/dist/esm/tools/mcp/index.js +6 -0
  154. package/dist/esm/tools/mcp/mcp_session_manager.js +25 -0
  155. package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +1 -2
  156. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +50 -3
  157. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -1
  158. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
  159. package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -2
  160. package/dist/esm/tools/retrieval/base_retrieval_tool.js +16 -2
  161. package/dist/esm/tools/toolbox_tool.js +80 -0
  162. package/dist/esm/utils/env_aware_utils.js +6 -8
  163. package/dist/esm/utils/error_utils.js +9 -10
  164. package/dist/esm/utils/file_extension_utils.js +11 -0
  165. package/dist/esm/utils/file_utils.js +2 -23
  166. package/dist/esm/utils/gemini_schema_util.js +4 -1
  167. package/dist/esm/utils/json_utils.js +21 -0
  168. package/dist/esm/utils/live_connection_utils.js +4 -5
  169. package/dist/esm/utils/logger_node.js +7 -1
  170. package/dist/esm/utils/object_notation_utils.js +4 -2
  171. package/dist/esm/utils/streaming_utils.js +11 -11
  172. package/dist/esm/version.js +1 -1
  173. package/dist/types/a2a/a2a_remote_agent.d.ts +9 -0
  174. package/dist/types/a2a/agent_card.d.ts +44 -1
  175. package/dist/types/a2a/agent_to_a2a.d.ts +9 -0
  176. package/dist/types/a2a/index.d.ts +1 -0
  177. package/dist/types/agents/functions.d.ts +33 -1
  178. package/dist/types/agents/invocation_context.d.ts +20 -1
  179. package/dist/types/agents/langgraph_agent.d.ts +153 -0
  180. package/dist/types/agents/remote_agent.d.ts +68 -0
  181. package/dist/types/auth/auth_handler.d.ts +28 -1
  182. package/dist/types/auth/auth_schemes.d.ts +13 -0
  183. package/dist/types/cli/cli_eval.d.ts +173 -0
  184. package/dist/types/cli/utils/envs.d.ts +23 -0
  185. package/dist/types/cli/utils/evals.d.ts +47 -0
  186. package/dist/types/cli/utils/logs.d.ts +38 -0
  187. package/dist/types/code_executors/code_execution_utils.d.ts +39 -0
  188. package/dist/types/code_executors/code_executor_context.d.ts +1 -0
  189. package/dist/types/common.d.ts +30 -4
  190. package/dist/types/events/abort_events.d.ts +43 -0
  191. package/dist/types/events/event.d.ts +4 -0
  192. package/dist/types/events/internal_metadata.d.ts +78 -0
  193. package/dist/types/examples/example_util.d.ts +17 -0
  194. package/dist/types/flows/llm_flows/audio_transcriber.d.ts +85 -0
  195. package/dist/types/index.d.ts +16 -1
  196. package/dist/types/models/gemini_llm_connection.d.ts +6 -7
  197. package/dist/types/models/routed_llm.d.ts +1 -1
  198. package/dist/types/plugins/debug_logging_plugin.d.ts +157 -0
  199. package/dist/types/plugins/tool_call_integrity_plugin.d.ts +116 -0
  200. package/dist/types/runner/in_memory_runner.d.ts +2 -1
  201. package/dist/types/runner/runner.d.ts +34 -0
  202. package/dist/types/sessions/state.d.ts +5 -1
  203. package/dist/types/sessions/vertex_ai_session_service.d.ts +8 -0
  204. package/dist/types/skills/skill.d.ts +1 -1
  205. package/dist/types/telemetry/tracing.d.ts +4 -2
  206. package/dist/types/tools/apihub_tool/apihub_toolset.d.ts +122 -0
  207. package/dist/types/tools/apihub_tool/clients/apihub_client.d.ts +142 -0
  208. package/dist/types/tools/apihub_tool/clients/secret_client.d.ts +55 -0
  209. package/dist/types/tools/apihub_tool/clients/service_account.d.ts +11 -0
  210. package/dist/types/tools/application_integration_tool/application_integration_toolset.d.ts +86 -0
  211. package/dist/types/tools/application_integration_tool/clients/cloud_request.d.ts +53 -0
  212. package/dist/types/tools/application_integration_tool/clients/connections_client.d.ts +215 -0
  213. package/dist/types/tools/application_integration_tool/clients/integration_client.d.ts +72 -0
  214. package/dist/types/tools/crewai_tool.d.ts +85 -0
  215. package/dist/types/tools/example_tool.d.ts +10 -0
  216. package/dist/types/tools/function_tool.d.ts +32 -0
  217. package/dist/types/tools/google_api_tool/google_api_tool.d.ts +30 -0
  218. package/dist/types/tools/google_api_tool/google_api_tool_set.d.ts +78 -0
  219. package/dist/types/tools/google_api_tool/google_api_tool_sets.d.ts +33 -0
  220. package/dist/types/tools/google_api_tool/googleapi_to_openapi_converter.d.ts +164 -0
  221. package/dist/types/tools/google_api_tool/index.d.ts +11 -0
  222. package/dist/types/tools/langchain_tool.d.ts +103 -0
  223. package/dist/types/tools/mcp/index.d.ts +3 -0
  224. package/dist/types/tools/mcp/mcp_session_manager.d.ts +34 -1
  225. package/dist/types/tools/mcp/mcp_toolset.d.ts +15 -0
  226. package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +19 -0
  227. package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +18 -1
  228. package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +2 -1
  229. package/dist/types/tools/retrieval/base_retrieval_tool.d.ts +15 -0
  230. package/dist/types/tools/toolbox_tool.d.ts +73 -0
  231. package/dist/types/utils/env_aware_utils.d.ts +18 -2
  232. package/dist/types/utils/error_utils.d.ts +7 -0
  233. package/dist/types/utils/file_utils.d.ts +6 -1
  234. package/dist/types/utils/gemini_schema_util.d.ts +1 -2
  235. package/dist/types/utils/json_utils.d.ts +11 -0
  236. package/dist/types/utils/object_notation_utils.d.ts +7 -0
  237. package/dist/types/utils/streaming_utils.d.ts +11 -4
  238. package/dist/types/version.d.ts +1 -1
  239. package/dist/web/index_web.js +105 -106
  240. package/dist/web/index_web.js.map +4 -4
  241. package/package.json +8 -3
@@ -0,0 +1,561 @@
1
+ import {createRequire as topLevelCreateRequire} from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __decorateClass = (decorators, target, key, kind) => {
7
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
8
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
9
+ if (decorator = decorators[i])
10
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
11
+ if (kind && result) __defProp(target, key, result);
12
+ return result;
13
+ };
14
+ /**
15
+ * @license
16
+ * Copyright 2026 Google LLC
17
+ * SPDX-License-Identifier: Apache-2.0
18
+ */
19
+ import { experimental } from "../../../utils/experimental.js";
20
+ import { toJsonObject } from "../../../utils/json_utils.js";
21
+ import { CloudPlatformTokenSource, sendCloudRequest } from "./cloud_request.js";
22
+ const CONNECTOR_URL = "https://connectors.googleapis.com";
23
+ const OPERATION_POLL_INTERVAL_MS = 1e3;
24
+ function toStringValue(value) {
25
+ return typeof value === "string" ? value : "";
26
+ }
27
+ __name(toStringValue, "toStringValue");
28
+ function sleep(ms) {
29
+ return new Promise((resolve) => setTimeout(resolve, ms));
30
+ }
31
+ __name(sleep, "sleep");
32
+ function schemaRef(name) {
33
+ return { $ref: `#/components/schemas/${name}` };
34
+ }
35
+ __name(schemaRef, "schemaRef");
36
+ const CONNECTOR_BASE_SPEC = {
37
+ openapi: "3.0.1",
38
+ info: {
39
+ title: "ExecuteConnection",
40
+ description: "This tool can execute a query on connection",
41
+ version: "4"
42
+ },
43
+ servers: [{ url: "https://integrations.googleapis.com" }],
44
+ security: [{ google_auth: ["https://www.googleapis.com/auth/cloud-platform"] }],
45
+ paths: {},
46
+ components: {
47
+ schemas: {
48
+ operation: {
49
+ type: "string",
50
+ default: "LIST_ENTITIES",
51
+ description: "Operation to execute. Possible values are LIST_ENTITIES, GET_ENTITY, CREATE_ENTITY, UPDATE_ENTITY, DELETE_ENTITY in case of entities. EXECUTE_ACTION in case of actions. and EXECUTE_QUERY in case of custom queries."
52
+ },
53
+ entityId: {
54
+ type: "string",
55
+ description: "Name of the entity"
56
+ },
57
+ connectorInputPayload: { type: "object" },
58
+ filterClause: {
59
+ type: "string",
60
+ default: "",
61
+ description: "WHERE clause in SQL query"
62
+ },
63
+ pageSize: {
64
+ type: "integer",
65
+ default: 50,
66
+ description: "Number of entities to return in the response"
67
+ },
68
+ pageToken: {
69
+ type: "string",
70
+ default: "",
71
+ description: "Page token to return the next page of entities"
72
+ },
73
+ connectionName: {
74
+ type: "string",
75
+ default: "",
76
+ description: "Connection resource name to run the query for"
77
+ },
78
+ serviceName: {
79
+ type: "string",
80
+ default: "",
81
+ description: "Service directory for the connection"
82
+ },
83
+ host: {
84
+ type: "string",
85
+ default: "",
86
+ description: "Host name in case of tls service directory"
87
+ },
88
+ entity: {
89
+ type: "string",
90
+ default: "Issues",
91
+ description: "Entity to run the query for"
92
+ },
93
+ action: {
94
+ type: "string",
95
+ default: "ExecuteCustomQuery",
96
+ description: "Action to run the query for"
97
+ },
98
+ query: {
99
+ type: "string",
100
+ default: "",
101
+ description: "Custom Query to execute on the connection"
102
+ },
103
+ dynamicAuthConfig: {
104
+ type: "object",
105
+ default: {},
106
+ description: "Dynamic auth config for the connection"
107
+ },
108
+ timeout: {
109
+ type: "integer",
110
+ default: 120,
111
+ description: "Timeout in seconds for execution of custom query"
112
+ },
113
+ connectorOutputPayload: { type: "object" },
114
+ nextPageToken: { type: "string" },
115
+ "execute-connector_Response": {
116
+ required: ["connectorOutputPayload"],
117
+ type: "object",
118
+ properties: {
119
+ connectorOutputPayload: schemaRef("connectorOutputPayload"),
120
+ nextPageToken: schemaRef("nextPageToken")
121
+ }
122
+ }
123
+ },
124
+ securitySchemes: {
125
+ google_auth: {
126
+ type: "oauth2",
127
+ flows: {
128
+ implicit: {
129
+ authorizationUrl: "https://accounts.google.com/o/oauth2/auth",
130
+ scopes: {
131
+ "https://www.googleapis.com/auth/cloud-platform": "Auth for google cloud services"
132
+ }
133
+ }
134
+ }
135
+ }
136
+ }
137
+ }
138
+ };
139
+ function connectorPayload(jsonSchema) {
140
+ const openApiSchema = {};
141
+ if ("description" in jsonSchema) {
142
+ openApiSchema["description"] = jsonSchema["description"];
143
+ }
144
+ if ("type" in jsonSchema) {
145
+ const type = jsonSchema["type"];
146
+ if (Array.isArray(type)) {
147
+ if (type.includes("null")) {
148
+ openApiSchema["nullable"] = true;
149
+ const otherTypes = type.filter((t) => t !== "null");
150
+ if (otherTypes.length > 0) {
151
+ openApiSchema["type"] = otherTypes[0];
152
+ }
153
+ } else if (type.length > 0) {
154
+ openApiSchema["type"] = type[0];
155
+ }
156
+ } else {
157
+ openApiSchema["type"] = type;
158
+ }
159
+ }
160
+ if (openApiSchema["type"] === "object" && "properties" in jsonSchema) {
161
+ const properties = {};
162
+ for (const [name, schema] of Object.entries(
163
+ toJsonObject(jsonSchema["properties"])
164
+ )) {
165
+ properties[name] = connectorPayload(toJsonObject(schema));
166
+ }
167
+ openApiSchema["properties"] = properties;
168
+ } else if (openApiSchema["type"] === "array" && "items" in jsonSchema) {
169
+ const items = jsonSchema["items"];
170
+ openApiSchema["items"] = Array.isArray(items) ? items.map((item) => connectorPayload(toJsonObject(item))) : connectorPayload(toJsonObject(items));
171
+ }
172
+ return openApiSchema;
173
+ }
174
+ __name(connectorPayload, "connectorPayload");
175
+ function postOperation(options) {
176
+ const { summary, description, operationId, requestSchemaRef, responseSchema } = options;
177
+ return {
178
+ post: {
179
+ summary,
180
+ description,
181
+ operationId,
182
+ requestBody: {
183
+ content: {
184
+ "application/json": {
185
+ schema: { $ref: requestSchemaRef }
186
+ }
187
+ }
188
+ },
189
+ responses: {
190
+ "200": {
191
+ description: "Success response",
192
+ content: {
193
+ "application/json": {
194
+ schema: responseSchema
195
+ }
196
+ }
197
+ }
198
+ }
199
+ }
200
+ };
201
+ }
202
+ __name(postOperation, "postOperation");
203
+ function entityIdRequest() {
204
+ return {
205
+ type: "object",
206
+ required: [
207
+ "entityId",
208
+ "operation",
209
+ "connectionName",
210
+ "serviceName",
211
+ "host",
212
+ "entity"
213
+ ],
214
+ properties: {
215
+ entityId: schemaRef("entityId"),
216
+ operation: schemaRef("operation"),
217
+ connectionName: schemaRef("connectionName"),
218
+ serviceName: schemaRef("serviceName"),
219
+ host: schemaRef("host"),
220
+ entity: schemaRef("entity")
221
+ }
222
+ };
223
+ }
224
+ __name(entityIdRequest, "entityIdRequest");
225
+ function getActionOperation(options) {
226
+ const {
227
+ action,
228
+ operation,
229
+ actionDisplayName,
230
+ toolName = "",
231
+ toolInstructions = ""
232
+ } = options;
233
+ let description = `Use this tool with action = "${action}" and operation = "${operation}" only. Don't ask these values from user.`;
234
+ if (operation === "EXECUTE_QUERY") {
235
+ description += " Use pageSize = 50 and timeout = 120 until user specifies a different value otherwise. If user provides a query in natural language, convert it to SQL query and then execute it using the tool.";
236
+ }
237
+ return postOperation({
238
+ summary: actionDisplayName,
239
+ description: `${description} ${toolInstructions}`,
240
+ operationId: `${toolName}_${actionDisplayName}`,
241
+ requestSchemaRef: `#/components/schemas/${actionDisplayName}_Request`,
242
+ responseSchema: schemaRef(`${actionDisplayName}_Response`)
243
+ });
244
+ }
245
+ __name(getActionOperation, "getActionOperation");
246
+ function listOperation(options) {
247
+ const {
248
+ entity,
249
+ schemaAsString = "",
250
+ toolName = "",
251
+ toolInstructions = ""
252
+ } = options;
253
+ return postOperation({
254
+ summary: `List ${entity}`,
255
+ description: `Returns all entities of type ${entity}. Use this tool with entity = "${entity}" and operation = "LIST_ENTITIES" only. Don't ask these values from user. Always use "" as filter clause and "" as page token and 50 as page size until user specifies a different value otherwise. Use single quotes for strings in filter clause. ${toolInstructions}`,
256
+ operationId: `${toolName}_list_${entity}`,
257
+ requestSchemaRef: `#/components/schemas/list_${entity}_Request`,
258
+ responseSchema: {
259
+ description: `Returns a list of ${entity} of json schema: ${schemaAsString}`,
260
+ $ref: "#/components/schemas/execute-connector_Response"
261
+ }
262
+ });
263
+ }
264
+ __name(listOperation, "listOperation");
265
+ function getOperation(options) {
266
+ const {
267
+ entity,
268
+ schemaAsString = "",
269
+ toolName = "",
270
+ toolInstructions = ""
271
+ } = options;
272
+ return postOperation({
273
+ summary: `Get ${entity}`,
274
+ description: `Returns the details of the ${entity}. Use this tool with entity = "${entity}" and operation = "GET_ENTITY" only. Don't ask these values from user. ${toolInstructions}`,
275
+ operationId: `${toolName}_get_${entity}`,
276
+ requestSchemaRef: `#/components/schemas/get_${entity}_Request`,
277
+ responseSchema: {
278
+ description: `Returns ${entity} of json schema: ${schemaAsString}`,
279
+ $ref: "#/components/schemas/execute-connector_Response"
280
+ }
281
+ });
282
+ }
283
+ __name(getOperation, "getOperation");
284
+ function createOperation(options) {
285
+ const { entity, toolName = "", toolInstructions = "" } = options;
286
+ return postOperation({
287
+ summary: `Create ${entity}`,
288
+ description: `Creates a new entity of type ${entity}. Use this tool with entity = "${entity}" and operation = "CREATE_ENTITY" only. Don't ask these values from user. Follow the schema of the entity provided in the instructions to create ${entity}. ${toolInstructions}`,
289
+ operationId: `${toolName}_create_${entity}`,
290
+ requestSchemaRef: `#/components/schemas/create_${entity}_Request`,
291
+ responseSchema: schemaRef("execute-connector_Response")
292
+ });
293
+ }
294
+ __name(createOperation, "createOperation");
295
+ function updateOperation(options) {
296
+ const { entity, toolName = "", toolInstructions = "" } = options;
297
+ return postOperation({
298
+ summary: `Update ${entity}`,
299
+ description: `Updates an entity of type ${entity}. Use this tool with entity = "${entity}" and operation = "UPDATE_ENTITY" only. Don't ask these values from user. Use entityId to uniquely identify the entity to update. Follow the schema of the entity provided in the instructions to update ${entity}. ${toolInstructions}`,
300
+ operationId: `${toolName}_update_${entity}`,
301
+ requestSchemaRef: `#/components/schemas/update_${entity}_Request`,
302
+ responseSchema: schemaRef("execute-connector_Response")
303
+ });
304
+ }
305
+ __name(updateOperation, "updateOperation");
306
+ function deleteOperation(options) {
307
+ const { entity, toolName = "", toolInstructions = "" } = options;
308
+ return postOperation({
309
+ summary: `Delete ${entity}`,
310
+ description: `Deletes an entity of type ${entity}. Use this tool with entity = "${entity}" and operation = "DELETE_ENTITY" only. Don't ask these values from user. ${toolInstructions}`,
311
+ operationId: `${toolName}_delete_${entity}`,
312
+ requestSchemaRef: `#/components/schemas/delete_${entity}_Request`,
313
+ responseSchema: schemaRef("execute-connector_Response")
314
+ });
315
+ }
316
+ __name(deleteOperation, "deleteOperation");
317
+ function createOperationRequest(entity) {
318
+ return {
319
+ type: "object",
320
+ required: [
321
+ "connectorInputPayload",
322
+ "operation",
323
+ "connectionName",
324
+ "serviceName",
325
+ "host",
326
+ "entity"
327
+ ],
328
+ properties: {
329
+ connectorInputPayload: schemaRef(`connectorInputPayload_${entity}`),
330
+ operation: schemaRef("operation"),
331
+ connectionName: schemaRef("connectionName"),
332
+ serviceName: schemaRef("serviceName"),
333
+ host: schemaRef("host"),
334
+ entity: schemaRef("entity")
335
+ }
336
+ };
337
+ }
338
+ __name(createOperationRequest, "createOperationRequest");
339
+ function updateOperationRequest(entity) {
340
+ return {
341
+ type: "object",
342
+ required: [
343
+ "connectorInputPayload",
344
+ "entityId",
345
+ "operation",
346
+ "connectionName",
347
+ "serviceName",
348
+ "host",
349
+ "entity"
350
+ ],
351
+ properties: {
352
+ connectorInputPayload: schemaRef(`connectorInputPayload_${entity}`),
353
+ entityId: schemaRef("entityId"),
354
+ operation: schemaRef("operation"),
355
+ connectionName: schemaRef("connectionName"),
356
+ serviceName: schemaRef("serviceName"),
357
+ host: schemaRef("host"),
358
+ entity: schemaRef("entity")
359
+ }
360
+ };
361
+ }
362
+ __name(updateOperationRequest, "updateOperationRequest");
363
+ function getOperationRequest() {
364
+ return entityIdRequest();
365
+ }
366
+ __name(getOperationRequest, "getOperationRequest");
367
+ function deleteOperationRequest() {
368
+ return entityIdRequest();
369
+ }
370
+ __name(deleteOperationRequest, "deleteOperationRequest");
371
+ function listOperationRequest() {
372
+ return {
373
+ type: "object",
374
+ required: ["operation", "connectionName", "serviceName", "host", "entity"],
375
+ properties: {
376
+ filterClause: schemaRef("filterClause"),
377
+ pageSize: schemaRef("pageSize"),
378
+ pageToken: schemaRef("pageToken"),
379
+ operation: schemaRef("operation"),
380
+ connectionName: schemaRef("connectionName"),
381
+ serviceName: schemaRef("serviceName"),
382
+ host: schemaRef("host"),
383
+ entity: schemaRef("entity")
384
+ }
385
+ };
386
+ }
387
+ __name(listOperationRequest, "listOperationRequest");
388
+ function actionRequest(action) {
389
+ return {
390
+ type: "object",
391
+ required: [
392
+ "operation",
393
+ "connectionName",
394
+ "serviceName",
395
+ "host",
396
+ "action",
397
+ "connectorInputPayload"
398
+ ],
399
+ properties: {
400
+ operation: schemaRef("operation"),
401
+ connectionName: schemaRef("connectionName"),
402
+ serviceName: schemaRef("serviceName"),
403
+ host: schemaRef("host"),
404
+ action: schemaRef("action"),
405
+ connectorInputPayload: schemaRef(`connectorInputPayload_${action}`)
406
+ }
407
+ };
408
+ }
409
+ __name(actionRequest, "actionRequest");
410
+ function actionResponse(action) {
411
+ return {
412
+ type: "object",
413
+ properties: {
414
+ connectorOutputPayload: schemaRef(`connectorOutputPayload_${action}`)
415
+ }
416
+ };
417
+ }
418
+ __name(actionResponse, "actionResponse");
419
+ function executeCustomQueryRequest() {
420
+ return {
421
+ type: "object",
422
+ required: [
423
+ "operation",
424
+ "connectionName",
425
+ "serviceName",
426
+ "host",
427
+ "action",
428
+ "query",
429
+ "timeout",
430
+ "pageSize"
431
+ ],
432
+ properties: {
433
+ operation: schemaRef("operation"),
434
+ connectionName: schemaRef("connectionName"),
435
+ serviceName: schemaRef("serviceName"),
436
+ host: schemaRef("host"),
437
+ action: schemaRef("action"),
438
+ query: schemaRef("query"),
439
+ timeout: schemaRef("timeout"),
440
+ pageSize: schemaRef("pageSize")
441
+ }
442
+ };
443
+ }
444
+ __name(executeCustomQueryRequest, "executeCustomQueryRequest");
445
+ let ConnectionsClient = class {
446
+ constructor(options) {
447
+ this.project = options.project;
448
+ this.location = options.location;
449
+ this.connection = options.connection;
450
+ this.tokenSource = new CloudPlatformTokenSource(options.serviceAccountJson);
451
+ }
452
+ /**
453
+ * Reads the service name and host of the connection, and whether it allows
454
+ * an authentication override.
455
+ */
456
+ async getConnectionDetails() {
457
+ const url = `${CONNECTOR_URL}/v1/projects/${this.project}/locations/${this.location}/connections/${this.connection}?view=BASIC`;
458
+ const connectionData = toJsonObject(await this.executeApiCall(url));
459
+ const host = toStringValue(connectionData["host"]);
460
+ const serviceName = host ? toStringValue(connectionData["tlsServiceDirectory"]) : toStringValue(connectionData["serviceDirectory"]);
461
+ const authOverrideEnabled = connectionData["authOverrideEnabled"] === true;
462
+ return { serviceName, host, authOverrideEnabled };
463
+ }
464
+ /**
465
+ * Reads the JSON schema of an entity and the operations it supports.
466
+ *
467
+ * @param entity The entity name.
468
+ * @throws Error When the API starts no operation for the entity.
469
+ */
470
+ async getEntitySchemaAndOperations(entity) {
471
+ const url = `${CONNECTOR_URL}/v1/projects/${this.project}/locations/${this.location}/connections/${this.connection}/connectionSchemaMetadata:getEntityType?entityId=${entity}`;
472
+ const operationId = toStringValue(
473
+ toJsonObject(await this.executeApiCall(url))["name"]
474
+ );
475
+ if (!operationId) {
476
+ throw new Error(
477
+ `Failed to get entity schema and operations for entity: ${entity}`
478
+ );
479
+ }
480
+ const response = toJsonObject(
481
+ (await this.pollOperation(operationId))["response"]
482
+ );
483
+ const operations = response["operations"];
484
+ return {
485
+ schema: toJsonObject(response["jsonSchema"]),
486
+ operations: Array.isArray(operations) ? operations.filter((op) => typeof op === "string") : []
487
+ };
488
+ }
489
+ /**
490
+ * Reads the input and output JSON schemas of an action.
491
+ *
492
+ * @param action The action name.
493
+ * @throws Error When the API starts no operation for the action.
494
+ */
495
+ async getActionSchema(action) {
496
+ const url = `${CONNECTOR_URL}/v1/projects/${this.project}/locations/${this.location}/connections/${this.connection}/connectionSchemaMetadata:getAction?actionId=${action}`;
497
+ const operationId = toStringValue(
498
+ toJsonObject(await this.executeApiCall(url))["name"]
499
+ );
500
+ if (!operationId) {
501
+ throw new Error(`Failed to get action schema for action: ${action}`);
502
+ }
503
+ const response = toJsonObject(
504
+ (await this.pollOperation(operationId))["response"]
505
+ );
506
+ return {
507
+ inputSchema: toJsonObject(response["inputJsonSchema"]),
508
+ outputSchema: toJsonObject(response["outputJsonSchema"]),
509
+ description: toStringValue(response["description"]),
510
+ displayName: toStringValue(response["displayName"])
511
+ };
512
+ }
513
+ /**
514
+ * Converts the JSON schema of an entity or an action payload into the
515
+ * OpenAPI schema the connector spec carries.
516
+ */
517
+ connectorPayload(jsonSchema) {
518
+ return connectorPayload(jsonSchema);
519
+ }
520
+ executeApiCall(url) {
521
+ return sendCloudRequest({
522
+ url,
523
+ method: "GET",
524
+ tokenSource: this.tokenSource,
525
+ invalidRequestMessage: `Invalid request. Please check the provided values of project(${this.project}), location(${this.location}), connection(${this.connection}).`
526
+ });
527
+ }
528
+ /** Polls a long-running operation until it reports `done`. */
529
+ async pollOperation(operationId) {
530
+ const url = `${CONNECTOR_URL}/v1/${operationId}`;
531
+ let operation = toJsonObject(await this.executeApiCall(url));
532
+ while (operation["done"] !== true) {
533
+ await sleep(OPERATION_POLL_INTERVAL_MS);
534
+ operation = toJsonObject(await this.executeApiCall(url));
535
+ }
536
+ return operation;
537
+ }
538
+ };
539
+ __name(ConnectionsClient, "ConnectionsClient");
540
+ ConnectionsClient = __decorateClass([
541
+ experimental
542
+ ], ConnectionsClient);
543
+ export {
544
+ CONNECTOR_BASE_SPEC,
545
+ ConnectionsClient,
546
+ actionRequest,
547
+ actionResponse,
548
+ connectorPayload,
549
+ createOperation,
550
+ createOperationRequest,
551
+ deleteOperation,
552
+ deleteOperationRequest,
553
+ executeCustomQueryRequest,
554
+ getActionOperation,
555
+ getOperation,
556
+ getOperationRequest,
557
+ listOperation,
558
+ listOperationRequest,
559
+ updateOperation,
560
+ updateOperationRequest
561
+ };