|
11 | 11 | run_project, |
12 | 12 | export_template, |
13 | 13 | ) |
14 | | -from agentstack.telemetry import track_cli_command |
15 | | -from agentstack.utils import get_version |
| 14 | +from agentstack.telemetry import track_cli_command, update_telemetry |
| 15 | +from agentstack.utils import get_version, term_color |
16 | 16 | from agentstack import generation |
17 | 17 | from agentstack.update import check_for_updates |
18 | 18 |
|
@@ -151,46 +151,54 @@ def main(): |
151 | 151 | print(f"AgentStack CLI version: {get_version()}") |
152 | 152 | sys.exit(0) |
153 | 153 |
|
154 | | - track_cli_command(args.command) |
| 154 | + telemetry_id = track_cli_command(args.command, " ".join(sys.argv[1:])) |
155 | 155 | check_for_updates(update_requested=args.command in ('update', 'u')) |
156 | 156 |
|
157 | 157 | # Handle commands |
158 | | - if args.command in ["docs"]: |
159 | | - webbrowser.open("https://docs.agentstack.sh/") |
160 | | - elif args.command in ["quickstart"]: |
161 | | - webbrowser.open("https://docs.agentstack.sh/quickstart") |
162 | | - elif args.command in ["templates"]: |
163 | | - webbrowser.open("https://docs.agentstack.sh/quickstart") |
164 | | - elif args.command in ["init", "i"]: |
165 | | - init_project_builder(args.slug_name, args.template, args.wizard) |
166 | | - elif args.command in ["run", "r"]: |
167 | | - run_project(command=args.function, debug=args.debug, cli_args=extra_args) |
168 | | - elif args.command in ['generate', 'g']: |
169 | | - if args.generate_command in ['agent', 'a']: |
170 | | - if not args.llm: |
171 | | - configure_default_model() |
172 | | - generation.add_agent(args.name, args.role, args.goal, args.backstory, args.llm) |
173 | | - elif args.generate_command in ['task', 't']: |
174 | | - generation.add_task(args.name, args.description, args.expected_output, args.agent) |
175 | | - else: |
176 | | - generate_parser.print_help() |
177 | | - elif args.command in ["tools", "t"]: |
178 | | - if args.tools_command in ["list", "l"]: |
179 | | - list_tools() |
180 | | - elif args.tools_command in ["add", "a"]: |
181 | | - agents = [args.agent] if args.agent else None |
182 | | - agents = args.agents.split(",") if args.agents else agents |
183 | | - add_tool(args.name, agents) |
184 | | - elif args.tools_command in ["remove", "r"]: |
185 | | - generation.remove_tool(args.name) |
| 158 | + try: |
| 159 | + if args.command in ["docs"]: |
| 160 | + webbrowser.open("https://docs.agentstack.sh/") |
| 161 | + elif args.command in ["quickstart"]: |
| 162 | + webbrowser.open("https://docs.agentstack.sh/quickstart") |
| 163 | + elif args.command in ["templates"]: |
| 164 | + webbrowser.open("https://docs.agentstack.sh/quickstart") |
| 165 | + elif args.command in ["init", "i"]: |
| 166 | + init_project_builder(args.slug_name, args.template, args.wizard) |
| 167 | + elif args.command in ["run", "r"]: |
| 168 | + run_project(command=args.function, debug=args.debug, cli_args=extra_args) |
| 169 | + elif args.command in ['generate', 'g']: |
| 170 | + if args.generate_command in ['agent', 'a']: |
| 171 | + if not args.llm: |
| 172 | + configure_default_model() |
| 173 | + generation.add_agent(args.name, args.role, args.goal, args.backstory, args.llm) |
| 174 | + elif args.generate_command in ['task', 't']: |
| 175 | + generation.add_task(args.name, args.description, args.expected_output, args.agent) |
| 176 | + else: |
| 177 | + generate_parser.print_help() |
| 178 | + elif args.command in ["tools", "t"]: |
| 179 | + if args.tools_command in ["list", "l"]: |
| 180 | + list_tools() |
| 181 | + elif args.tools_command in ["add", "a"]: |
| 182 | + agents = [args.agent] if args.agent else None |
| 183 | + agents = args.agents.split(",") if args.agents else agents |
| 184 | + add_tool(args.name, agents) |
| 185 | + elif args.tools_command in ["remove", "r"]: |
| 186 | + generation.remove_tool(args.name) |
| 187 | + else: |
| 188 | + tools_parser.print_help() |
| 189 | + elif args.command in ['export', 'e']: |
| 190 | + export_template(args.filename) |
| 191 | + elif args.command in ['update', 'u']: |
| 192 | + pass # Update check already done |
186 | 193 | else: |
187 | | - tools_parser.print_help() |
188 | | - elif args.command in ['export', 'e']: |
189 | | - export_template(args.filename) |
190 | | - elif args.command in ['update', 'u']: |
191 | | - pass # Update check already done |
192 | | - else: |
193 | | - parser.print_help() |
| 194 | + parser.print_help() |
| 195 | + except Exception as e: |
| 196 | + update_telemetry(telemetry_id, result=1, message=str(e)) |
| 197 | + print(term_color("An error occurred while running your AgentStack command:", "red")) |
| 198 | + print(e) |
| 199 | + sys.exit(1) |
| 200 | + |
| 201 | + update_telemetry(telemetry_id, result=0) |
194 | 202 |
|
195 | 203 |
|
196 | 204 | if __name__ == "__main__": |
|
0 commit comments