@google/adk 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/a2a/agent_card.js +8 -0
- package/dist/cjs/a2a/agent_executor.js +8 -3
- package/dist/cjs/agents/llm_agent.js +15 -1
- package/dist/cjs/agents/processors/content_processor_utils.js +10 -2
- package/dist/cjs/agents/processors/nl_planning_processor.js +114 -0
- package/dist/cjs/artifacts/gcs_artifact_service.js +13 -7
- package/dist/cjs/auth/auth_credential.js +12 -2
- package/dist/cjs/code_executors/code_execution_utils.js +3 -3
- package/dist/cjs/common.js +45 -0
- package/dist/cjs/examples/example.js +92 -0
- package/dist/cjs/examples/example_util.js +28 -4
- package/dist/cjs/examples/index.js +39 -0
- package/dist/cjs/examples/vertex_ai_example_store.js +39 -0
- package/dist/cjs/index.js +46 -0
- package/dist/cjs/memory/vertex_ai_memory_bank_service.js +17 -5
- package/dist/cjs/models/base_llm.js +1 -6
- package/dist/cjs/models/chrome_prompt_llm.js +16 -2
- package/dist/cjs/models/chrome_prompt_utils.js +54 -2
- package/dist/cjs/models/gemini_llm_connection.js +5 -4
- package/dist/cjs/planners/base_planner.js +56 -0
- package/dist/cjs/planners/built_in_planner.js +85 -0
- package/dist/cjs/planners/plan_re_act_planner.js +172 -0
- package/dist/cjs/plugins/base_plugin.js +46 -61
- package/dist/cjs/tools/example_tool.js +1 -1
- package/dist/cjs/tools/mcp/mcp_session_manager.js +14 -8
- package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +281 -2
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +15 -1
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/base_auth_credential_exchanger.js +70 -0
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +120 -0
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +10 -10
- package/dist/cjs/tools/openapi_tool/common/common.js +139 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +11 -6
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +73 -13
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +146 -34
- package/dist/cjs/tools/openapi_tool/openapi_toolset.js +14 -2
- package/dist/cjs/tools/openapi_tool/rest_api_tool.js +90 -28
- package/dist/cjs/tools/skill/skill_toolset.js +2 -0
- package/dist/cjs/tools/tool_context.js +41 -0
- package/dist/cjs/tools/webmcp/index.js +37 -0
- package/dist/cjs/tools/webmcp/webmcp_tool.js +156 -0
- package/dist/cjs/tools/webmcp/webmcp_toolset.js +116 -0
- package/dist/cjs/tools/webmcp/webmcp_types.js +50 -0
- package/dist/cjs/utils/case_utils.js +52 -2
- package/dist/cjs/utils/client_labels.js +67 -0
- package/dist/cjs/utils/gemini_schema_util.js +103 -3
- package/dist/cjs/utils/hash_utils.js +73 -0
- package/dist/cjs/utils/live_connection_utils.js +10 -9
- package/dist/cjs/utils/model_name.js +17 -2
- package/dist/cjs/utils/simple_zod_to_json.js +5 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/agent_card.js +8 -0
- package/dist/esm/a2a/agent_executor.js +8 -3
- package/dist/esm/agents/llm_agent.js +18 -1
- package/dist/esm/agents/processors/content_processor_utils.js +10 -2
- package/dist/esm/agents/processors/nl_planning_processor.js +87 -0
- package/dist/esm/artifacts/gcs_artifact_service.js +13 -7
- package/dist/esm/auth/auth_credential.js +11 -1
- package/dist/esm/code_executors/code_execution_utils.js +3 -3
- package/dist/esm/common.js +38 -2
- package/dist/esm/examples/example.js +85 -0
- package/dist/esm/examples/example_util.js +25 -3
- package/dist/esm/examples/index.js +11 -0
- package/dist/esm/examples/vertex_ai_example_store.js +11 -0
- package/dist/esm/index.js +51 -1
- package/dist/esm/memory/vertex_ai_memory_bank_service.js +17 -5
- package/dist/esm/models/base_llm.js +2 -7
- package/dist/esm/models/chrome_prompt_llm.js +20 -3
- package/dist/esm/models/chrome_prompt_utils.js +51 -2
- package/dist/esm/models/gemini_llm_connection.js +6 -5
- package/dist/esm/planners/base_planner.js +28 -0
- package/dist/esm/planners/built_in_planner.js +57 -0
- package/dist/esm/planners/plan_re_act_planner.js +145 -0
- package/dist/esm/plugins/base_plugin.js +46 -61
- package/dist/esm/tools/example_tool.js +1 -1
- package/dist/esm/tools/mcp/mcp_session_manager.js +14 -8
- package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +272 -1
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +15 -1
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/base_auth_credential_exchanger.js +43 -0
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +93 -0
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +10 -12
- package/dist/esm/tools/openapi_tool/common/common.js +112 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +11 -6
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +80 -13
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +146 -33
- package/dist/esm/tools/openapi_tool/openapi_toolset.js +14 -2
- package/dist/esm/tools/openapi_tool/rest_api_tool.js +89 -28
- package/dist/esm/tools/skill/skill_toolset.js +2 -0
- package/dist/esm/tools/tool_context.js +15 -0
- package/dist/esm/tools/webmcp/index.js +10 -0
- package/dist/esm/tools/webmcp/webmcp_tool.js +131 -0
- package/dist/esm/tools/webmcp/webmcp_toolset.js +89 -0
- package/dist/esm/tools/webmcp/webmcp_types.js +22 -0
- package/dist/esm/utils/case_utils.js +49 -1
- package/dist/esm/utils/client_labels.js +65 -0
- package/dist/esm/utils/gemini_schema_util.js +102 -3
- package/dist/esm/utils/hash_utils.js +45 -0
- package/dist/esm/utils/live_connection_utils.js +11 -10
- package/dist/esm/utils/model_name.js +15 -2
- package/dist/esm/utils/simple_zod_to_json.js +5 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/agents/llm_agent.d.ts +12 -1
- package/dist/types/agents/processors/nl_planning_processor.d.ts +30 -0
- package/dist/types/auth/auth_credential.d.ts +9 -0
- package/dist/types/common.d.ts +16 -4
- package/dist/types/examples/base_example_provider.d.ts +2 -2
- package/dist/types/examples/example.d.ts +75 -0
- package/dist/types/examples/example_util.d.ts +13 -2
- package/dist/types/examples/index.d.ts +18 -0
- package/dist/types/examples/vertex_ai_example_store.d.ts +7 -0
- package/dist/types/index.d.ts +12 -3
- package/dist/types/memory/memory_entry.d.ts +15 -0
- package/dist/types/memory/vertex_ai_memory_bank_service.d.ts +9 -0
- package/dist/types/models/chrome_prompt_utils.d.ts +29 -0
- package/dist/types/planners/base_planner.d.ts +50 -0
- package/dist/types/planners/built_in_planner.d.ts +53 -0
- package/dist/types/planners/plan_re_act_planner.d.ts +21 -0
- package/dist/types/plugins/base_plugin.d.ts +52 -52
- package/dist/types/skills/skill_registry.d.ts +8 -0
- package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +110 -1
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +32 -2
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/base_auth_credential_exchanger.d.ts +35 -0
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.d.ts +54 -0
- package/dist/types/tools/openapi_tool/common/common.d.ts +60 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +7 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +56 -2
- package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +73 -5
- package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +11 -0
- package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +42 -8
- package/dist/types/tools/tool_context.d.ts +19 -0
- package/dist/types/tools/webmcp/index.d.ts +12 -0
- package/dist/types/tools/webmcp/webmcp_tool.d.ts +47 -0
- package/dist/types/tools/webmcp/webmcp_toolset.d.ts +67 -0
- package/dist/types/tools/webmcp/webmcp_types.d.ts +69 -0
- package/dist/types/utils/case_utils.d.ts +36 -0
- package/dist/types/utils/client_labels.d.ts +33 -0
- package/dist/types/utils/gemini_schema_util.d.ts +13 -0
- package/dist/types/utils/hash_utils.d.ts +25 -0
- package/dist/types/utils/logger.d.ts +10 -2
- package/dist/types/utils/model_name.d.ts +30 -2
- package/dist/types/version.d.ts +1 -1
- package/dist/web/index_web.js +112 -79
- package/dist/web/index_web.js.map +4 -4
- package/package.json +8 -2
|
@@ -0,0 +1,172 @@
|
|
|
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
13
|
+
var __export = (target, all) => {
|
|
14
|
+
for (var name in all)
|
|
15
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
|
+
};
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from))
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
|
+
var plan_re_act_planner_exports = {};
|
|
27
|
+
__export(plan_re_act_planner_exports, {
|
|
28
|
+
PlanReActPlanner: () => PlanReActPlanner
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(plan_re_act_planner_exports);
|
|
31
|
+
var import_base_planner = require("./base_planner.js");
|
|
32
|
+
/**
|
|
33
|
+
* @license
|
|
34
|
+
* Copyright 2026 Google LLC
|
|
35
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
36
|
+
*/
|
|
37
|
+
const PLANNING_TAG = "/*PLANNING*/";
|
|
38
|
+
const REPLANNING_TAG = "/*REPLANNING*/";
|
|
39
|
+
const REASONING_TAG = "/*REASONING*/";
|
|
40
|
+
const ACTION_TAG = "/*ACTION*/";
|
|
41
|
+
const FINAL_ANSWER_TAG = "/*FINAL_ANSWER*/";
|
|
42
|
+
const THOUGHT_PREFIX_TAGS = [
|
|
43
|
+
PLANNING_TAG,
|
|
44
|
+
REASONING_TAG,
|
|
45
|
+
ACTION_TAG,
|
|
46
|
+
REPLANNING_TAG
|
|
47
|
+
];
|
|
48
|
+
const _PlanReActPlanner = class _PlanReActPlanner extends import_base_planner.BasePlanner {
|
|
49
|
+
buildPlanningInstruction(_readonlyContext, _llmRequest) {
|
|
50
|
+
return buildNlPlannerInstruction();
|
|
51
|
+
}
|
|
52
|
+
processPlanningResponse(_callbackContext, responseParts) {
|
|
53
|
+
if (!responseParts || responseParts.length === 0) {
|
|
54
|
+
return void 0;
|
|
55
|
+
}
|
|
56
|
+
const preservedParts = [];
|
|
57
|
+
let firstFcPartIndex = -1;
|
|
58
|
+
for (let i = 0; i < responseParts.length; i++) {
|
|
59
|
+
const part = responseParts[i];
|
|
60
|
+
if (part.functionCall) {
|
|
61
|
+
if (!part.functionCall.name) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
preservedParts.push(part);
|
|
65
|
+
firstFcPartIndex = i;
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
handleNonFunctionCallPart(part, preservedParts);
|
|
69
|
+
}
|
|
70
|
+
if (firstFcPartIndex > 0) {
|
|
71
|
+
for (let j = firstFcPartIndex + 1; j < responseParts.length; j++) {
|
|
72
|
+
if (!responseParts[j].functionCall) {
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
preservedParts.push(responseParts[j]);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return preservedParts;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
__name(_PlanReActPlanner, "PlanReActPlanner");
|
|
82
|
+
let PlanReActPlanner = _PlanReActPlanner;
|
|
83
|
+
function splitByLastPattern(text, separator) {
|
|
84
|
+
const index = text.lastIndexOf(separator);
|
|
85
|
+
if (index === -1) {
|
|
86
|
+
return [text, ""];
|
|
87
|
+
}
|
|
88
|
+
const end = index + separator.length;
|
|
89
|
+
return [text.slice(0, end), text.slice(end)];
|
|
90
|
+
}
|
|
91
|
+
__name(splitByLastPattern, "splitByLastPattern");
|
|
92
|
+
function handleNonFunctionCallPart(responsePart, preservedParts) {
|
|
93
|
+
var _a;
|
|
94
|
+
if (responsePart.text && responsePart.text.includes(FINAL_ANSWER_TAG)) {
|
|
95
|
+
const [reasoningText, finalAnswerText] = splitByLastPattern(
|
|
96
|
+
responsePart.text,
|
|
97
|
+
FINAL_ANSWER_TAG
|
|
98
|
+
);
|
|
99
|
+
if (reasoningText) {
|
|
100
|
+
preservedParts.push(markAsThought({ text: reasoningText }));
|
|
101
|
+
}
|
|
102
|
+
if (finalAnswerText) {
|
|
103
|
+
preservedParts.push({ text: finalAnswerText });
|
|
104
|
+
}
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const responseText = (_a = responsePart.text) != null ? _a : "";
|
|
108
|
+
if (responseText && THOUGHT_PREFIX_TAGS.some((tag) => responseText.startsWith(tag))) {
|
|
109
|
+
preservedParts.push(markAsThought(responsePart));
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
preservedParts.push(responsePart);
|
|
113
|
+
}
|
|
114
|
+
__name(handleNonFunctionCallPart, "handleNonFunctionCallPart");
|
|
115
|
+
function markAsThought(responsePart) {
|
|
116
|
+
if (responsePart.text) {
|
|
117
|
+
return { ...responsePart, thought: true };
|
|
118
|
+
}
|
|
119
|
+
return responsePart;
|
|
120
|
+
}
|
|
121
|
+
__name(markAsThought, "markAsThought");
|
|
122
|
+
function buildNlPlannerInstruction() {
|
|
123
|
+
const highLevelPreamble = `
|
|
124
|
+
When answering the question, try to leverage the available tools to gather the information instead of your memorized knowledge.
|
|
125
|
+
|
|
126
|
+
Follow this process when answering the question: (1) first come up with a plan in natural language text format; (2) Then use tools to execute the plan and provide reasoning between tool code snippets to make a summary of current state and next step. Tool code snippets and reasoning should be interleaved with each other. (3) In the end, return one final answer.
|
|
127
|
+
|
|
128
|
+
Follow this format when answering the question: (1) The planning part should be under ${PLANNING_TAG}. (2) The tool code snippets should be under ${ACTION_TAG}, and the reasoning parts should be under ${REASONING_TAG}. (3) The final answer part should be under ${FINAL_ANSWER_TAG}.
|
|
129
|
+
`;
|
|
130
|
+
const planningPreamble = `
|
|
131
|
+
Below are the requirements for the planning:
|
|
132
|
+
The plan is made to answer the user query if following the plan. The plan is coherent and covers all aspects of information from user query, and only involves the tools that are accessible by the agent. The plan contains the decomposed steps as a numbered list where each step should use one or multiple available tools. By reading the plan, you can intuitively know which tools to trigger or what actions to take.
|
|
133
|
+
If the initial plan cannot be successfully executed, you should learn from previous execution results and revise your plan. The revised plan should be be under ${REPLANNING_TAG}. Then use tools to follow the new plan.
|
|
134
|
+
`;
|
|
135
|
+
const reasoningPreamble = `
|
|
136
|
+
Below are the requirements for the reasoning:
|
|
137
|
+
The reasoning makes a summary of the current trajectory based on the user query and tool outputs. Based on the tool outputs and plan, the reasoning also comes up with instructions to the next steps, making the trajectory closer to the final answer.
|
|
138
|
+
`;
|
|
139
|
+
const finalAnswerPreamble = `
|
|
140
|
+
Below are the requirements for the final answer:
|
|
141
|
+
The final answer should be precise and follow query formatting requirements. Some queries may not be answerable with the available tools and information. In those cases, inform the user why you cannot process their query and ask for more information.
|
|
142
|
+
`;
|
|
143
|
+
const toolCodeWithoutPythonLibrariesPreamble = `
|
|
144
|
+
Below are the requirements for the tool code:
|
|
145
|
+
|
|
146
|
+
**Custom Tools:** The available tools are described in the context and can be directly used.
|
|
147
|
+
- Code must be valid self-contained Python snippets with no imports and no references to tools or Python libraries that are not in the context.
|
|
148
|
+
- You cannot use any parameters or fields that are not explicitly defined in the APIs in the context.
|
|
149
|
+
- The code snippets should be readable, efficient, and directly relevant to the user query and reasoning steps.
|
|
150
|
+
- When using the tools, you should use the library name together with the function name, e.g., vertex_search.search().
|
|
151
|
+
- If Python libraries are not provided in the context, NEVER write your own code other than the function calls using the provided tools.
|
|
152
|
+
`;
|
|
153
|
+
const userInputPreamble = `
|
|
154
|
+
VERY IMPORTANT instruction that you MUST follow in addition to the above instructions:
|
|
155
|
+
|
|
156
|
+
You should ask for clarification if you need more information to answer the question.
|
|
157
|
+
You should prefer using the information available in the context instead of repeated tool use.
|
|
158
|
+
`;
|
|
159
|
+
return [
|
|
160
|
+
highLevelPreamble,
|
|
161
|
+
planningPreamble,
|
|
162
|
+
reasoningPreamble,
|
|
163
|
+
finalAnswerPreamble,
|
|
164
|
+
toolCodeWithoutPythonLibrariesPreamble,
|
|
165
|
+
userInputPreamble
|
|
166
|
+
].join("\n\n");
|
|
167
|
+
}
|
|
168
|
+
__name(buildNlPlannerInstruction, "buildNlPlannerInstruction");
|
|
169
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
170
|
+
0 && (module.exports = {
|
|
171
|
+
PlanReActPlanner
|
|
172
|
+
});
|
|
@@ -65,14 +65,13 @@ const _BasePlugin = class _BasePlugin {
|
|
|
65
65
|
* This callback helps logging and modifying the user message before the
|
|
66
66
|
* runner starts the invocation.
|
|
67
67
|
*
|
|
68
|
-
* @param
|
|
69
|
-
* @param
|
|
68
|
+
* @param _params.invocationContext The context for the entire invocation.
|
|
69
|
+
* @param _params.userMessage The message content input by user.
|
|
70
70
|
* @returns An optional `Content` to be returned to the ADK. Returning a
|
|
71
71
|
* value to replace the user message. Returning `undefined` to proceed
|
|
72
72
|
* normally.
|
|
73
73
|
*/
|
|
74
|
-
|
|
75
|
-
async onUserMessageCallback(params) {
|
|
74
|
+
async onUserMessageCallback(_params) {
|
|
76
75
|
return;
|
|
77
76
|
}
|
|
78
77
|
/**
|
|
@@ -81,14 +80,13 @@ const _BasePlugin = class _BasePlugin {
|
|
|
81
80
|
* This is the first callback to be called in the lifecycle, ideal for global
|
|
82
81
|
* setup or initialization tasks.
|
|
83
82
|
*
|
|
84
|
-
* @param
|
|
83
|
+
* @param _params.invocationContext The context for the entire invocation, containing
|
|
85
84
|
* session information, the root agent, etc.
|
|
86
85
|
* @returns An optional `Event` to be returned to the ADK. Returning a value
|
|
87
86
|
* to halt execution of the runner and ends the runner with that event.
|
|
88
87
|
* Return `undefined` to proceed normally.
|
|
89
88
|
*/
|
|
90
|
-
|
|
91
|
-
async beforeRunCallback(params) {
|
|
89
|
+
async beforeRunCallback(_params) {
|
|
92
90
|
return;
|
|
93
91
|
}
|
|
94
92
|
/**
|
|
@@ -97,16 +95,15 @@ const _BasePlugin = class _BasePlugin {
|
|
|
97
95
|
* This is the ideal place to make modification to the event before the event
|
|
98
96
|
* is handled by the underlying agent app.
|
|
99
97
|
*
|
|
100
|
-
* @param
|
|
101
|
-
* @param
|
|
98
|
+
* @param _params.invocationContext The context for the entire invocation.
|
|
99
|
+
* @param _params.event The event raised by the runner.
|
|
102
100
|
* @returns An optional value. A non-`undefined` return may be used by the
|
|
103
|
-
* framework to modify or replace the response. Copy
|
|
104
|
-
* constructing a replacement to preserve fields that are not
|
|
105
|
-
* modified, such as event actions. Returning `undefined` allows the
|
|
101
|
+
* framework to modify or replace the response. Copy the incoming
|
|
102
|
+
* `event` when constructing a replacement to preserve fields that are not
|
|
103
|
+
* being modified, such as event actions. Returning `undefined` allows the
|
|
106
104
|
* original response to be used.
|
|
107
105
|
*/
|
|
108
|
-
|
|
109
|
-
async onEventCallback(params) {
|
|
106
|
+
async onEventCallback(_params) {
|
|
110
107
|
return;
|
|
111
108
|
}
|
|
112
109
|
/**
|
|
@@ -115,11 +112,10 @@ const _BasePlugin = class _BasePlugin {
|
|
|
115
112
|
* This is the final callback in the ADK lifecycle, suitable for cleanup,
|
|
116
113
|
* final logging, or reporting tasks.
|
|
117
114
|
*
|
|
118
|
-
* @param
|
|
115
|
+
* @param _params.invocationContext The context for the entire invocation.
|
|
119
116
|
* @returns undefined
|
|
120
117
|
*/
|
|
121
|
-
|
|
122
|
-
async afterRunCallback(params) {
|
|
118
|
+
async afterRunCallback(_params) {
|
|
123
119
|
return;
|
|
124
120
|
}
|
|
125
121
|
/**
|
|
@@ -128,14 +124,13 @@ const _BasePlugin = class _BasePlugin {
|
|
|
128
124
|
* This callback can be used for logging, setup, or to short-circuit the
|
|
129
125
|
* agent's execution by returning a value.
|
|
130
126
|
*
|
|
131
|
-
* @param
|
|
132
|
-
* @param
|
|
127
|
+
* @param _params.agent The agent that is about to run.
|
|
128
|
+
* @param _params.callbackContext The context for the agent invocation.
|
|
133
129
|
* @returns An optional `Content` object. If a value is returned, it will
|
|
134
130
|
* bypass the agent's callbacks and its execution, and return this value
|
|
135
131
|
* directly. Returning `undefined` allows the agent to proceed normally.
|
|
136
132
|
*/
|
|
137
|
-
|
|
138
|
-
async beforeAgentCallback(params) {
|
|
133
|
+
async beforeAgentCallback(_params) {
|
|
139
134
|
return;
|
|
140
135
|
}
|
|
141
136
|
/**
|
|
@@ -144,14 +139,13 @@ const _BasePlugin = class _BasePlugin {
|
|
|
144
139
|
* This callback can be used to inspect, log, or modify the agent's final
|
|
145
140
|
* result before it is returned.
|
|
146
141
|
*
|
|
147
|
-
* @param
|
|
148
|
-
* @param
|
|
142
|
+
* @param _params.agent The agent that has just run.
|
|
143
|
+
* @param _params.callbackContext The context for the agent invocation.
|
|
149
144
|
* @returns An optional `Content` object. If a value is returned, it will
|
|
150
145
|
* replace the agent's original result. Returning `undefined` uses the
|
|
151
146
|
* original, unmodified result.
|
|
152
147
|
*/
|
|
153
|
-
|
|
154
|
-
async afterAgentCallback(params) {
|
|
148
|
+
async afterAgentCallback(_params) {
|
|
155
149
|
return;
|
|
156
150
|
}
|
|
157
151
|
/**
|
|
@@ -192,14 +186,13 @@ const _BasePlugin = class _BasePlugin {
|
|
|
192
186
|
* object. It can also be used to implement caching by returning a cached
|
|
193
187
|
* `LlmResponse`, which would skip the actual model call.
|
|
194
188
|
*
|
|
195
|
-
* @param
|
|
196
|
-
* @param
|
|
189
|
+
* @param _params.callbackContext The context for the current agent call.
|
|
190
|
+
* @param _params.llmRequest The prepared request object to be sent to the model.
|
|
197
191
|
* @returns An optional value. The interpretation of a non-`undefined`
|
|
198
192
|
* trigger an early exit and returns the response immediately. Returning
|
|
199
193
|
* `undefined` allows the LLM request to proceed normally.
|
|
200
194
|
*/
|
|
201
|
-
|
|
202
|
-
async beforeModelCallback(params) {
|
|
195
|
+
async beforeModelCallback(_params) {
|
|
203
196
|
return;
|
|
204
197
|
}
|
|
205
198
|
/**
|
|
@@ -208,14 +201,13 @@ const _BasePlugin = class _BasePlugin {
|
|
|
208
201
|
* This is the ideal place to log model responses, collect metrics on token
|
|
209
202
|
* usage, or perform post-processing on the raw `LlmResponse`.
|
|
210
203
|
*
|
|
211
|
-
* @param
|
|
212
|
-
* @param
|
|
204
|
+
* @param _params.callbackContext The context for the current agent call.
|
|
205
|
+
* @param _params.llmResponse The response object received from the model.
|
|
213
206
|
* @returns An optional value. A non-`undefined` return may be used by the
|
|
214
207
|
* framework to modify or replace the response. Returning `undefined`
|
|
215
208
|
* allows the original response to be used.
|
|
216
209
|
*/
|
|
217
|
-
|
|
218
|
-
async afterModelCallback(params) {
|
|
210
|
+
async afterModelCallback(_params) {
|
|
219
211
|
return;
|
|
220
212
|
}
|
|
221
213
|
/**
|
|
@@ -224,28 +216,24 @@ const _BasePlugin = class _BasePlugin {
|
|
|
224
216
|
* This callback provides an opportunity to handle model errors gracefully,
|
|
225
217
|
* potentially providing alternative responses or recovery mechanisms.
|
|
226
218
|
*
|
|
227
|
-
* @param
|
|
228
|
-
* @param
|
|
219
|
+
* @param _params.callbackContext The context for the current agent call.
|
|
220
|
+
* @param _params.llmRequest The request that was sent to the model when the error
|
|
229
221
|
* occurred.
|
|
230
|
-
* @param
|
|
222
|
+
* @param _params.error The exception that was raised during model execution.
|
|
231
223
|
* @returns An optional LlmResponse. If an LlmResponse is returned, it will be
|
|
232
224
|
* used instead of propagating the error. Returning `undefined` allows
|
|
233
225
|
* the original error to be raised.
|
|
234
226
|
*/
|
|
235
|
-
|
|
236
|
-
async onModelErrorCallback(params) {
|
|
227
|
+
async onModelErrorCallback(_params) {
|
|
237
228
|
return;
|
|
238
229
|
}
|
|
239
|
-
|
|
240
|
-
async beforeToolSelection(params) {
|
|
230
|
+
async beforeToolSelection(_params) {
|
|
241
231
|
return;
|
|
242
232
|
}
|
|
243
|
-
|
|
244
|
-
async beforeContextCompaction(params) {
|
|
233
|
+
async beforeContextCompaction(_params) {
|
|
245
234
|
return;
|
|
246
235
|
}
|
|
247
|
-
|
|
248
|
-
async afterContextCompaction(params) {
|
|
236
|
+
async afterContextCompaction(_params) {
|
|
249
237
|
return;
|
|
250
238
|
}
|
|
251
239
|
/**
|
|
@@ -254,16 +242,15 @@ const _BasePlugin = class _BasePlugin {
|
|
|
254
242
|
* This callback is useful for logging tool usage, input validation, or
|
|
255
243
|
* modifying the arguments before they are passed to the tool.
|
|
256
244
|
*
|
|
257
|
-
* @param
|
|
258
|
-
* @param
|
|
245
|
+
* @param _params.tool The tool instance that is about to be executed.
|
|
246
|
+
* @param _params.toolArgs The dictionary of arguments to be used for invoking the
|
|
259
247
|
* tool.
|
|
260
|
-
* @param
|
|
248
|
+
* @param _params.toolContext The context specific to the tool execution.
|
|
261
249
|
* @returns An optional dictionary. If a dictionary is returned, it will stop
|
|
262
250
|
* the tool execution and return this response immediately. Returning
|
|
263
251
|
* `undefined` uses the original, unmodified arguments.
|
|
264
252
|
*/
|
|
265
|
-
|
|
266
|
-
async beforeToolCallback(params) {
|
|
253
|
+
async beforeToolCallback(_params) {
|
|
267
254
|
return;
|
|
268
255
|
}
|
|
269
256
|
/**
|
|
@@ -272,17 +259,16 @@ const _BasePlugin = class _BasePlugin {
|
|
|
272
259
|
* This callback allows for inspecting, logging, or modifying the result
|
|
273
260
|
* returned by a tool.
|
|
274
261
|
*
|
|
275
|
-
* @param
|
|
276
|
-
* @param
|
|
277
|
-
* @param
|
|
278
|
-
* @param
|
|
262
|
+
* @param _params.tool The tool instance that has just been executed.
|
|
263
|
+
* @param _params.toolArgs The original arguments that were passed to the tool.
|
|
264
|
+
* @param _params.toolContext The context specific to the tool execution.
|
|
265
|
+
* @param _params.result The dictionary returned by the tool invocation.
|
|
279
266
|
* @returns An optional dictionary. If a dictionary is returned, it will
|
|
280
267
|
* **replace** the original result from the tool. This allows for
|
|
281
268
|
* post-processing or altering tool outputs. Returning `undefined` uses
|
|
282
269
|
* the original, unmodified result.
|
|
283
270
|
*/
|
|
284
|
-
|
|
285
|
-
async afterToolCallback(params) {
|
|
271
|
+
async afterToolCallback(_params) {
|
|
286
272
|
return;
|
|
287
273
|
}
|
|
288
274
|
/**
|
|
@@ -301,16 +287,15 @@ const _BasePlugin = class _BasePlugin {
|
|
|
301
287
|
* This callback provides an opportunity to handle tool errors gracefully,
|
|
302
288
|
* potentially providing alternative responses or recovery mechanisms.
|
|
303
289
|
*
|
|
304
|
-
* @param
|
|
305
|
-
* @param
|
|
306
|
-
* @param
|
|
307
|
-
* @param
|
|
290
|
+
* @param _params.tool The tool instance that encountered an error.
|
|
291
|
+
* @param _params.toolArgs The arguments that were passed to the tool.
|
|
292
|
+
* @param _params.toolContext The context specific to the tool execution.
|
|
293
|
+
* @param _params.error The exception that was raised during tool execution.
|
|
308
294
|
* @returns An optional dictionary. If a dictionary is returned, it will be
|
|
309
295
|
* used as the tool response instead of propagating the error. Returning
|
|
310
296
|
* `undefined` allows the original error to be raised.
|
|
311
297
|
*/
|
|
312
|
-
|
|
313
|
-
async onToolErrorCallback(params) {
|
|
298
|
+
async onToolErrorCallback(_params) {
|
|
314
299
|
return;
|
|
315
300
|
}
|
|
316
301
|
};
|
|
@@ -59,7 +59,7 @@ const _ExampleTool = class _ExampleTool extends import_base_tool.BaseTool {
|
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
61
|
(0, import_llm_request.appendInstructions)(llmRequest, [
|
|
62
|
-
(0, import_example_util.buildExampleSi)(this.examples, parts[0].text, llmRequest.model)
|
|
62
|
+
await (0, import_example_util.buildExampleSi)(this.examples, parts[0].text, llmRequest.model)
|
|
63
63
|
]);
|
|
64
64
|
}
|
|
65
65
|
};
|
|
@@ -38,6 +38,7 @@ __export(mcp_session_manager_exports, {
|
|
|
38
38
|
MCPSessionManager: () => MCPSessionManager
|
|
39
39
|
});
|
|
40
40
|
module.exports = __toCommonJS(mcp_session_manager_exports);
|
|
41
|
+
var import_client_labels = require("../../utils/client_labels.js");
|
|
41
42
|
var import_error_utils = require("../../utils/error_utils.js");
|
|
42
43
|
var import_logger = require("../../utils/logger.js");
|
|
43
44
|
var import_optional_peer = require("../../utils/optional_peer.js");
|
|
@@ -54,13 +55,24 @@ function logTransportError(err) {
|
|
|
54
55
|
import_logger.logger.error("MCP transport error: " + (0, import_error_utils.formatError)(err));
|
|
55
56
|
}
|
|
56
57
|
__name(logTransportError, "logTransportError");
|
|
58
|
+
function buildTransportOptions(params) {
|
|
59
|
+
const { transportOptions, header } = params;
|
|
60
|
+
const callerHeaders = (transportOptions == null ? void 0 : transportOptions.requestInit) === void 0 ? header : transportOptions.requestInit.headers;
|
|
61
|
+
return {
|
|
62
|
+
...transportOptions,
|
|
63
|
+
requestInit: {
|
|
64
|
+
...transportOptions == null ? void 0 : transportOptions.requestInit,
|
|
65
|
+
headers: (0, import_client_labels.mergeTrackingHeaders)(callerHeaders)
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
__name(buildTransportOptions, "buildTransportOptions");
|
|
57
70
|
const _MCPSessionManager = class _MCPSessionManager {
|
|
58
71
|
constructor(connectionParams) {
|
|
59
72
|
this.activeSessions = /* @__PURE__ */ new Set();
|
|
60
73
|
this.connectionParams = connectionParams;
|
|
61
74
|
}
|
|
62
75
|
async createSession() {
|
|
63
|
-
var _a;
|
|
64
76
|
const { Client } = await (0, import_optional_peer.loadOptionalPeer)(
|
|
65
77
|
MCP_SDK,
|
|
66
78
|
() => Promise.resolve().then(() => __toESM(require("@modelcontextprotocol/sdk/client/index.js"), 1))
|
|
@@ -81,19 +93,13 @@ const _MCPSessionManager = class _MCPSessionManager {
|
|
|
81
93
|
break;
|
|
82
94
|
}
|
|
83
95
|
case "StreamableHTTPConnectionParams": {
|
|
84
|
-
const options = (_a = this.connectionParams.transportOptions) != null ? _a : {};
|
|
85
|
-
if (!options.requestInit && this.connectionParams.header !== void 0) {
|
|
86
|
-
options.requestInit = {
|
|
87
|
-
headers: this.connectionParams.header
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
96
|
const { StreamableHTTPClientTransport } = await (0, import_optional_peer.loadOptionalPeer)(
|
|
91
97
|
MCP_SDK,
|
|
92
98
|
() => Promise.resolve().then(() => __toESM(require("@modelcontextprotocol/sdk/client/streamableHttp.js"), 1))
|
|
93
99
|
);
|
|
94
100
|
const transport = new StreamableHTTPClientTransport(
|
|
95
101
|
new URL(this.connectionParams.url),
|
|
96
|
-
|
|
102
|
+
buildTransportOptions(this.connectionParams)
|
|
97
103
|
);
|
|
98
104
|
transport.onerror = logTransportError;
|
|
99
105
|
await client.connect(transport);
|