@iqai/adk 0.0.2 → 0.0.4

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/dist/index.js CHANGED
@@ -114,7 +114,7 @@ var init_base_tool = __esm({
114
114
  }
115
115
  return {
116
116
  error: "Execution failed",
117
- message: _optionalChain([lastError, 'optionalAccess', _ => _.message]) || "Unknown error occurred",
117
+ message: _optionalChain([lastError, 'optionalAccess', _2 => _2.message]) || "Unknown error occurred",
118
118
  tool: this.name
119
119
  };
120
120
  }
@@ -254,14 +254,14 @@ var init_function_tool = __esm({
254
254
  * @param options Optional configuration for the tool
255
255
  */
256
256
  constructor(func, options) {
257
- const name = _optionalChain([options, 'optionalAccess', _2 => _2.name]) || func.name;
258
- const description = _optionalChain([options, 'optionalAccess', _3 => _3.description]) || _optionalChain([(func.toString().match(/\/\*\*([\s\S]*?)\*\//) || []), 'access', _4 => _4[1], 'optionalAccess', _5 => _5.trim, 'call', _6 => _6()]) || "";
257
+ const name = _optionalChain([options, 'optionalAccess', _3 => _3.name]) || func.name;
258
+ const description = _optionalChain([options, 'optionalAccess', _4 => _4.description]) || _optionalChain([(func.toString().match(/\/\*\*([\s\S]*?)\*\//) || []), 'access', _5 => _5[1], 'optionalAccess', _6 => _6.trim, 'call', _7 => _7()]) || "";
259
259
  super({
260
260
  name,
261
261
  description,
262
- isLongRunning: _optionalChain([options, 'optionalAccess', _7 => _7.isLongRunning]) || false,
263
- shouldRetryOnFailure: _optionalChain([options, 'optionalAccess', _8 => _8.shouldRetryOnFailure]) || false,
264
- maxRetryAttempts: _optionalChain([options, 'optionalAccess', _9 => _9.maxRetryAttempts]) || 3
262
+ isLongRunning: _optionalChain([options, 'optionalAccess', _8 => _8.isLongRunning]) || false,
263
+ shouldRetryOnFailure: _optionalChain([options, 'optionalAccess', _9 => _9.shouldRetryOnFailure]) || false,
264
+ maxRetryAttempts: _optionalChain([options, 'optionalAccess', _10 => _10.maxRetryAttempts]) || 3
265
265
  });
266
266
  this.mandatoryArgs = [];
267
267
  this.func = func;
@@ -587,13 +587,13 @@ var StreamingMode = /* @__PURE__ */ ((StreamingMode2) => {
587
587
  })(StreamingMode || {});
588
588
  var RunConfig = class {
589
589
  constructor(config) {
590
- this.speechConfig = _optionalChain([config, 'optionalAccess', _10 => _10.speechConfig]);
591
- this.responseModalities = _optionalChain([config, 'optionalAccess', _11 => _11.responseModalities]);
592
- this.saveInputBlobsAsArtifacts = _optionalChain([config, 'optionalAccess', _12 => _12.saveInputBlobsAsArtifacts]) || false;
593
- this.supportCFC = _optionalChain([config, 'optionalAccess', _13 => _13.supportCFC]) || false;
594
- this.streamingMode = _optionalChain([config, 'optionalAccess', _14 => _14.streamingMode]) || "NONE" /* NONE */;
590
+ this.speechConfig = _optionalChain([config, 'optionalAccess', _11 => _11.speechConfig]);
591
+ this.responseModalities = _optionalChain([config, 'optionalAccess', _12 => _12.responseModalities]);
592
+ this.saveInputBlobsAsArtifacts = _optionalChain([config, 'optionalAccess', _13 => _13.saveInputBlobsAsArtifacts]) || false;
593
+ this.supportCFC = _optionalChain([config, 'optionalAccess', _14 => _14.supportCFC]) || false;
594
+ this.streamingMode = _optionalChain([config, 'optionalAccess', _15 => _15.streamingMode]) || "NONE" /* NONE */;
595
595
  this.stream = this.streamingMode !== "NONE" /* NONE */;
596
- this.outputAudioTranscription = _optionalChain([config, 'optionalAccess', _15 => _15.outputAudioTranscription]);
596
+ this.outputAudioTranscription = _optionalChain([config, 'optionalAccess', _16 => _16.outputAudioTranscription]);
597
597
  }
598
598
  };
599
599
 
@@ -685,7 +685,7 @@ var InvocationContext = class _InvocationContext {
685
685
  session.metadata = { ...this.metadata };
686
686
  session.updatedAt = /* @__PURE__ */ new Date();
687
687
  Object.entries(this.variables).forEach(([key, value]) => {
688
- _optionalChain([session, 'optionalAccess', _16 => _16.state, 'access', _17 => _17.set, 'call', _18 => _18(key, value)]);
688
+ _optionalChain([session, 'optionalAccess', _17 => _17.state, 'access', _18 => _18.set, 'call', _19 => _19(key, value)]);
689
689
  });
690
690
  await this.sessionService.updateSession(session);
691
691
  if (this.memoryService) {
@@ -705,7 +705,7 @@ var InvocationContext = class _InvocationContext {
705
705
  }
706
706
  const searchOptions = {
707
707
  ...options,
708
- sessionId: _optionalChain([options, 'optionalAccess', _19 => _19.sessionId]) || this.sessionId
708
+ sessionId: _optionalChain([options, 'optionalAccess', _20 => _20.sessionId]) || this.sessionId
709
709
  };
710
710
  return await this.memoryService.searchMemory(query, searchOptions);
711
711
  }
@@ -1482,7 +1482,7 @@ var LoopAgent = class extends BaseAgent {
1482
1482
  messages: conditionMessages,
1483
1483
  config
1484
1484
  });
1485
- const content = _optionalChain([conditionResponse, 'access', _20 => _20.content, 'optionalAccess', _21 => _21.toLowerCase, 'call', _22 => _22()]) || "";
1485
+ const content = _optionalChain([conditionResponse, 'access', _21 => _21.content, 'optionalAccess', _22 => _22.toLowerCase, 'call', _23 => _23()]) || "";
1486
1486
  const shouldContinue = content.includes("yes") && !content.includes("no");
1487
1487
  if (process.env.DEBUG === "true") {
1488
1488
  console.log(
@@ -1886,12 +1886,12 @@ var LangGraphAgent = class extends BaseAgent {
1886
1886
  };
1887
1887
  }
1888
1888
  }
1889
- const lastNodeResult = _optionalChain([this, 'access', _23 => _23.results, 'access', _24 => _24[this.results.length - 1], 'optionalAccess', _25 => _25.result]);
1889
+ const lastNodeResult = _optionalChain([this, 'access', _24 => _24.results, 'access', _25 => _25[this.results.length - 1], 'optionalAccess', _26 => _26.result]);
1890
1890
  if (this.isLLMResponse(lastNodeResult)) {
1891
1891
  return lastNodeResult;
1892
1892
  }
1893
1893
  return {
1894
- content: `Graph execution complete. Final result from node "${_optionalChain([this, 'access', _26 => _26.results, 'access', _27 => _27[this.results.length - 1], 'optionalAccess', _28 => _28.node])}": ${typeof lastNodeResult === "string" ? lastNodeResult : JSON.stringify(lastNodeResult, null, 2)}`,
1894
+ content: `Graph execution complete. Final result from node "${_optionalChain([this, 'access', _27 => _27.results, 'access', _28 => _28[this.results.length - 1], 'optionalAccess', _29 => _29.node])}": ${typeof lastNodeResult === "string" ? lastNodeResult : JSON.stringify(lastNodeResult, null, 2)}`,
1895
1895
  role: "assistant"
1896
1896
  };
1897
1897
  }
@@ -2000,12 +2000,12 @@ Node output: ${this.extractTextContent(result.content)}` : ""}`,
2000
2000
  return;
2001
2001
  }
2002
2002
  }
2003
- const lastNodeResult = _optionalChain([this, 'access', _29 => _29.results, 'access', _30 => _30[this.results.length - 1], 'optionalAccess', _31 => _31.result]);
2003
+ const lastNodeResult = _optionalChain([this, 'access', _30 => _30.results, 'access', _31 => _31[this.results.length - 1], 'optionalAccess', _32 => _32.result]);
2004
2004
  if (this.isLLMResponse(lastNodeResult)) {
2005
2005
  yield lastNodeResult;
2006
2006
  } else {
2007
2007
  yield {
2008
- content: `Graph execution complete. Final result from node "${_optionalChain([this, 'access', _32 => _32.results, 'access', _33 => _33[this.results.length - 1], 'optionalAccess', _34 => _34.node])}": ${typeof lastNodeResult === "string" ? lastNodeResult : JSON.stringify(lastNodeResult, null, 2)}`,
2008
+ content: `Graph execution complete. Final result from node "${_optionalChain([this, 'access', _33 => _33.results, 'access', _34 => _34[this.results.length - 1], 'optionalAccess', _35 => _35.node])}": ${typeof lastNodeResult === "string" ? lastNodeResult : JSON.stringify(lastNodeResult, null, 2)}`,
2009
2009
  role: "assistant"
2010
2010
  };
2011
2011
  }
@@ -2023,11 +2023,19 @@ __export(tools_exports, {
2023
2023
  GoogleSearch: () => GoogleSearch,
2024
2024
  HttpRequestTool: () => HttpRequestTool,
2025
2025
  LoadMemoryTool: () => LoadMemoryTool,
2026
+ McpError: () => McpError,
2027
+ McpErrorType: () => McpErrorType,
2028
+ McpToolset: () => McpToolset,
2026
2029
  ToolContext: () => ToolContext,
2027
2030
  TransferToAgentTool: () => TransferToAgentTool,
2028
2031
  UserInteractionTool: () => UserInteractionTool,
2032
+ adkToMcpToolType: () => adkToMcpToolType,
2029
2033
  buildFunctionDeclaration: () => buildFunctionDeclaration,
2030
- createFunctionTool: () => createFunctionTool
2034
+ createFunctionTool: () => createFunctionTool,
2035
+ getMcpTools: () => getMcpTools,
2036
+ jsonSchemaToDeclaration: () => jsonSchemaToDeclaration,
2037
+ mcpSchemaToParameters: () => mcpSchemaToParameters,
2038
+ normalizeJsonSchema: () => normalizeJsonSchema
2031
2039
  });
2032
2040
  init_base_tool();
2033
2041
  init_function_tool();
@@ -2233,7 +2241,7 @@ var FileOperationsTool = class extends BaseTool {
2233
2241
  name: "file_operations",
2234
2242
  description: "Perform file system operations like reading, writing, and managing files"
2235
2243
  });
2236
- this.basePath = _optionalChain([options, 'optionalAccess', _35 => _35.basePath]) || process.cwd();
2244
+ this.basePath = _optionalChain([options, 'optionalAccess', _36 => _36.basePath]) || process.cwd();
2237
2245
  }
2238
2246
  /**
2239
2247
  * Get the function declaration for the tool
@@ -2756,7 +2764,7 @@ var LoadMemoryTool = class extends BaseTool {
2756
2764
  const searchResult = await context.searchMemory(args.query);
2757
2765
  return {
2758
2766
  memories: searchResult.memories || [],
2759
- count: _optionalChain([searchResult, 'access', _36 => _36.memories, 'optionalAccess', _37 => _37.length]) || 0
2767
+ count: _optionalChain([searchResult, 'access', _37 => _37.memories, 'optionalAccess', _38 => _38.length]) || 0
2760
2768
  };
2761
2769
  } catch (error) {
2762
2770
  console.error("Error searching memory:", error);
@@ -2768,6 +2776,702 @@ var LoadMemoryTool = class extends BaseTool {
2768
2776
  }
2769
2777
  };
2770
2778
 
2779
+ // src/tools/mcp/client.ts
2780
+ var _indexjs = require('@modelcontextprotocol/sdk/client/index.js');
2781
+ var _ssejs = require('@modelcontextprotocol/sdk/client/sse.js');
2782
+ var _stdiojs = require('@modelcontextprotocol/sdk/client/stdio.js');
2783
+
2784
+ // src/tools/mcp/types.ts
2785
+ var McpErrorType = /* @__PURE__ */ ((McpErrorType2) => {
2786
+ McpErrorType2["CONNECTION_ERROR"] = "connection_error";
2787
+ McpErrorType2["TOOL_EXECUTION_ERROR"] = "tool_execution_error";
2788
+ McpErrorType2["RESOURCE_CLOSED_ERROR"] = "resource_closed_error";
2789
+ McpErrorType2["TIMEOUT_ERROR"] = "timeout_error";
2790
+ McpErrorType2["INVALID_SCHEMA_ERROR"] = "invalid_schema_error";
2791
+ return McpErrorType2;
2792
+ })(McpErrorType || {});
2793
+ var McpError = class extends Error {
2794
+ constructor(message, type, originalError) {
2795
+ super(message);
2796
+ this.name = "McpError";
2797
+ this.type = type;
2798
+ this.originalError = originalError;
2799
+ }
2800
+ };
2801
+
2802
+ // src/tools/mcp/utils.ts
2803
+ function withRetry(fn, instance, reinitMethod, maxRetries = 1) {
2804
+ return async (...args) => {
2805
+ let attempt = 0;
2806
+ while (attempt <= maxRetries) {
2807
+ try {
2808
+ return await fn.apply(instance, args);
2809
+ } catch (error) {
2810
+ const isClosedResourceError = error instanceof Error && (error.message.includes("closed") || error.message.includes("ECONNRESET") || error.message.includes("socket hang up"));
2811
+ if (!isClosedResourceError || attempt >= maxRetries) {
2812
+ throw error;
2813
+ }
2814
+ console.warn(
2815
+ `Resource closed, reinitializing (attempt ${attempt + 1}/${maxRetries + 1})...`
2816
+ );
2817
+ try {
2818
+ await reinitMethod(instance);
2819
+ } catch (reinitError) {
2820
+ console.error("Error reinitializing resources:", reinitError);
2821
+ throw new Error(`Failed to reinitialize resources: ${reinitError}`);
2822
+ }
2823
+ attempt++;
2824
+ }
2825
+ }
2826
+ throw new Error("Unexpected end of retry loop");
2827
+ };
2828
+ }
2829
+
2830
+ // src/tools/mcp/client.ts
2831
+ var McpClientService = class {
2832
+ constructor(config) {
2833
+ this.client = null;
2834
+ this.transport = null;
2835
+ this.isClosing = false;
2836
+ this.config = config;
2837
+ }
2838
+ /**
2839
+ * Initializes and returns an MCP client based on configuration.
2840
+ * Will create a new client if one doesn't exist yet.
2841
+ */
2842
+ async initialize() {
2843
+ if (this.isClosing) {
2844
+ throw new McpError(
2845
+ "Cannot initialize a client that is being closed",
2846
+ "resource_closed_error" /* RESOURCE_CLOSED_ERROR */
2847
+ );
2848
+ }
2849
+ if (this.client) {
2850
+ return this.client;
2851
+ }
2852
+ try {
2853
+ if (!this.transport) {
2854
+ this.transport = await this.createTransport();
2855
+ }
2856
+ const client = new (0, _indexjs.Client)(
2857
+ {
2858
+ name: this.config.name,
2859
+ version: "0.0.1"
2860
+ },
2861
+ {
2862
+ capabilities: {
2863
+ prompts: {},
2864
+ resources: {},
2865
+ tools: {}
2866
+ }
2867
+ }
2868
+ );
2869
+ const connectPromise = client.connect(this.transport);
2870
+ if (this.config.timeout) {
2871
+ const timeoutPromise = new Promise((_, reject) => {
2872
+ setTimeout(() => {
2873
+ reject(
2874
+ new McpError(
2875
+ `MCP client connection timed out after ${this.config.timeout}ms`,
2876
+ "timeout_error" /* TIMEOUT_ERROR */
2877
+ )
2878
+ );
2879
+ }, this.config.timeout);
2880
+ });
2881
+ await Promise.race([connectPromise, timeoutPromise]);
2882
+ } else {
2883
+ await connectPromise;
2884
+ }
2885
+ if (this.config.debug) {
2886
+ console.log("\u2705 MCP client connected successfully");
2887
+ }
2888
+ this.client = client;
2889
+ return client;
2890
+ } catch (error) {
2891
+ await this.cleanupResources();
2892
+ if (!(error instanceof McpError)) {
2893
+ console.error("Failed to initialize MCP client:", error);
2894
+ throw new McpError(
2895
+ `Failed to initialize MCP client: ${error instanceof Error ? error.message : String(error)}`,
2896
+ "connection_error" /* CONNECTION_ERROR */,
2897
+ error instanceof Error ? error : void 0
2898
+ );
2899
+ }
2900
+ throw error;
2901
+ }
2902
+ }
2903
+ /**
2904
+ * Creates a transport based on the configuration.
2905
+ */
2906
+ async createTransport() {
2907
+ try {
2908
+ if (this.config.transport.mode === "sse") {
2909
+ if (this.config.debug) {
2910
+ console.log(
2911
+ "\u{1F680} Initializing MCP client in SSE mode",
2912
+ this.config.transport.serverUrl
2913
+ );
2914
+ }
2915
+ const headers = {
2916
+ ...this.config.transport.headers || {},
2917
+ ...this.config.headers || {}
2918
+ };
2919
+ return new (0, _ssejs.SSEClientTransport)(
2920
+ new URL(this.config.transport.serverUrl),
2921
+ {
2922
+ requestInit: {
2923
+ headers,
2924
+ ...this.config.timeout ? { timeout: this.config.timeout } : {}
2925
+ }
2926
+ }
2927
+ );
2928
+ }
2929
+ if (this.config.debug) {
2930
+ console.log(
2931
+ "\u{1F680} Initializing MCP client in STDIO mode",
2932
+ this.config.transport.command
2933
+ );
2934
+ }
2935
+ return new (0, _stdiojs.StdioClientTransport)({
2936
+ command: this.config.transport.command,
2937
+ args: this.config.transport.args,
2938
+ env: this.config.transport.env
2939
+ });
2940
+ } catch (error) {
2941
+ throw new McpError(
2942
+ `Failed to create transport: ${error instanceof Error ? error.message : String(error)}`,
2943
+ "connection_error" /* CONNECTION_ERROR */,
2944
+ error instanceof Error ? error : void 0
2945
+ );
2946
+ }
2947
+ }
2948
+ /**
2949
+ * Re-initializes the MCP client when a session is closed.
2950
+ * Used by the retry mechanism.
2951
+ */
2952
+ async reinitialize() {
2953
+ if (this.config.debug) {
2954
+ console.log("\u{1F504} Reinitializing MCP client after closed connection");
2955
+ }
2956
+ await this.cleanupResources();
2957
+ this.client = null;
2958
+ this.transport = null;
2959
+ await this.initialize();
2960
+ }
2961
+ /**
2962
+ * Cleans up resources associated with this client service.
2963
+ * Similar to Python's AsyncExitStack.aclose() functionality.
2964
+ */
2965
+ async cleanupResources() {
2966
+ try {
2967
+ this.isClosing = true;
2968
+ if (this.client) {
2969
+ try {
2970
+ if (typeof this.client.close === "function") {
2971
+ await this.client.close();
2972
+ }
2973
+ } catch (err) {
2974
+ }
2975
+ }
2976
+ if (this.transport && typeof this.transport.close === "function") {
2977
+ await this.transport.close();
2978
+ }
2979
+ if (this.config.debug) {
2980
+ console.log("\u{1F9F9} Cleaned up MCP client resources");
2981
+ }
2982
+ } catch (error) {
2983
+ console.error("Error cleaning up MCP resources:", error);
2984
+ } finally {
2985
+ this.client = null;
2986
+ this.transport = null;
2987
+ this.isClosing = false;
2988
+ }
2989
+ }
2990
+ /**
2991
+ * Call an MCP tool with retry capability if the session is closed.
2992
+ */
2993
+ async callTool(name, args) {
2994
+ try {
2995
+ const wrappedCall = withRetry(
2996
+ async function() {
2997
+ const client = await this.initialize();
2998
+ return client.callTool({
2999
+ name,
3000
+ arguments: args
3001
+ });
3002
+ },
3003
+ this,
3004
+ async (instance) => await instance.reinitialize(),
3005
+ _optionalChain([this, 'access', _39 => _39.config, 'access', _40 => _40.retryOptions, 'optionalAccess', _41 => _41.maxRetries]) || 2
3006
+ );
3007
+ return await wrappedCall();
3008
+ } catch (error) {
3009
+ if (!(error instanceof McpError)) {
3010
+ throw new McpError(
3011
+ `Error calling tool "${name}": ${error instanceof Error ? error.message : String(error)}`,
3012
+ "tool_execution_error" /* TOOL_EXECUTION_ERROR */,
3013
+ error instanceof Error ? error : void 0
3014
+ );
3015
+ }
3016
+ throw error;
3017
+ }
3018
+ }
3019
+ /**
3020
+ * Closes and cleans up all resources.
3021
+ * Should be called when the service is no longer needed.
3022
+ * Similar to Python's close() method.
3023
+ */
3024
+ async close() {
3025
+ if (this.config.debug) {
3026
+ console.log("\u{1F51A} Closing MCP client service");
3027
+ }
3028
+ await this.cleanupResources();
3029
+ }
3030
+ /**
3031
+ * Checks if the client is currently connected
3032
+ */
3033
+ isConnected() {
3034
+ return !!this.client && !this.isClosing;
3035
+ }
3036
+ };
3037
+
3038
+ // src/tools/mcp/create-tool.ts
3039
+ init_base_tool();
3040
+
3041
+ // src/tools/mcp/schema-conversion.ts
3042
+ function adkToMcpToolType(tool) {
3043
+ const declaration = tool.getDeclaration();
3044
+ const params = declarationToJsonSchema(declaration);
3045
+ return {
3046
+ name: tool.name,
3047
+ description: tool.description || "",
3048
+ inputSchema: {
3049
+ type: "object",
3050
+ properties: params
3051
+ }
3052
+ };
3053
+ }
3054
+ function declarationToJsonSchema(declaration) {
3055
+ if (!declaration.parameters) {
3056
+ return {};
3057
+ }
3058
+ if (declaration.parameters.properties) {
3059
+ return declaration.parameters.properties;
3060
+ }
3061
+ return declaration.parameters;
3062
+ }
3063
+ function jsonSchemaToDeclaration(name, description, schema) {
3064
+ let parameters;
3065
+ if (schema) {
3066
+ if (typeof schema === "object" && "type" in schema && typeof schema.type === "string") {
3067
+ parameters = schema;
3068
+ } else {
3069
+ parameters = {
3070
+ type: "object",
3071
+ properties: schema
3072
+ };
3073
+ }
3074
+ } else {
3075
+ parameters = {
3076
+ type: "object",
3077
+ properties: {}
3078
+ };
3079
+ }
3080
+ return {
3081
+ name,
3082
+ description,
3083
+ parameters
3084
+ };
3085
+ }
3086
+ function normalizeJsonSchema(schema) {
3087
+ if (!schema) {
3088
+ return { type: "object", properties: {} };
3089
+ }
3090
+ const normalizedSchema = { ...schema };
3091
+ if (!normalizedSchema.type) {
3092
+ normalizedSchema.type = determineSchemaType(normalizedSchema);
3093
+ }
3094
+ switch (normalizedSchema.type) {
3095
+ case "object":
3096
+ return normalizeObjectSchema(normalizedSchema);
3097
+ case "array":
3098
+ return normalizeArraySchema(normalizedSchema);
3099
+ case "string":
3100
+ return normalizeStringSchema(normalizedSchema);
3101
+ case "number":
3102
+ case "integer":
3103
+ return normalizeNumberSchema(normalizedSchema);
3104
+ case "boolean":
3105
+ return { type: "boolean" };
3106
+ case "null":
3107
+ return { type: "null" };
3108
+ default:
3109
+ return normalizedSchema;
3110
+ }
3111
+ }
3112
+ function determineSchemaType(schema) {
3113
+ if (schema.properties || schema.required || schema.additionalProperties !== void 0) {
3114
+ return "object";
3115
+ }
3116
+ if (schema.items) {
3117
+ return "array";
3118
+ }
3119
+ if (schema.enum !== void 0) {
3120
+ if (schema.enum.length === 0) return "string";
3121
+ const firstItem = schema.enum[0];
3122
+ if (typeof firstItem === "string") return "string";
3123
+ if (typeof firstItem === "number") return "number";
3124
+ if (typeof firstItem === "boolean") return "boolean";
3125
+ return "string";
3126
+ }
3127
+ if (schema.minLength !== void 0 || schema.maxLength !== void 0 || schema.pattern) {
3128
+ return "string";
3129
+ }
3130
+ if (schema.minimum !== void 0 || schema.maximum !== void 0 || schema.exclusiveMinimum !== void 0 || schema.exclusiveMaximum !== void 0) {
3131
+ return schema.multipleOf === void 0 || schema.multipleOf % 1 === 0 ? "integer" : "number";
3132
+ }
3133
+ return "object";
3134
+ }
3135
+ function normalizeObjectSchema(schema) {
3136
+ const normalizedSchema = {
3137
+ type: "object",
3138
+ properties: {}
3139
+ };
3140
+ if (schema.properties) {
3141
+ normalizedSchema.properties = {};
3142
+ for (const [key, value] of Object.entries(schema.properties)) {
3143
+ normalizedSchema.properties[key] = normalizeJsonSchema(
3144
+ value
3145
+ );
3146
+ }
3147
+ }
3148
+ if (schema.required) normalizedSchema.required = schema.required;
3149
+ if (schema.additionalProperties !== void 0)
3150
+ normalizedSchema.additionalProperties = schema.additionalProperties;
3151
+ if (schema.title) normalizedSchema.title = schema.title;
3152
+ if (schema.description) normalizedSchema.description = schema.description;
3153
+ return normalizedSchema;
3154
+ }
3155
+ function normalizeArraySchema(schema) {
3156
+ const normalizedSchema = {
3157
+ type: "array"
3158
+ };
3159
+ if (schema.items) {
3160
+ normalizedSchema.items = normalizeJsonSchema(
3161
+ schema.items
3162
+ );
3163
+ }
3164
+ if (schema.minItems !== void 0)
3165
+ normalizedSchema.minItems = schema.minItems;
3166
+ if (schema.maxItems !== void 0)
3167
+ normalizedSchema.maxItems = schema.maxItems;
3168
+ if (schema.uniqueItems !== void 0)
3169
+ normalizedSchema.uniqueItems = schema.uniqueItems;
3170
+ if (schema.title) normalizedSchema.title = schema.title;
3171
+ if (schema.description) normalizedSchema.description = schema.description;
3172
+ return normalizedSchema;
3173
+ }
3174
+ function normalizeStringSchema(schema) {
3175
+ const normalizedSchema = {
3176
+ type: "string"
3177
+ };
3178
+ if (schema.minLength !== void 0)
3179
+ normalizedSchema.minLength = schema.minLength;
3180
+ if (schema.maxLength !== void 0)
3181
+ normalizedSchema.maxLength = schema.maxLength;
3182
+ if (schema.pattern) normalizedSchema.pattern = schema.pattern;
3183
+ if (schema.format) normalizedSchema.format = schema.format;
3184
+ if (schema.enum) normalizedSchema.enum = schema.enum;
3185
+ if (schema.title) normalizedSchema.title = schema.title;
3186
+ if (schema.description) normalizedSchema.description = schema.description;
3187
+ return normalizedSchema;
3188
+ }
3189
+ function normalizeNumberSchema(schema) {
3190
+ const normalizedSchema = {
3191
+ type: schema.type
3192
+ };
3193
+ if (schema.minimum !== void 0) normalizedSchema.minimum = schema.minimum;
3194
+ if (schema.maximum !== void 0) normalizedSchema.maximum = schema.maximum;
3195
+ if (schema.exclusiveMinimum !== void 0)
3196
+ normalizedSchema.exclusiveMinimum = schema.exclusiveMinimum;
3197
+ if (schema.exclusiveMaximum !== void 0)
3198
+ normalizedSchema.exclusiveMaximum = schema.exclusiveMaximum;
3199
+ if (schema.multipleOf !== void 0)
3200
+ normalizedSchema.multipleOf = schema.multipleOf;
3201
+ if (schema.enum) normalizedSchema.enum = schema.enum;
3202
+ if (schema.title) normalizedSchema.title = schema.title;
3203
+ if (schema.description) normalizedSchema.description = schema.description;
3204
+ return normalizedSchema;
3205
+ }
3206
+ function mcpSchemaToParameters(mcpTool) {
3207
+ let schema;
3208
+ if (mcpTool.inputSchema) {
3209
+ schema = mcpTool.inputSchema;
3210
+ } else if (mcpTool.parameters) {
3211
+ schema = mcpTool.parameters;
3212
+ }
3213
+ if (!schema) {
3214
+ return {
3215
+ type: "object",
3216
+ properties: {}
3217
+ };
3218
+ }
3219
+ return normalizeJsonSchema(schema);
3220
+ }
3221
+
3222
+ // src/tools/mcp/create-tool.ts
3223
+ async function createTool(mcpTool, client) {
3224
+ try {
3225
+ return new McpToolAdapter(mcpTool, client);
3226
+ } catch (error) {
3227
+ if (!(error instanceof McpError)) {
3228
+ throw new McpError(
3229
+ `Failed to create tool from MCP tool: ${error instanceof Error ? error.message : String(error)}`,
3230
+ "invalid_schema_error" /* INVALID_SCHEMA_ERROR */,
3231
+ error instanceof Error ? error : void 0
3232
+ );
3233
+ }
3234
+ throw error;
3235
+ }
3236
+ }
3237
+ var McpToolAdapter = class extends BaseTool {
3238
+ constructor(mcpTool, client) {
3239
+ const metadata = mcpTool.metadata || {};
3240
+ super({
3241
+ name: mcpTool.name || `mcp_${Date.now()}`,
3242
+ description: mcpTool.description || "MCP Tool",
3243
+ isLongRunning: _nullishCoalesce(metadata.isLongRunning, () => ( false)),
3244
+ shouldRetryOnFailure: _nullishCoalesce(metadata.shouldRetryOnFailure, () => ( false)),
3245
+ maxRetryAttempts: _nullishCoalesce(metadata.maxRetryAttempts, () => ( 3))
3246
+ });
3247
+ this.clientService = null;
3248
+ this.mcpTool = mcpTool;
3249
+ this.client = client;
3250
+ if (client.reinitialize && typeof client.reinitialize === "function") {
3251
+ this.clientService = client;
3252
+ }
3253
+ }
3254
+ getDeclaration() {
3255
+ try {
3256
+ const parameters = mcpSchemaToParameters(this.mcpTool);
3257
+ return {
3258
+ name: this.name,
3259
+ description: this.description,
3260
+ parameters
3261
+ };
3262
+ } catch (error) {
3263
+ throw new McpError(
3264
+ `Failed to convert schema for tool ${this.name}: ${error instanceof Error ? error.message : String(error)}`,
3265
+ "invalid_schema_error" /* INVALID_SCHEMA_ERROR */,
3266
+ error instanceof Error ? error : void 0
3267
+ );
3268
+ }
3269
+ }
3270
+ async runAsync(args, _context) {
3271
+ if (process.env.DEBUG === "true") {
3272
+ console.log(`Executing MCP tool ${this.name} with args:`, args);
3273
+ }
3274
+ try {
3275
+ if (typeof this.mcpTool.execute === "function") {
3276
+ return await this.mcpTool.execute(args);
3277
+ }
3278
+ if (this.clientService) {
3279
+ return await this.clientService.callTool(this.name, args);
3280
+ }
3281
+ if (this.client && typeof this.client.callTool === "function") {
3282
+ if (this.shouldRetryOnFailure) {
3283
+ const executeWithRetry = withRetry(
3284
+ async () => {
3285
+ return await this.client.callTool({
3286
+ name: this.name,
3287
+ arguments: args
3288
+ });
3289
+ },
3290
+ this,
3291
+ async () => {
3292
+ console.warn(
3293
+ `MCP tool ${this.name} encountered a closed resource, but cannot reinitialize client.`
3294
+ );
3295
+ },
3296
+ this.maxRetryAttempts
3297
+ );
3298
+ return await executeWithRetry();
3299
+ }
3300
+ const result = await this.client.callTool({
3301
+ name: this.name,
3302
+ arguments: args
3303
+ });
3304
+ return result;
3305
+ }
3306
+ throw new McpError(
3307
+ `Cannot execute MCP tool ${this.name}: No execution method found`,
3308
+ "tool_execution_error" /* TOOL_EXECUTION_ERROR */
3309
+ );
3310
+ } catch (error) {
3311
+ if (!(error instanceof McpError)) {
3312
+ console.error(`Error executing MCP tool ${this.name}:`, error);
3313
+ throw new McpError(
3314
+ `Error executing MCP tool ${this.name}: ${error instanceof Error ? error.message : String(error)}`,
3315
+ "tool_execution_error" /* TOOL_EXECUTION_ERROR */,
3316
+ error instanceof Error ? error : void 0
3317
+ );
3318
+ }
3319
+ throw error;
3320
+ }
3321
+ }
3322
+ };
3323
+
3324
+ // src/tools/mcp/index.ts
3325
+ var McpToolset = class {
3326
+ constructor(config, toolFilter = null) {
3327
+ this.clientService = null;
3328
+ this.toolFilter = null;
3329
+ this.tools = [];
3330
+ this.isClosing = false;
3331
+ this.config = config;
3332
+ this.toolFilter = toolFilter;
3333
+ this.clientService = new McpClientService(config);
3334
+ }
3335
+ /**
3336
+ * Checks if a tool should be included based on the tool filter.
3337
+ * Similar to Python's _is_selected method.
3338
+ */
3339
+ isSelected(tool, context) {
3340
+ if (!this.toolFilter) {
3341
+ return true;
3342
+ }
3343
+ if (typeof this.toolFilter === "function") {
3344
+ return this.toolFilter(tool, context);
3345
+ }
3346
+ if (Array.isArray(this.toolFilter)) {
3347
+ return this.toolFilter.includes(tool.name);
3348
+ }
3349
+ return true;
3350
+ }
3351
+ /**
3352
+ * Initializes the client service and establishes a connection.
3353
+ */
3354
+ async initialize() {
3355
+ if (this.isClosing) {
3356
+ throw new McpError(
3357
+ "Cannot initialize a toolset that is being closed",
3358
+ "resource_closed_error" /* RESOURCE_CLOSED_ERROR */
3359
+ );
3360
+ }
3361
+ if (!this.clientService) {
3362
+ this.clientService = new McpClientService(this.config);
3363
+ }
3364
+ await this.clientService.initialize();
3365
+ return this.clientService;
3366
+ }
3367
+ /**
3368
+ * Retrieves tools from the MCP server and converts them to BaseTool instances.
3369
+ * Similar to Python's get_tools method.
3370
+ */
3371
+ async getTools(context) {
3372
+ try {
3373
+ if (this.isClosing) {
3374
+ throw new McpError(
3375
+ "Cannot get tools from a toolset that is being closed",
3376
+ "resource_closed_error" /* RESOURCE_CLOSED_ERROR */
3377
+ );
3378
+ }
3379
+ if (this.tools.length > 0 && !_optionalChain([this, 'access', _42 => _42.config, 'access', _43 => _43.cacheConfig, 'optionalAccess', _44 => _44.enabled]) === false) {
3380
+ return this.tools;
3381
+ }
3382
+ if (!this.clientService) {
3383
+ await this.initialize();
3384
+ }
3385
+ const client = await this.clientService.initialize();
3386
+ const toolsResponse = await client.listTools();
3387
+ if (!toolsResponse.tools || !Array.isArray(toolsResponse.tools)) {
3388
+ console.warn("MCP server returned no tools or invalid tools array");
3389
+ return [];
3390
+ }
3391
+ const tools = [];
3392
+ for (const mcpTool of toolsResponse.tools) {
3393
+ if (this.isSelected(mcpTool, context)) {
3394
+ try {
3395
+ const tool = await createTool(mcpTool, client);
3396
+ tools.push(tool);
3397
+ } catch (toolError) {
3398
+ console.error(
3399
+ `Failed to create tool from MCP tool "${mcpTool.name}":`,
3400
+ toolError
3401
+ );
3402
+ }
3403
+ }
3404
+ }
3405
+ if (_optionalChain([this, 'access', _45 => _45.config, 'access', _46 => _46.cacheConfig, 'optionalAccess', _47 => _47.enabled]) !== false) {
3406
+ this.tools = tools;
3407
+ }
3408
+ return tools;
3409
+ } catch (error) {
3410
+ if (!(error instanceof McpError)) {
3411
+ console.error("Error retrieving MCP tools:", error);
3412
+ throw new McpError(
3413
+ `Error retrieving MCP tools: ${error instanceof Error ? error.message : String(error)}`,
3414
+ "connection_error" /* CONNECTION_ERROR */,
3415
+ error instanceof Error ? error : void 0
3416
+ );
3417
+ }
3418
+ throw error;
3419
+ }
3420
+ }
3421
+ /**
3422
+ * Converts ADK tools to MCP tool format for bidirectional support
3423
+ */
3424
+ convertADKToolsToMCP(tools) {
3425
+ return tools.map((tool) => adkToMcpToolType(tool));
3426
+ }
3427
+ /**
3428
+ * Refreshes the tool cache by clearing it and fetching tools again
3429
+ */
3430
+ async refreshTools(context) {
3431
+ this.tools = [];
3432
+ return this.getTools(context);
3433
+ }
3434
+ /**
3435
+ * Closes the connection to the MCP server.
3436
+ * Similar to Python's close method.
3437
+ */
3438
+ async close() {
3439
+ if (this.isClosing) {
3440
+ return;
3441
+ }
3442
+ try {
3443
+ this.isClosing = true;
3444
+ if (this.clientService) {
3445
+ await this.clientService.close();
3446
+ this.clientService = null;
3447
+ }
3448
+ this.tools = [];
3449
+ if (this.config.debug) {
3450
+ console.log("\u2705 MCP toolset closed successfully");
3451
+ }
3452
+ } catch (error) {
3453
+ console.error("Error closing MCP toolset:", error);
3454
+ } finally {
3455
+ this.isClosing = false;
3456
+ }
3457
+ }
3458
+ /**
3459
+ * Disposes of all resources. This method should be called when the toolset is no longer needed.
3460
+ * Provides alignment with disposal patterns common in TypeScript.
3461
+ */
3462
+ async dispose() {
3463
+ await this.close();
3464
+ }
3465
+ };
3466
+ async function getMcpTools(config, toolFilter) {
3467
+ const toolset = new McpToolset(config, toolFilter);
3468
+ try {
3469
+ return await toolset.getTools();
3470
+ } finally {
3471
+ await toolset.close().catch((err) => console.error("Error closing toolset:", err));
3472
+ }
3473
+ }
3474
+
2771
3475
  // src/models/index.ts
2772
3476
  var models_exports = {};
2773
3477
  __export(models_exports, {
@@ -2947,7 +3651,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
2947
3651
  * Convert Anthropic tool calls to ADK tool calls
2948
3652
  */
2949
3653
  convertToolCalls(toolUses) {
2950
- if (!_optionalChain([toolUses, 'optionalAccess', _38 => _38.length])) {
3654
+ if (!_optionalChain([toolUses, 'optionalAccess', _48 => _48.length])) {
2951
3655
  return void 0;
2952
3656
  }
2953
3657
  return toolUses.map((toolUse) => ({
@@ -2962,7 +3666,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
2962
3666
  * Extract tool uses from response content
2963
3667
  */
2964
3668
  extractToolUses(content) {
2965
- if (!_optionalChain([content, 'optionalAccess', _39 => _39.length])) return [];
3669
+ if (!_optionalChain([content, 'optionalAccess', _49 => _49.length])) return [];
2966
3670
  const toolUses = [];
2967
3671
  for (const block of content) {
2968
3672
  if (process.env.DEBUG === "true") {
@@ -3101,7 +3805,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
3101
3805
  const llmResponse = new LLMResponse({
3102
3806
  role: "assistant",
3103
3807
  content,
3104
- tool_calls: _optionalChain([toolCalls, 'optionalAccess', _40 => _40.length]) ? toolCalls : void 0,
3808
+ tool_calls: _optionalChain([toolCalls, 'optionalAccess', _50 => _50.length]) ? toolCalls : void 0,
3105
3809
  raw_response: apiResponse
3106
3810
  });
3107
3811
  if (process.env.DEBUG === "true") {
@@ -3110,7 +3814,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
3110
3814
  JSON.stringify(
3111
3815
  {
3112
3816
  role: llmResponse.role,
3113
- content: _optionalChain([llmResponse, 'access', _41 => _41.content, 'optionalAccess', _42 => _42.substring, 'call', _43 => _43(0, 50)]) + (llmResponse.content && llmResponse.content.length > 50 ? "..." : ""),
3817
+ content: _optionalChain([llmResponse, 'access', _51 => _51.content, 'optionalAccess', _52 => _52.substring, 'call', _53 => _53(0, 50)]) + (llmResponse.content && llmResponse.content.length > 50 ? "..." : ""),
3114
3818
  tool_calls: llmResponse.tool_calls ? `[${llmResponse.tool_calls.length} calls]` : "undefined"
3115
3819
  },
3116
3820
  null,
@@ -3135,17 +3839,17 @@ var AnthropicLLM = class extends BaseLLM {
3135
3839
  */
3136
3840
  constructor(model, config) {
3137
3841
  super(model);
3138
- this.apiKey = _optionalChain([config, 'optionalAccess', _44 => _44.apiKey]) || process.env.ANTHROPIC_API_KEY || "";
3139
- this.baseURL = _optionalChain([config, 'optionalAccess', _45 => _45.baseURL]) || "https://api.anthropic.com/v1";
3842
+ this.apiKey = _optionalChain([config, 'optionalAccess', _54 => _54.apiKey]) || process.env.ANTHROPIC_API_KEY || "";
3843
+ this.baseURL = _optionalChain([config, 'optionalAccess', _55 => _55.baseURL]) || "https://api.anthropic.com/v1";
3140
3844
  if (!this.apiKey) {
3141
3845
  throw new Error(
3142
3846
  "Anthropic API key is required. Provide it in config or set ANTHROPIC_API_KEY environment variable."
3143
3847
  );
3144
3848
  }
3145
3849
  this.defaultParams = {
3146
- temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _46 => _46.defaultParams, 'optionalAccess', _47 => _47.temperature]), () => ( 0.7)),
3147
- top_p: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _48 => _48.defaultParams, 'optionalAccess', _49 => _49.top_p]), () => ( 1)),
3148
- max_tokens: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _50 => _50.defaultParams, 'optionalAccess', _51 => _51.max_tokens]), () => ( 1024))
3850
+ temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _56 => _56.defaultParams, 'optionalAccess', _57 => _57.temperature]), () => ( 0.7)),
3851
+ top_p: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _58 => _58.defaultParams, 'optionalAccess', _59 => _59.top_p]), () => ( 1)),
3852
+ max_tokens: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _60 => _60.defaultParams, 'optionalAccess', _61 => _61.max_tokens]), () => ( 1024))
3149
3853
  };
3150
3854
  }
3151
3855
  /**
@@ -3231,7 +3935,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
3231
3935
  * Convert ADK function declarations to Anthropic tool format
3232
3936
  */
3233
3937
  convertFunctionsToTools(functions) {
3234
- if (!_optionalChain([functions, 'optionalAccess', _52 => _52.length])) {
3938
+ if (!_optionalChain([functions, 'optionalAccess', _62 => _62.length])) {
3235
3939
  return [];
3236
3940
  }
3237
3941
  return functions.map((func) => ({
@@ -3244,7 +3948,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
3244
3948
  * Convert Anthropic tool calls to ADK tool calls
3245
3949
  */
3246
3950
  convertToolUses(toolUses) {
3247
- if (!_optionalChain([toolUses, 'optionalAccess', _53 => _53.length])) {
3951
+ if (!_optionalChain([toolUses, 'optionalAccess', _63 => _63.length])) {
3248
3952
  return [];
3249
3953
  }
3250
3954
  return toolUses.map((toolUse) => ({
@@ -3259,7 +3963,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
3259
3963
  * Extract tool uses from response content
3260
3964
  */
3261
3965
  extractToolUses(content) {
3262
- if (!_optionalChain([content, 'optionalAccess', _54 => _54.length])) return [];
3966
+ if (!_optionalChain([content, 'optionalAccess', _64 => _64.length])) return [];
3263
3967
  const toolUses = [];
3264
3968
  for (const block of content) {
3265
3969
  if (process.env.DEBUG === "true") {
@@ -3336,7 +4040,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
3336
4040
  temperature: _nullishCoalesce(llmRequest.config.temperature, () => ( this.defaultParams.temperature)),
3337
4041
  max_tokens: _nullishCoalesce(llmRequest.config.max_tokens, () => ( this.defaultParams.max_tokens)),
3338
4042
  top_p: _nullishCoalesce(llmRequest.config.top_p, () => ( this.defaultParams.top_p)),
3339
- tools: _optionalChain([tools, 'optionalAccess', _55 => _55.length]) ? tools : void 0
4043
+ tools: _optionalChain([tools, 'optionalAccess', _65 => _65.length]) ? tools : void 0
3340
4044
  };
3341
4045
  if (process.env.DEBUG === "true") {
3342
4046
  console.log("Anthropic API Request:", {
@@ -3388,7 +4092,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
3388
4092
  JSON.stringify(
3389
4093
  {
3390
4094
  role: llmResponse.role,
3391
- content: _optionalChain([llmResponse, 'access', _56 => _56.content, 'optionalAccess', _57 => _57.substring, 'call', _58 => _58(0, 50)]) + (llmResponse.content && llmResponse.content.length > 50 ? "..." : ""),
4095
+ content: _optionalChain([llmResponse, 'access', _66 => _66.content, 'optionalAccess', _67 => _67.substring, 'call', _68 => _68(0, 50)]) + (llmResponse.content && llmResponse.content.length > 50 ? "..." : ""),
3392
4096
  tool_calls: llmResponse.tool_calls ? `[${llmResponse.tool_calls.length} calls]` : "undefined"
3393
4097
  },
3394
4098
  null,
@@ -3436,9 +4140,9 @@ var GoogleLLM = class extends BaseLLM {
3436
4140
  constructor(model, config) {
3437
4141
  super(model);
3438
4142
  const apiKey = process.env.GOOGLE_API_KEY;
3439
- const projectId = _optionalChain([config, 'optionalAccess', _59 => _59.projectId]) || process.env.GOOGLE_CLOUD_PROJECT;
3440
- const location = _optionalChain([config, 'optionalAccess', _60 => _60.location]) || process.env.GOOGLE_CLOUD_LOCATION;
3441
- const useVertexAI = _optionalChain([process, 'access', _61 => _61.env, 'access', _62 => _62.USE_VERTEX_AI, 'optionalAccess', _63 => _63.toLowerCase, 'call', _64 => _64()]) === "true";
4143
+ const projectId = _optionalChain([config, 'optionalAccess', _69 => _69.projectId]) || process.env.GOOGLE_CLOUD_PROJECT;
4144
+ const location = _optionalChain([config, 'optionalAccess', _70 => _70.location]) || process.env.GOOGLE_CLOUD_LOCATION;
4145
+ const useVertexAI = _optionalChain([process, 'access', _71 => _71.env, 'access', _72 => _72.USE_VERTEX_AI, 'optionalAccess', _73 => _73.toLowerCase, 'call', _74 => _74()]) === "true";
3442
4146
  if (!useVertexAI && !apiKey) {
3443
4147
  throw new Error(
3444
4148
  "Google API Key is required. Provide via config or GOOGLE_API_KEY env var."
@@ -3463,9 +4167,9 @@ var GoogleLLM = class extends BaseLLM {
3463
4167
  }
3464
4168
  this.ai = new (0, _genai.GoogleGenAI)(options);
3465
4169
  this.defaultParams = {
3466
- temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _65 => _65.defaultParams, 'optionalAccess', _66 => _66.temperature]), () => ( 0.7)),
3467
- topP: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _67 => _67.defaultParams, 'optionalAccess', _68 => _68.top_p]), () => ( 1)),
3468
- maxOutputTokens: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _69 => _69.defaultParams, 'optionalAccess', _70 => _70.maxOutputTokens]), () => ( 1024))
4170
+ temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _75 => _75.defaultParams, 'optionalAccess', _76 => _76.temperature]), () => ( 0.7)),
4171
+ topP: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _77 => _77.defaultParams, 'optionalAccess', _78 => _78.top_p]), () => ( 1)),
4172
+ maxOutputTokens: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _79 => _79.defaultParams, 'optionalAccess', _80 => _80.maxOutputTokens]), () => ( 1024))
3469
4173
  };
3470
4174
  }
3471
4175
  /**
@@ -3603,7 +4307,7 @@ var GoogleLLM = class extends BaseLLM {
3603
4307
  );
3604
4308
  parts.push({ text: "" });
3605
4309
  }
3606
- if (googleRole === "function" && (parts.length !== 1 || !_optionalChain([parts, 'access', _71 => _71[0], 'optionalAccess', _72 => _72.functionResponse]))) {
4310
+ if (googleRole === "function" && (parts.length !== 1 || !_optionalChain([parts, 'access', _81 => _81[0], 'optionalAccess', _82 => _82.functionResponse]))) {
3607
4311
  console.error(
3608
4312
  `[GoogleLLM] convertMessage - Invalid parts for 'function' role. Expected 1 functionResponse part. Got:`,
3609
4313
  JSON.stringify(parts),
@@ -3711,13 +4415,13 @@ var GoogleLLM = class extends BaseLLM {
3711
4415
  role: "assistant",
3712
4416
  content: null
3713
4417
  });
3714
- if (typeof _optionalChain([response, 'optionalAccess', _73 => _73.candidates, 'optionalAccess', _74 => _74[0], 'optionalAccess', _75 => _75.content, 'optionalAccess', _76 => _76.parts, 'optionalAccess', _77 => _77[0], 'optionalAccess', _78 => _78.text]) === "string") {
4418
+ if (typeof _optionalChain([response, 'optionalAccess', _83 => _83.candidates, 'optionalAccess', _84 => _84[0], 'optionalAccess', _85 => _85.content, 'optionalAccess', _86 => _86.parts, 'optionalAccess', _87 => _87[0], 'optionalAccess', _88 => _88.text]) === "string") {
3715
4419
  result.content = response.candidates[0].content.parts[0].text;
3716
4420
  }
3717
- if (_optionalChain([response, 'optionalAccess', _79 => _79.candidates, 'optionalAccess', _80 => _80[0], 'optionalAccess', _81 => _81.content, 'optionalAccess', _82 => _82.parts, 'optionalAccess', _83 => _83[0], 'optionalAccess', _84 => _84.text])) {
4421
+ if (_optionalChain([response, 'optionalAccess', _89 => _89.candidates, 'optionalAccess', _90 => _90[0], 'optionalAccess', _91 => _91.content, 'optionalAccess', _92 => _92.parts, 'optionalAccess', _93 => _93[0], 'optionalAccess', _94 => _94.text])) {
3718
4422
  result.content = response.candidates[0].content.parts[0].text;
3719
4423
  }
3720
- if (_optionalChain([response, 'optionalAccess', _85 => _85.candidates, 'optionalAccess', _86 => _86[0], 'optionalAccess', _87 => _87.content, 'optionalAccess', _88 => _88.parts, 'optionalAccess', _89 => _89[0], 'optionalAccess', _90 => _90.functionCall])) {
4424
+ if (_optionalChain([response, 'optionalAccess', _95 => _95.candidates, 'optionalAccess', _96 => _96[0], 'optionalAccess', _97 => _97.content, 'optionalAccess', _98 => _98.parts, 'optionalAccess', _99 => _99[0], 'optionalAccess', _100 => _100.functionCall])) {
3721
4425
  const functionCall = response.candidates[0].content.parts[0].functionCall;
3722
4426
  result.function_call = {
3723
4427
  name: functionCall.name,
@@ -3764,10 +4468,10 @@ var GoogleLLM = class extends BaseLLM {
3764
4468
  if (stream) {
3765
4469
  const streamingResult = await this.ai.models.generateContentStream(requestOptions);
3766
4470
  for await (const chunk of streamingResult) {
3767
- if (!_optionalChain([chunk, 'access', _91 => _91.candidates, 'optionalAccess', _92 => _92[0], 'optionalAccess', _93 => _93.content, 'optionalAccess', _94 => _94.parts, 'optionalAccess', _95 => _95[0], 'optionalAccess', _96 => _96.text])) {
4471
+ if (!_optionalChain([chunk, 'access', _101 => _101.candidates, 'optionalAccess', _102 => _102[0], 'optionalAccess', _103 => _103.content, 'optionalAccess', _104 => _104.parts, 'optionalAccess', _105 => _105[0], 'optionalAccess', _106 => _106.text])) {
3768
4472
  continue;
3769
4473
  }
3770
- const partialText = _optionalChain([chunk, 'access', _97 => _97.candidates, 'access', _98 => _98[0], 'optionalAccess', _99 => _99.content, 'optionalAccess', _100 => _100.parts, 'access', _101 => _101[0], 'optionalAccess', _102 => _102.text]) || "";
4474
+ const partialText = _optionalChain([chunk, 'access', _107 => _107.candidates, 'access', _108 => _108[0], 'optionalAccess', _109 => _109.content, 'optionalAccess', _110 => _110.parts, 'access', _111 => _111[0], 'optionalAccess', _112 => _112.text]) || "";
3771
4475
  const partialResponse = new LLMResponse({
3772
4476
  content: partialText,
3773
4477
  role: "assistant",
@@ -3879,10 +4583,10 @@ var OpenAILLMConnection = class extends BaseLLMConnection {
3879
4583
  for await (const chunk of stream) {
3880
4584
  if (chunk.choices.length === 0) continue;
3881
4585
  const delta = chunk.choices[0].delta;
3882
- if (_optionalChain([delta, 'optionalAccess', _103 => _103.content])) {
4586
+ if (_optionalChain([delta, 'optionalAccess', _113 => _113.content])) {
3883
4587
  responseContent += delta.content;
3884
4588
  }
3885
- if (_optionalChain([delta, 'optionalAccess', _104 => _104.function_call])) {
4589
+ if (_optionalChain([delta, 'optionalAccess', _114 => _114.function_call])) {
3886
4590
  if (!functionCall) {
3887
4591
  functionCall = {
3888
4592
  name: delta.function_call.name || "",
@@ -3893,7 +4597,7 @@ var OpenAILLMConnection = class extends BaseLLMConnection {
3893
4597
  functionCall.arguments += delta.function_call.arguments || "";
3894
4598
  }
3895
4599
  }
3896
- if (_optionalChain([delta, 'optionalAccess', _105 => _105.tool_calls])) {
4600
+ if (_optionalChain([delta, 'optionalAccess', _115 => _115.tool_calls])) {
3897
4601
  for (const toolDelta of delta.tool_calls) {
3898
4602
  const id = toolDelta.id || "";
3899
4603
  let tool = toolCalls.find((t) => t.id === id);
@@ -3901,20 +4605,20 @@ var OpenAILLMConnection = class extends BaseLLMConnection {
3901
4605
  tool = {
3902
4606
  id,
3903
4607
  function: {
3904
- name: _optionalChain([toolDelta, 'access', _106 => _106.function, 'optionalAccess', _107 => _107.name]) || "",
3905
- arguments: _optionalChain([toolDelta, 'access', _108 => _108.function, 'optionalAccess', _109 => _109.arguments]) || ""
4608
+ name: _optionalChain([toolDelta, 'access', _116 => _116.function, 'optionalAccess', _117 => _117.name]) || "",
4609
+ arguments: _optionalChain([toolDelta, 'access', _118 => _118.function, 'optionalAccess', _119 => _119.arguments]) || ""
3906
4610
  }
3907
4611
  };
3908
4612
  toolCalls.push(tool);
3909
4613
  } else {
3910
- tool.function.name += _optionalChain([toolDelta, 'access', _110 => _110.function, 'optionalAccess', _111 => _111.name]) || "";
3911
- tool.function.arguments += _optionalChain([toolDelta, 'access', _112 => _112.function, 'optionalAccess', _113 => _113.arguments]) || "";
4614
+ tool.function.name += _optionalChain([toolDelta, 'access', _120 => _120.function, 'optionalAccess', _121 => _121.name]) || "";
4615
+ tool.function.arguments += _optionalChain([toolDelta, 'access', _122 => _122.function, 'optionalAccess', _123 => _123.arguments]) || "";
3912
4616
  }
3913
4617
  }
3914
4618
  }
3915
4619
  if (this.responseCallback) {
3916
4620
  const response = new LLMResponse({
3917
- content: _optionalChain([delta, 'optionalAccess', _114 => _114.content]) || null,
4621
+ content: _optionalChain([delta, 'optionalAccess', _124 => _124.content]) || null,
3918
4622
  role: "assistant",
3919
4623
  function_call: functionCall,
3920
4624
  tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
@@ -4016,16 +4720,16 @@ var OpenAILLM = class extends BaseLLM {
4016
4720
  constructor(model, config) {
4017
4721
  super(model);
4018
4722
  this.client = new (0, _openai2.default)({
4019
- apiKey: _optionalChain([config, 'optionalAccess', _115 => _115.apiKey]) || process.env.OPENAI_API_KEY,
4020
- baseURL: _optionalChain([config, 'optionalAccess', _116 => _116.baseURL]),
4021
- organization: _optionalChain([config, 'optionalAccess', _117 => _117.organization])
4723
+ apiKey: _optionalChain([config, 'optionalAccess', _125 => _125.apiKey]) || process.env.OPENAI_API_KEY,
4724
+ baseURL: _optionalChain([config, 'optionalAccess', _126 => _126.baseURL]),
4725
+ organization: _optionalChain([config, 'optionalAccess', _127 => _127.organization])
4022
4726
  });
4023
4727
  this.defaultParams = {
4024
- temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _118 => _118.defaultParams, 'optionalAccess', _119 => _119.temperature]), () => ( 0.7)),
4025
- top_p: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _120 => _120.defaultParams, 'optionalAccess', _121 => _121.top_p]), () => ( 1)),
4026
- max_tokens: _optionalChain([config, 'optionalAccess', _122 => _122.defaultParams, 'optionalAccess', _123 => _123.max_tokens]),
4027
- frequency_penalty: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _124 => _124.defaultParams, 'optionalAccess', _125 => _125.frequency_penalty]), () => ( 0)),
4028
- presence_penalty: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _126 => _126.defaultParams, 'optionalAccess', _127 => _127.presence_penalty]), () => ( 0))
4728
+ temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _128 => _128.defaultParams, 'optionalAccess', _129 => _129.temperature]), () => ( 0.7)),
4729
+ top_p: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _130 => _130.defaultParams, 'optionalAccess', _131 => _131.top_p]), () => ( 1)),
4730
+ max_tokens: _optionalChain([config, 'optionalAccess', _132 => _132.defaultParams, 'optionalAccess', _133 => _133.max_tokens]),
4731
+ frequency_penalty: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _134 => _134.defaultParams, 'optionalAccess', _135 => _135.frequency_penalty]), () => ( 0)),
4732
+ presence_penalty: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _136 => _136.defaultParams, 'optionalAccess', _137 => _137.presence_penalty]), () => ( 0))
4029
4733
  };
4030
4734
  }
4031
4735
  /**
@@ -4135,16 +4839,16 @@ var OpenAILLM = class extends BaseLLM {
4135
4839
  */
4136
4840
  convertResponse(response) {
4137
4841
  const result = new LLMResponse({
4138
- content: _optionalChain([response, 'access', _128 => _128.message, 'optionalAccess', _129 => _129.content]) || null,
4139
- role: _optionalChain([response, 'access', _130 => _130.message, 'optionalAccess', _131 => _131.role]) || "assistant"
4842
+ content: _optionalChain([response, 'access', _138 => _138.message, 'optionalAccess', _139 => _139.content]) || null,
4843
+ role: _optionalChain([response, 'access', _140 => _140.message, 'optionalAccess', _141 => _141.role]) || "assistant"
4140
4844
  });
4141
- if (_optionalChain([response, 'access', _132 => _132.message, 'optionalAccess', _133 => _133.function_call])) {
4845
+ if (_optionalChain([response, 'access', _142 => _142.message, 'optionalAccess', _143 => _143.function_call])) {
4142
4846
  result.function_call = {
4143
4847
  name: response.message.function_call.name,
4144
4848
  arguments: response.message.function_call.arguments
4145
4849
  };
4146
4850
  }
4147
- if (_optionalChain([response, 'access', _134 => _134.message, 'optionalAccess', _135 => _135.tool_calls])) {
4851
+ if (_optionalChain([response, 'access', _144 => _144.message, 'optionalAccess', _145 => _145.tool_calls])) {
4148
4852
  result.tool_calls = response.message.tool_calls.map((tool) => ({
4149
4853
  id: tool.id,
4150
4854
  function: {
@@ -4164,24 +4868,24 @@ var OpenAILLM = class extends BaseLLM {
4164
4868
  `OpenAI: Converting chunk - delta: ${JSON.stringify(chunk.delta || {})}`
4165
4869
  );
4166
4870
  }
4167
- const content = _optionalChain([chunk, 'access', _136 => _136.delta, 'optionalAccess', _137 => _137.content]);
4871
+ const content = _optionalChain([chunk, 'access', _146 => _146.delta, 'optionalAccess', _147 => _147.content]);
4168
4872
  const result = new LLMResponse({
4169
4873
  content: content !== void 0 ? content : null,
4170
- role: _optionalChain([chunk, 'access', _138 => _138.delta, 'optionalAccess', _139 => _139.role]) || "assistant",
4874
+ role: _optionalChain([chunk, 'access', _148 => _148.delta, 'optionalAccess', _149 => _149.role]) || "assistant",
4171
4875
  is_partial: true
4172
4876
  });
4173
- if (_optionalChain([chunk, 'access', _140 => _140.delta, 'optionalAccess', _141 => _141.function_call])) {
4877
+ if (_optionalChain([chunk, 'access', _150 => _150.delta, 'optionalAccess', _151 => _151.function_call])) {
4174
4878
  result.function_call = {
4175
4879
  name: chunk.delta.function_call.name || "",
4176
4880
  arguments: chunk.delta.function_call.arguments || ""
4177
4881
  };
4178
4882
  }
4179
- if (_optionalChain([chunk, 'access', _142 => _142.delta, 'optionalAccess', _143 => _143.tool_calls])) {
4883
+ if (_optionalChain([chunk, 'access', _152 => _152.delta, 'optionalAccess', _153 => _153.tool_calls])) {
4180
4884
  result.tool_calls = chunk.delta.tool_calls.map((tool) => ({
4181
4885
  id: tool.id || "",
4182
4886
  function: {
4183
- name: _optionalChain([tool, 'access', _144 => _144.function, 'optionalAccess', _145 => _145.name]) || "",
4184
- arguments: _optionalChain([tool, 'access', _146 => _146.function, 'optionalAccess', _147 => _147.arguments]) || ""
4887
+ name: _optionalChain([tool, 'access', _154 => _154.function, 'optionalAccess', _155 => _155.name]) || "",
4888
+ arguments: _optionalChain([tool, 'access', _156 => _156.function, 'optionalAccess', _157 => _157.arguments]) || ""
4185
4889
  }
4186
4890
  }));
4187
4891
  }
@@ -4239,7 +4943,7 @@ var OpenAILLM = class extends BaseLLM {
4239
4943
  }
4240
4944
  if (process.env.DEBUG === "true") {
4241
4945
  console.log(
4242
- `OpenAI: Chunk received - delta: "${_optionalChain([choice, 'access', _148 => _148.delta, 'optionalAccess', _149 => _149.content]) || ""}"`,
4946
+ `OpenAI: Chunk received - delta: "${_optionalChain([choice, 'access', _158 => _158.delta, 'optionalAccess', _159 => _159.content]) || ""}"`,
4243
4947
  `responseChunk content: "${responseChunk.content || ""}"`,
4244
4948
  `is_partial: ${responseChunk.is_partial}`,
4245
4949
  `accumulated: "${accumulatedContent.substring(0, 30)}${accumulatedContent.length > 30 ? "..." : ""}"`
@@ -4480,7 +5184,7 @@ var OAuth2Credential = class extends AuthCredential {
4480
5184
  "Cannot refresh token: no refresh token or refresh function"
4481
5185
  );
4482
5186
  }
4483
- const result = await _optionalChain([this, 'access', _150 => _150.refreshFunction, 'optionalCall', _151 => _151(this.refreshToken)]);
5187
+ const result = await _optionalChain([this, 'access', _160 => _160.refreshFunction, 'optionalCall', _161 => _161(this.refreshToken)]);
4484
5188
  if (!result) {
4485
5189
  throw new Error("Failed to refresh token");
4486
5190
  }
@@ -4518,7 +5222,7 @@ var AuthHandler = class {
4518
5222
  * Gets the authentication token
4519
5223
  */
4520
5224
  getToken() {
4521
- return _optionalChain([this, 'access', _152 => _152.credential, 'optionalAccess', _153 => _153.getToken, 'call', _154 => _154()]);
5225
+ return _optionalChain([this, 'access', _162 => _162.credential, 'optionalAccess', _163 => _163.getToken, 'call', _164 => _164()]);
4522
5226
  }
4523
5227
  /**
4524
5228
  * Gets headers for HTTP requests
@@ -4533,7 +5237,7 @@ var AuthHandler = class {
4533
5237
  * Refreshes the token if necessary
4534
5238
  */
4535
5239
  async refreshToken() {
4536
- if (_optionalChain([this, 'access', _155 => _155.credential, 'optionalAccess', _156 => _156.canRefresh, 'call', _157 => _157()])) {
5240
+ if (_optionalChain([this, 'access', _165 => _165.credential, 'optionalAccess', _166 => _166.canRefresh, 'call', _167 => _167()])) {
4537
5241
  await this.credential.refresh();
4538
5242
  }
4539
5243
  }
@@ -4709,7 +5413,7 @@ var InMemoryMemoryService = class {
4709
5413
  };
4710
5414
  const normalizedQuery = query.toLowerCase().trim();
4711
5415
  const queryTerms = normalizedQuery.split(/\s+/);
4712
- const sessionsToSearch = _optionalChain([options, 'optionalAccess', _158 => _158.sessionId]) ? this.sessions.has(options.sessionId) ? [this.sessions.get(options.sessionId)] : [] : Array.from(this.sessions.values());
5416
+ const sessionsToSearch = _optionalChain([options, 'optionalAccess', _168 => _168.sessionId]) ? this.sessions.has(options.sessionId) ? [this.sessions.get(options.sessionId)] : [] : Array.from(this.sessions.values());
4713
5417
  for (const session of sessionsToSearch) {
4714
5418
  const matchedEvents = [];
4715
5419
  const scores = [];
@@ -4735,7 +5439,7 @@ var InMemoryMemoryService = class {
4735
5439
  }
4736
5440
  }
4737
5441
  const score = queryTerms.length > 0 ? termMatches / queryTerms.length : 0;
4738
- if (_optionalChain([options, 'optionalAccess', _159 => _159.threshold]) !== void 0 && score < options.threshold) {
5442
+ if (_optionalChain([options, 'optionalAccess', _169 => _169.threshold]) !== void 0 && score < options.threshold) {
4739
5443
  continue;
4740
5444
  }
4741
5445
  if (score > 0) {
@@ -4755,7 +5459,7 @@ var InMemoryMemoryService = class {
4755
5459
  response.memories.sort(
4756
5460
  (a, b) => (_nullishCoalesce(b.relevanceScore, () => ( 0))) - (_nullishCoalesce(a.relevanceScore, () => ( 0)))
4757
5461
  );
4758
- if (_optionalChain([options, 'optionalAccess', _160 => _160.limit]) !== void 0 && options.limit > 0) {
5462
+ if (_optionalChain([options, 'optionalAccess', _170 => _170.limit]) !== void 0 && options.limit > 0) {
4759
5463
  response.memories = response.memories.slice(0, options.limit);
4760
5464
  }
4761
5465
  return response;
@@ -5004,17 +5708,17 @@ var InMemorySessionService = class {
5004
5708
  let sessions = Array.from(this.sessions.values()).filter(
5005
5709
  (session) => session.userId === userId
5006
5710
  );
5007
- if (_optionalChain([options, 'optionalAccess', _161 => _161.createdAfter])) {
5711
+ if (_optionalChain([options, 'optionalAccess', _171 => _171.createdAfter])) {
5008
5712
  sessions = sessions.filter(
5009
5713
  (session) => session.createdAt >= options.createdAfter
5010
5714
  );
5011
5715
  }
5012
- if (_optionalChain([options, 'optionalAccess', _162 => _162.updatedAfter])) {
5716
+ if (_optionalChain([options, 'optionalAccess', _172 => _172.updatedAfter])) {
5013
5717
  sessions = sessions.filter(
5014
5718
  (session) => session.updatedAt >= options.updatedAfter
5015
5719
  );
5016
5720
  }
5017
- if (_optionalChain([options, 'optionalAccess', _163 => _163.metadataFilter])) {
5721
+ if (_optionalChain([options, 'optionalAccess', _173 => _173.metadataFilter])) {
5018
5722
  sessions = sessions.filter((session) => {
5019
5723
  for (const [key, value] of Object.entries(options.metadataFilter)) {
5020
5724
  if (session.metadata[key] !== value) {
@@ -5025,7 +5729,7 @@ var InMemorySessionService = class {
5025
5729
  });
5026
5730
  }
5027
5731
  sessions.sort((a, b) => b.updatedAt.getTime() - a.updatedAt.getTime());
5028
- if (_optionalChain([options, 'optionalAccess', _164 => _164.limit]) !== void 0 && options.limit > 0) {
5732
+ if (_optionalChain([options, 'optionalAccess', _174 => _174.limit]) !== void 0 && options.limit > 0) {
5029
5733
  sessions = sessions.slice(0, options.limit);
5030
5734
  }
5031
5735
  return sessions;
@@ -5060,7 +5764,7 @@ var InMemorySessionService = class {
5060
5764
  if (event.is_partial) {
5061
5765
  return event;
5062
5766
  }
5063
- if (_optionalChain([event, 'access', _165 => _165.actions, 'optionalAccess', _166 => _166.stateDelta])) {
5767
+ if (_optionalChain([event, 'access', _175 => _175.actions, 'optionalAccess', _176 => _176.stateDelta])) {
5064
5768
  for (const [key, value] of Object.entries(event.actions.stateDelta)) {
5065
5769
  if (key.startsWith("_temp_")) {
5066
5770
  continue;
@@ -5164,7 +5868,7 @@ var PostgresSessionService = class {
5164
5868
  }
5165
5869
  async listSessions(userId, options) {
5166
5870
  let query = this.db.select().from(this.sessionsTable).where(_drizzleorm.eq.call(void 0, this.sessionsTable.userId, userId));
5167
- if (_optionalChain([options, 'optionalAccess', _167 => _167.limit]) !== void 0 && options.limit > 0) {
5871
+ if (_optionalChain([options, 'optionalAccess', _177 => _177.limit]) !== void 0 && options.limit > 0) {
5168
5872
  query = query.limit(options.limit);
5169
5873
  }
5170
5874
  const results = await query;
@@ -5191,12 +5895,12 @@ var PostgresSessionService = class {
5191
5895
  if (event.is_partial) {
5192
5896
  return event;
5193
5897
  }
5194
- if (_optionalChain([event, 'access', _168 => _168.actions, 'optionalAccess', _169 => _169.stateDelta])) {
5898
+ if (_optionalChain([event, 'access', _178 => _178.actions, 'optionalAccess', _179 => _179.stateDelta])) {
5195
5899
  for (const [key, value] of Object.entries(event.actions.stateDelta)) {
5196
5900
  if (key.startsWith("_temp_")) {
5197
5901
  continue;
5198
5902
  }
5199
- _optionalChain([session, 'access', _170 => _170.state, 'optionalAccess', _171 => _171.set, 'call', _172 => _172(key, value)]);
5903
+ _optionalChain([session, 'access', _180 => _180.state, 'optionalAccess', _181 => _181.set, 'call', _182 => _182(key, value)]);
5200
5904
  }
5201
5905
  }
5202
5906
  if (!session.events) {
@@ -5341,7 +6045,7 @@ var PgLiteSessionService = class {
5341
6045
  async listSessions(userId, options) {
5342
6046
  await this.ensureInitialized();
5343
6047
  let query = this.db.select().from(this.sessionsTable).where(_drizzleorm.eq.call(void 0, this.sessionsTable.userId, userId));
5344
- if (_optionalChain([options, 'optionalAccess', _173 => _173.limit]) !== void 0 && options.limit > 0) {
6048
+ if (_optionalChain([options, 'optionalAccess', _183 => _183.limit]) !== void 0 && options.limit > 0) {
5345
6049
  query = query.limit(options.limit);
5346
6050
  }
5347
6051
  const results = await query;
@@ -5370,12 +6074,12 @@ var PgLiteSessionService = class {
5370
6074
  if (event.is_partial) {
5371
6075
  return event;
5372
6076
  }
5373
- if (_optionalChain([event, 'access', _174 => _174.actions, 'optionalAccess', _175 => _175.stateDelta])) {
6077
+ if (_optionalChain([event, 'access', _184 => _184.actions, 'optionalAccess', _185 => _185.stateDelta])) {
5374
6078
  for (const [key, value] of Object.entries(event.actions.stateDelta)) {
5375
6079
  if (key.startsWith("_temp_")) {
5376
6080
  continue;
5377
6081
  }
5378
- _optionalChain([session, 'access', _176 => _176.state, 'optionalAccess', _177 => _177.set, 'call', _178 => _178(key, value)]);
6082
+ _optionalChain([session, 'access', _186 => _186.state, 'optionalAccess', _187 => _187.set, 'call', _188 => _188(key, value)]);
5379
6083
  }
5380
6084
  }
5381
6085
  if (!session.events) {
@@ -5718,4 +6422,12 @@ var VERSION = "0.1.0";
5718
6422
 
5719
6423
 
5720
6424
 
5721
- 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.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.StreamingMode = StreamingMode; exports.ToolContext = ToolContext; exports.Tools = tools_exports; exports.TransferToAgentTool = TransferToAgentTool; exports.UserInteractionTool = UserInteractionTool; exports.VERSION = VERSION; exports.buildFunctionDeclaration = buildFunctionDeclaration; exports.cloneSession = cloneSession; exports.createFunctionTool = createFunctionTool; exports.generateSessionId = generateSessionId; exports.registerProviders = registerProviders; exports.validateSession = validateSession;
6425
+
6426
+
6427
+
6428
+
6429
+
6430
+
6431
+
6432
+
6433
+ 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.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.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.generateSessionId = generateSessionId; exports.getMcpTools = getMcpTools; exports.jsonSchemaToDeclaration = jsonSchemaToDeclaration; exports.mcpSchemaToParameters = mcpSchemaToParameters; exports.normalizeJsonSchema = normalizeJsonSchema; exports.registerProviders = registerProviders; exports.validateSession = validateSession;