@google/adk 0.2.5 → 0.4.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/part_converter_utils.js +210 -0
- package/dist/cjs/agents/active_streaming_tool.js +1 -1
- package/dist/cjs/agents/base_agent.js +46 -24
- package/dist/cjs/agents/base_llm_processor.js +1 -1
- package/dist/cjs/agents/callback_context.js +5 -2
- package/dist/cjs/agents/content_processor_utils.js +16 -8
- package/dist/cjs/agents/functions.js +81 -30
- 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 +106 -62
- package/dist/cjs/agents/loop_agent.js +3 -2
- package/dist/cjs/agents/parallel_agent.js +4 -5
- 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 +145 -58
- package/dist/cjs/artifacts/in_memory_artifact_service.js +72 -10
- package/dist/cjs/artifacts/registry.js +55 -0
- package/dist/cjs/auth/auth_credential.js +1 -1
- package/dist/cjs/auth/auth_handler.js +4 -2
- 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 +4 -2
- package/dist/cjs/code_executors/built_in_code_executor.js +8 -4
- package/dist/cjs/code_executors/code_execution_utils.js +1 -1
- package/dist/cjs/code_executors/code_executor_context.js +6 -6
- package/dist/cjs/common.js +18 -1
- package/dist/cjs/events/event.js +34 -7
- 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 +54 -83
- 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 +4 -2
- 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 +9 -5
- package/dist/cjs/models/base_llm_connection.js +1 -1
- package/dist/cjs/models/gemini_llm_connection.js +2 -1
- package/dist/cjs/models/google_llm.js +73 -54
- package/dist/cjs/models/llm_request.js +1 -1
- package/dist/cjs/models/llm_response.js +1 -1
- package/dist/cjs/models/registry.js +3 -1
- package/dist/cjs/plugins/base_plugin.js +13 -1
- package/dist/cjs/plugins/logging_plugin.js +51 -14
- package/dist/cjs/plugins/plugin_manager.js +57 -25
- package/dist/cjs/plugins/security_plugin.js +2 -2
- package/dist/cjs/runner/in_memory_runner.js +1 -1
- package/dist/cjs/runner/runner.js +142 -96
- package/dist/cjs/sessions/base_session_service.js +53 -3
- package/dist/cjs/sessions/database_session_service.js +364 -0
- package/dist/cjs/sessions/db/operations.js +114 -0
- package/dist/cjs/sessions/db/schema.js +204 -0
- package/dist/cjs/sessions/in_memory_session_service.js +60 -34
- 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 +8 -10
- package/dist/cjs/telemetry/setup.js +16 -8
- package/dist/cjs/telemetry/tracing.js +38 -16
- package/dist/cjs/tools/agent_tool.js +9 -5
- package/dist/cjs/tools/base_tool.js +5 -3
- package/dist/cjs/tools/base_toolset.js +1 -1
- package/dist/cjs/tools/forwarding_artifact_service.js +18 -2
- package/dist/cjs/tools/function_tool.js +2 -3
- package/dist/cjs/tools/google_search_tool.js +2 -3
- package/dist/cjs/tools/long_running_tool.js +1 -1
- package/dist/cjs/tools/mcp/mcp_session_manager.js +17 -11
- package/dist/cjs/tools/mcp/mcp_tool.js +2 -4
- package/dist/cjs/tools/mcp/mcp_toolset.js +2 -2
- package/dist/cjs/tools/tool_confirmation.js +1 -1
- package/dist/cjs/tools/tool_context.js +1 -1
- package/dist/cjs/utils/client_labels.js +1 -1
- package/dist/cjs/utils/env_aware_utils.js +11 -2
- package/dist/cjs/utils/gemini_schema_util.js +10 -5
- package/dist/cjs/utils/logger.js +48 -4
- 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 +101 -142
- package/dist/cjs/utils/variant_utils.js +3 -9
- package/dist/cjs/version.js +2 -2
- package/dist/esm/a2a/part_converter_utils.js +171 -0
- package/dist/esm/agents/base_agent.js +50 -24
- package/dist/esm/agents/callback_context.js +4 -1
- package/dist/esm/agents/content_processor_utils.js +25 -9
- package/dist/esm/agents/functions.js +84 -29
- package/dist/esm/agents/llm_agent.js +110 -62
- package/dist/esm/agents/loop_agent.js +2 -1
- package/dist/esm/agents/parallel_agent.js +3 -4
- 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 +144 -57
- package/dist/esm/artifacts/in_memory_artifact_service.js +69 -8
- package/dist/esm/artifacts/registry.js +28 -0
- package/dist/esm/auth/auth_handler.js +3 -1
- package/dist/esm/code_executors/base_code_executor.js +3 -1
- package/dist/esm/code_executors/built_in_code_executor.js +7 -3
- package/dist/esm/code_executors/code_executor_context.js +5 -5
- package/dist/esm/common.js +12 -2
- package/dist/esm/events/event.js +30 -5
- package/dist/esm/events/event_actions.js +1 -1
- package/dist/esm/events/structured_events.js +74 -0
- package/dist/esm/index.js +18 -88
- package/dist/esm/memory/in_memory_memory_service.js +3 -1
- package/dist/esm/models/apigee_llm.js +152 -0
- package/dist/esm/models/base_llm.js +8 -4
- package/dist/esm/models/gemini_llm_connection.js +1 -0
- package/dist/esm/models/google_llm.js +75 -53
- package/dist/esm/models/registry.js +2 -0
- package/dist/esm/plugins/base_plugin.js +12 -0
- package/dist/esm/plugins/logging_plugin.js +55 -14
- package/dist/esm/plugins/plugin_manager.js +56 -24
- package/dist/esm/plugins/security_plugin.js +1 -1
- package/dist/esm/runner/runner.js +145 -96
- package/dist/esm/sessions/base_session_service.js +49 -1
- package/dist/esm/sessions/database_session_service.js +350 -0
- package/dist/esm/sessions/db/operations.js +87 -0
- package/dist/esm/sessions/db/schema.js +172 -0
- package/dist/esm/sessions/in_memory_session_service.js +61 -33
- package/dist/esm/sessions/registry.js +25 -0
- package/dist/esm/telemetry/google_cloud.js +7 -9
- package/dist/esm/telemetry/setup.js +23 -9
- package/dist/esm/telemetry/tracing.js +37 -15
- package/dist/esm/tools/agent_tool.js +8 -4
- package/dist/esm/tools/base_tool.js +4 -2
- package/dist/esm/tools/forwarding_artifact_service.js +17 -1
- package/dist/esm/tools/function_tool.js +1 -2
- package/dist/esm/tools/google_search_tool.js +2 -5
- package/dist/esm/tools/long_running_tool.js +3 -1
- package/dist/esm/tools/mcp/mcp_session_manager.js +22 -12
- package/dist/esm/tools/mcp/mcp_tool.js +1 -3
- package/dist/esm/tools/mcp/mcp_toolset.js +1 -1
- package/dist/esm/utils/env_aware_utils.js +9 -1
- package/dist/esm/utils/gemini_schema_util.js +9 -4
- package/dist/esm/utils/logger.js +43 -2
- package/dist/esm/utils/object_notation_utils.js +47 -0
- package/dist/esm/utils/simple_zod_to_json.js +102 -141
- package/dist/esm/utils/variant_utils.js +1 -7
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/part_converter_utils.d.ts +47 -0
- package/dist/types/agents/base_agent.d.ts +2 -1
- package/dist/types/agents/callback_context.d.ts +1 -1
- package/dist/types/agents/llm_agent.d.ts +12 -12
- package/dist/types/agents/loop_agent.d.ts +1 -1
- package/dist/types/agents/parallel_agent.d.ts +1 -1
- 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 +8 -5
- package/dist/types/artifacts/registry.d.ts +7 -0
- package/dist/types/code_executors/built_in_code_executor.d.ts +1 -1
- package/dist/types/code_executors/code_executor_context.d.ts +2 -4
- package/dist/types/common.d.ts +13 -3
- 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 +7 -3
- package/dist/types/models/apigee_llm.d.ts +59 -0
- package/dist/types/models/base_llm_connection.d.ts +1 -1
- package/dist/types/models/google_llm.d.ts +5 -2
- package/dist/types/models/llm_response.d.ts +1 -1
- package/dist/types/plugins/logging_plugin.d.ts +12 -12
- package/dist/types/plugins/plugin_manager.d.ts +12 -12
- package/dist/types/plugins/security_plugin.d.ts +1 -1
- package/dist/types/runner/runner.d.ts +16 -1
- package/dist/types/sessions/base_session_service.d.ts +20 -0
- package/dist/types/sessions/database_session_service.d.ts +31 -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 +9 -6
- package/dist/types/sessions/registry.d.ts +7 -0
- package/dist/types/telemetry/setup.d.ts +1 -1
- package/dist/types/telemetry/tracing.d.ts +7 -6
- package/dist/types/tools/agent_tool.d.ts +1 -1
- package/dist/types/tools/base_tool.d.ts +1 -1
- package/dist/types/tools/base_toolset.d.ts +2 -1
- package/dist/types/tools/forwarding_artifact_service.d.ts +4 -2
- package/dist/types/tools/function_tool.d.ts +4 -3
- package/dist/types/tools/google_search_tool.d.ts +3 -3
- package/dist/types/tools/mcp/mcp_session_manager.d.ts +10 -3
- package/dist/types/tools/mcp/mcp_toolset.d.ts +1 -2
- package/dist/types/utils/env_aware_utils.d.ts +7 -0
- package/dist/types/utils/gemini_schema_util.d.ts +4 -12
- package/dist/types/utils/logger.d.ts +11 -10
- package/dist/types/utils/object_notation_utils.d.ts +21 -0
- package/dist/types/utils/simple_zod_to_json.d.ts +5 -4
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/part_converter_utils.js +171 -0
- package/dist/web/agents/base_agent.js +96 -35
- package/dist/web/agents/callback_context.js +4 -1
- package/dist/web/agents/content_processor_utils.js +25 -9
- package/dist/web/agents/functions.js +84 -29
- package/dist/web/agents/llm_agent.js +166 -83
- package/dist/web/agents/loop_agent.js +2 -1
- package/dist/web/agents/parallel_agent.js +3 -4
- 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 +139 -54
- package/dist/web/artifacts/in_memory_artifact_service.js +69 -8
- package/dist/web/artifacts/registry.js +28 -0
- package/dist/web/auth/auth_handler.js +3 -1
- package/dist/web/code_executors/base_code_executor.js +3 -1
- package/dist/web/code_executors/built_in_code_executor.js +7 -3
- package/dist/web/code_executors/code_executor_context.js +5 -5
- package/dist/web/common.js +12 -2
- package/dist/web/events/event.js +30 -5
- package/dist/web/events/event_actions.js +1 -1
- package/dist/web/events/structured_events.js +74 -0
- package/dist/web/index.js +18 -8
- package/dist/web/memory/in_memory_memory_service.js +3 -1
- package/dist/web/models/apigee_llm.js +219 -0
- package/dist/web/models/base_llm.js +8 -4
- package/dist/web/models/gemini_llm_connection.js +1 -0
- package/dist/web/models/google_llm.js +75 -50
- package/dist/web/models/registry.js +2 -0
- package/dist/web/plugins/base_plugin.js +12 -0
- package/dist/web/plugins/logging_plugin.js +55 -14
- package/dist/web/plugins/plugin_manager.js +56 -24
- package/dist/web/plugins/security_plugin.js +1 -1
- package/dist/web/runner/runner.js +192 -108
- package/dist/web/sessions/base_session_service.js +49 -1
- package/dist/web/sessions/database_session_service.js +368 -0
- package/dist/web/sessions/db/operations.js +87 -0
- package/dist/web/sessions/db/schema.js +172 -0
- package/dist/web/sessions/in_memory_session_service.js +61 -33
- package/dist/web/sessions/registry.js +25 -0
- package/dist/web/telemetry/google_cloud.js +7 -9
- package/dist/web/telemetry/setup.js +23 -9
- package/dist/web/telemetry/tracing.js +37 -15
- package/dist/web/tools/agent_tool.js +8 -4
- package/dist/web/tools/base_tool.js +4 -2
- package/dist/web/tools/forwarding_artifact_service.js +17 -1
- package/dist/web/tools/function_tool.js +1 -2
- package/dist/web/tools/google_search_tool.js +2 -5
- package/dist/web/tools/long_running_tool.js +3 -1
- package/dist/web/tools/mcp/mcp_session_manager.js +22 -12
- package/dist/web/tools/mcp/mcp_tool.js +1 -3
- package/dist/web/tools/mcp/mcp_toolset.js +1 -1
- package/dist/web/utils/env_aware_utils.js +9 -1
- package/dist/web/utils/gemini_schema_util.js +9 -4
- package/dist/web/utils/logger.js +43 -2
- package/dist/web/utils/object_notation_utils.js +47 -0
- package/dist/web/utils/simple_zod_to_json.js +102 -155
- package/dist/web/utils/variant_utils.js +1 -7
- package/dist/web/version.js +1 -1
- package/package.json +16 -5
- package/dist/cjs/index.js.map +0 -7
- package/dist/esm/index.js.map +0 -7
- package/dist/web/index.js.map +0 -7
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -47,7 +47,7 @@ var PolicyOutcome = /* @__PURE__ */ ((PolicyOutcome2) => {
|
|
|
47
47
|
return PolicyOutcome2;
|
|
48
48
|
})(PolicyOutcome || {});
|
|
49
49
|
class InMemoryPolicyEngine {
|
|
50
|
-
async evaluate(
|
|
50
|
+
async evaluate() {
|
|
51
51
|
return Promise.resolve({
|
|
52
52
|
outcome: "ALLOW" /* ALLOW */,
|
|
53
53
|
reason: "For prototyping purpose, all tool calls are allowed."
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -36,6 +36,7 @@ var import_built_in_code_executor = require("../code_executors/built_in_code_exe
|
|
|
36
36
|
var import_event = require("../events/event.js");
|
|
37
37
|
var import_event_actions = require("../events/event_actions.js");
|
|
38
38
|
var import_plugin_manager = require("../plugins/plugin_manager.js");
|
|
39
|
+
var import_tracing = require("../telemetry/tracing.js");
|
|
39
40
|
var import_logger = require("../utils/logger.js");
|
|
40
41
|
var import_model_name = require("../utils/model_name.js");
|
|
41
42
|
/**
|
|
@@ -54,6 +55,37 @@ class Runner {
|
|
|
54
55
|
this.memoryService = input.memoryService;
|
|
55
56
|
this.credentialService = input.credentialService;
|
|
56
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Runs the agent with a new, ephemeral session.
|
|
60
|
+
*
|
|
61
|
+
* @param params.userId The user ID of the session.
|
|
62
|
+
* @param params.newMessage A new message to append to the session.
|
|
63
|
+
* @param params.stateDelta An optional state delta to apply to the session.
|
|
64
|
+
* @param params.runConfig The run config for the agent.
|
|
65
|
+
* @yields The Events generated by the agent.
|
|
66
|
+
*/
|
|
67
|
+
async *runEphemeral(params) {
|
|
68
|
+
const session = await this.sessionService.createSession({
|
|
69
|
+
appName: this.appName,
|
|
70
|
+
userId: params.userId
|
|
71
|
+
});
|
|
72
|
+
const sessionId = session.id;
|
|
73
|
+
try {
|
|
74
|
+
yield* this.runAsync({
|
|
75
|
+
userId: params.userId,
|
|
76
|
+
sessionId,
|
|
77
|
+
newMessage: params.newMessage,
|
|
78
|
+
stateDelta: params.stateDelta,
|
|
79
|
+
runConfig: params.runConfig
|
|
80
|
+
});
|
|
81
|
+
} finally {
|
|
82
|
+
await this.sessionService.deleteSession({
|
|
83
|
+
appName: this.appName,
|
|
84
|
+
userId: params.userId,
|
|
85
|
+
sessionId
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
57
89
|
/**
|
|
58
90
|
* Runs the agent with the given message, and returns an async generator of
|
|
59
91
|
* events.
|
|
@@ -67,109 +99,123 @@ class Runner {
|
|
|
67
99
|
*/
|
|
68
100
|
// TODO - b/425992518: user, sessionId, and runConfig can be internalized.
|
|
69
101
|
async *runAsync(params) {
|
|
70
|
-
var _a;
|
|
71
102
|
const { userId, sessionId, stateDelta } = params;
|
|
72
103
|
const runConfig = (0, import_run_config.createRunConfig)(params.runConfig);
|
|
73
104
|
let newMessage = params.newMessage;
|
|
74
|
-
const span =
|
|
105
|
+
const span = import_tracing.tracer.startSpan("invocation");
|
|
106
|
+
const ctx = import_api.trace.setSpan(import_api.context.active(), span);
|
|
75
107
|
try {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
credentialService: this.credentialService,
|
|
105
|
-
invocationId: (0, import_invocation_context.newInvocationContextId)(),
|
|
106
|
-
agent: this.agent,
|
|
107
|
-
session,
|
|
108
|
-
userContent: newMessage,
|
|
109
|
-
runConfig,
|
|
110
|
-
pluginManager: this.pluginManager
|
|
111
|
-
});
|
|
112
|
-
const pluginUserMessage = await this.pluginManager.runOnUserMessageCallback({
|
|
113
|
-
userMessage: newMessage,
|
|
114
|
-
invocationContext
|
|
115
|
-
});
|
|
116
|
-
if (pluginUserMessage) {
|
|
117
|
-
newMessage = pluginUserMessage;
|
|
118
|
-
}
|
|
119
|
-
if (newMessage) {
|
|
120
|
-
if (!((_a = newMessage.parts) == null ? void 0 : _a.length)) {
|
|
121
|
-
throw new Error("No parts in the newMessage.");
|
|
122
|
-
}
|
|
123
|
-
if (runConfig.saveInputBlobsAsArtifacts) {
|
|
124
|
-
await this.saveArtifacts(
|
|
125
|
-
invocationContext.invocationId,
|
|
126
|
-
session.userId,
|
|
127
|
-
session.id,
|
|
128
|
-
newMessage
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
await this.sessionService.appendEvent({
|
|
132
|
-
session,
|
|
133
|
-
event: (0, import_event.createEvent)({
|
|
134
|
-
invocationId: invocationContext.invocationId,
|
|
135
|
-
author: "user",
|
|
136
|
-
actions: stateDelta ? (0, import_event_actions.createEventActions)({ stateDelta }) : void 0,
|
|
137
|
-
content: newMessage
|
|
138
|
-
})
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
invocationContext.agent = this.determineAgentForResumption(
|
|
142
|
-
session,
|
|
143
|
-
this.agent
|
|
144
|
-
);
|
|
145
|
-
const beforeRunCallbackResponse = await this.pluginManager.runBeforeRunCallback({ invocationContext });
|
|
146
|
-
if (beforeRunCallbackResponse) {
|
|
147
|
-
const earlyExitEvent = (0, import_event.createEvent)({
|
|
148
|
-
invocationId: invocationContext.invocationId,
|
|
149
|
-
author: "model",
|
|
150
|
-
content: beforeRunCallbackResponse
|
|
151
|
-
});
|
|
152
|
-
await this.sessionService.appendEvent({ session, event: earlyExitEvent });
|
|
153
|
-
yield earlyExitEvent;
|
|
154
|
-
} else {
|
|
155
|
-
for await (const event of invocationContext.agent.runAsync(
|
|
156
|
-
invocationContext
|
|
157
|
-
)) {
|
|
158
|
-
if (!event.partial) {
|
|
159
|
-
await this.sessionService.appendEvent({ session, event });
|
|
108
|
+
yield* (0, import_tracing.runAsyncGeneratorWithOtelContext)(
|
|
109
|
+
ctx,
|
|
110
|
+
this,
|
|
111
|
+
async function* () {
|
|
112
|
+
var _a;
|
|
113
|
+
const session = await this.sessionService.getSession({
|
|
114
|
+
appName: this.appName,
|
|
115
|
+
userId,
|
|
116
|
+
sessionId
|
|
117
|
+
});
|
|
118
|
+
if (!session) {
|
|
119
|
+
if (!this.appName) {
|
|
120
|
+
throw new Error(
|
|
121
|
+
`Session lookup failed: appName must be provided in runner constructor`
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
throw new Error(`Session not found: ${sessionId}`);
|
|
125
|
+
}
|
|
126
|
+
if (runConfig.supportCfc && (0, import_llm_agent.isLlmAgent)(this.agent)) {
|
|
127
|
+
const modelName = this.agent.canonicalModel.model;
|
|
128
|
+
if (!(0, import_model_name.isGemini2OrAbove)(modelName)) {
|
|
129
|
+
throw new Error(
|
|
130
|
+
`CFC is not supported for model: ${modelName} in agent: ${this.agent.name}`
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
if (!(0, import_built_in_code_executor.isBuiltInCodeExecutor)(this.agent.codeExecutor)) {
|
|
134
|
+
this.agent.codeExecutor = new import_built_in_code_executor.BuiltInCodeExecutor();
|
|
135
|
+
}
|
|
160
136
|
}
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
137
|
+
const invocationContext = new import_invocation_context.InvocationContext({
|
|
138
|
+
artifactService: this.artifactService,
|
|
139
|
+
sessionService: this.sessionService,
|
|
140
|
+
memoryService: this.memoryService,
|
|
141
|
+
credentialService: this.credentialService,
|
|
142
|
+
invocationId: (0, import_invocation_context.newInvocationContextId)(),
|
|
143
|
+
agent: this.agent,
|
|
144
|
+
session,
|
|
145
|
+
userContent: newMessage,
|
|
146
|
+
runConfig,
|
|
147
|
+
pluginManager: this.pluginManager
|
|
148
|
+
});
|
|
149
|
+
const pluginUserMessage = await this.pluginManager.runOnUserMessageCallback({
|
|
150
|
+
userMessage: newMessage,
|
|
151
|
+
invocationContext
|
|
164
152
|
});
|
|
165
|
-
if (
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
|
|
153
|
+
if (pluginUserMessage) {
|
|
154
|
+
newMessage = pluginUserMessage;
|
|
155
|
+
}
|
|
156
|
+
if (newMessage) {
|
|
157
|
+
if (!((_a = newMessage.parts) == null ? void 0 : _a.length)) {
|
|
158
|
+
throw new Error("No parts in the newMessage.");
|
|
159
|
+
}
|
|
160
|
+
if (runConfig.saveInputBlobsAsArtifacts) {
|
|
161
|
+
await this.saveArtifacts(
|
|
162
|
+
invocationContext.invocationId,
|
|
163
|
+
session.userId,
|
|
164
|
+
session.id,
|
|
165
|
+
newMessage
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
await this.sessionService.appendEvent({
|
|
169
|
+
session,
|
|
170
|
+
event: (0, import_event.createEvent)({
|
|
171
|
+
invocationId: invocationContext.invocationId,
|
|
172
|
+
author: "user",
|
|
173
|
+
actions: stateDelta ? (0, import_event_actions.createEventActions)({ stateDelta }) : void 0,
|
|
174
|
+
content: newMessage
|
|
175
|
+
})
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
invocationContext.agent = this.determineAgentForResumption(
|
|
179
|
+
session,
|
|
180
|
+
this.agent
|
|
181
|
+
);
|
|
182
|
+
if (newMessage) {
|
|
183
|
+
const beforeRunCallbackResponse = await this.pluginManager.runBeforeRunCallback({
|
|
184
|
+
invocationContext
|
|
185
|
+
});
|
|
186
|
+
if (beforeRunCallbackResponse) {
|
|
187
|
+
const earlyExitEvent = (0, import_event.createEvent)({
|
|
188
|
+
invocationId: invocationContext.invocationId,
|
|
189
|
+
author: "model",
|
|
190
|
+
content: beforeRunCallbackResponse
|
|
191
|
+
});
|
|
192
|
+
await this.sessionService.appendEvent({
|
|
193
|
+
session,
|
|
194
|
+
event: earlyExitEvent
|
|
195
|
+
});
|
|
196
|
+
yield earlyExitEvent;
|
|
197
|
+
} else {
|
|
198
|
+
for await (const event of invocationContext.agent.runAsync(
|
|
199
|
+
invocationContext
|
|
200
|
+
)) {
|
|
201
|
+
if (!event.partial) {
|
|
202
|
+
await this.sessionService.appendEvent({ session, event });
|
|
203
|
+
}
|
|
204
|
+
const modifiedEvent = await this.pluginManager.runOnEventCallback({
|
|
205
|
+
invocationContext,
|
|
206
|
+
event
|
|
207
|
+
});
|
|
208
|
+
if (modifiedEvent) {
|
|
209
|
+
yield modifiedEvent;
|
|
210
|
+
} else {
|
|
211
|
+
yield event;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
await this.pluginManager.runAfterRunCallback({ invocationContext });
|
|
215
|
+
}
|
|
169
216
|
}
|
|
170
217
|
}
|
|
171
|
-
|
|
172
|
-
await this.pluginManager.runAfterRunCallback({ invocationContext });
|
|
218
|
+
);
|
|
173
219
|
} finally {
|
|
174
220
|
span.end();
|
|
175
221
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -24,9 +24,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var base_session_service_exports = {};
|
|
26
26
|
__export(base_session_service_exports, {
|
|
27
|
-
BaseSessionService: () => BaseSessionService
|
|
27
|
+
BaseSessionService: () => BaseSessionService,
|
|
28
|
+
mergeStates: () => mergeStates,
|
|
29
|
+
trimTempDeltaState: () => trimTempDeltaState
|
|
28
30
|
});
|
|
29
31
|
module.exports = __toCommonJS(base_session_service_exports);
|
|
32
|
+
var import_lodash_es = require("lodash-es");
|
|
30
33
|
var import_state = require("./state.js");
|
|
31
34
|
/**
|
|
32
35
|
* @license
|
|
@@ -34,6 +37,26 @@ var import_state = require("./state.js");
|
|
|
34
37
|
* SPDX-License-Identifier: Apache-2.0
|
|
35
38
|
*/
|
|
36
39
|
class BaseSessionService {
|
|
40
|
+
/**
|
|
41
|
+
* Gets a session or creates one if it doesn't exist.
|
|
42
|
+
*
|
|
43
|
+
* @param request The request to get or create a session.
|
|
44
|
+
* @return A promise that resolves to the session instance.
|
|
45
|
+
*/
|
|
46
|
+
async getOrCreateSession(request) {
|
|
47
|
+
if (!request.sessionId) {
|
|
48
|
+
return this.createSession(request);
|
|
49
|
+
}
|
|
50
|
+
const session = await this.getSession({
|
|
51
|
+
appName: request.appName,
|
|
52
|
+
userId: request.userId,
|
|
53
|
+
sessionId: request.sessionId
|
|
54
|
+
});
|
|
55
|
+
if (session) {
|
|
56
|
+
return session;
|
|
57
|
+
}
|
|
58
|
+
return this.createSession(request);
|
|
59
|
+
}
|
|
37
60
|
/**
|
|
38
61
|
* Appends an event to a session.
|
|
39
62
|
*
|
|
@@ -44,6 +67,7 @@ class BaseSessionService {
|
|
|
44
67
|
if (event.partial) {
|
|
45
68
|
return event;
|
|
46
69
|
}
|
|
70
|
+
event = trimTempDeltaState(event);
|
|
47
71
|
this.updateSessionState({ session, event });
|
|
48
72
|
session.events.push(event);
|
|
49
73
|
return event;
|
|
@@ -65,7 +89,33 @@ class BaseSessionService {
|
|
|
65
89
|
}
|
|
66
90
|
}
|
|
67
91
|
}
|
|
92
|
+
function trimTempDeltaState(event) {
|
|
93
|
+
if (!event.actions || !event.actions.stateDelta) {
|
|
94
|
+
return event;
|
|
95
|
+
}
|
|
96
|
+
const stateDelta = event.actions.stateDelta;
|
|
97
|
+
const filteredStateDelta = {};
|
|
98
|
+
for (const [key, value] of Object.entries(stateDelta)) {
|
|
99
|
+
if (!key.startsWith(import_state.State.TEMP_PREFIX)) {
|
|
100
|
+
filteredStateDelta[key] = value;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
event.actions.stateDelta = filteredStateDelta;
|
|
104
|
+
return event;
|
|
105
|
+
}
|
|
106
|
+
function mergeStates(appState = {}, userState = {}, sessionState = {}) {
|
|
107
|
+
const merged = (0, import_lodash_es.cloneDeep)(sessionState);
|
|
108
|
+
for (const [k, v] of Object.entries(appState)) {
|
|
109
|
+
merged[import_state.State.APP_PREFIX + k] = v;
|
|
110
|
+
}
|
|
111
|
+
for (const [k, v] of Object.entries(userState)) {
|
|
112
|
+
merged[import_state.State.USER_PREFIX + k] = v;
|
|
113
|
+
}
|
|
114
|
+
return merged;
|
|
115
|
+
}
|
|
68
116
|
// Annotate the CommonJS export names for ESM import in node:
|
|
69
117
|
0 && (module.exports = {
|
|
70
|
-
BaseSessionService
|
|
118
|
+
BaseSessionService,
|
|
119
|
+
mergeStates,
|
|
120
|
+
trimTempDeltaState
|
|
71
121
|
});
|