@agentspan/agentspan 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +227 -0
- package/build.sh +35 -0
- package/cli.js +28 -0
- package/client/client.go +365 -0
- package/cmd/agent.go +120 -0
- package/cmd/compile.go +37 -0
- package/cmd/configure.go +48 -0
- package/cmd/delete.go +44 -0
- package/cmd/doctor.go +486 -0
- package/cmd/execution.go +155 -0
- package/cmd/get.go +40 -0
- package/cmd/helpers.go +21 -0
- package/cmd/init.go +83 -0
- package/cmd/list.go +55 -0
- package/cmd/respond.go +56 -0
- package/cmd/root.go +44 -0
- package/cmd/run.go +116 -0
- package/cmd/server.go +446 -0
- package/cmd/server_unix.go +36 -0
- package/cmd/server_windows.go +37 -0
- package/cmd/status.go +72 -0
- package/cmd/stream.go +32 -0
- package/cmd/update.go +91 -0
- package/config/config.go +78 -0
- package/dist/agentspan_darwin_amd64 +0 -0
- package/dist/agentspan_darwin_arm64 +0 -0
- package/dist/agentspan_linux_amd64 +0 -0
- package/dist/agentspan_linux_arm64 +0 -0
- package/dist/agentspan_windows_amd64.exe +0 -0
- package/dist/agentspan_windows_arm64.exe +0 -0
- package/examples/multi-agent.yaml +22 -0
- package/examples/simple-agent.yaml +7 -0
- package/go.mod +17 -0
- package/go.sum +24 -0
- package/install.js +122 -0
- package/install.sh +104 -0
- package/internal/progress/bar.go +121 -0
- package/main.go +10 -0
- package/package.json +43 -0
package/cmd/agent.go
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// Copyright (c) 2025 AgentSpan
|
|
2
|
+
// Licensed under the MIT License. See LICENSE file in the project root for details.
|
|
3
|
+
|
|
4
|
+
package cmd
|
|
5
|
+
|
|
6
|
+
import (
|
|
7
|
+
"encoding/json"
|
|
8
|
+
"fmt"
|
|
9
|
+
"os"
|
|
10
|
+
|
|
11
|
+
"github.com/agentspan/agentspan/cli/client"
|
|
12
|
+
"github.com/fatih/color"
|
|
13
|
+
"github.com/spf13/cobra"
|
|
14
|
+
"gopkg.in/yaml.v3"
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
var agentCmd = &cobra.Command{
|
|
18
|
+
Use: "agent",
|
|
19
|
+
Aliases: []string{"a"},
|
|
20
|
+
Short: "Manage agents",
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
func init() {
|
|
24
|
+
rootCmd.AddCommand(agentCmd)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// loadAgentConfig reads a YAML or JSON agent config file into a map
|
|
28
|
+
func loadAgentConfig(path string) (map[string]interface{}, error) {
|
|
29
|
+
data, err := os.ReadFile(path)
|
|
30
|
+
if err != nil {
|
|
31
|
+
return nil, fmt.Errorf("read config file: %w", err)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var cfg map[string]interface{}
|
|
35
|
+
|
|
36
|
+
// Try YAML first (superset of JSON)
|
|
37
|
+
if err := yaml.Unmarshal(data, &cfg); err != nil {
|
|
38
|
+
// Fall back to JSON
|
|
39
|
+
if err := json.Unmarshal(data, &cfg); err != nil {
|
|
40
|
+
return nil, fmt.Errorf("parse config file (tried YAML and JSON): %w", err)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return cfg, nil
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// printJSON pretty-prints a value as JSON
|
|
48
|
+
func printJSON(v interface{}) {
|
|
49
|
+
data, _ := json.MarshalIndent(v, "", " ")
|
|
50
|
+
fmt.Println(string(data))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// printSSEEvent formats and prints an SSE event
|
|
54
|
+
func printSSEEvent(evt client.SSEEvent) {
|
|
55
|
+
var data map[string]interface{}
|
|
56
|
+
if err := json.Unmarshal([]byte(evt.Data), &data); err != nil {
|
|
57
|
+
// Not JSON, print raw
|
|
58
|
+
if evt.Event != "" {
|
|
59
|
+
fmt.Printf("[%s] %s\n", evt.Event, evt.Data)
|
|
60
|
+
}
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
eventType := evt.Event
|
|
65
|
+
if eventType == "" {
|
|
66
|
+
if t, ok := data["type"].(string); ok {
|
|
67
|
+
eventType = t
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
switch eventType {
|
|
72
|
+
case "thinking":
|
|
73
|
+
color.New(color.FgHiBlack).Printf(" [thinking] %s\n", truncate(dataStr(data, "message"), 120))
|
|
74
|
+
case "tool_call":
|
|
75
|
+
color.New(color.FgCyan).Printf(" [tool] %s(%s)\n", dataStr(data, "toolName"), truncate(dataStr(data, "input"), 100))
|
|
76
|
+
case "tool_result":
|
|
77
|
+
result := truncate(dataStr(data, "result"), 200)
|
|
78
|
+
color.New(color.FgCyan).Printf(" [result] %s -> %s\n", dataStr(data, "toolName"), result)
|
|
79
|
+
case "handoff":
|
|
80
|
+
color.New(color.FgYellow).Printf(" [handoff] -> %s\n", dataStr(data, "agentName"))
|
|
81
|
+
case "waiting":
|
|
82
|
+
color.New(color.FgYellow, color.Bold).Printf(" [waiting] Human input required (workflow: %s)\n", dataStr(data, "workflowId"))
|
|
83
|
+
case "guardrail_pass":
|
|
84
|
+
color.New(color.FgGreen).Printf(" [guardrail] PASS %s\n", dataStr(data, "guardrailName"))
|
|
85
|
+
case "guardrail_fail":
|
|
86
|
+
color.New(color.FgRed).Printf(" [guardrail] FAIL %s: %s\n", dataStr(data, "guardrailName"), dataStr(data, "reason"))
|
|
87
|
+
case "error":
|
|
88
|
+
color.New(color.FgRed, color.Bold).Printf(" [error] %s\n", dataStr(data, "message"))
|
|
89
|
+
case "done":
|
|
90
|
+
output := dataStr(data, "output")
|
|
91
|
+
if output != "" {
|
|
92
|
+
fmt.Println()
|
|
93
|
+
color.New(color.Bold).Println(output)
|
|
94
|
+
}
|
|
95
|
+
default:
|
|
96
|
+
if eventType != "" {
|
|
97
|
+
fmt.Printf(" [%s] %s\n", eventType, truncate(evt.Data, 150))
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
func dataStr(data map[string]interface{}, key string) string {
|
|
103
|
+
if v, ok := data[key]; ok {
|
|
104
|
+
switch val := v.(type) {
|
|
105
|
+
case string:
|
|
106
|
+
return val
|
|
107
|
+
default:
|
|
108
|
+
b, _ := json.Marshal(val)
|
|
109
|
+
return string(b)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return ""
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
func truncate(s string, max int) string {
|
|
116
|
+
if len(s) <= max {
|
|
117
|
+
return s
|
|
118
|
+
}
|
|
119
|
+
return s[:max] + "..."
|
|
120
|
+
}
|
package/cmd/compile.go
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Copyright (c) 2025 AgentSpan
|
|
2
|
+
// Licensed under the MIT License. See LICENSE file in the project root for details.
|
|
3
|
+
|
|
4
|
+
package cmd
|
|
5
|
+
|
|
6
|
+
import (
|
|
7
|
+
"fmt"
|
|
8
|
+
|
|
9
|
+
"github.com/spf13/cobra"
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
var compileCmd = &cobra.Command{
|
|
13
|
+
Use: "compile <config-file>",
|
|
14
|
+
Short: "Compile an agent config to a Conductor workflow definition",
|
|
15
|
+
Args: cobra.ExactArgs(1),
|
|
16
|
+
RunE: func(cmd *cobra.Command, args []string) error {
|
|
17
|
+
agentConfig, err := loadAgentConfig(args[0])
|
|
18
|
+
if err != nil {
|
|
19
|
+
return err
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
cfg := getConfig()
|
|
23
|
+
c := newClient(cfg)
|
|
24
|
+
|
|
25
|
+
result, err := c.Compile(agentConfig)
|
|
26
|
+
if err != nil {
|
|
27
|
+
return fmt.Errorf("compilation failed: %w", err)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
printJSON(result)
|
|
31
|
+
return nil
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
func init() {
|
|
36
|
+
agentCmd.AddCommand(compileCmd)
|
|
37
|
+
}
|
package/cmd/configure.go
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Copyright (c) 2025 AgentSpan
|
|
2
|
+
// Licensed under the MIT License. See LICENSE file in the project root for details.
|
|
3
|
+
|
|
4
|
+
package cmd
|
|
5
|
+
|
|
6
|
+
import (
|
|
7
|
+
"fmt"
|
|
8
|
+
|
|
9
|
+
"github.com/agentspan/agentspan/cli/config"
|
|
10
|
+
"github.com/fatih/color"
|
|
11
|
+
"github.com/spf13/cobra"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
var configureCmd = &cobra.Command{
|
|
15
|
+
Use: "configure",
|
|
16
|
+
Short: "Configure the CLI (server URL, auth credentials)",
|
|
17
|
+
RunE: func(cmd *cobra.Command, args []string) error {
|
|
18
|
+
cfg := config.Load()
|
|
19
|
+
|
|
20
|
+
if url, _ := cmd.Flags().GetString("url"); url != "" {
|
|
21
|
+
cfg.ServerURL = url
|
|
22
|
+
}
|
|
23
|
+
if key, _ := cmd.Flags().GetString("auth-key"); key != "" {
|
|
24
|
+
cfg.AuthKey = key
|
|
25
|
+
}
|
|
26
|
+
if secret, _ := cmd.Flags().GetString("auth-secret"); secret != "" {
|
|
27
|
+
cfg.AuthSecret = secret
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if err := config.Save(cfg); err != nil {
|
|
31
|
+
return fmt.Errorf("failed to save config: %w", err)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
color.Green("Configuration saved!")
|
|
35
|
+
fmt.Printf(" Server URL: %s\n", cfg.ServerURL)
|
|
36
|
+
if cfg.AuthKey != "" {
|
|
37
|
+
fmt.Printf(" Auth Key: %s\n", cfg.AuthKey)
|
|
38
|
+
}
|
|
39
|
+
return nil
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
func init() {
|
|
44
|
+
configureCmd.Flags().String("url", "", "Runtime server URL")
|
|
45
|
+
configureCmd.Flags().String("auth-key", "", "Auth key")
|
|
46
|
+
configureCmd.Flags().String("auth-secret", "", "Auth secret")
|
|
47
|
+
rootCmd.AddCommand(configureCmd)
|
|
48
|
+
}
|
package/cmd/delete.go
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Copyright (c) 2025 AgentSpan
|
|
2
|
+
// Licensed under the MIT License. See LICENSE file in the project root for details.
|
|
3
|
+
|
|
4
|
+
package cmd
|
|
5
|
+
|
|
6
|
+
import (
|
|
7
|
+
"fmt"
|
|
8
|
+
|
|
9
|
+
"github.com/fatih/color"
|
|
10
|
+
"github.com/spf13/cobra"
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
var deleteVersion int
|
|
14
|
+
|
|
15
|
+
var deleteCmd = &cobra.Command{
|
|
16
|
+
Use: "delete <name>",
|
|
17
|
+
Short: "Delete an agent workflow definition",
|
|
18
|
+
Args: cobra.ExactArgs(1),
|
|
19
|
+
RunE: func(cmd *cobra.Command, args []string) error {
|
|
20
|
+
cfg := getConfig()
|
|
21
|
+
c := newClient(cfg)
|
|
22
|
+
|
|
23
|
+
var versionPtr *int
|
|
24
|
+
if cmd.Flags().Changed("version") {
|
|
25
|
+
versionPtr = &deleteVersion
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if err := c.DeleteAgent(args[0], versionPtr); err != nil {
|
|
29
|
+
return fmt.Errorf("failed to delete agent: %w", err)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if versionPtr != nil {
|
|
33
|
+
color.Green("Deleted agent '%s' version %d", args[0], *versionPtr)
|
|
34
|
+
} else {
|
|
35
|
+
color.Green("Deleted agent '%s' (latest version)", args[0])
|
|
36
|
+
}
|
|
37
|
+
return nil
|
|
38
|
+
},
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
func init() {
|
|
42
|
+
deleteCmd.Flags().IntVar(&deleteVersion, "version", 0, "Agent version to delete (default: latest)")
|
|
43
|
+
agentCmd.AddCommand(deleteCmd)
|
|
44
|
+
}
|