@iqai/adk 0.1.9 → 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 +6 -0
- package/README.md +1 -2
- package/dist/index.d.mts +67 -14
- package/dist/index.d.ts +67 -14
- package/dist/index.js +258 -88
- package/dist/index.mjs +206 -36
- 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, {
|
|
@@ -3722,6 +3855,7 @@ __export(tools_exports, {
|
|
|
3722
3855
|
buildFunctionDeclaration: () => buildFunctionDeclaration,
|
|
3723
3856
|
createFunctionTool: () => createFunctionTool,
|
|
3724
3857
|
createSamplingHandler: () => createSamplingHandler,
|
|
3858
|
+
createTool: () => createTool,
|
|
3725
3859
|
getMcpTools: () => getMcpTools,
|
|
3726
3860
|
jsonSchemaToDeclaration: () => jsonSchemaToDeclaration,
|
|
3727
3861
|
mcpSchemaToParameters: () => mcpSchemaToParameters,
|
|
@@ -3729,6 +3863,68 @@ __export(tools_exports, {
|
|
|
3729
3863
|
});
|
|
3730
3864
|
init_base_tool();
|
|
3731
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
|
+
|
|
3732
3928
|
// src/tools/tool-context.ts
|
|
3733
3929
|
var ToolContext = class extends CallbackContext {
|
|
3734
3930
|
/**
|
|
@@ -5280,7 +5476,7 @@ function mcpSchemaToParameters(mcpTool) {
|
|
|
5280
5476
|
}
|
|
5281
5477
|
|
|
5282
5478
|
// src/tools/mcp/create-tool.ts
|
|
5283
|
-
async function
|
|
5479
|
+
async function createTool2(mcpTool, client) {
|
|
5284
5480
|
try {
|
|
5285
5481
|
return new McpToolAdapter(mcpTool, client);
|
|
5286
5482
|
} catch (error) {
|
|
@@ -5614,7 +5810,7 @@ var McpToolset = class {
|
|
|
5614
5810
|
for (const mcpTool of toolsResponse.tools) {
|
|
5615
5811
|
if (this.isSelected(mcpTool, context)) {
|
|
5616
5812
|
try {
|
|
5617
|
-
const tool = await
|
|
5813
|
+
const tool = await createTool2(mcpTool, client);
|
|
5618
5814
|
tools.push(tool);
|
|
5619
5815
|
} catch (toolError) {
|
|
5620
5816
|
console.error(
|
|
@@ -6150,7 +6346,7 @@ var BaseLlmFlow = class {
|
|
|
6150
6346
|
}).join(", ");
|
|
6151
6347
|
const systemInstruction = llmRequest.getSystemInstructionText() || "";
|
|
6152
6348
|
const truncatedSystemInstruction = systemInstruction.length > 100 ? `${systemInstruction.substring(0, 100)}...` : systemInstruction;
|
|
6153
|
-
const contentPreview = llmRequest.contents?.length > 0 ?
|
|
6349
|
+
const contentPreview = llmRequest.contents?.length > 0 ? LogFormatter.formatContentPreview(llmRequest.contents[0]) : "none";
|
|
6154
6350
|
this.logger.debugStructured("\u{1F4E4} LLM Request", {
|
|
6155
6351
|
Model: llm.model,
|
|
6156
6352
|
Agent: invocationContext.agent.name,
|
|
@@ -6174,12 +6370,13 @@ var BaseLlmFlow = class {
|
|
|
6174
6370
|
llmResponse
|
|
6175
6371
|
);
|
|
6176
6372
|
const tokenCount = llmResponse.usageMetadata?.totalTokenCount || "unknown";
|
|
6177
|
-
const
|
|
6178
|
-
const
|
|
6373
|
+
const functionCalls = llmResponse.content?.parts?.filter((part) => part.functionCall) || [];
|
|
6374
|
+
const functionCallsDisplay = LogFormatter.formatFunctionCalls(functionCalls);
|
|
6375
|
+
const responsePreview = LogFormatter.formatResponsePreview(llmResponse);
|
|
6179
6376
|
this.logger.debugStructured("\u{1F4E5} LLM Response", {
|
|
6180
6377
|
Model: llm.model,
|
|
6181
6378
|
"Token Count": tokenCount,
|
|
6182
|
-
"Function Calls":
|
|
6379
|
+
"Function Calls": functionCallsDisplay,
|
|
6183
6380
|
"Response Preview": responsePreview,
|
|
6184
6381
|
"Finish Reason": llmResponse.finishReason || "unknown",
|
|
6185
6382
|
"Response #": responseCount,
|
|
@@ -6265,34 +6462,6 @@ var BaseLlmFlow = class {
|
|
|
6265
6462
|
}
|
|
6266
6463
|
return event;
|
|
6267
6464
|
}
|
|
6268
|
-
/**
|
|
6269
|
-
* Logs data in a visually appealing format that works well in any terminal size.
|
|
6270
|
-
* Uses vertical layout for better readability and respects debug settings.
|
|
6271
|
-
*/
|
|
6272
|
-
_formatContentPreview(content) {
|
|
6273
|
-
if (!content) return "none";
|
|
6274
|
-
if (content.parts && Array.isArray(content.parts)) {
|
|
6275
|
-
const textParts = content.parts.filter((part) => part.text).map((part) => part.text).join(" ");
|
|
6276
|
-
return textParts.length > 80 ? `${textParts.substring(0, 80)}...` : textParts || "no text content";
|
|
6277
|
-
}
|
|
6278
|
-
if (typeof content === "string") {
|
|
6279
|
-
return content.length > 80 ? `${content.substring(0, 80)}...` : content;
|
|
6280
|
-
}
|
|
6281
|
-
const stringified = JSON.stringify(content);
|
|
6282
|
-
return stringified.length > 80 ? `${stringified.substring(0, 80)}...` : stringified;
|
|
6283
|
-
}
|
|
6284
|
-
/**
|
|
6285
|
-
* Formats response content preview for debug logging
|
|
6286
|
-
*/
|
|
6287
|
-
_formatResponsePreview(llmResponse) {
|
|
6288
|
-
if (!llmResponse.content) return "none";
|
|
6289
|
-
if (llmResponse.content.parts && Array.isArray(llmResponse.content.parts)) {
|
|
6290
|
-
const textParts = llmResponse.content.parts.filter((part) => part.text).map((part) => part.text).join(" ");
|
|
6291
|
-
return textParts.length > 80 ? `${textParts.substring(0, 80)}...` : textParts || "no text content";
|
|
6292
|
-
}
|
|
6293
|
-
const stringified = JSON.stringify(llmResponse.content);
|
|
6294
|
-
return stringified.length > 80 ? `${stringified.substring(0, 80)}...` : stringified;
|
|
6295
|
-
}
|
|
6296
6465
|
__getLlm(invocationContext) {
|
|
6297
6466
|
const llm = invocationContext.agent.canonicalModel;
|
|
6298
6467
|
return llm;
|
|
@@ -11116,6 +11285,7 @@ export {
|
|
|
11116
11285
|
createPostgresSessionService,
|
|
11117
11286
|
createSamplingHandler,
|
|
11118
11287
|
createSqliteSessionService,
|
|
11288
|
+
createTool,
|
|
11119
11289
|
generateAuthEvent,
|
|
11120
11290
|
generateClientFunctionCallId,
|
|
11121
11291
|
getLongRunningFunctionCalls,
|