mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-06 00:09:37 +08:00
- Move MobileAction struct from uixt package to uixt/option package - Delete uixt/driver_action.go file as MobileAction is now in option package - Update all import statements across the codebase to use option.MobileAction - Update ActionTool interface to use option.MobileAction in ConvertActionToCallToolRequest method - Maintain backward compatibility while improving package organization - Clean up code structure by consolidating action-related types in option package Files affected: - server/uixt.go: Updated imports and type references - step.go: Updated imports and ActionResult struct - step_ui.go: Updated all MobileAction references to option.MobileAction - uixt/mcp_server.go: Updated ActionTool interface and removed detailed comments - uixt/mcp_server_test.go: Updated all test cases to use option.MobileAction - uixt/mcp_tools_*.go: Updated ConvertActionToCallToolRequest method signatures - uixt/option/action.go: Added MobileAction struct definition - uixt/sdk.go: Updated ExecuteAction method signature
115 lines
3.6 KiB
Go
115 lines
3.6 KiB
Go
package uixt
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/httprunner/httprunner/v5/uixt/option"
|
|
"github.com/mark3labs/mcp-go/mcp"
|
|
"github.com/mark3labs/mcp-go/server"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
// ToolAIAction implements the ai_action tool call.
|
|
type ToolAIAction struct{}
|
|
|
|
func (t *ToolAIAction) Name() option.ActionName {
|
|
return option.ACTION_AIAction
|
|
}
|
|
|
|
func (t *ToolAIAction) Description() string {
|
|
return "Perform AI-driven automation actions using natural language prompts to describe the desired operation"
|
|
}
|
|
|
|
func (t *ToolAIAction) Options() []mcp.ToolOption {
|
|
unifiedReq := &option.ActionOptions{}
|
|
return unifiedReq.GetMCPOptions(option.ACTION_AIAction)
|
|
}
|
|
|
|
func (t *ToolAIAction) Implement() server.ToolHandlerFunc {
|
|
return func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|
driverExt, err := setupXTDriver(ctx, request.Params.Arguments)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("setup driver failed: %w", err)
|
|
}
|
|
|
|
unifiedReq, err := parseActionOptions(request.Params.Arguments)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// AI action logic
|
|
log.Info().Str("prompt", unifiedReq.Prompt).Msg("performing AI action")
|
|
err = driverExt.AIAction(unifiedReq.Prompt)
|
|
if err != nil {
|
|
return mcp.NewToolResultError(fmt.Sprintf("AI action failed: %s", err.Error())), nil
|
|
}
|
|
|
|
return mcp.NewToolResultText(fmt.Sprintf("Successfully performed AI action with prompt: %s", unifiedReq.Prompt)), nil
|
|
}
|
|
}
|
|
|
|
func (t *ToolAIAction) ConvertActionToCallToolRequest(action option.MobileAction) (mcp.CallToolRequest, error) {
|
|
if prompt, ok := action.Params.(string); ok {
|
|
arguments := map[string]any{
|
|
"prompt": prompt,
|
|
}
|
|
return buildMCPCallToolRequest(t.Name(), arguments), nil
|
|
}
|
|
return mcp.CallToolRequest{}, fmt.Errorf("invalid AI action params: %v", action.Params)
|
|
}
|
|
|
|
func (t *ToolAIAction) ReturnSchema() map[string]string {
|
|
return map[string]string{
|
|
"message": "string: Success message confirming AI action was performed",
|
|
"prompt": "string: Natural language prompt that was processed",
|
|
"actionTaken": "string: Description of the specific action that was taken by AI",
|
|
}
|
|
}
|
|
|
|
// ToolFinished implements the finished tool call.
|
|
type ToolFinished struct{}
|
|
|
|
func (t *ToolFinished) Name() option.ActionName {
|
|
return option.ACTION_Finished
|
|
}
|
|
|
|
func (t *ToolFinished) Description() string {
|
|
return "Mark the current automation task as completed with a result message"
|
|
}
|
|
|
|
func (t *ToolFinished) Options() []mcp.ToolOption {
|
|
unifiedReq := &option.ActionOptions{}
|
|
return unifiedReq.GetMCPOptions(option.ACTION_Finished)
|
|
}
|
|
|
|
func (t *ToolFinished) Implement() server.ToolHandlerFunc {
|
|
return func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|
unifiedReq, err := parseActionOptions(request.Params.Arguments)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
log.Info().Str("reason", unifiedReq.Content).Msg("task finished")
|
|
|
|
return mcp.NewToolResultText(fmt.Sprintf("Task completed: %s", unifiedReq.Content)), nil
|
|
}
|
|
}
|
|
|
|
func (t *ToolFinished) ConvertActionToCallToolRequest(action option.MobileAction) (mcp.CallToolRequest, error) {
|
|
if reason, ok := action.Params.(string); ok {
|
|
arguments := map[string]any{
|
|
"content": reason,
|
|
}
|
|
return buildMCPCallToolRequest(t.Name(), arguments), nil
|
|
}
|
|
return mcp.CallToolRequest{}, fmt.Errorf("invalid finished params: %v", action.Params)
|
|
}
|
|
|
|
func (t *ToolFinished) ReturnSchema() map[string]string {
|
|
return map[string]string{
|
|
"message": "string: Success message confirming task completion",
|
|
"content": "string: Completion reason or result description",
|
|
"taskCompleted": "bool: Boolean indicating task was successfully finished",
|
|
}
|
|
}
|