@google/adk 2.3.0 → 2.4.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 (162) hide show
  1. package/dist/cjs/agents/agent_engine_client.js +172 -0
  2. package/dist/cjs/agents/base_agent.js +20 -4
  3. package/dist/cjs/agents/functions.js +28 -0
  4. package/dist/cjs/agents/instructions.js +2 -1
  5. package/dist/cjs/agents/llm_agent.js +19 -6
  6. package/dist/cjs/agents/processors/basic_llm_request_processor.js +1 -1
  7. package/dist/cjs/agents/processors/code_execution_request_processor.js +8 -0
  8. package/dist/cjs/agents/processors/content_processor_utils.js +38 -10
  9. package/dist/cjs/agents/processors/content_request_processor.js +34 -2
  10. package/dist/cjs/agents/processors/instructions_llm_request_processor.js +1 -1
  11. package/dist/cjs/agents/processors/nl_planning_processor.js +12 -3
  12. package/dist/cjs/cli/utils/logs.js +6 -6
  13. package/dist/cjs/code_executors/container_code_executor.js +27 -16
  14. package/dist/cjs/code_executors/unsafe_local_code_executor.js +6 -1
  15. package/dist/cjs/common.js +9 -20
  16. package/dist/cjs/errors/input_validation_error.js +3 -2
  17. package/dist/cjs/index.js +9 -2
  18. package/dist/cjs/plugins/base_plugin.js +13 -23
  19. package/dist/cjs/sessions/base_session_service.js +14 -8
  20. package/dist/cjs/sessions/database_session_service.js +50 -28
  21. package/dist/cjs/sessions/stale_session_error.js +59 -0
  22. package/dist/cjs/skills/loader.js +52 -18
  23. package/dist/cjs/telemetry/setup.js +0 -1
  24. package/dist/cjs/telemetry/tracing.js +53 -10
  25. package/dist/cjs/tools/apihub_tool/apihub_toolset.js +18 -23
  26. package/dist/cjs/tools/application_integration_tool/application_integration_toolset.js +120 -42
  27. package/dist/cjs/tools/application_integration_tool/clients/connections_client.js +163 -95
  28. package/dist/cjs/tools/application_integration_tool/clients/integration_client.js +13 -9
  29. package/dist/cjs/tools/application_integration_tool/integration_connector_tool.js +184 -0
  30. package/dist/cjs/tools/google_api_tool/google_api_tool.js +4 -1
  31. package/dist/cjs/tools/google_api_tool/google_api_toolset.js +173 -0
  32. package/dist/cjs/tools/google_api_tool/google_api_toolsets.js +124 -0
  33. package/dist/cjs/tools/google_api_tool/googleapi_to_openapi_converter.js +2 -2
  34. package/dist/cjs/tools/google_api_tool/index.js +20 -23
  35. package/dist/cjs/tools/load_artifacts_tool.js +12 -6
  36. package/dist/cjs/tools/load_memory_tool.js +12 -10
  37. package/dist/cjs/tools/mcp/mcp_toolset.js +1 -14
  38. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -2
  39. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +20 -6
  40. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +17 -6
  41. package/dist/cjs/tools/openapi_tool/openapi_toolset.js +7 -13
  42. package/dist/cjs/tools/openapi_tool/rest_api_tool.js +17 -1
  43. package/dist/cjs/tools/toolbox_toolset.js +174 -0
  44. package/dist/cjs/tools/webmcp/webmcp_toolset.js +1 -14
  45. package/dist/cjs/utils/client_labels.js +19 -2
  46. package/dist/cjs/utils/failover_utils.js +1 -1
  47. package/dist/cjs/utils/gemini_schema_util.js +24 -6
  48. package/dist/cjs/utils/logger_node.js +4 -0
  49. package/dist/cjs/utils/output_schema_utils.js +5 -2
  50. package/dist/cjs/utils/task.js +1 -1
  51. package/dist/cjs/version.js +1 -1
  52. package/dist/esm/agents/agent_engine_client.js +144 -0
  53. package/dist/esm/agents/base_agent.js +20 -4
  54. package/dist/esm/agents/functions.js +28 -0
  55. package/dist/esm/agents/instructions.js +2 -1
  56. package/dist/esm/agents/llm_agent.js +19 -6
  57. package/dist/esm/agents/processors/basic_llm_request_processor.js +1 -1
  58. package/dist/esm/agents/processors/code_execution_request_processor.js +8 -0
  59. package/dist/esm/agents/processors/content_processor_utils.js +38 -10
  60. package/dist/esm/agents/processors/content_request_processor.js +34 -2
  61. package/dist/esm/agents/processors/instructions_llm_request_processor.js +1 -1
  62. package/dist/esm/agents/processors/nl_planning_processor.js +12 -3
  63. package/dist/esm/cli/utils/logs.js +4 -4
  64. package/dist/esm/code_executors/container_code_executor.js +27 -16
  65. package/dist/esm/code_executors/unsafe_local_code_executor.js +6 -1
  66. package/dist/esm/common.js +10 -13
  67. package/dist/esm/errors/input_validation_error.js +3 -2
  68. package/dist/esm/index.js +17 -3
  69. package/dist/esm/plugins/base_plugin.js +13 -23
  70. package/dist/esm/sessions/base_session_service.js +12 -7
  71. package/dist/esm/sessions/database_session_service.js +49 -28
  72. package/dist/esm/sessions/stale_session_error.js +31 -0
  73. package/dist/esm/skills/loader.js +51 -17
  74. package/dist/esm/telemetry/setup.js +1 -2
  75. package/dist/esm/telemetry/tracing.js +57 -11
  76. package/dist/esm/tools/apihub_tool/apihub_toolset.js +17 -22
  77. package/dist/esm/tools/application_integration_tool/application_integration_toolset.js +124 -42
  78. package/dist/esm/tools/application_integration_tool/clients/connections_client.js +163 -95
  79. package/dist/esm/tools/application_integration_tool/clients/integration_client.js +13 -9
  80. package/dist/esm/tools/application_integration_tool/integration_connector_tool.js +158 -0
  81. package/dist/esm/tools/google_api_tool/google_api_tool.js +4 -1
  82. package/dist/esm/tools/google_api_tool/google_api_toolset.js +146 -0
  83. package/dist/esm/tools/google_api_tool/google_api_toolsets.js +94 -0
  84. package/dist/esm/tools/google_api_tool/googleapi_to_openapi_converter.js +2 -2
  85. package/dist/esm/tools/google_api_tool/index.js +18 -20
  86. package/dist/esm/tools/load_artifacts_tool.js +10 -5
  87. package/dist/esm/tools/load_memory_tool.js +12 -10
  88. package/dist/esm/tools/mcp/mcp_toolset.js +1 -14
  89. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -2
  90. package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +20 -6
  91. package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +17 -6
  92. package/dist/esm/tools/openapi_tool/openapi_toolset.js +6 -12
  93. package/dist/esm/tools/openapi_tool/rest_api_tool.js +17 -1
  94. package/dist/esm/tools/toolbox_toolset.js +148 -0
  95. package/dist/esm/tools/webmcp/webmcp_toolset.js +1 -14
  96. package/dist/esm/utils/client_labels.js +19 -2
  97. package/dist/esm/utils/failover_utils.js +1 -1
  98. package/dist/esm/utils/gemini_schema_util.js +23 -6
  99. package/dist/esm/utils/logger_node.js +4 -0
  100. package/dist/esm/utils/output_schema_utils.js +5 -2
  101. package/dist/esm/utils/task.js +1 -1
  102. package/dist/esm/version.js +1 -1
  103. package/dist/types/agents/agent_engine_client.d.ts +37 -0
  104. package/dist/types/agents/base_agent.d.ts +12 -0
  105. package/dist/types/agents/llm_agent.d.ts +5 -1
  106. package/dist/types/agents/processors/content_processor_utils.d.ts +4 -2
  107. package/dist/types/agents/processors/nl_planning_processor.d.ts +2 -1
  108. package/dist/types/cli/utils/logs.d.ts +1 -1
  109. package/dist/types/code_executors/container_code_executor.d.ts +17 -5
  110. package/dist/types/common.d.ts +5 -9
  111. package/dist/types/errors/input_validation_error.d.ts +2 -1
  112. package/dist/types/index.d.ts +4 -2
  113. package/dist/types/plugins/base_plugin.d.ts +0 -10
  114. package/dist/types/sessions/base_session_service.d.ts +5 -0
  115. package/dist/types/sessions/database_session_service.d.ts +17 -1
  116. package/dist/types/sessions/stale_session_error.d.ts +21 -0
  117. package/dist/types/skills/loader.d.ts +3 -2
  118. package/dist/types/telemetry/tracing.d.ts +17 -3
  119. package/dist/types/tools/apihub_tool/apihub_toolset.d.ts +14 -21
  120. package/dist/types/tools/application_integration_tool/application_integration_toolset.d.ts +32 -9
  121. package/dist/types/tools/application_integration_tool/clients/connections_client.d.ts +22 -8
  122. package/dist/types/tools/application_integration_tool/clients/integration_client.d.ts +3 -3
  123. package/dist/types/tools/application_integration_tool/integration_connector_tool.d.ts +70 -0
  124. package/dist/types/tools/base_toolset.d.ts +6 -5
  125. package/dist/types/tools/google_api_tool/google_api_tool.d.ts +10 -3
  126. package/dist/types/tools/google_api_tool/google_api_toolset.d.ts +55 -0
  127. package/dist/types/tools/google_api_tool/google_api_toolsets.d.ts +48 -0
  128. package/dist/types/tools/google_api_tool/googleapi_to_openapi_converter.d.ts +5 -4
  129. package/dist/types/tools/google_api_tool/index.d.ts +4 -5
  130. package/dist/types/tools/load_artifacts_tool.d.ts +14 -1
  131. package/dist/types/tools/load_memory_tool.d.ts +23 -1
  132. package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +12 -0
  133. package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +8 -0
  134. package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +5 -0
  135. package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +10 -0
  136. package/dist/types/tools/toolbox_toolset.d.ts +159 -0
  137. package/dist/types/utils/client_labels.d.ts +2 -1
  138. package/dist/types/utils/gemini_schema_util.d.ts +8 -0
  139. package/dist/types/utils/output_schema_utils.d.ts +3 -2
  140. package/dist/types/utils/simple_zod_to_json.d.ts +1 -2
  141. package/dist/types/version.d.ts +1 -1
  142. package/dist/web/index_web.js +74 -66
  143. package/dist/web/index_web.js.map +4 -4
  144. package/package.json +34 -27
  145. package/dist/cjs/agents/remote_agent.js +0 -187
  146. package/dist/cjs/tools/crewai_tool.js +0 -132
  147. package/dist/cjs/tools/google_api_tool/google_api_tool_set.js +0 -226
  148. package/dist/cjs/tools/google_api_tool/google_api_tool_sets.js +0 -58
  149. package/dist/cjs/tools/langchain_tool.js +0 -172
  150. package/dist/cjs/tools/toolbox_tool.js +0 -108
  151. package/dist/esm/agents/remote_agent.js +0 -164
  152. package/dist/esm/tools/crewai_tool.js +0 -107
  153. package/dist/esm/tools/google_api_tool/google_api_tool_set.js +0 -188
  154. package/dist/esm/tools/google_api_tool/google_api_tool_sets.js +0 -24
  155. package/dist/esm/tools/langchain_tool.js +0 -148
  156. package/dist/esm/tools/toolbox_tool.js +0 -80
  157. package/dist/types/agents/remote_agent.d.ts +0 -68
  158. package/dist/types/tools/crewai_tool.d.ts +0 -85
  159. package/dist/types/tools/google_api_tool/google_api_tool_set.d.ts +0 -78
  160. package/dist/types/tools/google_api_tool/google_api_tool_sets.d.ts +0 -33
  161. package/dist/types/tools/langchain_tool.d.ts +0 -103
  162. package/dist/types/tools/toolbox_tool.d.ts +0 -73
@@ -20,15 +20,24 @@ import {
20
20
  AuthCredentialTypes
21
21
  } from "../../auth/auth_credential.js";
22
22
  import { experimental } from "../../utils/experimental.js";
23
- import { isJsonObject } from "../../utils/json_utils.js";
23
+ import {
24
+ isJsonObject,
25
+ toJsonObject
26
+ } from "../../utils/json_utils.js";
27
+ import { logger } from "../../utils/logger.js";
24
28
  import { BaseToolset } from "../base_toolset.js";
25
29
  import { serviceAccountDictToSchemeCredential } from "../openapi_tool/auth/auth_helpers.js";
30
+ import { OpenApiSpecParser } from "../openapi_tool/openapi_spec_parser/openapi_spec_parser.js";
26
31
  import { OpenAPIToolset } from "../openapi_tool/openapi_toolset.js";
32
+ import { createRestApiTool } from "../openapi_tool/rest_api_tool.js";
27
33
  import { CLOUD_PLATFORM_SCOPE } from "./clients/cloud_request.js";
28
34
  import {
29
35
  ConnectionsClient
30
36
  } from "./clients/connections_client.js";
31
37
  import { IntegrationClient } from "./clients/integration_client.js";
38
+ import {
39
+ IntegrationConnectorTool
40
+ } from "./integration_connector_tool.js";
32
41
  const AUTH_SCHEME = {
33
42
  type: "http",
34
43
  scheme: "bearer",
@@ -36,19 +45,20 @@ const AUTH_SCHEME = {
36
45
  };
37
46
  let ApplicationIntegrationToolset = class extends BaseToolset {
38
47
  /**
39
- * @throws Error Unless the options name either an integration and a trigger,
40
- * or a connection with at least one entity operation or action.
48
+ * @throws Error Unless the options name either an integration, or a
49
+ * connection with at least one entity operation or action.
41
50
  */
42
51
  constructor(options) {
43
- var _a, _b;
44
- super([]);
45
- const hasIntegration = Boolean(options.integration && options.trigger);
52
+ var _a, _b, _c;
53
+ super((_a = options.toolFilter) != null ? _a : []);
54
+ this.openApiToolsets = [];
55
+ const hasIntegration = Boolean(options.integration);
46
56
  const hasConnection = Boolean(
47
- options.connection && (Object.keys((_a = options.entityOperations) != null ? _a : {}).length > 0 || ((_b = options.actions) != null ? _b : []).length > 0)
57
+ options.connection && (Object.keys((_b = options.entityOperations) != null ? _b : {}).length > 0 || ((_c = options.actions) != null ? _c : []).length > 0)
48
58
  );
49
59
  if (!hasIntegration && !hasConnection) {
50
60
  throw new Error(
51
- "Either (integration and trigger) or (connection and (entityOperations or actions)) should be provided."
61
+ "Either integration or (connection and (entityOperations or actions)) should be provided."
52
62
  );
53
63
  }
54
64
  this.options = options;
@@ -59,72 +69,117 @@ let ApplicationIntegrationToolset = class extends BaseToolset {
59
69
  * The first call fetches the spec and builds the tools. Concurrent calls
60
70
  * share that load. When it fails, the next call tries again.
61
71
  */
62
- async getTools() {
72
+ async getTools(context) {
63
73
  if (!this.toolsPromise) {
64
74
  this.toolsPromise = this.loadTools();
65
75
  }
66
76
  try {
67
- return await this.toolsPromise;
77
+ const tools = await this.toolsPromise;
78
+ return tools.filter((tool) => this.isToolSelected(tool, context));
68
79
  } catch (e) {
69
80
  this.toolsPromise = void 0;
70
81
  throw e;
71
82
  }
72
83
  }
73
84
  async close() {
85
+ for (const openApiToolset of this.openApiToolsets) {
86
+ await openApiToolset.close();
87
+ }
74
88
  }
75
89
  async loadTools() {
76
- var _a;
90
+ var _a, _b;
77
91
  const {
78
92
  project,
79
93
  location,
80
94
  integration,
81
- trigger,
95
+ triggers,
82
96
  connection,
83
97
  entityOperations,
84
98
  actions,
85
- toolName = "",
99
+ toolNamePrefix,
86
100
  toolInstructions = "",
87
- serviceAccountJson
101
+ serviceAccountJson,
102
+ authScheme,
103
+ authCredential: dynamicAuthCredential
88
104
  } = this.options;
105
+ const resolvedToolName = toolNamePrefix != null ? toolNamePrefix : "";
106
+ this.openApiToolsets = [];
89
107
  const integrationClient = new IntegrationClient({
90
108
  project,
91
109
  location,
92
110
  integration,
93
- trigger,
111
+ triggers,
94
112
  connection,
95
113
  entityOperations,
96
114
  actions,
97
115
  serviceAccountJson
98
116
  });
99
- let specDict;
100
- if (integration && trigger) {
101
- specDict = await integrationClient.getOpenApiSpecForIntegration();
102
- } else {
103
- const connectionName = connection != null ? connection : "";
104
- const { serviceName, host } = await new ConnectionsClient({
105
- project,
106
- location,
107
- connection: connectionName,
108
- serviceAccountJson
109
- }).getConnectionDetails();
110
- const instructions = `${toolInstructions}ALWAYS use serviceName = ${serviceName}, host = ${host} and the connection name = projects/${project}/locations/${location}/connections/${connectionName} when using this tool. DO NOT ask the user for these values as you already have those.`;
111
- specDict = await integrationClient.getOpenApiSpecForConnection(
112
- toolName,
113
- instructions
114
- );
115
- }
116
- const spec = specDict;
117
117
  const authCredential = buildAuthCredential(serviceAccountJson);
118
118
  const toolsByName = /* @__PURE__ */ new Map();
119
- for (const [path, pathItem] of Object.entries((_a = spec.paths) != null ? _a : {})) {
120
- const tools = await new OpenAPIToolset({
121
- specDict: { ...spec, paths: { [removeFragment(path)]: pathItem } },
122
- authCredential,
123
- authScheme: AUTH_SCHEME
124
- }).getTools();
125
- for (const tool of tools) {
126
- toolsByName.set(tool.name, tool);
119
+ if (integration) {
120
+ const specDict2 = await integrationClient.getOpenApiSpecForIntegration();
121
+ const spec2 = toOpenApiDocument(specDict2);
122
+ for (const [path, pathItem] of Object.entries((_a = spec2.paths) != null ? _a : {})) {
123
+ const openApiToolset = new OpenAPIToolset({
124
+ specDict: { ...spec2, paths: { [removeFragment(path)]: pathItem } },
125
+ authCredential,
126
+ authScheme: AUTH_SCHEME
127
+ });
128
+ this.openApiToolsets.push(openApiToolset);
129
+ const tools = await openApiToolset.getTools();
130
+ for (const tool of tools) {
131
+ toolsByName.set(tool.name, tool);
132
+ }
127
133
  }
134
+ return [...toolsByName.values()];
135
+ }
136
+ const connectionName = connection != null ? connection : "";
137
+ const connectionDetails = await new ConnectionsClient({
138
+ project,
139
+ location,
140
+ connection: connectionName,
141
+ serviceAccountJson
142
+ }).getConnectionDetails();
143
+ if (authScheme && dynamicAuthCredential && !connectionDetails.authOverrideEnabled) {
144
+ logger.warn(
145
+ "Authentication schema and credentials are not used because authOverrideEnabled is not enabled in the connection."
146
+ );
147
+ }
148
+ const specDict = await integrationClient.getOpenApiSpecForConnection(
149
+ resolvedToolName,
150
+ toolInstructions
151
+ );
152
+ const spec = toOpenApiDocument(specDict);
153
+ addDynamicAuthConfigToConnectionSchemas(spec);
154
+ const operations = new OpenApiSpecParser().parse(spec);
155
+ for (const openApiOperation of operations) {
156
+ const operationObject = toJsonObject(openApiOperation.operation);
157
+ const operation = toStringValue(operationObject["x-operation"]);
158
+ const entity = toStringValue(operationObject["x-entity"]);
159
+ const action = toStringValue(operationObject["x-action"]);
160
+ const restApiTool = createRestApiTool({
161
+ ...openApiOperation,
162
+ endpoint: {
163
+ ...openApiOperation.endpoint,
164
+ path: removeFragment(openApiOperation.endpoint.path)
165
+ }
166
+ });
167
+ restApiTool.configureAuthScheme(AUTH_SCHEME);
168
+ restApiTool.configureAuthCredential(authCredential);
169
+ const tool = new IntegrationConnectorTool({
170
+ name: restApiTool.name,
171
+ description: restApiTool.description,
172
+ connectionName: (_b = connectionDetails.name) != null ? _b : "",
173
+ connectionHost: connectionDetails.host,
174
+ connectionServiceName: connectionDetails.serviceName,
175
+ entity,
176
+ action,
177
+ operation,
178
+ restApiTool,
179
+ authScheme: connectionDetails.authOverrideEnabled ? authScheme : void 0,
180
+ authCredential: connectionDetails.authOverrideEnabled ? dynamicAuthCredential : void 0
181
+ });
182
+ toolsByName.set(tool.name, tool);
128
183
  }
129
184
  return [...toolsByName.values()];
130
185
  }
@@ -133,6 +188,32 @@ __name(ApplicationIntegrationToolset, "ApplicationIntegrationToolset");
133
188
  ApplicationIntegrationToolset = __decorateClass([
134
189
  experimental
135
190
  ], ApplicationIntegrationToolset);
191
+ function addDynamicAuthConfigToConnectionSchemas(spec) {
192
+ var _a;
193
+ const schemas = (_a = spec.components) == null ? void 0 : _a.schemas;
194
+ if (!schemas) {
195
+ return;
196
+ }
197
+ for (const [schemaName, schema] of Object.entries(schemas)) {
198
+ if (schemaName.endsWith("_Request") && isJsonObject(schema) && isJsonObject(schema.properties) && !("query" in schema.properties) && !("dynamicAuthConfig" in schema.properties)) {
199
+ schema.properties = {
200
+ ...schema.properties,
201
+ dynamicAuthConfig: {
202
+ $ref: "#/components/schemas/dynamicAuthConfig"
203
+ }
204
+ };
205
+ }
206
+ }
207
+ }
208
+ __name(addDynamicAuthConfigToConnectionSchemas, "addDynamicAuthConfigToConnectionSchemas");
209
+ function toOpenApiDocument(specDict) {
210
+ return specDict;
211
+ }
212
+ __name(toOpenApiDocument, "toOpenApiDocument");
213
+ function toStringValue(value) {
214
+ return typeof value === "string" ? value : "";
215
+ }
216
+ __name(toStringValue, "toStringValue");
136
217
  function buildAuthCredential(serviceAccountJson) {
137
218
  if (!serviceAccountJson) {
138
219
  return {
@@ -159,5 +240,6 @@ function removeFragment(path) {
159
240
  }
160
241
  __name(removeFragment, "removeFragment");
161
242
  export {
162
- ApplicationIntegrationToolset
243
+ ApplicationIntegrationToolset,
244
+ IntegrationConnectorTool
163
245
  };
@@ -173,55 +173,48 @@ function connectorPayload(jsonSchema) {
173
173
  }
174
174
  __name(connectorPayload, "connectorPayload");
175
175
  function postOperation(options) {
176
- const { summary, description, operationId, requestSchemaRef, responseSchema } = options;
177
- return {
178
- post: {
179
- summary,
180
- description,
181
- operationId,
182
- requestBody: {
176
+ const {
177
+ summary,
178
+ description,
179
+ operationId,
180
+ xOperation,
181
+ xEntity,
182
+ xAction,
183
+ requestSchemaRef,
184
+ responseSchema
185
+ } = options;
186
+ const post = {
187
+ summary,
188
+ description,
189
+ operationId,
190
+ "x-operation": xOperation,
191
+ requestBody: {
192
+ content: {
193
+ "application/json": {
194
+ schema: { $ref: requestSchemaRef }
195
+ }
196
+ }
197
+ },
198
+ responses: {
199
+ "200": {
200
+ description: "Success response",
183
201
  content: {
184
202
  "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
- }
203
+ schema: responseSchema
196
204
  }
197
205
  }
198
206
  }
199
207
  }
200
208
  };
209
+ if (xEntity !== void 0) {
210
+ post["x-entity"] = xEntity;
211
+ }
212
+ if (xAction !== void 0) {
213
+ post["x-action"] = xAction;
214
+ }
215
+ return { post };
201
216
  }
202
217
  __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
218
  function getActionOperation(options) {
226
219
  const {
227
220
  action,
@@ -230,7 +223,7 @@ function getActionOperation(options) {
230
223
  toolName = "",
231
224
  toolInstructions = ""
232
225
  } = options;
233
- let description = `Use this tool with action = "${action}" and operation = "${operation}" only. Don't ask these values from user.`;
226
+ let description = `Use this tool to execute ${action}`;
234
227
  if (operation === "EXECUTE_QUERY") {
235
228
  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
229
  }
@@ -238,6 +231,8 @@ function getActionOperation(options) {
238
231
  summary: actionDisplayName,
239
232
  description: `${description} ${toolInstructions}`,
240
233
  operationId: `${toolName}_${actionDisplayName}`,
234
+ xOperation: operation,
235
+ xAction: action,
241
236
  requestSchemaRef: `#/components/schemas/${actionDisplayName}_Request`,
242
237
  responseSchema: schemaRef(`${actionDisplayName}_Response`)
243
238
  });
@@ -252,8 +247,10 @@ function listOperation(options) {
252
247
  } = options;
253
248
  return postOperation({
254
249
  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}`,
250
+ description: `Returns the list of ${entity} data. If the page token was available in the response, let users know there are more records available. Ask if the user wants to fetch the next page of results. When passing filter use the following format: \`field_name1='value1' AND field_name2='value2'\`. ${toolInstructions}`,
256
251
  operationId: `${toolName}_list_${entity}`,
252
+ xOperation: "LIST_ENTITIES",
253
+ xEntity: entity,
257
254
  requestSchemaRef: `#/components/schemas/list_${entity}_Request`,
258
255
  responseSchema: {
259
256
  description: `Returns a list of ${entity} of json schema: ${schemaAsString}`,
@@ -271,8 +268,10 @@ function getOperation(options) {
271
268
  } = options;
272
269
  return postOperation({
273
270
  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}`,
271
+ description: `Returns the details of the ${entity}. ${toolInstructions}`,
275
272
  operationId: `${toolName}_get_${entity}`,
273
+ xOperation: "GET_ENTITY",
274
+ xEntity: entity,
276
275
  requestSchemaRef: `#/components/schemas/get_${entity}_Request`,
277
276
  responseSchema: {
278
277
  description: `Returns ${entity} of json schema: ${schemaAsString}`,
@@ -284,9 +283,11 @@ __name(getOperation, "getOperation");
284
283
  function createOperation(options) {
285
284
  const { entity, toolName = "", toolInstructions = "" } = options;
286
285
  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}`,
286
+ summary: `Creates a new ${entity}`,
287
+ description: `Creates a new ${entity}. ${toolInstructions}`,
289
288
  operationId: `${toolName}_create_${entity}`,
289
+ xOperation: "CREATE_ENTITY",
290
+ xEntity: entity,
290
291
  requestSchemaRef: `#/components/schemas/create_${entity}_Request`,
291
292
  responseSchema: schemaRef("execute-connector_Response")
292
293
  });
@@ -295,9 +296,11 @@ __name(createOperation, "createOperation");
295
296
  function updateOperation(options) {
296
297
  const { entity, toolName = "", toolInstructions = "" } = options;
297
298
  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}`,
299
+ summary: `Updates the ${entity}`,
300
+ description: `Updates the ${entity}. ${toolInstructions}`,
300
301
  operationId: `${toolName}_update_${entity}`,
302
+ xOperation: "UPDATE_ENTITY",
303
+ xEntity: entity,
301
304
  requestSchemaRef: `#/components/schemas/update_${entity}_Request`,
302
305
  responseSchema: schemaRef("execute-connector_Response")
303
306
  });
@@ -306,15 +309,28 @@ __name(updateOperation, "updateOperation");
306
309
  function deleteOperation(options) {
307
310
  const { entity, toolName = "", toolInstructions = "" } = options;
308
311
  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}`,
312
+ summary: `Delete the ${entity}`,
313
+ description: `Deletes the ${entity}. ${toolInstructions}`,
311
314
  operationId: `${toolName}_delete_${entity}`,
315
+ xOperation: "DELETE_ENTITY",
316
+ xEntity: entity,
312
317
  requestSchemaRef: `#/components/schemas/delete_${entity}_Request`,
313
318
  responseSchema: schemaRef("execute-connector_Response")
314
319
  });
315
320
  }
316
321
  __name(deleteOperation, "deleteOperation");
317
- function createOperationRequest(entity) {
322
+ function createOperationRequest(entity, options) {
323
+ const properties = {
324
+ connectorInputPayload: schemaRef(`connectorInputPayload_${entity}`),
325
+ operation: schemaRef("operation"),
326
+ connectionName: schemaRef("connectionName"),
327
+ serviceName: schemaRef("serviceName"),
328
+ host: schemaRef("host"),
329
+ entity: schemaRef("entity")
330
+ };
331
+ if (options == null ? void 0 : options.includeDynamicAuthConfig) {
332
+ properties["dynamicAuthConfig"] = schemaRef("dynamicAuthConfig");
333
+ }
318
334
  return {
319
335
  type: "object",
320
336
  required: [
@@ -325,18 +341,24 @@ function createOperationRequest(entity) {
325
341
  "host",
326
342
  "entity"
327
343
  ],
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
- }
344
+ properties
336
345
  };
337
346
  }
338
347
  __name(createOperationRequest, "createOperationRequest");
339
- function updateOperationRequest(entity) {
348
+ function updateOperationRequest(entity, options) {
349
+ const properties = {
350
+ connectorInputPayload: schemaRef(`connectorInputPayload_${entity}`),
351
+ entityId: schemaRef("entityId"),
352
+ operation: schemaRef("operation"),
353
+ connectionName: schemaRef("connectionName"),
354
+ serviceName: schemaRef("serviceName"),
355
+ host: schemaRef("host"),
356
+ entity: schemaRef("entity"),
357
+ filterClause: schemaRef("filterClause")
358
+ };
359
+ if (options == null ? void 0 : options.includeDynamicAuthConfig) {
360
+ properties["dynamicAuthConfig"] = schemaRef("dynamicAuthConfig");
361
+ }
340
362
  return {
341
363
  type: "object",
342
364
  required: [
@@ -348,44 +370,96 @@ function updateOperationRequest(entity) {
348
370
  "host",
349
371
  "entity"
350
372
  ],
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
- }
373
+ properties
360
374
  };
361
375
  }
362
376
  __name(updateOperationRequest, "updateOperationRequest");
363
- function getOperationRequest() {
364
- return entityIdRequest();
377
+ function getOperationRequest(options) {
378
+ const properties = {
379
+ entityId: schemaRef("entityId"),
380
+ operation: schemaRef("operation"),
381
+ connectionName: schemaRef("connectionName"),
382
+ serviceName: schemaRef("serviceName"),
383
+ host: schemaRef("host"),
384
+ entity: schemaRef("entity")
385
+ };
386
+ if (options == null ? void 0 : options.includeDynamicAuthConfig) {
387
+ properties["dynamicAuthConfig"] = schemaRef("dynamicAuthConfig");
388
+ }
389
+ return {
390
+ type: "object",
391
+ required: [
392
+ "entityId",
393
+ "operation",
394
+ "connectionName",
395
+ "serviceName",
396
+ "host",
397
+ "entity"
398
+ ],
399
+ properties
400
+ };
365
401
  }
366
402
  __name(getOperationRequest, "getOperationRequest");
367
- function deleteOperationRequest() {
368
- return entityIdRequest();
403
+ function deleteOperationRequest(options) {
404
+ const properties = {
405
+ entityId: schemaRef("entityId"),
406
+ operation: schemaRef("operation"),
407
+ connectionName: schemaRef("connectionName"),
408
+ serviceName: schemaRef("serviceName"),
409
+ host: schemaRef("host"),
410
+ entity: schemaRef("entity"),
411
+ filterClause: schemaRef("filterClause")
412
+ };
413
+ if (options == null ? void 0 : options.includeDynamicAuthConfig) {
414
+ properties["dynamicAuthConfig"] = schemaRef("dynamicAuthConfig");
415
+ }
416
+ return {
417
+ type: "object",
418
+ required: [
419
+ "entityId",
420
+ "operation",
421
+ "connectionName",
422
+ "serviceName",
423
+ "host",
424
+ "entity"
425
+ ],
426
+ properties
427
+ };
369
428
  }
370
429
  __name(deleteOperationRequest, "deleteOperationRequest");
371
- function listOperationRequest() {
430
+ function listOperationRequest(options) {
431
+ const properties = {
432
+ filterClause: schemaRef("filterClause"),
433
+ pageSize: schemaRef("pageSize"),
434
+ pageToken: schemaRef("pageToken"),
435
+ operation: schemaRef("operation"),
436
+ connectionName: schemaRef("connectionName"),
437
+ serviceName: schemaRef("serviceName"),
438
+ host: schemaRef("host"),
439
+ entity: schemaRef("entity")
440
+ };
441
+ if (options == null ? void 0 : options.includeDynamicAuthConfig) {
442
+ properties["dynamicAuthConfig"] = schemaRef("dynamicAuthConfig");
443
+ }
372
444
  return {
373
445
  type: "object",
374
446
  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
- }
447
+ properties
385
448
  };
386
449
  }
387
450
  __name(listOperationRequest, "listOperationRequest");
388
- function actionRequest(action) {
451
+ function actionRequest(action, options) {
452
+ const properties = {
453
+ operation: schemaRef("operation"),
454
+ connectionName: schemaRef("connectionName"),
455
+ serviceName: schemaRef("serviceName"),
456
+ host: schemaRef("host"),
457
+ action: schemaRef("action"),
458
+ connectorInputPayload: schemaRef(`connectorInputPayload_${action}`)
459
+ };
460
+ if (options == null ? void 0 : options.includeDynamicAuthConfig) {
461
+ properties["dynamicAuthConfig"] = schemaRef("dynamicAuthConfig");
462
+ }
389
463
  return {
390
464
  type: "object",
391
465
  required: [
@@ -396,14 +470,7 @@ function actionRequest(action) {
396
470
  "action",
397
471
  "connectorInputPayload"
398
472
  ],
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
- }
473
+ properties
407
474
  };
408
475
  }
409
476
  __name(actionRequest, "actionRequest");
@@ -450,16 +517,17 @@ let ConnectionsClient = class {
450
517
  this.tokenSource = new CloudPlatformTokenSource(options.serviceAccountJson);
451
518
  }
452
519
  /**
453
- * Reads the service name and host of the connection, and whether it allows
454
- * an authentication override.
520
+ * Reads the resource name, service name and host of the connection, and
521
+ * whether it allows an authentication override.
455
522
  */
456
523
  async getConnectionDetails() {
457
524
  const url = `${CONNECTOR_URL}/v1/projects/${this.project}/locations/${this.location}/connections/${this.connection}?view=BASIC`;
458
525
  const connectionData = toJsonObject(await this.executeApiCall(url));
526
+ const name = toStringValue(connectionData["name"]);
459
527
  const host = toStringValue(connectionData["host"]);
460
528
  const serviceName = host ? toStringValue(connectionData["tlsServiceDirectory"]) : toStringValue(connectionData["serviceDirectory"]);
461
529
  const authOverrideEnabled = connectionData["authOverrideEnabled"] === true;
462
- return { serviceName, host, authOverrideEnabled };
530
+ return { name, serviceName, host, authOverrideEnabled };
463
531
  }
464
532
  /**
465
533
  * Reads the JSON schema of an entity and the operations it supports.