@iqai/adk 0.0.9 → 0.0.11
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 +12 -0
- package/dist/index.d.mts +99 -41
- package/dist/index.d.ts +99 -41
- package/dist/index.js +195 -138
- package/dist/index.mjs +117 -60
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2186,6 +2186,7 @@ __export(tools_exports, {
|
|
|
2186
2186
|
LoadMemoryTool: () => LoadMemoryTool,
|
|
2187
2187
|
McpError: () => McpError,
|
|
2188
2188
|
McpErrorType: () => McpErrorType,
|
|
2189
|
+
McpSamplingHandler: () => McpSamplingHandler,
|
|
2189
2190
|
McpToolset: () => McpToolset,
|
|
2190
2191
|
ToolContext: () => ToolContext,
|
|
2191
2192
|
TransferToAgentTool: () => TransferToAgentTool,
|
|
@@ -2193,6 +2194,7 @@ __export(tools_exports, {
|
|
|
2193
2194
|
adkToMcpToolType: () => adkToMcpToolType,
|
|
2194
2195
|
buildFunctionDeclaration: () => buildFunctionDeclaration,
|
|
2195
2196
|
createFunctionTool: () => createFunctionTool,
|
|
2197
|
+
createSamplingHandler: () => createSamplingHandler,
|
|
2196
2198
|
getMcpTools: () => getMcpTools,
|
|
2197
2199
|
jsonSchemaToDeclaration: () => jsonSchemaToDeclaration,
|
|
2198
2200
|
mcpSchemaToParameters: () => mcpSchemaToParameters,
|
|
@@ -2980,14 +2982,23 @@ var McpError = class extends Error {
|
|
|
2980
2982
|
var McpSamplingHandler = (_class17 = class {
|
|
2981
2983
|
__init20() {this.logger = new Logger({ name: "McpSamplingHandler" })}
|
|
2982
2984
|
|
|
2983
|
-
constructor(
|
|
2984
|
-
this.
|
|
2985
|
+
constructor(samplingHandler) {;_class17.prototype.__init20.call(this);
|
|
2986
|
+
this.samplingHandler = samplingHandler;
|
|
2985
2987
|
}
|
|
2986
2988
|
/**
|
|
2987
2989
|
* Handle MCP sampling request and convert between formats
|
|
2988
2990
|
*/
|
|
2989
2991
|
async handleSamplingRequest(request) {
|
|
2990
2992
|
try {
|
|
2993
|
+
if (request.method !== "sampling/createMessage") {
|
|
2994
|
+
this.logger.error(
|
|
2995
|
+
`Invalid method for sampling handler: ${request.method}. Expected: sampling/createMessage`
|
|
2996
|
+
);
|
|
2997
|
+
throw new McpError(
|
|
2998
|
+
`Invalid method: ${request.method}. This handler only processes sampling/createMessage requests.`,
|
|
2999
|
+
"INVALID_REQUEST_ERROR" /* INVALID_REQUEST_ERROR */
|
|
3000
|
+
);
|
|
3001
|
+
}
|
|
2991
3002
|
const validationResult = _typesjs.CreateMessageRequestSchema.safeParse(request);
|
|
2992
3003
|
if (!validationResult.success) {
|
|
2993
3004
|
this.logger.error(
|
|
@@ -3013,19 +3024,19 @@ var McpSamplingHandler = (_class17 = class {
|
|
|
3013
3024
|
);
|
|
3014
3025
|
}
|
|
3015
3026
|
this.logger.debug("Converting MCP request to ADK format");
|
|
3016
|
-
const adkMessages = this.convertMcpMessagesToADK(
|
|
3027
|
+
const adkMessages = this.convertMcpMessagesToADK(
|
|
3028
|
+
mcpParams.messages,
|
|
3029
|
+
mcpParams.systemPrompt
|
|
3030
|
+
);
|
|
3017
3031
|
const adkRequest = {
|
|
3018
3032
|
messages: adkMessages,
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
maxTokens: mcpParams.maxTokens,
|
|
3024
|
-
stopSequences: mcpParams.stopSequences,
|
|
3025
|
-
metadata: mcpParams.metadata
|
|
3033
|
+
config: {
|
|
3034
|
+
temperature: mcpParams.temperature,
|
|
3035
|
+
max_tokens: mcpParams.maxTokens
|
|
3036
|
+
}
|
|
3026
3037
|
};
|
|
3027
3038
|
this.logger.debug("Calling ADK sampling handler");
|
|
3028
|
-
const adkResponse = await this.
|
|
3039
|
+
const adkResponse = await this.samplingHandler(adkRequest);
|
|
3029
3040
|
this.logger.debug("Converting ADK response to MCP format");
|
|
3030
3041
|
const mcpResponse = this.convertADKResponseToMcp(adkResponse);
|
|
3031
3042
|
const responseValidation = _typesjs.CreateMessageResultSchema.safeParse(mcpResponse);
|
|
@@ -3055,54 +3066,66 @@ var McpSamplingHandler = (_class17 = class {
|
|
|
3055
3066
|
/**
|
|
3056
3067
|
* Convert MCP messages to ADK message format
|
|
3057
3068
|
*/
|
|
3058
|
-
convertMcpMessagesToADK(mcpMessages) {
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
const contentParts = [];
|
|
3066
|
-
if (mcpMessage.content.text) {
|
|
3067
|
-
contentParts.push({
|
|
3068
|
-
type: "text",
|
|
3069
|
-
text: mcpMessage.content.text
|
|
3070
|
-
});
|
|
3071
|
-
}
|
|
3072
|
-
if (mcpMessage.content.data) {
|
|
3073
|
-
const mimeType = mcpMessage.content.mimeType || "image/jpeg";
|
|
3074
|
-
const dataUrl = `data:${mimeType};base64,${mcpMessage.content.data}`;
|
|
3075
|
-
contentParts.push({
|
|
3076
|
-
type: "image",
|
|
3077
|
-
image_url: {
|
|
3078
|
-
url: dataUrl
|
|
3079
|
-
}
|
|
3080
|
-
});
|
|
3081
|
-
}
|
|
3082
|
-
adkContent = contentParts.length > 0 ? contentParts : "";
|
|
3083
|
-
} else {
|
|
3084
|
-
this.logger.warn(
|
|
3085
|
-
`Unknown MCP content type: ${mcpMessage.content.type}`
|
|
3086
|
-
);
|
|
3087
|
-
adkContent = mcpMessage.content.data || "";
|
|
3088
|
-
}
|
|
3089
|
-
const adkMessage = {
|
|
3090
|
-
role: adkRole,
|
|
3091
|
-
content: adkContent
|
|
3092
|
-
};
|
|
3093
|
-
this.logger.debug(
|
|
3094
|
-
`Converted MCP message - role: ${mcpMessage.role} -> ${adkRole}, content type: ${mcpMessage.content.type}`
|
|
3095
|
-
);
|
|
3096
|
-
return adkMessage;
|
|
3069
|
+
convertMcpMessagesToADK(mcpMessages, systemPrompt) {
|
|
3070
|
+
const transformedMessages = mcpMessages.map(
|
|
3071
|
+
(mcpMessage) => this.convertSingleMcpMessageToADK(mcpMessage)
|
|
3072
|
+
);
|
|
3073
|
+
transformedMessages.unshift({
|
|
3074
|
+
role: "system",
|
|
3075
|
+
content: systemPrompt
|
|
3097
3076
|
});
|
|
3077
|
+
return transformedMessages;
|
|
3078
|
+
}
|
|
3079
|
+
/**
|
|
3080
|
+
* Convert a single MCP message to ADK message format
|
|
3081
|
+
*/
|
|
3082
|
+
convertSingleMcpMessageToADK(mcpMessage) {
|
|
3083
|
+
const adkRole = mcpMessage.role === "assistant" ? "assistant" : "user";
|
|
3084
|
+
const adkContent = this.convertMcpContentToADK(mcpMessage.content);
|
|
3085
|
+
const adkMessage = {
|
|
3086
|
+
role: adkRole,
|
|
3087
|
+
content: adkContent
|
|
3088
|
+
};
|
|
3089
|
+
this.logger.debug(
|
|
3090
|
+
`Converted MCP message - role: ${mcpMessage.role} -> ${adkRole}, content type: ${mcpMessage.content.type}`
|
|
3091
|
+
);
|
|
3092
|
+
return adkMessage;
|
|
3093
|
+
}
|
|
3094
|
+
/**
|
|
3095
|
+
* Convert MCP message content to ADK content format
|
|
3096
|
+
*/
|
|
3097
|
+
convertMcpContentToADK(mcpContent) {
|
|
3098
|
+
if (mcpContent.type === "text") {
|
|
3099
|
+
return mcpContent.text || "";
|
|
3100
|
+
}
|
|
3101
|
+
if (mcpContent.type === "image") {
|
|
3102
|
+
const contentParts = [];
|
|
3103
|
+
if (mcpContent.text) {
|
|
3104
|
+
contentParts.push({
|
|
3105
|
+
type: "text",
|
|
3106
|
+
text: mcpContent.text
|
|
3107
|
+
});
|
|
3108
|
+
}
|
|
3109
|
+
if (mcpContent.data) {
|
|
3110
|
+
const mimeType = mcpContent.mimeType || "image/jpeg";
|
|
3111
|
+
const dataUrl = `data:${mimeType};base64,${mcpContent.data}`;
|
|
3112
|
+
contentParts.push({
|
|
3113
|
+
type: "image",
|
|
3114
|
+
image_url: {
|
|
3115
|
+
url: dataUrl
|
|
3116
|
+
}
|
|
3117
|
+
});
|
|
3118
|
+
}
|
|
3119
|
+
return contentParts.length > 0 ? contentParts : "";
|
|
3120
|
+
}
|
|
3121
|
+
this.logger.warn(`Unknown MCP content type: ${mcpContent.type}`);
|
|
3122
|
+
return mcpContent.data || "";
|
|
3098
3123
|
}
|
|
3099
3124
|
/**
|
|
3100
3125
|
* Convert ADK response to MCP response format
|
|
3101
3126
|
*/
|
|
3102
3127
|
convertADKResponseToMcp(adkResponse) {
|
|
3103
3128
|
const mcpResponse = {
|
|
3104
|
-
model: adkResponse.model,
|
|
3105
|
-
stopReason: adkResponse.stopReason,
|
|
3106
3129
|
role: "assistant",
|
|
3107
3130
|
// ADK responses are always from assistant
|
|
3108
3131
|
content: {
|
|
@@ -3110,19 +3133,20 @@ var McpSamplingHandler = (_class17 = class {
|
|
|
3110
3133
|
text: adkResponse.content || ""
|
|
3111
3134
|
}
|
|
3112
3135
|
};
|
|
3113
|
-
this.logger.debug(
|
|
3114
|
-
`Converted ADK response - model: ${adkResponse.model}, content length: ${_optionalChain([adkResponse, 'access', _39 => _39.content, 'optionalAccess', _40 => _40.length]) || 0}`
|
|
3115
|
-
);
|
|
3136
|
+
this.logger.debug(`Received content: ${adkResponse.content}`);
|
|
3116
3137
|
return mcpResponse;
|
|
3117
3138
|
}
|
|
3118
3139
|
/**
|
|
3119
3140
|
* Update the ADK handler
|
|
3120
3141
|
*/
|
|
3121
3142
|
updateHandler(handler) {
|
|
3122
|
-
this.
|
|
3143
|
+
this.samplingHandler = handler;
|
|
3123
3144
|
this.logger.debug("ADK sampling handler updated");
|
|
3124
3145
|
}
|
|
3125
3146
|
}, _class17);
|
|
3147
|
+
function createSamplingHandler(handler) {
|
|
3148
|
+
return handler;
|
|
3149
|
+
}
|
|
3126
3150
|
|
|
3127
3151
|
// src/tools/mcp/utils.ts
|
|
3128
3152
|
function withRetry(fn, instance, reinitMethod, maxRetries = 1) {
|
|
@@ -3162,6 +3186,9 @@ var McpClientService = (_class18 = class {
|
|
|
3162
3186
|
__init25() {this.logger = new Logger({ name: "McpClientService" })}
|
|
3163
3187
|
constructor(config) {;_class18.prototype.__init21.call(this);_class18.prototype.__init22.call(this);_class18.prototype.__init23.call(this);_class18.prototype.__init24.call(this);_class18.prototype.__init25.call(this);
|
|
3164
3188
|
this.config = config;
|
|
3189
|
+
if (config.samplingHandler) {
|
|
3190
|
+
this.mcpSamplingHandler = new McpSamplingHandler(config.samplingHandler);
|
|
3191
|
+
}
|
|
3165
3192
|
}
|
|
3166
3193
|
/**
|
|
3167
3194
|
* Initializes and returns an MCP client based on configuration.
|
|
@@ -3190,7 +3217,9 @@ var McpClientService = (_class18 = class {
|
|
|
3190
3217
|
capabilities: {
|
|
3191
3218
|
prompts: {},
|
|
3192
3219
|
resources: {},
|
|
3193
|
-
tools: {}
|
|
3220
|
+
tools: {},
|
|
3221
|
+
sampling: {}
|
|
3222
|
+
// Enable sampling capability
|
|
3194
3223
|
}
|
|
3195
3224
|
}
|
|
3196
3225
|
);
|
|
@@ -3331,7 +3360,7 @@ var McpClientService = (_class18 = class {
|
|
|
3331
3360
|
},
|
|
3332
3361
|
this,
|
|
3333
3362
|
async (instance) => await instance.reinitialize(),
|
|
3334
|
-
_optionalChain([this, 'access',
|
|
3363
|
+
_optionalChain([this, 'access', _39 => _39.config, 'access', _40 => _40.retryOptions, 'optionalAccess', _41 => _41.maxRetries]) || 2
|
|
3335
3364
|
);
|
|
3336
3365
|
return await wrappedCall();
|
|
3337
3366
|
} catch (error) {
|
|
@@ -3396,13 +3425,13 @@ var McpClientService = (_class18 = class {
|
|
|
3396
3425
|
}
|
|
3397
3426
|
}
|
|
3398
3427
|
/**
|
|
3399
|
-
* Set
|
|
3428
|
+
* Set a new ADK sampling handler
|
|
3400
3429
|
*/
|
|
3401
3430
|
setSamplingHandler(handler) {
|
|
3402
3431
|
this.mcpSamplingHandler = new McpSamplingHandler(handler);
|
|
3403
3432
|
if (this.client) {
|
|
3404
3433
|
this.setupSamplingHandler(this.client).catch((error) => {
|
|
3405
|
-
console.error("Failed to update sampling handler:", error);
|
|
3434
|
+
console.error("Failed to update ADK sampling handler:", error);
|
|
3406
3435
|
});
|
|
3407
3436
|
}
|
|
3408
3437
|
}
|
|
@@ -3413,7 +3442,7 @@ var McpClientService = (_class18 = class {
|
|
|
3413
3442
|
this.mcpSamplingHandler = null;
|
|
3414
3443
|
if (this.client) {
|
|
3415
3444
|
try {
|
|
3416
|
-
_optionalChain([this, 'access',
|
|
3445
|
+
_optionalChain([this, 'access', _42 => _42.client, 'access', _43 => _43.removeRequestHandler, 'optionalCall', _44 => _44("sampling/createMessage")]);
|
|
3417
3446
|
} catch (error) {
|
|
3418
3447
|
console.error("Failed to remove sampling handler:", error);
|
|
3419
3448
|
}
|
|
@@ -3753,6 +3782,32 @@ var McpToolset = (_class20 = class {
|
|
|
3753
3782
|
await this.clientService.initialize();
|
|
3754
3783
|
return this.clientService;
|
|
3755
3784
|
}
|
|
3785
|
+
/**
|
|
3786
|
+
* Set a sampling handler for this MCP toolset.
|
|
3787
|
+
* This allows MCP servers to request LLM completions through your ADK agent.
|
|
3788
|
+
*
|
|
3789
|
+
* @param handler - ADK sampling handler that receives ADK-formatted messages
|
|
3790
|
+
*/
|
|
3791
|
+
setSamplingHandler(handler) {
|
|
3792
|
+
if (!this.clientService) {
|
|
3793
|
+
this.clientService = new McpClientService(this.config);
|
|
3794
|
+
}
|
|
3795
|
+
this.clientService.setSamplingHandler(handler);
|
|
3796
|
+
if (this.config.debug) {
|
|
3797
|
+
console.log("\u{1F3AF} Sampling handler set for MCP toolset");
|
|
3798
|
+
}
|
|
3799
|
+
}
|
|
3800
|
+
/**
|
|
3801
|
+
* Remove the sampling handler
|
|
3802
|
+
*/
|
|
3803
|
+
removeSamplingHandler() {
|
|
3804
|
+
if (this.clientService) {
|
|
3805
|
+
this.clientService.removeSamplingHandler();
|
|
3806
|
+
if (this.config.debug) {
|
|
3807
|
+
console.log("\u{1F6AB} Sampling handler removed from MCP toolset");
|
|
3808
|
+
}
|
|
3809
|
+
}
|
|
3810
|
+
}
|
|
3756
3811
|
/**
|
|
3757
3812
|
* Retrieves tools from the MCP server and converts them to BaseTool instances.
|
|
3758
3813
|
* Similar to Python's get_tools method.
|
|
@@ -3765,7 +3820,7 @@ var McpToolset = (_class20 = class {
|
|
|
3765
3820
|
"resource_closed_error" /* RESOURCE_CLOSED_ERROR */
|
|
3766
3821
|
);
|
|
3767
3822
|
}
|
|
3768
|
-
if (this.tools.length > 0 && !_optionalChain([this, 'access',
|
|
3823
|
+
if (this.tools.length > 0 && !_optionalChain([this, 'access', _45 => _45.config, 'access', _46 => _46.cacheConfig, 'optionalAccess', _47 => _47.enabled]) === false) {
|
|
3769
3824
|
return this.tools;
|
|
3770
3825
|
}
|
|
3771
3826
|
if (!this.clientService) {
|
|
@@ -3791,7 +3846,7 @@ var McpToolset = (_class20 = class {
|
|
|
3791
3846
|
}
|
|
3792
3847
|
}
|
|
3793
3848
|
}
|
|
3794
|
-
if (_optionalChain([this, 'access',
|
|
3849
|
+
if (_optionalChain([this, 'access', _48 => _48.config, 'access', _49 => _49.cacheConfig, 'optionalAccess', _50 => _50.enabled]) !== false) {
|
|
3795
3850
|
this.tools = tools;
|
|
3796
3851
|
}
|
|
3797
3852
|
return tools;
|
|
@@ -4095,7 +4150,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4095
4150
|
* Convert Anthropic tool calls to ADK tool calls
|
|
4096
4151
|
*/
|
|
4097
4152
|
convertToolCalls(toolUses) {
|
|
4098
|
-
if (!_optionalChain([toolUses, 'optionalAccess',
|
|
4153
|
+
if (!_optionalChain([toolUses, 'optionalAccess', _51 => _51.length])) {
|
|
4099
4154
|
return void 0;
|
|
4100
4155
|
}
|
|
4101
4156
|
return toolUses.map((toolUse) => ({
|
|
@@ -4110,7 +4165,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4110
4165
|
* Extract tool uses from response content
|
|
4111
4166
|
*/
|
|
4112
4167
|
extractToolUses(content) {
|
|
4113
|
-
if (!_optionalChain([content, 'optionalAccess',
|
|
4168
|
+
if (!_optionalChain([content, 'optionalAccess', _52 => _52.length])) return [];
|
|
4114
4169
|
const toolUses = [];
|
|
4115
4170
|
for (const block of content) {
|
|
4116
4171
|
this.logger.debug(`Processing content block of type: ${block.type}`);
|
|
@@ -4226,17 +4281,17 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4226
4281
|
const toolUses = this.extractToolUses(apiResponse.content);
|
|
4227
4282
|
const toolCalls = this.convertToolCalls(toolUses);
|
|
4228
4283
|
this.logger.debug(
|
|
4229
|
-
`- Extracted ${toolUses.length} tool uses in content and converted ${_optionalChain([toolCalls, 'optionalAccess',
|
|
4284
|
+
`- Extracted ${toolUses.length} tool uses in content and converted ${_optionalChain([toolCalls, 'optionalAccess', _53 => _53.length]) || 0} tool calls`
|
|
4230
4285
|
);
|
|
4231
4286
|
const llmResponse = new LLMResponse({
|
|
4232
4287
|
role: "assistant",
|
|
4233
4288
|
content,
|
|
4234
|
-
tool_calls: _optionalChain([toolCalls, 'optionalAccess',
|
|
4289
|
+
tool_calls: _optionalChain([toolCalls, 'optionalAccess', _54 => _54.length]) ? toolCalls : void 0,
|
|
4235
4290
|
raw_response: apiResponse
|
|
4236
4291
|
});
|
|
4237
4292
|
const logObject = {
|
|
4238
4293
|
role: llmResponse.role,
|
|
4239
|
-
content: _optionalChain([llmResponse, 'access',
|
|
4294
|
+
content: _optionalChain([llmResponse, 'access', _55 => _55.content, 'optionalAccess', _56 => _56.substring, 'call', _57 => _57(0, 50)]) + (llmResponse.content && llmResponse.content.length > 50 ? "..." : ""),
|
|
4240
4295
|
tool_calls: llmResponse.tool_calls ? `[${llmResponse.tool_calls.length} calls]` : "undefined"
|
|
4241
4296
|
};
|
|
4242
4297
|
this.logger.debug(
|
|
@@ -4271,17 +4326,17 @@ var AnthropicLLM = (_class23 = class extends BaseLLM {
|
|
|
4271
4326
|
*/
|
|
4272
4327
|
constructor(model, config) {
|
|
4273
4328
|
super(model);_class23.prototype.__init34.call(this);;
|
|
4274
|
-
this.apiKey = _optionalChain([config, 'optionalAccess',
|
|
4275
|
-
this.baseURL = _optionalChain([config, 'optionalAccess',
|
|
4329
|
+
this.apiKey = _optionalChain([config, 'optionalAccess', _58 => _58.apiKey]) || process.env.ANTHROPIC_API_KEY || "";
|
|
4330
|
+
this.baseURL = _optionalChain([config, 'optionalAccess', _59 => _59.baseURL]) || "https://api.anthropic.com/v1";
|
|
4276
4331
|
if (!this.apiKey) {
|
|
4277
4332
|
throw new Error(
|
|
4278
4333
|
"Anthropic API key is required. Provide it in config or set ANTHROPIC_API_KEY environment variable."
|
|
4279
4334
|
);
|
|
4280
4335
|
}
|
|
4281
4336
|
this.defaultParams = {
|
|
4282
|
-
temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4283
|
-
top_p: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4284
|
-
max_tokens: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4337
|
+
temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _60 => _60.defaultParams, 'optionalAccess', _61 => _61.temperature]), () => ( 0.7)),
|
|
4338
|
+
top_p: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _62 => _62.defaultParams, 'optionalAccess', _63 => _63.top_p]), () => ( 1)),
|
|
4339
|
+
max_tokens: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _64 => _64.defaultParams, 'optionalAccess', _65 => _65.max_tokens]), () => ( 1024))
|
|
4285
4340
|
};
|
|
4286
4341
|
}
|
|
4287
4342
|
/**
|
|
@@ -4367,7 +4422,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4367
4422
|
* Convert ADK function declarations to Anthropic tool format
|
|
4368
4423
|
*/
|
|
4369
4424
|
convertFunctionsToTools(functions) {
|
|
4370
|
-
if (!_optionalChain([functions, 'optionalAccess',
|
|
4425
|
+
if (!_optionalChain([functions, 'optionalAccess', _66 => _66.length])) {
|
|
4371
4426
|
return [];
|
|
4372
4427
|
}
|
|
4373
4428
|
return functions.map((func) => ({
|
|
@@ -4380,7 +4435,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4380
4435
|
* Convert Anthropic tool calls to ADK tool calls
|
|
4381
4436
|
*/
|
|
4382
4437
|
convertToolUses(toolUses) {
|
|
4383
|
-
if (!_optionalChain([toolUses, 'optionalAccess',
|
|
4438
|
+
if (!_optionalChain([toolUses, 'optionalAccess', _67 => _67.length])) {
|
|
4384
4439
|
return [];
|
|
4385
4440
|
}
|
|
4386
4441
|
return toolUses.map((toolUse) => ({
|
|
@@ -4395,7 +4450,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4395
4450
|
* Extract tool uses from response content
|
|
4396
4451
|
*/
|
|
4397
4452
|
extractToolUses(content) {
|
|
4398
|
-
if (!_optionalChain([content, 'optionalAccess',
|
|
4453
|
+
if (!_optionalChain([content, 'optionalAccess', _68 => _68.length])) return [];
|
|
4399
4454
|
const toolUses = [];
|
|
4400
4455
|
for (const block of content) {
|
|
4401
4456
|
this.logger.debug(`Processing content block of type: ${block.type}`);
|
|
@@ -4466,7 +4521,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4466
4521
|
temperature: _nullishCoalesce(llmRequest.config.temperature, () => ( this.defaultParams.temperature)),
|
|
4467
4522
|
max_tokens: _nullishCoalesce(llmRequest.config.max_tokens, () => ( this.defaultParams.max_tokens)),
|
|
4468
4523
|
top_p: _nullishCoalesce(llmRequest.config.top_p, () => ( this.defaultParams.top_p)),
|
|
4469
|
-
tools: _optionalChain([tools, 'optionalAccess',
|
|
4524
|
+
tools: _optionalChain([tools, 'optionalAccess', _69 => _69.length]) ? tools : void 0
|
|
4470
4525
|
};
|
|
4471
4526
|
this.logger.debug("API Request:", {
|
|
4472
4527
|
model: params.model,
|
|
@@ -4497,7 +4552,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4497
4552
|
});
|
|
4498
4553
|
const logObject = {
|
|
4499
4554
|
role: llmResponse.role,
|
|
4500
|
-
content: _optionalChain([llmResponse, 'access',
|
|
4555
|
+
content: _optionalChain([llmResponse, 'access', _70 => _70.content, 'optionalAccess', _71 => _71.substring, 'call', _72 => _72(0, 50)]) + (llmResponse.content && llmResponse.content.length > 50 ? "..." : ""),
|
|
4501
4556
|
tool_calls: llmResponse.tool_calls ? `[${llmResponse.tool_calls.length} calls]` : "undefined"
|
|
4502
4557
|
};
|
|
4503
4558
|
this.logger.debug(
|
|
@@ -4550,9 +4605,9 @@ var GoogleLLM = class extends BaseLLM {
|
|
|
4550
4605
|
constructor(model, config) {
|
|
4551
4606
|
super(model);
|
|
4552
4607
|
const apiKey = process.env.GOOGLE_API_KEY;
|
|
4553
|
-
const projectId = _optionalChain([config, 'optionalAccess',
|
|
4554
|
-
const location = _optionalChain([config, 'optionalAccess',
|
|
4555
|
-
const useVertexAI = _optionalChain([process, 'access',
|
|
4608
|
+
const projectId = _optionalChain([config, 'optionalAccess', _73 => _73.projectId]) || process.env.GOOGLE_CLOUD_PROJECT;
|
|
4609
|
+
const location = _optionalChain([config, 'optionalAccess', _74 => _74.location]) || process.env.GOOGLE_CLOUD_LOCATION;
|
|
4610
|
+
const useVertexAI = _optionalChain([process, 'access', _75 => _75.env, 'access', _76 => _76.USE_VERTEX_AI, 'optionalAccess', _77 => _77.toLowerCase, 'call', _78 => _78()]) === "true";
|
|
4556
4611
|
if (!useVertexAI && !apiKey) {
|
|
4557
4612
|
throw new Error(
|
|
4558
4613
|
"Google API Key is required. Provide via config or GOOGLE_API_KEY env var."
|
|
@@ -4577,9 +4632,9 @@ var GoogleLLM = class extends BaseLLM {
|
|
|
4577
4632
|
}
|
|
4578
4633
|
this.ai = new (0, _genai.GoogleGenAI)(options);
|
|
4579
4634
|
this.defaultParams = {
|
|
4580
|
-
temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4581
|
-
topP: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4582
|
-
maxOutputTokens: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4635
|
+
temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _79 => _79.defaultParams, 'optionalAccess', _80 => _80.temperature]), () => ( 0.7)),
|
|
4636
|
+
topP: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _81 => _81.defaultParams, 'optionalAccess', _82 => _82.top_p]), () => ( 1)),
|
|
4637
|
+
maxOutputTokens: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _83 => _83.defaultParams, 'optionalAccess', _84 => _84.maxOutputTokens]), () => ( 1024))
|
|
4583
4638
|
};
|
|
4584
4639
|
}
|
|
4585
4640
|
/**
|
|
@@ -4717,7 +4772,7 @@ var GoogleLLM = class extends BaseLLM {
|
|
|
4717
4772
|
);
|
|
4718
4773
|
parts.push({ text: "" });
|
|
4719
4774
|
}
|
|
4720
|
-
if (googleRole === "function" && (parts.length !== 1 || !_optionalChain([parts, 'access',
|
|
4775
|
+
if (googleRole === "function" && (parts.length !== 1 || !_optionalChain([parts, 'access', _85 => _85[0], 'optionalAccess', _86 => _86.functionResponse]))) {
|
|
4721
4776
|
console.error(
|
|
4722
4777
|
`[GoogleLLM] convertMessage - Invalid parts for 'function' role. Expected 1 functionResponse part. Got:`,
|
|
4723
4778
|
JSON.stringify(parts),
|
|
@@ -4825,13 +4880,13 @@ var GoogleLLM = class extends BaseLLM {
|
|
|
4825
4880
|
role: "assistant",
|
|
4826
4881
|
content: null
|
|
4827
4882
|
});
|
|
4828
|
-
if (typeof _optionalChain([response, 'optionalAccess',
|
|
4883
|
+
if (typeof _optionalChain([response, 'optionalAccess', _87 => _87.candidates, 'optionalAccess', _88 => _88[0], 'optionalAccess', _89 => _89.content, 'optionalAccess', _90 => _90.parts, 'optionalAccess', _91 => _91[0], 'optionalAccess', _92 => _92.text]) === "string") {
|
|
4829
4884
|
result.content = response.candidates[0].content.parts[0].text;
|
|
4830
4885
|
}
|
|
4831
|
-
if (_optionalChain([response, 'optionalAccess',
|
|
4886
|
+
if (_optionalChain([response, 'optionalAccess', _93 => _93.candidates, 'optionalAccess', _94 => _94[0], 'optionalAccess', _95 => _95.content, 'optionalAccess', _96 => _96.parts, 'optionalAccess', _97 => _97[0], 'optionalAccess', _98 => _98.text])) {
|
|
4832
4887
|
result.content = response.candidates[0].content.parts[0].text;
|
|
4833
4888
|
}
|
|
4834
|
-
if (_optionalChain([response, 'optionalAccess',
|
|
4889
|
+
if (_optionalChain([response, 'optionalAccess', _99 => _99.candidates, 'optionalAccess', _100 => _100[0], 'optionalAccess', _101 => _101.content, 'optionalAccess', _102 => _102.parts, 'optionalAccess', _103 => _103[0], 'optionalAccess', _104 => _104.functionCall])) {
|
|
4835
4890
|
const functionCall = response.candidates[0].content.parts[0].functionCall;
|
|
4836
4891
|
result.function_call = {
|
|
4837
4892
|
name: functionCall.name,
|
|
@@ -4878,10 +4933,10 @@ var GoogleLLM = class extends BaseLLM {
|
|
|
4878
4933
|
if (stream) {
|
|
4879
4934
|
const streamingResult = await this.ai.models.generateContentStream(requestOptions);
|
|
4880
4935
|
for await (const chunk of streamingResult) {
|
|
4881
|
-
if (!_optionalChain([chunk, 'access',
|
|
4936
|
+
if (!_optionalChain([chunk, 'access', _105 => _105.candidates, 'optionalAccess', _106 => _106[0], 'optionalAccess', _107 => _107.content, 'optionalAccess', _108 => _108.parts, 'optionalAccess', _109 => _109[0], 'optionalAccess', _110 => _110.text])) {
|
|
4882
4937
|
continue;
|
|
4883
4938
|
}
|
|
4884
|
-
const partialText = _optionalChain([chunk, 'access',
|
|
4939
|
+
const partialText = _optionalChain([chunk, 'access', _111 => _111.candidates, 'access', _112 => _112[0], 'optionalAccess', _113 => _113.content, 'optionalAccess', _114 => _114.parts, 'access', _115 => _115[0], 'optionalAccess', _116 => _116.text]) || "";
|
|
4885
4940
|
const partialResponse = new LLMResponse({
|
|
4886
4941
|
content: partialText,
|
|
4887
4942
|
role: "assistant",
|
|
@@ -5022,10 +5077,10 @@ var OpenAILLMConnection = (_class24 = class extends BaseLLMConnection {
|
|
|
5022
5077
|
for await (const chunk of stream) {
|
|
5023
5078
|
if (chunk.choices.length === 0) continue;
|
|
5024
5079
|
const delta = chunk.choices[0].delta;
|
|
5025
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
5080
|
+
if (_optionalChain([delta, 'optionalAccess', _117 => _117.content])) {
|
|
5026
5081
|
responseContent += delta.content;
|
|
5027
5082
|
}
|
|
5028
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
5083
|
+
if (_optionalChain([delta, 'optionalAccess', _118 => _118.function_call])) {
|
|
5029
5084
|
if (!functionCall) {
|
|
5030
5085
|
functionCall = {
|
|
5031
5086
|
name: delta.function_call.name || "",
|
|
@@ -5036,7 +5091,7 @@ var OpenAILLMConnection = (_class24 = class extends BaseLLMConnection {
|
|
|
5036
5091
|
functionCall.arguments += delta.function_call.arguments || "";
|
|
5037
5092
|
}
|
|
5038
5093
|
}
|
|
5039
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
5094
|
+
if (_optionalChain([delta, 'optionalAccess', _119 => _119.tool_calls])) {
|
|
5040
5095
|
for (const toolDelta of delta.tool_calls) {
|
|
5041
5096
|
const id = toolDelta.id || "";
|
|
5042
5097
|
let tool = toolCalls.find((t) => t.id === id);
|
|
@@ -5044,20 +5099,20 @@ var OpenAILLMConnection = (_class24 = class extends BaseLLMConnection {
|
|
|
5044
5099
|
tool = {
|
|
5045
5100
|
id,
|
|
5046
5101
|
function: {
|
|
5047
|
-
name: _optionalChain([toolDelta, 'access',
|
|
5048
|
-
arguments: _optionalChain([toolDelta, 'access',
|
|
5102
|
+
name: _optionalChain([toolDelta, 'access', _120 => _120.function, 'optionalAccess', _121 => _121.name]) || "",
|
|
5103
|
+
arguments: _optionalChain([toolDelta, 'access', _122 => _122.function, 'optionalAccess', _123 => _123.arguments]) || ""
|
|
5049
5104
|
}
|
|
5050
5105
|
};
|
|
5051
5106
|
toolCalls.push(tool);
|
|
5052
5107
|
} else {
|
|
5053
|
-
tool.function.name += _optionalChain([toolDelta, 'access',
|
|
5054
|
-
tool.function.arguments += _optionalChain([toolDelta, 'access',
|
|
5108
|
+
tool.function.name += _optionalChain([toolDelta, 'access', _124 => _124.function, 'optionalAccess', _125 => _125.name]) || "";
|
|
5109
|
+
tool.function.arguments += _optionalChain([toolDelta, 'access', _126 => _126.function, 'optionalAccess', _127 => _127.arguments]) || "";
|
|
5055
5110
|
}
|
|
5056
5111
|
}
|
|
5057
5112
|
}
|
|
5058
5113
|
if (this.responseCallback) {
|
|
5059
5114
|
const response = new LLMResponse({
|
|
5060
|
-
content: _optionalChain([delta, 'optionalAccess',
|
|
5115
|
+
content: _optionalChain([delta, 'optionalAccess', _128 => _128.content]) || null,
|
|
5061
5116
|
role: "assistant",
|
|
5062
5117
|
function_call: functionCall,
|
|
5063
5118
|
tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
|
|
@@ -5168,16 +5223,16 @@ var OpenAILLM = (_class25 = class extends BaseLLM {
|
|
|
5168
5223
|
constructor(model, config) {
|
|
5169
5224
|
super(model);_class25.prototype.__init36.call(this);;
|
|
5170
5225
|
this.client = new (0, _openai2.default)({
|
|
5171
|
-
apiKey: _optionalChain([config, 'optionalAccess',
|
|
5172
|
-
baseURL: _optionalChain([config, 'optionalAccess',
|
|
5173
|
-
organization: _optionalChain([config, 'optionalAccess',
|
|
5226
|
+
apiKey: _optionalChain([config, 'optionalAccess', _129 => _129.apiKey]) || process.env.OPENAI_API_KEY,
|
|
5227
|
+
baseURL: _optionalChain([config, 'optionalAccess', _130 => _130.baseURL]),
|
|
5228
|
+
organization: _optionalChain([config, 'optionalAccess', _131 => _131.organization])
|
|
5174
5229
|
});
|
|
5175
5230
|
this.defaultParams = {
|
|
5176
|
-
temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
5177
|
-
top_p: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
5178
|
-
max_tokens: _optionalChain([config, 'optionalAccess',
|
|
5179
|
-
frequency_penalty: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
5180
|
-
presence_penalty: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
5231
|
+
temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _132 => _132.defaultParams, 'optionalAccess', _133 => _133.temperature]), () => ( 0.7)),
|
|
5232
|
+
top_p: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _134 => _134.defaultParams, 'optionalAccess', _135 => _135.top_p]), () => ( 1)),
|
|
5233
|
+
max_tokens: _optionalChain([config, 'optionalAccess', _136 => _136.defaultParams, 'optionalAccess', _137 => _137.max_tokens]),
|
|
5234
|
+
frequency_penalty: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _138 => _138.defaultParams, 'optionalAccess', _139 => _139.frequency_penalty]), () => ( 0)),
|
|
5235
|
+
presence_penalty: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _140 => _140.defaultParams, 'optionalAccess', _141 => _141.presence_penalty]), () => ( 0))
|
|
5181
5236
|
};
|
|
5182
5237
|
}
|
|
5183
5238
|
/**
|
|
@@ -5287,16 +5342,16 @@ var OpenAILLM = (_class25 = class extends BaseLLM {
|
|
|
5287
5342
|
*/
|
|
5288
5343
|
convertResponse(response) {
|
|
5289
5344
|
const result = new LLMResponse({
|
|
5290
|
-
content: _optionalChain([response, 'access',
|
|
5291
|
-
role: _optionalChain([response, 'access',
|
|
5345
|
+
content: _optionalChain([response, 'access', _142 => _142.message, 'optionalAccess', _143 => _143.content]) || null,
|
|
5346
|
+
role: _optionalChain([response, 'access', _144 => _144.message, 'optionalAccess', _145 => _145.role]) || "assistant"
|
|
5292
5347
|
});
|
|
5293
|
-
if (_optionalChain([response, 'access',
|
|
5348
|
+
if (_optionalChain([response, 'access', _146 => _146.message, 'optionalAccess', _147 => _147.function_call])) {
|
|
5294
5349
|
result.function_call = {
|
|
5295
5350
|
name: response.message.function_call.name,
|
|
5296
5351
|
arguments: response.message.function_call.arguments
|
|
5297
5352
|
};
|
|
5298
5353
|
}
|
|
5299
|
-
if (_optionalChain([response, 'access',
|
|
5354
|
+
if (_optionalChain([response, 'access', _148 => _148.message, 'optionalAccess', _149 => _149.tool_calls])) {
|
|
5300
5355
|
result.tool_calls = response.message.tool_calls.map((tool) => ({
|
|
5301
5356
|
id: tool.id,
|
|
5302
5357
|
function: {
|
|
@@ -5314,24 +5369,24 @@ var OpenAILLM = (_class25 = class extends BaseLLM {
|
|
|
5314
5369
|
this.logger.debug(
|
|
5315
5370
|
`Converting chunk - delta: ${JSON.stringify(chunk.delta || {})}`
|
|
5316
5371
|
);
|
|
5317
|
-
const content = _optionalChain([chunk, 'access',
|
|
5372
|
+
const content = _optionalChain([chunk, 'access', _150 => _150.delta, 'optionalAccess', _151 => _151.content]);
|
|
5318
5373
|
const result = new LLMResponse({
|
|
5319
5374
|
content: content !== void 0 ? content : null,
|
|
5320
|
-
role: _optionalChain([chunk, 'access',
|
|
5375
|
+
role: _optionalChain([chunk, 'access', _152 => _152.delta, 'optionalAccess', _153 => _153.role]) || "assistant",
|
|
5321
5376
|
is_partial: true
|
|
5322
5377
|
});
|
|
5323
|
-
if (_optionalChain([chunk, 'access',
|
|
5378
|
+
if (_optionalChain([chunk, 'access', _154 => _154.delta, 'optionalAccess', _155 => _155.function_call])) {
|
|
5324
5379
|
result.function_call = {
|
|
5325
5380
|
name: chunk.delta.function_call.name || "",
|
|
5326
5381
|
arguments: chunk.delta.function_call.arguments || ""
|
|
5327
5382
|
};
|
|
5328
5383
|
}
|
|
5329
|
-
if (_optionalChain([chunk, 'access',
|
|
5384
|
+
if (_optionalChain([chunk, 'access', _156 => _156.delta, 'optionalAccess', _157 => _157.tool_calls])) {
|
|
5330
5385
|
result.tool_calls = chunk.delta.tool_calls.map((tool) => ({
|
|
5331
5386
|
id: tool.id || "",
|
|
5332
5387
|
function: {
|
|
5333
|
-
name: _optionalChain([tool, 'access',
|
|
5334
|
-
arguments: _optionalChain([tool, 'access',
|
|
5388
|
+
name: _optionalChain([tool, 'access', _158 => _158.function, 'optionalAccess', _159 => _159.name]) || "",
|
|
5389
|
+
arguments: _optionalChain([tool, 'access', _160 => _160.function, 'optionalAccess', _161 => _161.arguments]) || ""
|
|
5335
5390
|
}
|
|
5336
5391
|
}));
|
|
5337
5392
|
}
|
|
@@ -5380,7 +5435,7 @@ var OpenAILLM = (_class25 = class extends BaseLLM {
|
|
|
5380
5435
|
accumulatedContent += responseChunk.content;
|
|
5381
5436
|
}
|
|
5382
5437
|
this.logger.debug(
|
|
5383
|
-
`Chunk received - delta: "${_optionalChain([choice, 'access',
|
|
5438
|
+
`Chunk received - delta: "${_optionalChain([choice, 'access', _162 => _162.delta, 'optionalAccess', _163 => _163.content]) || ""}"`,
|
|
5384
5439
|
`responseChunk content: "${responseChunk.content || ""}"`,
|
|
5385
5440
|
`is_partial: ${responseChunk.is_partial}`,
|
|
5386
5441
|
`accumulated: "${accumulatedContent.substring(0, 30)}${accumulatedContent.length > 30 ? "..." : ""}"`
|
|
@@ -5646,7 +5701,7 @@ var OAuth2Credential = class extends AuthCredential {
|
|
|
5646
5701
|
"Cannot refresh token: no refresh token or refresh function"
|
|
5647
5702
|
);
|
|
5648
5703
|
}
|
|
5649
|
-
const result = await _optionalChain([this, 'access',
|
|
5704
|
+
const result = await _optionalChain([this, 'access', _164 => _164.refreshFunction, 'optionalCall', _165 => _165(this.refreshToken)]);
|
|
5650
5705
|
if (!result) {
|
|
5651
5706
|
throw new Error("Failed to refresh token");
|
|
5652
5707
|
}
|
|
@@ -5700,7 +5755,7 @@ var AuthHandler = class {
|
|
|
5700
5755
|
* Gets the authentication token
|
|
5701
5756
|
*/
|
|
5702
5757
|
getToken() {
|
|
5703
|
-
return _optionalChain([this, 'access',
|
|
5758
|
+
return _optionalChain([this, 'access', _166 => _166.credential, 'optionalAccess', _167 => _167.getToken, 'call', _168 => _168()]);
|
|
5704
5759
|
}
|
|
5705
5760
|
/**
|
|
5706
5761
|
* Gets headers for HTTP requests
|
|
@@ -5715,7 +5770,7 @@ var AuthHandler = class {
|
|
|
5715
5770
|
* Refreshes the token if necessary
|
|
5716
5771
|
*/
|
|
5717
5772
|
async refreshToken() {
|
|
5718
|
-
if (_optionalChain([this, 'access',
|
|
5773
|
+
if (_optionalChain([this, 'access', _169 => _169.credential, 'optionalAccess', _170 => _170.canRefresh, 'call', _171 => _171()])) {
|
|
5719
5774
|
await this.credential.refresh();
|
|
5720
5775
|
}
|
|
5721
5776
|
}
|
|
@@ -5941,7 +5996,7 @@ var InMemoryMemoryService = class {
|
|
|
5941
5996
|
};
|
|
5942
5997
|
const normalizedQuery = query.toLowerCase().trim();
|
|
5943
5998
|
const queryTerms = normalizedQuery.split(/\s+/);
|
|
5944
|
-
const sessionsToSearch = _optionalChain([options, 'optionalAccess',
|
|
5999
|
+
const sessionsToSearch = _optionalChain([options, 'optionalAccess', _172 => _172.sessionId]) ? this.sessions.has(options.sessionId) ? [this.sessions.get(options.sessionId)] : [] : Array.from(this.sessions.values());
|
|
5945
6000
|
for (const session of sessionsToSearch) {
|
|
5946
6001
|
const matchedEvents = [];
|
|
5947
6002
|
const scores = [];
|
|
@@ -5967,7 +6022,7 @@ var InMemoryMemoryService = class {
|
|
|
5967
6022
|
}
|
|
5968
6023
|
}
|
|
5969
6024
|
const score = queryTerms.length > 0 ? termMatches / queryTerms.length : 0;
|
|
5970
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6025
|
+
if (_optionalChain([options, 'optionalAccess', _173 => _173.threshold]) !== void 0 && score < options.threshold) {
|
|
5971
6026
|
continue;
|
|
5972
6027
|
}
|
|
5973
6028
|
if (score > 0) {
|
|
@@ -5987,7 +6042,7 @@ var InMemoryMemoryService = class {
|
|
|
5987
6042
|
response.memories.sort(
|
|
5988
6043
|
(a, b) => (_nullishCoalesce(b.relevanceScore, () => ( 0))) - (_nullishCoalesce(a.relevanceScore, () => ( 0)))
|
|
5989
6044
|
);
|
|
5990
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6045
|
+
if (_optionalChain([options, 'optionalAccess', _174 => _174.limit]) !== void 0 && options.limit > 0) {
|
|
5991
6046
|
response.memories = response.memories.slice(0, options.limit);
|
|
5992
6047
|
}
|
|
5993
6048
|
return response;
|
|
@@ -6253,17 +6308,17 @@ var InMemorySessionService = class {
|
|
|
6253
6308
|
let sessions = Array.from(this.sessions.values()).filter(
|
|
6254
6309
|
(session) => session.userId === userId
|
|
6255
6310
|
);
|
|
6256
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6311
|
+
if (_optionalChain([options, 'optionalAccess', _175 => _175.createdAfter])) {
|
|
6257
6312
|
sessions = sessions.filter(
|
|
6258
6313
|
(session) => session.createdAt >= options.createdAfter
|
|
6259
6314
|
);
|
|
6260
6315
|
}
|
|
6261
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6316
|
+
if (_optionalChain([options, 'optionalAccess', _176 => _176.updatedAfter])) {
|
|
6262
6317
|
sessions = sessions.filter(
|
|
6263
6318
|
(session) => session.updatedAt >= options.updatedAfter
|
|
6264
6319
|
);
|
|
6265
6320
|
}
|
|
6266
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6321
|
+
if (_optionalChain([options, 'optionalAccess', _177 => _177.metadataFilter])) {
|
|
6267
6322
|
sessions = sessions.filter((session) => {
|
|
6268
6323
|
for (const [key, value] of Object.entries(options.metadataFilter)) {
|
|
6269
6324
|
if (session.metadata[key] !== value) {
|
|
@@ -6274,7 +6329,7 @@ var InMemorySessionService = class {
|
|
|
6274
6329
|
});
|
|
6275
6330
|
}
|
|
6276
6331
|
sessions.sort((a, b) => b.updatedAt.getTime() - a.updatedAt.getTime());
|
|
6277
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6332
|
+
if (_optionalChain([options, 'optionalAccess', _178 => _178.limit]) !== void 0 && options.limit > 0) {
|
|
6278
6333
|
sessions = sessions.slice(0, options.limit);
|
|
6279
6334
|
}
|
|
6280
6335
|
return sessions;
|
|
@@ -6309,7 +6364,7 @@ var InMemorySessionService = class {
|
|
|
6309
6364
|
if (event.is_partial) {
|
|
6310
6365
|
return event;
|
|
6311
6366
|
}
|
|
6312
|
-
if (_optionalChain([event, 'access',
|
|
6367
|
+
if (_optionalChain([event, 'access', _179 => _179.actions, 'optionalAccess', _180 => _180.stateDelta])) {
|
|
6313
6368
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
6314
6369
|
if (key.startsWith("_temp_")) {
|
|
6315
6370
|
continue;
|
|
@@ -6415,7 +6470,7 @@ var PostgresSessionService = class {
|
|
|
6415
6470
|
}
|
|
6416
6471
|
async listSessions(userId, options) {
|
|
6417
6472
|
let query = this.db.select().from(this.sessionsTable).where(_drizzleorm.eq.call(void 0, this.sessionsTable.userId, userId));
|
|
6418
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6473
|
+
if (_optionalChain([options, 'optionalAccess', _181 => _181.limit]) !== void 0 && options.limit > 0) {
|
|
6419
6474
|
query = query.limit(options.limit);
|
|
6420
6475
|
}
|
|
6421
6476
|
const results = await query;
|
|
@@ -6442,12 +6497,12 @@ var PostgresSessionService = class {
|
|
|
6442
6497
|
if (event.is_partial) {
|
|
6443
6498
|
return event;
|
|
6444
6499
|
}
|
|
6445
|
-
if (_optionalChain([event, 'access',
|
|
6500
|
+
if (_optionalChain([event, 'access', _182 => _182.actions, 'optionalAccess', _183 => _183.stateDelta])) {
|
|
6446
6501
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
6447
6502
|
if (key.startsWith("_temp_")) {
|
|
6448
6503
|
continue;
|
|
6449
6504
|
}
|
|
6450
|
-
_optionalChain([session, 'access',
|
|
6505
|
+
_optionalChain([session, 'access', _184 => _184.state, 'optionalAccess', _185 => _185.set, 'call', _186 => _186(key, value)]);
|
|
6451
6506
|
}
|
|
6452
6507
|
}
|
|
6453
6508
|
if (!session.events) {
|
|
@@ -6591,7 +6646,7 @@ var PgLiteSessionService = (_class27 = class {
|
|
|
6591
6646
|
async listSessions(userId, options) {
|
|
6592
6647
|
await this.ensureInitialized();
|
|
6593
6648
|
let query = this.db.select().from(this.sessionsTable).where(_drizzleorm.eq.call(void 0, this.sessionsTable.userId, userId));
|
|
6594
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6649
|
+
if (_optionalChain([options, 'optionalAccess', _187 => _187.limit]) !== void 0 && options.limit > 0) {
|
|
6595
6650
|
query = query.limit(options.limit);
|
|
6596
6651
|
}
|
|
6597
6652
|
const results = await query;
|
|
@@ -6614,12 +6669,12 @@ var PgLiteSessionService = (_class27 = class {
|
|
|
6614
6669
|
if (event.is_partial) {
|
|
6615
6670
|
return event;
|
|
6616
6671
|
}
|
|
6617
|
-
if (_optionalChain([event, 'access',
|
|
6672
|
+
if (_optionalChain([event, 'access', _188 => _188.actions, 'optionalAccess', _189 => _189.stateDelta])) {
|
|
6618
6673
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
6619
6674
|
if (key.startsWith("_temp_")) {
|
|
6620
6675
|
continue;
|
|
6621
6676
|
}
|
|
6622
|
-
_optionalChain([session, 'access',
|
|
6677
|
+
_optionalChain([session, 'access', _190 => _190.state, 'optionalAccess', _191 => _191.set, 'call', _192 => _192(key, value)]);
|
|
6623
6678
|
}
|
|
6624
6679
|
}
|
|
6625
6680
|
if (!session.events) {
|
|
@@ -6776,7 +6831,7 @@ var SqliteSessionService = (_class28 = class {
|
|
|
6776
6831
|
async listSessions(userId, options) {
|
|
6777
6832
|
await this.ensureInitialized();
|
|
6778
6833
|
let query = this.db.select().from(this.sessionsTable).where(_drizzleorm.eq.call(void 0, this.sessionsTable.userId, userId));
|
|
6779
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6834
|
+
if (_optionalChain([options, 'optionalAccess', _193 => _193.limit]) !== void 0 && options.limit > 0) {
|
|
6780
6835
|
query = query.limit(options.limit);
|
|
6781
6836
|
}
|
|
6782
6837
|
const results = await query;
|
|
@@ -6799,12 +6854,12 @@ var SqliteSessionService = (_class28 = class {
|
|
|
6799
6854
|
if (event.is_partial) {
|
|
6800
6855
|
return event;
|
|
6801
6856
|
}
|
|
6802
|
-
if (_optionalChain([event, 'access',
|
|
6857
|
+
if (_optionalChain([event, 'access', _194 => _194.actions, 'optionalAccess', _195 => _195.stateDelta])) {
|
|
6803
6858
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
6804
6859
|
if (key.startsWith("_temp_")) {
|
|
6805
6860
|
continue;
|
|
6806
6861
|
}
|
|
6807
|
-
_optionalChain([session, 'access',
|
|
6862
|
+
_optionalChain([session, 'access', _196 => _196.state, 'optionalAccess', _197 => _197.set, 'call', _198 => _198(key, value)]);
|
|
6808
6863
|
}
|
|
6809
6864
|
}
|
|
6810
6865
|
if (!session.events) {
|
|
@@ -7202,4 +7257,6 @@ var VERSION = "0.1.0";
|
|
|
7202
7257
|
|
|
7203
7258
|
|
|
7204
7259
|
|
|
7205
|
-
|
|
7260
|
+
|
|
7261
|
+
|
|
7262
|
+
exports.Agent = Agent; exports.Agents = agents_exports; exports.AnthropicLLM = AnthropicLLM; exports.AnthropicLLMConnection = AnthropicLLMConnection; 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.BaseAgent = BaseAgent; exports.BaseLLM = BaseLLM; exports.BaseLLMConnection = BaseLLMConnection; exports.BaseTool = BaseTool; exports.BasicAuthCredential = BasicAuthCredential; exports.BearerTokenCredential = BearerTokenCredential; exports.ExitLoopTool = ExitLoopTool; exports.FileOperationsTool = FileOperationsTool; exports.FunctionTool = FunctionTool; exports.GetUserChoiceTool = GetUserChoiceTool; exports.GoogleLLM = GoogleLLM; exports.GoogleSearch = GoogleSearch; exports.HttpRequestTool = HttpRequestTool; exports.HttpScheme = HttpScheme; exports.InMemoryMemoryService = InMemoryMemoryService; exports.InMemoryRunner = InMemoryRunner; exports.InMemorySessionService = InMemorySessionService; exports.InvocationContext = InvocationContext; exports.LLMRegistry = LLMRegistry; exports.LLMRequest = LLMRequest; exports.LLMResponse = LLMResponse; exports.LangGraphAgent = LangGraphAgent; exports.LoadMemoryTool = LoadMemoryTool; exports.LoopAgent = LoopAgent; exports.McpError = McpError; exports.McpErrorType = McpErrorType; exports.McpSamplingHandler = McpSamplingHandler; exports.McpToolset = McpToolset; exports.Memory = memory_exports; exports.Models = models_exports; exports.OAuth2Credential = OAuth2Credential; exports.OAuth2Scheme = OAuth2Scheme; exports.OpenAILLM = OpenAILLM; exports.OpenAILLMConnection = OpenAILLMConnection; exports.OpenIdConnectScheme = OpenIdConnectScheme; exports.ParallelAgent = ParallelAgent; exports.PersistentMemoryService = PersistentMemoryService; exports.PgLiteSessionService = PgLiteSessionService; exports.PostgresSessionService = PostgresSessionService; exports.RunConfig = RunConfig; exports.Runner = Runner; exports.SequentialAgent = SequentialAgent; exports.SessionState = SessionState; exports.Sessions = sessions_exports; exports.SqliteSessionService = SqliteSessionService; exports.StreamingMode = StreamingMode; exports.ToolContext = ToolContext; exports.Tools = tools_exports; exports.TransferToAgentTool = TransferToAgentTool; exports.UserInteractionTool = UserInteractionTool; exports.VERSION = VERSION; exports.adkToMcpToolType = adkToMcpToolType; exports.buildFunctionDeclaration = buildFunctionDeclaration; exports.cloneSession = cloneSession; exports.createFunctionTool = createFunctionTool; exports.createSamplingHandler = createSamplingHandler; exports.generateSessionId = generateSessionId; exports.getMcpTools = getMcpTools; exports.jsonSchemaToDeclaration = jsonSchemaToDeclaration; exports.mcpSchemaToParameters = mcpSchemaToParameters; exports.normalizeJsonSchema = normalizeJsonSchema; exports.registerProviders = registerProviders; exports.validateSession = validateSession;
|