-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwarp-engine-client
More file actions
executable file
·210 lines (158 loc) · 6.12 KB
/
warp-engine-client
File metadata and controls
executable file
·210 lines (158 loc) · 6.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env python3
"""
Warp Engine Client CLI - Interact with the Engine Service
This demonstrates how Warp Terminal would programmatically use the engine.
"""
import sys
import json
import time
import argparse
from pathlib import Path
# Add project to path
sys.path.insert(0, str(Path(__file__).parent / "src"))
from warpengine.client.engine_client import WarpEngineClient, WarpAIInterface
def print_status(client: WarpEngineClient):
"""Print service status."""
if not client.is_running():
print("❌ Service not running. Start with: ./warp-engine-service start")
return
print("✅ Service is running")
try:
status = client.get_status()
if status:
print(f" Jobs: {status.get('jobs_total', 0)} total")
print(f" Running: {status.get('jobs_running', 0)}")
print(f" Completed: {status.get('jobs_completed', 0)}")
print(f" Failed: {status.get('jobs_failed', 0)}")
print(f" WebSocket connections: {status.get('websocket_connections', 0)}")
except Exception as e:
print(f" (Could not get detailed status: {e})")
def create_agent_interactive(client: WarpEngineClient):
"""Create an agent interactively."""
print("🤖 Agent Creation Wizard")
print("-" * 40)
name = input("Agent name: ").strip()
print("\nAgent type:")
print(" 1. Research Agent")
print(" 2. Code Generator")
print(" 3. Data Analyst")
print(" 4. Custom")
choice = input("Select (1-4): ").strip()
type_map = {
"1": "RESEARCH",
"2": "CODE_GENERATOR",
"3": "DATA_ANALYST",
"4": "CUSTOM"
}
agent_type = type_map.get(choice, "CUSTOM")
description = input("Description: ").strip()
print("\nCreating agent...")
result = client.create_agent(name, agent_type, description)
if result.success:
print(f"✅ Agent created successfully!")
print(f" Slug: {result.result['slug']}")
print(f" Executable: {result.result['executable']}")
else:
print(f"❌ Failed: {result.error}")
def natural_language_interface(client: WarpEngineClient):
"""Natural language interface demo."""
ai = WarpAIInterface(client)
print("🤖 Warp AI Interface (type 'exit' to quit)")
print("-" * 40)
print("Try: 'Create an agent that researches quantum computing'")
print(" 'List all agents'")
print(" 'Run the research agent on AI ethics'")
print()
while True:
try:
request = input("You: ").strip()
if request.lower() in ['exit', 'quit']:
break
if not request:
continue
response = ai.process_user_request(request)
print(f"\nAI: {response}\n")
except KeyboardInterrupt:
break
except Exception as e:
print(f"Error: {e}")
def execute_command(client: WarpEngineClient, command: str, params: str = None):
"""Execute a raw command."""
params_dict = json.loads(params) if params else {}
print(f"Executing: {command}")
result = client.execute_command(command, params_dict)
if result.success:
print("✅ Success")
if result.result:
print(json.dumps(result.result, indent=2))
else:
print(f"❌ Failed: {result.error}")
if result.logs:
print("\nLogs:")
for log in result.logs:
print(f" {log}")
def main():
"""Main entry point."""
parser = argparse.ArgumentParser(
description="Warp Engine Client - Interact with the Engine Service"
)
parser.add_argument(
"--url",
default="http://127.0.0.1:8788",
help="Service URL (default: http://127.0.0.1:8788)"
)
subparsers = parser.add_subparsers(dest="command", help="Commands")
# Status command
subparsers.add_parser("status", help="Check service status")
# Create agent command
subparsers.add_parser("create", help="Create an agent interactively")
# List agents command
subparsers.add_parser("list", help="List all agents")
# Run agent command
run_parser = subparsers.add_parser("run", help="Run an agent")
run_parser.add_argument("agent", help="Agent name/slug")
run_parser.add_argument("input", help="Input text")
# Natural language interface
subparsers.add_parser("ai", help="Natural language interface")
# Raw command execution
exec_parser = subparsers.add_parser("exec", help="Execute raw command")
exec_parser.add_argument("cmd", help="Command to execute")
exec_parser.add_argument("--params", help="JSON parameters")
args = parser.parse_args()
# Create client
client = WarpEngineClient(args.url)
# Check if service is running
if args.command != "status" and not client.is_running():
print("❌ Service not running. Start with: ./warp-engine-service start")
sys.exit(1)
# Execute command
if args.command == "status":
print_status(client)
elif args.command == "create":
create_agent_interactive(client)
elif args.command == "list":
agents = client.list_agents()
if agents:
print("📋 Available Agents:")
for agent in agents:
print(f" • {agent['name']} ({agent['slug']})")
if agent.get('description'):
print(f" {agent['description']}")
else:
print("No agents found")
elif args.command == "run":
print(f"Running agent: {args.agent}")
result = client.run_agent(args.agent, args.input)
if result.success:
print("✅ Success")
print(result.result.get('output', 'No output'))
else:
print(f"❌ Failed: {result.error}")
elif args.command == "ai":
natural_language_interface(client)
elif args.command == "exec":
execute_command(client, args.cmd, args.params)
else:
parser.print_help()
if __name__ == "__main__":
main()