fix: compilation errors in commands and providers
This commit is contained in:
parent
81841df578
commit
b068f6ae44
4 changed files with 27 additions and 42 deletions
|
|
@ -10,57 +10,54 @@ import (
|
|||
|
||||
func acpCommand() Definition {
|
||||
return Definition{
|
||||
Prefix: "acp",
|
||||
Name: "acp",
|
||||
Description: "Agent Client Protocol capabilities (e.g. acp spawn, status, close)",
|
||||
Category: "System",
|
||||
Usage: "/acp <action> [args...]",
|
||||
Handler: func(ctx context.Context, args string, rt Runtime) error {
|
||||
parts := strings.Fields(args)
|
||||
if len(parts) == 0 {
|
||||
return fmt.Errorf("missing acp action (spawn, status, close)")
|
||||
Handler: func(ctx context.Context, req Request, rt *Runtime) error {
|
||||
parts := strings.Fields(req.Text)
|
||||
if len(parts) < 2 {
|
||||
return req.Reply("Usage: /acp <action> [args...]")
|
||||
}
|
||||
|
||||
action := parts[0]
|
||||
action := parts[1]
|
||||
switch action {
|
||||
case "spawn":
|
||||
if len(parts) < 2 {
|
||||
return fmt.Errorf("usage: /acp spawn <harness_id>")
|
||||
if len(parts) < 3 {
|
||||
return req.Reply("usage: /acp spawn <harness_id>")
|
||||
}
|
||||
harness := parts[1]
|
||||
harness := parts[2]
|
||||
session, err := acp.GetManager().Spawn(harness, "session", harness, "", "cli-spawned", []string{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to spawn ACP session: %v", err)
|
||||
return req.Reply(fmt.Sprintf("failed to spawn ACP session: %v", err))
|
||||
}
|
||||
rt.PrintSysMessage(fmt.Sprintf("✓ Spawned ACP harness '%s'. Session Key: %s", harness, session.Key))
|
||||
return req.Reply(fmt.Sprintf("✓ Spawned ACP harness '%s'. Session Key: %s", harness, session.Key))
|
||||
|
||||
case "status":
|
||||
sessions := acp.GetManager().ListSessions()
|
||||
if len(sessions) == 0 {
|
||||
rt.PrintSysMessage("No active ACP sessions.")
|
||||
return nil
|
||||
return req.Reply("No active ACP sessions.")
|
||||
}
|
||||
var b strings.Builder
|
||||
b.WriteString("Active ACP Sessions:\n")
|
||||
for _, s := range sessions {
|
||||
b.WriteString(fmt.Sprintf("- Key: %s | Harness: %s | Status: %s\n", s.Key, s.AgentID, s.Status()))
|
||||
}
|
||||
rt.PrintSysMessage(b.String())
|
||||
return req.Reply(b.String())
|
||||
|
||||
case "close":
|
||||
if len(parts) < 2 {
|
||||
return fmt.Errorf("usage: /acp close <session_key>")
|
||||
if len(parts) < 3 {
|
||||
return req.Reply("usage: /acp close <session_key>")
|
||||
}
|
||||
key := parts[1]
|
||||
key := parts[2]
|
||||
err := acp.GetManager().CloseSession(key)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to close session: %v", err)
|
||||
return req.Reply(fmt.Sprintf("failed to close session: %v", err))
|
||||
}
|
||||
rt.PrintSysMessage(fmt.Sprintf("✓ Closed ACP session %s", key))
|
||||
return req.Reply(fmt.Sprintf("✓ Closed ACP session %s", key))
|
||||
|
||||
default:
|
||||
return fmt.Errorf("unknown acp action: %s", action)
|
||||
return req.Reply(fmt.Sprintf("unknown acp action: %s", action))
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/sipeed/picoclaw/pkg/auth"
|
||||
)
|
||||
|
||||
func versionCommand() Definition {
|
||||
|
|
|
|||
|
|
@ -13,40 +13,27 @@ func whatsappCommand() Definition {
|
|||
return Definition{
|
||||
Name: "whatsapp",
|
||||
Description: "WhatsApp management commands",
|
||||
Subcommands: []Definition{
|
||||
SubCommands: []SubCommand{
|
||||
{
|
||||
Name: "qr",
|
||||
Description: "Get the latest WhatsApp pairing QR code",
|
||||
Handler: func(ctx context.Context, req Request, rt Runtime) ExecuteResult {
|
||||
Handler: func(ctx context.Context, req Request, rt *Runtime) error {
|
||||
ch, ok := rt.GetChannel("whatsapp_native")
|
||||
if !ok {
|
||||
return ExecuteResult{
|
||||
Outcome: OutcomeHandled,
|
||||
Err: fmt.Errorf("whatsapp_native channel is not enabled"),
|
||||
}
|
||||
return req.Reply("whatsapp_native channel is not enabled")
|
||||
}
|
||||
|
||||
qp, ok := ch.(qrProvider)
|
||||
if !ok {
|
||||
return ExecuteResult{
|
||||
Outcome: OutcomeHandled,
|
||||
Err: fmt.Errorf("whatsapp_native channel does not support QR retrieval"),
|
||||
}
|
||||
return req.Reply("whatsapp_native channel does not support QR retrieval")
|
||||
}
|
||||
|
||||
qr := qp.GetLastQR()
|
||||
if qr == "" {
|
||||
return ExecuteResult{
|
||||
Outcome: OutcomeHandled,
|
||||
Err: fmt.Errorf("no QR code available yet. please wait for the channel to initialize"),
|
||||
}
|
||||
return req.Reply("no QR code available yet. please wait for the channel to initialize")
|
||||
}
|
||||
|
||||
// For now, return the QR code string.
|
||||
// Optimization: In the future, we can return an image reference.
|
||||
_ = req.Reply(fmt.Sprintf("Scan this QR code string (or wait for image support): %s", qr))
|
||||
|
||||
return ExecuteResult{Outcome: OutcomeHandled}
|
||||
return req.Reply(fmt.Sprintf("Scan this QR code string (or wait for image support): %s", qr))
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package providers
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"github.com/sipeed/picoclaw/pkg/config"
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue