@google/adk 1.2.0 → 1.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 (190) hide show
  1. package/dist/cjs/agents/base_agent.js +19 -1
  2. package/dist/cjs/agents/instructions.js +81 -33
  3. package/dist/cjs/agents/invocation_context.js +0 -1
  4. package/dist/cjs/agents/llm_agent.js +52 -5
  5. package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +7 -0
  6. package/dist/cjs/agents/processors/basic_llm_request_processor.js +8 -1
  7. package/dist/cjs/agents/processors/content_processor_utils.js +37 -24
  8. package/dist/cjs/agents/processors/content_request_processor.js +7 -0
  9. package/dist/cjs/agents/processors/context_compactor_request_processor.js +12 -0
  10. package/dist/cjs/agents/processors/identity_llm_request_processor.js +7 -0
  11. package/dist/cjs/agents/processors/instructions_llm_request_processor.js +5 -0
  12. package/dist/cjs/agents/processors/request_confirmation_llm_request_processor.js +9 -1
  13. package/dist/cjs/agents/processors/tool_filter_request_processor.js +7 -1
  14. package/dist/cjs/auth/auth_preprocessor.js +12 -10
  15. package/dist/cjs/auth/oauth2/oauth2_discovery.js +1 -1
  16. package/dist/cjs/code_executors/code_executor_context.js +7 -7
  17. package/dist/cjs/common.js +39 -0
  18. package/dist/cjs/context/summarizers/llm_summarizer.js +11 -0
  19. package/dist/cjs/context/token_based_context_compactor.js +1 -1
  20. package/dist/cjs/events/event.js +1 -1
  21. package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
  22. package/dist/cjs/models/gemini_llm_connection.js +62 -19
  23. package/dist/cjs/models/google_llm.js +26 -8
  24. package/dist/cjs/plugins/security_plugin.js +16 -0
  25. package/dist/cjs/sessions/base_session_service.js +13 -2
  26. package/dist/cjs/sessions/database_session_service.js +2 -2
  27. package/dist/cjs/sessions/db/schema.js +45 -10
  28. package/dist/cjs/sessions/in_memory_session_service.js +2 -1
  29. package/dist/cjs/sessions/vertex_ai_session_service.js +2 -1
  30. package/dist/cjs/skills/gcp_skill_registry.js +104 -0
  31. package/dist/cjs/skills/loader.js +65 -0
  32. package/dist/cjs/skills/skill_registry.js +27 -0
  33. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +232 -0
  34. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +224 -0
  35. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +127 -0
  36. package/dist/cjs/tools/openapi_tool/openapi_toolset.js +133 -0
  37. package/dist/cjs/tools/openapi_tool/rest_api_tool.js +256 -0
  38. package/dist/cjs/tools/skill/load_skill_resource_tool.js +25 -3
  39. package/dist/cjs/tools/skill/load_skill_tool.js +12 -1
  40. package/dist/cjs/tools/skill/run_skill_script_tool.js +12 -1
  41. package/dist/cjs/tools/skill/search_skills_tool.js +108 -0
  42. package/dist/cjs/tools/skill/skill_toolset.js +40 -5
  43. package/dist/cjs/utils/async_queue.js +88 -0
  44. package/dist/cjs/utils/case_utils.js +53 -0
  45. package/dist/cjs/utils/env_aware_utils.js +4 -0
  46. package/dist/cjs/utils/live_connection_utils.js +284 -0
  47. package/dist/cjs/utils/model_name.js +9 -0
  48. package/dist/cjs/utils/streaming_utils.js +9 -8
  49. package/dist/cjs/version.js +1 -1
  50. package/dist/esm/agents/base_agent.js +19 -1
  51. package/dist/esm/agents/instructions.js +81 -33
  52. package/dist/esm/agents/invocation_context.js +0 -1
  53. package/dist/esm/agents/llm_agent.js +53 -5
  54. package/dist/esm/agents/processors/agent_transfer_llm_request_processor.js +7 -0
  55. package/dist/esm/agents/processors/basic_llm_request_processor.js +8 -1
  56. package/dist/esm/agents/processors/content_processor_utils.js +35 -23
  57. package/dist/esm/agents/processors/content_request_processor.js +7 -0
  58. package/dist/esm/agents/processors/context_compactor_request_processor.js +12 -0
  59. package/dist/esm/agents/processors/identity_llm_request_processor.js +7 -0
  60. package/dist/esm/agents/processors/instructions_llm_request_processor.js +5 -0
  61. package/dist/esm/agents/processors/request_confirmation_llm_request_processor.js +9 -1
  62. package/dist/esm/agents/processors/tool_filter_request_processor.js +7 -1
  63. package/dist/esm/auth/auth_preprocessor.js +12 -10
  64. package/dist/esm/auth/oauth2/oauth2_discovery.js +1 -1
  65. package/dist/esm/code_executors/code_executor_context.js +7 -7
  66. package/dist/esm/common.js +33 -1
  67. package/dist/esm/context/summarizers/llm_summarizer.js +11 -0
  68. package/dist/esm/context/token_based_context_compactor.js +1 -1
  69. package/dist/esm/events/event.js +1 -1
  70. package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
  71. package/dist/esm/models/gemini_llm_connection.js +62 -19
  72. package/dist/esm/models/google_llm.js +26 -8
  73. package/dist/esm/plugins/security_plugin.js +16 -0
  74. package/dist/esm/sessions/base_session_service.js +11 -1
  75. package/dist/esm/sessions/database_session_service.js +2 -2
  76. package/dist/esm/sessions/db/schema.js +44 -10
  77. package/dist/esm/sessions/in_memory_session_service.js +4 -2
  78. package/dist/esm/sessions/vertex_ai_session_service.js +4 -2
  79. package/dist/esm/skills/gcp_skill_registry.js +78 -0
  80. package/dist/esm/skills/loader.js +64 -0
  81. package/dist/esm/skills/skill_registry.js +7 -0
  82. package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +206 -0
  83. package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
  84. package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +101 -0
  85. package/dist/esm/tools/openapi_tool/openapi_toolset.js +97 -0
  86. package/dist/esm/tools/openapi_tool/rest_api_tool.js +229 -0
  87. package/dist/esm/tools/skill/load_skill_resource_tool.js +25 -3
  88. package/dist/esm/tools/skill/load_skill_tool.js +12 -1
  89. package/dist/esm/tools/skill/run_skill_script_tool.js +12 -1
  90. package/dist/esm/tools/skill/search_skills_tool.js +82 -0
  91. package/dist/esm/tools/skill/skill_toolset.js +40 -5
  92. package/dist/esm/utils/async_queue.js +60 -0
  93. package/dist/esm/utils/case_utils.js +25 -0
  94. package/dist/esm/utils/env_aware_utils.js +4 -0
  95. package/dist/esm/utils/live_connection_utils.js +256 -0
  96. package/dist/esm/utils/model_name.js +8 -0
  97. package/dist/esm/utils/streaming_utils.js +9 -8
  98. package/dist/esm/version.js +1 -1
  99. package/dist/types/a2a/a2a_remote_agent_utils.d.ts +29 -4
  100. package/dist/types/a2a/event_converter_utils.d.ts +14 -1
  101. package/dist/types/a2a/metadata_converter_utils.d.ts +18 -0
  102. package/dist/types/a2a/part_converter_utils.d.ts +51 -6
  103. package/dist/types/agents/invocation_context.d.ts +0 -9
  104. package/dist/types/agents/llm_agent.d.ts +14 -0
  105. package/dist/types/agents/processors/agent_transfer_llm_request_processor.d.ts +14 -0
  106. package/dist/types/agents/processors/basic_llm_request_processor.d.ts +7 -0
  107. package/dist/types/agents/processors/content_processor_utils.d.ts +26 -0
  108. package/dist/types/agents/processors/content_request_processor.d.ts +16 -0
  109. package/dist/types/agents/processors/context_compactor_request_processor.d.ts +12 -0
  110. package/dist/types/agents/processors/identity_llm_request_processor.d.ts +7 -0
  111. package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +9 -1
  112. package/dist/types/agents/processors/tool_filter_request_processor.d.ts +12 -1
  113. package/dist/types/common.d.ts +15 -1
  114. package/dist/types/context/summarizers/llm_summarizer.d.ts +17 -0
  115. package/dist/types/events/event_actions.d.ts +1 -2
  116. package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +21 -2
  117. package/dist/types/models/base_llm_connection.d.ts +10 -0
  118. package/dist/types/models/gemini_llm_connection.d.ts +15 -4
  119. package/dist/types/models/llm_response.d.ts +10 -1
  120. package/dist/types/plugins/security_plugin.d.ts +30 -0
  121. package/dist/types/sessions/base_session_service.d.ts +4 -0
  122. package/dist/types/sessions/db/schema.d.ts +1 -0
  123. package/dist/types/skills/gcp_skill_registry.d.ts +24 -0
  124. package/dist/types/skills/loader.d.ts +7 -0
  125. package/dist/types/skills/skill.d.ts +1 -1
  126. package/dist/types/skills/skill_registry.d.ts +29 -0
  127. package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +34 -0
  128. package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +59 -0
  129. package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +23 -0
  130. package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +27 -0
  131. package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +50 -0
  132. package/dist/types/tools/skill/load_skill_resource_tool.d.ts +1 -1
  133. package/dist/types/tools/skill/search_skills_tool.d.ts +14 -0
  134. package/dist/types/tools/skill/skill_toolset.d.ts +5 -0
  135. package/dist/types/utils/async_queue.d.ts +18 -0
  136. package/dist/types/utils/case_utils.d.ts +12 -0
  137. package/dist/types/utils/live_connection_utils.d.ts +30 -0
  138. package/dist/types/utils/model_name.d.ts +7 -0
  139. package/dist/types/utils/streaming_utils.d.ts +0 -1
  140. package/dist/types/version.d.ts +1 -1
  141. package/dist/web/agents/base_agent.js +31 -1
  142. package/dist/web/agents/instructions.js +81 -33
  143. package/dist/web/agents/invocation_context.js +0 -1
  144. package/dist/web/agents/llm_agent.js +53 -5
  145. package/dist/web/agents/processors/agent_transfer_llm_request_processor.js +7 -0
  146. package/dist/web/agents/processors/basic_llm_request_processor.js +8 -1
  147. package/dist/web/agents/processors/content_processor_utils.js +53 -23
  148. package/dist/web/agents/processors/content_request_processor.js +7 -0
  149. package/dist/web/agents/processors/context_compactor_request_processor.js +12 -0
  150. package/dist/web/agents/processors/identity_llm_request_processor.js +7 -0
  151. package/dist/web/agents/processors/instructions_llm_request_processor.js +5 -0
  152. package/dist/web/agents/processors/request_confirmation_llm_request_processor.js +9 -1
  153. package/dist/web/agents/processors/tool_filter_request_processor.js +7 -1
  154. package/dist/web/auth/auth_preprocessor.js +12 -10
  155. package/dist/web/auth/oauth2/oauth2_discovery.js +1 -1
  156. package/dist/web/code_executors/code_executor_context.js +7 -7
  157. package/dist/web/common.js +33 -1
  158. package/dist/web/context/summarizers/llm_summarizer.js +11 -0
  159. package/dist/web/context/token_based_context_compactor.js +1 -1
  160. package/dist/web/events/event.js +1 -1
  161. package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
  162. package/dist/web/models/gemini_llm_connection.js +75 -19
  163. package/dist/web/models/google_llm.js +26 -8
  164. package/dist/web/plugins/security_plugin.js +16 -0
  165. package/dist/web/sessions/base_session_service.js +11 -1
  166. package/dist/web/sessions/database_session_service.js +2 -2
  167. package/dist/web/sessions/db/schema.js +44 -10
  168. package/dist/web/sessions/in_memory_session_service.js +4 -2
  169. package/dist/web/sessions/vertex_ai_session_service.js +4 -2
  170. package/dist/web/skills/gcp_skill_registry.js +78 -0
  171. package/dist/web/skills/loader.js +64 -0
  172. package/dist/web/skills/skill_registry.js +7 -0
  173. package/dist/web/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +221 -0
  174. package/dist/web/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
  175. package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +101 -0
  176. package/dist/web/tools/openapi_tool/openapi_toolset.js +97 -0
  177. package/dist/web/tools/openapi_tool/rest_api_tool.js +229 -0
  178. package/dist/web/tools/skill/load_skill_resource_tool.js +25 -3
  179. package/dist/web/tools/skill/load_skill_tool.js +12 -1
  180. package/dist/web/tools/skill/run_skill_script_tool.js +12 -1
  181. package/dist/web/tools/skill/search_skills_tool.js +82 -0
  182. package/dist/web/tools/skill/skill_toolset.js +40 -5
  183. package/dist/web/utils/async_queue.js +60 -0
  184. package/dist/web/utils/case_utils.js +25 -0
  185. package/dist/web/utils/env_aware_utils.js +4 -0
  186. package/dist/web/utils/live_connection_utils.js +254 -0
  187. package/dist/web/utils/model_name.js +8 -0
  188. package/dist/web/utils/streaming_utils.js +9 -8
  189. package/dist/web/version.js +1 -1
  190. package/package.json +3 -1
@@ -11,10 +11,21 @@ import {
11
11
  import { stringifyContent } from "../../events/event.js";
12
12
  const DEFAULT_PROMPT = "The following is a conversation history between a user and an AI agent. Please summarize the conversation, focusing on key information and decisions made, as well as any unresolved questions or tasks. The summary should be concise and capture the essence of the interaction.";
13
13
  class LlmSummarizer {
14
+ /**
15
+ * @param options - Configuration specifying the LLM and optional prompt.
16
+ */
14
17
  constructor(options) {
15
18
  this.llm = options.llm;
16
19
  this.prompt = options.prompt || DEFAULT_PROMPT;
17
20
  }
21
+ /**
22
+ * Summarizes a list of events into a single {@link CompactedEvent} using the
23
+ * configured LLM.
24
+ *
25
+ * @param events - The events to summarize. Must be non-empty.
26
+ * @returns A promise resolving to the compacted representation.
27
+ * @throws {Error} If `events` is empty or the LLM returns no content.
28
+ */
18
29
  async summarize(events) {
19
30
  var _a, _b, _c, _d, _e, _f;
20
31
  if (events.length === 0) {
@@ -75,7 +75,7 @@ class TokenBasedContextCompactor {
75
75
  compactedEvent.actions = {
76
76
  stateDelta: {},
77
77
  artifactDelta: {},
78
- requestedAuthConfigs: [],
78
+ requestedAuthConfigs: {},
79
79
  requestedToolConfirmations: {}
80
80
  };
81
81
  }
@@ -20,7 +20,7 @@ function createEvent(params = {}) {
20
20
  };
21
21
  }
22
22
  function isFinalResponse(event) {
23
- if (event.actions.skipSummarization || event.longRunningToolIds && event.longRunningToolIds.length > 0) {
23
+ if (event.actions.skipSummarization || event.longRunningToolIds && event.longRunningToolIds.length > 0 || event.actions.requestedAuthConfigs && Object.keys(event.actions.requestedAuthConfigs).length > 0) {
24
24
  return true;
25
25
  }
26
26
  return getFunctionCalls(event).length === 0 && getFunctionResponses(event).length === 0 && !event.partial && !hasTrailingCodeExecutionResult(event);
@@ -12,6 +12,19 @@ import {
12
12
  import { MCPTool } from "../../tools/mcp/mcp_tool.js";
13
13
  import { GCP_MCP_SERVER_DESTINATION_ID } from "./types.js";
14
14
  class AgentRegistrySingleMCPToolset extends BaseToolset {
15
+ /**
16
+ * @param options - Configuration for the MCP toolset.
17
+ * @param options.destinationResourceId - Telemetry identifier injected as
18
+ * `gcp.mcp.server.destination.id` into each resolved tool's custom metadata.
19
+ * @param options.connectionParams - HTTP connection parameters for the MCP server.
20
+ * @param options.toolFilter - Optional predicate or list of tool names to include.
21
+ * When omitted, all tools from the server are returned.
22
+ * @param options.prefix - Optional prefix prepended to each tool name (e.g. `myServer_toolName`).
23
+ * @param options.headerProvider - Optional async function called immediately before each
24
+ * {@link getTools} invocation to supply or refresh request headers (e.g. GCP auth tokens).
25
+ * @param options.authScheme - Optional auth scheme forwarded to each resolved tool.
26
+ * @param options.authCredential - Optional credential forwarded to each resolved tool.
27
+ */
15
28
  constructor(options) {
16
29
  super(options.toolFilter || [], options.prefix);
17
30
  this.destinationResourceId = options.destinationResourceId;
@@ -21,8 +34,14 @@ class AgentRegistrySingleMCPToolset extends BaseToolset {
21
34
  this.authCredential = options.authCredential;
22
35
  }
23
36
  /**
24
- * Connects to the underlying MCP server, retrieves tool definitions, prefixes tool names,
25
- * and injects destination telemetry metadata.
37
+ * Connects to the underlying MCP server, retrieves tool definitions, prefixes
38
+ * tool names, and injects destination telemetry metadata into each tool.
39
+ *
40
+ * The `headerProvider`, if configured, is invoked immediately before the
41
+ * connection is established so that tokens are always fresh.
42
+ *
43
+ * @param context - Optional readonly agent context passed to the header provider.
44
+ * @returns The resolved and optionally filtered list of {@link MCPTool} instances.
26
45
  */
27
46
  async getTools(context) {
28
47
  var _a, _b, _c;
@@ -2,13 +2,17 @@ import {createRequire as topLevelCreateRequire} from 'module';
2
2
  const require = topLevelCreateRequire(import.meta.url);
3
3
  /**
4
4
  * @license
5
- * Copyright 2025 Google LLC
5
+ * Copyright 2026 Google LLC
6
6
  * SPDX-License-Identifier: Apache-2.0
7
7
  */
8
+ import { LiveResponseAggregator } from "../utils/live_connection_utils.js";
8
9
  import { logger } from "../utils/logger.js";
10
+ import { isGemini3xFlashLive } from "../utils/model_name.js";
9
11
  class GeminiLlmConnection {
10
- constructor(geminiSession) {
12
+ constructor(geminiSession, modelVersion, messageQueue) {
11
13
  this.geminiSession = geminiSession;
14
+ this.modelVersion = modelVersion;
15
+ this.messageQueue = messageQueue;
12
16
  }
13
17
  /**
14
18
  * Sends the conversation history to the gemini model.
@@ -27,9 +31,10 @@ class GeminiLlmConnection {
27
31
  }
28
32
  );
29
33
  if (contents.length > 0) {
34
+ const isGemini3x = isGemini3xFlashLive(this.modelVersion);
30
35
  this.geminiSession.sendClientContent({
31
36
  turns: contents,
32
- turnComplete: contents[contents.length - 1].role === "user"
37
+ turnComplete: isGemini3x ? true : contents[contents.length - 1].role === "user"
33
38
  });
34
39
  } else {
35
40
  logger.info("no content is sent");
@@ -56,10 +61,16 @@ class GeminiLlmConnection {
56
61
  });
57
62
  } else {
58
63
  logger.debug("Sending LLM new content", content);
59
- this.geminiSession.sendClientContent({
60
- turns: [content],
61
- turnComplete: true
62
- });
64
+ const isGemini3x = isGemini3xFlashLive(this.modelVersion);
65
+ if (isGemini3x && content.parts.length === 1 && content.parts[0].text) {
66
+ logger.debug("Using sendRealtimeInput for Gemini 3.x text input");
67
+ this.geminiSession.sendRealtimeInput({ text: content.parts[0].text });
68
+ } else {
69
+ this.geminiSession.sendClientContent({
70
+ turns: [content],
71
+ turnComplete: true
72
+ });
73
+ }
63
74
  }
64
75
  }
65
76
  /**
@@ -68,8 +79,36 @@ class GeminiLlmConnection {
68
79
  * @param blob The blob to send to the model.
69
80
  */
70
81
  async sendRealtime(blob) {
82
+ var _a, _b, _c;
71
83
  logger.debug("Sending LLM Blob:", blob);
72
- this.geminiSession.sendRealtimeInput({ media: blob });
84
+ const isGemini3x = isGemini3xFlashLive(this.modelVersion);
85
+ const isNativeAudio = (_a = this.modelVersion) == null ? void 0 : _a.includes("native-audio");
86
+ if (isGemini3x || isNativeAudio) {
87
+ if ((_b = blob.mimeType) == null ? void 0 : _b.startsWith("audio/")) {
88
+ this.geminiSession.sendRealtimeInput({ audio: blob });
89
+ } else if ((_c = blob.mimeType) == null ? void 0 : _c.startsWith("image/")) {
90
+ this.geminiSession.sendRealtimeInput({ video: blob });
91
+ } else {
92
+ logger.warn(
93
+ "Blob not sent. Unknown or empty mime type for sendRealtimeInput:",
94
+ blob.mimeType
95
+ );
96
+ }
97
+ } else {
98
+ this.geminiSession.sendRealtimeInput({ media: blob });
99
+ }
100
+ }
101
+ /**
102
+ * Sends an activity start signal to the model.
103
+ */
104
+ async sendActivityStart() {
105
+ this.geminiSession.sendRealtimeInput({ activityStart: {} });
106
+ }
107
+ /**
108
+ * Sends an activity end signal to the model.
109
+ */
110
+ async sendActivityEnd() {
111
+ this.geminiSession.sendRealtimeInput({ activityEnd: {} });
73
112
  }
74
113
  /**
75
114
  * Builds a full text response.
@@ -78,20 +117,24 @@ class GeminiLlmConnection {
78
117
  * partial.
79
118
  *
80
119
  * @param text The text to be included in the response.
120
+ * @param isThought Whether the text is a thought.
121
+ * @param groundingMetadata The grounding metadata to include.
81
122
  * @returns An LlmResponse containing the full text.
82
123
  */
83
- buildFullTextResponse(text) {
84
- return {
85
- content: {
86
- role: "model",
87
- parts: [{ text }]
88
- }
89
- };
90
- }
91
- // TODO(b/425992518): GenAI SDK inconsistent API, missing methods.
92
- // eslint-disable-next-line require-yield
93
124
  async *receive() {
94
- throw new Error("Not Implemented.");
125
+ if (!this.messageQueue) {
126
+ throw new Error("Message queue is not initialized.");
127
+ }
128
+ const aggregator = new LiveResponseAggregator(this.modelVersion);
129
+ for await (const message of this.messageQueue) {
130
+ logger.debug("Got LLM Live message:", message);
131
+ for (const response of aggregator.processMessage(message)) {
132
+ yield response;
133
+ }
134
+ }
135
+ for (const response of aggregator.close()) {
136
+ yield response;
137
+ }
95
138
  }
96
139
  /**
97
140
  * Closes the llm server connection.
@@ -12,6 +12,7 @@ import {
12
12
  import { getBooleanEnvVar, isBrowser } from "../utils/env_aware_utils.js";
13
13
  import { logger } from "../utils/logger.js";
14
14
  import { GoogleLLMVariant } from "../utils/variant_utils.js";
15
+ import { AsyncQueue } from "../utils/async_queue.js";
15
16
  import { StreamingResponseAggregator } from "../utils/streaming_utils.js";
16
17
  import { BaseLlm } from "./base_llm.js";
17
18
  import { GeminiLlmConnection } from "./gemini_llm_connection.js";
@@ -143,10 +144,19 @@ class Gemini extends BaseLlm {
143
144
  }
144
145
  get liveApiClient() {
145
146
  if (!this._liveApiClient) {
146
- this._liveApiClient = new GoogleGenAI({
147
- apiKey: this.apiKey,
148
- httpOptions: this.getLiveHttpOptions()
149
- });
147
+ if (this.vertexai) {
148
+ this._liveApiClient = new GoogleGenAI({
149
+ vertexai: this.vertexai,
150
+ project: this.project,
151
+ location: this.location || "global",
152
+ httpOptions: this.getLiveHttpOptions()
153
+ });
154
+ } else {
155
+ this._liveApiClient = new GoogleGenAI({
156
+ apiKey: this.apiKey,
157
+ httpOptions: this.getLiveHttpOptions()
158
+ });
159
+ }
150
160
  }
151
161
  return this._liveApiClient;
152
162
  }
@@ -178,16 +188,24 @@ class Gemini extends BaseLlm {
178
188
  };
179
189
  }
180
190
  llmRequest.liveConnectConfig.tools = (_c = llmRequest.config) == null ? void 0 : _c.tools;
191
+ const modelVersion = (_d = llmRequest.model) != null ? _d : this.model;
192
+ const messageQueue = new AsyncQueue();
181
193
  const liveSession = await this.liveApiClient.live.connect({
182
- model: (_d = llmRequest.model) != null ? _d : this.model,
194
+ model: modelVersion,
183
195
  config: llmRequest.liveConnectConfig,
184
196
  callbacks: {
185
- // TODO - b/425992518: GenAI SDK inconsistent API, missing methods.
186
- onmessage: () => {
197
+ onmessage: (message) => {
198
+ messageQueue.push(message);
199
+ },
200
+ onerror: (error) => {
201
+ messageQueue.error(error);
202
+ },
203
+ onclose: () => {
204
+ messageQueue.close();
187
205
  }
188
206
  }
189
207
  });
190
- return new GeminiLlmConnection(liveSession);
208
+ return new GeminiLlmConnection(liveSession, modelVersion, messageQueue);
191
209
  }
192
210
  preprocessRequest(llmRequest) {
193
211
  if (this.apiBackend === GoogleLLMVariant.GEMINI_API) {
@@ -16,6 +16,11 @@ var PolicyOutcome = /* @__PURE__ */ ((PolicyOutcome2) => {
16
16
  return PolicyOutcome2;
17
17
  })(PolicyOutcome || {});
18
18
  class InMemoryPolicyEngine {
19
+ /**
20
+ * Always returns {@link PolicyOutcome.ALLOW} for every tool call.
21
+ *
22
+ * @returns A promise resolving to an ALLOW result.
23
+ */
19
24
  async evaluate() {
20
25
  return Promise.resolve({
21
26
  outcome: "ALLOW" /* ALLOW */,
@@ -24,11 +29,22 @@ class InMemoryPolicyEngine {
24
29
  }
25
30
  }
26
31
  class SecurityPlugin extends BasePlugin {
32
+ /**
33
+ * @param params - Optional configuration. Defaults to {@link InMemoryPolicyEngine}
34
+ * when no policy engine is provided.
35
+ */
27
36
  constructor(params) {
28
37
  var _a;
29
38
  super("security_plugin");
30
39
  this.policyEngine = (_a = params == null ? void 0 : params.policyEngine) != null ? _a : new InMemoryPolicyEngine();
31
40
  }
41
+ /**
42
+ * Intercepts tool calls, evaluating them against the policy engine before
43
+ * execution and handling confirmation flows for calls that require it.
44
+ *
45
+ * @returns A partial or error response object if the call is blocked or
46
+ * awaiting confirmation, or `undefined` to allow execution to proceed.
47
+ */
32
48
  async beforeToolCallback({
33
49
  tool,
34
50
  toolArgs,
@@ -74,6 +74,15 @@ function trimTempDeltaState(event) {
74
74
  event.actions.stateDelta = filteredStateDelta;
75
75
  return event;
76
76
  }
77
+ function trimTempState(state) {
78
+ const filteredState = {};
79
+ for (const [key, value] of Object.entries(state)) {
80
+ if (!key.startsWith(State.TEMP_PREFIX)) {
81
+ filteredState[key] = value;
82
+ }
83
+ }
84
+ return filteredState;
85
+ }
77
86
  function mergeStates(appState = {}, userState = {}, sessionState = {}) {
78
87
  const merged = cloneDeep(sessionState);
79
88
  for (const [k, v] of Object.entries(appState)) {
@@ -87,5 +96,6 @@ function mergeStates(appState = {}, userState = {}, sessionState = {}) {
87
96
  export {
88
97
  BaseSessionService,
89
98
  mergeStates,
90
- trimTempDeltaState
99
+ trimTempDeltaState,
100
+ trimTempState
91
101
  };
@@ -108,7 +108,7 @@ class DatabaseSessionService extends BaseSessionService {
108
108
  appStateDelta[key.replace(State.APP_PREFIX, "")] = value;
109
109
  } else if (key.startsWith(State.USER_PREFIX)) {
110
110
  userStateDelta[key.replace(State.USER_PREFIX, "")] = value;
111
- } else {
111
+ } else if (!key.startsWith(State.TEMP_PREFIX)) {
112
112
  sessionState[key] = value;
113
113
  }
114
114
  }
@@ -357,7 +357,7 @@ class DatabaseSessionService extends BaseSessionService {
357
357
  appDelta[key.replace(State.APP_PREFIX, "")] = value;
358
358
  } else if (key.startsWith(State.USER_PREFIX)) {
359
359
  userDelta[key.replace(State.USER_PREFIX, "")] = value;
360
- } else {
360
+ } else if (!key.startsWith(State.TEMP_PREFIX)) {
361
361
  sessionDelta[key] = value;
362
362
  }
363
363
  }
@@ -22,6 +22,7 @@ import {
22
22
  } from "../../events/event.js";
23
23
  const SCHEMA_VERSION_KEY = "schema_version";
24
24
  const SCHEMA_VERSION_1_JSON = "1";
25
+ const STORAGE_KEY_COLUMN_LENGTH = 191;
25
26
  class CamelCaseToSnakeCaseJsonType extends JsonType {
26
27
  convertToDatabaseValue(value) {
27
28
  return JSON.stringify(transformToSnakeCaseEvent(value));
@@ -50,7 +51,11 @@ let StorageAppState = class {
50
51
  }
51
52
  };
52
53
  __decorateClass([
53
- PrimaryKey({ type: "string", fieldName: "app_name" })
54
+ PrimaryKey({
55
+ type: "string",
56
+ fieldName: "app_name",
57
+ length: STORAGE_KEY_COLUMN_LENGTH
58
+ })
54
59
  ], StorageAppState.prototype, "appName", 2);
55
60
  __decorateClass([
56
61
  Property({ type: "json" })
@@ -73,10 +78,18 @@ let StorageUserState = class {
73
78
  }
74
79
  };
75
80
  __decorateClass([
76
- PrimaryKey({ type: "string", fieldName: "app_name" })
81
+ PrimaryKey({
82
+ type: "string",
83
+ fieldName: "app_name",
84
+ length: STORAGE_KEY_COLUMN_LENGTH
85
+ })
77
86
  ], StorageUserState.prototype, "appName", 2);
78
87
  __decorateClass([
79
- PrimaryKey({ type: "string", fieldName: "user_id" })
88
+ PrimaryKey({
89
+ type: "string",
90
+ fieldName: "user_id",
91
+ length: STORAGE_KEY_COLUMN_LENGTH
92
+ })
80
93
  ], StorageUserState.prototype, "userId", 2);
81
94
  __decorateClass([
82
95
  Property({ type: "json" })
@@ -100,13 +113,21 @@ let StorageSession = class {
100
113
  }
101
114
  };
102
115
  __decorateClass([
103
- PrimaryKey({ type: "string" })
116
+ PrimaryKey({ type: "string", length: STORAGE_KEY_COLUMN_LENGTH })
104
117
  ], StorageSession.prototype, "id", 2);
105
118
  __decorateClass([
106
- PrimaryKey({ type: "string", fieldName: "app_name" })
119
+ PrimaryKey({
120
+ type: "string",
121
+ fieldName: "app_name",
122
+ length: STORAGE_KEY_COLUMN_LENGTH
123
+ })
107
124
  ], StorageSession.prototype, "appName", 2);
108
125
  __decorateClass([
109
- PrimaryKey({ type: "string", fieldName: "user_id" })
126
+ PrimaryKey({
127
+ type: "string",
128
+ fieldName: "user_id",
129
+ length: STORAGE_KEY_COLUMN_LENGTH
130
+ })
110
131
  ], StorageSession.prototype, "userId", 2);
111
132
  __decorateClass([
112
133
  Property({ type: "json" })
@@ -132,16 +153,28 @@ PrimaryKey.name;
132
153
  let StorageEvent = class {
133
154
  };
134
155
  __decorateClass([
135
- PrimaryKey({ type: "string" })
156
+ PrimaryKey({ type: "string", length: STORAGE_KEY_COLUMN_LENGTH })
136
157
  ], StorageEvent.prototype, "id", 2);
137
158
  __decorateClass([
138
- PrimaryKey({ type: "string", fieldName: "app_name" })
159
+ PrimaryKey({
160
+ type: "string",
161
+ fieldName: "app_name",
162
+ length: STORAGE_KEY_COLUMN_LENGTH
163
+ })
139
164
  ], StorageEvent.prototype, "appName", 2);
140
165
  __decorateClass([
141
- PrimaryKey({ type: "string", fieldName: "user_id" })
166
+ PrimaryKey({
167
+ type: "string",
168
+ fieldName: "user_id",
169
+ length: STORAGE_KEY_COLUMN_LENGTH
170
+ })
142
171
  ], StorageEvent.prototype, "userId", 2);
143
172
  __decorateClass([
144
- PrimaryKey({ type: "string", fieldName: "session_id" })
173
+ PrimaryKey({
174
+ type: "string",
175
+ fieldName: "session_id",
176
+ length: STORAGE_KEY_COLUMN_LENGTH
177
+ })
145
178
  ], StorageEvent.prototype, "sessionId", 2);
146
179
  __decorateClass([
147
180
  Property({ type: "string", fieldName: "invocation_id" })
@@ -166,6 +199,7 @@ export {
166
199
  ENTITIES,
167
200
  SCHEMA_VERSION_1_JSON,
168
201
  SCHEMA_VERSION_KEY,
202
+ STORAGE_KEY_COLUMN_LENGTH,
169
203
  StorageAppState,
170
204
  StorageEvent,
171
205
  StorageMetadata,
@@ -10,7 +10,8 @@ import { randomUUID } from "../utils/env_aware_utils.js";
10
10
  import { logger } from "../utils/logger.js";
11
11
  import {
12
12
  BaseSessionService,
13
- mergeStates
13
+ mergeStates,
14
+ trimTempState
14
15
  } from "./base_session_service.js";
15
16
  import { createSession } from "./session.js";
16
17
  import { State } from "./state.js";
@@ -41,11 +42,12 @@ class InMemorySessionService extends BaseSessionService {
41
42
  sessionId
42
43
  }) {
43
44
  var _a;
45
+ const filteredState = state ? trimTempState(state) : void 0;
44
46
  const session = createSession({
45
47
  id: sessionId || randomUUID(),
46
48
  appName,
47
49
  userId,
48
- state,
50
+ state: filteredState,
49
51
  events: [],
50
52
  lastUpdateTime: Date.now()
51
53
  });
@@ -22,7 +22,8 @@ import { logger } from "../utils/logger.js";
22
22
  import { getExpressModeApiKey } from "../utils/vertex_ai_utils.js";
23
23
  import { partialCopy } from "../utils/partial_copy.js";
24
24
  import {
25
- BaseSessionService
25
+ BaseSessionService,
26
+ trimTempState
26
27
  } from "./base_session_service.js";
27
28
  import { createSession } from "./session.js";
28
29
  const DEFAULT_MAX_ATTEMPTS = 30;
@@ -83,11 +84,12 @@ let VertexAiSessionService = class extends BaseSessionService {
83
84
  }) {
84
85
  var _a;
85
86
  const reasoningEngineId = this.getReasoningEngineId(appName);
87
+ const filteredState = state ? trimTempState(state) : void 0;
86
88
  let apiResponse = await this.sessions.createInternal({
87
89
  name: `reasoningEngines/${reasoningEngineId}`,
88
90
  userId,
89
91
  config: {
90
- ...state ? { sessionState: state } : {},
92
+ ...filteredState ? { sessionState: filteredState } : {},
91
93
  ...sessionId ? { sessionId } : {}
92
94
  }
93
95
  });
@@ -0,0 +1,78 @@
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 { experimental } from "../utils/experimental.js";
20
+ import { loadSkillFromZipBuffer } from "./loader.js";
21
+ let GCPSkillRegistry = class {
22
+ constructor(options = {}) {
23
+ this.projectId = options.projectId || process.env.GOOGLE_CLOUD_PROJECT;
24
+ this.location = options.location || process.env.GOOGLE_CLOUD_LOCATION;
25
+ this.client = options.client || new Client({
26
+ project: this.projectId,
27
+ location: this.location
28
+ });
29
+ }
30
+ async getSkill(name) {
31
+ const apiClient = this.client.apiClient;
32
+ const httpResponse = await apiClient.request({
33
+ path: `skills/${name}`,
34
+ httpMethod: "GET",
35
+ httpOptions: { apiVersion: "v1beta1" }
36
+ });
37
+ const response = await httpResponse.json();
38
+ const zippedFilesystem = response.zippedFilesystem || response.zipped_filesystem;
39
+ if (!zippedFilesystem) {
40
+ throw new Error(`Skill '${name}' does not contain zipped filesystem.`);
41
+ }
42
+ const zipBuffer = Buffer.from(zippedFilesystem, "base64");
43
+ return loadSkillFromZipBuffer(zipBuffer);
44
+ }
45
+ async searchSkills(query) {
46
+ const apiClient = this.client.apiClient;
47
+ const trimmedQuery = query.trim();
48
+ const isSearch = trimmedQuery.length > 0;
49
+ const path = isSearch ? `skills:retrieve?query=${encodeURIComponent(trimmedQuery)}` : "skills";
50
+ const httpResponse = await apiClient.request({
51
+ path,
52
+ httpMethod: "GET",
53
+ httpOptions: { apiVersion: "v1beta1" }
54
+ });
55
+ const response = await httpResponse.json();
56
+ const skillsList = isSearch ? response.retrievedSkills || response.retrieved_skills : response.skills;
57
+ const results = [];
58
+ if (skillsList && Array.isArray(skillsList)) {
59
+ for (const s of skillsList) {
60
+ const skillNameStr = s.skillName || s.skill_name || s.name || "";
61
+ const descriptionStr = s.description || "";
62
+ const parts = skillNameStr.split("/");
63
+ const name = skillNameStr ? parts[parts.length - 1] : "";
64
+ results.push({
65
+ name,
66
+ description: descriptionStr
67
+ });
68
+ }
69
+ }
70
+ return results;
71
+ }
72
+ };
73
+ GCPSkillRegistry = __decorateClass([
74
+ experimental
75
+ ], GCPSkillRegistry);
76
+ export {
77
+ GCPSkillRegistry
78
+ };
@@ -5,6 +5,7 @@ const require = topLevelCreateRequire(import.meta.url);
5
5
  * Copyright 2026 Google LLC
6
6
  * SPDX-License-Identifier: Apache-2.0
7
7
  */
8
+ import AdmZip from "adm-zip";
8
9
  import yaml from "js-yaml";
9
10
  import * as fs from "node:fs/promises";
10
11
  import * as path from "node:path";
@@ -236,9 +237,72 @@ async function loadAllSkillsInDir(skillsBasePath) {
236
237
  }
237
238
  return skills;
238
239
  }
240
+ function loadSkillFromZipBuffer(zipBuffer) {
241
+ const zip = new AdmZip(zipBuffer);
242
+ const entries = zip.getEntries();
243
+ let skillMdContent = "";
244
+ for (const entry of entries) {
245
+ if (entry.isDirectory) continue;
246
+ if (entry.entryName.toLowerCase() === "skill.md") {
247
+ skillMdContent = entry.getData().toString("utf-8");
248
+ break;
249
+ }
250
+ }
251
+ if (!skillMdContent) {
252
+ throw new Error("SKILL.md not found in zipped filesystem.");
253
+ }
254
+ const { frontmatter: parsed, body } = parseSkillMdContent(skillMdContent);
255
+ const frontmatter = FrontmatterSchema.parse(parsed);
256
+ const references = {};
257
+ const assets = {};
258
+ const scripts = {};
259
+ function loadZipDir(prefix) {
260
+ const res = {};
261
+ const normPrefix = prefix.endsWith("/") ? prefix : `${prefix}/`;
262
+ for (const entry of entries) {
263
+ if (entry.isDirectory) continue;
264
+ if (entry.entryName.startsWith(normPrefix)) {
265
+ if (entry.entryName.includes("__pycache__")) continue;
266
+ const relativePath = entry.entryName.substring(normPrefix.length);
267
+ if (!relativePath) continue;
268
+ const data = entry.getData();
269
+ try {
270
+ res[relativePath] = data.toString("utf-8");
271
+ } catch (_e) {
272
+ res[relativePath] = data;
273
+ }
274
+ }
275
+ }
276
+ return res;
277
+ }
278
+ const refFiles = loadZipDir("references");
279
+ for (const [key, val] of Object.entries(refFiles)) {
280
+ references[key] = val;
281
+ }
282
+ const assetFiles = loadZipDir("assets");
283
+ for (const [key, val] of Object.entries(assetFiles)) {
284
+ assets[key] = val;
285
+ }
286
+ const rawScripts = loadZipDir("scripts");
287
+ for (const [key, val] of Object.entries(rawScripts)) {
288
+ if (typeof val === "string") {
289
+ scripts[key] = { src: val };
290
+ }
291
+ }
292
+ return {
293
+ frontmatter,
294
+ instructions: body,
295
+ resources: {
296
+ references,
297
+ assets,
298
+ scripts
299
+ }
300
+ };
301
+ }
239
302
  export {
240
303
  loadAllSkillsInDir,
241
304
  loadSkillFromDir,
305
+ loadSkillFromZipBuffer,
242
306
  parseSkillMdContent,
243
307
  validateSkillDir
244
308
  };
@@ -0,0 +1,7 @@
1
+ import {createRequire as topLevelCreateRequire} from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ /**
4
+ * @license
5
+ * Copyright 2026 Google LLC
6
+ * SPDX-License-Identifier: Apache-2.0
7
+ */