change: fix logs

This commit is contained in:
lilong.129
2025-06-05 20:26:18 +08:00
parent 5f400735fc
commit 56831845ca
14 changed files with 18 additions and 38 deletions
+1 -1
View File
@@ -1 +1 @@
v5.0.0-beta-2506052000 v5.0.0-beta-2506052026
+1
View File
@@ -742,6 +742,7 @@ func (ad *ADBDriver) ForegroundInfo() (app types.AppInfo, err error) {
} }
func (ad *ADBDriver) SetIme(imeRegx string) error { func (ad *ADBDriver) SetIme(imeRegx string) error {
log.Info().Str("imeRegx", imeRegx).Msg("ADBDriver.SetIme")
imeList := ad.ListIme() imeList := ad.ListIme()
ime := "" ime := ""
for _, imeName := range imeList { for _, imeName := range imeList {
+5
View File
@@ -201,6 +201,7 @@ func (wd *BrowserDriver) CreateNetListener() (*websocket.Conn, error) {
} }
func (wd *BrowserDriver) CloseTab(pageIndex int) (err error) { func (wd *BrowserDriver) CloseTab(pageIndex int) (err error) {
log.Info().Int("pageIndex", pageIndex).Msg("BrowserDriver.CloseTab")
data := map[string]interface{}{ data := map[string]interface{}{
"page_index": pageIndex, "page_index": pageIndex,
} }
@@ -210,6 +211,7 @@ func (wd *BrowserDriver) CloseTab(pageIndex int) (err error) {
} }
func (wd *BrowserDriver) HoverBySelector(selector string, options ...option.ActionOption) (err error) { func (wd *BrowserDriver) HoverBySelector(selector string, options ...option.ActionOption) (err error) {
log.Info().Str("selector", selector).Msg("BrowserDriver.HoverBySelector")
data := map[string]interface{}{ data := map[string]interface{}{
"selector": selector, "selector": selector,
} }
@@ -222,6 +224,7 @@ func (wd *BrowserDriver) HoverBySelector(selector string, options ...option.Acti
} }
func (wd *BrowserDriver) TapBySelector(selector string, options ...option.ActionOption) (err error) { func (wd *BrowserDriver) TapBySelector(selector string, options ...option.ActionOption) (err error) {
log.Info().Str("selector", selector).Msg("BrowserDriver.TapBySelector")
data := map[string]interface{}{ data := map[string]interface{}{
"selector": selector, "selector": selector,
} }
@@ -234,6 +237,7 @@ func (wd *BrowserDriver) TapBySelector(selector string, options ...option.Action
} }
func (wd *BrowserDriver) SecondaryClick(x, y float64) (err error) { func (wd *BrowserDriver) SecondaryClick(x, y float64) (err error) {
log.Info().Float64("x", x).Float64("y", y).Msg("BrowserDriver.SecondaryClick")
data := map[string]interface{}{ data := map[string]interface{}{
"x": x, "x": x,
"y": y, "y": y,
@@ -243,6 +247,7 @@ func (wd *BrowserDriver) SecondaryClick(x, y float64) (err error) {
} }
func (wd *BrowserDriver) SecondaryClickBySelector(selector string, options ...option.ActionOption) (err error) { func (wd *BrowserDriver) SecondaryClickBySelector(selector string, options ...option.ActionOption) (err error) {
log.Info().Str("selector", selector).Msg("BrowserDriver.SecondaryClickBySelector")
data := map[string]interface{}{ data := map[string]interface{}{
"selector": selector, "selector": selector,
} }
+8 -6
View File
@@ -18,7 +18,7 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
) )
func (dExt *XTDriver) StartToGoal(ctx context.Context, text string, opts ...option.ActionOption) error { func (dExt *XTDriver) StartToGoal(ctx context.Context, prompt string, opts ...option.ActionOption) error {
options := option.NewActionOptions(opts...) options := option.NewActionOptions(opts...)
log.Info().Int("max_retry_times", options.MaxRetryTimes).Msg("StartToGoal") log.Info().Int("max_retry_times", options.MaxRetryTimes).Msg("StartToGoal")
var attempt int var attempt int
@@ -34,7 +34,7 @@ func (dExt *XTDriver) StartToGoal(ctx context.Context, text string, opts ...opti
default: default:
} }
if err := dExt.AIAction(ctx, text, opts...); err != nil { if err := dExt.AIAction(ctx, prompt, opts...); err != nil {
// Check if this is a LLM service request error that should be retried // Check if this is a LLM service request error that should be retried
if errors.Is(err, code.LLMRequestServiceError) { if errors.Is(err, code.LLMRequestServiceError) {
log.Warn().Err(err).Int("attempt", attempt). log.Warn().Err(err).Int("attempt", attempt).
@@ -50,9 +50,11 @@ func (dExt *XTDriver) StartToGoal(ctx context.Context, text string, opts ...opti
} }
} }
func (dExt *XTDriver) AIAction(ctx context.Context, text string, opts ...option.ActionOption) error { func (dExt *XTDriver) AIAction(ctx context.Context, prompt string, opts ...option.ActionOption) error {
log.Info().Str("prompt", prompt).Msg("performing AI action")
// plan next action // plan next action
result, err := dExt.PlanNextAction(ctx, text, opts...) result, err := dExt.PlanNextAction(ctx, prompt, opts...)
if err != nil { if err != nil {
return err return err
} }
@@ -95,7 +97,7 @@ func (dExt *XTDriver) AIAction(ctx context.Context, text string, opts ...option.
return nil return nil
} }
func (dExt *XTDriver) PlanNextAction(ctx context.Context, text string, opts ...option.ActionOption) (*ai.PlanningResult, error) { func (dExt *XTDriver) PlanNextAction(ctx context.Context, prompt string, opts ...option.ActionOption) (*ai.PlanningResult, error) {
if dExt.LLMService == nil { if dExt.LLMService == nil {
return nil, errors.New("LLM service is not initialized") return nil, errors.New("LLM service is not initialized")
} }
@@ -127,7 +129,7 @@ func (dExt *XTDriver) PlanNextAction(ctx context.Context, text string, opts ...o
} }
planningOpts := &ai.PlanningOptions{ planningOpts := &ai.PlanningOptions{
UserInstruction: text, UserInstruction: prompt,
Message: &schema.Message{ Message: &schema.Message{
Role: schema.User, Role: schema.User,
MultiContent: []schema.ChatMessagePart{ MultiContent: []schema.ChatMessagePart{
+3
View File
@@ -96,6 +96,7 @@ func (dExt *XTDriver) SwipeToTapTexts(texts []string, opts ...option.ActionOptio
return errors.New("no text to tap") return errors.New("no text to tap")
} }
log.Info().Strs("texts", texts).Msg("swipe to tap texts")
opts = append(opts, option.WithMatchOne(true), option.WithRegex(true)) opts = append(opts, option.WithMatchOne(true), option.WithRegex(true))
actionOptions := option.NewActionOptions(opts...) actionOptions := option.NewActionOptions(opts...)
actionOptions.Identifier = "" actionOptions.Identifier = ""
@@ -136,6 +137,8 @@ func (dExt *XTDriver) SwipeToTapTexts(texts []string, opts ...option.ActionOptio
} }
func (dExt *XTDriver) SwipeToTapApp(appName string, opts ...option.ActionOption) error { func (dExt *XTDriver) SwipeToTapApp(appName string, opts ...option.ActionOption) error {
log.Info().Str("appName", appName).Msg("swipe to tap app")
// go to home screen // go to home screen
if err := dExt.Home(); err != nil { if err := dExt.Home(); err != nil {
return errors.Wrap(err, "go to home screen failed") return errors.Wrap(err, "go to home screen failed")
-2
View File
@@ -39,7 +39,6 @@ func (t *ToolStartToGoal) Implement() server.ToolHandlerFunc {
} }
// Start to goal logic // Start to goal logic
log.Info().Str("prompt", unifiedReq.Prompt).Msg("starting to goal")
err = driverExt.StartToGoal(ctx, unifiedReq.Prompt) err = driverExt.StartToGoal(ctx, unifiedReq.Prompt)
if err != nil { if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("Failed to achieve goal: %s", err.Error())), nil return mcp.NewToolResultError(fmt.Sprintf("Failed to achieve goal: %s", err.Error())), nil
@@ -98,7 +97,6 @@ func (t *ToolAIAction) Implement() server.ToolHandlerFunc {
} }
// AI action logic // AI action logic
log.Info().Str("prompt", unifiedReq.Prompt).Msg("performing AI action")
err = driverExt.AIAction(ctx, unifiedReq.Prompt) err = driverExt.AIAction(ctx, unifiedReq.Prompt)
if err != nil { if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("AI action failed: %s", err.Error())), nil return mcp.NewToolResultError(fmt.Sprintf("AI action failed: %s", err.Error())), nil
-5
View File
@@ -84,7 +84,6 @@ func (t *ToolLaunchApp) Implement() server.ToolHandlerFunc {
} }
// Launch app action logic // Launch app action logic
log.Info().Str("packageName", unifiedReq.PackageName).Msg("launching app")
err = driverExt.AppLaunch(unifiedReq.PackageName) err = driverExt.AppLaunch(unifiedReq.PackageName)
if err != nil { if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("Launch app failed: %s", err.Error())), nil return mcp.NewToolResultError(fmt.Sprintf("Launch app failed: %s", err.Error())), nil
@@ -141,7 +140,6 @@ func (t *ToolTerminateApp) Implement() server.ToolHandlerFunc {
} }
// Terminate app action logic // Terminate app action logic
log.Info().Str("packageName", unifiedReq.PackageName).Msg("terminating app")
success, err := driverExt.AppTerminate(unifiedReq.PackageName) success, err := driverExt.AppTerminate(unifiedReq.PackageName)
if err != nil { if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("Terminate app failed: %s", err.Error())), nil return mcp.NewToolResultError(fmt.Sprintf("Terminate app failed: %s", err.Error())), nil
@@ -197,7 +195,6 @@ func (t *ToolAppInstall) Implement() server.ToolHandlerFunc {
} }
// App install action logic // App install action logic
log.Info().Str("appUrl", unifiedReq.AppUrl).Msg("installing app")
err = driverExt.GetDevice().Install(unifiedReq.AppUrl) err = driverExt.GetDevice().Install(unifiedReq.AppUrl)
if err != nil { if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("App install failed: %s", err.Error())), nil return mcp.NewToolResultError(fmt.Sprintf("App install failed: %s", err.Error())), nil
@@ -253,7 +250,6 @@ func (t *ToolAppUninstall) Implement() server.ToolHandlerFunc {
} }
// App uninstall action logic // App uninstall action logic
log.Info().Str("packageName", unifiedReq.PackageName).Msg("uninstalling app")
err = driverExt.GetDevice().Uninstall(unifiedReq.PackageName) err = driverExt.GetDevice().Uninstall(unifiedReq.PackageName)
if err != nil { if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("App uninstall failed: %s", err.Error())), nil return mcp.NewToolResultError(fmt.Sprintf("App uninstall failed: %s", err.Error())), nil
@@ -309,7 +305,6 @@ func (t *ToolAppClear) Implement() server.ToolHandlerFunc {
} }
// App clear action logic // App clear action logic
log.Info().Str("packageName", unifiedReq.PackageName).Msg("clearing app")
err = driverExt.AppClear(unifiedReq.PackageName) err = driverExt.AppClear(unifiedReq.PackageName)
if err != nil { if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("App clear failed: %s", err.Error())), nil return mcp.NewToolResultError(fmt.Sprintf("App clear failed: %s", err.Error())), nil
-4
View File
@@ -8,7 +8,6 @@ import (
"github.com/httprunner/httprunner/v5/uixt/types" "github.com/httprunner/httprunner/v5/uixt/types"
"github.com/mark3labs/mcp-go/mcp" "github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server" "github.com/mark3labs/mcp-go/server"
"github.com/rs/zerolog/log"
) )
// ToolPressButton implements the press_button tool call. // ToolPressButton implements the press_button tool call.
@@ -40,7 +39,6 @@ func (t *ToolPressButton) Implement() server.ToolHandlerFunc {
} }
// Press button action logic // Press button action logic
log.Info().Str("button", string(unifiedReq.Button)).Msg("pressing button")
err = driverExt.PressButton(types.DeviceButton(unifiedReq.Button)) err = driverExt.PressButton(types.DeviceButton(unifiedReq.Button))
if err != nil { if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("Press button failed: %s", err.Error())), nil return mcp.NewToolResultError(fmt.Sprintf("Press button failed: %s", err.Error())), nil
@@ -91,7 +89,6 @@ func (t *ToolHome) Implement() server.ToolHandlerFunc {
} }
// Home action logic // Home action logic
log.Info().Msg("pressing home button")
err = driverExt.Home() err = driverExt.Home()
if err != nil { if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("Home button press failed: %s", err.Error())), nil return mcp.NewToolResultError(fmt.Sprintf("Home button press failed: %s", err.Error())), nil
@@ -135,7 +132,6 @@ func (t *ToolBack) Implement() server.ToolHandlerFunc {
} }
// Back action logic // Back action logic
log.Info().Msg("pressing back button")
err = driverExt.Back() err = driverExt.Back()
if err != nil { if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("Back button press failed: %s", err.Error())), nil return mcp.NewToolResultError(fmt.Sprintf("Back button press failed: %s", err.Error())), nil
-3
View File
@@ -7,7 +7,6 @@ import (
"github.com/httprunner/httprunner/v5/uixt/option" "github.com/httprunner/httprunner/v5/uixt/option"
"github.com/mark3labs/mcp-go/mcp" "github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server" "github.com/mark3labs/mcp-go/server"
"github.com/rs/zerolog/log"
) )
// ToolInput implements the input tool call. // ToolInput implements the input tool call.
@@ -43,7 +42,6 @@ func (t *ToolInput) Implement() server.ToolHandlerFunc {
} }
// Input action logic // Input action logic
log.Info().Str("text", unifiedReq.Text).Msg("inputting text")
err = driverExt.Input(unifiedReq.Text) err = driverExt.Input(unifiedReq.Text)
if err != nil { if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("Input failed: %s", err.Error())), nil return mcp.NewToolResultError(fmt.Sprintf("Input failed: %s", err.Error())), nil
@@ -97,7 +95,6 @@ func (t *ToolSetIme) Implement() server.ToolHandlerFunc {
} }
// Set IME action logic // Set IME action logic
log.Info().Str("ime", unifiedReq.Ime).Msg("setting IME")
err = driverExt.SetIme(unifiedReq.Ime) err = driverExt.SetIme(unifiedReq.Ime)
if err != nil { if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("Set IME failed: %s", err.Error())), nil return mcp.NewToolResultError(fmt.Sprintf("Set IME failed: %s", err.Error())), nil
-1
View File
@@ -129,7 +129,6 @@ func (t *ToolGetSource) Implement() server.ToolHandlerFunc {
} }
// Get source action logic // Get source action logic
log.Info().Str("packageName", unifiedReq.PackageName).Msg("getting source")
_, err = driverExt.Source(option.WithProcessName(unifiedReq.PackageName)) _, err = driverExt.Source(option.WithProcessName(unifiedReq.PackageName))
if err != nil { if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("Get source failed: %s", err.Error())), nil return mcp.NewToolResultError(fmt.Sprintf("Get source failed: %s", err.Error())), nil
-2
View File
@@ -331,7 +331,6 @@ func (t *ToolSwipeToTapApp) Implement() server.ToolHandlerFunc {
} }
// Swipe to tap app action logic // Swipe to tap app action logic
log.Info().Str("appName", unifiedReq.AppName).Msg("swipe to tap app")
err = driverExt.SwipeToTapApp(unifiedReq.AppName, opts...) err = driverExt.SwipeToTapApp(unifiedReq.AppName, opts...)
if err != nil { if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("Swipe to tap app failed: %s", err.Error())), nil return mcp.NewToolResultError(fmt.Sprintf("Swipe to tap app failed: %s", err.Error())), nil
@@ -410,7 +409,6 @@ func (t *ToolSwipeToTapText) Implement() server.ToolHandlerFunc {
} }
// Swipe to tap text action logic // Swipe to tap text action logic
log.Info().Str("text", unifiedReq.Text).Msg("swipe to tap text")
err = driverExt.SwipeToTapTexts([]string{unifiedReq.Text}, opts...) err = driverExt.SwipeToTapTexts([]string{unifiedReq.Text}, opts...)
if err != nil { if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("Swipe to tap text failed: %s", err.Error())), nil return mcp.NewToolResultError(fmt.Sprintf("Swipe to tap text failed: %s", err.Error())), nil
-7
View File
@@ -8,7 +8,6 @@ import (
"github.com/httprunner/httprunner/v5/uixt/option" "github.com/httprunner/httprunner/v5/uixt/option"
"github.com/mark3labs/mcp-go/mcp" "github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server" "github.com/mark3labs/mcp-go/server"
"github.com/rs/zerolog/log"
) )
// ToolTapXY implements the tap_xy tool call. // ToolTapXY implements the tap_xy tool call.
@@ -135,8 +134,6 @@ func (t *ToolTapAbsXY) Implement() server.ToolHandlerFunc {
} }
// Tap absolute XY action logic // Tap absolute XY action logic
log.Info().Float64("x", unifiedReq.X).Float64("y", unifiedReq.Y).Msg("tapping at absolute coordinates")
err = driverExt.TapAbsXY(unifiedReq.X, unifiedReq.Y, opts...) err = driverExt.TapAbsXY(unifiedReq.X, unifiedReq.Y, opts...)
if err != nil { if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("Tap absolute XY failed: %s", err.Error())), nil return mcp.NewToolResultError(fmt.Sprintf("Tap absolute XY failed: %s", err.Error())), nil
@@ -221,7 +218,6 @@ func (t *ToolTapByOCR) Implement() server.ToolHandlerFunc {
} }
// Tap by OCR action logic // Tap by OCR action logic
log.Info().Str("text", unifiedReq.Text).Msg("tapping by OCR")
err = driverExt.TapByOCR(unifiedReq.Text, opts...) err = driverExt.TapByOCR(unifiedReq.Text, opts...)
if err != nil { if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("Tap by OCR failed: %s", err.Error())), nil return mcp.NewToolResultError(fmt.Sprintf("Tap by OCR failed: %s", err.Error())), nil
@@ -287,9 +283,6 @@ func (t *ToolTapByCV) Implement() server.ToolHandlerFunc {
opts = append(opts, option.WithPreMarkOperation(true)) opts = append(opts, option.WithPreMarkOperation(true))
} }
// Tap by CV action logic
log.Info().Msg("tapping by CV")
// For TapByCV, we need to check if there are UI types in the options // For TapByCV, we need to check if there are UI types in the options
// In the original DoAction, it requires ScreenShotWithUITypes to be set // In the original DoAction, it requires ScreenShotWithUITypes to be set
// We'll add a basic implementation that triggers CV recognition // We'll add a basic implementation that triggers CV recognition
-2
View File
@@ -161,7 +161,6 @@ func (t *ToolSleepRandom) Implement() server.ToolHandlerFunc {
} }
// Sleep random action logic // Sleep random action logic
log.Info().Floats64("params", unifiedReq.Params).Msg("sleeping for random duration")
sleepStrict(time.Now(), getSimulationDuration(unifiedReq.Params)) sleepStrict(time.Now(), getSimulationDuration(unifiedReq.Params))
return mcp.NewToolResultText(fmt.Sprintf("Successfully slept for random duration with params: %v", unifiedReq.Params)), nil return mcp.NewToolResultText(fmt.Sprintf("Successfully slept for random duration with params: %v", unifiedReq.Params)), nil
@@ -210,7 +209,6 @@ func (t *ToolClosePopups) Implement() server.ToolHandlerFunc {
} }
// Close popups action logic // Close popups action logic
log.Info().Msg("closing popups")
err = driverExt.ClosePopupsHandler() err = driverExt.ClosePopupsHandler()
if err != nil { if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("Close popups failed: %s", err.Error())), nil return mcp.NewToolResultError(fmt.Sprintf("Close popups failed: %s", err.Error())), nil
-5
View File
@@ -101,7 +101,6 @@ func (t *ToolSecondaryClick) Implement() server.ToolHandlerFunc {
} }
// Secondary click action logic // Secondary click action logic
log.Info().Float64("x", unifiedReq.X).Float64("y", unifiedReq.Y).Msg("performing secondary click")
err = driverExt.SecondaryClick(unifiedReq.X, unifiedReq.Y) err = driverExt.SecondaryClick(unifiedReq.X, unifiedReq.Y)
if err != nil { if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("Secondary click failed: %s", err.Error())), nil return mcp.NewToolResultError(fmt.Sprintf("Secondary click failed: %s", err.Error())), nil
@@ -159,7 +158,6 @@ func (t *ToolHoverBySelector) Implement() server.ToolHandlerFunc {
} }
// Hover by selector action logic // Hover by selector action logic
log.Info().Str("selector", unifiedReq.Selector).Msg("hovering by selector")
err = driverExt.HoverBySelector(unifiedReq.Selector) err = driverExt.HoverBySelector(unifiedReq.Selector)
if err != nil { if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("Hover by selector failed: %s", err.Error())), nil return mcp.NewToolResultError(fmt.Sprintf("Hover by selector failed: %s", err.Error())), nil
@@ -215,7 +213,6 @@ func (t *ToolTapBySelector) Implement() server.ToolHandlerFunc {
} }
// Tap by selector action logic // Tap by selector action logic
log.Info().Str("selector", unifiedReq.Selector).Msg("tapping by selector")
err = driverExt.TapBySelector(unifiedReq.Selector) err = driverExt.TapBySelector(unifiedReq.Selector)
if err != nil { if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("Tap by selector failed: %s", err.Error())), nil return mcp.NewToolResultError(fmt.Sprintf("Tap by selector failed: %s", err.Error())), nil
@@ -271,7 +268,6 @@ func (t *ToolSecondaryClickBySelector) Implement() server.ToolHandlerFunc {
} }
// Secondary click by selector action logic // Secondary click by selector action logic
log.Info().Str("selector", unifiedReq.Selector).Msg("performing secondary click by selector")
err = driverExt.SecondaryClickBySelector(unifiedReq.Selector) err = driverExt.SecondaryClickBySelector(unifiedReq.Selector)
if err != nil { if err != nil {
return mcp.NewToolResultError(fmt.Sprintf("Secondary click by selector failed: %s", err.Error())), nil return mcp.NewToolResultError(fmt.Sprintf("Secondary click by selector failed: %s", err.Error())), nil
@@ -332,7 +328,6 @@ func (t *ToolWebCloseTab) Implement() server.ToolHandlerFunc {
} }
// Web close tab action logic // Web close tab action logic
log.Info().Int("tabIndex", unifiedReq.TabIndex).Msg("closing web tab")
browserDriver, ok := driverExt.IDriver.(*BrowserDriver) browserDriver, ok := driverExt.IDriver.(*BrowserDriver)
if !ok { if !ok {
return nil, fmt.Errorf("web close tab is only supported for browser drivers") return nil, fmt.Errorf("web close tab is only supported for browser drivers")