refactor: unify action execution interface and merge AI action handling

This commit is contained in:
lilong.129
2025-06-07 23:59:07 +08:00
parent fcf3009c67
commit ec4f1eb68a
8 changed files with 199 additions and 65 deletions
+10 -6
View File
@@ -13,7 +13,8 @@ import (
// ToolStartToGoal implements the start_to_goal tool call.
type ToolStartToGoal struct {
// Return data fields - these define the structure of data returned by this tool
Prompt string `json:"prompt" desc:"Goal prompt that was executed"`
Prompt string `json:"prompt" desc:"Goal prompt that was executed"`
SubActions []*SubActionResult `json:"sub_actions" desc:"Sub-actions that were executed"`
}
func (t *ToolStartToGoal) Name() option.ActionName {
@@ -42,14 +43,15 @@ func (t *ToolStartToGoal) Implement() server.ToolHandlerFunc {
}
// Start to goal logic
err = driverExt.StartToGoal(ctx, unifiedReq.Prompt)
subActionResults, err := driverExt.StartToGoal(ctx, unifiedReq.Prompt)
if err != nil {
return NewMCPErrorResponse(fmt.Sprintf("Failed to achieve goal: %s", err.Error())), nil
}
message := fmt.Sprintf("Successfully achieved goal: %s", unifiedReq.Prompt)
returnData := ToolStartToGoal{
Prompt: unifiedReq.Prompt,
Prompt: unifiedReq.Prompt,
SubActions: subActionResults,
}
return NewMCPSuccessResponse(message, &returnData), nil
@@ -73,7 +75,8 @@ func (t *ToolStartToGoal) ConvertActionToCallToolRequest(action option.MobileAct
// ToolAIAction implements the ai_action tool call.
type ToolAIAction struct {
// Return data fields - these define the structure of data returned by this tool
Prompt string `json:"prompt" desc:"AI action prompt that was executed"`
Prompt string `json:"prompt" desc:"AI action prompt that was executed"`
SubActions []*SubActionResult `json:"sub_actions" desc:"Sub-actions that were executed"`
}
func (t *ToolAIAction) Name() option.ActionName {
@@ -102,14 +105,15 @@ func (t *ToolAIAction) Implement() server.ToolHandlerFunc {
}
// AI action logic
err = driverExt.AIAction(ctx, unifiedReq.Prompt)
subActionResults, err := driverExt.AIAction(ctx, unifiedReq.Prompt)
if err != nil {
return NewMCPErrorResponse(fmt.Sprintf("AI action failed: %s", err.Error())), nil
}
message := fmt.Sprintf("Successfully performed AI action with prompt: %s", unifiedReq.Prompt)
returnData := ToolAIAction{
Prompt: unifiedReq.Prompt,
Prompt: unifiedReq.Prompt,
SubActions: subActionResults,
}
return NewMCPSuccessResponse(message, &returnData), nil