@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
|
@@ -21,6 +21,15 @@ import { CodeExecutionLanguage } from "../../code_executors/code_execution_utils
|
|
|
21
21
|
import { experimental } from "../../utils/experimental.js";
|
|
22
22
|
import { materializeFiles } from "../../utils/file_utils.js";
|
|
23
23
|
import { BaseTool } from "../base_tool.js";
|
|
24
|
+
var RunSkillInlineScriptErrorCode = /* @__PURE__ */ ((RunSkillInlineScriptErrorCode2) => {
|
|
25
|
+
RunSkillInlineScriptErrorCode2["MISSING_SCRIPT_CONTENT"] = "MISSING_SCRIPT_CONTENT";
|
|
26
|
+
RunSkillInlineScriptErrorCode2["MISSING_LANGUAGE"] = "MISSING_LANGUAGE";
|
|
27
|
+
RunSkillInlineScriptErrorCode2["NO_CODE_EXECUTOR"] = "NO_CODE_EXECUTOR";
|
|
28
|
+
RunSkillInlineScriptErrorCode2["EXECUTION_ERROR"] = "EXECUTION_ERROR";
|
|
29
|
+
RunSkillInlineScriptErrorCode2["CONFIRMATION_REJECTED"] = "CONFIRMATION_REJECTED";
|
|
30
|
+
return RunSkillInlineScriptErrorCode2;
|
|
31
|
+
})(RunSkillInlineScriptErrorCode || {});
|
|
32
|
+
const REQUIRE_CONFIRMATION_MESSAGE = "This tool call needs external confirmation before completion.";
|
|
24
33
|
let RunSkillInlineScriptTool = class extends BaseTool {
|
|
25
34
|
constructor(toolset) {
|
|
26
35
|
super({
|
|
@@ -70,13 +79,13 @@ let RunSkillInlineScriptTool = class extends BaseTool {
|
|
|
70
79
|
if (!inlineScriptContent) {
|
|
71
80
|
return {
|
|
72
81
|
error: "Script content is required.",
|
|
73
|
-
errorCode: "MISSING_SCRIPT_CONTENT"
|
|
82
|
+
errorCode: "MISSING_SCRIPT_CONTENT" /* MISSING_SCRIPT_CONTENT */
|
|
74
83
|
};
|
|
75
84
|
}
|
|
76
85
|
if (!language) {
|
|
77
86
|
return {
|
|
78
87
|
error: "Language is required.",
|
|
79
|
-
errorCode: "MISSING_LANGUAGE"
|
|
88
|
+
errorCode: "MISSING_LANGUAGE" /* MISSING_LANGUAGE */
|
|
80
89
|
};
|
|
81
90
|
}
|
|
82
91
|
let codeExecutor = (_a = this.toolset) == null ? void 0 : _a.codeExecutor;
|
|
@@ -89,9 +98,17 @@ let RunSkillInlineScriptTool = class extends BaseTool {
|
|
|
89
98
|
if (!codeExecutor) {
|
|
90
99
|
return {
|
|
91
100
|
error: "No code executor configured.",
|
|
92
|
-
errorCode: "NO_CODE_EXECUTOR"
|
|
101
|
+
errorCode: "NO_CODE_EXECUTOR" /* NO_CODE_EXECUTOR */
|
|
93
102
|
};
|
|
94
103
|
}
|
|
104
|
+
const confirmationResult = this.enforceConfirmation(
|
|
105
|
+
toolContext,
|
|
106
|
+
inlineScriptContent,
|
|
107
|
+
language
|
|
108
|
+
);
|
|
109
|
+
if (confirmationResult) {
|
|
110
|
+
return confirmationResult;
|
|
111
|
+
}
|
|
95
112
|
try {
|
|
96
113
|
const result = await codeExecutor.executeCode({
|
|
97
114
|
invocationContext: toolContext.invocationContext,
|
|
@@ -107,14 +124,44 @@ let RunSkillInlineScriptTool = class extends BaseTool {
|
|
|
107
124
|
} catch (e) {
|
|
108
125
|
return {
|
|
109
126
|
error: "Failed to execute inline script: ".concat(e.message),
|
|
110
|
-
errorCode: "EXECUTION_ERROR"
|
|
127
|
+
errorCode: "EXECUTION_ERROR" /* EXECUTION_ERROR */
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Enforces a human-in-the-loop confirmation gate before executing an inline
|
|
133
|
+
* script, using the repo's standard tool-confirmation mechanism.
|
|
134
|
+
*
|
|
135
|
+
* - When no confirmation has been provided yet, a confirmation is requested
|
|
136
|
+
* (surfacing the language and script that would run) and an intermediate
|
|
137
|
+
* result is returned so the tool call pauses until the client responds.
|
|
138
|
+
* - When a confirmation exists but was not confirmed, a rejection error is
|
|
139
|
+
* returned and execution is refused.
|
|
140
|
+
* - When the confirmation is confirmed, `undefined` is returned to allow the
|
|
141
|
+
* caller to proceed with execution.
|
|
142
|
+
*/
|
|
143
|
+
enforceConfirmation(toolContext, scriptContent, language) {
|
|
144
|
+
const confirmation = toolContext.toolConfirmation;
|
|
145
|
+
if (!confirmation) {
|
|
146
|
+
toolContext.requestConfirmation({
|
|
147
|
+
hint: "Confirmation is required before executing an inline skill script. " + "The agent requested to run the following ".concat(language, " script in the ") + "code executor. Only approve if you trust its contents:\n\n" + scriptContent,
|
|
148
|
+
payload: { language, scriptContent }
|
|
149
|
+
});
|
|
150
|
+
return { partial: REQUIRE_CONFIRMATION_MESSAGE };
|
|
151
|
+
}
|
|
152
|
+
if (!confirmation.confirmed) {
|
|
153
|
+
return {
|
|
154
|
+
error: "Inline script execution was not confirmed and was rejected.",
|
|
155
|
+
errorCode: "CONFIRMATION_REJECTED" /* CONFIRMATION_REJECTED */
|
|
111
156
|
};
|
|
112
157
|
}
|
|
158
|
+
return void 0;
|
|
113
159
|
}
|
|
114
160
|
};
|
|
115
161
|
RunSkillInlineScriptTool = __decorateClass([
|
|
116
162
|
experimental
|
|
117
163
|
], RunSkillInlineScriptTool);
|
|
118
164
|
export {
|
|
165
|
+
RunSkillInlineScriptErrorCode,
|
|
119
166
|
RunSkillInlineScriptTool
|
|
120
167
|
};
|
|
@@ -41,9 +41,11 @@ let SkillToolset = class extends BaseToolset {
|
|
|
41
41
|
new ListSkillsTool(this),
|
|
42
42
|
new LoadSkillTool(this),
|
|
43
43
|
new LoadSkillResourceTool(this),
|
|
44
|
-
new RunSkillScriptTool(this)
|
|
45
|
-
new RunSkillInlineScriptTool(this)
|
|
44
|
+
new RunSkillScriptTool(this)
|
|
46
45
|
];
|
|
46
|
+
if (options.allowInlineScripts) {
|
|
47
|
+
this.tools.push(new RunSkillInlineScriptTool(this));
|
|
48
|
+
}
|
|
47
49
|
if (this.registry) {
|
|
48
50
|
this.tools.push(new SearchSkillsTool(this));
|
|
49
51
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
*/
|
|
8
|
+
class AsyncLocalStorage {
|
|
9
|
+
run(store, callback) {
|
|
10
|
+
const previous = this.store;
|
|
11
|
+
this.store = store;
|
|
12
|
+
try {
|
|
13
|
+
return callback();
|
|
14
|
+
} finally {
|
|
15
|
+
this.store = previous;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
getStore() {
|
|
19
|
+
return this.store;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
AsyncLocalStorage
|
|
24
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
*/
|
|
8
|
+
function isSegmentPrefix(currentBranch, targetBranch) {
|
|
9
|
+
return !targetBranch || targetBranch === currentBranch || !!currentBranch && currentBranch.startsWith("".concat(targetBranch, "."));
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
isSegmentPrefix
|
|
13
|
+
};
|
|
@@ -5,24 +5,60 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
5
5
|
* Copyright 2025 Google LLC
|
|
6
6
|
* SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
*/
|
|
8
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
8
9
|
import { version } from "../version.js";
|
|
9
10
|
import { isBrowser } from "./env_aware_utils.js";
|
|
10
11
|
const ADK_LABEL = "google-adk";
|
|
11
12
|
const LANGUAGE_LABEL = "gl-typescript";
|
|
12
13
|
const AGENT_ENGINE_TELEMETRY_TAG = "remote_reasoning_engine";
|
|
13
14
|
const AGENT_ENGINE_TELEMETRY_ENV_VARIABLE_NAME = "GOOGLE_CLOUD_AGENT_ENGINE_ID";
|
|
15
|
+
const clientLabelLocalStorage = new AsyncLocalStorage();
|
|
16
|
+
const USER_AGENT_PATTERNS = [
|
|
17
|
+
["Edge", /(?:Edg|Edge|EdgA)\/([0-9.]+)/i],
|
|
18
|
+
["Firefox", /(?:Firefox|FxiOS)\/([0-9.]+)/i],
|
|
19
|
+
["Chrome", /(?:Chrome|CriOS)\/([0-9.]+)/i],
|
|
20
|
+
["Safari", /Version\/([0-9.]+).*Safari/i]
|
|
21
|
+
];
|
|
22
|
+
function parseUserAgent(userAgent) {
|
|
23
|
+
if (!userAgent) {
|
|
24
|
+
return "Browser";
|
|
25
|
+
}
|
|
26
|
+
for (const [name, regex] of USER_AGENT_PATTERNS) {
|
|
27
|
+
const match = userAgent.match(regex);
|
|
28
|
+
if (match) {
|
|
29
|
+
return "".concat(name, "/").concat(match[1]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return "Browser";
|
|
33
|
+
}
|
|
14
34
|
function _getDefaultLabels() {
|
|
15
35
|
let frameworkLabel = "".concat(ADK_LABEL, "/").concat(version);
|
|
16
36
|
if (!isBrowser() && process.env[AGENT_ENGINE_TELEMETRY_ENV_VARIABLE_NAME]) {
|
|
17
37
|
frameworkLabel = "".concat(frameworkLabel, "+").concat(AGENT_ENGINE_TELEMETRY_TAG);
|
|
18
38
|
}
|
|
19
|
-
const
|
|
39
|
+
const languageLabelDetail = isBrowser() ? (
|
|
40
|
+
// eslint-disable-next-line no-undef
|
|
41
|
+
parseUserAgent(window.navigator.userAgent)
|
|
42
|
+
) : process.version;
|
|
43
|
+
const languageLabel = "".concat(LANGUAGE_LABEL, "/").concat(languageLabelDetail);
|
|
20
44
|
return [frameworkLabel, languageLabel];
|
|
21
45
|
}
|
|
46
|
+
function runWithClientLabel(clientLabel, callback) {
|
|
47
|
+
if (typeof clientLabel !== "string" || clientLabel.trim() === "") {
|
|
48
|
+
throw new Error("Client label must be a non-empty string.");
|
|
49
|
+
}
|
|
50
|
+
return clientLabelLocalStorage.run(clientLabel, callback);
|
|
51
|
+
}
|
|
22
52
|
function getClientLabels() {
|
|
23
53
|
const labels = _getDefaultLabels();
|
|
54
|
+
const contextLabel = clientLabelLocalStorage.getStore();
|
|
55
|
+
if (contextLabel) {
|
|
56
|
+
labels.push(contextLabel);
|
|
57
|
+
}
|
|
24
58
|
return labels;
|
|
25
59
|
}
|
|
26
60
|
export {
|
|
27
|
-
getClientLabels
|
|
61
|
+
getClientLabels,
|
|
62
|
+
parseUserAgent,
|
|
63
|
+
runWithClientLabel
|
|
28
64
|
};
|
|
@@ -29,7 +29,16 @@ function randomUUID() {
|
|
|
29
29
|
}
|
|
30
30
|
function base64Encode(data) {
|
|
31
31
|
if (isBrowser()) {
|
|
32
|
-
|
|
32
|
+
let strData = "";
|
|
33
|
+
if (typeof data === "string") {
|
|
34
|
+
strData = data;
|
|
35
|
+
} else {
|
|
36
|
+
const len = data.byteLength;
|
|
37
|
+
for (let i = 0; i < len; i++) {
|
|
38
|
+
strData += String.fromCharCode(data[i]);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return window.btoa(strData);
|
|
33
42
|
}
|
|
34
43
|
return Buffer.from(data).toString("base64");
|
|
35
44
|
}
|
|
@@ -75,7 +75,7 @@ import {
|
|
|
75
75
|
FinishReason
|
|
76
76
|
} from "@google/genai";
|
|
77
77
|
import { JSONPath } from "jsonpath-plus";
|
|
78
|
-
import { generateClientFunctionCallId } from "../
|
|
78
|
+
import { generateClientFunctionCallId } from "../events/event.js";
|
|
79
79
|
import { FeatureName, isFeatureEnabled } from "../features/feature_registry.js";
|
|
80
80
|
import { createLlmResponse } from "../models/llm_response.js";
|
|
81
81
|
const UNSAFE_PROPERTY_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
@@ -401,10 +401,16 @@ class StreamingResponseAggregator {
|
|
|
401
401
|
const candidate = (_b = (_a = this.response) == null ? void 0 : _a.candidates) == null ? void 0 : _b[0];
|
|
402
402
|
const finishReason = (_c = this.finishReason) != null ? _c : candidate == null ? void 0 : candidate.finishReason;
|
|
403
403
|
return {
|
|
404
|
-
content
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
404
|
+
// Only attach a model `content` when there are actual parts to emit. When
|
|
405
|
+
// the turn accumulated no parts (e.g. a function call that was already
|
|
406
|
+
// flushed, followed by a trailing STOP chunk that carries only usage
|
|
407
|
+
// metadata) we still surface that trailing metadata, but MUST NOT emit
|
|
408
|
+
// `content: { parts: [] }`. An empty-parts model turn corrupts the session
|
|
409
|
+
// history: on the next request the Vertex AI backend rejects the whole
|
|
410
|
+
// call with HTTP 400 "Unable to submit request because it must include at
|
|
411
|
+
// least one parts field", which breaks multi-turn tool-using sessions
|
|
412
|
+
// right after the first tool call (google/adk-js#21, #22).
|
|
413
|
+
content: finalParts ? { role: "model", parts: finalParts } : void 0,
|
|
408
414
|
groundingMetadata: this.groundingMetadata,
|
|
409
415
|
citationMetadata: this.citationMetadata,
|
|
410
416
|
errorCode: finishReason === FinishReason.STOP ? void 0 : finishReason,
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
*/
|
|
8
|
+
class Task {
|
|
9
|
+
constructor(executable) {
|
|
10
|
+
this.executable = executable;
|
|
11
|
+
this.isDone = false;
|
|
12
|
+
this.abortController = new AbortController();
|
|
13
|
+
const markDone = () => {
|
|
14
|
+
this.isDone = true;
|
|
15
|
+
};
|
|
16
|
+
this.promise = executable(this.abortController.signal);
|
|
17
|
+
this.promise.then(markDone).catch(markDone);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Cancels the task execution.
|
|
21
|
+
*/
|
|
22
|
+
cancel() {
|
|
23
|
+
this.abortController.abort();
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Returns true if the task has completed (either resolved or rejected).
|
|
27
|
+
*/
|
|
28
|
+
done() {
|
|
29
|
+
return this.isDone;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
Task
|
|
34
|
+
};
|
package/dist/web/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@google/adk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Google ADK JS",
|
|
5
5
|
"author": "Google",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@google-cloud/opentelemetry-cloud-trace-exporter": "^3.0.0",
|
|
46
46
|
"@google-cloud/storage": "^7.17.1",
|
|
47
47
|
"@google-cloud/vertexai": "^1.12.0",
|
|
48
|
-
"@google/genai": "^
|
|
48
|
+
"@google/genai": "^2.9.0",
|
|
49
49
|
"@mikro-orm/core": "^6.6.10",
|
|
50
50
|
"@mikro-orm/reflection": "^6.6.6",
|
|
51
51
|
"@modelcontextprotocol/sdk": "^1.26.0",
|