@iqai/adk 0.0.10 → 0.0.12
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 +23 -50
- package/dist/index.d.ts +23 -50
- package/dist/index.js +144 -134
- package/dist/index.mjs +67 -57
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @iqai/adk
|
|
2
2
|
|
|
3
|
+
## 0.0.12
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 948b0a1: Fixes sampling handler type to include promise
|
|
8
|
+
|
|
9
|
+
## 0.0.11
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 9c7a7a7: Adds proper input and output conversion from LLMRequest and LLMResponse types
|
|
14
|
+
|
|
3
15
|
## 0.0.10
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -2703,7 +2703,7 @@ type McpConfig = {
|
|
|
2703
2703
|
* Sampling handler for processing MCP sampling requests.
|
|
2704
2704
|
* This allows MCP servers to request LLM completions through your ADK agent.
|
|
2705
2705
|
*/
|
|
2706
|
-
samplingHandler?:
|
|
2706
|
+
samplingHandler?: SamplingHandler;
|
|
2707
2707
|
};
|
|
2708
2708
|
type McpTransportType = {
|
|
2709
2709
|
mode: "stdio";
|
|
@@ -2735,41 +2735,9 @@ declare class McpError extends Error {
|
|
|
2735
2735
|
originalError?: Error;
|
|
2736
2736
|
constructor(message: string, type: McpErrorType, originalError?: Error);
|
|
2737
2737
|
}
|
|
2738
|
-
type
|
|
2739
|
-
type
|
|
2740
|
-
type SamplingHandler = (
|
|
2741
|
-
/**
|
|
2742
|
-
* ADK sampling request format - what we pass to the user's handler
|
|
2743
|
-
*/
|
|
2744
|
-
interface ADKSamplingRequest {
|
|
2745
|
-
messages: Message[];
|
|
2746
|
-
systemPrompt?: string;
|
|
2747
|
-
modelPreferences?: {
|
|
2748
|
-
hints?: Array<{
|
|
2749
|
-
name?: string;
|
|
2750
|
-
}>;
|
|
2751
|
-
costPriority?: number;
|
|
2752
|
-
speedPriority?: number;
|
|
2753
|
-
intelligencePriority?: number;
|
|
2754
|
-
};
|
|
2755
|
-
includeContext?: "none" | "thisServer" | "allServers";
|
|
2756
|
-
temperature?: number;
|
|
2757
|
-
maxTokens: number;
|
|
2758
|
-
stopSequences?: string[];
|
|
2759
|
-
metadata?: Record<string, unknown>;
|
|
2760
|
-
}
|
|
2761
|
-
/**
|
|
2762
|
-
* ADK sampling response format - what we expect from the user's handler
|
|
2763
|
-
*/
|
|
2764
|
-
interface ADKSamplingResponse {
|
|
2765
|
-
model: string;
|
|
2766
|
-
stopReason?: "endTurn" | "stopSequence" | "maxTokens" | string;
|
|
2767
|
-
content: string | null;
|
|
2768
|
-
}
|
|
2769
|
-
/**
|
|
2770
|
-
* ADK sampling handler function type - receives ADK formatted messages
|
|
2771
|
-
*/
|
|
2772
|
-
type ADKSamplingHandler = (request: ADKSamplingRequest) => Promise<ADKSamplingResponse>;
|
|
2738
|
+
type McpSamplingRequest = z.infer<typeof CreateMessageRequestSchema>;
|
|
2739
|
+
type McpSamplingResponse = z.infer<typeof CreateMessageResultSchema>;
|
|
2740
|
+
type SamplingHandler = (messages: LLMRequest) => Promise<LLMResponse>;
|
|
2773
2741
|
|
|
2774
2742
|
declare class McpClientService {
|
|
2775
2743
|
private config;
|
|
@@ -2816,7 +2784,7 @@ declare class McpClientService {
|
|
|
2816
2784
|
/**
|
|
2817
2785
|
* Set a new ADK sampling handler
|
|
2818
2786
|
*/
|
|
2819
|
-
setSamplingHandler(handler:
|
|
2787
|
+
setSamplingHandler(handler: SamplingHandler): void;
|
|
2820
2788
|
/**
|
|
2821
2789
|
* Remove the sampling handler
|
|
2822
2790
|
*/
|
|
@@ -2849,16 +2817,24 @@ declare function mcpSchemaToParameters(mcpTool: Tool): JSONSchema;
|
|
|
2849
2817
|
*/
|
|
2850
2818
|
declare class McpSamplingHandler {
|
|
2851
2819
|
private logger;
|
|
2852
|
-
private
|
|
2853
|
-
constructor(
|
|
2820
|
+
private samplingHandler;
|
|
2821
|
+
constructor(samplingHandler: SamplingHandler);
|
|
2854
2822
|
/**
|
|
2855
2823
|
* Handle MCP sampling request and convert between formats
|
|
2856
2824
|
*/
|
|
2857
|
-
handleSamplingRequest(request:
|
|
2825
|
+
handleSamplingRequest(request: McpSamplingRequest): Promise<McpSamplingResponse>;
|
|
2858
2826
|
/**
|
|
2859
2827
|
* Convert MCP messages to ADK message format
|
|
2860
2828
|
*/
|
|
2861
2829
|
private convertMcpMessagesToADK;
|
|
2830
|
+
/**
|
|
2831
|
+
* Convert a single MCP message to ADK message format
|
|
2832
|
+
*/
|
|
2833
|
+
private convertSingleMcpMessageToADK;
|
|
2834
|
+
/**
|
|
2835
|
+
* Convert MCP message content to ADK content format
|
|
2836
|
+
*/
|
|
2837
|
+
private convertMcpContentToADK;
|
|
2862
2838
|
/**
|
|
2863
2839
|
* Convert ADK response to MCP response format
|
|
2864
2840
|
*/
|
|
@@ -2866,7 +2842,7 @@ declare class McpSamplingHandler {
|
|
|
2866
2842
|
/**
|
|
2867
2843
|
* Update the ADK handler
|
|
2868
2844
|
*/
|
|
2869
|
-
updateHandler(handler:
|
|
2845
|
+
updateHandler(handler: SamplingHandler): void;
|
|
2870
2846
|
}
|
|
2871
2847
|
/**
|
|
2872
2848
|
* Helper function to create a sampling handler with proper TypeScript types.
|
|
@@ -2903,7 +2879,7 @@ declare class McpSamplingHandler {
|
|
|
2903
2879
|
* });
|
|
2904
2880
|
* ```
|
|
2905
2881
|
*/
|
|
2906
|
-
declare function createSamplingHandler(handler:
|
|
2882
|
+
declare function createSamplingHandler(handler: SamplingHandler): SamplingHandler;
|
|
2907
2883
|
|
|
2908
2884
|
/**
|
|
2909
2885
|
* A class for managing MCP tools similar to Python's MCPToolset.
|
|
@@ -2931,7 +2907,7 @@ declare class McpToolset {
|
|
|
2931
2907
|
*
|
|
2932
2908
|
* @param handler - ADK sampling handler that receives ADK-formatted messages
|
|
2933
2909
|
*/
|
|
2934
|
-
setSamplingHandler(handler:
|
|
2910
|
+
setSamplingHandler(handler: SamplingHandler): void;
|
|
2935
2911
|
/**
|
|
2936
2912
|
* Remove the sampling handler
|
|
2937
2913
|
*/
|
|
@@ -2975,9 +2951,6 @@ declare function getMcpTools(config: McpConfig, toolFilter?: string[] | ((tool:
|
|
|
2975
2951
|
* Tools module exports
|
|
2976
2952
|
*/
|
|
2977
2953
|
|
|
2978
|
-
type index$2_ADKSamplingHandler = ADKSamplingHandler;
|
|
2979
|
-
type index$2_ADKSamplingRequest = ADKSamplingRequest;
|
|
2980
|
-
type index$2_ADKSamplingResponse = ADKSamplingResponse;
|
|
2981
2954
|
type index$2_BaseTool = BaseTool;
|
|
2982
2955
|
declare const index$2_BaseTool: typeof BaseTool;
|
|
2983
2956
|
type index$2_BuildFunctionDeclarationOptions = BuildFunctionDeclarationOptions;
|
|
@@ -3003,12 +2976,12 @@ type index$2_McpErrorType = McpErrorType;
|
|
|
3003
2976
|
declare const index$2_McpErrorType: typeof McpErrorType;
|
|
3004
2977
|
type index$2_McpSamplingHandler = McpSamplingHandler;
|
|
3005
2978
|
declare const index$2_McpSamplingHandler: typeof McpSamplingHandler;
|
|
2979
|
+
type index$2_McpSamplingRequest = McpSamplingRequest;
|
|
2980
|
+
type index$2_McpSamplingResponse = McpSamplingResponse;
|
|
3006
2981
|
type index$2_McpToolset = McpToolset;
|
|
3007
2982
|
declare const index$2_McpToolset: typeof McpToolset;
|
|
3008
2983
|
type index$2_McpTransportType = McpTransportType;
|
|
3009
2984
|
type index$2_SamplingHandler = SamplingHandler;
|
|
3010
|
-
type index$2_SamplingRequest = SamplingRequest;
|
|
3011
|
-
type index$2_SamplingResponse = SamplingResponse;
|
|
3012
2985
|
type index$2_ToolConfig = ToolConfig;
|
|
3013
2986
|
type index$2_ToolContext = ToolContext;
|
|
3014
2987
|
declare const index$2_ToolContext: typeof ToolContext;
|
|
@@ -3025,7 +2998,7 @@ declare const index$2_jsonSchemaToDeclaration: typeof jsonSchemaToDeclaration;
|
|
|
3025
2998
|
declare const index$2_mcpSchemaToParameters: typeof mcpSchemaToParameters;
|
|
3026
2999
|
declare const index$2_normalizeJsonSchema: typeof normalizeJsonSchema;
|
|
3027
3000
|
declare namespace index$2 {
|
|
3028
|
-
export {
|
|
3001
|
+
export { index$2_BaseTool as BaseTool, type index$2_BuildFunctionDeclarationOptions as BuildFunctionDeclarationOptions, index$2_ExitLoopTool as ExitLoopTool, index$2_FileOperationsTool as FileOperationsTool, index$2_FunctionTool as FunctionTool, index$2_GetUserChoiceTool as GetUserChoiceTool, index$2_GoogleSearch as GoogleSearch, index$2_HttpRequestTool as HttpRequestTool, type index$2_IToolContext as IToolContext, index$2_LoadMemoryTool as LoadMemoryTool, type index$2_McpConfig as McpConfig, index$2_McpError as McpError, index$2_McpErrorType as McpErrorType, index$2_McpSamplingHandler as McpSamplingHandler, type index$2_McpSamplingRequest as McpSamplingRequest, type index$2_McpSamplingResponse as McpSamplingResponse, index$2_McpToolset as McpToolset, type index$2_McpTransportType as McpTransportType, type index$2_SamplingHandler as SamplingHandler, type index$2_ToolConfig as ToolConfig, index$2_ToolContext as ToolContext, index$2_TransferToAgentTool as TransferToAgentTool, index$2_UserInteractionTool as UserInteractionTool, index$2_adkToMcpToolType as adkToMcpToolType, index$2_buildFunctionDeclaration as buildFunctionDeclaration, index$2_createFunctionTool as createFunctionTool, index$2_createSamplingHandler as createSamplingHandler, index$2_getMcpTools as getMcpTools, index$2_jsonSchemaToDeclaration as jsonSchemaToDeclaration, index$2_mcpSchemaToParameters as mcpSchemaToParameters, index$2_normalizeJsonSchema as normalizeJsonSchema };
|
|
3029
3002
|
}
|
|
3030
3003
|
|
|
3031
3004
|
/**
|
|
@@ -3584,4 +3557,4 @@ declare class InMemoryRunner extends Runner {
|
|
|
3584
3557
|
|
|
3585
3558
|
declare const VERSION = "0.1.0";
|
|
3586
3559
|
|
|
3587
|
-
export {
|
|
3560
|
+
export { Agent, type AgentConfig, index$3 as Agents, AnthropicLLM, type AnthropicLLMConfig, AnthropicLLMConnection, ApiKeyCredential, ApiKeyScheme, type AudioTranscriptionConfig, AuthConfig, AuthCredential, AuthCredentialType, AuthHandler, AuthScheme, AuthSchemeType, BaseAgent, BaseLLM, BaseLLMConnection, type BaseMemoryService, BaseTool, BasicAuthCredential, BearerTokenCredential, type BuildFunctionDeclarationOptions, ExitLoopTool, FileOperationsTool, type FunctionCall, type FunctionDeclaration, FunctionTool, GetUserChoiceTool, GoogleLLM, type GoogleLLMConfig, GoogleSearch, HttpRequestTool, HttpScheme, type IToolContext, type ImageContent, InMemoryMemoryService, InMemoryRunner, InMemorySessionService, InvocationContext, type JSONSchema, LLMRegistry, LLMRequest, type LLMRequestConfig, LLMResponse, LangGraphAgent, type LangGraphAgentConfig, type LangGraphNode, type ListSessionOptions, LoadMemoryTool, LoopAgent, type LoopAgentConfig, type McpConfig, McpError, McpErrorType, McpSamplingHandler, type McpSamplingRequest, type McpSamplingResponse, McpToolset, type McpTransportType, index$1 as Memory, type MemoryResult, type Message, type MessageContent, type MessageRole, index$4 as Models, OAuth2Credential, OAuth2Scheme, type OAuthFlow, type OAuthFlows, OpenAILLM, type OpenAILLMConfig, OpenAILLMConnection, OpenIdConnectScheme, ParallelAgent, type ParallelAgentConfig, PersistentMemoryService, PgLiteSessionService, PostgresSessionService, RunConfig, Runner, type SamplingHandler, type SearchMemoryOptions, type SearchMemoryResponse, SequentialAgent, type SequentialAgentConfig, type Session, type SessionService, SessionState, index as Sessions, type SpeechConfig, SqliteSessionService, StreamingMode, type TextContent, type ToolCall, type ToolConfig, ToolContext, index$2 as Tools, TransferToAgentTool, UserInteractionTool, VERSION, adkToMcpToolType, buildFunctionDeclaration, cloneSession, createFunctionTool, createSamplingHandler, generateSessionId, getMcpTools, jsonSchemaToDeclaration, mcpSchemaToParameters, normalizeJsonSchema, registerProviders, validateSession };
|
package/dist/index.d.ts
CHANGED
|
@@ -2703,7 +2703,7 @@ type McpConfig = {
|
|
|
2703
2703
|
* Sampling handler for processing MCP sampling requests.
|
|
2704
2704
|
* This allows MCP servers to request LLM completions through your ADK agent.
|
|
2705
2705
|
*/
|
|
2706
|
-
samplingHandler?:
|
|
2706
|
+
samplingHandler?: SamplingHandler;
|
|
2707
2707
|
};
|
|
2708
2708
|
type McpTransportType = {
|
|
2709
2709
|
mode: "stdio";
|
|
@@ -2735,41 +2735,9 @@ declare class McpError extends Error {
|
|
|
2735
2735
|
originalError?: Error;
|
|
2736
2736
|
constructor(message: string, type: McpErrorType, originalError?: Error);
|
|
2737
2737
|
}
|
|
2738
|
-
type
|
|
2739
|
-
type
|
|
2740
|
-
type SamplingHandler = (
|
|
2741
|
-
/**
|
|
2742
|
-
* ADK sampling request format - what we pass to the user's handler
|
|
2743
|
-
*/
|
|
2744
|
-
interface ADKSamplingRequest {
|
|
2745
|
-
messages: Message[];
|
|
2746
|
-
systemPrompt?: string;
|
|
2747
|
-
modelPreferences?: {
|
|
2748
|
-
hints?: Array<{
|
|
2749
|
-
name?: string;
|
|
2750
|
-
}>;
|
|
2751
|
-
costPriority?: number;
|
|
2752
|
-
speedPriority?: number;
|
|
2753
|
-
intelligencePriority?: number;
|
|
2754
|
-
};
|
|
2755
|
-
includeContext?: "none" | "thisServer" | "allServers";
|
|
2756
|
-
temperature?: number;
|
|
2757
|
-
maxTokens: number;
|
|
2758
|
-
stopSequences?: string[];
|
|
2759
|
-
metadata?: Record<string, unknown>;
|
|
2760
|
-
}
|
|
2761
|
-
/**
|
|
2762
|
-
* ADK sampling response format - what we expect from the user's handler
|
|
2763
|
-
*/
|
|
2764
|
-
interface ADKSamplingResponse {
|
|
2765
|
-
model: string;
|
|
2766
|
-
stopReason?: "endTurn" | "stopSequence" | "maxTokens" | string;
|
|
2767
|
-
content: string | null;
|
|
2768
|
-
}
|
|
2769
|
-
/**
|
|
2770
|
-
* ADK sampling handler function type - receives ADK formatted messages
|
|
2771
|
-
*/
|
|
2772
|
-
type ADKSamplingHandler = (request: ADKSamplingRequest) => Promise<ADKSamplingResponse>;
|
|
2738
|
+
type McpSamplingRequest = z.infer<typeof CreateMessageRequestSchema>;
|
|
2739
|
+
type McpSamplingResponse = z.infer<typeof CreateMessageResultSchema>;
|
|
2740
|
+
type SamplingHandler = (messages: LLMRequest) => Promise<LLMResponse>;
|
|
2773
2741
|
|
|
2774
2742
|
declare class McpClientService {
|
|
2775
2743
|
private config;
|
|
@@ -2816,7 +2784,7 @@ declare class McpClientService {
|
|
|
2816
2784
|
/**
|
|
2817
2785
|
* Set a new ADK sampling handler
|
|
2818
2786
|
*/
|
|
2819
|
-
setSamplingHandler(handler:
|
|
2787
|
+
setSamplingHandler(handler: SamplingHandler): void;
|
|
2820
2788
|
/**
|
|
2821
2789
|
* Remove the sampling handler
|
|
2822
2790
|
*/
|
|
@@ -2849,16 +2817,24 @@ declare function mcpSchemaToParameters(mcpTool: Tool): JSONSchema;
|
|
|
2849
2817
|
*/
|
|
2850
2818
|
declare class McpSamplingHandler {
|
|
2851
2819
|
private logger;
|
|
2852
|
-
private
|
|
2853
|
-
constructor(
|
|
2820
|
+
private samplingHandler;
|
|
2821
|
+
constructor(samplingHandler: SamplingHandler);
|
|
2854
2822
|
/**
|
|
2855
2823
|
* Handle MCP sampling request and convert between formats
|
|
2856
2824
|
*/
|
|
2857
|
-
handleSamplingRequest(request:
|
|
2825
|
+
handleSamplingRequest(request: McpSamplingRequest): Promise<McpSamplingResponse>;
|
|
2858
2826
|
/**
|
|
2859
2827
|
* Convert MCP messages to ADK message format
|
|
2860
2828
|
*/
|
|
2861
2829
|
private convertMcpMessagesToADK;
|
|
2830
|
+
/**
|
|
2831
|
+
* Convert a single MCP message to ADK message format
|
|
2832
|
+
*/
|
|
2833
|
+
private convertSingleMcpMessageToADK;
|
|
2834
|
+
/**
|
|
2835
|
+
* Convert MCP message content to ADK content format
|
|
2836
|
+
*/
|
|
2837
|
+
private convertMcpContentToADK;
|
|
2862
2838
|
/**
|
|
2863
2839
|
* Convert ADK response to MCP response format
|
|
2864
2840
|
*/
|
|
@@ -2866,7 +2842,7 @@ declare class McpSamplingHandler {
|
|
|
2866
2842
|
/**
|
|
2867
2843
|
* Update the ADK handler
|
|
2868
2844
|
*/
|
|
2869
|
-
updateHandler(handler:
|
|
2845
|
+
updateHandler(handler: SamplingHandler): void;
|
|
2870
2846
|
}
|
|
2871
2847
|
/**
|
|
2872
2848
|
* Helper function to create a sampling handler with proper TypeScript types.
|
|
@@ -2903,7 +2879,7 @@ declare class McpSamplingHandler {
|
|
|
2903
2879
|
* });
|
|
2904
2880
|
* ```
|
|
2905
2881
|
*/
|
|
2906
|
-
declare function createSamplingHandler(handler:
|
|
2882
|
+
declare function createSamplingHandler(handler: SamplingHandler): SamplingHandler;
|
|
2907
2883
|
|
|
2908
2884
|
/**
|
|
2909
2885
|
* A class for managing MCP tools similar to Python's MCPToolset.
|
|
@@ -2931,7 +2907,7 @@ declare class McpToolset {
|
|
|
2931
2907
|
*
|
|
2932
2908
|
* @param handler - ADK sampling handler that receives ADK-formatted messages
|
|
2933
2909
|
*/
|
|
2934
|
-
setSamplingHandler(handler:
|
|
2910
|
+
setSamplingHandler(handler: SamplingHandler): void;
|
|
2935
2911
|
/**
|
|
2936
2912
|
* Remove the sampling handler
|
|
2937
2913
|
*/
|
|
@@ -2975,9 +2951,6 @@ declare function getMcpTools(config: McpConfig, toolFilter?: string[] | ((tool:
|
|
|
2975
2951
|
* Tools module exports
|
|
2976
2952
|
*/
|
|
2977
2953
|
|
|
2978
|
-
type index$2_ADKSamplingHandler = ADKSamplingHandler;
|
|
2979
|
-
type index$2_ADKSamplingRequest = ADKSamplingRequest;
|
|
2980
|
-
type index$2_ADKSamplingResponse = ADKSamplingResponse;
|
|
2981
2954
|
type index$2_BaseTool = BaseTool;
|
|
2982
2955
|
declare const index$2_BaseTool: typeof BaseTool;
|
|
2983
2956
|
type index$2_BuildFunctionDeclarationOptions = BuildFunctionDeclarationOptions;
|
|
@@ -3003,12 +2976,12 @@ type index$2_McpErrorType = McpErrorType;
|
|
|
3003
2976
|
declare const index$2_McpErrorType: typeof McpErrorType;
|
|
3004
2977
|
type index$2_McpSamplingHandler = McpSamplingHandler;
|
|
3005
2978
|
declare const index$2_McpSamplingHandler: typeof McpSamplingHandler;
|
|
2979
|
+
type index$2_McpSamplingRequest = McpSamplingRequest;
|
|
2980
|
+
type index$2_McpSamplingResponse = McpSamplingResponse;
|
|
3006
2981
|
type index$2_McpToolset = McpToolset;
|
|
3007
2982
|
declare const index$2_McpToolset: typeof McpToolset;
|
|
3008
2983
|
type index$2_McpTransportType = McpTransportType;
|
|
3009
2984
|
type index$2_SamplingHandler = SamplingHandler;
|
|
3010
|
-
type index$2_SamplingRequest = SamplingRequest;
|
|
3011
|
-
type index$2_SamplingResponse = SamplingResponse;
|
|
3012
2985
|
type index$2_ToolConfig = ToolConfig;
|
|
3013
2986
|
type index$2_ToolContext = ToolContext;
|
|
3014
2987
|
declare const index$2_ToolContext: typeof ToolContext;
|
|
@@ -3025,7 +2998,7 @@ declare const index$2_jsonSchemaToDeclaration: typeof jsonSchemaToDeclaration;
|
|
|
3025
2998
|
declare const index$2_mcpSchemaToParameters: typeof mcpSchemaToParameters;
|
|
3026
2999
|
declare const index$2_normalizeJsonSchema: typeof normalizeJsonSchema;
|
|
3027
3000
|
declare namespace index$2 {
|
|
3028
|
-
export {
|
|
3001
|
+
export { index$2_BaseTool as BaseTool, type index$2_BuildFunctionDeclarationOptions as BuildFunctionDeclarationOptions, index$2_ExitLoopTool as ExitLoopTool, index$2_FileOperationsTool as FileOperationsTool, index$2_FunctionTool as FunctionTool, index$2_GetUserChoiceTool as GetUserChoiceTool, index$2_GoogleSearch as GoogleSearch, index$2_HttpRequestTool as HttpRequestTool, type index$2_IToolContext as IToolContext, index$2_LoadMemoryTool as LoadMemoryTool, type index$2_McpConfig as McpConfig, index$2_McpError as McpError, index$2_McpErrorType as McpErrorType, index$2_McpSamplingHandler as McpSamplingHandler, type index$2_McpSamplingRequest as McpSamplingRequest, type index$2_McpSamplingResponse as McpSamplingResponse, index$2_McpToolset as McpToolset, type index$2_McpTransportType as McpTransportType, type index$2_SamplingHandler as SamplingHandler, type index$2_ToolConfig as ToolConfig, index$2_ToolContext as ToolContext, index$2_TransferToAgentTool as TransferToAgentTool, index$2_UserInteractionTool as UserInteractionTool, index$2_adkToMcpToolType as adkToMcpToolType, index$2_buildFunctionDeclaration as buildFunctionDeclaration, index$2_createFunctionTool as createFunctionTool, index$2_createSamplingHandler as createSamplingHandler, index$2_getMcpTools as getMcpTools, index$2_jsonSchemaToDeclaration as jsonSchemaToDeclaration, index$2_mcpSchemaToParameters as mcpSchemaToParameters, index$2_normalizeJsonSchema as normalizeJsonSchema };
|
|
3029
3002
|
}
|
|
3030
3003
|
|
|
3031
3004
|
/**
|
|
@@ -3584,4 +3557,4 @@ declare class InMemoryRunner extends Runner {
|
|
|
3584
3557
|
|
|
3585
3558
|
declare const VERSION = "0.1.0";
|
|
3586
3559
|
|
|
3587
|
-
export {
|
|
3560
|
+
export { Agent, type AgentConfig, index$3 as Agents, AnthropicLLM, type AnthropicLLMConfig, AnthropicLLMConnection, ApiKeyCredential, ApiKeyScheme, type AudioTranscriptionConfig, AuthConfig, AuthCredential, AuthCredentialType, AuthHandler, AuthScheme, AuthSchemeType, BaseAgent, BaseLLM, BaseLLMConnection, type BaseMemoryService, BaseTool, BasicAuthCredential, BearerTokenCredential, type BuildFunctionDeclarationOptions, ExitLoopTool, FileOperationsTool, type FunctionCall, type FunctionDeclaration, FunctionTool, GetUserChoiceTool, GoogleLLM, type GoogleLLMConfig, GoogleSearch, HttpRequestTool, HttpScheme, type IToolContext, type ImageContent, InMemoryMemoryService, InMemoryRunner, InMemorySessionService, InvocationContext, type JSONSchema, LLMRegistry, LLMRequest, type LLMRequestConfig, LLMResponse, LangGraphAgent, type LangGraphAgentConfig, type LangGraphNode, type ListSessionOptions, LoadMemoryTool, LoopAgent, type LoopAgentConfig, type McpConfig, McpError, McpErrorType, McpSamplingHandler, type McpSamplingRequest, type McpSamplingResponse, McpToolset, type McpTransportType, index$1 as Memory, type MemoryResult, type Message, type MessageContent, type MessageRole, index$4 as Models, OAuth2Credential, OAuth2Scheme, type OAuthFlow, type OAuthFlows, OpenAILLM, type OpenAILLMConfig, OpenAILLMConnection, OpenIdConnectScheme, ParallelAgent, type ParallelAgentConfig, PersistentMemoryService, PgLiteSessionService, PostgresSessionService, RunConfig, Runner, type SamplingHandler, type SearchMemoryOptions, type SearchMemoryResponse, SequentialAgent, type SequentialAgentConfig, type Session, type SessionService, SessionState, index as Sessions, type SpeechConfig, SqliteSessionService, StreamingMode, type TextContent, type ToolCall, type ToolConfig, ToolContext, index$2 as Tools, TransferToAgentTool, UserInteractionTool, VERSION, adkToMcpToolType, buildFunctionDeclaration, cloneSession, createFunctionTool, createSamplingHandler, generateSessionId, getMcpTools, jsonSchemaToDeclaration, mcpSchemaToParameters, normalizeJsonSchema, registerProviders, validateSession };
|
package/dist/index.js
CHANGED
|
@@ -2982,8 +2982,8 @@ var McpError = class extends Error {
|
|
|
2982
2982
|
var McpSamplingHandler = (_class17 = class {
|
|
2983
2983
|
__init20() {this.logger = new Logger({ name: "McpSamplingHandler" })}
|
|
2984
2984
|
|
|
2985
|
-
constructor(
|
|
2986
|
-
this.
|
|
2985
|
+
constructor(samplingHandler) {;_class17.prototype.__init20.call(this);
|
|
2986
|
+
this.samplingHandler = samplingHandler;
|
|
2987
2987
|
}
|
|
2988
2988
|
/**
|
|
2989
2989
|
* Handle MCP sampling request and convert between formats
|
|
@@ -3024,19 +3024,19 @@ var McpSamplingHandler = (_class17 = class {
|
|
|
3024
3024
|
);
|
|
3025
3025
|
}
|
|
3026
3026
|
this.logger.debug("Converting MCP request to ADK format");
|
|
3027
|
-
const adkMessages = this.convertMcpMessagesToADK(
|
|
3027
|
+
const adkMessages = this.convertMcpMessagesToADK(
|
|
3028
|
+
mcpParams.messages,
|
|
3029
|
+
mcpParams.systemPrompt
|
|
3030
|
+
);
|
|
3028
3031
|
const adkRequest = {
|
|
3029
3032
|
messages: adkMessages,
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
maxTokens: mcpParams.maxTokens,
|
|
3035
|
-
stopSequences: mcpParams.stopSequences,
|
|
3036
|
-
metadata: mcpParams.metadata
|
|
3033
|
+
config: {
|
|
3034
|
+
temperature: mcpParams.temperature,
|
|
3035
|
+
max_tokens: mcpParams.maxTokens
|
|
3036
|
+
}
|
|
3037
3037
|
};
|
|
3038
3038
|
this.logger.debug("Calling ADK sampling handler");
|
|
3039
|
-
const adkResponse = await this.
|
|
3039
|
+
const adkResponse = await this.samplingHandler(adkRequest);
|
|
3040
3040
|
this.logger.debug("Converting ADK response to MCP format");
|
|
3041
3041
|
const mcpResponse = this.convertADKResponseToMcp(adkResponse);
|
|
3042
3042
|
const responseValidation = _typesjs.CreateMessageResultSchema.safeParse(mcpResponse);
|
|
@@ -3066,54 +3066,66 @@ var McpSamplingHandler = (_class17 = class {
|
|
|
3066
3066
|
/**
|
|
3067
3067
|
* Convert MCP messages to ADK message format
|
|
3068
3068
|
*/
|
|
3069
|
-
convertMcpMessagesToADK(mcpMessages) {
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
const contentParts = [];
|
|
3077
|
-
if (mcpMessage.content.text) {
|
|
3078
|
-
contentParts.push({
|
|
3079
|
-
type: "text",
|
|
3080
|
-
text: mcpMessage.content.text
|
|
3081
|
-
});
|
|
3082
|
-
}
|
|
3083
|
-
if (mcpMessage.content.data) {
|
|
3084
|
-
const mimeType = mcpMessage.content.mimeType || "image/jpeg";
|
|
3085
|
-
const dataUrl = `data:${mimeType};base64,${mcpMessage.content.data}`;
|
|
3086
|
-
contentParts.push({
|
|
3087
|
-
type: "image",
|
|
3088
|
-
image_url: {
|
|
3089
|
-
url: dataUrl
|
|
3090
|
-
}
|
|
3091
|
-
});
|
|
3092
|
-
}
|
|
3093
|
-
adkContent = contentParts.length > 0 ? contentParts : "";
|
|
3094
|
-
} else {
|
|
3095
|
-
this.logger.warn(
|
|
3096
|
-
`Unknown MCP content type: ${mcpMessage.content.type}`
|
|
3097
|
-
);
|
|
3098
|
-
adkContent = mcpMessage.content.data || "";
|
|
3099
|
-
}
|
|
3100
|
-
const adkMessage = {
|
|
3101
|
-
role: adkRole,
|
|
3102
|
-
content: adkContent
|
|
3103
|
-
};
|
|
3104
|
-
this.logger.debug(
|
|
3105
|
-
`Converted MCP message - role: ${mcpMessage.role} -> ${adkRole}, content type: ${mcpMessage.content.type}`
|
|
3106
|
-
);
|
|
3107
|
-
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
|
|
3108
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 || "";
|
|
3109
3123
|
}
|
|
3110
3124
|
/**
|
|
3111
3125
|
* Convert ADK response to MCP response format
|
|
3112
3126
|
*/
|
|
3113
3127
|
convertADKResponseToMcp(adkResponse) {
|
|
3114
3128
|
const mcpResponse = {
|
|
3115
|
-
model: adkResponse.model,
|
|
3116
|
-
stopReason: adkResponse.stopReason,
|
|
3117
3129
|
role: "assistant",
|
|
3118
3130
|
// ADK responses are always from assistant
|
|
3119
3131
|
content: {
|
|
@@ -3121,16 +3133,14 @@ var McpSamplingHandler = (_class17 = class {
|
|
|
3121
3133
|
text: adkResponse.content || ""
|
|
3122
3134
|
}
|
|
3123
3135
|
};
|
|
3124
|
-
this.logger.debug(
|
|
3125
|
-
`Converted ADK response - model: ${adkResponse.model}, content length: ${_optionalChain([adkResponse, 'access', _39 => _39.content, 'optionalAccess', _40 => _40.length]) || 0}`
|
|
3126
|
-
);
|
|
3136
|
+
this.logger.debug(`Received content: ${adkResponse.content}`);
|
|
3127
3137
|
return mcpResponse;
|
|
3128
3138
|
}
|
|
3129
3139
|
/**
|
|
3130
3140
|
* Update the ADK handler
|
|
3131
3141
|
*/
|
|
3132
3142
|
updateHandler(handler) {
|
|
3133
|
-
this.
|
|
3143
|
+
this.samplingHandler = handler;
|
|
3134
3144
|
this.logger.debug("ADK sampling handler updated");
|
|
3135
3145
|
}
|
|
3136
3146
|
}, _class17);
|
|
@@ -3350,7 +3360,7 @@ var McpClientService = (_class18 = class {
|
|
|
3350
3360
|
},
|
|
3351
3361
|
this,
|
|
3352
3362
|
async (instance) => await instance.reinitialize(),
|
|
3353
|
-
_optionalChain([this, 'access',
|
|
3363
|
+
_optionalChain([this, 'access', _39 => _39.config, 'access', _40 => _40.retryOptions, 'optionalAccess', _41 => _41.maxRetries]) || 2
|
|
3354
3364
|
);
|
|
3355
3365
|
return await wrappedCall();
|
|
3356
3366
|
} catch (error) {
|
|
@@ -3432,7 +3442,7 @@ var McpClientService = (_class18 = class {
|
|
|
3432
3442
|
this.mcpSamplingHandler = null;
|
|
3433
3443
|
if (this.client) {
|
|
3434
3444
|
try {
|
|
3435
|
-
_optionalChain([this, 'access',
|
|
3445
|
+
_optionalChain([this, 'access', _42 => _42.client, 'access', _43 => _43.removeRequestHandler, 'optionalCall', _44 => _44("sampling/createMessage")]);
|
|
3436
3446
|
} catch (error) {
|
|
3437
3447
|
console.error("Failed to remove sampling handler:", error);
|
|
3438
3448
|
}
|
|
@@ -3810,7 +3820,7 @@ var McpToolset = (_class20 = class {
|
|
|
3810
3820
|
"resource_closed_error" /* RESOURCE_CLOSED_ERROR */
|
|
3811
3821
|
);
|
|
3812
3822
|
}
|
|
3813
|
-
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) {
|
|
3814
3824
|
return this.tools;
|
|
3815
3825
|
}
|
|
3816
3826
|
if (!this.clientService) {
|
|
@@ -3836,7 +3846,7 @@ var McpToolset = (_class20 = class {
|
|
|
3836
3846
|
}
|
|
3837
3847
|
}
|
|
3838
3848
|
}
|
|
3839
|
-
if (_optionalChain([this, 'access',
|
|
3849
|
+
if (_optionalChain([this, 'access', _48 => _48.config, 'access', _49 => _49.cacheConfig, 'optionalAccess', _50 => _50.enabled]) !== false) {
|
|
3840
3850
|
this.tools = tools;
|
|
3841
3851
|
}
|
|
3842
3852
|
return tools;
|
|
@@ -4140,7 +4150,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4140
4150
|
* Convert Anthropic tool calls to ADK tool calls
|
|
4141
4151
|
*/
|
|
4142
4152
|
convertToolCalls(toolUses) {
|
|
4143
|
-
if (!_optionalChain([toolUses, 'optionalAccess',
|
|
4153
|
+
if (!_optionalChain([toolUses, 'optionalAccess', _51 => _51.length])) {
|
|
4144
4154
|
return void 0;
|
|
4145
4155
|
}
|
|
4146
4156
|
return toolUses.map((toolUse) => ({
|
|
@@ -4155,7 +4165,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4155
4165
|
* Extract tool uses from response content
|
|
4156
4166
|
*/
|
|
4157
4167
|
extractToolUses(content) {
|
|
4158
|
-
if (!_optionalChain([content, 'optionalAccess',
|
|
4168
|
+
if (!_optionalChain([content, 'optionalAccess', _52 => _52.length])) return [];
|
|
4159
4169
|
const toolUses = [];
|
|
4160
4170
|
for (const block of content) {
|
|
4161
4171
|
this.logger.debug(`Processing content block of type: ${block.type}`);
|
|
@@ -4271,17 +4281,17 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4271
4281
|
const toolUses = this.extractToolUses(apiResponse.content);
|
|
4272
4282
|
const toolCalls = this.convertToolCalls(toolUses);
|
|
4273
4283
|
this.logger.debug(
|
|
4274
|
-
`- 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`
|
|
4275
4285
|
);
|
|
4276
4286
|
const llmResponse = new LLMResponse({
|
|
4277
4287
|
role: "assistant",
|
|
4278
4288
|
content,
|
|
4279
|
-
tool_calls: _optionalChain([toolCalls, 'optionalAccess',
|
|
4289
|
+
tool_calls: _optionalChain([toolCalls, 'optionalAccess', _54 => _54.length]) ? toolCalls : void 0,
|
|
4280
4290
|
raw_response: apiResponse
|
|
4281
4291
|
});
|
|
4282
4292
|
const logObject = {
|
|
4283
4293
|
role: llmResponse.role,
|
|
4284
|
-
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 ? "..." : ""),
|
|
4285
4295
|
tool_calls: llmResponse.tool_calls ? `[${llmResponse.tool_calls.length} calls]` : "undefined"
|
|
4286
4296
|
};
|
|
4287
4297
|
this.logger.debug(
|
|
@@ -4316,17 +4326,17 @@ var AnthropicLLM = (_class23 = class extends BaseLLM {
|
|
|
4316
4326
|
*/
|
|
4317
4327
|
constructor(model, config) {
|
|
4318
4328
|
super(model);_class23.prototype.__init34.call(this);;
|
|
4319
|
-
this.apiKey = _optionalChain([config, 'optionalAccess',
|
|
4320
|
-
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";
|
|
4321
4331
|
if (!this.apiKey) {
|
|
4322
4332
|
throw new Error(
|
|
4323
4333
|
"Anthropic API key is required. Provide it in config or set ANTHROPIC_API_KEY environment variable."
|
|
4324
4334
|
);
|
|
4325
4335
|
}
|
|
4326
4336
|
this.defaultParams = {
|
|
4327
|
-
temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4328
|
-
top_p: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4329
|
-
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))
|
|
4330
4340
|
};
|
|
4331
4341
|
}
|
|
4332
4342
|
/**
|
|
@@ -4412,7 +4422,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4412
4422
|
* Convert ADK function declarations to Anthropic tool format
|
|
4413
4423
|
*/
|
|
4414
4424
|
convertFunctionsToTools(functions) {
|
|
4415
|
-
if (!_optionalChain([functions, 'optionalAccess',
|
|
4425
|
+
if (!_optionalChain([functions, 'optionalAccess', _66 => _66.length])) {
|
|
4416
4426
|
return [];
|
|
4417
4427
|
}
|
|
4418
4428
|
return functions.map((func) => ({
|
|
@@ -4425,7 +4435,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4425
4435
|
* Convert Anthropic tool calls to ADK tool calls
|
|
4426
4436
|
*/
|
|
4427
4437
|
convertToolUses(toolUses) {
|
|
4428
|
-
if (!_optionalChain([toolUses, 'optionalAccess',
|
|
4438
|
+
if (!_optionalChain([toolUses, 'optionalAccess', _67 => _67.length])) {
|
|
4429
4439
|
return [];
|
|
4430
4440
|
}
|
|
4431
4441
|
return toolUses.map((toolUse) => ({
|
|
@@ -4440,7 +4450,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4440
4450
|
* Extract tool uses from response content
|
|
4441
4451
|
*/
|
|
4442
4452
|
extractToolUses(content) {
|
|
4443
|
-
if (!_optionalChain([content, 'optionalAccess',
|
|
4453
|
+
if (!_optionalChain([content, 'optionalAccess', _68 => _68.length])) return [];
|
|
4444
4454
|
const toolUses = [];
|
|
4445
4455
|
for (const block of content) {
|
|
4446
4456
|
this.logger.debug(`Processing content block of type: ${block.type}`);
|
|
@@ -4511,7 +4521,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4511
4521
|
temperature: _nullishCoalesce(llmRequest.config.temperature, () => ( this.defaultParams.temperature)),
|
|
4512
4522
|
max_tokens: _nullishCoalesce(llmRequest.config.max_tokens, () => ( this.defaultParams.max_tokens)),
|
|
4513
4523
|
top_p: _nullishCoalesce(llmRequest.config.top_p, () => ( this.defaultParams.top_p)),
|
|
4514
|
-
tools: _optionalChain([tools, 'optionalAccess',
|
|
4524
|
+
tools: _optionalChain([tools, 'optionalAccess', _69 => _69.length]) ? tools : void 0
|
|
4515
4525
|
};
|
|
4516
4526
|
this.logger.debug("API Request:", {
|
|
4517
4527
|
model: params.model,
|
|
@@ -4542,7 +4552,7 @@ ${typeof message.content === "string" ? message.content : JSON.stringify(message
|
|
|
4542
4552
|
});
|
|
4543
4553
|
const logObject = {
|
|
4544
4554
|
role: llmResponse.role,
|
|
4545
|
-
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 ? "..." : ""),
|
|
4546
4556
|
tool_calls: llmResponse.tool_calls ? `[${llmResponse.tool_calls.length} calls]` : "undefined"
|
|
4547
4557
|
};
|
|
4548
4558
|
this.logger.debug(
|
|
@@ -4595,9 +4605,9 @@ var GoogleLLM = class extends BaseLLM {
|
|
|
4595
4605
|
constructor(model, config) {
|
|
4596
4606
|
super(model);
|
|
4597
4607
|
const apiKey = process.env.GOOGLE_API_KEY;
|
|
4598
|
-
const projectId = _optionalChain([config, 'optionalAccess',
|
|
4599
|
-
const location = _optionalChain([config, 'optionalAccess',
|
|
4600
|
-
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";
|
|
4601
4611
|
if (!useVertexAI && !apiKey) {
|
|
4602
4612
|
throw new Error(
|
|
4603
4613
|
"Google API Key is required. Provide via config or GOOGLE_API_KEY env var."
|
|
@@ -4622,9 +4632,9 @@ var GoogleLLM = class extends BaseLLM {
|
|
|
4622
4632
|
}
|
|
4623
4633
|
this.ai = new (0, _genai.GoogleGenAI)(options);
|
|
4624
4634
|
this.defaultParams = {
|
|
4625
|
-
temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4626
|
-
topP: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
4627
|
-
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))
|
|
4628
4638
|
};
|
|
4629
4639
|
}
|
|
4630
4640
|
/**
|
|
@@ -4762,7 +4772,7 @@ var GoogleLLM = class extends BaseLLM {
|
|
|
4762
4772
|
);
|
|
4763
4773
|
parts.push({ text: "" });
|
|
4764
4774
|
}
|
|
4765
|
-
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]))) {
|
|
4766
4776
|
console.error(
|
|
4767
4777
|
`[GoogleLLM] convertMessage - Invalid parts for 'function' role. Expected 1 functionResponse part. Got:`,
|
|
4768
4778
|
JSON.stringify(parts),
|
|
@@ -4870,13 +4880,13 @@ var GoogleLLM = class extends BaseLLM {
|
|
|
4870
4880
|
role: "assistant",
|
|
4871
4881
|
content: null
|
|
4872
4882
|
});
|
|
4873
|
-
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") {
|
|
4874
4884
|
result.content = response.candidates[0].content.parts[0].text;
|
|
4875
4885
|
}
|
|
4876
|
-
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])) {
|
|
4877
4887
|
result.content = response.candidates[0].content.parts[0].text;
|
|
4878
4888
|
}
|
|
4879
|
-
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])) {
|
|
4880
4890
|
const functionCall = response.candidates[0].content.parts[0].functionCall;
|
|
4881
4891
|
result.function_call = {
|
|
4882
4892
|
name: functionCall.name,
|
|
@@ -4923,10 +4933,10 @@ var GoogleLLM = class extends BaseLLM {
|
|
|
4923
4933
|
if (stream) {
|
|
4924
4934
|
const streamingResult = await this.ai.models.generateContentStream(requestOptions);
|
|
4925
4935
|
for await (const chunk of streamingResult) {
|
|
4926
|
-
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])) {
|
|
4927
4937
|
continue;
|
|
4928
4938
|
}
|
|
4929
|
-
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]) || "";
|
|
4930
4940
|
const partialResponse = new LLMResponse({
|
|
4931
4941
|
content: partialText,
|
|
4932
4942
|
role: "assistant",
|
|
@@ -5067,10 +5077,10 @@ var OpenAILLMConnection = (_class24 = class extends BaseLLMConnection {
|
|
|
5067
5077
|
for await (const chunk of stream) {
|
|
5068
5078
|
if (chunk.choices.length === 0) continue;
|
|
5069
5079
|
const delta = chunk.choices[0].delta;
|
|
5070
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
5080
|
+
if (_optionalChain([delta, 'optionalAccess', _117 => _117.content])) {
|
|
5071
5081
|
responseContent += delta.content;
|
|
5072
5082
|
}
|
|
5073
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
5083
|
+
if (_optionalChain([delta, 'optionalAccess', _118 => _118.function_call])) {
|
|
5074
5084
|
if (!functionCall) {
|
|
5075
5085
|
functionCall = {
|
|
5076
5086
|
name: delta.function_call.name || "",
|
|
@@ -5081,7 +5091,7 @@ var OpenAILLMConnection = (_class24 = class extends BaseLLMConnection {
|
|
|
5081
5091
|
functionCall.arguments += delta.function_call.arguments || "";
|
|
5082
5092
|
}
|
|
5083
5093
|
}
|
|
5084
|
-
if (_optionalChain([delta, 'optionalAccess',
|
|
5094
|
+
if (_optionalChain([delta, 'optionalAccess', _119 => _119.tool_calls])) {
|
|
5085
5095
|
for (const toolDelta of delta.tool_calls) {
|
|
5086
5096
|
const id = toolDelta.id || "";
|
|
5087
5097
|
let tool = toolCalls.find((t) => t.id === id);
|
|
@@ -5089,20 +5099,20 @@ var OpenAILLMConnection = (_class24 = class extends BaseLLMConnection {
|
|
|
5089
5099
|
tool = {
|
|
5090
5100
|
id,
|
|
5091
5101
|
function: {
|
|
5092
|
-
name: _optionalChain([toolDelta, 'access',
|
|
5093
|
-
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]) || ""
|
|
5094
5104
|
}
|
|
5095
5105
|
};
|
|
5096
5106
|
toolCalls.push(tool);
|
|
5097
5107
|
} else {
|
|
5098
|
-
tool.function.name += _optionalChain([toolDelta, 'access',
|
|
5099
|
-
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]) || "";
|
|
5100
5110
|
}
|
|
5101
5111
|
}
|
|
5102
5112
|
}
|
|
5103
5113
|
if (this.responseCallback) {
|
|
5104
5114
|
const response = new LLMResponse({
|
|
5105
|
-
content: _optionalChain([delta, 'optionalAccess',
|
|
5115
|
+
content: _optionalChain([delta, 'optionalAccess', _128 => _128.content]) || null,
|
|
5106
5116
|
role: "assistant",
|
|
5107
5117
|
function_call: functionCall,
|
|
5108
5118
|
tool_calls: toolCalls.length > 0 ? toolCalls : void 0,
|
|
@@ -5213,16 +5223,16 @@ var OpenAILLM = (_class25 = class extends BaseLLM {
|
|
|
5213
5223
|
constructor(model, config) {
|
|
5214
5224
|
super(model);_class25.prototype.__init36.call(this);;
|
|
5215
5225
|
this.client = new (0, _openai2.default)({
|
|
5216
|
-
apiKey: _optionalChain([config, 'optionalAccess',
|
|
5217
|
-
baseURL: _optionalChain([config, 'optionalAccess',
|
|
5218
|
-
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])
|
|
5219
5229
|
});
|
|
5220
5230
|
this.defaultParams = {
|
|
5221
|
-
temperature: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
5222
|
-
top_p: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
5223
|
-
max_tokens: _optionalChain([config, 'optionalAccess',
|
|
5224
|
-
frequency_penalty: _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
5225
|
-
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))
|
|
5226
5236
|
};
|
|
5227
5237
|
}
|
|
5228
5238
|
/**
|
|
@@ -5332,16 +5342,16 @@ var OpenAILLM = (_class25 = class extends BaseLLM {
|
|
|
5332
5342
|
*/
|
|
5333
5343
|
convertResponse(response) {
|
|
5334
5344
|
const result = new LLMResponse({
|
|
5335
|
-
content: _optionalChain([response, 'access',
|
|
5336
|
-
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"
|
|
5337
5347
|
});
|
|
5338
|
-
if (_optionalChain([response, 'access',
|
|
5348
|
+
if (_optionalChain([response, 'access', _146 => _146.message, 'optionalAccess', _147 => _147.function_call])) {
|
|
5339
5349
|
result.function_call = {
|
|
5340
5350
|
name: response.message.function_call.name,
|
|
5341
5351
|
arguments: response.message.function_call.arguments
|
|
5342
5352
|
};
|
|
5343
5353
|
}
|
|
5344
|
-
if (_optionalChain([response, 'access',
|
|
5354
|
+
if (_optionalChain([response, 'access', _148 => _148.message, 'optionalAccess', _149 => _149.tool_calls])) {
|
|
5345
5355
|
result.tool_calls = response.message.tool_calls.map((tool) => ({
|
|
5346
5356
|
id: tool.id,
|
|
5347
5357
|
function: {
|
|
@@ -5359,24 +5369,24 @@ var OpenAILLM = (_class25 = class extends BaseLLM {
|
|
|
5359
5369
|
this.logger.debug(
|
|
5360
5370
|
`Converting chunk - delta: ${JSON.stringify(chunk.delta || {})}`
|
|
5361
5371
|
);
|
|
5362
|
-
const content = _optionalChain([chunk, 'access',
|
|
5372
|
+
const content = _optionalChain([chunk, 'access', _150 => _150.delta, 'optionalAccess', _151 => _151.content]);
|
|
5363
5373
|
const result = new LLMResponse({
|
|
5364
5374
|
content: content !== void 0 ? content : null,
|
|
5365
|
-
role: _optionalChain([chunk, 'access',
|
|
5375
|
+
role: _optionalChain([chunk, 'access', _152 => _152.delta, 'optionalAccess', _153 => _153.role]) || "assistant",
|
|
5366
5376
|
is_partial: true
|
|
5367
5377
|
});
|
|
5368
|
-
if (_optionalChain([chunk, 'access',
|
|
5378
|
+
if (_optionalChain([chunk, 'access', _154 => _154.delta, 'optionalAccess', _155 => _155.function_call])) {
|
|
5369
5379
|
result.function_call = {
|
|
5370
5380
|
name: chunk.delta.function_call.name || "",
|
|
5371
5381
|
arguments: chunk.delta.function_call.arguments || ""
|
|
5372
5382
|
};
|
|
5373
5383
|
}
|
|
5374
|
-
if (_optionalChain([chunk, 'access',
|
|
5384
|
+
if (_optionalChain([chunk, 'access', _156 => _156.delta, 'optionalAccess', _157 => _157.tool_calls])) {
|
|
5375
5385
|
result.tool_calls = chunk.delta.tool_calls.map((tool) => ({
|
|
5376
5386
|
id: tool.id || "",
|
|
5377
5387
|
function: {
|
|
5378
|
-
name: _optionalChain([tool, 'access',
|
|
5379
|
-
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]) || ""
|
|
5380
5390
|
}
|
|
5381
5391
|
}));
|
|
5382
5392
|
}
|
|
@@ -5425,7 +5435,7 @@ var OpenAILLM = (_class25 = class extends BaseLLM {
|
|
|
5425
5435
|
accumulatedContent += responseChunk.content;
|
|
5426
5436
|
}
|
|
5427
5437
|
this.logger.debug(
|
|
5428
|
-
`Chunk received - delta: "${_optionalChain([choice, 'access',
|
|
5438
|
+
`Chunk received - delta: "${_optionalChain([choice, 'access', _162 => _162.delta, 'optionalAccess', _163 => _163.content]) || ""}"`,
|
|
5429
5439
|
`responseChunk content: "${responseChunk.content || ""}"`,
|
|
5430
5440
|
`is_partial: ${responseChunk.is_partial}`,
|
|
5431
5441
|
`accumulated: "${accumulatedContent.substring(0, 30)}${accumulatedContent.length > 30 ? "..." : ""}"`
|
|
@@ -5691,7 +5701,7 @@ var OAuth2Credential = class extends AuthCredential {
|
|
|
5691
5701
|
"Cannot refresh token: no refresh token or refresh function"
|
|
5692
5702
|
);
|
|
5693
5703
|
}
|
|
5694
|
-
const result = await _optionalChain([this, 'access',
|
|
5704
|
+
const result = await _optionalChain([this, 'access', _164 => _164.refreshFunction, 'optionalCall', _165 => _165(this.refreshToken)]);
|
|
5695
5705
|
if (!result) {
|
|
5696
5706
|
throw new Error("Failed to refresh token");
|
|
5697
5707
|
}
|
|
@@ -5745,7 +5755,7 @@ var AuthHandler = class {
|
|
|
5745
5755
|
* Gets the authentication token
|
|
5746
5756
|
*/
|
|
5747
5757
|
getToken() {
|
|
5748
|
-
return _optionalChain([this, 'access',
|
|
5758
|
+
return _optionalChain([this, 'access', _166 => _166.credential, 'optionalAccess', _167 => _167.getToken, 'call', _168 => _168()]);
|
|
5749
5759
|
}
|
|
5750
5760
|
/**
|
|
5751
5761
|
* Gets headers for HTTP requests
|
|
@@ -5760,7 +5770,7 @@ var AuthHandler = class {
|
|
|
5760
5770
|
* Refreshes the token if necessary
|
|
5761
5771
|
*/
|
|
5762
5772
|
async refreshToken() {
|
|
5763
|
-
if (_optionalChain([this, 'access',
|
|
5773
|
+
if (_optionalChain([this, 'access', _169 => _169.credential, 'optionalAccess', _170 => _170.canRefresh, 'call', _171 => _171()])) {
|
|
5764
5774
|
await this.credential.refresh();
|
|
5765
5775
|
}
|
|
5766
5776
|
}
|
|
@@ -5986,7 +5996,7 @@ var InMemoryMemoryService = class {
|
|
|
5986
5996
|
};
|
|
5987
5997
|
const normalizedQuery = query.toLowerCase().trim();
|
|
5988
5998
|
const queryTerms = normalizedQuery.split(/\s+/);
|
|
5989
|
-
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());
|
|
5990
6000
|
for (const session of sessionsToSearch) {
|
|
5991
6001
|
const matchedEvents = [];
|
|
5992
6002
|
const scores = [];
|
|
@@ -6012,7 +6022,7 @@ var InMemoryMemoryService = class {
|
|
|
6012
6022
|
}
|
|
6013
6023
|
}
|
|
6014
6024
|
const score = queryTerms.length > 0 ? termMatches / queryTerms.length : 0;
|
|
6015
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6025
|
+
if (_optionalChain([options, 'optionalAccess', _173 => _173.threshold]) !== void 0 && score < options.threshold) {
|
|
6016
6026
|
continue;
|
|
6017
6027
|
}
|
|
6018
6028
|
if (score > 0) {
|
|
@@ -6032,7 +6042,7 @@ var InMemoryMemoryService = class {
|
|
|
6032
6042
|
response.memories.sort(
|
|
6033
6043
|
(a, b) => (_nullishCoalesce(b.relevanceScore, () => ( 0))) - (_nullishCoalesce(a.relevanceScore, () => ( 0)))
|
|
6034
6044
|
);
|
|
6035
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6045
|
+
if (_optionalChain([options, 'optionalAccess', _174 => _174.limit]) !== void 0 && options.limit > 0) {
|
|
6036
6046
|
response.memories = response.memories.slice(0, options.limit);
|
|
6037
6047
|
}
|
|
6038
6048
|
return response;
|
|
@@ -6298,17 +6308,17 @@ var InMemorySessionService = class {
|
|
|
6298
6308
|
let sessions = Array.from(this.sessions.values()).filter(
|
|
6299
6309
|
(session) => session.userId === userId
|
|
6300
6310
|
);
|
|
6301
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6311
|
+
if (_optionalChain([options, 'optionalAccess', _175 => _175.createdAfter])) {
|
|
6302
6312
|
sessions = sessions.filter(
|
|
6303
6313
|
(session) => session.createdAt >= options.createdAfter
|
|
6304
6314
|
);
|
|
6305
6315
|
}
|
|
6306
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6316
|
+
if (_optionalChain([options, 'optionalAccess', _176 => _176.updatedAfter])) {
|
|
6307
6317
|
sessions = sessions.filter(
|
|
6308
6318
|
(session) => session.updatedAt >= options.updatedAfter
|
|
6309
6319
|
);
|
|
6310
6320
|
}
|
|
6311
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6321
|
+
if (_optionalChain([options, 'optionalAccess', _177 => _177.metadataFilter])) {
|
|
6312
6322
|
sessions = sessions.filter((session) => {
|
|
6313
6323
|
for (const [key, value] of Object.entries(options.metadataFilter)) {
|
|
6314
6324
|
if (session.metadata[key] !== value) {
|
|
@@ -6319,7 +6329,7 @@ var InMemorySessionService = class {
|
|
|
6319
6329
|
});
|
|
6320
6330
|
}
|
|
6321
6331
|
sessions.sort((a, b) => b.updatedAt.getTime() - a.updatedAt.getTime());
|
|
6322
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6332
|
+
if (_optionalChain([options, 'optionalAccess', _178 => _178.limit]) !== void 0 && options.limit > 0) {
|
|
6323
6333
|
sessions = sessions.slice(0, options.limit);
|
|
6324
6334
|
}
|
|
6325
6335
|
return sessions;
|
|
@@ -6354,7 +6364,7 @@ var InMemorySessionService = class {
|
|
|
6354
6364
|
if (event.is_partial) {
|
|
6355
6365
|
return event;
|
|
6356
6366
|
}
|
|
6357
|
-
if (_optionalChain([event, 'access',
|
|
6367
|
+
if (_optionalChain([event, 'access', _179 => _179.actions, 'optionalAccess', _180 => _180.stateDelta])) {
|
|
6358
6368
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
6359
6369
|
if (key.startsWith("_temp_")) {
|
|
6360
6370
|
continue;
|
|
@@ -6460,7 +6470,7 @@ var PostgresSessionService = class {
|
|
|
6460
6470
|
}
|
|
6461
6471
|
async listSessions(userId, options) {
|
|
6462
6472
|
let query = this.db.select().from(this.sessionsTable).where(_drizzleorm.eq.call(void 0, this.sessionsTable.userId, userId));
|
|
6463
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6473
|
+
if (_optionalChain([options, 'optionalAccess', _181 => _181.limit]) !== void 0 && options.limit > 0) {
|
|
6464
6474
|
query = query.limit(options.limit);
|
|
6465
6475
|
}
|
|
6466
6476
|
const results = await query;
|
|
@@ -6487,12 +6497,12 @@ var PostgresSessionService = class {
|
|
|
6487
6497
|
if (event.is_partial) {
|
|
6488
6498
|
return event;
|
|
6489
6499
|
}
|
|
6490
|
-
if (_optionalChain([event, 'access',
|
|
6500
|
+
if (_optionalChain([event, 'access', _182 => _182.actions, 'optionalAccess', _183 => _183.stateDelta])) {
|
|
6491
6501
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
6492
6502
|
if (key.startsWith("_temp_")) {
|
|
6493
6503
|
continue;
|
|
6494
6504
|
}
|
|
6495
|
-
_optionalChain([session, 'access',
|
|
6505
|
+
_optionalChain([session, 'access', _184 => _184.state, 'optionalAccess', _185 => _185.set, 'call', _186 => _186(key, value)]);
|
|
6496
6506
|
}
|
|
6497
6507
|
}
|
|
6498
6508
|
if (!session.events) {
|
|
@@ -6636,7 +6646,7 @@ var PgLiteSessionService = (_class27 = class {
|
|
|
6636
6646
|
async listSessions(userId, options) {
|
|
6637
6647
|
await this.ensureInitialized();
|
|
6638
6648
|
let query = this.db.select().from(this.sessionsTable).where(_drizzleorm.eq.call(void 0, this.sessionsTable.userId, userId));
|
|
6639
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6649
|
+
if (_optionalChain([options, 'optionalAccess', _187 => _187.limit]) !== void 0 && options.limit > 0) {
|
|
6640
6650
|
query = query.limit(options.limit);
|
|
6641
6651
|
}
|
|
6642
6652
|
const results = await query;
|
|
@@ -6659,12 +6669,12 @@ var PgLiteSessionService = (_class27 = class {
|
|
|
6659
6669
|
if (event.is_partial) {
|
|
6660
6670
|
return event;
|
|
6661
6671
|
}
|
|
6662
|
-
if (_optionalChain([event, 'access',
|
|
6672
|
+
if (_optionalChain([event, 'access', _188 => _188.actions, 'optionalAccess', _189 => _189.stateDelta])) {
|
|
6663
6673
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
6664
6674
|
if (key.startsWith("_temp_")) {
|
|
6665
6675
|
continue;
|
|
6666
6676
|
}
|
|
6667
|
-
_optionalChain([session, 'access',
|
|
6677
|
+
_optionalChain([session, 'access', _190 => _190.state, 'optionalAccess', _191 => _191.set, 'call', _192 => _192(key, value)]);
|
|
6668
6678
|
}
|
|
6669
6679
|
}
|
|
6670
6680
|
if (!session.events) {
|
|
@@ -6821,7 +6831,7 @@ var SqliteSessionService = (_class28 = class {
|
|
|
6821
6831
|
async listSessions(userId, options) {
|
|
6822
6832
|
await this.ensureInitialized();
|
|
6823
6833
|
let query = this.db.select().from(this.sessionsTable).where(_drizzleorm.eq.call(void 0, this.sessionsTable.userId, userId));
|
|
6824
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
6834
|
+
if (_optionalChain([options, 'optionalAccess', _193 => _193.limit]) !== void 0 && options.limit > 0) {
|
|
6825
6835
|
query = query.limit(options.limit);
|
|
6826
6836
|
}
|
|
6827
6837
|
const results = await query;
|
|
@@ -6844,12 +6854,12 @@ var SqliteSessionService = (_class28 = class {
|
|
|
6844
6854
|
if (event.is_partial) {
|
|
6845
6855
|
return event;
|
|
6846
6856
|
}
|
|
6847
|
-
if (_optionalChain([event, 'access',
|
|
6857
|
+
if (_optionalChain([event, 'access', _194 => _194.actions, 'optionalAccess', _195 => _195.stateDelta])) {
|
|
6848
6858
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
6849
6859
|
if (key.startsWith("_temp_")) {
|
|
6850
6860
|
continue;
|
|
6851
6861
|
}
|
|
6852
|
-
_optionalChain([session, 'access',
|
|
6862
|
+
_optionalChain([session, 'access', _196 => _196.state, 'optionalAccess', _197 => _197.set, 'call', _198 => _198(key, value)]);
|
|
6853
6863
|
}
|
|
6854
6864
|
}
|
|
6855
6865
|
if (!session.events) {
|
package/dist/index.mjs
CHANGED
|
@@ -2981,9 +2981,9 @@ var McpError = class extends Error {
|
|
|
2981
2981
|
// src/tools/mcp/sampling-handler.ts
|
|
2982
2982
|
var McpSamplingHandler = class {
|
|
2983
2983
|
logger = new Logger({ name: "McpSamplingHandler" });
|
|
2984
|
-
|
|
2985
|
-
constructor(
|
|
2986
|
-
this.
|
|
2984
|
+
samplingHandler;
|
|
2985
|
+
constructor(samplingHandler) {
|
|
2986
|
+
this.samplingHandler = samplingHandler;
|
|
2987
2987
|
}
|
|
2988
2988
|
/**
|
|
2989
2989
|
* Handle MCP sampling request and convert between formats
|
|
@@ -3024,19 +3024,19 @@ var McpSamplingHandler = class {
|
|
|
3024
3024
|
);
|
|
3025
3025
|
}
|
|
3026
3026
|
this.logger.debug("Converting MCP request to ADK format");
|
|
3027
|
-
const adkMessages = this.convertMcpMessagesToADK(
|
|
3027
|
+
const adkMessages = this.convertMcpMessagesToADK(
|
|
3028
|
+
mcpParams.messages,
|
|
3029
|
+
mcpParams.systemPrompt
|
|
3030
|
+
);
|
|
3028
3031
|
const adkRequest = {
|
|
3029
3032
|
messages: adkMessages,
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
maxTokens: mcpParams.maxTokens,
|
|
3035
|
-
stopSequences: mcpParams.stopSequences,
|
|
3036
|
-
metadata: mcpParams.metadata
|
|
3033
|
+
config: {
|
|
3034
|
+
temperature: mcpParams.temperature,
|
|
3035
|
+
max_tokens: mcpParams.maxTokens
|
|
3036
|
+
}
|
|
3037
3037
|
};
|
|
3038
3038
|
this.logger.debug("Calling ADK sampling handler");
|
|
3039
|
-
const adkResponse = await this.
|
|
3039
|
+
const adkResponse = await this.samplingHandler(adkRequest);
|
|
3040
3040
|
this.logger.debug("Converting ADK response to MCP format");
|
|
3041
3041
|
const mcpResponse = this.convertADKResponseToMcp(adkResponse);
|
|
3042
3042
|
const responseValidation = CreateMessageResultSchema.safeParse(mcpResponse);
|
|
@@ -3066,54 +3066,66 @@ var McpSamplingHandler = class {
|
|
|
3066
3066
|
/**
|
|
3067
3067
|
* Convert MCP messages to ADK message format
|
|
3068
3068
|
*/
|
|
3069
|
-
convertMcpMessagesToADK(mcpMessages) {
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
const contentParts = [];
|
|
3077
|
-
if (mcpMessage.content.text) {
|
|
3078
|
-
contentParts.push({
|
|
3079
|
-
type: "text",
|
|
3080
|
-
text: mcpMessage.content.text
|
|
3081
|
-
});
|
|
3082
|
-
}
|
|
3083
|
-
if (mcpMessage.content.data) {
|
|
3084
|
-
const mimeType = mcpMessage.content.mimeType || "image/jpeg";
|
|
3085
|
-
const dataUrl = `data:${mimeType};base64,${mcpMessage.content.data}`;
|
|
3086
|
-
contentParts.push({
|
|
3087
|
-
type: "image",
|
|
3088
|
-
image_url: {
|
|
3089
|
-
url: dataUrl
|
|
3090
|
-
}
|
|
3091
|
-
});
|
|
3092
|
-
}
|
|
3093
|
-
adkContent = contentParts.length > 0 ? contentParts : "";
|
|
3094
|
-
} else {
|
|
3095
|
-
this.logger.warn(
|
|
3096
|
-
`Unknown MCP content type: ${mcpMessage.content.type}`
|
|
3097
|
-
);
|
|
3098
|
-
adkContent = mcpMessage.content.data || "";
|
|
3099
|
-
}
|
|
3100
|
-
const adkMessage = {
|
|
3101
|
-
role: adkRole,
|
|
3102
|
-
content: adkContent
|
|
3103
|
-
};
|
|
3104
|
-
this.logger.debug(
|
|
3105
|
-
`Converted MCP message - role: ${mcpMessage.role} -> ${adkRole}, content type: ${mcpMessage.content.type}`
|
|
3106
|
-
);
|
|
3107
|
-
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
|
|
3108
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 || "";
|
|
3109
3123
|
}
|
|
3110
3124
|
/**
|
|
3111
3125
|
* Convert ADK response to MCP response format
|
|
3112
3126
|
*/
|
|
3113
3127
|
convertADKResponseToMcp(adkResponse) {
|
|
3114
3128
|
const mcpResponse = {
|
|
3115
|
-
model: adkResponse.model,
|
|
3116
|
-
stopReason: adkResponse.stopReason,
|
|
3117
3129
|
role: "assistant",
|
|
3118
3130
|
// ADK responses are always from assistant
|
|
3119
3131
|
content: {
|
|
@@ -3121,16 +3133,14 @@ var McpSamplingHandler = class {
|
|
|
3121
3133
|
text: adkResponse.content || ""
|
|
3122
3134
|
}
|
|
3123
3135
|
};
|
|
3124
|
-
this.logger.debug(
|
|
3125
|
-
`Converted ADK response - model: ${adkResponse.model}, content length: ${adkResponse.content?.length || 0}`
|
|
3126
|
-
);
|
|
3136
|
+
this.logger.debug(`Received content: ${adkResponse.content}`);
|
|
3127
3137
|
return mcpResponse;
|
|
3128
3138
|
}
|
|
3129
3139
|
/**
|
|
3130
3140
|
* Update the ADK handler
|
|
3131
3141
|
*/
|
|
3132
3142
|
updateHandler(handler) {
|
|
3133
|
-
this.
|
|
3143
|
+
this.samplingHandler = handler;
|
|
3134
3144
|
this.logger.debug("ADK sampling handler updated");
|
|
3135
3145
|
}
|
|
3136
3146
|
};
|