@google/adk 0.4.0 → 0.6.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/README.md +1 -1
- package/dist/cjs/a2a/a2a_event.js +317 -0
- package/dist/cjs/a2a/a2a_remote_agent.js +174 -0
- package/dist/cjs/a2a/a2a_remote_agent_run_processor.js +198 -0
- package/dist/cjs/a2a/a2a_remote_agent_utils.js +165 -0
- package/dist/cjs/a2a/agent_card.js +380 -0
- package/dist/cjs/a2a/agent_executor.js +221 -0
- package/dist/cjs/a2a/agent_to_a2a.js +115 -0
- package/dist/cjs/a2a/event_converter_utils.js +201 -0
- package/dist/cjs/a2a/event_processor_utils.js +180 -0
- package/dist/cjs/a2a/executor_context.js +53 -0
- package/dist/cjs/a2a/metadata_converter_utils.js +126 -0
- package/dist/cjs/a2a/part_converter_utils.js +47 -34
- package/dist/cjs/agents/base_agent.js +3 -3
- package/dist/cjs/{tools/tool_context.js → agents/context.js} +70 -15
- package/dist/cjs/agents/functions.js +2 -2
- package/dist/cjs/agents/llm_agent.js +38 -674
- package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +132 -0
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +68 -0
- package/dist/cjs/agents/processors/code_execution_request_processor.js +389 -0
- package/dist/cjs/agents/{content_processor_utils.js → processors/content_processor_utils.js} +21 -2
- package/dist/cjs/agents/processors/content_request_processor.js +87 -0
- package/dist/cjs/agents/processors/context_compactor_request_processor.js +61 -0
- package/dist/cjs/agents/processors/identity_llm_request_processor.js +54 -0
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +85 -0
- package/dist/cjs/agents/processors/request_confirmation_llm_request_processor.js +165 -0
- package/dist/cjs/artifacts/file_artifact_service.js +35 -4
- package/dist/cjs/common.js +48 -7
- package/dist/cjs/context/base_context_compactor.js +27 -0
- package/dist/cjs/context/summarizers/base_summarizer.js +27 -0
- package/dist/cjs/context/summarizers/llm_summarizer.js +93 -0
- package/dist/cjs/context/token_based_context_compactor.js +135 -0
- package/dist/cjs/context/truncating_context_compactor.js +58 -0
- package/dist/cjs/events/compacted_event.js +53 -0
- package/dist/cjs/index.js +113 -53
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/memory/in_memory_memory_service.js +1 -1
- package/dist/cjs/models/llm_response.js +2 -0
- package/dist/cjs/plugins/base_plugin.js +1 -1
- package/dist/cjs/runner/runner.js +20 -11
- package/dist/cjs/sessions/database_session_service.js +4 -1
- package/dist/cjs/sessions/db/operations.js +25 -23
- package/dist/cjs/sessions/state.js +2 -2
- package/dist/cjs/tools/agent_tool.js +6 -5
- package/dist/cjs/tools/base_tool.js +3 -0
- package/dist/cjs/tools/base_toolset.js +13 -3
- package/dist/cjs/tools/exit_loop_tool.js +63 -0
- package/dist/cjs/tools/load_artifacts_tool.js +188 -0
- package/dist/cjs/tools/load_memory_tool.js +107 -0
- package/dist/cjs/tools/mcp/mcp_toolset.js +9 -5
- package/dist/cjs/tools/preload_memory_tool.js +109 -0
- package/dist/cjs/utils/logger.js +62 -54
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/a2a_event.js +269 -0
- package/dist/esm/a2a/a2a_remote_agent.js +148 -0
- package/dist/esm/a2a/a2a_remote_agent_run_processor.js +175 -0
- package/dist/esm/a2a/a2a_remote_agent_utils.js +131 -0
- package/dist/esm/a2a/agent_card.js +340 -0
- package/dist/esm/a2a/agent_executor.js +202 -0
- package/dist/esm/a2a/agent_to_a2a.js +80 -0
- package/dist/esm/a2a/event_converter_utils.js +187 -0
- package/dist/esm/a2a/event_processor_utils.js +159 -0
- package/dist/esm/a2a/executor_context.js +23 -0
- package/dist/esm/a2a/metadata_converter_utils.js +91 -0
- package/dist/esm/a2a/part_converter_utils.js +49 -34
- package/dist/esm/agents/base_agent.js +3 -3
- package/dist/{web/tools/tool_context.js → esm/agents/context.js} +66 -11
- package/dist/esm/agents/functions.js +2 -2
- package/dist/esm/agents/llm_agent.js +31 -683
- package/dist/esm/agents/processors/agent_transfer_llm_request_processor.js +101 -0
- package/dist/esm/agents/processors/basic_llm_request_processor.js +37 -0
- package/dist/esm/agents/processors/code_execution_request_processor.js +363 -0
- package/dist/esm/agents/{content_processor_utils.js → processors/content_processor_utils.js} +23 -2
- package/dist/esm/agents/processors/content_request_processor.js +59 -0
- package/dist/esm/agents/processors/context_compactor_request_processor.js +31 -0
- package/dist/esm/agents/processors/identity_llm_request_processor.js +23 -0
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +54 -0
- package/dist/esm/agents/processors/request_confirmation_llm_request_processor.js +140 -0
- package/dist/esm/artifacts/file_artifact_service.js +30 -3
- package/dist/esm/common.js +44 -10
- package/dist/esm/context/base_context_compactor.js +5 -0
- package/dist/esm/context/summarizers/base_summarizer.js +5 -0
- package/dist/esm/context/summarizers/llm_summarizer.js +65 -0
- package/dist/esm/context/token_based_context_compactor.js +105 -0
- package/dist/esm/context/truncating_context_compactor.js +28 -0
- package/dist/esm/events/compacted_event.js +22 -0
- package/dist/esm/index.js +119 -18
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/memory/in_memory_memory_service.js +1 -1
- package/dist/esm/models/llm_response.js +2 -0
- package/dist/esm/plugins/base_plugin.js +1 -1
- package/dist/esm/runner/runner.js +18 -10
- package/dist/esm/sessions/database_session_service.js +4 -1
- package/dist/esm/sessions/db/operations.js +32 -18
- package/dist/esm/sessions/state.js +2 -2
- package/dist/esm/tools/agent_tool.js +6 -5
- package/dist/esm/tools/base_tool.js +3 -0
- package/dist/esm/tools/base_toolset.js +11 -2
- package/dist/esm/tools/exit_loop_tool.js +32 -0
- package/dist/esm/tools/load_artifacts_tool.js +159 -0
- package/dist/esm/tools/load_memory_tool.js +78 -0
- package/dist/esm/tools/mcp/mcp_toolset.js +9 -5
- package/dist/esm/tools/preload_memory_tool.js +80 -0
- package/dist/esm/utils/logger.js +52 -54
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_event.d.ts +139 -0
- package/dist/types/a2a/a2a_remote_agent.d.ts +63 -0
- package/dist/types/a2a/a2a_remote_agent_run_processor.d.ts +31 -0
- package/dist/types/a2a/a2a_remote_agent_utils.d.ts +38 -0
- package/dist/types/a2a/agent_card.d.ts +23 -0
- package/dist/types/a2a/agent_executor.d.ts +52 -0
- package/dist/types/a2a/agent_to_a2a.d.ts +45 -0
- package/dist/types/a2a/event_converter_utils.d.ts +20 -0
- package/dist/types/a2a/event_processor_utils.d.ts +24 -0
- package/dist/types/a2a/executor_context.d.ts +33 -0
- package/dist/types/a2a/metadata_converter_utils.d.ts +63 -0
- package/dist/types/a2a/part_converter_utils.d.ts +4 -3
- package/dist/types/agents/base_agent.d.ts +2 -2
- package/dist/types/{tools/tool_context.d.ts → agents/context.d.ts} +43 -8
- package/dist/types/agents/llm_agent.d.ts +14 -31
- package/dist/types/agents/loop_agent.d.ts +1 -1
- package/dist/types/agents/processors/agent_transfer_llm_request_processor.d.ts +18 -0
- package/dist/types/agents/{base_llm_processor.d.ts → processors/base_llm_processor.d.ts} +4 -4
- package/dist/types/agents/processors/basic_llm_request_processor.d.ts +13 -0
- package/dist/types/agents/processors/code_execution_request_processor.d.ts +34 -0
- package/dist/types/agents/{content_processor_utils.d.ts → processors/content_processor_utils.d.ts} +1 -1
- package/dist/types/agents/processors/content_request_processor.d.ts +13 -0
- package/dist/types/agents/processors/context_compactor_request_processor.d.ts +22 -0
- package/dist/types/agents/processors/identity_llm_request_processor.d.ts +13 -0
- package/dist/types/agents/processors/instructions_llm_request_processor.d.ts +16 -0
- package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +13 -0
- package/dist/types/artifacts/file_artifact_service.d.ts +4 -0
- package/dist/types/auth/credential_service/base_credential_service.d.ts +3 -3
- package/dist/types/auth/credential_service/in_memory_credential_service.d.ts +3 -3
- package/dist/types/common.d.ts +20 -5
- package/dist/types/context/base_context_compactor.d.ts +24 -0
- package/dist/types/context/summarizers/base_summarizer.d.ts +19 -0
- package/dist/types/context/summarizers/llm_summarizer.d.ts +23 -0
- package/dist/types/context/token_based_context_compactor.d.ts +33 -0
- package/dist/types/context/truncating_context_compactor.d.ts +24 -0
- package/dist/types/events/compacted_event.d.ts +33 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/models/llm_response.d.ts +5 -1
- package/dist/types/plugins/base_plugin.d.ts +12 -13
- package/dist/types/plugins/logging_plugin.d.ts +9 -10
- package/dist/types/plugins/plugin_manager.d.ts +9 -10
- package/dist/types/plugins/security_plugin.d.ts +2 -2
- package/dist/types/runner/runner.d.ts +13 -0
- package/dist/types/sessions/database_session_service.d.ts +2 -1
- package/dist/types/sessions/db/operations.d.ts +3 -4
- package/dist/types/tools/base_tool.d.ts +3 -3
- package/dist/types/tools/base_toolset.d.ts +12 -3
- package/dist/types/tools/exit_loop_tool.d.ts +24 -0
- package/dist/types/tools/forwarding_artifact_service.d.ts +2 -2
- package/dist/types/tools/function_tool.d.ts +2 -2
- package/dist/types/tools/load_artifacts_tool.d.ts +21 -0
- package/dist/types/tools/load_memory_tool.d.ts +22 -0
- package/dist/types/tools/mcp/mcp_toolset.d.ts +1 -1
- package/dist/types/tools/preload_memory_tool.d.ts +23 -0
- package/dist/types/utils/logger.d.ts +5 -9
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/a2a_event.js +269 -0
- package/dist/web/a2a/a2a_remote_agent.js +193 -0
- package/dist/web/a2a/a2a_remote_agent_run_processor.js +175 -0
- package/dist/web/a2a/a2a_remote_agent_utils.js +131 -0
- package/dist/web/a2a/agent_card.js +340 -0
- package/dist/web/a2a/agent_executor.js +216 -0
- package/dist/web/a2a/agent_to_a2a.js +80 -0
- package/dist/web/a2a/event_converter_utils.js +201 -0
- package/dist/web/a2a/event_processor_utils.js +168 -0
- package/dist/web/a2a/executor_context.js +23 -0
- package/dist/web/a2a/metadata_converter_utils.js +108 -0
- package/dist/web/a2a/part_converter_utils.js +49 -34
- package/dist/web/agents/base_agent.js +3 -3
- package/dist/{esm/tools/tool_context.js → web/agents/context.js} +66 -11
- package/dist/web/agents/functions.js +2 -2
- package/dist/web/agents/llm_agent.js +31 -661
- package/dist/web/agents/processors/agent_transfer_llm_request_processor.js +100 -0
- package/dist/web/agents/processors/basic_llm_request_processor.js +71 -0
- package/dist/web/agents/processors/code_execution_request_processor.js +365 -0
- package/dist/web/agents/{content_processor_utils.js → processors/content_processor_utils.js} +22 -2
- package/dist/web/agents/processors/content_request_processor.js +77 -0
- package/dist/web/agents/processors/context_compactor_request_processor.js +49 -0
- package/dist/web/agents/processors/identity_llm_request_processor.js +41 -0
- package/dist/web/agents/processors/instructions_llm_request_processor.js +72 -0
- package/dist/web/agents/processors/request_confirmation_llm_request_processor.js +158 -0
- package/dist/web/artifacts/file_artifact_service.js +30 -3
- package/dist/web/common.js +44 -10
- package/dist/web/context/base_context_compactor.js +5 -0
- package/dist/web/context/summarizers/base_summarizer.js +5 -0
- package/dist/web/context/summarizers/llm_summarizer.js +74 -0
- package/dist/web/context/token_based_context_compactor.js +105 -0
- package/dist/web/context/truncating_context_compactor.js +28 -0
- package/dist/web/events/compacted_event.js +40 -0
- package/dist/web/index.js +13 -18
- package/dist/web/index.js.map +7 -0
- package/dist/web/memory/in_memory_memory_service.js +1 -1
- package/dist/web/models/llm_response.js +2 -0
- package/dist/web/plugins/base_plugin.js +1 -1
- package/dist/web/runner/runner.js +18 -10
- package/dist/web/sessions/database_session_service.js +4 -1
- package/dist/web/sessions/db/operations.js +32 -18
- package/dist/web/sessions/state.js +2 -2
- package/dist/web/tools/agent_tool.js +6 -5
- package/dist/web/tools/base_tool.js +3 -0
- package/dist/web/tools/base_toolset.js +11 -2
- package/dist/web/tools/exit_loop_tool.js +32 -0
- package/dist/web/tools/load_artifacts_tool.js +150 -0
- package/dist/web/tools/load_memory_tool.js +77 -0
- package/dist/web/tools/mcp/mcp_toolset.js +27 -5
- package/dist/web/tools/preload_memory_tool.js +75 -0
- package/dist/web/utils/logger.js +52 -54
- package/dist/web/version.js +1 -1
- package/package.json +7 -4
- package/dist/cjs/agents/callback_context.js +0 -101
- package/dist/esm/agents/callback_context.js +0 -71
- package/dist/types/agents/callback_context.d.ts +0 -42
- package/dist/web/agents/callback_context.js +0 -71
- /package/dist/cjs/agents/{base_llm_processor.js → processors/base_llm_processor.js} +0 -0
- /package/dist/esm/agents/{base_llm_processor.js → processors/base_llm_processor.js} +0 -0
- /package/dist/web/agents/{base_llm_processor.js → processors/base_llm_processor.js} +0 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import {
|
|
7
|
+
createModelContent,
|
|
8
|
+
createUserContent
|
|
9
|
+
} from "@google/genai";
|
|
10
|
+
import { createEvent } from "../events/event.js";
|
|
11
|
+
import { createEventActions } from "../events/event_actions.js";
|
|
12
|
+
import { randomUUID } from "../utils/env_aware_utils.js";
|
|
13
|
+
import {
|
|
14
|
+
getEventMetadata,
|
|
15
|
+
getFailedTaskStatusUpdateEventError,
|
|
16
|
+
isFailedTaskStatusUpdateEvent,
|
|
17
|
+
isInputRequiredTaskStatusUpdateEvent,
|
|
18
|
+
isMessage,
|
|
19
|
+
isTask,
|
|
20
|
+
isTaskArtifactUpdateEvent,
|
|
21
|
+
isTaskStatusUpdateEvent,
|
|
22
|
+
isTerminalTaskStatusUpdateEvent,
|
|
23
|
+
MessageRole
|
|
24
|
+
} from "./a2a_event.js";
|
|
25
|
+
import {
|
|
26
|
+
A2AMetadataKeys,
|
|
27
|
+
getA2AEventMetadata
|
|
28
|
+
} from "./metadata_converter_utils.js";
|
|
29
|
+
import { toA2AParts, toGenAIPart, toGenAIParts } from "./part_converter_utils.js";
|
|
30
|
+
function toA2AMessage(event, {
|
|
31
|
+
appName,
|
|
32
|
+
userId,
|
|
33
|
+
sessionId
|
|
34
|
+
}) {
|
|
35
|
+
var _a;
|
|
36
|
+
return {
|
|
37
|
+
kind: "message",
|
|
38
|
+
messageId: randomUUID(),
|
|
39
|
+
role: event.author === MessageRole.USER ? MessageRole.USER : MessageRole.AGENT,
|
|
40
|
+
parts: toA2AParts(((_a = event.content) == null ? void 0 : _a.parts) || [], event.longRunningToolIds),
|
|
41
|
+
metadata: getA2AEventMetadata(event, { appName, userId, sessionId })
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function toAdkEvent(event, invocationId, agentName) {
|
|
45
|
+
if (isMessage(event)) {
|
|
46
|
+
return messageToAdkEvent(event, invocationId, agentName);
|
|
47
|
+
}
|
|
48
|
+
if (isTask(event)) {
|
|
49
|
+
return taskToAdkEvent(event, invocationId, agentName);
|
|
50
|
+
}
|
|
51
|
+
if (isTaskArtifactUpdateEvent(event)) {
|
|
52
|
+
return artifactUpdateToAdkEvent(event, invocationId, agentName);
|
|
53
|
+
}
|
|
54
|
+
if (isTaskStatusUpdateEvent(event)) {
|
|
55
|
+
return event.final ? finalTaskStatusUpdateToAdkEvent(event, invocationId, agentName) : taskStatusUpdateToAdkEvent(event, invocationId, agentName);
|
|
56
|
+
}
|
|
57
|
+
return void 0;
|
|
58
|
+
}
|
|
59
|
+
function messageToAdkEvent(msg, invocationId, agentName, parentEvent) {
|
|
60
|
+
const parts = toGenAIParts(msg.parts);
|
|
61
|
+
return {
|
|
62
|
+
...createAdkEventFromMetadata(parentEvent || msg),
|
|
63
|
+
invocationId,
|
|
64
|
+
author: msg.role === MessageRole.USER ? MessageRole.USER : agentName,
|
|
65
|
+
content: msg.role === MessageRole.USER ? createUserContent(parts) : createModelContent(parts),
|
|
66
|
+
turnComplete: true,
|
|
67
|
+
partial: false
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function artifactUpdateToAdkEvent(a2aEvent, invocationId, agentName) {
|
|
71
|
+
var _a;
|
|
72
|
+
const partsToConvert = ((_a = a2aEvent.artifact) == null ? void 0 : _a.parts) || [];
|
|
73
|
+
if (partsToConvert.length === 0) {
|
|
74
|
+
return void 0;
|
|
75
|
+
}
|
|
76
|
+
const partial = !!getEventMetadata(a2aEvent)[A2AMetadataKeys.PARTIAL] || a2aEvent.append || !a2aEvent.lastChunk;
|
|
77
|
+
return {
|
|
78
|
+
...createAdkEventFromMetadata(a2aEvent),
|
|
79
|
+
invocationId,
|
|
80
|
+
author: agentName,
|
|
81
|
+
content: createModelContent(toGenAIParts(partsToConvert)),
|
|
82
|
+
longRunningToolIds: getLongRunningToolIDs(partsToConvert),
|
|
83
|
+
partial
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function finalTaskStatusUpdateToAdkEvent(a2aEvent, invocationId, agentName) {
|
|
87
|
+
var _a;
|
|
88
|
+
const partsToConvert = ((_a = a2aEvent.status.message) == null ? void 0 : _a.parts) || [];
|
|
89
|
+
if (partsToConvert.length === 0) {
|
|
90
|
+
return void 0;
|
|
91
|
+
}
|
|
92
|
+
const parts = toGenAIParts(partsToConvert);
|
|
93
|
+
const isFailedTask = isFailedTaskStatusUpdateEvent(a2aEvent);
|
|
94
|
+
const hasContent = !isFailedTask && parts.length > 0;
|
|
95
|
+
return {
|
|
96
|
+
...createAdkEventFromMetadata(a2aEvent),
|
|
97
|
+
invocationId,
|
|
98
|
+
author: agentName,
|
|
99
|
+
errorMessage: isFailedTask ? getFailedTaskStatusUpdateEventError(a2aEvent) : void 0,
|
|
100
|
+
content: hasContent ? createModelContent(parts) : void 0,
|
|
101
|
+
longRunningToolIds: getLongRunningToolIDs(partsToConvert),
|
|
102
|
+
turnComplete: true
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function taskStatusUpdateToAdkEvent(a2aEvent, invocationId, agentName) {
|
|
106
|
+
const msg = a2aEvent.status.message;
|
|
107
|
+
if (!msg) {
|
|
108
|
+
return void 0;
|
|
109
|
+
}
|
|
110
|
+
const parts = toGenAIParts(msg.parts);
|
|
111
|
+
return {
|
|
112
|
+
...createAdkEventFromMetadata(a2aEvent),
|
|
113
|
+
invocationId,
|
|
114
|
+
author: agentName,
|
|
115
|
+
content: createModelContent(parts),
|
|
116
|
+
turnComplete: false,
|
|
117
|
+
partial: true
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function taskToAdkEvent(a2aTask, invocationId, agentName) {
|
|
121
|
+
var _a, _b;
|
|
122
|
+
const parts = [];
|
|
123
|
+
const longRunningToolIds = [];
|
|
124
|
+
if (a2aTask.artifacts) {
|
|
125
|
+
for (const artifact of a2aTask.artifacts) {
|
|
126
|
+
if (((_a = artifact.parts) == null ? void 0 : _a.length) > 0) {
|
|
127
|
+
const artifactParts = toGenAIParts(artifact.parts);
|
|
128
|
+
parts.push(...artifactParts);
|
|
129
|
+
longRunningToolIds.push(...getLongRunningToolIDs(artifact.parts));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if ((_b = a2aTask.status) == null ? void 0 : _b.message) {
|
|
134
|
+
const a2aParts = a2aTask.status.message.parts;
|
|
135
|
+
const genAIParts = toGenAIParts(a2aParts);
|
|
136
|
+
parts.push(...genAIParts);
|
|
137
|
+
longRunningToolIds.push(...getLongRunningToolIDs(a2aParts));
|
|
138
|
+
}
|
|
139
|
+
const isTerminal = isTerminalTaskStatusUpdateEvent(a2aTask) || isInputRequiredTaskStatusUpdateEvent(a2aTask);
|
|
140
|
+
const isFailed = isFailedTaskStatusUpdateEvent(a2aTask);
|
|
141
|
+
if (parts.length === 0 && !isTerminal) {
|
|
142
|
+
return void 0;
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
...createAdkEventFromMetadata(a2aTask),
|
|
146
|
+
invocationId,
|
|
147
|
+
author: agentName,
|
|
148
|
+
content: isFailed ? void 0 : createModelContent(parts),
|
|
149
|
+
errorMessage: isFailed ? getFailedTaskStatusUpdateEventError(a2aTask) : void 0,
|
|
150
|
+
longRunningToolIds,
|
|
151
|
+
turnComplete: isTerminal
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function createAdkEventFromMetadata(a2aEvent) {
|
|
155
|
+
const metadata = a2aEvent.metadata || {};
|
|
156
|
+
return createEvent({
|
|
157
|
+
branch: metadata[A2AMetadataKeys.BRANCH],
|
|
158
|
+
author: metadata[A2AMetadataKeys.AUTHOR],
|
|
159
|
+
partial: metadata[A2AMetadataKeys.PARTIAL],
|
|
160
|
+
errorCode: metadata[A2AMetadataKeys.ERROR_CODE],
|
|
161
|
+
errorMessage: metadata[A2AMetadataKeys.ERROR_MESSAGE],
|
|
162
|
+
citationMetadata: metadata[A2AMetadataKeys.CITATION_METADATA],
|
|
163
|
+
groundingMetadata: metadata[A2AMetadataKeys.GROUNDING_METADATA],
|
|
164
|
+
usageMetadata: metadata[A2AMetadataKeys.USAGE_METADATA],
|
|
165
|
+
customMetadata: metadata[A2AMetadataKeys.CUSTOM_METADATA],
|
|
166
|
+
actions: createEventActions({
|
|
167
|
+
escalate: !!metadata[A2AMetadataKeys.ESCALATE],
|
|
168
|
+
transferToAgent: metadata[A2AMetadataKeys.TRANSFER_TO_AGENT]
|
|
169
|
+
})
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
function getLongRunningToolIDs(parts) {
|
|
173
|
+
const ids = [];
|
|
174
|
+
for (const a2aPart of parts) {
|
|
175
|
+
if (a2aPart.metadata && a2aPart.metadata[A2AMetadataKeys.IS_LONG_RUNNING]) {
|
|
176
|
+
const genAIPart = toGenAIPart(a2aPart);
|
|
177
|
+
if (genAIPart.functionCall && genAIPart.functionCall.id) {
|
|
178
|
+
ids.push(genAIPart.functionCall.id);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return ids;
|
|
183
|
+
}
|
|
184
|
+
export {
|
|
185
|
+
toA2AMessage,
|
|
186
|
+
toAdkEvent
|
|
187
|
+
};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { createEventActions } from "../events/event_actions.js";
|
|
7
|
+
import {
|
|
8
|
+
createInputMissingErrorEvent,
|
|
9
|
+
createTaskCompletedEvent,
|
|
10
|
+
createTaskFailedEvent,
|
|
11
|
+
createTaskInputRequiredEvent,
|
|
12
|
+
isInputRequiredTaskStatusUpdateEvent
|
|
13
|
+
} from "./a2a_event.js";
|
|
14
|
+
import {
|
|
15
|
+
getA2AEventMetadata,
|
|
16
|
+
getA2AEventMetadataFromActions,
|
|
17
|
+
getA2ASessionMetadata
|
|
18
|
+
} from "./metadata_converter_utils.js";
|
|
19
|
+
import { toA2AParts, toGenAIParts } from "./part_converter_utils.js";
|
|
20
|
+
function getFinalTaskStatusUpdate(adkEvents, context) {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
const finalEventActions = createEventActions();
|
|
23
|
+
for (const adkEvent of adkEvents) {
|
|
24
|
+
if (adkEvent.errorCode || adkEvent.errorMessage) {
|
|
25
|
+
return createTaskFailedEvent({
|
|
26
|
+
taskId: context.requestContext.taskId,
|
|
27
|
+
contextId: context.requestContext.contextId,
|
|
28
|
+
error: new Error(adkEvent.errorMessage || adkEvent.errorCode),
|
|
29
|
+
metadata: {
|
|
30
|
+
...getA2AEventMetadata(adkEvent, context),
|
|
31
|
+
...getA2AEventMetadataFromActions(finalEventActions)
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
finalEventActions.escalate = finalEventActions.escalate || ((_a = adkEvent.actions) == null ? void 0 : _a.escalate);
|
|
36
|
+
if ((_b = adkEvent.actions) == null ? void 0 : _b.transferToAgent) {
|
|
37
|
+
finalEventActions.transferToAgent = adkEvent.actions.transferToAgent;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const inputRequiredEvent = scanForInputRequiredEvents(adkEvents, context);
|
|
41
|
+
if (inputRequiredEvent) {
|
|
42
|
+
return {
|
|
43
|
+
...inputRequiredEvent,
|
|
44
|
+
metadata: {
|
|
45
|
+
...inputRequiredEvent.metadata,
|
|
46
|
+
...getA2AEventMetadataFromActions(finalEventActions)
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return createTaskCompletedEvent({
|
|
51
|
+
taskId: context.requestContext.taskId,
|
|
52
|
+
contextId: context.requestContext.contextId,
|
|
53
|
+
metadata: {
|
|
54
|
+
...getA2ASessionMetadata(context),
|
|
55
|
+
...getA2AEventMetadataFromActions(finalEventActions)
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function scanForInputRequiredEvents(adkEvents, context) {
|
|
60
|
+
var _a, _b;
|
|
61
|
+
const inputRequiredParts = [];
|
|
62
|
+
const inputRequiredFunctionCallIds = /* @__PURE__ */ new Set();
|
|
63
|
+
for (const adkEvent of adkEvents) {
|
|
64
|
+
if (!((_b = (_a = adkEvent.content) == null ? void 0 : _a.parts) == null ? void 0 : _b.length)) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
for (const genAIPart of adkEvent.content.parts) {
|
|
68
|
+
const longRunningFunctionCallId = getLongRunnningFunctionCallId(
|
|
69
|
+
genAIPart,
|
|
70
|
+
adkEvent.longRunningToolIds,
|
|
71
|
+
inputRequiredParts
|
|
72
|
+
);
|
|
73
|
+
if (!longRunningFunctionCallId) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
const isAlreadyAdded = inputRequiredFunctionCallIds.has(
|
|
77
|
+
longRunningFunctionCallId
|
|
78
|
+
);
|
|
79
|
+
if (isAlreadyAdded) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
inputRequiredParts.push(genAIPart);
|
|
83
|
+
inputRequiredFunctionCallIds.add(longRunningFunctionCallId);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (inputRequiredParts.length > 0) {
|
|
87
|
+
return createTaskInputRequiredEvent({
|
|
88
|
+
taskId: context.requestContext.taskId,
|
|
89
|
+
contextId: context.requestContext.contextId,
|
|
90
|
+
parts: toA2AParts(inputRequiredParts, [...inputRequiredFunctionCallIds]),
|
|
91
|
+
metadata: getA2ASessionMetadata(context)
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return void 0;
|
|
95
|
+
}
|
|
96
|
+
function getLongRunnningFunctionCallId(genAIPart, longRunningToolIds = [], inputRequiredParts = []) {
|
|
97
|
+
var _a, _b, _c;
|
|
98
|
+
const functionCallId = (_a = genAIPart.functionCall) == null ? void 0 : _a.id;
|
|
99
|
+
const functionResponseId = (_b = genAIPart.functionResponse) == null ? void 0 : _b.id;
|
|
100
|
+
if (!functionCallId && !functionResponseId) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (functionCallId && longRunningToolIds.includes(functionCallId)) {
|
|
104
|
+
return functionCallId;
|
|
105
|
+
}
|
|
106
|
+
if (functionResponseId && longRunningToolIds.includes(functionResponseId)) {
|
|
107
|
+
return functionResponseId;
|
|
108
|
+
}
|
|
109
|
+
for (const part of inputRequiredParts) {
|
|
110
|
+
if (((_c = part.functionCall) == null ? void 0 : _c.id) === functionResponseId) {
|
|
111
|
+
return functionResponseId;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
function getTaskInputRequiredEvent(task, genAIContent) {
|
|
117
|
+
var _a;
|
|
118
|
+
if (!task || !isInputRequiredTaskStatusUpdateEvent(task) || !task.status.message) {
|
|
119
|
+
return void 0;
|
|
120
|
+
}
|
|
121
|
+
const statusMsg = task.status.message;
|
|
122
|
+
const taskParts = toGenAIParts(statusMsg.parts);
|
|
123
|
+
for (const taskPart of taskParts) {
|
|
124
|
+
const functionCallId = (_a = taskPart.functionCall) == null ? void 0 : _a.id;
|
|
125
|
+
if (!functionCallId) {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const hasMatchingResponse = ((genAIContent == null ? void 0 : genAIContent.parts) || []).some(
|
|
129
|
+
(p) => {
|
|
130
|
+
var _a2;
|
|
131
|
+
return ((_a2 = p.functionResponse) == null ? void 0 : _a2.id) === functionCallId;
|
|
132
|
+
}
|
|
133
|
+
);
|
|
134
|
+
if (!hasMatchingResponse) {
|
|
135
|
+
return createInputMissingErrorEvent({
|
|
136
|
+
taskId: task.id,
|
|
137
|
+
contextId: task.contextId,
|
|
138
|
+
parts: [
|
|
139
|
+
...statusMsg.parts.filter((p) => {
|
|
140
|
+
var _a2;
|
|
141
|
+
return !((_a2 = p.metadata) == null ? void 0 : _a2.validation_error);
|
|
142
|
+
}),
|
|
143
|
+
{
|
|
144
|
+
kind: "text",
|
|
145
|
+
text: `No input provided for function call id ${functionCallId}`,
|
|
146
|
+
metadata: {
|
|
147
|
+
validation_error: true
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
]
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return void 0;
|
|
155
|
+
}
|
|
156
|
+
export {
|
|
157
|
+
getFinalTaskStatusUpdate,
|
|
158
|
+
getTaskInputRequiredEvent
|
|
159
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
function createExecutorContext({
|
|
7
|
+
session,
|
|
8
|
+
userContent,
|
|
9
|
+
requestContext
|
|
10
|
+
}) {
|
|
11
|
+
return {
|
|
12
|
+
userId: session.userId,
|
|
13
|
+
sessionId: session.id,
|
|
14
|
+
appName: session.appName,
|
|
15
|
+
readonlyState: session.state,
|
|
16
|
+
events: session.events,
|
|
17
|
+
userContent,
|
|
18
|
+
requestContext
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
createExecutorContext
|
|
23
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { isTask } from "./a2a_event.js";
|
|
7
|
+
const ADK_METADATA_KEY_PREFIX = "adk_";
|
|
8
|
+
const A2A_METADATA_KEY_PREFIX = "a2a:";
|
|
9
|
+
var A2AMetadataKeys = ((A2AMetadataKeys2) => {
|
|
10
|
+
A2AMetadataKeys2["APP_NAME"] = `${ADK_METADATA_KEY_PREFIX}app_name`;
|
|
11
|
+
A2AMetadataKeys2["USER_ID"] = `${ADK_METADATA_KEY_PREFIX}user_id`;
|
|
12
|
+
A2AMetadataKeys2["SESSION_ID"] = `${ADK_METADATA_KEY_PREFIX}session_id`;
|
|
13
|
+
A2AMetadataKeys2["INVOCATION_ID"] = `${ADK_METADATA_KEY_PREFIX}invocation_id`;
|
|
14
|
+
A2AMetadataKeys2["AUTHOR"] = `${ADK_METADATA_KEY_PREFIX}author`;
|
|
15
|
+
A2AMetadataKeys2["BRANCH"] = `${ADK_METADATA_KEY_PREFIX}branch`;
|
|
16
|
+
A2AMetadataKeys2["DATA_PART_TYPE"] = `${ADK_METADATA_KEY_PREFIX}type`;
|
|
17
|
+
A2AMetadataKeys2["PARTIAL"] = `${ADK_METADATA_KEY_PREFIX}partial`;
|
|
18
|
+
A2AMetadataKeys2["ESCALATE"] = `${ADK_METADATA_KEY_PREFIX}escalate`;
|
|
19
|
+
A2AMetadataKeys2["TRANSFER_TO_AGENT"] = `${ADK_METADATA_KEY_PREFIX}transfer_to_agent`;
|
|
20
|
+
A2AMetadataKeys2["IS_LONG_RUNNING"] = `${ADK_METADATA_KEY_PREFIX}is_long_running`;
|
|
21
|
+
A2AMetadataKeys2["THOUGHT"] = `${ADK_METADATA_KEY_PREFIX}thought`;
|
|
22
|
+
A2AMetadataKeys2["ERROR_CODE"] = `${ADK_METADATA_KEY_PREFIX}error_code`;
|
|
23
|
+
A2AMetadataKeys2["ERROR_MESSAGE"] = `${ADK_METADATA_KEY_PREFIX}error_message`;
|
|
24
|
+
A2AMetadataKeys2["CITATION_METADATA"] = `${ADK_METADATA_KEY_PREFIX}citation_metadata`;
|
|
25
|
+
A2AMetadataKeys2["GROUNDING_METADATA"] = `${ADK_METADATA_KEY_PREFIX}grounding_metadata`;
|
|
26
|
+
A2AMetadataKeys2["USAGE_METADATA"] = `${ADK_METADATA_KEY_PREFIX}usage_metadata`;
|
|
27
|
+
A2AMetadataKeys2["CUSTOM_METADATA"] = `${ADK_METADATA_KEY_PREFIX}custom_metadata`;
|
|
28
|
+
A2AMetadataKeys2["VIDEO_METADATA"] = `${ADK_METADATA_KEY_PREFIX}video_metadata`;
|
|
29
|
+
return A2AMetadataKeys2;
|
|
30
|
+
})(A2AMetadataKeys || {});
|
|
31
|
+
var AdkMetadataKeys = ((AdkMetadataKeys2) => {
|
|
32
|
+
AdkMetadataKeys2["TASK_ID"] = `${A2A_METADATA_KEY_PREFIX}task_id`;
|
|
33
|
+
AdkMetadataKeys2["CONTEXT_ID"] = `${A2A_METADATA_KEY_PREFIX}context_id`;
|
|
34
|
+
return AdkMetadataKeys2;
|
|
35
|
+
})(AdkMetadataKeys || {});
|
|
36
|
+
function getAdkEventMetadata(a2aEvent) {
|
|
37
|
+
return {
|
|
38
|
+
[AdkMetadataKeys.TASK_ID]: isTask(a2aEvent) ? a2aEvent.id : a2aEvent.taskId,
|
|
39
|
+
[AdkMetadataKeys.CONTEXT_ID]: a2aEvent.contextId
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function getA2AEventMetadata(adkEvent, {
|
|
43
|
+
appName,
|
|
44
|
+
userId,
|
|
45
|
+
sessionId
|
|
46
|
+
}) {
|
|
47
|
+
return {
|
|
48
|
+
...getA2AEventMetadataFromActions(adkEvent.actions),
|
|
49
|
+
...getA2ASessionMetadata({
|
|
50
|
+
appName,
|
|
51
|
+
userId,
|
|
52
|
+
sessionId
|
|
53
|
+
}),
|
|
54
|
+
[A2AMetadataKeys.INVOCATION_ID]: adkEvent.invocationId,
|
|
55
|
+
[A2AMetadataKeys.AUTHOR]: adkEvent.author,
|
|
56
|
+
[A2AMetadataKeys.BRANCH]: adkEvent.branch,
|
|
57
|
+
[A2AMetadataKeys.ERROR_CODE]: adkEvent.errorMessage,
|
|
58
|
+
[A2AMetadataKeys.ERROR_MESSAGE]: adkEvent.errorMessage,
|
|
59
|
+
[A2AMetadataKeys.CITATION_METADATA]: adkEvent.citationMetadata,
|
|
60
|
+
[A2AMetadataKeys.GROUNDING_METADATA]: adkEvent.groundingMetadata,
|
|
61
|
+
[A2AMetadataKeys.USAGE_METADATA]: adkEvent.usageMetadata,
|
|
62
|
+
[A2AMetadataKeys.CUSTOM_METADATA]: adkEvent.customMetadata,
|
|
63
|
+
[A2AMetadataKeys.PARTIAL]: adkEvent.partial,
|
|
64
|
+
[A2AMetadataKeys.IS_LONG_RUNNING]: (adkEvent.longRunningToolIds || []).length > 0
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function getA2ASessionMetadata({
|
|
68
|
+
appName,
|
|
69
|
+
userId,
|
|
70
|
+
sessionId
|
|
71
|
+
}) {
|
|
72
|
+
return {
|
|
73
|
+
[A2AMetadataKeys.APP_NAME]: appName,
|
|
74
|
+
[A2AMetadataKeys.USER_ID]: userId,
|
|
75
|
+
[A2AMetadataKeys.SESSION_ID]: sessionId
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function getA2AEventMetadataFromActions(actions) {
|
|
79
|
+
return {
|
|
80
|
+
[A2AMetadataKeys.ESCALATE]: actions.escalate,
|
|
81
|
+
[A2AMetadataKeys.TRANSFER_TO_AGENT]: actions.transferToAgent
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export {
|
|
85
|
+
A2AMetadataKeys,
|
|
86
|
+
AdkMetadataKeys,
|
|
87
|
+
getA2AEventMetadata,
|
|
88
|
+
getA2AEventMetadataFromActions,
|
|
89
|
+
getA2ASessionMetadata,
|
|
90
|
+
getAdkEventMetadata
|
|
91
|
+
};
|
|
@@ -3,12 +3,11 @@
|
|
|
3
3
|
* Copyright 2026 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
})(MetadataKeys || {});
|
|
6
|
+
import {
|
|
7
|
+
createModelContent,
|
|
8
|
+
createUserContent
|
|
9
|
+
} from "@google/genai";
|
|
10
|
+
import { A2AMetadataKeys } from "./metadata_converter_utils.js";
|
|
12
11
|
var DataPartType = /* @__PURE__ */ ((DataPartType2) => {
|
|
13
12
|
DataPartType2["FUNCTION_CALL"] = "function_call";
|
|
14
13
|
DataPartType2["FUNCTION_RESPONSE"] = "function_response";
|
|
@@ -16,7 +15,7 @@ var DataPartType = /* @__PURE__ */ ((DataPartType2) => {
|
|
|
16
15
|
DataPartType2["CODE_EXECUTABLE_CODE"] = "executable_code";
|
|
17
16
|
return DataPartType2;
|
|
18
17
|
})(DataPartType || {});
|
|
19
|
-
function toA2AParts(parts, longRunningToolIDs = []) {
|
|
18
|
+
function toA2AParts(parts = [], longRunningToolIDs = []) {
|
|
20
19
|
return parts.map((part) => toA2APart(part, longRunningToolIDs));
|
|
21
20
|
}
|
|
22
21
|
function toA2APart(part, longRunningToolIDs) {
|
|
@@ -30,14 +29,18 @@ function toA2APart(part, longRunningToolIDs) {
|
|
|
30
29
|
}
|
|
31
30
|
function toA2ATextPart(part) {
|
|
32
31
|
const a2aPart = { kind: "text", text: part.text || "" };
|
|
33
|
-
if (
|
|
32
|
+
if (part.thought) {
|
|
34
33
|
a2aPart.metadata = {
|
|
35
|
-
[
|
|
34
|
+
[A2AMetadataKeys.THOUGHT]: true
|
|
36
35
|
};
|
|
37
36
|
}
|
|
38
37
|
return a2aPart;
|
|
39
38
|
}
|
|
40
39
|
function toA2AFilePart(part) {
|
|
40
|
+
const metadata = {};
|
|
41
|
+
if (part.videoMetadata) {
|
|
42
|
+
metadata[A2AMetadataKeys.VIDEO_METADATA] = part.videoMetadata;
|
|
43
|
+
}
|
|
41
44
|
if (part.fileData) {
|
|
42
45
|
return {
|
|
43
46
|
kind: "file",
|
|
@@ -45,7 +48,7 @@ function toA2AFilePart(part) {
|
|
|
45
48
|
uri: part.fileData.fileUri || "",
|
|
46
49
|
mimeType: part.fileData.mimeType
|
|
47
50
|
},
|
|
48
|
-
metadata
|
|
51
|
+
metadata
|
|
49
52
|
};
|
|
50
53
|
}
|
|
51
54
|
if (part.inlineData) {
|
|
@@ -55,37 +58,41 @@ function toA2AFilePart(part) {
|
|
|
55
58
|
bytes: part.inlineData.data || "",
|
|
56
59
|
mimeType: part.inlineData.mimeType
|
|
57
60
|
},
|
|
58
|
-
metadata
|
|
61
|
+
metadata
|
|
59
62
|
};
|
|
60
63
|
}
|
|
61
64
|
throw new Error(`Not a file part: ${JSON.stringify(part)}`);
|
|
62
65
|
}
|
|
63
66
|
function toA2ADataPart(part, longRunningToolIDs = []) {
|
|
64
|
-
let
|
|
67
|
+
let dataPartType;
|
|
65
68
|
let data;
|
|
66
69
|
if (part.functionCall) {
|
|
67
|
-
|
|
70
|
+
dataPartType = "function_call" /* FUNCTION_CALL */;
|
|
68
71
|
data = part.functionCall;
|
|
69
72
|
} else if (part.functionResponse) {
|
|
70
|
-
|
|
73
|
+
dataPartType = "function_response" /* FUNCTION_RESPONSE */;
|
|
71
74
|
data = part.functionResponse;
|
|
72
75
|
} else if (part.executableCode) {
|
|
73
|
-
|
|
76
|
+
dataPartType = "executable_code" /* CODE_EXECUTABLE_CODE */;
|
|
74
77
|
data = part.executableCode;
|
|
75
78
|
} else if (part.codeExecutionResult) {
|
|
76
|
-
|
|
79
|
+
dataPartType = "code_execution_result" /* CODE_EXEC_RESULT */;
|
|
77
80
|
data = part.codeExecutionResult;
|
|
78
81
|
} else {
|
|
79
|
-
|
|
82
|
+
return {
|
|
83
|
+
kind: "data",
|
|
84
|
+
data: {},
|
|
85
|
+
metadata: {}
|
|
86
|
+
};
|
|
80
87
|
}
|
|
81
88
|
const metadata = {
|
|
82
|
-
[
|
|
89
|
+
[A2AMetadataKeys.DATA_PART_TYPE]: dataPartType
|
|
83
90
|
};
|
|
84
|
-
if (part.functionCall && part.functionCall.
|
|
85
|
-
metadata[
|
|
91
|
+
if (part.functionCall && part.functionCall.id && longRunningToolIDs.includes(part.functionCall.id)) {
|
|
92
|
+
metadata[A2AMetadataKeys.IS_LONG_RUNNING] = true;
|
|
86
93
|
}
|
|
87
|
-
if (part.functionResponse && part.functionResponse.
|
|
88
|
-
metadata[
|
|
94
|
+
if (part.functionResponse && part.functionResponse.id && longRunningToolIDs.includes(part.functionResponse.id)) {
|
|
95
|
+
metadata[A2AMetadataKeys.IS_LONG_RUNNING] = true;
|
|
89
96
|
}
|
|
90
97
|
return {
|
|
91
98
|
kind: "data",
|
|
@@ -93,6 +100,10 @@ function toA2ADataPart(part, longRunningToolIDs = []) {
|
|
|
93
100
|
metadata
|
|
94
101
|
};
|
|
95
102
|
}
|
|
103
|
+
function toGenAIContent(a2aMessage) {
|
|
104
|
+
const parts = toGenAIParts(a2aMessage.parts);
|
|
105
|
+
return a2aMessage.role === "user" ? createUserContent(parts) : createModelContent(parts);
|
|
106
|
+
}
|
|
96
107
|
function toGenAIParts(a2aParts) {
|
|
97
108
|
return a2aParts.map((a2aPart) => toGenAIPart(a2aPart));
|
|
98
109
|
}
|
|
@@ -112,25 +123,28 @@ function toGenAIPartText(a2aPart) {
|
|
|
112
123
|
var _a;
|
|
113
124
|
return {
|
|
114
125
|
text: a2aPart.text,
|
|
115
|
-
thought: !!((_a = a2aPart.metadata) == null ? void 0 : _a[
|
|
126
|
+
thought: !!((_a = a2aPart.metadata) == null ? void 0 : _a[A2AMetadataKeys.THOUGHT])
|
|
116
127
|
};
|
|
117
128
|
}
|
|
118
129
|
function toGenAIPartFile(a2aPart) {
|
|
130
|
+
var _a;
|
|
131
|
+
const part = {};
|
|
132
|
+
if ((_a = a2aPart.metadata) == null ? void 0 : _a[A2AMetadataKeys.VIDEO_METADATA]) {
|
|
133
|
+
part.videoMetadata = a2aPart.metadata[A2AMetadataKeys.VIDEO_METADATA];
|
|
134
|
+
}
|
|
119
135
|
if ("bytes" in a2aPart.file) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
mimeType: a2aPart.file.mimeType || ""
|
|
124
|
-
}
|
|
136
|
+
part.inlineData = {
|
|
137
|
+
data: a2aPart.file.bytes,
|
|
138
|
+
mimeType: a2aPart.file.mimeType || ""
|
|
125
139
|
};
|
|
140
|
+
return part;
|
|
126
141
|
}
|
|
127
142
|
if ("uri" in a2aPart.file) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
mimeType: a2aPart.file.mimeType || ""
|
|
132
|
-
}
|
|
143
|
+
part.fileData = {
|
|
144
|
+
fileUri: a2aPart.file.uri,
|
|
145
|
+
mimeType: a2aPart.file.mimeType || ""
|
|
133
146
|
};
|
|
147
|
+
return part;
|
|
134
148
|
}
|
|
135
149
|
throw new Error(`Not a file part: ${JSON.stringify(a2aPart)}`);
|
|
136
150
|
}
|
|
@@ -140,7 +154,7 @@ function toGenAIPartData(a2aPart) {
|
|
|
140
154
|
throw new Error(`No data in part: ${JSON.stringify(a2aPart)}`);
|
|
141
155
|
}
|
|
142
156
|
const data = a2aPart.data;
|
|
143
|
-
const type = (_a = a2aPart.metadata) == null ? void 0 : _a[
|
|
157
|
+
const type = (_a = a2aPart.metadata) == null ? void 0 : _a[A2AMetadataKeys.DATA_PART_TYPE];
|
|
144
158
|
if (type === "function_call" /* FUNCTION_CALL */) {
|
|
145
159
|
return { functionCall: data };
|
|
146
160
|
}
|
|
@@ -163,6 +177,7 @@ export {
|
|
|
163
177
|
toA2APart,
|
|
164
178
|
toA2AParts,
|
|
165
179
|
toA2ATextPart,
|
|
180
|
+
toGenAIContent,
|
|
166
181
|
toGenAIPart,
|
|
167
182
|
toGenAIPartData,
|
|
168
183
|
toGenAIPartFile,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
traceAgentInvocation,
|
|
12
12
|
tracer
|
|
13
13
|
} from "../telemetry/tracing.js";
|
|
14
|
-
import {
|
|
14
|
+
import { Context } from "./context.js";
|
|
15
15
|
import { InvocationContext } from "./invocation_context.js";
|
|
16
16
|
const BASE_AGENT_SIGNATURE_SYMBOL = Symbol.for("google.adk.baseAgent");
|
|
17
17
|
function isBaseAgent(obj) {
|
|
@@ -153,7 +153,7 @@ class BaseAgent {
|
|
|
153
153
|
if (this.beforeAgentCallback.length === 0) {
|
|
154
154
|
return void 0;
|
|
155
155
|
}
|
|
156
|
-
const callbackContext = new
|
|
156
|
+
const callbackContext = new Context({ invocationContext });
|
|
157
157
|
for (const callback of this.beforeAgentCallback) {
|
|
158
158
|
const content = await callback(callbackContext);
|
|
159
159
|
if (content) {
|
|
@@ -188,7 +188,7 @@ class BaseAgent {
|
|
|
188
188
|
if (this.afterAgentCallback.length === 0) {
|
|
189
189
|
return void 0;
|
|
190
190
|
}
|
|
191
|
-
const callbackContext = new
|
|
191
|
+
const callbackContext = new Context({ invocationContext });
|
|
192
192
|
for (const callback of this.afterAgentCallback) {
|
|
193
193
|
const content = await callback(callbackContext);
|
|
194
194
|
if (content) {
|