@iqai/adk 0.1.8 → 0.1.10
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 +14 -0
- package/README.md +1 -2
- package/dist/index.d.mts +88 -19
- package/dist/index.d.ts +88 -19
- package/dist/index.js +281 -97
- package/dist/index.mjs +229 -45
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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 __defProp = Object.defineProperty;
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
@@ -25,14 +25,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
25
25
|
};
|
|
26
26
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
27
|
|
|
28
|
-
// src/
|
|
28
|
+
// src/logger/index.ts
|
|
29
29
|
var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk);
|
|
30
30
|
function isDebugEnabled() {
|
|
31
31
|
return process.env.NODE_ENV === "development" || process.env.ADK_DEBUG === "true";
|
|
32
32
|
}
|
|
33
33
|
var Logger;
|
|
34
34
|
var init_logger = __esm({
|
|
35
|
-
"src/
|
|
35
|
+
"src/logger/index.ts"() {
|
|
36
36
|
Logger = (_class = class {
|
|
37
37
|
|
|
38
38
|
__init2() {this.isDebugEnabled = isDebugEnabled()}
|
|
@@ -3685,6 +3685,139 @@ __export(events_exports, {
|
|
|
3685
3685
|
// src/flows/llm-flows/base-llm-flow.ts
|
|
3686
3686
|
init_logger();
|
|
3687
3687
|
|
|
3688
|
+
// src/logger/log-formatter.ts
|
|
3689
|
+
var LogFormatter = class _LogFormatter {
|
|
3690
|
+
/**
|
|
3691
|
+
* Formats function calls for display in logs.
|
|
3692
|
+
* Returns a comma-separated string of function names with argument previews.
|
|
3693
|
+
*
|
|
3694
|
+
* @param functionCalls Array of Parts containing function calls
|
|
3695
|
+
* @returns Formatted string representation of function calls
|
|
3696
|
+
*/
|
|
3697
|
+
static formatFunctionCalls(functionCalls) {
|
|
3698
|
+
if (!functionCalls || functionCalls.length === 0) {
|
|
3699
|
+
return "none";
|
|
3700
|
+
}
|
|
3701
|
+
return functionCalls.filter((part) => part.functionCall).map((part) => {
|
|
3702
|
+
const fc = part.functionCall;
|
|
3703
|
+
const argsPreview = fc.args ? JSON.stringify(fc.args).substring(0, 50) + (JSON.stringify(fc.args).length > 50 ? "..." : "") : "{}";
|
|
3704
|
+
return `${fc.name}(${argsPreview})`;
|
|
3705
|
+
}).join(", ");
|
|
3706
|
+
}
|
|
3707
|
+
/**
|
|
3708
|
+
* Formats content preview for debug logging.
|
|
3709
|
+
* Uses a consistent format for displaying content in logs.
|
|
3710
|
+
*
|
|
3711
|
+
* @param content Content object to format
|
|
3712
|
+
* @returns Formatted string representation of content
|
|
3713
|
+
*/
|
|
3714
|
+
static formatContentPreview(content) {
|
|
3715
|
+
if (!content) return "none";
|
|
3716
|
+
if (content.parts && Array.isArray(content.parts)) {
|
|
3717
|
+
const textParts = content.parts.filter((part) => part.text).map((part) => part.text).join(" ");
|
|
3718
|
+
return textParts.length > 80 ? `${textParts.substring(0, 80)}...` : textParts || "no text content";
|
|
3719
|
+
}
|
|
3720
|
+
const stringified = JSON.stringify(content);
|
|
3721
|
+
return stringified.length > 80 ? `${stringified.substring(0, 80)}...` : stringified;
|
|
3722
|
+
}
|
|
3723
|
+
/**
|
|
3724
|
+
* Formats response content preview for debug logging.
|
|
3725
|
+
* Specifically handles LlmResponse content structure.
|
|
3726
|
+
*
|
|
3727
|
+
* @param llmResponse LlmResponse object to format
|
|
3728
|
+
* @returns Formatted string representation of response content
|
|
3729
|
+
*/
|
|
3730
|
+
static formatResponsePreview(llmResponse) {
|
|
3731
|
+
if (!llmResponse.content) return "none";
|
|
3732
|
+
return _LogFormatter.formatContentPreview(llmResponse.content);
|
|
3733
|
+
}
|
|
3734
|
+
/**
|
|
3735
|
+
* Formats a single function call for detailed logging.
|
|
3736
|
+
* Provides more detailed formatting than formatFunctionCalls for individual calls.
|
|
3737
|
+
*
|
|
3738
|
+
* @param functionCall FunctionCall object to format
|
|
3739
|
+
* @returns Formatted string representation of the function call
|
|
3740
|
+
*/
|
|
3741
|
+
static formatSingleFunctionCall(functionCall) {
|
|
3742
|
+
const argsStr = functionCall.args ? JSON.stringify(functionCall.args, null, 2) : "{}";
|
|
3743
|
+
return `${functionCall.name}(
|
|
3744
|
+
${argsStr}
|
|
3745
|
+
)`;
|
|
3746
|
+
}
|
|
3747
|
+
/**
|
|
3748
|
+
* Formats function response for detailed logging.
|
|
3749
|
+
* Provides detailed formatting for function response objects.
|
|
3750
|
+
*
|
|
3751
|
+
* @param part Part containing function response
|
|
3752
|
+
* @returns Formatted string representation of the function response
|
|
3753
|
+
*/
|
|
3754
|
+
static formatFunctionResponse(part) {
|
|
3755
|
+
if (!part.functionResponse) return "none";
|
|
3756
|
+
const response = part.functionResponse;
|
|
3757
|
+
const responseStr = response.response ? JSON.stringify(response.response, null, 2) : "{}";
|
|
3758
|
+
return `${response.name} -> ${responseStr}`;
|
|
3759
|
+
}
|
|
3760
|
+
/**
|
|
3761
|
+
* Formats content parts for detailed inspection.
|
|
3762
|
+
* Shows the structure and content of all parts in a Content object.
|
|
3763
|
+
*
|
|
3764
|
+
* @param content Content object with parts to format
|
|
3765
|
+
* @returns Array of formatted strings, one per part
|
|
3766
|
+
*/
|
|
3767
|
+
static formatContentParts(content) {
|
|
3768
|
+
if (!content.parts) return ["no parts"];
|
|
3769
|
+
return content.parts.map((part, index) => {
|
|
3770
|
+
const partType = _LogFormatter.getPartType(part);
|
|
3771
|
+
const preview = _LogFormatter.getPartPreview(part);
|
|
3772
|
+
return `[${index}] ${partType}: ${preview}`;
|
|
3773
|
+
});
|
|
3774
|
+
}
|
|
3775
|
+
/**
|
|
3776
|
+
* Gets the type of a Part for logging purposes.
|
|
3777
|
+
*
|
|
3778
|
+
* @param part Part object to analyze
|
|
3779
|
+
* @returns String describing the part type
|
|
3780
|
+
*/
|
|
3781
|
+
static getPartType(part) {
|
|
3782
|
+
if (part.text !== void 0) return "text";
|
|
3783
|
+
if (part.functionCall !== void 0) return "function_call";
|
|
3784
|
+
if (part.functionResponse !== void 0) return "function_response";
|
|
3785
|
+
if (part.fileData !== void 0) return "file_data";
|
|
3786
|
+
if (part.executableCode !== void 0) return "executable_code";
|
|
3787
|
+
if (part.codeExecutionResult !== void 0) return "code_execution_result";
|
|
3788
|
+
return "unknown";
|
|
3789
|
+
}
|
|
3790
|
+
/**
|
|
3791
|
+
* Gets a preview of Part content for logging purposes.
|
|
3792
|
+
*
|
|
3793
|
+
* @param part Part object to preview
|
|
3794
|
+
* @returns String preview of the part content
|
|
3795
|
+
*/
|
|
3796
|
+
static getPartPreview(part) {
|
|
3797
|
+
if (part.text !== void 0) {
|
|
3798
|
+
return part.text.length > 50 ? `"${part.text.substring(0, 50)}..."` : `"${part.text}"`;
|
|
3799
|
+
}
|
|
3800
|
+
if (part.functionCall !== void 0) {
|
|
3801
|
+
return _LogFormatter.formatSingleFunctionCall(part.functionCall);
|
|
3802
|
+
}
|
|
3803
|
+
if (part.functionResponse !== void 0) {
|
|
3804
|
+
return _LogFormatter.formatFunctionResponse(part);
|
|
3805
|
+
}
|
|
3806
|
+
if (part.fileData !== void 0) {
|
|
3807
|
+
return `file: ${part.fileData.mimeType || "unknown type"}`;
|
|
3808
|
+
}
|
|
3809
|
+
if (part.executableCode !== void 0) {
|
|
3810
|
+
const code = part.executableCode.code || "";
|
|
3811
|
+
return code.length > 50 ? `"${code.substring(0, 50)}..."` : `"${code}"`;
|
|
3812
|
+
}
|
|
3813
|
+
if (part.codeExecutionResult !== void 0) {
|
|
3814
|
+
const outcome = part.codeExecutionResult.outcome || "unknown";
|
|
3815
|
+
return `execution result: ${outcome}`;
|
|
3816
|
+
}
|
|
3817
|
+
return "unknown content";
|
|
3818
|
+
}
|
|
3819
|
+
};
|
|
3820
|
+
|
|
3688
3821
|
// src/tools/index.ts
|
|
3689
3822
|
var tools_exports = {};
|
|
3690
3823
|
__export(tools_exports, {
|
|
@@ -3701,6 +3834,7 @@ __export(tools_exports, {
|
|
|
3701
3834
|
McpAtp: () => McpAtp,
|
|
3702
3835
|
McpBamm: () => McpBamm,
|
|
3703
3836
|
McpCoinGecko: () => McpCoinGecko,
|
|
3837
|
+
McpDiscord: () => McpDiscord,
|
|
3704
3838
|
McpError: () => McpError,
|
|
3705
3839
|
McpErrorType: () => McpErrorType,
|
|
3706
3840
|
McpFilesystem: () => McpFilesystem,
|
|
@@ -3721,6 +3855,7 @@ __export(tools_exports, {
|
|
|
3721
3855
|
buildFunctionDeclaration: () => buildFunctionDeclaration,
|
|
3722
3856
|
createFunctionTool: () => createFunctionTool,
|
|
3723
3857
|
createSamplingHandler: () => createSamplingHandler,
|
|
3858
|
+
createTool: () => createTool,
|
|
3724
3859
|
getMcpTools: () => getMcpTools,
|
|
3725
3860
|
jsonSchemaToDeclaration: () => jsonSchemaToDeclaration,
|
|
3726
3861
|
mcpSchemaToParameters: () => mcpSchemaToParameters,
|
|
@@ -3728,6 +3863,68 @@ __export(tools_exports, {
|
|
|
3728
3863
|
});
|
|
3729
3864
|
init_base_tool();
|
|
3730
3865
|
|
|
3866
|
+
// src/tools/base/create-tool.ts
|
|
3867
|
+
init_base_tool();
|
|
3868
|
+
var _v4 = require('zod/v4'); var z = _interopRequireWildcard(_v4);
|
|
3869
|
+
var CreatedTool = class extends BaseTool {
|
|
3870
|
+
|
|
3871
|
+
|
|
3872
|
+
|
|
3873
|
+
constructor(config) {
|
|
3874
|
+
super({
|
|
3875
|
+
name: config.name,
|
|
3876
|
+
description: config.description,
|
|
3877
|
+
isLongRunning: _nullishCoalesce(config.isLongRunning, () => ( false)),
|
|
3878
|
+
shouldRetryOnFailure: _nullishCoalesce(config.shouldRetryOnFailure, () => ( false)),
|
|
3879
|
+
maxRetryAttempts: _nullishCoalesce(config.maxRetryAttempts, () => ( 3))
|
|
3880
|
+
});
|
|
3881
|
+
this.func = config.fn;
|
|
3882
|
+
this.schema = config.schema;
|
|
3883
|
+
this.functionDeclaration = this.buildDeclaration();
|
|
3884
|
+
}
|
|
3885
|
+
/**
|
|
3886
|
+
* Executes the tool function with validation
|
|
3887
|
+
*/
|
|
3888
|
+
async runAsync(args, context) {
|
|
3889
|
+
try {
|
|
3890
|
+
const validatedArgs = this.schema.parse(args);
|
|
3891
|
+
const result = await Promise.resolve(
|
|
3892
|
+
this.func.length > 1 ? this.func(validatedArgs, context) : this.func(validatedArgs)
|
|
3893
|
+
);
|
|
3894
|
+
return _nullishCoalesce(result, () => ( {}));
|
|
3895
|
+
} catch (error) {
|
|
3896
|
+
if (error instanceof z.ZodError) {
|
|
3897
|
+
return {
|
|
3898
|
+
error: `Invalid arguments for ${this.name}: ${z.prettifyError(error)}`
|
|
3899
|
+
};
|
|
3900
|
+
}
|
|
3901
|
+
return {
|
|
3902
|
+
error: `Error executing ${this.name}: ${error instanceof Error ? error.message : String(error)}`
|
|
3903
|
+
};
|
|
3904
|
+
}
|
|
3905
|
+
}
|
|
3906
|
+
/**
|
|
3907
|
+
* Returns the function declaration for this tool
|
|
3908
|
+
*/
|
|
3909
|
+
getDeclaration() {
|
|
3910
|
+
return this.functionDeclaration;
|
|
3911
|
+
}
|
|
3912
|
+
/**
|
|
3913
|
+
* Builds the function declaration from the Zod schema
|
|
3914
|
+
*/
|
|
3915
|
+
buildDeclaration() {
|
|
3916
|
+
const parameters = z.toJSONSchema(this.schema);
|
|
3917
|
+
return {
|
|
3918
|
+
name: this.name,
|
|
3919
|
+
description: this.description,
|
|
3920
|
+
parameters
|
|
3921
|
+
};
|
|
3922
|
+
}
|
|
3923
|
+
};
|
|
3924
|
+
function createTool(config) {
|
|
3925
|
+
return new CreatedTool(config);
|
|
3926
|
+
}
|
|
3927
|
+
|
|
3731
3928
|
// src/tools/tool-context.ts
|
|
3732
3929
|
var ToolContext = class extends CallbackContext {
|
|
3733
3930
|
/**
|
|
@@ -4761,13 +4958,17 @@ var McpSamplingHandler = (_class18 = class {
|
|
|
4761
4958
|
*/
|
|
4762
4959
|
convertADKResponseToMcp(adkResponse, model) {
|
|
4763
4960
|
let responseText = "";
|
|
4764
|
-
if (adkResponse
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
}
|
|
4961
|
+
if (typeof adkResponse === "string") {
|
|
4962
|
+
responseText = adkResponse;
|
|
4963
|
+
} else {
|
|
4964
|
+
if (adkResponse.content) {
|
|
4965
|
+
if (typeof adkResponse.content === "string") {
|
|
4966
|
+
responseText = adkResponse.content;
|
|
4967
|
+
} else if (adkResponse.content.parts) {
|
|
4968
|
+
responseText = adkResponse.content.parts.map((part) => {
|
|
4969
|
+
return typeof part.text === "string" ? part.text : "";
|
|
4970
|
+
}).join("");
|
|
4971
|
+
}
|
|
4771
4972
|
}
|
|
4772
4973
|
}
|
|
4773
4974
|
const mcpResponse = {
|
|
@@ -5275,7 +5476,7 @@ function mcpSchemaToParameters(mcpTool) {
|
|
|
5275
5476
|
}
|
|
5276
5477
|
|
|
5277
5478
|
// src/tools/mcp/create-tool.ts
|
|
5278
|
-
async function
|
|
5479
|
+
async function createTool2(mcpTool, client) {
|
|
5279
5480
|
try {
|
|
5280
5481
|
return new McpToolAdapter(mcpTool, client);
|
|
5281
5482
|
} catch (error) {
|
|
@@ -5473,6 +5674,14 @@ function McpTelegram(config = {}) {
|
|
|
5473
5674
|
);
|
|
5474
5675
|
return new McpToolset(mcpConfig);
|
|
5475
5676
|
}
|
|
5677
|
+
function McpDiscord(config = {}) {
|
|
5678
|
+
const mcpConfig = createMcpConfig(
|
|
5679
|
+
"Discord MCP Client",
|
|
5680
|
+
"@iqai/mcp-discord",
|
|
5681
|
+
config
|
|
5682
|
+
);
|
|
5683
|
+
return new McpToolset(mcpConfig);
|
|
5684
|
+
}
|
|
5476
5685
|
function McpCoinGecko(config = {}) {
|
|
5477
5686
|
const mcpConfig = createMcpConfig(
|
|
5478
5687
|
"CoinGecko MCP Client",
|
|
@@ -5601,7 +5810,7 @@ var McpToolset = (_class21 = class {
|
|
|
5601
5810
|
for (const mcpTool of toolsResponse.tools) {
|
|
5602
5811
|
if (this.isSelected(mcpTool, context)) {
|
|
5603
5812
|
try {
|
|
5604
|
-
const tool = await
|
|
5813
|
+
const tool = await createTool2(mcpTool, client);
|
|
5605
5814
|
tools.push(tool);
|
|
5606
5815
|
} catch (toolError) {
|
|
5607
5816
|
console.error(
|
|
@@ -6137,7 +6346,7 @@ var BaseLlmFlow = (_class22 = class {constructor() { _class22.prototype.__init39
|
|
|
6137
6346
|
}).join(", ");
|
|
6138
6347
|
const systemInstruction = llmRequest.getSystemInstructionText() || "";
|
|
6139
6348
|
const truncatedSystemInstruction = systemInstruction.length > 100 ? `${systemInstruction.substring(0, 100)}...` : systemInstruction;
|
|
6140
|
-
const contentPreview = _optionalChain([llmRequest, 'access', _188 => _188.contents, 'optionalAccess', _189 => _189.length]) > 0 ?
|
|
6349
|
+
const contentPreview = _optionalChain([llmRequest, 'access', _188 => _188.contents, 'optionalAccess', _189 => _189.length]) > 0 ? LogFormatter.formatContentPreview(llmRequest.contents[0]) : "none";
|
|
6141
6350
|
this.logger.debugStructured("\u{1F4E4} LLM Request", {
|
|
6142
6351
|
Model: llm.model,
|
|
6143
6352
|
Agent: invocationContext.agent.name,
|
|
@@ -6161,12 +6370,13 @@ var BaseLlmFlow = (_class22 = class {constructor() { _class22.prototype.__init39
|
|
|
6161
6370
|
llmResponse
|
|
6162
6371
|
);
|
|
6163
6372
|
const tokenCount = _optionalChain([llmResponse, 'access', _195 => _195.usageMetadata, 'optionalAccess', _196 => _196.totalTokenCount]) || "unknown";
|
|
6164
|
-
const
|
|
6165
|
-
const
|
|
6373
|
+
const functionCalls = _optionalChain([llmResponse, 'access', _197 => _197.content, 'optionalAccess', _198 => _198.parts, 'optionalAccess', _199 => _199.filter, 'call', _200 => _200((part) => part.functionCall)]) || [];
|
|
6374
|
+
const functionCallsDisplay = LogFormatter.formatFunctionCalls(functionCalls);
|
|
6375
|
+
const responsePreview = LogFormatter.formatResponsePreview(llmResponse);
|
|
6166
6376
|
this.logger.debugStructured("\u{1F4E5} LLM Response", {
|
|
6167
6377
|
Model: llm.model,
|
|
6168
6378
|
"Token Count": tokenCount,
|
|
6169
|
-
"Function Calls":
|
|
6379
|
+
"Function Calls": functionCallsDisplay,
|
|
6170
6380
|
"Response Preview": responsePreview,
|
|
6171
6381
|
"Finish Reason": llmResponse.finishReason || "unknown",
|
|
6172
6382
|
"Response #": responseCount,
|
|
@@ -6252,34 +6462,6 @@ var BaseLlmFlow = (_class22 = class {constructor() { _class22.prototype.__init39
|
|
|
6252
6462
|
}
|
|
6253
6463
|
return event;
|
|
6254
6464
|
}
|
|
6255
|
-
/**
|
|
6256
|
-
* Logs data in a visually appealing format that works well in any terminal size.
|
|
6257
|
-
* Uses vertical layout for better readability and respects debug settings.
|
|
6258
|
-
*/
|
|
6259
|
-
_formatContentPreview(content) {
|
|
6260
|
-
if (!content) return "none";
|
|
6261
|
-
if (content.parts && Array.isArray(content.parts)) {
|
|
6262
|
-
const textParts = content.parts.filter((part) => part.text).map((part) => part.text).join(" ");
|
|
6263
|
-
return textParts.length > 80 ? `${textParts.substring(0, 80)}...` : textParts || "no text content";
|
|
6264
|
-
}
|
|
6265
|
-
if (typeof content === "string") {
|
|
6266
|
-
return content.length > 80 ? `${content.substring(0, 80)}...` : content;
|
|
6267
|
-
}
|
|
6268
|
-
const stringified = JSON.stringify(content);
|
|
6269
|
-
return stringified.length > 80 ? `${stringified.substring(0, 80)}...` : stringified;
|
|
6270
|
-
}
|
|
6271
|
-
/**
|
|
6272
|
-
* Formats response content preview for debug logging
|
|
6273
|
-
*/
|
|
6274
|
-
_formatResponsePreview(llmResponse) {
|
|
6275
|
-
if (!llmResponse.content) return "none";
|
|
6276
|
-
if (llmResponse.content.parts && Array.isArray(llmResponse.content.parts)) {
|
|
6277
|
-
const textParts = llmResponse.content.parts.filter((part) => part.text).map((part) => part.text).join(" ");
|
|
6278
|
-
return textParts.length > 80 ? `${textParts.substring(0, 80)}...` : textParts || "no text content";
|
|
6279
|
-
}
|
|
6280
|
-
const stringified = JSON.stringify(llmResponse.content);
|
|
6281
|
-
return stringified.length > 80 ? `${stringified.substring(0, 80)}...` : stringified;
|
|
6282
|
-
}
|
|
6283
6465
|
__getLlm(invocationContext) {
|
|
6284
6466
|
const llm = invocationContext.agent.canonicalModel;
|
|
6285
6467
|
return llm;
|
|
@@ -6332,7 +6514,7 @@ var EnhancedAuthConfig = class {
|
|
|
6332
6514
|
*/
|
|
6333
6515
|
generateCredentialKey() {
|
|
6334
6516
|
const schemeKey = this.authScheme.type || "unknown";
|
|
6335
|
-
const credentialKey = _optionalChain([this, 'access',
|
|
6517
|
+
const credentialKey = _optionalChain([this, 'access', _201 => _201.rawAuthCredential, 'optionalAccess', _202 => _202.type]) || "none";
|
|
6336
6518
|
const timestamp = Date.now();
|
|
6337
6519
|
return `adk_${schemeKey}_${credentialKey}_${timestamp}`;
|
|
6338
6520
|
}
|
|
@@ -6489,7 +6671,7 @@ var AuthLlmRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
6489
6671
|
*/
|
|
6490
6672
|
parseAndStoreAuthResponse(authHandler, invocationContext) {
|
|
6491
6673
|
try {
|
|
6492
|
-
const credentialKey = _optionalChain([authHandler, 'access',
|
|
6674
|
+
const credentialKey = _optionalChain([authHandler, 'access', _203 => _203.authConfig, 'access', _204 => _204.context, 'optionalAccess', _205 => _205.credentialKey]) || `temp:${Date.now()}`;
|
|
6493
6675
|
const fullCredentialKey = credentialKey.startsWith("temp:") ? credentialKey : `temp:${credentialKey}`;
|
|
6494
6676
|
invocationContext.session.state[fullCredentialKey] = authHandler.credential;
|
|
6495
6677
|
if (authHandler.authConfig.authScheme.type === "oauth2" || authHandler.authConfig.authScheme.type === "openIdConnect") {
|
|
@@ -6597,7 +6779,7 @@ var BuiltInCodeExecutor = class extends BaseCodeExecutor {
|
|
|
6597
6779
|
* Pre-process the LLM request for Gemini 2.0+ models to use the code execution tool
|
|
6598
6780
|
*/
|
|
6599
6781
|
processLlmRequest(llmRequest) {
|
|
6600
|
-
if (!_optionalChain([llmRequest, 'access',
|
|
6782
|
+
if (!_optionalChain([llmRequest, 'access', _206 => _206.model, 'optionalAccess', _207 => _207.startsWith, 'call', _208 => _208("gemini-2")])) {
|
|
6601
6783
|
throw new Error(
|
|
6602
6784
|
`Gemini code execution tool is not supported for model ${llmRequest.model}`
|
|
6603
6785
|
);
|
|
@@ -6642,7 +6824,7 @@ var CodeExecutionUtils = class _CodeExecutionUtils {
|
|
|
6642
6824
|
* Extracts the first code block from the content and truncates everything after it
|
|
6643
6825
|
*/
|
|
6644
6826
|
static extractCodeAndTruncateContent(content, codeBlockDelimiters) {
|
|
6645
|
-
if (!_optionalChain([content, 'optionalAccess',
|
|
6827
|
+
if (!_optionalChain([content, 'optionalAccess', _209 => _209.parts, 'optionalAccess', _210 => _210.length])) {
|
|
6646
6828
|
return null;
|
|
6647
6829
|
}
|
|
6648
6830
|
for (let idx = 0; idx < content.parts.length; idx++) {
|
|
@@ -6728,7 +6910,7 @@ ${fileNames}`);
|
|
|
6728
6910
|
* Converts the code execution parts to text parts in a Content
|
|
6729
6911
|
*/
|
|
6730
6912
|
static convertCodeExecutionParts(content, codeBlockDelimiter, executionResultDelimiters) {
|
|
6731
|
-
if (!_optionalChain([content, 'access',
|
|
6913
|
+
if (!_optionalChain([content, 'access', _211 => _211.parts, 'optionalAccess', _212 => _212.length])) {
|
|
6732
6914
|
return;
|
|
6733
6915
|
}
|
|
6734
6916
|
const lastPart = content.parts[content.parts.length - 1];
|
|
@@ -7121,7 +7303,7 @@ async function* runPostProcessor(invocationContext, llmResponse) {
|
|
|
7121
7303
|
function extractAndReplaceInlineFiles(codeExecutorContext, llmRequest) {
|
|
7122
7304
|
const allInputFiles = codeExecutorContext.getInputFiles();
|
|
7123
7305
|
const savedFileNames = new Set(allInputFiles.map((f) => f.name));
|
|
7124
|
-
for (let i = 0; i < (_optionalChain([llmRequest, 'access',
|
|
7306
|
+
for (let i = 0; i < (_optionalChain([llmRequest, 'access', _213 => _213.contents, 'optionalAccess', _214 => _214.length]) || 0); i++) {
|
|
7125
7307
|
const content = llmRequest.contents[i];
|
|
7126
7308
|
if (content.role !== "user" || !content.parts) {
|
|
7127
7309
|
continue;
|
|
@@ -7153,7 +7335,7 @@ Available file: \`${fileName}\`
|
|
|
7153
7335
|
}
|
|
7154
7336
|
function getOrSetExecutionId(invocationContext, codeExecutorContext) {
|
|
7155
7337
|
const agent = invocationContext.agent;
|
|
7156
|
-
if (!hasCodeExecutor(agent) || !_optionalChain([agent, 'access',
|
|
7338
|
+
if (!hasCodeExecutor(agent) || !_optionalChain([agent, 'access', _215 => _215.codeExecutor, 'optionalAccess', _216 => _216.stateful])) {
|
|
7157
7339
|
return void 0;
|
|
7158
7340
|
}
|
|
7159
7341
|
let executionId = codeExecutorContext.getExecutionId();
|
|
@@ -7384,7 +7566,7 @@ function rearrangeEventsForLatestFunctionResponse(events) {
|
|
|
7384
7566
|
continue;
|
|
7385
7567
|
}
|
|
7386
7568
|
const functionResponses2 = event.getFunctionResponses();
|
|
7387
|
-
if (_optionalChain([functionResponses2, 'optionalAccess',
|
|
7569
|
+
if (_optionalChain([functionResponses2, 'optionalAccess', _217 => _217.some, 'call', _218 => _218((fr) => fr.id && functionResponsesIds.has(fr.id))])) {
|
|
7388
7570
|
functionResponseEvents.push(event);
|
|
7389
7571
|
}
|
|
7390
7572
|
}
|
|
@@ -7483,7 +7665,7 @@ function mergeFunctionResponseEvents(functionResponseEvents) {
|
|
|
7483
7665
|
const partIndicesInMergedEvent = {};
|
|
7484
7666
|
for (let idx = 0; idx < partsInMergedEvent.length; idx++) {
|
|
7485
7667
|
const part = partsInMergedEvent[idx];
|
|
7486
|
-
if (_optionalChain([part, 'access',
|
|
7668
|
+
if (_optionalChain([part, 'access', _219 => _219.functionResponse, 'optionalAccess', _220 => _220.id])) {
|
|
7487
7669
|
partIndicesInMergedEvent[part.functionResponse.id] = idx;
|
|
7488
7670
|
}
|
|
7489
7671
|
}
|
|
@@ -7492,7 +7674,7 @@ function mergeFunctionResponseEvents(functionResponseEvents) {
|
|
|
7492
7674
|
throw new Error("There should be at least one function_response part.");
|
|
7493
7675
|
}
|
|
7494
7676
|
for (const part of event.content.parts) {
|
|
7495
|
-
if (_optionalChain([part, 'access',
|
|
7677
|
+
if (_optionalChain([part, 'access', _221 => _221.functionResponse, 'optionalAccess', _222 => _222.id])) {
|
|
7496
7678
|
const functionCallId = part.functionResponse.id;
|
|
7497
7679
|
if (functionCallId in partIndicesInMergedEvent) {
|
|
7498
7680
|
partsInMergedEvent[partIndicesInMergedEvent[functionCallId]] = part;
|
|
@@ -7742,7 +7924,7 @@ var PlanReActPlanner = class extends BasePlanner {
|
|
|
7742
7924
|
let firstFcPartIndex = -1;
|
|
7743
7925
|
for (let i = 0; i < responseParts.length; i++) {
|
|
7744
7926
|
if (responseParts[i].functionCall) {
|
|
7745
|
-
if (!_optionalChain([responseParts, 'access',
|
|
7927
|
+
if (!_optionalChain([responseParts, 'access', _223 => _223[i], 'access', _224 => _224.functionCall, 'optionalAccess', _225 => _225.name])) {
|
|
7746
7928
|
continue;
|
|
7747
7929
|
}
|
|
7748
7930
|
preservedParts.push(responseParts[i]);
|
|
@@ -7781,7 +7963,7 @@ var PlanReActPlanner = class extends BasePlanner {
|
|
|
7781
7963
|
* Handles non-function-call parts of the response
|
|
7782
7964
|
*/
|
|
7783
7965
|
_handleNonFunctionCallParts(responsePart, preservedParts) {
|
|
7784
|
-
if (_optionalChain([responsePart, 'access',
|
|
7966
|
+
if (_optionalChain([responsePart, 'access', _226 => _226.text, 'optionalAccess', _227 => _227.includes, 'call', _228 => _228(FINAL_ANSWER_TAG)])) {
|
|
7785
7967
|
const [reasoningText, finalAnswerText] = this._splitByLastPattern(
|
|
7786
7968
|
responsePart.text,
|
|
7787
7969
|
FINAL_ANSWER_TAG
|
|
@@ -8258,7 +8440,7 @@ var LlmAgent = (_class23 = class _LlmAgent extends BaseAgent {
|
|
|
8258
8440
|
* This matches the Python implementation's _llm_flow property
|
|
8259
8441
|
*/
|
|
8260
8442
|
get llmFlow() {
|
|
8261
|
-
if (this.disallowTransferToParent && this.disallowTransferToPeers && !_optionalChain([this, 'access',
|
|
8443
|
+
if (this.disallowTransferToParent && this.disallowTransferToPeers && !_optionalChain([this, 'access', _229 => _229.subAgents, 'optionalAccess', _230 => _230.length])) {
|
|
8262
8444
|
return new SingleFlow();
|
|
8263
8445
|
}
|
|
8264
8446
|
return new AutoFlow();
|
|
@@ -8268,7 +8450,7 @@ var LlmAgent = (_class23 = class _LlmAgent extends BaseAgent {
|
|
|
8268
8450
|
* This matches the Python implementation's __maybe_save_output_to_state
|
|
8269
8451
|
*/
|
|
8270
8452
|
maybeSaveOutputToState(event) {
|
|
8271
|
-
if (this.outputKey && event.isFinalResponse() && _optionalChain([event, 'access',
|
|
8453
|
+
if (this.outputKey && event.isFinalResponse() && _optionalChain([event, 'access', _231 => _231.content, 'optionalAccess', _232 => _232.parts])) {
|
|
8272
8454
|
const result = event.content.parts.map((part) => part.text || "").join("");
|
|
8273
8455
|
if (result) {
|
|
8274
8456
|
if (!event.actions.stateDelta) {
|
|
@@ -8631,7 +8813,7 @@ var LoopAgent = class extends BaseAgent {
|
|
|
8631
8813
|
for (const subAgent of this.subAgents) {
|
|
8632
8814
|
for await (const event of subAgent.runAsync(ctx)) {
|
|
8633
8815
|
yield event;
|
|
8634
|
-
if (_optionalChain([event, 'access',
|
|
8816
|
+
if (_optionalChain([event, 'access', _233 => _233.actions, 'optionalAccess', _234 => _234.escalate])) {
|
|
8635
8817
|
return;
|
|
8636
8818
|
}
|
|
8637
8819
|
}
|
|
@@ -8942,17 +9124,17 @@ var RunConfig = class {
|
|
|
8942
9124
|
*/
|
|
8943
9125
|
|
|
8944
9126
|
constructor(config) {
|
|
8945
|
-
this.speechConfig = _optionalChain([config, 'optionalAccess',
|
|
8946
|
-
this.responseModalities = _optionalChain([config, 'optionalAccess',
|
|
8947
|
-
this.saveInputBlobsAsArtifacts = _optionalChain([config, 'optionalAccess',
|
|
8948
|
-
this.supportCFC = _optionalChain([config, 'optionalAccess',
|
|
8949
|
-
this.streamingMode = _optionalChain([config, 'optionalAccess',
|
|
8950
|
-
this.outputAudioTranscription = _optionalChain([config, 'optionalAccess',
|
|
8951
|
-
this.inputAudioTranscription = _optionalChain([config, 'optionalAccess',
|
|
8952
|
-
this.realtimeInputConfig = _optionalChain([config, 'optionalAccess',
|
|
8953
|
-
this.enableAffectiveDialog = _optionalChain([config, 'optionalAccess',
|
|
8954
|
-
this.proactivity = _optionalChain([config, 'optionalAccess',
|
|
8955
|
-
this.maxLlmCalls = _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
9127
|
+
this.speechConfig = _optionalChain([config, 'optionalAccess', _235 => _235.speechConfig]);
|
|
9128
|
+
this.responseModalities = _optionalChain([config, 'optionalAccess', _236 => _236.responseModalities]);
|
|
9129
|
+
this.saveInputBlobsAsArtifacts = _optionalChain([config, 'optionalAccess', _237 => _237.saveInputBlobsAsArtifacts]) || false;
|
|
9130
|
+
this.supportCFC = _optionalChain([config, 'optionalAccess', _238 => _238.supportCFC]) || false;
|
|
9131
|
+
this.streamingMode = _optionalChain([config, 'optionalAccess', _239 => _239.streamingMode]) || "NONE" /* NONE */;
|
|
9132
|
+
this.outputAudioTranscription = _optionalChain([config, 'optionalAccess', _240 => _240.outputAudioTranscription]);
|
|
9133
|
+
this.inputAudioTranscription = _optionalChain([config, 'optionalAccess', _241 => _241.inputAudioTranscription]);
|
|
9134
|
+
this.realtimeInputConfig = _optionalChain([config, 'optionalAccess', _242 => _242.realtimeInputConfig]);
|
|
9135
|
+
this.enableAffectiveDialog = _optionalChain([config, 'optionalAccess', _243 => _243.enableAffectiveDialog]);
|
|
9136
|
+
this.proactivity = _optionalChain([config, 'optionalAccess', _244 => _244.proactivity]);
|
|
9137
|
+
this.maxLlmCalls = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _245 => _245.maxLlmCalls]), () => ( 500));
|
|
8956
9138
|
this.validateMaxLlmCalls();
|
|
8957
9139
|
}
|
|
8958
9140
|
/**
|
|
@@ -9096,7 +9278,7 @@ var InMemoryMemoryService = (_class28 = class {
|
|
|
9096
9278
|
}
|
|
9097
9279
|
const userSessions = this._sessionEvents.get(userKey);
|
|
9098
9280
|
const filteredEvents = session.events.filter(
|
|
9099
|
-
(event) => _optionalChain([event, 'access',
|
|
9281
|
+
(event) => _optionalChain([event, 'access', _246 => _246.content, 'optionalAccess', _247 => _247.parts])
|
|
9100
9282
|
);
|
|
9101
9283
|
userSessions.set(session.id, filteredEvents);
|
|
9102
9284
|
}
|
|
@@ -9235,7 +9417,7 @@ var InMemorySessionService = (_class29 = class extends BaseSessionService {const
|
|
|
9235
9417
|
return this.createSessionImpl(appName, userId, state, sessionId);
|
|
9236
9418
|
}
|
|
9237
9419
|
createSessionImpl(appName, userId, state, sessionId) {
|
|
9238
|
-
const finalSessionId = _optionalChain([sessionId, 'optionalAccess',
|
|
9420
|
+
const finalSessionId = _optionalChain([sessionId, 'optionalAccess', _248 => _248.trim, 'call', _249 => _249()]) || _crypto.randomUUID.call(void 0, );
|
|
9239
9421
|
const session = {
|
|
9240
9422
|
appName,
|
|
9241
9423
|
userId,
|
|
@@ -9392,7 +9574,7 @@ var InMemorySessionService = (_class29 = class extends BaseSessionService {const
|
|
|
9392
9574
|
warning(`sessionId ${sessionId} not in sessions[appName][userId]`);
|
|
9393
9575
|
return event;
|
|
9394
9576
|
}
|
|
9395
|
-
if (_optionalChain([event, 'access',
|
|
9577
|
+
if (_optionalChain([event, 'access', _250 => _250.actions, 'optionalAccess', _251 => _251.stateDelta])) {
|
|
9396
9578
|
for (const key in event.actions.stateDelta) {
|
|
9397
9579
|
const value = event.actions.stateDelta[key];
|
|
9398
9580
|
if (key.startsWith(State.APP_PREFIX)) {
|
|
@@ -9426,14 +9608,14 @@ function _findFunctionCallEventIfLastEventIsFunctionResponse(session) {
|
|
|
9426
9608
|
return null;
|
|
9427
9609
|
}
|
|
9428
9610
|
const lastEvent = events[events.length - 1];
|
|
9429
|
-
if (_optionalChain([lastEvent, 'access',
|
|
9430
|
-
const functionCallId = _optionalChain([lastEvent, 'access',
|
|
9611
|
+
if (_optionalChain([lastEvent, 'access', _252 => _252.content, 'optionalAccess', _253 => _253.parts, 'optionalAccess', _254 => _254.some, 'call', _255 => _255((part) => part.functionResponse)])) {
|
|
9612
|
+
const functionCallId = _optionalChain([lastEvent, 'access', _256 => _256.content, 'access', _257 => _257.parts, 'access', _258 => _258.find, 'call', _259 => _259(
|
|
9431
9613
|
(part) => part.functionResponse
|
|
9432
|
-
), 'optionalAccess',
|
|
9614
|
+
), 'optionalAccess', _260 => _260.functionResponse, 'optionalAccess', _261 => _261.id]);
|
|
9433
9615
|
if (!functionCallId) return null;
|
|
9434
9616
|
for (let i = events.length - 2; i >= 0; i--) {
|
|
9435
9617
|
const event = events[i];
|
|
9436
|
-
const functionCalls = _optionalChain([event, 'access',
|
|
9618
|
+
const functionCalls = _optionalChain([event, 'access', _262 => _262.getFunctionCalls, 'optionalCall', _263 => _263()]) || [];
|
|
9437
9619
|
for (const functionCall of functionCalls) {
|
|
9438
9620
|
if (functionCall.id === functionCallId) {
|
|
9439
9621
|
return event;
|
|
@@ -9621,15 +9803,15 @@ var Runner = (_class30 = class {
|
|
|
9621
9803
|
*/
|
|
9622
9804
|
_findAgentToRun(session, rootAgent) {
|
|
9623
9805
|
const event = _findFunctionCallEventIfLastEventIsFunctionResponse(session);
|
|
9624
|
-
if (_optionalChain([event, 'optionalAccess',
|
|
9806
|
+
if (_optionalChain([event, 'optionalAccess', _264 => _264.author])) {
|
|
9625
9807
|
return rootAgent.findAgent(event.author);
|
|
9626
9808
|
}
|
|
9627
|
-
const nonUserEvents = _optionalChain([session, 'access',
|
|
9809
|
+
const nonUserEvents = _optionalChain([session, 'access', _265 => _265.events, 'optionalAccess', _266 => _266.filter, 'call', _267 => _267((e) => e.author !== "user"), 'access', _268 => _268.reverse, 'call', _269 => _269()]) || [];
|
|
9628
9810
|
for (const event2 of nonUserEvents) {
|
|
9629
9811
|
if (event2.author === rootAgent.name) {
|
|
9630
9812
|
return rootAgent;
|
|
9631
9813
|
}
|
|
9632
|
-
const agent = _optionalChain([rootAgent, 'access',
|
|
9814
|
+
const agent = _optionalChain([rootAgent, 'access', _270 => _270.findSubAgent, 'optionalCall', _271 => _271(event2.author)]);
|
|
9633
9815
|
if (!agent) {
|
|
9634
9816
|
this.logger.debug(
|
|
9635
9817
|
`Event from an unknown agent: ${event2.author}, event id: ${event2.id}`
|
|
@@ -9967,7 +10149,7 @@ var AgentBuilder = (_class31 = class _AgentBuilder {
|
|
|
9967
10149
|
const sessionConfig = this.sessionConfig;
|
|
9968
10150
|
return {
|
|
9969
10151
|
async ask(message) {
|
|
9970
|
-
const
|
|
10152
|
+
const newMessage = typeof message === "string" ? { parts: [{ text: message }] } : typeof message === "object" && "contents" in message ? { parts: message.contents[message.contents.length - 1].parts } : message;
|
|
9971
10153
|
let response = "";
|
|
9972
10154
|
if (!sessionConfig) {
|
|
9973
10155
|
throw new Error("Session configuration is required");
|
|
@@ -9975,9 +10157,9 @@ var AgentBuilder = (_class31 = class _AgentBuilder {
|
|
|
9975
10157
|
for await (const event of baseRunner.runAsync({
|
|
9976
10158
|
userId: sessionConfig.userId,
|
|
9977
10159
|
sessionId: session.id,
|
|
9978
|
-
newMessage
|
|
10160
|
+
newMessage
|
|
9979
10161
|
})) {
|
|
9980
|
-
if (_optionalChain([event, 'access',
|
|
10162
|
+
if (_optionalChain([event, 'access', _272 => _272.content, 'optionalAccess', _273 => _273.parts]) && Array.isArray(event.content.parts)) {
|
|
9981
10163
|
const content = event.content.parts.map(
|
|
9982
10164
|
(part) => (part && typeof part === "object" && "text" in part ? part.text : "") || ""
|
|
9983
10165
|
).join("");
|
|
@@ -10057,7 +10239,7 @@ var VertexAiSessionService = class extends BaseSessionService {
|
|
|
10057
10239
|
path: `operations/${operationId}`,
|
|
10058
10240
|
request_dict: {}
|
|
10059
10241
|
});
|
|
10060
|
-
if (_optionalChain([lroResponse, 'optionalAccess',
|
|
10242
|
+
if (_optionalChain([lroResponse, 'optionalAccess', _274 => _274.done])) {
|
|
10061
10243
|
break;
|
|
10062
10244
|
}
|
|
10063
10245
|
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
@@ -10428,12 +10610,12 @@ var DatabaseSessionService = (_class32 = class extends BaseSessionService {
|
|
|
10428
10610
|
}
|
|
10429
10611
|
async createSession(appName, userId, state, sessionId) {
|
|
10430
10612
|
await this.ensureInitialized();
|
|
10431
|
-
const id = _optionalChain([sessionId, 'optionalAccess',
|
|
10613
|
+
const id = _optionalChain([sessionId, 'optionalAccess', _275 => _275.trim, 'call', _276 => _276()]) || this.generateSessionId();
|
|
10432
10614
|
return await this.db.transaction().execute(async (trx) => {
|
|
10433
10615
|
const appState = await trx.selectFrom("app_states").selectAll().where("app_name", "=", appName).executeTakeFirst();
|
|
10434
10616
|
const userState = await trx.selectFrom("user_states").selectAll().where("app_name", "=", appName).where("user_id", "=", userId).executeTakeFirst();
|
|
10435
|
-
let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess',
|
|
10436
|
-
let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess',
|
|
10617
|
+
let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _277 => _277.state]), {});
|
|
10618
|
+
let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _278 => _278.state]), {});
|
|
10437
10619
|
if (!appState) {
|
|
10438
10620
|
await trx.insertInto("app_states").values({
|
|
10439
10621
|
app_name: appName,
|
|
@@ -10492,21 +10674,21 @@ var DatabaseSessionService = (_class32 = class extends BaseSessionService {
|
|
|
10492
10674
|
return void 0;
|
|
10493
10675
|
}
|
|
10494
10676
|
let eventQuery = trx.selectFrom("events").selectAll().where("session_id", "=", sessionId).orderBy("timestamp", "desc");
|
|
10495
|
-
if (_optionalChain([config, 'optionalAccess',
|
|
10677
|
+
if (_optionalChain([config, 'optionalAccess', _279 => _279.afterTimestamp])) {
|
|
10496
10678
|
eventQuery = eventQuery.where(
|
|
10497
10679
|
"timestamp",
|
|
10498
10680
|
">=",
|
|
10499
10681
|
new Date(config.afterTimestamp * 1e3)
|
|
10500
10682
|
);
|
|
10501
10683
|
}
|
|
10502
|
-
if (_optionalChain([config, 'optionalAccess',
|
|
10684
|
+
if (_optionalChain([config, 'optionalAccess', _280 => _280.numRecentEvents])) {
|
|
10503
10685
|
eventQuery = eventQuery.limit(config.numRecentEvents);
|
|
10504
10686
|
}
|
|
10505
10687
|
const storageEvents = await eventQuery.execute();
|
|
10506
10688
|
const appState = await trx.selectFrom("app_states").selectAll().where("app_name", "=", appName).executeTakeFirst();
|
|
10507
10689
|
const userState = await trx.selectFrom("user_states").selectAll().where("app_name", "=", appName).where("user_id", "=", userId).executeTakeFirst();
|
|
10508
|
-
const currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess',
|
|
10509
|
-
const currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess',
|
|
10690
|
+
const currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _281 => _281.state]), {});
|
|
10691
|
+
const currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _282 => _282.state]), {});
|
|
10510
10692
|
const sessionState = this.parseJsonSafely(storageSession.state, {});
|
|
10511
10693
|
const mergedState = this.mergeState(
|
|
10512
10694
|
currentAppState,
|
|
@@ -10564,13 +10746,13 @@ var DatabaseSessionService = (_class32 = class extends BaseSessionService {
|
|
|
10564
10746
|
}
|
|
10565
10747
|
const appState = await trx.selectFrom("app_states").selectAll().where("app_name", "=", session.appName).executeTakeFirst();
|
|
10566
10748
|
const userState = await trx.selectFrom("user_states").selectAll().where("app_name", "=", session.appName).where("user_id", "=", session.userId).executeTakeFirst();
|
|
10567
|
-
let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess',
|
|
10568
|
-
let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess',
|
|
10749
|
+
let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _283 => _283.state]), {});
|
|
10750
|
+
let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _284 => _284.state]), {});
|
|
10569
10751
|
let sessionState = this.parseJsonSafely(storageSession.state, {});
|
|
10570
10752
|
let appStateDelta = {};
|
|
10571
10753
|
let userStateDelta = {};
|
|
10572
10754
|
let sessionStateDelta = {};
|
|
10573
|
-
if (_optionalChain([event, 'access',
|
|
10755
|
+
if (_optionalChain([event, 'access', _285 => _285.actions, 'optionalAccess', _286 => _286.stateDelta])) {
|
|
10574
10756
|
const deltas = this.extractStateDelta(event.actions.stateDelta);
|
|
10575
10757
|
appStateDelta = deltas.appStateDelta;
|
|
10576
10758
|
userStateDelta = deltas.userStateDelta;
|
|
@@ -10716,7 +10898,7 @@ var DatabaseSessionService = (_class32 = class extends BaseSessionService {
|
|
|
10716
10898
|
* Overrides the base class method to work with plain object state.
|
|
10717
10899
|
*/
|
|
10718
10900
|
updateSessionState(session, event) {
|
|
10719
|
-
if (!_optionalChain([event, 'access',
|
|
10901
|
+
if (!_optionalChain([event, 'access', _287 => _287.actions, 'optionalAccess', _288 => _288.stateDelta])) {
|
|
10720
10902
|
return;
|
|
10721
10903
|
}
|
|
10722
10904
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
@@ -10886,7 +11068,7 @@ var GcsArtifactService = class {
|
|
|
10886
11068
|
};
|
|
10887
11069
|
return part;
|
|
10888
11070
|
} catch (error) {
|
|
10889
|
-
if (_optionalChain([error, 'optionalAccess',
|
|
11071
|
+
if (_optionalChain([error, 'optionalAccess', _289 => _289.code]) === 404) {
|
|
10890
11072
|
return null;
|
|
10891
11073
|
}
|
|
10892
11074
|
throw error;
|
|
@@ -11130,4 +11312,6 @@ var VERSION = "0.1.0";
|
|
|
11130
11312
|
|
|
11131
11313
|
|
|
11132
11314
|
|
|
11133
|
-
|
|
11315
|
+
|
|
11316
|
+
|
|
11317
|
+
exports.AF_FUNCTION_CALL_ID_PREFIX = AF_FUNCTION_CALL_ID_PREFIX; exports.Agent = LlmAgent; exports.AgentBuilder = AgentBuilder; 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.McpNearIntentSwaps = McpNearIntentSwaps; 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;
|