mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-04-29 08:08:59 +08:00
add exec/process background session workflow and register process tool
This commit is contained in:
@@ -20,14 +20,16 @@ type ExecTool struct {
|
||||
timeout time.Duration
|
||||
sandboxEnabled bool
|
||||
sandboxImage string
|
||||
procManager *ProcessManager
|
||||
}
|
||||
|
||||
func NewExecTool(cfg config.ShellConfig, workspace string) *ExecTool {
|
||||
func NewExecTool(cfg config.ShellConfig, workspace string, pm *ProcessManager) *ExecTool {
|
||||
return &ExecTool{
|
||||
workingDir: workspace,
|
||||
timeout: cfg.Timeout,
|
||||
sandboxEnabled: cfg.Sandbox.Enabled,
|
||||
sandboxImage: cfg.Sandbox.Image,
|
||||
procManager: pm,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +53,10 @@ func (t *ExecTool) Parameters() map[string]interface{} {
|
||||
"type": "string",
|
||||
"description": "Optional working directory for the command",
|
||||
},
|
||||
"background": map[string]interface{}{
|
||||
"type": "boolean",
|
||||
"description": "Run command in background and return session id",
|
||||
},
|
||||
},
|
||||
"required": []string{"command"},
|
||||
}
|
||||
@@ -74,6 +80,17 @@ func (t *ExecTool) Execute(ctx context.Context, args map[string]interface{}) (st
|
||||
}
|
||||
}
|
||||
|
||||
if bg, _ := args["background"].(bool); bg {
|
||||
if t.procManager == nil {
|
||||
return "", fmt.Errorf("background process manager not configured")
|
||||
}
|
||||
sid, err := t.procManager.Start(command, cwd)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return fmt.Sprintf("{\"session_id\":%q,\"running\":true}", sid), nil
|
||||
}
|
||||
|
||||
if t.sandboxEnabled {
|
||||
return t.executeInSandbox(ctx, command, cwd)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user