@google/adk 1.4.0 → 1.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/dist/cjs/a2a/a2a_remote_agent.js +12 -2
- package/dist/cjs/a2a/agent_to_a2a.js +18 -3
- package/dist/cjs/a2a/auth.js +65 -0
- package/dist/cjs/a2a/event_converter_utils.js +47 -18
- package/dist/cjs/a2a/metadata_converter_utils.js +1 -1
- package/dist/cjs/agents/base_agent.js +39 -0
- package/dist/cjs/agents/functions.js +26 -28
- package/dist/cjs/agents/llm_agent.js +4 -2
- package/dist/cjs/agents/loop_agent.js +15 -3
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +3 -2
- package/dist/cjs/agents/processors/content_processor_utils.js +2 -1
- package/dist/cjs/agents/processors/content_request_processor.js +2 -21
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +3 -1
- package/dist/cjs/agents/routed_agent.js +31 -0
- package/dist/cjs/agents/run_config.js +3 -2
- package/dist/cjs/artifacts/in_memory_artifact_service.js +17 -9
- package/dist/cjs/auth/credential_service/in_memory_credential_service.js +14 -3
- package/dist/cjs/code_executors/unsafe_local_code_executor.js +23 -12
- package/dist/cjs/common.js +35 -0
- package/dist/cjs/context/agent_controlled_context_compactor.js +2 -11
- package/dist/cjs/context/anchored_context_compactor.js +127 -0
- package/dist/cjs/context/compaction_utils.js +64 -0
- package/dist/cjs/context/token_based_context_compactor.js +13 -44
- package/dist/cjs/events/compacted_event.js +9 -3
- package/dist/cjs/events/event.js +28 -0
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- package/dist/cjs/memory/in_memory_memory_service.js +13 -2
- package/dist/cjs/memory/vertex_ai_memory_bank_service.js +3 -0
- package/dist/cjs/plugins/base_plugin.js +4 -2
- package/dist/cjs/plugins/global_instruction_plugin.js +97 -0
- package/dist/cjs/runner/runner.js +69 -23
- package/dist/cjs/sessions/base_session_service.js +8 -3
- package/dist/cjs/sessions/in_memory_session_service.js +8 -8
- package/dist/cjs/sessions/vertex_ai_session_service.js +22 -10
- package/dist/cjs/skills/loader.js +40 -6
- package/dist/cjs/tools/enterprise_web_search_tool.js +81 -0
- package/dist/cjs/tools/example_tool.js +68 -0
- package/dist/cjs/tools/get_user_choice_tool.js +53 -0
- package/dist/cjs/tools/load_web_page.js +250 -0
- package/dist/cjs/tools/mcp/load_mcp_resource_tool.js +140 -0
- package/dist/cjs/tools/mcp/mcp_session_manager.js +35 -21
- package/dist/cjs/tools/mcp/mcp_toolset.js +63 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +13 -10
- package/dist/cjs/tools/request_input_tool.js +54 -0
- package/dist/cjs/tools/skill/run_skill_inline_script_tool.js +54 -4
- package/dist/cjs/tools/skill/skill_toolset.js +4 -2
- package/dist/cjs/utils/branch_trie.js +41 -0
- package/dist/cjs/utils/crypto_shim.js +43 -0
- package/dist/cjs/utils/env_aware_utils.js +15 -13
- package/dist/cjs/utils/error_utils.js +120 -0
- package/dist/cjs/utils/file_utils.js +5 -2
- package/dist/cjs/utils/output_schema_utils.js +43 -0
- package/dist/cjs/utils/streaming_utils.js +5 -5
- package/dist/cjs/utils/vertex_ai_utils.js +3 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/a2a_remote_agent.js +12 -2
- package/dist/esm/a2a/agent_to_a2a.js +18 -3
- package/dist/esm/a2a/auth.js +37 -0
- package/dist/esm/a2a/event_converter_utils.js +47 -18
- package/dist/esm/a2a/metadata_converter_utils.js +1 -1
- package/dist/esm/agents/base_agent.js +39 -0
- package/dist/esm/agents/functions.js +27 -24
- package/dist/esm/agents/llm_agent.js +6 -4
- package/dist/esm/agents/loop_agent.js +15 -3
- package/dist/esm/agents/processors/basic_llm_request_processor.js +3 -2
- package/dist/esm/agents/processors/content_processor_utils.js +2 -1
- package/dist/esm/agents/processors/content_request_processor.js +2 -21
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +3 -1
- package/dist/esm/agents/routed_agent.js +31 -0
- package/dist/esm/agents/run_config.js +3 -2
- package/dist/esm/artifacts/in_memory_artifact_service.js +17 -9
- package/dist/esm/auth/credential_service/in_memory_credential_service.js +14 -3
- package/dist/esm/code_executors/unsafe_local_code_executor.js +22 -11
- package/dist/esm/common.js +29 -1
- package/dist/esm/context/agent_controlled_context_compactor.js +2 -11
- package/dist/esm/context/anchored_context_compactor.js +99 -0
- package/dist/esm/context/compaction_utils.js +38 -0
- package/dist/esm/context/token_based_context_compactor.js +16 -44
- package/dist/esm/events/compacted_event.js +7 -2
- package/dist/esm/events/event.js +24 -0
- package/dist/esm/index.js +8 -1
- package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- package/dist/esm/memory/in_memory_memory_service.js +13 -2
- package/dist/esm/memory/vertex_ai_memory_bank_service.js +7 -1
- package/dist/esm/plugins/base_plugin.js +4 -2
- package/dist/esm/plugins/global_instruction_plugin.js +69 -0
- package/dist/esm/runner/runner.js +69 -23
- package/dist/esm/sessions/base_session_service.js +8 -3
- package/dist/esm/sessions/in_memory_session_service.js +8 -8
- package/dist/esm/sessions/vertex_ai_session_service.js +26 -11
- package/dist/esm/skills/loader.js +40 -6
- package/dist/esm/tools/enterprise_web_search_tool.js +55 -0
- package/dist/esm/tools/example_tool.js +42 -0
- package/dist/esm/tools/get_user_choice_tool.js +25 -0
- package/dist/esm/tools/load_web_page.js +221 -0
- package/dist/esm/tools/mcp/load_mcp_resource_tool.js +114 -0
- package/dist/esm/tools/mcp/mcp_session_manager.js +35 -21
- package/dist/esm/tools/mcp/mcp_toolset.js +63 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +13 -10
- package/dist/esm/tools/request_input_tool.js +26 -0
- package/dist/esm/tools/skill/run_skill_inline_script_tool.js +53 -4
- package/dist/esm/tools/skill/skill_toolset.js +4 -2
- package/dist/esm/utils/branch_trie.js +13 -0
- package/dist/esm/utils/crypto_shim.js +15 -0
- package/dist/esm/utils/env_aware_utils.js +15 -13
- package/dist/esm/utils/error_utils.js +92 -0
- package/dist/esm/utils/file_utils.js +5 -2
- package/dist/esm/utils/output_schema_utils.js +15 -0
- package/dist/esm/utils/streaming_utils.js +1 -1
- package/dist/esm/utils/vertex_ai_utils.js +2 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent.d.ts +5 -1
- package/dist/types/a2a/agent_to_a2a.d.ts +38 -0
- package/dist/types/a2a/auth.d.ts +30 -0
- package/dist/types/a2a/event_converter_utils.d.ts +4 -1
- package/dist/types/agents/base_agent.d.ts +29 -1
- package/dist/types/agents/functions.d.ts +1 -9
- package/dist/types/agents/llm_agent.d.ts +5 -1
- package/dist/types/agents/loop_agent.d.ts +2 -2
- package/dist/types/agents/routed_agent.d.ts +24 -1
- package/dist/types/agents/run_config.d.ts +1 -1
- package/dist/types/auth/credential_service/in_memory_credential_service.d.ts +11 -0
- package/dist/types/code_executors/unsafe_local_code_executor.d.ts +5 -1
- package/dist/types/common.d.ts +11 -2
- package/dist/types/context/agent_controlled_context_compactor.d.ts +0 -1
- package/dist/types/context/anchored_context_compactor.d.ts +35 -0
- package/dist/types/context/compaction_utils.d.ts +23 -0
- package/dist/types/context/token_based_context_compactor.d.ts +0 -1
- package/dist/types/events/compacted_event.d.ts +10 -0
- package/dist/types/events/event.d.ts +13 -0
- package/dist/types/index.d.ts +5 -3
- package/dist/types/memory/in_memory_memory_service.d.ts +11 -0
- package/dist/types/plugins/base_plugin.d.ts +4 -2
- package/dist/types/plugins/global_instruction_plugin.d.ts +38 -0
- package/dist/types/runner/runner.d.ts +1 -1
- package/dist/types/sessions/base_session_service.d.ts +8 -0
- package/dist/types/sessions/in_memory_session_service.d.ts +9 -0
- package/dist/types/sessions/vertex_ai_session_service.d.ts +19 -1
- package/dist/types/skills/loader.d.ts +5 -0
- package/dist/types/tools/enterprise_web_search_tool.d.ts +26 -0
- package/dist/types/tools/example_tool.d.ts +21 -0
- package/dist/types/tools/get_user_choice_tool.d.ts +14 -0
- package/dist/types/tools/load_web_page.d.ts +33 -0
- package/dist/types/tools/mcp/load_mcp_resource_tool.d.ts +26 -0
- package/dist/types/tools/mcp/mcp_toolset.d.ts +27 -0
- package/dist/types/tools/request_input_tool.d.ts +15 -0
- package/dist/types/tools/skill/run_skill_inline_script_tool.d.ts +25 -0
- package/dist/types/tools/skill/skill_toolset.d.ts +9 -0
- package/dist/types/utils/branch_trie.d.ts +14 -0
- package/dist/types/utils/crypto_shim.d.ts +16 -0
- package/dist/types/utils/env_aware_utils.d.ts +23 -0
- package/dist/types/utils/error_utils.d.ts +18 -0
- package/dist/types/utils/output_schema_utils.d.ts +18 -0
- package/dist/types/utils/vertex_ai_utils.d.ts +1 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/a2a_remote_agent.js +12 -2
- package/dist/web/a2a/agent_to_a2a.js +18 -3
- package/dist/web/a2a/auth.js +37 -0
- package/dist/web/a2a/event_converter_utils.js +47 -18
- package/dist/web/a2a/metadata_converter_utils.js +1 -1
- package/dist/web/agents/base_agent.js +39 -0
- package/dist/web/agents/functions.js +27 -24
- package/dist/web/agents/llm_agent.js +6 -4
- package/dist/web/agents/loop_agent.js +27 -3
- package/dist/web/agents/processors/basic_llm_request_processor.js +3 -2
- package/dist/web/agents/processors/content_processor_utils.js +2 -1
- package/dist/web/agents/processors/content_request_processor.js +2 -21
- package/dist/web/agents/processors/instructions_llm_request_processor.js +3 -1
- package/dist/web/agents/routed_agent.js +31 -0
- package/dist/web/agents/run_config.js +8 -3
- package/dist/web/artifacts/in_memory_artifact_service.js +17 -9
- package/dist/web/auth/credential_service/in_memory_credential_service.js +14 -3
- package/dist/web/code_executors/unsafe_local_code_executor.js +22 -11
- package/dist/web/common.js +29 -1
- package/dist/web/context/agent_controlled_context_compactor.js +2 -11
- package/dist/web/context/anchored_context_compactor.js +117 -0
- package/dist/web/context/compaction_utils.js +38 -0
- package/dist/web/context/token_based_context_compactor.js +16 -44
- package/dist/web/events/compacted_event.js +7 -2
- package/dist/web/events/event.js +24 -0
- package/dist/web/index.js +8 -1
- package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- package/dist/web/memory/in_memory_memory_service.js +13 -2
- package/dist/web/memory/vertex_ai_memory_bank_service.js +7 -1
- package/dist/web/plugins/base_plugin.js +4 -2
- package/dist/web/plugins/global_instruction_plugin.js +67 -0
- package/dist/web/runner/runner.js +65 -22
- package/dist/web/sessions/base_session_service.js +8 -3
- package/dist/web/sessions/in_memory_session_service.js +8 -8
- package/dist/web/sessions/vertex_ai_session_service.js +24 -11
- package/dist/web/skills/loader.js +40 -6
- package/dist/web/tools/enterprise_web_search_tool.js +55 -0
- package/dist/web/tools/example_tool.js +42 -0
- package/dist/web/tools/get_user_choice_tool.js +25 -0
- package/dist/web/tools/load_web_page.js +221 -0
- package/dist/web/tools/mcp/load_mcp_resource_tool.js +107 -0
- package/dist/web/tools/mcp/mcp_session_manager.js +35 -21
- package/dist/web/tools/mcp/mcp_toolset.js +63 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +13 -10
- package/dist/web/tools/request_input_tool.js +26 -0
- package/dist/web/tools/skill/run_skill_inline_script_tool.js +51 -4
- package/dist/web/tools/skill/skill_toolset.js +4 -2
- package/dist/web/utils/branch_trie.js +13 -0
- package/dist/web/utils/crypto_shim.js +15 -0
- package/dist/web/utils/env_aware_utils.js +15 -13
- package/dist/web/utils/error_utils.js +92 -0
- package/dist/web/utils/file_utils.js +5 -2
- package/dist/web/utils/output_schema_utils.js +15 -0
- package/dist/web/utils/streaming_utils.js +1 -1
- package/dist/web/utils/vertex_ai_utils.js +2 -0
- package/dist/web/version.js +1 -1
- package/package.json +1 -1
|
@@ -29,6 +29,7 @@ __export(token_based_context_compactor_exports, {
|
|
|
29
29
|
module.exports = __toCommonJS(token_based_context_compactor_exports);
|
|
30
30
|
var import_content_processor_utils = require("../agents/processors/content_processor_utils.js");
|
|
31
31
|
var import_compacted_event = require("../events/compacted_event.js");
|
|
32
|
+
var import_compaction_utils = require("./compaction_utils.js");
|
|
32
33
|
/**
|
|
33
34
|
* @license
|
|
34
35
|
* Copyright 2026 Google LLC
|
|
@@ -41,31 +42,20 @@ class TokenBasedContextCompactor {
|
|
|
41
42
|
this.eventRetentionSize = options.eventRetentionSize;
|
|
42
43
|
this.summarizer = options.summarizer;
|
|
43
44
|
}
|
|
44
|
-
getActiveEvents(events) {
|
|
45
|
-
let latestCompactedEvent = void 0;
|
|
46
|
-
for (let i = events.length - 1; i >= 0; i--) {
|
|
47
|
-
const e = events[i];
|
|
48
|
-
if ((0, import_compacted_event.isCompactedEvent)(e)) {
|
|
49
|
-
if (!latestCompactedEvent || e.endTime > latestCompactedEvent.endTime) {
|
|
50
|
-
latestCompactedEvent = e;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
if (!latestCompactedEvent) {
|
|
55
|
-
return events;
|
|
56
|
-
}
|
|
57
|
-
const activeRawEvents = events.filter(
|
|
58
|
-
(e) => !(0, import_compacted_event.isCompactedEvent)(e) && e.timestamp > latestCompactedEvent.endTime
|
|
59
|
-
);
|
|
60
|
-
return [latestCompactedEvent, ...activeRawEvents];
|
|
61
|
-
}
|
|
62
45
|
shouldCompact(invocationContext) {
|
|
63
46
|
const events = invocationContext.session.events;
|
|
64
|
-
const activeEvents =
|
|
47
|
+
const activeEvents = (0, import_compaction_utils.getActiveEvents)(events);
|
|
65
48
|
const rawEvents = activeEvents.filter((e) => !(0, import_compacted_event.isCompactedEvent)(e));
|
|
66
49
|
if (rawEvents.length <= this.eventRetentionSize) {
|
|
67
50
|
return false;
|
|
68
51
|
}
|
|
52
|
+
const retainStartIndex = (0, import_compaction_utils.calculateRetainStartIndex)(
|
|
53
|
+
rawEvents,
|
|
54
|
+
this.eventRetentionSize
|
|
55
|
+
);
|
|
56
|
+
if (retainStartIndex === 0) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
69
59
|
const promptTokenCount = latestPromptTokenCount(
|
|
70
60
|
activeEvents,
|
|
71
61
|
invocationContext
|
|
@@ -77,24 +67,15 @@ class TokenBasedContextCompactor {
|
|
|
77
67
|
}
|
|
78
68
|
async compact(invocationContext) {
|
|
79
69
|
const events = invocationContext.session.events;
|
|
80
|
-
const activeEvents =
|
|
70
|
+
const activeEvents = (0, import_compaction_utils.getActiveEvents)(events);
|
|
81
71
|
const rawEvents = activeEvents.filter((e) => !(0, import_compacted_event.isCompactedEvent)(e));
|
|
82
72
|
if (rawEvents.length <= this.eventRetentionSize) {
|
|
83
73
|
return;
|
|
84
74
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
75
|
+
const retainStartIndex = (0, import_compaction_utils.calculateRetainStartIndex)(
|
|
76
|
+
rawEvents,
|
|
77
|
+
this.eventRetentionSize
|
|
88
78
|
);
|
|
89
|
-
while (retainStartIndex > 0) {
|
|
90
|
-
const eventToRetain = rawEvents[retainStartIndex];
|
|
91
|
-
const previousEvent = rawEvents[retainStartIndex - 1];
|
|
92
|
-
if (hasFunctionResponse(eventToRetain) && hasFunctionCall(previousEvent)) {
|
|
93
|
-
retainStartIndex--;
|
|
94
|
-
} else {
|
|
95
|
-
break;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
79
|
if (retainStartIndex === 0) {
|
|
99
80
|
return;
|
|
100
81
|
}
|
|
@@ -149,18 +130,6 @@ function estimatePromptTokenCount(activeEvents, invocationContext) {
|
|
|
149
130
|
}
|
|
150
131
|
return Math.ceil(totalChars / CHARS_PER_TOKEN);
|
|
151
132
|
}
|
|
152
|
-
function hasFunctionCall(event) {
|
|
153
|
-
var _a, _b;
|
|
154
|
-
return !!((_b = (_a = event.content) == null ? void 0 : _a.parts) == null ? void 0 : _b.some(
|
|
155
|
-
(part) => part.functionCall !== void 0
|
|
156
|
-
));
|
|
157
|
-
}
|
|
158
|
-
function hasFunctionResponse(event) {
|
|
159
|
-
var _a, _b;
|
|
160
|
-
return !!((_b = (_a = event.content) == null ? void 0 : _a.parts) == null ? void 0 : _b.some(
|
|
161
|
-
(part) => part.functionResponse !== void 0
|
|
162
|
-
));
|
|
163
|
-
}
|
|
164
133
|
// Annotate the CommonJS export names for ESM import in node:
|
|
165
134
|
0 && (module.exports = {
|
|
166
135
|
TokenBasedContextCompactor
|
|
@@ -25,7 +25,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
25
25
|
var compacted_event_exports = {};
|
|
26
26
|
__export(compacted_event_exports, {
|
|
27
27
|
createCompactedEvent: () => createCompactedEvent,
|
|
28
|
-
isCompactedEvent: () => isCompactedEvent
|
|
28
|
+
isCompactedEvent: () => isCompactedEvent,
|
|
29
|
+
isScratchpadEvent: () => isScratchpadEvent
|
|
29
30
|
});
|
|
30
31
|
module.exports = __toCommonJS(compacted_event_exports);
|
|
31
32
|
var import_event = require("./event.js");
|
|
@@ -37,17 +38,22 @@ var import_event = require("./event.js");
|
|
|
37
38
|
function isCompactedEvent(event) {
|
|
38
39
|
return "isCompacted" in event && event.isCompacted === true;
|
|
39
40
|
}
|
|
41
|
+
function isScratchpadEvent(event) {
|
|
42
|
+
return isCompactedEvent(event) && event.isScratchpad === true;
|
|
43
|
+
}
|
|
40
44
|
function createCompactedEvent(params = {}) {
|
|
41
45
|
return {
|
|
42
46
|
...(0, import_event.createEvent)(params),
|
|
43
47
|
isCompacted: params.isCompacted || true,
|
|
44
48
|
startTime: params.startTime,
|
|
45
49
|
endTime: params.endTime,
|
|
46
|
-
compactedContent: params.compactedContent
|
|
50
|
+
compactedContent: params.compactedContent,
|
|
51
|
+
isScratchpad: params.isScratchpad
|
|
47
52
|
};
|
|
48
53
|
}
|
|
49
54
|
// Annotate the CommonJS export names for ESM import in node:
|
|
50
55
|
0 && (module.exports = {
|
|
51
56
|
createCompactedEvent,
|
|
52
|
-
isCompactedEvent
|
|
57
|
+
isCompactedEvent,
|
|
58
|
+
isScratchpadEvent
|
|
53
59
|
});
|
package/dist/cjs/events/event.js
CHANGED
|
@@ -24,19 +24,24 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var event_exports = {};
|
|
26
26
|
__export(event_exports, {
|
|
27
|
+
AF_FUNCTION_CALL_ID_PREFIX: () => AF_FUNCTION_CALL_ID_PREFIX,
|
|
27
28
|
createEvent: () => createEvent,
|
|
28
29
|
createNewEventId: () => createNewEventId,
|
|
30
|
+
generateClientFunctionCallId: () => generateClientFunctionCallId,
|
|
31
|
+
getEventTokens: () => getEventTokens,
|
|
29
32
|
getFunctionCalls: () => getFunctionCalls,
|
|
30
33
|
getFunctionResponses: () => getFunctionResponses,
|
|
31
34
|
hasThoughts: () => hasThoughts,
|
|
32
35
|
hasTrailingCodeExecutionResult: () => hasTrailingCodeExecutionResult,
|
|
33
36
|
isFinalResponse: () => isFinalResponse,
|
|
37
|
+
populateClientFunctionCallId: () => populateClientFunctionCallId,
|
|
34
38
|
pruneThoughts: () => pruneThoughts,
|
|
35
39
|
stringifyContent: () => stringifyContent,
|
|
36
40
|
transformToCamelCaseEvent: () => transformToCamelCaseEvent,
|
|
37
41
|
transformToSnakeCaseEvent: () => transformToSnakeCaseEvent
|
|
38
42
|
});
|
|
39
43
|
module.exports = __toCommonJS(event_exports);
|
|
44
|
+
var import_env_aware_utils = require("../utils/env_aware_utils.js");
|
|
40
45
|
var import_object_notation_utils = require("../utils/object_notation_utils.js");
|
|
41
46
|
var import_event_actions = require("./event_actions.js");
|
|
42
47
|
/**
|
|
@@ -73,6 +78,17 @@ function getFunctionCalls(event) {
|
|
|
73
78
|
}
|
|
74
79
|
return funcCalls;
|
|
75
80
|
}
|
|
81
|
+
const AF_FUNCTION_CALL_ID_PREFIX = "adk-";
|
|
82
|
+
function generateClientFunctionCallId() {
|
|
83
|
+
return `${AF_FUNCTION_CALL_ID_PREFIX}${(0, import_env_aware_utils.randomUUID)()}`;
|
|
84
|
+
}
|
|
85
|
+
function populateClientFunctionCallId(modelResponseEvent) {
|
|
86
|
+
for (const functionCall of getFunctionCalls(modelResponseEvent)) {
|
|
87
|
+
if (!functionCall.id) {
|
|
88
|
+
functionCall.id = generateClientFunctionCallId();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
76
92
|
function getFunctionResponses(event) {
|
|
77
93
|
const funcResponses = [];
|
|
78
94
|
if (event.content && event.content.parts) {
|
|
@@ -102,6 +118,14 @@ function stringifyContent(event) {
|
|
|
102
118
|
return (_a2 = part.text) != null ? _a2 : "";
|
|
103
119
|
}).join("");
|
|
104
120
|
}
|
|
121
|
+
function getEventTokens(event) {
|
|
122
|
+
var _a;
|
|
123
|
+
if (((_a = event.usageMetadata) == null ? void 0 : _a.promptTokenCount) !== void 0) {
|
|
124
|
+
return event.usageMetadata.promptTokenCount;
|
|
125
|
+
}
|
|
126
|
+
const contentStr = stringifyContent(event);
|
|
127
|
+
return Math.ceil(contentStr.length / 4);
|
|
128
|
+
}
|
|
105
129
|
function hasThoughts(event) {
|
|
106
130
|
var _a, _b;
|
|
107
131
|
return !!((_b = (_a = event.content) == null ? void 0 : _a.parts) == null ? void 0 : _b.some((part) => part.thought === true));
|
|
@@ -158,13 +182,17 @@ function transformToSnakeCaseEvent(event) {
|
|
|
158
182
|
}
|
|
159
183
|
// Annotate the CommonJS export names for ESM import in node:
|
|
160
184
|
0 && (module.exports = {
|
|
185
|
+
AF_FUNCTION_CALL_ID_PREFIX,
|
|
161
186
|
createEvent,
|
|
162
187
|
createNewEventId,
|
|
188
|
+
generateClientFunctionCallId,
|
|
189
|
+
getEventTokens,
|
|
163
190
|
getFunctionCalls,
|
|
164
191
|
getFunctionResponses,
|
|
165
192
|
hasThoughts,
|
|
166
193
|
hasTrailingCodeExecutionResult,
|
|
167
194
|
isFinalResponse,
|
|
195
|
+
populateClientFunctionCallId,
|
|
168
196
|
pruneThoughts,
|
|
169
197
|
stringifyContent,
|
|
170
198
|
transformToCamelCaseEvent,
|
package/dist/cjs/index.js
CHANGED
|
@@ -34,10 +34,12 @@ __export(index_exports, {
|
|
|
34
34
|
GcsArtifactService: () => import_gcs_artifact_service.GcsArtifactService,
|
|
35
35
|
InvocationContext: () => import_invocation_context.InvocationContext,
|
|
36
36
|
RemoteA2AAgent: () => import_a2a_remote_agent.RemoteA2AAgent,
|
|
37
|
+
RunSkillInlineScriptErrorCode: () => import_run_skill_inline_script_tool.RunSkillInlineScriptErrorCode,
|
|
37
38
|
RunSkillInlineScriptTool: () => import_run_skill_inline_script_tool.RunSkillInlineScriptTool,
|
|
38
39
|
RunSkillScriptTool: () => import_run_skill_script_tool.RunSkillScriptTool,
|
|
39
40
|
UnsafeLocalCodeExecutor: () => import_unsafe_local_code_executor.UnsafeLocalCodeExecutor,
|
|
40
41
|
VertexAiSessionService: () => import_vertex_ai_session_service.VertexAiSessionService,
|
|
42
|
+
bearerTokenUserBuilder: () => import_auth.bearerTokenUserBuilder,
|
|
41
43
|
getA2AAgentCard: () => import_agent_card.getA2AAgentCard,
|
|
42
44
|
getArtifactServiceFromUri: () => import_registry.getArtifactServiceFromUri,
|
|
43
45
|
getSessionServiceFromUri: () => import_registry2.getSessionServiceFromUri,
|
|
@@ -51,6 +53,7 @@ var import_a2a_remote_agent = require("./a2a/a2a_remote_agent.js");
|
|
|
51
53
|
var import_agent_card = require("./a2a/agent_card.js");
|
|
52
54
|
var import_agent_executor = require("./a2a/agent_executor.js");
|
|
53
55
|
var import_agent_to_a2a = require("./a2a/agent_to_a2a.js");
|
|
56
|
+
var import_auth = require("./a2a/auth.js");
|
|
54
57
|
var import_invocation_context = require("./agents/invocation_context.js");
|
|
55
58
|
var import_file_artifact_service = require("./artifacts/file_artifact_service.js");
|
|
56
59
|
var import_gcs_artifact_service = require("./artifacts/gcs_artifact_service.js");
|
|
@@ -68,6 +71,7 @@ var import_run_skill_script_tool = require("./tools/skill/run_skill_script_tool.
|
|
|
68
71
|
__reExport(index_exports, require("./integrations/agent_registry/agent_registry.js"), module.exports);
|
|
69
72
|
__reExport(index_exports, require("./telemetry/google_cloud.js"), module.exports);
|
|
70
73
|
__reExport(index_exports, require("./telemetry/setup.js"), module.exports);
|
|
74
|
+
__reExport(index_exports, require("./tools/mcp/load_mcp_resource_tool.js"), module.exports);
|
|
71
75
|
__reExport(index_exports, require("./tools/mcp/mcp_session_manager.js"), module.exports);
|
|
72
76
|
__reExport(index_exports, require("./tools/mcp/mcp_tool.js"), module.exports);
|
|
73
77
|
__reExport(index_exports, require("./tools/mcp/mcp_toolset.js"), module.exports);
|
|
@@ -87,10 +91,12 @@ __reExport(index_exports, require("./tools/mcp/mcp_toolset.js"), module.exports)
|
|
|
87
91
|
GcsArtifactService,
|
|
88
92
|
InvocationContext,
|
|
89
93
|
RemoteA2AAgent,
|
|
94
|
+
RunSkillInlineScriptErrorCode,
|
|
90
95
|
RunSkillInlineScriptTool,
|
|
91
96
|
RunSkillScriptTool,
|
|
92
97
|
UnsafeLocalCodeExecutor,
|
|
93
98
|
VertexAiSessionService,
|
|
99
|
+
bearerTokenUserBuilder,
|
|
94
100
|
getA2AAgentCard,
|
|
95
101
|
getArtifactServiceFromUri,
|
|
96
102
|
getSessionServiceFromUri,
|
|
@@ -102,6 +108,7 @@ __reExport(index_exports, require("./tools/mcp/mcp_toolset.js"), module.exports)
|
|
|
102
108
|
...require("./integrations/agent_registry/agent_registry.js"),
|
|
103
109
|
...require("./telemetry/google_cloud.js"),
|
|
104
110
|
...require("./telemetry/setup.js"),
|
|
111
|
+
...require("./tools/mcp/load_mcp_resource_tool.js"),
|
|
105
112
|
...require("./tools/mcp/mcp_session_manager.js"),
|
|
106
113
|
...require("./tools/mcp/mcp_tool.js"),
|
|
107
114
|
...require("./tools/mcp/mcp_toolset.js")
|
|
@@ -30,6 +30,7 @@ module.exports = __toCommonJS(agent_registry_mcp_toolset_exports);
|
|
|
30
30
|
var import_base_toolset = require("../../tools/base_toolset.js");
|
|
31
31
|
var import_mcp_session_manager = require("../../tools/mcp/mcp_session_manager.js");
|
|
32
32
|
var import_mcp_tool = require("../../tools/mcp/mcp_tool.js");
|
|
33
|
+
var import_logger = require("../../utils/logger.js");
|
|
33
34
|
var import_types2 = require("./types.js");
|
|
34
35
|
/**
|
|
35
36
|
* @license
|
|
@@ -90,7 +91,14 @@ class AgentRegistrySingleMCPToolset extends import_base_toolset.BaseToolset {
|
|
|
90
91
|
};
|
|
91
92
|
const sessionManager = new import_mcp_session_manager.MCPSessionManager(connectionParamsCopy);
|
|
92
93
|
const session = await sessionManager.createSession();
|
|
93
|
-
|
|
94
|
+
let listResult;
|
|
95
|
+
try {
|
|
96
|
+
listResult = await session.listTools();
|
|
97
|
+
} finally {
|
|
98
|
+
await sessionManager.closeSession(session).catch((e) => {
|
|
99
|
+
import_logger.logger.warn("Failed to close MCP discovery session", e);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
94
102
|
const tools = listResult.tools.map((tool) => {
|
|
95
103
|
const prefixedName = this.prefix ? `${this.prefix}_${tool.name}` : tool.name;
|
|
96
104
|
const mcpTool = new import_mcp_tool.MCPTool(
|
|
@@ -35,12 +35,23 @@ module.exports = __toCommonJS(in_memory_memory_service_exports);
|
|
|
35
35
|
class InMemoryMemoryService {
|
|
36
36
|
constructor() {
|
|
37
37
|
this.memories = [];
|
|
38
|
-
|
|
38
|
+
/**
|
|
39
|
+
* A map from user key to a map from session ID to events.
|
|
40
|
+
*
|
|
41
|
+
* The inner map is keyed by `session.id`, which arrives off the request path
|
|
42
|
+
* and contains no `/`, so it can be exactly `__proto__`. On a plain object
|
|
43
|
+
* literal that key would reach the inherited `__proto__` setter and
|
|
44
|
+
* re-parent the map instead of creating an own property, silently dropping
|
|
45
|
+
* the session from the `Object.values` scan in `searchMemory`. The outer key
|
|
46
|
+
* always contains a `/` (see `getUserKey`) and cannot collide, but is
|
|
47
|
+
* created the same way for consistency.
|
|
48
|
+
*/
|
|
49
|
+
this.sessionEvents = /* @__PURE__ */ Object.create(null);
|
|
39
50
|
}
|
|
40
51
|
async addSessionToMemory(session) {
|
|
41
52
|
const userKey = getUserKey(session.appName, session.userId);
|
|
42
53
|
if (!this.sessionEvents[userKey]) {
|
|
43
|
-
this.sessionEvents[userKey] =
|
|
54
|
+
this.sessionEvents[userKey] = /* @__PURE__ */ Object.create(null);
|
|
44
55
|
}
|
|
45
56
|
this.sessionEvents[userKey][session.id] = session.events.filter(
|
|
46
57
|
(event) => {
|
|
@@ -116,6 +116,9 @@ class VertexAiMemoryBankService {
|
|
|
116
116
|
if (options.client) {
|
|
117
117
|
this.memories = options.client.agentEnginesInternal.memories;
|
|
118
118
|
} else {
|
|
119
|
+
if (this.expressModeApiKey && (!this.projectId || !this.location)) {
|
|
120
|
+
throw new Error(import_vertex_ai_utils.EXPRESS_MODE_UNSUPPORTED_MESSAGE);
|
|
121
|
+
}
|
|
119
122
|
const client = new import_vertexai.Client({
|
|
120
123
|
project: this.projectId,
|
|
121
124
|
location: this.location
|
|
@@ -99,8 +99,10 @@ class BasePlugin {
|
|
|
99
99
|
* @param params.invocationContext The context for the entire invocation.
|
|
100
100
|
* @param params.event The event raised by the runner.
|
|
101
101
|
* @returns An optional value. A non-`undefined` return may be used by the
|
|
102
|
-
* framework to modify or replace the response.
|
|
103
|
-
*
|
|
102
|
+
* framework to modify or replace the response. Copy `params.event` when
|
|
103
|
+
* constructing a replacement to preserve fields that are not being
|
|
104
|
+
* modified, such as event actions. Returning `undefined` allows the
|
|
105
|
+
* original response to be used.
|
|
104
106
|
*/
|
|
105
107
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
106
108
|
async onEventCallback(params) {
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var global_instruction_plugin_exports = {};
|
|
26
|
+
__export(global_instruction_plugin_exports, {
|
|
27
|
+
GlobalInstructionPlugin: () => GlobalInstructionPlugin
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(global_instruction_plugin_exports);
|
|
30
|
+
var import_instructions = require("../agents/instructions.js");
|
|
31
|
+
var import_readonly_context = require("../agents/readonly_context.js");
|
|
32
|
+
var import_base_plugin = require("./base_plugin.js");
|
|
33
|
+
/**
|
|
34
|
+
* @license
|
|
35
|
+
* Copyright 2026 Google LLC
|
|
36
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
37
|
+
*/
|
|
38
|
+
class GlobalInstructionPlugin extends import_base_plugin.BasePlugin {
|
|
39
|
+
/**
|
|
40
|
+
* Initializes the GlobalInstructionPlugin.
|
|
41
|
+
*
|
|
42
|
+
* @param globalInstruction The instruction to apply globally. Can be a string
|
|
43
|
+
* or an InstructionProvider function that takes ReadonlyContext and
|
|
44
|
+
* returns a string (sync or async).
|
|
45
|
+
* @param name The name of the plugin (defaults to 'global_instruction').
|
|
46
|
+
*/
|
|
47
|
+
constructor(globalInstruction, name = "global_instruction") {
|
|
48
|
+
super(name);
|
|
49
|
+
this.globalInstruction = globalInstruction;
|
|
50
|
+
}
|
|
51
|
+
async beforeModelCallback(params) {
|
|
52
|
+
if (!this.globalInstruction) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const readonlyContext = new import_readonly_context.ReadonlyContext(
|
|
56
|
+
params.callbackContext.invocationContext
|
|
57
|
+
);
|
|
58
|
+
const finalGlobalInstruction = await this.resolveGlobalInstruction(readonlyContext);
|
|
59
|
+
if (!finalGlobalInstruction) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (!params.llmRequest.config) {
|
|
63
|
+
params.llmRequest.config = {};
|
|
64
|
+
}
|
|
65
|
+
const existingInstruction = params.llmRequest.config.systemInstruction;
|
|
66
|
+
if (!existingInstruction || Array.isArray(existingInstruction) && existingInstruction.length === 0) {
|
|
67
|
+
params.llmRequest.config.systemInstruction = finalGlobalInstruction;
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (typeof existingInstruction === "string") {
|
|
71
|
+
params.llmRequest.config.systemInstruction = `${finalGlobalInstruction}
|
|
72
|
+
|
|
73
|
+
${existingInstruction}`;
|
|
74
|
+
} else if (Array.isArray(existingInstruction)) {
|
|
75
|
+
params.llmRequest.config.systemInstruction = [
|
|
76
|
+
finalGlobalInstruction,
|
|
77
|
+
...existingInstruction
|
|
78
|
+
];
|
|
79
|
+
} else {
|
|
80
|
+
params.llmRequest.config.systemInstruction = [
|
|
81
|
+
finalGlobalInstruction,
|
|
82
|
+
existingInstruction
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
async resolveGlobalInstruction(readonlyContext) {
|
|
88
|
+
if (typeof this.globalInstruction === "string") {
|
|
89
|
+
return await (0, import_instructions.injectSessionState)(this.globalInstruction, readonlyContext);
|
|
90
|
+
}
|
|
91
|
+
return await this.globalInstruction(readonlyContext);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
95
|
+
0 && (module.exports = {
|
|
96
|
+
GlobalInstructionPlugin
|
|
97
|
+
});
|
|
@@ -142,7 +142,7 @@ class Runner {
|
|
|
142
142
|
ctx,
|
|
143
143
|
this,
|
|
144
144
|
async function* () {
|
|
145
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
145
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
146
146
|
const session = await this.sessionService.getSession({
|
|
147
147
|
appName: this.appName,
|
|
148
148
|
userId,
|
|
@@ -203,7 +203,7 @@ class Runner {
|
|
|
203
203
|
throw new Error("No parts in the newMessage.");
|
|
204
204
|
}
|
|
205
205
|
if (runConfig.saveInputBlobsAsArtifacts) {
|
|
206
|
-
await this.saveArtifacts(
|
|
206
|
+
newMessage = await this.saveArtifacts(
|
|
207
207
|
invocationContext.invocationId,
|
|
208
208
|
session.userId,
|
|
209
209
|
session.id,
|
|
@@ -259,24 +259,31 @@ class Runner {
|
|
|
259
259
|
if ((_h = params.abortSignal) == null ? void 0 : _h.aborted) {
|
|
260
260
|
return;
|
|
261
261
|
}
|
|
262
|
-
if (!event.partial) {
|
|
263
|
-
await this.sessionService.appendEvent({ session, event });
|
|
264
|
-
}
|
|
265
262
|
const modifiedEvent = await this.pluginManager.runOnEventCallback({
|
|
266
263
|
invocationContext,
|
|
267
264
|
event
|
|
268
265
|
});
|
|
269
|
-
|
|
270
|
-
|
|
266
|
+
const outputEvent = modifiedEvent ? {
|
|
267
|
+
...modifiedEvent,
|
|
268
|
+
id: event.id,
|
|
269
|
+
invocationId: event.invocationId,
|
|
270
|
+
timestamp: event.timestamp,
|
|
271
|
+
author: modifiedEvent.author || event.author,
|
|
272
|
+
branch: (_i = modifiedEvent.branch) != null ? _i : event.branch
|
|
273
|
+
} : event;
|
|
274
|
+
if (!event.partial) {
|
|
275
|
+
await this.sessionService.appendEvent({
|
|
276
|
+
session,
|
|
277
|
+
event: outputEvent
|
|
278
|
+
});
|
|
271
279
|
}
|
|
272
|
-
if (
|
|
273
|
-
|
|
274
|
-
} else {
|
|
275
|
-
yield event;
|
|
280
|
+
if ((_j = params.abortSignal) == null ? void 0 : _j.aborted) {
|
|
281
|
+
return;
|
|
276
282
|
}
|
|
283
|
+
yield outputEvent;
|
|
277
284
|
}
|
|
278
285
|
await this.pluginManager.runAfterRunCallback({ invocationContext });
|
|
279
|
-
if ((
|
|
286
|
+
if ((_k = params.abortSignal) == null ? void 0 : _k.aborted) {
|
|
280
287
|
return;
|
|
281
288
|
}
|
|
282
289
|
}
|
|
@@ -291,7 +298,7 @@ class Runner {
|
|
|
291
298
|
}
|
|
292
299
|
/**
|
|
293
300
|
* Saves artifacts from the message parts and replaces the inline data with
|
|
294
|
-
* a file name placeholder.
|
|
301
|
+
* a file name placeholder and optional file reference.
|
|
295
302
|
*
|
|
296
303
|
* @param invocationId The current invocation ID.
|
|
297
304
|
* @param userId The user ID of the session.
|
|
@@ -301,28 +308,67 @@ class Runner {
|
|
|
301
308
|
async saveArtifacts(invocationId, userId, sessionId, message) {
|
|
302
309
|
var _a2;
|
|
303
310
|
if (!this.artifactService || !((_a2 = message.parts) == null ? void 0 : _a2.length)) {
|
|
304
|
-
return;
|
|
311
|
+
return message;
|
|
305
312
|
}
|
|
306
313
|
const sessionKey = {
|
|
307
314
|
appName: this.appName,
|
|
308
315
|
userId,
|
|
309
316
|
sessionId
|
|
310
317
|
};
|
|
318
|
+
const newParts = [];
|
|
319
|
+
let modified = false;
|
|
311
320
|
for (let i = 0; i < message.parts.length; i++) {
|
|
312
321
|
const part = message.parts[i];
|
|
313
322
|
if (!part.inlineData) {
|
|
323
|
+
newParts.push(part);
|
|
314
324
|
continue;
|
|
315
325
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
326
|
+
try {
|
|
327
|
+
const inlineData = part.inlineData;
|
|
328
|
+
const fileName = inlineData.displayName || `artifact_${invocationId}_${i}`;
|
|
329
|
+
const version = await this.artifactService.saveArtifact({
|
|
330
|
+
...sessionKey,
|
|
331
|
+
filename: fileName,
|
|
332
|
+
artifact: part
|
|
333
|
+
});
|
|
334
|
+
newParts.push((0, import_genai.createPartFromText)(`[Uploaded Artifact: "${fileName}"]`));
|
|
335
|
+
try {
|
|
336
|
+
const artifactVersion = await this.artifactService.getArtifactVersion(
|
|
337
|
+
{
|
|
338
|
+
...sessionKey,
|
|
339
|
+
filename: fileName,
|
|
340
|
+
version
|
|
341
|
+
}
|
|
342
|
+
);
|
|
343
|
+
if ((artifactVersion == null ? void 0 : artifactVersion.canonicalUri) && /^(gs|https?):/i.test(artifactVersion.canonicalUri)) {
|
|
344
|
+
newParts.push({
|
|
345
|
+
fileData: {
|
|
346
|
+
fileUri: artifactVersion.canonicalUri,
|
|
347
|
+
mimeType: artifactVersion.mimeType || inlineData.mimeType || "",
|
|
348
|
+
displayName: fileName
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
} catch (error) {
|
|
353
|
+
import_logger.logger.warn(
|
|
354
|
+
`Failed to resolve artifact version for ${fileName}:`,
|
|
355
|
+
error
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
modified = true;
|
|
359
|
+
import_logger.logger.info(`Successfully saved artifact: ${fileName}`);
|
|
360
|
+
} catch (error) {
|
|
361
|
+
import_logger.logger.error(`Failed to save artifact for part ${i}:`, error);
|
|
362
|
+
newParts.push(part);
|
|
363
|
+
}
|
|
325
364
|
}
|
|
365
|
+
if (!modified) {
|
|
366
|
+
return message;
|
|
367
|
+
}
|
|
368
|
+
return {
|
|
369
|
+
...message,
|
|
370
|
+
parts: newParts
|
|
371
|
+
};
|
|
326
372
|
}
|
|
327
373
|
/**
|
|
328
374
|
* Determines the next agent to run to continue the session. This is primarily
|
|
@@ -91,7 +91,12 @@ class BaseSessionService {
|
|
|
91
91
|
if (key.startsWith(import_state.State.TEMP_PREFIX)) {
|
|
92
92
|
continue;
|
|
93
93
|
}
|
|
94
|
-
session.state
|
|
94
|
+
Object.defineProperty(session.state, key, {
|
|
95
|
+
value,
|
|
96
|
+
writable: true,
|
|
97
|
+
enumerable: true,
|
|
98
|
+
configurable: true
|
|
99
|
+
});
|
|
95
100
|
}
|
|
96
101
|
}
|
|
97
102
|
}
|
|
@@ -100,7 +105,7 @@ function trimTempDeltaState(event) {
|
|
|
100
105
|
return event;
|
|
101
106
|
}
|
|
102
107
|
const stateDelta = event.actions.stateDelta;
|
|
103
|
-
const filteredStateDelta =
|
|
108
|
+
const filteredStateDelta = /* @__PURE__ */ Object.create(null);
|
|
104
109
|
for (const [key, value] of Object.entries(stateDelta)) {
|
|
105
110
|
if (!key.startsWith(import_state.State.TEMP_PREFIX)) {
|
|
106
111
|
filteredStateDelta[key] = value;
|
|
@@ -110,7 +115,7 @@ function trimTempDeltaState(event) {
|
|
|
110
115
|
return event;
|
|
111
116
|
}
|
|
112
117
|
function trimTempState(state) {
|
|
113
|
-
const filteredState =
|
|
118
|
+
const filteredState = /* @__PURE__ */ Object.create(null);
|
|
114
119
|
for (const [key, value] of Object.entries(state)) {
|
|
115
120
|
if (!key.startsWith(import_state.State.TEMP_PREFIX)) {
|
|
116
121
|
filteredState[key] = value;
|
|
@@ -49,15 +49,15 @@ class InMemorySessionService extends import_base_session_service.BaseSessionServ
|
|
|
49
49
|
* A map from app name to a map from user ID to a map from session ID to
|
|
50
50
|
* session.
|
|
51
51
|
*/
|
|
52
|
-
this.sessions =
|
|
52
|
+
this.sessions = /* @__PURE__ */ Object.create(null);
|
|
53
53
|
/**
|
|
54
54
|
* A map from app name to a map from user ID to a map from key to the value.
|
|
55
55
|
*/
|
|
56
|
-
this.userState =
|
|
56
|
+
this.userState = /* @__PURE__ */ Object.create(null);
|
|
57
57
|
/**
|
|
58
58
|
* A map from app name to a map from key to the value.
|
|
59
59
|
*/
|
|
60
|
-
this.appState =
|
|
60
|
+
this.appState = /* @__PURE__ */ Object.create(null);
|
|
61
61
|
}
|
|
62
62
|
async createSession({
|
|
63
63
|
appName,
|
|
@@ -76,10 +76,10 @@ class InMemorySessionService extends import_base_session_service.BaseSessionServ
|
|
|
76
76
|
lastUpdateTime: Date.now()
|
|
77
77
|
});
|
|
78
78
|
if (!this.sessions[appName]) {
|
|
79
|
-
this.sessions[appName] =
|
|
79
|
+
this.sessions[appName] = /* @__PURE__ */ Object.create(null);
|
|
80
80
|
}
|
|
81
81
|
if (!this.sessions[appName][userId]) {
|
|
82
|
-
this.sessions[appName][userId] =
|
|
82
|
+
this.sessions[appName][userId] = /* @__PURE__ */ Object.create(null);
|
|
83
83
|
}
|
|
84
84
|
this.sessions[appName][userId][session.id] = session;
|
|
85
85
|
const copiedSession = (0, import_lodash_es.cloneDeep)(session);
|
|
@@ -244,12 +244,12 @@ class InMemorySessionService extends import_base_session_service.BaseSessionServ
|
|
|
244
244
|
if (event.actions && event.actions.stateDelta) {
|
|
245
245
|
for (const key of Object.keys(event.actions.stateDelta)) {
|
|
246
246
|
if (key.startsWith(import_state.State.APP_PREFIX)) {
|
|
247
|
-
this.appState[appName] = this.appState[appName] ||
|
|
247
|
+
this.appState[appName] = this.appState[appName] || /* @__PURE__ */ Object.create(null);
|
|
248
248
|
this.appState[appName][key.replace(import_state.State.APP_PREFIX, "")] = event.actions.stateDelta[key];
|
|
249
249
|
}
|
|
250
250
|
if (key.startsWith(import_state.State.USER_PREFIX)) {
|
|
251
|
-
this.userState[appName] = this.userState[appName] ||
|
|
252
|
-
this.userState[appName][userId] = this.userState[appName][userId] ||
|
|
251
|
+
this.userState[appName] = this.userState[appName] || /* @__PURE__ */ Object.create(null);
|
|
252
|
+
this.userState[appName][userId] = this.userState[appName][userId] || /* @__PURE__ */ Object.create(null);
|
|
253
253
|
this.userState[appName][userId][key.replace(import_state.State.USER_PREFIX, "")] = event.actions.stateDelta[key];
|
|
254
254
|
}
|
|
255
255
|
}
|