devduck 0.1.1766644714__py3-none-any.whl → 0.3.0__py3-none-any.whl

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.

Potentially problematic release.


This version of devduck might be problematic. Click here for more details.

devduck/tools/tray.py DELETED
@@ -1,247 +0,0 @@
1
- """
2
- Tray app control tool - integrated with devduck
3
- """
4
-
5
- from strands import tool
6
- from typing import Dict, Any, List
7
- import subprocess
8
- import socket
9
- import json
10
- import tempfile
11
- import os
12
- import sys
13
- import time
14
- import signal
15
- from pathlib import Path
16
-
17
- # Global state
18
- _tray_process = None
19
-
20
-
21
- def _send_ipc_command(socket_path: str, command: Dict) -> Dict:
22
- """Send IPC command to tray app"""
23
- try:
24
- client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
25
- client.settimeout(10.0)
26
- client.connect(socket_path)
27
-
28
- # Send command
29
- message = json.dumps(command).encode("utf-8")
30
- client.sendall(message)
31
-
32
- # Receive response
33
- response_data = b""
34
- while True:
35
- chunk = client.recv(4096)
36
- if not chunk:
37
- break
38
- response_data += chunk
39
- # Check if we have complete JSON
40
- try:
41
- json.loads(response_data.decode("utf-8"))
42
- break
43
- except:
44
- continue
45
-
46
- client.close()
47
-
48
- if not response_data:
49
- return {"status": "error", "message": "Empty response"}
50
-
51
- return json.loads(response_data.decode("utf-8"))
52
- except socket.timeout:
53
- return {"status": "error", "message": "Timeout"}
54
- except Exception as e:
55
- return {"status": "error", "message": str(e)}
56
-
57
-
58
- @tool
59
- def tray(
60
- action: str,
61
- items: List[Dict[str, Any]] = None,
62
- title: str = None,
63
- message: Dict[str, Any] = None,
64
- text: str = None,
65
- ) -> Dict[str, Any]:
66
- """Control system tray app with devduck integration.
67
-
68
- Returns:
69
- Dict with status and content
70
- """
71
- global _tray_process
72
-
73
- socket_path = os.path.join(tempfile.gettempdir(), "devduck_tray.sock")
74
-
75
- if action == "start":
76
- if _tray_process and _tray_process.poll() is None:
77
- return {"status": "success", "content": [{"text": "✓ Already running"}]}
78
-
79
- # Get tray script path
80
- tools_dir = Path(__file__).parent
81
- tray_script = tools_dir / "_tray_app.py"
82
-
83
- if not tray_script.exists():
84
- return {
85
- "status": "error",
86
- "content": [{"text": f"❌ Tray app not found: {tray_script}"}],
87
- }
88
-
89
- _tray_process = subprocess.Popen(
90
- [sys.executable, str(tray_script)],
91
- stdout=subprocess.DEVNULL,
92
- stderr=subprocess.DEVNULL,
93
- )
94
-
95
- time.sleep(1.5)
96
-
97
- return {
98
- "status": "success",
99
- "content": [{"text": f"✓ Tray app started (PID: {_tray_process.pid})"}],
100
- }
101
-
102
- elif action == "stop":
103
- if _tray_process:
104
- try:
105
- os.kill(_tray_process.pid, signal.SIGTERM)
106
- _tray_process.wait(timeout=3)
107
- except:
108
- pass
109
- _tray_process = None
110
-
111
- return {"status": "success", "content": [{"text": "✓ Stopped"}]}
112
-
113
- elif action == "status":
114
- is_running = _tray_process and _tray_process.poll() is None
115
- return {"status": "success", "content": [{"text": f"Running: {is_running}"}]}
116
-
117
- elif action == "update_menu":
118
- if not items:
119
- return {
120
- "status": "error",
121
- "content": [{"text": "items parameter required"}],
122
- }
123
-
124
- result = _send_ipc_command(
125
- socket_path, {"action": "update_menu", "items": items}
126
- )
127
-
128
- if result.get("status") == "success":
129
- return {
130
- "status": "success",
131
- "content": [{"text": f"✓ Menu updated ({len(items)} items)"}],
132
- }
133
- else:
134
- return {
135
- "status": "error",
136
- "content": [
137
- {"text": f"Failed: {result.get('message', 'Unknown error')}"}
138
- ],
139
- }
140
-
141
- elif action == "update_title":
142
- if not title:
143
- return {
144
- "status": "error",
145
- "content": [{"text": "title parameter required"}],
146
- }
147
-
148
- result = _send_ipc_command(
149
- socket_path, {"action": "update_title", "title": title}
150
- )
151
-
152
- if result.get("status") == "success":
153
- return {"status": "success", "content": [{"text": f"✓ Title: {title}"}]}
154
- else:
155
- return {
156
- "status": "error",
157
- "content": [{"text": f"Failed: {result.get('message')}"}],
158
- }
159
-
160
- elif action == "set_progress":
161
- """Set progress indicator: idle, thinking, processing, complete, error"""
162
- if not text:
163
- return {
164
- "status": "error",
165
- "content": [
166
- {
167
- "text": "text parameter required (idle/thinking/processing/complete/error)"
168
- }
169
- ],
170
- }
171
-
172
- result = _send_ipc_command(
173
- socket_path, {"action": "set_progress", "progress": text}
174
- )
175
-
176
- if result.get("status") == "success":
177
- return {"status": "success", "content": [{"text": f"✓ Progress: {text}"}]}
178
- else:
179
- return {
180
- "status": "error",
181
- "content": [{"text": f"Failed: {result.get('message')}"}],
182
- }
183
-
184
- elif action == "notify":
185
- if not message:
186
- return {
187
- "status": "error",
188
- "content": [{"text": "message parameter required"}],
189
- }
190
-
191
- result = _send_ipc_command(
192
- socket_path, {"action": "notify", "message": message}
193
- )
194
-
195
- if result.get("status") == "success":
196
- return {"status": "success", "content": [{"text": "✓ Notification sent"}]}
197
- else:
198
- return {
199
- "status": "error",
200
- "content": [{"text": f"Failed: {result.get('message')}"}],
201
- }
202
-
203
- elif action == "show_input":
204
- result = _send_ipc_command(socket_path, {"action": "show_input"})
205
-
206
- if result.get("status") == "success":
207
- return {"status": "success", "content": [{"text": "✓ Input shown"}]}
208
- else:
209
- return {
210
- "status": "error",
211
- "content": [{"text": f"Failed: {result.get('message')}"}],
212
- }
213
-
214
- elif action == "stream_text":
215
- if not text:
216
- return {"status": "error", "content": [{"text": "text parameter required"}]}
217
-
218
- result = _send_ipc_command(socket_path, {"action": "stream_text", "text": text})
219
-
220
- if result.get("status") == "success":
221
- return {"status": "success", "content": [{"text": "✓ Text streamed"}]}
222
- else:
223
- return {
224
- "status": "error",
225
- "content": [{"text": f"Failed: {result.get('message')}"}],
226
- }
227
-
228
- elif action in ["toggle_tcp", "toggle_ws", "toggle_mcp"]:
229
- result = _send_ipc_command(socket_path, {"action": action})
230
-
231
- if result.get("status") == "success":
232
- return {"status": "success", "content": [{"text": f"✓ {action} executed"}]}
233
- else:
234
- return {
235
- "status": "error",
236
- "content": [{"text": f"Failed: {result.get('message')}"}],
237
- }
238
-
239
- else:
240
- return {
241
- "status": "error",
242
- "content": [
243
- {
244
- "text": f"Unknown action: {action}. Available: start, stop, status, update_menu, update_title, set_progress, notify, show_input, stream_text, toggle_tcp, toggle_ws, toggle_mcp"
245
- }
246
- ],
247
- }