@@ -56,14 +56,24 @@ func loadEmulatorMocks(path string) (map[string][]emulatorMock, error) {
5656 }
5757
5858 mocks := make (map [string ][]emulatorMock )
59- for i , m := range file .Mocks {
59+ for i := range file .Mocks {
60+ m := & file .Mocks [i ]
6061 if m .ToolName == "" {
6162 return nil , fmt .Errorf ("invalid emulator mock at index %d: tool_name is required" , i )
6263 }
6364 if m .Parameters == nil {
6465 m .Parameters = map [string ]any {}
6566 }
66- mocks [m .ToolName ] = append (mocks [m .ToolName ], m )
67+ normalized , err := normalizeJSONValue (m .Parameters )
68+ if err != nil {
69+ return nil , fmt .Errorf ("failed to normalize parameters for mock at index %d: %w" , i , err )
70+ }
71+ normalizedMap , ok := normalized .(map [string ]any )
72+ if ! ok {
73+ return nil , fmt .Errorf ("failed to normalize parameters for mock at index %d: expected object parameters" , i )
74+ }
75+ m .Parameters = normalizedMap
76+ mocks [m .ToolName ] = append (mocks [m .ToolName ], * m )
6777 }
6878
6979 return mocks , nil
@@ -93,37 +103,28 @@ func normalizeJSONValue(v any) (any, error) {
93103 return normalized , nil
94104}
95105
96- func (e emulatorTool ) findMock (params parameters.ParamValues ) (any , bool ) {
97- in , err := normalizeJSONValue (params .AsMap ())
98- if err != nil {
99- return nil , false
100- }
101- inMap , ok := in .(map [string ]any )
102- if ! ok {
103- return nil , false
104- }
105-
106+ func (e emulatorTool ) findMock (inMap map [string ]any ) (any , bool ) {
106107 for _ , mock := range e .mocks {
107- expected , err := normalizeJSONValue (mock .Parameters )
108- if err != nil {
109- continue
110- }
111- expectedMap , ok := expected .(map [string ]any )
112- if ! ok {
113- continue
114- }
115- if reflect .DeepEqual (inMap , expectedMap ) {
108+ if reflect .DeepEqual (inMap , mock .Parameters ) {
116109 return mock .Response , true
117110 }
118111 }
119112 return nil , false
120113}
121114
122115func (e emulatorTool ) Invoke (ctx context.Context , resourceMgr tools.SourceProvider , params parameters.ParamValues , accessToken tools.AccessToken ) (any , util.ToolboxError ) {
123- if response , found := e .findMock (params ); found {
116+ in , err := normalizeJSONValue (params .AsMap ())
117+ if err != nil {
118+ return nil , util .NewAgentError ("emulator mode: failed to normalize input parameters" , err )
119+ }
120+ inMap , ok := in .(map [string ]any )
121+ if ! ok {
122+ return nil , util .NewAgentError ("emulator mode: failed to normalize input parameters" , nil )
123+ }
124+ if response , found := e .findMock (inMap ); found {
124125 return response , nil
125126 }
126- return nil , util .NewAgentError (fmt .Sprintf ("emulator mode: no mock matched for tool %q with parameters %v" , e .name , params . AsMap () ), nil )
127+ return nil , util .NewAgentError (fmt .Sprintf ("emulator mode: no mock matched for tool %q with parameters %v" , e .name , inMap ), nil )
127128}
128129
129130func (e emulatorTool ) EmbedParams (ctx context.Context , params parameters.ParamValues , embeddingModels map [string ]embeddingmodels.EmbeddingModel ) (parameters.ParamValues , error ) {
0 commit comments