@softactivate/adk 1.1.0 → 1.2.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 (141) hide show
  1. package/dist/cjs/agents/functions.js +4 -0
  2. package/dist/cjs/auth/oauth2/oauth2_discovery.js +26 -2
  3. package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +305 -0
  4. package/dist/cjs/code_executors/code_execution_utils.js +1 -1
  5. package/dist/cjs/common.js +3 -0
  6. package/dist/cjs/events/event.js +2 -0
  7. package/dist/cjs/index.js +14 -0
  8. package/dist/cjs/integrations/agent_registry/agent_registry.js +362 -0
  9. package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +103 -0
  10. package/dist/cjs/integrations/agent_registry/helpers.js +57 -0
  11. package/dist/cjs/integrations/agent_registry/types.js +50 -0
  12. package/dist/cjs/memory/vertex_ai_memory_bank_service.js +496 -0
  13. package/dist/cjs/runner/in_memory_runner.js +10 -5
  14. package/dist/cjs/runner/runner.js +32 -2
  15. package/dist/cjs/sessions/database_session_service.js +49 -3
  16. package/dist/cjs/sessions/in_memory_session_service.js +70 -14
  17. package/dist/cjs/sessions/registry.js +4 -0
  18. package/dist/cjs/sessions/vertex_ai_session_service.js +428 -0
  19. package/dist/cjs/tools/agent_tool.js +17 -8
  20. package/dist/cjs/tools/exit_loop_tool.js +9 -0
  21. package/dist/cjs/tools/function_tool.js +7 -2
  22. package/dist/cjs/tools/long_running_tool.js +2 -1
  23. package/dist/cjs/tools/mcp/mcp_session_manager.js +11 -0
  24. package/dist/cjs/tools/mcp/mcp_tool.js +10 -7
  25. package/dist/cjs/tools/mcp/mcp_toolset.js +10 -2
  26. package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +78 -0
  27. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +84 -0
  28. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +133 -0
  29. package/dist/cjs/tools/skill/load_skill_resource_tool.js +2 -25
  30. package/dist/cjs/utils/file_utils.js +28 -0
  31. package/dist/cjs/utils/gemini_schema_util.js +18 -0
  32. package/dist/cjs/utils/partial_copy.js +51 -0
  33. package/dist/cjs/utils/streaming_utils.js +167 -118
  34. package/dist/cjs/utils/vertex_ai_utils.js +50 -0
  35. package/dist/cjs/version.js +1 -1
  36. package/dist/esm/agents/functions.js +4 -0
  37. package/dist/esm/auth/oauth2/oauth2_discovery.js +26 -2
  38. package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +281 -0
  39. package/dist/esm/code_executors/code_execution_utils.js +1 -1
  40. package/dist/esm/common.js +2 -0
  41. package/dist/esm/events/event.js +2 -0
  42. package/dist/esm/index.js +11 -0
  43. package/dist/esm/integrations/agent_registry/agent_registry.js +333 -0
  44. package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +77 -0
  45. package/dist/esm/integrations/agent_registry/helpers.js +28 -0
  46. package/dist/esm/integrations/agent_registry/types.js +20 -0
  47. package/dist/esm/memory/vertex_ai_memory_bank_service.js +468 -0
  48. package/dist/esm/runner/in_memory_runner.js +10 -5
  49. package/dist/esm/runner/runner.js +32 -2
  50. package/dist/esm/sessions/database_session_service.js +49 -3
  51. package/dist/esm/sessions/in_memory_session_service.js +70 -14
  52. package/dist/esm/sessions/registry.js +7 -0
  53. package/dist/esm/sessions/vertex_ai_session_service.js +403 -0
  54. package/dist/esm/tools/agent_tool.js +17 -8
  55. package/dist/esm/tools/exit_loop_tool.js +9 -0
  56. package/dist/esm/tools/function_tool.js +7 -2
  57. package/dist/esm/tools/long_running_tool.js +2 -1
  58. package/dist/esm/tools/mcp/mcp_session_manager.js +11 -0
  59. package/dist/esm/tools/mcp/mcp_tool.js +10 -7
  60. package/dist/esm/tools/mcp/mcp_toolset.js +10 -2
  61. package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +48 -0
  62. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
  63. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
  64. package/dist/esm/tools/skill/load_skill_resource_tool.js +1 -24
  65. package/dist/esm/utils/file_utils.js +26 -0
  66. package/dist/esm/utils/gemini_schema_util.js +18 -0
  67. package/dist/esm/utils/partial_copy.js +23 -0
  68. package/dist/esm/utils/streaming_utils.js +165 -117
  69. package/dist/esm/utils/vertex_ai_utils.js +22 -0
  70. package/dist/esm/version.js +1 -1
  71. package/dist/types/a2a/a2a_remote_agent.d.ts +14 -0
  72. package/dist/types/agents/processors/base_llm_processor.d.ts +12 -4
  73. package/dist/types/agents/processors/basic_llm_request_processor.d.ts +5 -0
  74. package/dist/types/agents/processors/identity_llm_request_processor.d.ts +4 -0
  75. package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +5 -0
  76. package/dist/types/agents/run_config.d.ts +15 -0
  77. package/dist/types/code_executors/agent_engine_sandbox_code_executor.d.ts +51 -0
  78. package/dist/types/common.d.ts +2 -0
  79. package/dist/types/events/event_actions.d.ts +24 -6
  80. package/dist/types/events/structured_events.d.ts +13 -0
  81. package/dist/types/examples/example_util.d.ts +25 -0
  82. package/dist/types/index.d.ts +6 -0
  83. package/dist/types/integrations/agent_registry/agent_registry.d.ts +94 -0
  84. package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +43 -0
  85. package/dist/types/integrations/agent_registry/helpers.d.ts +7 -0
  86. package/dist/types/integrations/agent_registry/types.d.ts +101 -0
  87. package/dist/types/memory/vertex_ai_memory_bank_service.d.ts +52 -0
  88. package/dist/types/runner/in_memory_runner.d.ts +28 -1
  89. package/dist/types/runner/runner.d.ts +47 -0
  90. package/dist/types/sessions/base_session_service.d.ts +18 -0
  91. package/dist/types/sessions/database_session_service.d.ts +1 -1
  92. package/dist/types/sessions/in_memory_session_service.d.ts +1 -1
  93. package/dist/types/sessions/vertex_ai_session_service.d.ts +37 -0
  94. package/dist/types/tools/exit_loop_tool.d.ts +9 -0
  95. package/dist/types/tools/function_tool.d.ts +22 -2
  96. package/dist/types/tools/long_running_tool.d.ts +11 -1
  97. package/dist/types/tools/mcp/mcp_session_manager.d.ts +3 -0
  98. package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +25 -0
  99. package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +20 -0
  100. package/dist/types/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.d.ts +20 -0
  101. package/dist/types/utils/file_utils.d.ts +2 -0
  102. package/dist/types/utils/partial_copy.d.ts +13 -0
  103. package/dist/types/utils/streaming_utils.d.ts +8 -17
  104. package/dist/types/utils/vertex_ai_utils.d.ts +14 -0
  105. package/dist/types/version.d.ts +1 -1
  106. package/dist/web/agents/functions.js +4 -0
  107. package/dist/web/auth/oauth2/oauth2_discovery.js +26 -2
  108. package/dist/web/code_executors/agent_engine_sandbox_code_executor.js +281 -0
  109. package/dist/web/code_executors/code_execution_utils.js +1 -1
  110. package/dist/web/common.js +2 -0
  111. package/dist/web/events/event.js +2 -0
  112. package/dist/web/index.js +11 -0
  113. package/dist/web/integrations/agent_registry/agent_registry.js +333 -0
  114. package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +90 -0
  115. package/dist/web/integrations/agent_registry/helpers.js +28 -0
  116. package/dist/web/integrations/agent_registry/types.js +20 -0
  117. package/dist/web/memory/vertex_ai_memory_bank_service.js +475 -0
  118. package/dist/web/runner/in_memory_runner.js +10 -5
  119. package/dist/web/runner/runner.js +32 -2
  120. package/dist/web/sessions/database_session_service.js +49 -3
  121. package/dist/web/sessions/in_memory_session_service.js +70 -14
  122. package/dist/web/sessions/registry.js +7 -0
  123. package/dist/web/sessions/vertex_ai_session_service.js +414 -0
  124. package/dist/web/tools/agent_tool.js +17 -8
  125. package/dist/web/tools/exit_loop_tool.js +9 -0
  126. package/dist/web/tools/function_tool.js +7 -2
  127. package/dist/web/tools/long_running_tool.js +2 -1
  128. package/dist/web/tools/mcp/mcp_session_manager.js +11 -0
  129. package/dist/web/tools/mcp/mcp_tool.js +10 -7
  130. package/dist/web/tools/mcp/mcp_toolset.js +10 -2
  131. package/dist/web/tools/openapi_tool/auth/auth_helpers.js +48 -0
  132. package/dist/web/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
  133. package/dist/web/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
  134. package/dist/web/tools/skill/load_skill_resource_tool.js +1 -24
  135. package/dist/web/utils/file_utils.js +26 -0
  136. package/dist/web/utils/gemini_schema_util.js +18 -0
  137. package/dist/web/utils/partial_copy.js +23 -0
  138. package/dist/web/utils/streaming_utils.js +218 -117
  139. package/dist/web/utils/vertex_ai_utils.js +22 -0
  140. package/dist/web/version.js +1 -1
  141. package/package.json +2 -1
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { AuthCredential } from '../../../../auth/auth_credential.js';
7
+ import { AuthScheme } from '../../../../auth/auth_schemes.js';
8
+ import { BaseCredentialExchanger, ExchangeResult } from '../../../../auth/exchanger/base_credential_exchanger.js';
9
+ /**
10
+ * Automatically selects the appropriate credential exchanger based on the auth scheme.
11
+ * Ported from Python implementation.
12
+ */
13
+ export declare class AutoAuthCredentialExchanger implements BaseCredentialExchanger {
14
+ private exchangers;
15
+ constructor();
16
+ exchange(params: {
17
+ authScheme?: AuthScheme;
18
+ authCredential: AuthCredential;
19
+ }): Promise<ExchangeResult>;
20
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { AuthCredential } from '../../../../auth/auth_credential.js';
7
+ import { AuthScheme } from '../../../../auth/auth_schemes.js';
8
+ import { BaseCredentialExchanger, ExchangeResult } from '../../../../auth/exchanger/base_credential_exchanger.js';
9
+ /**
10
+ * Fetches credentials for Google Service Account.
11
+ * Ported from Python implementation.
12
+ */
13
+ export declare class ServiceAccountCredentialExchanger implements BaseCredentialExchanger {
14
+ exchange(params: {
15
+ authScheme?: AuthScheme;
16
+ authCredential: AuthCredential;
17
+ }): Promise<ExchangeResult>;
18
+ private exchangeForDefaultCredential;
19
+ private exchangeForExplicitCredential;
20
+ }
@@ -9,3 +9,5 @@ import { File } from '../code_executors/code_execution_utils.js';
9
9
  * @param files The files to materialize.
10
10
  */
11
11
  export declare function materializeFiles(files: File[], dir?: string): Promise<File[]>;
12
+ export declare const EXTENSION_TO_MIME_TYPE: Record<string, string>;
13
+ export declare function guessMimeType(filePath: string): string;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * Copies a set of keys from one object to another.
8
+ *
9
+ * @param source The source object.
10
+ * @param targetKeys The keys to copy.
11
+ * @returns A new object with the specified keys copied from source.
12
+ */
13
+ export declare function partialCopy<TDest extends object>(source: object, targetKeys: (keyof TDest)[]): TDest;
@@ -3,7 +3,7 @@
3
3
  * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { GenerateContentResponse } from '@google/genai';
6
+ import { GenerateContentResponse, Part } from '@google/genai';
7
7
  import { LlmResponse } from '../models/llm_response.js';
8
8
  /**
9
9
  * Aggregates partial streaming responses.
@@ -17,24 +17,15 @@ export declare class StreamingResponseAggregator {
17
17
  private groundingMetadata?;
18
18
  private citationMetadata?;
19
19
  private response?;
20
- private text;
21
- private thoughtText;
22
- private partsSequence;
23
- private currentTextBuffer;
24
- private currentTextIsThought?;
25
20
  private finishReason?;
26
- private currentFcName?;
27
- private currentFcArgs;
28
- private currentFcId?;
29
- private currentThoughtSignature?;
30
- private lastThoughtSignature?;
21
+ private lastThoughtSignature;
22
+ private sawFunctionCall;
23
+ private readonly strategy;
31
24
  constructor(isProgressiveMode?: boolean);
32
- private flushTextBufferToSequence;
33
- private getValueFromPartialArg;
34
- private setValueByJsonPath;
35
- private flushFunctionCallToSequence;
36
- private processStreamingFunctionCall;
37
- private processFunctionCallPart;
38
25
  processResponse(response: GenerateContentResponse): AsyncGenerator<LlmResponse, void, void>;
39
26
  close(): LlmResponse | undefined;
40
27
  }
28
+ /**
29
+ * Checks if a response part has no meaningful content (empty text, no tool calls, etc.)
30
+ */
31
+ export declare function isEmptyContentPart(part: Part): boolean;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * Validates and returns the API key for Express Mode.
8
+ *
9
+ * @param project The project id.
10
+ * @param location The location.
11
+ * @param expressModeApiKey The API key for Express Mode.
12
+ * @returns The resolved API key or undefined.
13
+ */
14
+ export declare function getExpressModeApiKey(project?: string, location?: string, expressModeApiKey?: string): string | undefined;
@@ -3,4 +3,4 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- export declare const version = "1.1.0";
6
+ export declare const version = "1.2.0";
@@ -177,6 +177,8 @@ function buildResponseEvent(tool, functionResult, toolContext, invocationContext
177
177
  let responseResult;
178
178
  if (typeof functionResult !== "object" || functionResult == null) {
179
179
  responseResult = { result: functionResult };
180
+ } else if (Array.isArray(functionResult)) {
181
+ responseResult = { results: functionResult };
180
182
  } else {
181
183
  responseResult = functionResult;
182
184
  }
@@ -411,6 +413,8 @@ async function handleFunctionCallList({
411
413
  functionResponse = { error: functionResponseError };
412
414
  } else if (typeof functionResponse !== "object" || functionResponse == null) {
413
415
  functionResponse = { result: functionResponse };
416
+ } else if (Array.isArray(functionResponse)) {
417
+ functionResponse = { results: functionResponse };
414
418
  }
415
419
  const functionResponseEvent = createEvent({
416
420
  invocationId: invocationContext.invocationId,
@@ -123,6 +123,18 @@ class OAuth2DiscoveryManager {
123
123
  return void 0;
124
124
  }
125
125
  }
126
+ function normaliseHostname(raw) {
127
+ const stripped = raw.replace(/^\[|\]$/g, "");
128
+ const m = stripped.match(/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i);
129
+ if (m) {
130
+ const hi = parseInt(m[1], 16);
131
+ const lo = parseInt(m[2], 16);
132
+ return [hi >> 8 & 255, hi & 255, lo >> 8 & 255, lo & 255].join(".");
133
+ }
134
+ const mDot = stripped.match(/^::ffff:(\d+\.\d+\.\d+\.\d+)$/i);
135
+ if (mDot) return mDot[1];
136
+ return raw;
137
+ }
126
138
  function validateDiscoveryUrl(urlStr) {
127
139
  try {
128
140
  const url = new URL(urlStr);
@@ -130,8 +142,8 @@ function validateDiscoveryUrl(urlStr) {
130
142
  logger.warn("Unsafe protocol for discovery URL: ".concat(url.protocol));
131
143
  return false;
132
144
  }
133
- const host = url.hostname.toLowerCase();
134
- if (host === "localhost" || host === "127.0.0.1" || host === "[::1]" || host.startsWith("10.") || host.startsWith("192.168.") || host.startsWith("169.254.")) {
145
+ const host = normaliseHostname(url.hostname.toLowerCase());
146
+ if (host === "localhost" || host === "127.0.0.1" || host === "[::1]" || host === "0.0.0.0" || host.startsWith("10.") || host.startsWith("192.168.") || host.startsWith("169.254.")) {
135
147
  logger.warn("Unsafe host for discovery URL: ".concat(host));
136
148
  return false;
137
149
  }
@@ -143,6 +155,18 @@ function validateDiscoveryUrl(urlStr) {
143
155
  return false;
144
156
  }
145
157
  }
158
+ const cgnatMatch = host.match(/^100\.(\d+)\./);
159
+ if (cgnatMatch) {
160
+ const secondOctet = parseInt(cgnatMatch[1], 10);
161
+ if (secondOctet >= 64 && secondOctet <= 127) {
162
+ logger.warn("Unsafe host for discovery URL: ".concat(host));
163
+ return false;
164
+ }
165
+ }
166
+ if (/^\[(f[cd][0-9a-f]{2}|fe[89ab][0-9a-f]):/i.test(url.hostname)) {
167
+ logger.warn("Unsafe host for discovery URL: ".concat(url.hostname));
168
+ return false;
169
+ }
146
170
  return true;
147
171
  } catch (e) {
148
172
  logger.warn("Failed to parse URL for validation ".concat(urlStr, ": ").concat(e));
@@ -0,0 +1,281 @@
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 __decorateClass = (decorators, target, key, kind) => {
6
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
7
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
8
+ if (decorator = decorators[i])
9
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
10
+ if (kind && result) __defProp(target, key, result);
11
+ return result;
12
+ };
13
+ /**
14
+ * @license
15
+ * Copyright 2026 Google LLC
16
+ * SPDX-License-Identifier: Apache-2.0
17
+ */
18
+ import { Client } from "@google-cloud/vertexai";
19
+ import { Language } from "@google-cloud/vertexai/build/src/genai/types.js";
20
+ import { experimental } from "../utils/experimental.js";
21
+ import { guessMimeType } from "../utils/file_utils.js";
22
+ const SANDBOX_PATTERN = /^projects\/([a-zA-Z0-9-_]+)\/locations\/([a-zA-Z0-9-_]+)\/reasoningEngines\/(\d+)\/sandboxEnvironments\/(\d+)$/;
23
+ const ENGINE_PATTERN = /^projects\/([a-zA-Z0-9-_]+)\/locations\/([a-zA-Z0-9-_]+)\/reasoningEngines\/(\d+)$/;
24
+ import { logger } from "../utils/logger.js";
25
+ import { BaseCodeExecutor } from "./base_code_executor.js";
26
+ import {
27
+ CodeExecutionLanguage
28
+ } from "./code_execution_utils.js";
29
+ const DEFAULT_MAX_ATTEMPTS = 180;
30
+ const DEFAULT_SANDBOX_TTL = "31536000s";
31
+ const DEFAULT_SANDBOX_DISPLAY_NAME = "default_sandbox";
32
+ const DEFAULT_ENGINE_DISPLAY_NAME = "default_engine";
33
+ function mapLanguage(lang) {
34
+ switch (lang) {
35
+ case CodeExecutionLanguage.PYTHON:
36
+ return Language.LANGUAGE_PYTHON;
37
+ case CodeExecutionLanguage.JAVASCRIPT:
38
+ return Language.LANGUAGE_JAVASCRIPT;
39
+ default:
40
+ throw new Error("Unsupported language for Agent Engine Sandbox: ".concat(lang));
41
+ }
42
+ }
43
+ let AgentEngineSandboxCodeExecutor = class extends BaseCodeExecutor {
44
+ constructor(options = {}) {
45
+ super();
46
+ this.sandboxResourceName = options.sandboxResourceName;
47
+ this.agentEngineResourceName = options.agentEngineResourceName;
48
+ this.projectId = options.projectId || process.env.GOOGLE_CLOUD_PROJECT;
49
+ this.location = options.location || process.env.GOOGLE_CLOUD_LOCATION || "us-central1";
50
+ if (this.sandboxResourceName) {
51
+ const match = this.sandboxResourceName.match(SANDBOX_PATTERN);
52
+ if (match) {
53
+ this.projectId = match[1];
54
+ this.location = match[2];
55
+ } else {
56
+ throw new Error(
57
+ "Invalid sandbox resource name: ".concat(this.sandboxResourceName)
58
+ );
59
+ }
60
+ } else if (this.agentEngineResourceName) {
61
+ const match = this.agentEngineResourceName.match(ENGINE_PATTERN);
62
+ if (match) {
63
+ this.projectId = match[1];
64
+ this.location = match[2];
65
+ } else {
66
+ throw new Error(
67
+ "Invalid agent engine resource name: ".concat(this.agentEngineResourceName)
68
+ );
69
+ }
70
+ }
71
+ if (options.client) {
72
+ this.client = options.client;
73
+ } else {
74
+ if (!this.projectId) {
75
+ throw new Error("Project ID is required.");
76
+ }
77
+ this.client = new Client({
78
+ project: this.projectId,
79
+ location: this.location
80
+ });
81
+ }
82
+ }
83
+ async executeCode(params) {
84
+ var _a;
85
+ const { invocationContext, codeExecutionInput } = params;
86
+ const language = mapLanguage(codeExecutionInput.language);
87
+ const agentEngineName = await this.getOrCreateAgentEngine();
88
+ const sandboxName = await this.getOrCreateSandbox(
89
+ invocationContext,
90
+ agentEngineName,
91
+ language
92
+ );
93
+ const inputs = [
94
+ {
95
+ mimeType: "application/json",
96
+ data: Buffer.from(
97
+ JSON.stringify({ code: codeExecutionInput.code })
98
+ ).toString("base64")
99
+ }
100
+ ];
101
+ if (codeExecutionInput.inputFiles) {
102
+ for (const file of codeExecutionInput.inputFiles) {
103
+ inputs.push({
104
+ mimeType: file.mimeType,
105
+ data: file.content,
106
+ // Assumed to be already base64 encoded based on CodeExecutionInput definition
107
+ metadata: {
108
+ attributes: {
109
+ file_name: Buffer.from(file.name).toString("base64")
110
+ }
111
+ }
112
+ });
113
+ }
114
+ }
115
+ logger.debug("Executing code in sandbox ".concat(sandboxName, "..."));
116
+ const response = await this.client.agentEnginesInternal.sandboxes.executeCodeInternal({
117
+ name: sandboxName,
118
+ inputs
119
+ });
120
+ let stdout = "";
121
+ let stderr = "";
122
+ const outputFiles = [];
123
+ if (response.outputs) {
124
+ for (const output of response.outputs) {
125
+ const attributes = ((_a = output.metadata) == null ? void 0 : _a.attributes) || {};
126
+ const encodedFileName = attributes["file_name"];
127
+ const fileName = encodedFileName ? Buffer.from(encodedFileName, "base64").toString("utf-8") : void 0;
128
+ if (output.mimeType === "application/json" && !fileName) {
129
+ if (output.data) {
130
+ const jsonStr = Buffer.from(output.data, "base64").toString(
131
+ "utf-8"
132
+ );
133
+ try {
134
+ const jsonData = JSON.parse(jsonStr);
135
+ if (jsonData.msg_out !== void 0) {
136
+ stdout = jsonData.msg_out;
137
+ } else {
138
+ stdout = "";
139
+ }
140
+ if (jsonData.msg_err !== void 0) {
141
+ stderr = jsonData.msg_err;
142
+ } else {
143
+ stderr = "";
144
+ }
145
+ } catch (e) {
146
+ logger.warn("Failed to parse JSON output from sandbox", e);
147
+ stdout = jsonStr;
148
+ }
149
+ }
150
+ } else {
151
+ let mimeType = output.mimeType;
152
+ const name = fileName || "output_file";
153
+ if (!mimeType) {
154
+ mimeType = guessMimeType(name);
155
+ }
156
+ outputFiles.push({
157
+ name,
158
+ content: output.data || "",
159
+ mimeType
160
+ });
161
+ }
162
+ }
163
+ }
164
+ return {
165
+ stdout,
166
+ stderr,
167
+ outputFiles
168
+ };
169
+ }
170
+ async getOrCreateAgentEngine() {
171
+ if (this.agentEngineResourceName) {
172
+ return this.agentEngineResourceName;
173
+ }
174
+ if (!this.agentEngineCreationPromise) {
175
+ this.agentEngineCreationPromise = (async () => {
176
+ logger.debug(
177
+ "No Agent Engine resource name provided. Creating a new one..."
178
+ );
179
+ const operation = await this.client.agentEnginesInternal.createInternal(
180
+ {
181
+ config: {
182
+ displayName: DEFAULT_ENGINE_DISPLAY_NAME
183
+ }
184
+ }
185
+ );
186
+ let apiResponse = operation;
187
+ let attempts = 0;
188
+ while (!apiResponse.done && attempts < DEFAULT_MAX_ATTEMPTS) {
189
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
190
+ apiResponse = await this.client.agentEnginesInternal.getAgentOperationInternal({
191
+ operationName: operation.name
192
+ });
193
+ attempts++;
194
+ }
195
+ if (!apiResponse.done) {
196
+ throw new Error(
197
+ "Agent Engine creation operation ".concat(operation.name, " did not complete in time.")
198
+ );
199
+ }
200
+ const response = apiResponse.response;
201
+ this.agentEngineResourceName = response.name;
202
+ logger.debug("Created Agent Engine: ".concat(this.agentEngineResourceName));
203
+ return this.agentEngineResourceName;
204
+ })();
205
+ }
206
+ return this.agentEngineCreationPromise;
207
+ }
208
+ async getOrCreateSandbox(invocationContext, agentEngineName, language) {
209
+ var _a, _b;
210
+ if (this.sandboxResourceName) {
211
+ return this.sandboxResourceName;
212
+ }
213
+ const stateKey = "sandbox_name_".concat(language.toLowerCase());
214
+ let sandboxName = (_b = (_a = invocationContext.session) == null ? void 0 : _a.state) == null ? void 0 : _b[stateKey];
215
+ let createNewSandbox = false;
216
+ if (!sandboxName) {
217
+ createNewSandbox = true;
218
+ } else {
219
+ try {
220
+ const sandbox = await this.client.agentEnginesInternal.sandboxes.getInternal({
221
+ name: sandboxName
222
+ });
223
+ if (!sandbox || sandbox.state !== "STATE_RUNNING") {
224
+ createNewSandbox = true;
225
+ }
226
+ } catch (error) {
227
+ logger.debug(
228
+ "Failed to get sandbox ".concat(sandboxName, ", will create a new one"),
229
+ error
230
+ );
231
+ createNewSandbox = true;
232
+ }
233
+ }
234
+ if (createNewSandbox) {
235
+ logger.debug("Creating a new ".concat(language, " code execution sandbox..."));
236
+ const operation = await this.client.agentEnginesInternal.sandboxes.createInternal({
237
+ name: agentEngineName,
238
+ spec: {
239
+ codeExecutionEnvironment: {
240
+ codeLanguage: language
241
+ }
242
+ },
243
+ config: {
244
+ displayName: DEFAULT_SANDBOX_DISPLAY_NAME,
245
+ ttl: DEFAULT_SANDBOX_TTL
246
+ }
247
+ });
248
+ let apiResponse = operation;
249
+ let attempts = 0;
250
+ while (!apiResponse.done && attempts < DEFAULT_MAX_ATTEMPTS) {
251
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
252
+ apiResponse = await this.client.agentEnginesInternal.sandboxes.getSandboxOperationInternal(
253
+ {
254
+ operationName: operation.name
255
+ }
256
+ );
257
+ attempts++;
258
+ }
259
+ if (!apiResponse.done) {
260
+ throw new Error(
261
+ "Sandbox creation operation ".concat(operation.name, " did not complete in time.")
262
+ );
263
+ }
264
+ const response = apiResponse.response;
265
+ sandboxName = response.name;
266
+ if (invocationContext.session) {
267
+ if (!invocationContext.session.state) {
268
+ invocationContext.session.state = {};
269
+ }
270
+ invocationContext.session.state[stateKey] = sandboxName;
271
+ }
272
+ }
273
+ return sandboxName;
274
+ }
275
+ };
276
+ AgentEngineSandboxCodeExecutor = __decorateClass([
277
+ experimental
278
+ ], AgentEngineSandboxCodeExecutor);
279
+ export {
280
+ AgentEngineSandboxCodeExecutor
281
+ };
@@ -47,7 +47,7 @@ function extractCodeAndTruncateContent(content, codeBlockDelimiters) {
47
47
  const leadingDelimiterPattern = codeBlockDelimiters.map((d) => d[0]).join("|");
48
48
  const trailingDelimiterPattern = codeBlockDelimiters.map((d) => d[1]).join("|");
49
49
  const match = new RegExp(
50
- "?<prefix>.*?)(".concat(leadingDelimiterPattern, ")(?<codeStr>.*?)(").concat(trailingDelimiterPattern, ")(?<suffix>.*?)$"),
50
+ "(?<prefix>.*?)(".concat(leadingDelimiterPattern, ")(?<codeStr>.*?)(").concat(trailingDelimiterPattern, ")(?<suffix>.*?)$"),
51
51
  "s"
52
52
  ).exec(responseText);
53
53
  const { prefix, codeStr } = (match == null ? void 0 : match.groups) || {};
@@ -64,6 +64,7 @@ import {
64
64
  isBaseExampleProvider
65
65
  } from "./examples/base_example_provider.js";
66
66
  import { InMemoryMemoryService } from "./memory/in_memory_memory_service.js";
67
+ import { VertexAiMemoryBankService } from "./memory/vertex_ai_memory_bank_service.js";
67
68
  import { ApigeeLlm } from "./models/apigee_llm.js";
68
69
  import { BaseLlm, isBaseLlm } from "./models/base_llm.js";
69
70
  import { Gemini, geminiInitParams } from "./models/google_llm.js";
@@ -208,6 +209,7 @@ export {
208
209
  TruncatingContextCompactor,
209
210
  URL_CONTEXT,
210
211
  UrlContextTool,
212
+ VertexAiMemoryBankService,
211
213
  VertexAiSearchTool,
212
214
  VertexRagRetrievalTool,
213
215
  createEvent,
@@ -97,6 +97,7 @@ const PRESERVE_KEYS_CAMEL_CASE = [
97
97
  "actions.requestedAuthConfigs",
98
98
  "actions.requestedToolConfirmations",
99
99
  "actions.customMetadata",
100
+ "customMetadata",
100
101
  "content.parts.functionCall.args",
101
102
  "content.parts.functionResponse.response"
102
103
  ];
@@ -106,6 +107,7 @@ const PRESERVE_KEYS_SNAKE_CASE = [
106
107
  "actions.requested_auth_configs",
107
108
  "actions.requested_tool_confirmations",
108
109
  "actions.custom_metadata",
110
+ "custom_metadata",
109
111
  "content.parts.function_call.args",
110
112
  "content.parts.function_response.response"
111
113
  ];
package/dist/web/index.js CHANGED
@@ -9,15 +9,21 @@ import { AGENT_CARD_PATH, RemoteA2AAgent } from "./a2a/a2a_remote_agent.js";
9
9
  import { getA2AAgentCard } from "./a2a/agent_card.js";
10
10
  import { A2AAgentExecutor } from "./a2a/agent_executor.js";
11
11
  import { toA2a } from "./a2a/agent_to_a2a.js";
12
+ import { InvocationContext } from "./agents/invocation_context.js";
12
13
  import { FileArtifactService } from "./artifacts/file_artifact_service.js";
13
14
  import { GcsArtifactService } from "./artifacts/gcs_artifact_service.js";
14
15
  import { getArtifactServiceFromUri } from "./artifacts/registry.js";
16
+ import {
17
+ AgentEngineSandboxCodeExecutor
18
+ } from "./code_executors/agent_engine_sandbox_code_executor.js";
19
+ import { CodeExecutionLanguage } from "./code_executors/code_execution_utils.js";
15
20
  import {
16
21
  UnsafeLocalCodeExecutor
17
22
  } from "./code_executors/unsafe_local_code_executor.js";
18
23
  export * from "./common.js";
19
24
  import { DatabaseSessionService } from "./sessions/database_session_service.js";
20
25
  import { getSessionServiceFromUri } from "./sessions/registry.js";
26
+ import { VertexAiSessionService } from "./sessions/vertex_ai_session_service.js";
21
27
  import {
22
28
  loadAllSkillsInDir,
23
29
  loadSkillFromDir,
@@ -25,6 +31,7 @@ import {
25
31
  } from "./skills/loader.js";
26
32
  import { RunSkillInlineScriptTool } from "./tools/skill/run_skill_inline_script_tool.js";
27
33
  import { RunSkillScriptTool } from "./tools/skill/run_skill_script_tool.js";
34
+ export * from "./integrations/agent_registry/agent_registry.js";
28
35
  export * from "./telemetry/google_cloud.js";
29
36
  export * from "./telemetry/setup.js";
30
37
  export * from "./tools/mcp/mcp_session_manager.js";
@@ -33,13 +40,17 @@ export * from "./tools/mcp/mcp_toolset.js";
33
40
  export {
34
41
  A2AAgentExecutor,
35
42
  AGENT_CARD_PATH,
43
+ AgentEngineSandboxCodeExecutor,
44
+ CodeExecutionLanguage,
36
45
  DatabaseSessionService,
37
46
  FileArtifactService,
38
47
  GcsArtifactService,
48
+ InvocationContext,
39
49
  RemoteA2AAgent,
40
50
  RunSkillInlineScriptTool,
41
51
  RunSkillScriptTool,
42
52
  UnsafeLocalCodeExecutor,
53
+ VertexAiSessionService,
43
54
  getA2AAgentCard,
44
55
  getArtifactServiceFromUri,
45
56
  getSessionServiceFromUri,