@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.mjs
CHANGED
|
@@ -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
|
import chalk from "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 {
|
|
37
37
|
name;
|
|
38
38
|
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
|
+
import * as z from "zod/v4";
|
|
3869
|
+
var CreatedTool = class extends BaseTool {
|
|
3870
|
+
func;
|
|
3871
|
+
schema;
|
|
3872
|
+
functionDeclaration;
|
|
3873
|
+
constructor(config) {
|
|
3874
|
+
super({
|
|
3875
|
+
name: config.name,
|
|
3876
|
+
description: config.description,
|
|
3877
|
+
isLongRunning: config.isLongRunning ?? false,
|
|
3878
|
+
shouldRetryOnFailure: config.shouldRetryOnFailure ?? false,
|
|
3879
|
+
maxRetryAttempts: 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 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 = 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 = 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 = class {
|
|
|
6137
6346
|
}).join(", ");
|
|
6138
6347
|
const systemInstruction = llmRequest.getSystemInstructionText() || "";
|
|
6139
6348
|
const truncatedSystemInstruction = systemInstruction.length > 100 ? `${systemInstruction.substring(0, 100)}...` : systemInstruction;
|
|
6140
|
-
const contentPreview = llmRequest.contents?.length > 0 ?
|
|
6349
|
+
const contentPreview = llmRequest.contents?.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 = class {
|
|
|
6161
6370
|
llmResponse
|
|
6162
6371
|
);
|
|
6163
6372
|
const tokenCount = llmResponse.usageMetadata?.totalTokenCount || "unknown";
|
|
6164
|
-
const
|
|
6165
|
-
const
|
|
6373
|
+
const functionCalls = llmResponse.content?.parts?.filter((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 = class {
|
|
|
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;
|
|
@@ -9967,7 +10149,7 @@ var AgentBuilder = 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,7 +10157,7 @@ var AgentBuilder = 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
10162
|
if (event.content?.parts && Array.isArray(event.content.parts)) {
|
|
9981
10163
|
const content = event.content.parts.map(
|
|
@@ -11049,6 +11231,7 @@ export {
|
|
|
11049
11231
|
McpAtp,
|
|
11050
11232
|
McpBamm,
|
|
11051
11233
|
McpCoinGecko,
|
|
11234
|
+
McpDiscord,
|
|
11052
11235
|
McpError,
|
|
11053
11236
|
McpErrorType,
|
|
11054
11237
|
McpFilesystem,
|
|
@@ -11102,6 +11285,7 @@ export {
|
|
|
11102
11285
|
createPostgresSessionService,
|
|
11103
11286
|
createSamplingHandler,
|
|
11104
11287
|
createSqliteSessionService,
|
|
11288
|
+
createTool,
|
|
11105
11289
|
generateAuthEvent,
|
|
11106
11290
|
generateClientFunctionCallId,
|
|
11107
11291
|
getLongRunningFunctionCalls,
|