@google/adk 0.3.0 → 0.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/a2a_event.js +290 -0
- package/dist/cjs/a2a/event_converter_utils.js +201 -0
- package/dist/cjs/a2a/executor_context.js +53 -0
- package/dist/cjs/a2a/metadata_converter_utils.js +125 -0
- package/dist/cjs/a2a/part_converter_utils.js +212 -0
- package/dist/cjs/agents/active_streaming_tool.js +1 -1
- package/dist/cjs/agents/base_agent.js +6 -6
- package/dist/cjs/agents/content_processor_utils.js +1 -1
- package/dist/cjs/{tools/tool_context.js → agents/context.js} +71 -16
- package/dist/cjs/agents/functions.js +4 -3
- package/dist/cjs/agents/instructions.js +1 -1
- package/dist/cjs/agents/invocation_context.js +1 -1
- package/dist/cjs/agents/live_request_queue.js +1 -1
- package/dist/cjs/agents/llm_agent.js +76 -711
- package/dist/cjs/agents/loop_agent.js +1 -1
- package/dist/cjs/agents/parallel_agent.js +1 -1
- package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +132 -0
- package/dist/cjs/agents/{base_llm_processor.js → processors/base_llm_processor.js} +1 -1
- 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/processors/content_request_processor.js +66 -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/agents/readonly_context.js +13 -1
- package/dist/cjs/agents/run_config.js +2 -1
- package/dist/cjs/agents/sequential_agent.js +1 -1
- package/dist/cjs/agents/transcription_entry.js +1 -1
- package/dist/cjs/artifacts/base_artifact_service.js +1 -1
- package/dist/cjs/artifacts/file_artifact_service.js +491 -0
- package/dist/cjs/artifacts/gcs_artifact_service.js +127 -48
- package/dist/cjs/artifacts/in_memory_artifact_service.js +54 -6
- package/dist/cjs/artifacts/registry.js +55 -0
- package/dist/cjs/auth/auth_credential.js +1 -1
- package/dist/cjs/auth/auth_handler.js +1 -1
- package/dist/cjs/auth/auth_schemes.js +1 -1
- package/dist/cjs/auth/auth_tool.js +1 -1
- package/dist/cjs/auth/credential_service/base_credential_service.js +1 -1
- package/dist/cjs/auth/credential_service/in_memory_credential_service.js +1 -1
- package/dist/cjs/auth/exchanger/base_credential_exchanger.js +1 -1
- package/dist/cjs/auth/exchanger/credential_exchanger_registry.js +1 -1
- package/dist/cjs/code_executors/base_code_executor.js +1 -1
- package/dist/cjs/code_executors/built_in_code_executor.js +1 -1
- package/dist/cjs/code_executors/code_execution_utils.js +1 -1
- package/dist/cjs/code_executors/code_executor_context.js +1 -1
- package/dist/cjs/common.js +25 -8
- package/dist/cjs/events/event.js +33 -4
- package/dist/cjs/events/event_actions.js +2 -2
- package/dist/cjs/events/structured_events.js +105 -0
- package/dist/cjs/examples/base_example_provider.js +1 -1
- package/dist/cjs/examples/example.js +1 -1
- package/dist/cjs/examples/example_util.js +1 -1
- package/dist/cjs/index.js +24 -17
- package/dist/cjs/index.js.map +4 -4
- package/dist/cjs/index_web.js +1 -1
- package/dist/cjs/memory/base_memory_service.js +1 -1
- package/dist/cjs/memory/in_memory_memory_service.js +1 -1
- package/dist/cjs/memory/memory_entry.js +1 -1
- package/dist/cjs/models/apigee_llm.js +182 -0
- package/dist/cjs/models/base_llm.js +1 -1
- package/dist/cjs/models/base_llm_connection.js +1 -1
- package/dist/cjs/models/gemini_llm_connection.js +1 -1
- package/dist/cjs/models/google_llm.js +70 -51
- package/dist/cjs/models/llm_request.js +1 -1
- package/dist/cjs/models/llm_response.js +3 -1
- package/dist/cjs/models/registry.js +3 -1
- package/dist/cjs/plugins/base_plugin.js +2 -2
- package/dist/cjs/plugins/logging_plugin.js +1 -1
- package/dist/cjs/plugins/plugin_manager.js +1 -1
- package/dist/cjs/plugins/security_plugin.js +1 -1
- package/dist/cjs/runner/in_memory_runner.js +1 -1
- package/dist/cjs/runner/runner.js +33 -2
- package/dist/cjs/sessions/base_session_service.js +53 -3
- package/dist/cjs/sessions/database_session_service.js +367 -0
- package/dist/cjs/sessions/db/operations.js +126 -0
- package/dist/cjs/sessions/db/schema.js +204 -0
- package/dist/cjs/sessions/in_memory_session_service.js +24 -22
- package/dist/cjs/sessions/registry.js +49 -0
- package/dist/cjs/sessions/session.js +1 -1
- package/dist/cjs/sessions/state.js +1 -1
- package/dist/cjs/telemetry/google_cloud.js +1 -1
- package/dist/cjs/telemetry/setup.js +1 -1
- package/dist/cjs/telemetry/tracing.js +1 -1
- package/dist/cjs/tools/agent_tool.js +1 -1
- package/dist/cjs/tools/base_tool.js +4 -1
- package/dist/cjs/tools/base_toolset.js +14 -4
- package/dist/cjs/tools/exit_loop_tool.js +63 -0
- package/dist/cjs/tools/forwarding_artifact_service.js +17 -1
- package/dist/cjs/tools/function_tool.js +1 -1
- package/dist/cjs/tools/google_search_tool.js +1 -1
- package/dist/cjs/tools/long_running_tool.js +1 -1
- package/dist/cjs/tools/mcp/mcp_session_manager.js +1 -1
- package/dist/cjs/tools/mcp/mcp_tool.js +1 -1
- package/dist/cjs/tools/mcp/mcp_toolset.js +10 -6
- package/dist/cjs/tools/tool_confirmation.js +1 -1
- package/dist/cjs/utils/client_labels.js +1 -1
- package/dist/cjs/utils/env_aware_utils.js +10 -1
- package/dist/cjs/utils/gemini_schema_util.js +1 -1
- package/dist/cjs/utils/logger.js +62 -55
- package/dist/cjs/utils/model_name.js +1 -1
- package/dist/cjs/utils/object_notation_utils.js +78 -0
- package/dist/cjs/utils/simple_zod_to_json.js +1 -1
- package/dist/cjs/utils/variant_utils.js +3 -9
- package/dist/cjs/version.js +2 -2
- package/dist/esm/a2a/a2a_event.js +243 -0
- package/dist/esm/a2a/event_converter_utils.js +187 -0
- package/dist/esm/a2a/executor_context.js +23 -0
- package/dist/esm/a2a/metadata_converter_utils.js +90 -0
- package/dist/esm/a2a/part_converter_utils.js +175 -0
- package/dist/esm/agents/base_agent.js +5 -5
- package/dist/esm/{tools/tool_context.js → agents/context.js} +66 -11
- package/dist/esm/agents/functions.js +3 -2
- package/dist/esm/agents/llm_agent.js +69 -720
- 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/processors/content_request_processor.js +38 -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/agents/readonly_context.js +12 -0
- package/dist/esm/agents/run_config.js +1 -0
- package/dist/esm/artifacts/file_artifact_service.js +451 -0
- package/dist/esm/artifacts/gcs_artifact_service.js +126 -47
- package/dist/esm/artifacts/in_memory_artifact_service.js +51 -4
- package/dist/esm/artifacts/registry.js +28 -0
- package/dist/esm/common.js +20 -10
- package/dist/esm/events/event.js +29 -2
- package/dist/esm/events/event_actions.js +1 -1
- package/dist/esm/events/structured_events.js +74 -0
- package/dist/esm/index.js +24 -17
- package/dist/esm/index.js.map +4 -4
- package/dist/esm/models/apigee_llm.js +152 -0
- package/dist/esm/models/google_llm.js +67 -49
- package/dist/esm/models/llm_response.js +2 -0
- package/dist/esm/models/registry.js +2 -0
- package/dist/esm/plugins/base_plugin.js +1 -1
- package/dist/esm/runner/runner.js +32 -1
- package/dist/esm/sessions/base_session_service.js +49 -1
- package/dist/esm/sessions/database_session_service.js +353 -0
- package/dist/esm/sessions/db/operations.js +111 -0
- package/dist/esm/sessions/db/schema.js +172 -0
- package/dist/esm/sessions/in_memory_session_service.js +23 -21
- package/dist/esm/sessions/registry.js +25 -0
- 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/forwarding_artifact_service.js +16 -0
- package/dist/esm/tools/mcp/mcp_toolset.js +9 -5
- package/dist/esm/utils/env_aware_utils.js +8 -0
- package/dist/esm/utils/logger.js +51 -54
- package/dist/esm/utils/object_notation_utils.js +47 -0
- package/dist/esm/utils/variant_utils.js +1 -7
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_event.d.ts +122 -0
- package/dist/types/a2a/event_converter_utils.d.ts +20 -0
- package/dist/types/a2a/executor_context.d.ts +33 -0
- package/dist/types/a2a/metadata_converter_utils.d.ts +62 -0
- package/dist/types/a2a/part_converter_utils.d.ts +48 -0
- 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 +19 -42
- 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/processors/content_request_processor.d.ts +13 -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/agents/readonly_context.d.ts +8 -0
- package/dist/types/agents/run_config.d.ts +6 -0
- package/dist/types/artifacts/base_artifact_service.d.ts +31 -0
- package/dist/types/artifacts/file_artifact_service.d.ts +43 -0
- package/dist/types/artifacts/gcs_artifact_service.d.ts +3 -1
- package/dist/types/artifacts/in_memory_artifact_service.d.ts +5 -2
- package/dist/types/artifacts/registry.d.ts +7 -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 +15 -6
- package/dist/types/events/event.d.ts +15 -1
- package/dist/types/events/event_actions.d.ts +1 -1
- package/dist/types/events/structured_events.d.ts +106 -0
- package/dist/types/index.d.ts +5 -1
- package/dist/types/models/apigee_llm.d.ts +59 -0
- package/dist/types/models/google_llm.d.ts +5 -2
- 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 +15 -0
- package/dist/types/sessions/base_session_service.d.ts +20 -0
- package/dist/types/sessions/database_session_service.d.ts +32 -0
- package/dist/types/sessions/db/operations.d.ts +29 -0
- package/dist/types/sessions/db/schema.d.ts +45 -0
- package/dist/types/sessions/in_memory_session_service.d.ts +4 -1
- package/dist/types/sessions/registry.d.ts +7 -0
- 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 +5 -3
- package/dist/types/tools/function_tool.d.ts +2 -2
- package/dist/types/tools/mcp/mcp_toolset.d.ts +1 -1
- package/dist/types/utils/env_aware_utils.d.ts +7 -0
- package/dist/types/utils/logger.d.ts +5 -9
- package/dist/types/utils/object_notation_utils.d.ts +21 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/a2a_event.js +243 -0
- package/dist/web/a2a/event_converter_utils.js +201 -0
- package/dist/web/a2a/executor_context.js +23 -0
- package/dist/web/a2a/metadata_converter_utils.js +107 -0
- package/dist/web/a2a/part_converter_utils.js +175 -0
- package/dist/web/agents/base_agent.js +5 -5
- package/dist/web/{tools/tool_context.js → agents/context.js} +66 -11
- package/dist/web/agents/functions.js +3 -2
- package/dist/web/agents/llm_agent.js +90 -717
- 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/processors/content_request_processor.js +56 -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/agents/readonly_context.js +12 -0
- package/dist/web/agents/run_config.js +2 -1
- package/dist/web/artifacts/file_artifact_service.js +506 -0
- package/dist/web/artifacts/gcs_artifact_service.js +123 -46
- package/dist/web/artifacts/in_memory_artifact_service.js +51 -4
- package/dist/web/artifacts/registry.js +28 -0
- package/dist/web/common.js +20 -10
- package/dist/web/events/event.js +29 -2
- package/dist/web/events/event_actions.js +1 -1
- package/dist/web/events/structured_events.js +74 -0
- package/dist/web/index.js +7 -2
- package/dist/web/index.js.map +4 -4
- package/dist/web/models/apigee_llm.js +219 -0
- package/dist/web/models/google_llm.js +67 -46
- package/dist/web/models/llm_response.js +2 -0
- package/dist/web/models/registry.js +2 -0
- package/dist/web/plugins/base_plugin.js +1 -1
- package/dist/web/runner/runner.js +34 -1
- package/dist/web/sessions/base_session_service.js +49 -1
- package/dist/web/sessions/database_session_service.js +371 -0
- package/dist/web/sessions/db/operations.js +111 -0
- package/dist/web/sessions/db/schema.js +172 -0
- package/dist/web/sessions/in_memory_session_service.js +23 -21
- package/dist/web/sessions/registry.js +25 -0
- 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/forwarding_artifact_service.js +16 -0
- package/dist/web/tools/mcp/mcp_toolset.js +27 -5
- package/dist/web/utils/env_aware_utils.js +8 -0
- package/dist/web/utils/logger.js +51 -54
- package/dist/web/utils/object_notation_utils.js +47 -0
- package/dist/web/utils/variant_utils.js +1 -7
- package/dist/web/version.js +1 -1
- package/package.json +13 -3
- 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/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,201 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
/**
|
|
21
|
+
* @license
|
|
22
|
+
* Copyright 2026 Google LLC
|
|
23
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
24
|
+
*/
|
|
25
|
+
import {
|
|
26
|
+
createModelContent,
|
|
27
|
+
createUserContent
|
|
28
|
+
} from "@google/genai";
|
|
29
|
+
import { createEvent } from "../events/event.js";
|
|
30
|
+
import { createEventActions } from "../events/event_actions.js";
|
|
31
|
+
import { randomUUID } from "../utils/env_aware_utils.js";
|
|
32
|
+
import {
|
|
33
|
+
getEventMetadata,
|
|
34
|
+
getFailedTaskStatusUpdateEventError,
|
|
35
|
+
isFailedTaskStatusUpdateEvent,
|
|
36
|
+
isInputRequiredTaskStatusUpdateEvent,
|
|
37
|
+
isMessage,
|
|
38
|
+
isTask,
|
|
39
|
+
isTaskArtifactUpdateEvent,
|
|
40
|
+
isTaskStatusUpdateEvent,
|
|
41
|
+
isTerminalTaskStatusUpdateEvent,
|
|
42
|
+
MessageRole
|
|
43
|
+
} from "./a2a_event.js";
|
|
44
|
+
import {
|
|
45
|
+
A2AMetadataKeys,
|
|
46
|
+
getA2AEventMetadata
|
|
47
|
+
} from "./metadata_converter_utils.js";
|
|
48
|
+
import { toA2AParts, toGenAIPart, toGenAIParts } from "./part_converter_utils.js";
|
|
49
|
+
function toA2AMessage(event, {
|
|
50
|
+
appName,
|
|
51
|
+
userId,
|
|
52
|
+
sessionId
|
|
53
|
+
}) {
|
|
54
|
+
var _a;
|
|
55
|
+
return {
|
|
56
|
+
kind: "message",
|
|
57
|
+
messageId: randomUUID(),
|
|
58
|
+
role: event.author === MessageRole.USER ? MessageRole.USER : MessageRole.AGENT,
|
|
59
|
+
parts: toA2AParts(((_a = event.content) == null ? void 0 : _a.parts) || [], event.longRunningToolIds),
|
|
60
|
+
metadata: getA2AEventMetadata(event, { appName, userId, sessionId })
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function toAdkEvent(event, invocationId, agentName) {
|
|
64
|
+
if (isMessage(event)) {
|
|
65
|
+
return messageToAdkEvent(event, invocationId, agentName);
|
|
66
|
+
}
|
|
67
|
+
if (isTask(event)) {
|
|
68
|
+
return taskToAdkEvent(event, invocationId, agentName);
|
|
69
|
+
}
|
|
70
|
+
if (isTaskArtifactUpdateEvent(event)) {
|
|
71
|
+
return artifactUpdateToAdkEvent(event, invocationId, agentName);
|
|
72
|
+
}
|
|
73
|
+
if (isTaskStatusUpdateEvent(event)) {
|
|
74
|
+
return event.final ? finalTaskStatusUpdateToAdkEvent(event, invocationId, agentName) : taskStatusUpdateToAdkEvent(event, invocationId, agentName);
|
|
75
|
+
}
|
|
76
|
+
return void 0;
|
|
77
|
+
}
|
|
78
|
+
function messageToAdkEvent(msg, invocationId, agentName, parentEvent) {
|
|
79
|
+
const parts = toGenAIParts(msg.parts);
|
|
80
|
+
return __spreadProps(__spreadValues({}, createAdkEventFromMetadata(parentEvent || msg)), {
|
|
81
|
+
invocationId,
|
|
82
|
+
author: msg.role === MessageRole.USER ? MessageRole.USER : agentName,
|
|
83
|
+
content: msg.role === MessageRole.USER ? createUserContent(parts) : createModelContent(parts),
|
|
84
|
+
turnComplete: true,
|
|
85
|
+
partial: false
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function artifactUpdateToAdkEvent(a2aEvent, invocationId, agentName) {
|
|
89
|
+
var _a;
|
|
90
|
+
const partsToConvert = ((_a = a2aEvent.artifact) == null ? void 0 : _a.parts) || [];
|
|
91
|
+
if (partsToConvert.length === 0) {
|
|
92
|
+
return void 0;
|
|
93
|
+
}
|
|
94
|
+
const partial = !!getEventMetadata(a2aEvent)[A2AMetadataKeys.PARTIAL] || a2aEvent.append || !a2aEvent.lastChunk;
|
|
95
|
+
return __spreadProps(__spreadValues({}, createAdkEventFromMetadata(a2aEvent)), {
|
|
96
|
+
invocationId,
|
|
97
|
+
author: agentName,
|
|
98
|
+
content: createModelContent(toGenAIParts(partsToConvert)),
|
|
99
|
+
longRunningToolIds: getLongRunningToolIDs(partsToConvert),
|
|
100
|
+
partial
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function finalTaskStatusUpdateToAdkEvent(a2aEvent, invocationId, agentName) {
|
|
104
|
+
var _a;
|
|
105
|
+
const partsToConvert = ((_a = a2aEvent.status.message) == null ? void 0 : _a.parts) || [];
|
|
106
|
+
if (partsToConvert.length === 0) {
|
|
107
|
+
return void 0;
|
|
108
|
+
}
|
|
109
|
+
const parts = toGenAIParts(partsToConvert);
|
|
110
|
+
const isFailedTask = isFailedTaskStatusUpdateEvent(a2aEvent);
|
|
111
|
+
const hasContent = !isFailedTask && parts.length > 0;
|
|
112
|
+
return __spreadProps(__spreadValues({}, createAdkEventFromMetadata(a2aEvent)), {
|
|
113
|
+
invocationId,
|
|
114
|
+
author: agentName,
|
|
115
|
+
errorMessage: isFailedTask ? getFailedTaskStatusUpdateEventError(a2aEvent) : void 0,
|
|
116
|
+
content: hasContent ? createModelContent(parts) : void 0,
|
|
117
|
+
longRunningToolIds: getLongRunningToolIDs(partsToConvert),
|
|
118
|
+
turnComplete: true
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function taskStatusUpdateToAdkEvent(a2aEvent, invocationId, agentName) {
|
|
122
|
+
const msg = a2aEvent.status.message;
|
|
123
|
+
if (!msg) {
|
|
124
|
+
return void 0;
|
|
125
|
+
}
|
|
126
|
+
const parts = toGenAIParts(msg.parts);
|
|
127
|
+
return __spreadProps(__spreadValues({}, createAdkEventFromMetadata(a2aEvent)), {
|
|
128
|
+
invocationId,
|
|
129
|
+
author: agentName,
|
|
130
|
+
content: createModelContent(parts),
|
|
131
|
+
turnComplete: false,
|
|
132
|
+
partial: true
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
function taskToAdkEvent(a2aTask, invocationId, agentName) {
|
|
136
|
+
var _a, _b;
|
|
137
|
+
const parts = [];
|
|
138
|
+
const longRunningToolIds = [];
|
|
139
|
+
if (a2aTask.artifacts) {
|
|
140
|
+
for (const artifact of a2aTask.artifacts) {
|
|
141
|
+
if (((_a = artifact.parts) == null ? void 0 : _a.length) > 0) {
|
|
142
|
+
const artifactParts = toGenAIParts(artifact.parts);
|
|
143
|
+
parts.push(...artifactParts);
|
|
144
|
+
longRunningToolIds.push(...getLongRunningToolIDs(artifact.parts));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if ((_b = a2aTask.status) == null ? void 0 : _b.message) {
|
|
149
|
+
const a2aParts = a2aTask.status.message.parts;
|
|
150
|
+
const genAIParts = toGenAIParts(a2aParts);
|
|
151
|
+
parts.push(...genAIParts);
|
|
152
|
+
longRunningToolIds.push(...getLongRunningToolIDs(a2aParts));
|
|
153
|
+
}
|
|
154
|
+
const isTerminal = isTerminalTaskStatusUpdateEvent(a2aTask) || isInputRequiredTaskStatusUpdateEvent(a2aTask);
|
|
155
|
+
const isFailed = isFailedTaskStatusUpdateEvent(a2aTask);
|
|
156
|
+
if (parts.length === 0 && !isTerminal) {
|
|
157
|
+
return void 0;
|
|
158
|
+
}
|
|
159
|
+
return __spreadProps(__spreadValues({}, createAdkEventFromMetadata(a2aTask)), {
|
|
160
|
+
invocationId,
|
|
161
|
+
author: agentName,
|
|
162
|
+
content: isFailed ? void 0 : createModelContent(parts),
|
|
163
|
+
errorMessage: isFailed ? getFailedTaskStatusUpdateEventError(a2aTask) : void 0,
|
|
164
|
+
longRunningToolIds,
|
|
165
|
+
turnComplete: isTerminal
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
function createAdkEventFromMetadata(a2aEvent) {
|
|
169
|
+
const metadata = a2aEvent.metadata || {};
|
|
170
|
+
return createEvent({
|
|
171
|
+
branch: metadata[A2AMetadataKeys.BRANCH],
|
|
172
|
+
author: metadata[A2AMetadataKeys.AUTHOR],
|
|
173
|
+
partial: metadata[A2AMetadataKeys.PARTIAL],
|
|
174
|
+
errorCode: metadata[A2AMetadataKeys.ERROR_CODE],
|
|
175
|
+
errorMessage: metadata[A2AMetadataKeys.ERROR_MESSAGE],
|
|
176
|
+
citationMetadata: metadata[A2AMetadataKeys.CITATION_METADATA],
|
|
177
|
+
groundingMetadata: metadata[A2AMetadataKeys.GROUNDING_METADATA],
|
|
178
|
+
usageMetadata: metadata[A2AMetadataKeys.USAGE_METADATA],
|
|
179
|
+
customMetadata: metadata[A2AMetadataKeys.CUSTOM_METADATA],
|
|
180
|
+
actions: createEventActions({
|
|
181
|
+
escalate: !!metadata[A2AMetadataKeys.ESCALATE],
|
|
182
|
+
transferToAgent: metadata[A2AMetadataKeys.TRANSFER_TO_AGENT]
|
|
183
|
+
})
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
function getLongRunningToolIDs(parts) {
|
|
187
|
+
const ids = [];
|
|
188
|
+
for (const a2aPart of parts) {
|
|
189
|
+
if (a2aPart.metadata && a2aPart.metadata[A2AMetadataKeys.IS_LONG_RUNNING]) {
|
|
190
|
+
const genAIPart = toGenAIPart(a2aPart);
|
|
191
|
+
if (genAIPart.functionCall && genAIPart.functionCall.id) {
|
|
192
|
+
ids.push(genAIPart.functionCall.id);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return ids;
|
|
197
|
+
}
|
|
198
|
+
export {
|
|
199
|
+
toA2AMessage,
|
|
200
|
+
toAdkEvent
|
|
201
|
+
};
|
|
@@ -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
|
+
agentName: session.appName,
|
|
15
|
+
readonlyState: session.state,
|
|
16
|
+
events: session.events,
|
|
17
|
+
userContent,
|
|
18
|
+
requestContext
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
createExecutorContext
|
|
23
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
/**
|
|
21
|
+
* @license
|
|
22
|
+
* Copyright 2026 Google LLC
|
|
23
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
24
|
+
*/
|
|
25
|
+
import { isTask } from "./a2a_event.js";
|
|
26
|
+
const ADK_METADATA_KEY_PREFIX = "adk_";
|
|
27
|
+
const A2A_METADATA_KEY_PREFIX = "a2a:";
|
|
28
|
+
var A2AMetadataKeys = ((A2AMetadataKeys2) => {
|
|
29
|
+
A2AMetadataKeys2[A2AMetadataKeys2["APP_NAME"] = "".concat(ADK_METADATA_KEY_PREFIX, "app_name")] = "APP_NAME";
|
|
30
|
+
A2AMetadataKeys2[A2AMetadataKeys2["USER_ID"] = "".concat(ADK_METADATA_KEY_PREFIX, "user_id")] = "USER_ID";
|
|
31
|
+
A2AMetadataKeys2[A2AMetadataKeys2["SESSION_ID"] = "".concat(ADK_METADATA_KEY_PREFIX, "session_id")] = "SESSION_ID";
|
|
32
|
+
A2AMetadataKeys2[A2AMetadataKeys2["INVOCATION_ID"] = "".concat(ADK_METADATA_KEY_PREFIX, "invocation_id")] = "INVOCATION_ID";
|
|
33
|
+
A2AMetadataKeys2[A2AMetadataKeys2["AUTHOR"] = "".concat(ADK_METADATA_KEY_PREFIX, "author")] = "AUTHOR";
|
|
34
|
+
A2AMetadataKeys2[A2AMetadataKeys2["BRANCH"] = "".concat(ADK_METADATA_KEY_PREFIX, "branch")] = "BRANCH";
|
|
35
|
+
A2AMetadataKeys2[A2AMetadataKeys2["DATA_PART_TYPE"] = "".concat(ADK_METADATA_KEY_PREFIX, "type")] = "DATA_PART_TYPE";
|
|
36
|
+
A2AMetadataKeys2[A2AMetadataKeys2["PARTIAL"] = "".concat(ADK_METADATA_KEY_PREFIX, "partial")] = "PARTIAL";
|
|
37
|
+
A2AMetadataKeys2[A2AMetadataKeys2["ESCALATE"] = "".concat(ADK_METADATA_KEY_PREFIX, "escalate")] = "ESCALATE";
|
|
38
|
+
A2AMetadataKeys2[A2AMetadataKeys2["TRANSFER_TO_AGENT"] = "".concat(ADK_METADATA_KEY_PREFIX, "transfer_to_agent")] = "TRANSFER_TO_AGENT";
|
|
39
|
+
A2AMetadataKeys2[A2AMetadataKeys2["IS_LONG_RUNNING"] = "".concat(ADK_METADATA_KEY_PREFIX, "is_long_running")] = "IS_LONG_RUNNING";
|
|
40
|
+
A2AMetadataKeys2[A2AMetadataKeys2["THOUGHT"] = "".concat(ADK_METADATA_KEY_PREFIX, "thought")] = "THOUGHT";
|
|
41
|
+
A2AMetadataKeys2[A2AMetadataKeys2["ERROR_CODE"] = "".concat(ADK_METADATA_KEY_PREFIX, "error_code")] = "ERROR_CODE";
|
|
42
|
+
A2AMetadataKeys2[A2AMetadataKeys2["ERROR_MESSAGE"] = "".concat(ADK_METADATA_KEY_PREFIX, "error_message")] = "ERROR_MESSAGE";
|
|
43
|
+
A2AMetadataKeys2[A2AMetadataKeys2["CITATION_METADATA"] = "".concat(ADK_METADATA_KEY_PREFIX, "citation_metadata")] = "CITATION_METADATA";
|
|
44
|
+
A2AMetadataKeys2[A2AMetadataKeys2["GROUNDING_METADATA"] = "".concat(ADK_METADATA_KEY_PREFIX, "grounding_metadata")] = "GROUNDING_METADATA";
|
|
45
|
+
A2AMetadataKeys2[A2AMetadataKeys2["USAGE_METADATA"] = "".concat(ADK_METADATA_KEY_PREFIX, "usage_metadata")] = "USAGE_METADATA";
|
|
46
|
+
A2AMetadataKeys2[A2AMetadataKeys2["CUSTOM_METADATA"] = "".concat(ADK_METADATA_KEY_PREFIX, "custom_metadata")] = "CUSTOM_METADATA";
|
|
47
|
+
return A2AMetadataKeys2;
|
|
48
|
+
})(A2AMetadataKeys || {});
|
|
49
|
+
var AdkMetadataKeys = ((AdkMetadataKeys2) => {
|
|
50
|
+
AdkMetadataKeys2[AdkMetadataKeys2["TASK_ID"] = "".concat(A2A_METADATA_KEY_PREFIX, "task_id")] = "TASK_ID";
|
|
51
|
+
AdkMetadataKeys2[AdkMetadataKeys2["CONTEXT_ID"] = "".concat(A2A_METADATA_KEY_PREFIX, "context_id")] = "CONTEXT_ID";
|
|
52
|
+
return AdkMetadataKeys2;
|
|
53
|
+
})(AdkMetadataKeys || {});
|
|
54
|
+
function getAdkEventMetadata(a2aEvent) {
|
|
55
|
+
return {
|
|
56
|
+
[AdkMetadataKeys.TASK_ID]: isTask(a2aEvent) ? a2aEvent.id : a2aEvent.taskId,
|
|
57
|
+
[AdkMetadataKeys.CONTEXT_ID]: a2aEvent.contextId
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function getA2AEventMetadata(adkEvent, {
|
|
61
|
+
appName,
|
|
62
|
+
userId,
|
|
63
|
+
sessionId
|
|
64
|
+
}) {
|
|
65
|
+
return __spreadProps(__spreadValues(__spreadValues({}, getA2AEventMetadataFromActions(adkEvent.actions)), getA2ASessionMetadata({
|
|
66
|
+
appName,
|
|
67
|
+
userId,
|
|
68
|
+
sessionId
|
|
69
|
+
})), {
|
|
70
|
+
[A2AMetadataKeys.INVOCATION_ID]: adkEvent.invocationId,
|
|
71
|
+
[A2AMetadataKeys.AUTHOR]: adkEvent.author,
|
|
72
|
+
[A2AMetadataKeys.BRANCH]: adkEvent.branch,
|
|
73
|
+
[A2AMetadataKeys.ERROR_CODE]: adkEvent.errorMessage,
|
|
74
|
+
[A2AMetadataKeys.ERROR_MESSAGE]: adkEvent.errorMessage,
|
|
75
|
+
[A2AMetadataKeys.CITATION_METADATA]: adkEvent.citationMetadata,
|
|
76
|
+
[A2AMetadataKeys.GROUNDING_METADATA]: adkEvent.groundingMetadata,
|
|
77
|
+
[A2AMetadataKeys.USAGE_METADATA]: adkEvent.usageMetadata,
|
|
78
|
+
[A2AMetadataKeys.CUSTOM_METADATA]: adkEvent.customMetadata,
|
|
79
|
+
[A2AMetadataKeys.PARTIAL]: adkEvent.partial,
|
|
80
|
+
[A2AMetadataKeys.IS_LONG_RUNNING]: (adkEvent.longRunningToolIds || []).length > 0
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function getA2ASessionMetadata({
|
|
84
|
+
appName,
|
|
85
|
+
userId,
|
|
86
|
+
sessionId
|
|
87
|
+
}) {
|
|
88
|
+
return {
|
|
89
|
+
[A2AMetadataKeys.APP_NAME]: appName,
|
|
90
|
+
[A2AMetadataKeys.USER_ID]: userId,
|
|
91
|
+
[A2AMetadataKeys.SESSION_ID]: sessionId
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function getA2AEventMetadataFromActions(actions) {
|
|
95
|
+
return {
|
|
96
|
+
[A2AMetadataKeys.ESCALATE]: actions.escalate,
|
|
97
|
+
[A2AMetadataKeys.TRANSFER_TO_AGENT]: actions.transferToAgent
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
export {
|
|
101
|
+
A2AMetadataKeys,
|
|
102
|
+
AdkMetadataKeys,
|
|
103
|
+
getA2AEventMetadata,
|
|
104
|
+
getA2AEventMetadataFromActions,
|
|
105
|
+
getA2ASessionMetadata,
|
|
106
|
+
getAdkEventMetadata
|
|
107
|
+
};
|
|
@@ -0,0 +1,175 @@
|
|
|
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 { A2AMetadataKeys } from "./metadata_converter_utils.js";
|
|
11
|
+
var DataPartType = /* @__PURE__ */ ((DataPartType2) => {
|
|
12
|
+
DataPartType2["FUNCTION_CALL"] = "function_call";
|
|
13
|
+
DataPartType2["FUNCTION_RESPONSE"] = "function_response";
|
|
14
|
+
DataPartType2["CODE_EXEC_RESULT"] = "code_execution_result";
|
|
15
|
+
DataPartType2["CODE_EXECUTABLE_CODE"] = "executable_code";
|
|
16
|
+
return DataPartType2;
|
|
17
|
+
})(DataPartType || {});
|
|
18
|
+
function toA2AParts(parts = [], longRunningToolIDs = []) {
|
|
19
|
+
return parts.map((part) => toA2APart(part, longRunningToolIDs));
|
|
20
|
+
}
|
|
21
|
+
function toA2APart(part, longRunningToolIDs) {
|
|
22
|
+
if (part.text !== void 0 && part.text !== null) {
|
|
23
|
+
return toA2ATextPart(part);
|
|
24
|
+
}
|
|
25
|
+
if (part.inlineData || part.fileData) {
|
|
26
|
+
return toA2AFilePart(part);
|
|
27
|
+
}
|
|
28
|
+
return toA2ADataPart(part, longRunningToolIDs);
|
|
29
|
+
}
|
|
30
|
+
function toA2ATextPart(part) {
|
|
31
|
+
const a2aPart = { kind: "text", text: part.text || "" };
|
|
32
|
+
if (part.thought) {
|
|
33
|
+
a2aPart.metadata = {
|
|
34
|
+
[A2AMetadataKeys.THOUGHT]: true
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return a2aPart;
|
|
38
|
+
}
|
|
39
|
+
function toA2AFilePart(part) {
|
|
40
|
+
if (part.fileData) {
|
|
41
|
+
return {
|
|
42
|
+
kind: "file",
|
|
43
|
+
file: {
|
|
44
|
+
uri: part.fileData.fileUri || "",
|
|
45
|
+
mimeType: part.fileData.mimeType
|
|
46
|
+
},
|
|
47
|
+
metadata: {}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (part.inlineData) {
|
|
51
|
+
return {
|
|
52
|
+
kind: "file",
|
|
53
|
+
file: {
|
|
54
|
+
bytes: part.inlineData.data || "",
|
|
55
|
+
mimeType: part.inlineData.mimeType
|
|
56
|
+
},
|
|
57
|
+
metadata: {}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
throw new Error("Not a file part: ".concat(JSON.stringify(part)));
|
|
61
|
+
}
|
|
62
|
+
function toA2ADataPart(part, longRunningToolIDs = []) {
|
|
63
|
+
let dataPartType;
|
|
64
|
+
let data;
|
|
65
|
+
if (part.functionCall) {
|
|
66
|
+
dataPartType = "function_call" /* FUNCTION_CALL */;
|
|
67
|
+
data = part.functionCall;
|
|
68
|
+
} else if (part.functionResponse) {
|
|
69
|
+
dataPartType = "function_response" /* FUNCTION_RESPONSE */;
|
|
70
|
+
data = part.functionResponse;
|
|
71
|
+
} else if (part.executableCode) {
|
|
72
|
+
dataPartType = "executable_code" /* CODE_EXECUTABLE_CODE */;
|
|
73
|
+
data = part.executableCode;
|
|
74
|
+
} else if (part.codeExecutionResult) {
|
|
75
|
+
dataPartType = "code_execution_result" /* CODE_EXEC_RESULT */;
|
|
76
|
+
data = part.codeExecutionResult;
|
|
77
|
+
} else {
|
|
78
|
+
throw new Error("Unknown part type: ".concat(JSON.stringify(part)));
|
|
79
|
+
}
|
|
80
|
+
const metadata = {
|
|
81
|
+
[A2AMetadataKeys.DATA_PART_TYPE]: dataPartType
|
|
82
|
+
};
|
|
83
|
+
if (part.functionCall && part.functionCall.id && longRunningToolIDs.includes(part.functionCall.id)) {
|
|
84
|
+
metadata[A2AMetadataKeys.IS_LONG_RUNNING] = true;
|
|
85
|
+
}
|
|
86
|
+
if (part.functionResponse && part.functionResponse.id && longRunningToolIDs.includes(part.functionResponse.id)) {
|
|
87
|
+
metadata[A2AMetadataKeys.IS_LONG_RUNNING] = true;
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
kind: "data",
|
|
91
|
+
data,
|
|
92
|
+
metadata
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function toGenAIContent(a2aMessage) {
|
|
96
|
+
const parts = toGenAIParts(a2aMessage.parts);
|
|
97
|
+
return a2aMessage.role === "user" ? createUserContent(parts) : createModelContent(parts);
|
|
98
|
+
}
|
|
99
|
+
function toGenAIParts(a2aParts) {
|
|
100
|
+
return a2aParts.map((a2aPart) => toGenAIPart(a2aPart));
|
|
101
|
+
}
|
|
102
|
+
function toGenAIPart(a2aPart) {
|
|
103
|
+
if (a2aPart.kind === "text") {
|
|
104
|
+
return toGenAIPartText(a2aPart);
|
|
105
|
+
}
|
|
106
|
+
if (a2aPart.kind === "file") {
|
|
107
|
+
return toGenAIPartFile(a2aPart);
|
|
108
|
+
}
|
|
109
|
+
if (a2aPart.kind === "data") {
|
|
110
|
+
return toGenAIPartData(a2aPart);
|
|
111
|
+
}
|
|
112
|
+
throw new Error("Unknown part kind: ".concat(JSON.stringify(a2aPart)));
|
|
113
|
+
}
|
|
114
|
+
function toGenAIPartText(a2aPart) {
|
|
115
|
+
var _a;
|
|
116
|
+
return {
|
|
117
|
+
text: a2aPart.text,
|
|
118
|
+
thought: !!((_a = a2aPart.metadata) == null ? void 0 : _a[A2AMetadataKeys.THOUGHT])
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function toGenAIPartFile(a2aPart) {
|
|
122
|
+
if ("bytes" in a2aPart.file) {
|
|
123
|
+
return {
|
|
124
|
+
inlineData: {
|
|
125
|
+
data: a2aPart.file.bytes,
|
|
126
|
+
mimeType: a2aPart.file.mimeType || ""
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
if ("uri" in a2aPart.file) {
|
|
131
|
+
return {
|
|
132
|
+
fileData: {
|
|
133
|
+
fileUri: a2aPart.file.uri,
|
|
134
|
+
mimeType: a2aPart.file.mimeType || ""
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
throw new Error("Not a file part: ".concat(JSON.stringify(a2aPart)));
|
|
139
|
+
}
|
|
140
|
+
function toGenAIPartData(a2aPart) {
|
|
141
|
+
var _a;
|
|
142
|
+
if (!a2aPart.data) {
|
|
143
|
+
throw new Error("No data in part: ".concat(JSON.stringify(a2aPart)));
|
|
144
|
+
}
|
|
145
|
+
const data = a2aPart.data;
|
|
146
|
+
const type = (_a = a2aPart.metadata) == null ? void 0 : _a[A2AMetadataKeys.DATA_PART_TYPE];
|
|
147
|
+
if (type === "function_call" /* FUNCTION_CALL */) {
|
|
148
|
+
return { functionCall: data };
|
|
149
|
+
}
|
|
150
|
+
if (type === "function_response" /* FUNCTION_RESPONSE */) {
|
|
151
|
+
return { functionResponse: data };
|
|
152
|
+
}
|
|
153
|
+
if (type === "executable_code" /* CODE_EXECUTABLE_CODE */) {
|
|
154
|
+
return { executableCode: data };
|
|
155
|
+
}
|
|
156
|
+
if (type === "code_execution_result" /* CODE_EXEC_RESULT */) {
|
|
157
|
+
return { codeExecutionResult: data };
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
text: JSON.stringify(a2aPart.data)
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
export {
|
|
164
|
+
toA2ADataPart,
|
|
165
|
+
toA2AFilePart,
|
|
166
|
+
toA2APart,
|
|
167
|
+
toA2AParts,
|
|
168
|
+
toA2ATextPart,
|
|
169
|
+
toGenAIContent,
|
|
170
|
+
toGenAIPart,
|
|
171
|
+
toGenAIPartData,
|
|
172
|
+
toGenAIPartFile,
|
|
173
|
+
toGenAIPartText,
|
|
174
|
+
toGenAIParts
|
|
175
|
+
};
|
|
@@ -78,7 +78,7 @@ import {
|
|
|
78
78
|
traceAgentInvocation,
|
|
79
79
|
tracer
|
|
80
80
|
} from "../telemetry/tracing.js";
|
|
81
|
-
import {
|
|
81
|
+
import { Context } from "./context.js";
|
|
82
82
|
import { InvocationContext } from "./invocation_context.js";
|
|
83
83
|
const BASE_AGENT_SIGNATURE_SYMBOL = Symbol.for("google.adk.baseAgent");
|
|
84
84
|
function isBaseAgent(obj) {
|
|
@@ -239,7 +239,7 @@ class BaseAgent {
|
|
|
239
239
|
if (this.beforeAgentCallback.length === 0) {
|
|
240
240
|
return void 0;
|
|
241
241
|
}
|
|
242
|
-
const callbackContext = new
|
|
242
|
+
const callbackContext = new Context({ invocationContext });
|
|
243
243
|
for (const callback of this.beforeAgentCallback) {
|
|
244
244
|
const content = await callback(callbackContext);
|
|
245
245
|
if (content) {
|
|
@@ -274,7 +274,7 @@ class BaseAgent {
|
|
|
274
274
|
if (this.afterAgentCallback.length === 0) {
|
|
275
275
|
return void 0;
|
|
276
276
|
}
|
|
277
|
-
const callbackContext = new
|
|
277
|
+
const callbackContext = new Context({ invocationContext });
|
|
278
278
|
for (const callback of this.afterAgentCallback) {
|
|
279
279
|
const content = await callback(callbackContext);
|
|
280
280
|
if (content) {
|
|
@@ -311,7 +311,7 @@ class BaseAgent {
|
|
|
311
311
|
function validateAgentName(name) {
|
|
312
312
|
if (!isIdentifier(name)) {
|
|
313
313
|
throw new Error(
|
|
314
|
-
'Found invalid agent name: "'.concat(name, '". Agent name must be a valid identifier. It should start with a letter (a-z, A-Z) or an underscore (_), and can only contain letters, digits (0-9), and
|
|
314
|
+
'Found invalid agent name: "'.concat(name, '". Agent name must be a valid identifier. It should start with a letter (a-z, A-Z) or an underscore (_), and can only contain letters, digits (0-9), underscores, and hyphens.')
|
|
315
315
|
);
|
|
316
316
|
}
|
|
317
317
|
if (name === "user") {
|
|
@@ -322,7 +322,7 @@ function validateAgentName(name) {
|
|
|
322
322
|
return name;
|
|
323
323
|
}
|
|
324
324
|
function isIdentifier(str) {
|
|
325
|
-
return new RegExp("^[\\p{ID_Start}$_][\\p{ID_Continue}$_]*$", "u").test(str);
|
|
325
|
+
return new RegExp("^[\\p{ID_Start}$_][\\p{ID_Continue}$_-]*$", "u").test(str);
|
|
326
326
|
}
|
|
327
327
|
function getRootAgent(rootAgent) {
|
|
328
328
|
while (rootAgent.parentAgent) {
|
|
@@ -3,29 +3,84 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import { CallbackContext } from "../agents/callback_context.js";
|
|
7
6
|
import { AuthHandler } from "../auth/auth_handler.js";
|
|
7
|
+
import { createEventActions } from "../events/event_actions.js";
|
|
8
|
+
import { State } from "../sessions/state.js";
|
|
8
9
|
import { ToolConfirmation } from "../tools/tool_confirmation.js";
|
|
9
|
-
|
|
10
|
+
import { ReadonlyContext } from "./readonly_context.js";
|
|
11
|
+
class Context extends ReadonlyContext {
|
|
10
12
|
/**
|
|
11
|
-
* @param
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
13
|
+
* @param options The configuration options for the Context.
|
|
14
|
+
* @param options.invocationContext The invocation context.
|
|
15
|
+
* @param options.eventActions The event actions of the current call.
|
|
16
|
+
* @param options.functionCallId The function call id of the current tool call.
|
|
14
17
|
* This id was returned in the function call event from LLM to identify a
|
|
15
18
|
* function call. If LLM didn't return this id, ADK will assign one to it.
|
|
16
19
|
* This id is used to map function call response to the original function
|
|
17
20
|
* call.
|
|
18
|
-
* @param
|
|
21
|
+
* @param options.toolConfirmation The tool confirmation of the current tool
|
|
19
22
|
* call.
|
|
20
23
|
*/
|
|
21
|
-
constructor(
|
|
22
|
-
super(
|
|
23
|
-
this.
|
|
24
|
-
this.
|
|
24
|
+
constructor(options) {
|
|
25
|
+
super(options.invocationContext);
|
|
26
|
+
this.eventActions = options.eventActions || createEventActions();
|
|
27
|
+
this._state = new State(
|
|
28
|
+
options.invocationContext.session.state,
|
|
29
|
+
this.eventActions.stateDelta
|
|
30
|
+
);
|
|
31
|
+
this.functionCallId = options.functionCallId;
|
|
32
|
+
this.toolConfirmation = options.toolConfirmation;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The delta-aware state of the current session.
|
|
36
|
+
*/
|
|
37
|
+
get state() {
|
|
38
|
+
return this._state;
|
|
25
39
|
}
|
|
26
40
|
get actions() {
|
|
27
41
|
return this.eventActions;
|
|
28
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Loads an artifact attached to the current session.
|
|
45
|
+
*
|
|
46
|
+
* @param filename The filename of the artifact.
|
|
47
|
+
* @param version The version of the artifact. If not provided, the latest
|
|
48
|
+
* version will be used.
|
|
49
|
+
* @return A promise that resolves to the loaded artifact.
|
|
50
|
+
*/
|
|
51
|
+
loadArtifact(filename, version) {
|
|
52
|
+
if (!this.invocationContext.artifactService) {
|
|
53
|
+
throw new Error("Artifact service is not initialized.");
|
|
54
|
+
}
|
|
55
|
+
return this.invocationContext.artifactService.loadArtifact({
|
|
56
|
+
appName: this.invocationContext.appName,
|
|
57
|
+
userId: this.invocationContext.userId,
|
|
58
|
+
sessionId: this.invocationContext.session.id,
|
|
59
|
+
filename,
|
|
60
|
+
version
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Saves an artifact attached to the current session.
|
|
65
|
+
*
|
|
66
|
+
* @param filename The filename of the artifact.
|
|
67
|
+
* @param artifact The artifact to save.
|
|
68
|
+
* @return A promise that resolves to the version of the saved artifact.
|
|
69
|
+
*/
|
|
70
|
+
async saveArtifact(filename, artifact) {
|
|
71
|
+
if (!this.invocationContext.artifactService) {
|
|
72
|
+
throw new Error("Artifact service is not initialized.");
|
|
73
|
+
}
|
|
74
|
+
const version = await this.invocationContext.artifactService.saveArtifact({
|
|
75
|
+
appName: this.invocationContext.appName,
|
|
76
|
+
userId: this.invocationContext.userId,
|
|
77
|
+
sessionId: this.invocationContext.session.id,
|
|
78
|
+
filename,
|
|
79
|
+
artifact
|
|
80
|
+
});
|
|
81
|
+
this.eventActions.artifactDelta[filename] = version;
|
|
82
|
+
return version;
|
|
83
|
+
}
|
|
29
84
|
requestCredential(authConfig) {
|
|
30
85
|
if (!this.functionCallId) {
|
|
31
86
|
throw new Error("functionCallId is not set.");
|
|
@@ -90,5 +145,5 @@ class ToolContext extends CallbackContext {
|
|
|
90
145
|
}
|
|
91
146
|
}
|
|
92
147
|
export {
|
|
93
|
-
|
|
148
|
+
Context
|
|
94
149
|
};
|
|
@@ -7,9 +7,9 @@ import { createUserContent } from "@google/genai";
|
|
|
7
7
|
import { isEmpty } from "lodash-es";
|
|
8
8
|
import { createEvent, getFunctionCalls } from "../events/event.js";
|
|
9
9
|
import { mergeEventActions } from "../events/event_actions.js";
|
|
10
|
-
import { ToolContext } from "../tools/tool_context.js";
|
|
11
10
|
import { randomUUID } from "../utils/env_aware_utils.js";
|
|
12
11
|
import { logger } from "../utils/logger.js";
|
|
12
|
+
import { Context } from "./context.js";
|
|
13
13
|
import {
|
|
14
14
|
traceMergedToolCalls,
|
|
15
15
|
tracer,
|
|
@@ -128,6 +128,7 @@ function generateRequestConfirmationEvent({
|
|
|
128
128
|
parts,
|
|
129
129
|
role: functionResponseEvent.content.role
|
|
130
130
|
},
|
|
131
|
+
actions: functionResponseEvent.actions,
|
|
131
132
|
longRunningToolIds: Array.from(longRunningToolIds)
|
|
132
133
|
});
|
|
133
134
|
}
|
|
@@ -351,7 +352,7 @@ function getToolAndContext({
|
|
|
351
352
|
"Function ".concat(functionCall.name, " is not found in the toolsDict.")
|
|
352
353
|
);
|
|
353
354
|
}
|
|
354
|
-
const toolContext = new
|
|
355
|
+
const toolContext = new Context({
|
|
355
356
|
invocationContext,
|
|
356
357
|
functionCallId: functionCall.id || void 0,
|
|
357
358
|
toolConfirmation
|