@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
|
@@ -75,6 +75,69 @@ class MCPToolset extends import_base_toolset.BaseToolset {
|
|
|
75
75
|
);
|
|
76
76
|
return tools;
|
|
77
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Lists the names of the resources advertised by the MCP server.
|
|
80
|
+
*
|
|
81
|
+
* @return The resource names available on the server.
|
|
82
|
+
*/
|
|
83
|
+
async listResources() {
|
|
84
|
+
const session = await this.mcpSessionManager.createSession();
|
|
85
|
+
try {
|
|
86
|
+
const result = await session.listResources();
|
|
87
|
+
return result.resources.map((resource) => resource.name);
|
|
88
|
+
} finally {
|
|
89
|
+
await this.mcpSessionManager.closeSession(session);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Returns metadata for the resource whose name matches `name`.
|
|
94
|
+
*
|
|
95
|
+
* @param name The advertised name of the resource.
|
|
96
|
+
* @return The matching MCP `Resource`.
|
|
97
|
+
* @throws If no resource with the given name is advertised by the server.
|
|
98
|
+
*/
|
|
99
|
+
async getResourceInfo(name) {
|
|
100
|
+
const session = await this.mcpSessionManager.createSession();
|
|
101
|
+
let result;
|
|
102
|
+
try {
|
|
103
|
+
result = await session.listResources();
|
|
104
|
+
} finally {
|
|
105
|
+
await this.mcpSessionManager.closeSession(session);
|
|
106
|
+
}
|
|
107
|
+
const resource = result.resources.find(
|
|
108
|
+
(candidate) => candidate.name === name
|
|
109
|
+
);
|
|
110
|
+
if (!resource) {
|
|
111
|
+
throw new Error(`Resource with name '${name}' not found.`);
|
|
112
|
+
}
|
|
113
|
+
return resource;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Reads the contents of the named resource from the MCP server.
|
|
117
|
+
*
|
|
118
|
+
* The resource name is resolved to a URI via {@link getResourceInfo} before
|
|
119
|
+
* reading. Binary contents are returned base64-encoded, exactly as provided
|
|
120
|
+
* by the server (never decoded and re-encoded).
|
|
121
|
+
*
|
|
122
|
+
* @param name The advertised name of the resource to read.
|
|
123
|
+
* @return The resource contents (text and/or base64-encoded binary).
|
|
124
|
+
* @throws If the resource is unknown or has no URI.
|
|
125
|
+
*/
|
|
126
|
+
async readResource(name) {
|
|
127
|
+
const resourceInfo = await this.getResourceInfo(name);
|
|
128
|
+
if (!resourceInfo.uri) {
|
|
129
|
+
throw new Error(`Resource '${name}' has no URI.`);
|
|
130
|
+
}
|
|
131
|
+
const session = await this.mcpSessionManager.createSession();
|
|
132
|
+
try {
|
|
133
|
+
const result = await session.readResource({
|
|
134
|
+
uri: resourceInfo.uri
|
|
135
|
+
});
|
|
136
|
+
return result.contents;
|
|
137
|
+
} finally {
|
|
138
|
+
await this.mcpSessionManager.closeSession(session);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
78
141
|
async close() {
|
|
79
142
|
const sessions = this.mcpSessionManager.getActiveSessions();
|
|
80
143
|
await Promise.allSettled(
|
|
@@ -52,20 +52,10 @@ class ToolContextCredentialStore {
|
|
|
52
52
|
}
|
|
53
53
|
getCredential(authScheme) {
|
|
54
54
|
const key = this.getCredentialKey(authScheme);
|
|
55
|
-
|
|
56
|
-
if (state) {
|
|
57
|
-
const serialized = state[key];
|
|
58
|
-
if (serialized) {
|
|
59
|
-
return serialized;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return void 0;
|
|
55
|
+
return this.context.state.get(key);
|
|
63
56
|
}
|
|
64
57
|
storeCredential(key, credential) {
|
|
65
|
-
|
|
66
|
-
if (state) {
|
|
67
|
-
state[key] = credential;
|
|
68
|
-
}
|
|
58
|
+
this.context.state.set(key, credential);
|
|
69
59
|
}
|
|
70
60
|
}
|
|
71
61
|
let ToolAuthHandler = class {
|
|
@@ -97,19 +87,22 @@ let ToolAuthHandler = class {
|
|
|
97
87
|
rawAuthCredential: this.authCredential,
|
|
98
88
|
credentialKey: this.credentialKey || "default_openapi_key"
|
|
99
89
|
};
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
90
|
+
const authResponseCredential = this.context.getAuthResponse(authConfig);
|
|
91
|
+
const credential = authResponseCredential != null ? authResponseCredential : this.authCredential;
|
|
92
|
+
if (!credential) {
|
|
93
|
+
this.context.requestCredential(authConfig);
|
|
94
|
+
return { state: "pending" };
|
|
95
|
+
}
|
|
96
|
+
const exchanger = new import_auto_auth_credential_exchanger.AutoAuthCredentialExchanger();
|
|
97
|
+
const result = await exchanger.exchange({
|
|
98
|
+
authScheme: this.authScheme,
|
|
99
|
+
authCredential: credential
|
|
100
|
+
});
|
|
101
|
+
if (authResponseCredential || result.wasExchanged) {
|
|
107
102
|
const key = store.getCredentialKey(this.authScheme);
|
|
108
103
|
store.storeCredential(key, result.credential);
|
|
109
|
-
return { state: "done", authCredential: result.credential };
|
|
110
104
|
}
|
|
111
|
-
|
|
112
|
-
return { state: "pending" };
|
|
105
|
+
return { state: "done", authCredential: result.credential };
|
|
113
106
|
}
|
|
114
107
|
};
|
|
115
108
|
__decorateClass([
|
|
@@ -32,6 +32,7 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
32
32
|
};
|
|
33
33
|
var run_skill_inline_script_tool_exports = {};
|
|
34
34
|
__export(run_skill_inline_script_tool_exports, {
|
|
35
|
+
RunSkillInlineScriptErrorCode: () => RunSkillInlineScriptErrorCode,
|
|
35
36
|
RunSkillInlineScriptTool: () => RunSkillInlineScriptTool
|
|
36
37
|
});
|
|
37
38
|
module.exports = __toCommonJS(run_skill_inline_script_tool_exports);
|
|
@@ -46,6 +47,15 @@ var import_base_tool = require("../base_tool.js");
|
|
|
46
47
|
* Copyright 2026 Google LLC
|
|
47
48
|
* SPDX-License-Identifier: Apache-2.0
|
|
48
49
|
*/
|
|
50
|
+
var RunSkillInlineScriptErrorCode = /* @__PURE__ */ ((RunSkillInlineScriptErrorCode2) => {
|
|
51
|
+
RunSkillInlineScriptErrorCode2["MISSING_SCRIPT_CONTENT"] = "MISSING_SCRIPT_CONTENT";
|
|
52
|
+
RunSkillInlineScriptErrorCode2["MISSING_LANGUAGE"] = "MISSING_LANGUAGE";
|
|
53
|
+
RunSkillInlineScriptErrorCode2["NO_CODE_EXECUTOR"] = "NO_CODE_EXECUTOR";
|
|
54
|
+
RunSkillInlineScriptErrorCode2["EXECUTION_ERROR"] = "EXECUTION_ERROR";
|
|
55
|
+
RunSkillInlineScriptErrorCode2["CONFIRMATION_REJECTED"] = "CONFIRMATION_REJECTED";
|
|
56
|
+
return RunSkillInlineScriptErrorCode2;
|
|
57
|
+
})(RunSkillInlineScriptErrorCode || {});
|
|
58
|
+
const REQUIRE_CONFIRMATION_MESSAGE = "This tool call needs external confirmation before completion.";
|
|
49
59
|
let RunSkillInlineScriptTool = class extends import_base_tool.BaseTool {
|
|
50
60
|
constructor(toolset) {
|
|
51
61
|
super({
|
|
@@ -95,13 +105,13 @@ let RunSkillInlineScriptTool = class extends import_base_tool.BaseTool {
|
|
|
95
105
|
if (!inlineScriptContent) {
|
|
96
106
|
return {
|
|
97
107
|
error: "Script content is required.",
|
|
98
|
-
errorCode: "MISSING_SCRIPT_CONTENT"
|
|
108
|
+
errorCode: "MISSING_SCRIPT_CONTENT" /* MISSING_SCRIPT_CONTENT */
|
|
99
109
|
};
|
|
100
110
|
}
|
|
101
111
|
if (!language) {
|
|
102
112
|
return {
|
|
103
113
|
error: "Language is required.",
|
|
104
|
-
errorCode: "MISSING_LANGUAGE"
|
|
114
|
+
errorCode: "MISSING_LANGUAGE" /* MISSING_LANGUAGE */
|
|
105
115
|
};
|
|
106
116
|
}
|
|
107
117
|
let codeExecutor = (_a = this.toolset) == null ? void 0 : _a.codeExecutor;
|
|
@@ -114,9 +124,17 @@ let RunSkillInlineScriptTool = class extends import_base_tool.BaseTool {
|
|
|
114
124
|
if (!codeExecutor) {
|
|
115
125
|
return {
|
|
116
126
|
error: "No code executor configured.",
|
|
117
|
-
errorCode: "NO_CODE_EXECUTOR"
|
|
127
|
+
errorCode: "NO_CODE_EXECUTOR" /* NO_CODE_EXECUTOR */
|
|
118
128
|
};
|
|
119
129
|
}
|
|
130
|
+
const confirmationResult = this.enforceConfirmation(
|
|
131
|
+
toolContext,
|
|
132
|
+
inlineScriptContent,
|
|
133
|
+
language
|
|
134
|
+
);
|
|
135
|
+
if (confirmationResult) {
|
|
136
|
+
return confirmationResult;
|
|
137
|
+
}
|
|
120
138
|
try {
|
|
121
139
|
const result = await codeExecutor.executeCode({
|
|
122
140
|
invocationContext: toolContext.invocationContext,
|
|
@@ -132,9 +150,40 @@ let RunSkillInlineScriptTool = class extends import_base_tool.BaseTool {
|
|
|
132
150
|
} catch (e) {
|
|
133
151
|
return {
|
|
134
152
|
error: `Failed to execute inline script: ${e.message}`,
|
|
135
|
-
errorCode: "EXECUTION_ERROR"
|
|
153
|
+
errorCode: "EXECUTION_ERROR" /* EXECUTION_ERROR */
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Enforces a human-in-the-loop confirmation gate before executing an inline
|
|
159
|
+
* script, using the repo's standard tool-confirmation mechanism.
|
|
160
|
+
*
|
|
161
|
+
* - When no confirmation has been provided yet, a confirmation is requested
|
|
162
|
+
* (surfacing the language and script that would run) and an intermediate
|
|
163
|
+
* result is returned so the tool call pauses until the client responds.
|
|
164
|
+
* - When a confirmation exists but was not confirmed, a rejection error is
|
|
165
|
+
* returned and execution is refused.
|
|
166
|
+
* - When the confirmation is confirmed, `undefined` is returned to allow the
|
|
167
|
+
* caller to proceed with execution.
|
|
168
|
+
*/
|
|
169
|
+
enforceConfirmation(toolContext, scriptContent, language) {
|
|
170
|
+
const confirmation = toolContext.toolConfirmation;
|
|
171
|
+
if (!confirmation) {
|
|
172
|
+
toolContext.requestConfirmation({
|
|
173
|
+
hint: `Confirmation is required before executing an inline skill script. The agent requested to run the following ${language} script in the code executor. Only approve if you trust its contents:
|
|
174
|
+
|
|
175
|
+
` + scriptContent,
|
|
176
|
+
payload: { language, scriptContent }
|
|
177
|
+
});
|
|
178
|
+
return { partial: REQUIRE_CONFIRMATION_MESSAGE };
|
|
179
|
+
}
|
|
180
|
+
if (!confirmation.confirmed) {
|
|
181
|
+
return {
|
|
182
|
+
error: "Inline script execution was not confirmed and was rejected.",
|
|
183
|
+
errorCode: "CONFIRMATION_REJECTED" /* CONFIRMATION_REJECTED */
|
|
136
184
|
};
|
|
137
185
|
}
|
|
186
|
+
return void 0;
|
|
138
187
|
}
|
|
139
188
|
};
|
|
140
189
|
RunSkillInlineScriptTool = __decorateClass([
|
|
@@ -142,5 +191,6 @@ RunSkillInlineScriptTool = __decorateClass([
|
|
|
142
191
|
], RunSkillInlineScriptTool);
|
|
143
192
|
// Annotate the CommonJS export names for ESM import in node:
|
|
144
193
|
0 && (module.exports = {
|
|
194
|
+
RunSkillInlineScriptErrorCode,
|
|
145
195
|
RunSkillInlineScriptTool
|
|
146
196
|
});
|
|
@@ -80,9 +80,11 @@ let SkillToolset = class extends import_base_toolset.BaseToolset {
|
|
|
80
80
|
new import_list_skills_tool.ListSkillsTool(this),
|
|
81
81
|
new import_load_skill_tool.LoadSkillTool(this),
|
|
82
82
|
new import_load_skill_resource_tool.LoadSkillResourceTool(this),
|
|
83
|
-
new import_run_skill_script_tool.RunSkillScriptTool(this)
|
|
84
|
-
new import_run_skill_inline_script_tool.RunSkillInlineScriptTool(this)
|
|
83
|
+
new import_run_skill_script_tool.RunSkillScriptTool(this)
|
|
85
84
|
];
|
|
85
|
+
if (options.allowInlineScripts) {
|
|
86
|
+
this.tools.push(new import_run_skill_inline_script_tool.RunSkillInlineScriptTool(this));
|
|
87
|
+
}
|
|
86
88
|
if (this.registry) {
|
|
87
89
|
this.tools.push(new import_search_skills_tool.SearchSkillsTool(this));
|
|
88
90
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var async_hooks_shim_exports = {};
|
|
26
|
+
__export(async_hooks_shim_exports, {
|
|
27
|
+
AsyncLocalStorage: () => AsyncLocalStorage
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(async_hooks_shim_exports);
|
|
30
|
+
/**
|
|
31
|
+
* @license
|
|
32
|
+
* Copyright 2026 Google LLC
|
|
33
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
34
|
+
*/
|
|
35
|
+
class AsyncLocalStorage {
|
|
36
|
+
run(store, callback) {
|
|
37
|
+
const previous = this.store;
|
|
38
|
+
this.store = store;
|
|
39
|
+
try {
|
|
40
|
+
return callback();
|
|
41
|
+
} finally {
|
|
42
|
+
this.store = previous;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
getStore() {
|
|
46
|
+
return this.store;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
AsyncLocalStorage
|
|
52
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var branch_trie_exports = {};
|
|
26
|
+
__export(branch_trie_exports, {
|
|
27
|
+
isSegmentPrefix: () => isSegmentPrefix
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(branch_trie_exports);
|
|
30
|
+
/**
|
|
31
|
+
* @license
|
|
32
|
+
* Copyright 2026 Google LLC
|
|
33
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
34
|
+
*/
|
|
35
|
+
function isSegmentPrefix(currentBranch, targetBranch) {
|
|
36
|
+
return !targetBranch || targetBranch === currentBranch || !!currentBranch && currentBranch.startsWith(`${targetBranch}.`);
|
|
37
|
+
}
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
isSegmentPrefix
|
|
41
|
+
});
|
|
@@ -24,9 +24,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var client_labels_exports = {};
|
|
26
26
|
__export(client_labels_exports, {
|
|
27
|
-
getClientLabels: () => getClientLabels
|
|
27
|
+
getClientLabels: () => getClientLabels,
|
|
28
|
+
parseUserAgent: () => parseUserAgent,
|
|
29
|
+
runWithClientLabel: () => runWithClientLabel
|
|
28
30
|
});
|
|
29
31
|
module.exports = __toCommonJS(client_labels_exports);
|
|
32
|
+
var import_node_async_hooks = require("node:async_hooks");
|
|
30
33
|
var import_version = require("../version.js");
|
|
31
34
|
var import_env_aware_utils = require("./env_aware_utils.js");
|
|
32
35
|
/**
|
|
@@ -38,19 +41,54 @@ const ADK_LABEL = "google-adk";
|
|
|
38
41
|
const LANGUAGE_LABEL = "gl-typescript";
|
|
39
42
|
const AGENT_ENGINE_TELEMETRY_TAG = "remote_reasoning_engine";
|
|
40
43
|
const AGENT_ENGINE_TELEMETRY_ENV_VARIABLE_NAME = "GOOGLE_CLOUD_AGENT_ENGINE_ID";
|
|
44
|
+
const clientLabelLocalStorage = new import_node_async_hooks.AsyncLocalStorage();
|
|
45
|
+
const USER_AGENT_PATTERNS = [
|
|
46
|
+
["Edge", /(?:Edg|Edge|EdgA)\/([0-9.]+)/i],
|
|
47
|
+
["Firefox", /(?:Firefox|FxiOS)\/([0-9.]+)/i],
|
|
48
|
+
["Chrome", /(?:Chrome|CriOS)\/([0-9.]+)/i],
|
|
49
|
+
["Safari", /Version\/([0-9.]+).*Safari/i]
|
|
50
|
+
];
|
|
51
|
+
function parseUserAgent(userAgent) {
|
|
52
|
+
if (!userAgent) {
|
|
53
|
+
return "Browser";
|
|
54
|
+
}
|
|
55
|
+
for (const [name, regex] of USER_AGENT_PATTERNS) {
|
|
56
|
+
const match = userAgent.match(regex);
|
|
57
|
+
if (match) {
|
|
58
|
+
return `${name}/${match[1]}`;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return "Browser";
|
|
62
|
+
}
|
|
41
63
|
function _getDefaultLabels() {
|
|
42
64
|
let frameworkLabel = `${ADK_LABEL}/${import_version.version}`;
|
|
43
65
|
if (!(0, import_env_aware_utils.isBrowser)() && process.env[AGENT_ENGINE_TELEMETRY_ENV_VARIABLE_NAME]) {
|
|
44
66
|
frameworkLabel = `${frameworkLabel}+${AGENT_ENGINE_TELEMETRY_TAG}`;
|
|
45
67
|
}
|
|
46
|
-
const
|
|
68
|
+
const languageLabelDetail = (0, import_env_aware_utils.isBrowser)() ? (
|
|
69
|
+
// eslint-disable-next-line no-undef
|
|
70
|
+
parseUserAgent(window.navigator.userAgent)
|
|
71
|
+
) : process.version;
|
|
72
|
+
const languageLabel = `${LANGUAGE_LABEL}/${languageLabelDetail}`;
|
|
47
73
|
return [frameworkLabel, languageLabel];
|
|
48
74
|
}
|
|
75
|
+
function runWithClientLabel(clientLabel, callback) {
|
|
76
|
+
if (typeof clientLabel !== "string" || clientLabel.trim() === "") {
|
|
77
|
+
throw new Error("Client label must be a non-empty string.");
|
|
78
|
+
}
|
|
79
|
+
return clientLabelLocalStorage.run(clientLabel, callback);
|
|
80
|
+
}
|
|
49
81
|
function getClientLabels() {
|
|
50
82
|
const labels = _getDefaultLabels();
|
|
83
|
+
const contextLabel = clientLabelLocalStorage.getStore();
|
|
84
|
+
if (contextLabel) {
|
|
85
|
+
labels.push(contextLabel);
|
|
86
|
+
}
|
|
51
87
|
return labels;
|
|
52
88
|
}
|
|
53
89
|
// Annotate the CommonJS export names for ESM import in node:
|
|
54
90
|
0 && (module.exports = {
|
|
55
|
-
getClientLabels
|
|
91
|
+
getClientLabels,
|
|
92
|
+
parseUserAgent,
|
|
93
|
+
runWithClientLabel
|
|
56
94
|
});
|
|
@@ -61,7 +61,16 @@ function randomUUID() {
|
|
|
61
61
|
}
|
|
62
62
|
function base64Encode(data) {
|
|
63
63
|
if (isBrowser()) {
|
|
64
|
-
|
|
64
|
+
let strData = "";
|
|
65
|
+
if (typeof data === "string") {
|
|
66
|
+
strData = data;
|
|
67
|
+
} else {
|
|
68
|
+
const len = data.byteLength;
|
|
69
|
+
for (let i = 0; i < len; i++) {
|
|
70
|
+
strData += String.fromCharCode(data[i]);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return window.btoa(strData);
|
|
65
74
|
}
|
|
66
75
|
return Buffer.from(data).toString("base64");
|
|
67
76
|
}
|
|
@@ -30,7 +30,7 @@ __export(streaming_utils_exports, {
|
|
|
30
30
|
module.exports = __toCommonJS(streaming_utils_exports);
|
|
31
31
|
var import_genai = require("@google/genai");
|
|
32
32
|
var import_jsonpath_plus = require("jsonpath-plus");
|
|
33
|
-
var
|
|
33
|
+
var import_event = require("../events/event.js");
|
|
34
34
|
var import_feature_registry = require("../features/feature_registry.js");
|
|
35
35
|
var import_llm_response = require("../models/llm_response.js");
|
|
36
36
|
/**
|
|
@@ -127,7 +127,7 @@ class ProgressiveStrategy {
|
|
|
127
127
|
functionCall: {
|
|
128
128
|
name: this.currentFcName,
|
|
129
129
|
args: JSON.parse(JSON.stringify(this.currentFcArgs)),
|
|
130
|
-
id: (_a = this.currentFcId) != null ? _a : (0,
|
|
130
|
+
id: (_a = this.currentFcId) != null ? _a : (0, import_event.generateClientFunctionCallId)()
|
|
131
131
|
}
|
|
132
132
|
};
|
|
133
133
|
if (this.currentThoughtSignature) {
|
|
@@ -172,7 +172,7 @@ class ProgressiveStrategy {
|
|
|
172
172
|
}
|
|
173
173
|
if (fc.partialArgs || fc.willContinue) {
|
|
174
174
|
if (!fc.id && !this.currentFcId) {
|
|
175
|
-
fc.id = (0,
|
|
175
|
+
fc.id = (0, import_event.generateClientFunctionCallId)();
|
|
176
176
|
}
|
|
177
177
|
if (part.thoughtSignature && !this.currentThoughtSignature) {
|
|
178
178
|
this.currentThoughtSignature = part.thoughtSignature;
|
|
@@ -181,7 +181,7 @@ class ProgressiveStrategy {
|
|
|
181
181
|
} else {
|
|
182
182
|
if (fc.name) {
|
|
183
183
|
if (!fc.id) {
|
|
184
|
-
fc.id = (0,
|
|
184
|
+
fc.id = (0, import_event.generateClientFunctionCallId)();
|
|
185
185
|
}
|
|
186
186
|
this.flushTextBufferToSequence();
|
|
187
187
|
this.partsSequence.push(part);
|
|
@@ -243,7 +243,7 @@ class NonProgressiveStrategy {
|
|
|
243
243
|
continue;
|
|
244
244
|
}
|
|
245
245
|
if (part.functionCall && !part.functionCall.id) {
|
|
246
|
-
part.functionCall.id = (0,
|
|
246
|
+
part.functionCall.id = (0, import_event.generateClientFunctionCallId)();
|
|
247
247
|
}
|
|
248
248
|
nonTextParts.push(part);
|
|
249
249
|
}
|
|
@@ -356,10 +356,16 @@ class StreamingResponseAggregator {
|
|
|
356
356
|
const candidate = (_b = (_a = this.response) == null ? void 0 : _a.candidates) == null ? void 0 : _b[0];
|
|
357
357
|
const finishReason = (_c = this.finishReason) != null ? _c : candidate == null ? void 0 : candidate.finishReason;
|
|
358
358
|
return {
|
|
359
|
-
content
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
359
|
+
// Only attach a model `content` when there are actual parts to emit. When
|
|
360
|
+
// the turn accumulated no parts (e.g. a function call that was already
|
|
361
|
+
// flushed, followed by a trailing STOP chunk that carries only usage
|
|
362
|
+
// metadata) we still surface that trailing metadata, but MUST NOT emit
|
|
363
|
+
// `content: { parts: [] }`. An empty-parts model turn corrupts the session
|
|
364
|
+
// history: on the next request the Vertex AI backend rejects the whole
|
|
365
|
+
// call with HTTP 400 "Unable to submit request because it must include at
|
|
366
|
+
// least one parts field", which breaks multi-turn tool-using sessions
|
|
367
|
+
// right after the first tool call (google/adk-js#21, #22).
|
|
368
|
+
content: finalParts ? { role: "model", parts: finalParts } : void 0,
|
|
363
369
|
groundingMetadata: this.groundingMetadata,
|
|
364
370
|
citationMetadata: this.citationMetadata,
|
|
365
371
|
errorCode: finishReason === import_genai.FinishReason.STOP ? void 0 : finishReason,
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var task_exports = {};
|
|
26
|
+
__export(task_exports, {
|
|
27
|
+
Task: () => Task
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(task_exports);
|
|
30
|
+
/**
|
|
31
|
+
* @license
|
|
32
|
+
* Copyright 2026 Google LLC
|
|
33
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
34
|
+
*/
|
|
35
|
+
class Task {
|
|
36
|
+
constructor(executable) {
|
|
37
|
+
this.executable = executable;
|
|
38
|
+
this.isDone = false;
|
|
39
|
+
this.abortController = new AbortController();
|
|
40
|
+
const markDone = () => {
|
|
41
|
+
this.isDone = true;
|
|
42
|
+
};
|
|
43
|
+
this.promise = executable(this.abortController.signal);
|
|
44
|
+
this.promise.then(markDone).catch(markDone);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Cancels the task execution.
|
|
48
|
+
*/
|
|
49
|
+
cancel() {
|
|
50
|
+
this.abortController.abort();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Returns true if the task has completed (either resolved or rejected).
|
|
54
|
+
*/
|
|
55
|
+
done() {
|
|
56
|
+
return this.isDone;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
60
|
+
0 && (module.exports = {
|
|
61
|
+
Task
|
|
62
|
+
});
|
package/dist/cjs/version.js
CHANGED
|
@@ -32,7 +32,7 @@ module.exports = __toCommonJS(version_exports);
|
|
|
32
32
|
* Copyright 2025 Google LLC
|
|
33
33
|
* SPDX-License-Identifier: Apache-2.0
|
|
34
34
|
*/
|
|
35
|
-
const version = "1.
|
|
35
|
+
const version = "1.5.0";
|
|
36
36
|
// Annotate the CommonJS export names for ESM import in node:
|
|
37
37
|
0 && (module.exports = {
|
|
38
38
|
version
|
|
@@ -16,10 +16,26 @@ import {
|
|
|
16
16
|
import express from "express";
|
|
17
17
|
import { StreamingMode } from "../agents/run_config.js";
|
|
18
18
|
import { InMemorySessionService } from "../sessions/in_memory_session_service.js";
|
|
19
|
+
import { logger } from "../utils/logger.js";
|
|
19
20
|
import { getA2AAgentCard, resolveAgentCard } from "./agent_card.js";
|
|
20
21
|
import { A2AAgentExecutor } from "./agent_executor.js";
|
|
22
|
+
function resolveA2aUserBuilder(options) {
|
|
23
|
+
if (options.authentication) {
|
|
24
|
+
return options.authentication;
|
|
25
|
+
}
|
|
26
|
+
if (options.allowUnauthenticated === true) {
|
|
27
|
+
logger.warn(
|
|
28
|
+
"SECURITY WARNING: Mounting the A2A server WITHOUT authentication because `allowUnauthenticated: true` was set. The agent and all of its tools are exposed to any network-reachable caller, which can invoke them with arbitrary input and read the output. Do NOT use this outside of local, trusted development."
|
|
29
|
+
);
|
|
30
|
+
return UserBuilder.noAuthentication;
|
|
31
|
+
}
|
|
32
|
+
throw new Error(
|
|
33
|
+
"toA2a: refusing to mount the A2A server without authentication. The A2A surface lets any network-reachable caller invoke this agent and its tools with arbitrary input and read the output, so it must be authenticated. Provide `authentication` (a UserBuilder that validates the request, e.g. a bearer token or OIDC credential) or, only for local/trusted development, explicitly set `allowUnauthenticated: true`."
|
|
34
|
+
);
|
|
35
|
+
}
|
|
21
36
|
async function toA2a(agent, options = {}) {
|
|
22
37
|
var _a, _b, _c, _d;
|
|
38
|
+
const userBuilder = resolveA2aUserBuilder(options);
|
|
23
39
|
const host = (_a = options.host) != null ? _a : "localhost";
|
|
24
40
|
const port = (_b = options.port) != null ? _b : 8e3;
|
|
25
41
|
const protocol = (_c = options.protocol) != null ? _c : "http";
|
|
@@ -65,14 +81,14 @@ async function toA2a(agent, options = {}) {
|
|
|
65
81
|
`${basePath}/rest`,
|
|
66
82
|
restHandler({
|
|
67
83
|
requestHandler,
|
|
68
|
-
userBuilder
|
|
84
|
+
userBuilder
|
|
69
85
|
})
|
|
70
86
|
);
|
|
71
87
|
app.use(
|
|
72
88
|
`${basePath}/jsonrpc`,
|
|
73
89
|
jsonRpcHandler({
|
|
74
90
|
requestHandler,
|
|
75
|
-
userBuilder
|
|
91
|
+
userBuilder
|
|
76
92
|
})
|
|
77
93
|
);
|
|
78
94
|
return app;
|
|
@@ -58,13 +58,14 @@ function toAdkEvent(event, invocationId, agentName) {
|
|
|
58
58
|
}
|
|
59
59
|
return void 0;
|
|
60
60
|
}
|
|
61
|
-
function messageToAdkEvent(msg, invocationId, agentName
|
|
61
|
+
function messageToAdkEvent(msg, invocationId, agentName) {
|
|
62
62
|
const parts = toGenAIParts(msg.parts);
|
|
63
|
+
const content = parts.length === 0 ? void 0 : msg.role === MessageRole.USER ? createUserContent(parts) : createModelContent(parts);
|
|
63
64
|
return {
|
|
64
|
-
...createAdkEventFromMetadata(
|
|
65
|
+
...createAdkEventFromMetadata(msg),
|
|
65
66
|
invocationId,
|
|
66
67
|
author: msg.role === MessageRole.USER ? MessageRole.USER : agentName,
|
|
67
|
-
content
|
|
68
|
+
content,
|
|
68
69
|
turnComplete: true,
|
|
69
70
|
partial: false
|
|
70
71
|
};
|
|
@@ -110,6 +111,9 @@ function taskStatusUpdateToAdkEvent(a2aEvent, invocationId, agentName) {
|
|
|
110
111
|
return void 0;
|
|
111
112
|
}
|
|
112
113
|
const parts = toGenAIParts(msg.parts);
|
|
114
|
+
if (parts.length === 0) {
|
|
115
|
+
return void 0;
|
|
116
|
+
}
|
|
113
117
|
return {
|
|
114
118
|
...createAdkEventFromMetadata(a2aEvent),
|
|
115
119
|
invocationId,
|
|
@@ -140,7 +144,7 @@ function taskToAdkEvent(a2aTask, invocationId, agentName) {
|
|
|
140
144
|
}
|
|
141
145
|
const isTerminal = isTerminalTaskStatusUpdateEvent(a2aTask) || isInputRequiredTaskStatusUpdateEvent(a2aTask);
|
|
142
146
|
const isFailed = isFailedTaskStatusUpdateEvent(a2aTask);
|
|
143
|
-
if (parts.length === 0 && !
|
|
147
|
+
if (parts.length === 0 && !isFailed) {
|
|
144
148
|
return void 0;
|
|
145
149
|
}
|
|
146
150
|
return {
|
|
@@ -56,7 +56,7 @@ function getA2AEventMetadata(adkEvent, {
|
|
|
56
56
|
[A2AMetadataKeys.INVOCATION_ID]: adkEvent.invocationId,
|
|
57
57
|
[A2AMetadataKeys.AUTHOR]: adkEvent.author,
|
|
58
58
|
[A2AMetadataKeys.BRANCH]: adkEvent.branch,
|
|
59
|
-
[A2AMetadataKeys.ERROR_CODE]: adkEvent.
|
|
59
|
+
[A2AMetadataKeys.ERROR_CODE]: adkEvent.errorCode,
|
|
60
60
|
[A2AMetadataKeys.ERROR_MESSAGE]: adkEvent.errorMessage,
|
|
61
61
|
[A2AMetadataKeys.CITATION_METADATA]: adkEvent.citationMetadata,
|
|
62
62
|
[A2AMetadataKeys.GROUNDING_METADATA]: adkEvent.groundingMetadata,
|
|
@@ -5,9 +5,14 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
5
5
|
* Copyright 2025 Google LLC
|
|
6
6
|
* SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
*/
|
|
8
|
+
import { Task } from "../utils/task.js";
|
|
8
9
|
class ActiveStreamingTool {
|
|
9
10
|
constructor(params = {}) {
|
|
10
|
-
|
|
11
|
+
if (params.task instanceof Promise) {
|
|
12
|
+
this.task = new Task(() => params.task);
|
|
13
|
+
} else {
|
|
14
|
+
this.task = params.task;
|
|
15
|
+
}
|
|
11
16
|
this.stream = params.stream;
|
|
12
17
|
}
|
|
13
18
|
}
|