@iqai/adk 0.1.12 → 0.1.14
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 +21 -0
- package/dist/index.d.mts +2061 -2004
- package/dist/index.d.ts +2061 -2004
- package/dist/index.js +626 -427
- package/dist/index.mjs +467 -268
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13; var _class14; var _class15; var _class16; var _class17; var _class18; var _class19; var _class20; var _class21; var _class22; var _class23; var _class24; var _class25; var _class26; var _class27; var _class28; var _class29; var _class30; var _class31; var _class32;var __defProp = Object.defineProperty;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13; var _class14; var _class15; var _class16; var _class17; var _class18; var _class19; var _class20; var _class21; var _class22; var _class23; var _class24; var _class25; var _class26; var _class27; var _class28; var _class29; var _class30; var _class31; var _class32; var _class33;var __defProp = Object.defineProperty;
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
@@ -323,15 +323,17 @@ var init_base_tool = __esm({
|
|
|
323
323
|
if (!llmRequest.config || !llmRequest.config.tools) {
|
|
324
324
|
return null;
|
|
325
325
|
}
|
|
326
|
-
|
|
327
|
-
(tool) => tool.functionDeclarations && tool.functionDeclarations.length > 0
|
|
326
|
+
const toolWithFunctionDeclaration = llmRequest.config.tools.find(
|
|
327
|
+
(tool) => "functionDeclarations" in tool && tool.functionDeclarations && tool.functionDeclarations.length > 0
|
|
328
328
|
) || null;
|
|
329
|
+
return toolWithFunctionDeclaration;
|
|
329
330
|
}
|
|
330
331
|
}, _class2);
|
|
331
332
|
}
|
|
332
333
|
});
|
|
333
334
|
|
|
334
335
|
// src/tools/function/function-utils.ts
|
|
336
|
+
var _genai = require('@google/genai');
|
|
335
337
|
function buildFunctionDeclaration(func, options = {}) {
|
|
336
338
|
const funcStr = func.toString();
|
|
337
339
|
const name = options.name || func.name;
|
|
@@ -352,10 +354,10 @@ function buildFunctionDeclaration(func, options = {}) {
|
|
|
352
354
|
function extractParametersSchema(func, ignoreParams = []) {
|
|
353
355
|
const funcStr = func.toString();
|
|
354
356
|
const paramMatch = funcStr.match(/\(([^)]*)\)/);
|
|
355
|
-
if (!paramMatch) return { type:
|
|
357
|
+
if (!paramMatch) return { type: _genai.Type.OBJECT, properties: {} };
|
|
356
358
|
const paramList = paramMatch[1].split(",").map((param) => param.trim()).filter((param) => param !== "");
|
|
357
359
|
if (paramList.length === 0 || paramList.length === 1 && paramList[0] === "") {
|
|
358
|
-
return { type:
|
|
360
|
+
return { type: _genai.Type.OBJECT, properties: {} };
|
|
359
361
|
}
|
|
360
362
|
const jsDocParams = extractJSDocParams(funcStr);
|
|
361
363
|
const jsDocTypes = extractJSDocTypes(funcStr);
|
|
@@ -395,7 +397,7 @@ function extractParametersSchema(func, ignoreParams = []) {
|
|
|
395
397
|
}
|
|
396
398
|
}
|
|
397
399
|
const schema = {
|
|
398
|
-
type:
|
|
400
|
+
type: _genai.Type.OBJECT,
|
|
399
401
|
properties
|
|
400
402
|
};
|
|
401
403
|
if (required.length > 0) {
|
|
@@ -1364,7 +1366,7 @@ var BaseLLMConnection = class {
|
|
|
1364
1366
|
|
|
1365
1367
|
|
|
1366
1368
|
|
|
1367
|
-
|
|
1369
|
+
|
|
1368
1370
|
var AGENT_ENGINE_TELEMETRY_TAG = "remote_reasoning_engine";
|
|
1369
1371
|
var AGENT_ENGINE_TELEMETRY_ENV_VARIABLE_NAME = "GOOGLE_CLOUD_AGENT_ENGINE_ID";
|
|
1370
1372
|
var GoogleLlm = class extends BaseLlm {
|
|
@@ -1397,7 +1399,7 @@ var GoogleLlm = class extends BaseLlm {
|
|
|
1397
1399
|
this.preprocessRequest(llmRequest);
|
|
1398
1400
|
const model = llmRequest.model || this.model;
|
|
1399
1401
|
const contents = this.convertContents(llmRequest.contents || []);
|
|
1400
|
-
const config =
|
|
1402
|
+
const config = llmRequest.config;
|
|
1401
1403
|
if (stream) {
|
|
1402
1404
|
const responses = await this.apiClient.models.generateContentStream({
|
|
1403
1405
|
model,
|
|
@@ -1491,19 +1493,6 @@ var GoogleLlm = class extends BaseLlm {
|
|
|
1491
1493
|
parts: content.parts || [{ text: content.content || "" }]
|
|
1492
1494
|
}));
|
|
1493
1495
|
}
|
|
1494
|
-
/**
|
|
1495
|
-
* Convert LlmRequest config to GoogleGenAI format
|
|
1496
|
-
*/
|
|
1497
|
-
convertConfig(config) {
|
|
1498
|
-
if (!config) return {};
|
|
1499
|
-
return {
|
|
1500
|
-
temperature: config.temperature,
|
|
1501
|
-
topP: config.top_p,
|
|
1502
|
-
maxOutputTokens: config.max_tokens,
|
|
1503
|
-
tools: config.tools,
|
|
1504
|
-
systemInstruction: config.system_instruction
|
|
1505
|
-
};
|
|
1506
|
-
}
|
|
1507
1496
|
/**
|
|
1508
1497
|
* Preprocesses the request based on the API backend.
|
|
1509
1498
|
*/
|
|
@@ -3295,7 +3284,7 @@ var CallbackContext = class extends ReadonlyContext {
|
|
|
3295
3284
|
constructor(invocationContext, options = {}) {
|
|
3296
3285
|
super(invocationContext);
|
|
3297
3286
|
this._eventActions = options.eventActions || new EventActions();
|
|
3298
|
-
this._state =
|
|
3287
|
+
this._state = State.create(
|
|
3299
3288
|
invocationContext.session.state,
|
|
3300
3289
|
this._eventActions.stateDelta
|
|
3301
3290
|
);
|
|
@@ -3821,6 +3810,7 @@ ${argsStr}
|
|
|
3821
3810
|
// src/tools/index.ts
|
|
3822
3811
|
var tools_exports = {};
|
|
3823
3812
|
__export(tools_exports, {
|
|
3813
|
+
AgentTool: () => AgentTool,
|
|
3824
3814
|
BaseTool: () => BaseTool,
|
|
3825
3815
|
ExitLoopTool: () => ExitLoopTool,
|
|
3826
3816
|
FileOperationsTool: () => FileOperationsTool,
|
|
@@ -3843,7 +3833,7 @@ __export(tools_exports, {
|
|
|
3843
3833
|
McpIqWiki: () => McpIqWiki,
|
|
3844
3834
|
McpMemory: () => McpMemory,
|
|
3845
3835
|
McpNearAgent: () => McpNearAgent,
|
|
3846
|
-
|
|
3836
|
+
McpNearIntents: () => McpNearIntents,
|
|
3847
3837
|
McpOdos: () => McpOdos,
|
|
3848
3838
|
McpSamplingHandler: () => McpSamplingHandler,
|
|
3849
3839
|
McpTelegram: () => McpTelegram,
|
|
@@ -3925,6 +3915,283 @@ function createTool(config) {
|
|
|
3925
3915
|
return new CreatedTool(config);
|
|
3926
3916
|
}
|
|
3927
3917
|
|
|
3918
|
+
// src/tools/common/agent-tool.ts
|
|
3919
|
+
init_logger();
|
|
3920
|
+
|
|
3921
|
+
|
|
3922
|
+
|
|
3923
|
+
// src/agents/invocation-context.ts
|
|
3924
|
+
var LlmCallsLimitExceededError = class extends Error {
|
|
3925
|
+
constructor(message) {
|
|
3926
|
+
super(message);
|
|
3927
|
+
this.name = "LlmCallsLimitExceededError";
|
|
3928
|
+
}
|
|
3929
|
+
};
|
|
3930
|
+
var InvocationCostManager = (_class13 = class {constructor() { _class13.prototype.__init22.call(this); }
|
|
3931
|
+
/**
|
|
3932
|
+
* A counter that keeps track of number of llm calls made.
|
|
3933
|
+
*/
|
|
3934
|
+
__init22() {this._numberOfLlmCalls = 0}
|
|
3935
|
+
/**
|
|
3936
|
+
* Increments _numberOfLlmCalls and enforces the limit.
|
|
3937
|
+
*/
|
|
3938
|
+
incrementAndEnforceLlmCallsLimit(runConfig) {
|
|
3939
|
+
this._numberOfLlmCalls += 1;
|
|
3940
|
+
if (runConfig && runConfig.maxLlmCalls > 0 && this._numberOfLlmCalls > runConfig.maxLlmCalls) {
|
|
3941
|
+
throw new LlmCallsLimitExceededError(
|
|
3942
|
+
`Max number of llm calls limit of \`${runConfig.maxLlmCalls}\` exceeded`
|
|
3943
|
+
);
|
|
3944
|
+
}
|
|
3945
|
+
}
|
|
3946
|
+
}, _class13);
|
|
3947
|
+
function newInvocationContextId() {
|
|
3948
|
+
return `e-${crypto.randomUUID()}`;
|
|
3949
|
+
}
|
|
3950
|
+
var InvocationContext = (_class14 = class _InvocationContext {
|
|
3951
|
+
|
|
3952
|
+
|
|
3953
|
+
|
|
3954
|
+
/**
|
|
3955
|
+
* The id of this invocation context. Readonly.
|
|
3956
|
+
*/
|
|
3957
|
+
|
|
3958
|
+
/**
|
|
3959
|
+
* The branch of the invocation context.
|
|
3960
|
+
*
|
|
3961
|
+
* The format is like agent_1.agent_2.agent_3, where agent_1 is the parent of
|
|
3962
|
+
* agent_2, and agent_2 is the parent of agent_3.
|
|
3963
|
+
*
|
|
3964
|
+
* Branch is used when multiple sub-agents shouldn't see their peer agents'
|
|
3965
|
+
* conversation history.
|
|
3966
|
+
*/
|
|
3967
|
+
|
|
3968
|
+
/**
|
|
3969
|
+
* The current agent of this invocation context. Readonly.
|
|
3970
|
+
*/
|
|
3971
|
+
|
|
3972
|
+
/**
|
|
3973
|
+
* The user content that started this invocation. Readonly.
|
|
3974
|
+
*/
|
|
3975
|
+
|
|
3976
|
+
/**
|
|
3977
|
+
* The current session of this invocation context. Readonly.
|
|
3978
|
+
*/
|
|
3979
|
+
|
|
3980
|
+
/**
|
|
3981
|
+
* Whether to end this invocation.
|
|
3982
|
+
*
|
|
3983
|
+
* Set to True in callbacks or tools to terminate this invocation.
|
|
3984
|
+
*/
|
|
3985
|
+
__init23() {this.endInvocation = false}
|
|
3986
|
+
/**
|
|
3987
|
+
* The queue to receive live requests.
|
|
3988
|
+
*/
|
|
3989
|
+
|
|
3990
|
+
/**
|
|
3991
|
+
* The running streaming tools of this invocation.
|
|
3992
|
+
*/
|
|
3993
|
+
|
|
3994
|
+
/**
|
|
3995
|
+
* Caches necessary, data audio or contents, that are needed by transcription.
|
|
3996
|
+
*/
|
|
3997
|
+
|
|
3998
|
+
/**
|
|
3999
|
+
* Configurations for live agents under this invocation.
|
|
4000
|
+
*/
|
|
4001
|
+
|
|
4002
|
+
/**
|
|
4003
|
+
* A container to keep track of different kinds of costs incurred as a part
|
|
4004
|
+
* of this invocation.
|
|
4005
|
+
*/
|
|
4006
|
+
__init24() {this._invocationCostManager = new InvocationCostManager()}
|
|
4007
|
+
/**
|
|
4008
|
+
* Constructor for InvocationContext
|
|
4009
|
+
*/
|
|
4010
|
+
constructor(options) {;_class14.prototype.__init23.call(this);_class14.prototype.__init24.call(this);
|
|
4011
|
+
this.artifactService = options.artifactService;
|
|
4012
|
+
this.sessionService = options.sessionService;
|
|
4013
|
+
this.memoryService = options.memoryService;
|
|
4014
|
+
this.invocationId = options.invocationId || newInvocationContextId();
|
|
4015
|
+
this.branch = options.branch;
|
|
4016
|
+
this.agent = options.agent;
|
|
4017
|
+
this.userContent = options.userContent;
|
|
4018
|
+
this.session = options.session;
|
|
4019
|
+
this.endInvocation = options.endInvocation || false;
|
|
4020
|
+
this.liveRequestQueue = options.liveRequestQueue;
|
|
4021
|
+
this.activeStreamingTools = options.activeStreamingTools;
|
|
4022
|
+
this.transcriptionCache = options.transcriptionCache;
|
|
4023
|
+
this.runConfig = options.runConfig;
|
|
4024
|
+
}
|
|
4025
|
+
/**
|
|
4026
|
+
* App name from the session
|
|
4027
|
+
*/
|
|
4028
|
+
get appName() {
|
|
4029
|
+
return this.session.appName;
|
|
4030
|
+
}
|
|
4031
|
+
/**
|
|
4032
|
+
* User ID from the session
|
|
4033
|
+
*/
|
|
4034
|
+
get userId() {
|
|
4035
|
+
return this.session.userId;
|
|
4036
|
+
}
|
|
4037
|
+
/**
|
|
4038
|
+
* Tracks number of llm calls made.
|
|
4039
|
+
*
|
|
4040
|
+
* @throws {LlmCallsLimitExceededError} If number of llm calls made exceed the set threshold.
|
|
4041
|
+
*/
|
|
4042
|
+
incrementLlmCallCount() {
|
|
4043
|
+
this._invocationCostManager.incrementAndEnforceLlmCallsLimit(
|
|
4044
|
+
this.runConfig
|
|
4045
|
+
);
|
|
4046
|
+
}
|
|
4047
|
+
/**
|
|
4048
|
+
* Creates a child invocation context for a sub-agent
|
|
4049
|
+
*/
|
|
4050
|
+
createChildContext(agent) {
|
|
4051
|
+
return new _InvocationContext({
|
|
4052
|
+
artifactService: this.artifactService,
|
|
4053
|
+
sessionService: this.sessionService,
|
|
4054
|
+
memoryService: this.memoryService,
|
|
4055
|
+
invocationId: this.invocationId,
|
|
4056
|
+
// Keep same invocation ID
|
|
4057
|
+
branch: this.branch ? `${this.branch}.${agent.name}` : agent.name,
|
|
4058
|
+
// Update branch
|
|
4059
|
+
agent,
|
|
4060
|
+
// Update to the new agent
|
|
4061
|
+
userContent: this.userContent,
|
|
4062
|
+
session: this.session,
|
|
4063
|
+
endInvocation: this.endInvocation,
|
|
4064
|
+
liveRequestQueue: this.liveRequestQueue,
|
|
4065
|
+
activeStreamingTools: this.activeStreamingTools,
|
|
4066
|
+
transcriptionCache: this.transcriptionCache,
|
|
4067
|
+
runConfig: this.runConfig
|
|
4068
|
+
});
|
|
4069
|
+
}
|
|
4070
|
+
}, _class14);
|
|
4071
|
+
|
|
4072
|
+
// src/tools/common/agent-tool.ts
|
|
4073
|
+
init_base_tool();
|
|
4074
|
+
function isLlmAgent(agent) {
|
|
4075
|
+
return true;
|
|
4076
|
+
}
|
|
4077
|
+
var AgentTool = (_class15 = class extends BaseTool {
|
|
4078
|
+
/**
|
|
4079
|
+
* The agent used by this tool
|
|
4080
|
+
*/
|
|
4081
|
+
|
|
4082
|
+
/**
|
|
4083
|
+
* The function declaration schema
|
|
4084
|
+
*/
|
|
4085
|
+
|
|
4086
|
+
/**
|
|
4087
|
+
* The key to store the tool output in the state
|
|
4088
|
+
*/
|
|
4089
|
+
|
|
4090
|
+
/**
|
|
4091
|
+
* Whether to skip summarization of the agent's response
|
|
4092
|
+
*/
|
|
4093
|
+
|
|
4094
|
+
__init25() {this.logger = new Logger({ name: "AgentTool" })}
|
|
4095
|
+
/**
|
|
4096
|
+
* Create a new agent tool
|
|
4097
|
+
*/
|
|
4098
|
+
constructor(config) {
|
|
4099
|
+
super({
|
|
4100
|
+
name: config.name,
|
|
4101
|
+
description: config.description || config.agent.description,
|
|
4102
|
+
isLongRunning: config.isLongRunning || false,
|
|
4103
|
+
shouldRetryOnFailure: config.shouldRetryOnFailure || false,
|
|
4104
|
+
maxRetryAttempts: config.maxRetryAttempts || 3
|
|
4105
|
+
});_class15.prototype.__init25.call(this);;
|
|
4106
|
+
this.agent = config.agent;
|
|
4107
|
+
this.functionDeclaration = config.functionDeclaration;
|
|
4108
|
+
this.outputKey = config.outputKey;
|
|
4109
|
+
this.skipSummarization = config.skipSummarization || false;
|
|
4110
|
+
}
|
|
4111
|
+
/**
|
|
4112
|
+
* Get the function declaration for the tool
|
|
4113
|
+
*/
|
|
4114
|
+
getDeclaration() {
|
|
4115
|
+
if (this.functionDeclaration) {
|
|
4116
|
+
return this.functionDeclaration;
|
|
4117
|
+
}
|
|
4118
|
+
const description = isLlmAgent(this.agent) ? typeof this.agent.instruction === "string" ? this.agent.instruction : this.description : this.description;
|
|
4119
|
+
return {
|
|
4120
|
+
name: this.name,
|
|
4121
|
+
description,
|
|
4122
|
+
parameters: {
|
|
4123
|
+
type: _genai.Type.OBJECT,
|
|
4124
|
+
properties: {
|
|
4125
|
+
input: {
|
|
4126
|
+
type: _genai.Type.STRING,
|
|
4127
|
+
description: "The input to provide to the agent"
|
|
4128
|
+
}
|
|
4129
|
+
},
|
|
4130
|
+
required: ["input"]
|
|
4131
|
+
}
|
|
4132
|
+
};
|
|
4133
|
+
}
|
|
4134
|
+
/**
|
|
4135
|
+
* Execute the tool by running the agent with the provided input
|
|
4136
|
+
*/
|
|
4137
|
+
async runAsync(params, context) {
|
|
4138
|
+
try {
|
|
4139
|
+
const input = params.input || Object.values(params)[0];
|
|
4140
|
+
if (!isLlmAgent(this.agent)) {
|
|
4141
|
+
throw new Error(
|
|
4142
|
+
`Agent ${this.name} does not support running as a tool`
|
|
4143
|
+
);
|
|
4144
|
+
}
|
|
4145
|
+
const parentInvocation = context._invocationContext;
|
|
4146
|
+
const childInvocationContext = new InvocationContext({
|
|
4147
|
+
invocationId: _uuid.v4.call(void 0, ),
|
|
4148
|
+
agent: this.agent,
|
|
4149
|
+
session: parentInvocation.session,
|
|
4150
|
+
artifactService: parentInvocation.artifactService,
|
|
4151
|
+
sessionService: parentInvocation.sessionService,
|
|
4152
|
+
memoryService: parentInvocation.memoryService,
|
|
4153
|
+
runConfig: parentInvocation.runConfig,
|
|
4154
|
+
userContent: {
|
|
4155
|
+
role: "user",
|
|
4156
|
+
parts: [{ text: String(input) }]
|
|
4157
|
+
},
|
|
4158
|
+
branch: parentInvocation.branch ? `${parentInvocation.branch}.${this.agent.name}` : this.agent.name
|
|
4159
|
+
});
|
|
4160
|
+
let lastEvent = null;
|
|
4161
|
+
for await (const event of this.agent.runAsync(childInvocationContext)) {
|
|
4162
|
+
if (!event.partial) {
|
|
4163
|
+
await childInvocationContext.sessionService.appendEvent(
|
|
4164
|
+
childInvocationContext.session,
|
|
4165
|
+
event
|
|
4166
|
+
);
|
|
4167
|
+
}
|
|
4168
|
+
if (event.content && event.author === this.agent.name) {
|
|
4169
|
+
lastEvent = event;
|
|
4170
|
+
}
|
|
4171
|
+
}
|
|
4172
|
+
if (!lastEvent || !lastEvent.content || !lastEvent.content.parts) {
|
|
4173
|
+
return "";
|
|
4174
|
+
}
|
|
4175
|
+
const mergedText = lastEvent.content.parts.filter((part) => part.text !== void 0 && part.text !== null).map((part) => part.text).join("\n");
|
|
4176
|
+
let toolResult;
|
|
4177
|
+
try {
|
|
4178
|
+
toolResult = JSON.parse(mergedText);
|
|
4179
|
+
} catch (e2) {
|
|
4180
|
+
toolResult = mergedText;
|
|
4181
|
+
}
|
|
4182
|
+
if (this.outputKey && _optionalChain([context, 'optionalAccess', _144 => _144.state])) {
|
|
4183
|
+
context.state[this.outputKey] = toolResult;
|
|
4184
|
+
}
|
|
4185
|
+
return toolResult;
|
|
4186
|
+
} catch (error) {
|
|
4187
|
+
this.logger.error(`Error executing agent tool ${this.name}:`, error);
|
|
4188
|
+
throw new Error(
|
|
4189
|
+
`Agent tool execution failed: ${error instanceof Error ? error.message : String(error)}`
|
|
4190
|
+
);
|
|
4191
|
+
}
|
|
4192
|
+
}
|
|
4193
|
+
}, _class15);
|
|
4194
|
+
|
|
3928
4195
|
// src/tools/tool-context.ts
|
|
3929
4196
|
var ToolContext = class extends CallbackContext {
|
|
3930
4197
|
/**
|
|
@@ -3992,8 +4259,9 @@ init_function_utils();
|
|
|
3992
4259
|
// src/tools/common/google-search.ts
|
|
3993
4260
|
init_logger();
|
|
3994
4261
|
init_base_tool();
|
|
3995
|
-
|
|
3996
|
-
|
|
4262
|
+
|
|
4263
|
+
var GoogleSearch = (_class16 = class extends BaseTool {
|
|
4264
|
+
__init26() {this.logger = new Logger({ name: "GoogleSearch" })}
|
|
3997
4265
|
/**
|
|
3998
4266
|
* Constructor for GoogleSearch
|
|
3999
4267
|
*/
|
|
@@ -4001,7 +4269,7 @@ var GoogleSearch = (_class13 = class extends BaseTool {
|
|
|
4001
4269
|
super({
|
|
4002
4270
|
name: "google_search",
|
|
4003
4271
|
description: "Search the web using Google"
|
|
4004
|
-
});
|
|
4272
|
+
});_class16.prototype.__init26.call(this);;
|
|
4005
4273
|
}
|
|
4006
4274
|
/**
|
|
4007
4275
|
* Get the function declaration for the tool
|
|
@@ -4011,14 +4279,14 @@ var GoogleSearch = (_class13 = class extends BaseTool {
|
|
|
4011
4279
|
name: this.name,
|
|
4012
4280
|
description: this.description,
|
|
4013
4281
|
parameters: {
|
|
4014
|
-
type:
|
|
4282
|
+
type: _genai.Type.OBJECT,
|
|
4015
4283
|
properties: {
|
|
4016
4284
|
query: {
|
|
4017
|
-
type:
|
|
4285
|
+
type: _genai.Type.STRING,
|
|
4018
4286
|
description: "The search query to execute"
|
|
4019
4287
|
},
|
|
4020
4288
|
num_results: {
|
|
4021
|
-
type:
|
|
4289
|
+
type: _genai.Type.INTEGER,
|
|
4022
4290
|
description: "Number of results to return (max 10)",
|
|
4023
4291
|
default: 5
|
|
4024
4292
|
}
|
|
@@ -4050,10 +4318,11 @@ var GoogleSearch = (_class13 = class extends BaseTool {
|
|
|
4050
4318
|
]
|
|
4051
4319
|
};
|
|
4052
4320
|
}
|
|
4053
|
-
},
|
|
4321
|
+
}, _class16);
|
|
4054
4322
|
|
|
4055
4323
|
// src/tools/common/http-request-tool.ts
|
|
4056
4324
|
init_base_tool();
|
|
4325
|
+
|
|
4057
4326
|
var HttpRequestTool = class extends BaseTool {
|
|
4058
4327
|
constructor() {
|
|
4059
4328
|
super({
|
|
@@ -4069,38 +4338,32 @@ var HttpRequestTool = class extends BaseTool {
|
|
|
4069
4338
|
name: this.name,
|
|
4070
4339
|
description: this.description,
|
|
4071
4340
|
parameters: {
|
|
4072
|
-
type:
|
|
4341
|
+
type: _genai.Type.OBJECT,
|
|
4073
4342
|
properties: {
|
|
4074
4343
|
url: {
|
|
4075
|
-
type:
|
|
4344
|
+
type: _genai.Type.STRING,
|
|
4076
4345
|
description: "The URL to send the request to"
|
|
4077
4346
|
},
|
|
4078
4347
|
method: {
|
|
4079
|
-
type:
|
|
4348
|
+
type: _genai.Type.STRING,
|
|
4080
4349
|
description: "The HTTP method to use (GET, POST, PUT, DELETE, etc.)",
|
|
4081
4350
|
enum: ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"],
|
|
4082
4351
|
default: "GET"
|
|
4083
4352
|
},
|
|
4084
4353
|
headers: {
|
|
4085
|
-
type:
|
|
4086
|
-
description: "Request headers to include"
|
|
4087
|
-
additionalProperties: {
|
|
4088
|
-
type: "string"
|
|
4089
|
-
}
|
|
4354
|
+
type: _genai.Type.OBJECT,
|
|
4355
|
+
description: "Request headers to include"
|
|
4090
4356
|
},
|
|
4091
4357
|
body: {
|
|
4092
|
-
type:
|
|
4358
|
+
type: _genai.Type.STRING,
|
|
4093
4359
|
description: "Request body content (as string, typically JSON)"
|
|
4094
4360
|
},
|
|
4095
4361
|
params: {
|
|
4096
|
-
type:
|
|
4097
|
-
description: "URL query parameters to include"
|
|
4098
|
-
additionalProperties: {
|
|
4099
|
-
type: "string"
|
|
4100
|
-
}
|
|
4362
|
+
type: _genai.Type.OBJECT,
|
|
4363
|
+
description: "URL query parameters to include"
|
|
4101
4364
|
},
|
|
4102
4365
|
timeout: {
|
|
4103
|
-
type:
|
|
4366
|
+
type: _genai.Type.INTEGER,
|
|
4104
4367
|
description: "Request timeout in milliseconds",
|
|
4105
4368
|
default: 1e4
|
|
4106
4369
|
}
|
|
@@ -4175,6 +4438,7 @@ var HttpRequestTool = class extends BaseTool {
|
|
|
4175
4438
|
init_base_tool();
|
|
4176
4439
|
var _promises = require('fs/promises'); var _promises2 = _interopRequireDefault(_promises);
|
|
4177
4440
|
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
4441
|
+
|
|
4178
4442
|
var FileOperationsTool = class extends BaseTool {
|
|
4179
4443
|
|
|
4180
4444
|
constructor(options) {
|
|
@@ -4182,7 +4446,7 @@ var FileOperationsTool = class extends BaseTool {
|
|
|
4182
4446
|
name: "file_operations",
|
|
4183
4447
|
description: "Perform file system operations like reading, writing, and managing files"
|
|
4184
4448
|
});
|
|
4185
|
-
this.basePath = _optionalChain([options, 'optionalAccess',
|
|
4449
|
+
this.basePath = _optionalChain([options, 'optionalAccess', _145 => _145.basePath]) || process.cwd();
|
|
4186
4450
|
}
|
|
4187
4451
|
/**
|
|
4188
4452
|
* Get the function declaration for the tool
|
|
@@ -4192,10 +4456,10 @@ var FileOperationsTool = class extends BaseTool {
|
|
|
4192
4456
|
name: this.name,
|
|
4193
4457
|
description: this.description,
|
|
4194
4458
|
parameters: {
|
|
4195
|
-
type:
|
|
4459
|
+
type: _genai.Type.OBJECT,
|
|
4196
4460
|
properties: {
|
|
4197
4461
|
operation: {
|
|
4198
|
-
type:
|
|
4462
|
+
type: _genai.Type.STRING,
|
|
4199
4463
|
description: "The file operation to perform",
|
|
4200
4464
|
enum: [
|
|
4201
4465
|
"read",
|
|
@@ -4208,15 +4472,15 @@ var FileOperationsTool = class extends BaseTool {
|
|
|
4208
4472
|
]
|
|
4209
4473
|
},
|
|
4210
4474
|
filepath: {
|
|
4211
|
-
type:
|
|
4475
|
+
type: _genai.Type.STRING,
|
|
4212
4476
|
description: "Path to the file or directory (relative to the base path)"
|
|
4213
4477
|
},
|
|
4214
4478
|
content: {
|
|
4215
|
-
type:
|
|
4479
|
+
type: _genai.Type.STRING,
|
|
4216
4480
|
description: "Content to write to the file (for write and append operations)"
|
|
4217
4481
|
},
|
|
4218
4482
|
encoding: {
|
|
4219
|
-
type:
|
|
4483
|
+
type: _genai.Type.STRING,
|
|
4220
4484
|
description: "File encoding to use",
|
|
4221
4485
|
default: "utf8"
|
|
4222
4486
|
}
|
|
@@ -4363,7 +4627,7 @@ var FileOperationsTool = class extends BaseTool {
|
|
|
4363
4627
|
success: true,
|
|
4364
4628
|
data: true
|
|
4365
4629
|
};
|
|
4366
|
-
} catch (
|
|
4630
|
+
} catch (e3) {
|
|
4367
4631
|
return {
|
|
4368
4632
|
success: true,
|
|
4369
4633
|
data: false
|
|
@@ -4422,6 +4686,7 @@ var FileOperationsTool = class extends BaseTool {
|
|
|
4422
4686
|
|
|
4423
4687
|
// src/tools/common/user-interaction-tool.ts
|
|
4424
4688
|
init_base_tool();
|
|
4689
|
+
|
|
4425
4690
|
var UserInteractionTool = class extends BaseTool {
|
|
4426
4691
|
constructor() {
|
|
4427
4692
|
super({
|
|
@@ -4438,21 +4703,21 @@ var UserInteractionTool = class extends BaseTool {
|
|
|
4438
4703
|
name: this.name,
|
|
4439
4704
|
description: this.description,
|
|
4440
4705
|
parameters: {
|
|
4441
|
-
type:
|
|
4706
|
+
type: _genai.Type.OBJECT,
|
|
4442
4707
|
properties: {
|
|
4443
4708
|
prompt: {
|
|
4444
|
-
type:
|
|
4709
|
+
type: _genai.Type.STRING,
|
|
4445
4710
|
description: "The prompt message to display to the user"
|
|
4446
4711
|
},
|
|
4447
4712
|
options: {
|
|
4448
|
-
type:
|
|
4713
|
+
type: _genai.Type.ARRAY,
|
|
4449
4714
|
description: "Optional array of choices to present to the user",
|
|
4450
4715
|
items: {
|
|
4451
|
-
type:
|
|
4716
|
+
type: _genai.Type.STRING
|
|
4452
4717
|
}
|
|
4453
4718
|
},
|
|
4454
4719
|
defaultValue: {
|
|
4455
|
-
type:
|
|
4720
|
+
type: _genai.Type.STRING,
|
|
4456
4721
|
description: "Optional default value for the input field"
|
|
4457
4722
|
}
|
|
4458
4723
|
},
|
|
@@ -4499,8 +4764,8 @@ var UserInteractionTool = class extends BaseTool {
|
|
|
4499
4764
|
// src/tools/common/exit-loop-tool.ts
|
|
4500
4765
|
init_logger();
|
|
4501
4766
|
init_base_tool();
|
|
4502
|
-
var ExitLoopTool = (
|
|
4503
|
-
|
|
4767
|
+
var ExitLoopTool = (_class17 = class extends BaseTool {
|
|
4768
|
+
__init27() {this.logger = new Logger({ name: "ExitLoopTool" })}
|
|
4504
4769
|
/**
|
|
4505
4770
|
* Constructor for ExitLoopTool
|
|
4506
4771
|
*/
|
|
@@ -4508,7 +4773,7 @@ var ExitLoopTool = (_class14 = class extends BaseTool {
|
|
|
4508
4773
|
super({
|
|
4509
4774
|
name: "exit_loop",
|
|
4510
4775
|
description: "Exits the loop. Call this function only when you are instructed to do so."
|
|
4511
|
-
});
|
|
4776
|
+
});_class17.prototype.__init27.call(this);;
|
|
4512
4777
|
}
|
|
4513
4778
|
/**
|
|
4514
4779
|
* Execute the exit loop action
|
|
@@ -4517,13 +4782,14 @@ var ExitLoopTool = (_class14 = class extends BaseTool {
|
|
|
4517
4782
|
this.logger.debug("Executing exit loop tool");
|
|
4518
4783
|
context.actions.escalate = true;
|
|
4519
4784
|
}
|
|
4520
|
-
},
|
|
4785
|
+
}, _class17);
|
|
4521
4786
|
|
|
4522
4787
|
// src/tools/common/get-user-choice-tool.ts
|
|
4523
4788
|
init_logger();
|
|
4524
4789
|
init_base_tool();
|
|
4525
|
-
|
|
4526
|
-
|
|
4790
|
+
|
|
4791
|
+
var GetUserChoiceTool = (_class18 = class extends BaseTool {
|
|
4792
|
+
__init28() {this.logger = new Logger({ name: "GetUserChoiceTool" })}
|
|
4527
4793
|
/**
|
|
4528
4794
|
* Constructor for GetUserChoiceTool
|
|
4529
4795
|
*/
|
|
@@ -4532,7 +4798,7 @@ var GetUserChoiceTool = (_class15 = class extends BaseTool {
|
|
|
4532
4798
|
name: "get_user_choice",
|
|
4533
4799
|
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.",
|
|
4534
4800
|
isLongRunning: true
|
|
4535
|
-
});
|
|
4801
|
+
});_class18.prototype.__init28.call(this);;
|
|
4536
4802
|
}
|
|
4537
4803
|
/**
|
|
4538
4804
|
* Get the function declaration for the tool
|
|
@@ -4542,17 +4808,17 @@ var GetUserChoiceTool = (_class15 = class extends BaseTool {
|
|
|
4542
4808
|
name: this.name,
|
|
4543
4809
|
description: this.description,
|
|
4544
4810
|
parameters: {
|
|
4545
|
-
type:
|
|
4811
|
+
type: _genai.Type.OBJECT,
|
|
4546
4812
|
properties: {
|
|
4547
4813
|
options: {
|
|
4548
|
-
type:
|
|
4814
|
+
type: _genai.Type.ARRAY,
|
|
4549
4815
|
description: "List of options for the user to choose from",
|
|
4550
4816
|
items: {
|
|
4551
|
-
type:
|
|
4817
|
+
type: _genai.Type.STRING
|
|
4552
4818
|
}
|
|
4553
4819
|
},
|
|
4554
4820
|
question: {
|
|
4555
|
-
type:
|
|
4821
|
+
type: _genai.Type.STRING,
|
|
4556
4822
|
description: "The question or prompt to show the user before presenting options"
|
|
4557
4823
|
}
|
|
4558
4824
|
},
|
|
@@ -4575,13 +4841,13 @@ var GetUserChoiceTool = (_class15 = class extends BaseTool {
|
|
|
4575
4841
|
context.actions.skipSummarization = true;
|
|
4576
4842
|
return null;
|
|
4577
4843
|
}
|
|
4578
|
-
},
|
|
4844
|
+
}, _class18);
|
|
4579
4845
|
|
|
4580
4846
|
// src/tools/common/transfer-to-agent-tool.ts
|
|
4581
4847
|
init_logger();
|
|
4582
4848
|
init_base_tool();
|
|
4583
|
-
var TransferToAgentTool = (
|
|
4584
|
-
|
|
4849
|
+
var TransferToAgentTool = (_class19 = class extends BaseTool {
|
|
4850
|
+
__init29() {this.logger = new Logger({ name: "TransferToAgentTool" })}
|
|
4585
4851
|
/**
|
|
4586
4852
|
* Constructor for TransferToAgentTool
|
|
4587
4853
|
*/
|
|
@@ -4589,7 +4855,7 @@ var TransferToAgentTool = (_class16 = class extends BaseTool {
|
|
|
4589
4855
|
super({
|
|
4590
4856
|
name: "transfer_to_agent",
|
|
4591
4857
|
description: "Transfer the question to another agent."
|
|
4592
|
-
});
|
|
4858
|
+
});_class19.prototype.__init29.call(this);;
|
|
4593
4859
|
}
|
|
4594
4860
|
/**
|
|
4595
4861
|
* Execute the transfer to agent action
|
|
@@ -4598,13 +4864,14 @@ var TransferToAgentTool = (_class16 = class extends BaseTool {
|
|
|
4598
4864
|
this.logger.debug(`Executing transfer to agent: ${args.agent_name}`);
|
|
4599
4865
|
context.actions.transferToAgent = args.agent_name;
|
|
4600
4866
|
}
|
|
4601
|
-
},
|
|
4867
|
+
}, _class19);
|
|
4602
4868
|
|
|
4603
4869
|
// src/tools/common/load-memory-tool.ts
|
|
4604
4870
|
init_logger();
|
|
4605
4871
|
init_base_tool();
|
|
4606
|
-
|
|
4607
|
-
|
|
4872
|
+
|
|
4873
|
+
var LoadMemoryTool = (_class20 = class extends BaseTool {
|
|
4874
|
+
__init30() {this.logger = new Logger({ name: "LoadMemoryTool" })}
|
|
4608
4875
|
/**
|
|
4609
4876
|
* Constructor for LoadMemoryTool
|
|
4610
4877
|
*/
|
|
@@ -4612,7 +4879,7 @@ var LoadMemoryTool = (_class17 = class extends BaseTool {
|
|
|
4612
4879
|
super({
|
|
4613
4880
|
name: "load_memory",
|
|
4614
4881
|
description: "Loads the memory for the current user based on a query."
|
|
4615
|
-
});
|
|
4882
|
+
});_class20.prototype.__init30.call(this);;
|
|
4616
4883
|
}
|
|
4617
4884
|
/**
|
|
4618
4885
|
* Get the function declaration for the tool
|
|
@@ -4622,10 +4889,10 @@ var LoadMemoryTool = (_class17 = class extends BaseTool {
|
|
|
4622
4889
|
name: this.name,
|
|
4623
4890
|
description: this.description,
|
|
4624
4891
|
parameters: {
|
|
4625
|
-
type:
|
|
4892
|
+
type: _genai.Type.OBJECT,
|
|
4626
4893
|
properties: {
|
|
4627
4894
|
query: {
|
|
4628
|
-
type:
|
|
4895
|
+
type: _genai.Type.STRING,
|
|
4629
4896
|
description: "The query to load memories for"
|
|
4630
4897
|
}
|
|
4631
4898
|
},
|
|
@@ -4642,7 +4909,7 @@ var LoadMemoryTool = (_class17 = class extends BaseTool {
|
|
|
4642
4909
|
const searchResult = await context.searchMemory(args.query);
|
|
4643
4910
|
return {
|
|
4644
4911
|
memories: searchResult.memories || [],
|
|
4645
|
-
count: _optionalChain([searchResult, 'access',
|
|
4912
|
+
count: _optionalChain([searchResult, 'access', _146 => _146.memories, 'optionalAccess', _147 => _147.length]) || 0
|
|
4646
4913
|
};
|
|
4647
4914
|
} catch (error) {
|
|
4648
4915
|
console.error("Error searching memory:", error);
|
|
@@ -4652,10 +4919,11 @@ var LoadMemoryTool = (_class17 = class extends BaseTool {
|
|
|
4652
4919
|
};
|
|
4653
4920
|
}
|
|
4654
4921
|
}
|
|
4655
|
-
},
|
|
4922
|
+
}, _class20);
|
|
4656
4923
|
|
|
4657
4924
|
// src/tools/common/load-artifacts-tool.ts
|
|
4658
4925
|
init_base_tool();
|
|
4926
|
+
|
|
4659
4927
|
var LoadArtifactsTool = class extends BaseTool {
|
|
4660
4928
|
constructor() {
|
|
4661
4929
|
super({
|
|
@@ -4671,12 +4939,12 @@ var LoadArtifactsTool = class extends BaseTool {
|
|
|
4671
4939
|
name: this.name,
|
|
4672
4940
|
description: this.description,
|
|
4673
4941
|
parameters: {
|
|
4674
|
-
type:
|
|
4942
|
+
type: _genai.Type.OBJECT,
|
|
4675
4943
|
properties: {
|
|
4676
4944
|
artifact_names: {
|
|
4677
|
-
type:
|
|
4945
|
+
type: _genai.Type.ARRAY,
|
|
4678
4946
|
items: {
|
|
4679
|
-
type:
|
|
4947
|
+
type: _genai.Type.STRING
|
|
4680
4948
|
},
|
|
4681
4949
|
description: "List of artifact names to load"
|
|
4682
4950
|
}
|
|
@@ -4803,10 +5071,10 @@ var McpError = class extends Error {
|
|
|
4803
5071
|
};
|
|
4804
5072
|
|
|
4805
5073
|
// src/tools/mcp/sampling-handler.ts
|
|
4806
|
-
var McpSamplingHandler = (
|
|
4807
|
-
|
|
5074
|
+
var McpSamplingHandler = (_class21 = class {
|
|
5075
|
+
__init31() {this.logger = new Logger({ name: "McpSamplingHandler" })}
|
|
4808
5076
|
|
|
4809
|
-
constructor(samplingHandler) {;
|
|
5077
|
+
constructor(samplingHandler) {;_class21.prototype.__init31.call(this);
|
|
4810
5078
|
this.samplingHandler = samplingHandler;
|
|
4811
5079
|
}
|
|
4812
5080
|
/**
|
|
@@ -4991,7 +5259,7 @@ var McpSamplingHandler = (_class18 = class {
|
|
|
4991
5259
|
this.samplingHandler = handler;
|
|
4992
5260
|
this.logger.debug("ADK sampling handler updated");
|
|
4993
5261
|
}
|
|
4994
|
-
},
|
|
5262
|
+
}, _class21);
|
|
4995
5263
|
function createSamplingHandler(handler) {
|
|
4996
5264
|
return handler;
|
|
4997
5265
|
}
|
|
@@ -5025,14 +5293,14 @@ function withRetry(fn, instance, reinitMethod, maxRetries = 1) {
|
|
|
5025
5293
|
}
|
|
5026
5294
|
|
|
5027
5295
|
// src/tools/mcp/client.ts
|
|
5028
|
-
var McpClientService = (
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
constructor(config) {;
|
|
5296
|
+
var McpClientService = (_class22 = class {
|
|
5297
|
+
|
|
5298
|
+
__init32() {this.client = null}
|
|
5299
|
+
__init33() {this.transport = null}
|
|
5300
|
+
__init34() {this.isClosing = false}
|
|
5301
|
+
__init35() {this.mcpSamplingHandler = null}
|
|
5302
|
+
__init36() {this.logger = new Logger({ name: "McpClientService" })}
|
|
5303
|
+
constructor(config) {;_class22.prototype.__init32.call(this);_class22.prototype.__init33.call(this);_class22.prototype.__init34.call(this);_class22.prototype.__init35.call(this);_class22.prototype.__init36.call(this);
|
|
5036
5304
|
this.config = config;
|
|
5037
5305
|
if (config.samplingHandler) {
|
|
5038
5306
|
this.mcpSamplingHandler = new McpSamplingHandler(config.samplingHandler);
|
|
@@ -5198,7 +5466,7 @@ var McpClientService = (_class19 = class {
|
|
|
5198
5466
|
},
|
|
5199
5467
|
this,
|
|
5200
5468
|
async (instance) => await instance.reinitialize(),
|
|
5201
|
-
_optionalChain([this, 'access',
|
|
5469
|
+
_optionalChain([this, 'access', _148 => _148.config, 'access', _149 => _149.retryOptions, 'optionalAccess', _150 => _150.maxRetries]) || 2
|
|
5202
5470
|
);
|
|
5203
5471
|
return await wrappedCall();
|
|
5204
5472
|
} catch (error) {
|
|
@@ -5282,19 +5550,20 @@ var McpClientService = (_class19 = class {
|
|
|
5282
5550
|
this.mcpSamplingHandler = null;
|
|
5283
5551
|
if (this.client) {
|
|
5284
5552
|
try {
|
|
5285
|
-
_optionalChain([this, 'access',
|
|
5553
|
+
_optionalChain([this, 'access', _151 => _151.client, 'access', _152 => _152.removeRequestHandler, 'optionalCall', _153 => _153("sampling/createMessage")]);
|
|
5286
5554
|
} catch (error) {
|
|
5287
5555
|
this.logger.error("Failed to remove sampling handler:", error);
|
|
5288
5556
|
}
|
|
5289
5557
|
}
|
|
5290
5558
|
}
|
|
5291
|
-
},
|
|
5559
|
+
}, _class22);
|
|
5292
5560
|
|
|
5293
5561
|
// src/tools/mcp/create-tool.ts
|
|
5294
5562
|
init_logger();
|
|
5295
5563
|
init_base_tool();
|
|
5296
5564
|
|
|
5297
5565
|
// src/tools/mcp/schema-conversion.ts
|
|
5566
|
+
|
|
5298
5567
|
function adkToMcpToolType(tool) {
|
|
5299
5568
|
const declaration = tool.getDeclaration();
|
|
5300
5569
|
const params = declarationToJsonSchema(declaration);
|
|
@@ -5323,13 +5592,13 @@ function jsonSchemaToDeclaration(name, description, schema) {
|
|
|
5323
5592
|
parameters = schema;
|
|
5324
5593
|
} else {
|
|
5325
5594
|
parameters = {
|
|
5326
|
-
type:
|
|
5595
|
+
type: _genai.Type.OBJECT,
|
|
5327
5596
|
properties: schema
|
|
5328
5597
|
};
|
|
5329
5598
|
}
|
|
5330
5599
|
} else {
|
|
5331
5600
|
parameters = {
|
|
5332
|
-
type:
|
|
5601
|
+
type: _genai.Type.OBJECT,
|
|
5333
5602
|
properties: {}
|
|
5334
5603
|
};
|
|
5335
5604
|
}
|
|
@@ -5341,7 +5610,7 @@ function jsonSchemaToDeclaration(name, description, schema) {
|
|
|
5341
5610
|
}
|
|
5342
5611
|
function normalizeJsonSchema(schema) {
|
|
5343
5612
|
if (!schema) {
|
|
5344
|
-
return { type:
|
|
5613
|
+
return { type: _genai.Type.OBJECT, properties: {} };
|
|
5345
5614
|
}
|
|
5346
5615
|
const normalizedSchema = { ...schema };
|
|
5347
5616
|
if (!normalizedSchema.type) {
|
|
@@ -5358,39 +5627,39 @@ function normalizeJsonSchema(schema) {
|
|
|
5358
5627
|
case "integer":
|
|
5359
5628
|
return normalizeNumberSchema(normalizedSchema);
|
|
5360
5629
|
case "boolean":
|
|
5361
|
-
return { type:
|
|
5630
|
+
return { type: _genai.Type.BOOLEAN };
|
|
5362
5631
|
case "null":
|
|
5363
|
-
return { type:
|
|
5632
|
+
return { type: _genai.Type.NULL };
|
|
5364
5633
|
default:
|
|
5365
5634
|
return normalizedSchema;
|
|
5366
5635
|
}
|
|
5367
5636
|
}
|
|
5368
5637
|
function determineSchemaType(schema) {
|
|
5369
5638
|
if (schema.properties || schema.required || schema.additionalProperties !== void 0) {
|
|
5370
|
-
return
|
|
5639
|
+
return _genai.Type.OBJECT;
|
|
5371
5640
|
}
|
|
5372
5641
|
if (schema.items) {
|
|
5373
|
-
return
|
|
5642
|
+
return _genai.Type.ARRAY;
|
|
5374
5643
|
}
|
|
5375
5644
|
if (schema.enum !== void 0) {
|
|
5376
|
-
if (schema.enum.length === 0) return
|
|
5645
|
+
if (schema.enum.length === 0) return _genai.Type.STRING;
|
|
5377
5646
|
const firstItem = schema.enum[0];
|
|
5378
|
-
if (typeof firstItem === "string") return
|
|
5379
|
-
if (typeof firstItem === "number") return
|
|
5380
|
-
if (typeof firstItem === "boolean") return
|
|
5381
|
-
return
|
|
5647
|
+
if (typeof firstItem === "string") return _genai.Type.STRING;
|
|
5648
|
+
if (typeof firstItem === "number") return _genai.Type.NUMBER;
|
|
5649
|
+
if (typeof firstItem === "boolean") return _genai.Type.BOOLEAN;
|
|
5650
|
+
return _genai.Type.STRING;
|
|
5382
5651
|
}
|
|
5383
5652
|
if (schema.minLength !== void 0 || schema.maxLength !== void 0 || schema.pattern) {
|
|
5384
|
-
return
|
|
5653
|
+
return _genai.Type.STRING;
|
|
5385
5654
|
}
|
|
5386
5655
|
if (schema.minimum !== void 0 || schema.maximum !== void 0 || schema.exclusiveMinimum !== void 0 || schema.exclusiveMaximum !== void 0) {
|
|
5387
|
-
return schema.multipleOf === void 0 || schema.multipleOf % 1 === 0 ?
|
|
5656
|
+
return schema.multipleOf === void 0 || schema.multipleOf % 1 === 0 ? _genai.Type.INTEGER : _genai.Type.NUMBER;
|
|
5388
5657
|
}
|
|
5389
|
-
return
|
|
5658
|
+
return _genai.Type.OBJECT;
|
|
5390
5659
|
}
|
|
5391
5660
|
function normalizeObjectSchema(schema) {
|
|
5392
5661
|
const normalizedSchema = {
|
|
5393
|
-
type:
|
|
5662
|
+
type: _genai.Type.OBJECT,
|
|
5394
5663
|
properties: {}
|
|
5395
5664
|
};
|
|
5396
5665
|
if (schema.properties) {
|
|
@@ -5402,15 +5671,13 @@ function normalizeObjectSchema(schema) {
|
|
|
5402
5671
|
}
|
|
5403
5672
|
}
|
|
5404
5673
|
if (schema.required) normalizedSchema.required = schema.required;
|
|
5405
|
-
if (schema.additionalProperties !== void 0)
|
|
5406
|
-
normalizedSchema.additionalProperties = schema.additionalProperties;
|
|
5407
5674
|
if (schema.title) normalizedSchema.title = schema.title;
|
|
5408
5675
|
if (schema.description) normalizedSchema.description = schema.description;
|
|
5409
5676
|
return normalizedSchema;
|
|
5410
5677
|
}
|
|
5411
5678
|
function normalizeArraySchema(schema) {
|
|
5412
5679
|
const normalizedSchema = {
|
|
5413
|
-
type:
|
|
5680
|
+
type: _genai.Type.ARRAY
|
|
5414
5681
|
};
|
|
5415
5682
|
if (schema.items) {
|
|
5416
5683
|
normalizedSchema.items = normalizeJsonSchema(
|
|
@@ -5421,15 +5688,13 @@ function normalizeArraySchema(schema) {
|
|
|
5421
5688
|
normalizedSchema.minItems = schema.minItems;
|
|
5422
5689
|
if (schema.maxItems !== void 0)
|
|
5423
5690
|
normalizedSchema.maxItems = schema.maxItems;
|
|
5424
|
-
if (schema.uniqueItems !== void 0)
|
|
5425
|
-
normalizedSchema.uniqueItems = schema.uniqueItems;
|
|
5426
5691
|
if (schema.title) normalizedSchema.title = schema.title;
|
|
5427
5692
|
if (schema.description) normalizedSchema.description = schema.description;
|
|
5428
5693
|
return normalizedSchema;
|
|
5429
5694
|
}
|
|
5430
5695
|
function normalizeStringSchema(schema) {
|
|
5431
5696
|
const normalizedSchema = {
|
|
5432
|
-
type:
|
|
5697
|
+
type: _genai.Type.STRING
|
|
5433
5698
|
};
|
|
5434
5699
|
if (schema.minLength !== void 0)
|
|
5435
5700
|
normalizedSchema.minLength = schema.minLength;
|
|
@@ -5448,12 +5713,6 @@ function normalizeNumberSchema(schema) {
|
|
|
5448
5713
|
};
|
|
5449
5714
|
if (schema.minimum !== void 0) normalizedSchema.minimum = schema.minimum;
|
|
5450
5715
|
if (schema.maximum !== void 0) normalizedSchema.maximum = schema.maximum;
|
|
5451
|
-
if (schema.exclusiveMinimum !== void 0)
|
|
5452
|
-
normalizedSchema.exclusiveMinimum = schema.exclusiveMinimum;
|
|
5453
|
-
if (schema.exclusiveMaximum !== void 0)
|
|
5454
|
-
normalizedSchema.exclusiveMaximum = schema.exclusiveMaximum;
|
|
5455
|
-
if (schema.multipleOf !== void 0)
|
|
5456
|
-
normalizedSchema.multipleOf = schema.multipleOf;
|
|
5457
5716
|
if (schema.enum) normalizedSchema.enum = schema.enum;
|
|
5458
5717
|
if (schema.title) normalizedSchema.title = schema.title;
|
|
5459
5718
|
if (schema.description) normalizedSchema.description = schema.description;
|
|
@@ -5468,7 +5727,7 @@ function mcpSchemaToParameters(mcpTool) {
|
|
|
5468
5727
|
}
|
|
5469
5728
|
if (!schema) {
|
|
5470
5729
|
return {
|
|
5471
|
-
type:
|
|
5730
|
+
type: _genai.Type.OBJECT,
|
|
5472
5731
|
properties: {}
|
|
5473
5732
|
};
|
|
5474
5733
|
}
|
|
@@ -5490,11 +5749,11 @@ async function createTool2(mcpTool, client) {
|
|
|
5490
5749
|
throw error;
|
|
5491
5750
|
}
|
|
5492
5751
|
}
|
|
5493
|
-
var McpToolAdapter = (
|
|
5752
|
+
var McpToolAdapter = (_class23 = class extends BaseTool {
|
|
5494
5753
|
|
|
5495
5754
|
|
|
5496
|
-
|
|
5497
|
-
|
|
5755
|
+
__init37() {this.clientService = null}
|
|
5756
|
+
__init38() {this.logger = new Logger({ name: "McpToolAdapter" })}
|
|
5498
5757
|
constructor(mcpTool, client) {
|
|
5499
5758
|
const metadata = mcpTool.metadata || {};
|
|
5500
5759
|
super({
|
|
@@ -5503,7 +5762,7 @@ var McpToolAdapter = (_class20 = class extends BaseTool {
|
|
|
5503
5762
|
isLongRunning: _nullishCoalesce(metadata.isLongRunning, () => ( false)),
|
|
5504
5763
|
shouldRetryOnFailure: _nullishCoalesce(metadata.shouldRetryOnFailure, () => ( false)),
|
|
5505
5764
|
maxRetryAttempts: _nullishCoalesce(metadata.maxRetryAttempts, () => ( 3))
|
|
5506
|
-
});
|
|
5765
|
+
});_class23.prototype.__init37.call(this);_class23.prototype.__init38.call(this);;
|
|
5507
5766
|
this.mcpTool = mcpTool;
|
|
5508
5767
|
this.client = client;
|
|
5509
5768
|
if (client.reinitialize && typeof client.reinitialize === "function") {
|
|
@@ -5576,7 +5835,7 @@ var McpToolAdapter = (_class20 = class extends BaseTool {
|
|
|
5576
5835
|
throw error;
|
|
5577
5836
|
}
|
|
5578
5837
|
}
|
|
5579
|
-
},
|
|
5838
|
+
}, _class23);
|
|
5580
5839
|
|
|
5581
5840
|
// src/tools/mcp/servers.ts
|
|
5582
5841
|
function createMcpConfig(name, packageName, config = {}) {
|
|
@@ -5650,10 +5909,10 @@ function McpNearAgent(config = {}) {
|
|
|
5650
5909
|
);
|
|
5651
5910
|
return new McpToolset(mcpConfig);
|
|
5652
5911
|
}
|
|
5653
|
-
function
|
|
5912
|
+
function McpNearIntents(config = {}) {
|
|
5654
5913
|
const mcpConfig = createMcpConfig(
|
|
5655
5914
|
"Near Intents Swaps MCP Client",
|
|
5656
|
-
"@iqai/mcp-near-
|
|
5915
|
+
"@iqai/mcp-near-intents",
|
|
5657
5916
|
config
|
|
5658
5917
|
);
|
|
5659
5918
|
return new McpToolset(mcpConfig);
|
|
@@ -5713,13 +5972,13 @@ function McpGeneric(packageName, config = {}, name) {
|
|
|
5713
5972
|
}
|
|
5714
5973
|
|
|
5715
5974
|
// src/tools/mcp/index.ts
|
|
5716
|
-
var McpToolset = (
|
|
5975
|
+
var McpToolset = (_class24 = class {
|
|
5717
5976
|
|
|
5718
|
-
|
|
5719
|
-
|
|
5720
|
-
|
|
5721
|
-
|
|
5722
|
-
constructor(config, toolFilter = null) {;
|
|
5977
|
+
__init39() {this.clientService = null}
|
|
5978
|
+
__init40() {this.toolFilter = null}
|
|
5979
|
+
__init41() {this.tools = []}
|
|
5980
|
+
__init42() {this.isClosing = false}
|
|
5981
|
+
constructor(config, toolFilter = null) {;_class24.prototype.__init39.call(this);_class24.prototype.__init40.call(this);_class24.prototype.__init41.call(this);_class24.prototype.__init42.call(this);
|
|
5723
5982
|
this.config = config;
|
|
5724
5983
|
this.toolFilter = toolFilter;
|
|
5725
5984
|
this.clientService = new McpClientService(config);
|
|
@@ -5794,7 +6053,7 @@ var McpToolset = (_class21 = class {
|
|
|
5794
6053
|
"resource_closed_error" /* RESOURCE_CLOSED_ERROR */
|
|
5795
6054
|
);
|
|
5796
6055
|
}
|
|
5797
|
-
if (this.tools.length > 0 && !_optionalChain([this, 'access',
|
|
6056
|
+
if (this.tools.length > 0 && !_optionalChain([this, 'access', _154 => _154.config, 'access', _155 => _155.cacheConfig, 'optionalAccess', _156 => _156.enabled]) === false) {
|
|
5798
6057
|
return this.tools;
|
|
5799
6058
|
}
|
|
5800
6059
|
if (!this.clientService) {
|
|
@@ -5820,7 +6079,7 @@ var McpToolset = (_class21 = class {
|
|
|
5820
6079
|
}
|
|
5821
6080
|
}
|
|
5822
6081
|
}
|
|
5823
|
-
if (_optionalChain([this, 'access',
|
|
6082
|
+
if (_optionalChain([this, 'access', _157 => _157.config, 'access', _158 => _158.cacheConfig, 'optionalAccess', _159 => _159.enabled]) !== false) {
|
|
5824
6083
|
this.tools = tools;
|
|
5825
6084
|
}
|
|
5826
6085
|
return tools;
|
|
@@ -5880,7 +6139,7 @@ var McpToolset = (_class21 = class {
|
|
|
5880
6139
|
async dispose() {
|
|
5881
6140
|
await this.close();
|
|
5882
6141
|
}
|
|
5883
|
-
},
|
|
6142
|
+
}, _class24);
|
|
5884
6143
|
async function getMcpTools(config, toolFilter) {
|
|
5885
6144
|
const toolset = new McpToolset(config, toolFilter);
|
|
5886
6145
|
try {
|
|
@@ -5908,12 +6167,12 @@ function populateClientFunctionCallId(modelResponseEvent) {
|
|
|
5908
6167
|
}
|
|
5909
6168
|
}
|
|
5910
6169
|
function removeClientFunctionCallId(content) {
|
|
5911
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
6170
|
+
if (_optionalChain([content, 'optionalAccess', _160 => _160.parts])) {
|
|
5912
6171
|
for (const part of content.parts) {
|
|
5913
|
-
if (_optionalChain([part, 'access',
|
|
6172
|
+
if (_optionalChain([part, 'access', _161 => _161.functionCall, 'optionalAccess', _162 => _162.id, 'optionalAccess', _163 => _163.startsWith, 'call', _164 => _164(AF_FUNCTION_CALL_ID_PREFIX)])) {
|
|
5914
6173
|
part.functionCall.id = void 0;
|
|
5915
6174
|
}
|
|
5916
|
-
if (_optionalChain([part, 'access',
|
|
6175
|
+
if (_optionalChain([part, 'access', _165 => _165.functionResponse, 'optionalAccess', _166 => _166.id, 'optionalAccess', _167 => _167.startsWith, 'call', _168 => _168(AF_FUNCTION_CALL_ID_PREFIX)])) {
|
|
5917
6176
|
part.functionResponse.id = void 0;
|
|
5918
6177
|
}
|
|
5919
6178
|
}
|
|
@@ -5961,7 +6220,7 @@ function generateAuthEvent(invocationContext, functionResponseEvent) {
|
|
|
5961
6220
|
}
|
|
5962
6221
|
async function handleFunctionCallsAsync(invocationContext, functionCallEvent, toolsDict, filters) {
|
|
5963
6222
|
const agent = invocationContext.agent;
|
|
5964
|
-
if (!
|
|
6223
|
+
if (!isLlmAgent2(agent)) {
|
|
5965
6224
|
return null;
|
|
5966
6225
|
}
|
|
5967
6226
|
const functionCalls = functionCallEvent.getFunctionCalls();
|
|
@@ -6058,7 +6317,7 @@ function mergeParallelFunctionResponseEvents(functionResponseEvents) {
|
|
|
6058
6317
|
}
|
|
6059
6318
|
const mergedParts = [];
|
|
6060
6319
|
for (const event of functionResponseEvents) {
|
|
6061
|
-
if (_optionalChain([event, 'access',
|
|
6320
|
+
if (_optionalChain([event, 'access', _169 => _169.content, 'optionalAccess', _170 => _170.parts])) {
|
|
6062
6321
|
for (const part of event.content.parts) {
|
|
6063
6322
|
mergedParts.push(part);
|
|
6064
6323
|
}
|
|
@@ -6085,16 +6344,16 @@ function mergeParallelFunctionResponseEvents(functionResponseEvents) {
|
|
|
6085
6344
|
mergedEvent.timestamp = baseEvent.timestamp;
|
|
6086
6345
|
return mergedEvent;
|
|
6087
6346
|
}
|
|
6088
|
-
function
|
|
6347
|
+
function isLlmAgent2(agent) {
|
|
6089
6348
|
return agent && typeof agent === "object" && "canonicalModel" in agent;
|
|
6090
6349
|
}
|
|
6091
6350
|
|
|
6092
6351
|
// src/flows/llm-flows/base-llm-flow.ts
|
|
6093
6352
|
var _ADK_AGENT_NAME_LABEL_KEY = "adk_agent_name";
|
|
6094
|
-
var BaseLlmFlow = (
|
|
6095
|
-
|
|
6096
|
-
|
|
6097
|
-
|
|
6353
|
+
var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43.call(this);_class25.prototype.__init44.call(this);_class25.prototype.__init45.call(this); }
|
|
6354
|
+
__init43() {this.requestProcessors = []}
|
|
6355
|
+
__init44() {this.responseProcessors = []}
|
|
6356
|
+
__init45() {this.logger = new Logger({ name: "BaseLlmFlow" })}
|
|
6098
6357
|
async *runAsync(invocationContext) {
|
|
6099
6358
|
this.logger.info(`Agent '${invocationContext.agent.name}' started.`);
|
|
6100
6359
|
let stepCount = 0;
|
|
@@ -6186,7 +6445,7 @@ var BaseLlmFlow = (_class22 = class {constructor() { _class22.prototype.__init39
|
|
|
6186
6445
|
if (tools.length > 0) {
|
|
6187
6446
|
const toolsData = tools.map((tool) => ({
|
|
6188
6447
|
Name: tool.name,
|
|
6189
|
-
Description: _optionalChain([tool, 'access',
|
|
6448
|
+
Description: _optionalChain([tool, 'access', _171 => _171.description, 'optionalAccess', _172 => _172.substring, 'call', _173 => _173(0, 50)]) + (_optionalChain([tool, 'access', _174 => _174.description, 'optionalAccess', _175 => _175.length]) > 50 ? "..." : ""),
|
|
6190
6449
|
"Long Running": tool.isLongRunning ? "Yes" : "No"
|
|
6191
6450
|
}));
|
|
6192
6451
|
this.logger.debugArray("\u{1F6E0}\uFE0F Available Tools", toolsData);
|
|
@@ -6249,14 +6508,14 @@ var BaseLlmFlow = (_class22 = class {constructor() { _class22.prototype.__init39
|
|
|
6249
6508
|
);
|
|
6250
6509
|
if (functionResponseEvent) {
|
|
6251
6510
|
yield functionResponseEvent;
|
|
6252
|
-
const transferToAgent = _optionalChain([functionResponseEvent, 'access',
|
|
6511
|
+
const transferToAgent = _optionalChain([functionResponseEvent, 'access', _176 => _176.actions, 'optionalAccess', _177 => _177.transferToAgent]);
|
|
6253
6512
|
if (transferToAgent) {
|
|
6254
6513
|
this.logger.info(`\u{1F504} Live transfer to agent '${transferToAgent}'`);
|
|
6255
6514
|
const agentToRun = this._getAgentToRun(
|
|
6256
6515
|
invocationContext,
|
|
6257
6516
|
transferToAgent
|
|
6258
6517
|
);
|
|
6259
|
-
for await (const event of _optionalChain([agentToRun, 'access',
|
|
6518
|
+
for await (const event of _optionalChain([agentToRun, 'access', _178 => _178.runLive, 'optionalCall', _179 => _179(invocationContext)]) || agentToRun.runAsync(invocationContext)) {
|
|
6260
6519
|
yield event;
|
|
6261
6520
|
}
|
|
6262
6521
|
}
|
|
@@ -6288,7 +6547,7 @@ var BaseLlmFlow = (_class22 = class {constructor() { _class22.prototype.__init39
|
|
|
6288
6547
|
yield authEvent;
|
|
6289
6548
|
}
|
|
6290
6549
|
yield functionResponseEvent;
|
|
6291
|
-
const transferToAgent = _optionalChain([functionResponseEvent, 'access',
|
|
6550
|
+
const transferToAgent = _optionalChain([functionResponseEvent, 'access', _180 => _180.actions, 'optionalAccess', _181 => _181.transferToAgent]);
|
|
6292
6551
|
if (transferToAgent) {
|
|
6293
6552
|
this.logger.info(`\u{1F504} Transferring to agent '${transferToAgent}'`);
|
|
6294
6553
|
const agentToRun = this._getAgentToRun(
|
|
@@ -6334,27 +6593,27 @@ var BaseLlmFlow = (_class22 = class {constructor() { _class22.prototype.__init39
|
|
|
6334
6593
|
}
|
|
6335
6594
|
invocationContext.incrementLlmCallCount();
|
|
6336
6595
|
const isStreaming = invocationContext.runConfig.streamingMode === "sse" /* SSE */;
|
|
6337
|
-
const tools = _optionalChain([llmRequest, 'access',
|
|
6596
|
+
const tools = _optionalChain([llmRequest, 'access', _182 => _182.config, 'optionalAccess', _183 => _183.tools]) || [];
|
|
6338
6597
|
const toolNames = tools.map((tool) => {
|
|
6339
6598
|
if (tool.functionDeclarations && Array.isArray(tool.functionDeclarations)) {
|
|
6340
6599
|
return tool.functionDeclarations.map((fn) => fn.name).join(", ");
|
|
6341
6600
|
}
|
|
6342
6601
|
if (tool.name) return tool.name;
|
|
6343
|
-
if (_optionalChain([tool, 'access',
|
|
6344
|
-
if (_optionalChain([tool, 'access',
|
|
6602
|
+
if (_optionalChain([tool, 'access', _184 => _184.function, 'optionalAccess', _185 => _185.name])) return tool.function.name;
|
|
6603
|
+
if (_optionalChain([tool, 'access', _186 => _186.function, 'optionalAccess', _187 => _187.function, 'optionalAccess', _188 => _188.name])) return tool.function.function.name;
|
|
6345
6604
|
return "unknown";
|
|
6346
6605
|
}).join(", ");
|
|
6347
6606
|
const systemInstruction = llmRequest.getSystemInstructionText() || "";
|
|
6348
6607
|
const truncatedSystemInstruction = systemInstruction.length > 100 ? `${systemInstruction.substring(0, 100)}...` : systemInstruction;
|
|
6349
|
-
const contentPreview = _optionalChain([llmRequest, 'access',
|
|
6608
|
+
const contentPreview = _optionalChain([llmRequest, 'access', _189 => _189.contents, 'optionalAccess', _190 => _190.length]) > 0 ? LogFormatter.formatContentPreview(llmRequest.contents[0]) : "none";
|
|
6350
6609
|
this.logger.debugStructured("\u{1F4E4} LLM Request", {
|
|
6351
6610
|
Model: llm.model,
|
|
6352
6611
|
Agent: invocationContext.agent.name,
|
|
6353
|
-
"Content Items": _optionalChain([llmRequest, 'access',
|
|
6612
|
+
"Content Items": _optionalChain([llmRequest, 'access', _191 => _191.contents, 'optionalAccess', _192 => _192.length]) || 0,
|
|
6354
6613
|
"Content Preview": contentPreview,
|
|
6355
6614
|
"System Instruction": truncatedSystemInstruction || "none",
|
|
6356
6615
|
"Available Tools": toolNames || "none",
|
|
6357
|
-
"Tool Count": _optionalChain([llmRequest, 'access',
|
|
6616
|
+
"Tool Count": _optionalChain([llmRequest, 'access', _193 => _193.config, 'optionalAccess', _194 => _194.tools, 'optionalAccess', _195 => _195.length]) || 0,
|
|
6358
6617
|
Streaming: isStreaming ? "Yes" : "No"
|
|
6359
6618
|
});
|
|
6360
6619
|
let responseCount = 0;
|
|
@@ -6369,8 +6628,8 @@ var BaseLlmFlow = (_class22 = class {constructor() { _class22.prototype.__init39
|
|
|
6369
6628
|
llmRequest,
|
|
6370
6629
|
llmResponse
|
|
6371
6630
|
);
|
|
6372
|
-
const tokenCount = _optionalChain([llmResponse, 'access',
|
|
6373
|
-
const functionCalls = _optionalChain([llmResponse, 'access',
|
|
6631
|
+
const tokenCount = _optionalChain([llmResponse, 'access', _196 => _196.usageMetadata, 'optionalAccess', _197 => _197.totalTokenCount]) || "unknown";
|
|
6632
|
+
const functionCalls = _optionalChain([llmResponse, 'access', _198 => _198.content, 'optionalAccess', _199 => _199.parts, 'optionalAccess', _200 => _200.filter, 'call', _201 => _201((part) => part.functionCall)]) || [];
|
|
6374
6633
|
const functionCallsDisplay = LogFormatter.formatFunctionCalls(functionCalls);
|
|
6375
6634
|
const responsePreview = LogFormatter.formatResponsePreview(llmResponse);
|
|
6376
6635
|
this.logger.debugStructured("\u{1F4E5} LLM Response", {
|
|
@@ -6466,7 +6725,7 @@ var BaseLlmFlow = (_class22 = class {constructor() { _class22.prototype.__init39
|
|
|
6466
6725
|
const llm = invocationContext.agent.canonicalModel;
|
|
6467
6726
|
return llm;
|
|
6468
6727
|
}
|
|
6469
|
-
},
|
|
6728
|
+
}, _class25);
|
|
6470
6729
|
|
|
6471
6730
|
// src/flows/llm-flows/base-llm-processor.ts
|
|
6472
6731
|
var BaseLlmRequestProcessor = class {
|
|
@@ -6514,7 +6773,7 @@ var EnhancedAuthConfig = class {
|
|
|
6514
6773
|
*/
|
|
6515
6774
|
generateCredentialKey() {
|
|
6516
6775
|
const schemeKey = this.authScheme.type || "unknown";
|
|
6517
|
-
const credentialKey = _optionalChain([this, 'access',
|
|
6776
|
+
const credentialKey = _optionalChain([this, 'access', _202 => _202.rawAuthCredential, 'optionalAccess', _203 => _203.type]) || "none";
|
|
6518
6777
|
const timestamp = Date.now();
|
|
6519
6778
|
return `adk_${schemeKey}_${credentialKey}_${timestamp}`;
|
|
6520
6779
|
}
|
|
@@ -6671,7 +6930,7 @@ var AuthLlmRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
6671
6930
|
*/
|
|
6672
6931
|
parseAndStoreAuthResponse(authHandler, invocationContext) {
|
|
6673
6932
|
try {
|
|
6674
|
-
const credentialKey = _optionalChain([authHandler, 'access',
|
|
6933
|
+
const credentialKey = _optionalChain([authHandler, 'access', _204 => _204.authConfig, 'access', _205 => _205.context, 'optionalAccess', _206 => _206.credentialKey]) || `temp:${Date.now()}`;
|
|
6675
6934
|
const fullCredentialKey = credentialKey.startsWith("temp:") ? credentialKey : `temp:${credentialKey}`;
|
|
6676
6935
|
invocationContext.session.state[fullCredentialKey] = authHandler.credential;
|
|
6677
6936
|
if (authHandler.authConfig.authScheme.type === "oauth2" || authHandler.authConfig.authScheme.type === "openIdConnect") {
|
|
@@ -6779,7 +7038,7 @@ var BuiltInCodeExecutor = class extends BaseCodeExecutor {
|
|
|
6779
7038
|
* Pre-process the LLM request for Gemini 2.0+ models to use the code execution tool
|
|
6780
7039
|
*/
|
|
6781
7040
|
processLlmRequest(llmRequest) {
|
|
6782
|
-
if (!_optionalChain([llmRequest, 'access',
|
|
7041
|
+
if (!_optionalChain([llmRequest, 'access', _207 => _207.model, 'optionalAccess', _208 => _208.startsWith, 'call', _209 => _209("gemini-2")])) {
|
|
6783
7042
|
throw new Error(
|
|
6784
7043
|
`Gemini code execution tool is not supported for model ${llmRequest.model}`
|
|
6785
7044
|
);
|
|
@@ -6816,7 +7075,7 @@ var CodeExecutionUtils = class _CodeExecutionUtils {
|
|
|
6816
7075
|
static isBase64Encoded(str) {
|
|
6817
7076
|
try {
|
|
6818
7077
|
return btoa(atob(str)) === str;
|
|
6819
|
-
} catch (
|
|
7078
|
+
} catch (e4) {
|
|
6820
7079
|
return false;
|
|
6821
7080
|
}
|
|
6822
7081
|
}
|
|
@@ -6824,7 +7083,7 @@ var CodeExecutionUtils = class _CodeExecutionUtils {
|
|
|
6824
7083
|
* Extracts the first code block from the content and truncates everything after it
|
|
6825
7084
|
*/
|
|
6826
7085
|
static extractCodeAndTruncateContent(content, codeBlockDelimiters) {
|
|
6827
|
-
if (!_optionalChain([content, 'optionalAccess',
|
|
7086
|
+
if (!_optionalChain([content, 'optionalAccess', _210 => _210.parts, 'optionalAccess', _211 => _211.length])) {
|
|
6828
7087
|
return null;
|
|
6829
7088
|
}
|
|
6830
7089
|
for (let idx = 0; idx < content.parts.length; idx++) {
|
|
@@ -6910,7 +7169,7 @@ ${fileNames}`);
|
|
|
6910
7169
|
* Converts the code execution parts to text parts in a Content
|
|
6911
7170
|
*/
|
|
6912
7171
|
static convertCodeExecutionParts(content, codeBlockDelimiter, executionResultDelimiters) {
|
|
6913
|
-
if (!_optionalChain([content, 'access',
|
|
7172
|
+
if (!_optionalChain([content, 'access', _212 => _212.parts, 'optionalAccess', _213 => _213.length])) {
|
|
6914
7173
|
return;
|
|
6915
7174
|
}
|
|
6916
7175
|
const lastPart = content.parts[content.parts.length - 1];
|
|
@@ -7303,7 +7562,7 @@ async function* runPostProcessor(invocationContext, llmResponse) {
|
|
|
7303
7562
|
function extractAndReplaceInlineFiles(codeExecutorContext, llmRequest) {
|
|
7304
7563
|
const allInputFiles = codeExecutorContext.getInputFiles();
|
|
7305
7564
|
const savedFileNames = new Set(allInputFiles.map((f) => f.name));
|
|
7306
|
-
for (let i = 0; i < (_optionalChain([llmRequest, 'access',
|
|
7565
|
+
for (let i = 0; i < (_optionalChain([llmRequest, 'access', _214 => _214.contents, 'optionalAccess', _215 => _215.length]) || 0); i++) {
|
|
7307
7566
|
const content = llmRequest.contents[i];
|
|
7308
7567
|
if (content.role !== "user" || !content.parts) {
|
|
7309
7568
|
continue;
|
|
@@ -7335,7 +7594,7 @@ Available file: \`${fileName}\`
|
|
|
7335
7594
|
}
|
|
7336
7595
|
function getOrSetExecutionId(invocationContext, codeExecutorContext) {
|
|
7337
7596
|
const agent = invocationContext.agent;
|
|
7338
|
-
if (!hasCodeExecutor(agent) || !_optionalChain([agent, 'access',
|
|
7597
|
+
if (!hasCodeExecutor(agent) || !_optionalChain([agent, 'access', _216 => _216.codeExecutor, 'optionalAccess', _217 => _217.stateful])) {
|
|
7339
7598
|
return void 0;
|
|
7340
7599
|
}
|
|
7341
7600
|
let executionId = codeExecutorContext.getExecutionId();
|
|
@@ -7566,7 +7825,7 @@ function rearrangeEventsForLatestFunctionResponse(events) {
|
|
|
7566
7825
|
continue;
|
|
7567
7826
|
}
|
|
7568
7827
|
const functionResponses2 = event.getFunctionResponses();
|
|
7569
|
-
if (_optionalChain([functionResponses2, 'optionalAccess',
|
|
7828
|
+
if (_optionalChain([functionResponses2, 'optionalAccess', _218 => _218.some, 'call', _219 => _219((fr) => fr.id && functionResponsesIds.has(fr.id))])) {
|
|
7570
7829
|
functionResponseEvents.push(event);
|
|
7571
7830
|
}
|
|
7572
7831
|
}
|
|
@@ -7665,7 +7924,7 @@ function mergeFunctionResponseEvents(functionResponseEvents) {
|
|
|
7665
7924
|
const partIndicesInMergedEvent = {};
|
|
7666
7925
|
for (let idx = 0; idx < partsInMergedEvent.length; idx++) {
|
|
7667
7926
|
const part = partsInMergedEvent[idx];
|
|
7668
|
-
if (_optionalChain([part, 'access',
|
|
7927
|
+
if (_optionalChain([part, 'access', _220 => _220.functionResponse, 'optionalAccess', _221 => _221.id])) {
|
|
7669
7928
|
partIndicesInMergedEvent[part.functionResponse.id] = idx;
|
|
7670
7929
|
}
|
|
7671
7930
|
}
|
|
@@ -7674,7 +7933,7 @@ function mergeFunctionResponseEvents(functionResponseEvents) {
|
|
|
7674
7933
|
throw new Error("There should be at least one function_response part.");
|
|
7675
7934
|
}
|
|
7676
7935
|
for (const part of event.content.parts) {
|
|
7677
|
-
if (_optionalChain([part, 'access',
|
|
7936
|
+
if (_optionalChain([part, 'access', _222 => _222.functionResponse, 'optionalAccess', _223 => _223.id])) {
|
|
7678
7937
|
const functionCallId = part.functionResponse.id;
|
|
7679
7938
|
if (functionCallId in partIndicesInMergedEvent) {
|
|
7680
7939
|
partsInMergedEvent[partIndicesInMergedEvent[functionCallId]] = part;
|
|
@@ -7924,7 +8183,7 @@ var PlanReActPlanner = class extends BasePlanner {
|
|
|
7924
8183
|
let firstFcPartIndex = -1;
|
|
7925
8184
|
for (let i = 0; i < responseParts.length; i++) {
|
|
7926
8185
|
if (responseParts[i].functionCall) {
|
|
7927
|
-
if (!_optionalChain([responseParts, 'access',
|
|
8186
|
+
if (!_optionalChain([responseParts, 'access', _224 => _224[i], 'access', _225 => _225.functionCall, 'optionalAccess', _226 => _226.name])) {
|
|
7928
8187
|
continue;
|
|
7929
8188
|
}
|
|
7930
8189
|
preservedParts.push(responseParts[i]);
|
|
@@ -7963,7 +8222,7 @@ var PlanReActPlanner = class extends BasePlanner {
|
|
|
7963
8222
|
* Handles non-function-call parts of the response
|
|
7964
8223
|
*/
|
|
7965
8224
|
_handleNonFunctionCallParts(responsePart, preservedParts) {
|
|
7966
|
-
if (_optionalChain([responsePart, 'access',
|
|
8225
|
+
if (_optionalChain([responsePart, 'access', _227 => _227.text, 'optionalAccess', _228 => _228.includes, 'call', _229 => _229(FINAL_ANSWER_TAG)])) {
|
|
7967
8226
|
const [reasoningText, finalAnswerText] = this._splitByLastPattern(
|
|
7968
8227
|
responsePart.text,
|
|
7969
8228
|
FINAL_ANSWER_TAG
|
|
@@ -8133,6 +8392,42 @@ function removeThoughtFromRequest(llmRequest) {
|
|
|
8133
8392
|
var requestProcessor7 = new NlPlanningRequestProcessor();
|
|
8134
8393
|
var responseProcessor2 = new NlPlanningResponseProcessor();
|
|
8135
8394
|
|
|
8395
|
+
// src/flows/llm-flows/shared-memory.ts
|
|
8396
|
+
var SharedMemoryRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
8397
|
+
async *runAsync(invocationContext, llmRequest) {
|
|
8398
|
+
const memoryService = invocationContext.memoryService;
|
|
8399
|
+
if (!memoryService) return;
|
|
8400
|
+
const lastUserEvent = invocationContext.session.events.findLast((e) => e.author === "user" && _optionalChain([e, 'access', _230 => _230.content, 'optionalAccess', _231 => _231.parts, 'optionalAccess', _232 => _232.length]));
|
|
8401
|
+
if (!lastUserEvent) return;
|
|
8402
|
+
const query = (_nullishCoalesce(lastUserEvent.content.parts, () => ( []))).map((p) => p.text || "").join(" ");
|
|
8403
|
+
const results = await memoryService.searchMemory({
|
|
8404
|
+
appName: invocationContext.appName,
|
|
8405
|
+
userId: invocationContext.userId,
|
|
8406
|
+
query
|
|
8407
|
+
});
|
|
8408
|
+
const sessionTexts = new Set(
|
|
8409
|
+
(llmRequest.contents || []).flatMap(
|
|
8410
|
+
(c) => _optionalChain([c, 'access', _233 => _233.parts, 'optionalAccess', _234 => _234.map, 'call', _235 => _235((p) => p.text)]) || []
|
|
8411
|
+
)
|
|
8412
|
+
);
|
|
8413
|
+
for (const memory of results.memories) {
|
|
8414
|
+
const memoryText = (_nullishCoalesce(memory.content.parts, () => ( []))).map((p) => p.text || "").join(" ");
|
|
8415
|
+
if (!sessionTexts.has(memoryText)) {
|
|
8416
|
+
llmRequest.contents = llmRequest.contents || [];
|
|
8417
|
+
llmRequest.contents.push({
|
|
8418
|
+
role: "user",
|
|
8419
|
+
parts: [
|
|
8420
|
+
{
|
|
8421
|
+
text: `[${memory.author}] said: ${memoryText}`
|
|
8422
|
+
}
|
|
8423
|
+
]
|
|
8424
|
+
});
|
|
8425
|
+
}
|
|
8426
|
+
}
|
|
8427
|
+
}
|
|
8428
|
+
};
|
|
8429
|
+
var sharedMemoryRequestProcessor = new SharedMemoryRequestProcessor();
|
|
8430
|
+
|
|
8136
8431
|
// src/flows/llm-flows/single-flow.ts
|
|
8137
8432
|
var SingleFlow = class extends BaseLlmFlow {
|
|
8138
8433
|
/**
|
|
@@ -8147,6 +8442,7 @@ var SingleFlow = class extends BaseLlmFlow {
|
|
|
8147
8442
|
requestProcessor6,
|
|
8148
8443
|
requestProcessor5,
|
|
8149
8444
|
requestProcessor4,
|
|
8445
|
+
sharedMemoryRequestProcessor,
|
|
8150
8446
|
// Some implementations of NL Planning mark planning contents as thoughts
|
|
8151
8447
|
// in the post processor. Since these need to be unmarked, NL Planning
|
|
8152
8448
|
// should be after contents.
|
|
@@ -8187,14 +8483,7 @@ var AgentTransferLlmRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
8187
8483
|
agent,
|
|
8188
8484
|
transferTargets
|
|
8189
8485
|
);
|
|
8190
|
-
|
|
8191
|
-
llmRequest.appendInstructions([transferInstructions]);
|
|
8192
|
-
} else {
|
|
8193
|
-
const existingInstructions = llmRequest.instructions || "";
|
|
8194
|
-
llmRequest.instructions = `${existingInstructions}
|
|
8195
|
-
|
|
8196
|
-
${transferInstructions}`;
|
|
8197
|
-
}
|
|
8486
|
+
llmRequest.appendInstructions([transferInstructions]);
|
|
8198
8487
|
const transferToAgentTool = new TransferToAgentTool();
|
|
8199
8488
|
const toolContext = new ToolContext(invocationContext);
|
|
8200
8489
|
await transferToAgentTool.processLlmRequest(toolContext, llmRequest);
|
|
@@ -8269,7 +8558,7 @@ var AutoFlow = class extends SingleFlow {
|
|
|
8269
8558
|
|
|
8270
8559
|
// src/agents/llm-agent.ts
|
|
8271
8560
|
init_function_tool();
|
|
8272
|
-
var LlmAgent = (
|
|
8561
|
+
var LlmAgent = (_class26 = class _LlmAgent extends BaseAgent {
|
|
8273
8562
|
/**
|
|
8274
8563
|
* The model to use for the agent
|
|
8275
8564
|
* When not set, the agent will inherit the model from its ancestor
|
|
@@ -8346,7 +8635,7 @@ var LlmAgent = (_class23 = class _LlmAgent extends BaseAgent {
|
|
|
8346
8635
|
*/
|
|
8347
8636
|
|
|
8348
8637
|
// Schema type - depends on specific implementation
|
|
8349
|
-
|
|
8638
|
+
__init46() {this.logger = new Logger({ name: "LlmAgent" })}
|
|
8350
8639
|
/**
|
|
8351
8640
|
* Constructor for LlmAgent
|
|
8352
8641
|
*/
|
|
@@ -8354,7 +8643,7 @@ var LlmAgent = (_class23 = class _LlmAgent extends BaseAgent {
|
|
|
8354
8643
|
super({
|
|
8355
8644
|
name: config.name,
|
|
8356
8645
|
description: config.description
|
|
8357
|
-
});
|
|
8646
|
+
});_class26.prototype.__init46.call(this);;
|
|
8358
8647
|
this.model = config.model || "";
|
|
8359
8648
|
this.instruction = config.instruction || "";
|
|
8360
8649
|
this.globalInstruction = config.globalInstruction || "";
|
|
@@ -8440,7 +8729,7 @@ var LlmAgent = (_class23 = class _LlmAgent extends BaseAgent {
|
|
|
8440
8729
|
* This matches the Python implementation's _llm_flow property
|
|
8441
8730
|
*/
|
|
8442
8731
|
get llmFlow() {
|
|
8443
|
-
if (this.disallowTransferToParent && this.disallowTransferToPeers && !_optionalChain([this, 'access',
|
|
8732
|
+
if (this.disallowTransferToParent && this.disallowTransferToPeers && !_optionalChain([this, 'access', _236 => _236.subAgents, 'optionalAccess', _237 => _237.length])) {
|
|
8444
8733
|
return new SingleFlow();
|
|
8445
8734
|
}
|
|
8446
8735
|
return new AutoFlow();
|
|
@@ -8450,7 +8739,7 @@ var LlmAgent = (_class23 = class _LlmAgent extends BaseAgent {
|
|
|
8450
8739
|
* This matches the Python implementation's __maybe_save_output_to_state
|
|
8451
8740
|
*/
|
|
8452
8741
|
maybeSaveOutputToState(event) {
|
|
8453
|
-
if (this.outputKey && event.isFinalResponse() && _optionalChain([event, 'access',
|
|
8742
|
+
if (this.outputKey && event.isFinalResponse() && _optionalChain([event, 'access', _238 => _238.content, 'optionalAccess', _239 => _239.parts])) {
|
|
8454
8743
|
const result = event.content.parts.map((part) => part.text || "").join("");
|
|
8455
8744
|
if (result) {
|
|
8456
8745
|
if (!event.actions.stateDelta) {
|
|
@@ -8490,7 +8779,7 @@ var LlmAgent = (_class23 = class _LlmAgent extends BaseAgent {
|
|
|
8490
8779
|
yield errorEvent;
|
|
8491
8780
|
}
|
|
8492
8781
|
}
|
|
8493
|
-
},
|
|
8782
|
+
}, _class26);
|
|
8494
8783
|
|
|
8495
8784
|
// src/agents/sequential-agent.ts
|
|
8496
8785
|
var SequentialAgent = class extends BaseAgent {
|
|
@@ -8549,155 +8838,6 @@ do not generate any text other than the function call.`;
|
|
|
8549
8838
|
}
|
|
8550
8839
|
};
|
|
8551
8840
|
|
|
8552
|
-
// src/agents/invocation-context.ts
|
|
8553
|
-
var LlmCallsLimitExceededError = class extends Error {
|
|
8554
|
-
constructor(message) {
|
|
8555
|
-
super(message);
|
|
8556
|
-
this.name = "LlmCallsLimitExceededError";
|
|
8557
|
-
}
|
|
8558
|
-
};
|
|
8559
|
-
var InvocationCostManager = (_class24 = class {constructor() { _class24.prototype.__init43.call(this); }
|
|
8560
|
-
/**
|
|
8561
|
-
* A counter that keeps track of number of llm calls made.
|
|
8562
|
-
*/
|
|
8563
|
-
__init43() {this._numberOfLlmCalls = 0}
|
|
8564
|
-
/**
|
|
8565
|
-
* Increments _numberOfLlmCalls and enforces the limit.
|
|
8566
|
-
*/
|
|
8567
|
-
incrementAndEnforceLlmCallsLimit(runConfig) {
|
|
8568
|
-
this._numberOfLlmCalls += 1;
|
|
8569
|
-
if (runConfig && runConfig.maxLlmCalls > 0 && this._numberOfLlmCalls > runConfig.maxLlmCalls) {
|
|
8570
|
-
throw new LlmCallsLimitExceededError(
|
|
8571
|
-
`Max number of llm calls limit of \`${runConfig.maxLlmCalls}\` exceeded`
|
|
8572
|
-
);
|
|
8573
|
-
}
|
|
8574
|
-
}
|
|
8575
|
-
}, _class24);
|
|
8576
|
-
function newInvocationContextId() {
|
|
8577
|
-
return `e-${crypto.randomUUID()}`;
|
|
8578
|
-
}
|
|
8579
|
-
var InvocationContext = (_class25 = class _InvocationContext {
|
|
8580
|
-
|
|
8581
|
-
|
|
8582
|
-
|
|
8583
|
-
/**
|
|
8584
|
-
* The id of this invocation context. Readonly.
|
|
8585
|
-
*/
|
|
8586
|
-
|
|
8587
|
-
/**
|
|
8588
|
-
* The branch of the invocation context.
|
|
8589
|
-
*
|
|
8590
|
-
* The format is like agent_1.agent_2.agent_3, where agent_1 is the parent of
|
|
8591
|
-
* agent_2, and agent_2 is the parent of agent_3.
|
|
8592
|
-
*
|
|
8593
|
-
* Branch is used when multiple sub-agents shouldn't see their peer agents'
|
|
8594
|
-
* conversation history.
|
|
8595
|
-
*/
|
|
8596
|
-
|
|
8597
|
-
/**
|
|
8598
|
-
* The current agent of this invocation context. Readonly.
|
|
8599
|
-
*/
|
|
8600
|
-
|
|
8601
|
-
/**
|
|
8602
|
-
* The user content that started this invocation. Readonly.
|
|
8603
|
-
*/
|
|
8604
|
-
|
|
8605
|
-
/**
|
|
8606
|
-
* The current session of this invocation context. Readonly.
|
|
8607
|
-
*/
|
|
8608
|
-
|
|
8609
|
-
/**
|
|
8610
|
-
* Whether to end this invocation.
|
|
8611
|
-
*
|
|
8612
|
-
* Set to True in callbacks or tools to terminate this invocation.
|
|
8613
|
-
*/
|
|
8614
|
-
__init44() {this.endInvocation = false}
|
|
8615
|
-
/**
|
|
8616
|
-
* The queue to receive live requests.
|
|
8617
|
-
*/
|
|
8618
|
-
|
|
8619
|
-
/**
|
|
8620
|
-
* The running streaming tools of this invocation.
|
|
8621
|
-
*/
|
|
8622
|
-
|
|
8623
|
-
/**
|
|
8624
|
-
* Caches necessary, data audio or contents, that are needed by transcription.
|
|
8625
|
-
*/
|
|
8626
|
-
|
|
8627
|
-
/**
|
|
8628
|
-
* Configurations for live agents under this invocation.
|
|
8629
|
-
*/
|
|
8630
|
-
|
|
8631
|
-
/**
|
|
8632
|
-
* A container to keep track of different kinds of costs incurred as a part
|
|
8633
|
-
* of this invocation.
|
|
8634
|
-
*/
|
|
8635
|
-
__init45() {this._invocationCostManager = new InvocationCostManager()}
|
|
8636
|
-
/**
|
|
8637
|
-
* Constructor for InvocationContext
|
|
8638
|
-
*/
|
|
8639
|
-
constructor(options) {;_class25.prototype.__init44.call(this);_class25.prototype.__init45.call(this);
|
|
8640
|
-
this.artifactService = options.artifactService;
|
|
8641
|
-
this.sessionService = options.sessionService;
|
|
8642
|
-
this.memoryService = options.memoryService;
|
|
8643
|
-
this.invocationId = options.invocationId || newInvocationContextId();
|
|
8644
|
-
this.branch = options.branch;
|
|
8645
|
-
this.agent = options.agent;
|
|
8646
|
-
this.userContent = options.userContent;
|
|
8647
|
-
this.session = options.session;
|
|
8648
|
-
this.endInvocation = options.endInvocation || false;
|
|
8649
|
-
this.liveRequestQueue = options.liveRequestQueue;
|
|
8650
|
-
this.activeStreamingTools = options.activeStreamingTools;
|
|
8651
|
-
this.transcriptionCache = options.transcriptionCache;
|
|
8652
|
-
this.runConfig = options.runConfig;
|
|
8653
|
-
}
|
|
8654
|
-
/**
|
|
8655
|
-
* App name from the session
|
|
8656
|
-
*/
|
|
8657
|
-
get appName() {
|
|
8658
|
-
return this.session.appName;
|
|
8659
|
-
}
|
|
8660
|
-
/**
|
|
8661
|
-
* User ID from the session
|
|
8662
|
-
*/
|
|
8663
|
-
get userId() {
|
|
8664
|
-
return this.session.userId;
|
|
8665
|
-
}
|
|
8666
|
-
/**
|
|
8667
|
-
* Tracks number of llm calls made.
|
|
8668
|
-
*
|
|
8669
|
-
* @throws {LlmCallsLimitExceededError} If number of llm calls made exceed the set threshold.
|
|
8670
|
-
*/
|
|
8671
|
-
incrementLlmCallCount() {
|
|
8672
|
-
this._invocationCostManager.incrementAndEnforceLlmCallsLimit(
|
|
8673
|
-
this.runConfig
|
|
8674
|
-
);
|
|
8675
|
-
}
|
|
8676
|
-
/**
|
|
8677
|
-
* Creates a child invocation context for a sub-agent
|
|
8678
|
-
*/
|
|
8679
|
-
createChildContext(agent) {
|
|
8680
|
-
return new _InvocationContext({
|
|
8681
|
-
artifactService: this.artifactService,
|
|
8682
|
-
sessionService: this.sessionService,
|
|
8683
|
-
memoryService: this.memoryService,
|
|
8684
|
-
invocationId: this.invocationId,
|
|
8685
|
-
// Keep same invocation ID
|
|
8686
|
-
branch: this.branch ? `${this.branch}.${agent.name}` : agent.name,
|
|
8687
|
-
// Update branch
|
|
8688
|
-
agent,
|
|
8689
|
-
// Update to the new agent
|
|
8690
|
-
userContent: this.userContent,
|
|
8691
|
-
session: this.session,
|
|
8692
|
-
endInvocation: this.endInvocation,
|
|
8693
|
-
liveRequestQueue: this.liveRequestQueue,
|
|
8694
|
-
activeStreamingTools: this.activeStreamingTools,
|
|
8695
|
-
transcriptionCache: this.transcriptionCache,
|
|
8696
|
-
runConfig: this.runConfig
|
|
8697
|
-
});
|
|
8698
|
-
}
|
|
8699
|
-
}, _class25);
|
|
8700
|
-
|
|
8701
8841
|
// src/agents/parallel-agent.ts
|
|
8702
8842
|
function createBranchContextForSubAgent(agent, subAgent, invocationContext) {
|
|
8703
8843
|
const branchSuffix = `${agent.name}.${subAgent.name}`;
|
|
@@ -8813,7 +8953,7 @@ var LoopAgent = class extends BaseAgent {
|
|
|
8813
8953
|
for (const subAgent of this.subAgents) {
|
|
8814
8954
|
for await (const event of subAgent.runAsync(ctx)) {
|
|
8815
8955
|
yield event;
|
|
8816
|
-
if (_optionalChain([event, 'access',
|
|
8956
|
+
if (_optionalChain([event, 'access', _240 => _240.actions, 'optionalAccess', _241 => _241.escalate])) {
|
|
8817
8957
|
return;
|
|
8818
8958
|
}
|
|
8819
8959
|
}
|
|
@@ -8831,7 +8971,7 @@ var LoopAgent = class extends BaseAgent {
|
|
|
8831
8971
|
|
|
8832
8972
|
// src/agents/lang-graph-agent.ts
|
|
8833
8973
|
init_logger();
|
|
8834
|
-
var LangGraphAgent = (
|
|
8974
|
+
var LangGraphAgent = (_class27 = class extends BaseAgent {
|
|
8835
8975
|
/**
|
|
8836
8976
|
* Graph nodes (agents and their connections)
|
|
8837
8977
|
*/
|
|
@@ -8847,8 +8987,8 @@ var LangGraphAgent = (_class26 = class extends BaseAgent {
|
|
|
8847
8987
|
/**
|
|
8848
8988
|
* Results from node executions
|
|
8849
8989
|
*/
|
|
8850
|
-
|
|
8851
|
-
|
|
8990
|
+
__init47() {this.results = []}
|
|
8991
|
+
__init48() {this.logger = new Logger({ name: "LangGraphAgent" })}
|
|
8852
8992
|
/**
|
|
8853
8993
|
* Constructor for LangGraphAgent
|
|
8854
8994
|
*/
|
|
@@ -8856,7 +8996,7 @@ var LangGraphAgent = (_class26 = class extends BaseAgent {
|
|
|
8856
8996
|
super({
|
|
8857
8997
|
name: config.name,
|
|
8858
8998
|
description: config.description
|
|
8859
|
-
});
|
|
8999
|
+
});_class27.prototype.__init47.call(this);_class27.prototype.__init48.call(this);;
|
|
8860
9000
|
this.nodes = /* @__PURE__ */ new Map();
|
|
8861
9001
|
for (const node of config.nodes) {
|
|
8862
9002
|
if (this.nodes.has(node.name)) {
|
|
@@ -9052,7 +9192,7 @@ var LangGraphAgent = (_class26 = class extends BaseAgent {
|
|
|
9052
9192
|
}
|
|
9053
9193
|
this.maxSteps = maxSteps;
|
|
9054
9194
|
}
|
|
9055
|
-
},
|
|
9195
|
+
}, _class27);
|
|
9056
9196
|
|
|
9057
9197
|
// src/agents/agent-builder.ts
|
|
9058
9198
|
|
|
@@ -9124,17 +9264,17 @@ var RunConfig = class {
|
|
|
9124
9264
|
*/
|
|
9125
9265
|
|
|
9126
9266
|
constructor(config) {
|
|
9127
|
-
this.speechConfig = _optionalChain([config, 'optionalAccess',
|
|
9128
|
-
this.responseModalities = _optionalChain([config, 'optionalAccess',
|
|
9129
|
-
this.saveInputBlobsAsArtifacts = _optionalChain([config, 'optionalAccess',
|
|
9130
|
-
this.supportCFC = _optionalChain([config, 'optionalAccess',
|
|
9131
|
-
this.streamingMode = _optionalChain([config, 'optionalAccess',
|
|
9132
|
-
this.outputAudioTranscription = _optionalChain([config, 'optionalAccess',
|
|
9133
|
-
this.inputAudioTranscription = _optionalChain([config, 'optionalAccess',
|
|
9134
|
-
this.realtimeInputConfig = _optionalChain([config, 'optionalAccess',
|
|
9135
|
-
this.enableAffectiveDialog = _optionalChain([config, 'optionalAccess',
|
|
9136
|
-
this.proactivity = _optionalChain([config, 'optionalAccess',
|
|
9137
|
-
this.maxLlmCalls = _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
9267
|
+
this.speechConfig = _optionalChain([config, 'optionalAccess', _242 => _242.speechConfig]);
|
|
9268
|
+
this.responseModalities = _optionalChain([config, 'optionalAccess', _243 => _243.responseModalities]);
|
|
9269
|
+
this.saveInputBlobsAsArtifacts = _optionalChain([config, 'optionalAccess', _244 => _244.saveInputBlobsAsArtifacts]) || false;
|
|
9270
|
+
this.supportCFC = _optionalChain([config, 'optionalAccess', _245 => _245.supportCFC]) || false;
|
|
9271
|
+
this.streamingMode = _optionalChain([config, 'optionalAccess', _246 => _246.streamingMode]) || "NONE" /* NONE */;
|
|
9272
|
+
this.outputAudioTranscription = _optionalChain([config, 'optionalAccess', _247 => _247.outputAudioTranscription]);
|
|
9273
|
+
this.inputAudioTranscription = _optionalChain([config, 'optionalAccess', _248 => _248.inputAudioTranscription]);
|
|
9274
|
+
this.realtimeInputConfig = _optionalChain([config, 'optionalAccess', _249 => _249.realtimeInputConfig]);
|
|
9275
|
+
this.enableAffectiveDialog = _optionalChain([config, 'optionalAccess', _250 => _250.enableAffectiveDialog]);
|
|
9276
|
+
this.proactivity = _optionalChain([config, 'optionalAccess', _251 => _251.proactivity]);
|
|
9277
|
+
this.maxLlmCalls = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _252 => _252.maxLlmCalls]), () => ( 500));
|
|
9138
9278
|
this.validateMaxLlmCalls();
|
|
9139
9279
|
}
|
|
9140
9280
|
/**
|
|
@@ -9155,8 +9295,8 @@ var RunConfig = class {
|
|
|
9155
9295
|
};
|
|
9156
9296
|
|
|
9157
9297
|
// src/artifacts/in-memory-artifact-service.ts
|
|
9158
|
-
var InMemoryArtifactService = (
|
|
9159
|
-
|
|
9298
|
+
var InMemoryArtifactService = (_class28 = class {constructor() { _class28.prototype.__init49.call(this); }
|
|
9299
|
+
__init49() {this.artifacts = /* @__PURE__ */ new Map()}
|
|
9160
9300
|
fileHasUserNamespace(filename) {
|
|
9161
9301
|
return filename.startsWith("user:");
|
|
9162
9302
|
}
|
|
@@ -9229,7 +9369,7 @@ var InMemoryArtifactService = (_class27 = class {constructor() { _class27.protot
|
|
|
9229
9369
|
}
|
|
9230
9370
|
return Array.from({ length: versions.length }, (_, i) => i);
|
|
9231
9371
|
}
|
|
9232
|
-
},
|
|
9372
|
+
}, _class28);
|
|
9233
9373
|
|
|
9234
9374
|
// src/runners.ts
|
|
9235
9375
|
init_logger();
|
|
@@ -9256,15 +9396,15 @@ function _extractWordsLower(text) {
|
|
|
9256
9396
|
const words = text.match(/[A-Za-z]+/g) || [];
|
|
9257
9397
|
return new Set(words.map((word) => word.toLowerCase()));
|
|
9258
9398
|
}
|
|
9259
|
-
var InMemoryMemoryService = (
|
|
9399
|
+
var InMemoryMemoryService = (_class29 = class {
|
|
9260
9400
|
/**
|
|
9261
9401
|
* Keys are app_name/user_id, session_id. Values are session event lists.
|
|
9262
9402
|
*/
|
|
9263
|
-
|
|
9403
|
+
__init50() {this._sessionEvents = /* @__PURE__ */ new Map()}
|
|
9264
9404
|
/**
|
|
9265
9405
|
* Constructor for InMemoryMemoryService
|
|
9266
9406
|
*/
|
|
9267
|
-
constructor() {;
|
|
9407
|
+
constructor() {;_class29.prototype.__init50.call(this);
|
|
9268
9408
|
this._sessionEvents = /* @__PURE__ */ new Map();
|
|
9269
9409
|
}
|
|
9270
9410
|
/**
|
|
@@ -9278,7 +9418,7 @@ var InMemoryMemoryService = (_class28 = class {
|
|
|
9278
9418
|
}
|
|
9279
9419
|
const userSessions = this._sessionEvents.get(userKey);
|
|
9280
9420
|
const filteredEvents = session.events.filter(
|
|
9281
|
-
(event) => _optionalChain([event, 'access',
|
|
9421
|
+
(event) => _optionalChain([event, 'access', _253 => _253.content, 'optionalAccess', _254 => _254.parts])
|
|
9282
9422
|
);
|
|
9283
9423
|
userSessions.set(session.id, filteredEvents);
|
|
9284
9424
|
}
|
|
@@ -9348,7 +9488,7 @@ var InMemoryMemoryService = (_class28 = class {
|
|
|
9348
9488
|
clear() {
|
|
9349
9489
|
this._sessionEvents.clear();
|
|
9350
9490
|
}
|
|
9351
|
-
},
|
|
9491
|
+
}, _class29);
|
|
9352
9492
|
|
|
9353
9493
|
// src/sessions/in-memory-session-service.ts
|
|
9354
9494
|
var _crypto = require('crypto');
|
|
@@ -9390,19 +9530,19 @@ var BaseSessionService = class {
|
|
|
9390
9530
|
};
|
|
9391
9531
|
|
|
9392
9532
|
// src/sessions/in-memory-session-service.ts
|
|
9393
|
-
var InMemorySessionService = (
|
|
9533
|
+
var InMemorySessionService = (_class30 = class extends BaseSessionService {constructor(...args2) { super(...args2); _class30.prototype.__init51.call(this);_class30.prototype.__init52.call(this);_class30.prototype.__init53.call(this); }
|
|
9394
9534
|
/**
|
|
9395
9535
|
* A map from app name to a map from user ID to a map from session ID to session.
|
|
9396
9536
|
*/
|
|
9397
|
-
|
|
9537
|
+
__init51() {this.sessions = /* @__PURE__ */ new Map()}
|
|
9398
9538
|
/**
|
|
9399
9539
|
* A map from app name to a map from user ID to a map from key to the value.
|
|
9400
9540
|
*/
|
|
9401
|
-
|
|
9541
|
+
__init52() {this.userState = /* @__PURE__ */ new Map()}
|
|
9402
9542
|
/**
|
|
9403
9543
|
* A map from app name to a map from key to the value.
|
|
9404
9544
|
*/
|
|
9405
|
-
|
|
9545
|
+
__init53() {this.appState = /* @__PURE__ */ new Map()}
|
|
9406
9546
|
/**
|
|
9407
9547
|
* Creates a new session.
|
|
9408
9548
|
*/
|
|
@@ -9417,7 +9557,7 @@ var InMemorySessionService = (_class29 = class extends BaseSessionService {const
|
|
|
9417
9557
|
return this.createSessionImpl(appName, userId, state, sessionId);
|
|
9418
9558
|
}
|
|
9419
9559
|
createSessionImpl(appName, userId, state, sessionId) {
|
|
9420
|
-
const finalSessionId = _optionalChain([sessionId, 'optionalAccess',
|
|
9560
|
+
const finalSessionId = _optionalChain([sessionId, 'optionalAccess', _255 => _255.trim, 'call', _256 => _256()]) || _crypto.randomUUID.call(void 0, );
|
|
9421
9561
|
const session = {
|
|
9422
9562
|
appName,
|
|
9423
9563
|
userId,
|
|
@@ -9574,7 +9714,7 @@ var InMemorySessionService = (_class29 = class extends BaseSessionService {const
|
|
|
9574
9714
|
warning(`sessionId ${sessionId} not in sessions[appName][userId]`);
|
|
9575
9715
|
return event;
|
|
9576
9716
|
}
|
|
9577
|
-
if (_optionalChain([event, 'access',
|
|
9717
|
+
if (_optionalChain([event, 'access', _257 => _257.actions, 'optionalAccess', _258 => _258.stateDelta])) {
|
|
9578
9718
|
for (const key in event.actions.stateDelta) {
|
|
9579
9719
|
const value = event.actions.stateDelta[key];
|
|
9580
9720
|
if (key.startsWith(State.APP_PREFIX)) {
|
|
@@ -9599,7 +9739,7 @@ var InMemorySessionService = (_class29 = class extends BaseSessionService {const
|
|
|
9599
9739
|
storageSession.lastUpdateTime = event.timestamp;
|
|
9600
9740
|
return event;
|
|
9601
9741
|
}
|
|
9602
|
-
},
|
|
9742
|
+
}, _class30);
|
|
9603
9743
|
|
|
9604
9744
|
// src/runners.ts
|
|
9605
9745
|
function _findFunctionCallEventIfLastEventIsFunctionResponse(session) {
|
|
@@ -9608,14 +9748,14 @@ function _findFunctionCallEventIfLastEventIsFunctionResponse(session) {
|
|
|
9608
9748
|
return null;
|
|
9609
9749
|
}
|
|
9610
9750
|
const lastEvent = events[events.length - 1];
|
|
9611
|
-
if (_optionalChain([lastEvent, 'access',
|
|
9612
|
-
const functionCallId = _optionalChain([lastEvent, 'access',
|
|
9751
|
+
if (_optionalChain([lastEvent, 'access', _259 => _259.content, 'optionalAccess', _260 => _260.parts, 'optionalAccess', _261 => _261.some, 'call', _262 => _262((part) => part.functionResponse)])) {
|
|
9752
|
+
const functionCallId = _optionalChain([lastEvent, 'access', _263 => _263.content, 'access', _264 => _264.parts, 'access', _265 => _265.find, 'call', _266 => _266(
|
|
9613
9753
|
(part) => part.functionResponse
|
|
9614
|
-
), 'optionalAccess',
|
|
9754
|
+
), 'optionalAccess', _267 => _267.functionResponse, 'optionalAccess', _268 => _268.id]);
|
|
9615
9755
|
if (!functionCallId) return null;
|
|
9616
9756
|
for (let i = events.length - 2; i >= 0; i--) {
|
|
9617
9757
|
const event = events[i];
|
|
9618
|
-
const functionCalls = _optionalChain([event, 'access',
|
|
9758
|
+
const functionCalls = _optionalChain([event, 'access', _269 => _269.getFunctionCalls, 'optionalCall', _270 => _270()]) || [];
|
|
9619
9759
|
for (const functionCall of functionCalls) {
|
|
9620
9760
|
if (functionCall.id === functionCallId) {
|
|
9621
9761
|
return event;
|
|
@@ -9625,7 +9765,7 @@ function _findFunctionCallEventIfLastEventIsFunctionResponse(session) {
|
|
|
9625
9765
|
}
|
|
9626
9766
|
return null;
|
|
9627
9767
|
}
|
|
9628
|
-
var Runner = (
|
|
9768
|
+
var Runner = (_class31 = class {
|
|
9629
9769
|
/**
|
|
9630
9770
|
* The app name of the runner.
|
|
9631
9771
|
*/
|
|
@@ -9646,7 +9786,7 @@ var Runner = (_class30 = class {
|
|
|
9646
9786
|
* The memory service for the runner.
|
|
9647
9787
|
*/
|
|
9648
9788
|
|
|
9649
|
-
|
|
9789
|
+
__init54() {this.logger = new Logger({ name: "Runner" })}
|
|
9650
9790
|
/**
|
|
9651
9791
|
* Initializes the Runner.
|
|
9652
9792
|
*/
|
|
@@ -9656,7 +9796,7 @@ var Runner = (_class30 = class {
|
|
|
9656
9796
|
artifactService,
|
|
9657
9797
|
sessionService,
|
|
9658
9798
|
memoryService
|
|
9659
|
-
}) {;
|
|
9799
|
+
}) {;_class31.prototype.__init54.call(this);
|
|
9660
9800
|
this.appName = appName;
|
|
9661
9801
|
this.agent = agent;
|
|
9662
9802
|
this.artifactService = artifactService;
|
|
@@ -9745,6 +9885,9 @@ var Runner = (_class30 = class {
|
|
|
9745
9885
|
)) {
|
|
9746
9886
|
if (!event.partial) {
|
|
9747
9887
|
await this.sessionService.appendEvent(session, event);
|
|
9888
|
+
if (this.memoryService) {
|
|
9889
|
+
await this.memoryService.addSessionToMemory(session);
|
|
9890
|
+
}
|
|
9748
9891
|
}
|
|
9749
9892
|
yield event;
|
|
9750
9893
|
}
|
|
@@ -9803,15 +9946,15 @@ var Runner = (_class30 = class {
|
|
|
9803
9946
|
*/
|
|
9804
9947
|
_findAgentToRun(session, rootAgent) {
|
|
9805
9948
|
const event = _findFunctionCallEventIfLastEventIsFunctionResponse(session);
|
|
9806
|
-
if (_optionalChain([event, 'optionalAccess',
|
|
9949
|
+
if (_optionalChain([event, 'optionalAccess', _271 => _271.author])) {
|
|
9807
9950
|
return rootAgent.findAgent(event.author);
|
|
9808
9951
|
}
|
|
9809
|
-
const nonUserEvents = _optionalChain([session, 'access',
|
|
9952
|
+
const nonUserEvents = _optionalChain([session, 'access', _272 => _272.events, 'optionalAccess', _273 => _273.filter, 'call', _274 => _274((e) => e.author !== "user"), 'access', _275 => _275.reverse, 'call', _276 => _276()]) || [];
|
|
9810
9953
|
for (const event2 of nonUserEvents) {
|
|
9811
9954
|
if (event2.author === rootAgent.name) {
|
|
9812
9955
|
return rootAgent;
|
|
9813
9956
|
}
|
|
9814
|
-
const agent = _optionalChain([rootAgent, 'access',
|
|
9957
|
+
const agent = _optionalChain([rootAgent, 'access', _277 => _277.findSubAgent, 'optionalCall', _278 => _278(event2.author)]);
|
|
9815
9958
|
if (!agent) {
|
|
9816
9959
|
this.logger.debug(
|
|
9817
9960
|
`Event from an unknown agent: ${event2.author}, event id: ${event2.id}`
|
|
@@ -9860,7 +10003,7 @@ var Runner = (_class30 = class {
|
|
|
9860
10003
|
runConfig
|
|
9861
10004
|
});
|
|
9862
10005
|
}
|
|
9863
|
-
},
|
|
10006
|
+
}, _class31);
|
|
9864
10007
|
var InMemoryRunner = class extends Runner {
|
|
9865
10008
|
/**
|
|
9866
10009
|
* Deprecated. Please don't use. The in-memory session service for the runner.
|
|
@@ -9883,16 +10026,18 @@ var InMemoryRunner = class extends Runner {
|
|
|
9883
10026
|
};
|
|
9884
10027
|
|
|
9885
10028
|
// src/agents/agent-builder.ts
|
|
9886
|
-
var AgentBuilder = (
|
|
10029
|
+
var AgentBuilder = (_class32 = class _AgentBuilder {
|
|
10030
|
+
|
|
9887
10031
|
|
|
9888
10032
|
|
|
9889
10033
|
|
|
9890
10034
|
|
|
9891
|
-
|
|
10035
|
+
__init55() {this.agentType = "llm"}
|
|
10036
|
+
|
|
9892
10037
|
/**
|
|
9893
10038
|
* Private constructor - use static create() method
|
|
9894
10039
|
*/
|
|
9895
|
-
constructor(name) {;
|
|
10040
|
+
constructor(name) {;_class32.prototype.__init55.call(this);
|
|
9896
10041
|
this.config = { name };
|
|
9897
10042
|
}
|
|
9898
10043
|
/**
|
|
@@ -9956,6 +10101,24 @@ var AgentBuilder = (_class31 = class _AgentBuilder {
|
|
|
9956
10101
|
this.config.planner = planner;
|
|
9957
10102
|
return this;
|
|
9958
10103
|
}
|
|
10104
|
+
/**
|
|
10105
|
+
* Set the code executor for the agent
|
|
10106
|
+
* @param codeExecutor The code executor to use for running code
|
|
10107
|
+
* @returns This builder instance for chaining
|
|
10108
|
+
*/
|
|
10109
|
+
withCodeExecutor(codeExecutor) {
|
|
10110
|
+
this.config.codeExecutor = codeExecutor;
|
|
10111
|
+
return this;
|
|
10112
|
+
}
|
|
10113
|
+
/**
|
|
10114
|
+
* Set the output key for the agent
|
|
10115
|
+
* @param outputKey The output key in session state to store the output of the agent
|
|
10116
|
+
* @returns This builder instance for chaining
|
|
10117
|
+
*/
|
|
10118
|
+
withOutputKey(outputKey) {
|
|
10119
|
+
this.config.outputKey = outputKey;
|
|
10120
|
+
return this;
|
|
10121
|
+
}
|
|
9959
10122
|
/**
|
|
9960
10123
|
* Configure as a sequential agent
|
|
9961
10124
|
* @param subAgents Sub-agents to execute in sequence
|
|
@@ -10006,14 +10169,38 @@ var AgentBuilder = (_class31 = class _AgentBuilder {
|
|
|
10006
10169
|
* @param options Session configuration options (userId and appName)
|
|
10007
10170
|
* @returns This builder instance for chaining
|
|
10008
10171
|
*/
|
|
10009
|
-
|
|
10010
|
-
this.
|
|
10011
|
-
|
|
10172
|
+
withSessionService(service, options = {}) {
|
|
10173
|
+
this.sessionService = service;
|
|
10174
|
+
this.sessionOptions = {
|
|
10012
10175
|
userId: options.userId || this.generateDefaultUserId(),
|
|
10013
|
-
appName: options.appName || this.generateDefaultAppName()
|
|
10176
|
+
appName: options.appName || this.generateDefaultAppName(),
|
|
10177
|
+
state: options.state,
|
|
10178
|
+
sessionId: options.sessionId
|
|
10014
10179
|
};
|
|
10015
10180
|
return this;
|
|
10016
10181
|
}
|
|
10182
|
+
/**
|
|
10183
|
+
* Configure with an existing session instance
|
|
10184
|
+
* @param session Existing session to use
|
|
10185
|
+
* @returns This builder instance for chaining
|
|
10186
|
+
* @throws Error if no session service has been configured via withSessionService()
|
|
10187
|
+
*/
|
|
10188
|
+
withSession(session) {
|
|
10189
|
+
if (!this.sessionService) {
|
|
10190
|
+
throw new Error(
|
|
10191
|
+
"Session service must be configured before using withSession(). Call withSessionService() first, or use withQuickSession() for in-memory sessions."
|
|
10192
|
+
);
|
|
10193
|
+
}
|
|
10194
|
+
this.sessionOptions = {
|
|
10195
|
+
...this.sessionOptions,
|
|
10196
|
+
userId: session.userId,
|
|
10197
|
+
appName: session.appName,
|
|
10198
|
+
sessionId: session.id,
|
|
10199
|
+
state: session.state
|
|
10200
|
+
};
|
|
10201
|
+
this.existingSession = session;
|
|
10202
|
+
return this;
|
|
10203
|
+
}
|
|
10017
10204
|
/**
|
|
10018
10205
|
* Configure memory service for the agent
|
|
10019
10206
|
* @param memoryService Memory service to use for conversation history and context
|
|
@@ -10039,7 +10226,7 @@ var AgentBuilder = (_class31 = class _AgentBuilder {
|
|
|
10039
10226
|
* @returns This builder instance for chaining
|
|
10040
10227
|
*/
|
|
10041
10228
|
withQuickSession(options = {}) {
|
|
10042
|
-
return this.
|
|
10229
|
+
return this.withSessionService(new InMemorySessionService(), options);
|
|
10043
10230
|
}
|
|
10044
10231
|
/**
|
|
10045
10232
|
* Build the agent and optionally create runner and session
|
|
@@ -10049,18 +10236,24 @@ var AgentBuilder = (_class31 = class _AgentBuilder {
|
|
|
10049
10236
|
const agent = this.createAgent();
|
|
10050
10237
|
let runner;
|
|
10051
10238
|
let session;
|
|
10052
|
-
if (!this.
|
|
10239
|
+
if (!this.sessionService) {
|
|
10053
10240
|
this.withQuickSession();
|
|
10054
10241
|
}
|
|
10055
|
-
if (this.
|
|
10056
|
-
|
|
10057
|
-
this.
|
|
10058
|
-
|
|
10059
|
-
|
|
10242
|
+
if (this.sessionService && this.sessionOptions) {
|
|
10243
|
+
if (this.existingSession) {
|
|
10244
|
+
session = this.existingSession;
|
|
10245
|
+
} else {
|
|
10246
|
+
session = await this.sessionService.createSession(
|
|
10247
|
+
this.sessionOptions.appName,
|
|
10248
|
+
this.sessionOptions.userId,
|
|
10249
|
+
this.sessionOptions.state,
|
|
10250
|
+
this.sessionOptions.sessionId
|
|
10251
|
+
);
|
|
10252
|
+
}
|
|
10060
10253
|
const runnerConfig = {
|
|
10061
|
-
appName: this.
|
|
10254
|
+
appName: this.sessionOptions.appName,
|
|
10062
10255
|
agent,
|
|
10063
|
-
sessionService: this.
|
|
10256
|
+
sessionService: this.sessionService,
|
|
10064
10257
|
memoryService: this.memoryService,
|
|
10065
10258
|
artifactService: this.artifactService
|
|
10066
10259
|
};
|
|
@@ -10095,7 +10288,12 @@ var AgentBuilder = (_class31 = class _AgentBuilder {
|
|
|
10095
10288
|
description: this.config.description,
|
|
10096
10289
|
instruction: this.config.instruction,
|
|
10097
10290
|
tools: this.config.tools,
|
|
10098
|
-
planner: this.config.planner
|
|
10291
|
+
planner: this.config.planner,
|
|
10292
|
+
codeExecutor: this.config.codeExecutor,
|
|
10293
|
+
memoryService: this.memoryService,
|
|
10294
|
+
artifactService: this.artifactService,
|
|
10295
|
+
outputKey: this.config.outputKey,
|
|
10296
|
+
sessionService: this.sessionService
|
|
10099
10297
|
});
|
|
10100
10298
|
}
|
|
10101
10299
|
case "sequential":
|
|
@@ -10160,20 +10358,20 @@ var AgentBuilder = (_class31 = class _AgentBuilder {
|
|
|
10160
10358
|
* @returns Enhanced runner with simplified API
|
|
10161
10359
|
*/
|
|
10162
10360
|
createEnhancedRunner(baseRunner, session) {
|
|
10163
|
-
const
|
|
10361
|
+
const sessionOptions = this.sessionOptions;
|
|
10164
10362
|
return {
|
|
10165
10363
|
async ask(message) {
|
|
10166
10364
|
const newMessage = typeof message === "string" ? { parts: [{ text: message }] } : typeof message === "object" && "contents" in message ? { parts: message.contents[message.contents.length - 1].parts } : message;
|
|
10167
10365
|
let response = "";
|
|
10168
|
-
if (!
|
|
10366
|
+
if (!_optionalChain([sessionOptions, 'optionalAccess', _279 => _279.userId])) {
|
|
10169
10367
|
throw new Error("Session configuration is required");
|
|
10170
10368
|
}
|
|
10171
10369
|
for await (const event of baseRunner.runAsync({
|
|
10172
|
-
userId:
|
|
10370
|
+
userId: sessionOptions.userId,
|
|
10173
10371
|
sessionId: session.id,
|
|
10174
10372
|
newMessage
|
|
10175
10373
|
})) {
|
|
10176
|
-
if (_optionalChain([event, 'access',
|
|
10374
|
+
if (_optionalChain([event, 'access', _280 => _280.content, 'optionalAccess', _281 => _281.parts]) && Array.isArray(event.content.parts)) {
|
|
10177
10375
|
const content = event.content.parts.map(
|
|
10178
10376
|
(part) => (part && typeof part === "object" && "text" in part ? part.text : "") || ""
|
|
10179
10377
|
).join("");
|
|
@@ -10182,14 +10380,14 @@ var AgentBuilder = (_class31 = class _AgentBuilder {
|
|
|
10182
10380
|
}
|
|
10183
10381
|
}
|
|
10184
10382
|
}
|
|
10185
|
-
return response;
|
|
10383
|
+
return response.trim();
|
|
10186
10384
|
},
|
|
10187
10385
|
runAsync(params) {
|
|
10188
10386
|
return baseRunner.runAsync(params);
|
|
10189
10387
|
}
|
|
10190
10388
|
};
|
|
10191
10389
|
}
|
|
10192
|
-
},
|
|
10390
|
+
}, _class32);
|
|
10193
10391
|
|
|
10194
10392
|
// src/memory/index.ts
|
|
10195
10393
|
var memory_exports = {};
|
|
@@ -10253,7 +10451,7 @@ var VertexAiSessionService = class extends BaseSessionService {
|
|
|
10253
10451
|
path: `operations/${operationId}`,
|
|
10254
10452
|
request_dict: {}
|
|
10255
10453
|
});
|
|
10256
|
-
if (_optionalChain([lroResponse, 'optionalAccess',
|
|
10454
|
+
if (_optionalChain([lroResponse, 'optionalAccess', _282 => _282.done])) {
|
|
10257
10455
|
break;
|
|
10258
10456
|
}
|
|
10259
10457
|
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
@@ -10523,11 +10721,11 @@ var VertexAiSessionService = class extends BaseSessionService {
|
|
|
10523
10721
|
|
|
10524
10722
|
// src/sessions/database-session-service.ts
|
|
10525
10723
|
var _kysely = require('kysely');
|
|
10526
|
-
var DatabaseSessionService = (
|
|
10724
|
+
var DatabaseSessionService = (_class33 = class extends BaseSessionService {
|
|
10527
10725
|
|
|
10528
|
-
|
|
10726
|
+
__init56() {this.initialized = false}
|
|
10529
10727
|
constructor(config) {
|
|
10530
|
-
super();
|
|
10728
|
+
super();_class33.prototype.__init56.call(this);;
|
|
10531
10729
|
this.db = config.db;
|
|
10532
10730
|
if (!config.skipTableCreation) {
|
|
10533
10731
|
this.initializeDatabase().catch((error) => {
|
|
@@ -10602,7 +10800,7 @@ var DatabaseSessionService = (_class32 = class extends BaseSessionService {
|
|
|
10602
10800
|
if (!jsonString) return defaultValue;
|
|
10603
10801
|
try {
|
|
10604
10802
|
return JSON.parse(jsonString);
|
|
10605
|
-
} catch (
|
|
10803
|
+
} catch (e5) {
|
|
10606
10804
|
return defaultValue;
|
|
10607
10805
|
}
|
|
10608
10806
|
}
|
|
@@ -10624,12 +10822,12 @@ var DatabaseSessionService = (_class32 = class extends BaseSessionService {
|
|
|
10624
10822
|
}
|
|
10625
10823
|
async createSession(appName, userId, state, sessionId) {
|
|
10626
10824
|
await this.ensureInitialized();
|
|
10627
|
-
const id = _optionalChain([sessionId, 'optionalAccess',
|
|
10825
|
+
const id = _optionalChain([sessionId, 'optionalAccess', _283 => _283.trim, 'call', _284 => _284()]) || this.generateSessionId();
|
|
10628
10826
|
return await this.db.transaction().execute(async (trx) => {
|
|
10629
10827
|
const appState = await trx.selectFrom("app_states").selectAll().where("app_name", "=", appName).executeTakeFirst();
|
|
10630
10828
|
const userState = await trx.selectFrom("user_states").selectAll().where("app_name", "=", appName).where("user_id", "=", userId).executeTakeFirst();
|
|
10631
|
-
let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess',
|
|
10632
|
-
let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess',
|
|
10829
|
+
let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _285 => _285.state]), {});
|
|
10830
|
+
let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _286 => _286.state]), {});
|
|
10633
10831
|
if (!appState) {
|
|
10634
10832
|
await trx.insertInto("app_states").values({
|
|
10635
10833
|
app_name: appName,
|
|
@@ -10688,21 +10886,21 @@ var DatabaseSessionService = (_class32 = class extends BaseSessionService {
|
|
|
10688
10886
|
return void 0;
|
|
10689
10887
|
}
|
|
10690
10888
|
let eventQuery = trx.selectFrom("events").selectAll().where("session_id", "=", sessionId).orderBy("timestamp", "desc");
|
|
10691
|
-
if (_optionalChain([config, 'optionalAccess',
|
|
10889
|
+
if (_optionalChain([config, 'optionalAccess', _287 => _287.afterTimestamp])) {
|
|
10692
10890
|
eventQuery = eventQuery.where(
|
|
10693
10891
|
"timestamp",
|
|
10694
10892
|
">=",
|
|
10695
10893
|
new Date(config.afterTimestamp * 1e3)
|
|
10696
10894
|
);
|
|
10697
10895
|
}
|
|
10698
|
-
if (_optionalChain([config, 'optionalAccess',
|
|
10896
|
+
if (_optionalChain([config, 'optionalAccess', _288 => _288.numRecentEvents])) {
|
|
10699
10897
|
eventQuery = eventQuery.limit(config.numRecentEvents);
|
|
10700
10898
|
}
|
|
10701
10899
|
const storageEvents = await eventQuery.execute();
|
|
10702
10900
|
const appState = await trx.selectFrom("app_states").selectAll().where("app_name", "=", appName).executeTakeFirst();
|
|
10703
10901
|
const userState = await trx.selectFrom("user_states").selectAll().where("app_name", "=", appName).where("user_id", "=", userId).executeTakeFirst();
|
|
10704
|
-
const currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess',
|
|
10705
|
-
const currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess',
|
|
10902
|
+
const currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _289 => _289.state]), {});
|
|
10903
|
+
const currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _290 => _290.state]), {});
|
|
10706
10904
|
const sessionState = this.parseJsonSafely(storageSession.state, {});
|
|
10707
10905
|
const mergedState = this.mergeState(
|
|
10708
10906
|
currentAppState,
|
|
@@ -10760,13 +10958,13 @@ var DatabaseSessionService = (_class32 = class extends BaseSessionService {
|
|
|
10760
10958
|
}
|
|
10761
10959
|
const appState = await trx.selectFrom("app_states").selectAll().where("app_name", "=", session.appName).executeTakeFirst();
|
|
10762
10960
|
const userState = await trx.selectFrom("user_states").selectAll().where("app_name", "=", session.appName).where("user_id", "=", session.userId).executeTakeFirst();
|
|
10763
|
-
let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess',
|
|
10764
|
-
let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess',
|
|
10961
|
+
let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _291 => _291.state]), {});
|
|
10962
|
+
let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _292 => _292.state]), {});
|
|
10765
10963
|
let sessionState = this.parseJsonSafely(storageSession.state, {});
|
|
10766
10964
|
let appStateDelta = {};
|
|
10767
10965
|
let userStateDelta = {};
|
|
10768
10966
|
let sessionStateDelta = {};
|
|
10769
|
-
if (_optionalChain([event, 'access',
|
|
10967
|
+
if (_optionalChain([event, 'access', _293 => _293.actions, 'optionalAccess', _294 => _294.stateDelta])) {
|
|
10770
10968
|
const deltas = this.extractStateDelta(event.actions.stateDelta);
|
|
10771
10969
|
appStateDelta = deltas.appStateDelta;
|
|
10772
10970
|
userStateDelta = deltas.userStateDelta;
|
|
@@ -10912,7 +11110,7 @@ var DatabaseSessionService = (_class32 = class extends BaseSessionService {
|
|
|
10912
11110
|
* Overrides the base class method to work with plain object state.
|
|
10913
11111
|
*/
|
|
10914
11112
|
updateSessionState(session, event) {
|
|
10915
|
-
if (!_optionalChain([event, 'access',
|
|
11113
|
+
if (!_optionalChain([event, 'access', _295 => _295.actions, 'optionalAccess', _296 => _296.stateDelta])) {
|
|
10916
11114
|
return;
|
|
10917
11115
|
}
|
|
10918
11116
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
@@ -10921,7 +11119,7 @@ var DatabaseSessionService = (_class32 = class extends BaseSessionService {
|
|
|
10921
11119
|
}
|
|
10922
11120
|
}
|
|
10923
11121
|
}
|
|
10924
|
-
},
|
|
11122
|
+
}, _class33);
|
|
10925
11123
|
|
|
10926
11124
|
// src/sessions/database-factories.ts
|
|
10927
11125
|
var _dedent = require('dedent'); var _dedent2 = _interopRequireDefault(_dedent);
|
|
@@ -11082,7 +11280,7 @@ var GcsArtifactService = class {
|
|
|
11082
11280
|
};
|
|
11083
11281
|
return part;
|
|
11084
11282
|
} catch (error) {
|
|
11085
|
-
if (_optionalChain([error, 'optionalAccess',
|
|
11283
|
+
if (_optionalChain([error, 'optionalAccess', _297 => _297.code]) === 404) {
|
|
11086
11284
|
return null;
|
|
11087
11285
|
}
|
|
11088
11286
|
throw error;
|
|
@@ -11328,4 +11526,5 @@ var VERSION = "0.1.0";
|
|
|
11328
11526
|
|
|
11329
11527
|
|
|
11330
11528
|
|
|
11331
|
-
|
|
11529
|
+
|
|
11530
|
+
exports.AF_FUNCTION_CALL_ID_PREFIX = AF_FUNCTION_CALL_ID_PREFIX; exports.Agent = LlmAgent; exports.AgentBuilder = AgentBuilder; exports.AgentTool = AgentTool; exports.Agents = agents_exports; exports.AiSdkLlm = AiSdkLlm; exports.AnthropicLlm = AnthropicLlm; exports.ApiKeyCredential = ApiKeyCredential; exports.ApiKeyScheme = ApiKeyScheme; exports.AuthConfig = AuthConfig; exports.AuthCredential = AuthCredential; exports.AuthCredentialType = AuthCredentialType; exports.AuthHandler = AuthHandler; exports.AuthScheme = AuthScheme; exports.AuthSchemeType = AuthSchemeType; exports.AuthTool = AuthTool; exports.AutoFlow = AutoFlow; exports.BaseAgent = BaseAgent; exports.BaseCodeExecutor = BaseCodeExecutor; exports.BaseLLMConnection = BaseLLMConnection; exports.BaseLlm = BaseLlm; exports.BaseLlmFlow = BaseLlmFlow; exports.BaseLlmRequestProcessor = BaseLlmRequestProcessor; exports.BaseLlmResponseProcessor = BaseLlmResponseProcessor; exports.BasePlanner = BasePlanner; exports.BaseSessionService = BaseSessionService; exports.BaseTool = BaseTool; exports.BasicAuthCredential = BasicAuthCredential; exports.BearerTokenCredential = BearerTokenCredential; exports.BuiltInCodeExecutor = BuiltInCodeExecutor; exports.BuiltInPlanner = BuiltInPlanner; exports.CallbackContext = CallbackContext; exports.CodeExecutionUtils = CodeExecutionUtils; exports.CodeExecutorContext = CodeExecutorContext; exports.DatabaseSessionService = DatabaseSessionService; exports.EnhancedAuthConfig = EnhancedAuthConfig; exports.Event = Event; exports.EventActions = EventActions; exports.Events = events_exports; exports.ExitLoopTool = ExitLoopTool; exports.FileOperationsTool = FileOperationsTool; exports.Flows = flows_exports; exports.FunctionTool = FunctionTool; exports.GcsArtifactService = GcsArtifactService; exports.GetUserChoiceTool = GetUserChoiceTool; exports.GoogleLlm = GoogleLlm; exports.GoogleSearch = GoogleSearch; exports.HttpRequestTool = HttpRequestTool; exports.HttpScheme = HttpScheme; exports.InMemoryArtifactService = InMemoryArtifactService; exports.InMemoryMemoryService = InMemoryMemoryService; exports.InMemoryRunner = InMemoryRunner; exports.InMemorySessionService = InMemorySessionService; exports.InvocationContext = InvocationContext; exports.LLMRegistry = LLMRegistry; exports.LangGraphAgent = LangGraphAgent; exports.LlmAgent = LlmAgent; exports.LlmCallsLimitExceededError = LlmCallsLimitExceededError; exports.LlmRequest = LlmRequest; exports.LlmResponse = LlmResponse; exports.LoadArtifactsTool = LoadArtifactsTool; exports.LoadMemoryTool = LoadMemoryTool; exports.LoopAgent = LoopAgent; exports.McpAbi = McpAbi; exports.McpAtp = McpAtp; exports.McpBamm = McpBamm; exports.McpCoinGecko = McpCoinGecko; exports.McpDiscord = McpDiscord; exports.McpError = McpError; exports.McpErrorType = McpErrorType; exports.McpFilesystem = McpFilesystem; exports.McpFraxlend = McpFraxlend; exports.McpGeneric = McpGeneric; exports.McpIqWiki = McpIqWiki; exports.McpMemory = McpMemory; exports.McpNearAgent = McpNearAgent; exports.McpNearIntents = McpNearIntents; exports.McpOdos = McpOdos; exports.McpSamplingHandler = McpSamplingHandler; exports.McpTelegram = McpTelegram; exports.McpToolset = McpToolset; exports.Memory = memory_exports; exports.Models = models_exports; exports.OAuth2Credential = OAuth2Credential; exports.OAuth2Scheme = OAuth2Scheme; exports.OpenAiLlm = OpenAiLlm; exports.OpenIdConnectScheme = OpenIdConnectScheme; exports.ParallelAgent = ParallelAgent; exports.PlanReActPlanner = PlanReActPlanner; exports.REQUEST_EUC_FUNCTION_CALL_NAME = REQUEST_EUC_FUNCTION_CALL_NAME; exports.ReadonlyContext = ReadonlyContext; exports.RunConfig = RunConfig; exports.Runner = Runner; exports.SequentialAgent = SequentialAgent; exports.Sessions = sessions_exports; exports.SingleFlow = SingleFlow; exports.State = State; exports.StreamingMode = StreamingMode; exports.TelemetryService = TelemetryService; exports.ToolContext = ToolContext; exports.Tools = tools_exports; exports.TransferToAgentTool = TransferToAgentTool; exports.UserInteractionTool = UserInteractionTool; exports.VERSION = VERSION; exports.VertexAiSessionService = VertexAiSessionService; exports._findFunctionCallEventIfLastEventIsFunctionResponse = _findFunctionCallEventIfLastEventIsFunctionResponse; exports.adkToMcpToolType = adkToMcpToolType; exports.agentTransferRequestProcessor = requestProcessor8; exports.basicRequestProcessor = requestProcessor2; exports.buildFunctionDeclaration = buildFunctionDeclaration; exports.codeExecutionRequestProcessor = requestProcessor3; exports.codeExecutionResponseProcessor = responseProcessor; exports.contentRequestProcessor = requestProcessor4; exports.createAuthToolArguments = createAuthToolArguments; exports.createBranchContextForSubAgent = createBranchContextForSubAgent; exports.createDatabaseSessionService = createDatabaseSessionService; exports.createFunctionTool = createFunctionTool; exports.createMysqlSessionService = createMysqlSessionService; exports.createPostgresSessionService = createPostgresSessionService; exports.createSamplingHandler = createSamplingHandler; exports.createSqliteSessionService = createSqliteSessionService; exports.createTool = createTool; exports.generateAuthEvent = generateAuthEvent; exports.generateClientFunctionCallId = generateClientFunctionCallId; exports.getLongRunningFunctionCalls = getLongRunningFunctionCalls; exports.getMcpTools = getMcpTools; exports.handleFunctionCallsAsync = handleFunctionCallsAsync; exports.handleFunctionCallsLive = handleFunctionCallsLive; exports.identityRequestProcessor = requestProcessor5; exports.initializeTelemetry = initializeTelemetry; exports.injectSessionState = injectSessionState; exports.instructionsRequestProcessor = requestProcessor6; exports.isEnhancedAuthConfig = isEnhancedAuthConfig; exports.jsonSchemaToDeclaration = jsonSchemaToDeclaration; exports.mcpSchemaToParameters = mcpSchemaToParameters; exports.mergeAgentRun = mergeAgentRun; exports.mergeParallelFunctionResponseEvents = mergeParallelFunctionResponseEvents; exports.newInvocationContextId = newInvocationContextId; exports.nlPlanningRequestProcessor = requestProcessor7; exports.nlPlanningResponseProcessor = responseProcessor2; exports.normalizeJsonSchema = normalizeJsonSchema; exports.populateClientFunctionCallId = populateClientFunctionCallId; exports.registerProviders = registerProviders; exports.removeClientFunctionCallId = removeClientFunctionCallId; exports.requestProcessor = requestProcessor; exports.shutdownTelemetry = shutdownTelemetry; exports.telemetryService = telemetryService; exports.traceLlmCall = traceLlmCall; exports.traceToolCall = traceToolCall; exports.tracer = tracer;
|