@google/adk 1.3.0 → 1.5.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.
- package/dist/cjs/a2a/agent_to_a2a.js +18 -2
- package/dist/cjs/a2a/event_converter_utils.js +8 -4
- package/dist/cjs/a2a/metadata_converter_utils.js +1 -1
- package/dist/cjs/agents/active_streaming_tool.js +6 -1
- package/dist/cjs/agents/base_agent.js +39 -0
- package/dist/cjs/agents/context.js +1 -11
- package/dist/cjs/agents/functions.js +39 -35
- package/dist/cjs/agents/instructions.js +23 -5
- package/dist/cjs/agents/invocation_context.js +2 -5
- package/dist/cjs/agents/llm_agent.js +10 -7
- package/dist/cjs/agents/loop_agent.js +15 -3
- package/dist/cjs/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/cjs/agents/processors/content_processor_utils.js +18 -4
- package/dist/cjs/agents/processors/context_compactor_request_processor.js +4 -2
- package/dist/cjs/agents/processors/interactions_request_processor.js +63 -0
- package/dist/cjs/agents/routed_agent.js +31 -0
- package/dist/cjs/agents/run_config.js +3 -2
- package/dist/cjs/apps/app.js +79 -0
- package/dist/cjs/apps/resumability_config.js +44 -0
- package/dist/cjs/artifacts/file_artifact_service.js +14 -1
- package/dist/cjs/artifacts/gcs_artifact_service.js +57 -15
- package/dist/cjs/artifacts/in_memory_artifact_service.js +12 -1
- package/dist/cjs/artifacts/scoped_artifact_service.js +101 -0
- package/dist/cjs/artifacts/session_artifact_service.js +27 -0
- package/dist/cjs/auth/oauth2/oauth2_discovery.js +17 -5
- package/dist/cjs/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/cjs/common.js +76 -0
- package/dist/cjs/context/agent_controlled_context_compactor.js +109 -0
- package/dist/cjs/context/anchored_context_compactor.js +127 -0
- package/dist/cjs/context/compaction_utils.js +52 -0
- package/dist/cjs/context/token_based_context_compactor.js +52 -33
- package/dist/cjs/context/trajectory_thought_pruning_compactor.js +71 -0
- package/dist/cjs/events/compacted_event.js +9 -3
- package/dist/cjs/events/event.js +52 -0
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- package/dist/cjs/models/google_llm.js +25 -10
- package/dist/cjs/models/interactions_utils.js +732 -0
- package/dist/cjs/plugins/base_plugin.js +1 -0
- package/dist/cjs/plugins/global_instruction_plugin.js +97 -0
- package/dist/cjs/runner/in_memory_runner.js +13 -2
- package/dist/cjs/runner/runner.js +143 -83
- package/dist/cjs/sessions/base_session_service.js +6 -1
- package/dist/cjs/sessions/database_session_service.js +24 -7
- package/dist/cjs/sessions/vertex_ai_session_service.js +19 -4
- package/dist/cjs/skills/loader.js +2 -2
- package/dist/cjs/tools/base_toolset.js +1 -1
- package/dist/cjs/tools/consolidate_context_tool.js +79 -0
- package/dist/cjs/tools/enterprise_web_search_tool.js +81 -0
- package/dist/cjs/tools/example_tool.js +68 -0
- package/dist/cjs/tools/forwarding_artifact_service.js +16 -28
- package/dist/cjs/tools/load_web_page.js +250 -0
- package/dist/cjs/tools/mcp/load_mcp_resource_tool.js +140 -0
- package/dist/cjs/tools/mcp/mcp_toolset.js +63 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -22
- package/dist/cjs/tools/skill/run_skill_inline_script_tool.js +54 -4
- package/dist/cjs/tools/skill/skill_toolset.js +4 -2
- package/dist/cjs/utils/async_hooks_shim.js +52 -0
- package/dist/cjs/utils/branch_trie.js +41 -0
- package/dist/cjs/utils/client_labels.js +41 -3
- package/dist/cjs/utils/env_aware_utils.js +10 -1
- package/dist/cjs/utils/streaming_utils.js +15 -9
- package/dist/cjs/utils/task.js +62 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/agent_to_a2a.js +18 -2
- package/dist/esm/a2a/event_converter_utils.js +8 -4
- package/dist/esm/a2a/metadata_converter_utils.js +1 -1
- package/dist/esm/agents/active_streaming_tool.js +6 -1
- package/dist/esm/agents/base_agent.js +39 -0
- package/dist/esm/agents/context.js +1 -11
- package/dist/esm/agents/functions.js +43 -32
- package/dist/esm/agents/instructions.js +23 -5
- package/dist/esm/agents/invocation_context.js +2 -5
- package/dist/esm/agents/llm_agent.js +12 -9
- package/dist/esm/agents/loop_agent.js +15 -3
- package/dist/esm/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/esm/agents/processors/content_processor_utils.js +16 -3
- package/dist/esm/agents/processors/context_compactor_request_processor.js +4 -2
- package/dist/esm/agents/processors/interactions_request_processor.js +34 -0
- package/dist/esm/agents/routed_agent.js +31 -0
- package/dist/esm/agents/run_config.js +3 -2
- package/dist/esm/apps/app.js +49 -0
- package/dist/esm/apps/resumability_config.js +16 -0
- package/dist/esm/artifacts/file_artifact_service.js +14 -1
- package/dist/esm/artifacts/gcs_artifact_service.js +57 -15
- package/dist/esm/artifacts/in_memory_artifact_service.js +12 -1
- package/dist/esm/artifacts/scoped_artifact_service.js +73 -0
- package/dist/esm/artifacts/session_artifact_service.js +7 -0
- package/dist/esm/auth/oauth2/oauth2_discovery.js +14 -4
- package/dist/esm/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/esm/common.js +67 -3
- package/dist/esm/context/agent_controlled_context_compactor.js +81 -0
- package/dist/esm/context/anchored_context_compactor.js +99 -0
- package/dist/esm/context/compaction_utils.js +27 -0
- package/dist/esm/context/token_based_context_compactor.js +52 -33
- package/dist/esm/context/trajectory_thought_pruning_compactor.js +43 -0
- package/dist/esm/events/compacted_event.js +7 -2
- package/dist/esm/events/event.js +46 -0
- package/dist/esm/index.js +6 -1
- package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- package/dist/esm/models/google_llm.js +23 -9
- package/dist/esm/models/interactions_utils.js +697 -0
- package/dist/esm/plugins/base_plugin.js +1 -0
- package/dist/esm/plugins/global_instruction_plugin.js +69 -0
- package/dist/esm/runner/in_memory_runner.js +13 -2
- package/dist/esm/runner/runner.js +141 -84
- package/dist/esm/sessions/base_session_service.js +6 -1
- package/dist/esm/sessions/database_session_service.js +24 -7
- package/dist/esm/sessions/vertex_ai_session_service.js +17 -3
- package/dist/esm/skills/loader.js +2 -2
- package/dist/esm/tools/base_toolset.js +1 -1
- package/dist/esm/tools/consolidate_context_tool.js +51 -0
- package/dist/esm/tools/enterprise_web_search_tool.js +55 -0
- package/dist/esm/tools/example_tool.js +42 -0
- package/dist/esm/tools/forwarding_artifact_service.js +16 -28
- package/dist/esm/tools/load_web_page.js +221 -0
- package/dist/esm/tools/mcp/load_mcp_resource_tool.js +114 -0
- package/dist/esm/tools/mcp/mcp_toolset.js +63 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -22
- package/dist/esm/tools/skill/run_skill_inline_script_tool.js +53 -4
- package/dist/esm/tools/skill/skill_toolset.js +4 -2
- package/dist/esm/utils/async_hooks_shim.js +24 -0
- package/dist/esm/utils/branch_trie.js +13 -0
- package/dist/esm/utils/client_labels.js +38 -2
- package/dist/esm/utils/env_aware_utils.js +10 -1
- package/dist/esm/utils/streaming_utils.js +11 -5
- package/dist/esm/utils/task.js +34 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent.d.ts +5 -1
- package/dist/types/a2a/agent_to_a2a.d.ts +38 -0
- package/dist/types/agents/active_streaming_tool.d.ts +3 -4
- package/dist/types/agents/base_agent.d.ts +29 -1
- package/dist/types/agents/functions.d.ts +12 -17
- package/dist/types/agents/invocation_context.d.ts +7 -3
- package/dist/types/agents/llm_agent.d.ts +5 -1
- package/dist/types/agents/loop_agent.d.ts +2 -2
- package/dist/types/agents/processors/content_processor_utils.d.ts +8 -0
- package/dist/types/agents/processors/interactions_request_processor.d.ts +17 -0
- package/dist/types/agents/routed_agent.d.ts +24 -1
- package/dist/types/agents/run_config.d.ts +1 -1
- package/dist/types/apps/app.d.ts +52 -0
- package/dist/types/apps/resumability_config.d.ts +27 -0
- package/dist/types/artifacts/base_artifact_service.d.ts +6 -36
- package/dist/types/artifacts/gcs_artifact_service.d.ts +2 -1
- package/dist/types/artifacts/scoped_artifact_service.d.ts +25 -0
- package/dist/types/artifacts/session_artifact_service.d.ts +25 -0
- package/dist/types/auth/oauth2/oauth2_discovery.d.ts +11 -0
- package/dist/types/common.d.ts +29 -5
- package/dist/types/context/agent_controlled_context_compactor.d.ts +24 -0
- package/dist/types/context/anchored_context_compactor.d.ts +35 -0
- package/dist/types/context/base_context_compactor.d.ts +3 -0
- package/dist/types/context/compaction_utils.d.ts +15 -0
- package/dist/types/context/token_based_context_compactor.d.ts +6 -1
- package/dist/types/context/trajectory_thought_pruning_compactor.d.ts +27 -0
- package/dist/types/events/compacted_event.d.ts +10 -0
- package/dist/types/events/event.d.ts +21 -0
- package/dist/types/index.d.ts +3 -2
- package/dist/types/models/google_llm.d.ts +15 -1
- package/dist/types/models/interactions_utils.d.ts +92 -0
- package/dist/types/models/llm_request.d.ts +4 -0
- package/dist/types/models/llm_response.d.ts +4 -0
- package/dist/types/plugins/base_plugin.d.ts +2 -1
- package/dist/types/plugins/global_instruction_plugin.d.ts +38 -0
- package/dist/types/runner/in_memory_runner.d.ts +7 -1
- package/dist/types/runner/runner.d.ts +44 -10
- package/dist/types/sessions/base_session_service.d.ts +3 -16
- package/dist/types/sessions/session.d.ts +11 -0
- package/dist/types/sessions/vertex_ai_session_service.d.ts +9 -1
- package/dist/types/tools/consolidate_context_tool.d.ts +19 -0
- package/dist/types/tools/enterprise_web_search_tool.d.ts +26 -0
- package/dist/types/tools/example_tool.d.ts +21 -0
- package/dist/types/tools/forwarding_artifact_service.d.ts +3 -2
- package/dist/types/tools/load_web_page.d.ts +33 -0
- package/dist/types/tools/mcp/load_mcp_resource_tool.d.ts +26 -0
- package/dist/types/tools/mcp/mcp_toolset.d.ts +27 -0
- package/dist/types/tools/skill/run_skill_inline_script_tool.d.ts +25 -0
- package/dist/types/tools/skill/skill_toolset.d.ts +9 -0
- package/dist/types/utils/async_hooks_shim.d.ts +10 -0
- package/dist/types/utils/branch_trie.d.ts +14 -0
- package/dist/types/utils/client_labels.d.ts +10 -0
- package/dist/types/utils/env_aware_utils.d.ts +3 -3
- package/dist/types/utils/task.d.ts +24 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/agent_to_a2a.js +18 -2
- package/dist/web/a2a/event_converter_utils.js +8 -4
- package/dist/web/a2a/metadata_converter_utils.js +1 -1
- package/dist/web/agents/active_streaming_tool.js +6 -1
- package/dist/web/agents/base_agent.js +39 -0
- package/dist/web/agents/context.js +1 -11
- package/dist/web/agents/functions.js +43 -32
- package/dist/web/agents/instructions.js +23 -5
- package/dist/web/agents/invocation_context.js +2 -5
- package/dist/web/agents/llm_agent.js +12 -9
- package/dist/web/agents/loop_agent.js +27 -3
- package/dist/web/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/web/agents/processors/content_processor_utils.js +16 -3
- package/dist/web/agents/processors/context_compactor_request_processor.js +4 -2
- package/dist/web/agents/processors/interactions_request_processor.js +52 -0
- package/dist/web/agents/routed_agent.js +31 -0
- package/dist/web/agents/run_config.js +8 -3
- package/dist/web/apps/app.js +49 -0
- package/dist/web/apps/resumability_config.js +31 -0
- package/dist/web/artifacts/file_artifact_service.js +14 -1
- package/dist/web/artifacts/gcs_artifact_service.js +55 -15
- package/dist/web/artifacts/in_memory_artifact_service.js +12 -1
- package/dist/web/artifacts/scoped_artifact_service.js +86 -0
- package/dist/web/artifacts/session_artifact_service.js +7 -0
- package/dist/web/auth/oauth2/oauth2_discovery.js +14 -4
- package/dist/web/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/web/common.js +67 -3
- package/dist/web/context/agent_controlled_context_compactor.js +81 -0
- package/dist/web/context/anchored_context_compactor.js +117 -0
- package/dist/web/context/compaction_utils.js +27 -0
- package/dist/web/context/token_based_context_compactor.js +52 -33
- package/dist/web/context/trajectory_thought_pruning_compactor.js +43 -0
- package/dist/web/events/compacted_event.js +7 -2
- package/dist/web/events/event.js +44 -0
- package/dist/web/index.js +6 -1
- package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- package/dist/web/models/google_llm.js +54 -9
- package/dist/web/models/interactions_utils.js +728 -0
- package/dist/web/plugins/base_plugin.js +1 -0
- package/dist/web/plugins/global_instruction_plugin.js +67 -0
- package/dist/web/runner/in_memory_runner.js +13 -2
- package/dist/web/runner/runner.js +157 -84
- package/dist/web/sessions/base_session_service.js +6 -1
- package/dist/web/sessions/database_session_service.js +24 -7
- package/dist/web/sessions/vertex_ai_session_service.js +17 -3
- package/dist/web/skills/loader.js +2 -2
- package/dist/web/tools/base_toolset.js +1 -1
- package/dist/web/tools/consolidate_context_tool.js +51 -0
- package/dist/web/tools/enterprise_web_search_tool.js +55 -0
- package/dist/web/tools/example_tool.js +42 -0
- package/dist/web/tools/forwarding_artifact_service.js +16 -28
- package/dist/web/tools/load_web_page.js +221 -0
- package/dist/web/tools/mcp/load_mcp_resource_tool.js +107 -0
- package/dist/web/tools/mcp/mcp_toolset.js +63 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -22
- package/dist/web/tools/skill/run_skill_inline_script_tool.js +51 -4
- package/dist/web/tools/skill/skill_toolset.js +4 -2
- package/dist/web/utils/async_hooks_shim.js +24 -0
- package/dist/web/utils/branch_trie.js +13 -0
- package/dist/web/utils/client_labels.js +38 -2
- package/dist/web/utils/env_aware_utils.js +10 -1
- package/dist/web/utils/streaming_utils.js +11 -5
- package/dist/web/utils/task.js +34 -0
- package/dist/web/version.js +1 -1
- package/package.json +2 -2
package/dist/web/events/event.js
CHANGED
|
@@ -24,6 +24,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
24
24
|
* Copyright 2026 Google LLC
|
|
25
25
|
* SPDX-License-Identifier: Apache-2.0
|
|
26
26
|
*/
|
|
27
|
+
import { randomUUID } from "../utils/env_aware_utils.js";
|
|
27
28
|
import { toCamelCase, toSnakeCase } from "../utils/object_notation_utils.js";
|
|
28
29
|
import { createEventActions } from "./event_actions.js";
|
|
29
30
|
function createEvent(params = {}) {
|
|
@@ -54,6 +55,17 @@ function getFunctionCalls(event) {
|
|
|
54
55
|
}
|
|
55
56
|
return funcCalls;
|
|
56
57
|
}
|
|
58
|
+
const AF_FUNCTION_CALL_ID_PREFIX = "adk-";
|
|
59
|
+
function generateClientFunctionCallId() {
|
|
60
|
+
return "".concat(AF_FUNCTION_CALL_ID_PREFIX).concat(randomUUID());
|
|
61
|
+
}
|
|
62
|
+
function populateClientFunctionCallId(modelResponseEvent) {
|
|
63
|
+
for (const functionCall of getFunctionCalls(modelResponseEvent)) {
|
|
64
|
+
if (!functionCall.id) {
|
|
65
|
+
functionCall.id = generateClientFunctionCallId();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
57
69
|
function getFunctionResponses(event) {
|
|
58
70
|
const funcResponses = [];
|
|
59
71
|
if (event.content && event.content.parts) {
|
|
@@ -83,6 +95,32 @@ function stringifyContent(event) {
|
|
|
83
95
|
return (_a2 = part.text) != null ? _a2 : "";
|
|
84
96
|
}).join("");
|
|
85
97
|
}
|
|
98
|
+
function getEventTokens(event) {
|
|
99
|
+
var _a;
|
|
100
|
+
if (((_a = event.usageMetadata) == null ? void 0 : _a.promptTokenCount) !== void 0) {
|
|
101
|
+
return event.usageMetadata.promptTokenCount;
|
|
102
|
+
}
|
|
103
|
+
const contentStr = stringifyContent(event);
|
|
104
|
+
return Math.ceil(contentStr.length / 4);
|
|
105
|
+
}
|
|
106
|
+
function hasThoughts(event) {
|
|
107
|
+
var _a, _b;
|
|
108
|
+
return !!((_b = (_a = event.content) == null ? void 0 : _a.parts) == null ? void 0 : _b.some((part) => part.thought === true));
|
|
109
|
+
}
|
|
110
|
+
function pruneThoughts(event) {
|
|
111
|
+
var _a;
|
|
112
|
+
if (!((_a = event.content) == null ? void 0 : _a.parts)) {
|
|
113
|
+
return event;
|
|
114
|
+
}
|
|
115
|
+
const prunedParts = event.content.parts.filter(
|
|
116
|
+
(part) => part.thought !== true
|
|
117
|
+
);
|
|
118
|
+
return __spreadProps(__spreadValues({}, event), {
|
|
119
|
+
content: __spreadProps(__spreadValues({}, event.content), {
|
|
120
|
+
parts: prunedParts
|
|
121
|
+
})
|
|
122
|
+
});
|
|
123
|
+
}
|
|
86
124
|
const ASCII_LETTERS_AND_NUMBERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
87
125
|
function createNewEventId() {
|
|
88
126
|
let id = "";
|
|
@@ -118,12 +156,18 @@ function transformToSnakeCaseEvent(event) {
|
|
|
118
156
|
return toSnakeCase(event, PRESERVE_KEYS_CAMEL_CASE);
|
|
119
157
|
}
|
|
120
158
|
export {
|
|
159
|
+
AF_FUNCTION_CALL_ID_PREFIX,
|
|
121
160
|
createEvent,
|
|
122
161
|
createNewEventId,
|
|
162
|
+
generateClientFunctionCallId,
|
|
163
|
+
getEventTokens,
|
|
123
164
|
getFunctionCalls,
|
|
124
165
|
getFunctionResponses,
|
|
166
|
+
hasThoughts,
|
|
125
167
|
hasTrailingCodeExecutionResult,
|
|
126
168
|
isFinalResponse,
|
|
169
|
+
populateClientFunctionCallId,
|
|
170
|
+
pruneThoughts,
|
|
127
171
|
stringifyContent,
|
|
128
172
|
transformToCamelCaseEvent,
|
|
129
173
|
transformToSnakeCaseEvent
|
package/dist/web/index.js
CHANGED
|
@@ -29,11 +29,15 @@ import {
|
|
|
29
29
|
loadSkillFromDir,
|
|
30
30
|
validateSkillDir
|
|
31
31
|
} from "./skills/loader.js";
|
|
32
|
-
import {
|
|
32
|
+
import {
|
|
33
|
+
RunSkillInlineScriptErrorCode,
|
|
34
|
+
RunSkillInlineScriptTool
|
|
35
|
+
} from "./tools/skill/run_skill_inline_script_tool.js";
|
|
33
36
|
import { RunSkillScriptTool } from "./tools/skill/run_skill_script_tool.js";
|
|
34
37
|
export * from "./integrations/agent_registry/agent_registry.js";
|
|
35
38
|
export * from "./telemetry/google_cloud.js";
|
|
36
39
|
export * from "./telemetry/setup.js";
|
|
40
|
+
export * from "./tools/mcp/load_mcp_resource_tool.js";
|
|
37
41
|
export * from "./tools/mcp/mcp_session_manager.js";
|
|
38
42
|
export * from "./tools/mcp/mcp_tool.js";
|
|
39
43
|
export * from "./tools/mcp/mcp_toolset.js";
|
|
@@ -47,6 +51,7 @@ export {
|
|
|
47
51
|
GcsArtifactService,
|
|
48
52
|
InvocationContext,
|
|
49
53
|
RemoteA2AAgent,
|
|
54
|
+
RunSkillInlineScriptErrorCode,
|
|
50
55
|
RunSkillInlineScriptTool,
|
|
51
56
|
RunSkillScriptTool,
|
|
52
57
|
UnsafeLocalCodeExecutor,
|
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
MCPSessionManager
|
|
30
30
|
} from "../../tools/mcp/mcp_session_manager.js";
|
|
31
31
|
import { MCPTool } from "../../tools/mcp/mcp_tool.js";
|
|
32
|
+
import { logger } from "../../utils/logger.js";
|
|
32
33
|
import { GCP_MCP_SERVER_DESTINATION_ID } from "./types.js";
|
|
33
34
|
class AgentRegistrySingleMCPToolset extends BaseToolset {
|
|
34
35
|
/**
|
|
@@ -78,7 +79,14 @@ class AgentRegistrySingleMCPToolset extends BaseToolset {
|
|
|
78
79
|
});
|
|
79
80
|
const sessionManager = new MCPSessionManager(connectionParamsCopy);
|
|
80
81
|
const session = await sessionManager.createSession();
|
|
81
|
-
|
|
82
|
+
let listResult;
|
|
83
|
+
try {
|
|
84
|
+
listResult = await session.listTools();
|
|
85
|
+
} finally {
|
|
86
|
+
await sessionManager.closeSession(session).catch((e) => {
|
|
87
|
+
logger.warn("Failed to close MCP discovery session", e);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
82
90
|
const tools = listResult.tools.map((tool) => {
|
|
83
91
|
const prefixedName = this.prefix ? "".concat(this.prefix, "_").concat(tool.name) : tool.name;
|
|
84
92
|
const mcpTool = new MCPTool(
|
|
@@ -5,6 +5,9 @@ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
7
|
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
8
|
+
var __typeError = (msg) => {
|
|
9
|
+
throw TypeError(msg);
|
|
10
|
+
};
|
|
8
11
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
12
|
var __spreadValues = (a, b) => {
|
|
10
13
|
for (var prop in b || (b = {}))
|
|
@@ -32,12 +35,41 @@ var __asyncGenerator = (__this, __arguments, generator) => {
|
|
|
32
35
|
}, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
|
|
33
36
|
return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
|
|
34
37
|
};
|
|
38
|
+
var __yieldStar = (value) => {
|
|
39
|
+
var obj = value[__knownSymbol("asyncIterator")], isAwait = false, method, it = {};
|
|
40
|
+
if (obj == null) {
|
|
41
|
+
obj = value[__knownSymbol("iterator")]();
|
|
42
|
+
method = (k) => it[k] = (x) => obj[k](x);
|
|
43
|
+
} else {
|
|
44
|
+
obj = obj.call(value);
|
|
45
|
+
method = (k) => it[k] = (v) => {
|
|
46
|
+
if (isAwait) {
|
|
47
|
+
isAwait = false;
|
|
48
|
+
if (k === "throw") throw v;
|
|
49
|
+
return v;
|
|
50
|
+
}
|
|
51
|
+
isAwait = true;
|
|
52
|
+
return {
|
|
53
|
+
done: false,
|
|
54
|
+
value: new __await(new Promise((resolve) => {
|
|
55
|
+
var x = obj[k](v);
|
|
56
|
+
if (!(x instanceof Object)) __typeError("Object expected");
|
|
57
|
+
resolve(x);
|
|
58
|
+
}), 1)
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return it[__knownSymbol("iterator")] = () => it, method("next"), "throw" in obj ? method("throw") : it.throw = (x) => {
|
|
63
|
+
throw x;
|
|
64
|
+
}, "return" in obj && method("return"), it;
|
|
65
|
+
};
|
|
35
66
|
var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")]) ? it.call(obj) : (obj = obj[__knownSymbol("iterator")](), it = {}, method = (key, fn) => (fn = obj[key]) && (it[key] = (arg) => new Promise((yes, no, done) => (arg = fn.call(obj, arg), done = arg.done, Promise.resolve(arg.value).then((value) => yes({ value, done }), no)))), method("next"), method("return"), it);
|
|
36
67
|
/**
|
|
37
68
|
* @license
|
|
38
69
|
* Copyright 2025 Google LLC
|
|
39
70
|
* SPDX-License-Identifier: Apache-2.0
|
|
40
71
|
*/
|
|
72
|
+
var _a, _b;
|
|
41
73
|
import {
|
|
42
74
|
createPartFromText,
|
|
43
75
|
GoogleGenAI
|
|
@@ -49,8 +81,13 @@ import { AsyncQueue } from "../utils/async_queue.js";
|
|
|
49
81
|
import { StreamingResponseAggregator } from "../utils/streaming_utils.js";
|
|
50
82
|
import { BaseLlm } from "./base_llm.js";
|
|
51
83
|
import { GeminiLlmConnection } from "./gemini_llm_connection.js";
|
|
84
|
+
import { generateContentViaInteractions } from "./interactions_utils.js";
|
|
52
85
|
import { createLlmResponse } from "./llm_response.js";
|
|
53
|
-
|
|
86
|
+
const GEMINI_MODEL_SYMBOL = Symbol.for("google.adk.geminiModel");
|
|
87
|
+
function isGemini(obj) {
|
|
88
|
+
return typeof obj === "object" && obj !== null && GEMINI_MODEL_SYMBOL in obj && obj[GEMINI_MODEL_SYMBOL] === true;
|
|
89
|
+
}
|
|
90
|
+
class Gemini extends (_b = BaseLlm, _a = GEMINI_MODEL_SYMBOL, _b) {
|
|
54
91
|
/**
|
|
55
92
|
* @param params The parameters for creating a Gemini instance.
|
|
56
93
|
*/
|
|
@@ -60,12 +97,14 @@ class Gemini extends BaseLlm {
|
|
|
60
97
|
vertexai,
|
|
61
98
|
project,
|
|
62
99
|
location,
|
|
63
|
-
headers
|
|
100
|
+
headers,
|
|
101
|
+
useInteractionsApi
|
|
64
102
|
}) {
|
|
65
103
|
if (!model) {
|
|
66
104
|
model = "gemini-2.5-flash";
|
|
67
105
|
}
|
|
68
106
|
super({ model });
|
|
107
|
+
this[_a] = true;
|
|
69
108
|
const params = geminiInitParams({
|
|
70
109
|
model,
|
|
71
110
|
vertexai,
|
|
@@ -83,6 +122,7 @@ class Gemini extends BaseLlm {
|
|
|
83
122
|
this.apiKey = params.apiKey;
|
|
84
123
|
this.headers = headers;
|
|
85
124
|
this.vertexai = !!params.vertexai;
|
|
125
|
+
this.useInteractionsApi = !!useInteractionsApi;
|
|
86
126
|
}
|
|
87
127
|
/**
|
|
88
128
|
* Sends a request to the Gemini model.
|
|
@@ -93,11 +133,15 @@ class Gemini extends BaseLlm {
|
|
|
93
133
|
*/
|
|
94
134
|
generateContentAsync(llmRequest, stream = false, abortSignal) {
|
|
95
135
|
return __asyncGenerator(this, null, function* () {
|
|
96
|
-
var
|
|
136
|
+
var _a2, _b2, _c;
|
|
137
|
+
if (this.useInteractionsApi) {
|
|
138
|
+
yield* __yieldStar(generateContentViaInteractions(this.apiClient, llmRequest, stream));
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
97
141
|
this.preprocessRequest(llmRequest);
|
|
98
142
|
this.maybeAppendUserContent(llmRequest);
|
|
99
143
|
logger.info(
|
|
100
|
-
"Sending out request, model: ".concat((
|
|
144
|
+
"Sending out request, model: ".concat((_a2 = llmRequest.model) != null ? _a2 : this.model, ", backend: ").concat(this.apiBackend, ", stream: ").concat(stream)
|
|
101
145
|
);
|
|
102
146
|
if (!llmRequest.config) {
|
|
103
147
|
llmRequest.config = {};
|
|
@@ -110,7 +154,7 @@ class Gemini extends BaseLlm {
|
|
|
110
154
|
}
|
|
111
155
|
if (stream) {
|
|
112
156
|
const streamResult = yield new __await(this.apiClient.models.generateContentStream({
|
|
113
|
-
model: (
|
|
157
|
+
model: (_b2 = llmRequest.model) != null ? _b2 : this.model,
|
|
114
158
|
contents: llmRequest.contents,
|
|
115
159
|
config: llmRequest.config
|
|
116
160
|
}));
|
|
@@ -223,8 +267,8 @@ class Gemini extends BaseLlm {
|
|
|
223
267
|
* @returns BaseLlmConnection, the connection to the Gemini model.
|
|
224
268
|
*/
|
|
225
269
|
async connect(llmRequest) {
|
|
226
|
-
var
|
|
227
|
-
if ((
|
|
270
|
+
var _a2, _b2, _c, _d;
|
|
271
|
+
if ((_a2 = llmRequest.liveConnectConfig) == null ? void 0 : _a2.httpOptions) {
|
|
228
272
|
if (!llmRequest.liveConnectConfig.httpOptions.headers) {
|
|
229
273
|
llmRequest.liveConnectConfig.httpOptions.headers = {};
|
|
230
274
|
}
|
|
@@ -234,7 +278,7 @@ class Gemini extends BaseLlm {
|
|
|
234
278
|
);
|
|
235
279
|
llmRequest.liveConnectConfig.httpOptions.apiVersion = this.liveApiVersion;
|
|
236
280
|
}
|
|
237
|
-
if ((
|
|
281
|
+
if ((_b2 = llmRequest.config) == null ? void 0 : _b2.systemInstruction) {
|
|
238
282
|
llmRequest.liveConnectConfig.systemInstruction = {
|
|
239
283
|
role: "system",
|
|
240
284
|
// TODO - b/425992518: validate type casting works well.
|
|
@@ -335,5 +379,6 @@ function geminiInitParams({
|
|
|
335
379
|
}
|
|
336
380
|
export {
|
|
337
381
|
Gemini,
|
|
338
|
-
geminiInitParams
|
|
382
|
+
geminiInitParams,
|
|
383
|
+
isGemini
|
|
339
384
|
};
|