Terminal-Assistant-Interface 1.0.11__tar.gz → 1.1.0__tar.gz
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.
- {terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/PKG-INFO +1 -1
- {terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/pyproject.toml +1 -1
- {terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/src/Terminal_Assistant_Interface.egg-info/PKG-INFO +1 -1
- {terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/src/termiai/__init__.py +68 -5
- {terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/src/termilib/ftapi.py +3 -1
- {terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/src/termilib/tools.py +73 -5
- {terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/LICENSE +0 -0
- {terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/README.md +0 -0
- {terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/setup.cfg +0 -0
- {terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/src/Terminal_Assistant_Interface.egg-info/SOURCES.txt +0 -0
- {terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/src/Terminal_Assistant_Interface.egg-info/dependency_links.txt +0 -0
- {terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/src/Terminal_Assistant_Interface.egg-info/entry_points.txt +0 -0
- {terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/src/Terminal_Assistant_Interface.egg-info/requires.txt +0 -0
- {terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/src/Terminal_Assistant_Interface.egg-info/top_level.txt +0 -0
- {terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/src/termiai/__main__.py +0 -0
- {terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/src/termiai/clean.py +0 -0
- {terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/src/termiai_main.py +0 -0
- {terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/src/termilib/__init__.py +0 -0
- {terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/src/termilib/__main__.py +0 -0
- {terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/src/termilib/icon_data.py +0 -0
- {terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/src/termilib/test.py +0 -0
{terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/src/termiai/__init__.py
RENAMED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
# Made by @Ericwasepic127
|
|
3
3
|
|
|
4
|
-
import flet as ft, os, sys,
|
|
4
|
+
import flet as ft, os, sys, time, asyncio, platform as p, pathlib
|
|
5
5
|
sys.path.append("..")
|
|
6
6
|
sys.setrecursionlimit((10 ** 9) * 2)
|
|
7
7
|
from termilib import tools, ftapi
|
|
8
|
+
tools.alock =asyncio.Lock()
|
|
8
9
|
sysprompt = PROMPT = f"""You are TermiAI, a helpful assistant for users who are scared of the terminal.
|
|
9
10
|
You are created by @Ericwasepic127, and licensed under MIT
|
|
10
11
|
|
|
@@ -37,7 +38,7 @@ The Remove commands are safe unless USER is going to critcal files, like in Linu
|
|
|
37
38
|
You have access to these tools:
|
|
38
39
|
- `ddg_search` OR `deepsearch`: Use for web searches, the search tool may or may not exists, or diffrent name due user settings sets ddg_search or deepsearch or even disabled
|
|
39
40
|
- `currentutctime`: Use for getting the current time
|
|
40
|
-
- `run_command`: Use for running shell commands
|
|
41
|
+
- `run_command`: Use for running shell commands, but user cann't see terminal output
|
|
41
42
|
- `fetch`: Fetches things from internet, as like cURL, but use this instead cURL
|
|
42
43
|
|
|
43
44
|
Use the appropriate tool for each task. Do NOT output JSON. Use the native tool calling mechanism.
|
|
@@ -56,12 +57,40 @@ Format your response with Markdown.
|
|
|
56
57
|
tools.VERBOSE = "--verbose" in sys.argv
|
|
57
58
|
|
|
58
59
|
def setup_ai(data):
|
|
60
|
+
page = ft.context.page
|
|
61
|
+
dialog = ft.AlertDialog(
|
|
62
|
+
title=ft.Text("Request to run command"),
|
|
63
|
+
)
|
|
64
|
+
@tools.unerror(False)
|
|
65
|
+
async def onrun(command="", at="", background=False):
|
|
66
|
+
f = asyncio.Future()
|
|
67
|
+
def fgive(task):
|
|
68
|
+
if task.cancelled():
|
|
69
|
+
f.cancel()
|
|
70
|
+
elif (exc := task.exception()) is not None:
|
|
71
|
+
f.set_exception(exc)
|
|
72
|
+
else:
|
|
73
|
+
f.set_result(task.result())
|
|
74
|
+
def ok(e):
|
|
75
|
+
page.pop_dialog()
|
|
76
|
+
if background:
|
|
77
|
+
page.run_task(tools.run_command, command, at)
|
|
78
|
+
f.set_result("process spawned")
|
|
79
|
+
return
|
|
80
|
+
cf = page.run_task(tools.run_command, command, at)
|
|
81
|
+
cf.add_done_callback(fgive)
|
|
82
|
+
async with tools.alock:
|
|
83
|
+
dialog.on_dismiss = lambda e: f.done() or f.set_result("User closed confirmation dialog.")
|
|
84
|
+
dialog.content = ft.Text("AI wants to run command %s at %s\nWould you like to continue?" % (command, at or os.getcwd()))
|
|
85
|
+
dialog.actions = [ft.Button(content="YES", on_click=ok), ft.Button(content="NO", on_click=lambda e: page.pop_dialog() or f.set_result("User denied command execution."))]
|
|
86
|
+
page.show_dialog(dialog)
|
|
87
|
+
return await f
|
|
59
88
|
ai = tools.AsyncAI(data, sysprompt)
|
|
60
89
|
ai.assignTool(tools.grab, "fetch", "Use this instead cURL, wget, fetches things", {"url": {"type": "string", "description": "URL to fetch"}, "params": {"type": "object", "description": "Parameters in URL so you don't need any custom params on URL"}, "method": {"type": "string", "description": "Methods from POST/PUT/DELETE/GET"}, "json": {"type": "object", "description": "On POST, give this as JSON formatted POST request"}}, ["url"])
|
|
61
90
|
ai.assignTool(tools.instantSearch, "ddg_search", "Instant search API by duckduckgo, for quick lookups.", {"q": {"type": "string", "description": "Search query"}}, ["q"]) if tools.APPCONFIG.get("instantSearch", True) and tools.APPCONFIG.get("searching", True) else None
|
|
62
91
|
ai.assignTool(tools.deepsearch, "deepsearch", "Deep search API by LangSearch, for deep and unfindable questions.", {"q": {"type": "string", "description": "Search query"}}, ["q"]) if not tools.APPCONFIG.get("instantSearch", True) and tools.APPCONFIG.get("searching", True) else None
|
|
63
92
|
ai.assignTool(tools.get_current_time, "currentutctime", "Get latest UTC time", {"local": {"type": "boolean", "description": "Use true"}}, ["local"])
|
|
64
|
-
ai.assignTool(
|
|
93
|
+
ai.assignTool(onrun, "run_command", "Runs a shell command. Output is not directly visible to user. Give string instead list/array, we need \"echo 'this_example'\" not ['echo', 'this_example'].", {"command": {"type": "string", "description": "The command (not cmd argument!!!!)"}, "at": {"type": "string", "description": "Directory to run on"}, "background": {"type": "boolean", "description": "Will run on background or foreground? Default is false (foreground) and does not give stderr/stdout/returncode on background ones"}}, ["command"])
|
|
65
94
|
return ai
|
|
66
95
|
|
|
67
96
|
def chatElem(page: ft.Page, dlg):
|
|
@@ -130,6 +159,7 @@ def loadChatFromJson(page, name, dlg):
|
|
|
130
159
|
|
|
131
160
|
|
|
132
161
|
async def bping():
|
|
162
|
+
tools.ping_runs = True
|
|
133
163
|
while True:
|
|
134
164
|
await tools.loop()
|
|
135
165
|
if tools.VERBOSE:
|
|
@@ -137,7 +167,7 @@ async def bping():
|
|
|
137
167
|
await asyncio.sleep(13.75 * 60)
|
|
138
168
|
|
|
139
169
|
def main(page: ft.Page):
|
|
140
|
-
page.run_task(bping)
|
|
170
|
+
page.run_task(bping) if tools.ping_runs else None
|
|
141
171
|
page.title = "TermiAI - Your personal helper to run commands for you"
|
|
142
172
|
ftapi.setSize(page, (960, 540), False)
|
|
143
173
|
dlg = ft.AlertDialog(
|
|
@@ -194,6 +224,39 @@ def main(page: ft.Page):
|
|
|
194
224
|
],
|
|
195
225
|
value="1" if not tools.APPCONFIG.get("searching", True) else ("2" if tools.APPCONFIG.get("instantSearch", True) else "3")
|
|
196
226
|
)
|
|
227
|
+
async def on_export(e):
|
|
228
|
+
path = await ft.FilePicker().save_file(
|
|
229
|
+
file_name=f"termiai-backup-{int(time.time())}.zip",
|
|
230
|
+
allowed_extensions=["zip"]
|
|
231
|
+
)
|
|
232
|
+
if path:
|
|
233
|
+
tools.export_backup(path)
|
|
234
|
+
|
|
235
|
+
async def on_import(e):
|
|
236
|
+
files = await ft.FilePicker().pick_files(
|
|
237
|
+
allow_multiple=False,
|
|
238
|
+
allowed_extensions=["zip"]
|
|
239
|
+
)
|
|
240
|
+
if files:
|
|
241
|
+
tools.import_backup(files[0].path)
|
|
242
|
+
page.controls.clear()
|
|
243
|
+
main(page)
|
|
244
|
+
|
|
245
|
+
backup_row = ft.Row(
|
|
246
|
+
controls=[
|
|
247
|
+
ft.Button(
|
|
248
|
+
content="Export Backup (.zip)",
|
|
249
|
+
icon=ft.Icons.UPLOAD_FILE,
|
|
250
|
+
on_click=on_export,
|
|
251
|
+
),
|
|
252
|
+
ft.Button(
|
|
253
|
+
content="Restore Backup (.zip)",
|
|
254
|
+
icon=ft.Icons.DOWNLOAD,
|
|
255
|
+
on_click=on_import,
|
|
256
|
+
),
|
|
257
|
+
],
|
|
258
|
+
)
|
|
259
|
+
|
|
197
260
|
sideItems = [{
|
|
198
261
|
"items": [
|
|
199
262
|
ft.Text("Welcome to TermiAI!", size=30),
|
|
@@ -208,7 +271,7 @@ def main(page: ft.Page):
|
|
|
208
271
|
darkTog,
|
|
209
272
|
choose_server,
|
|
210
273
|
choose_search,
|
|
211
|
-
|
|
274
|
+
backup_row
|
|
212
275
|
],
|
|
213
276
|
"label": "Settings",
|
|
214
277
|
"icon": ft.Icons.SETTINGS
|
{terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/src/termilib/ftapi.py
RENAMED
|
@@ -173,7 +173,7 @@ def shellv2(page, do, waitmsg="Please wait..."):
|
|
|
173
173
|
|
|
174
174
|
log = ft.Column(auto_scroll=True, spacing=12, expand=True, scroll=ft.ScrollMode.AUTO)
|
|
175
175
|
log.flag = False
|
|
176
|
-
inp = ft.TextField(expand=True, autofocus=True)
|
|
176
|
+
inp = ft.TextField(expand=True, autofocus=True, multiline=True, min_lines=1, max_lines=5, shift_enter=True)
|
|
177
177
|
send_btn = ft.IconButton(ft.Icons.SEND)
|
|
178
178
|
def handle_link(e):
|
|
179
179
|
page.run_task(url_launcher.launch_url, e.data)
|
|
@@ -216,11 +216,13 @@ def shellv2(page, do, waitmsg="Please wait..."):
|
|
|
216
216
|
out = ft.Markdown(value=f"*{waitmsg}*", selectable=False, extension_set=ft.MarkdownExtensionSet.GITHUB_WEB)
|
|
217
217
|
log.controls.append(out)
|
|
218
218
|
send_btn.disabled = True
|
|
219
|
+
inp.disabled = True
|
|
219
220
|
page.update()
|
|
220
221
|
response_text = await do(q)
|
|
221
222
|
out.value = response_text
|
|
222
223
|
out.selectable = True
|
|
223
224
|
send_btn.disabled = False
|
|
225
|
+
inp.disabled = False
|
|
224
226
|
await inp.focus()
|
|
225
227
|
page.update()
|
|
226
228
|
inp.on_submit = lambda e: page.run_task(send, e)
|
{terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/src/termilib/tools.py
RENAMED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
# Made by @Ericwasepic127
|
|
3
3
|
|
|
4
|
-
import httpx, json, asyncio, platformdirs, os, threading as t, uuid, time, datetime, inspect, traceback
|
|
4
|
+
import httpx, json, asyncio, platformdirs, os, threading as t, uuid, time, datetime, inspect, traceback, tempfile, sys
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
RUNTIMEDIR = platformdirs.user_runtime_dir("TermiAI", ensure_exists=True)
|
|
8
|
+
except (OSError, PermissionError):
|
|
9
|
+
RUNTIMEDIR = os.path.join(tempfile.gettempdir(), "TermiAI")
|
|
10
|
+
os.makedirs(RUNTIMEDIR, exist_ok=True)
|
|
5
11
|
|
|
6
12
|
CONFIGS = platformdirs.user_config_dir("TermiAI")
|
|
7
13
|
DATA = platformdirs.user_data_dir("TermiAI")
|
|
@@ -13,6 +19,7 @@ CHATJSON = None
|
|
|
13
19
|
URL = None
|
|
14
20
|
BASEAIURL = "https://ai-proxy-%s.onrender.com/"
|
|
15
21
|
VERBOSE = False
|
|
22
|
+
ping_runs = False
|
|
16
23
|
THERROR = """<!doctype html>
|
|
17
24
|
<html lang=en>
|
|
18
25
|
<title>429 Too Many Requests</title>
|
|
@@ -22,6 +29,30 @@ THERROR = """<!doctype html>
|
|
|
22
29
|
os.makedirs(CONFIGS, exist_ok=True)
|
|
23
30
|
os.makedirs(DATA, exist_ok=True)
|
|
24
31
|
|
|
32
|
+
LOCKPATH = os.path.join(RUNTIMEDIR, ".lockfile")
|
|
33
|
+
_lock_fd = open(LOCKPATH, "w")
|
|
34
|
+
|
|
35
|
+
def acquire_lock(fd):
|
|
36
|
+
if sys.platform == "win32":
|
|
37
|
+
import msvcrt
|
|
38
|
+
fd.seek(0)
|
|
39
|
+
msvcrt.locking(fd.fileno(), msvcrt.LK_NBLCK, 1)
|
|
40
|
+
else:
|
|
41
|
+
import fcntl
|
|
42
|
+
fcntl.flock(fd.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
|
|
43
|
+
|
|
44
|
+
try:
|
|
45
|
+
acquire_lock(_lock_fd)
|
|
46
|
+
_lock_fd.write(f"pid={os.getpid()} time={int(time.time())}\n")
|
|
47
|
+
_lock_fd.flush()
|
|
48
|
+
except (BlockingIOError, OSError):
|
|
49
|
+
print("TermiAI is already running!")
|
|
50
|
+
sys.exit(1)
|
|
51
|
+
except SystemExit:
|
|
52
|
+
raise
|
|
53
|
+
except:
|
|
54
|
+
pass
|
|
55
|
+
|
|
25
56
|
class HandleError:
|
|
26
57
|
def __init__(self):
|
|
27
58
|
self.cleanup()
|
|
@@ -114,6 +145,35 @@ def awrap(f):
|
|
|
114
145
|
return res
|
|
115
146
|
return a
|
|
116
147
|
|
|
148
|
+
import zipfile
|
|
149
|
+
|
|
150
|
+
@swrap
|
|
151
|
+
def export_backup(zip_path: str):
|
|
152
|
+
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zf:
|
|
153
|
+
for folder, prefix in [(CONFIGS, "configs"), (DATA, "data")]:
|
|
154
|
+
if os.path.exists(folder):
|
|
155
|
+
for fname in os.listdir(folder):
|
|
156
|
+
fpath = JOIN(folder, fname)
|
|
157
|
+
if os.path.isfile(fpath):
|
|
158
|
+
zf.write(fpath, arcname=f"{prefix}/{fname}")
|
|
159
|
+
|
|
160
|
+
@swrap
|
|
161
|
+
def import_backup(zip_path: str):
|
|
162
|
+
with zipfile.ZipFile(zip_path, "r") as zf:
|
|
163
|
+
for member in zf.namelist():
|
|
164
|
+
if member.endswith("/") or ".." in member:
|
|
165
|
+
continue
|
|
166
|
+
if member.startswith("configs/"):
|
|
167
|
+
target = JOIN(CONFIGS, os.path.basename(member))
|
|
168
|
+
elif member.startswith("data/"):
|
|
169
|
+
target = JOIN(DATA, os.path.basename(member))
|
|
170
|
+
else:
|
|
171
|
+
continue
|
|
172
|
+
with zf.open(member) as src, open(target, "wb") as dst:
|
|
173
|
+
dst.write(src.read())
|
|
174
|
+
CHATJSON.reload()
|
|
175
|
+
APPCONFIG.reload()
|
|
176
|
+
|
|
117
177
|
@awrap
|
|
118
178
|
@unerror(False)
|
|
119
179
|
async def grab(url=None, method="GET", follow_redirects=True, **kwargs):
|
|
@@ -192,14 +252,22 @@ async def post(data):
|
|
|
192
252
|
try:
|
|
193
253
|
r = await client.post(URL or "https://ai-proxy-x.onrender.com/", content=json.dumps(data), headers={"Content-Type": "application/json"}, timeout=120, follow_redirects=True)
|
|
194
254
|
m = r.json()
|
|
255
|
+
if isinstance(m, list):
|
|
256
|
+
try:
|
|
257
|
+
m = json.loads(m[0])
|
|
258
|
+
except:
|
|
259
|
+
pass
|
|
195
260
|
except json.JSONDecodeError as e:
|
|
261
|
+
if VERBOSE:
|
|
262
|
+
print(r.text, "\nStatus code:", r.status_code)
|
|
196
263
|
try:
|
|
197
264
|
if ("<!doctype html>" in r.text and "<html>" in r.text and r.status_code == 429 and "error" in r.text) or THERROR in r.text.strip().rstrip():
|
|
198
265
|
m = {"error": {"message": "Too many requests per minute. Please wait about 1 minute"}}
|
|
199
266
|
else:
|
|
200
|
-
if
|
|
267
|
+
if "<!doctype html>" in r.text.lower() and "<html>" in r.text and r.headers.get("content-type", "html") != "application/json" and not r.ok or "base64" in r.text.lower() or "render" in r.text.lower() or "waf" in r.text.lower():
|
|
201
268
|
m = {"error": {"message": "Some serverside problems, please try again later"}}
|
|
202
|
-
|
|
269
|
+
else:
|
|
270
|
+
m = {"error": {"message": "Decode Error (server did not sent what expected): " + r.text[:50]}}
|
|
203
271
|
except (BaseException, Exception) as e:
|
|
204
272
|
m = {"error": {"message": e.__class__.__name__ + ": " + str(e)}}
|
|
205
273
|
except (BaseException, Exception) as e:
|
|
@@ -408,7 +476,7 @@ class AsyncAI:
|
|
|
408
476
|
currentLoop += 1
|
|
409
477
|
if tool == "tool_calls":
|
|
410
478
|
for call in calls:
|
|
411
|
-
clone.append({"role": "tool", "tool_call_id": call.get("id"), "content": "Too much tool calls: try again in next request - you cannot run any tool calls because you exceeding tool limit per one message"})
|
|
479
|
+
clone.append({"role": "tool", "tool_call_id": call.get("id"), "content": "Too much tool calls: try again in next request - you cannot run any tool calls because you exceeding tool limit per one message."})
|
|
412
480
|
dclon["messages"] = clone
|
|
413
481
|
returned = await post(dclon)
|
|
414
482
|
c = returned.get("choices")
|
|
@@ -427,7 +495,7 @@ DEFAULTDATA = {
|
|
|
427
495
|
"search": True,
|
|
428
496
|
"custom": False,
|
|
429
497
|
"instantSearch": True,
|
|
430
|
-
"maxToolLoop":
|
|
498
|
+
"maxToolLoop": 5,
|
|
431
499
|
}
|
|
432
500
|
|
|
433
501
|
CHATJSON = LiveJson(CHATS)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/src/termiai/__main__.py
RENAMED
|
File without changes
|
{terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/src/termiai/clean.py
RENAMED
|
File without changes
|
{terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/src/termiai_main.py
RENAMED
|
File without changes
|
{terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/src/termilib/__init__.py
RENAMED
|
File without changes
|
{terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/src/termilib/__main__.py
RENAMED
|
File without changes
|
{terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/src/termilib/icon_data.py
RENAMED
|
File without changes
|
{terminal_assistant_interface-1.0.11 → terminal_assistant_interface-1.1.0}/src/termilib/test.py
RENAMED
|
File without changes
|