Skip to content

Commit a778a4c

Browse files
authored
get-kagent-script (#156)
* get-kagent-script * make error more clear for dashboard not on mac * oops
1 parent 8981487 commit a778a4c

File tree

8 files changed

+81
-70
lines changed

8 files changed

+81
-70
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ cython_debug/
188188
#.idea/
189189

190190
go/bin/
191-
.vscode/settings.json
191+
.vscode/
192192

193193
## Helm
194194
*.tgz

.vscode/launch.json

-16
This file was deleted.

go/cli/internal/cli/dashboard.go

+6-40
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,16 @@
1+
//go:build !darwin
2+
13
package cli
24

35
import (
46
"context"
5-
"os/exec"
6-
"strings"
7-
"time"
87

98
"github.com/abiosoft/ishell/v2"
10-
"github.com/kagent-dev/kagent/go/cli/internal/config"
119
)
1210

1311
func DashboardCmd(ctx context.Context, c *ishell.Context) {
14-
cfg := config.GetCfg(c)
15-
ctx, cancel := context.WithCancel(ctx)
16-
cmd := exec.CommandContext(ctx, "kubectl", "-n", cfg.Namespace, "port-forward", "service/kagent", "8082:80")
17-
18-
defer func() {
19-
cancel()
20-
if err := cmd.Wait(); err != nil { // These 2 errors are expected
21-
if !strings.Contains(err.Error(), "signal: killed") && !strings.Contains(err.Error(), "exec: not started") {
22-
c.Printf("Error waiting for port-forward to exit: %v\n", err)
23-
}
24-
}
25-
}()
26-
27-
if err := cmd.Start(); err != nil {
28-
c.Println("Error port-forwarding kagent:", err)
29-
return
30-
}
31-
32-
// Wait for the port-forward to start
33-
time.Sleep(1 * time.Second)
34-
35-
// Open the dashboard in the browser
36-
openCmd := exec.CommandContext(ctx, "open", "http://localhost:8082")
37-
if err := openCmd.Run(); err != nil {
38-
c.Printf("Error opening kagent dashboard: %v\n", err)
39-
}
40-
41-
c.Println("kagent dashboard is available at http://localhost:8082")
42-
43-
// This waits for user input to stop the port-forward
44-
c.ShowPrompt(false)
45-
c.Println("Press Enter to stop the port-forward...")
46-
if _, err := c.ReadLineErr(); err != nil {
47-
c.Println("Error reading input:", err)
48-
}
49-
c.ShowPrompt(true)
12+
c.Println("Dashboard is not available on this platform")
13+
c.Println("You can easily start the dashboard by running:")
14+
c.Println("kubectl port-forward -n kagent service/kagent 8082:80")
15+
c.Println("and then opening http://localhost:8082 in your browser")
5016
}
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//go:build darwin
2+
3+
package cli
4+
5+
import (
6+
"context"
7+
"os/exec"
8+
"strings"
9+
"time"
10+
11+
"github.com/abiosoft/ishell/v2"
12+
"github.com/kagent-dev/kagent/go/cli/internal/config"
13+
)
14+
15+
func DashboardCmd(ctx context.Context, c *ishell.Context) {
16+
cfg := config.GetCfg(c)
17+
ctx, cancel := context.WithCancel(ctx)
18+
cmd := exec.CommandContext(ctx, "kubectl", "-n", cfg.Namespace, "port-forward", "service/kagent", "8082:80")
19+
20+
defer func() {
21+
cancel()
22+
if err := cmd.Wait(); err != nil { // These 2 errors are expected
23+
if !strings.Contains(err.Error(), "signal: killed") && !strings.Contains(err.Error(), "exec: not started") {
24+
c.Printf("Error waiting for port-forward to exit: %v\n", err)
25+
}
26+
}
27+
}()
28+
29+
if err := cmd.Start(); err != nil {
30+
c.Println("Error port-forwarding kagent:", err)
31+
return
32+
}
33+
34+
// Wait for the port-forward to start
35+
time.Sleep(1 * time.Second)
36+
37+
// Open the dashboard in the browser
38+
openCmd := exec.CommandContext(ctx, "open", "http://localhost:8082")
39+
if err := openCmd.Run(); err != nil {
40+
c.Printf("Error opening kagent dashboard: %v\n", err)
41+
}
42+
43+
c.Println("kagent dashboard is available at http://localhost:8082")
44+
45+
// This waits for user input to stop the port-forward
46+
c.ShowPrompt(false)
47+
c.Println("Press Enter to stop the port-forward...")
48+
if _, err := c.ReadLineErr(); err != nil {
49+
c.Println("Error reading input:", err)
50+
}
51+
c.ShowPrompt(true)
52+
}

python/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,4 @@ EXPOSE 8081
9494
LABEL org.opencontainers.image.source=https://github.com/kagent-dev/kagent
9595
LABEL org.opencontainers.image.description="Kagent app is the apiserver for running agents."
9696

97-
CMD ["uv", "run", "kagent", "serve", "--host", "0.0.0.0", "--port", "8081"]
97+
CMD ["uv", "run", "kagent-engine", "serve", "--host", "0.0.0.0", "--port", "8081"]

python/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ lint = [
4242
]
4343

4444
[project.scripts]
45-
kagent = "kagent.cli:run"
45+
kagent-engine = "kagent.cli:run"
4646
tool_gen = "kagent.tools.utils.tool_gen:main"
4747

4848
[tool.uv.sources]

python/src/kagent/tools/utils/tool_gen.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,17 @@ def create_dummy_args(model_fields: dict[str, FieldInfo]):
8585
dummy_args[field_name] = next(iter(field_type))
8686
elif inspect.isclass(field_type) and issubclass(field_type, BaseModel):
8787
# For nested Pydantic models, recursively create dummy values
88-
if hasattr(field_type, "model_fields"):
88+
if field_info.annotation is not None and field_info.annotation.__name__ == "ComponentModel":
89+
dummy_args[field_name] = {
90+
"provider": "<YourProviderHere",
91+
"component_version": 1,
92+
"version": 1,
93+
"component_type": "model",
94+
"description": "A description of the model",
95+
"label": "<YourLabelHere>",
96+
"config": {},
97+
}
98+
elif hasattr(field_type, "model_fields"):
8999
nested_args = create_dummy_args(field_type.model_fields)
90100
dummy_args[field_name] = field_type(**nested_args)
91101
else:
@@ -214,6 +224,8 @@ def main(args=None) -> None:
214224
all_config.extend(tools)
215225
except Exception as e:
216226
logging.error(f"Error processing directory {dir_name}: {e}")
227+
# This was causing docker build to silently not fail
228+
raise e
217229

218230
# Write to the output file
219231
with open(file_path, "w") as f:

scripts/get-kagent

+7-10
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ checkDesiredVersion() {
103103
local latest_release_url="https://api.github.com/repos/kagent-dev/kagent/releases/latest"
104104
local latest_release_response=""
105105
if [ "${HAS_CURL}" == "true" ]; then
106-
latest_release_response=$( curl --header "Authorization: Bearer $GITHUB_TOKEN" -L --silent --show-error --fail "$latest_release_url" 2>&1 || true )
106+
latest_release_response=$( curl -L --silent --show-error --fail "$latest_release_url" 2>&1 || true )
107107
elif [ "${HAS_WGET}" == "true" ]; then
108108
latest_release_response=$( wget "$latest_release_url" -q -O - 2>&1 || true )
109109
fi
@@ -140,13 +140,13 @@ downloadFile() {
140140
KAGENT_DIST="kagent-$OS-$ARCH"
141141
DOWNLOAD_URL="https://github.com/kagent-dev/kagent/releases/download/$TAG/$KAGENT_DIST"
142142
CHECKSUM_URL="$DOWNLOAD_URL.sha256"
143-
KAGENT_TMP_ROOT="$(mktemp -dt kagent -installer-XXXXXX)"
143+
KAGENT_TMP_ROOT="$(mktemp -dt kagent-installer-XXXXXX)"
144144
KAGENT_TMP_FILE="$KAGENT_TMP_ROOT/$KAGENT_DIST"
145145
KAGENT_SUM_FILE="$KAGENT_TMP_ROOT/$KAGENT_DIST.sha256"
146146
echo "Downloading $DOWNLOAD_URL"
147147
if [ "${HAS_CURL}" == "true" ]; then
148-
curl --header "Authorization: Bearer $GITHUB_TOKEN" -SsL "$CHECKSUM_URL" -o "$KAGENT_SUM_FILE"
149-
curl --header "Authorization: Bearer $GITHUB_TOKEN" -SsL "$DOWNLOAD_URL" -o "$KAGENT_TMP_FILE"
148+
curl -SsL "$CHECKSUM_URL" -o "$KAGENT_SUM_FILE"
149+
curl -SsL "$DOWNLOAD_URL" -o "$KAGENT_TMP_FILE"
150150
elif [ "${HAS_WGET}" == "true" ]; then
151151
wget -q -O "$KAGENT_SUM_FILE" "$CHECKSUM_URL"
152152
wget -q -O "$KAGENT_TMP_FILE" "$DOWNLOAD_URL"
@@ -164,20 +164,17 @@ verifyFile() {
164164

165165
# installFile installs the kagent binary.
166166
installFile() {
167-
KAGENT_TMP="$KAGENT_TMP_ROOT/$BINARY_NAME"
168-
mkdir -p "$KAGENT_TMP"
169-
tar xf "$KAGENT_TMP_FILE" -C "$KAGENT_TMP"
170-
KAGENT_TMP_BIN="$KAGENT_TMP/$OS-$ARCH/kagent"
171167
echo "Preparing to install $BINARY_NAME into ${KAGENT_INSTALL_DIR}"
172-
runAsRoot cp "$KAGENT_TMP_BIN" "$KAGENT_INSTALL_DIR/$BINARY_NAME"
168+
runAsRoot chmod +x "$KAGENT_TMP_ROOT/$BINARY_NAME-$OS-$ARCH"
169+
runAsRoot cp "$KAGENT_TMP_ROOT/$BINARY_NAME-$OS-$ARCH" "$KAGENT_INSTALL_DIR/$BINARY_NAME"
173170
echo "$BINARY_NAME installed into $KAGENT_INSTALL_DIR/$BINARY_NAME"
174171
}
175172

176173
# verifyChecksum verifies the SHA256 checksum of the binary package.
177174
verifyChecksum() {
178175
printf "Verifying checksum... "
179176
local sum=$(openssl sha1 -sha256 ${KAGENT_TMP_FILE} | awk '{print $2}')
180-
local expected_sum=$(cat ${KAGENT_SUM_FILE})
177+
local expected_sum=$(cat ${KAGENT_SUM_FILE} | awk '{print $1}')
181178
if [ "$sum" != "$expected_sum" ]; then
182179
echo "SHA sum of ${KAGENT_TMP_FILE} does not match. Aborting."
183180
exit 1

0 commit comments

Comments
 (0)