|
5 | 5 | """ |
6 | 6 |
|
7 | 7 | import logging |
| 8 | +import re |
8 | 9 | import shlex |
9 | 10 | import shutil |
10 | 11 | import subprocess |
|
29 | 30 |
|
30 | 31 | logger = logging.getLogger(__name__) |
31 | 32 |
|
| 33 | +# Store the initial working directory when the module is imported |
| 34 | +INITIAL_WORKING_DIRECTORY = Path.cwd() |
| 35 | + |
| 36 | + |
| 37 | +def slugify_name(name: str) -> str: |
| 38 | + """Convert agent name to a filesystem-safe slug.""" |
| 39 | + # Convert to lowercase and replace spaces/special chars with hyphens |
| 40 | + slug = re.sub(r"[^\w\s-]", "", name.lower()) |
| 41 | + slug = re.sub(r"[-\s]+", "-", slug) |
| 42 | + return slug.strip("-") |
| 43 | + |
| 44 | + |
32 | 45 | agents_api = flask.Blueprint("agents_api", __name__) |
33 | 46 |
|
34 | 47 |
|
@@ -64,10 +77,15 @@ def api_agents_put(): |
64 | 77 |
|
65 | 78 | path = req_json.get("path") |
66 | 79 | if not path: |
67 | | - return flask.jsonify({"error": "path is required"}), 400 |
| 80 | + # Auto-generate path from initial directory + slugified agent name |
| 81 | + agent_slug = slugify_name(agent_name) |
| 82 | + path = INITIAL_WORKING_DIRECTORY / agent_slug |
68 | 83 | else: |
69 | 84 | path = Path(path).expanduser().resolve() |
70 | 85 |
|
| 86 | + # Ensure path is a Path object and resolved |
| 87 | + path = Path(path).expanduser().resolve() |
| 88 | + |
71 | 89 | # Ensure the folder is empty |
72 | 90 | if path.exists(): |
73 | 91 | return flask.jsonify({"error": f"Folder/path already exists: {path}"}), 400 |
@@ -189,5 +207,6 @@ def api_agents_put(): |
189 | 207 | "status": "ok", |
190 | 208 | "message": "Agent created", |
191 | 209 | "initial_conversation_id": conversation_id, |
| 210 | + "agent_path": str(path), |
192 | 211 | } |
193 | 212 | ) |
0 commit comments