@iqai/adk 0.5.6 → 0.5.7
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/CHANGELOG.md +6 -0
- package/dist/index.d.mts +189 -189
- package/dist/index.d.ts +189 -189
- package/dist/index.js +525 -500
- package/dist/index.mjs +444 -419
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -4666,248 +4666,29 @@ var AgentTool = (_class15 = class extends BaseTool {
|
|
|
4666
4666
|
}
|
|
4667
4667
|
}, _class15);
|
|
4668
4668
|
|
|
4669
|
-
// src/tools/tool
|
|
4670
|
-
var ToolContext = class extends CallbackContext {
|
|
4671
|
-
/**
|
|
4672
|
-
* The function call id of the current tool call. This id was
|
|
4673
|
-
* returned in the function call event from LLM to identify a function call.
|
|
4674
|
-
* If LLM didn't return this id, ADK will assign one to it. This id is used
|
|
4675
|
-
* to map function call response to the original function call.
|
|
4676
|
-
*/
|
|
4677
|
-
|
|
4678
|
-
/**
|
|
4679
|
-
* Constructor for ToolContext
|
|
4680
|
-
*/
|
|
4681
|
-
constructor(invocationContext, options = {}) {
|
|
4682
|
-
super(invocationContext, { eventActions: options.eventActions });
|
|
4683
|
-
this.functionCallId = options.functionCallId;
|
|
4684
|
-
}
|
|
4685
|
-
/**
|
|
4686
|
-
* Gets the event actions of the current tool call
|
|
4687
|
-
*/
|
|
4688
|
-
get actions() {
|
|
4689
|
-
return this.eventActions;
|
|
4690
|
-
}
|
|
4691
|
-
/**
|
|
4692
|
-
* Lists the filenames of the artifacts attached to the current session
|
|
4693
|
-
*/
|
|
4694
|
-
async listArtifacts() {
|
|
4695
|
-
if (!this._invocationContext.artifactService) {
|
|
4696
|
-
throw new Error("Artifact service is not initialized.");
|
|
4697
|
-
}
|
|
4698
|
-
return await this._invocationContext.artifactService.listArtifactKeys({
|
|
4699
|
-
appName: this._invocationContext.appName,
|
|
4700
|
-
userId: this._invocationContext.userId,
|
|
4701
|
-
sessionId: this._invocationContext.session.id
|
|
4702
|
-
});
|
|
4703
|
-
}
|
|
4704
|
-
/**
|
|
4705
|
-
* Searches the memory of the current user
|
|
4706
|
-
*/
|
|
4707
|
-
async searchMemory(query) {
|
|
4708
|
-
if (!this._invocationContext.memoryService) {
|
|
4709
|
-
throw new Error("Memory service is not available.");
|
|
4710
|
-
}
|
|
4711
|
-
return await this._invocationContext.memoryService.searchMemory({
|
|
4712
|
-
query,
|
|
4713
|
-
appName: this._invocationContext.appName,
|
|
4714
|
-
userId: this._invocationContext.userId
|
|
4715
|
-
});
|
|
4716
|
-
}
|
|
4717
|
-
};
|
|
4718
|
-
|
|
4719
|
-
// src/tools/index.ts
|
|
4720
|
-
init_function_tool();
|
|
4721
|
-
|
|
4722
|
-
// src/tools/function/index.ts
|
|
4723
|
-
init_function_tool();
|
|
4724
|
-
init_function_utils();
|
|
4725
|
-
function createFunctionTool(func, options) {
|
|
4726
|
-
const { FunctionTool: FunctionTool2 } = (init_function_tool(), __toCommonJS(function_tool_exports));
|
|
4727
|
-
return new FunctionTool2(func, options);
|
|
4728
|
-
}
|
|
4729
|
-
|
|
4730
|
-
// src/tools/index.ts
|
|
4731
|
-
init_function_utils();
|
|
4732
|
-
|
|
4733
|
-
// src/tools/common/google-search.ts
|
|
4669
|
+
// src/tools/common/exit-loop-tool.ts
|
|
4734
4670
|
init_logger();
|
|
4735
4671
|
init_base_tool();
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
__init26() {this.logger = new Logger({ name: "GoogleSearch" })}
|
|
4672
|
+
var ExitLoopTool = (_class16 = class extends BaseTool {
|
|
4673
|
+
__init26() {this.logger = new Logger({ name: "ExitLoopTool" })}
|
|
4739
4674
|
/**
|
|
4740
|
-
* Constructor for
|
|
4675
|
+
* Constructor for ExitLoopTool
|
|
4741
4676
|
*/
|
|
4742
4677
|
constructor() {
|
|
4743
4678
|
super({
|
|
4744
|
-
name: "
|
|
4745
|
-
description: "
|
|
4679
|
+
name: "exit_loop",
|
|
4680
|
+
description: "Exits the loop. Call this function only when you are instructed to do so."
|
|
4746
4681
|
});_class16.prototype.__init26.call(this);;
|
|
4747
4682
|
}
|
|
4748
4683
|
/**
|
|
4749
|
-
*
|
|
4750
|
-
*/
|
|
4751
|
-
getDeclaration() {
|
|
4752
|
-
return {
|
|
4753
|
-
name: this.name,
|
|
4754
|
-
description: this.description,
|
|
4755
|
-
parameters: {
|
|
4756
|
-
type: _genai.Type.OBJECT,
|
|
4757
|
-
properties: {
|
|
4758
|
-
query: {
|
|
4759
|
-
type: _genai.Type.STRING,
|
|
4760
|
-
description: "The search query to execute"
|
|
4761
|
-
},
|
|
4762
|
-
num_results: {
|
|
4763
|
-
type: _genai.Type.INTEGER,
|
|
4764
|
-
description: "Number of results to return (max 10)",
|
|
4765
|
-
default: 5
|
|
4766
|
-
}
|
|
4767
|
-
},
|
|
4768
|
-
required: ["query"]
|
|
4769
|
-
}
|
|
4770
|
-
};
|
|
4771
|
-
}
|
|
4772
|
-
/**
|
|
4773
|
-
* Execute the search
|
|
4774
|
-
* This is a simplified implementation that doesn't actually search, just returns mock results
|
|
4684
|
+
* Execute the exit loop action
|
|
4775
4685
|
*/
|
|
4776
|
-
async runAsync(
|
|
4777
|
-
this.logger.debug(
|
|
4778
|
-
|
|
4779
|
-
);
|
|
4780
|
-
return {
|
|
4781
|
-
results: [
|
|
4782
|
-
{
|
|
4783
|
-
title: `Result 1 for ${args.query}`,
|
|
4784
|
-
link: "https://example.com/1",
|
|
4785
|
-
snippet: `This is a sample result for the query "${args.query}".`
|
|
4786
|
-
},
|
|
4787
|
-
{
|
|
4788
|
-
title: `Result 2 for ${args.query}`,
|
|
4789
|
-
link: "https://example.com/2",
|
|
4790
|
-
snippet: `Another sample result for "${args.query}".`
|
|
4791
|
-
}
|
|
4792
|
-
]
|
|
4793
|
-
};
|
|
4686
|
+
async runAsync(_args, context4) {
|
|
4687
|
+
this.logger.debug("Executing exit loop tool");
|
|
4688
|
+
context4.actions.escalate = true;
|
|
4794
4689
|
}
|
|
4795
4690
|
}, _class16);
|
|
4796
4691
|
|
|
4797
|
-
// src/tools/common/http-request-tool.ts
|
|
4798
|
-
init_base_tool();
|
|
4799
|
-
|
|
4800
|
-
var HttpRequestTool = class extends BaseTool {
|
|
4801
|
-
constructor() {
|
|
4802
|
-
super({
|
|
4803
|
-
name: "http_request",
|
|
4804
|
-
description: "Make HTTP requests to external APIs and web services"
|
|
4805
|
-
});
|
|
4806
|
-
}
|
|
4807
|
-
/**
|
|
4808
|
-
* Get the function declaration for the tool
|
|
4809
|
-
*/
|
|
4810
|
-
getDeclaration() {
|
|
4811
|
-
return {
|
|
4812
|
-
name: this.name,
|
|
4813
|
-
description: this.description,
|
|
4814
|
-
parameters: {
|
|
4815
|
-
type: _genai.Type.OBJECT,
|
|
4816
|
-
properties: {
|
|
4817
|
-
url: {
|
|
4818
|
-
type: _genai.Type.STRING,
|
|
4819
|
-
description: "The URL to send the request to"
|
|
4820
|
-
},
|
|
4821
|
-
method: {
|
|
4822
|
-
type: _genai.Type.STRING,
|
|
4823
|
-
description: "The HTTP method to use (GET, POST, PUT, DELETE, etc.)",
|
|
4824
|
-
enum: ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"],
|
|
4825
|
-
default: "GET"
|
|
4826
|
-
},
|
|
4827
|
-
headers: {
|
|
4828
|
-
type: _genai.Type.OBJECT,
|
|
4829
|
-
description: "Request headers to include"
|
|
4830
|
-
},
|
|
4831
|
-
body: {
|
|
4832
|
-
type: _genai.Type.STRING,
|
|
4833
|
-
description: "Request body content (as string, typically JSON)"
|
|
4834
|
-
},
|
|
4835
|
-
params: {
|
|
4836
|
-
type: _genai.Type.OBJECT,
|
|
4837
|
-
description: "URL query parameters to include"
|
|
4838
|
-
},
|
|
4839
|
-
timeout: {
|
|
4840
|
-
type: _genai.Type.INTEGER,
|
|
4841
|
-
description: "Request timeout in milliseconds",
|
|
4842
|
-
default: 1e4
|
|
4843
|
-
}
|
|
4844
|
-
},
|
|
4845
|
-
required: ["url"]
|
|
4846
|
-
}
|
|
4847
|
-
};
|
|
4848
|
-
}
|
|
4849
|
-
/**
|
|
4850
|
-
* Execute the HTTP request
|
|
4851
|
-
*/
|
|
4852
|
-
async runAsync(args, _context) {
|
|
4853
|
-
try {
|
|
4854
|
-
const {
|
|
4855
|
-
url,
|
|
4856
|
-
method = "GET",
|
|
4857
|
-
headers = {},
|
|
4858
|
-
body,
|
|
4859
|
-
params,
|
|
4860
|
-
timeout = 1e4
|
|
4861
|
-
} = args;
|
|
4862
|
-
const urlObj = new URL(url);
|
|
4863
|
-
if (params) {
|
|
4864
|
-
Object.entries(params).forEach(([key, value]) => {
|
|
4865
|
-
urlObj.searchParams.append(key, value);
|
|
4866
|
-
});
|
|
4867
|
-
}
|
|
4868
|
-
const requestHeaders = { ...headers };
|
|
4869
|
-
if (body && !requestHeaders["Content-Type"] && this.isValidJson(body)) {
|
|
4870
|
-
requestHeaders["Content-Type"] = "application/json";
|
|
4871
|
-
}
|
|
4872
|
-
const options = {
|
|
4873
|
-
method,
|
|
4874
|
-
headers: requestHeaders,
|
|
4875
|
-
body,
|
|
4876
|
-
signal: AbortSignal.timeout(timeout)
|
|
4877
|
-
};
|
|
4878
|
-
const response = await fetch(urlObj.toString(), options);
|
|
4879
|
-
const responseHeaders = {};
|
|
4880
|
-
response.headers.forEach((value, key) => {
|
|
4881
|
-
responseHeaders[key] = value;
|
|
4882
|
-
});
|
|
4883
|
-
const responseBody = await response.text();
|
|
4884
|
-
return {
|
|
4885
|
-
statusCode: response.status,
|
|
4886
|
-
headers: responseHeaders,
|
|
4887
|
-
body: responseBody
|
|
4888
|
-
};
|
|
4889
|
-
} catch (error) {
|
|
4890
|
-
return {
|
|
4891
|
-
statusCode: 0,
|
|
4892
|
-
headers: {},
|
|
4893
|
-
body: "",
|
|
4894
|
-
error: error instanceof Error ? error.message : String(error)
|
|
4895
|
-
};
|
|
4896
|
-
}
|
|
4897
|
-
}
|
|
4898
|
-
/**
|
|
4899
|
-
* Check if a string is valid JSON
|
|
4900
|
-
*/
|
|
4901
|
-
isValidJson(str) {
|
|
4902
|
-
try {
|
|
4903
|
-
JSON.parse(str);
|
|
4904
|
-
return true;
|
|
4905
|
-
} catch (e) {
|
|
4906
|
-
return false;
|
|
4907
|
-
}
|
|
4908
|
-
}
|
|
4909
|
-
};
|
|
4910
|
-
|
|
4911
4692
|
// src/tools/common/file-operations-tool.ts
|
|
4912
4693
|
init_base_tool();
|
|
4913
4694
|
var _promises = require('fs/promises'); var fs2 = _interopRequireWildcard(_promises);
|
|
@@ -5158,112 +4939,12 @@ var FileOperationsTool = class extends BaseTool {
|
|
|
5158
4939
|
}
|
|
5159
4940
|
};
|
|
5160
4941
|
|
|
5161
|
-
// src/tools/common/user-interaction-tool.ts
|
|
5162
|
-
init_base_tool();
|
|
5163
|
-
|
|
5164
|
-
var UserInteractionTool = class extends BaseTool {
|
|
5165
|
-
constructor() {
|
|
5166
|
-
super({
|
|
5167
|
-
name: "user_interaction",
|
|
5168
|
-
description: "Prompt the user for input during agent execution",
|
|
5169
|
-
isLongRunning: true
|
|
5170
|
-
});
|
|
5171
|
-
}
|
|
5172
|
-
/**
|
|
5173
|
-
* Get the function declaration for the tool
|
|
5174
|
-
*/
|
|
5175
|
-
getDeclaration() {
|
|
5176
|
-
return {
|
|
5177
|
-
name: this.name,
|
|
5178
|
-
description: this.description,
|
|
5179
|
-
parameters: {
|
|
5180
|
-
type: _genai.Type.OBJECT,
|
|
5181
|
-
properties: {
|
|
5182
|
-
prompt: {
|
|
5183
|
-
type: _genai.Type.STRING,
|
|
5184
|
-
description: "The prompt message to display to the user"
|
|
5185
|
-
},
|
|
5186
|
-
options: {
|
|
5187
|
-
type: _genai.Type.ARRAY,
|
|
5188
|
-
description: "Optional array of choices to present to the user",
|
|
5189
|
-
items: {
|
|
5190
|
-
type: _genai.Type.STRING
|
|
5191
|
-
}
|
|
5192
|
-
},
|
|
5193
|
-
defaultValue: {
|
|
5194
|
-
type: _genai.Type.STRING,
|
|
5195
|
-
description: "Optional default value for the input field"
|
|
5196
|
-
}
|
|
5197
|
-
},
|
|
5198
|
-
required: ["prompt"]
|
|
5199
|
-
}
|
|
5200
|
-
};
|
|
5201
|
-
}
|
|
5202
|
-
/**
|
|
5203
|
-
* Execute the user interaction
|
|
5204
|
-
*/
|
|
5205
|
-
async runAsync(args, context4) {
|
|
5206
|
-
try {
|
|
5207
|
-
const actions = context4.actions;
|
|
5208
|
-
if (!actions || !actions.promptUser) {
|
|
5209
|
-
return {
|
|
5210
|
-
success: false,
|
|
5211
|
-
error: "User interaction is not supported in the current environment"
|
|
5212
|
-
};
|
|
5213
|
-
}
|
|
5214
|
-
if (actions.skipSummarization) {
|
|
5215
|
-
actions.skipSummarization(true);
|
|
5216
|
-
}
|
|
5217
|
-
const promptOptions = args.options && args.options.length > 0 ? {
|
|
5218
|
-
choices: args.options
|
|
5219
|
-
} : void 0;
|
|
5220
|
-
const response = await actions.promptUser({
|
|
5221
|
-
prompt: args.prompt,
|
|
5222
|
-
defaultValue: args.defaultValue,
|
|
5223
|
-
options: promptOptions
|
|
5224
|
-
});
|
|
5225
|
-
return {
|
|
5226
|
-
success: true,
|
|
5227
|
-
userInput: response
|
|
5228
|
-
};
|
|
5229
|
-
} catch (error) {
|
|
5230
|
-
return {
|
|
5231
|
-
success: false,
|
|
5232
|
-
error: error instanceof Error ? error.message : String(error)
|
|
5233
|
-
};
|
|
5234
|
-
}
|
|
5235
|
-
}
|
|
5236
|
-
};
|
|
5237
|
-
|
|
5238
|
-
// src/tools/common/exit-loop-tool.ts
|
|
5239
|
-
init_logger();
|
|
5240
|
-
init_base_tool();
|
|
5241
|
-
var ExitLoopTool = (_class17 = class extends BaseTool {
|
|
5242
|
-
__init27() {this.logger = new Logger({ name: "ExitLoopTool" })}
|
|
5243
|
-
/**
|
|
5244
|
-
* Constructor for ExitLoopTool
|
|
5245
|
-
*/
|
|
5246
|
-
constructor() {
|
|
5247
|
-
super({
|
|
5248
|
-
name: "exit_loop",
|
|
5249
|
-
description: "Exits the loop. Call this function only when you are instructed to do so."
|
|
5250
|
-
});_class17.prototype.__init27.call(this);;
|
|
5251
|
-
}
|
|
5252
|
-
/**
|
|
5253
|
-
* Execute the exit loop action
|
|
5254
|
-
*/
|
|
5255
|
-
async runAsync(_args, context4) {
|
|
5256
|
-
this.logger.debug("Executing exit loop tool");
|
|
5257
|
-
context4.actions.escalate = true;
|
|
5258
|
-
}
|
|
5259
|
-
}, _class17);
|
|
5260
|
-
|
|
5261
4942
|
// src/tools/common/get-user-choice-tool.ts
|
|
5262
4943
|
init_logger();
|
|
5263
4944
|
init_base_tool();
|
|
5264
4945
|
|
|
5265
|
-
var GetUserChoiceTool = (
|
|
5266
|
-
|
|
4946
|
+
var GetUserChoiceTool = (_class17 = class extends BaseTool {
|
|
4947
|
+
__init27() {this.logger = new Logger({ name: "GetUserChoiceTool" })}
|
|
5267
4948
|
/**
|
|
5268
4949
|
* Constructor for GetUserChoiceTool
|
|
5269
4950
|
*/
|
|
@@ -5272,7 +4953,7 @@ var GetUserChoiceTool = (_class18 = class extends BaseTool {
|
|
|
5272
4953
|
name: "get_user_choice",
|
|
5273
4954
|
description: "This tool provides the options to the user and asks them to choose one. Use this tool when you need the user to make a selection between multiple options. Do not list options in your response - use this tool instead.",
|
|
5274
4955
|
isLongRunning: true
|
|
5275
|
-
});
|
|
4956
|
+
});_class17.prototype.__init27.call(this);;
|
|
5276
4957
|
}
|
|
5277
4958
|
/**
|
|
5278
4959
|
* Get the function declaration for the tool
|
|
@@ -5315,22 +4996,22 @@ var GetUserChoiceTool = (_class18 = class extends BaseTool {
|
|
|
5315
4996
|
context4.actions.skipSummarization = true;
|
|
5316
4997
|
return null;
|
|
5317
4998
|
}
|
|
5318
|
-
},
|
|
4999
|
+
}, _class17);
|
|
5319
5000
|
|
|
5320
|
-
// src/tools/common/
|
|
5001
|
+
// src/tools/common/google-search.ts
|
|
5321
5002
|
init_logger();
|
|
5322
5003
|
init_base_tool();
|
|
5323
5004
|
|
|
5324
|
-
var
|
|
5325
|
-
|
|
5005
|
+
var GoogleSearch = (_class18 = class extends BaseTool {
|
|
5006
|
+
__init28() {this.logger = new Logger({ name: "GoogleSearch" })}
|
|
5326
5007
|
/**
|
|
5327
|
-
* Constructor for
|
|
5008
|
+
* Constructor for GoogleSearch
|
|
5328
5009
|
*/
|
|
5329
5010
|
constructor() {
|
|
5330
5011
|
super({
|
|
5331
|
-
name: "
|
|
5332
|
-
description: "
|
|
5333
|
-
});
|
|
5012
|
+
name: "google_search",
|
|
5013
|
+
description: "Search the web using Google"
|
|
5014
|
+
});_class18.prototype.__init28.call(this);;
|
|
5334
5015
|
}
|
|
5335
5016
|
/**
|
|
5336
5017
|
* Get the function declaration for the tool
|
|
@@ -5342,38 +5023,54 @@ var TransferToAgentTool = (_class19 = class extends BaseTool {
|
|
|
5342
5023
|
parameters: {
|
|
5343
5024
|
type: _genai.Type.OBJECT,
|
|
5344
5025
|
properties: {
|
|
5345
|
-
|
|
5026
|
+
query: {
|
|
5346
5027
|
type: _genai.Type.STRING,
|
|
5347
|
-
description: "The
|
|
5028
|
+
description: "The search query to execute"
|
|
5029
|
+
},
|
|
5030
|
+
num_results: {
|
|
5031
|
+
type: _genai.Type.INTEGER,
|
|
5032
|
+
description: "Number of results to return (max 10)",
|
|
5033
|
+
default: 5
|
|
5348
5034
|
}
|
|
5349
5035
|
},
|
|
5350
|
-
required: ["
|
|
5036
|
+
required: ["query"]
|
|
5351
5037
|
}
|
|
5352
5038
|
};
|
|
5353
5039
|
}
|
|
5354
5040
|
/**
|
|
5355
|
-
* Execute the
|
|
5041
|
+
* Execute the search
|
|
5042
|
+
* This is a simplified implementation that doesn't actually search, just returns mock results
|
|
5356
5043
|
*/
|
|
5357
|
-
async runAsync(args,
|
|
5358
|
-
this.logger.debug(
|
|
5359
|
-
|
|
5044
|
+
async runAsync(args, _context) {
|
|
5045
|
+
this.logger.debug(
|
|
5046
|
+
`[GoogleSearch] Executing Google search for: ${args.query}`
|
|
5047
|
+
);
|
|
5048
|
+
return {
|
|
5049
|
+
results: [
|
|
5050
|
+
{
|
|
5051
|
+
title: `Result 1 for ${args.query}`,
|
|
5052
|
+
link: "https://example.com/1",
|
|
5053
|
+
snippet: `This is a sample result for the query "${args.query}".`
|
|
5054
|
+
},
|
|
5055
|
+
{
|
|
5056
|
+
title: `Result 2 for ${args.query}`,
|
|
5057
|
+
link: "https://example.com/2",
|
|
5058
|
+
snippet: `Another sample result for "${args.query}".`
|
|
5059
|
+
}
|
|
5060
|
+
]
|
|
5061
|
+
};
|
|
5360
5062
|
}
|
|
5361
|
-
},
|
|
5063
|
+
}, _class18);
|
|
5362
5064
|
|
|
5363
|
-
// src/tools/common/
|
|
5364
|
-
init_logger();
|
|
5065
|
+
// src/tools/common/http-request-tool.ts
|
|
5365
5066
|
init_base_tool();
|
|
5366
5067
|
|
|
5367
|
-
var
|
|
5368
|
-
__init30() {this.logger = new Logger({ name: "LoadMemoryTool" })}
|
|
5369
|
-
/**
|
|
5370
|
-
* Constructor for LoadMemoryTool
|
|
5371
|
-
*/
|
|
5068
|
+
var HttpRequestTool = class extends BaseTool {
|
|
5372
5069
|
constructor() {
|
|
5373
5070
|
super({
|
|
5374
|
-
name: "
|
|
5375
|
-
description: "
|
|
5376
|
-
});
|
|
5071
|
+
name: "http_request",
|
|
5072
|
+
description: "Make HTTP requests to external APIs and web services"
|
|
5073
|
+
});
|
|
5377
5074
|
}
|
|
5378
5075
|
/**
|
|
5379
5076
|
* Get the function declaration for the tool
|
|
@@ -5385,35 +5082,99 @@ var LoadMemoryTool = (_class20 = class extends BaseTool {
|
|
|
5385
5082
|
parameters: {
|
|
5386
5083
|
type: _genai.Type.OBJECT,
|
|
5387
5084
|
properties: {
|
|
5388
|
-
|
|
5085
|
+
url: {
|
|
5389
5086
|
type: _genai.Type.STRING,
|
|
5390
|
-
description: "The
|
|
5087
|
+
description: "The URL to send the request to"
|
|
5088
|
+
},
|
|
5089
|
+
method: {
|
|
5090
|
+
type: _genai.Type.STRING,
|
|
5091
|
+
description: "The HTTP method to use (GET, POST, PUT, DELETE, etc.)",
|
|
5092
|
+
enum: ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"],
|
|
5093
|
+
default: "GET"
|
|
5094
|
+
},
|
|
5095
|
+
headers: {
|
|
5096
|
+
type: _genai.Type.OBJECT,
|
|
5097
|
+
description: "Request headers to include"
|
|
5098
|
+
},
|
|
5099
|
+
body: {
|
|
5100
|
+
type: _genai.Type.STRING,
|
|
5101
|
+
description: "Request body content (as string, typically JSON)"
|
|
5102
|
+
},
|
|
5103
|
+
params: {
|
|
5104
|
+
type: _genai.Type.OBJECT,
|
|
5105
|
+
description: "URL query parameters to include"
|
|
5106
|
+
},
|
|
5107
|
+
timeout: {
|
|
5108
|
+
type: _genai.Type.INTEGER,
|
|
5109
|
+
description: "Request timeout in milliseconds",
|
|
5110
|
+
default: 1e4
|
|
5391
5111
|
}
|
|
5392
5112
|
},
|
|
5393
|
-
required: ["
|
|
5113
|
+
required: ["url"]
|
|
5394
5114
|
}
|
|
5395
5115
|
};
|
|
5396
5116
|
}
|
|
5397
5117
|
/**
|
|
5398
|
-
* Execute the
|
|
5118
|
+
* Execute the HTTP request
|
|
5399
5119
|
*/
|
|
5400
|
-
async runAsync(args,
|
|
5401
|
-
this.logger.debug(`Executing load_memory with query: ${args.query}`);
|
|
5120
|
+
async runAsync(args, _context) {
|
|
5402
5121
|
try {
|
|
5403
|
-
const
|
|
5122
|
+
const {
|
|
5123
|
+
url,
|
|
5124
|
+
method = "GET",
|
|
5125
|
+
headers = {},
|
|
5126
|
+
body,
|
|
5127
|
+
params,
|
|
5128
|
+
timeout = 1e4
|
|
5129
|
+
} = args;
|
|
5130
|
+
const urlObj = new URL(url);
|
|
5131
|
+
if (params) {
|
|
5132
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
5133
|
+
urlObj.searchParams.append(key, value);
|
|
5134
|
+
});
|
|
5135
|
+
}
|
|
5136
|
+
const requestHeaders = { ...headers };
|
|
5137
|
+
if (body && !requestHeaders["Content-Type"] && this.isValidJson(body)) {
|
|
5138
|
+
requestHeaders["Content-Type"] = "application/json";
|
|
5139
|
+
}
|
|
5140
|
+
const options = {
|
|
5141
|
+
method,
|
|
5142
|
+
headers: requestHeaders,
|
|
5143
|
+
body,
|
|
5144
|
+
signal: AbortSignal.timeout(timeout)
|
|
5145
|
+
};
|
|
5146
|
+
const response = await fetch(urlObj.toString(), options);
|
|
5147
|
+
const responseHeaders = {};
|
|
5148
|
+
response.headers.forEach((value, key) => {
|
|
5149
|
+
responseHeaders[key] = value;
|
|
5150
|
+
});
|
|
5151
|
+
const responseBody = await response.text();
|
|
5404
5152
|
return {
|
|
5405
|
-
|
|
5406
|
-
|
|
5153
|
+
statusCode: response.status,
|
|
5154
|
+
headers: responseHeaders,
|
|
5155
|
+
body: responseBody
|
|
5407
5156
|
};
|
|
5408
5157
|
} catch (error) {
|
|
5409
|
-
console.error("Error searching memory:", error);
|
|
5410
5158
|
return {
|
|
5411
|
-
|
|
5412
|
-
|
|
5159
|
+
statusCode: 0,
|
|
5160
|
+
headers: {},
|
|
5161
|
+
body: "",
|
|
5162
|
+
error: error instanceof Error ? error.message : String(error)
|
|
5413
5163
|
};
|
|
5414
5164
|
}
|
|
5415
5165
|
}
|
|
5416
|
-
|
|
5166
|
+
/**
|
|
5167
|
+
* Check if a string is valid JSON
|
|
5168
|
+
*/
|
|
5169
|
+
isValidJson(str) {
|
|
5170
|
+
try {
|
|
5171
|
+
JSON.parse(str);
|
|
5172
|
+
return true;
|
|
5173
|
+
} catch (e) {
|
|
5174
|
+
return false;
|
|
5175
|
+
}
|
|
5176
|
+
}
|
|
5177
|
+
};
|
|
5417
5178
|
|
|
5418
5179
|
// src/tools/common/load-artifacts-tool.ts
|
|
5419
5180
|
init_base_tool();
|
|
@@ -5528,10 +5289,197 @@ than the function call.
|
|
|
5528
5289
|
}
|
|
5529
5290
|
};
|
|
5530
5291
|
|
|
5292
|
+
// src/tools/common/load-memory-tool.ts
|
|
5293
|
+
init_logger();
|
|
5294
|
+
init_base_tool();
|
|
5295
|
+
|
|
5296
|
+
var LoadMemoryTool = (_class19 = class extends BaseTool {
|
|
5297
|
+
__init29() {this.logger = new Logger({ name: "LoadMemoryTool" })}
|
|
5298
|
+
/**
|
|
5299
|
+
* Constructor for LoadMemoryTool
|
|
5300
|
+
*/
|
|
5301
|
+
constructor() {
|
|
5302
|
+
super({
|
|
5303
|
+
name: "load_memory",
|
|
5304
|
+
description: "Loads the memory for the current user based on a query."
|
|
5305
|
+
});_class19.prototype.__init29.call(this);;
|
|
5306
|
+
}
|
|
5307
|
+
/**
|
|
5308
|
+
* Get the function declaration for the tool
|
|
5309
|
+
*/
|
|
5310
|
+
getDeclaration() {
|
|
5311
|
+
return {
|
|
5312
|
+
name: this.name,
|
|
5313
|
+
description: this.description,
|
|
5314
|
+
parameters: {
|
|
5315
|
+
type: _genai.Type.OBJECT,
|
|
5316
|
+
properties: {
|
|
5317
|
+
query: {
|
|
5318
|
+
type: _genai.Type.STRING,
|
|
5319
|
+
description: "The query to load memories for"
|
|
5320
|
+
}
|
|
5321
|
+
},
|
|
5322
|
+
required: ["query"]
|
|
5323
|
+
}
|
|
5324
|
+
};
|
|
5325
|
+
}
|
|
5326
|
+
/**
|
|
5327
|
+
* Execute the memory loading action
|
|
5328
|
+
*/
|
|
5329
|
+
async runAsync(args, context4) {
|
|
5330
|
+
this.logger.debug(`Executing load_memory with query: ${args.query}`);
|
|
5331
|
+
try {
|
|
5332
|
+
const searchResult = await context4.searchMemory(args.query);
|
|
5333
|
+
return {
|
|
5334
|
+
memories: searchResult.memories || [],
|
|
5335
|
+
count: _optionalChain([searchResult, 'access', _165 => _165.memories, 'optionalAccess', _166 => _166.length]) || 0
|
|
5336
|
+
};
|
|
5337
|
+
} catch (error) {
|
|
5338
|
+
console.error("Error searching memory:", error);
|
|
5339
|
+
return {
|
|
5340
|
+
error: "Memory search failed",
|
|
5341
|
+
message: error instanceof Error ? error.message : String(error)
|
|
5342
|
+
};
|
|
5343
|
+
}
|
|
5344
|
+
}
|
|
5345
|
+
}, _class19);
|
|
5346
|
+
|
|
5347
|
+
// src/tools/common/transfer-to-agent-tool.ts
|
|
5348
|
+
init_logger();
|
|
5349
|
+
init_base_tool();
|
|
5350
|
+
|
|
5351
|
+
var TransferToAgentTool = (_class20 = class extends BaseTool {
|
|
5352
|
+
__init30() {this.logger = new Logger({ name: "TransferToAgentTool" })}
|
|
5353
|
+
/**
|
|
5354
|
+
* Constructor for TransferToAgentTool
|
|
5355
|
+
*/
|
|
5356
|
+
constructor() {
|
|
5357
|
+
super({
|
|
5358
|
+
name: "transfer_to_agent",
|
|
5359
|
+
description: "Transfer the question to another agent when it's more suitable to answer the user's question according to the agent's description. Use this function when you determine that another agent in the system would be better equipped to handle the user's request based on their specialized capabilities and expertise areas."
|
|
5360
|
+
});_class20.prototype.__init30.call(this);;
|
|
5361
|
+
}
|
|
5362
|
+
/**
|
|
5363
|
+
* Get the function declaration for the tool
|
|
5364
|
+
*/
|
|
5365
|
+
getDeclaration() {
|
|
5366
|
+
return {
|
|
5367
|
+
name: this.name,
|
|
5368
|
+
description: this.description,
|
|
5369
|
+
parameters: {
|
|
5370
|
+
type: _genai.Type.OBJECT,
|
|
5371
|
+
properties: {
|
|
5372
|
+
agent_name: {
|
|
5373
|
+
type: _genai.Type.STRING,
|
|
5374
|
+
description: "The name of the agent to transfer control to"
|
|
5375
|
+
}
|
|
5376
|
+
},
|
|
5377
|
+
required: ["agent_name"]
|
|
5378
|
+
}
|
|
5379
|
+
};
|
|
5380
|
+
}
|
|
5381
|
+
/**
|
|
5382
|
+
* Execute the transfer to agent action
|
|
5383
|
+
*/
|
|
5384
|
+
async runAsync(args, context4) {
|
|
5385
|
+
this.logger.debug(`Executing transfer to agent: ${args.agent_name}`);
|
|
5386
|
+
context4.actions.transferToAgent = args.agent_name;
|
|
5387
|
+
}
|
|
5388
|
+
}, _class20);
|
|
5389
|
+
|
|
5390
|
+
// src/tools/common/user-interaction-tool.ts
|
|
5391
|
+
init_base_tool();
|
|
5392
|
+
|
|
5393
|
+
var UserInteractionTool = class extends BaseTool {
|
|
5394
|
+
constructor() {
|
|
5395
|
+
super({
|
|
5396
|
+
name: "user_interaction",
|
|
5397
|
+
description: "Prompt the user for input during agent execution",
|
|
5398
|
+
isLongRunning: true
|
|
5399
|
+
});
|
|
5400
|
+
}
|
|
5401
|
+
/**
|
|
5402
|
+
* Get the function declaration for the tool
|
|
5403
|
+
*/
|
|
5404
|
+
getDeclaration() {
|
|
5405
|
+
return {
|
|
5406
|
+
name: this.name,
|
|
5407
|
+
description: this.description,
|
|
5408
|
+
parameters: {
|
|
5409
|
+
type: _genai.Type.OBJECT,
|
|
5410
|
+
properties: {
|
|
5411
|
+
prompt: {
|
|
5412
|
+
type: _genai.Type.STRING,
|
|
5413
|
+
description: "The prompt message to display to the user"
|
|
5414
|
+
},
|
|
5415
|
+
options: {
|
|
5416
|
+
type: _genai.Type.ARRAY,
|
|
5417
|
+
description: "Optional array of choices to present to the user",
|
|
5418
|
+
items: {
|
|
5419
|
+
type: _genai.Type.STRING
|
|
5420
|
+
}
|
|
5421
|
+
},
|
|
5422
|
+
defaultValue: {
|
|
5423
|
+
type: _genai.Type.STRING,
|
|
5424
|
+
description: "Optional default value for the input field"
|
|
5425
|
+
}
|
|
5426
|
+
},
|
|
5427
|
+
required: ["prompt"]
|
|
5428
|
+
}
|
|
5429
|
+
};
|
|
5430
|
+
}
|
|
5431
|
+
/**
|
|
5432
|
+
* Execute the user interaction
|
|
5433
|
+
*/
|
|
5434
|
+
async runAsync(args, context4) {
|
|
5435
|
+
try {
|
|
5436
|
+
const actions = context4.actions;
|
|
5437
|
+
if (!actions || !actions.promptUser) {
|
|
5438
|
+
return {
|
|
5439
|
+
success: false,
|
|
5440
|
+
error: "User interaction is not supported in the current environment"
|
|
5441
|
+
};
|
|
5442
|
+
}
|
|
5443
|
+
if (actions.skipSummarization) {
|
|
5444
|
+
actions.skipSummarization(true);
|
|
5445
|
+
}
|
|
5446
|
+
const promptOptions = args.options && args.options.length > 0 ? {
|
|
5447
|
+
choices: args.options
|
|
5448
|
+
} : void 0;
|
|
5449
|
+
const response = await actions.promptUser({
|
|
5450
|
+
prompt: args.prompt,
|
|
5451
|
+
defaultValue: args.defaultValue,
|
|
5452
|
+
options: promptOptions
|
|
5453
|
+
});
|
|
5454
|
+
return {
|
|
5455
|
+
success: true,
|
|
5456
|
+
userInput: response
|
|
5457
|
+
};
|
|
5458
|
+
} catch (error) {
|
|
5459
|
+
return {
|
|
5460
|
+
success: false,
|
|
5461
|
+
error: error instanceof Error ? error.message : String(error)
|
|
5462
|
+
};
|
|
5463
|
+
}
|
|
5464
|
+
}
|
|
5465
|
+
};
|
|
5466
|
+
|
|
5467
|
+
// src/tools/function/index.ts
|
|
5468
|
+
init_function_tool();
|
|
5469
|
+
init_function_utils();
|
|
5470
|
+
function createFunctionTool(func, options) {
|
|
5471
|
+
const { FunctionTool: FunctionTool2 } = (init_function_tool(), __toCommonJS(function_tool_exports));
|
|
5472
|
+
return new FunctionTool2(func, options);
|
|
5473
|
+
}
|
|
5474
|
+
|
|
5475
|
+
// src/tools/index.ts
|
|
5476
|
+
init_function_tool();
|
|
5477
|
+
init_function_utils();
|
|
5478
|
+
|
|
5531
5479
|
// src/tools/mcp/client.ts
|
|
5532
5480
|
init_logger();
|
|
5533
5481
|
var _indexjs = require('@modelcontextprotocol/sdk/client/index.js');
|
|
5534
|
-
var
|
|
5482
|
+
var _streamableHttpjs = require('@modelcontextprotocol/sdk/client/streamableHttp.js');
|
|
5535
5483
|
var _stdiojs = require('@modelcontextprotocol/sdk/client/stdio.js');
|
|
5536
5484
|
var _typesjs = require('@modelcontextprotocol/sdk/types.js');
|
|
5537
5485
|
|
|
@@ -5683,7 +5631,7 @@ var McpSamplingHandler = (_class21 = class {
|
|
|
5683
5631
|
parts: adkParts
|
|
5684
5632
|
};
|
|
5685
5633
|
this.logger.debug(
|
|
5686
|
-
`Converted MCP message - role: ${mcpMessage.role} -> ${adkRole}, content type: ${mcpMessage.content.type}`
|
|
5634
|
+
`Converted MCP message - role: ${mcpMessage.role} -> ${adkRole}, content type: ${Array.isArray(mcpMessage.content) ? "array" : _nullishCoalesce(_optionalChain([mcpMessage, 'access', _167 => _167.content, 'optionalAccess', _168 => _168.type]), () => ( "unknown"))}`
|
|
5687
5635
|
);
|
|
5688
5636
|
return adkContent;
|
|
5689
5637
|
}
|
|
@@ -5691,29 +5639,54 @@ var McpSamplingHandler = (_class21 = class {
|
|
|
5691
5639
|
* Convert MCP message content to ADK parts format
|
|
5692
5640
|
*/
|
|
5693
5641
|
convertMcpContentToADKParts(mcpContent) {
|
|
5694
|
-
|
|
5695
|
-
|
|
5696
|
-
return
|
|
5642
|
+
const safeText = (value) => typeof value === "string" ? value : "";
|
|
5643
|
+
if (Array.isArray(mcpContent)) {
|
|
5644
|
+
return mcpContent.flatMap((c) => this.convertMcpContentToADKParts(c));
|
|
5697
5645
|
}
|
|
5698
|
-
|
|
5699
|
-
|
|
5700
|
-
|
|
5701
|
-
parts.push({ text: mcpContent.text });
|
|
5646
|
+
switch (mcpContent.type) {
|
|
5647
|
+
case "text": {
|
|
5648
|
+
return [{ text: safeText(mcpContent.text) }];
|
|
5702
5649
|
}
|
|
5703
|
-
|
|
5704
|
-
|
|
5650
|
+
case "image":
|
|
5651
|
+
case "audio": {
|
|
5652
|
+
const parts = [];
|
|
5653
|
+
if ("text" in mcpContent) {
|
|
5654
|
+
const t = safeText(mcpContent.text);
|
|
5655
|
+
if (t) parts.push({ text: t });
|
|
5656
|
+
}
|
|
5657
|
+
const hasData = typeof mcpContent.data === "string" && mcpContent.data.length > 0;
|
|
5658
|
+
if (!hasData) {
|
|
5659
|
+
this.logger.warn(
|
|
5660
|
+
`Missing or invalid 'data' for ${mcpContent.type} content.`
|
|
5661
|
+
);
|
|
5662
|
+
return [
|
|
5663
|
+
...parts,
|
|
5664
|
+
{
|
|
5665
|
+
text: `[${mcpContent.type.toUpperCase()} CONTENT MISSING DATA]`
|
|
5666
|
+
}
|
|
5667
|
+
];
|
|
5668
|
+
}
|
|
5705
5669
|
parts.push({
|
|
5706
5670
|
inlineData: {
|
|
5707
5671
|
data: mcpContent.data,
|
|
5708
|
-
mimeType
|
|
5672
|
+
mimeType: safeText(mcpContent.mimeType) || (mcpContent.type === "image" ? "image/jpeg" : "audio/mpeg")
|
|
5709
5673
|
}
|
|
5710
5674
|
});
|
|
5675
|
+
return parts;
|
|
5676
|
+
}
|
|
5677
|
+
case "tool_use": {
|
|
5678
|
+
return [{ text: `[Tool Use: ${safeText(mcpContent.name)}]` }];
|
|
5679
|
+
}
|
|
5680
|
+
case "tool_result": {
|
|
5681
|
+
return [{ text: `[Tool Result: ${safeText(mcpContent.toolUseId)}]` }];
|
|
5682
|
+
}
|
|
5683
|
+
default: {
|
|
5684
|
+
this.logger.warn(
|
|
5685
|
+
`Unknown MCP content type: ${safeText(mcpContent.type)}`
|
|
5686
|
+
);
|
|
5687
|
+
return [{ text: "[Unknown content type]" }];
|
|
5711
5688
|
}
|
|
5712
|
-
return parts.length > 0 ? parts : [{ text: "" }];
|
|
5713
5689
|
}
|
|
5714
|
-
this.logger.warn(`Unknown MCP content type: ${mcpContent.type}`);
|
|
5715
|
-
const fallbackText = typeof mcpContent.data === "string" ? mcpContent.data : "";
|
|
5716
|
-
return [{ text: fallbackText }];
|
|
5717
5690
|
}
|
|
5718
5691
|
/**
|
|
5719
5692
|
* Convert ADK response to MCP response format
|
|
@@ -5825,9 +5798,6 @@ var McpClientService = (_class22 = class {
|
|
|
5825
5798
|
},
|
|
5826
5799
|
{
|
|
5827
5800
|
capabilities: {
|
|
5828
|
-
prompts: {},
|
|
5829
|
-
resources: {},
|
|
5830
|
-
tools: {},
|
|
5831
5801
|
sampling: {}
|
|
5832
5802
|
// Enable sampling capability
|
|
5833
5803
|
}
|
|
@@ -5880,7 +5850,7 @@ var McpClientService = (_class22 = class {
|
|
|
5880
5850
|
...this.config.transport.headers || {},
|
|
5881
5851
|
...this.config.headers || {}
|
|
5882
5852
|
};
|
|
5883
|
-
return new (0,
|
|
5853
|
+
return new (0, _streamableHttpjs.StreamableHTTPClientTransport)(
|
|
5884
5854
|
new URL(this.config.transport.serverUrl),
|
|
5885
5855
|
{
|
|
5886
5856
|
requestInit: {
|
|
@@ -5930,7 +5900,7 @@ var McpClientService = (_class22 = class {
|
|
|
5930
5900
|
if (typeof this.client.close === "function") {
|
|
5931
5901
|
await this.client.close();
|
|
5932
5902
|
}
|
|
5933
|
-
} catch (
|
|
5903
|
+
} catch (_err) {
|
|
5934
5904
|
}
|
|
5935
5905
|
}
|
|
5936
5906
|
if (this.transport && typeof this.transport.close === "function") {
|
|
@@ -5960,7 +5930,7 @@ var McpClientService = (_class22 = class {
|
|
|
5960
5930
|
},
|
|
5961
5931
|
this,
|
|
5962
5932
|
async (instance) => await instance.reinitialize(),
|
|
5963
|
-
_optionalChain([this, 'access',
|
|
5933
|
+
_optionalChain([this, 'access', _169 => _169.config, 'access', _170 => _170.retryOptions, 'optionalAccess', _171 => _171.maxRetries]) || 2
|
|
5964
5934
|
);
|
|
5965
5935
|
return await wrappedCall();
|
|
5966
5936
|
} catch (error) {
|
|
@@ -6044,7 +6014,7 @@ var McpClientService = (_class22 = class {
|
|
|
6044
6014
|
this.mcpSamplingHandler = null;
|
|
6045
6015
|
if (this.client) {
|
|
6046
6016
|
try {
|
|
6047
|
-
_optionalChain([this, 'access',
|
|
6017
|
+
_optionalChain([this, 'access', _172 => _172.client, 'access', _173 => _173.removeRequestHandler, 'optionalCall', _174 => _174("sampling/createMessage")]);
|
|
6048
6018
|
} catch (error) {
|
|
6049
6019
|
this.logger.error("Failed to remove sampling handler:", error);
|
|
6050
6020
|
}
|
|
@@ -6216,7 +6186,7 @@ function mcpSchemaToParameters(mcpTool) {
|
|
|
6216
6186
|
let schema;
|
|
6217
6187
|
if (mcpTool.inputSchema) {
|
|
6218
6188
|
schema = mcpTool.inputSchema;
|
|
6219
|
-
} else if (mcpTool.parameters) {
|
|
6189
|
+
} else if ("parameters" in mcpTool && mcpTool.parameters) {
|
|
6220
6190
|
schema = mcpTool.parameters;
|
|
6221
6191
|
}
|
|
6222
6192
|
if (!schema) {
|
|
@@ -6254,7 +6224,12 @@ var McpToolAdapter = (_class23 = class extends BaseTool {
|
|
|
6254
6224
|
|
|
6255
6225
|
__init38() {this.logger = new Logger({ name: "McpToolAdapter" })}
|
|
6256
6226
|
constructor(mcpTool, client, handler) {
|
|
6257
|
-
|
|
6227
|
+
let metadata = {};
|
|
6228
|
+
if ("metadata" in mcpTool && typeof mcpTool.metadata === "object") {
|
|
6229
|
+
metadata = mcpTool.metadata;
|
|
6230
|
+
} else if (mcpTool._meta && typeof mcpTool._meta === "object") {
|
|
6231
|
+
metadata = mcpTool._meta;
|
|
6232
|
+
}
|
|
6258
6233
|
super({
|
|
6259
6234
|
name: mcpTool.name || `mcp_${Date.now()}`,
|
|
6260
6235
|
description: mcpTool.description || "MCP Tool",
|
|
@@ -6288,7 +6263,7 @@ var McpToolAdapter = (_class23 = class extends BaseTool {
|
|
|
6288
6263
|
async runAsync(args, _context) {
|
|
6289
6264
|
this.logger.debug(`Executing MCP tool ${this.name} with args:`, args);
|
|
6290
6265
|
try {
|
|
6291
|
-
if (typeof this.mcpTool.execute === "function") {
|
|
6266
|
+
if ("execute" in this.mcpTool && typeof this.mcpTool.execute === "function") {
|
|
6292
6267
|
return await this.mcpTool.execute(args);
|
|
6293
6268
|
}
|
|
6294
6269
|
if (this.clientService) {
|
|
@@ -6588,7 +6563,7 @@ var McpToolset = (_class24 = class {
|
|
|
6588
6563
|
"resource_closed_error" /* RESOURCE_CLOSED_ERROR */
|
|
6589
6564
|
);
|
|
6590
6565
|
}
|
|
6591
|
-
if (this.tools.length > 0 && !_optionalChain([this, 'access',
|
|
6566
|
+
if (this.tools.length > 0 && !_optionalChain([this, 'access', _175 => _175.config, 'access', _176 => _176.cacheConfig, 'optionalAccess', _177 => _177.enabled]) === false) {
|
|
6592
6567
|
return this.tools;
|
|
6593
6568
|
}
|
|
6594
6569
|
if (!this.clientService) {
|
|
@@ -6617,7 +6592,7 @@ var McpToolset = (_class24 = class {
|
|
|
6617
6592
|
}
|
|
6618
6593
|
}
|
|
6619
6594
|
}
|
|
6620
|
-
if (_optionalChain([this, 'access',
|
|
6595
|
+
if (_optionalChain([this, 'access', _178 => _178.config, 'access', _179 => _179.cacheConfig, 'optionalAccess', _180 => _180.enabled]) !== false) {
|
|
6621
6596
|
this.tools = tools;
|
|
6622
6597
|
}
|
|
6623
6598
|
return tools;
|
|
@@ -6687,6 +6662,56 @@ async function getMcpTools(config, toolFilter) {
|
|
|
6687
6662
|
}
|
|
6688
6663
|
}
|
|
6689
6664
|
|
|
6665
|
+
// src/tools/tool-context.ts
|
|
6666
|
+
var ToolContext = class extends CallbackContext {
|
|
6667
|
+
/**
|
|
6668
|
+
* The function call id of the current tool call. This id was
|
|
6669
|
+
* returned in the function call event from LLM to identify a function call.
|
|
6670
|
+
* If LLM didn't return this id, ADK will assign one to it. This id is used
|
|
6671
|
+
* to map function call response to the original function call.
|
|
6672
|
+
*/
|
|
6673
|
+
|
|
6674
|
+
/**
|
|
6675
|
+
* Constructor for ToolContext
|
|
6676
|
+
*/
|
|
6677
|
+
constructor(invocationContext, options = {}) {
|
|
6678
|
+
super(invocationContext, { eventActions: options.eventActions });
|
|
6679
|
+
this.functionCallId = options.functionCallId;
|
|
6680
|
+
}
|
|
6681
|
+
/**
|
|
6682
|
+
* Gets the event actions of the current tool call
|
|
6683
|
+
*/
|
|
6684
|
+
get actions() {
|
|
6685
|
+
return this.eventActions;
|
|
6686
|
+
}
|
|
6687
|
+
/**
|
|
6688
|
+
* Lists the filenames of the artifacts attached to the current session
|
|
6689
|
+
*/
|
|
6690
|
+
async listArtifacts() {
|
|
6691
|
+
if (!this._invocationContext.artifactService) {
|
|
6692
|
+
throw new Error("Artifact service is not initialized.");
|
|
6693
|
+
}
|
|
6694
|
+
return await this._invocationContext.artifactService.listArtifactKeys({
|
|
6695
|
+
appName: this._invocationContext.appName,
|
|
6696
|
+
userId: this._invocationContext.userId,
|
|
6697
|
+
sessionId: this._invocationContext.session.id
|
|
6698
|
+
});
|
|
6699
|
+
}
|
|
6700
|
+
/**
|
|
6701
|
+
* Searches the memory of the current user
|
|
6702
|
+
*/
|
|
6703
|
+
async searchMemory(query) {
|
|
6704
|
+
if (!this._invocationContext.memoryService) {
|
|
6705
|
+
throw new Error("Memory service is not available.");
|
|
6706
|
+
}
|
|
6707
|
+
return await this._invocationContext.memoryService.searchMemory({
|
|
6708
|
+
query,
|
|
6709
|
+
appName: this._invocationContext.appName,
|
|
6710
|
+
userId: this._invocationContext.userId
|
|
6711
|
+
});
|
|
6712
|
+
}
|
|
6713
|
+
};
|
|
6714
|
+
|
|
6690
6715
|
// src/flows/llm-flows/functions.ts
|
|
6691
6716
|
|
|
6692
6717
|
var AF_FUNCTION_CALL_ID_PREFIX = "adk-";
|
|
@@ -6706,12 +6731,12 @@ function populateClientFunctionCallId(modelResponseEvent) {
|
|
|
6706
6731
|
}
|
|
6707
6732
|
}
|
|
6708
6733
|
function removeClientFunctionCallId(content) {
|
|
6709
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
6734
|
+
if (_optionalChain([content, 'optionalAccess', _181 => _181.parts])) {
|
|
6710
6735
|
for (const part of content.parts) {
|
|
6711
|
-
if (_optionalChain([part, 'access',
|
|
6736
|
+
if (_optionalChain([part, 'access', _182 => _182.functionCall, 'optionalAccess', _183 => _183.id, 'optionalAccess', _184 => _184.startsWith, 'call', _185 => _185(AF_FUNCTION_CALL_ID_PREFIX)])) {
|
|
6712
6737
|
part.functionCall.id = void 0;
|
|
6713
6738
|
}
|
|
6714
|
-
if (_optionalChain([part, 'access',
|
|
6739
|
+
if (_optionalChain([part, 'access', _186 => _186.functionResponse, 'optionalAccess', _187 => _187.id, 'optionalAccess', _188 => _188.startsWith, 'call', _189 => _189(AF_FUNCTION_CALL_ID_PREFIX)])) {
|
|
6715
6740
|
part.functionResponse.id = void 0;
|
|
6716
6741
|
}
|
|
6717
6742
|
}
|
|
@@ -6906,7 +6931,7 @@ function mergeParallelFunctionResponseEvents(functionResponseEvents) {
|
|
|
6906
6931
|
}
|
|
6907
6932
|
const mergedParts = [];
|
|
6908
6933
|
for (const event of functionResponseEvents) {
|
|
6909
|
-
if (_optionalChain([event, 'access',
|
|
6934
|
+
if (_optionalChain([event, 'access', _190 => _190.content, 'optionalAccess', _191 => _191.parts])) {
|
|
6910
6935
|
for (const part of event.content.parts) {
|
|
6911
6936
|
mergedParts.push(part);
|
|
6912
6937
|
}
|
|
@@ -7027,7 +7052,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
7027
7052
|
const seen = /* @__PURE__ */ new Set();
|
|
7028
7053
|
const filtered = [];
|
|
7029
7054
|
for (const t of tools) {
|
|
7030
|
-
const name = _optionalChain([t, 'optionalAccess',
|
|
7055
|
+
const name = _optionalChain([t, 'optionalAccess', _192 => _192.name]);
|
|
7031
7056
|
if (!name) continue;
|
|
7032
7057
|
if (seen.has(name)) {
|
|
7033
7058
|
continue;
|
|
@@ -7044,7 +7069,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
7044
7069
|
if (tools.length > 0) {
|
|
7045
7070
|
const toolsData = tools.map((tool) => ({
|
|
7046
7071
|
Name: tool.name,
|
|
7047
|
-
Description: _optionalChain([tool, 'access',
|
|
7072
|
+
Description: _optionalChain([tool, 'access', _193 => _193.description, 'optionalAccess', _194 => _194.substring, 'call', _195 => _195(0, 50)]) + (_optionalChain([tool, 'access', _196 => _196.description, 'optionalAccess', _197 => _197.length]) > 50 ? "..." : ""),
|
|
7048
7073
|
"Long Running": tool.isLongRunning ? "Yes" : "No"
|
|
7049
7074
|
}));
|
|
7050
7075
|
this.logger.debugArray("\u{1F6E0}\uFE0F Available Tools", toolsData);
|
|
@@ -7107,14 +7132,14 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
7107
7132
|
);
|
|
7108
7133
|
if (functionResponseEvent) {
|
|
7109
7134
|
yield functionResponseEvent;
|
|
7110
|
-
const transferToAgent = _optionalChain([functionResponseEvent, 'access',
|
|
7135
|
+
const transferToAgent = _optionalChain([functionResponseEvent, 'access', _198 => _198.actions, 'optionalAccess', _199 => _199.transferToAgent]);
|
|
7111
7136
|
if (transferToAgent) {
|
|
7112
7137
|
this.logger.debug(`\u{1F504} Live transfer to agent '${transferToAgent}'`);
|
|
7113
7138
|
const agentToRun = this._getAgentToRun(
|
|
7114
7139
|
invocationContext,
|
|
7115
7140
|
transferToAgent
|
|
7116
7141
|
);
|
|
7117
|
-
for await (const event of _optionalChain([agentToRun, 'access',
|
|
7142
|
+
for await (const event of _optionalChain([agentToRun, 'access', _200 => _200.runLive, 'optionalCall', _201 => _201(invocationContext)]) || agentToRun.runAsync(invocationContext)) {
|
|
7118
7143
|
yield event;
|
|
7119
7144
|
}
|
|
7120
7145
|
}
|
|
@@ -7146,7 +7171,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
7146
7171
|
yield authEvent;
|
|
7147
7172
|
}
|
|
7148
7173
|
yield functionResponseEvent;
|
|
7149
|
-
const transferToAgent = _optionalChain([functionResponseEvent, 'access',
|
|
7174
|
+
const transferToAgent = _optionalChain([functionResponseEvent, 'access', _202 => _202.actions, 'optionalAccess', _203 => _203.transferToAgent]);
|
|
7150
7175
|
if (transferToAgent) {
|
|
7151
7176
|
this.logger.debug(`\u{1F504} Transferring to agent '${transferToAgent}'`);
|
|
7152
7177
|
const agentToRun = this._getAgentToRun(
|
|
@@ -7192,7 +7217,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
7192
7217
|
}
|
|
7193
7218
|
invocationContext.incrementLlmCallCount();
|
|
7194
7219
|
const isStreaming = invocationContext.runConfig.streamingMode === "sse" /* SSE */;
|
|
7195
|
-
let tools = _optionalChain([llmRequest, 'access',
|
|
7220
|
+
let tools = _optionalChain([llmRequest, 'access', _204 => _204.config, 'optionalAccess', _205 => _205.tools]) || [];
|
|
7196
7221
|
if (tools.length) {
|
|
7197
7222
|
const deduped = [];
|
|
7198
7223
|
const seenFn = /* @__PURE__ */ new Set();
|
|
@@ -7201,7 +7226,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
7201
7226
|
if (tool && Array.isArray(tool.functionDeclarations)) {
|
|
7202
7227
|
const newFds = tool.functionDeclarations.filter(
|
|
7203
7228
|
(fd) => {
|
|
7204
|
-
if (_optionalChain([fd, 'optionalAccess',
|
|
7229
|
+
if (_optionalChain([fd, 'optionalAccess', _206 => _206.name])) {
|
|
7205
7230
|
if (seenFn.has(fd.name)) {
|
|
7206
7231
|
return false;
|
|
7207
7232
|
}
|
|
@@ -7213,7 +7238,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
7213
7238
|
if (newFds.length) {
|
|
7214
7239
|
deduped.push({ ...tool, functionDeclarations: newFds });
|
|
7215
7240
|
}
|
|
7216
|
-
} else if (_optionalChain([tool, 'optionalAccess',
|
|
7241
|
+
} else if (_optionalChain([tool, 'optionalAccess', _207 => _207.name])) {
|
|
7217
7242
|
if (seenFn.has(tool.name)) continue;
|
|
7218
7243
|
seenFn.add(tool.name);
|
|
7219
7244
|
deduped.push(tool);
|
|
@@ -7233,21 +7258,21 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
7233
7258
|
return tool.functionDeclarations.map((fn) => fn.name).join(", ");
|
|
7234
7259
|
}
|
|
7235
7260
|
if (tool.name) return tool.name;
|
|
7236
|
-
if (_optionalChain([tool, 'access',
|
|
7237
|
-
if (_optionalChain([tool, 'access',
|
|
7261
|
+
if (_optionalChain([tool, 'access', _208 => _208.function, 'optionalAccess', _209 => _209.name])) return tool.function.name;
|
|
7262
|
+
if (_optionalChain([tool, 'access', _210 => _210.function, 'optionalAccess', _211 => _211.function, 'optionalAccess', _212 => _212.name])) return tool.function.function.name;
|
|
7238
7263
|
return "unknown";
|
|
7239
7264
|
}).join(", ");
|
|
7240
7265
|
const systemInstruction = llmRequest.getSystemInstructionText() || "";
|
|
7241
7266
|
const truncatedSystemInstruction = systemInstruction.length > 100 ? `${systemInstruction.substring(0, 100)}...` : systemInstruction;
|
|
7242
|
-
const contentPreview = _optionalChain([llmRequest, 'access',
|
|
7267
|
+
const contentPreview = _optionalChain([llmRequest, 'access', _213 => _213.contents, 'optionalAccess', _214 => _214.length]) > 0 ? LogFormatter.formatContentPreview(llmRequest.contents[0]) : "none";
|
|
7243
7268
|
this.logger.debugStructured("\u{1F4E4} LLM Request", {
|
|
7244
7269
|
Model: llm.model,
|
|
7245
7270
|
Agent: invocationContext.agent.name,
|
|
7246
|
-
"Content Items": _optionalChain([llmRequest, 'access',
|
|
7271
|
+
"Content Items": _optionalChain([llmRequest, 'access', _215 => _215.contents, 'optionalAccess', _216 => _216.length]) || 0,
|
|
7247
7272
|
"Content Preview": contentPreview,
|
|
7248
7273
|
"System Instruction": truncatedSystemInstruction || "none",
|
|
7249
7274
|
"Available Tools": toolNames || "none",
|
|
7250
|
-
"Tool Count": _optionalChain([llmRequest, 'access',
|
|
7275
|
+
"Tool Count": _optionalChain([llmRequest, 'access', _217 => _217.config, 'optionalAccess', _218 => _218.tools, 'optionalAccess', _219 => _219.length]) || 0,
|
|
7251
7276
|
Streaming: isStreaming ? "Yes" : "No"
|
|
7252
7277
|
});
|
|
7253
7278
|
let responseCount = 0;
|
|
@@ -7262,8 +7287,8 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
7262
7287
|
llmRequest,
|
|
7263
7288
|
llmResponse
|
|
7264
7289
|
);
|
|
7265
|
-
const tokenCount = _optionalChain([llmResponse, 'access',
|
|
7266
|
-
const functionCalls = _optionalChain([llmResponse, 'access',
|
|
7290
|
+
const tokenCount = _optionalChain([llmResponse, 'access', _220 => _220.usageMetadata, 'optionalAccess', _221 => _221.totalTokenCount]) || "unknown";
|
|
7291
|
+
const functionCalls = _optionalChain([llmResponse, 'access', _222 => _222.content, 'optionalAccess', _223 => _223.parts, 'optionalAccess', _224 => _224.filter, 'call', _225 => _225((part) => part.functionCall)]) || [];
|
|
7267
7292
|
const functionCallsDisplay = LogFormatter.formatFunctionCalls(functionCalls);
|
|
7268
7293
|
const responsePreview = LogFormatter.formatResponsePreview(llmResponse);
|
|
7269
7294
|
this.logger.debugStructured("\u{1F4E5} LLM Response", {
|
|
@@ -7407,7 +7432,7 @@ var EnhancedAuthConfig = class {
|
|
|
7407
7432
|
*/
|
|
7408
7433
|
generateCredentialKey() {
|
|
7409
7434
|
const schemeKey = this.authScheme.type || "unknown";
|
|
7410
|
-
const credentialKey = _optionalChain([this, 'access',
|
|
7435
|
+
const credentialKey = _optionalChain([this, 'access', _226 => _226.rawAuthCredential, 'optionalAccess', _227 => _227.type]) || "none";
|
|
7411
7436
|
const timestamp = Date.now();
|
|
7412
7437
|
return `adk_${schemeKey}_${credentialKey}_${timestamp}`;
|
|
7413
7438
|
}
|
|
@@ -7564,7 +7589,7 @@ var AuthLlmRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
7564
7589
|
*/
|
|
7565
7590
|
parseAndStoreAuthResponse(authHandler, invocationContext) {
|
|
7566
7591
|
try {
|
|
7567
|
-
const credentialKey = _optionalChain([authHandler, 'access',
|
|
7592
|
+
const credentialKey = _optionalChain([authHandler, 'access', _228 => _228.authConfig, 'access', _229 => _229.context, 'optionalAccess', _230 => _230.credentialKey]) || `temp:${Date.now()}`;
|
|
7568
7593
|
const fullCredentialKey = credentialKey.startsWith("temp:") ? credentialKey : `temp:${credentialKey}`;
|
|
7569
7594
|
invocationContext.session.state[fullCredentialKey] = authHandler.credential;
|
|
7570
7595
|
if (authHandler.authConfig.authScheme.type === "oauth2" || authHandler.authConfig.authScheme.type === "openIdConnect") {
|
|
@@ -7593,7 +7618,7 @@ var BasicLlmRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
7593
7618
|
llmRequest.config = {};
|
|
7594
7619
|
}
|
|
7595
7620
|
if (agent.outputSchema) {
|
|
7596
|
-
const hasTools = await _asyncOptionalChain([(await _optionalChain([agent, 'access',
|
|
7621
|
+
const hasTools = await _asyncOptionalChain([(await _optionalChain([agent, 'access', _231 => _231.canonicalTools, 'optionalCall', _232 => _232(invocationContext)])), 'optionalAccess', async _233 => _233.length]) > 0;
|
|
7597
7622
|
const hasTransfers = !!("subAgents" in agent && agent.subAgents && agent.subAgents.length > 0 && !(agent.disallowTransferToParent && agent.disallowTransferToPeers));
|
|
7598
7623
|
if (!hasTools && !hasTransfers) {
|
|
7599
7624
|
llmRequest.setOutputSchema(agent.outputSchema);
|
|
@@ -7685,7 +7710,7 @@ var BuiltInCodeExecutor = class extends BaseCodeExecutor {
|
|
|
7685
7710
|
* Pre-process the LLM request for Gemini 2.0+ models to use the code execution tool
|
|
7686
7711
|
*/
|
|
7687
7712
|
processLlmRequest(llmRequest) {
|
|
7688
|
-
if (!_optionalChain([llmRequest, 'access',
|
|
7713
|
+
if (!_optionalChain([llmRequest, 'access', _234 => _234.model, 'optionalAccess', _235 => _235.startsWith, 'call', _236 => _236("gemini-2")])) {
|
|
7689
7714
|
throw new Error(
|
|
7690
7715
|
`Gemini code execution tool is not supported for model ${llmRequest.model}`
|
|
7691
7716
|
);
|
|
@@ -7730,7 +7755,7 @@ var CodeExecutionUtils = class _CodeExecutionUtils {
|
|
|
7730
7755
|
* Extracts the first code block from the content and truncates everything after it
|
|
7731
7756
|
*/
|
|
7732
7757
|
static extractCodeAndTruncateContent(content, codeBlockDelimiters) {
|
|
7733
|
-
if (!_optionalChain([content, 'optionalAccess',
|
|
7758
|
+
if (!_optionalChain([content, 'optionalAccess', _237 => _237.parts, 'optionalAccess', _238 => _238.length])) {
|
|
7734
7759
|
return null;
|
|
7735
7760
|
}
|
|
7736
7761
|
for (let idx = 0; idx < content.parts.length; idx++) {
|
|
@@ -7816,7 +7841,7 @@ ${fileNames}`);
|
|
|
7816
7841
|
* Converts the code execution parts to text parts in a Content
|
|
7817
7842
|
*/
|
|
7818
7843
|
static convertCodeExecutionParts(content, codeBlockDelimiter, executionResultDelimiters) {
|
|
7819
|
-
if (!_optionalChain([content, 'access',
|
|
7844
|
+
if (!_optionalChain([content, 'access', _239 => _239.parts, 'optionalAccess', _240 => _240.length])) {
|
|
7820
7845
|
return;
|
|
7821
7846
|
}
|
|
7822
7847
|
const lastPart = content.parts[content.parts.length - 1];
|
|
@@ -8209,7 +8234,7 @@ async function* runPostProcessor(invocationContext, llmResponse) {
|
|
|
8209
8234
|
function extractAndReplaceInlineFiles(codeExecutorContext, llmRequest) {
|
|
8210
8235
|
const allInputFiles = codeExecutorContext.getInputFiles();
|
|
8211
8236
|
const savedFileNames = new Set(allInputFiles.map((f) => f.name));
|
|
8212
|
-
for (let i = 0; i < (_optionalChain([llmRequest, 'access',
|
|
8237
|
+
for (let i = 0; i < (_optionalChain([llmRequest, 'access', _241 => _241.contents, 'optionalAccess', _242 => _242.length]) || 0); i++) {
|
|
8213
8238
|
const content = llmRequest.contents[i];
|
|
8214
8239
|
if (content.role !== "user" || !content.parts) {
|
|
8215
8240
|
continue;
|
|
@@ -8241,7 +8266,7 @@ Available file: \`${fileName}\`
|
|
|
8241
8266
|
}
|
|
8242
8267
|
function getOrSetExecutionId(invocationContext, codeExecutorContext) {
|
|
8243
8268
|
const agent = invocationContext.agent;
|
|
8244
|
-
if (!hasCodeExecutor(agent) || !_optionalChain([agent, 'access',
|
|
8269
|
+
if (!hasCodeExecutor(agent) || !_optionalChain([agent, 'access', _243 => _243.codeExecutor, 'optionalAccess', _244 => _244.stateful])) {
|
|
8245
8270
|
return void 0;
|
|
8246
8271
|
}
|
|
8247
8272
|
let executionId = codeExecutorContext.getExecutionId();
|
|
@@ -8472,7 +8497,7 @@ function rearrangeEventsForLatestFunctionResponse(events) {
|
|
|
8472
8497
|
continue;
|
|
8473
8498
|
}
|
|
8474
8499
|
const functionResponses2 = event.getFunctionResponses();
|
|
8475
|
-
if (_optionalChain([functionResponses2, 'optionalAccess',
|
|
8500
|
+
if (_optionalChain([functionResponses2, 'optionalAccess', _245 => _245.some, 'call', _246 => _246((fr) => fr.id && functionResponsesIds.has(fr.id))])) {
|
|
8476
8501
|
functionResponseEvents.push(event);
|
|
8477
8502
|
}
|
|
8478
8503
|
}
|
|
@@ -8492,7 +8517,7 @@ function getContents(currentBranch, events, agentName = "") {
|
|
|
8492
8517
|
let i = events.length - 1;
|
|
8493
8518
|
while (i >= 0) {
|
|
8494
8519
|
const event = events[i];
|
|
8495
|
-
if (_optionalChain([event, 'access',
|
|
8520
|
+
if (_optionalChain([event, 'access', _247 => _247.actions, 'optionalAccess', _248 => _248.rewindBeforeInvocationId])) {
|
|
8496
8521
|
const rewindInvocationId = event.actions.rewindBeforeInvocationId;
|
|
8497
8522
|
const rewindIndex = invocationIdToIndex.get(rewindInvocationId);
|
|
8498
8523
|
if (rewindIndex !== void 0 && rewindIndex < i) {
|
|
@@ -8594,7 +8619,7 @@ function mergeFunctionResponseEvents(functionResponseEvents) {
|
|
|
8594
8619
|
const partIndicesInMergedEvent = {};
|
|
8595
8620
|
for (let idx = 0; idx < partsInMergedEvent.length; idx++) {
|
|
8596
8621
|
const part = partsInMergedEvent[idx];
|
|
8597
|
-
if (_optionalChain([part, 'access',
|
|
8622
|
+
if (_optionalChain([part, 'access', _249 => _249.functionResponse, 'optionalAccess', _250 => _250.id])) {
|
|
8598
8623
|
partIndicesInMergedEvent[part.functionResponse.id] = idx;
|
|
8599
8624
|
}
|
|
8600
8625
|
}
|
|
@@ -8603,7 +8628,7 @@ function mergeFunctionResponseEvents(functionResponseEvents) {
|
|
|
8603
8628
|
throw new Error("There should be at least one function_response part.");
|
|
8604
8629
|
}
|
|
8605
8630
|
for (const part of event.content.parts) {
|
|
8606
|
-
if (_optionalChain([part, 'access',
|
|
8631
|
+
if (_optionalChain([part, 'access', _251 => _251.functionResponse, 'optionalAccess', _252 => _252.id])) {
|
|
8607
8632
|
const functionCallId = part.functionResponse.id;
|
|
8608
8633
|
if (functionCallId in partIndicesInMergedEvent) {
|
|
8609
8634
|
partsInMergedEvent[partIndicesInMergedEvent[functionCallId]] = part;
|
|
@@ -8643,7 +8668,7 @@ function processCompactionEvents(events) {
|
|
|
8643
8668
|
let lastCompactionStartTime = Number.POSITIVE_INFINITY;
|
|
8644
8669
|
for (let i = events.length - 1; i >= 0; i--) {
|
|
8645
8670
|
const event = events[i];
|
|
8646
|
-
if (_optionalChain([event, 'access',
|
|
8671
|
+
if (_optionalChain([event, 'access', _253 => _253.actions, 'optionalAccess', _254 => _254.compaction])) {
|
|
8647
8672
|
const compaction = event.actions.compaction;
|
|
8648
8673
|
const synthesizedEvent = new Event({
|
|
8649
8674
|
timestamp: compaction.endTimestamp,
|
|
@@ -8965,7 +8990,7 @@ var PlanReActPlanner = class extends BasePlanner {
|
|
|
8965
8990
|
let firstFcPartIndex = -1;
|
|
8966
8991
|
for (let i = 0; i < responseParts.length; i++) {
|
|
8967
8992
|
if (responseParts[i].functionCall) {
|
|
8968
|
-
if (!_optionalChain([responseParts, 'access',
|
|
8993
|
+
if (!_optionalChain([responseParts, 'access', _255 => _255[i], 'access', _256 => _256.functionCall, 'optionalAccess', _257 => _257.name])) {
|
|
8969
8994
|
continue;
|
|
8970
8995
|
}
|
|
8971
8996
|
preservedParts.push(responseParts[i]);
|
|
@@ -9004,7 +9029,7 @@ var PlanReActPlanner = class extends BasePlanner {
|
|
|
9004
9029
|
* Handles non-function-call parts of the response
|
|
9005
9030
|
*/
|
|
9006
9031
|
_handleNonFunctionCallParts(responsePart, preservedParts) {
|
|
9007
|
-
if (_optionalChain([responsePart, 'access',
|
|
9032
|
+
if (_optionalChain([responsePart, 'access', _258 => _258.text, 'optionalAccess', _259 => _259.includes, 'call', _260 => _260(FINAL_ANSWER_TAG)])) {
|
|
9008
9033
|
const [reasoningText, finalAnswerText] = this._splitByLastPattern(
|
|
9009
9034
|
responsePart.text,
|
|
9010
9035
|
FINAL_ANSWER_TAG
|
|
@@ -9243,7 +9268,7 @@ var OutputSchemaResponseProcessor = (_class26 = class extends BaseLlmResponsePro
|
|
|
9243
9268
|
stripCodeFences(raw) {
|
|
9244
9269
|
const fencePattern = /```(?:json)?\s*([\s\S]*?)```/i;
|
|
9245
9270
|
const fenceMatch = raw.match(fencePattern);
|
|
9246
|
-
if (_optionalChain([fenceMatch, 'optionalAccess',
|
|
9271
|
+
if (_optionalChain([fenceMatch, 'optionalAccess', _261 => _261[1]])) {
|
|
9247
9272
|
return fenceMatch[1].trim();
|
|
9248
9273
|
}
|
|
9249
9274
|
const lines = raw.split(/\r?\n/).map((l) => l.trim());
|
|
@@ -9280,7 +9305,7 @@ var SharedMemoryRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
9280
9305
|
const memoryService = invocationContext.memoryService;
|
|
9281
9306
|
if (!memoryService) return;
|
|
9282
9307
|
const lastUserEvent = invocationContext.session.events.findLast(
|
|
9283
|
-
(e) => e.author === "user" && _optionalChain([e, 'access',
|
|
9308
|
+
(e) => e.author === "user" && _optionalChain([e, 'access', _262 => _262.content, 'optionalAccess', _263 => _263.parts, 'optionalAccess', _264 => _264.length])
|
|
9284
9309
|
);
|
|
9285
9310
|
if (!lastUserEvent) return;
|
|
9286
9311
|
const query = (_nullishCoalesce(lastUserEvent.content.parts, () => ( []))).map((p) => p.text || "").join(" ");
|
|
@@ -9291,7 +9316,7 @@ var SharedMemoryRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
9291
9316
|
});
|
|
9292
9317
|
const sessionTexts = new Set(
|
|
9293
9318
|
(llmRequest.contents || []).flatMap(
|
|
9294
|
-
(c) => _optionalChain([c, 'access',
|
|
9319
|
+
(c) => _optionalChain([c, 'access', _265 => _265.parts, 'optionalAccess', _266 => _266.map, 'call', _267 => _267((p) => p.text)]) || []
|
|
9295
9320
|
)
|
|
9296
9321
|
);
|
|
9297
9322
|
for (const memory of results.memories) {
|
|
@@ -9712,7 +9737,7 @@ var LlmAgent = (_class27 = class _LlmAgent extends BaseAgent {
|
|
|
9712
9737
|
* This matches the Python implementation's _llm_flow property
|
|
9713
9738
|
*/
|
|
9714
9739
|
get llmFlow() {
|
|
9715
|
-
if (this.disallowTransferToParent && this.disallowTransferToPeers && !_optionalChain([this, 'access',
|
|
9740
|
+
if (this.disallowTransferToParent && this.disallowTransferToPeers && !_optionalChain([this, 'access', _268 => _268.subAgents, 'optionalAccess', _269 => _269.length])) {
|
|
9716
9741
|
return new SingleFlow();
|
|
9717
9742
|
}
|
|
9718
9743
|
return new AutoFlow();
|
|
@@ -9728,7 +9753,7 @@ var LlmAgent = (_class27 = class _LlmAgent extends BaseAgent {
|
|
|
9728
9753
|
);
|
|
9729
9754
|
return;
|
|
9730
9755
|
}
|
|
9731
|
-
if (this.outputKey && event.isFinalResponse() && _optionalChain([event, 'access',
|
|
9756
|
+
if (this.outputKey && event.isFinalResponse() && _optionalChain([event, 'access', _270 => _270.content, 'optionalAccess', _271 => _271.parts])) {
|
|
9732
9757
|
let result = event.content.parts.map((part) => part.text || "").join("");
|
|
9733
9758
|
if (this.outputSchema) {
|
|
9734
9759
|
if (!result.trim()) {
|
|
@@ -9948,7 +9973,7 @@ var LoopAgent = class extends BaseAgent {
|
|
|
9948
9973
|
for (const subAgent of this.subAgents) {
|
|
9949
9974
|
for await (const event of subAgent.runAsync(ctx)) {
|
|
9950
9975
|
yield event;
|
|
9951
|
-
if (_optionalChain([event, 'access',
|
|
9976
|
+
if (_optionalChain([event, 'access', _272 => _272.actions, 'optionalAccess', _273 => _273.escalate])) {
|
|
9952
9977
|
return;
|
|
9953
9978
|
}
|
|
9954
9979
|
}
|
|
@@ -10260,17 +10285,17 @@ var RunConfig = class {
|
|
|
10260
10285
|
*/
|
|
10261
10286
|
|
|
10262
10287
|
constructor(config) {
|
|
10263
|
-
this.speechConfig = _optionalChain([config, 'optionalAccess',
|
|
10264
|
-
this.responseModalities = _optionalChain([config, 'optionalAccess',
|
|
10265
|
-
this.saveInputBlobsAsArtifacts = _optionalChain([config, 'optionalAccess',
|
|
10266
|
-
this.supportCFC = _optionalChain([config, 'optionalAccess',
|
|
10267
|
-
this.streamingMode = _optionalChain([config, 'optionalAccess',
|
|
10268
|
-
this.outputAudioTranscription = _optionalChain([config, 'optionalAccess',
|
|
10269
|
-
this.inputAudioTranscription = _optionalChain([config, 'optionalAccess',
|
|
10270
|
-
this.realtimeInputConfig = _optionalChain([config, 'optionalAccess',
|
|
10271
|
-
this.enableAffectiveDialog = _optionalChain([config, 'optionalAccess',
|
|
10272
|
-
this.proactivity = _optionalChain([config, 'optionalAccess',
|
|
10273
|
-
this.maxLlmCalls = _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
10288
|
+
this.speechConfig = _optionalChain([config, 'optionalAccess', _274 => _274.speechConfig]);
|
|
10289
|
+
this.responseModalities = _optionalChain([config, 'optionalAccess', _275 => _275.responseModalities]);
|
|
10290
|
+
this.saveInputBlobsAsArtifacts = _optionalChain([config, 'optionalAccess', _276 => _276.saveInputBlobsAsArtifacts]) || false;
|
|
10291
|
+
this.supportCFC = _optionalChain([config, 'optionalAccess', _277 => _277.supportCFC]) || false;
|
|
10292
|
+
this.streamingMode = _optionalChain([config, 'optionalAccess', _278 => _278.streamingMode]) || "NONE" /* NONE */;
|
|
10293
|
+
this.outputAudioTranscription = _optionalChain([config, 'optionalAccess', _279 => _279.outputAudioTranscription]);
|
|
10294
|
+
this.inputAudioTranscription = _optionalChain([config, 'optionalAccess', _280 => _280.inputAudioTranscription]);
|
|
10295
|
+
this.realtimeInputConfig = _optionalChain([config, 'optionalAccess', _281 => _281.realtimeInputConfig]);
|
|
10296
|
+
this.enableAffectiveDialog = _optionalChain([config, 'optionalAccess', _282 => _282.enableAffectiveDialog]);
|
|
10297
|
+
this.proactivity = _optionalChain([config, 'optionalAccess', _283 => _283.proactivity]);
|
|
10298
|
+
this.maxLlmCalls = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _284 => _284.maxLlmCalls]), () => ( 500));
|
|
10274
10299
|
this.validateMaxLlmCalls();
|
|
10275
10300
|
}
|
|
10276
10301
|
/**
|
|
@@ -10328,7 +10353,7 @@ function getArtifactUri(args) {
|
|
|
10328
10353
|
}
|
|
10329
10354
|
function isArtifactRef(artifact) {
|
|
10330
10355
|
return Boolean(
|
|
10331
|
-
_optionalChain([artifact, 'access',
|
|
10356
|
+
_optionalChain([artifact, 'access', _285 => _285.fileData, 'optionalAccess', _286 => _286.fileUri]) && artifact.fileData.fileUri.startsWith("artifact://")
|
|
10332
10357
|
);
|
|
10333
10358
|
}
|
|
10334
10359
|
|
|
@@ -10377,10 +10402,10 @@ var InMemoryArtifactService = (_class29 = class {constructor() { _class29.protot
|
|
|
10377
10402
|
return null;
|
|
10378
10403
|
}
|
|
10379
10404
|
if (isArtifactRef(artifactEntry)) {
|
|
10380
|
-
const parsedUri = parseArtifactUri(_optionalChain([artifactEntry, 'access',
|
|
10405
|
+
const parsedUri = parseArtifactUri(_optionalChain([artifactEntry, 'access', _287 => _287.fileData, 'optionalAccess', _288 => _288.fileUri]) || "");
|
|
10381
10406
|
if (!parsedUri) {
|
|
10382
10407
|
throw new Error(
|
|
10383
|
-
`Invalid artifact reference URI: ${_optionalChain([artifactEntry, 'access',
|
|
10408
|
+
`Invalid artifact reference URI: ${_optionalChain([artifactEntry, 'access', _289 => _289.fileData, 'optionalAccess', _290 => _290.fileUri])}`
|
|
10384
10409
|
);
|
|
10385
10410
|
}
|
|
10386
10411
|
return await this.loadArtifact({
|
|
@@ -10391,7 +10416,7 @@ var InMemoryArtifactService = (_class29 = class {constructor() { _class29.protot
|
|
|
10391
10416
|
version: parsedUri.version
|
|
10392
10417
|
});
|
|
10393
10418
|
}
|
|
10394
|
-
if (!artifactEntry.text && (!_optionalChain([artifactEntry, 'access',
|
|
10419
|
+
if (!artifactEntry.text && (!_optionalChain([artifactEntry, 'access', _291 => _291.inlineData, 'optionalAccess', _292 => _292.data]) || artifactEntry.inlineData.data.length === 0) && !artifactEntry.fileData) {
|
|
10395
10420
|
return null;
|
|
10396
10421
|
}
|
|
10397
10422
|
return artifactEntry;
|
|
@@ -10478,7 +10503,7 @@ var InMemoryMemoryService = (_class30 = class {
|
|
|
10478
10503
|
}
|
|
10479
10504
|
const userSessions = this._sessionEvents.get(userKey);
|
|
10480
10505
|
const filteredEvents = session.events.filter(
|
|
10481
|
-
(event) => _optionalChain([event, 'access',
|
|
10506
|
+
(event) => _optionalChain([event, 'access', _293 => _293.content, 'optionalAccess', _294 => _294.parts])
|
|
10482
10507
|
);
|
|
10483
10508
|
userSessions.set(session.id, filteredEvents);
|
|
10484
10509
|
}
|
|
@@ -10622,7 +10647,7 @@ var InMemorySessionService = (_class31 = class extends BaseSessionService {const
|
|
|
10622
10647
|
return this.createSessionImpl(appName, userId, state, sessionId);
|
|
10623
10648
|
}
|
|
10624
10649
|
createSessionImpl(appName, userId, state, sessionId) {
|
|
10625
|
-
const finalSessionId = _optionalChain([sessionId, 'optionalAccess',
|
|
10650
|
+
const finalSessionId = _optionalChain([sessionId, 'optionalAccess', _295 => _295.trim, 'call', _296 => _296()]) || _crypto.randomUUID.call(void 0, );
|
|
10626
10651
|
const session = {
|
|
10627
10652
|
appName,
|
|
10628
10653
|
userId,
|
|
@@ -10779,7 +10804,7 @@ var InMemorySessionService = (_class31 = class extends BaseSessionService {const
|
|
|
10779
10804
|
warning(`sessionId ${sessionId} not in sessions[appName][userId]`);
|
|
10780
10805
|
return event;
|
|
10781
10806
|
}
|
|
10782
|
-
if (_optionalChain([event, 'access',
|
|
10807
|
+
if (_optionalChain([event, 'access', _297 => _297.actions, 'optionalAccess', _298 => _298.stateDelta])) {
|
|
10783
10808
|
for (const key in event.actions.stateDelta) {
|
|
10784
10809
|
const value = event.actions.stateDelta[key];
|
|
10785
10810
|
if (key.startsWith(State.APP_PREFIX)) {
|
|
@@ -10813,14 +10838,14 @@ function _findFunctionCallEventIfLastEventIsFunctionResponse(session) {
|
|
|
10813
10838
|
return null;
|
|
10814
10839
|
}
|
|
10815
10840
|
const lastEvent = events[events.length - 1];
|
|
10816
|
-
if (_optionalChain([lastEvent, 'access',
|
|
10817
|
-
const functionCallId = _optionalChain([lastEvent, 'access',
|
|
10841
|
+
if (_optionalChain([lastEvent, 'access', _299 => _299.content, 'optionalAccess', _300 => _300.parts, 'optionalAccess', _301 => _301.some, 'call', _302 => _302((part) => part.functionResponse)])) {
|
|
10842
|
+
const functionCallId = _optionalChain([lastEvent, 'access', _303 => _303.content, 'access', _304 => _304.parts, 'access', _305 => _305.find, 'call', _306 => _306(
|
|
10818
10843
|
(part) => part.functionResponse
|
|
10819
|
-
), 'optionalAccess',
|
|
10844
|
+
), 'optionalAccess', _307 => _307.functionResponse, 'optionalAccess', _308 => _308.id]);
|
|
10820
10845
|
if (!functionCallId) return null;
|
|
10821
10846
|
for (let i = events.length - 2; i >= 0; i--) {
|
|
10822
10847
|
const event = events[i];
|
|
10823
|
-
const functionCalls = _optionalChain([event, 'access',
|
|
10848
|
+
const functionCalls = _optionalChain([event, 'access', _309 => _309.getFunctionCalls, 'optionalCall', _310 => _310()]) || [];
|
|
10824
10849
|
for (const functionCall of functionCalls) {
|
|
10825
10850
|
if (functionCall.id === functionCallId) {
|
|
10826
10851
|
return event;
|
|
@@ -11033,15 +11058,15 @@ var Runner = (_class32 = class {
|
|
|
11033
11058
|
*/
|
|
11034
11059
|
_findAgentToRun(session, rootAgent) {
|
|
11035
11060
|
const event = _findFunctionCallEventIfLastEventIsFunctionResponse(session);
|
|
11036
|
-
if (_optionalChain([event, 'optionalAccess',
|
|
11061
|
+
if (_optionalChain([event, 'optionalAccess', _311 => _311.author])) {
|
|
11037
11062
|
return rootAgent.findAgent(event.author);
|
|
11038
11063
|
}
|
|
11039
|
-
const nonUserEvents = _optionalChain([session, 'access',
|
|
11064
|
+
const nonUserEvents = _optionalChain([session, 'access', _312 => _312.events, 'optionalAccess', _313 => _313.filter, 'call', _314 => _314((e) => e.author !== "user"), 'access', _315 => _315.reverse, 'call', _316 => _316()]) || [];
|
|
11040
11065
|
for (const event2 of nonUserEvents) {
|
|
11041
11066
|
if (event2.author === rootAgent.name) {
|
|
11042
11067
|
return rootAgent;
|
|
11043
11068
|
}
|
|
11044
|
-
const agent = _optionalChain([rootAgent, 'access',
|
|
11069
|
+
const agent = _optionalChain([rootAgent, 'access', _317 => _317.findSubAgent, 'optionalCall', _318 => _318(event2.author)]);
|
|
11045
11070
|
if (!agent) {
|
|
11046
11071
|
this.logger.debug(
|
|
11047
11072
|
`Event from an unknown agent: ${event2.author}, event id: ${event2.id}`
|
|
@@ -11119,7 +11144,7 @@ var Runner = (_class32 = class {
|
|
|
11119
11144
|
* Gets the configured summarizer or creates a default LLM-based one.
|
|
11120
11145
|
*/
|
|
11121
11146
|
_getOrCreateSummarizer() {
|
|
11122
|
-
if (_optionalChain([this, 'access',
|
|
11147
|
+
if (_optionalChain([this, 'access', _319 => _319.eventsCompactionConfig, 'optionalAccess', _320 => _320.summarizer])) {
|
|
11123
11148
|
return this.eventsCompactionConfig.summarizer;
|
|
11124
11149
|
}
|
|
11125
11150
|
if (this.agent instanceof LlmAgent) {
|
|
@@ -11183,7 +11208,7 @@ var Runner = (_class32 = class {
|
|
|
11183
11208
|
const stateAtRewindPoint = {};
|
|
11184
11209
|
for (let i = 0; i < rewindEventIndex; i++) {
|
|
11185
11210
|
const event = session.events[i];
|
|
11186
|
-
if (_optionalChain([event, 'access',
|
|
11211
|
+
if (_optionalChain([event, 'access', _321 => _321.actions, 'optionalAccess', _322 => _322.stateDelta])) {
|
|
11187
11212
|
for (const [k, v] of Object.entries(event.actions.stateDelta)) {
|
|
11188
11213
|
if (k.startsWith("app:") || k.startsWith("user:")) {
|
|
11189
11214
|
continue;
|
|
@@ -11220,13 +11245,13 @@ var Runner = (_class32 = class {
|
|
|
11220
11245
|
const versionsAtRewindPoint = {};
|
|
11221
11246
|
for (let i = 0; i < rewindEventIndex; i++) {
|
|
11222
11247
|
const event = session.events[i];
|
|
11223
|
-
if (_optionalChain([event, 'access',
|
|
11248
|
+
if (_optionalChain([event, 'access', _323 => _323.actions, 'optionalAccess', _324 => _324.artifactDelta])) {
|
|
11224
11249
|
Object.assign(versionsAtRewindPoint, event.actions.artifactDelta);
|
|
11225
11250
|
}
|
|
11226
11251
|
}
|
|
11227
11252
|
const currentVersions = {};
|
|
11228
11253
|
for (const event of session.events) {
|
|
11229
|
-
if (_optionalChain([event, 'access',
|
|
11254
|
+
if (_optionalChain([event, 'access', _325 => _325.actions, 'optionalAccess', _326 => _326.artifactDelta])) {
|
|
11230
11255
|
Object.assign(currentVersions, event.actions.artifactDelta);
|
|
11231
11256
|
}
|
|
11232
11257
|
}
|
|
@@ -11911,7 +11936,7 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
|
|
|
11911
11936
|
const outputSchema = this.config.outputSchema;
|
|
11912
11937
|
const agentType = this.agentType;
|
|
11913
11938
|
const isMulti = agentType === "parallel" || agentType === "sequential";
|
|
11914
|
-
const subAgentNames = _optionalChain([this, 'access',
|
|
11939
|
+
const subAgentNames = _optionalChain([this, 'access', _327 => _327.config, 'access', _328 => _328.subAgents, 'optionalAccess', _329 => _329.map, 'call', _330 => _330((a) => a.name)]) || [];
|
|
11915
11940
|
const runConfig = this.runConfig;
|
|
11916
11941
|
return {
|
|
11917
11942
|
__outputSchema: outputSchema,
|
|
@@ -11920,7 +11945,7 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
|
|
|
11920
11945
|
let combinedResponse = "";
|
|
11921
11946
|
const perAgentBuffers = {};
|
|
11922
11947
|
const authors = /* @__PURE__ */ new Set();
|
|
11923
|
-
if (!_optionalChain([sessionOptions, 'optionalAccess',
|
|
11948
|
+
if (!_optionalChain([sessionOptions, 'optionalAccess', _331 => _331.userId])) {
|
|
11924
11949
|
throw new Error("Session configuration is required");
|
|
11925
11950
|
}
|
|
11926
11951
|
for await (const event of baseRunner.runAsync({
|
|
@@ -11929,7 +11954,7 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
|
|
|
11929
11954
|
newMessage,
|
|
11930
11955
|
runConfig
|
|
11931
11956
|
})) {
|
|
11932
|
-
if (_optionalChain([event, 'access',
|
|
11957
|
+
if (_optionalChain([event, 'access', _332 => _332.content, 'optionalAccess', _333 => _333.parts]) && Array.isArray(event.content.parts)) {
|
|
11933
11958
|
const content = event.content.parts.map(
|
|
11934
11959
|
(part) => (part && typeof part === "object" && "text" in part ? part.text : "") || ""
|
|
11935
11960
|
).join("");
|
|
@@ -12219,7 +12244,7 @@ var VertexAiSessionService = class extends BaseSessionService {
|
|
|
12219
12244
|
path: `operations/${operationId}`,
|
|
12220
12245
|
request_dict: {}
|
|
12221
12246
|
});
|
|
12222
|
-
if (_optionalChain([lroResponse, 'optionalAccess',
|
|
12247
|
+
if (_optionalChain([lroResponse, 'optionalAccess', _334 => _334.done])) {
|
|
12223
12248
|
break;
|
|
12224
12249
|
}
|
|
12225
12250
|
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
@@ -12590,12 +12615,12 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
|
|
|
12590
12615
|
}
|
|
12591
12616
|
async createSession(appName, userId, state, sessionId) {
|
|
12592
12617
|
await this.ensureInitialized();
|
|
12593
|
-
const id = _optionalChain([sessionId, 'optionalAccess',
|
|
12618
|
+
const id = _optionalChain([sessionId, 'optionalAccess', _335 => _335.trim, 'call', _336 => _336()]) || this.generateSessionId();
|
|
12594
12619
|
return await this.db.transaction().execute(async (trx) => {
|
|
12595
12620
|
const appState = await trx.selectFrom("app_states").selectAll().where("app_name", "=", appName).executeTakeFirst();
|
|
12596
12621
|
const userState = await trx.selectFrom("user_states").selectAll().where("app_name", "=", appName).where("user_id", "=", userId).executeTakeFirst();
|
|
12597
|
-
let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess',
|
|
12598
|
-
let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess',
|
|
12622
|
+
let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _337 => _337.state]), {});
|
|
12623
|
+
let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _338 => _338.state]), {});
|
|
12599
12624
|
if (!appState) {
|
|
12600
12625
|
await trx.insertInto("app_states").values({
|
|
12601
12626
|
app_name: appName,
|
|
@@ -12654,21 +12679,21 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
|
|
|
12654
12679
|
return void 0;
|
|
12655
12680
|
}
|
|
12656
12681
|
let eventQuery = trx.selectFrom("events").selectAll().where("session_id", "=", sessionId).orderBy("timestamp", "desc");
|
|
12657
|
-
if (_optionalChain([config, 'optionalAccess',
|
|
12682
|
+
if (_optionalChain([config, 'optionalAccess', _339 => _339.afterTimestamp])) {
|
|
12658
12683
|
eventQuery = eventQuery.where(
|
|
12659
12684
|
"timestamp",
|
|
12660
12685
|
">=",
|
|
12661
12686
|
new Date(config.afterTimestamp * 1e3)
|
|
12662
12687
|
);
|
|
12663
12688
|
}
|
|
12664
|
-
if (_optionalChain([config, 'optionalAccess',
|
|
12689
|
+
if (_optionalChain([config, 'optionalAccess', _340 => _340.numRecentEvents])) {
|
|
12665
12690
|
eventQuery = eventQuery.limit(config.numRecentEvents);
|
|
12666
12691
|
}
|
|
12667
12692
|
const storageEvents = await eventQuery.execute();
|
|
12668
12693
|
const appState = await trx.selectFrom("app_states").selectAll().where("app_name", "=", appName).executeTakeFirst();
|
|
12669
12694
|
const userState = await trx.selectFrom("user_states").selectAll().where("app_name", "=", appName).where("user_id", "=", userId).executeTakeFirst();
|
|
12670
|
-
const currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess',
|
|
12671
|
-
const currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess',
|
|
12695
|
+
const currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _341 => _341.state]), {});
|
|
12696
|
+
const currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _342 => _342.state]), {});
|
|
12672
12697
|
const sessionState = this.parseJsonSafely(storageSession.state, {});
|
|
12673
12698
|
const mergedState = this.mergeState(
|
|
12674
12699
|
currentAppState,
|
|
@@ -12726,13 +12751,13 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
|
|
|
12726
12751
|
}
|
|
12727
12752
|
const appState = await trx.selectFrom("app_states").selectAll().where("app_name", "=", session.appName).executeTakeFirst();
|
|
12728
12753
|
const userState = await trx.selectFrom("user_states").selectAll().where("app_name", "=", session.appName).where("user_id", "=", session.userId).executeTakeFirst();
|
|
12729
|
-
let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess',
|
|
12730
|
-
let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess',
|
|
12754
|
+
let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _343 => _343.state]), {});
|
|
12755
|
+
let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _344 => _344.state]), {});
|
|
12731
12756
|
let sessionState = this.parseJsonSafely(storageSession.state, {});
|
|
12732
12757
|
let appStateDelta = {};
|
|
12733
12758
|
let userStateDelta = {};
|
|
12734
12759
|
let sessionStateDelta = {};
|
|
12735
|
-
if (_optionalChain([event, 'access',
|
|
12760
|
+
if (_optionalChain([event, 'access', _345 => _345.actions, 'optionalAccess', _346 => _346.stateDelta])) {
|
|
12736
12761
|
const deltas = this.extractStateDelta(event.actions.stateDelta);
|
|
12737
12762
|
appStateDelta = deltas.appStateDelta;
|
|
12738
12763
|
userStateDelta = deltas.userStateDelta;
|
|
@@ -12878,7 +12903,7 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
|
|
|
12878
12903
|
* Overrides the base class method to work with plain object state.
|
|
12879
12904
|
*/
|
|
12880
12905
|
updateSessionState(session, event) {
|
|
12881
|
-
if (!_optionalChain([event, 'access',
|
|
12906
|
+
if (!_optionalChain([event, 'access', _347 => _347.actions, 'optionalAccess', _348 => _348.stateDelta])) {
|
|
12882
12907
|
return;
|
|
12883
12908
|
}
|
|
12884
12909
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
@@ -13048,7 +13073,7 @@ var GcsArtifactService = class {
|
|
|
13048
13073
|
};
|
|
13049
13074
|
return part;
|
|
13050
13075
|
} catch (error) {
|
|
13051
|
-
if (_optionalChain([error, 'optionalAccess',
|
|
13076
|
+
if (_optionalChain([error, 'optionalAccess', _349 => _349.code]) === 404) {
|
|
13052
13077
|
return null;
|
|
13053
13078
|
}
|
|
13054
13079
|
throw error;
|
|
@@ -13299,13 +13324,13 @@ var VertexAiEvalFacade = class _VertexAiEvalFacade {
|
|
|
13299
13324
|
};
|
|
13300
13325
|
}
|
|
13301
13326
|
_getText(content) {
|
|
13302
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
13327
|
+
if (_optionalChain([content, 'optionalAccess', _350 => _350.parts])) {
|
|
13303
13328
|
return content.parts.map((p) => p.text || "").filter((text) => text.length > 0).join("\n");
|
|
13304
13329
|
}
|
|
13305
13330
|
return "";
|
|
13306
13331
|
}
|
|
13307
13332
|
_getScore(evalResult) {
|
|
13308
|
-
if (_optionalChain([evalResult, 'optionalAccess',
|
|
13333
|
+
if (_optionalChain([evalResult, 'optionalAccess', _351 => _351.summaryMetrics, 'optionalAccess', _352 => _352[0], 'optionalAccess', _353 => _353.meanScore]) !== void 0 && typeof evalResult.summaryMetrics[0].meanScore === "number" && !Number.isNaN(evalResult.summaryMetrics[0].meanScore)) {
|
|
13309
13334
|
return evalResult.summaryMetrics[0].meanScore;
|
|
13310
13335
|
}
|
|
13311
13336
|
return void 0;
|
|
@@ -13455,7 +13480,7 @@ var ResponseEvaluator = class extends Evaluator {
|
|
|
13455
13480
|
return fmeasure;
|
|
13456
13481
|
}
|
|
13457
13482
|
extractText(content) {
|
|
13458
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
13483
|
+
if (_optionalChain([content, 'optionalAccess', _354 => _354.parts])) {
|
|
13459
13484
|
return content.parts.map((p) => p.text || "").filter((text) => text.length > 0).join(" ");
|
|
13460
13485
|
}
|
|
13461
13486
|
return "";
|
|
@@ -13488,7 +13513,7 @@ var TrajectoryEvaluator = class extends Evaluator {
|
|
|
13488
13513
|
for (let i = 0; i < actualInvocations.length; i++) {
|
|
13489
13514
|
const actual = actualInvocations[i];
|
|
13490
13515
|
const expected = expectedInvocations[i];
|
|
13491
|
-
if (!_optionalChain([actual, 'access',
|
|
13516
|
+
if (!_optionalChain([actual, 'access', _355 => _355.intermediateData, 'optionalAccess', _356 => _356.toolUses]) || !_optionalChain([expected, 'access', _357 => _357.intermediateData, 'optionalAccess', _358 => _358.toolUses])) {
|
|
13492
13517
|
perInvocationResults.push({
|
|
13493
13518
|
actualInvocation: actual,
|
|
13494
13519
|
expectedInvocation: expected,
|
|
@@ -13576,7 +13601,7 @@ var SafetyEvaluatorV1 = class extends Evaluator {
|
|
|
13576
13601
|
|
|
13577
13602
|
// src/evaluation/llm-as-judge-utils.ts
|
|
13578
13603
|
function getTextFromContent(content) {
|
|
13579
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
13604
|
+
if (_optionalChain([content, 'optionalAccess', _359 => _359.parts])) {
|
|
13580
13605
|
return content.parts.map((part) => part.text).filter(Boolean).join("\n");
|
|
13581
13606
|
}
|
|
13582
13607
|
return "";
|
|
@@ -13588,9 +13613,9 @@ function getEvalStatus(score, threshold) {
|
|
|
13588
13613
|
// src/evaluation/llm-as-judge.ts
|
|
13589
13614
|
var LlmAsJudge = class {
|
|
13590
13615
|
async sampleJudge(prompt, numSamples, critiqueParser, judgeModelOptions) {
|
|
13591
|
-
const modelName = _optionalChain([judgeModelOptions, 'optionalAccess',
|
|
13616
|
+
const modelName = _optionalChain([judgeModelOptions, 'optionalAccess', _360 => _360.judgeModel]) || "gemini-2.5-flash";
|
|
13592
13617
|
const model = LLMRegistry.getModelOrCreate(modelName);
|
|
13593
|
-
const config = _optionalChain([judgeModelOptions, 'optionalAccess',
|
|
13618
|
+
const config = _optionalChain([judgeModelOptions, 'optionalAccess', _361 => _361.judgeModelConfig]) || {};
|
|
13594
13619
|
const samples = [];
|
|
13595
13620
|
for (let i = 0; i < numSamples; i++) {
|
|
13596
13621
|
try {
|
|
@@ -13656,7 +13681,7 @@ function parseCritique(response) {
|
|
|
13656
13681
|
const labelMatchIsResponseValid = response.match(
|
|
13657
13682
|
/"is_the_agent_response_valid":\s*\[*[\n\s]*"*([^"^\]^\s]*)"*[\n\s]*\]*\s*[,\n\}]/
|
|
13658
13683
|
);
|
|
13659
|
-
if (_optionalChain([labelMatchIsResponseValid, 'optionalAccess',
|
|
13684
|
+
if (_optionalChain([labelMatchIsResponseValid, 'optionalAccess', _362 => _362[1]])) {
|
|
13660
13685
|
const label = labelMatchIsResponseValid[1].toLowerCase();
|
|
13661
13686
|
return label === "valid" ? "valid" /* VALID */ : "invalid" /* INVALID */;
|
|
13662
13687
|
}
|
|
@@ -13701,7 +13726,7 @@ var FinalResponseMatchV2Evaluator = class extends Evaluator {
|
|
|
13701
13726
|
"{prompt}",
|
|
13702
13727
|
prompt
|
|
13703
13728
|
).replace("{response}", response).replace("{golden_response}", goldenResponse);
|
|
13704
|
-
const numSamples = _nullishCoalesce(_optionalChain([this, 'access',
|
|
13729
|
+
const numSamples = _nullishCoalesce(_optionalChain([this, 'access', _363 => _363.metric, 'access', _364 => _364.judgeModelOptions, 'optionalAccess', _365 => _365.numSamples]), () => ( DEFAULT_NUM_SAMPLES));
|
|
13705
13730
|
const labels = await this.llmAsJudge.sampleJudge(
|
|
13706
13731
|
formattedPrompt,
|
|
13707
13732
|
numSamples,
|
|
@@ -13741,7 +13766,7 @@ var MetricEvaluatorRegistry = (_class35 = class {constructor() { _class35.protot
|
|
|
13741
13766
|
const metricName = metricInfo.metricName;
|
|
13742
13767
|
if (this.registry.has(metricName)) {
|
|
13743
13768
|
console.info(
|
|
13744
|
-
`Updating Evaluator class for ${metricName} from ${_optionalChain([this, 'access',
|
|
13769
|
+
`Updating Evaluator class for ${metricName} from ${_optionalChain([this, 'access', _366 => _366.registry, 'access', _367 => _367.get, 'call', _368 => _368(metricName), 'optionalAccess', _369 => _369.evaluator, 'access', _370 => _370.name])} to ${evaluator.name}`
|
|
13745
13770
|
);
|
|
13746
13771
|
}
|
|
13747
13772
|
this.registry.set(metricName, {
|
|
@@ -13855,10 +13880,10 @@ var LocalEvalService = class extends BaseEvalService {
|
|
|
13855
13880
|
for (const evalMetric of evaluateConfig.evalMetrics) {
|
|
13856
13881
|
const evaluator = DEFAULT_METRIC_EVALUATOR_REGISTRY.getEvaluator(evalMetric);
|
|
13857
13882
|
const actual = results.filter(
|
|
13858
|
-
(r) => !_optionalChain([r, 'access',
|
|
13883
|
+
(r) => !_optionalChain([r, 'access', _371 => _371.invocationId, 'optionalAccess', _372 => _372.includes, 'call', _373 => _373("expected")])
|
|
13859
13884
|
);
|
|
13860
13885
|
const expected = results.filter(
|
|
13861
|
-
(r) => _optionalChain([r, 'access',
|
|
13886
|
+
(r) => _optionalChain([r, 'access', _374 => _374.invocationId, 'optionalAccess', _375 => _375.includes, 'call', _376 => _376("expected")])
|
|
13862
13887
|
);
|
|
13863
13888
|
const result = await evaluator.evaluateInvocations(actual, expected);
|
|
13864
13889
|
evalResult.evalCaseResults.push({
|
|
@@ -14250,13 +14275,13 @@ ${failures.join(
|
|
|
14250
14275
|
console.log("\n\n");
|
|
14251
14276
|
}
|
|
14252
14277
|
static _convertContentToText(content) {
|
|
14253
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
14278
|
+
if (_optionalChain([content, 'optionalAccess', _377 => _377.parts])) {
|
|
14254
14279
|
return content.parts.map((p) => p.text || "").filter((text) => text.length > 0).join("\n");
|
|
14255
14280
|
}
|
|
14256
14281
|
return "";
|
|
14257
14282
|
}
|
|
14258
14283
|
static _convertToolCallsToText(intermediateData) {
|
|
14259
|
-
if (_optionalChain([intermediateData, 'optionalAccess',
|
|
14284
|
+
if (_optionalChain([intermediateData, 'optionalAccess', _378 => _378.toolUses])) {
|
|
14260
14285
|
return intermediateData.toolUses.map((t) => JSON.stringify(t)).join("\n");
|
|
14261
14286
|
}
|
|
14262
14287
|
return "";
|
|
@@ -14311,7 +14336,7 @@ ${failures.join(
|
|
|
14311
14336
|
for (const [metricName, evalMetricResultsWithInvocations] of Object.entries(
|
|
14312
14337
|
evalMetricResults
|
|
14313
14338
|
)) {
|
|
14314
|
-
const threshold = _optionalChain([evalMetricResultsWithInvocations, 'access',
|
|
14339
|
+
const threshold = _optionalChain([evalMetricResultsWithInvocations, 'access', _379 => _379[0], 'optionalAccess', _380 => _380.evalMetricResult, 'access', _381 => _381.threshold]) || 0;
|
|
14315
14340
|
const scores = evalMetricResultsWithInvocations.map((m) => m.evalMetricResult.score).filter((s) => s !== void 0);
|
|
14316
14341
|
let overallScore;
|
|
14317
14342
|
let overallEvalStatus;
|
|
@@ -14400,7 +14425,7 @@ var RougeEvaluator = class extends Evaluator {
|
|
|
14400
14425
|
}
|
|
14401
14426
|
};
|
|
14402
14427
|
function getTextFromContent2(content) {
|
|
14403
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
14428
|
+
if (_optionalChain([content, 'optionalAccess', _382 => _382.parts])) {
|
|
14404
14429
|
return content.parts.map((part) => part.text).filter(Boolean).join("\n");
|
|
14405
14430
|
}
|
|
14406
14431
|
return "";
|